001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.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.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.CalendarUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.LockPersistence;
040    import com.liferay.portal.service.persistence.ResourcePersistence;
041    import com.liferay.portal.service.persistence.UserPersistence;
042    import com.liferay.portal.service.persistence.WorkflowInstanceLinkPersistence;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
046    import com.liferay.portlet.messageboards.NoSuchThreadException;
047    import com.liferay.portlet.messageboards.model.MBThread;
048    import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
049    import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
050    import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
051    import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
052    
053    import java.io.Serializable;
054    
055    import java.util.ArrayList;
056    import java.util.Collections;
057    import java.util.Date;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the message boards thread service.
062     *
063     * <p>
064     * 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.
065     * </p>
066     *
067     * <p>
068     * Caching information and settings can be found in <code>portal.properties</code>
069     * </p>
070     *
071     * @author Brian Wing Shun Chan
072     * @see MBThreadPersistence
073     * @see MBThreadUtil
074     * @generated
075     */
076    public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
077            implements MBThreadPersistence {
078            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
079            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
080                    ".List";
081            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
082                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
083                            "findByGroupId",
084                            new String[] {
085                                    Long.class.getName(),
086                                    
087                            "java.lang.Integer", "java.lang.Integer",
088                                    "com.liferay.portal.kernel.util.OrderByComparator"
089                            });
090            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
091                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
092                            "countByGroupId", new String[] { Long.class.getName() });
093            public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
094                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
095                            "findByG_C",
096                            new String[] {
097                                    Long.class.getName(), Long.class.getName(),
098                                    
099                            "java.lang.Integer", "java.lang.Integer",
100                                    "com.liferay.portal.kernel.util.OrderByComparator"
101                            });
102            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
103                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "countByG_C",
105                            new String[] { Long.class.getName(), Long.class.getName() });
106            public static final FinderPath FINDER_PATH_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
107                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108                            "findByG_NotC",
109                            new String[] {
110                                    Long.class.getName(), Long.class.getName(),
111                                    
112                            "java.lang.Integer", "java.lang.Integer",
113                                    "com.liferay.portal.kernel.util.OrderByComparator"
114                            });
115            public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
116                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117                            "countByG_NotC",
118                            new String[] { Long.class.getName(), Long.class.getName() });
119            public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
120                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121                            "findByG_S",
122                            new String[] {
123                                    Long.class.getName(), Integer.class.getName(),
124                                    
125                            "java.lang.Integer", "java.lang.Integer",
126                                    "com.liferay.portal.kernel.util.OrderByComparator"
127                            });
128            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
129                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
130                            "countByG_S",
131                            new String[] { Long.class.getName(), Integer.class.getName() });
132            public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
133                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
134                            "findByC_P",
135                            new String[] {
136                                    Long.class.getName(), Double.class.getName(),
137                                    
138                            "java.lang.Integer", "java.lang.Integer",
139                                    "com.liferay.portal.kernel.util.OrderByComparator"
140                            });
141            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
142                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
143                            "countByC_P",
144                            new String[] { Long.class.getName(), Double.class.getName() });
145            public static final FinderPath FINDER_PATH_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
146                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
147                            "findByG_C_L",
148                            new String[] {
149                                    Long.class.getName(), Long.class.getName(), Date.class.getName(),
150                                    
151                            "java.lang.Integer", "java.lang.Integer",
152                                    "com.liferay.portal.kernel.util.OrderByComparator"
153                            });
154            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
155                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
156                            "countByG_C_L",
157                            new String[] {
158                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
159                            });
160            public static final FinderPath FINDER_PATH_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
161                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
162                            "findByG_C_S",
163                            new String[] {
164                                    Long.class.getName(), Long.class.getName(),
165                                    Integer.class.getName(),
166                                    
167                            "java.lang.Integer", "java.lang.Integer",
168                                    "com.liferay.portal.kernel.util.OrderByComparator"
169                            });
170            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
171                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
172                            "countByG_C_S",
173                            new String[] {
174                                    Long.class.getName(), Long.class.getName(),
175                                    Integer.class.getName()
176                            });
177            public static final FinderPath FINDER_PATH_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
178                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
179                            "findByG_NotC_S",
180                            new String[] {
181                                    Long.class.getName(), Long.class.getName(),
182                                    Integer.class.getName(),
183                                    
184                            "java.lang.Integer", "java.lang.Integer",
185                                    "com.liferay.portal.kernel.util.OrderByComparator"
186                            });
187            public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
188                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
189                            "countByG_NotC_S",
190                            new String[] {
191                                    Long.class.getName(), Long.class.getName(),
192                                    Integer.class.getName()
193                            });
194            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
195                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
196                            "findAll", new String[0]);
197            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
198                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
199                            "countAll", new String[0]);
200    
201            /**
202             * Caches the message boards thread in the entity cache if it is enabled.
203             *
204             * @param mbThread the message boards thread to cache
205             */
206            public void cacheResult(MBThread mbThread) {
207                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
208                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
209            }
210    
211            /**
212             * Caches the message boards threads in the entity cache if it is enabled.
213             *
214             * @param mbThreads the message boards threads to cache
215             */
216            public void cacheResult(List<MBThread> mbThreads) {
217                    for (MBThread mbThread : mbThreads) {
218                            if (EntityCacheUtil.getResult(
219                                                    MBThreadModelImpl.ENTITY_CACHE_ENABLED,
220                                                    MBThreadImpl.class, mbThread.getPrimaryKey(), this) == null) {
221                                    cacheResult(mbThread);
222                            }
223                    }
224            }
225    
226            /**
227             * Clears the cache for all message boards threads.
228             *
229             * <p>
230             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
231             * </p>
232             */
233            public void clearCache() {
234                    CacheRegistryUtil.clear(MBThreadImpl.class.getName());
235                    EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
236                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
237                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
238            }
239    
240            /**
241             * Clears the cache for the message boards thread.
242             *
243             * <p>
244             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
245             * </p>
246             */
247            public void clearCache(MBThread mbThread) {
248                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
249                            MBThreadImpl.class, mbThread.getPrimaryKey());
250            }
251    
252            /**
253             * Creates a new message boards thread with the primary key. Does not add the message boards thread to the database.
254             *
255             * @param threadId the primary key for the new message boards thread
256             * @return the new message boards thread
257             */
258            public MBThread create(long threadId) {
259                    MBThread mbThread = new MBThreadImpl();
260    
261                    mbThread.setNew(true);
262                    mbThread.setPrimaryKey(threadId);
263    
264                    return mbThread;
265            }
266    
267            /**
268             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
269             *
270             * @param primaryKey the primary key of the message boards thread to remove
271             * @return the message boards thread that was removed
272             * @throws com.liferay.portal.NoSuchModelException if a message boards thread with the primary key could not be found
273             * @throws SystemException if a system exception occurred
274             */
275            public MBThread remove(Serializable primaryKey)
276                    throws NoSuchModelException, SystemException {
277                    return remove(((Long)primaryKey).longValue());
278            }
279    
280            /**
281             * Removes the message boards thread with the primary key from the database. Also notifies the appropriate model listeners.
282             *
283             * @param threadId the primary key of the message boards thread to remove
284             * @return the message boards thread that was removed
285             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
286             * @throws SystemException if a system exception occurred
287             */
288            public MBThread remove(long threadId)
289                    throws NoSuchThreadException, SystemException {
290                    Session session = null;
291    
292                    try {
293                            session = openSession();
294    
295                            MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
296                                            new Long(threadId));
297    
298                            if (mbThread == null) {
299                                    if (_log.isWarnEnabled()) {
300                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
301                                    }
302    
303                                    throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
304                                            threadId);
305                            }
306    
307                            return remove(mbThread);
308                    }
309                    catch (NoSuchThreadException nsee) {
310                            throw nsee;
311                    }
312                    catch (Exception e) {
313                            throw processException(e);
314                    }
315                    finally {
316                            closeSession(session);
317                    }
318            }
319    
320            protected MBThread removeImpl(MBThread mbThread) throws SystemException {
321                    mbThread = toUnwrappedModel(mbThread);
322    
323                    Session session = null;
324    
325                    try {
326                            session = openSession();
327    
328                            BatchSessionUtil.delete(session, mbThread);
329                    }
330                    catch (Exception e) {
331                            throw processException(e);
332                    }
333                    finally {
334                            closeSession(session);
335                    }
336    
337                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
338    
339                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
340                            MBThreadImpl.class, mbThread.getPrimaryKey());
341    
342                    return mbThread;
343            }
344    
345            public MBThread updateImpl(
346                    com.liferay.portlet.messageboards.model.MBThread mbThread, boolean merge)
347                    throws SystemException {
348                    mbThread = toUnwrappedModel(mbThread);
349    
350                    Session session = null;
351    
352                    try {
353                            session = openSession();
354    
355                            BatchSessionUtil.update(session, mbThread, merge);
356    
357                            mbThread.setNew(false);
358                    }
359                    catch (Exception e) {
360                            throw processException(e);
361                    }
362                    finally {
363                            closeSession(session);
364                    }
365    
366                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
367    
368                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
369                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
370    
371                    return mbThread;
372            }
373    
374            protected MBThread toUnwrappedModel(MBThread mbThread) {
375                    if (mbThread instanceof MBThreadImpl) {
376                            return mbThread;
377                    }
378    
379                    MBThreadImpl mbThreadImpl = new MBThreadImpl();
380    
381                    mbThreadImpl.setNew(mbThread.isNew());
382                    mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
383    
384                    mbThreadImpl.setThreadId(mbThread.getThreadId());
385                    mbThreadImpl.setGroupId(mbThread.getGroupId());
386                    mbThreadImpl.setCategoryId(mbThread.getCategoryId());
387                    mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
388                    mbThreadImpl.setMessageCount(mbThread.getMessageCount());
389                    mbThreadImpl.setViewCount(mbThread.getViewCount());
390                    mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
391                    mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
392                    mbThreadImpl.setPriority(mbThread.getPriority());
393                    mbThreadImpl.setStatus(mbThread.getStatus());
394                    mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
395                    mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
396                    mbThreadImpl.setStatusDate(mbThread.getStatusDate());
397    
398                    return mbThreadImpl;
399            }
400    
401            /**
402             * Finds the message boards thread with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
403             *
404             * @param primaryKey the primary key of the message boards thread to find
405             * @return the message boards thread
406             * @throws com.liferay.portal.NoSuchModelException 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 findByPrimaryKey(Serializable primaryKey)
410                    throws NoSuchModelException, SystemException {
411                    return findByPrimaryKey(((Long)primaryKey).longValue());
412            }
413    
414            /**
415             * Finds the message boards thread with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadException} if it could not be found.
416             *
417             * @param threadId the primary key of the message boards thread to find
418             * @return the message boards thread
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            public MBThread findByPrimaryKey(long threadId)
423                    throws NoSuchThreadException, SystemException {
424                    MBThread mbThread = fetchByPrimaryKey(threadId);
425    
426                    if (mbThread == null) {
427                            if (_log.isWarnEnabled()) {
428                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
429                            }
430    
431                            throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
432                                    threadId);
433                    }
434    
435                    return mbThread;
436            }
437    
438            /**
439             * Finds the message boards thread with the primary key or returns <code>null</code> if it could not be found.
440             *
441             * @param primaryKey the primary key of the message boards thread to find
442             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
443             * @throws SystemException if a system exception occurred
444             */
445            public MBThread fetchByPrimaryKey(Serializable primaryKey)
446                    throws SystemException {
447                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
448            }
449    
450            /**
451             * Finds the message boards thread with the primary key or returns <code>null</code> if it could not be found.
452             *
453             * @param threadId the primary key of the message boards thread to find
454             * @return the message boards thread, or <code>null</code> if a message boards thread with the primary key could not be found
455             * @throws SystemException if a system exception occurred
456             */
457            public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
458                    MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
459                                    MBThreadImpl.class, threadId, this);
460    
461                    if (mbThread == null) {
462                            Session session = null;
463    
464                            try {
465                                    session = openSession();
466    
467                                    mbThread = (MBThread)session.get(MBThreadImpl.class,
468                                                    new Long(threadId));
469                            }
470                            catch (Exception e) {
471                                    throw processException(e);
472                            }
473                            finally {
474                                    if (mbThread != null) {
475                                            cacheResult(mbThread);
476                                    }
477    
478                                    closeSession(session);
479                            }
480                    }
481    
482                    return mbThread;
483            }
484    
485            /**
486             * Finds all the message boards threads where groupId = &#63;.
487             *
488             * @param groupId the group id to search with
489             * @return the matching message boards threads
490             * @throws SystemException if a system exception occurred
491             */
492            public List<MBThread> findByGroupId(long groupId) throws SystemException {
493                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
494            }
495    
496            /**
497             * Finds a range of all the message boards threads where groupId = &#63;.
498             *
499             * <p>
500             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
501             * </p>
502             *
503             * @param groupId the group id to search with
504             * @param start the lower bound of the range of message boards threads to return
505             * @param end the upper bound of the range of message boards threads to return (not inclusive)
506             * @return the range of matching message boards threads
507             * @throws SystemException if a system exception occurred
508             */
509            public List<MBThread> findByGroupId(long groupId, int start, int end)
510                    throws SystemException {
511                    return findByGroupId(groupId, start, end, null);
512            }
513    
514            /**
515             * Finds an ordered range of all the message boards threads where groupId = &#63;.
516             *
517             * <p>
518             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
519             * </p>
520             *
521             * @param groupId the group id to search with
522             * @param start the lower bound of the range of message boards threads to return
523             * @param end the upper bound of the range of message boards threads to return (not inclusive)
524             * @param orderByComparator the comparator to order the results by
525             * @return the ordered range of matching message boards threads
526             * @throws SystemException if a system exception occurred
527             */
528            public List<MBThread> findByGroupId(long groupId, int start, int end,
529                    OrderByComparator orderByComparator) throws SystemException {
530                    Object[] finderArgs = new Object[] {
531                                    groupId,
532                                    
533                                    String.valueOf(start), String.valueOf(end),
534                                    String.valueOf(orderByComparator)
535                            };
536    
537                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
538                                    finderArgs, this);
539    
540                    if (list == null) {
541                            Session session = null;
542    
543                            try {
544                                    session = openSession();
545    
546                                    StringBundler query = null;
547    
548                                    if (orderByComparator != null) {
549                                            query = new StringBundler(3 +
550                                                            (orderByComparator.getOrderByFields().length * 3));
551                                    }
552                                    else {
553                                            query = new StringBundler(3);
554                                    }
555    
556                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
557    
558                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
559    
560                                    if (orderByComparator != null) {
561                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
562                                                    orderByComparator);
563                                    }
564    
565                                    else {
566                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
567                                    }
568    
569                                    String sql = query.toString();
570    
571                                    Query q = session.createQuery(sql);
572    
573                                    QueryPos qPos = QueryPos.getInstance(q);
574    
575                                    qPos.add(groupId);
576    
577                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
578                                                    end);
579                            }
580                            catch (Exception e) {
581                                    throw processException(e);
582                            }
583                            finally {
584                                    if (list == null) {
585                                            list = new ArrayList<MBThread>();
586                                    }
587    
588                                    cacheResult(list);
589    
590                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
591                                            finderArgs, list);
592    
593                                    closeSession(session);
594                            }
595                    }
596    
597                    return list;
598            }
599    
600            /**
601             * Finds the first message boards thread in the ordered set where groupId = &#63;.
602             *
603             * <p>
604             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
605             * </p>
606             *
607             * @param groupId the group id to search with
608             * @param orderByComparator the comparator to order the set by
609             * @return the first matching message boards thread
610             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
611             * @throws SystemException if a system exception occurred
612             */
613            public MBThread findByGroupId_First(long groupId,
614                    OrderByComparator orderByComparator)
615                    throws NoSuchThreadException, SystemException {
616                    List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
617    
618                    if (list.isEmpty()) {
619                            StringBundler msg = new StringBundler(4);
620    
621                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
622    
623                            msg.append("groupId=");
624                            msg.append(groupId);
625    
626                            msg.append(StringPool.CLOSE_CURLY_BRACE);
627    
628                            throw new NoSuchThreadException(msg.toString());
629                    }
630                    else {
631                            return list.get(0);
632                    }
633            }
634    
635            /**
636             * Finds the last message boards thread in the ordered set where groupId = &#63;.
637             *
638             * <p>
639             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
640             * </p>
641             *
642             * @param groupId the group id to search with
643             * @param orderByComparator the comparator to order the set by
644             * @return the last matching message boards thread
645             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
646             * @throws SystemException if a system exception occurred
647             */
648            public MBThread findByGroupId_Last(long groupId,
649                    OrderByComparator orderByComparator)
650                    throws NoSuchThreadException, SystemException {
651                    int count = countByGroupId(groupId);
652    
653                    List<MBThread> list = findByGroupId(groupId, count - 1, count,
654                                    orderByComparator);
655    
656                    if (list.isEmpty()) {
657                            StringBundler msg = new StringBundler(4);
658    
659                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
660    
661                            msg.append("groupId=");
662                            msg.append(groupId);
663    
664                            msg.append(StringPool.CLOSE_CURLY_BRACE);
665    
666                            throw new NoSuchThreadException(msg.toString());
667                    }
668                    else {
669                            return list.get(0);
670                    }
671            }
672    
673            /**
674             * Finds the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63;.
675             *
676             * <p>
677             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
678             * </p>
679             *
680             * @param threadId the primary key of the current message boards thread
681             * @param groupId the group id to search with
682             * @param orderByComparator the comparator to order the set by
683             * @return the previous, current, and next message boards thread
684             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
685             * @throws SystemException if a system exception occurred
686             */
687            public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
688                    OrderByComparator orderByComparator)
689                    throws NoSuchThreadException, SystemException {
690                    MBThread mbThread = findByPrimaryKey(threadId);
691    
692                    Session session = null;
693    
694                    try {
695                            session = openSession();
696    
697                            MBThread[] array = new MBThreadImpl[3];
698    
699                            array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
700                                            orderByComparator, true);
701    
702                            array[1] = mbThread;
703    
704                            array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
705                                            orderByComparator, false);
706    
707                            return array;
708                    }
709                    catch (Exception e) {
710                            throw processException(e);
711                    }
712                    finally {
713                            closeSession(session);
714                    }
715            }
716    
717            protected MBThread getByGroupId_PrevAndNext(Session session,
718                    MBThread mbThread, long groupId, OrderByComparator orderByComparator,
719                    boolean previous) {
720                    StringBundler query = null;
721    
722                    if (orderByComparator != null) {
723                            query = new StringBundler(6 +
724                                            (orderByComparator.getOrderByFields().length * 6));
725                    }
726                    else {
727                            query = new StringBundler(3);
728                    }
729    
730                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
731    
732                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
733    
734                    if (orderByComparator != null) {
735                            String[] orderByFields = orderByComparator.getOrderByFields();
736    
737                            if (orderByFields.length > 0) {
738                                    query.append(WHERE_AND);
739                            }
740    
741                            for (int i = 0; i < orderByFields.length; i++) {
742                                    query.append(_ORDER_BY_ENTITY_ALIAS);
743                                    query.append(orderByFields[i]);
744    
745                                    if ((i + 1) < orderByFields.length) {
746                                            if (orderByComparator.isAscending() ^ previous) {
747                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
748                                            }
749                                            else {
750                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
751                                            }
752                                    }
753                                    else {
754                                            if (orderByComparator.isAscending() ^ previous) {
755                                                    query.append(WHERE_GREATER_THAN);
756                                            }
757                                            else {
758                                                    query.append(WHERE_LESSER_THAN);
759                                            }
760                                    }
761                            }
762    
763                            query.append(ORDER_BY_CLAUSE);
764    
765                            for (int i = 0; i < orderByFields.length; i++) {
766                                    query.append(_ORDER_BY_ENTITY_ALIAS);
767                                    query.append(orderByFields[i]);
768    
769                                    if ((i + 1) < orderByFields.length) {
770                                            if (orderByComparator.isAscending() ^ previous) {
771                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
772                                            }
773                                            else {
774                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
775                                            }
776                                    }
777                                    else {
778                                            if (orderByComparator.isAscending() ^ previous) {
779                                                    query.append(ORDER_BY_ASC);
780                                            }
781                                            else {
782                                                    query.append(ORDER_BY_DESC);
783                                            }
784                                    }
785                            }
786                    }
787    
788                    else {
789                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
790                    }
791    
792                    String sql = query.toString();
793    
794                    Query q = session.createQuery(sql);
795    
796                    q.setFirstResult(0);
797                    q.setMaxResults(2);
798    
799                    QueryPos qPos = QueryPos.getInstance(q);
800    
801                    qPos.add(groupId);
802    
803                    if (orderByComparator != null) {
804                            Object[] values = orderByComparator.getOrderByValues(mbThread);
805    
806                            for (Object value : values) {
807                                    qPos.add(value);
808                            }
809                    }
810    
811                    List<MBThread> list = q.list();
812    
813                    if (list.size() == 2) {
814                            return list.get(1);
815                    }
816                    else {
817                            return null;
818                    }
819            }
820    
821            /**
822             * Finds all the message boards threads where groupId = &#63; and categoryId = &#63;.
823             *
824             * @param groupId the group id to search with
825             * @param categoryId the category id to search with
826             * @return the matching message boards threads
827             * @throws SystemException if a system exception occurred
828             */
829            public List<MBThread> findByG_C(long groupId, long categoryId)
830                    throws SystemException {
831                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
832                            QueryUtil.ALL_POS, null);
833            }
834    
835            /**
836             * Finds a range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
837             *
838             * <p>
839             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
840             * </p>
841             *
842             * @param groupId the group id to search with
843             * @param categoryId the category id to search with
844             * @param start the lower bound of the range of message boards threads to return
845             * @param end the upper bound of the range of message boards threads to return (not inclusive)
846             * @return the range of matching message boards threads
847             * @throws SystemException if a system exception occurred
848             */
849            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
850                    int end) throws SystemException {
851                    return findByG_C(groupId, categoryId, start, end, null);
852            }
853    
854            /**
855             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63;.
856             *
857             * <p>
858             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
859             * </p>
860             *
861             * @param groupId the group id to search with
862             * @param categoryId the category id to search with
863             * @param start the lower bound of the range of message boards threads to return
864             * @param end the upper bound of the range of message boards threads to return (not inclusive)
865             * @param orderByComparator the comparator to order the results by
866             * @return the ordered range of matching message boards threads
867             * @throws SystemException if a system exception occurred
868             */
869            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
870                    int end, OrderByComparator orderByComparator) throws SystemException {
871                    Object[] finderArgs = new Object[] {
872                                    groupId, categoryId,
873                                    
874                                    String.valueOf(start), String.valueOf(end),
875                                    String.valueOf(orderByComparator)
876                            };
877    
878                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
879                                    finderArgs, this);
880    
881                    if (list == null) {
882                            Session session = null;
883    
884                            try {
885                                    session = openSession();
886    
887                                    StringBundler query = null;
888    
889                                    if (orderByComparator != null) {
890                                            query = new StringBundler(4 +
891                                                            (orderByComparator.getOrderByFields().length * 3));
892                                    }
893                                    else {
894                                            query = new StringBundler(4);
895                                    }
896    
897                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
898    
899                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
900    
901                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
902    
903                                    if (orderByComparator != null) {
904                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
905                                                    orderByComparator);
906                                    }
907    
908                                    else {
909                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
910                                    }
911    
912                                    String sql = query.toString();
913    
914                                    Query q = session.createQuery(sql);
915    
916                                    QueryPos qPos = QueryPos.getInstance(q);
917    
918                                    qPos.add(groupId);
919    
920                                    qPos.add(categoryId);
921    
922                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
923                                                    end);
924                            }
925                            catch (Exception e) {
926                                    throw processException(e);
927                            }
928                            finally {
929                                    if (list == null) {
930                                            list = new ArrayList<MBThread>();
931                                    }
932    
933                                    cacheResult(list);
934    
935                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
936                                            list);
937    
938                                    closeSession(session);
939                            }
940                    }
941    
942                    return list;
943            }
944    
945            /**
946             * Finds the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
947             *
948             * <p>
949             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
950             * </p>
951             *
952             * @param groupId the group id to search with
953             * @param categoryId the category id to search with
954             * @param orderByComparator the comparator to order the set by
955             * @return the first matching message boards thread
956             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
957             * @throws SystemException if a system exception occurred
958             */
959            public MBThread findByG_C_First(long groupId, long categoryId,
960                    OrderByComparator orderByComparator)
961                    throws NoSuchThreadException, SystemException {
962                    List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
963                                    orderByComparator);
964    
965                    if (list.isEmpty()) {
966                            StringBundler msg = new StringBundler(6);
967    
968                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
969    
970                            msg.append("groupId=");
971                            msg.append(groupId);
972    
973                            msg.append(", categoryId=");
974                            msg.append(categoryId);
975    
976                            msg.append(StringPool.CLOSE_CURLY_BRACE);
977    
978                            throw new NoSuchThreadException(msg.toString());
979                    }
980                    else {
981                            return list.get(0);
982                    }
983            }
984    
985            /**
986             * Finds the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
987             *
988             * <p>
989             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
990             * </p>
991             *
992             * @param groupId the group id to search with
993             * @param categoryId the category id to search with
994             * @param orderByComparator the comparator to order the set by
995             * @return the last matching message boards thread
996             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
997             * @throws SystemException if a system exception occurred
998             */
999            public MBThread findByG_C_Last(long groupId, long categoryId,
1000                    OrderByComparator orderByComparator)
1001                    throws NoSuchThreadException, SystemException {
1002                    int count = countByG_C(groupId, categoryId);
1003    
1004                    List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
1005                                    orderByComparator);
1006    
1007                    if (list.isEmpty()) {
1008                            StringBundler msg = new StringBundler(6);
1009    
1010                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1011    
1012                            msg.append("groupId=");
1013                            msg.append(groupId);
1014    
1015                            msg.append(", categoryId=");
1016                            msg.append(categoryId);
1017    
1018                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1019    
1020                            throw new NoSuchThreadException(msg.toString());
1021                    }
1022                    else {
1023                            return list.get(0);
1024                    }
1025            }
1026    
1027            /**
1028             * Finds the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId = &#63;.
1029             *
1030             * <p>
1031             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1032             * </p>
1033             *
1034             * @param threadId the primary key of the current message boards thread
1035             * @param groupId the group id to search with
1036             * @param categoryId the category id to search with
1037             * @param orderByComparator the comparator to order the set by
1038             * @return the previous, current, and next message boards thread
1039             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1040             * @throws SystemException if a system exception occurred
1041             */
1042            public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
1043                    long categoryId, OrderByComparator orderByComparator)
1044                    throws NoSuchThreadException, SystemException {
1045                    MBThread mbThread = findByPrimaryKey(threadId);
1046    
1047                    Session session = null;
1048    
1049                    try {
1050                            session = openSession();
1051    
1052                            MBThread[] array = new MBThreadImpl[3];
1053    
1054                            array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
1055                                            categoryId, orderByComparator, true);
1056    
1057                            array[1] = mbThread;
1058    
1059                            array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
1060                                            categoryId, orderByComparator, false);
1061    
1062                            return array;
1063                    }
1064                    catch (Exception e) {
1065                            throw processException(e);
1066                    }
1067                    finally {
1068                            closeSession(session);
1069                    }
1070            }
1071    
1072            protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
1073                    long groupId, long categoryId, OrderByComparator orderByComparator,
1074                    boolean previous) {
1075                    StringBundler query = null;
1076    
1077                    if (orderByComparator != null) {
1078                            query = new StringBundler(6 +
1079                                            (orderByComparator.getOrderByFields().length * 6));
1080                    }
1081                    else {
1082                            query = new StringBundler(3);
1083                    }
1084    
1085                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1086    
1087                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1088    
1089                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1090    
1091                    if (orderByComparator != null) {
1092                            String[] orderByFields = orderByComparator.getOrderByFields();
1093    
1094                            if (orderByFields.length > 0) {
1095                                    query.append(WHERE_AND);
1096                            }
1097    
1098                            for (int i = 0; i < orderByFields.length; i++) {
1099                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1100                                    query.append(orderByFields[i]);
1101    
1102                                    if ((i + 1) < orderByFields.length) {
1103                                            if (orderByComparator.isAscending() ^ previous) {
1104                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1105                                            }
1106                                            else {
1107                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1108                                            }
1109                                    }
1110                                    else {
1111                                            if (orderByComparator.isAscending() ^ previous) {
1112                                                    query.append(WHERE_GREATER_THAN);
1113                                            }
1114                                            else {
1115                                                    query.append(WHERE_LESSER_THAN);
1116                                            }
1117                                    }
1118                            }
1119    
1120                            query.append(ORDER_BY_CLAUSE);
1121    
1122                            for (int i = 0; i < orderByFields.length; i++) {
1123                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1124                                    query.append(orderByFields[i]);
1125    
1126                                    if ((i + 1) < orderByFields.length) {
1127                                            if (orderByComparator.isAscending() ^ previous) {
1128                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1129                                            }
1130                                            else {
1131                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1132                                            }
1133                                    }
1134                                    else {
1135                                            if (orderByComparator.isAscending() ^ previous) {
1136                                                    query.append(ORDER_BY_ASC);
1137                                            }
1138                                            else {
1139                                                    query.append(ORDER_BY_DESC);
1140                                            }
1141                                    }
1142                            }
1143                    }
1144    
1145                    else {
1146                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1147                    }
1148    
1149                    String sql = query.toString();
1150    
1151                    Query q = session.createQuery(sql);
1152    
1153                    q.setFirstResult(0);
1154                    q.setMaxResults(2);
1155    
1156                    QueryPos qPos = QueryPos.getInstance(q);
1157    
1158                    qPos.add(groupId);
1159    
1160                    qPos.add(categoryId);
1161    
1162                    if (orderByComparator != null) {
1163                            Object[] values = orderByComparator.getOrderByValues(mbThread);
1164    
1165                            for (Object value : values) {
1166                                    qPos.add(value);
1167                            }
1168                    }
1169    
1170                    List<MBThread> list = q.list();
1171    
1172                    if (list.size() == 2) {
1173                            return list.get(1);
1174                    }
1175                    else {
1176                            return null;
1177                    }
1178            }
1179    
1180            /**
1181             * Finds all the message boards threads where groupId = &#63; and categoryId = any &#63;.
1182             *
1183             * <p>
1184             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1185             * </p>
1186             *
1187             * @param groupId the group id to search with
1188             * @param categoryIds the category ids to search with
1189             * @return the matching message boards threads
1190             * @throws SystemException if a system exception occurred
1191             */
1192            public List<MBThread> findByG_C(long groupId, long[] categoryIds)
1193                    throws SystemException {
1194                    return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
1195                            QueryUtil.ALL_POS, null);
1196            }
1197    
1198            /**
1199             * Finds a range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
1200             *
1201             * <p>
1202             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1203             * </p>
1204             *
1205             * @param groupId the group id to search with
1206             * @param categoryIds the category ids to search with
1207             * @param start the lower bound of the range of message boards threads to return
1208             * @param end the upper bound of the range of message boards threads to return (not inclusive)
1209             * @return the range of matching message boards threads
1210             * @throws SystemException if a system exception occurred
1211             */
1212            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
1213                    int start, int end) throws SystemException {
1214                    return findByG_C(groupId, categoryIds, start, end, null);
1215            }
1216    
1217            /**
1218             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63;.
1219             *
1220             * <p>
1221             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1222             * </p>
1223             *
1224             * @param groupId the group id to search with
1225             * @param categoryIds the category ids to search with
1226             * @param start the lower bound of the range of message boards threads to return
1227             * @param end the upper bound of the range of message boards threads to return (not inclusive)
1228             * @param orderByComparator the comparator to order the results by
1229             * @return the ordered range of matching message boards threads
1230             * @throws SystemException if a system exception occurred
1231             */
1232            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
1233                    int start, int end, OrderByComparator orderByComparator)
1234                    throws SystemException {
1235                    Object[] finderArgs = new Object[] {
1236                                    groupId, StringUtil.merge(categoryIds),
1237                                    
1238                                    String.valueOf(start), String.valueOf(end),
1239                                    String.valueOf(orderByComparator)
1240                            };
1241    
1242                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
1243                                    finderArgs, this);
1244    
1245                    if (list == null) {
1246                            Session session = null;
1247    
1248                            try {
1249                                    session = openSession();
1250    
1251                                    StringBundler query = new StringBundler();
1252    
1253                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1254    
1255                                    boolean conjunctionable = false;
1256    
1257                                    if (conjunctionable) {
1258                                            query.append(WHERE_AND);
1259                                    }
1260    
1261                                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
1262    
1263                                    conjunctionable = true;
1264    
1265                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
1266                                            if (conjunctionable) {
1267                                                    query.append(WHERE_AND);
1268                                            }
1269    
1270                                            query.append(StringPool.OPEN_PARENTHESIS);
1271    
1272                                            for (int i = 0; i < categoryIds.length; i++) {
1273                                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
1274    
1275                                                    if ((i + 1) < categoryIds.length) {
1276                                                            query.append(WHERE_OR);
1277                                                    }
1278                                            }
1279    
1280                                            query.append(StringPool.CLOSE_PARENTHESIS);
1281    
1282                                            conjunctionable = true;
1283                                    }
1284    
1285                                    if (orderByComparator != null) {
1286                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1287                                                    orderByComparator);
1288                                    }
1289    
1290                                    else {
1291                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1292                                    }
1293    
1294                                    String sql = query.toString();
1295    
1296                                    Query q = session.createQuery(sql);
1297    
1298                                    QueryPos qPos = QueryPos.getInstance(q);
1299    
1300                                    qPos.add(groupId);
1301    
1302                                    if (categoryIds != null) {
1303                                            qPos.add(categoryIds);
1304                                    }
1305    
1306                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1307                                                    end);
1308                            }
1309                            catch (Exception e) {
1310                                    throw processException(e);
1311                            }
1312                            finally {
1313                                    if (list == null) {
1314                                            list = new ArrayList<MBThread>();
1315                                    }
1316    
1317                                    cacheResult(list);
1318    
1319                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
1320                                            list);
1321    
1322                                    closeSession(session);
1323                            }
1324                    }
1325    
1326                    return list;
1327            }
1328    
1329            /**
1330             * Finds all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
1331             *
1332             * @param groupId the group id to search with
1333             * @param categoryId the category id to search with
1334             * @return the matching message boards threads
1335             * @throws SystemException if a system exception occurred
1336             */
1337            public List<MBThread> findByG_NotC(long groupId, long categoryId)
1338                    throws SystemException {
1339                    return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
1340                            QueryUtil.ALL_POS, null);
1341            }
1342    
1343            /**
1344             * Finds a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
1345             *
1346             * <p>
1347             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1348             * </p>
1349             *
1350             * @param groupId the group id to search with
1351             * @param categoryId the category id to search with
1352             * @param start the lower bound of the range of message boards threads to return
1353             * @param end the upper bound of the range of message boards threads to return (not inclusive)
1354             * @return the range of matching message boards threads
1355             * @throws SystemException if a system exception occurred
1356             */
1357            public List<MBThread> findByG_NotC(long groupId, long categoryId,
1358                    int start, int end) throws SystemException {
1359                    return findByG_NotC(groupId, categoryId, start, end, null);
1360            }
1361    
1362            /**
1363             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
1364             *
1365             * <p>
1366             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1367             * </p>
1368             *
1369             * @param groupId the group id to search with
1370             * @param categoryId the category id to search with
1371             * @param start the lower bound of the range of message boards threads to return
1372             * @param end the upper bound of the range of message boards threads to return (not inclusive)
1373             * @param orderByComparator the comparator to order the results by
1374             * @return the ordered range of matching message boards threads
1375             * @throws SystemException if a system exception occurred
1376             */
1377            public List<MBThread> findByG_NotC(long groupId, long categoryId,
1378                    int start, int end, OrderByComparator orderByComparator)
1379                    throws SystemException {
1380                    Object[] finderArgs = new Object[] {
1381                                    groupId, categoryId,
1382                                    
1383                                    String.valueOf(start), String.valueOf(end),
1384                                    String.valueOf(orderByComparator)
1385                            };
1386    
1387                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTC,
1388                                    finderArgs, this);
1389    
1390                    if (list == null) {
1391                            Session session = null;
1392    
1393                            try {
1394                                    session = openSession();
1395    
1396                                    StringBundler query = null;
1397    
1398                                    if (orderByComparator != null) {
1399                                            query = new StringBundler(4 +
1400                                                            (orderByComparator.getOrderByFields().length * 3));
1401                                    }
1402                                    else {
1403                                            query = new StringBundler(4);
1404                                    }
1405    
1406                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1407    
1408                                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
1409    
1410                                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
1411    
1412                                    if (orderByComparator != null) {
1413                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1414                                                    orderByComparator);
1415                                    }
1416    
1417                                    else {
1418                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1419                                    }
1420    
1421                                    String sql = query.toString();
1422    
1423                                    Query q = session.createQuery(sql);
1424    
1425                                    QueryPos qPos = QueryPos.getInstance(q);
1426    
1427                                    qPos.add(groupId);
1428    
1429                                    qPos.add(categoryId);
1430    
1431                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1432                                                    end);
1433                            }
1434                            catch (Exception e) {
1435                                    throw processException(e);
1436                            }
1437                            finally {
1438                                    if (list == null) {
1439                                            list = new ArrayList<MBThread>();
1440                                    }
1441    
1442                                    cacheResult(list);
1443    
1444                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTC,
1445                                            finderArgs, list);
1446    
1447                                    closeSession(session);
1448                            }
1449                    }
1450    
1451                    return list;
1452            }
1453    
1454            /**
1455             * Finds the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
1456             *
1457             * <p>
1458             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1459             * </p>
1460             *
1461             * @param groupId the group id to search with
1462             * @param categoryId the category id to search with
1463             * @param orderByComparator the comparator to order the set by
1464             * @return the first matching message boards thread
1465             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1466             * @throws SystemException if a system exception occurred
1467             */
1468            public MBThread findByG_NotC_First(long groupId, long categoryId,
1469                    OrderByComparator orderByComparator)
1470                    throws NoSuchThreadException, SystemException {
1471                    List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
1472                                    orderByComparator);
1473    
1474                    if (list.isEmpty()) {
1475                            StringBundler msg = new StringBundler(6);
1476    
1477                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1478    
1479                            msg.append("groupId=");
1480                            msg.append(groupId);
1481    
1482                            msg.append(", categoryId=");
1483                            msg.append(categoryId);
1484    
1485                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1486    
1487                            throw new NoSuchThreadException(msg.toString());
1488                    }
1489                    else {
1490                            return list.get(0);
1491                    }
1492            }
1493    
1494            /**
1495             * Finds the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
1496             *
1497             * <p>
1498             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1499             * </p>
1500             *
1501             * @param groupId the group id to search with
1502             * @param categoryId the category id to search with
1503             * @param orderByComparator the comparator to order the set by
1504             * @return the last matching message boards thread
1505             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1506             * @throws SystemException if a system exception occurred
1507             */
1508            public MBThread findByG_NotC_Last(long groupId, long categoryId,
1509                    OrderByComparator orderByComparator)
1510                    throws NoSuchThreadException, SystemException {
1511                    int count = countByG_NotC(groupId, categoryId);
1512    
1513                    List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
1514                                    count, orderByComparator);
1515    
1516                    if (list.isEmpty()) {
1517                            StringBundler msg = new StringBundler(6);
1518    
1519                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1520    
1521                            msg.append("groupId=");
1522                            msg.append(groupId);
1523    
1524                            msg.append(", categoryId=");
1525                            msg.append(categoryId);
1526    
1527                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1528    
1529                            throw new NoSuchThreadException(msg.toString());
1530                    }
1531                    else {
1532                            return list.get(0);
1533                    }
1534            }
1535    
1536            /**
1537             * Finds the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63;.
1538             *
1539             * <p>
1540             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1541             * </p>
1542             *
1543             * @param threadId the primary key of the current message boards thread
1544             * @param groupId the group id to search with
1545             * @param categoryId the category id to search with
1546             * @param orderByComparator the comparator to order the set by
1547             * @return the previous, current, and next message boards thread
1548             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1549             * @throws SystemException if a system exception occurred
1550             */
1551            public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
1552                    long categoryId, OrderByComparator orderByComparator)
1553                    throws NoSuchThreadException, SystemException {
1554                    MBThread mbThread = findByPrimaryKey(threadId);
1555    
1556                    Session session = null;
1557    
1558                    try {
1559                            session = openSession();
1560    
1561                            MBThread[] array = new MBThreadImpl[3];
1562    
1563                            array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
1564                                            categoryId, orderByComparator, true);
1565    
1566                            array[1] = mbThread;
1567    
1568                            array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
1569                                            categoryId, orderByComparator, false);
1570    
1571                            return array;
1572                    }
1573                    catch (Exception e) {
1574                            throw processException(e);
1575                    }
1576                    finally {
1577                            closeSession(session);
1578                    }
1579            }
1580    
1581            protected MBThread getByG_NotC_PrevAndNext(Session session,
1582                    MBThread mbThread, long groupId, long categoryId,
1583                    OrderByComparator orderByComparator, boolean previous) {
1584                    StringBundler query = null;
1585    
1586                    if (orderByComparator != null) {
1587                            query = new StringBundler(6 +
1588                                            (orderByComparator.getOrderByFields().length * 6));
1589                    }
1590                    else {
1591                            query = new StringBundler(3);
1592                    }
1593    
1594                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1595    
1596                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
1597    
1598                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
1599    
1600                    if (orderByComparator != null) {
1601                            String[] orderByFields = orderByComparator.getOrderByFields();
1602    
1603                            if (orderByFields.length > 0) {
1604                                    query.append(WHERE_AND);
1605                            }
1606    
1607                            for (int i = 0; i < orderByFields.length; i++) {
1608                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1609                                    query.append(orderByFields[i]);
1610    
1611                                    if ((i + 1) < orderByFields.length) {
1612                                            if (orderByComparator.isAscending() ^ previous) {
1613                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1614                                            }
1615                                            else {
1616                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1617                                            }
1618                                    }
1619                                    else {
1620                                            if (orderByComparator.isAscending() ^ previous) {
1621                                                    query.append(WHERE_GREATER_THAN);
1622                                            }
1623                                            else {
1624                                                    query.append(WHERE_LESSER_THAN);
1625                                            }
1626                                    }
1627                            }
1628    
1629                            query.append(ORDER_BY_CLAUSE);
1630    
1631                            for (int i = 0; i < orderByFields.length; i++) {
1632                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1633                                    query.append(orderByFields[i]);
1634    
1635                                    if ((i + 1) < orderByFields.length) {
1636                                            if (orderByComparator.isAscending() ^ previous) {
1637                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1638                                            }
1639                                            else {
1640                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1641                                            }
1642                                    }
1643                                    else {
1644                                            if (orderByComparator.isAscending() ^ previous) {
1645                                                    query.append(ORDER_BY_ASC);
1646                                            }
1647                                            else {
1648                                                    query.append(ORDER_BY_DESC);
1649                                            }
1650                                    }
1651                            }
1652                    }
1653    
1654                    else {
1655                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1656                    }
1657    
1658                    String sql = query.toString();
1659    
1660                    Query q = session.createQuery(sql);
1661    
1662                    q.setFirstResult(0);
1663                    q.setMaxResults(2);
1664    
1665                    QueryPos qPos = QueryPos.getInstance(q);
1666    
1667                    qPos.add(groupId);
1668    
1669                    qPos.add(categoryId);
1670    
1671                    if (orderByComparator != null) {
1672                            Object[] values = orderByComparator.getOrderByValues(mbThread);
1673    
1674                            for (Object value : values) {
1675                                    qPos.add(value);
1676                            }
1677                    }
1678    
1679                    List<MBThread> list = q.list();
1680    
1681                    if (list.size() == 2) {
1682                            return list.get(1);
1683                    }
1684                    else {
1685                            return null;
1686                    }
1687            }
1688    
1689            /**
1690             * Finds all the message boards threads where groupId = &#63; and status = &#63;.
1691             *
1692             * @param groupId the group id to search with
1693             * @param status the status to search with
1694             * @return the matching message boards threads
1695             * @throws SystemException if a system exception occurred
1696             */
1697            public List<MBThread> findByG_S(long groupId, int status)
1698                    throws SystemException {
1699                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1700                            null);
1701            }
1702    
1703            /**
1704             * Finds a range of all the message boards threads where groupId = &#63; and status = &#63;.
1705             *
1706             * <p>
1707             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1708             * </p>
1709             *
1710             * @param groupId the group id to search with
1711             * @param status the status to search with
1712             * @param start the lower bound of the range of message boards threads to return
1713             * @param end the upper bound of the range of message boards threads to return (not inclusive)
1714             * @return the range of matching message boards threads
1715             * @throws SystemException if a system exception occurred
1716             */
1717            public List<MBThread> findByG_S(long groupId, int status, int start, int end)
1718                    throws SystemException {
1719                    return findByG_S(groupId, status, start, end, null);
1720            }
1721    
1722            /**
1723             * Finds an ordered range of all the message boards threads where groupId = &#63; and status = &#63;.
1724             *
1725             * <p>
1726             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1727             * </p>
1728             *
1729             * @param groupId the group id to search with
1730             * @param status the status to search with
1731             * @param start the lower bound of the range of message boards threads to return
1732             * @param end the upper bound of the range of message boards threads to return (not inclusive)
1733             * @param orderByComparator the comparator to order the results by
1734             * @return the ordered range of matching message boards threads
1735             * @throws SystemException if a system exception occurred
1736             */
1737            public List<MBThread> findByG_S(long groupId, int status, int start,
1738                    int end, OrderByComparator orderByComparator) throws SystemException {
1739                    Object[] finderArgs = new Object[] {
1740                                    groupId, status,
1741                                    
1742                                    String.valueOf(start), String.valueOf(end),
1743                                    String.valueOf(orderByComparator)
1744                            };
1745    
1746                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
1747                                    finderArgs, this);
1748    
1749                    if (list == null) {
1750                            Session session = null;
1751    
1752                            try {
1753                                    session = openSession();
1754    
1755                                    StringBundler query = null;
1756    
1757                                    if (orderByComparator != null) {
1758                                            query = new StringBundler(4 +
1759                                                            (orderByComparator.getOrderByFields().length * 3));
1760                                    }
1761                                    else {
1762                                            query = new StringBundler(4);
1763                                    }
1764    
1765                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1766    
1767                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1768    
1769                                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
1770    
1771                                    if (orderByComparator != null) {
1772                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1773                                                    orderByComparator);
1774                                    }
1775    
1776                                    else {
1777                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1778                                    }
1779    
1780                                    String sql = query.toString();
1781    
1782                                    Query q = session.createQuery(sql);
1783    
1784                                    QueryPos qPos = QueryPos.getInstance(q);
1785    
1786                                    qPos.add(groupId);
1787    
1788                                    qPos.add(status);
1789    
1790                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1791                                                    end);
1792                            }
1793                            catch (Exception e) {
1794                                    throw processException(e);
1795                            }
1796                            finally {
1797                                    if (list == null) {
1798                                            list = new ArrayList<MBThread>();
1799                                    }
1800    
1801                                    cacheResult(list);
1802    
1803                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S, finderArgs,
1804                                            list);
1805    
1806                                    closeSession(session);
1807                            }
1808                    }
1809    
1810                    return list;
1811            }
1812    
1813            /**
1814             * Finds the first message boards thread in the ordered set where groupId = &#63; and status = &#63;.
1815             *
1816             * <p>
1817             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1818             * </p>
1819             *
1820             * @param groupId the group id to search with
1821             * @param status the status to search with
1822             * @param orderByComparator the comparator to order the set by
1823             * @return the first matching message boards thread
1824             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1825             * @throws SystemException if a system exception occurred
1826             */
1827            public MBThread findByG_S_First(long groupId, int status,
1828                    OrderByComparator orderByComparator)
1829                    throws NoSuchThreadException, SystemException {
1830                    List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
1831    
1832                    if (list.isEmpty()) {
1833                            StringBundler msg = new StringBundler(6);
1834    
1835                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1836    
1837                            msg.append("groupId=");
1838                            msg.append(groupId);
1839    
1840                            msg.append(", status=");
1841                            msg.append(status);
1842    
1843                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1844    
1845                            throw new NoSuchThreadException(msg.toString());
1846                    }
1847                    else {
1848                            return list.get(0);
1849                    }
1850            }
1851    
1852            /**
1853             * Finds the last message boards thread in the ordered set where groupId = &#63; and status = &#63;.
1854             *
1855             * <p>
1856             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1857             * </p>
1858             *
1859             * @param groupId the group id to search with
1860             * @param status the status to search with
1861             * @param orderByComparator the comparator to order the set by
1862             * @return the last matching message boards thread
1863             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
1864             * @throws SystemException if a system exception occurred
1865             */
1866            public MBThread findByG_S_Last(long groupId, int status,
1867                    OrderByComparator orderByComparator)
1868                    throws NoSuchThreadException, SystemException {
1869                    int count = countByG_S(groupId, status);
1870    
1871                    List<MBThread> list = findByG_S(groupId, status, count - 1, count,
1872                                    orderByComparator);
1873    
1874                    if (list.isEmpty()) {
1875                            StringBundler msg = new StringBundler(6);
1876    
1877                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1878    
1879                            msg.append("groupId=");
1880                            msg.append(groupId);
1881    
1882                            msg.append(", status=");
1883                            msg.append(status);
1884    
1885                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1886    
1887                            throw new NoSuchThreadException(msg.toString());
1888                    }
1889                    else {
1890                            return list.get(0);
1891                    }
1892            }
1893    
1894            /**
1895             * Finds the message boards threads before and after the current message boards thread in the ordered set where groupId = &#63; and status = &#63;.
1896             *
1897             * <p>
1898             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1899             * </p>
1900             *
1901             * @param threadId the primary key of the current message boards thread
1902             * @param groupId the group id to search with
1903             * @param status the status to search with
1904             * @param orderByComparator the comparator to order the set by
1905             * @return the previous, current, and next message boards thread
1906             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
1907             * @throws SystemException if a system exception occurred
1908             */
1909            public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
1910                    int status, OrderByComparator orderByComparator)
1911                    throws NoSuchThreadException, SystemException {
1912                    MBThread mbThread = findByPrimaryKey(threadId);
1913    
1914                    Session session = null;
1915    
1916                    try {
1917                            session = openSession();
1918    
1919                            MBThread[] array = new MBThreadImpl[3];
1920    
1921                            array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
1922                                            orderByComparator, true);
1923    
1924                            array[1] = mbThread;
1925    
1926                            array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
1927                                            orderByComparator, false);
1928    
1929                            return array;
1930                    }
1931                    catch (Exception e) {
1932                            throw processException(e);
1933                    }
1934                    finally {
1935                            closeSession(session);
1936                    }
1937            }
1938    
1939            protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
1940                    long groupId, int status, OrderByComparator orderByComparator,
1941                    boolean previous) {
1942                    StringBundler query = null;
1943    
1944                    if (orderByComparator != null) {
1945                            query = new StringBundler(6 +
1946                                            (orderByComparator.getOrderByFields().length * 6));
1947                    }
1948                    else {
1949                            query = new StringBundler(3);
1950                    }
1951    
1952                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1953    
1954                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1955    
1956                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
1957    
1958                    if (orderByComparator != null) {
1959                            String[] orderByFields = orderByComparator.getOrderByFields();
1960    
1961                            if (orderByFields.length > 0) {
1962                                    query.append(WHERE_AND);
1963                            }
1964    
1965                            for (int i = 0; i < orderByFields.length; i++) {
1966                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1967                                    query.append(orderByFields[i]);
1968    
1969                                    if ((i + 1) < orderByFields.length) {
1970                                            if (orderByComparator.isAscending() ^ previous) {
1971                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1972                                            }
1973                                            else {
1974                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1975                                            }
1976                                    }
1977                                    else {
1978                                            if (orderByComparator.isAscending() ^ previous) {
1979                                                    query.append(WHERE_GREATER_THAN);
1980                                            }
1981                                            else {
1982                                                    query.append(WHERE_LESSER_THAN);
1983                                            }
1984                                    }
1985                            }
1986    
1987                            query.append(ORDER_BY_CLAUSE);
1988    
1989                            for (int i = 0; i < orderByFields.length; i++) {
1990                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1991                                    query.append(orderByFields[i]);
1992    
1993                                    if ((i + 1) < orderByFields.length) {
1994                                            if (orderByComparator.isAscending() ^ previous) {
1995                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1996                                            }
1997                                            else {
1998                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1999                                            }
2000                                    }
2001                                    else {
2002                                            if (orderByComparator.isAscending() ^ previous) {
2003                                                    query.append(ORDER_BY_ASC);
2004                                            }
2005                                            else {
2006                                                    query.append(ORDER_BY_DESC);
2007                                            }
2008                                    }
2009                            }
2010                    }
2011    
2012                    else {
2013                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2014                    }
2015    
2016                    String sql = query.toString();
2017    
2018                    Query q = session.createQuery(sql);
2019    
2020                    q.setFirstResult(0);
2021                    q.setMaxResults(2);
2022    
2023                    QueryPos qPos = QueryPos.getInstance(q);
2024    
2025                    qPos.add(groupId);
2026    
2027                    qPos.add(status);
2028    
2029                    if (orderByComparator != null) {
2030                            Object[] values = orderByComparator.getOrderByValues(mbThread);
2031    
2032                            for (Object value : values) {
2033                                    qPos.add(value);
2034                            }
2035                    }
2036    
2037                    List<MBThread> list = q.list();
2038    
2039                    if (list.size() == 2) {
2040                            return list.get(1);
2041                    }
2042                    else {
2043                            return null;
2044                    }
2045            }
2046    
2047            /**
2048             * Finds all the message boards threads where categoryId = &#63; and priority = &#63;.
2049             *
2050             * @param categoryId the category id to search with
2051             * @param priority the priority to search with
2052             * @return the matching message boards threads
2053             * @throws SystemException if a system exception occurred
2054             */
2055            public List<MBThread> findByC_P(long categoryId, double priority)
2056                    throws SystemException {
2057                    return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
2058                            QueryUtil.ALL_POS, null);
2059            }
2060    
2061            /**
2062             * Finds a range of all the message boards threads where categoryId = &#63; and priority = &#63;.
2063             *
2064             * <p>
2065             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2066             * </p>
2067             *
2068             * @param categoryId the category id to search with
2069             * @param priority the priority to search with
2070             * @param start the lower bound of the range of message boards threads to return
2071             * @param end the upper bound of the range of message boards threads to return (not inclusive)
2072             * @return the range of matching message boards threads
2073             * @throws SystemException if a system exception occurred
2074             */
2075            public List<MBThread> findByC_P(long categoryId, double priority,
2076                    int start, int end) throws SystemException {
2077                    return findByC_P(categoryId, priority, start, end, null);
2078            }
2079    
2080            /**
2081             * Finds an ordered range of all the message boards threads where categoryId = &#63; and priority = &#63;.
2082             *
2083             * <p>
2084             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2085             * </p>
2086             *
2087             * @param categoryId the category id to search with
2088             * @param priority the priority to search with
2089             * @param start the lower bound of the range of message boards threads to return
2090             * @param end the upper bound of the range of message boards threads to return (not inclusive)
2091             * @param orderByComparator the comparator to order the results by
2092             * @return the ordered range of matching message boards threads
2093             * @throws SystemException if a system exception occurred
2094             */
2095            public List<MBThread> findByC_P(long categoryId, double priority,
2096                    int start, int end, OrderByComparator orderByComparator)
2097                    throws SystemException {
2098                    Object[] finderArgs = new Object[] {
2099                                    categoryId, priority,
2100                                    
2101                                    String.valueOf(start), String.valueOf(end),
2102                                    String.valueOf(orderByComparator)
2103                            };
2104    
2105                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
2106                                    finderArgs, this);
2107    
2108                    if (list == null) {
2109                            Session session = null;
2110    
2111                            try {
2112                                    session = openSession();
2113    
2114                                    StringBundler query = null;
2115    
2116                                    if (orderByComparator != null) {
2117                                            query = new StringBundler(4 +
2118                                                            (orderByComparator.getOrderByFields().length * 3));
2119                                    }
2120                                    else {
2121                                            query = new StringBundler(4);
2122                                    }
2123    
2124                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2125    
2126                                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
2127    
2128                                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
2129    
2130                                    if (orderByComparator != null) {
2131                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2132                                                    orderByComparator);
2133                                    }
2134    
2135                                    else {
2136                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2137                                    }
2138    
2139                                    String sql = query.toString();
2140    
2141                                    Query q = session.createQuery(sql);
2142    
2143                                    QueryPos qPos = QueryPos.getInstance(q);
2144    
2145                                    qPos.add(categoryId);
2146    
2147                                    qPos.add(priority);
2148    
2149                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2150                                                    end);
2151                            }
2152                            catch (Exception e) {
2153                                    throw processException(e);
2154                            }
2155                            finally {
2156                                    if (list == null) {
2157                                            list = new ArrayList<MBThread>();
2158                                    }
2159    
2160                                    cacheResult(list);
2161    
2162                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
2163                                            list);
2164    
2165                                    closeSession(session);
2166                            }
2167                    }
2168    
2169                    return list;
2170            }
2171    
2172            /**
2173             * Finds the first message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
2174             *
2175             * <p>
2176             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2177             * </p>
2178             *
2179             * @param categoryId the category id to search with
2180             * @param priority the priority to search with
2181             * @param orderByComparator the comparator to order the set by
2182             * @return the first matching message boards thread
2183             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2184             * @throws SystemException if a system exception occurred
2185             */
2186            public MBThread findByC_P_First(long categoryId, double priority,
2187                    OrderByComparator orderByComparator)
2188                    throws NoSuchThreadException, SystemException {
2189                    List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
2190                                    orderByComparator);
2191    
2192                    if (list.isEmpty()) {
2193                            StringBundler msg = new StringBundler(6);
2194    
2195                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2196    
2197                            msg.append("categoryId=");
2198                            msg.append(categoryId);
2199    
2200                            msg.append(", priority=");
2201                            msg.append(priority);
2202    
2203                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2204    
2205                            throw new NoSuchThreadException(msg.toString());
2206                    }
2207                    else {
2208                            return list.get(0);
2209                    }
2210            }
2211    
2212            /**
2213             * Finds the last message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
2214             *
2215             * <p>
2216             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2217             * </p>
2218             *
2219             * @param categoryId the category id to search with
2220             * @param priority the priority to search with
2221             * @param orderByComparator the comparator to order the set by
2222             * @return the last matching message boards thread
2223             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2224             * @throws SystemException if a system exception occurred
2225             */
2226            public MBThread findByC_P_Last(long categoryId, double priority,
2227                    OrderByComparator orderByComparator)
2228                    throws NoSuchThreadException, SystemException {
2229                    int count = countByC_P(categoryId, priority);
2230    
2231                    List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
2232                                    orderByComparator);
2233    
2234                    if (list.isEmpty()) {
2235                            StringBundler msg = new StringBundler(6);
2236    
2237                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2238    
2239                            msg.append("categoryId=");
2240                            msg.append(categoryId);
2241    
2242                            msg.append(", priority=");
2243                            msg.append(priority);
2244    
2245                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2246    
2247                            throw new NoSuchThreadException(msg.toString());
2248                    }
2249                    else {
2250                            return list.get(0);
2251                    }
2252            }
2253    
2254            /**
2255             * Finds the message boards threads before and after the current message boards thread in the ordered set where categoryId = &#63; and priority = &#63;.
2256             *
2257             * <p>
2258             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2259             * </p>
2260             *
2261             * @param threadId the primary key of the current message boards thread
2262             * @param categoryId the category id to search with
2263             * @param priority the priority to search with
2264             * @param orderByComparator the comparator to order the set by
2265             * @return the previous, current, and next message boards thread
2266             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
2267             * @throws SystemException if a system exception occurred
2268             */
2269            public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
2270                    double priority, OrderByComparator orderByComparator)
2271                    throws NoSuchThreadException, SystemException {
2272                    MBThread mbThread = findByPrimaryKey(threadId);
2273    
2274                    Session session = null;
2275    
2276                    try {
2277                            session = openSession();
2278    
2279                            MBThread[] array = new MBThreadImpl[3];
2280    
2281                            array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
2282                                            priority, orderByComparator, true);
2283    
2284                            array[1] = mbThread;
2285    
2286                            array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
2287                                            priority, orderByComparator, false);
2288    
2289                            return array;
2290                    }
2291                    catch (Exception e) {
2292                            throw processException(e);
2293                    }
2294                    finally {
2295                            closeSession(session);
2296                    }
2297            }
2298    
2299            protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
2300                    long categoryId, double priority, OrderByComparator orderByComparator,
2301                    boolean previous) {
2302                    StringBundler query = null;
2303    
2304                    if (orderByComparator != null) {
2305                            query = new StringBundler(6 +
2306                                            (orderByComparator.getOrderByFields().length * 6));
2307                    }
2308                    else {
2309                            query = new StringBundler(3);
2310                    }
2311    
2312                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2313    
2314                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
2315    
2316                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
2317    
2318                    if (orderByComparator != null) {
2319                            String[] orderByFields = orderByComparator.getOrderByFields();
2320    
2321                            if (orderByFields.length > 0) {
2322                                    query.append(WHERE_AND);
2323                            }
2324    
2325                            for (int i = 0; i < orderByFields.length; i++) {
2326                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2327                                    query.append(orderByFields[i]);
2328    
2329                                    if ((i + 1) < orderByFields.length) {
2330                                            if (orderByComparator.isAscending() ^ previous) {
2331                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2332                                            }
2333                                            else {
2334                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2335                                            }
2336                                    }
2337                                    else {
2338                                            if (orderByComparator.isAscending() ^ previous) {
2339                                                    query.append(WHERE_GREATER_THAN);
2340                                            }
2341                                            else {
2342                                                    query.append(WHERE_LESSER_THAN);
2343                                            }
2344                                    }
2345                            }
2346    
2347                            query.append(ORDER_BY_CLAUSE);
2348    
2349                            for (int i = 0; i < orderByFields.length; i++) {
2350                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2351                                    query.append(orderByFields[i]);
2352    
2353                                    if ((i + 1) < orderByFields.length) {
2354                                            if (orderByComparator.isAscending() ^ previous) {
2355                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2356                                            }
2357                                            else {
2358                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2359                                            }
2360                                    }
2361                                    else {
2362                                            if (orderByComparator.isAscending() ^ previous) {
2363                                                    query.append(ORDER_BY_ASC);
2364                                            }
2365                                            else {
2366                                                    query.append(ORDER_BY_DESC);
2367                                            }
2368                                    }
2369                            }
2370                    }
2371    
2372                    else {
2373                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2374                    }
2375    
2376                    String sql = query.toString();
2377    
2378                    Query q = session.createQuery(sql);
2379    
2380                    q.setFirstResult(0);
2381                    q.setMaxResults(2);
2382    
2383                    QueryPos qPos = QueryPos.getInstance(q);
2384    
2385                    qPos.add(categoryId);
2386    
2387                    qPos.add(priority);
2388    
2389                    if (orderByComparator != null) {
2390                            Object[] values = orderByComparator.getOrderByValues(mbThread);
2391    
2392                            for (Object value : values) {
2393                                    qPos.add(value);
2394                            }
2395                    }
2396    
2397                    List<MBThread> list = q.list();
2398    
2399                    if (list.size() == 2) {
2400                            return list.get(1);
2401                    }
2402                    else {
2403                            return null;
2404                    }
2405            }
2406    
2407            /**
2408             * Finds all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
2409             *
2410             * @param groupId the group id to search with
2411             * @param categoryId the category id to search with
2412             * @param lastPostDate the last post date to search with
2413             * @return the matching message boards threads
2414             * @throws SystemException if a system exception occurred
2415             */
2416            public List<MBThread> findByG_C_L(long groupId, long categoryId,
2417                    Date lastPostDate) throws SystemException {
2418                    return findByG_C_L(groupId, categoryId, lastPostDate,
2419                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2420            }
2421    
2422            /**
2423             * Finds a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
2424             *
2425             * <p>
2426             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2427             * </p>
2428             *
2429             * @param groupId the group id to search with
2430             * @param categoryId the category id to search with
2431             * @param lastPostDate the last post date to search with
2432             * @param start the lower bound of the range of message boards threads to return
2433             * @param end the upper bound of the range of message boards threads to return (not inclusive)
2434             * @return the range of matching message boards threads
2435             * @throws SystemException if a system exception occurred
2436             */
2437            public List<MBThread> findByG_C_L(long groupId, long categoryId,
2438                    Date lastPostDate, int start, int end) throws SystemException {
2439                    return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
2440            }
2441    
2442            /**
2443             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
2444             *
2445             * <p>
2446             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2447             * </p>
2448             *
2449             * @param groupId the group id to search with
2450             * @param categoryId the category id to search with
2451             * @param lastPostDate the last post date to search with
2452             * @param start the lower bound of the range of message boards threads to return
2453             * @param end the upper bound of the range of message boards threads to return (not inclusive)
2454             * @param orderByComparator the comparator to order the results by
2455             * @return the ordered range of matching message boards threads
2456             * @throws SystemException if a system exception occurred
2457             */
2458            public List<MBThread> findByG_C_L(long groupId, long categoryId,
2459                    Date lastPostDate, int start, int end,
2460                    OrderByComparator orderByComparator) throws SystemException {
2461                    Object[] finderArgs = new Object[] {
2462                                    groupId, categoryId, lastPostDate,
2463                                    
2464                                    String.valueOf(start), String.valueOf(end),
2465                                    String.valueOf(orderByComparator)
2466                            };
2467    
2468                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_L,
2469                                    finderArgs, this);
2470    
2471                    if (list == null) {
2472                            Session session = null;
2473    
2474                            try {
2475                                    session = openSession();
2476    
2477                                    StringBundler query = null;
2478    
2479                                    if (orderByComparator != null) {
2480                                            query = new StringBundler(5 +
2481                                                            (orderByComparator.getOrderByFields().length * 3));
2482                                    }
2483                                    else {
2484                                            query = new StringBundler(5);
2485                                    }
2486    
2487                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2488    
2489                                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
2490    
2491                                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
2492    
2493                                    if (lastPostDate == null) {
2494                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
2495                                    }
2496                                    else {
2497                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
2498                                    }
2499    
2500                                    if (orderByComparator != null) {
2501                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2502                                                    orderByComparator);
2503                                    }
2504    
2505                                    else {
2506                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2507                                    }
2508    
2509                                    String sql = query.toString();
2510    
2511                                    Query q = session.createQuery(sql);
2512    
2513                                    QueryPos qPos = QueryPos.getInstance(q);
2514    
2515                                    qPos.add(groupId);
2516    
2517                                    qPos.add(categoryId);
2518    
2519                                    if (lastPostDate != null) {
2520                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
2521                                    }
2522    
2523                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2524                                                    end);
2525                            }
2526                            catch (Exception e) {
2527                                    throw processException(e);
2528                            }
2529                            finally {
2530                                    if (list == null) {
2531                                            list = new ArrayList<MBThread>();
2532                                    }
2533    
2534                                    cacheResult(list);
2535    
2536                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_L,
2537                                            finderArgs, list);
2538    
2539                                    closeSession(session);
2540                            }
2541                    }
2542    
2543                    return list;
2544            }
2545    
2546            /**
2547             * Finds the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
2548             *
2549             * <p>
2550             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2551             * </p>
2552             *
2553             * @param groupId the group id to search with
2554             * @param categoryId the category id to search with
2555             * @param lastPostDate the last post date to search with
2556             * @param orderByComparator the comparator to order the set by
2557             * @return the first matching message boards thread
2558             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2559             * @throws SystemException if a system exception occurred
2560             */
2561            public MBThread findByG_C_L_First(long groupId, long categoryId,
2562                    Date lastPostDate, OrderByComparator orderByComparator)
2563                    throws NoSuchThreadException, SystemException {
2564                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
2565                                    1, orderByComparator);
2566    
2567                    if (list.isEmpty()) {
2568                            StringBundler msg = new StringBundler(8);
2569    
2570                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2571    
2572                            msg.append("groupId=");
2573                            msg.append(groupId);
2574    
2575                            msg.append(", categoryId=");
2576                            msg.append(categoryId);
2577    
2578                            msg.append(", lastPostDate=");
2579                            msg.append(lastPostDate);
2580    
2581                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2582    
2583                            throw new NoSuchThreadException(msg.toString());
2584                    }
2585                    else {
2586                            return list.get(0);
2587                    }
2588            }
2589    
2590            /**
2591             * Finds the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
2592             *
2593             * <p>
2594             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2595             * </p>
2596             *
2597             * @param groupId the group id to search with
2598             * @param categoryId the category id to search with
2599             * @param lastPostDate the last post date to search with
2600             * @param orderByComparator the comparator to order the set by
2601             * @return the last matching message boards thread
2602             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2603             * @throws SystemException if a system exception occurred
2604             */
2605            public MBThread findByG_C_L_Last(long groupId, long categoryId,
2606                    Date lastPostDate, OrderByComparator orderByComparator)
2607                    throws NoSuchThreadException, SystemException {
2608                    int count = countByG_C_L(groupId, categoryId, lastPostDate);
2609    
2610                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
2611                                    count - 1, count, orderByComparator);
2612    
2613                    if (list.isEmpty()) {
2614                            StringBundler msg = new StringBundler(8);
2615    
2616                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2617    
2618                            msg.append("groupId=");
2619                            msg.append(groupId);
2620    
2621                            msg.append(", categoryId=");
2622                            msg.append(categoryId);
2623    
2624                            msg.append(", lastPostDate=");
2625                            msg.append(lastPostDate);
2626    
2627                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2628    
2629                            throw new NoSuchThreadException(msg.toString());
2630                    }
2631                    else {
2632                            return list.get(0);
2633                    }
2634            }
2635    
2636            /**
2637             * Finds 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;.
2638             *
2639             * <p>
2640             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2641             * </p>
2642             *
2643             * @param threadId the primary key of the current message boards thread
2644             * @param groupId the group id to search with
2645             * @param categoryId the category id to search with
2646             * @param lastPostDate the last post date to search with
2647             * @param orderByComparator the comparator to order the set by
2648             * @return the previous, current, and next message boards thread
2649             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
2650             * @throws SystemException if a system exception occurred
2651             */
2652            public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
2653                    long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
2654                    throws NoSuchThreadException, SystemException {
2655                    MBThread mbThread = findByPrimaryKey(threadId);
2656    
2657                    Session session = null;
2658    
2659                    try {
2660                            session = openSession();
2661    
2662                            MBThread[] array = new MBThreadImpl[3];
2663    
2664                            array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
2665                                            categoryId, lastPostDate, orderByComparator, true);
2666    
2667                            array[1] = mbThread;
2668    
2669                            array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
2670                                            categoryId, lastPostDate, orderByComparator, false);
2671    
2672                            return array;
2673                    }
2674                    catch (Exception e) {
2675                            throw processException(e);
2676                    }
2677                    finally {
2678                            closeSession(session);
2679                    }
2680            }
2681    
2682            protected MBThread getByG_C_L_PrevAndNext(Session session,
2683                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
2684                    OrderByComparator orderByComparator, boolean previous) {
2685                    StringBundler query = null;
2686    
2687                    if (orderByComparator != null) {
2688                            query = new StringBundler(6 +
2689                                            (orderByComparator.getOrderByFields().length * 6));
2690                    }
2691                    else {
2692                            query = new StringBundler(3);
2693                    }
2694    
2695                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2696    
2697                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
2698    
2699                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
2700    
2701                    if (lastPostDate == null) {
2702                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
2703                    }
2704                    else {
2705                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
2706                    }
2707    
2708                    if (orderByComparator != null) {
2709                            String[] orderByFields = orderByComparator.getOrderByFields();
2710    
2711                            if (orderByFields.length > 0) {
2712                                    query.append(WHERE_AND);
2713                            }
2714    
2715                            for (int i = 0; i < orderByFields.length; i++) {
2716                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2717                                    query.append(orderByFields[i]);
2718    
2719                                    if ((i + 1) < orderByFields.length) {
2720                                            if (orderByComparator.isAscending() ^ previous) {
2721                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2722                                            }
2723                                            else {
2724                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2725                                            }
2726                                    }
2727                                    else {
2728                                            if (orderByComparator.isAscending() ^ previous) {
2729                                                    query.append(WHERE_GREATER_THAN);
2730                                            }
2731                                            else {
2732                                                    query.append(WHERE_LESSER_THAN);
2733                                            }
2734                                    }
2735                            }
2736    
2737                            query.append(ORDER_BY_CLAUSE);
2738    
2739                            for (int i = 0; i < orderByFields.length; i++) {
2740                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2741                                    query.append(orderByFields[i]);
2742    
2743                                    if ((i + 1) < orderByFields.length) {
2744                                            if (orderByComparator.isAscending() ^ previous) {
2745                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2746                                            }
2747                                            else {
2748                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2749                                            }
2750                                    }
2751                                    else {
2752                                            if (orderByComparator.isAscending() ^ previous) {
2753                                                    query.append(ORDER_BY_ASC);
2754                                            }
2755                                            else {
2756                                                    query.append(ORDER_BY_DESC);
2757                                            }
2758                                    }
2759                            }
2760                    }
2761    
2762                    else {
2763                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2764                    }
2765    
2766                    String sql = query.toString();
2767    
2768                    Query q = session.createQuery(sql);
2769    
2770                    q.setFirstResult(0);
2771                    q.setMaxResults(2);
2772    
2773                    QueryPos qPos = QueryPos.getInstance(q);
2774    
2775                    qPos.add(groupId);
2776    
2777                    qPos.add(categoryId);
2778    
2779                    if (lastPostDate != null) {
2780                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
2781                    }
2782    
2783                    if (orderByComparator != null) {
2784                            Object[] values = orderByComparator.getOrderByValues(mbThread);
2785    
2786                            for (Object value : values) {
2787                                    qPos.add(value);
2788                            }
2789                    }
2790    
2791                    List<MBThread> list = q.list();
2792    
2793                    if (list.size() == 2) {
2794                            return list.get(1);
2795                    }
2796                    else {
2797                            return null;
2798                    }
2799            }
2800    
2801            /**
2802             * Finds all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
2803             *
2804             * @param groupId the group id to search with
2805             * @param categoryId the category id to search with
2806             * @param status the status to search with
2807             * @return the matching message boards threads
2808             * @throws SystemException if a system exception occurred
2809             */
2810            public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
2811                    throws SystemException {
2812                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
2813                            QueryUtil.ALL_POS, null);
2814            }
2815    
2816            /**
2817             * Finds a range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
2818             *
2819             * <p>
2820             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2821             * </p>
2822             *
2823             * @param groupId the group id to search with
2824             * @param categoryId the category id to search with
2825             * @param status the status to search with
2826             * @param start the lower bound of the range of message boards threads to return
2827             * @param end the upper bound of the range of message boards threads to return (not inclusive)
2828             * @return the range of matching message boards threads
2829             * @throws SystemException if a system exception occurred
2830             */
2831            public List<MBThread> findByG_C_S(long groupId, long categoryId,
2832                    int status, int start, int end) throws SystemException {
2833                    return findByG_C_S(groupId, categoryId, status, start, end, null);
2834            }
2835    
2836            /**
2837             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
2838             *
2839             * <p>
2840             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2841             * </p>
2842             *
2843             * @param groupId the group id to search with
2844             * @param categoryId the category id to search with
2845             * @param status the status to search with
2846             * @param start the lower bound of the range of message boards threads to return
2847             * @param end the upper bound of the range of message boards threads to return (not inclusive)
2848             * @param orderByComparator the comparator to order the results by
2849             * @return the ordered range of matching message boards threads
2850             * @throws SystemException if a system exception occurred
2851             */
2852            public List<MBThread> findByG_C_S(long groupId, long categoryId,
2853                    int status, int start, int end, OrderByComparator orderByComparator)
2854                    throws SystemException {
2855                    Object[] finderArgs = new Object[] {
2856                                    groupId, categoryId, status,
2857                                    
2858                                    String.valueOf(start), String.valueOf(end),
2859                                    String.valueOf(orderByComparator)
2860                            };
2861    
2862                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
2863                                    finderArgs, this);
2864    
2865                    if (list == null) {
2866                            Session session = null;
2867    
2868                            try {
2869                                    session = openSession();
2870    
2871                                    StringBundler query = null;
2872    
2873                                    if (orderByComparator != null) {
2874                                            query = new StringBundler(5 +
2875                                                            (orderByComparator.getOrderByFields().length * 3));
2876                                    }
2877                                    else {
2878                                            query = new StringBundler(5);
2879                                    }
2880    
2881                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2882    
2883                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
2884    
2885                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
2886    
2887                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
2888    
2889                                    if (orderByComparator != null) {
2890                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2891                                                    orderByComparator);
2892                                    }
2893    
2894                                    else {
2895                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2896                                    }
2897    
2898                                    String sql = query.toString();
2899    
2900                                    Query q = session.createQuery(sql);
2901    
2902                                    QueryPos qPos = QueryPos.getInstance(q);
2903    
2904                                    qPos.add(groupId);
2905    
2906                                    qPos.add(categoryId);
2907    
2908                                    qPos.add(status);
2909    
2910                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2911                                                    end);
2912                            }
2913                            catch (Exception e) {
2914                                    throw processException(e);
2915                            }
2916                            finally {
2917                                    if (list == null) {
2918                                            list = new ArrayList<MBThread>();
2919                                    }
2920    
2921                                    cacheResult(list);
2922    
2923                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
2924                                            finderArgs, list);
2925    
2926                                    closeSession(session);
2927                            }
2928                    }
2929    
2930                    return list;
2931            }
2932    
2933            /**
2934             * Finds the first message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
2935             *
2936             * <p>
2937             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2938             * </p>
2939             *
2940             * @param groupId the group id to search with
2941             * @param categoryId the category id to search with
2942             * @param status the status to search with
2943             * @param orderByComparator the comparator to order the set by
2944             * @return the first matching message boards thread
2945             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2946             * @throws SystemException if a system exception occurred
2947             */
2948            public MBThread findByG_C_S_First(long groupId, long categoryId,
2949                    int status, OrderByComparator orderByComparator)
2950                    throws NoSuchThreadException, SystemException {
2951                    List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
2952                                    orderByComparator);
2953    
2954                    if (list.isEmpty()) {
2955                            StringBundler msg = new StringBundler(8);
2956    
2957                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2958    
2959                            msg.append("groupId=");
2960                            msg.append(groupId);
2961    
2962                            msg.append(", categoryId=");
2963                            msg.append(categoryId);
2964    
2965                            msg.append(", status=");
2966                            msg.append(status);
2967    
2968                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2969    
2970                            throw new NoSuchThreadException(msg.toString());
2971                    }
2972                    else {
2973                            return list.get(0);
2974                    }
2975            }
2976    
2977            /**
2978             * Finds the last message boards thread in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
2979             *
2980             * <p>
2981             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2982             * </p>
2983             *
2984             * @param groupId the group id to search with
2985             * @param categoryId the category id to search with
2986             * @param status the status to search with
2987             * @param orderByComparator the comparator to order the set by
2988             * @return the last matching message boards thread
2989             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
2990             * @throws SystemException if a system exception occurred
2991             */
2992            public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
2993                    OrderByComparator orderByComparator)
2994                    throws NoSuchThreadException, SystemException {
2995                    int count = countByG_C_S(groupId, categoryId, status);
2996    
2997                    List<MBThread> list = findByG_C_S(groupId, categoryId, status,
2998                                    count - 1, count, orderByComparator);
2999    
3000                    if (list.isEmpty()) {
3001                            StringBundler msg = new StringBundler(8);
3002    
3003                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3004    
3005                            msg.append("groupId=");
3006                            msg.append(groupId);
3007    
3008                            msg.append(", categoryId=");
3009                            msg.append(categoryId);
3010    
3011                            msg.append(", status=");
3012                            msg.append(status);
3013    
3014                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3015    
3016                            throw new NoSuchThreadException(msg.toString());
3017                    }
3018                    else {
3019                            return list.get(0);
3020                    }
3021            }
3022    
3023            /**
3024             * Finds 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;.
3025             *
3026             * <p>
3027             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3028             * </p>
3029             *
3030             * @param threadId the primary key of the current message boards thread
3031             * @param groupId the group id to search with
3032             * @param categoryId the category id to search with
3033             * @param status the status to search with
3034             * @param orderByComparator the comparator to order the set by
3035             * @return the previous, current, and next message boards thread
3036             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3037             * @throws SystemException if a system exception occurred
3038             */
3039            public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
3040                    long categoryId, int status, OrderByComparator orderByComparator)
3041                    throws NoSuchThreadException, SystemException {
3042                    MBThread mbThread = findByPrimaryKey(threadId);
3043    
3044                    Session session = null;
3045    
3046                    try {
3047                            session = openSession();
3048    
3049                            MBThread[] array = new MBThreadImpl[3];
3050    
3051                            array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
3052                                            categoryId, status, orderByComparator, true);
3053    
3054                            array[1] = mbThread;
3055    
3056                            array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
3057                                            categoryId, status, orderByComparator, false);
3058    
3059                            return array;
3060                    }
3061                    catch (Exception e) {
3062                            throw processException(e);
3063                    }
3064                    finally {
3065                            closeSession(session);
3066                    }
3067            }
3068    
3069            protected MBThread getByG_C_S_PrevAndNext(Session session,
3070                    MBThread mbThread, long groupId, long categoryId, int status,
3071                    OrderByComparator orderByComparator, boolean previous) {
3072                    StringBundler query = null;
3073    
3074                    if (orderByComparator != null) {
3075                            query = new StringBundler(6 +
3076                                            (orderByComparator.getOrderByFields().length * 6));
3077                    }
3078                    else {
3079                            query = new StringBundler(3);
3080                    }
3081    
3082                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
3083    
3084                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
3085    
3086                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
3087    
3088                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
3089    
3090                    if (orderByComparator != null) {
3091                            String[] orderByFields = orderByComparator.getOrderByFields();
3092    
3093                            if (orderByFields.length > 0) {
3094                                    query.append(WHERE_AND);
3095                            }
3096    
3097                            for (int i = 0; i < orderByFields.length; i++) {
3098                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3099                                    query.append(orderByFields[i]);
3100    
3101                                    if ((i + 1) < orderByFields.length) {
3102                                            if (orderByComparator.isAscending() ^ previous) {
3103                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3104                                            }
3105                                            else {
3106                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3107                                            }
3108                                    }
3109                                    else {
3110                                            if (orderByComparator.isAscending() ^ previous) {
3111                                                    query.append(WHERE_GREATER_THAN);
3112                                            }
3113                                            else {
3114                                                    query.append(WHERE_LESSER_THAN);
3115                                            }
3116                                    }
3117                            }
3118    
3119                            query.append(ORDER_BY_CLAUSE);
3120    
3121                            for (int i = 0; i < orderByFields.length; i++) {
3122                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3123                                    query.append(orderByFields[i]);
3124    
3125                                    if ((i + 1) < orderByFields.length) {
3126                                            if (orderByComparator.isAscending() ^ previous) {
3127                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3128                                            }
3129                                            else {
3130                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3131                                            }
3132                                    }
3133                                    else {
3134                                            if (orderByComparator.isAscending() ^ previous) {
3135                                                    query.append(ORDER_BY_ASC);
3136                                            }
3137                                            else {
3138                                                    query.append(ORDER_BY_DESC);
3139                                            }
3140                                    }
3141                            }
3142                    }
3143    
3144                    else {
3145                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3146                    }
3147    
3148                    String sql = query.toString();
3149    
3150                    Query q = session.createQuery(sql);
3151    
3152                    q.setFirstResult(0);
3153                    q.setMaxResults(2);
3154    
3155                    QueryPos qPos = QueryPos.getInstance(q);
3156    
3157                    qPos.add(groupId);
3158    
3159                    qPos.add(categoryId);
3160    
3161                    qPos.add(status);
3162    
3163                    if (orderByComparator != null) {
3164                            Object[] values = orderByComparator.getOrderByValues(mbThread);
3165    
3166                            for (Object value : values) {
3167                                    qPos.add(value);
3168                            }
3169                    }
3170    
3171                    List<MBThread> list = q.list();
3172    
3173                    if (list.size() == 2) {
3174                            return list.get(1);
3175                    }
3176                    else {
3177                            return null;
3178                    }
3179            }
3180    
3181            /**
3182             * Finds all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
3183             *
3184             * <p>
3185             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3186             * </p>
3187             *
3188             * @param groupId the group id to search with
3189             * @param categoryIds the category ids to search with
3190             * @param status the status to search with
3191             * @return the matching message boards threads
3192             * @throws SystemException if a system exception occurred
3193             */
3194            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
3195                    int status) throws SystemException {
3196                    return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
3197                            QueryUtil.ALL_POS, null);
3198            }
3199    
3200            /**
3201             * Finds a range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
3202             *
3203             * <p>
3204             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3205             * </p>
3206             *
3207             * @param groupId the group id to search with
3208             * @param categoryIds the category ids to search with
3209             * @param status the status to search with
3210             * @param start the lower bound of the range of message boards threads to return
3211             * @param end the upper bound of the range of message boards threads to return (not inclusive)
3212             * @return the range of matching message boards threads
3213             * @throws SystemException if a system exception occurred
3214             */
3215            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
3216                    int status, int start, int end) throws SystemException {
3217                    return findByG_C_S(groupId, categoryIds, status, start, end, null);
3218            }
3219    
3220            /**
3221             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
3222             *
3223             * <p>
3224             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3225             * </p>
3226             *
3227             * @param groupId the group id to search with
3228             * @param categoryIds the category ids to search with
3229             * @param status the status to search with
3230             * @param start the lower bound of the range of message boards threads to return
3231             * @param end the upper bound of the range of message boards threads to return (not inclusive)
3232             * @param orderByComparator the comparator to order the results by
3233             * @return the ordered range of matching message boards threads
3234             * @throws SystemException if a system exception occurred
3235             */
3236            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
3237                    int status, int start, int end, OrderByComparator orderByComparator)
3238                    throws SystemException {
3239                    Object[] finderArgs = new Object[] {
3240                                    groupId, StringUtil.merge(categoryIds), status,
3241                                    
3242                                    String.valueOf(start), String.valueOf(end),
3243                                    String.valueOf(orderByComparator)
3244                            };
3245    
3246                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
3247                                    finderArgs, this);
3248    
3249                    if (list == null) {
3250                            Session session = null;
3251    
3252                            try {
3253                                    session = openSession();
3254    
3255                                    StringBundler query = new StringBundler();
3256    
3257                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
3258    
3259                                    boolean conjunctionable = false;
3260    
3261                                    if (conjunctionable) {
3262                                            query.append(WHERE_AND);
3263                                    }
3264    
3265                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
3266    
3267                                    conjunctionable = true;
3268    
3269                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
3270                                            if (conjunctionable) {
3271                                                    query.append(WHERE_AND);
3272                                            }
3273    
3274                                            query.append(StringPool.OPEN_PARENTHESIS);
3275    
3276                                            for (int i = 0; i < categoryIds.length; i++) {
3277                                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
3278    
3279                                                    if ((i + 1) < categoryIds.length) {
3280                                                            query.append(WHERE_OR);
3281                                                    }
3282                                            }
3283    
3284                                            query.append(StringPool.CLOSE_PARENTHESIS);
3285    
3286                                            conjunctionable = true;
3287                                    }
3288    
3289                                    if (conjunctionable) {
3290                                            query.append(WHERE_AND);
3291                                    }
3292    
3293                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
3294    
3295                                    conjunctionable = true;
3296    
3297                                    if (orderByComparator != null) {
3298                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3299                                                    orderByComparator);
3300                                    }
3301    
3302                                    else {
3303                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3304                                    }
3305    
3306                                    String sql = query.toString();
3307    
3308                                    Query q = session.createQuery(sql);
3309    
3310                                    QueryPos qPos = QueryPos.getInstance(q);
3311    
3312                                    qPos.add(groupId);
3313    
3314                                    if (categoryIds != null) {
3315                                            qPos.add(categoryIds);
3316                                    }
3317    
3318                                    qPos.add(status);
3319    
3320                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
3321                                                    end);
3322                            }
3323                            catch (Exception e) {
3324                                    throw processException(e);
3325                            }
3326                            finally {
3327                                    if (list == null) {
3328                                            list = new ArrayList<MBThread>();
3329                                    }
3330    
3331                                    cacheResult(list);
3332    
3333                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
3334                                            finderArgs, list);
3335    
3336                                    closeSession(session);
3337                            }
3338                    }
3339    
3340                    return list;
3341            }
3342    
3343            /**
3344             * Finds all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
3345             *
3346             * @param groupId the group id to search with
3347             * @param categoryId the category id to search with
3348             * @param status the status to search with
3349             * @return the matching message boards threads
3350             * @throws SystemException if a system exception occurred
3351             */
3352            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
3353                    int status) throws SystemException {
3354                    return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
3355                            QueryUtil.ALL_POS, null);
3356            }
3357    
3358            /**
3359             * Finds a range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
3360             *
3361             * <p>
3362             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3363             * </p>
3364             *
3365             * @param groupId the group id to search with
3366             * @param categoryId the category id to search with
3367             * @param status the status to search with
3368             * @param start the lower bound of the range of message boards threads to return
3369             * @param end the upper bound of the range of message boards threads to return (not inclusive)
3370             * @return the range of matching message boards threads
3371             * @throws SystemException if a system exception occurred
3372             */
3373            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
3374                    int status, int start, int end) throws SystemException {
3375                    return findByG_NotC_S(groupId, categoryId, status, start, end, null);
3376            }
3377    
3378            /**
3379             * Finds an ordered range of all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
3380             *
3381             * <p>
3382             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3383             * </p>
3384             *
3385             * @param groupId the group id to search with
3386             * @param categoryId the category id to search with
3387             * @param status the status to search with
3388             * @param start the lower bound of the range of message boards threads to return
3389             * @param end the upper bound of the range of message boards threads to return (not inclusive)
3390             * @param orderByComparator the comparator to order the results by
3391             * @return the ordered range of matching message boards threads
3392             * @throws SystemException if a system exception occurred
3393             */
3394            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
3395                    int status, int start, int end, OrderByComparator orderByComparator)
3396                    throws SystemException {
3397                    Object[] finderArgs = new Object[] {
3398                                    groupId, categoryId, status,
3399                                    
3400                                    String.valueOf(start), String.valueOf(end),
3401                                    String.valueOf(orderByComparator)
3402                            };
3403    
3404                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTC_S,
3405                                    finderArgs, this);
3406    
3407                    if (list == null) {
3408                            Session session = null;
3409    
3410                            try {
3411                                    session = openSession();
3412    
3413                                    StringBundler query = null;
3414    
3415                                    if (orderByComparator != null) {
3416                                            query = new StringBundler(5 +
3417                                                            (orderByComparator.getOrderByFields().length * 3));
3418                                    }
3419                                    else {
3420                                            query = new StringBundler(5);
3421                                    }
3422    
3423                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
3424    
3425                                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
3426    
3427                                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
3428    
3429                                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
3430    
3431                                    if (orderByComparator != null) {
3432                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3433                                                    orderByComparator);
3434                                    }
3435    
3436                                    else {
3437                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3438                                    }
3439    
3440                                    String sql = query.toString();
3441    
3442                                    Query q = session.createQuery(sql);
3443    
3444                                    QueryPos qPos = QueryPos.getInstance(q);
3445    
3446                                    qPos.add(groupId);
3447    
3448                                    qPos.add(categoryId);
3449    
3450                                    qPos.add(status);
3451    
3452                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
3453                                                    end);
3454                            }
3455                            catch (Exception e) {
3456                                    throw processException(e);
3457                            }
3458                            finally {
3459                                    if (list == null) {
3460                                            list = new ArrayList<MBThread>();
3461                                    }
3462    
3463                                    cacheResult(list);
3464    
3465                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTC_S,
3466                                            finderArgs, list);
3467    
3468                                    closeSession(session);
3469                            }
3470                    }
3471    
3472                    return list;
3473            }
3474    
3475            /**
3476             * Finds the first message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
3477             *
3478             * <p>
3479             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
3480             * </p>
3481             *
3482             * @param groupId the group id to search with
3483             * @param categoryId the category id to search with
3484             * @param status the status to search with
3485             * @param orderByComparator the comparator to order the set by
3486             * @return the first matching message boards thread
3487             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
3488             * @throws SystemException if a system exception occurred
3489             */
3490            public MBThread findByG_NotC_S_First(long groupId, long categoryId,
3491                    int status, OrderByComparator orderByComparator)
3492                    throws NoSuchThreadException, SystemException {
3493                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
3494                                    orderByComparator);
3495    
3496                    if (list.isEmpty()) {
3497                            StringBundler msg = new StringBundler(8);
3498    
3499                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3500    
3501                            msg.append("groupId=");
3502                            msg.append(groupId);
3503    
3504                            msg.append(", categoryId=");
3505                            msg.append(categoryId);
3506    
3507                            msg.append(", status=");
3508                            msg.append(status);
3509    
3510                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3511    
3512                            throw new NoSuchThreadException(msg.toString());
3513                    }
3514                    else {
3515                            return list.get(0);
3516                    }
3517            }
3518    
3519            /**
3520             * Finds the last message boards thread in the ordered set where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
3521             *
3522             * <p>
3523             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3524             * </p>
3525             *
3526             * @param groupId the group id to search with
3527             * @param categoryId the category id to search with
3528             * @param status the status to search with
3529             * @param orderByComparator the comparator to order the set by
3530             * @return the last matching message boards thread
3531             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a matching message boards thread could not be found
3532             * @throws SystemException if a system exception occurred
3533             */
3534            public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
3535                    int status, OrderByComparator orderByComparator)
3536                    throws NoSuchThreadException, SystemException {
3537                    int count = countByG_NotC_S(groupId, categoryId, status);
3538    
3539                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
3540                                    count - 1, count, orderByComparator);
3541    
3542                    if (list.isEmpty()) {
3543                            StringBundler msg = new StringBundler(8);
3544    
3545                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3546    
3547                            msg.append("groupId=");
3548                            msg.append(groupId);
3549    
3550                            msg.append(", categoryId=");
3551                            msg.append(categoryId);
3552    
3553                            msg.append(", status=");
3554                            msg.append(status);
3555    
3556                            msg.append(StringPool.CLOSE_CURLY_BRACE);
3557    
3558                            throw new NoSuchThreadException(msg.toString());
3559                    }
3560                    else {
3561                            return list.get(0);
3562                    }
3563            }
3564    
3565            /**
3566             * Finds 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;.
3567             *
3568             * <p>
3569             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3570             * </p>
3571             *
3572             * @param threadId the primary key of the current message boards thread
3573             * @param groupId the group id to search with
3574             * @param categoryId the category id to search with
3575             * @param status the status to search with
3576             * @param orderByComparator the comparator to order the set by
3577             * @return the previous, current, and next message boards thread
3578             * @throws com.liferay.portlet.messageboards.NoSuchThreadException if a message boards thread with the primary key could not be found
3579             * @throws SystemException if a system exception occurred
3580             */
3581            public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
3582                    long categoryId, int status, OrderByComparator orderByComparator)
3583                    throws NoSuchThreadException, SystemException {
3584                    MBThread mbThread = findByPrimaryKey(threadId);
3585    
3586                    Session session = null;
3587    
3588                    try {
3589                            session = openSession();
3590    
3591                            MBThread[] array = new MBThreadImpl[3];
3592    
3593                            array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
3594                                            categoryId, status, orderByComparator, true);
3595    
3596                            array[1] = mbThread;
3597    
3598                            array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
3599                                            categoryId, status, orderByComparator, false);
3600    
3601                            return array;
3602                    }
3603                    catch (Exception e) {
3604                            throw processException(e);
3605                    }
3606                    finally {
3607                            closeSession(session);
3608                    }
3609            }
3610    
3611            protected MBThread getByG_NotC_S_PrevAndNext(Session session,
3612                    MBThread mbThread, long groupId, long categoryId, int status,
3613                    OrderByComparator orderByComparator, boolean previous) {
3614                    StringBundler query = null;
3615    
3616                    if (orderByComparator != null) {
3617                            query = new StringBundler(6 +
3618                                            (orderByComparator.getOrderByFields().length * 6));
3619                    }
3620                    else {
3621                            query = new StringBundler(3);
3622                    }
3623    
3624                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
3625    
3626                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
3627    
3628                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
3629    
3630                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
3631    
3632                    if (orderByComparator != null) {
3633                            String[] orderByFields = orderByComparator.getOrderByFields();
3634    
3635                            if (orderByFields.length > 0) {
3636                                    query.append(WHERE_AND);
3637                            }
3638    
3639                            for (int i = 0; i < orderByFields.length; i++) {
3640                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3641                                    query.append(orderByFields[i]);
3642    
3643                                    if ((i + 1) < orderByFields.length) {
3644                                            if (orderByComparator.isAscending() ^ previous) {
3645                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3646                                            }
3647                                            else {
3648                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3649                                            }
3650                                    }
3651                                    else {
3652                                            if (orderByComparator.isAscending() ^ previous) {
3653                                                    query.append(WHERE_GREATER_THAN);
3654                                            }
3655                                            else {
3656                                                    query.append(WHERE_LESSER_THAN);
3657                                            }
3658                                    }
3659                            }
3660    
3661                            query.append(ORDER_BY_CLAUSE);
3662    
3663                            for (int i = 0; i < orderByFields.length; i++) {
3664                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3665                                    query.append(orderByFields[i]);
3666    
3667                                    if ((i + 1) < orderByFields.length) {
3668                                            if (orderByComparator.isAscending() ^ previous) {
3669                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3670                                            }
3671                                            else {
3672                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3673                                            }
3674                                    }
3675                                    else {
3676                                            if (orderByComparator.isAscending() ^ previous) {
3677                                                    query.append(ORDER_BY_ASC);
3678                                            }
3679                                            else {
3680                                                    query.append(ORDER_BY_DESC);
3681                                            }
3682                                    }
3683                            }
3684                    }
3685    
3686                    else {
3687                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3688                    }
3689    
3690                    String sql = query.toString();
3691    
3692                    Query q = session.createQuery(sql);
3693    
3694                    q.setFirstResult(0);
3695                    q.setMaxResults(2);
3696    
3697                    QueryPos qPos = QueryPos.getInstance(q);
3698    
3699                    qPos.add(groupId);
3700    
3701                    qPos.add(categoryId);
3702    
3703                    qPos.add(status);
3704    
3705                    if (orderByComparator != null) {
3706                            Object[] values = orderByComparator.getOrderByValues(mbThread);
3707    
3708                            for (Object value : values) {
3709                                    qPos.add(value);
3710                            }
3711                    }
3712    
3713                    List<MBThread> list = q.list();
3714    
3715                    if (list.size() == 2) {
3716                            return list.get(1);
3717                    }
3718                    else {
3719                            return null;
3720                    }
3721            }
3722    
3723            /**
3724             * Finds all the message boards threads.
3725             *
3726             * @return the message boards threads
3727             * @throws SystemException if a system exception occurred
3728             */
3729            public List<MBThread> findAll() throws SystemException {
3730                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3731            }
3732    
3733            /**
3734             * Finds a range of all the message boards threads.
3735             *
3736             * <p>
3737             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3738             * </p>
3739             *
3740             * @param start the lower bound of the range of message boards threads to return
3741             * @param end the upper bound of the range of message boards threads to return (not inclusive)
3742             * @return the range of message boards threads
3743             * @throws SystemException if a system exception occurred
3744             */
3745            public List<MBThread> findAll(int start, int end) throws SystemException {
3746                    return findAll(start, end, null);
3747            }
3748    
3749            /**
3750             * Finds an ordered range of all the message boards threads.
3751             *
3752             * <p>
3753             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
3754             * </p>
3755             *
3756             * @param start the lower bound of the range of message boards threads to return
3757             * @param end the upper bound of the range of message boards threads to return (not inclusive)
3758             * @param orderByComparator the comparator to order the results by
3759             * @return the ordered range of message boards threads
3760             * @throws SystemException if a system exception occurred
3761             */
3762            public List<MBThread> findAll(int start, int end,
3763                    OrderByComparator orderByComparator) throws SystemException {
3764                    Object[] finderArgs = new Object[] {
3765                                    String.valueOf(start), String.valueOf(end),
3766                                    String.valueOf(orderByComparator)
3767                            };
3768    
3769                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
3770                                    finderArgs, this);
3771    
3772                    if (list == null) {
3773                            Session session = null;
3774    
3775                            try {
3776                                    session = openSession();
3777    
3778                                    StringBundler query = null;
3779                                    String sql = null;
3780    
3781                                    if (orderByComparator != null) {
3782                                            query = new StringBundler(2 +
3783                                                            (orderByComparator.getOrderByFields().length * 3));
3784    
3785                                            query.append(_SQL_SELECT_MBTHREAD);
3786    
3787                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3788                                                    orderByComparator);
3789    
3790                                            sql = query.toString();
3791                                    }
3792                                    else {
3793                                            sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
3794                                    }
3795    
3796                                    Query q = session.createQuery(sql);
3797    
3798                                    if (orderByComparator == null) {
3799                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3800                                                            start, end, false);
3801    
3802                                            Collections.sort(list);
3803                                    }
3804                                    else {
3805                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3806                                                            start, end);
3807                                    }
3808                            }
3809                            catch (Exception e) {
3810                                    throw processException(e);
3811                            }
3812                            finally {
3813                                    if (list == null) {
3814                                            list = new ArrayList<MBThread>();
3815                                    }
3816    
3817                                    cacheResult(list);
3818    
3819                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
3820    
3821                                    closeSession(session);
3822                            }
3823                    }
3824    
3825                    return list;
3826            }
3827    
3828            /**
3829             * Removes all the message boards threads where groupId = &#63; from the database.
3830             *
3831             * @param groupId the group id to search with
3832             * @throws SystemException if a system exception occurred
3833             */
3834            public void removeByGroupId(long groupId) throws SystemException {
3835                    for (MBThread mbThread : findByGroupId(groupId)) {
3836                            remove(mbThread);
3837                    }
3838            }
3839    
3840            /**
3841             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; from the database.
3842             *
3843             * @param groupId the group id to search with
3844             * @param categoryId the category id to search with
3845             * @throws SystemException if a system exception occurred
3846             */
3847            public void removeByG_C(long groupId, long categoryId)
3848                    throws SystemException {
3849                    for (MBThread mbThread : findByG_C(groupId, categoryId)) {
3850                            remove(mbThread);
3851                    }
3852            }
3853    
3854            /**
3855             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; from the database.
3856             *
3857             * @param groupId the group id to search with
3858             * @param categoryId the category id to search with
3859             * @throws SystemException if a system exception occurred
3860             */
3861            public void removeByG_NotC(long groupId, long categoryId)
3862                    throws SystemException {
3863                    for (MBThread mbThread : findByG_NotC(groupId, categoryId)) {
3864                            remove(mbThread);
3865                    }
3866            }
3867    
3868            /**
3869             * Removes all the message boards threads where groupId = &#63; and status = &#63; from the database.
3870             *
3871             * @param groupId the group id to search with
3872             * @param status the status to search with
3873             * @throws SystemException if a system exception occurred
3874             */
3875            public void removeByG_S(long groupId, int status) throws SystemException {
3876                    for (MBThread mbThread : findByG_S(groupId, status)) {
3877                            remove(mbThread);
3878                    }
3879            }
3880    
3881            /**
3882             * Removes all the message boards threads where categoryId = &#63; and priority = &#63; from the database.
3883             *
3884             * @param categoryId the category id to search with
3885             * @param priority the priority to search with
3886             * @throws SystemException if a system exception occurred
3887             */
3888            public void removeByC_P(long categoryId, double priority)
3889                    throws SystemException {
3890                    for (MBThread mbThread : findByC_P(categoryId, priority)) {
3891                            remove(mbThread);
3892                    }
3893            }
3894    
3895            /**
3896             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63; from the database.
3897             *
3898             * @param groupId the group id to search with
3899             * @param categoryId the category id to search with
3900             * @param lastPostDate the last post date to search with
3901             * @throws SystemException if a system exception occurred
3902             */
3903            public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
3904                    throws SystemException {
3905                    for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate)) {
3906                            remove(mbThread);
3907                    }
3908            }
3909    
3910            /**
3911             * Removes all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
3912             *
3913             * @param groupId the group id to search with
3914             * @param categoryId the category id to search with
3915             * @param status the status to search with
3916             * @throws SystemException if a system exception occurred
3917             */
3918            public void removeByG_C_S(long groupId, long categoryId, int status)
3919                    throws SystemException {
3920                    for (MBThread mbThread : findByG_C_S(groupId, categoryId, status)) {
3921                            remove(mbThread);
3922                    }
3923            }
3924    
3925            /**
3926             * Removes all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63; from the database.
3927             *
3928             * @param groupId the group id to search with
3929             * @param categoryId the category id to search with
3930             * @param status the status to search with
3931             * @throws SystemException if a system exception occurred
3932             */
3933            public void removeByG_NotC_S(long groupId, long categoryId, int status)
3934                    throws SystemException {
3935                    for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status)) {
3936                            remove(mbThread);
3937                    }
3938            }
3939    
3940            /**
3941             * Removes all the message boards threads from the database.
3942             *
3943             * @throws SystemException if a system exception occurred
3944             */
3945            public void removeAll() throws SystemException {
3946                    for (MBThread mbThread : findAll()) {
3947                            remove(mbThread);
3948                    }
3949            }
3950    
3951            /**
3952             * Counts all the message boards threads where groupId = &#63;.
3953             *
3954             * @param groupId the group id to search with
3955             * @return the number of matching message boards threads
3956             * @throws SystemException if a system exception occurred
3957             */
3958            public int countByGroupId(long groupId) throws SystemException {
3959                    Object[] finderArgs = new Object[] { groupId };
3960    
3961                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3962                                    finderArgs, this);
3963    
3964                    if (count == null) {
3965                            Session session = null;
3966    
3967                            try {
3968                                    session = openSession();
3969    
3970                                    StringBundler query = new StringBundler(2);
3971    
3972                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3973    
3974                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3975    
3976                                    String sql = query.toString();
3977    
3978                                    Query q = session.createQuery(sql);
3979    
3980                                    QueryPos qPos = QueryPos.getInstance(q);
3981    
3982                                    qPos.add(groupId);
3983    
3984                                    count = (Long)q.uniqueResult();
3985                            }
3986                            catch (Exception e) {
3987                                    throw processException(e);
3988                            }
3989                            finally {
3990                                    if (count == null) {
3991                                            count = Long.valueOf(0);
3992                                    }
3993    
3994                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3995                                            finderArgs, count);
3996    
3997                                    closeSession(session);
3998                            }
3999                    }
4000    
4001                    return count.intValue();
4002            }
4003    
4004            /**
4005             * Counts all the message boards threads where groupId = &#63; and categoryId = &#63;.
4006             *
4007             * @param groupId the group id to search with
4008             * @param categoryId the category id to search with
4009             * @return the number of matching message boards threads
4010             * @throws SystemException if a system exception occurred
4011             */
4012            public int countByG_C(long groupId, long categoryId)
4013                    throws SystemException {
4014                    Object[] finderArgs = new Object[] { groupId, categoryId };
4015    
4016                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
4017                                    finderArgs, this);
4018    
4019                    if (count == null) {
4020                            Session session = null;
4021    
4022                            try {
4023                                    session = openSession();
4024    
4025                                    StringBundler query = new StringBundler(3);
4026    
4027                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4028    
4029                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
4030    
4031                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
4032    
4033                                    String sql = query.toString();
4034    
4035                                    Query q = session.createQuery(sql);
4036    
4037                                    QueryPos qPos = QueryPos.getInstance(q);
4038    
4039                                    qPos.add(groupId);
4040    
4041                                    qPos.add(categoryId);
4042    
4043                                    count = (Long)q.uniqueResult();
4044                            }
4045                            catch (Exception e) {
4046                                    throw processException(e);
4047                            }
4048                            finally {
4049                                    if (count == null) {
4050                                            count = Long.valueOf(0);
4051                                    }
4052    
4053                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
4054                                            count);
4055    
4056                                    closeSession(session);
4057                            }
4058                    }
4059    
4060                    return count.intValue();
4061            }
4062    
4063            /**
4064             * Counts all the message boards threads where groupId = &#63; and categoryId = any &#63;.
4065             *
4066             * @param groupId the group id to search with
4067             * @param categoryIds the category ids to search with
4068             * @return the number of matching message boards threads
4069             * @throws SystemException if a system exception occurred
4070             */
4071            public int countByG_C(long groupId, long[] categoryIds)
4072                    throws SystemException {
4073                    Object[] finderArgs = new Object[] {
4074                                    groupId, StringUtil.merge(categoryIds)
4075                            };
4076    
4077                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
4078                                    finderArgs, this);
4079    
4080                    if (count == null) {
4081                            Session session = null;
4082    
4083                            try {
4084                                    session = openSession();
4085    
4086                                    StringBundler query = new StringBundler();
4087    
4088                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4089    
4090                                    boolean conjunctionable = false;
4091    
4092                                    if (conjunctionable) {
4093                                            query.append(WHERE_AND);
4094                                    }
4095    
4096                                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
4097    
4098                                    conjunctionable = true;
4099    
4100                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
4101                                            if (conjunctionable) {
4102                                                    query.append(WHERE_AND);
4103                                            }
4104    
4105                                            query.append(StringPool.OPEN_PARENTHESIS);
4106    
4107                                            for (int i = 0; i < categoryIds.length; i++) {
4108                                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
4109    
4110                                                    if ((i + 1) < categoryIds.length) {
4111                                                            query.append(WHERE_OR);
4112                                                    }
4113                                            }
4114    
4115                                            query.append(StringPool.CLOSE_PARENTHESIS);
4116    
4117                                            conjunctionable = true;
4118                                    }
4119    
4120                                    String sql = query.toString();
4121    
4122                                    Query q = session.createQuery(sql);
4123    
4124                                    QueryPos qPos = QueryPos.getInstance(q);
4125    
4126                                    qPos.add(groupId);
4127    
4128                                    if (categoryIds != null) {
4129                                            qPos.add(categoryIds);
4130                                    }
4131    
4132                                    count = (Long)q.uniqueResult();
4133                            }
4134                            catch (Exception e) {
4135                                    throw processException(e);
4136                            }
4137                            finally {
4138                                    if (count == null) {
4139                                            count = Long.valueOf(0);
4140                                    }
4141    
4142                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
4143                                            count);
4144    
4145                                    closeSession(session);
4146                            }
4147                    }
4148    
4149                    return count.intValue();
4150            }
4151    
4152            /**
4153             * Counts all the message boards threads where groupId = &#63; and categoryId &ne; &#63;.
4154             *
4155             * @param groupId the group id to search with
4156             * @param categoryId the category id to search with
4157             * @return the number of matching message boards threads
4158             * @throws SystemException if a system exception occurred
4159             */
4160            public int countByG_NotC(long groupId, long categoryId)
4161                    throws SystemException {
4162                    Object[] finderArgs = new Object[] { groupId, categoryId };
4163    
4164                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC,
4165                                    finderArgs, this);
4166    
4167                    if (count == null) {
4168                            Session session = null;
4169    
4170                            try {
4171                                    session = openSession();
4172    
4173                                    StringBundler query = new StringBundler(3);
4174    
4175                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4176    
4177                                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4178    
4179                                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4180    
4181                                    String sql = query.toString();
4182    
4183                                    Query q = session.createQuery(sql);
4184    
4185                                    QueryPos qPos = QueryPos.getInstance(q);
4186    
4187                                    qPos.add(groupId);
4188    
4189                                    qPos.add(categoryId);
4190    
4191                                    count = (Long)q.uniqueResult();
4192                            }
4193                            catch (Exception e) {
4194                                    throw processException(e);
4195                            }
4196                            finally {
4197                                    if (count == null) {
4198                                            count = Long.valueOf(0);
4199                                    }
4200    
4201                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC,
4202                                            finderArgs, count);
4203    
4204                                    closeSession(session);
4205                            }
4206                    }
4207    
4208                    return count.intValue();
4209            }
4210    
4211            /**
4212             * Counts all the message boards threads where groupId = &#63; and status = &#63;.
4213             *
4214             * @param groupId the group id to search with
4215             * @param status the status to search with
4216             * @return the number of matching message boards threads
4217             * @throws SystemException if a system exception occurred
4218             */
4219            public int countByG_S(long groupId, int status) throws SystemException {
4220                    Object[] finderArgs = new Object[] { groupId, status };
4221    
4222                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
4223                                    finderArgs, this);
4224    
4225                    if (count == null) {
4226                            Session session = null;
4227    
4228                            try {
4229                                    session = openSession();
4230    
4231                                    StringBundler query = new StringBundler(3);
4232    
4233                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4234    
4235                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4236    
4237                                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4238    
4239                                    String sql = query.toString();
4240    
4241                                    Query q = session.createQuery(sql);
4242    
4243                                    QueryPos qPos = QueryPos.getInstance(q);
4244    
4245                                    qPos.add(groupId);
4246    
4247                                    qPos.add(status);
4248    
4249                                    count = (Long)q.uniqueResult();
4250                            }
4251                            catch (Exception e) {
4252                                    throw processException(e);
4253                            }
4254                            finally {
4255                                    if (count == null) {
4256                                            count = Long.valueOf(0);
4257                                    }
4258    
4259                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
4260                                            count);
4261    
4262                                    closeSession(session);
4263                            }
4264                    }
4265    
4266                    return count.intValue();
4267            }
4268    
4269            /**
4270             * Counts all the message boards threads where categoryId = &#63; and priority = &#63;.
4271             *
4272             * @param categoryId the category id to search with
4273             * @param priority the priority to search with
4274             * @return the number of matching message boards threads
4275             * @throws SystemException if a system exception occurred
4276             */
4277            public int countByC_P(long categoryId, double priority)
4278                    throws SystemException {
4279                    Object[] finderArgs = new Object[] { categoryId, priority };
4280    
4281                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
4282                                    finderArgs, this);
4283    
4284                    if (count == null) {
4285                            Session session = null;
4286    
4287                            try {
4288                                    session = openSession();
4289    
4290                                    StringBundler query = new StringBundler(3);
4291    
4292                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4293    
4294                                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4295    
4296                                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4297    
4298                                    String sql = query.toString();
4299    
4300                                    Query q = session.createQuery(sql);
4301    
4302                                    QueryPos qPos = QueryPos.getInstance(q);
4303    
4304                                    qPos.add(categoryId);
4305    
4306                                    qPos.add(priority);
4307    
4308                                    count = (Long)q.uniqueResult();
4309                            }
4310                            catch (Exception e) {
4311                                    throw processException(e);
4312                            }
4313                            finally {
4314                                    if (count == null) {
4315                                            count = Long.valueOf(0);
4316                                    }
4317    
4318                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
4319                                            count);
4320    
4321                                    closeSession(session);
4322                            }
4323                    }
4324    
4325                    return count.intValue();
4326            }
4327    
4328            /**
4329             * Counts all the message boards threads where groupId = &#63; and categoryId = &#63; and lastPostDate = &#63;.
4330             *
4331             * @param groupId the group id to search with
4332             * @param categoryId the category id to search with
4333             * @param lastPostDate the last post date to search with
4334             * @return the number of matching message boards threads
4335             * @throws SystemException if a system exception occurred
4336             */
4337            public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
4338                    throws SystemException {
4339                    Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
4340    
4341                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_L,
4342                                    finderArgs, this);
4343    
4344                    if (count == null) {
4345                            Session session = null;
4346    
4347                            try {
4348                                    session = openSession();
4349    
4350                                    StringBundler query = new StringBundler(4);
4351    
4352                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4353    
4354                                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
4355    
4356                                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
4357    
4358                                    if (lastPostDate == null) {
4359                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
4360                                    }
4361                                    else {
4362                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
4363                                    }
4364    
4365                                    String sql = query.toString();
4366    
4367                                    Query q = session.createQuery(sql);
4368    
4369                                    QueryPos qPos = QueryPos.getInstance(q);
4370    
4371                                    qPos.add(groupId);
4372    
4373                                    qPos.add(categoryId);
4374    
4375                                    if (lastPostDate != null) {
4376                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4377                                    }
4378    
4379                                    count = (Long)q.uniqueResult();
4380                            }
4381                            catch (Exception e) {
4382                                    throw processException(e);
4383                            }
4384                            finally {
4385                                    if (count == null) {
4386                                            count = Long.valueOf(0);
4387                                    }
4388    
4389                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_L,
4390                                            finderArgs, count);
4391    
4392                                    closeSession(session);
4393                            }
4394                    }
4395    
4396                    return count.intValue();
4397            }
4398    
4399            /**
4400             * Counts all the message boards threads where groupId = &#63; and categoryId = &#63; and status = &#63;.
4401             *
4402             * @param groupId the group id to search with
4403             * @param categoryId the category id to search with
4404             * @param status the status to search with
4405             * @return the number of matching message boards threads
4406             * @throws SystemException if a system exception occurred
4407             */
4408            public int countByG_C_S(long groupId, long categoryId, int status)
4409                    throws SystemException {
4410                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
4411    
4412                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
4413                                    finderArgs, this);
4414    
4415                    if (count == null) {
4416                            Session session = null;
4417    
4418                            try {
4419                                    session = openSession();
4420    
4421                                    StringBundler query = new StringBundler(4);
4422    
4423                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4424    
4425                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
4426    
4427                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
4428    
4429                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
4430    
4431                                    String sql = query.toString();
4432    
4433                                    Query q = session.createQuery(sql);
4434    
4435                                    QueryPos qPos = QueryPos.getInstance(q);
4436    
4437                                    qPos.add(groupId);
4438    
4439                                    qPos.add(categoryId);
4440    
4441                                    qPos.add(status);
4442    
4443                                    count = (Long)q.uniqueResult();
4444                            }
4445                            catch (Exception e) {
4446                                    throw processException(e);
4447                            }
4448                            finally {
4449                                    if (count == null) {
4450                                            count = Long.valueOf(0);
4451                                    }
4452    
4453                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
4454                                            finderArgs, count);
4455    
4456                                    closeSession(session);
4457                            }
4458                    }
4459    
4460                    return count.intValue();
4461            }
4462    
4463            /**
4464             * Counts all the message boards threads where groupId = &#63; and categoryId = any &#63; and status = &#63;.
4465             *
4466             * @param groupId the group id to search with
4467             * @param categoryIds the category ids to search with
4468             * @param status the status to search with
4469             * @return the number of matching message boards threads
4470             * @throws SystemException if a system exception occurred
4471             */
4472            public int countByG_C_S(long groupId, long[] categoryIds, int status)
4473                    throws SystemException {
4474                    Object[] finderArgs = new Object[] {
4475                                    groupId, StringUtil.merge(categoryIds), status
4476                            };
4477    
4478                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
4479                                    finderArgs, this);
4480    
4481                    if (count == null) {
4482                            Session session = null;
4483    
4484                            try {
4485                                    session = openSession();
4486    
4487                                    StringBundler query = new StringBundler();
4488    
4489                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4490    
4491                                    boolean conjunctionable = false;
4492    
4493                                    if (conjunctionable) {
4494                                            query.append(WHERE_AND);
4495                                    }
4496    
4497                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
4498    
4499                                    conjunctionable = true;
4500    
4501                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
4502                                            if (conjunctionable) {
4503                                                    query.append(WHERE_AND);
4504                                            }
4505    
4506                                            query.append(StringPool.OPEN_PARENTHESIS);
4507    
4508                                            for (int i = 0; i < categoryIds.length; i++) {
4509                                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
4510    
4511                                                    if ((i + 1) < categoryIds.length) {
4512                                                            query.append(WHERE_OR);
4513                                                    }
4514                                            }
4515    
4516                                            query.append(StringPool.CLOSE_PARENTHESIS);
4517    
4518                                            conjunctionable = true;
4519                                    }
4520    
4521                                    if (conjunctionable) {
4522                                            query.append(WHERE_AND);
4523                                    }
4524    
4525                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
4526    
4527                                    conjunctionable = true;
4528    
4529                                    String sql = query.toString();
4530    
4531                                    Query q = session.createQuery(sql);
4532    
4533                                    QueryPos qPos = QueryPos.getInstance(q);
4534    
4535                                    qPos.add(groupId);
4536    
4537                                    if (categoryIds != null) {
4538                                            qPos.add(categoryIds);
4539                                    }
4540    
4541                                    qPos.add(status);
4542    
4543                                    count = (Long)q.uniqueResult();
4544                            }
4545                            catch (Exception e) {
4546                                    throw processException(e);
4547                            }
4548                            finally {
4549                                    if (count == null) {
4550                                            count = Long.valueOf(0);
4551                                    }
4552    
4553                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
4554                                            finderArgs, count);
4555    
4556                                    closeSession(session);
4557                            }
4558                    }
4559    
4560                    return count.intValue();
4561            }
4562    
4563            /**
4564             * Counts all the message boards threads where groupId = &#63; and categoryId &ne; &#63; and status = &#63;.
4565             *
4566             * @param groupId the group id to search with
4567             * @param categoryId the category id to search with
4568             * @param status the status to search with
4569             * @return the number of matching message boards threads
4570             * @throws SystemException if a system exception occurred
4571             */
4572            public int countByG_NotC_S(long groupId, long categoryId, int status)
4573                    throws SystemException {
4574                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
4575    
4576                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
4577                                    finderArgs, this);
4578    
4579                    if (count == null) {
4580                            Session session = null;
4581    
4582                            try {
4583                                    session = openSession();
4584    
4585                                    StringBundler query = new StringBundler(4);
4586    
4587                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
4588    
4589                                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
4590    
4591                                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
4592    
4593                                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
4594    
4595                                    String sql = query.toString();
4596    
4597                                    Query q = session.createQuery(sql);
4598    
4599                                    QueryPos qPos = QueryPos.getInstance(q);
4600    
4601                                    qPos.add(groupId);
4602    
4603                                    qPos.add(categoryId);
4604    
4605                                    qPos.add(status);
4606    
4607                                    count = (Long)q.uniqueResult();
4608                            }
4609                            catch (Exception e) {
4610                                    throw processException(e);
4611                            }
4612                            finally {
4613                                    if (count == null) {
4614                                            count = Long.valueOf(0);
4615                                    }
4616    
4617                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
4618                                            finderArgs, count);
4619    
4620                                    closeSession(session);
4621                            }
4622                    }
4623    
4624                    return count.intValue();
4625            }
4626    
4627            /**
4628             * Counts all the message boards threads.
4629             *
4630             * @return the number of message boards threads
4631             * @throws SystemException if a system exception occurred
4632             */
4633            public int countAll() throws SystemException {
4634                    Object[] finderArgs = new Object[0];
4635    
4636                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4637                                    finderArgs, this);
4638    
4639                    if (count == null) {
4640                            Session session = null;
4641    
4642                            try {
4643                                    session = openSession();
4644    
4645                                    Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
4646    
4647                                    count = (Long)q.uniqueResult();
4648                            }
4649                            catch (Exception e) {
4650                                    throw processException(e);
4651                            }
4652                            finally {
4653                                    if (count == null) {
4654                                            count = Long.valueOf(0);
4655                                    }
4656    
4657                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
4658                                            count);
4659    
4660                                    closeSession(session);
4661                            }
4662                    }
4663    
4664                    return count.intValue();
4665            }
4666    
4667            /**
4668             * Initializes the message boards thread persistence.
4669             */
4670            public void afterPropertiesSet() {
4671                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4672                                            com.liferay.portal.util.PropsUtil.get(
4673                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
4674    
4675                    if (listenerClassNames.length > 0) {
4676                            try {
4677                                    List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
4678    
4679                                    for (String listenerClassName : listenerClassNames) {
4680                                            listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
4681                                                            listenerClassName));
4682                                    }
4683    
4684                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4685                            }
4686                            catch (Exception e) {
4687                                    _log.error(e);
4688                            }
4689                    }
4690            }
4691    
4692            public void destroy() {
4693                    EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
4694                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4695                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
4696            }
4697    
4698            @BeanReference(type = MBBanPersistence.class)
4699            protected MBBanPersistence mbBanPersistence;
4700            @BeanReference(type = MBCategoryPersistence.class)
4701            protected MBCategoryPersistence mbCategoryPersistence;
4702            @BeanReference(type = MBDiscussionPersistence.class)
4703            protected MBDiscussionPersistence mbDiscussionPersistence;
4704            @BeanReference(type = MBMailingListPersistence.class)
4705            protected MBMailingListPersistence mbMailingListPersistence;
4706            @BeanReference(type = MBMessagePersistence.class)
4707            protected MBMessagePersistence mbMessagePersistence;
4708            @BeanReference(type = MBMessageFlagPersistence.class)
4709            protected MBMessageFlagPersistence mbMessageFlagPersistence;
4710            @BeanReference(type = MBStatsUserPersistence.class)
4711            protected MBStatsUserPersistence mbStatsUserPersistence;
4712            @BeanReference(type = MBThreadPersistence.class)
4713            protected MBThreadPersistence mbThreadPersistence;
4714            @BeanReference(type = LockPersistence.class)
4715            protected LockPersistence lockPersistence;
4716            @BeanReference(type = ResourcePersistence.class)
4717            protected ResourcePersistence resourcePersistence;
4718            @BeanReference(type = UserPersistence.class)
4719            protected UserPersistence userPersistence;
4720            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4721            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4722            @BeanReference(type = AssetEntryPersistence.class)
4723            protected AssetEntryPersistence assetEntryPersistence;
4724            @BeanReference(type = RatingsStatsPersistence.class)
4725            protected RatingsStatsPersistence ratingsStatsPersistence;
4726            @BeanReference(type = SocialActivityPersistence.class)
4727            protected SocialActivityPersistence socialActivityPersistence;
4728            private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
4729            private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
4730            private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
4731            private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
4732            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ?";
4733            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
4734            private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
4735                    _removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
4736            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
4737            private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
4738                    _removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
4739            private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
4740            private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
4741            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
4742            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ?";
4743            private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
4744            private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
4745            private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
4746            private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
4747            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
4748            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
4749            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
4750            private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
4751                    _removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
4752            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
4753            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
4754                    _removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
4755            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
4756            private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
4757                    _removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
4758            private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
4759            private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
4760            private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
4761    
4762            private static String _removeConjunction(String sql) {
4763                    int pos = sql.indexOf(" AND ");
4764    
4765                    if (pos != -1) {
4766                            sql = sql.substring(0, pos);
4767                    }
4768    
4769                    return sql;
4770            }
4771    
4772            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
4773            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
4774            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
4775            private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
4776    }