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