001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.ArrayUtil;
032    import com.liferay.portal.kernel.util.CalendarUtil;
033    import com.liferay.portal.kernel.util.GetterUtil;
034    import com.liferay.portal.kernel.util.InstanceFactory;
035    import com.liferay.portal.kernel.util.OrderByComparator;
036    import com.liferay.portal.kernel.util.StringBundler;
037    import com.liferay.portal.kernel.util.StringPool;
038    import com.liferay.portal.kernel.util.StringUtil;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.persistence.LockPersistence;
044    import com.liferay.portal.service.persistence.SubscriptionPersistence;
045    import com.liferay.portal.service.persistence.UserPersistence;
046    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
050    import com.liferay.portlet.messageboards.NoSuchThreadException;
051    import com.liferay.portlet.messageboards.model.MBThread;
052    import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
053    import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
054    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
055    import com.liferay.portlet.social.service.persistence.SocialActivityCounterPersistence;
056    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
057    import com.liferay.portlet.trash.service.persistence.TrashEntryPersistence;
058    
059    import java.io.Serializable;
060    
061    import java.util.ArrayList;
062    import java.util.Collections;
063    import java.util.Date;
064    import java.util.List;
065    
066    /**
067     * The persistence implementation for the message boards thread service.
068     *
069     * <p>
070     * Caching information and settings can be found in <code>portal.properties</code>
071     * </p>
072     *
073     * @author Brian Wing Shun Chan
074     * @see MBThreadPersistence
075     * @see MBThreadUtil
076     * @generated
077     */
078    public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
079            implements MBThreadPersistence {
080            /*
081             * NOTE FOR DEVELOPERS:
082             *
083             * Never modify or reference this class directly. Always use {@link MBThreadUtil} to access the message boards thread persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
084             */
085            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
086            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087                    ".List1";
088            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
089                    ".List2";
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
091                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
093                            new String[] {
094                                    Long.class.getName(),
095                                    
096                            "java.lang.Integer", "java.lang.Integer",
097                                    "com.liferay.portal.kernel.util.OrderByComparator"
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
100                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
101                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
102                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
103                            new String[] { Long.class.getName() },
104                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
105            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
106                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
107                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
108                            new String[] { Long.class.getName() });
109            public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
110                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
111                            FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
112                            new String[] { Long.class.getName() },
113                            MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
114            public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
115                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
116                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
117                            new String[] { Long.class.getName() });
118            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
119                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
120                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
121                            new String[] {
122                                    Long.class.getName(), Long.class.getName(),
123                                    
124                            "java.lang.Integer", "java.lang.Integer",
125                                    "com.liferay.portal.kernel.util.OrderByComparator"
126                            });
127            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
128                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
130                            new String[] { Long.class.getName(), Long.class.getName() },
131                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
132                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK);
133            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
134                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
135                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
136                            new String[] { Long.class.getName(), Long.class.getName() });
137            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
138                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
139                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
140                            new String[] { Long.class.getName(), Long.class.getName() });
141            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
142                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
143                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
144                            new String[] {
145                                    Long.class.getName(), Long.class.getName(),
146                                    
147                            "java.lang.Integer", "java.lang.Integer",
148                                    "com.liferay.portal.kernel.util.OrderByComparator"
149                            });
150            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
151                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
152                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
153                            new String[] { Long.class.getName(), Long.class.getName() });
154            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
155                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
156                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
157                            new String[] {
158                                    Long.class.getName(), Integer.class.getName(),
159                                    
160                            "java.lang.Integer", "java.lang.Integer",
161                                    "com.liferay.portal.kernel.util.OrderByComparator"
162                            });
163            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
164                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
166                            new String[] { Long.class.getName(), Integer.class.getName() },
167                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
168                            MBThreadModelImpl.STATUS_COLUMN_BITMASK);
169            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
170                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
171                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
172                            new String[] { Long.class.getName(), Integer.class.getName() });
173            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
174                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
175                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
176                            new String[] {
177                                    Long.class.getName(), Double.class.getName(),
178                                    
179                            "java.lang.Integer", "java.lang.Integer",
180                                    "com.liferay.portal.kernel.util.OrderByComparator"
181                            });
182            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
183                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
184                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
185                            new String[] { Long.class.getName(), Double.class.getName() },
186                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
187                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
188            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
189                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
190                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
191                            new String[] { Long.class.getName(), Double.class.getName() });
192            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
193                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
194                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
195                            new String[] {
196                                    Date.class.getName(), Double.class.getName(),
197                                    
198                            "java.lang.Integer", "java.lang.Integer",
199                                    "com.liferay.portal.kernel.util.OrderByComparator"
200                            });
201            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
202                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
204                            new String[] { Date.class.getName(), Double.class.getName() },
205                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
206                            MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
207            public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
208                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
209                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
210                            new String[] { Date.class.getName(), Double.class.getName() });
211            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
212                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
213                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
214                            new String[] {
215                                    Long.class.getName(), Long.class.getName(), Date.class.getName(),
216                                    
217                            "java.lang.Integer", "java.lang.Integer",
218                                    "com.liferay.portal.kernel.util.OrderByComparator"
219                            });
220            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
221                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
222                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
223                            new String[] {
224                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
225                            },
226                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
227                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
228                            MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
229            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
230                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
231                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
232                            new String[] {
233                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
234                            });
235            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
236                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
237                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
238                            new String[] {
239                                    Long.class.getName(), Long.class.getName(),
240                                    Integer.class.getName(),
241                                    
242                            "java.lang.Integer", "java.lang.Integer",
243                                    "com.liferay.portal.kernel.util.OrderByComparator"
244                            });
245            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
246                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
247                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
248                            new String[] {
249                                    Long.class.getName(), Long.class.getName(),
250                                    Integer.class.getName()
251                            },
252                            MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
253                            MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
254                            MBThreadModelImpl.STATUS_COLUMN_BITMASK);
255            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
256                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
257                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
258                            new String[] {
259                                    Long.class.getName(), Long.class.getName(),
260                                    Integer.class.getName()
261                            });
262            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
263                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
264                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
265                            new String[] {
266                                    Long.class.getName(), Long.class.getName(),
267                                    Integer.class.getName()
268                            });
269            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
270                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
271                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
272                            new String[] {
273                                    Long.class.getName(), Long.class.getName(),
274                                    Integer.class.getName(),
275                                    
276                            "java.lang.Integer", "java.lang.Integer",
277                                    "com.liferay.portal.kernel.util.OrderByComparator"
278                            });
279            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S =
280                    new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
281                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
282                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_S",
283                            new String[] {
284                                    Long.class.getName(), Long.class.getName(),
285                                    Integer.class.getName()
286                            });
287            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
288                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
289                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
290            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
291                            MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
292                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
293            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
294                            MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
295                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
296    
297            /**
298             * Caches the message boards thread in the entity cache if it is enabled.
299             *
300             * @param mbThread the message boards thread
301             */
302            public void cacheResult(MBThread mbThread) {
303                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
304                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
305    
306                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
307                            new Object[] { Long.valueOf(mbThread.getRootMessageId()) }, mbThread);
308    
309                    mbThread.resetOriginalValues();
310            }
311    
312            /**
313             * Caches the message boards threads in the entity cache if it is enabled.
314             *
315             * @param mbThreads the message boards threads
316             */
317            public void cacheResult(List<MBThread> mbThreads) {
318                    for (MBThread mbThread : mbThreads) {
319                            if (EntityCacheUtil.getResult(
320                                                    MBThreadModelImpl.ENTITY_CACHE_ENABLED,
321                                                    MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
322                                    cacheResult(mbThread);
323                            }
324                            else {
325                                    mbThread.resetOriginalValues();
326                            }
327                    }
328            }
329    
330            /**
331             * Clears the cache for all message boards threads.
332             *
333             * <p>
334             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
335             * </p>
336             */
337            @Override
338            public void clearCache() {
339                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
340                            CacheRegistryUtil.clear(MBThreadImpl.class.getName());
341                    }
342    
343                    EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
344    
345                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
346                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
347                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
348            }
349    
350            /**
351             * Clears the cache for the message boards thread.
352             *
353             * <p>
354             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
355             * </p>
356             */
357            @Override
358            public void clearCache(MBThread mbThread) {
359                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
360                            MBThreadImpl.class, mbThread.getPrimaryKey());
361    
362                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
363                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
364    
365                    clearUniqueFindersCache(mbThread);
366            }
367    
368            @Override
369            public void clearCache(List<MBThread> mbThreads) {
370                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
371                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
372    
373                    for (MBThread mbThread : mbThreads) {
374                            EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
375                                    MBThreadImpl.class, mbThread.getPrimaryKey());
376    
377                            clearUniqueFindersCache(mbThread);
378                    }
379            }
380    
381            protected void clearUniqueFindersCache(MBThread mbThread) {
382                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
383                            new Object[] { Long.valueOf(mbThread.getRootMessageId()) });
384            }
385    
386            /**
387             * Creates a new message boards thread with the primary key. Does not add the message boards thread to the database.
388             *
389             * @param threadId the primary key for the new message boards thread
390             * @return the new message boards thread
391             */
392            public MBThread create(long threadId) {
393                    MBThread mbThread = new MBThreadImpl();
394    
395                    mbThread.setNew(true);
396                    mbThread.setPrimaryKey(threadId);
397    
398                    return mbThread;
399            }
400    
401            /**
402             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
403             *
404             * @param threadId the primary key of the message boards thread
405             * @return the message boards thread that was removed
406             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
407             * @throws SystemException if a system exception occurred
408             */
409            public MBThread remove(long threadId)
410                    throws NoSuchThreadException, SystemException {
411                    return remove(Long.valueOf(threadId));
412            }
413    
414            /**
415             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
416             *
417             * @param primaryKey the primary key of the message boards thread
418             * @return the message boards thread that was removed
419             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
420             * @throws SystemException if a system exception occurred
421             */
422            @Override
423            public MBThread remove(Serializable primaryKey)
424                    throws NoSuchThreadException, SystemException {
425                    Session session = null;
426    
427                    try {
428                            session = openSession();
429    
430                            MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
431                                            primaryKey);
432    
433                            if (mbThread == null) {
434                                    if (_log.isWarnEnabled()) {
435                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
436                                    }
437    
438                                    throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
439                                            primaryKey);
440                            }
441    
442                            return remove(mbThread);
443                    }
444                    catch (NoSuchThreadException nsee) {
445                            throw nsee;
446                    }
447                    catch (Exception e) {
448                            throw processException(e);
449                    }
450                    finally {
451                            closeSession(session);
452                    }
453            }
454    
455            @Override
456            protected MBThread removeImpl(MBThread mbThread) throws SystemException {
457                    mbThread = toUnwrappedModel(mbThread);
458    
459                    Session session = null;
460    
461                    try {
462                            session = openSession();
463    
464                            if (mbThread.isCachedModel()) {
465                                    mbThread = (MBThread)session.get(MBThreadImpl.class,
466                                                    mbThread.getPrimaryKeyObj());
467                            }
468    
469                            session.delete(mbThread);
470                    }
471                    catch (Exception e) {
472                            throw processException(e);
473                    }
474                    finally {
475                            closeSession(session);
476                    }
477    
478                    clearCache(mbThread);
479    
480                    return mbThread;
481            }
482    
483            @Override
484            public MBThread updateImpl(
485                    com.liferay.portlet.messageboards.model.MBThread mbThread)
486                    throws SystemException {
487                    mbThread = toUnwrappedModel(mbThread);
488    
489                    boolean isNew = mbThread.isNew();
490    
491                    MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
492    
493                    Session session = null;
494    
495                    try {
496                            session = openSession();
497    
498                            if (mbThread.isNew()) {
499                                    session.save(mbThread);
500    
501                                    mbThread.setNew(false);
502                            }
503                            else {
504                                    session.merge(mbThread);
505                            }
506                    }
507                    catch (Exception e) {
508                            throw processException(e);
509                    }
510                    finally {
511                            closeSession(session);
512                    }
513    
514                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
515    
516                    if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
517                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
518                    }
519    
520                    else {
521                            if ((mbThreadModelImpl.getColumnBitmask() &
522                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
523                                    Object[] args = new Object[] {
524                                                    Long.valueOf(mbThreadModelImpl.getOriginalGroupId())
525                                            };
526    
527                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
528                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
529                                            args);
530    
531                                    args = new Object[] { Long.valueOf(mbThreadModelImpl.getGroupId()) };
532    
533                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
534                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
535                                            args);
536                            }
537    
538                            if ((mbThreadModelImpl.getColumnBitmask() &
539                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
540                                    Object[] args = new Object[] {
541                                                    Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
542                                                    Long.valueOf(mbThreadModelImpl.getOriginalCategoryId())
543                                            };
544    
545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
546                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
547                                            args);
548    
549                                    args = new Object[] {
550                                                    Long.valueOf(mbThreadModelImpl.getGroupId()),
551                                                    Long.valueOf(mbThreadModelImpl.getCategoryId())
552                                            };
553    
554                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
555                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
556                                            args);
557                            }
558    
559                            if ((mbThreadModelImpl.getColumnBitmask() &
560                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
561                                    Object[] args = new Object[] {
562                                                    Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
563                                                    Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
564                                            };
565    
566                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
567                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
568                                            args);
569    
570                                    args = new Object[] {
571                                                    Long.valueOf(mbThreadModelImpl.getGroupId()),
572                                                    Integer.valueOf(mbThreadModelImpl.getStatus())
573                                            };
574    
575                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
576                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
577                                            args);
578                            }
579    
580                            if ((mbThreadModelImpl.getColumnBitmask() &
581                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
582                                    Object[] args = new Object[] {
583                                                    Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
584                                                    Double.valueOf(mbThreadModelImpl.getOriginalPriority())
585                                            };
586    
587                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
588                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
589                                            args);
590    
591                                    args = new Object[] {
592                                                    Long.valueOf(mbThreadModelImpl.getCategoryId()),
593                                                    Double.valueOf(mbThreadModelImpl.getPriority())
594                                            };
595    
596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
598                                            args);
599                            }
600    
601                            if ((mbThreadModelImpl.getColumnBitmask() &
602                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
603                                    Object[] args = new Object[] {
604                                                    mbThreadModelImpl.getOriginalLastPostDate(),
605                                                    Double.valueOf(mbThreadModelImpl.getOriginalPriority())
606                                            };
607    
608                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
609                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
610                                            args);
611    
612                                    args = new Object[] {
613                                                    mbThreadModelImpl.getLastPostDate(),
614                                                    Double.valueOf(mbThreadModelImpl.getPriority())
615                                            };
616    
617                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
618                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
619                                            args);
620                            }
621    
622                            if ((mbThreadModelImpl.getColumnBitmask() &
623                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
624                                    Object[] args = new Object[] {
625                                                    Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
626                                                    Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
627                                                    
628                                                    mbThreadModelImpl.getOriginalLastPostDate()
629                                            };
630    
631                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
632                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
633                                            args);
634    
635                                    args = new Object[] {
636                                                    Long.valueOf(mbThreadModelImpl.getGroupId()),
637                                                    Long.valueOf(mbThreadModelImpl.getCategoryId()),
638                                                    
639                                                    mbThreadModelImpl.getLastPostDate()
640                                            };
641    
642                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
643                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
644                                            args);
645                            }
646    
647                            if ((mbThreadModelImpl.getColumnBitmask() &
648                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
649                                    Object[] args = new Object[] {
650                                                    Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
651                                                    Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
652                                                    Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
653                                            };
654    
655                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
656                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
657                                            args);
658    
659                                    args = new Object[] {
660                                                    Long.valueOf(mbThreadModelImpl.getGroupId()),
661                                                    Long.valueOf(mbThreadModelImpl.getCategoryId()),
662                                                    Integer.valueOf(mbThreadModelImpl.getStatus())
663                                            };
664    
665                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
666                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
667                                            args);
668                            }
669                    }
670    
671                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
672                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
673    
674                    if (isNew) {
675                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
676                                    new Object[] { Long.valueOf(mbThread.getRootMessageId()) },
677                                    mbThread);
678                    }
679                    else {
680                            if ((mbThreadModelImpl.getColumnBitmask() &
681                                            FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
682                                    Object[] args = new Object[] {
683                                                    Long.valueOf(mbThreadModelImpl.getOriginalRootMessageId())
684                                            };
685    
686                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
687                                            args);
688    
689                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
690                                            args);
691    
692                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
693                                            new Object[] { Long.valueOf(mbThread.getRootMessageId()) },
694                                            mbThread);
695                            }
696                    }
697    
698                    return mbThread;
699            }
700    
701            protected MBThread toUnwrappedModel(MBThread mbThread) {
702                    if (mbThread instanceof MBThreadImpl) {
703                            return mbThread;
704                    }
705    
706                    MBThreadImpl mbThreadImpl = new MBThreadImpl();
707    
708                    mbThreadImpl.setNew(mbThread.isNew());
709                    mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
710    
711                    mbThreadImpl.setThreadId(mbThread.getThreadId());
712                    mbThreadImpl.setGroupId(mbThread.getGroupId());
713                    mbThreadImpl.setCompanyId(mbThread.getCompanyId());
714                    mbThreadImpl.setCategoryId(mbThread.getCategoryId());
715                    mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
716                    mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
717                    mbThreadImpl.setMessageCount(mbThread.getMessageCount());
718                    mbThreadImpl.setViewCount(mbThread.getViewCount());
719                    mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
720                    mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
721                    mbThreadImpl.setPriority(mbThread.getPriority());
722                    mbThreadImpl.setQuestion(mbThread.isQuestion());
723                    mbThreadImpl.setStatus(mbThread.getStatus());
724                    mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
725                    mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
726                    mbThreadImpl.setStatusDate(mbThread.getStatusDate());
727    
728                    return mbThreadImpl;
729            }
730    
731            /**
732             * Returns the message boards thread with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
733             *
734             * @param primaryKey the primary key of the message boards thread
735             * @return the message boards thread
736             * @throws com.liferay.portal.NoSuchModelException if a message boards thread with the primary key could not be found
737             * @throws SystemException if a system exception occurred
738             */
739            @Override
740            public MBThread findByPrimaryKey(Serializable primaryKey)
741                    throws NoSuchModelException, SystemException {
742                    return findByPrimaryKey(((Long)primaryKey).longValue());
743            }
744    
745            /**
746             * Returns the message boards thread with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
747             *
748             * @param threadId the primary key of the message boards thread
749             * @return the message boards thread
750             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
751             * @throws SystemException if a system exception occurred
752             */
753            public MBThread findByPrimaryKey(long threadId)
754                    throws NoSuchThreadException, SystemException {
755                    MBThread mbThread = fetchByPrimaryKey(threadId);
756    
757                    if (mbThread == null) {
758                            if (_log.isWarnEnabled()) {
759                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
760                            }
761    
762                            throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
763                                    threadId);
764                    }
765    
766                    return mbThread;
767            }
768    
769            /**
770             * Returns the message boards thread with the primary key or returns <code>null</code> if it could not be found.
771             *
772             * @param primaryKey the primary key of the message boards thread
773             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
774             * @throws SystemException if a system exception occurred
775             */
776            @Override
777            public MBThread fetchByPrimaryKey(Serializable primaryKey)
778                    throws SystemException {
779                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
780            }
781    
782            /**
783             * Returns the message boards thread with the primary key or returns <code>null</code> if it could not be found.
784             *
785             * @param threadId the primary key of the message boards thread
786             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
787             * @throws SystemException if a system exception occurred
788             */
789            public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
790                    MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
791                                    MBThreadImpl.class, threadId);
792    
793                    if (mbThread == _nullMBThread) {
794                            return null;
795                    }
796    
797                    if (mbThread == null) {
798                            Session session = null;
799    
800                            boolean hasException = false;
801    
802                            try {
803                                    session = openSession();
804    
805                                    mbThread = (MBThread)session.get(MBThreadImpl.class,
806                                                    Long.valueOf(threadId));
807                            }
808                            catch (Exception e) {
809                                    hasException = true;
810    
811                                    throw processException(e);
812                            }
813                            finally {
814                                    if (mbThread != null) {
815                                            cacheResult(mbThread);
816                                    }
817                                    else if (!hasException) {
818                                            EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
819                                                    MBThreadImpl.class, threadId, _nullMBThread);
820                                    }
821    
822                                    closeSession(session);
823                            }
824                    }
825    
826                    return mbThread;
827            }
828    
829            /**
830             * Returns all the message boards threads where groupId = &#63;.
831             *
832             * @param groupId the group ID
833             * @return the matching message boards threads
834             * @throws SystemException if a system exception occurred
835             */
836            public List<MBThread> findByGroupId(long groupId) throws SystemException {
837                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
838            }
839    
840            /**
841             * Returns a range of all the message boards threads where groupId = &#63;.
842             *
843             * <p>
844             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
845             * </p>
846             *
847             * @param groupId the group ID
848             * @param start the lower bound of the range of message boards threads
849             * @param end the upper bound of the range of message boards threads (not inclusive)
850             * @return the range of matching message boards threads
851             * @throws SystemException if a system exception occurred
852             */
853            public List<MBThread> findByGroupId(long groupId, int start, int end)
854                    throws SystemException {
855                    return findByGroupId(groupId, start, end, null);
856            }
857    
858            /**
859             * Returns an ordered range of all the message boards threads where groupId = &#63;.
860             *
861             * <p>
862             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
863             * </p>
864             *
865             * @param groupId the group ID
866             * @param start the lower bound of the range of message boards threads
867             * @param end the upper bound of the range of message boards threads (not inclusive)
868             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
869             * @return the ordered range of matching message boards threads
870             * @throws SystemException if a system exception occurred
871             */
872            public List<MBThread> findByGroupId(long groupId, int start, int end,
873                    OrderByComparator orderByComparator) throws SystemException {
874                    FinderPath finderPath = null;
875                    Object[] finderArgs = null;
876    
877                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
878                                    (orderByComparator == null)) {
879                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
880                            finderArgs = new Object[] { groupId };
881                    }
882                    else {
883                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
884                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
885                    }
886    
887                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
888                                    finderArgs, this);
889    
890                    if ((list != null) && !list.isEmpty()) {
891                            for (MBThread mbThread : list) {
892                                    if ((groupId != mbThread.getGroupId())) {
893                                            list = null;
894    
895                                            break;
896                                    }
897                            }
898                    }
899    
900                    if (list == null) {
901                            StringBundler query = null;
902    
903                            if (orderByComparator != null) {
904                                    query = new StringBundler(3 +
905                                                    (orderByComparator.getOrderByFields().length * 3));
906                            }
907                            else {
908                                    query = new StringBundler(3);
909                            }
910    
911                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
912    
913                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
914    
915                            if (orderByComparator != null) {
916                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
917                                            orderByComparator);
918                            }
919    
920                            else {
921                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
922                            }
923    
924                            String sql = query.toString();
925    
926                            Session session = null;
927    
928                            try {
929                                    session = openSession();
930    
931                                    Query q = session.createQuery(sql);
932    
933                                    QueryPos qPos = QueryPos.getInstance(q);
934    
935                                    qPos.add(groupId);
936    
937                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
938                                                    end);
939                            }
940                            catch (Exception e) {
941                                    throw processException(e);
942                            }
943                            finally {
944                                    if (list == null) {
945                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
946                                    }
947                                    else {
948                                            cacheResult(list);
949    
950                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
951                                    }
952    
953                                    closeSession(session);
954                            }
955                    }
956    
957                    return list;
958            }
959    
960            /**
961             * Returns the first message boards thread in the ordered set where groupId = &#63;.
962             *
963             * @param groupId the group ID
964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
965             * @return the first matching message boards thread
966             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
967             * @throws SystemException if a system exception occurred
968             */
969            public MBThread findByGroupId_First(long groupId,
970                    OrderByComparator orderByComparator)
971                    throws NoSuchThreadException, SystemException {
972                    MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
973    
974                    if (mbThread != null) {
975                            return mbThread;
976                    }
977    
978                    StringBundler msg = new StringBundler(4);
979    
980                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
981    
982                    msg.append("groupId=");
983                    msg.append(groupId);
984    
985                    msg.append(StringPool.CLOSE_CURLY_BRACE);
986    
987                    throw new NoSuchThreadException(msg.toString());
988            }
989    
990            /**
991             * Returns the first message boards thread in the ordered set where groupId = &#63;.
992             *
993             * @param groupId the group ID
994             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
995             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
996             * @throws SystemException if a system exception occurred
997             */
998            public MBThread fetchByGroupId_First(long groupId,
999                    OrderByComparator orderByComparator) throws SystemException {
1000                    List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1001    
1002                    if (!list.isEmpty()) {
1003                            return list.get(0);
1004                    }
1005    
1006                    return null;
1007            }
1008    
1009            /**
1010             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1011             *
1012             * @param groupId the group ID
1013             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1014             * @return the last matching message boards thread
1015             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1016             * @throws SystemException if a system exception occurred
1017             */
1018            public MBThread findByGroupId_Last(long groupId,
1019                    OrderByComparator orderByComparator)
1020                    throws NoSuchThreadException, SystemException {
1021                    MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
1022    
1023                    if (mbThread != null) {
1024                            return mbThread;
1025                    }
1026    
1027                    StringBundler msg = new StringBundler(4);
1028    
1029                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1030    
1031                    msg.append("groupId=");
1032                    msg.append(groupId);
1033    
1034                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1035    
1036                    throw new NoSuchThreadException(msg.toString());
1037            }
1038    
1039            /**
1040             * Returns the last message boards thread in the ordered set where groupId = &#63;.
1041             *
1042             * @param groupId the group ID
1043             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1044             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1045             * @throws SystemException if a system exception occurred
1046             */
1047            public MBThread fetchByGroupId_Last(long groupId,
1048                    OrderByComparator orderByComparator) throws SystemException {
1049                    int count = countByGroupId(groupId);
1050    
1051                    List<MBThread> list = findByGroupId(groupId, count - 1, count,
1052                                    orderByComparator);
1053    
1054                    if (!list.isEmpty()) {
1055                            return list.get(0);
1056                    }
1057    
1058                    return null;
1059            }
1060    
1061            /**
1062             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63;.
1063             *
1064             * @param threadId the primary key of the current message boards thread
1065             * @param groupId the group ID
1066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1067             * @return the previous, current, and next message boards thread
1068             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1069             * @throws SystemException if a system exception occurred
1070             */
1071            public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1072                    OrderByComparator orderByComparator)
1073                    throws NoSuchThreadException, SystemException {
1074                    MBThread mbThread = findByPrimaryKey(threadId);
1075    
1076                    Session session = null;
1077    
1078                    try {
1079                            session = openSession();
1080    
1081                            MBThread[] array = new MBThreadImpl[3];
1082    
1083                            array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1084                                            orderByComparator, true);
1085    
1086                            array[1] = mbThread;
1087    
1088                            array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1089                                            orderByComparator, false);
1090    
1091                            return array;
1092                    }
1093                    catch (Exception e) {
1094                            throw processException(e);
1095                    }
1096                    finally {
1097                            closeSession(session);
1098                    }
1099            }
1100    
1101            protected MBThread getByGroupId_PrevAndNext(Session session,
1102                    MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1103                    boolean previous) {
1104                    StringBundler query = null;
1105    
1106                    if (orderByComparator != null) {
1107                            query = new StringBundler(6 +
1108                                            (orderByComparator.getOrderByFields().length * 6));
1109                    }
1110                    else {
1111                            query = new StringBundler(3);
1112                    }
1113    
1114                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1115    
1116                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1117    
1118                    if (orderByComparator != null) {
1119                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1120    
1121                            if (orderByConditionFields.length > 0) {
1122                                    query.append(WHERE_AND);
1123                            }
1124    
1125                            for (int i = 0; i < orderByConditionFields.length; i++) {
1126                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1127                                    query.append(orderByConditionFields[i]);
1128    
1129                                    if ((i + 1) < orderByConditionFields.length) {
1130                                            if (orderByComparator.isAscending() ^ previous) {
1131                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1132                                            }
1133                                            else {
1134                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1135                                            }
1136                                    }
1137                                    else {
1138                                            if (orderByComparator.isAscending() ^ previous) {
1139                                                    query.append(WHERE_GREATER_THAN);
1140                                            }
1141                                            else {
1142                                                    query.append(WHERE_LESSER_THAN);
1143                                            }
1144                                    }
1145                            }
1146    
1147                            query.append(ORDER_BY_CLAUSE);
1148    
1149                            String[] orderByFields = orderByComparator.getOrderByFields();
1150    
1151                            for (int i = 0; i < orderByFields.length; i++) {
1152                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1153                                    query.append(orderByFields[i]);
1154    
1155                                    if ((i + 1) < orderByFields.length) {
1156                                            if (orderByComparator.isAscending() ^ previous) {
1157                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1158                                            }
1159                                            else {
1160                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1161                                            }
1162                                    }
1163                                    else {
1164                                            if (orderByComparator.isAscending() ^ previous) {
1165                                                    query.append(ORDER_BY_ASC);
1166                                            }
1167                                            else {
1168                                                    query.append(ORDER_BY_DESC);
1169                                            }
1170                                    }
1171                            }
1172                    }
1173    
1174                    else {
1175                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1176                    }
1177    
1178                    String sql = query.toString();
1179    
1180                    Query q = session.createQuery(sql);
1181    
1182                    q.setFirstResult(0);
1183                    q.setMaxResults(2);
1184    
1185                    QueryPos qPos = QueryPos.getInstance(q);
1186    
1187                    qPos.add(groupId);
1188    
1189                    if (orderByComparator != null) {
1190                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1191    
1192                            for (Object value : values) {
1193                                    qPos.add(value);
1194                            }
1195                    }
1196    
1197                    List<MBThread> list = q.list();
1198    
1199                    if (list.size() == 2) {
1200                            return list.get(1);
1201                    }
1202                    else {
1203                            return null;
1204                    }
1205            }
1206    
1207            /**
1208             * Returns all the message boards threads that the user has permission to view where groupId = &#63;.
1209             *
1210             * @param groupId the group ID
1211             * @return the matching message boards threads that the user has permission to view
1212             * @throws SystemException if a system exception occurred
1213             */
1214            public List<MBThread> filterFindByGroupId(long groupId)
1215                    throws SystemException {
1216                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1217                            QueryUtil.ALL_POS, null);
1218            }
1219    
1220            /**
1221             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63;.
1222             *
1223             * <p>
1224             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1225             * </p>
1226             *
1227             * @param groupId the group ID
1228             * @param start the lower bound of the range of message boards threads
1229             * @param end the upper bound of the range of message boards threads (not inclusive)
1230             * @return the range of matching message boards threads that the user has permission to view
1231             * @throws SystemException if a system exception occurred
1232             */
1233            public List<MBThread> filterFindByGroupId(long groupId, int start, int end)
1234                    throws SystemException {
1235                    return filterFindByGroupId(groupId, start, end, null);
1236            }
1237    
1238            /**
1239             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63;.
1240             *
1241             * <p>
1242             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1243             * </p>
1244             *
1245             * @param groupId the group ID
1246             * @param start the lower bound of the range of message boards threads
1247             * @param end the upper bound of the range of message boards threads (not inclusive)
1248             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1249             * @return the ordered range of matching message boards threads that the user has permission to view
1250             * @throws SystemException if a system exception occurred
1251             */
1252            public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1253                    OrderByComparator orderByComparator) throws SystemException {
1254                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1255                            return findByGroupId(groupId, start, end, orderByComparator);
1256                    }
1257    
1258                    StringBundler query = null;
1259    
1260                    if (orderByComparator != null) {
1261                            query = new StringBundler(3 +
1262                                            (orderByComparator.getOrderByFields().length * 3));
1263                    }
1264                    else {
1265                            query = new StringBundler(3);
1266                    }
1267    
1268                    if (getDB().isSupportsInlineDistinct()) {
1269                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1270                    }
1271                    else {
1272                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1273                    }
1274    
1275                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1276    
1277                    if (!getDB().isSupportsInlineDistinct()) {
1278                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1279                    }
1280    
1281                    if (orderByComparator != null) {
1282                            if (getDB().isSupportsInlineDistinct()) {
1283                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1284                                            orderByComparator);
1285                            }
1286                            else {
1287                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1288                                            orderByComparator);
1289                            }
1290                    }
1291    
1292                    else {
1293                            if (getDB().isSupportsInlineDistinct()) {
1294                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1295                            }
1296                            else {
1297                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
1298                            }
1299                    }
1300    
1301                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1302                                    MBThread.class.getName(),
1303                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1304    
1305                    Session session = null;
1306    
1307                    try {
1308                            session = openSession();
1309    
1310                            SQLQuery q = session.createSQLQuery(sql);
1311    
1312                            if (getDB().isSupportsInlineDistinct()) {
1313                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1314                            }
1315                            else {
1316                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1317                            }
1318    
1319                            QueryPos qPos = QueryPos.getInstance(q);
1320    
1321                            qPos.add(groupId);
1322    
1323                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1324                    }
1325                    catch (Exception e) {
1326                            throw processException(e);
1327                    }
1328                    finally {
1329                            closeSession(session);
1330                    }
1331            }
1332    
1333            /**
1334             * 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;.
1335             *
1336             * @param threadId the primary key of the current message boards thread
1337             * @param groupId the group ID
1338             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1339             * @return the previous, current, and next message boards thread
1340             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1341             * @throws SystemException if a system exception occurred
1342             */
1343            public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
1344                    long groupId, OrderByComparator orderByComparator)
1345                    throws NoSuchThreadException, SystemException {
1346                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1347                            return findByGroupId_PrevAndNext(threadId, groupId,
1348                                    orderByComparator);
1349                    }
1350    
1351                    MBThread mbThread = findByPrimaryKey(threadId);
1352    
1353                    Session session = null;
1354    
1355                    try {
1356                            session = openSession();
1357    
1358                            MBThread[] array = new MBThreadImpl[3];
1359    
1360                            array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
1361                                            groupId, orderByComparator, true);
1362    
1363                            array[1] = mbThread;
1364    
1365                            array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
1366                                            groupId, orderByComparator, false);
1367    
1368                            return array;
1369                    }
1370                    catch (Exception e) {
1371                            throw processException(e);
1372                    }
1373                    finally {
1374                            closeSession(session);
1375                    }
1376            }
1377    
1378            protected MBThread filterGetByGroupId_PrevAndNext(Session session,
1379                    MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1380                    boolean previous) {
1381                    StringBundler query = null;
1382    
1383                    if (orderByComparator != null) {
1384                            query = new StringBundler(6 +
1385                                            (orderByComparator.getOrderByFields().length * 6));
1386                    }
1387                    else {
1388                            query = new StringBundler(3);
1389                    }
1390    
1391                    if (getDB().isSupportsInlineDistinct()) {
1392                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1393                    }
1394                    else {
1395                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1396                    }
1397    
1398                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1399    
1400                    if (!getDB().isSupportsInlineDistinct()) {
1401                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1402                    }
1403    
1404                    if (orderByComparator != null) {
1405                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1406    
1407                            if (orderByConditionFields.length > 0) {
1408                                    query.append(WHERE_AND);
1409                            }
1410    
1411                            for (int i = 0; i < orderByConditionFields.length; i++) {
1412                                    if (getDB().isSupportsInlineDistinct()) {
1413                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1414                                    }
1415                                    else {
1416                                            query.append(_ORDER_BY_ENTITY_TABLE);
1417                                    }
1418    
1419                                    query.append(orderByConditionFields[i]);
1420    
1421                                    if ((i + 1) < orderByConditionFields.length) {
1422                                            if (orderByComparator.isAscending() ^ previous) {
1423                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1424                                            }
1425                                            else {
1426                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1427                                            }
1428                                    }
1429                                    else {
1430                                            if (orderByComparator.isAscending() ^ previous) {
1431                                                    query.append(WHERE_GREATER_THAN);
1432                                            }
1433                                            else {
1434                                                    query.append(WHERE_LESSER_THAN);
1435                                            }
1436                                    }
1437                            }
1438    
1439                            query.append(ORDER_BY_CLAUSE);
1440    
1441                            String[] orderByFields = orderByComparator.getOrderByFields();
1442    
1443                            for (int i = 0; i < orderByFields.length; i++) {
1444                                    if (getDB().isSupportsInlineDistinct()) {
1445                                            query.append(_ORDER_BY_ENTITY_ALIAS);
1446                                    }
1447                                    else {
1448                                            query.append(_ORDER_BY_ENTITY_TABLE);
1449                                    }
1450    
1451                                    query.append(orderByFields[i]);
1452    
1453                                    if ((i + 1) < orderByFields.length) {
1454                                            if (orderByComparator.isAscending() ^ previous) {
1455                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1456                                            }
1457                                            else {
1458                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1459                                            }
1460                                    }
1461                                    else {
1462                                            if (orderByComparator.isAscending() ^ previous) {
1463                                                    query.append(ORDER_BY_ASC);
1464                                            }
1465                                            else {
1466                                                    query.append(ORDER_BY_DESC);
1467                                            }
1468                                    }
1469                            }
1470                    }
1471    
1472                    else {
1473                            if (getDB().isSupportsInlineDistinct()) {
1474                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1475                            }
1476                            else {
1477                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
1478                            }
1479                    }
1480    
1481                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1482                                    MBThread.class.getName(),
1483                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1484    
1485                    SQLQuery q = session.createSQLQuery(sql);
1486    
1487                    q.setFirstResult(0);
1488                    q.setMaxResults(2);
1489    
1490                    if (getDB().isSupportsInlineDistinct()) {
1491                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1492                    }
1493                    else {
1494                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1495                    }
1496    
1497                    QueryPos qPos = QueryPos.getInstance(q);
1498    
1499                    qPos.add(groupId);
1500    
1501                    if (orderByComparator != null) {
1502                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1503    
1504                            for (Object value : values) {
1505                                    qPos.add(value);
1506                            }
1507                    }
1508    
1509                    List<MBThread> list = q.list();
1510    
1511                    if (list.size() == 2) {
1512                            return list.get(1);
1513                    }
1514                    else {
1515                            return null;
1516                    }
1517            }
1518    
1519            /**
1520             * Returns the message boards thread where rootMessageId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
1521             *
1522             * @param rootMessageId the root message ID
1523             * @return the matching message boards thread
1524             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1525             * @throws SystemException if a system exception occurred
1526             */
1527            public MBThread findByRootMessageId(long rootMessageId)
1528                    throws NoSuchThreadException, SystemException {
1529                    MBThread mbThread = fetchByRootMessageId(rootMessageId);
1530    
1531                    if (mbThread == null) {
1532                            StringBundler msg = new StringBundler(4);
1533    
1534                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1535    
1536                            msg.append("rootMessageId=");
1537                            msg.append(rootMessageId);
1538    
1539                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1540    
1541                            if (_log.isWarnEnabled()) {
1542                                    _log.warn(msg.toString());
1543                            }
1544    
1545                            throw new NoSuchThreadException(msg.toString());
1546                    }
1547    
1548                    return mbThread;
1549            }
1550    
1551            /**
1552             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1553             *
1554             * @param rootMessageId the root message ID
1555             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1556             * @throws SystemException if a system exception occurred
1557             */
1558            public MBThread fetchByRootMessageId(long rootMessageId)
1559                    throws SystemException {
1560                    return fetchByRootMessageId(rootMessageId, true);
1561            }
1562    
1563            /**
1564             * Returns the message boards thread where rootMessageId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1565             *
1566             * @param rootMessageId the root message ID
1567             * @param retrieveFromCache whether to use the finder cache
1568             * @return the matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1569             * @throws SystemException if a system exception occurred
1570             */
1571            public MBThread fetchByRootMessageId(long rootMessageId,
1572                    boolean retrieveFromCache) throws SystemException {
1573                    Object[] finderArgs = new Object[] { rootMessageId };
1574    
1575                    Object result = null;
1576    
1577                    if (retrieveFromCache) {
1578                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1579                                            finderArgs, this);
1580                    }
1581    
1582                    if (result instanceof MBThread) {
1583                            MBThread mbThread = (MBThread)result;
1584    
1585                            if ((rootMessageId != mbThread.getRootMessageId())) {
1586                                    result = null;
1587                            }
1588                    }
1589    
1590                    if (result == null) {
1591                            StringBundler query = new StringBundler(3);
1592    
1593                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1594    
1595                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
1596    
1597                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1598    
1599                            String sql = query.toString();
1600    
1601                            Session session = null;
1602    
1603                            try {
1604                                    session = openSession();
1605    
1606                                    Query q = session.createQuery(sql);
1607    
1608                                    QueryPos qPos = QueryPos.getInstance(q);
1609    
1610                                    qPos.add(rootMessageId);
1611    
1612                                    List<MBThread> list = q.list();
1613    
1614                                    result = list;
1615    
1616                                    MBThread mbThread = null;
1617    
1618                                    if (list.isEmpty()) {
1619                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1620                                                    finderArgs, list);
1621                                    }
1622                                    else {
1623                                            mbThread = list.get(0);
1624    
1625                                            cacheResult(mbThread);
1626    
1627                                            if ((mbThread.getRootMessageId() != rootMessageId)) {
1628                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1629                                                            finderArgs, mbThread);
1630                                            }
1631                                    }
1632    
1633                                    return mbThread;
1634                            }
1635                            catch (Exception e) {
1636                                    throw processException(e);
1637                            }
1638                            finally {
1639                                    if (result == null) {
1640                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1641                                                    finderArgs);
1642                                    }
1643    
1644                                    closeSession(session);
1645                            }
1646                    }
1647                    else {
1648                            if (result instanceof List<?>) {
1649                                    return null;
1650                            }
1651                            else {
1652                                    return (MBThread)result;
1653                            }
1654                    }
1655            }
1656    
1657            /**
1658             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63;.
1659             *
1660             * @param groupId the group ID
1661             * @param categoryId the category ID
1662             * @return the matching message boards threads
1663             * @throws SystemException if a system exception occurred
1664             */
1665            public List<MBThread> findByG_C(long groupId, long categoryId)
1666                    throws SystemException {
1667                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
1668                            QueryUtil.ALL_POS, null);
1669            }
1670    
1671            /**
1672             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
1673             *
1674             * <p>
1675             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1676             * </p>
1677             *
1678             * @param groupId the group ID
1679             * @param categoryId the category ID
1680             * @param start the lower bound of the range of message boards threads
1681             * @param end the upper bound of the range of message boards threads (not inclusive)
1682             * @return the range of matching message boards threads
1683             * @throws SystemException if a system exception occurred
1684             */
1685            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1686                    int end) throws SystemException {
1687                    return findByG_C(groupId, categoryId, start, end, null);
1688            }
1689    
1690            /**
1691             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
1692             *
1693             * <p>
1694             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1695             * </p>
1696             *
1697             * @param groupId the group ID
1698             * @param categoryId the category ID
1699             * @param start the lower bound of the range of message boards threads
1700             * @param end the upper bound of the range of message boards threads (not inclusive)
1701             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1702             * @return the ordered range of matching message boards threads
1703             * @throws SystemException if a system exception occurred
1704             */
1705            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1706                    int end, OrderByComparator orderByComparator) throws SystemException {
1707                    FinderPath finderPath = null;
1708                    Object[] finderArgs = null;
1709    
1710                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1711                                    (orderByComparator == null)) {
1712                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
1713                            finderArgs = new Object[] { groupId, categoryId };
1714                    }
1715                    else {
1716                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
1717                            finderArgs = new Object[] {
1718                                            groupId, categoryId,
1719                                            
1720                                            start, end, orderByComparator
1721                                    };
1722                    }
1723    
1724                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1725                                    finderArgs, this);
1726    
1727                    if ((list != null) && !list.isEmpty()) {
1728                            for (MBThread mbThread : list) {
1729                                    if ((groupId != mbThread.getGroupId()) ||
1730                                                    (categoryId != mbThread.getCategoryId())) {
1731                                            list = null;
1732    
1733                                            break;
1734                                    }
1735                            }
1736                    }
1737    
1738                    if (list == null) {
1739                            StringBundler query = null;
1740    
1741                            if (orderByComparator != null) {
1742                                    query = new StringBundler(4 +
1743                                                    (orderByComparator.getOrderByFields().length * 3));
1744                            }
1745                            else {
1746                                    query = new StringBundler(4);
1747                            }
1748    
1749                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1750    
1751                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1752    
1753                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1754    
1755                            if (orderByComparator != null) {
1756                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1757                                            orderByComparator);
1758                            }
1759    
1760                            else {
1761                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1762                            }
1763    
1764                            String sql = query.toString();
1765    
1766                            Session session = null;
1767    
1768                            try {
1769                                    session = openSession();
1770    
1771                                    Query q = session.createQuery(sql);
1772    
1773                                    QueryPos qPos = QueryPos.getInstance(q);
1774    
1775                                    qPos.add(groupId);
1776    
1777                                    qPos.add(categoryId);
1778    
1779                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1780                                                    end);
1781                            }
1782                            catch (Exception e) {
1783                                    throw processException(e);
1784                            }
1785                            finally {
1786                                    if (list == null) {
1787                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1788                                    }
1789                                    else {
1790                                            cacheResult(list);
1791    
1792                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1793                                    }
1794    
1795                                    closeSession(session);
1796                            }
1797                    }
1798    
1799                    return list;
1800            }
1801    
1802            /**
1803             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
1804             *
1805             * @param groupId the group ID
1806             * @param categoryId the category ID
1807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1808             * @return the first matching message boards thread
1809             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1810             * @throws SystemException if a system exception occurred
1811             */
1812            public MBThread findByG_C_First(long groupId, long categoryId,
1813                    OrderByComparator orderByComparator)
1814                    throws NoSuchThreadException, SystemException {
1815                    MBThread mbThread = fetchByG_C_First(groupId, categoryId,
1816                                    orderByComparator);
1817    
1818                    if (mbThread != null) {
1819                            return mbThread;
1820                    }
1821    
1822                    StringBundler msg = new StringBundler(6);
1823    
1824                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1825    
1826                    msg.append("groupId=");
1827                    msg.append(groupId);
1828    
1829                    msg.append(", categoryId=");
1830                    msg.append(categoryId);
1831    
1832                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1833    
1834                    throw new NoSuchThreadException(msg.toString());
1835            }
1836    
1837            /**
1838             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
1839             *
1840             * @param groupId the group ID
1841             * @param categoryId the category ID
1842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1843             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1844             * @throws SystemException if a system exception occurred
1845             */
1846            public MBThread fetchByG_C_First(long groupId, long categoryId,
1847                    OrderByComparator orderByComparator) throws SystemException {
1848                    List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
1849                                    orderByComparator);
1850    
1851                    if (!list.isEmpty()) {
1852                            return list.get(0);
1853                    }
1854    
1855                    return null;
1856            }
1857    
1858            /**
1859             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
1860             *
1861             * @param groupId the group ID
1862             * @param categoryId the category ID
1863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1864             * @return the last matching message boards thread
1865             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1866             * @throws SystemException if a system exception occurred
1867             */
1868            public MBThread findByG_C_Last(long groupId, long categoryId,
1869                    OrderByComparator orderByComparator)
1870                    throws NoSuchThreadException, SystemException {
1871                    MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
1872                                    orderByComparator);
1873    
1874                    if (mbThread != null) {
1875                            return mbThread;
1876                    }
1877    
1878                    StringBundler msg = new StringBundler(6);
1879    
1880                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1881    
1882                    msg.append("groupId=");
1883                    msg.append(groupId);
1884    
1885                    msg.append(", categoryId=");
1886                    msg.append(categoryId);
1887    
1888                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1889    
1890                    throw new NoSuchThreadException(msg.toString());
1891            }
1892    
1893            /**
1894             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
1895             *
1896             * @param groupId the group ID
1897             * @param categoryId the category ID
1898             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1899             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
1900             * @throws SystemException if a system exception occurred
1901             */
1902            public MBThread fetchByG_C_Last(long groupId, long categoryId,
1903                    OrderByComparator orderByComparator) throws SystemException {
1904                    int count = countByG_C(groupId, categoryId);
1905    
1906                    List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
1907                                    orderByComparator);
1908    
1909                    if (!list.isEmpty()) {
1910                            return list.get(0);
1911                    }
1912    
1913                    return null;
1914            }
1915    
1916            /**
1917             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
1918             *
1919             * @param threadId the primary key of the current message boards thread
1920             * @param groupId the group ID
1921             * @param categoryId the category ID
1922             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1923             * @return the previous, current, and next message boards thread
1924             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1925             * @throws SystemException if a system exception occurred
1926             */
1927            public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
1928                    long categoryId, OrderByComparator orderByComparator)
1929                    throws NoSuchThreadException, SystemException {
1930                    MBThread mbThread = findByPrimaryKey(threadId);
1931    
1932                    Session session = null;
1933    
1934                    try {
1935                            session = openSession();
1936    
1937                            MBThread[] array = new MBThreadImpl[3];
1938    
1939                            array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
1940                                            categoryId, orderByComparator, true);
1941    
1942                            array[1] = mbThread;
1943    
1944                            array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
1945                                            categoryId, orderByComparator, false);
1946    
1947                            return array;
1948                    }
1949                    catch (Exception e) {
1950                            throw processException(e);
1951                    }
1952                    finally {
1953                            closeSession(session);
1954                    }
1955            }
1956    
1957            protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
1958                    long groupId, long categoryId, OrderByComparator orderByComparator,
1959                    boolean previous) {
1960                    StringBundler query = null;
1961    
1962                    if (orderByComparator != null) {
1963                            query = new StringBundler(6 +
1964                                            (orderByComparator.getOrderByFields().length * 6));
1965                    }
1966                    else {
1967                            query = new StringBundler(3);
1968                    }
1969    
1970                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1971    
1972                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1973    
1974                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1975    
1976                    if (orderByComparator != null) {
1977                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1978    
1979                            if (orderByConditionFields.length > 0) {
1980                                    query.append(WHERE_AND);
1981                            }
1982    
1983                            for (int i = 0; i < orderByConditionFields.length; i++) {
1984                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1985                                    query.append(orderByConditionFields[i]);
1986    
1987                                    if ((i + 1) < orderByConditionFields.length) {
1988                                            if (orderByComparator.isAscending() ^ previous) {
1989                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1990                                            }
1991                                            else {
1992                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1993                                            }
1994                                    }
1995                                    else {
1996                                            if (orderByComparator.isAscending() ^ previous) {
1997                                                    query.append(WHERE_GREATER_THAN);
1998                                            }
1999                                            else {
2000                                                    query.append(WHERE_LESSER_THAN);
2001                                            }
2002                                    }
2003                            }
2004    
2005                            query.append(ORDER_BY_CLAUSE);
2006    
2007                            String[] orderByFields = orderByComparator.getOrderByFields();
2008    
2009                            for (int i = 0; i < orderByFields.length; i++) {
2010                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2011                                    query.append(orderByFields[i]);
2012    
2013                                    if ((i + 1) < orderByFields.length) {
2014                                            if (orderByComparator.isAscending() ^ previous) {
2015                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2016                                            }
2017                                            else {
2018                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2019                                            }
2020                                    }
2021                                    else {
2022                                            if (orderByComparator.isAscending() ^ previous) {
2023                                                    query.append(ORDER_BY_ASC);
2024                                            }
2025                                            else {
2026                                                    query.append(ORDER_BY_DESC);
2027                                            }
2028                                    }
2029                            }
2030                    }
2031    
2032                    else {
2033                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2034                    }
2035    
2036                    String sql = query.toString();
2037    
2038                    Query q = session.createQuery(sql);
2039    
2040                    q.setFirstResult(0);
2041                    q.setMaxResults(2);
2042    
2043                    QueryPos qPos = QueryPos.getInstance(q);
2044    
2045                    qPos.add(groupId);
2046    
2047                    qPos.add(categoryId);
2048    
2049                    if (orderByComparator != null) {
2050                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2051    
2052                            for (Object value : values) {
2053                                    qPos.add(value);
2054                            }
2055                    }
2056    
2057                    List<MBThread> list = q.list();
2058    
2059                    if (list.size() == 2) {
2060                            return list.get(1);
2061                    }
2062                    else {
2063                            return null;
2064                    }
2065            }
2066    
2067            /**
2068             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63;.
2069             *
2070             * <p>
2071             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2072             * </p>
2073             *
2074             * @param groupId the group ID
2075             * @param categoryIds the category IDs
2076             * @return the matching message boards threads
2077             * @throws SystemException if a system exception occurred
2078             */
2079            public List<MBThread> findByG_C(long groupId, long[] categoryIds)
2080                    throws SystemException {
2081                    return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2082                            QueryUtil.ALL_POS, null);
2083            }
2084    
2085            /**
2086             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
2087             *
2088             * <p>
2089             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2090             * </p>
2091             *
2092             * @param groupId the group ID
2093             * @param categoryIds the category IDs
2094             * @param start the lower bound of the range of message boards threads
2095             * @param end the upper bound of the range of message boards threads (not inclusive)
2096             * @return the range of matching message boards threads
2097             * @throws SystemException if a system exception occurred
2098             */
2099            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2100                    int start, int end) throws SystemException {
2101                    return findByG_C(groupId, categoryIds, start, end, null);
2102            }
2103    
2104            /**
2105             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
2106             *
2107             * <p>
2108             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2109             * </p>
2110             *
2111             * @param groupId the group ID
2112             * @param categoryIds the category IDs
2113             * @param start the lower bound of the range of message boards threads
2114             * @param end the upper bound of the range of message boards threads (not inclusive)
2115             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2116             * @return the ordered range of matching message boards threads
2117             * @throws SystemException if a system exception occurred
2118             */
2119            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2120                    int start, int end, OrderByComparator orderByComparator)
2121                    throws SystemException {
2122                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2123                    Object[] finderArgs = null;
2124    
2125                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2126                                    (orderByComparator == null)) {
2127                            finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
2128                    }
2129                    else {
2130                            finderArgs = new Object[] {
2131                                            groupId, StringUtil.merge(categoryIds),
2132                                            
2133                                            start, end, orderByComparator
2134                                    };
2135                    }
2136    
2137                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2138                                    finderArgs, this);
2139    
2140                    if ((list != null) && !list.isEmpty()) {
2141                            for (MBThread mbThread : list) {
2142                                    if ((groupId != mbThread.getGroupId()) ||
2143                                                    !ArrayUtil.contains(categoryIds,
2144                                                            mbThread.getCategoryId())) {
2145                                            list = null;
2146    
2147                                            break;
2148                                    }
2149                            }
2150                    }
2151    
2152                    if (list == null) {
2153                            StringBundler query = new StringBundler();
2154    
2155                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2156    
2157                            boolean conjunctionable = false;
2158    
2159                            if (conjunctionable) {
2160                                    query.append(WHERE_AND);
2161                            }
2162    
2163                            query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2164    
2165                            conjunctionable = true;
2166    
2167                            if ((categoryIds == null) || (categoryIds.length > 0)) {
2168                                    if (conjunctionable) {
2169                                            query.append(WHERE_AND);
2170                                    }
2171    
2172                                    query.append(StringPool.OPEN_PARENTHESIS);
2173    
2174                                    for (int i = 0; i < categoryIds.length; i++) {
2175                                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2176    
2177                                            if ((i + 1) < categoryIds.length) {
2178                                                    query.append(WHERE_OR);
2179                                            }
2180                                    }
2181    
2182                                    query.append(StringPool.CLOSE_PARENTHESIS);
2183    
2184                                    conjunctionable = true;
2185                            }
2186    
2187                            if (orderByComparator != null) {
2188                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2189                                            orderByComparator);
2190                            }
2191    
2192                            else {
2193                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2194                            }
2195    
2196                            String sql = query.toString();
2197    
2198                            Session session = null;
2199    
2200                            try {
2201                                    session = openSession();
2202    
2203                                    Query q = session.createQuery(sql);
2204    
2205                                    QueryPos qPos = QueryPos.getInstance(q);
2206    
2207                                    qPos.add(groupId);
2208    
2209                                    if (categoryIds != null) {
2210                                            qPos.add(categoryIds);
2211                                    }
2212    
2213                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2214                                                    end);
2215                            }
2216                            catch (Exception e) {
2217                                    throw processException(e);
2218                            }
2219                            finally {
2220                                    if (list == null) {
2221                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2222                                    }
2223                                    else {
2224                                            cacheResult(list);
2225    
2226                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2227                                    }
2228    
2229                                    closeSession(session);
2230                            }
2231                    }
2232    
2233                    return list;
2234            }
2235    
2236            /**
2237             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
2238             *
2239             * @param groupId the group ID
2240             * @param categoryId the category ID
2241             * @return the matching message boards threads that the user has permission to view
2242             * @throws SystemException if a system exception occurred
2243             */
2244            public List<MBThread> filterFindByG_C(long groupId, long categoryId)
2245                    throws SystemException {
2246                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2247                            QueryUtil.ALL_POS, null);
2248            }
2249    
2250            /**
2251             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
2252             *
2253             * <p>
2254             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2255             * </p>
2256             *
2257             * @param groupId the group ID
2258             * @param categoryId the category ID
2259             * @param start the lower bound of the range of message boards threads
2260             * @param end the upper bound of the range of message boards threads (not inclusive)
2261             * @return the range of matching message boards threads that the user has permission to view
2262             * @throws SystemException if a system exception occurred
2263             */
2264            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2265                    int start, int end) throws SystemException {
2266                    return filterFindByG_C(groupId, categoryId, start, end, null);
2267            }
2268    
2269            /**
2270             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
2271             *
2272             * <p>
2273             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2274             * </p>
2275             *
2276             * @param groupId the group ID
2277             * @param categoryId the category ID
2278             * @param start the lower bound of the range of message boards threads
2279             * @param end the upper bound of the range of message boards threads (not inclusive)
2280             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2281             * @return the ordered range of matching message boards threads that the user has permission to view
2282             * @throws SystemException if a system exception occurred
2283             */
2284            public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2285                    int start, int end, OrderByComparator orderByComparator)
2286                    throws SystemException {
2287                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2288                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
2289                    }
2290    
2291                    StringBundler query = null;
2292    
2293                    if (orderByComparator != null) {
2294                            query = new StringBundler(4 +
2295                                            (orderByComparator.getOrderByFields().length * 3));
2296                    }
2297                    else {
2298                            query = new StringBundler(4);
2299                    }
2300    
2301                    if (getDB().isSupportsInlineDistinct()) {
2302                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2303                    }
2304                    else {
2305                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2306                    }
2307    
2308                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2309    
2310                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2311    
2312                    if (!getDB().isSupportsInlineDistinct()) {
2313                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2314                    }
2315    
2316                    if (orderByComparator != null) {
2317                            if (getDB().isSupportsInlineDistinct()) {
2318                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2319                                            orderByComparator);
2320                            }
2321                            else {
2322                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2323                                            orderByComparator);
2324                            }
2325                    }
2326    
2327                    else {
2328                            if (getDB().isSupportsInlineDistinct()) {
2329                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2330                            }
2331                            else {
2332                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2333                            }
2334                    }
2335    
2336                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2337                                    MBThread.class.getName(),
2338                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2339    
2340                    Session session = null;
2341    
2342                    try {
2343                            session = openSession();
2344    
2345                            SQLQuery q = session.createSQLQuery(sql);
2346    
2347                            if (getDB().isSupportsInlineDistinct()) {
2348                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2349                            }
2350                            else {
2351                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2352                            }
2353    
2354                            QueryPos qPos = QueryPos.getInstance(q);
2355    
2356                            qPos.add(groupId);
2357    
2358                            qPos.add(categoryId);
2359    
2360                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2361                    }
2362                    catch (Exception e) {
2363                            throw processException(e);
2364                    }
2365                    finally {
2366                            closeSession(session);
2367                    }
2368            }
2369    
2370            /**
2371             * 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;.
2372             *
2373             * @param threadId the primary key of the current message boards thread
2374             * @param groupId the group ID
2375             * @param categoryId the category ID
2376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2377             * @return the previous, current, and next message boards thread
2378             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
2379             * @throws SystemException if a system exception occurred
2380             */
2381            public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
2382                    long categoryId, OrderByComparator orderByComparator)
2383                    throws NoSuchThreadException, SystemException {
2384                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2385                            return findByG_C_PrevAndNext(threadId, groupId, categoryId,
2386                                    orderByComparator);
2387                    }
2388    
2389                    MBThread mbThread = findByPrimaryKey(threadId);
2390    
2391                    Session session = null;
2392    
2393                    try {
2394                            session = openSession();
2395    
2396                            MBThread[] array = new MBThreadImpl[3];
2397    
2398                            array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
2399                                            categoryId, orderByComparator, true);
2400    
2401                            array[1] = mbThread;
2402    
2403                            array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
2404                                            categoryId, orderByComparator, false);
2405    
2406                            return array;
2407                    }
2408                    catch (Exception e) {
2409                            throw processException(e);
2410                    }
2411                    finally {
2412                            closeSession(session);
2413                    }
2414            }
2415    
2416            protected MBThread filterGetByG_C_PrevAndNext(Session session,
2417                    MBThread mbThread, long groupId, long categoryId,
2418                    OrderByComparator orderByComparator, boolean previous) {
2419                    StringBundler query = null;
2420    
2421                    if (orderByComparator != null) {
2422                            query = new StringBundler(6 +
2423                                            (orderByComparator.getOrderByFields().length * 6));
2424                    }
2425                    else {
2426                            query = new StringBundler(3);
2427                    }
2428    
2429                    if (getDB().isSupportsInlineDistinct()) {
2430                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2431                    }
2432                    else {
2433                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2434                    }
2435    
2436                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2437    
2438                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2439    
2440                    if (!getDB().isSupportsInlineDistinct()) {
2441                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2442                    }
2443    
2444                    if (orderByComparator != null) {
2445                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2446    
2447                            if (orderByConditionFields.length > 0) {
2448                                    query.append(WHERE_AND);
2449                            }
2450    
2451                            for (int i = 0; i < orderByConditionFields.length; i++) {
2452                                    if (getDB().isSupportsInlineDistinct()) {
2453                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2454                                    }
2455                                    else {
2456                                            query.append(_ORDER_BY_ENTITY_TABLE);
2457                                    }
2458    
2459                                    query.append(orderByConditionFields[i]);
2460    
2461                                    if ((i + 1) < orderByConditionFields.length) {
2462                                            if (orderByComparator.isAscending() ^ previous) {
2463                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2464                                            }
2465                                            else {
2466                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2467                                            }
2468                                    }
2469                                    else {
2470                                            if (orderByComparator.isAscending() ^ previous) {
2471                                                    query.append(WHERE_GREATER_THAN);
2472                                            }
2473                                            else {
2474                                                    query.append(WHERE_LESSER_THAN);
2475                                            }
2476                                    }
2477                            }
2478    
2479                            query.append(ORDER_BY_CLAUSE);
2480    
2481                            String[] orderByFields = orderByComparator.getOrderByFields();
2482    
2483                            for (int i = 0; i < orderByFields.length; i++) {
2484                                    if (getDB().isSupportsInlineDistinct()) {
2485                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2486                                    }
2487                                    else {
2488                                            query.append(_ORDER_BY_ENTITY_TABLE);
2489                                    }
2490    
2491                                    query.append(orderByFields[i]);
2492    
2493                                    if ((i + 1) < orderByFields.length) {
2494                                            if (orderByComparator.isAscending() ^ previous) {
2495                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2496                                            }
2497                                            else {
2498                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2499                                            }
2500                                    }
2501                                    else {
2502                                            if (orderByComparator.isAscending() ^ previous) {
2503                                                    query.append(ORDER_BY_ASC);
2504                                            }
2505                                            else {
2506                                                    query.append(ORDER_BY_DESC);
2507                                            }
2508                                    }
2509                            }
2510                    }
2511    
2512                    else {
2513                            if (getDB().isSupportsInlineDistinct()) {
2514                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2515                            }
2516                            else {
2517                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2518                            }
2519                    }
2520    
2521                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2522                                    MBThread.class.getName(),
2523                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2524    
2525                    SQLQuery q = session.createSQLQuery(sql);
2526    
2527                    q.setFirstResult(0);
2528                    q.setMaxResults(2);
2529    
2530                    if (getDB().isSupportsInlineDistinct()) {
2531                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2532                    }
2533                    else {
2534                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2535                    }
2536    
2537                    QueryPos qPos = QueryPos.getInstance(q);
2538    
2539                    qPos.add(groupId);
2540    
2541                    qPos.add(categoryId);
2542    
2543                    if (orderByComparator != null) {
2544                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2545    
2546                            for (Object value : values) {
2547                                    qPos.add(value);
2548                            }
2549                    }
2550    
2551                    List<MBThread> list = q.list();
2552    
2553                    if (list.size() == 2) {
2554                            return list.get(1);
2555                    }
2556                    else {
2557                            return null;
2558                    }
2559            }
2560    
2561            /**
2562             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
2563             *
2564             * @param groupId the group ID
2565             * @param categoryIds the category IDs
2566             * @return the matching message boards threads that the user has permission to view
2567             * @throws SystemException if a system exception occurred
2568             */
2569            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds)
2570                    throws SystemException {
2571                    return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2572                            QueryUtil.ALL_POS, null);
2573            }
2574    
2575            /**
2576             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
2577             *
2578             * <p>
2579             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2580             * </p>
2581             *
2582             * @param groupId the group ID
2583             * @param categoryIds the category IDs
2584             * @param start the lower bound of the range of message boards threads
2585             * @param end the upper bound of the range of message boards threads (not inclusive)
2586             * @return the range of matching message boards threads that the user has permission to view
2587             * @throws SystemException if a system exception occurred
2588             */
2589            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
2590                    int start, int end) throws SystemException {
2591                    return filterFindByG_C(groupId, categoryIds, start, end, null);
2592            }
2593    
2594            /**
2595             * Returns an ordered range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
2596             *
2597             * <p>
2598             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2599             * </p>
2600             *
2601             * @param groupId the group ID
2602             * @param categoryIds the category IDs
2603             * @param start the lower bound of the range of message boards threads
2604             * @param end the upper bound of the range of message boards threads (not inclusive)
2605             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2606             * @return the ordered range of matching message boards threads that the user has permission to view
2607             * @throws SystemException if a system exception occurred
2608             */
2609            public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
2610                    int start, int end, OrderByComparator orderByComparator)
2611                    throws SystemException {
2612                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2613                            return findByG_C(groupId, categoryIds, start, end, orderByComparator);
2614                    }
2615    
2616                    StringBundler query = new StringBundler();
2617    
2618                    if (getDB().isSupportsInlineDistinct()) {
2619                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2620                    }
2621                    else {
2622                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2623                    }
2624    
2625                    boolean conjunctionable = false;
2626    
2627                    if (conjunctionable) {
2628                            query.append(WHERE_AND);
2629                    }
2630    
2631                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2632    
2633                    conjunctionable = true;
2634    
2635                    if ((categoryIds == null) || (categoryIds.length > 0)) {
2636                            if (conjunctionable) {
2637                                    query.append(WHERE_AND);
2638                            }
2639    
2640                            query.append(StringPool.OPEN_PARENTHESIS);
2641    
2642                            for (int i = 0; i < categoryIds.length; i++) {
2643                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2644    
2645                                    if ((i + 1) < categoryIds.length) {
2646                                            query.append(WHERE_OR);
2647                                    }
2648                            }
2649    
2650                            query.append(StringPool.CLOSE_PARENTHESIS);
2651    
2652                            conjunctionable = true;
2653                    }
2654    
2655                    if (!getDB().isSupportsInlineDistinct()) {
2656                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2657                    }
2658    
2659                    if (orderByComparator != null) {
2660                            if (getDB().isSupportsInlineDistinct()) {
2661                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2662                                            orderByComparator);
2663                            }
2664                            else {
2665                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2666                                            orderByComparator);
2667                            }
2668                    }
2669    
2670                    else {
2671                            if (getDB().isSupportsInlineDistinct()) {
2672                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2673                            }
2674                            else {
2675                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
2676                            }
2677                    }
2678    
2679                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2680                                    MBThread.class.getName(),
2681                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2682    
2683                    Session session = null;
2684    
2685                    try {
2686                            session = openSession();
2687    
2688                            SQLQuery q = session.createSQLQuery(sql);
2689    
2690                            if (getDB().isSupportsInlineDistinct()) {
2691                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2692                            }
2693                            else {
2694                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2695                            }
2696    
2697                            QueryPos qPos = QueryPos.getInstance(q);
2698    
2699                            qPos.add(groupId);
2700    
2701                            if (categoryIds != null) {
2702                                    qPos.add(categoryIds);
2703                            }
2704    
2705                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2706                    }
2707                    catch (Exception e) {
2708                            throw processException(e);
2709                    }
2710                    finally {
2711                            closeSession(session);
2712                    }
2713            }
2714    
2715            /**
2716             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
2717             *
2718             * @param groupId the group ID
2719             * @param categoryId the category ID
2720             * @return the matching message boards threads
2721             * @throws SystemException if a system exception occurred
2722             */
2723            public List<MBThread> findByG_NotC(long groupId, long categoryId)
2724                    throws SystemException {
2725                    return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
2726                            QueryUtil.ALL_POS, null);
2727            }
2728    
2729            /**
2730             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
2731             *
2732             * <p>
2733             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2734             * </p>
2735             *
2736             * @param groupId the group ID
2737             * @param categoryId the category ID
2738             * @param start the lower bound of the range of message boards threads
2739             * @param end the upper bound of the range of message boards threads (not inclusive)
2740             * @return the range of matching message boards threads
2741             * @throws SystemException if a system exception occurred
2742             */
2743            public List<MBThread> findByG_NotC(long groupId, long categoryId,
2744                    int start, int end) throws SystemException {
2745                    return findByG_NotC(groupId, categoryId, start, end, null);
2746            }
2747    
2748            /**
2749             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
2750             *
2751             * <p>
2752             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2753             * </p>
2754             *
2755             * @param groupId the group ID
2756             * @param categoryId the category ID
2757             * @param start the lower bound of the range of message boards threads
2758             * @param end the upper bound of the range of message boards threads (not inclusive)
2759             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2760             * @return the ordered range of matching message boards threads
2761             * @throws SystemException if a system exception occurred
2762             */
2763            public List<MBThread> findByG_NotC(long groupId, long categoryId,
2764                    int start, int end, OrderByComparator orderByComparator)
2765                    throws SystemException {
2766                    FinderPath finderPath = null;
2767                    Object[] finderArgs = null;
2768    
2769                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
2770                    finderArgs = new Object[] {
2771                                    groupId, categoryId,
2772                                    
2773                                    start, end, orderByComparator
2774                            };
2775    
2776                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2777                                    finderArgs, this);
2778    
2779                    if ((list != null) && !list.isEmpty()) {
2780                            for (MBThread mbThread : list) {
2781                                    if ((groupId != mbThread.getGroupId()) ||
2782                                                    (categoryId != mbThread.getCategoryId())) {
2783                                            list = null;
2784    
2785                                            break;
2786                                    }
2787                            }
2788                    }
2789    
2790                    if (list == null) {
2791                            StringBundler query = null;
2792    
2793                            if (orderByComparator != null) {
2794                                    query = new StringBundler(4 +
2795                                                    (orderByComparator.getOrderByFields().length * 3));
2796                            }
2797                            else {
2798                                    query = new StringBundler(4);
2799                            }
2800    
2801                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
2802    
2803                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
2804    
2805                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
2806    
2807                            if (orderByComparator != null) {
2808                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2809                                            orderByComparator);
2810                            }
2811    
2812                            else {
2813                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2814                            }
2815    
2816                            String sql = query.toString();
2817    
2818                            Session session = null;
2819    
2820                            try {
2821                                    session = openSession();
2822    
2823                                    Query q = session.createQuery(sql);
2824    
2825                                    QueryPos qPos = QueryPos.getInstance(q);
2826    
2827                                    qPos.add(groupId);
2828    
2829                                    qPos.add(categoryId);
2830    
2831                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2832                                                    end);
2833                            }
2834                            catch (Exception e) {
2835                                    throw processException(e);
2836                            }
2837                            finally {
2838                                    if (list == null) {
2839                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2840                                    }
2841                                    else {
2842                                            cacheResult(list);
2843    
2844                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2845                                    }
2846    
2847                                    closeSession(session);
2848                            }
2849                    }
2850    
2851                    return list;
2852            }
2853    
2854            /**
2855             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#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 first matching message boards thread
2861             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2862             * @throws SystemException if a system exception occurred
2863             */
2864            public MBThread findByG_NotC_First(long groupId, long categoryId,
2865                    OrderByComparator orderByComparator)
2866                    throws NoSuchThreadException, SystemException {
2867                    MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
2868                                    orderByComparator);
2869    
2870                    if (mbThread != null) {
2871                            return mbThread;
2872                    }
2873    
2874                    StringBundler msg = new StringBundler(6);
2875    
2876                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2877    
2878                    msg.append("groupId=");
2879                    msg.append(groupId);
2880    
2881                    msg.append(", categoryId=");
2882                    msg.append(categoryId);
2883    
2884                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2885    
2886                    throw new NoSuchThreadException(msg.toString());
2887            }
2888    
2889            /**
2890             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
2891             *
2892             * @param groupId the group ID
2893             * @param categoryId the category ID
2894             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2895             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2896             * @throws SystemException if a system exception occurred
2897             */
2898            public MBThread fetchByG_NotC_First(long groupId, long categoryId,
2899                    OrderByComparator orderByComparator) throws SystemException {
2900                    List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
2901                                    orderByComparator);
2902    
2903                    if (!list.isEmpty()) {
2904                            return list.get(0);
2905                    }
2906    
2907                    return null;
2908            }
2909    
2910            /**
2911             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
2912             *
2913             * @param groupId the group ID
2914             * @param categoryId the category ID
2915             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2916             * @return the last matching message boards thread
2917             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2918             * @throws SystemException if a system exception occurred
2919             */
2920            public MBThread findByG_NotC_Last(long groupId, long categoryId,
2921                    OrderByComparator orderByComparator)
2922                    throws NoSuchThreadException, SystemException {
2923                    MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
2924                                    orderByComparator);
2925    
2926                    if (mbThread != null) {
2927                            return mbThread;
2928                    }
2929    
2930                    StringBundler msg = new StringBundler(6);
2931    
2932                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2933    
2934                    msg.append("groupId=");
2935                    msg.append(groupId);
2936    
2937                    msg.append(", categoryId=");
2938                    msg.append(categoryId);
2939    
2940                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2941    
2942                    throw new NoSuchThreadException(msg.toString());
2943            }
2944    
2945            /**
2946             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
2947             *
2948             * @param groupId the group ID
2949             * @param categoryId the category ID
2950             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2951             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
2952             * @throws SystemException if a system exception occurred
2953             */
2954            public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
2955                    OrderByComparator orderByComparator) throws SystemException {
2956                    int count = countByG_NotC(groupId, categoryId);
2957    
2958                    List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
2959                                    count, orderByComparator);
2960    
2961                    if (!list.isEmpty()) {
2962                            return list.get(0);
2963                    }
2964    
2965                    return null;
2966            }
2967    
2968            /**
2969             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
2970             *
2971             * @param threadId the primary key of the current message boards thread
2972             * @param groupId the group ID
2973             * @param categoryId the category ID
2974             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2975             * @return the previous, current, and next message boards thread
2976             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
2977             * @throws SystemException if a system exception occurred
2978             */
2979            public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
2980                    long categoryId, OrderByComparator orderByComparator)
2981                    throws NoSuchThreadException, SystemException {
2982                    MBThread mbThread = findByPrimaryKey(threadId);
2983    
2984                    Session session = null;
2985    
2986                    try {
2987                            session = openSession();
2988    
2989                            MBThread[] array = new MBThreadImpl[3];
2990    
2991                            array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2992                                            categoryId, orderByComparator, true);
2993    
2994                            array[1] = mbThread;
2995    
2996                            array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2997                                            categoryId, orderByComparator, false);
2998    
2999                            return array;
3000                    }
3001                    catch (Exception e) {
3002                            throw processException(e);
3003                    }
3004                    finally {
3005                            closeSession(session);
3006                    }
3007            }
3008    
3009            protected MBThread getByG_NotC_PrevAndNext(Session session,
3010                    MBThread mbThread, long groupId, long categoryId,
3011                    OrderByComparator orderByComparator, boolean previous) {
3012                    StringBundler query = null;
3013    
3014                    if (orderByComparator != null) {
3015                            query = new StringBundler(6 +
3016                                            (orderByComparator.getOrderByFields().length * 6));
3017                    }
3018                    else {
3019                            query = new StringBundler(3);
3020                    }
3021    
3022                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
3023    
3024                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3025    
3026                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3027    
3028                    if (orderByComparator != null) {
3029                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3030    
3031                            if (orderByConditionFields.length > 0) {
3032                                    query.append(WHERE_AND);
3033                            }
3034    
3035                            for (int i = 0; i < orderByConditionFields.length; i++) {
3036                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3037                                    query.append(orderByConditionFields[i]);
3038    
3039                                    if ((i + 1) < orderByConditionFields.length) {
3040                                            if (orderByComparator.isAscending() ^ previous) {
3041                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3042                                            }
3043                                            else {
3044                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3045                                            }
3046                                    }
3047                                    else {
3048                                            if (orderByComparator.isAscending() ^ previous) {
3049                                                    query.append(WHERE_GREATER_THAN);
3050                                            }
3051                                            else {
3052                                                    query.append(WHERE_LESSER_THAN);
3053                                            }
3054                                    }
3055                            }
3056    
3057                            query.append(ORDER_BY_CLAUSE);
3058    
3059                            String[] orderByFields = orderByComparator.getOrderByFields();
3060    
3061                            for (int i = 0; i < orderByFields.length; i++) {
3062                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3063                                    query.append(orderByFields[i]);
3064    
3065                                    if ((i + 1) < orderByFields.length) {
3066                                            if (orderByComparator.isAscending() ^ previous) {
3067                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3068                                            }
3069                                            else {
3070                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3071                                            }
3072                                    }
3073                                    else {
3074                                            if (orderByComparator.isAscending() ^ previous) {
3075                                                    query.append(ORDER_BY_ASC);
3076                                            }
3077                                            else {
3078                                                    query.append(ORDER_BY_DESC);
3079                                            }
3080                                    }
3081                            }
3082                    }
3083    
3084                    else {
3085                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3086                    }
3087    
3088                    String sql = query.toString();
3089    
3090                    Query q = session.createQuery(sql);
3091    
3092                    q.setFirstResult(0);
3093                    q.setMaxResults(2);
3094    
3095                    QueryPos qPos = QueryPos.getInstance(q);
3096    
3097                    qPos.add(groupId);
3098    
3099                    qPos.add(categoryId);
3100    
3101                    if (orderByComparator != null) {
3102                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3103    
3104                            for (Object value : values) {
3105                                    qPos.add(value);
3106                            }
3107                    }
3108    
3109                    List<MBThread> list = q.list();
3110    
3111                    if (list.size() == 2) {
3112                            return list.get(1);
3113                    }
3114                    else {
3115                            return null;
3116                    }
3117            }
3118    
3119            /**
3120             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
3121             *
3122             * @param groupId the group ID
3123             * @param categoryId the category ID
3124             * @return the matching message boards threads that the user has permission to view
3125             * @throws SystemException if a system exception occurred
3126             */
3127            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId)
3128                    throws SystemException {
3129                    return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3130                            QueryUtil.ALL_POS, null);
3131            }
3132    
3133            /**
3134             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
3135             *
3136             * <p>
3137             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3138             * </p>
3139             *
3140             * @param groupId the group ID
3141             * @param categoryId the category ID
3142             * @param start the lower bound of the range of message boards threads
3143             * @param end the upper bound of the range of message boards threads (not inclusive)
3144             * @return the range of matching message boards threads that the user has permission to view
3145             * @throws SystemException if a system exception occurred
3146             */
3147            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3148                    int start, int end) throws SystemException {
3149                    return filterFindByG_NotC(groupId, categoryId, start, end, null);
3150            }
3151    
3152            /**
3153             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and categoryId &ne; &#63;.
3154             *
3155             * <p>
3156             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3157             * </p>
3158             *
3159             * @param groupId the group ID
3160             * @param categoryId the category ID
3161             * @param start the lower bound of the range of message boards threads
3162             * @param end the upper bound of the range of message boards threads (not inclusive)
3163             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3164             * @return the ordered range of matching message boards threads that the user has permission to view
3165             * @throws SystemException if a system exception occurred
3166             */
3167            public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3168                    int start, int end, OrderByComparator orderByComparator)
3169                    throws SystemException {
3170                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3171                            return findByG_NotC(groupId, categoryId, start, end,
3172                                    orderByComparator);
3173                    }
3174    
3175                    StringBundler query = null;
3176    
3177                    if (orderByComparator != null) {
3178                            query = new StringBundler(4 +
3179                                            (orderByComparator.getOrderByFields().length * 3));
3180                    }
3181                    else {
3182                            query = new StringBundler(4);
3183                    }
3184    
3185                    if (getDB().isSupportsInlineDistinct()) {
3186                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3187                    }
3188                    else {
3189                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3190                    }
3191    
3192                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3193    
3194                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3195    
3196                    if (!getDB().isSupportsInlineDistinct()) {
3197                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3198                    }
3199    
3200                    if (orderByComparator != null) {
3201                            if (getDB().isSupportsInlineDistinct()) {
3202                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3203                                            orderByComparator);
3204                            }
3205                            else {
3206                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3207                                            orderByComparator);
3208                            }
3209                    }
3210    
3211                    else {
3212                            if (getDB().isSupportsInlineDistinct()) {
3213                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3214                            }
3215                            else {
3216                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3217                            }
3218                    }
3219    
3220                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3221                                    MBThread.class.getName(),
3222                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3223    
3224                    Session session = null;
3225    
3226                    try {
3227                            session = openSession();
3228    
3229                            SQLQuery q = session.createSQLQuery(sql);
3230    
3231                            if (getDB().isSupportsInlineDistinct()) {
3232                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3233                            }
3234                            else {
3235                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3236                            }
3237    
3238                            QueryPos qPos = QueryPos.getInstance(q);
3239    
3240                            qPos.add(groupId);
3241    
3242                            qPos.add(categoryId);
3243    
3244                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3245                    }
3246                    catch (Exception e) {
3247                            throw processException(e);
3248                    }
3249                    finally {
3250                            closeSession(session);
3251                    }
3252            }
3253    
3254            /**
3255             * 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;.
3256             *
3257             * @param threadId the primary key of the current message boards thread
3258             * @param groupId the group ID
3259             * @param categoryId the category ID
3260             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3261             * @return the previous, current, and next message boards thread
3262             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3263             * @throws SystemException if a system exception occurred
3264             */
3265            public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
3266                    long groupId, long categoryId, OrderByComparator orderByComparator)
3267                    throws NoSuchThreadException, SystemException {
3268                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3269                            return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
3270                                    orderByComparator);
3271                    }
3272    
3273                    MBThread mbThread = findByPrimaryKey(threadId);
3274    
3275                    Session session = null;
3276    
3277                    try {
3278                            session = openSession();
3279    
3280                            MBThread[] array = new MBThreadImpl[3];
3281    
3282                            array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3283                                            groupId, categoryId, orderByComparator, true);
3284    
3285                            array[1] = mbThread;
3286    
3287                            array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3288                                            groupId, categoryId, orderByComparator, false);
3289    
3290                            return array;
3291                    }
3292                    catch (Exception e) {
3293                            throw processException(e);
3294                    }
3295                    finally {
3296                            closeSession(session);
3297                    }
3298            }
3299    
3300            protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
3301                    MBThread mbThread, long groupId, long categoryId,
3302                    OrderByComparator orderByComparator, boolean previous) {
3303                    StringBundler query = null;
3304    
3305                    if (orderByComparator != null) {
3306                            query = new StringBundler(6 +
3307                                            (orderByComparator.getOrderByFields().length * 6));
3308                    }
3309                    else {
3310                            query = new StringBundler(3);
3311                    }
3312    
3313                    if (getDB().isSupportsInlineDistinct()) {
3314                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3315                    }
3316                    else {
3317                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3318                    }
3319    
3320                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3321    
3322                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3323    
3324                    if (!getDB().isSupportsInlineDistinct()) {
3325                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3326                    }
3327    
3328                    if (orderByComparator != null) {
3329                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3330    
3331                            if (orderByConditionFields.length > 0) {
3332                                    query.append(WHERE_AND);
3333                            }
3334    
3335                            for (int i = 0; i < orderByConditionFields.length; i++) {
3336                                    if (getDB().isSupportsInlineDistinct()) {
3337                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3338                                    }
3339                                    else {
3340                                            query.append(_ORDER_BY_ENTITY_TABLE);
3341                                    }
3342    
3343                                    query.append(orderByConditionFields[i]);
3344    
3345                                    if ((i + 1) < orderByConditionFields.length) {
3346                                            if (orderByComparator.isAscending() ^ previous) {
3347                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3348                                            }
3349                                            else {
3350                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3351                                            }
3352                                    }
3353                                    else {
3354                                            if (orderByComparator.isAscending() ^ previous) {
3355                                                    query.append(WHERE_GREATER_THAN);
3356                                            }
3357                                            else {
3358                                                    query.append(WHERE_LESSER_THAN);
3359                                            }
3360                                    }
3361                            }
3362    
3363                            query.append(ORDER_BY_CLAUSE);
3364    
3365                            String[] orderByFields = orderByComparator.getOrderByFields();
3366    
3367                            for (int i = 0; i < orderByFields.length; i++) {
3368                                    if (getDB().isSupportsInlineDistinct()) {
3369                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3370                                    }
3371                                    else {
3372                                            query.append(_ORDER_BY_ENTITY_TABLE);
3373                                    }
3374    
3375                                    query.append(orderByFields[i]);
3376    
3377                                    if ((i + 1) < orderByFields.length) {
3378                                            if (orderByComparator.isAscending() ^ previous) {
3379                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3380                                            }
3381                                            else {
3382                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3383                                            }
3384                                    }
3385                                    else {
3386                                            if (orderByComparator.isAscending() ^ previous) {
3387                                                    query.append(ORDER_BY_ASC);
3388                                            }
3389                                            else {
3390                                                    query.append(ORDER_BY_DESC);
3391                                            }
3392                                    }
3393                            }
3394                    }
3395    
3396                    else {
3397                            if (getDB().isSupportsInlineDistinct()) {
3398                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3399                            }
3400                            else {
3401                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3402                            }
3403                    }
3404    
3405                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3406                                    MBThread.class.getName(),
3407                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3408    
3409                    SQLQuery q = session.createSQLQuery(sql);
3410    
3411                    q.setFirstResult(0);
3412                    q.setMaxResults(2);
3413    
3414                    if (getDB().isSupportsInlineDistinct()) {
3415                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3416                    }
3417                    else {
3418                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3419                    }
3420    
3421                    QueryPos qPos = QueryPos.getInstance(q);
3422    
3423                    qPos.add(groupId);
3424    
3425                    qPos.add(categoryId);
3426    
3427                    if (orderByComparator != null) {
3428                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3429    
3430                            for (Object value : values) {
3431                                    qPos.add(value);
3432                            }
3433                    }
3434    
3435                    List<MBThread> list = q.list();
3436    
3437                    if (list.size() == 2) {
3438                            return list.get(1);
3439                    }
3440                    else {
3441                            return null;
3442                    }
3443            }
3444    
3445            /**
3446             * Returns all the message boards threads where groupId = &#63; and status = &#63;.
3447             *
3448             * @param groupId the group ID
3449             * @param status the status
3450             * @return the matching message boards threads
3451             * @throws SystemException if a system exception occurred
3452             */
3453            public List<MBThread> findByG_S(long groupId, int status)
3454                    throws SystemException {
3455                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3456                            null);
3457            }
3458    
3459            /**
3460             * Returns a range of all the message boards threads where groupId = &#63; and status = &#63;.
3461             *
3462             * <p>
3463             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3464             * </p>
3465             *
3466             * @param groupId the group ID
3467             * @param status the status
3468             * @param start the lower bound of the range of message boards threads
3469             * @param end the upper bound of the range of message boards threads (not inclusive)
3470             * @return the range of matching message boards threads
3471             * @throws SystemException if a system exception occurred
3472             */
3473            public List<MBThread> findByG_S(long groupId, int status, int start, int end)
3474                    throws SystemException {
3475                    return findByG_S(groupId, status, start, end, null);
3476            }
3477    
3478            /**
3479             * Returns an ordered range of all the message boards threads where groupId = &#63; and status = &#63;.
3480             *
3481             * <p>
3482             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3483             * </p>
3484             *
3485             * @param groupId the group ID
3486             * @param status the status
3487             * @param start the lower bound of the range of message boards threads
3488             * @param end the upper bound of the range of message boards threads (not inclusive)
3489             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3490             * @return the ordered range of matching message boards threads
3491             * @throws SystemException if a system exception occurred
3492             */
3493            public List<MBThread> findByG_S(long groupId, int status, int start,
3494                    int end, OrderByComparator orderByComparator) throws SystemException {
3495                    FinderPath finderPath = null;
3496                    Object[] finderArgs = null;
3497    
3498                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3499                                    (orderByComparator == null)) {
3500                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3501                            finderArgs = new Object[] { groupId, status };
3502                    }
3503                    else {
3504                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3505                            finderArgs = new Object[] {
3506                                            groupId, status,
3507                                            
3508                                            start, end, orderByComparator
3509                                    };
3510                    }
3511    
3512                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3513                                    finderArgs, this);
3514    
3515                    if ((list != null) && !list.isEmpty()) {
3516                            for (MBThread mbThread : list) {
3517                                    if ((groupId != mbThread.getGroupId()) ||
3518                                                    (status != mbThread.getStatus())) {
3519                                            list = null;
3520    
3521                                            break;
3522                                    }
3523                            }
3524                    }
3525    
3526                    if (list == null) {
3527                            StringBundler query = null;
3528    
3529                            if (orderByComparator != null) {
3530                                    query = new StringBundler(4 +
3531                                                    (orderByComparator.getOrderByFields().length * 3));
3532                            }
3533                            else {
3534                                    query = new StringBundler(4);
3535                            }
3536    
3537                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
3538    
3539                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3540    
3541                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
3542    
3543                            if (orderByComparator != null) {
3544                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3545                                            orderByComparator);
3546                            }
3547    
3548                            else {
3549                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3550                            }
3551    
3552                            String sql = query.toString();
3553    
3554                            Session session = null;
3555    
3556                            try {
3557                                    session = openSession();
3558    
3559                                    Query q = session.createQuery(sql);
3560    
3561                                    QueryPos qPos = QueryPos.getInstance(q);
3562    
3563                                    qPos.add(groupId);
3564    
3565                                    qPos.add(status);
3566    
3567                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
3568                                                    end);
3569                            }
3570                            catch (Exception e) {
3571                                    throw processException(e);
3572                            }
3573                            finally {
3574                                    if (list == null) {
3575                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3576                                    }
3577                                    else {
3578                                            cacheResult(list);
3579    
3580                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3581                                    }
3582    
3583                                    closeSession(session);
3584                            }
3585                    }
3586    
3587                    return list;
3588            }
3589    
3590            /**
3591             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
3592             *
3593             * @param groupId the group ID
3594             * @param status the status
3595             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3596             * @return the first matching message boards thread
3597             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
3598             * @throws SystemException if a system exception occurred
3599             */
3600            public MBThread findByG_S_First(long groupId, int status,
3601                    OrderByComparator orderByComparator)
3602                    throws NoSuchThreadException, SystemException {
3603                    MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
3604    
3605                    if (mbThread != null) {
3606                            return mbThread;
3607                    }
3608    
3609                    StringBundler msg = new StringBundler(6);
3610    
3611                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3612    
3613                    msg.append("groupId=");
3614                    msg.append(groupId);
3615    
3616                    msg.append(", status=");
3617                    msg.append(status);
3618    
3619                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3620    
3621                    throw new NoSuchThreadException(msg.toString());
3622            }
3623    
3624            /**
3625             * Returns the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
3626             *
3627             * @param groupId the group ID
3628             * @param status the status
3629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3630             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
3631             * @throws SystemException if a system exception occurred
3632             */
3633            public MBThread fetchByG_S_First(long groupId, int status,
3634                    OrderByComparator orderByComparator) throws SystemException {
3635                    List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
3636    
3637                    if (!list.isEmpty()) {
3638                            return list.get(0);
3639                    }
3640    
3641                    return null;
3642            }
3643    
3644            /**
3645             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
3646             *
3647             * @param groupId the group ID
3648             * @param status the status
3649             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3650             * @return the last matching message boards thread
3651             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
3652             * @throws SystemException if a system exception occurred
3653             */
3654            public MBThread findByG_S_Last(long groupId, int status,
3655                    OrderByComparator orderByComparator)
3656                    throws NoSuchThreadException, SystemException {
3657                    MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
3658    
3659                    if (mbThread != null) {
3660                            return mbThread;
3661                    }
3662    
3663                    StringBundler msg = new StringBundler(6);
3664    
3665                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3666    
3667                    msg.append("groupId=");
3668                    msg.append(groupId);
3669    
3670                    msg.append(", status=");
3671                    msg.append(status);
3672    
3673                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3674    
3675                    throw new NoSuchThreadException(msg.toString());
3676            }
3677    
3678            /**
3679             * Returns the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
3680             *
3681             * @param groupId the group ID
3682             * @param status the status
3683             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3684             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
3685             * @throws SystemException if a system exception occurred
3686             */
3687            public MBThread fetchByG_S_Last(long groupId, int status,
3688                    OrderByComparator orderByComparator) throws SystemException {
3689                    int count = countByG_S(groupId, status);
3690    
3691                    List<MBThread> list = findByG_S(groupId, status, count - 1, count,
3692                                    orderByComparator);
3693    
3694                    if (!list.isEmpty()) {
3695                            return list.get(0);
3696                    }
3697    
3698                    return null;
3699            }
3700    
3701            /**
3702             * Returns the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and status = &#63;.
3703             *
3704             * @param threadId the primary key of the current message boards thread
3705             * @param groupId the group ID
3706             * @param status the status
3707             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3708             * @return the previous, current, and next message boards thread
3709             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3710             * @throws SystemException if a system exception occurred
3711             */
3712            public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
3713                    int status, OrderByComparator orderByComparator)
3714                    throws NoSuchThreadException, SystemException {
3715                    MBThread mbThread = findByPrimaryKey(threadId);
3716    
3717                    Session session = null;
3718    
3719                    try {
3720                            session = openSession();
3721    
3722                            MBThread[] array = new MBThreadImpl[3];
3723    
3724                            array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3725                                            orderByComparator, true);
3726    
3727                            array[1] = mbThread;
3728    
3729                            array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3730                                            orderByComparator, false);
3731    
3732                            return array;
3733                    }
3734                    catch (Exception e) {
3735                            throw processException(e);
3736                    }
3737                    finally {
3738                            closeSession(session);
3739                    }
3740            }
3741    
3742            protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
3743                    long groupId, int status, OrderByComparator orderByComparator,
3744                    boolean previous) {
3745                    StringBundler query = null;
3746    
3747                    if (orderByComparator != null) {
3748                            query = new StringBundler(6 +
3749                                            (orderByComparator.getOrderByFields().length * 6));
3750                    }
3751                    else {
3752                            query = new StringBundler(3);
3753                    }
3754    
3755                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
3756    
3757                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3758    
3759                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3760    
3761                    if (orderByComparator != null) {
3762                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3763    
3764                            if (orderByConditionFields.length > 0) {
3765                                    query.append(WHERE_AND);
3766                            }
3767    
3768                            for (int i = 0; i < orderByConditionFields.length; i++) {
3769                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3770                                    query.append(orderByConditionFields[i]);
3771    
3772                                    if ((i + 1) < orderByConditionFields.length) {
3773                                            if (orderByComparator.isAscending() ^ previous) {
3774                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3775                                            }
3776                                            else {
3777                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3778                                            }
3779                                    }
3780                                    else {
3781                                            if (orderByComparator.isAscending() ^ previous) {
3782                                                    query.append(WHERE_GREATER_THAN);
3783                                            }
3784                                            else {
3785                                                    query.append(WHERE_LESSER_THAN);
3786                                            }
3787                                    }
3788                            }
3789    
3790                            query.append(ORDER_BY_CLAUSE);
3791    
3792                            String[] orderByFields = orderByComparator.getOrderByFields();
3793    
3794                            for (int i = 0; i < orderByFields.length; i++) {
3795                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3796                                    query.append(orderByFields[i]);
3797    
3798                                    if ((i + 1) < orderByFields.length) {
3799                                            if (orderByComparator.isAscending() ^ previous) {
3800                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3801                                            }
3802                                            else {
3803                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3804                                            }
3805                                    }
3806                                    else {
3807                                            if (orderByComparator.isAscending() ^ previous) {
3808                                                    query.append(ORDER_BY_ASC);
3809                                            }
3810                                            else {
3811                                                    query.append(ORDER_BY_DESC);
3812                                            }
3813                                    }
3814                            }
3815                    }
3816    
3817                    else {
3818                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3819                    }
3820    
3821                    String sql = query.toString();
3822    
3823                    Query q = session.createQuery(sql);
3824    
3825                    q.setFirstResult(0);
3826                    q.setMaxResults(2);
3827    
3828                    QueryPos qPos = QueryPos.getInstance(q);
3829    
3830                    qPos.add(groupId);
3831    
3832                    qPos.add(status);
3833    
3834                    if (orderByComparator != null) {
3835                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3836    
3837                            for (Object value : values) {
3838                                    qPos.add(value);
3839                            }
3840                    }
3841    
3842                    List<MBThread> list = q.list();
3843    
3844                    if (list.size() == 2) {
3845                            return list.get(1);
3846                    }
3847                    else {
3848                            return null;
3849                    }
3850            }
3851    
3852            /**
3853             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
3854             *
3855             * @param groupId the group ID
3856             * @param status the status
3857             * @return the matching message boards threads that the user has permission to view
3858             * @throws SystemException if a system exception occurred
3859             */
3860            public List<MBThread> filterFindByG_S(long groupId, int status)
3861                    throws SystemException {
3862                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
3863                            QueryUtil.ALL_POS, null);
3864            }
3865    
3866            /**
3867             * Returns a range of all the message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
3868             *
3869             * <p>
3870             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3871             * </p>
3872             *
3873             * @param groupId the group ID
3874             * @param status the status
3875             * @param start the lower bound of the range of message boards threads
3876             * @param end the upper bound of the range of message boards threads (not inclusive)
3877             * @return the range of matching message boards threads that the user has permission to view
3878             * @throws SystemException if a system exception occurred
3879             */
3880            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3881                    int end) throws SystemException {
3882                    return filterFindByG_S(groupId, status, start, end, null);
3883            }
3884    
3885            /**
3886             * Returns an ordered range of all the message boards threads that the user has permissions to view where groupId = &#63; and status = &#63;.
3887             *
3888             * <p>
3889             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3890             * </p>
3891             *
3892             * @param groupId the group ID
3893             * @param status the status
3894             * @param start the lower bound of the range of message boards threads
3895             * @param end the upper bound of the range of message boards threads (not inclusive)
3896             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3897             * @return the ordered range of matching message boards threads that the user has permission to view
3898             * @throws SystemException if a system exception occurred
3899             */
3900            public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3901                    int end, OrderByComparator orderByComparator) throws SystemException {
3902                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3903                            return findByG_S(groupId, status, start, end, orderByComparator);
3904                    }
3905    
3906                    StringBundler query = null;
3907    
3908                    if (orderByComparator != null) {
3909                            query = new StringBundler(4 +
3910                                            (orderByComparator.getOrderByFields().length * 3));
3911                    }
3912                    else {
3913                            query = new StringBundler(4);
3914                    }
3915    
3916                    if (getDB().isSupportsInlineDistinct()) {
3917                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3918                    }
3919                    else {
3920                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3921                    }
3922    
3923                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3924    
3925                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3926    
3927                    if (!getDB().isSupportsInlineDistinct()) {
3928                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3929                    }
3930    
3931                    if (orderByComparator != null) {
3932                            if (getDB().isSupportsInlineDistinct()) {
3933                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3934                                            orderByComparator);
3935                            }
3936                            else {
3937                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3938                                            orderByComparator);
3939                            }
3940                    }
3941    
3942                    else {
3943                            if (getDB().isSupportsInlineDistinct()) {
3944                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3945                            }
3946                            else {
3947                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
3948                            }
3949                    }
3950    
3951                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3952                                    MBThread.class.getName(),
3953                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3954    
3955                    Session session = null;
3956    
3957                    try {
3958                            session = openSession();
3959    
3960                            SQLQuery q = session.createSQLQuery(sql);
3961    
3962                            if (getDB().isSupportsInlineDistinct()) {
3963                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3964                            }
3965                            else {
3966                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3967                            }
3968    
3969                            QueryPos qPos = QueryPos.getInstance(q);
3970    
3971                            qPos.add(groupId);
3972    
3973                            qPos.add(status);
3974    
3975                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3976                    }
3977                    catch (Exception e) {
3978                            throw processException(e);
3979                    }
3980                    finally {
3981                            closeSession(session);
3982                    }
3983            }
3984    
3985            /**
3986             * 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;.
3987             *
3988             * @param threadId the primary key of the current message boards thread
3989             * @param groupId the group ID
3990             * @param status the status
3991             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3992             * @return the previous, current, and next message boards thread
3993             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3994             * @throws SystemException if a system exception occurred
3995             */
3996            public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
3997                    int status, OrderByComparator orderByComparator)
3998                    throws NoSuchThreadException, SystemException {
3999                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4000                            return findByG_S_PrevAndNext(threadId, groupId, status,
4001                                    orderByComparator);
4002                    }
4003    
4004                    MBThread mbThread = findByPrimaryKey(threadId);
4005    
4006                    Session session = null;
4007    
4008                    try {
4009                            session = openSession();
4010    
4011                            MBThread[] array = new MBThreadImpl[3];
4012    
4013                            array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
4014                                            status, orderByComparator, true);
4015    
4016                            array[1] = mbThread;
4017    
4018                            array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
4019                                            status, orderByComparator, false);
4020    
4021                            return array;
4022                    }
4023                    catch (Exception e) {
4024                            throw processException(e);
4025                    }
4026                    finally {
4027                            closeSession(session);
4028                    }
4029            }
4030    
4031            protected MBThread filterGetByG_S_PrevAndNext(Session session,
4032                    MBThread mbThread, long groupId, int status,
4033                    OrderByComparator orderByComparator, boolean previous) {
4034                    StringBundler query = null;
4035    
4036                    if (orderByComparator != null) {
4037                            query = new StringBundler(6 +
4038                                            (orderByComparator.getOrderByFields().length * 6));
4039                    }
4040                    else {
4041                            query = new StringBundler(3);
4042                    }
4043    
4044                    if (getDB().isSupportsInlineDistinct()) {
4045                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4046                    }
4047                    else {
4048                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4049                    }
4050    
4051                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4052    
4053                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4054    
4055                    if (!getDB().isSupportsInlineDistinct()) {
4056                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4057                    }
4058    
4059                    if (orderByComparator != null) {
4060                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4061    
4062                            if (orderByConditionFields.length > 0) {
4063                                    query.append(WHERE_AND);
4064                            }
4065    
4066                            for (int i = 0; i < orderByConditionFields.length; i++) {
4067                                    if (getDB().isSupportsInlineDistinct()) {
4068                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4069                                    }
4070                                    else {
4071                                            query.append(_ORDER_BY_ENTITY_TABLE);
4072                                    }
4073    
4074                                    query.append(orderByConditionFields[i]);
4075    
4076                                    if ((i + 1) < orderByConditionFields.length) {
4077                                            if (orderByComparator.isAscending() ^ previous) {
4078                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4079                                            }
4080                                            else {
4081                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4082                                            }
4083                                    }
4084                                    else {
4085                                            if (orderByComparator.isAscending() ^ previous) {
4086                                                    query.append(WHERE_GREATER_THAN);
4087                                            }
4088                                            else {
4089                                                    query.append(WHERE_LESSER_THAN);
4090                                            }
4091                                    }
4092                            }
4093    
4094                            query.append(ORDER_BY_CLAUSE);
4095    
4096                            String[] orderByFields = orderByComparator.getOrderByFields();
4097    
4098                            for (int i = 0; i < orderByFields.length; i++) {
4099                                    if (getDB().isSupportsInlineDistinct()) {
4100                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4101                                    }
4102                                    else {
4103                                            query.append(_ORDER_BY_ENTITY_TABLE);
4104                                    }
4105    
4106                                    query.append(orderByFields[i]);
4107    
4108                                    if ((i + 1) < orderByFields.length) {
4109                                            if (orderByComparator.isAscending() ^ previous) {
4110                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4111                                            }
4112                                            else {
4113                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4114                                            }
4115                                    }
4116                                    else {
4117                                            if (orderByComparator.isAscending() ^ previous) {
4118                                                    query.append(ORDER_BY_ASC);
4119                                            }
4120                                            else {
4121                                                    query.append(ORDER_BY_DESC);
4122                                            }
4123                                    }
4124                            }
4125                    }
4126    
4127                    else {
4128                            if (getDB().isSupportsInlineDistinct()) {
4129                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4130                            }
4131                            else {
4132                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
4133                            }
4134                    }
4135    
4136                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4137                                    MBThread.class.getName(),
4138                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4139    
4140                    SQLQuery q = session.createSQLQuery(sql);
4141    
4142                    q.setFirstResult(0);
4143                    q.setMaxResults(2);
4144    
4145                    if (getDB().isSupportsInlineDistinct()) {
4146                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4147                    }
4148                    else {
4149                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4150                    }
4151    
4152                    QueryPos qPos = QueryPos.getInstance(q);
4153    
4154                    qPos.add(groupId);
4155    
4156                    qPos.add(status);
4157    
4158                    if (orderByComparator != null) {
4159                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4160    
4161                            for (Object value : values) {
4162                                    qPos.add(value);
4163                            }
4164                    }
4165    
4166                    List<MBThread> list = q.list();
4167    
4168                    if (list.size() == 2) {
4169                            return list.get(1);
4170                    }
4171                    else {
4172                            return null;
4173                    }
4174            }
4175    
4176            /**
4177             * Returns all the message boards threads where categoryId = &#63; and priority = &#63;.
4178             *
4179             * @param categoryId the category ID
4180             * @param priority the priority
4181             * @return the matching message boards threads
4182             * @throws SystemException if a system exception occurred
4183             */
4184            public List<MBThread> findByC_P(long categoryId, double priority)
4185                    throws SystemException {
4186                    return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
4187                            QueryUtil.ALL_POS, null);
4188            }
4189    
4190            /**
4191             * Returns a range of all the message boards threads where categoryId = &#63; and priority = &#63;.
4192             *
4193             * <p>
4194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4195             * </p>
4196             *
4197             * @param categoryId the category ID
4198             * @param priority the priority
4199             * @param start the lower bound of the range of message boards threads
4200             * @param end the upper bound of the range of message boards threads (not inclusive)
4201             * @return the range of matching message boards threads
4202             * @throws SystemException if a system exception occurred
4203             */
4204            public List<MBThread> findByC_P(long categoryId, double priority,
4205                    int start, int end) throws SystemException {
4206                    return findByC_P(categoryId, priority, start, end, null);
4207            }
4208    
4209            /**
4210             * Returns an ordered range of all the message boards threads where categoryId = &#63; and priority = &#63;.
4211             *
4212             * <p>
4213             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4214             * </p>
4215             *
4216             * @param categoryId the category ID
4217             * @param priority the priority
4218             * @param start the lower bound of the range of message boards threads
4219             * @param end the upper bound of the range of message boards threads (not inclusive)
4220             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4221             * @return the ordered range of matching message boards threads
4222             * @throws SystemException if a system exception occurred
4223             */
4224            public List<MBThread> findByC_P(long categoryId, double priority,
4225                    int start, int end, OrderByComparator orderByComparator)
4226                    throws SystemException {
4227                    FinderPath finderPath = null;
4228                    Object[] finderArgs = null;
4229    
4230                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4231                                    (orderByComparator == null)) {
4232                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
4233                            finderArgs = new Object[] { categoryId, priority };
4234                    }
4235                    else {
4236                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
4237                            finderArgs = new Object[] {
4238                                            categoryId, priority,
4239                                            
4240                                            start, end, orderByComparator
4241                                    };
4242                    }
4243    
4244                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4245                                    finderArgs, this);
4246    
4247                    if ((list != null) && !list.isEmpty()) {
4248                            for (MBThread mbThread : list) {
4249                                    if ((categoryId != mbThread.getCategoryId()) ||
4250                                                    (priority != mbThread.getPriority())) {
4251                                            list = null;
4252    
4253                                            break;
4254                                    }
4255                            }
4256                    }
4257    
4258                    if (list == null) {
4259                            StringBundler query = null;
4260    
4261                            if (orderByComparator != null) {
4262                                    query = new StringBundler(4 +
4263                                                    (orderByComparator.getOrderByFields().length * 3));
4264                            }
4265                            else {
4266                                    query = new StringBundler(4);
4267                            }
4268    
4269                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
4270    
4271                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4272    
4273                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4274    
4275                            if (orderByComparator != null) {
4276                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4277                                            orderByComparator);
4278                            }
4279    
4280                            else {
4281                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4282                            }
4283    
4284                            String sql = query.toString();
4285    
4286                            Session session = null;
4287    
4288                            try {
4289                                    session = openSession();
4290    
4291                                    Query q = session.createQuery(sql);
4292    
4293                                    QueryPos qPos = QueryPos.getInstance(q);
4294    
4295                                    qPos.add(categoryId);
4296    
4297                                    qPos.add(priority);
4298    
4299                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4300                                                    end);
4301                            }
4302                            catch (Exception e) {
4303                                    throw processException(e);
4304                            }
4305                            finally {
4306                                    if (list == null) {
4307                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4308                                    }
4309                                    else {
4310                                            cacheResult(list);
4311    
4312                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4313                                    }
4314    
4315                                    closeSession(session);
4316                            }
4317                    }
4318    
4319                    return list;
4320            }
4321    
4322            /**
4323             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
4324             *
4325             * @param categoryId the category ID
4326             * @param priority the priority
4327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4328             * @return the first matching message boards thread
4329             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4330             * @throws SystemException if a system exception occurred
4331             */
4332            public MBThread findByC_P_First(long categoryId, double priority,
4333                    OrderByComparator orderByComparator)
4334                    throws NoSuchThreadException, SystemException {
4335                    MBThread mbThread = fetchByC_P_First(categoryId, priority,
4336                                    orderByComparator);
4337    
4338                    if (mbThread != null) {
4339                            return mbThread;
4340                    }
4341    
4342                    StringBundler msg = new StringBundler(6);
4343    
4344                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4345    
4346                    msg.append("categoryId=");
4347                    msg.append(categoryId);
4348    
4349                    msg.append(", priority=");
4350                    msg.append(priority);
4351    
4352                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4353    
4354                    throw new NoSuchThreadException(msg.toString());
4355            }
4356    
4357            /**
4358             * Returns the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
4359             *
4360             * @param categoryId the category ID
4361             * @param priority the priority
4362             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4363             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4364             * @throws SystemException if a system exception occurred
4365             */
4366            public MBThread fetchByC_P_First(long categoryId, double priority,
4367                    OrderByComparator orderByComparator) throws SystemException {
4368                    List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
4369                                    orderByComparator);
4370    
4371                    if (!list.isEmpty()) {
4372                            return list.get(0);
4373                    }
4374    
4375                    return null;
4376            }
4377    
4378            /**
4379             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
4380             *
4381             * @param categoryId the category ID
4382             * @param priority the priority
4383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4384             * @return the last matching message boards thread
4385             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4386             * @throws SystemException if a system exception occurred
4387             */
4388            public MBThread findByC_P_Last(long categoryId, double priority,
4389                    OrderByComparator orderByComparator)
4390                    throws NoSuchThreadException, SystemException {
4391                    MBThread mbThread = fetchByC_P_Last(categoryId, priority,
4392                                    orderByComparator);
4393    
4394                    if (mbThread != null) {
4395                            return mbThread;
4396                    }
4397    
4398                    StringBundler msg = new StringBundler(6);
4399    
4400                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4401    
4402                    msg.append("categoryId=");
4403                    msg.append(categoryId);
4404    
4405                    msg.append(", priority=");
4406                    msg.append(priority);
4407    
4408                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4409    
4410                    throw new NoSuchThreadException(msg.toString());
4411            }
4412    
4413            /**
4414             * Returns the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
4415             *
4416             * @param categoryId the category ID
4417             * @param priority the priority
4418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4419             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4420             * @throws SystemException if a system exception occurred
4421             */
4422            public MBThread fetchByC_P_Last(long categoryId, double priority,
4423                    OrderByComparator orderByComparator) throws SystemException {
4424                    int count = countByC_P(categoryId, priority);
4425    
4426                    List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
4427                                    orderByComparator);
4428    
4429                    if (!list.isEmpty()) {
4430                            return list.get(0);
4431                    }
4432    
4433                    return null;
4434            }
4435    
4436            /**
4437             * Returns the message boards threads before and after the current message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
4438             *
4439             * @param threadId the primary key of the current message boards thread
4440             * @param categoryId the category ID
4441             * @param priority the priority
4442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4443             * @return the previous, current, and next message boards thread
4444             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
4445             * @throws SystemException if a system exception occurred
4446             */
4447            public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
4448                    double priority, OrderByComparator orderByComparator)
4449                    throws NoSuchThreadException, SystemException {
4450                    MBThread mbThread = findByPrimaryKey(threadId);
4451    
4452                    Session session = null;
4453    
4454                    try {
4455                            session = openSession();
4456    
4457                            MBThread[] array = new MBThreadImpl[3];
4458    
4459                            array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4460                                            priority, orderByComparator, true);
4461    
4462                            array[1] = mbThread;
4463    
4464                            array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4465                                            priority, orderByComparator, false);
4466    
4467                            return array;
4468                    }
4469                    catch (Exception e) {
4470                            throw processException(e);
4471                    }
4472                    finally {
4473                            closeSession(session);
4474                    }
4475            }
4476    
4477            protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
4478                    long categoryId, double priority, OrderByComparator orderByComparator,
4479                    boolean previous) {
4480                    StringBundler query = null;
4481    
4482                    if (orderByComparator != null) {
4483                            query = new StringBundler(6 +
4484                                            (orderByComparator.getOrderByFields().length * 6));
4485                    }
4486                    else {
4487                            query = new StringBundler(3);
4488                    }
4489    
4490                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
4491    
4492                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4493    
4494                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4495    
4496                    if (orderByComparator != null) {
4497                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4498    
4499                            if (orderByConditionFields.length > 0) {
4500                                    query.append(WHERE_AND);
4501                            }
4502    
4503                            for (int i = 0; i < orderByConditionFields.length; i++) {
4504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4505                                    query.append(orderByConditionFields[i]);
4506    
4507                                    if ((i + 1) < orderByConditionFields.length) {
4508                                            if (orderByComparator.isAscending() ^ previous) {
4509                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4510                                            }
4511                                            else {
4512                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4513                                            }
4514                                    }
4515                                    else {
4516                                            if (orderByComparator.isAscending() ^ previous) {
4517                                                    query.append(WHERE_GREATER_THAN);
4518                                            }
4519                                            else {
4520                                                    query.append(WHERE_LESSER_THAN);
4521                                            }
4522                                    }
4523                            }
4524    
4525                            query.append(ORDER_BY_CLAUSE);
4526    
4527                            String[] orderByFields = orderByComparator.getOrderByFields();
4528    
4529                            for (int i = 0; i < orderByFields.length; i++) {
4530                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4531                                    query.append(orderByFields[i]);
4532    
4533                                    if ((i + 1) < orderByFields.length) {
4534                                            if (orderByComparator.isAscending() ^ previous) {
4535                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4536                                            }
4537                                            else {
4538                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4539                                            }
4540                                    }
4541                                    else {
4542                                            if (orderByComparator.isAscending() ^ previous) {
4543                                                    query.append(ORDER_BY_ASC);
4544                                            }
4545                                            else {
4546                                                    query.append(ORDER_BY_DESC);
4547                                            }
4548                                    }
4549                            }
4550                    }
4551    
4552                    else {
4553                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4554                    }
4555    
4556                    String sql = query.toString();
4557    
4558                    Query q = session.createQuery(sql);
4559    
4560                    q.setFirstResult(0);
4561                    q.setMaxResults(2);
4562    
4563                    QueryPos qPos = QueryPos.getInstance(q);
4564    
4565                    qPos.add(categoryId);
4566    
4567                    qPos.add(priority);
4568    
4569                    if (orderByComparator != null) {
4570                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4571    
4572                            for (Object value : values) {
4573                                    qPos.add(value);
4574                            }
4575                    }
4576    
4577                    List<MBThread> list = q.list();
4578    
4579                    if (list.size() == 2) {
4580                            return list.get(1);
4581                    }
4582                    else {
4583                            return null;
4584                    }
4585            }
4586    
4587            /**
4588             * Returns all the message boards threads where lastPostDate = &#63; and priority = &#63;.
4589             *
4590             * @param lastPostDate the last post date
4591             * @param priority the priority
4592             * @return the matching message boards threads
4593             * @throws SystemException if a system exception occurred
4594             */
4595            public List<MBThread> findByL_P(Date lastPostDate, double priority)
4596                    throws SystemException {
4597                    return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
4598                            QueryUtil.ALL_POS, null);
4599            }
4600    
4601            /**
4602             * Returns a range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
4603             *
4604             * <p>
4605             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4606             * </p>
4607             *
4608             * @param lastPostDate the last post date
4609             * @param priority the priority
4610             * @param start the lower bound of the range of message boards threads
4611             * @param end the upper bound of the range of message boards threads (not inclusive)
4612             * @return the range of matching message boards threads
4613             * @throws SystemException if a system exception occurred
4614             */
4615            public List<MBThread> findByL_P(Date lastPostDate, double priority,
4616                    int start, int end) throws SystemException {
4617                    return findByL_P(lastPostDate, priority, start, end, null);
4618            }
4619    
4620            /**
4621             * Returns an ordered range of all the message boards threads where lastPostDate = &#63; and priority = &#63;.
4622             *
4623             * <p>
4624             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
4625             * </p>
4626             *
4627             * @param lastPostDate the last post date
4628             * @param priority the priority
4629             * @param start the lower bound of the range of message boards threads
4630             * @param end the upper bound of the range of message boards threads (not inclusive)
4631             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4632             * @return the ordered range of matching message boards threads
4633             * @throws SystemException if a system exception occurred
4634             */
4635            public List<MBThread> findByL_P(Date lastPostDate, double priority,
4636                    int start, int end, OrderByComparator orderByComparator)
4637                    throws SystemException {
4638                    FinderPath finderPath = null;
4639                    Object[] finderArgs = null;
4640    
4641                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4642                                    (orderByComparator == null)) {
4643                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
4644                            finderArgs = new Object[] { lastPostDate, priority };
4645                    }
4646                    else {
4647                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
4648                            finderArgs = new Object[] {
4649                                            lastPostDate, priority,
4650                                            
4651                                            start, end, orderByComparator
4652                                    };
4653                    }
4654    
4655                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4656                                    finderArgs, this);
4657    
4658                    if ((list != null) && !list.isEmpty()) {
4659                            for (MBThread mbThread : list) {
4660                                    if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
4661                                                    (priority != mbThread.getPriority())) {
4662                                            list = null;
4663    
4664                                            break;
4665                                    }
4666                            }
4667                    }
4668    
4669                    if (list == null) {
4670                            StringBundler query = null;
4671    
4672                            if (orderByComparator != null) {
4673                                    query = new StringBundler(4 +
4674                                                    (orderByComparator.getOrderByFields().length * 3));
4675                            }
4676                            else {
4677                                    query = new StringBundler(4);
4678                            }
4679    
4680                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
4681    
4682                            if (lastPostDate == null) {
4683                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4684                            }
4685                            else {
4686                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4687                            }
4688    
4689                            query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4690    
4691                            if (orderByComparator != null) {
4692                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4693                                            orderByComparator);
4694                            }
4695    
4696                            else {
4697                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4698                            }
4699    
4700                            String sql = query.toString();
4701    
4702                            Session session = null;
4703    
4704                            try {
4705                                    session = openSession();
4706    
4707                                    Query q = session.createQuery(sql);
4708    
4709                                    QueryPos qPos = QueryPos.getInstance(q);
4710    
4711                                    if (lastPostDate != null) {
4712                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4713                                    }
4714    
4715                                    qPos.add(priority);
4716    
4717                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
4718                                                    end);
4719                            }
4720                            catch (Exception e) {
4721                                    throw processException(e);
4722                            }
4723                            finally {
4724                                    if (list == null) {
4725                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
4726                                    }
4727                                    else {
4728                                            cacheResult(list);
4729    
4730                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
4731                                    }
4732    
4733                                    closeSession(session);
4734                            }
4735                    }
4736    
4737                    return list;
4738            }
4739    
4740            /**
4741             * Returns the first message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
4742             *
4743             * @param lastPostDate the last post date
4744             * @param priority the priority
4745             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4746             * @return the first matching message boards thread
4747             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4748             * @throws SystemException if a system exception occurred
4749             */
4750            public MBThread findByL_P_First(Date lastPostDate, double priority,
4751                    OrderByComparator orderByComparator)
4752                    throws NoSuchThreadException, SystemException {
4753                    MBThread mbThread = fetchByL_P_First(lastPostDate, priority,
4754                                    orderByComparator);
4755    
4756                    if (mbThread != null) {
4757                            return mbThread;
4758                    }
4759    
4760                    StringBundler msg = new StringBundler(6);
4761    
4762                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4763    
4764                    msg.append("lastPostDate=");
4765                    msg.append(lastPostDate);
4766    
4767                    msg.append(", priority=");
4768                    msg.append(priority);
4769    
4770                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4771    
4772                    throw new NoSuchThreadException(msg.toString());
4773            }
4774    
4775            /**
4776             * Returns the first message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
4777             *
4778             * @param lastPostDate the last post date
4779             * @param priority the priority
4780             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4781             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4782             * @throws SystemException if a system exception occurred
4783             */
4784            public MBThread fetchByL_P_First(Date lastPostDate, double priority,
4785                    OrderByComparator orderByComparator) throws SystemException {
4786                    List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
4787                                    orderByComparator);
4788    
4789                    if (!list.isEmpty()) {
4790                            return list.get(0);
4791                    }
4792    
4793                    return null;
4794            }
4795    
4796            /**
4797             * Returns the last message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
4798             *
4799             * @param lastPostDate the last post date
4800             * @param priority the priority
4801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4802             * @return the last matching message boards thread
4803             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
4804             * @throws SystemException if a system exception occurred
4805             */
4806            public MBThread findByL_P_Last(Date lastPostDate, double priority,
4807                    OrderByComparator orderByComparator)
4808                    throws NoSuchThreadException, SystemException {
4809                    MBThread mbThread = fetchByL_P_Last(lastPostDate, priority,
4810                                    orderByComparator);
4811    
4812                    if (mbThread != null) {
4813                            return mbThread;
4814                    }
4815    
4816                    StringBundler msg = new StringBundler(6);
4817    
4818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4819    
4820                    msg.append("lastPostDate=");
4821                    msg.append(lastPostDate);
4822    
4823                    msg.append(", priority=");
4824                    msg.append(priority);
4825    
4826                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4827    
4828                    throw new NoSuchThreadException(msg.toString());
4829            }
4830    
4831            /**
4832             * Returns the last message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
4833             *
4834             * @param lastPostDate the last post date
4835             * @param priority the priority
4836             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4837             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
4838             * @throws SystemException if a system exception occurred
4839             */
4840            public MBThread fetchByL_P_Last(Date lastPostDate, double priority,
4841                    OrderByComparator orderByComparator) throws SystemException {
4842                    int count = countByL_P(lastPostDate, priority);
4843    
4844                    List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
4845                                    count, orderByComparator);
4846    
4847                    if (!list.isEmpty()) {
4848                            return list.get(0);
4849                    }
4850    
4851                    return null;
4852            }
4853    
4854            /**
4855             * Returns the message boards threads before and after the current message boards thread in the ordered set where lastPostDate = &#63; and priority = &#63;.
4856             *
4857             * @param threadId the primary key of the current message boards thread
4858             * @param lastPostDate the last post date
4859             * @param priority the priority
4860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4861             * @return the previous, current, and next message boards thread
4862             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
4863             * @throws SystemException if a system exception occurred
4864             */
4865            public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
4866                    double priority, OrderByComparator orderByComparator)
4867                    throws NoSuchThreadException, SystemException {
4868                    MBThread mbThread = findByPrimaryKey(threadId);
4869    
4870                    Session session = null;
4871    
4872                    try {
4873                            session = openSession();
4874    
4875                            MBThread[] array = new MBThreadImpl[3];
4876    
4877                            array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
4878                                            priority, orderByComparator, true);
4879    
4880                            array[1] = mbThread;
4881    
4882                            array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
4883                                            priority, orderByComparator, false);
4884    
4885                            return array;
4886                    }
4887                    catch (Exception e) {
4888                            throw processException(e);
4889                    }
4890                    finally {
4891                            closeSession(session);
4892                    }
4893            }
4894    
4895            protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
4896                    Date lastPostDate, double priority,
4897                    OrderByComparator orderByComparator, boolean previous) {
4898                    StringBundler query = null;
4899    
4900                    if (orderByComparator != null) {
4901                            query = new StringBundler(6 +
4902                                            (orderByComparator.getOrderByFields().length * 6));
4903                    }
4904                    else {
4905                            query = new StringBundler(3);
4906                    }
4907    
4908                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
4909    
4910                    if (lastPostDate == null) {
4911                            query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4912                    }
4913                    else {
4914                            query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4915                    }
4916    
4917                    query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4918    
4919                    if (orderByComparator != null) {
4920                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4921    
4922                            if (orderByConditionFields.length > 0) {
4923                                    query.append(WHERE_AND);
4924                            }
4925    
4926                            for (int i = 0; i < orderByConditionFields.length; i++) {
4927                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4928                                    query.append(orderByConditionFields[i]);
4929    
4930                                    if ((i + 1) < orderByConditionFields.length) {
4931                                            if (orderByComparator.isAscending() ^ previous) {
4932                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4933                                            }
4934                                            else {
4935                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4936                                            }
4937                                    }
4938                                    else {
4939                                            if (orderByComparator.isAscending() ^ previous) {
4940                                                    query.append(WHERE_GREATER_THAN);
4941                                            }
4942                                            else {
4943                                                    query.append(WHERE_LESSER_THAN);
4944                                            }
4945                                    }
4946                            }
4947    
4948                            query.append(ORDER_BY_CLAUSE);
4949    
4950                            String[] orderByFields = orderByComparator.getOrderByFields();
4951    
4952                            for (int i = 0; i < orderByFields.length; i++) {
4953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4954                                    query.append(orderByFields[i]);
4955    
4956                                    if ((i + 1) < orderByFields.length) {
4957                                            if (orderByComparator.isAscending() ^ previous) {
4958                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4959                                            }
4960                                            else {
4961                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4962                                            }
4963                                    }
4964                                    else {
4965                                            if (orderByComparator.isAscending() ^ previous) {
4966                                                    query.append(ORDER_BY_ASC);
4967                                            }
4968                                            else {
4969                                                    query.append(ORDER_BY_DESC);
4970                                            }
4971                                    }
4972                            }
4973                    }
4974    
4975                    else {
4976                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4977                    }
4978    
4979                    String sql = query.toString();
4980    
4981                    Query q = session.createQuery(sql);
4982    
4983                    q.setFirstResult(0);
4984                    q.setMaxResults(2);
4985    
4986                    QueryPos qPos = QueryPos.getInstance(q);
4987    
4988                    if (lastPostDate != null) {
4989                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4990                    }
4991    
4992                    qPos.add(priority);
4993    
4994                    if (orderByComparator != null) {
4995                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4996    
4997                            for (Object value : values) {
4998                                    qPos.add(value);
4999                            }
5000                    }
5001    
5002                    List<MBThread> list = q.list();
5003    
5004                    if (list.size() == 2) {
5005                            return list.get(1);
5006                    }
5007                    else {
5008                            return null;
5009                    }
5010            }
5011    
5012            /**
5013             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5014             *
5015             * @param groupId the group ID
5016             * @param categoryId the category ID
5017             * @param lastPostDate the last post date
5018             * @return the matching message boards threads
5019             * @throws SystemException if a system exception occurred
5020             */
5021            public List<MBThread> findByG_C_L(long groupId, long categoryId,
5022                    Date lastPostDate) throws SystemException {
5023                    return findByG_C_L(groupId, categoryId, lastPostDate,
5024                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5025            }
5026    
5027            /**
5028             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5029             *
5030             * <p>
5031             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5032             * </p>
5033             *
5034             * @param groupId the group ID
5035             * @param categoryId the category ID
5036             * @param lastPostDate the last post date
5037             * @param start the lower bound of the range of message boards threads
5038             * @param end the upper bound of the range of message boards threads (not inclusive)
5039             * @return the range of matching message boards threads
5040             * @throws SystemException if a system exception occurred
5041             */
5042            public List<MBThread> findByG_C_L(long groupId, long categoryId,
5043                    Date lastPostDate, int start, int end) throws SystemException {
5044                    return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
5045            }
5046    
5047            /**
5048             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5049             *
5050             * <p>
5051             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5052             * </p>
5053             *
5054             * @param groupId the group ID
5055             * @param categoryId the category ID
5056             * @param lastPostDate the last post date
5057             * @param start the lower bound of the range of message boards threads
5058             * @param end the upper bound of the range of message boards threads (not inclusive)
5059             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5060             * @return the ordered range of matching message boards threads
5061             * @throws SystemException if a system exception occurred
5062             */
5063            public List<MBThread> findByG_C_L(long groupId, long categoryId,
5064                    Date lastPostDate, int start, int end,
5065                    OrderByComparator orderByComparator) throws SystemException {
5066                    FinderPath finderPath = null;
5067                    Object[] finderArgs = null;
5068    
5069                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5070                                    (orderByComparator == null)) {
5071                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
5072                            finderArgs = new Object[] { groupId, categoryId, lastPostDate };
5073                    }
5074                    else {
5075                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
5076                            finderArgs = new Object[] {
5077                                            groupId, categoryId, lastPostDate,
5078                                            
5079                                            start, end, orderByComparator
5080                                    };
5081                    }
5082    
5083                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5084                                    finderArgs, this);
5085    
5086                    if ((list != null) && !list.isEmpty()) {
5087                            for (MBThread mbThread : list) {
5088                                    if ((groupId != mbThread.getGroupId()) ||
5089                                                    (categoryId != mbThread.getCategoryId()) ||
5090                                                    !Validator.equals(lastPostDate,
5091                                                            mbThread.getLastPostDate())) {
5092                                            list = null;
5093    
5094                                            break;
5095                                    }
5096                            }
5097                    }
5098    
5099                    if (list == null) {
5100                            StringBundler query = null;
5101    
5102                            if (orderByComparator != null) {
5103                                    query = new StringBundler(5 +
5104                                                    (orderByComparator.getOrderByFields().length * 3));
5105                            }
5106                            else {
5107                                    query = new StringBundler(5);
5108                            }
5109    
5110                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
5111    
5112                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5113    
5114                            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5115    
5116                            if (lastPostDate == null) {
5117                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5118                            }
5119                            else {
5120                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5121                            }
5122    
5123                            if (orderByComparator != null) {
5124                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5125                                            orderByComparator);
5126                            }
5127    
5128                            else {
5129                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5130                            }
5131    
5132                            String sql = query.toString();
5133    
5134                            Session session = null;
5135    
5136                            try {
5137                                    session = openSession();
5138    
5139                                    Query q = session.createQuery(sql);
5140    
5141                                    QueryPos qPos = QueryPos.getInstance(q);
5142    
5143                                    qPos.add(groupId);
5144    
5145                                    qPos.add(categoryId);
5146    
5147                                    if (lastPostDate != null) {
5148                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5149                                    }
5150    
5151                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
5152                                                    end);
5153                            }
5154                            catch (Exception e) {
5155                                    throw processException(e);
5156                            }
5157                            finally {
5158                                    if (list == null) {
5159                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5160                                    }
5161                                    else {
5162                                            cacheResult(list);
5163    
5164                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5165                                    }
5166    
5167                                    closeSession(session);
5168                            }
5169                    }
5170    
5171                    return list;
5172            }
5173    
5174            /**
5175             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5176             *
5177             * @param groupId the group ID
5178             * @param categoryId the category ID
5179             * @param lastPostDate the last post date
5180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5181             * @return the first matching message boards thread
5182             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5183             * @throws SystemException if a system exception occurred
5184             */
5185            public MBThread findByG_C_L_First(long groupId, long categoryId,
5186                    Date lastPostDate, OrderByComparator orderByComparator)
5187                    throws NoSuchThreadException, SystemException {
5188                    MBThread mbThread = fetchByG_C_L_First(groupId, categoryId,
5189                                    lastPostDate, orderByComparator);
5190    
5191                    if (mbThread != null) {
5192                            return mbThread;
5193                    }
5194    
5195                    StringBundler msg = new StringBundler(8);
5196    
5197                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5198    
5199                    msg.append("groupId=");
5200                    msg.append(groupId);
5201    
5202                    msg.append(", categoryId=");
5203                    msg.append(categoryId);
5204    
5205                    msg.append(", lastPostDate=");
5206                    msg.append(lastPostDate);
5207    
5208                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5209    
5210                    throw new NoSuchThreadException(msg.toString());
5211            }
5212    
5213            /**
5214             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5215             *
5216             * @param groupId the group ID
5217             * @param categoryId the category ID
5218             * @param lastPostDate the last post date
5219             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5220             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5221             * @throws SystemException if a system exception occurred
5222             */
5223            public MBThread fetchByG_C_L_First(long groupId, long categoryId,
5224                    Date lastPostDate, OrderByComparator orderByComparator)
5225                    throws SystemException {
5226                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
5227                                    1, orderByComparator);
5228    
5229                    if (!list.isEmpty()) {
5230                            return list.get(0);
5231                    }
5232    
5233                    return null;
5234            }
5235    
5236            /**
5237             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5238             *
5239             * @param groupId the group ID
5240             * @param categoryId the category ID
5241             * @param lastPostDate the last post date
5242             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5243             * @return the last matching message boards thread
5244             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5245             * @throws SystemException if a system exception occurred
5246             */
5247            public MBThread findByG_C_L_Last(long groupId, long categoryId,
5248                    Date lastPostDate, OrderByComparator orderByComparator)
5249                    throws NoSuchThreadException, SystemException {
5250                    MBThread mbThread = fetchByG_C_L_Last(groupId, categoryId,
5251                                    lastPostDate, orderByComparator);
5252    
5253                    if (mbThread != null) {
5254                            return mbThread;
5255                    }
5256    
5257                    StringBundler msg = new StringBundler(8);
5258    
5259                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5260    
5261                    msg.append("groupId=");
5262                    msg.append(groupId);
5263    
5264                    msg.append(", categoryId=");
5265                    msg.append(categoryId);
5266    
5267                    msg.append(", lastPostDate=");
5268                    msg.append(lastPostDate);
5269    
5270                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5271    
5272                    throw new NoSuchThreadException(msg.toString());
5273            }
5274    
5275            /**
5276             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5277             *
5278             * @param groupId the group ID
5279             * @param categoryId the category ID
5280             * @param lastPostDate the last post date
5281             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5282             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
5283             * @throws SystemException if a system exception occurred
5284             */
5285            public MBThread fetchByG_C_L_Last(long groupId, long categoryId,
5286                    Date lastPostDate, OrderByComparator orderByComparator)
5287                    throws SystemException {
5288                    int count = countByG_C_L(groupId, categoryId, lastPostDate);
5289    
5290                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
5291                                    count - 1, count, orderByComparator);
5292    
5293                    if (!list.isEmpty()) {
5294                            return list.get(0);
5295                    }
5296    
5297                    return null;
5298            }
5299    
5300            /**
5301             * 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;.
5302             *
5303             * @param threadId the primary key of the current message boards thread
5304             * @param groupId the group ID
5305             * @param categoryId the category ID
5306             * @param lastPostDate the last post date
5307             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5308             * @return the previous, current, and next message boards thread
5309             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5310             * @throws SystemException if a system exception occurred
5311             */
5312            public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
5313                    long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
5314                    throws NoSuchThreadException, SystemException {
5315                    MBThread mbThread = findByPrimaryKey(threadId);
5316    
5317                    Session session = null;
5318    
5319                    try {
5320                            session = openSession();
5321    
5322                            MBThread[] array = new MBThreadImpl[3];
5323    
5324                            array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5325                                            categoryId, lastPostDate, orderByComparator, true);
5326    
5327                            array[1] = mbThread;
5328    
5329                            array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5330                                            categoryId, lastPostDate, orderByComparator, false);
5331    
5332                            return array;
5333                    }
5334                    catch (Exception e) {
5335                            throw processException(e);
5336                    }
5337                    finally {
5338                            closeSession(session);
5339                    }
5340            }
5341    
5342            protected MBThread getByG_C_L_PrevAndNext(Session session,
5343                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5344                    OrderByComparator orderByComparator, boolean previous) {
5345                    StringBundler query = null;
5346    
5347                    if (orderByComparator != null) {
5348                            query = new StringBundler(6 +
5349                                            (orderByComparator.getOrderByFields().length * 6));
5350                    }
5351                    else {
5352                            query = new StringBundler(3);
5353                    }
5354    
5355                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
5356    
5357                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5358    
5359                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5360    
5361                    if (lastPostDate == null) {
5362                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5363                    }
5364                    else {
5365                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5366                    }
5367    
5368                    if (orderByComparator != null) {
5369                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5370    
5371                            if (orderByConditionFields.length > 0) {
5372                                    query.append(WHERE_AND);
5373                            }
5374    
5375                            for (int i = 0; i < orderByConditionFields.length; i++) {
5376                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5377                                    query.append(orderByConditionFields[i]);
5378    
5379                                    if ((i + 1) < orderByConditionFields.length) {
5380                                            if (orderByComparator.isAscending() ^ previous) {
5381                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5382                                            }
5383                                            else {
5384                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5385                                            }
5386                                    }
5387                                    else {
5388                                            if (orderByComparator.isAscending() ^ previous) {
5389                                                    query.append(WHERE_GREATER_THAN);
5390                                            }
5391                                            else {
5392                                                    query.append(WHERE_LESSER_THAN);
5393                                            }
5394                                    }
5395                            }
5396    
5397                            query.append(ORDER_BY_CLAUSE);
5398    
5399                            String[] orderByFields = orderByComparator.getOrderByFields();
5400    
5401                            for (int i = 0; i < orderByFields.length; i++) {
5402                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5403                                    query.append(orderByFields[i]);
5404    
5405                                    if ((i + 1) < orderByFields.length) {
5406                                            if (orderByComparator.isAscending() ^ previous) {
5407                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5408                                            }
5409                                            else {
5410                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5411                                            }
5412                                    }
5413                                    else {
5414                                            if (orderByComparator.isAscending() ^ previous) {
5415                                                    query.append(ORDER_BY_ASC);
5416                                            }
5417                                            else {
5418                                                    query.append(ORDER_BY_DESC);
5419                                            }
5420                                    }
5421                            }
5422                    }
5423    
5424                    else {
5425                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5426                    }
5427    
5428                    String sql = query.toString();
5429    
5430                    Query q = session.createQuery(sql);
5431    
5432                    q.setFirstResult(0);
5433                    q.setMaxResults(2);
5434    
5435                    QueryPos qPos = QueryPos.getInstance(q);
5436    
5437                    qPos.add(groupId);
5438    
5439                    qPos.add(categoryId);
5440    
5441                    if (lastPostDate != null) {
5442                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5443                    }
5444    
5445                    if (orderByComparator != null) {
5446                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5447    
5448                            for (Object value : values) {
5449                                    qPos.add(value);
5450                            }
5451                    }
5452    
5453                    List<MBThread> list = q.list();
5454    
5455                    if (list.size() == 2) {
5456                            return list.get(1);
5457                    }
5458                    else {
5459                            return null;
5460                    }
5461            }
5462    
5463            /**
5464             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
5465             *
5466             * @param groupId the group ID
5467             * @param categoryId the category ID
5468             * @param lastPostDate the last post date
5469             * @return the matching message boards threads that the user has permission to view
5470             * @throws SystemException if a system exception occurred
5471             */
5472            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5473                    Date lastPostDate) throws SystemException {
5474                    return filterFindByG_C_L(groupId, categoryId, lastPostDate,
5475                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5476            }
5477    
5478            /**
5479             * 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;.
5480             *
5481             * <p>
5482             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5483             * </p>
5484             *
5485             * @param groupId the group ID
5486             * @param categoryId the category ID
5487             * @param lastPostDate the last post date
5488             * @param start the lower bound of the range of message boards threads
5489             * @param end the upper bound of the range of message boards threads (not inclusive)
5490             * @return the range of matching message boards threads that the user has permission to view
5491             * @throws SystemException if a system exception occurred
5492             */
5493            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5494                    Date lastPostDate, int start, int end) throws SystemException {
5495                    return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
5496                            null);
5497            }
5498    
5499            /**
5500             * 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;.
5501             *
5502             * <p>
5503             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5504             * </p>
5505             *
5506             * @param groupId the group ID
5507             * @param categoryId the category ID
5508             * @param lastPostDate the last post date
5509             * @param start the lower bound of the range of message boards threads
5510             * @param end the upper bound of the range of message boards threads (not inclusive)
5511             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5512             * @return the ordered range of matching message boards threads that the user has permission to view
5513             * @throws SystemException if a system exception occurred
5514             */
5515            public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5516                    Date lastPostDate, int start, int end,
5517                    OrderByComparator orderByComparator) throws SystemException {
5518                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5519                            return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
5520                                    orderByComparator);
5521                    }
5522    
5523                    StringBundler query = null;
5524    
5525                    if (orderByComparator != null) {
5526                            query = new StringBundler(5 +
5527                                            (orderByComparator.getOrderByFields().length * 3));
5528                    }
5529                    else {
5530                            query = new StringBundler(5);
5531                    }
5532    
5533                    if (getDB().isSupportsInlineDistinct()) {
5534                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5535                    }
5536                    else {
5537                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5538                    }
5539    
5540                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5541    
5542                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5543    
5544                    if (lastPostDate == null) {
5545                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5546                    }
5547                    else {
5548                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5549                    }
5550    
5551                    if (!getDB().isSupportsInlineDistinct()) {
5552                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5553                    }
5554    
5555                    if (orderByComparator != null) {
5556                            if (getDB().isSupportsInlineDistinct()) {
5557                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5558                                            orderByComparator);
5559                            }
5560                            else {
5561                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5562                                            orderByComparator);
5563                            }
5564                    }
5565    
5566                    else {
5567                            if (getDB().isSupportsInlineDistinct()) {
5568                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5569                            }
5570                            else {
5571                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5572                            }
5573                    }
5574    
5575                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5576                                    MBThread.class.getName(),
5577                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5578    
5579                    Session session = null;
5580    
5581                    try {
5582                            session = openSession();
5583    
5584                            SQLQuery q = session.createSQLQuery(sql);
5585    
5586                            if (getDB().isSupportsInlineDistinct()) {
5587                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5588                            }
5589                            else {
5590                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5591                            }
5592    
5593                            QueryPos qPos = QueryPos.getInstance(q);
5594    
5595                            qPos.add(groupId);
5596    
5597                            qPos.add(categoryId);
5598    
5599                            if (lastPostDate != null) {
5600                                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5601                            }
5602    
5603                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5604                    }
5605                    catch (Exception e) {
5606                            throw processException(e);
5607                    }
5608                    finally {
5609                            closeSession(session);
5610                    }
5611            }
5612    
5613            /**
5614             * 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;.
5615             *
5616             * @param threadId the primary key of the current message boards thread
5617             * @param groupId the group ID
5618             * @param categoryId the category ID
5619             * @param lastPostDate the last post date
5620             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5621             * @return the previous, current, and next message boards thread
5622             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
5623             * @throws SystemException if a system exception occurred
5624             */
5625            public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
5626                    long groupId, long categoryId, Date lastPostDate,
5627                    OrderByComparator orderByComparator)
5628                    throws NoSuchThreadException, SystemException {
5629                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5630                            return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
5631                                    lastPostDate, orderByComparator);
5632                    }
5633    
5634                    MBThread mbThread = findByPrimaryKey(threadId);
5635    
5636                    Session session = null;
5637    
5638                    try {
5639                            session = openSession();
5640    
5641                            MBThread[] array = new MBThreadImpl[3];
5642    
5643                            array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
5644                                            categoryId, lastPostDate, orderByComparator, true);
5645    
5646                            array[1] = mbThread;
5647    
5648                            array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
5649                                            categoryId, lastPostDate, orderByComparator, false);
5650    
5651                            return array;
5652                    }
5653                    catch (Exception e) {
5654                            throw processException(e);
5655                    }
5656                    finally {
5657                            closeSession(session);
5658                    }
5659            }
5660    
5661            protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
5662                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5663                    OrderByComparator orderByComparator, boolean previous) {
5664                    StringBundler query = null;
5665    
5666                    if (orderByComparator != null) {
5667                            query = new StringBundler(6 +
5668                                            (orderByComparator.getOrderByFields().length * 6));
5669                    }
5670                    else {
5671                            query = new StringBundler(3);
5672                    }
5673    
5674                    if (getDB().isSupportsInlineDistinct()) {
5675                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5676                    }
5677                    else {
5678                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5679                    }
5680    
5681                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5682    
5683                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5684    
5685                    if (lastPostDate == null) {
5686                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5687                    }
5688                    else {
5689                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5690                    }
5691    
5692                    if (!getDB().isSupportsInlineDistinct()) {
5693                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5694                    }
5695    
5696                    if (orderByComparator != null) {
5697                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5698    
5699                            if (orderByConditionFields.length > 0) {
5700                                    query.append(WHERE_AND);
5701                            }
5702    
5703                            for (int i = 0; i < orderByConditionFields.length; i++) {
5704                                    if (getDB().isSupportsInlineDistinct()) {
5705                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5706                                    }
5707                                    else {
5708                                            query.append(_ORDER_BY_ENTITY_TABLE);
5709                                    }
5710    
5711                                    query.append(orderByConditionFields[i]);
5712    
5713                                    if ((i + 1) < orderByConditionFields.length) {
5714                                            if (orderByComparator.isAscending() ^ previous) {
5715                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5716                                            }
5717                                            else {
5718                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5719                                            }
5720                                    }
5721                                    else {
5722                                            if (orderByComparator.isAscending() ^ previous) {
5723                                                    query.append(WHERE_GREATER_THAN);
5724                                            }
5725                                            else {
5726                                                    query.append(WHERE_LESSER_THAN);
5727                                            }
5728                                    }
5729                            }
5730    
5731                            query.append(ORDER_BY_CLAUSE);
5732    
5733                            String[] orderByFields = orderByComparator.getOrderByFields();
5734    
5735                            for (int i = 0; i < orderByFields.length; i++) {
5736                                    if (getDB().isSupportsInlineDistinct()) {
5737                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5738                                    }
5739                                    else {
5740                                            query.append(_ORDER_BY_ENTITY_TABLE);
5741                                    }
5742    
5743                                    query.append(orderByFields[i]);
5744    
5745                                    if ((i + 1) < orderByFields.length) {
5746                                            if (orderByComparator.isAscending() ^ previous) {
5747                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5748                                            }
5749                                            else {
5750                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5751                                            }
5752                                    }
5753                                    else {
5754                                            if (orderByComparator.isAscending() ^ previous) {
5755                                                    query.append(ORDER_BY_ASC);
5756                                            }
5757                                            else {
5758                                                    query.append(ORDER_BY_DESC);
5759                                            }
5760                                    }
5761                            }
5762                    }
5763    
5764                    else {
5765                            if (getDB().isSupportsInlineDistinct()) {
5766                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5767                            }
5768                            else {
5769                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
5770                            }
5771                    }
5772    
5773                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5774                                    MBThread.class.getName(),
5775                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5776    
5777                    SQLQuery q = session.createSQLQuery(sql);
5778    
5779                    q.setFirstResult(0);
5780                    q.setMaxResults(2);
5781    
5782                    if (getDB().isSupportsInlineDistinct()) {
5783                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5784                    }
5785                    else {
5786                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5787                    }
5788    
5789                    QueryPos qPos = QueryPos.getInstance(q);
5790    
5791                    qPos.add(groupId);
5792    
5793                    qPos.add(categoryId);
5794    
5795                    if (lastPostDate != null) {
5796                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5797                    }
5798    
5799                    if (orderByComparator != null) {
5800                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5801    
5802                            for (Object value : values) {
5803                                    qPos.add(value);
5804                            }
5805                    }
5806    
5807                    List<MBThread> list = q.list();
5808    
5809                    if (list.size() == 2) {
5810                            return list.get(1);
5811                    }
5812                    else {
5813                            return null;
5814                    }
5815            }
5816    
5817            /**
5818             * Returns all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
5819             *
5820             * @param groupId the group ID
5821             * @param categoryId the category ID
5822             * @param status the status
5823             * @return the matching message boards threads
5824             * @throws SystemException if a system exception occurred
5825             */
5826            public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
5827                    throws SystemException {
5828                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
5829                            QueryUtil.ALL_POS, null);
5830            }
5831    
5832            /**
5833             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
5834             *
5835             * <p>
5836             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5837             * </p>
5838             *
5839             * @param groupId the group ID
5840             * @param categoryId the category ID
5841             * @param status the status
5842             * @param start the lower bound of the range of message boards threads
5843             * @param end the upper bound of the range of message boards threads (not inclusive)
5844             * @return the range of matching message boards threads
5845             * @throws SystemException if a system exception occurred
5846             */
5847            public List<MBThread> findByG_C_S(long groupId, long categoryId,
5848                    int status, int start, int end) throws SystemException {
5849                    return findByG_C_S(groupId, categoryId, status, start, end, null);
5850            }
5851    
5852            /**
5853             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
5854             *
5855             * <p>
5856             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
5857             * </p>
5858             *
5859             * @param groupId the group ID
5860             * @param categoryId the category ID
5861             * @param status the status
5862             * @param start the lower bound of the range of message boards threads
5863             * @param end the upper bound of the range of message boards threads (not inclusive)
5864             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5865             * @return the ordered range of matching message boards threads
5866             * @throws SystemException if a system exception occurred
5867             */
5868            public List<MBThread> findByG_C_S(long groupId, long categoryId,
5869                    int status, int start, int end, OrderByComparator orderByComparator)
5870                    throws SystemException {
5871                    FinderPath finderPath = null;
5872                    Object[] finderArgs = null;
5873    
5874                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5875                                    (orderByComparator == null)) {
5876                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
5877                            finderArgs = new Object[] { groupId, categoryId, status };
5878                    }
5879                    else {
5880                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
5881                            finderArgs = new Object[] {
5882                                            groupId, categoryId, status,
5883                                            
5884                                            start, end, orderByComparator
5885                                    };
5886                    }
5887    
5888                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5889                                    finderArgs, this);
5890    
5891                    if ((list != null) && !list.isEmpty()) {
5892                            for (MBThread mbThread : list) {
5893                                    if ((groupId != mbThread.getGroupId()) ||
5894                                                    (categoryId != mbThread.getCategoryId()) ||
5895                                                    (status != mbThread.getStatus())) {
5896                                            list = null;
5897    
5898                                            break;
5899                                    }
5900                            }
5901                    }
5902    
5903                    if (list == null) {
5904                            StringBundler query = null;
5905    
5906                            if (orderByComparator != null) {
5907                                    query = new StringBundler(5 +
5908                                                    (orderByComparator.getOrderByFields().length * 3));
5909                            }
5910                            else {
5911                                    query = new StringBundler(5);
5912                            }
5913    
5914                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
5915    
5916                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
5917    
5918                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
5919    
5920                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
5921    
5922                            if (orderByComparator != null) {
5923                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5924                                            orderByComparator);
5925                            }
5926    
5927                            else {
5928                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5929                            }
5930    
5931                            String sql = query.toString();
5932    
5933                            Session session = null;
5934    
5935                            try {
5936                                    session = openSession();
5937    
5938                                    Query q = session.createQuery(sql);
5939    
5940                                    QueryPos qPos = QueryPos.getInstance(q);
5941    
5942                                    qPos.add(groupId);
5943    
5944                                    qPos.add(categoryId);
5945    
5946                                    qPos.add(status);
5947    
5948                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
5949                                                    end);
5950                            }
5951                            catch (Exception e) {
5952                                    throw processException(e);
5953                            }
5954                            finally {
5955                                    if (list == null) {
5956                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
5957                                    }
5958                                    else {
5959                                            cacheResult(list);
5960    
5961                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
5962                                    }
5963    
5964                                    closeSession(session);
5965                            }
5966                    }
5967    
5968                    return list;
5969            }
5970    
5971            /**
5972             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
5973             *
5974             * @param groupId the group ID
5975             * @param categoryId the category ID
5976             * @param status the status
5977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5978             * @return the first matching message boards thread
5979             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
5980             * @throws SystemException if a system exception occurred
5981             */
5982            public MBThread findByG_C_S_First(long groupId, long categoryId,
5983                    int status, OrderByComparator orderByComparator)
5984                    throws NoSuchThreadException, SystemException {
5985                    MBThread mbThread = fetchByG_C_S_First(groupId, categoryId, status,
5986                                    orderByComparator);
5987    
5988                    if (mbThread != null) {
5989                            return mbThread;
5990                    }
5991    
5992                    StringBundler msg = new StringBundler(8);
5993    
5994                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5995    
5996                    msg.append("groupId=");
5997                    msg.append(groupId);
5998    
5999                    msg.append(", categoryId=");
6000                    msg.append(categoryId);
6001    
6002                    msg.append(", status=");
6003                    msg.append(status);
6004    
6005                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6006    
6007                    throw new NoSuchThreadException(msg.toString());
6008            }
6009    
6010            /**
6011             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
6012             *
6013             * @param groupId the group ID
6014             * @param categoryId the category ID
6015             * @param status the status
6016             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6017             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6018             * @throws SystemException if a system exception occurred
6019             */
6020            public MBThread fetchByG_C_S_First(long groupId, long categoryId,
6021                    int status, OrderByComparator orderByComparator)
6022                    throws SystemException {
6023                    List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
6024                                    orderByComparator);
6025    
6026                    if (!list.isEmpty()) {
6027                            return list.get(0);
6028                    }
6029    
6030                    return null;
6031            }
6032    
6033            /**
6034             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
6035             *
6036             * @param groupId the group ID
6037             * @param categoryId the category ID
6038             * @param status the status
6039             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6040             * @return the last matching message boards thread
6041             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
6042             * @throws SystemException if a system exception occurred
6043             */
6044            public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
6045                    OrderByComparator orderByComparator)
6046                    throws NoSuchThreadException, SystemException {
6047                    MBThread mbThread = fetchByG_C_S_Last(groupId, categoryId, status,
6048                                    orderByComparator);
6049    
6050                    if (mbThread != null) {
6051                            return mbThread;
6052                    }
6053    
6054                    StringBundler msg = new StringBundler(8);
6055    
6056                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6057    
6058                    msg.append("groupId=");
6059                    msg.append(groupId);
6060    
6061                    msg.append(", categoryId=");
6062                    msg.append(categoryId);
6063    
6064                    msg.append(", status=");
6065                    msg.append(status);
6066    
6067                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6068    
6069                    throw new NoSuchThreadException(msg.toString());
6070            }
6071    
6072            /**
6073             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
6074             *
6075             * @param groupId the group ID
6076             * @param categoryId the category ID
6077             * @param status the status
6078             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6079             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
6080             * @throws SystemException if a system exception occurred
6081             */
6082            public MBThread fetchByG_C_S_Last(long groupId, long categoryId,
6083                    int status, OrderByComparator orderByComparator)
6084                    throws SystemException {
6085                    int count = countByG_C_S(groupId, categoryId, status);
6086    
6087                    List<MBThread> list = findByG_C_S(groupId, categoryId, status,
6088                                    count - 1, count, orderByComparator);
6089    
6090                    if (!list.isEmpty()) {
6091                            return list.get(0);
6092                    }
6093    
6094                    return null;
6095            }
6096    
6097            /**
6098             * 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;.
6099             *
6100             * @param threadId the primary key of the current message boards thread
6101             * @param groupId the group ID
6102             * @param categoryId the category ID
6103             * @param status the status
6104             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6105             * @return the previous, current, and next message boards thread
6106             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
6107             * @throws SystemException if a system exception occurred
6108             */
6109            public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
6110                    long categoryId, int status, OrderByComparator orderByComparator)
6111                    throws NoSuchThreadException, SystemException {
6112                    MBThread mbThread = findByPrimaryKey(threadId);
6113    
6114                    Session session = null;
6115    
6116                    try {
6117                            session = openSession();
6118    
6119                            MBThread[] array = new MBThreadImpl[3];
6120    
6121                            array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
6122                                            categoryId, status, orderByComparator, true);
6123    
6124                            array[1] = mbThread;
6125    
6126                            array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
6127                                            categoryId, status, orderByComparator, false);
6128    
6129                            return array;
6130                    }
6131                    catch (Exception e) {
6132                            throw processException(e);
6133                    }
6134                    finally {
6135                            closeSession(session);
6136                    }
6137            }
6138    
6139            protected MBThread getByG_C_S_PrevAndNext(Session session,
6140                    MBThread mbThread, long groupId, long categoryId, int status,
6141                    OrderByComparator orderByComparator, boolean previous) {
6142                    StringBundler query = null;
6143    
6144                    if (orderByComparator != null) {
6145                            query = new StringBundler(6 +
6146                                            (orderByComparator.getOrderByFields().length * 6));
6147                    }
6148                    else {
6149                            query = new StringBundler(3);
6150                    }
6151    
6152                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
6153    
6154                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6155    
6156                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6157    
6158                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6159    
6160                    if (orderByComparator != null) {
6161                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6162    
6163                            if (orderByConditionFields.length > 0) {
6164                                    query.append(WHERE_AND);
6165                            }
6166    
6167                            for (int i = 0; i < orderByConditionFields.length; i++) {
6168                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6169                                    query.append(orderByConditionFields[i]);
6170    
6171                                    if ((i + 1) < orderByConditionFields.length) {
6172                                            if (orderByComparator.isAscending() ^ previous) {
6173                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6174                                            }
6175                                            else {
6176                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6177                                            }
6178                                    }
6179                                    else {
6180                                            if (orderByComparator.isAscending() ^ previous) {
6181                                                    query.append(WHERE_GREATER_THAN);
6182                                            }
6183                                            else {
6184                                                    query.append(WHERE_LESSER_THAN);
6185                                            }
6186                                    }
6187                            }
6188    
6189                            query.append(ORDER_BY_CLAUSE);
6190    
6191                            String[] orderByFields = orderByComparator.getOrderByFields();
6192    
6193                            for (int i = 0; i < orderByFields.length; i++) {
6194                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6195                                    query.append(orderByFields[i]);
6196    
6197                                    if ((i + 1) < orderByFields.length) {
6198                                            if (orderByComparator.isAscending() ^ previous) {
6199                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6200                                            }
6201                                            else {
6202                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6203                                            }
6204                                    }
6205                                    else {
6206                                            if (orderByComparator.isAscending() ^ previous) {
6207                                                    query.append(ORDER_BY_ASC);
6208                                            }
6209                                            else {
6210                                                    query.append(ORDER_BY_DESC);
6211                                            }
6212                                    }
6213                            }
6214                    }
6215    
6216                    else {
6217                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6218                    }
6219    
6220                    String sql = query.toString();
6221    
6222                    Query q = session.createQuery(sql);
6223    
6224                    q.setFirstResult(0);
6225                    q.setMaxResults(2);
6226    
6227                    QueryPos qPos = QueryPos.getInstance(q);
6228    
6229                    qPos.add(groupId);
6230    
6231                    qPos.add(categoryId);
6232    
6233                    qPos.add(status);
6234    
6235                    if (orderByComparator != null) {
6236                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6237    
6238                            for (Object value : values) {
6239                                    qPos.add(value);
6240                            }
6241                    }
6242    
6243                    List<MBThread> list = q.list();
6244    
6245                    if (list.size() == 2) {
6246                            return list.get(1);
6247                    }
6248                    else {
6249                            return null;
6250                    }
6251            }
6252    
6253            /**
6254             * Returns all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
6255             *
6256             * <p>
6257             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6258             * </p>
6259             *
6260             * @param groupId the group ID
6261             * @param categoryIds the category IDs
6262             * @param status the status
6263             * @return the matching message boards threads
6264             * @throws SystemException if a system exception occurred
6265             */
6266            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6267                    int status) throws SystemException {
6268                    return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
6269                            QueryUtil.ALL_POS, null);
6270            }
6271    
6272            /**
6273             * Returns a range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
6274             *
6275             * <p>
6276             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6277             * </p>
6278             *
6279             * @param groupId the group ID
6280             * @param categoryIds the category IDs
6281             * @param status the status
6282             * @param start the lower bound of the range of message boards threads
6283             * @param end the upper bound of the range of message boards threads (not inclusive)
6284             * @return the range of matching message boards threads
6285             * @throws SystemException if a system exception occurred
6286             */
6287            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6288                    int status, int start, int end) throws SystemException {
6289                    return findByG_C_S(groupId, categoryIds, status, start, end, null);
6290            }
6291    
6292            /**
6293             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
6294             *
6295             * <p>
6296             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6297             * </p>
6298             *
6299             * @param groupId the group ID
6300             * @param categoryIds the category IDs
6301             * @param status the status
6302             * @param start the lower bound of the range of message boards threads
6303             * @param end the upper bound of the range of message boards threads (not inclusive)
6304             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6305             * @return the ordered range of matching message boards threads
6306             * @throws SystemException if a system exception occurred
6307             */
6308            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
6309                    int status, int start, int end, OrderByComparator orderByComparator)
6310                    throws SystemException {
6311                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
6312                    Object[] finderArgs = null;
6313    
6314                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6315                                    (orderByComparator == null)) {
6316                            finderArgs = new Object[] {
6317                                            groupId, StringUtil.merge(categoryIds), status
6318                                    };
6319                    }
6320                    else {
6321                            finderArgs = new Object[] {
6322                                            groupId, StringUtil.merge(categoryIds), status,
6323                                            
6324                                            start, end, orderByComparator
6325                                    };
6326                    }
6327    
6328                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6329                                    finderArgs, this);
6330    
6331                    if ((list != null) && !list.isEmpty()) {
6332                            for (MBThread mbThread : list) {
6333                                    if ((groupId != mbThread.getGroupId()) ||
6334                                                    !ArrayUtil.contains(categoryIds,
6335                                                            mbThread.getCategoryId()) ||
6336                                                    (status != mbThread.getStatus())) {
6337                                            list = null;
6338    
6339                                            break;
6340                                    }
6341                            }
6342                    }
6343    
6344                    if (list == null) {
6345                            StringBundler query = new StringBundler();
6346    
6347                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
6348    
6349                            boolean conjunctionable = false;
6350    
6351                            if (conjunctionable) {
6352                                    query.append(WHERE_AND);
6353                            }
6354    
6355                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
6356    
6357                            conjunctionable = true;
6358    
6359                            if ((categoryIds == null) || (categoryIds.length > 0)) {
6360                                    if (conjunctionable) {
6361                                            query.append(WHERE_AND);
6362                                    }
6363    
6364                                    query.append(StringPool.OPEN_PARENTHESIS);
6365    
6366                                    for (int i = 0; i < categoryIds.length; i++) {
6367                                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
6368    
6369                                            if ((i + 1) < categoryIds.length) {
6370                                                    query.append(WHERE_OR);
6371                                            }
6372                                    }
6373    
6374                                    query.append(StringPool.CLOSE_PARENTHESIS);
6375    
6376                                    conjunctionable = true;
6377                            }
6378    
6379                            if (conjunctionable) {
6380                                    query.append(WHERE_AND);
6381                            }
6382    
6383                            query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
6384    
6385                            conjunctionable = true;
6386    
6387                            if (orderByComparator != null) {
6388                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6389                                            orderByComparator);
6390                            }
6391    
6392                            else {
6393                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6394                            }
6395    
6396                            String sql = query.toString();
6397    
6398                            Session session = null;
6399    
6400                            try {
6401                                    session = openSession();
6402    
6403                                    Query q = session.createQuery(sql);
6404    
6405                                    QueryPos qPos = QueryPos.getInstance(q);
6406    
6407                                    qPos.add(groupId);
6408    
6409                                    if (categoryIds != null) {
6410                                            qPos.add(categoryIds);
6411                                    }
6412    
6413                                    qPos.add(status);
6414    
6415                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
6416                                                    end);
6417                            }
6418                            catch (Exception e) {
6419                                    throw processException(e);
6420                            }
6421                            finally {
6422                                    if (list == null) {
6423                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
6424                                    }
6425                                    else {
6426                                            cacheResult(list);
6427    
6428                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
6429                                    }
6430    
6431                                    closeSession(session);
6432                            }
6433                    }
6434    
6435                    return list;
6436            }
6437    
6438            /**
6439             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
6440             *
6441             * @param groupId the group ID
6442             * @param categoryId the category ID
6443             * @param status the status
6444             * @return the matching message boards threads that the user has permission to view
6445             * @throws SystemException if a system exception occurred
6446             */
6447            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6448                    int status) throws SystemException {
6449                    return filterFindByG_C_S(groupId, categoryId, status,
6450                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6451            }
6452    
6453            /**
6454             * 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;.
6455             *
6456             * <p>
6457             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6458             * </p>
6459             *
6460             * @param groupId the group ID
6461             * @param categoryId the category ID
6462             * @param status the status
6463             * @param start the lower bound of the range of message boards threads
6464             * @param end the upper bound of the range of message boards threads (not inclusive)
6465             * @return the range of matching message boards threads that the user has permission to view
6466             * @throws SystemException if a system exception occurred
6467             */
6468            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6469                    int status, int start, int end) throws SystemException {
6470                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
6471            }
6472    
6473            /**
6474             * 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;.
6475             *
6476             * <p>
6477             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6478             * </p>
6479             *
6480             * @param groupId the group ID
6481             * @param categoryId the category ID
6482             * @param status the status
6483             * @param start the lower bound of the range of message boards threads
6484             * @param end the upper bound of the range of message boards threads (not inclusive)
6485             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6486             * @return the ordered range of matching message boards threads that the user has permission to view
6487             * @throws SystemException if a system exception occurred
6488             */
6489            public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6490                    int status, int start, int end, OrderByComparator orderByComparator)
6491                    throws SystemException {
6492                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6493                            return findByG_C_S(groupId, categoryId, status, start, end,
6494                                    orderByComparator);
6495                    }
6496    
6497                    StringBundler query = null;
6498    
6499                    if (orderByComparator != null) {
6500                            query = new StringBundler(5 +
6501                                            (orderByComparator.getOrderByFields().length * 3));
6502                    }
6503                    else {
6504                            query = new StringBundler(5);
6505                    }
6506    
6507                    if (getDB().isSupportsInlineDistinct()) {
6508                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6509                    }
6510                    else {
6511                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6512                    }
6513    
6514                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6515    
6516                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6517    
6518                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6519    
6520                    if (!getDB().isSupportsInlineDistinct()) {
6521                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6522                    }
6523    
6524                    if (orderByComparator != null) {
6525                            if (getDB().isSupportsInlineDistinct()) {
6526                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6527                                            orderByComparator);
6528                            }
6529                            else {
6530                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6531                                            orderByComparator);
6532                            }
6533                    }
6534    
6535                    else {
6536                            if (getDB().isSupportsInlineDistinct()) {
6537                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6538                            }
6539                            else {
6540                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
6541                            }
6542                    }
6543    
6544                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6545                                    MBThread.class.getName(),
6546                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6547    
6548                    Session session = null;
6549    
6550                    try {
6551                            session = openSession();
6552    
6553                            SQLQuery q = session.createSQLQuery(sql);
6554    
6555                            if (getDB().isSupportsInlineDistinct()) {
6556                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6557                            }
6558                            else {
6559                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6560                            }
6561    
6562                            QueryPos qPos = QueryPos.getInstance(q);
6563    
6564                            qPos.add(groupId);
6565    
6566                            qPos.add(categoryId);
6567    
6568                            qPos.add(status);
6569    
6570                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6571                    }
6572                    catch (Exception e) {
6573                            throw processException(e);
6574                    }
6575                    finally {
6576                            closeSession(session);
6577                    }
6578            }
6579    
6580            /**
6581             * 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;.
6582             *
6583             * @param threadId the primary key of the current message boards thread
6584             * @param groupId the group ID
6585             * @param categoryId the category ID
6586             * @param status the status
6587             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6588             * @return the previous, current, and next message boards thread
6589             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
6590             * @throws SystemException if a system exception occurred
6591             */
6592            public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
6593                    long groupId, long categoryId, int status,
6594                    OrderByComparator orderByComparator)
6595                    throws NoSuchThreadException, SystemException {
6596                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6597                            return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
6598                                    status, orderByComparator);
6599                    }
6600    
6601                    MBThread mbThread = findByPrimaryKey(threadId);
6602    
6603                    Session session = null;
6604    
6605                    try {
6606                            session = openSession();
6607    
6608                            MBThread[] array = new MBThreadImpl[3];
6609    
6610                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
6611                                            categoryId, status, orderByComparator, true);
6612    
6613                            array[1] = mbThread;
6614    
6615                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
6616                                            categoryId, status, orderByComparator, false);
6617    
6618                            return array;
6619                    }
6620                    catch (Exception e) {
6621                            throw processException(e);
6622                    }
6623                    finally {
6624                            closeSession(session);
6625                    }
6626            }
6627    
6628            protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
6629                    MBThread mbThread, long groupId, long categoryId, int status,
6630                    OrderByComparator orderByComparator, boolean previous) {
6631                    StringBundler query = null;
6632    
6633                    if (orderByComparator != null) {
6634                            query = new StringBundler(6 +
6635                                            (orderByComparator.getOrderByFields().length * 6));
6636                    }
6637                    else {
6638                            query = new StringBundler(3);
6639                    }
6640    
6641                    if (getDB().isSupportsInlineDistinct()) {
6642                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6643                    }
6644                    else {
6645                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6646                    }
6647    
6648                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6649    
6650                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6651    
6652                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6653    
6654                    if (!getDB().isSupportsInlineDistinct()) {
6655                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6656                    }
6657    
6658                    if (orderByComparator != null) {
6659                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6660    
6661                            if (orderByConditionFields.length > 0) {
6662                                    query.append(WHERE_AND);
6663                            }
6664    
6665                            for (int i = 0; i < orderByConditionFields.length; i++) {
6666                                    if (getDB().isSupportsInlineDistinct()) {
6667                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6668                                    }
6669                                    else {
6670                                            query.append(_ORDER_BY_ENTITY_TABLE);
6671                                    }
6672    
6673                                    query.append(orderByConditionFields[i]);
6674    
6675                                    if ((i + 1) < orderByConditionFields.length) {
6676                                            if (orderByComparator.isAscending() ^ previous) {
6677                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6678                                            }
6679                                            else {
6680                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6681                                            }
6682                                    }
6683                                    else {
6684                                            if (orderByComparator.isAscending() ^ previous) {
6685                                                    query.append(WHERE_GREATER_THAN);
6686                                            }
6687                                            else {
6688                                                    query.append(WHERE_LESSER_THAN);
6689                                            }
6690                                    }
6691                            }
6692    
6693                            query.append(ORDER_BY_CLAUSE);
6694    
6695                            String[] orderByFields = orderByComparator.getOrderByFields();
6696    
6697                            for (int i = 0; i < orderByFields.length; i++) {
6698                                    if (getDB().isSupportsInlineDistinct()) {
6699                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6700                                    }
6701                                    else {
6702                                            query.append(_ORDER_BY_ENTITY_TABLE);
6703                                    }
6704    
6705                                    query.append(orderByFields[i]);
6706    
6707                                    if ((i + 1) < orderByFields.length) {
6708                                            if (orderByComparator.isAscending() ^ previous) {
6709                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6710                                            }
6711                                            else {
6712                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6713                                            }
6714                                    }
6715                                    else {
6716                                            if (orderByComparator.isAscending() ^ previous) {
6717                                                    query.append(ORDER_BY_ASC);
6718                                            }
6719                                            else {
6720                                                    query.append(ORDER_BY_DESC);
6721                                            }
6722                                    }
6723                            }
6724                    }
6725    
6726                    else {
6727                            if (getDB().isSupportsInlineDistinct()) {
6728                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6729                            }
6730                            else {
6731                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
6732                            }
6733                    }
6734    
6735                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6736                                    MBThread.class.getName(),
6737                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6738    
6739                    SQLQuery q = session.createSQLQuery(sql);
6740    
6741                    q.setFirstResult(0);
6742                    q.setMaxResults(2);
6743    
6744                    if (getDB().isSupportsInlineDistinct()) {
6745                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6746                    }
6747                    else {
6748                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6749                    }
6750    
6751                    QueryPos qPos = QueryPos.getInstance(q);
6752    
6753                    qPos.add(groupId);
6754    
6755                    qPos.add(categoryId);
6756    
6757                    qPos.add(status);
6758    
6759                    if (orderByComparator != null) {
6760                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6761    
6762                            for (Object value : values) {
6763                                    qPos.add(value);
6764                            }
6765                    }
6766    
6767                    List<MBThread> list = q.list();
6768    
6769                    if (list.size() == 2) {
6770                            return list.get(1);
6771                    }
6772                    else {
6773                            return null;
6774                    }
6775            }
6776    
6777            /**
6778             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
6779             *
6780             * @param groupId the group ID
6781             * @param categoryIds the category IDs
6782             * @param status the status
6783             * @return the matching message boards threads that the user has permission to view
6784             * @throws SystemException if a system exception occurred
6785             */
6786            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6787                    int status) throws SystemException {
6788                    return filterFindByG_C_S(groupId, categoryIds, status,
6789                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6790            }
6791    
6792            /**
6793             * 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;.
6794             *
6795             * <p>
6796             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6797             * </p>
6798             *
6799             * @param groupId the group ID
6800             * @param categoryIds the category IDs
6801             * @param status the status
6802             * @param start the lower bound of the range of message boards threads
6803             * @param end the upper bound of the range of message boards threads (not inclusive)
6804             * @return the range of matching message boards threads that the user has permission to view
6805             * @throws SystemException if a system exception occurred
6806             */
6807            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6808                    int status, int start, int end) throws SystemException {
6809                    return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
6810            }
6811    
6812            /**
6813             * 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;.
6814             *
6815             * <p>
6816             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6817             * </p>
6818             *
6819             * @param groupId the group ID
6820             * @param categoryIds the category IDs
6821             * @param status the status
6822             * @param start the lower bound of the range of message boards threads
6823             * @param end the upper bound of the range of message boards threads (not inclusive)
6824             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6825             * @return the ordered range of matching message boards threads that the user has permission to view
6826             * @throws SystemException if a system exception occurred
6827             */
6828            public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
6829                    int status, int start, int end, OrderByComparator orderByComparator)
6830                    throws SystemException {
6831                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6832                            return findByG_C_S(groupId, categoryIds, status, start, end,
6833                                    orderByComparator);
6834                    }
6835    
6836                    StringBundler query = new StringBundler();
6837    
6838                    if (getDB().isSupportsInlineDistinct()) {
6839                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6840                    }
6841                    else {
6842                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6843                    }
6844    
6845                    boolean conjunctionable = false;
6846    
6847                    if (conjunctionable) {
6848                            query.append(WHERE_AND);
6849                    }
6850    
6851                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
6852    
6853                    conjunctionable = true;
6854    
6855                    if ((categoryIds == null) || (categoryIds.length > 0)) {
6856                            if (conjunctionable) {
6857                                    query.append(WHERE_AND);
6858                            }
6859    
6860                            query.append(StringPool.OPEN_PARENTHESIS);
6861    
6862                            for (int i = 0; i < categoryIds.length; i++) {
6863                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
6864    
6865                                    if ((i + 1) < categoryIds.length) {
6866                                            query.append(WHERE_OR);
6867                                    }
6868                            }
6869    
6870                            query.append(StringPool.CLOSE_PARENTHESIS);
6871    
6872                            conjunctionable = true;
6873                    }
6874    
6875                    if (conjunctionable) {
6876                            query.append(WHERE_AND);
6877                    }
6878    
6879                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
6880    
6881                    conjunctionable = true;
6882    
6883                    if (!getDB().isSupportsInlineDistinct()) {
6884                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6885                    }
6886    
6887                    if (orderByComparator != null) {
6888                            if (getDB().isSupportsInlineDistinct()) {
6889                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6890                                            orderByComparator);
6891                            }
6892                            else {
6893                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6894                                            orderByComparator);
6895                            }
6896                    }
6897    
6898                    else {
6899                            if (getDB().isSupportsInlineDistinct()) {
6900                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6901                            }
6902                            else {
6903                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
6904                            }
6905                    }
6906    
6907                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6908                                    MBThread.class.getName(),
6909                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6910    
6911                    Session session = null;
6912    
6913                    try {
6914                            session = openSession();
6915    
6916                            SQLQuery q = session.createSQLQuery(sql);
6917    
6918                            if (getDB().isSupportsInlineDistinct()) {
6919                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6920                            }
6921                            else {
6922                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6923                            }
6924    
6925                            QueryPos qPos = QueryPos.getInstance(q);
6926    
6927                            qPos.add(groupId);
6928    
6929                            if (categoryIds != null) {
6930                                    qPos.add(categoryIds);
6931                            }
6932    
6933                            qPos.add(status);
6934    
6935                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6936                    }
6937                    catch (Exception e) {
6938                            throw processException(e);
6939                    }
6940                    finally {
6941                            closeSession(session);
6942                    }
6943            }
6944    
6945            /**
6946             * Returns all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
6947             *
6948             * @param groupId the group ID
6949             * @param categoryId the category ID
6950             * @param status the status
6951             * @return the matching message boards threads
6952             * @throws SystemException if a system exception occurred
6953             */
6954            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6955                    int status) throws SystemException {
6956                    return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
6957                            QueryUtil.ALL_POS, null);
6958            }
6959    
6960            /**
6961             * Returns a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
6962             *
6963             * <p>
6964             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6965             * </p>
6966             *
6967             * @param groupId the group ID
6968             * @param categoryId the category ID
6969             * @param status the status
6970             * @param start the lower bound of the range of message boards threads
6971             * @param end the upper bound of the range of message boards threads (not inclusive)
6972             * @return the range of matching message boards threads
6973             * @throws SystemException if a system exception occurred
6974             */
6975            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6976                    int status, int start, int end) throws SystemException {
6977                    return findByG_NotC_S(groupId, categoryId, status, start, end, null);
6978            }
6979    
6980            /**
6981             * Returns an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
6982             *
6983             * <p>
6984             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
6985             * </p>
6986             *
6987             * @param groupId the group ID
6988             * @param categoryId the category ID
6989             * @param status the status
6990             * @param start the lower bound of the range of message boards threads
6991             * @param end the upper bound of the range of message boards threads (not inclusive)
6992             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6993             * @return the ordered range of matching message boards threads
6994             * @throws SystemException if a system exception occurred
6995             */
6996            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
6997                    int status, int start, int end, OrderByComparator orderByComparator)
6998                    throws SystemException {
6999                    FinderPath finderPath = null;
7000                    Object[] finderArgs = null;
7001    
7002                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
7003                    finderArgs = new Object[] {
7004                                    groupId, categoryId, status,
7005                                    
7006                                    start, end, orderByComparator
7007                            };
7008    
7009                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7010                                    finderArgs, this);
7011    
7012                    if ((list != null) && !list.isEmpty()) {
7013                            for (MBThread mbThread : list) {
7014                                    if ((groupId != mbThread.getGroupId()) ||
7015                                                    (categoryId != mbThread.getCategoryId()) ||
7016                                                    (status != mbThread.getStatus())) {
7017                                            list = null;
7018    
7019                                            break;
7020                                    }
7021                            }
7022                    }
7023    
7024                    if (list == null) {
7025                            StringBundler query = null;
7026    
7027                            if (orderByComparator != null) {
7028                                    query = new StringBundler(5 +
7029                                                    (orderByComparator.getOrderByFields().length * 3));
7030                            }
7031                            else {
7032                                    query = new StringBundler(5);
7033                            }
7034    
7035                            query.append(_SQL_SELECT_MBTHREAD_WHERE);
7036    
7037                            query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7038    
7039                            query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7040    
7041                            query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7042    
7043                            if (orderByComparator != null) {
7044                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7045                                            orderByComparator);
7046                            }
7047    
7048                            else {
7049                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7050                            }
7051    
7052                            String sql = query.toString();
7053    
7054                            Session session = null;
7055    
7056                            try {
7057                                    session = openSession();
7058    
7059                                    Query q = session.createQuery(sql);
7060    
7061                                    QueryPos qPos = QueryPos.getInstance(q);
7062    
7063                                    qPos.add(groupId);
7064    
7065                                    qPos.add(categoryId);
7066    
7067                                    qPos.add(status);
7068    
7069                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
7070                                                    end);
7071                            }
7072                            catch (Exception e) {
7073                                    throw processException(e);
7074                            }
7075                            finally {
7076                                    if (list == null) {
7077                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7078                                    }
7079                                    else {
7080                                            cacheResult(list);
7081    
7082                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7083                                    }
7084    
7085                                    closeSession(session);
7086                            }
7087                    }
7088    
7089                    return list;
7090            }
7091    
7092            /**
7093             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
7094             *
7095             * @param groupId the group ID
7096             * @param categoryId the category ID
7097             * @param status the status
7098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7099             * @return the first matching message boards thread
7100             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
7101             * @throws SystemException if a system exception occurred
7102             */
7103            public MBThread findByG_NotC_S_First(long groupId, long categoryId,
7104                    int status, OrderByComparator orderByComparator)
7105                    throws NoSuchThreadException, SystemException {
7106                    MBThread mbThread = fetchByG_NotC_S_First(groupId, categoryId, status,
7107                                    orderByComparator);
7108    
7109                    if (mbThread != null) {
7110                            return mbThread;
7111                    }
7112    
7113                    StringBundler msg = new StringBundler(8);
7114    
7115                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7116    
7117                    msg.append("groupId=");
7118                    msg.append(groupId);
7119    
7120                    msg.append(", categoryId=");
7121                    msg.append(categoryId);
7122    
7123                    msg.append(", status=");
7124                    msg.append(status);
7125    
7126                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7127    
7128                    throw new NoSuchThreadException(msg.toString());
7129            }
7130    
7131            /**
7132             * Returns the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
7133             *
7134             * @param groupId the group ID
7135             * @param categoryId the category ID
7136             * @param status the status
7137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7138             * @return the first matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
7139             * @throws SystemException if a system exception occurred
7140             */
7141            public MBThread fetchByG_NotC_S_First(long groupId, long categoryId,
7142                    int status, OrderByComparator orderByComparator)
7143                    throws SystemException {
7144                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
7145                                    orderByComparator);
7146    
7147                    if (!list.isEmpty()) {
7148                            return list.get(0);
7149                    }
7150    
7151                    return null;
7152            }
7153    
7154            /**
7155             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
7156             *
7157             * @param groupId the group ID
7158             * @param categoryId the category ID
7159             * @param status the status
7160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7161             * @return the last matching message boards thread
7162             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
7163             * @throws SystemException if a system exception occurred
7164             */
7165            public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
7166                    int status, OrderByComparator orderByComparator)
7167                    throws NoSuchThreadException, SystemException {
7168                    MBThread mbThread = fetchByG_NotC_S_Last(groupId, categoryId, status,
7169                                    orderByComparator);
7170    
7171                    if (mbThread != null) {
7172                            return mbThread;
7173                    }
7174    
7175                    StringBundler msg = new StringBundler(8);
7176    
7177                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7178    
7179                    msg.append("groupId=");
7180                    msg.append(groupId);
7181    
7182                    msg.append(", categoryId=");
7183                    msg.append(categoryId);
7184    
7185                    msg.append(", status=");
7186                    msg.append(status);
7187    
7188                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7189    
7190                    throw new NoSuchThreadException(msg.toString());
7191            }
7192    
7193            /**
7194             * Returns the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
7195             *
7196             * @param groupId the group ID
7197             * @param categoryId the category ID
7198             * @param status the status
7199             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7200             * @return the last matching message boards thread, or <code>null</code> if a matching message boards thread could not be found
7201             * @throws SystemException if a system exception occurred
7202             */
7203            public MBThread fetchByG_NotC_S_Last(long groupId, long categoryId,
7204                    int status, OrderByComparator orderByComparator)
7205                    throws SystemException {
7206                    int count = countByG_NotC_S(groupId, categoryId, status);
7207    
7208                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
7209                                    count - 1, count, orderByComparator);
7210    
7211                    if (!list.isEmpty()) {
7212                            return list.get(0);
7213                    }
7214    
7215                    return null;
7216            }
7217    
7218            /**
7219             * 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;.
7220             *
7221             * @param threadId the primary key of the current message boards thread
7222             * @param groupId the group ID
7223             * @param categoryId the category ID
7224             * @param status the status
7225             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7226             * @return the previous, current, and next message boards thread
7227             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
7228             * @throws SystemException if a system exception occurred
7229             */
7230            public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
7231                    long categoryId, int status, OrderByComparator orderByComparator)
7232                    throws NoSuchThreadException, SystemException {
7233                    MBThread mbThread = findByPrimaryKey(threadId);
7234    
7235                    Session session = null;
7236    
7237                    try {
7238                            session = openSession();
7239    
7240                            MBThread[] array = new MBThreadImpl[3];
7241    
7242                            array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
7243                                            categoryId, status, orderByComparator, true);
7244    
7245                            array[1] = mbThread;
7246    
7247                            array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
7248                                            categoryId, status, orderByComparator, false);
7249    
7250                            return array;
7251                    }
7252                    catch (Exception e) {
7253                            throw processException(e);
7254                    }
7255                    finally {
7256                            closeSession(session);
7257                    }
7258            }
7259    
7260            protected MBThread getByG_NotC_S_PrevAndNext(Session session,
7261                    MBThread mbThread, long groupId, long categoryId, int status,
7262                    OrderByComparator orderByComparator, boolean previous) {
7263                    StringBundler query = null;
7264    
7265                    if (orderByComparator != null) {
7266                            query = new StringBundler(6 +
7267                                            (orderByComparator.getOrderByFields().length * 6));
7268                    }
7269                    else {
7270                            query = new StringBundler(3);
7271                    }
7272    
7273                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
7274    
7275                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7276    
7277                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7278    
7279                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7280    
7281                    if (orderByComparator != null) {
7282                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7283    
7284                            if (orderByConditionFields.length > 0) {
7285                                    query.append(WHERE_AND);
7286                            }
7287    
7288                            for (int i = 0; i < orderByConditionFields.length; i++) {
7289                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7290                                    query.append(orderByConditionFields[i]);
7291    
7292                                    if ((i + 1) < orderByConditionFields.length) {
7293                                            if (orderByComparator.isAscending() ^ previous) {
7294                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7295                                            }
7296                                            else {
7297                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7298                                            }
7299                                    }
7300                                    else {
7301                                            if (orderByComparator.isAscending() ^ previous) {
7302                                                    query.append(WHERE_GREATER_THAN);
7303                                            }
7304                                            else {
7305                                                    query.append(WHERE_LESSER_THAN);
7306                                            }
7307                                    }
7308                            }
7309    
7310                            query.append(ORDER_BY_CLAUSE);
7311    
7312                            String[] orderByFields = orderByComparator.getOrderByFields();
7313    
7314                            for (int i = 0; i < orderByFields.length; i++) {
7315                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7316                                    query.append(orderByFields[i]);
7317    
7318                                    if ((i + 1) < orderByFields.length) {
7319                                            if (orderByComparator.isAscending() ^ previous) {
7320                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7321                                            }
7322                                            else {
7323                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7324                                            }
7325                                    }
7326                                    else {
7327                                            if (orderByComparator.isAscending() ^ previous) {
7328                                                    query.append(ORDER_BY_ASC);
7329                                            }
7330                                            else {
7331                                                    query.append(ORDER_BY_DESC);
7332                                            }
7333                                    }
7334                            }
7335                    }
7336    
7337                    else {
7338                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7339                    }
7340    
7341                    String sql = query.toString();
7342    
7343                    Query q = session.createQuery(sql);
7344    
7345                    q.setFirstResult(0);
7346                    q.setMaxResults(2);
7347    
7348                    QueryPos qPos = QueryPos.getInstance(q);
7349    
7350                    qPos.add(groupId);
7351    
7352                    qPos.add(categoryId);
7353    
7354                    qPos.add(status);
7355    
7356                    if (orderByComparator != null) {
7357                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7358    
7359                            for (Object value : values) {
7360                                    qPos.add(value);
7361                            }
7362                    }
7363    
7364                    List<MBThread> list = q.list();
7365    
7366                    if (list.size() == 2) {
7367                            return list.get(1);
7368                    }
7369                    else {
7370                            return null;
7371                    }
7372            }
7373    
7374            /**
7375             * Returns all the message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
7376             *
7377             * @param groupId the group ID
7378             * @param categoryId the category ID
7379             * @param status the status
7380             * @return the matching message boards threads that the user has permission to view
7381             * @throws SystemException if a system exception occurred
7382             */
7383            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7384                    int status) throws SystemException {
7385                    return filterFindByG_NotC_S(groupId, categoryId, status,
7386                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7387            }
7388    
7389            /**
7390             * 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;.
7391             *
7392             * <p>
7393             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7394             * </p>
7395             *
7396             * @param groupId the group ID
7397             * @param categoryId the category ID
7398             * @param status the status
7399             * @param start the lower bound of the range of message boards threads
7400             * @param end the upper bound of the range of message boards threads (not inclusive)
7401             * @return the range of matching message boards threads that the user has permission to view
7402             * @throws SystemException if a system exception occurred
7403             */
7404            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7405                    int status, int start, int end) throws SystemException {
7406                    return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
7407                            null);
7408            }
7409    
7410            /**
7411             * 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;.
7412             *
7413             * <p>
7414             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7415             * </p>
7416             *
7417             * @param groupId the group ID
7418             * @param categoryId the category ID
7419             * @param status the status
7420             * @param start the lower bound of the range of message boards threads
7421             * @param end the upper bound of the range of message boards threads (not inclusive)
7422             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7423             * @return the ordered range of matching message boards threads that the user has permission to view
7424             * @throws SystemException if a system exception occurred
7425             */
7426            public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
7427                    int status, int start, int end, OrderByComparator orderByComparator)
7428                    throws SystemException {
7429                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7430                            return findByG_NotC_S(groupId, categoryId, status, start, end,
7431                                    orderByComparator);
7432                    }
7433    
7434                    StringBundler query = null;
7435    
7436                    if (orderByComparator != null) {
7437                            query = new StringBundler(5 +
7438                                            (orderByComparator.getOrderByFields().length * 3));
7439                    }
7440                    else {
7441                            query = new StringBundler(5);
7442                    }
7443    
7444                    if (getDB().isSupportsInlineDistinct()) {
7445                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7446                    }
7447                    else {
7448                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7449                    }
7450    
7451                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7452    
7453                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7454    
7455                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7456    
7457                    if (!getDB().isSupportsInlineDistinct()) {
7458                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7459                    }
7460    
7461                    if (orderByComparator != null) {
7462                            if (getDB().isSupportsInlineDistinct()) {
7463                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7464                                            orderByComparator);
7465                            }
7466                            else {
7467                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7468                                            orderByComparator);
7469                            }
7470                    }
7471    
7472                    else {
7473                            if (getDB().isSupportsInlineDistinct()) {
7474                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7475                            }
7476                            else {
7477                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
7478                            }
7479                    }
7480    
7481                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7482                                    MBThread.class.getName(),
7483                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7484    
7485                    Session session = null;
7486    
7487                    try {
7488                            session = openSession();
7489    
7490                            SQLQuery q = session.createSQLQuery(sql);
7491    
7492                            if (getDB().isSupportsInlineDistinct()) {
7493                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7494                            }
7495                            else {
7496                                    q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7497                            }
7498    
7499                            QueryPos qPos = QueryPos.getInstance(q);
7500    
7501                            qPos.add(groupId);
7502    
7503                            qPos.add(categoryId);
7504    
7505                            qPos.add(status);
7506    
7507                            return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7508                    }
7509                    catch (Exception e) {
7510                            throw processException(e);
7511                    }
7512                    finally {
7513                            closeSession(session);
7514                    }
7515            }
7516    
7517            /**
7518             * 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;.
7519             *
7520             * @param threadId the primary key of the current message boards thread
7521             * @param groupId the group ID
7522             * @param categoryId the category ID
7523             * @param status the status
7524             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7525             * @return the previous, current, and next message boards thread
7526             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
7527             * @throws SystemException if a system exception occurred
7528             */
7529            public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
7530                    long groupId, long categoryId, int status,
7531                    OrderByComparator orderByComparator)
7532                    throws NoSuchThreadException, SystemException {
7533                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7534                            return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
7535                                    status, orderByComparator);
7536                    }
7537    
7538                    MBThread mbThread = findByPrimaryKey(threadId);
7539    
7540                    Session session = null;
7541    
7542                    try {
7543                            session = openSession();
7544    
7545                            MBThread[] array = new MBThreadImpl[3];
7546    
7547                            array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
7548                                            groupId, categoryId, status, orderByComparator, true);
7549    
7550                            array[1] = mbThread;
7551    
7552                            array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
7553                                            groupId, categoryId, status, orderByComparator, false);
7554    
7555                            return array;
7556                    }
7557                    catch (Exception e) {
7558                            throw processException(e);
7559                    }
7560                    finally {
7561                            closeSession(session);
7562                    }
7563            }
7564    
7565            protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
7566                    MBThread mbThread, long groupId, long categoryId, int status,
7567                    OrderByComparator orderByComparator, boolean previous) {
7568                    StringBundler query = null;
7569    
7570                    if (orderByComparator != null) {
7571                            query = new StringBundler(6 +
7572                                            (orderByComparator.getOrderByFields().length * 6));
7573                    }
7574                    else {
7575                            query = new StringBundler(3);
7576                    }
7577    
7578                    if (getDB().isSupportsInlineDistinct()) {
7579                            query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7580                    }
7581                    else {
7582                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7583                    }
7584    
7585                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
7586    
7587                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
7588    
7589                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
7590    
7591                    if (!getDB().isSupportsInlineDistinct()) {
7592                            query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7593                    }
7594    
7595                    if (orderByComparator != null) {
7596                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7597    
7598                            if (orderByConditionFields.length > 0) {
7599                                    query.append(WHERE_AND);
7600                            }
7601    
7602                            for (int i = 0; i < orderByConditionFields.length; i++) {
7603                                    if (getDB().isSupportsInlineDistinct()) {
7604                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7605                                    }
7606                                    else {
7607                                            query.append(_ORDER_BY_ENTITY_TABLE);
7608                                    }
7609    
7610                                    query.append(orderByConditionFields[i]);
7611    
7612                                    if ((i + 1) < orderByConditionFields.length) {
7613                                            if (orderByComparator.isAscending() ^ previous) {
7614                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7615                                            }
7616                                            else {
7617                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7618                                            }
7619                                    }
7620                                    else {
7621                                            if (orderByComparator.isAscending() ^ previous) {
7622                                                    query.append(WHERE_GREATER_THAN);
7623                                            }
7624                                            else {
7625                                                    query.append(WHERE_LESSER_THAN);
7626                                            }
7627                                    }
7628                            }
7629    
7630                            query.append(ORDER_BY_CLAUSE);
7631    
7632                            String[] orderByFields = orderByComparator.getOrderByFields();
7633    
7634                            for (int i = 0; i < orderByFields.length; i++) {
7635                                    if (getDB().isSupportsInlineDistinct()) {
7636                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7637                                    }
7638                                    else {
7639                                            query.append(_ORDER_BY_ENTITY_TABLE);
7640                                    }
7641    
7642                                    query.append(orderByFields[i]);
7643    
7644                                    if ((i + 1) < orderByFields.length) {
7645                                            if (orderByComparator.isAscending() ^ previous) {
7646                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7647                                            }
7648                                            else {
7649                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7650                                            }
7651                                    }
7652                                    else {
7653                                            if (orderByComparator.isAscending() ^ previous) {
7654                                                    query.append(ORDER_BY_ASC);
7655                                            }
7656                                            else {
7657                                                    query.append(ORDER_BY_DESC);
7658                                            }
7659                                    }
7660                            }
7661                    }
7662    
7663                    else {
7664                            if (getDB().isSupportsInlineDistinct()) {
7665                                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7666                            }
7667                            else {
7668                                    query.append(MBThreadModelImpl.ORDER_BY_SQL);
7669                            }
7670                    }
7671    
7672                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7673                                    MBThread.class.getName(),
7674                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7675    
7676                    SQLQuery q = session.createSQLQuery(sql);
7677    
7678                    q.setFirstResult(0);
7679                    q.setMaxResults(2);
7680    
7681                    if (getDB().isSupportsInlineDistinct()) {
7682                            q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7683                    }
7684                    else {
7685                            q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7686                    }
7687    
7688                    QueryPos qPos = QueryPos.getInstance(q);
7689    
7690                    qPos.add(groupId);
7691    
7692                    qPos.add(categoryId);
7693    
7694                    qPos.add(status);
7695    
7696                    if (orderByComparator != null) {
7697                            Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7698    
7699                            for (Object value : values) {
7700                                    qPos.add(value);
7701                            }
7702                    }
7703    
7704                    List<MBThread> list = q.list();
7705    
7706                    if (list.size() == 2) {
7707                            return list.get(1);
7708                    }
7709                    else {
7710                            return null;
7711                    }
7712            }
7713    
7714            /**
7715             * Returns all the message boards threads.
7716             *
7717             * @return the message boards threads
7718             * @throws SystemException if a system exception occurred
7719             */
7720            public List<MBThread> findAll() throws SystemException {
7721                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7722            }
7723    
7724            /**
7725             * Returns a range of all the message boards threads.
7726             *
7727             * <p>
7728             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7729             * </p>
7730             *
7731             * @param start the lower bound of the range of message boards threads
7732             * @param end the upper bound of the range of message boards threads (not inclusive)
7733             * @return the range of message boards threads
7734             * @throws SystemException if a system exception occurred
7735             */
7736            public List<MBThread> findAll(int start, int end) throws SystemException {
7737                    return findAll(start, end, null);
7738            }
7739    
7740            /**
7741             * Returns an ordered range of all the message boards threads.
7742             *
7743             * <p>
7744             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
7745             * </p>
7746             *
7747             * @param start the lower bound of the range of message boards threads
7748             * @param end the upper bound of the range of message boards threads (not inclusive)
7749             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7750             * @return the ordered range of message boards threads
7751             * @throws SystemException if a system exception occurred
7752             */
7753            public List<MBThread> findAll(int start, int end,
7754                    OrderByComparator orderByComparator) throws SystemException {
7755                    FinderPath finderPath = null;
7756                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
7757    
7758                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7759                                    (orderByComparator == null)) {
7760                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7761                            finderArgs = FINDER_ARGS_EMPTY;
7762                    }
7763                    else {
7764                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7765                            finderArgs = new Object[] { start, end, orderByComparator };
7766                    }
7767    
7768                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7769                                    finderArgs, this);
7770    
7771                    if (list == null) {
7772                            StringBundler query = null;
7773                            String sql = null;
7774    
7775                            if (orderByComparator != null) {
7776                                    query = new StringBundler(2 +
7777                                                    (orderByComparator.getOrderByFields().length * 3));
7778    
7779                                    query.append(_SQL_SELECT_MBTHREAD);
7780    
7781                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7782                                            orderByComparator);
7783    
7784                                    sql = query.toString();
7785                            }
7786                            else {
7787                                    sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
7788                            }
7789    
7790                            Session session = null;
7791    
7792                            try {
7793                                    session = openSession();
7794    
7795                                    Query q = session.createQuery(sql);
7796    
7797                                    if (orderByComparator == null) {
7798                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7799                                                            start, end, false);
7800    
7801                                            Collections.sort(list);
7802                                    }
7803                                    else {
7804                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7805                                                            start, end);
7806                                    }
7807                            }
7808                            catch (Exception e) {
7809                                    throw processException(e);
7810                            }
7811                            finally {
7812                                    if (list == null) {
7813                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
7814                                    }
7815                                    else {
7816                                            cacheResult(list);
7817    
7818                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
7819                                    }
7820    
7821                                    closeSession(session);
7822                            }
7823                    }
7824    
7825                    return list;
7826            }
7827    
7828            /**
7829             * Removes all the message boards threads where groupId = &#63; from the database.
7830             *
7831             * @param groupId the group ID
7832             * @throws SystemException if a system exception occurred
7833             */
7834            public void removeByGroupId(long groupId) throws SystemException {
7835                    for (MBThread mbThread : findByGroupId(groupId)) {
7836                            remove(mbThread);
7837                    }
7838            }
7839    
7840            /**
7841             * Removes the message boards thread where rootMessageId = &#63; from the database.
7842             *
7843             * @param rootMessageId the root message ID
7844             * @return the message boards thread that was removed
7845             * @throws SystemException if a system exception occurred
7846             */
7847            public MBThread removeByRootMessageId(long rootMessageId)
7848                    throws NoSuchThreadException, SystemException {
7849                    MBThread mbThread = findByRootMessageId(rootMessageId);
7850    
7851                    return remove(mbThread);
7852            }
7853    
7854            /**
7855             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; from the database.
7856             *
7857             * @param groupId the group ID
7858             * @param categoryId the category ID
7859             * @throws SystemException if a system exception occurred
7860             */
7861            public void removeByG_C(long groupId, long categoryId)
7862                    throws SystemException {
7863                    for (MBThread mbThread : findByG_C(groupId, categoryId)) {
7864                            remove(mbThread);
7865                    }
7866            }
7867    
7868            /**
7869             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; from the database.
7870             *
7871             * @param groupId the group ID
7872             * @param categoryId the category ID
7873             * @throws SystemException if a system exception occurred
7874             */
7875            public void removeByG_NotC(long groupId, long categoryId)
7876                    throws SystemException {
7877                    for (MBThread mbThread : findByG_NotC(groupId, categoryId)) {
7878                            remove(mbThread);
7879                    }
7880            }
7881    
7882            /**
7883             * Removes all the message boards threads where groupId = &#63; and status = &#63; from the database.
7884             *
7885             * @param groupId the group ID
7886             * @param status the status
7887             * @throws SystemException if a system exception occurred
7888             */
7889            public void removeByG_S(long groupId, int status) throws SystemException {
7890                    for (MBThread mbThread : findByG_S(groupId, status)) {
7891                            remove(mbThread);
7892                    }
7893            }
7894    
7895            /**
7896             * Removes all the message boards threads where categoryId = &#63; and priority = &#63; from the database.
7897             *
7898             * @param categoryId the category ID
7899             * @param priority the priority
7900             * @throws SystemException if a system exception occurred
7901             */
7902            public void removeByC_P(long categoryId, double priority)
7903                    throws SystemException {
7904                    for (MBThread mbThread : findByC_P(categoryId, priority)) {
7905                            remove(mbThread);
7906                    }
7907            }
7908    
7909            /**
7910             * Removes all the message boards threads where lastPostDate = &#63; and priority = &#63; from the database.
7911             *
7912             * @param lastPostDate the last post date
7913             * @param priority the priority
7914             * @throws SystemException if a system exception occurred
7915             */
7916            public void removeByL_P(Date lastPostDate, double priority)
7917                    throws SystemException {
7918                    for (MBThread mbThread : findByL_P(lastPostDate, priority)) {
7919                            remove(mbThread);
7920                    }
7921            }
7922    
7923            /**
7924             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63; from the database.
7925             *
7926             * @param groupId the group ID
7927             * @param categoryId the category ID
7928             * @param lastPostDate the last post date
7929             * @throws SystemException if a system exception occurred
7930             */
7931            public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
7932                    throws SystemException {
7933                    for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate)) {
7934                            remove(mbThread);
7935                    }
7936            }
7937    
7938            /**
7939             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
7940             *
7941             * @param groupId the group ID
7942             * @param categoryId the category ID
7943             * @param status the status
7944             * @throws SystemException if a system exception occurred
7945             */
7946            public void removeByG_C_S(long groupId, long categoryId, int status)
7947                    throws SystemException {
7948                    for (MBThread mbThread : findByG_C_S(groupId, categoryId, status)) {
7949                            remove(mbThread);
7950                    }
7951            }
7952    
7953            /**
7954             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63; from the database.
7955             *
7956             * @param groupId the group ID
7957             * @param categoryId the category ID
7958             * @param status the status
7959             * @throws SystemException if a system exception occurred
7960             */
7961            public void removeByG_NotC_S(long groupId, long categoryId, int status)
7962                    throws SystemException {
7963                    for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status)) {
7964                            remove(mbThread);
7965                    }
7966            }
7967    
7968            /**
7969             * Removes all the message boards threads from the database.
7970             *
7971             * @throws SystemException if a system exception occurred
7972             */
7973            public void removeAll() throws SystemException {
7974                    for (MBThread mbThread : findAll()) {
7975                            remove(mbThread);
7976                    }
7977            }
7978    
7979            /**
7980             * Returns the number of message boards threads where groupId = &#63;.
7981             *
7982             * @param groupId the group ID
7983             * @return the number of matching message boards threads
7984             * @throws SystemException if a system exception occurred
7985             */
7986            public int countByGroupId(long groupId) throws SystemException {
7987                    Object[] finderArgs = new Object[] { groupId };
7988    
7989                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
7990                                    finderArgs, this);
7991    
7992                    if (count == null) {
7993                            StringBundler query = new StringBundler(2);
7994    
7995                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
7996    
7997                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
7998    
7999                            String sql = query.toString();
8000    
8001                            Session session = null;
8002    
8003                            try {
8004                                    session = openSession();
8005    
8006                                    Query q = session.createQuery(sql);
8007    
8008                                    QueryPos qPos = QueryPos.getInstance(q);
8009    
8010                                    qPos.add(groupId);
8011    
8012                                    count = (Long)q.uniqueResult();
8013                            }
8014                            catch (Exception e) {
8015                                    throw processException(e);
8016                            }
8017                            finally {
8018                                    if (count == null) {
8019                                            count = Long.valueOf(0);
8020                                    }
8021    
8022                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
8023                                            finderArgs, count);
8024    
8025                                    closeSession(session);
8026                            }
8027                    }
8028    
8029                    return count.intValue();
8030            }
8031    
8032            /**
8033             * Returns the number of message boards threads that the user has permission to view where groupId = &#63;.
8034             *
8035             * @param groupId the group ID
8036             * @return the number of matching message boards threads that the user has permission to view
8037             * @throws SystemException if a system exception occurred
8038             */
8039            public int filterCountByGroupId(long groupId) throws SystemException {
8040                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8041                            return countByGroupId(groupId);
8042                    }
8043    
8044                    StringBundler query = new StringBundler(2);
8045    
8046                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8047    
8048                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
8049    
8050                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8051                                    MBThread.class.getName(),
8052                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8053    
8054                    Session session = null;
8055    
8056                    try {
8057                            session = openSession();
8058    
8059                            SQLQuery q = session.createSQLQuery(sql);
8060    
8061                            q.addScalar(COUNT_COLUMN_NAME,
8062                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8063    
8064                            QueryPos qPos = QueryPos.getInstance(q);
8065    
8066                            qPos.add(groupId);
8067    
8068                            Long count = (Long)q.uniqueResult();
8069    
8070                            return count.intValue();
8071                    }
8072                    catch (Exception e) {
8073                            throw processException(e);
8074                    }
8075                    finally {
8076                            closeSession(session);
8077                    }
8078            }
8079    
8080            /**
8081             * Returns the number of message boards threads where rootMessageId = &#63;.
8082             *
8083             * @param rootMessageId the root message ID
8084             * @return the number of matching message boards threads
8085             * @throws SystemException if a system exception occurred
8086             */
8087            public int countByRootMessageId(long rootMessageId)
8088                    throws SystemException {
8089                    Object[] finderArgs = new Object[] { rootMessageId };
8090    
8091                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
8092                                    finderArgs, this);
8093    
8094                    if (count == null) {
8095                            StringBundler query = new StringBundler(2);
8096    
8097                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8098    
8099                            query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
8100    
8101                            String sql = query.toString();
8102    
8103                            Session session = null;
8104    
8105                            try {
8106                                    session = openSession();
8107    
8108                                    Query q = session.createQuery(sql);
8109    
8110                                    QueryPos qPos = QueryPos.getInstance(q);
8111    
8112                                    qPos.add(rootMessageId);
8113    
8114                                    count = (Long)q.uniqueResult();
8115                            }
8116                            catch (Exception e) {
8117                                    throw processException(e);
8118                            }
8119                            finally {
8120                                    if (count == null) {
8121                                            count = Long.valueOf(0);
8122                                    }
8123    
8124                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
8125                                            finderArgs, count);
8126    
8127                                    closeSession(session);
8128                            }
8129                    }
8130    
8131                    return count.intValue();
8132            }
8133    
8134            /**
8135             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63;.
8136             *
8137             * @param groupId the group ID
8138             * @param categoryId the category ID
8139             * @return the number of matching message boards threads
8140             * @throws SystemException if a system exception occurred
8141             */
8142            public int countByG_C(long groupId, long categoryId)
8143                    throws SystemException {
8144                    Object[] finderArgs = new Object[] { groupId, categoryId };
8145    
8146                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
8147                                    finderArgs, this);
8148    
8149                    if (count == null) {
8150                            StringBundler query = new StringBundler(3);
8151    
8152                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8153    
8154                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
8155    
8156                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
8157    
8158                            String sql = query.toString();
8159    
8160                            Session session = null;
8161    
8162                            try {
8163                                    session = openSession();
8164    
8165                                    Query q = session.createQuery(sql);
8166    
8167                                    QueryPos qPos = QueryPos.getInstance(q);
8168    
8169                                    qPos.add(groupId);
8170    
8171                                    qPos.add(categoryId);
8172    
8173                                    count = (Long)q.uniqueResult();
8174                            }
8175                            catch (Exception e) {
8176                                    throw processException(e);
8177                            }
8178                            finally {
8179                                    if (count == null) {
8180                                            count = Long.valueOf(0);
8181                                    }
8182    
8183                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
8184                                            count);
8185    
8186                                    closeSession(session);
8187                            }
8188                    }
8189    
8190                    return count.intValue();
8191            }
8192    
8193            /**
8194             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63;.
8195             *
8196             * @param groupId the group ID
8197             * @param categoryIds the category IDs
8198             * @return the number of matching message boards threads
8199             * @throws SystemException if a system exception occurred
8200             */
8201            public int countByG_C(long groupId, long[] categoryIds)
8202                    throws SystemException {
8203                    Object[] finderArgs = new Object[] {
8204                                    groupId, StringUtil.merge(categoryIds)
8205                            };
8206    
8207                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
8208                                    finderArgs, this);
8209    
8210                    if (count == null) {
8211                            StringBundler query = new StringBundler();
8212    
8213                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8214    
8215                            boolean conjunctionable = false;
8216    
8217                            if (conjunctionable) {
8218                                    query.append(WHERE_AND);
8219                            }
8220    
8221                            query.append(_FINDER_COLUMN_G_C_GROUPID_5);
8222    
8223                            conjunctionable = true;
8224    
8225                            if ((categoryIds == null) || (categoryIds.length > 0)) {
8226                                    if (conjunctionable) {
8227                                            query.append(WHERE_AND);
8228                                    }
8229    
8230                                    query.append(StringPool.OPEN_PARENTHESIS);
8231    
8232                                    for (int i = 0; i < categoryIds.length; i++) {
8233                                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
8234    
8235                                            if ((i + 1) < categoryIds.length) {
8236                                                    query.append(WHERE_OR);
8237                                            }
8238                                    }
8239    
8240                                    query.append(StringPool.CLOSE_PARENTHESIS);
8241    
8242                                    conjunctionable = true;
8243                            }
8244    
8245                            String sql = query.toString();
8246    
8247                            Session session = null;
8248    
8249                            try {
8250                                    session = openSession();
8251    
8252                                    Query q = session.createQuery(sql);
8253    
8254                                    QueryPos qPos = QueryPos.getInstance(q);
8255    
8256                                    qPos.add(groupId);
8257    
8258                                    if (categoryIds != null) {
8259                                            qPos.add(categoryIds);
8260                                    }
8261    
8262                                    count = (Long)q.uniqueResult();
8263                            }
8264                            catch (Exception e) {
8265                                    throw processException(e);
8266                            }
8267                            finally {
8268                                    if (count == null) {
8269                                            count = Long.valueOf(0);
8270                                    }
8271    
8272                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
8273                                            finderArgs, count);
8274    
8275                                    closeSession(session);
8276                            }
8277                    }
8278    
8279                    return count.intValue();
8280            }
8281    
8282            /**
8283             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63;.
8284             *
8285             * @param groupId the group ID
8286             * @param categoryId the category ID
8287             * @return the number of matching message boards threads that the user has permission to view
8288             * @throws SystemException if a system exception occurred
8289             */
8290            public int filterCountByG_C(long groupId, long categoryId)
8291                    throws SystemException {
8292                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8293                            return countByG_C(groupId, categoryId);
8294                    }
8295    
8296                    StringBundler query = new StringBundler(3);
8297    
8298                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8299    
8300                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
8301    
8302                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
8303    
8304                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8305                                    MBThread.class.getName(),
8306                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8307    
8308                    Session session = null;
8309    
8310                    try {
8311                            session = openSession();
8312    
8313                            SQLQuery q = session.createSQLQuery(sql);
8314    
8315                            q.addScalar(COUNT_COLUMN_NAME,
8316                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8317    
8318                            QueryPos qPos = QueryPos.getInstance(q);
8319    
8320                            qPos.add(groupId);
8321    
8322                            qPos.add(categoryId);
8323    
8324                            Long count = (Long)q.uniqueResult();
8325    
8326                            return count.intValue();
8327                    }
8328                    catch (Exception e) {
8329                            throw processException(e);
8330                    }
8331                    finally {
8332                            closeSession(session);
8333                    }
8334            }
8335    
8336            /**
8337             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63;.
8338             *
8339             * @param groupId the group ID
8340             * @param categoryIds the category IDs
8341             * @return the number of matching message boards threads that the user has permission to view
8342             * @throws SystemException if a system exception occurred
8343             */
8344            public int filterCountByG_C(long groupId, long[] categoryIds)
8345                    throws SystemException {
8346                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8347                            return countByG_C(groupId, categoryIds);
8348                    }
8349    
8350                    StringBundler query = new StringBundler();
8351    
8352                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8353    
8354                    boolean conjunctionable = false;
8355    
8356                    if (conjunctionable) {
8357                            query.append(WHERE_AND);
8358                    }
8359    
8360                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
8361    
8362                    conjunctionable = true;
8363    
8364                    if ((categoryIds == null) || (categoryIds.length > 0)) {
8365                            if (conjunctionable) {
8366                                    query.append(WHERE_AND);
8367                            }
8368    
8369                            query.append(StringPool.OPEN_PARENTHESIS);
8370    
8371                            for (int i = 0; i < categoryIds.length; i++) {
8372                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
8373    
8374                                    if ((i + 1) < categoryIds.length) {
8375                                            query.append(WHERE_OR);
8376                                    }
8377                            }
8378    
8379                            query.append(StringPool.CLOSE_PARENTHESIS);
8380    
8381                            conjunctionable = true;
8382                    }
8383    
8384                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8385                                    MBThread.class.getName(),
8386                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8387    
8388                    Session session = null;
8389    
8390                    try {
8391                            session = openSession();
8392    
8393                            SQLQuery q = session.createSQLQuery(sql);
8394    
8395                            q.addScalar(COUNT_COLUMN_NAME,
8396                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8397    
8398                            QueryPos qPos = QueryPos.getInstance(q);
8399    
8400                            qPos.add(groupId);
8401    
8402                            if (categoryIds != null) {
8403                                    qPos.add(categoryIds);
8404                            }
8405    
8406                            Long count = (Long)q.uniqueResult();
8407    
8408                            return count.intValue();
8409                    }
8410                    catch (Exception e) {
8411                            throw processException(e);
8412                    }
8413                    finally {
8414                            closeSession(session);
8415                    }
8416            }
8417    
8418            /**
8419             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63;.
8420             *
8421             * @param groupId the group ID
8422             * @param categoryId the category ID
8423             * @return the number of matching message boards threads
8424             * @throws SystemException if a system exception occurred
8425             */
8426            public int countByG_NotC(long groupId, long categoryId)
8427                    throws SystemException {
8428                    Object[] finderArgs = new Object[] { groupId, categoryId };
8429    
8430                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC,
8431                                    finderArgs, this);
8432    
8433                    if (count == null) {
8434                            StringBundler query = new StringBundler(3);
8435    
8436                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8437    
8438                            query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
8439    
8440                            query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
8441    
8442                            String sql = query.toString();
8443    
8444                            Session session = null;
8445    
8446                            try {
8447                                    session = openSession();
8448    
8449                                    Query q = session.createQuery(sql);
8450    
8451                                    QueryPos qPos = QueryPos.getInstance(q);
8452    
8453                                    qPos.add(groupId);
8454    
8455                                    qPos.add(categoryId);
8456    
8457                                    count = (Long)q.uniqueResult();
8458                            }
8459                            catch (Exception e) {
8460                                    throw processException(e);
8461                            }
8462                            finally {
8463                                    if (count == null) {
8464                                            count = Long.valueOf(0);
8465                                    }
8466    
8467                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC,
8468                                            finderArgs, count);
8469    
8470                                    closeSession(session);
8471                            }
8472                    }
8473    
8474                    return count.intValue();
8475            }
8476    
8477            /**
8478             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63;.
8479             *
8480             * @param groupId the group ID
8481             * @param categoryId the category ID
8482             * @return the number of matching message boards threads that the user has permission to view
8483             * @throws SystemException if a system exception occurred
8484             */
8485            public int filterCountByG_NotC(long groupId, long categoryId)
8486                    throws SystemException {
8487                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8488                            return countByG_NotC(groupId, categoryId);
8489                    }
8490    
8491                    StringBundler query = new StringBundler(3);
8492    
8493                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8494    
8495                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
8496    
8497                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
8498    
8499                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8500                                    MBThread.class.getName(),
8501                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8502    
8503                    Session session = null;
8504    
8505                    try {
8506                            session = openSession();
8507    
8508                            SQLQuery q = session.createSQLQuery(sql);
8509    
8510                            q.addScalar(COUNT_COLUMN_NAME,
8511                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8512    
8513                            QueryPos qPos = QueryPos.getInstance(q);
8514    
8515                            qPos.add(groupId);
8516    
8517                            qPos.add(categoryId);
8518    
8519                            Long count = (Long)q.uniqueResult();
8520    
8521                            return count.intValue();
8522                    }
8523                    catch (Exception e) {
8524                            throw processException(e);
8525                    }
8526                    finally {
8527                            closeSession(session);
8528                    }
8529            }
8530    
8531            /**
8532             * Returns the number of message boards threads where groupId = &#63; and status = &#63;.
8533             *
8534             * @param groupId the group ID
8535             * @param status the status
8536             * @return the number of matching message boards threads
8537             * @throws SystemException if a system exception occurred
8538             */
8539            public int countByG_S(long groupId, int status) throws SystemException {
8540                    Object[] finderArgs = new Object[] { groupId, status };
8541    
8542                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
8543                                    finderArgs, this);
8544    
8545                    if (count == null) {
8546                            StringBundler query = new StringBundler(3);
8547    
8548                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8549    
8550                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
8551    
8552                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
8553    
8554                            String sql = query.toString();
8555    
8556                            Session session = null;
8557    
8558                            try {
8559                                    session = openSession();
8560    
8561                                    Query q = session.createQuery(sql);
8562    
8563                                    QueryPos qPos = QueryPos.getInstance(q);
8564    
8565                                    qPos.add(groupId);
8566    
8567                                    qPos.add(status);
8568    
8569                                    count = (Long)q.uniqueResult();
8570                            }
8571                            catch (Exception e) {
8572                                    throw processException(e);
8573                            }
8574                            finally {
8575                                    if (count == null) {
8576                                            count = Long.valueOf(0);
8577                                    }
8578    
8579                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
8580                                            count);
8581    
8582                                    closeSession(session);
8583                            }
8584                    }
8585    
8586                    return count.intValue();
8587            }
8588    
8589            /**
8590             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and status = &#63;.
8591             *
8592             * @param groupId the group ID
8593             * @param status the status
8594             * @return the number of matching message boards threads that the user has permission to view
8595             * @throws SystemException if a system exception occurred
8596             */
8597            public int filterCountByG_S(long groupId, int status)
8598                    throws SystemException {
8599                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8600                            return countByG_S(groupId, status);
8601                    }
8602    
8603                    StringBundler query = new StringBundler(3);
8604    
8605                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8606    
8607                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
8608    
8609                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
8610    
8611                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8612                                    MBThread.class.getName(),
8613                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8614    
8615                    Session session = null;
8616    
8617                    try {
8618                            session = openSession();
8619    
8620                            SQLQuery q = session.createSQLQuery(sql);
8621    
8622                            q.addScalar(COUNT_COLUMN_NAME,
8623                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8624    
8625                            QueryPos qPos = QueryPos.getInstance(q);
8626    
8627                            qPos.add(groupId);
8628    
8629                            qPos.add(status);
8630    
8631                            Long count = (Long)q.uniqueResult();
8632    
8633                            return count.intValue();
8634                    }
8635                    catch (Exception e) {
8636                            throw processException(e);
8637                    }
8638                    finally {
8639                            closeSession(session);
8640                    }
8641            }
8642    
8643            /**
8644             * Returns the number of message boards threads where categoryId = &#63; and priority = &#63;.
8645             *
8646             * @param categoryId the category ID
8647             * @param priority the priority
8648             * @return the number of matching message boards threads
8649             * @throws SystemException if a system exception occurred
8650             */
8651            public int countByC_P(long categoryId, double priority)
8652                    throws SystemException {
8653                    Object[] finderArgs = new Object[] { categoryId, priority };
8654    
8655                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
8656                                    finderArgs, this);
8657    
8658                    if (count == null) {
8659                            StringBundler query = new StringBundler(3);
8660    
8661                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8662    
8663                            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
8664    
8665                            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
8666    
8667                            String sql = query.toString();
8668    
8669                            Session session = null;
8670    
8671                            try {
8672                                    session = openSession();
8673    
8674                                    Query q = session.createQuery(sql);
8675    
8676                                    QueryPos qPos = QueryPos.getInstance(q);
8677    
8678                                    qPos.add(categoryId);
8679    
8680                                    qPos.add(priority);
8681    
8682                                    count = (Long)q.uniqueResult();
8683                            }
8684                            catch (Exception e) {
8685                                    throw processException(e);
8686                            }
8687                            finally {
8688                                    if (count == null) {
8689                                            count = Long.valueOf(0);
8690                                    }
8691    
8692                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
8693                                            count);
8694    
8695                                    closeSession(session);
8696                            }
8697                    }
8698    
8699                    return count.intValue();
8700            }
8701    
8702            /**
8703             * Returns the number of message boards threads where lastPostDate = &#63; and priority = &#63;.
8704             *
8705             * @param lastPostDate the last post date
8706             * @param priority the priority
8707             * @return the number of matching message boards threads
8708             * @throws SystemException if a system exception occurred
8709             */
8710            public int countByL_P(Date lastPostDate, double priority)
8711                    throws SystemException {
8712                    Object[] finderArgs = new Object[] { lastPostDate, priority };
8713    
8714                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_L_P,
8715                                    finderArgs, this);
8716    
8717                    if (count == null) {
8718                            StringBundler query = new StringBundler(3);
8719    
8720                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8721    
8722                            if (lastPostDate == null) {
8723                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
8724                            }
8725                            else {
8726                                    query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
8727                            }
8728    
8729                            query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
8730    
8731                            String sql = query.toString();
8732    
8733                            Session session = null;
8734    
8735                            try {
8736                                    session = openSession();
8737    
8738                                    Query q = session.createQuery(sql);
8739    
8740                                    QueryPos qPos = QueryPos.getInstance(q);
8741    
8742                                    if (lastPostDate != null) {
8743                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8744                                    }
8745    
8746                                    qPos.add(priority);
8747    
8748                                    count = (Long)q.uniqueResult();
8749                            }
8750                            catch (Exception e) {
8751                                    throw processException(e);
8752                            }
8753                            finally {
8754                                    if (count == null) {
8755                                            count = Long.valueOf(0);
8756                                    }
8757    
8758                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_L_P, finderArgs,
8759                                            count);
8760    
8761                                    closeSession(session);
8762                            }
8763                    }
8764    
8765                    return count.intValue();
8766            }
8767    
8768            /**
8769             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
8770             *
8771             * @param groupId the group ID
8772             * @param categoryId the category ID
8773             * @param lastPostDate the last post date
8774             * @return the number of matching message boards threads
8775             * @throws SystemException if a system exception occurred
8776             */
8777            public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
8778                    throws SystemException {
8779                    Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
8780    
8781                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_L,
8782                                    finderArgs, this);
8783    
8784                    if (count == null) {
8785                            StringBundler query = new StringBundler(4);
8786    
8787                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8788    
8789                            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
8790    
8791                            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
8792    
8793                            if (lastPostDate == null) {
8794                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
8795                            }
8796                            else {
8797                                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
8798                            }
8799    
8800                            String sql = query.toString();
8801    
8802                            Session session = null;
8803    
8804                            try {
8805                                    session = openSession();
8806    
8807                                    Query q = session.createQuery(sql);
8808    
8809                                    QueryPos qPos = QueryPos.getInstance(q);
8810    
8811                                    qPos.add(groupId);
8812    
8813                                    qPos.add(categoryId);
8814    
8815                                    if (lastPostDate != null) {
8816                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8817                                    }
8818    
8819                                    count = (Long)q.uniqueResult();
8820                            }
8821                            catch (Exception e) {
8822                                    throw processException(e);
8823                            }
8824                            finally {
8825                                    if (count == null) {
8826                                            count = Long.valueOf(0);
8827                                    }
8828    
8829                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_L,
8830                                            finderArgs, count);
8831    
8832                                    closeSession(session);
8833                            }
8834                    }
8835    
8836                    return count.intValue();
8837            }
8838    
8839            /**
8840             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
8841             *
8842             * @param groupId the group ID
8843             * @param categoryId the category ID
8844             * @param lastPostDate the last post date
8845             * @return the number of matching message boards threads that the user has permission to view
8846             * @throws SystemException if a system exception occurred
8847             */
8848            public int filterCountByG_C_L(long groupId, long categoryId,
8849                    Date lastPostDate) throws SystemException {
8850                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8851                            return countByG_C_L(groupId, categoryId, lastPostDate);
8852                    }
8853    
8854                    StringBundler query = new StringBundler(4);
8855    
8856                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
8857    
8858                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
8859    
8860                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
8861    
8862                    if (lastPostDate == null) {
8863                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
8864                    }
8865                    else {
8866                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
8867                    }
8868    
8869                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8870                                    MBThread.class.getName(),
8871                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8872    
8873                    Session session = null;
8874    
8875                    try {
8876                            session = openSession();
8877    
8878                            SQLQuery q = session.createSQLQuery(sql);
8879    
8880                            q.addScalar(COUNT_COLUMN_NAME,
8881                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8882    
8883                            QueryPos qPos = QueryPos.getInstance(q);
8884    
8885                            qPos.add(groupId);
8886    
8887                            qPos.add(categoryId);
8888    
8889                            if (lastPostDate != null) {
8890                                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
8891                            }
8892    
8893                            Long count = (Long)q.uniqueResult();
8894    
8895                            return count.intValue();
8896                    }
8897                    catch (Exception e) {
8898                            throw processException(e);
8899                    }
8900                    finally {
8901                            closeSession(session);
8902                    }
8903            }
8904    
8905            /**
8906             * Returns the number of message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
8907             *
8908             * @param groupId the group ID
8909             * @param categoryId the category ID
8910             * @param status the status
8911             * @return the number of matching message boards threads
8912             * @throws SystemException if a system exception occurred
8913             */
8914            public int countByG_C_S(long groupId, long categoryId, int status)
8915                    throws SystemException {
8916                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
8917    
8918                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
8919                                    finderArgs, this);
8920    
8921                    if (count == null) {
8922                            StringBundler query = new StringBundler(4);
8923    
8924                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8925    
8926                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8927    
8928                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8929    
8930                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8931    
8932                            String sql = query.toString();
8933    
8934                            Session session = null;
8935    
8936                            try {
8937                                    session = openSession();
8938    
8939                                    Query q = session.createQuery(sql);
8940    
8941                                    QueryPos qPos = QueryPos.getInstance(q);
8942    
8943                                    qPos.add(groupId);
8944    
8945                                    qPos.add(categoryId);
8946    
8947                                    qPos.add(status);
8948    
8949                                    count = (Long)q.uniqueResult();
8950                            }
8951                            catch (Exception e) {
8952                                    throw processException(e);
8953                            }
8954                            finally {
8955                                    if (count == null) {
8956                                            count = Long.valueOf(0);
8957                                    }
8958    
8959                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
8960                                            finderArgs, count);
8961    
8962                                    closeSession(session);
8963                            }
8964                    }
8965    
8966                    return count.intValue();
8967            }
8968    
8969            /**
8970             * Returns the number of message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
8971             *
8972             * @param groupId the group ID
8973             * @param categoryIds the category IDs
8974             * @param status the status
8975             * @return the number of matching message boards threads
8976             * @throws SystemException if a system exception occurred
8977             */
8978            public int countByG_C_S(long groupId, long[] categoryIds, int status)
8979                    throws SystemException {
8980                    Object[] finderArgs = new Object[] {
8981                                    groupId, StringUtil.merge(categoryIds), status
8982                            };
8983    
8984                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8985                                    finderArgs, this);
8986    
8987                    if (count == null) {
8988                            StringBundler query = new StringBundler();
8989    
8990                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
8991    
8992                            boolean conjunctionable = false;
8993    
8994                            if (conjunctionable) {
8995                                    query.append(WHERE_AND);
8996                            }
8997    
8998                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8999    
9000                            conjunctionable = true;
9001    
9002                            if ((categoryIds == null) || (categoryIds.length > 0)) {
9003                                    if (conjunctionable) {
9004                                            query.append(WHERE_AND);
9005                                    }
9006    
9007                                    query.append(StringPool.OPEN_PARENTHESIS);
9008    
9009                                    for (int i = 0; i < categoryIds.length; i++) {
9010                                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9011    
9012                                            if ((i + 1) < categoryIds.length) {
9013                                                    query.append(WHERE_OR);
9014                                            }
9015                                    }
9016    
9017                                    query.append(StringPool.CLOSE_PARENTHESIS);
9018    
9019                                    conjunctionable = true;
9020                            }
9021    
9022                            if (conjunctionable) {
9023                                    query.append(WHERE_AND);
9024                            }
9025    
9026                            query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9027    
9028                            conjunctionable = true;
9029    
9030                            String sql = query.toString();
9031    
9032                            Session session = null;
9033    
9034                            try {
9035                                    session = openSession();
9036    
9037                                    Query q = session.createQuery(sql);
9038    
9039                                    QueryPos qPos = QueryPos.getInstance(q);
9040    
9041                                    qPos.add(groupId);
9042    
9043                                    if (categoryIds != null) {
9044                                            qPos.add(categoryIds);
9045                                    }
9046    
9047                                    qPos.add(status);
9048    
9049                                    count = (Long)q.uniqueResult();
9050                            }
9051                            catch (Exception e) {
9052                                    throw processException(e);
9053                            }
9054                            finally {
9055                                    if (count == null) {
9056                                            count = Long.valueOf(0);
9057                                    }
9058    
9059                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9060                                            finderArgs, count);
9061    
9062                                    closeSession(session);
9063                            }
9064                    }
9065    
9066                    return count.intValue();
9067            }
9068    
9069            /**
9070             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
9071             *
9072             * @param groupId the group ID
9073             * @param categoryId the category ID
9074             * @param status the status
9075             * @return the number of matching message boards threads that the user has permission to view
9076             * @throws SystemException if a system exception occurred
9077             */
9078            public int filterCountByG_C_S(long groupId, long categoryId, int status)
9079                    throws SystemException {
9080                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9081                            return countByG_C_S(groupId, categoryId, status);
9082                    }
9083    
9084                    StringBundler query = new StringBundler(4);
9085    
9086                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9087    
9088                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9089    
9090                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
9091    
9092                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9093    
9094                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9095                                    MBThread.class.getName(),
9096                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9097    
9098                    Session session = null;
9099    
9100                    try {
9101                            session = openSession();
9102    
9103                            SQLQuery q = session.createSQLQuery(sql);
9104    
9105                            q.addScalar(COUNT_COLUMN_NAME,
9106                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9107    
9108                            QueryPos qPos = QueryPos.getInstance(q);
9109    
9110                            qPos.add(groupId);
9111    
9112                            qPos.add(categoryId);
9113    
9114                            qPos.add(status);
9115    
9116                            Long count = (Long)q.uniqueResult();
9117    
9118                            return count.intValue();
9119                    }
9120                    catch (Exception e) {
9121                            throw processException(e);
9122                    }
9123                    finally {
9124                            closeSession(session);
9125                    }
9126            }
9127    
9128            /**
9129             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId = any &#63; and status = &#63;.
9130             *
9131             * @param groupId the group ID
9132             * @param categoryIds the category IDs
9133             * @param status the status
9134             * @return the number of matching message boards threads that the user has permission to view
9135             * @throws SystemException if a system exception occurred
9136             */
9137            public int filterCountByG_C_S(long groupId, long[] categoryIds, int status)
9138                    throws SystemException {
9139                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9140                            return countByG_C_S(groupId, categoryIds, status);
9141                    }
9142    
9143                    StringBundler query = new StringBundler();
9144    
9145                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9146    
9147                    boolean conjunctionable = false;
9148    
9149                    if (conjunctionable) {
9150                            query.append(WHERE_AND);
9151                    }
9152    
9153                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
9154    
9155                    conjunctionable = true;
9156    
9157                    if ((categoryIds == null) || (categoryIds.length > 0)) {
9158                            if (conjunctionable) {
9159                                    query.append(WHERE_AND);
9160                            }
9161    
9162                            query.append(StringPool.OPEN_PARENTHESIS);
9163    
9164                            for (int i = 0; i < categoryIds.length; i++) {
9165                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9166    
9167                                    if ((i + 1) < categoryIds.length) {
9168                                            query.append(WHERE_OR);
9169                                    }
9170                            }
9171    
9172                            query.append(StringPool.CLOSE_PARENTHESIS);
9173    
9174                            conjunctionable = true;
9175                    }
9176    
9177                    if (conjunctionable) {
9178                            query.append(WHERE_AND);
9179                    }
9180    
9181                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9182    
9183                    conjunctionable = true;
9184    
9185                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9186                                    MBThread.class.getName(),
9187                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9188    
9189                    Session session = null;
9190    
9191                    try {
9192                            session = openSession();
9193    
9194                            SQLQuery q = session.createSQLQuery(sql);
9195    
9196                            q.addScalar(COUNT_COLUMN_NAME,
9197                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9198    
9199                            QueryPos qPos = QueryPos.getInstance(q);
9200    
9201                            qPos.add(groupId);
9202    
9203                            if (categoryIds != null) {
9204                                    qPos.add(categoryIds);
9205                            }
9206    
9207                            qPos.add(status);
9208    
9209                            Long count = (Long)q.uniqueResult();
9210    
9211                            return count.intValue();
9212                    }
9213                    catch (Exception e) {
9214                            throw processException(e);
9215                    }
9216                    finally {
9217                            closeSession(session);
9218                    }
9219            }
9220    
9221            /**
9222             * Returns the number of message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
9223             *
9224             * @param groupId the group ID
9225             * @param categoryId the category ID
9226             * @param status the status
9227             * @return the number of matching message boards threads
9228             * @throws SystemException if a system exception occurred
9229             */
9230            public int countByG_NotC_S(long groupId, long categoryId, int status)
9231                    throws SystemException {
9232                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
9233    
9234                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S,
9235                                    finderArgs, this);
9236    
9237                    if (count == null) {
9238                            StringBundler query = new StringBundler(4);
9239    
9240                            query.append(_SQL_COUNT_MBTHREAD_WHERE);
9241    
9242                            query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9243    
9244                            query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9245    
9246                            query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9247    
9248                            String sql = query.toString();
9249    
9250                            Session session = null;
9251    
9252                            try {
9253                                    session = openSession();
9254    
9255                                    Query q = session.createQuery(sql);
9256    
9257                                    QueryPos qPos = QueryPos.getInstance(q);
9258    
9259                                    qPos.add(groupId);
9260    
9261                                    qPos.add(categoryId);
9262    
9263                                    qPos.add(status);
9264    
9265                                    count = (Long)q.uniqueResult();
9266                            }
9267                            catch (Exception e) {
9268                                    throw processException(e);
9269                            }
9270                            finally {
9271                                    if (count == null) {
9272                                            count = Long.valueOf(0);
9273                                    }
9274    
9275                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S,
9276                                            finderArgs, count);
9277    
9278                                    closeSession(session);
9279                            }
9280                    }
9281    
9282                    return count.intValue();
9283            }
9284    
9285            /**
9286             * Returns the number of message boards threads that the user has permission to view where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
9287             *
9288             * @param groupId the group ID
9289             * @param categoryId the category ID
9290             * @param status the status
9291             * @return the number of matching message boards threads that the user has permission to view
9292             * @throws SystemException if a system exception occurred
9293             */
9294            public int filterCountByG_NotC_S(long groupId, long categoryId, int status)
9295                    throws SystemException {
9296                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9297                            return countByG_NotC_S(groupId, categoryId, status);
9298                    }
9299    
9300                    StringBundler query = new StringBundler(4);
9301    
9302                    query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9303    
9304                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9305    
9306                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9307    
9308                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9309    
9310                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9311                                    MBThread.class.getName(),
9312                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9313    
9314                    Session session = null;
9315    
9316                    try {
9317                            session = openSession();
9318    
9319                            SQLQuery q = session.createSQLQuery(sql);
9320    
9321                            q.addScalar(COUNT_COLUMN_NAME,
9322                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9323    
9324                            QueryPos qPos = QueryPos.getInstance(q);
9325    
9326                            qPos.add(groupId);
9327    
9328                            qPos.add(categoryId);
9329    
9330                            qPos.add(status);
9331    
9332                            Long count = (Long)q.uniqueResult();
9333    
9334                            return count.intValue();
9335                    }
9336                    catch (Exception e) {
9337                            throw processException(e);
9338                    }
9339                    finally {
9340                            closeSession(session);
9341                    }
9342            }
9343    
9344            /**
9345             * Returns the number of message boards threads.
9346             *
9347             * @return the number of message boards threads
9348             * @throws SystemException if a system exception occurred
9349             */
9350            public int countAll() throws SystemException {
9351                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9352                                    FINDER_ARGS_EMPTY, this);
9353    
9354                    if (count == null) {
9355                            Session session = null;
9356    
9357                            try {
9358                                    session = openSession();
9359    
9360                                    Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
9361    
9362                                    count = (Long)q.uniqueResult();
9363                            }
9364                            catch (Exception e) {
9365                                    throw processException(e);
9366                            }
9367                            finally {
9368                                    if (count == null) {
9369                                            count = Long.valueOf(0);
9370                                    }
9371    
9372                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9373                                            FINDER_ARGS_EMPTY, count);
9374    
9375                                    closeSession(session);
9376                            }
9377                    }
9378    
9379                    return count.intValue();
9380            }
9381    
9382            /**
9383             * Initializes the message boards thread persistence.
9384             */
9385            public void afterPropertiesSet() {
9386                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
9387                                            com.liferay.portal.util.PropsUtil.get(
9388                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
9389    
9390                    if (listenerClassNames.length > 0) {
9391                            try {
9392                                    List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
9393    
9394                                    for (String listenerClassName : listenerClassNames) {
9395                                            listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
9396                                                            listenerClassName));
9397                                    }
9398    
9399                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
9400                            }
9401                            catch (Exception e) {
9402                                    _log.error(e);
9403                            }
9404                    }
9405            }
9406    
9407            public void destroy() {
9408                    EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
9409                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9410                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9411            }
9412    
9413            @BeanReference(type = MBBanPersistence.class)
9414            protected MBBanPersistence mbBanPersistence;
9415            @BeanReference(type = MBCategoryPersistence.class)
9416            protected MBCategoryPersistence mbCategoryPersistence;
9417            @BeanReference(type = MBDiscussionPersistence.class)
9418            protected MBDiscussionPersistence mbDiscussionPersistence;
9419            @BeanReference(type = MBMailingListPersistence.class)
9420            protected MBMailingListPersistence mbMailingListPersistence;
9421            @BeanReference(type = MBMessagePersistence.class)
9422            protected MBMessagePersistence mbMessagePersistence;
9423            @BeanReference(type = MBStatsUserPersistence.class)
9424            protected MBStatsUserPersistence mbStatsUserPersistence;
9425            @BeanReference(type = MBThreadPersistence.class)
9426            protected MBThreadPersistence mbThreadPersistence;
9427            @BeanReference(type = MBThreadFlagPersistence.class)
9428            protected MBThreadFlagPersistence mbThreadFlagPersistence;
9429            @BeanReference(type = LockPersistence.class)
9430            protected LockPersistence lockPersistence;
9431            @BeanReference(type = SubscriptionPersistence.class)
9432            protected SubscriptionPersistence subscriptionPersistence;
9433            @BeanReference(type = UserPersistence.class)
9434            protected UserPersistence userPersistence;
9435            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
9436            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
9437            @BeanReference(type = AssetEntryPersistence.class)
9438            protected AssetEntryPersistence assetEntryPersistence;
9439            @BeanReference(type = RatingsStatsPersistence.class)
9440            protected RatingsStatsPersistence ratingsStatsPersistence;
9441            @BeanReference(type = SocialActivityPersistence.class)
9442            protected SocialActivityPersistence socialActivityPersistence;
9443            @BeanReference(type = SocialActivityCounterPersistence.class)
9444            protected SocialActivityCounterPersistence socialActivityCounterPersistence;
9445            @BeanReference(type = TrashEntryPersistence.class)
9446            protected TrashEntryPersistence trashEntryPersistence;
9447            private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
9448            private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
9449            private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
9450            private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
9451            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
9452            private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
9453            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
9454            private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
9455                    _removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
9456            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
9457            private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
9458                    _removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
9459            private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
9460            private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
9461            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9462            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
9463            private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9464            private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
9465            private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
9466            private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
9467            private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
9468            private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
9469            private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9470            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
9471            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
9472            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9473            private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
9474                    _removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
9475            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9476            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
9477                    _removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
9478            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9479            private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
9480                    _removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
9481            private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9482            private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
9483            private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
9484    
9485            private static String _removeConjunction(String sql) {
9486                    int pos = sql.indexOf(" AND ");
9487    
9488                    if (pos != -1) {
9489                            sql = sql.substring(0, pos);
9490                    }
9491    
9492                    return sql;
9493            }
9494    
9495            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
9496            private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
9497            private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
9498                    "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
9499            private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
9500                    ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
9501            private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
9502            private static final String _FILTER_ENTITY_ALIAS = "mbThread";
9503            private static final String _FILTER_ENTITY_TABLE = "MBThread";
9504            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
9505            private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
9506            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
9507            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
9508            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9509            private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
9510            private static MBThread _nullMBThread = new MBThreadImpl() {
9511                            @Override
9512                            public Object clone() {
9513                                    return this;
9514                            }
9515    
9516                            @Override
9517                            public CacheModel<MBThread> toCacheModel() {
9518                                    return _nullMBThreadCacheModel;
9519                            }
9520                    };
9521    
9522            private static CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
9523                            public MBThread toEntityModel() {
9524                                    return _nullMBThread;
9525                            }
9526                    };
9527    }