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     * @author    Brian Wing Shun Chan
062     * @see       MBThreadPersistence
063     * @see       MBThreadUtil
064     * @generated
065     */
066    public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
067            implements MBThreadPersistence {
068            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
069            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
070                    ".List";
071            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
072                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
073                            "findByGroupId",
074                            new String[] {
075                                    Long.class.getName(),
076                                    
077                            "java.lang.Integer", "java.lang.Integer",
078                                    "com.liferay.portal.kernel.util.OrderByComparator"
079                            });
080            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
081                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082                            "countByGroupId", new String[] { Long.class.getName() });
083            public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
084                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085                            "findByG_C",
086                            new String[] {
087                                    Long.class.getName(), Long.class.getName(),
088                                    
089                            "java.lang.Integer", "java.lang.Integer",
090                                    "com.liferay.portal.kernel.util.OrderByComparator"
091                            });
092            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
093                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
094                            "countByG_C",
095                            new String[] { Long.class.getName(), Long.class.getName() });
096            public static final FinderPath FINDER_PATH_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
097                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
098                            "findByG_NotC",
099                            new String[] {
100                                    Long.class.getName(), Long.class.getName(),
101                                    
102                            "java.lang.Integer", "java.lang.Integer",
103                                    "com.liferay.portal.kernel.util.OrderByComparator"
104                            });
105            public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
106                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107                            "countByG_NotC",
108                            new String[] { Long.class.getName(), Long.class.getName() });
109            public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
110                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111                            "findByG_S",
112                            new String[] {
113                                    Long.class.getName(), Integer.class.getName(),
114                                    
115                            "java.lang.Integer", "java.lang.Integer",
116                                    "com.liferay.portal.kernel.util.OrderByComparator"
117                            });
118            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
119                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120                            "countByG_S",
121                            new String[] { Long.class.getName(), Integer.class.getName() });
122            public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
123                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124                            "findByC_P",
125                            new String[] {
126                                    Long.class.getName(), Double.class.getName(),
127                                    
128                            "java.lang.Integer", "java.lang.Integer",
129                                    "com.liferay.portal.kernel.util.OrderByComparator"
130                            });
131            public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
132                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133                            "countByC_P",
134                            new String[] { Long.class.getName(), Double.class.getName() });
135            public static final FinderPath FINDER_PATH_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
136                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137                            "findByG_C_L",
138                            new String[] {
139                                    Long.class.getName(), Long.class.getName(), Date.class.getName(),
140                                    
141                            "java.lang.Integer", "java.lang.Integer",
142                                    "com.liferay.portal.kernel.util.OrderByComparator"
143                            });
144            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
145                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
146                            "countByG_C_L",
147                            new String[] {
148                                    Long.class.getName(), Long.class.getName(), Date.class.getName()
149                            });
150            public static final FinderPath FINDER_PATH_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
151                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
152                            "findByG_C_S",
153                            new String[] {
154                                    Long.class.getName(), Long.class.getName(),
155                                    Integer.class.getName(),
156                                    
157                            "java.lang.Integer", "java.lang.Integer",
158                                    "com.liferay.portal.kernel.util.OrderByComparator"
159                            });
160            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
161                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
162                            "countByG_C_S",
163                            new String[] {
164                                    Long.class.getName(), Long.class.getName(),
165                                    Integer.class.getName()
166                            });
167            public static final FinderPath FINDER_PATH_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
168                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
169                            "findByG_NotC_S",
170                            new String[] {
171                                    Long.class.getName(), Long.class.getName(),
172                                    Integer.class.getName(),
173                                    
174                            "java.lang.Integer", "java.lang.Integer",
175                                    "com.liferay.portal.kernel.util.OrderByComparator"
176                            });
177            public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
178                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
179                            "countByG_NotC_S",
180                            new String[] {
181                                    Long.class.getName(), Long.class.getName(),
182                                    Integer.class.getName()
183                            });
184            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
185                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
186                            "findAll", new String[0]);
187            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
188                            MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
189                            "countAll", new String[0]);
190    
191            public void cacheResult(MBThread mbThread) {
192                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
193                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
194            }
195    
196            public void cacheResult(List<MBThread> mbThreads) {
197                    for (MBThread mbThread : mbThreads) {
198                            if (EntityCacheUtil.getResult(
199                                                    MBThreadModelImpl.ENTITY_CACHE_ENABLED,
200                                                    MBThreadImpl.class, mbThread.getPrimaryKey(), this) == null) {
201                                    cacheResult(mbThread);
202                            }
203                    }
204            }
205    
206            public void clearCache() {
207                    CacheRegistryUtil.clear(MBThreadImpl.class.getName());
208                    EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
209                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
211            }
212    
213            public void clearCache(MBThread mbThread) {
214                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
215                            MBThreadImpl.class, mbThread.getPrimaryKey());
216            }
217    
218            public MBThread create(long threadId) {
219                    MBThread mbThread = new MBThreadImpl();
220    
221                    mbThread.setNew(true);
222                    mbThread.setPrimaryKey(threadId);
223    
224                    return mbThread;
225            }
226    
227            public MBThread remove(Serializable primaryKey)
228                    throws NoSuchModelException, SystemException {
229                    return remove(((Long)primaryKey).longValue());
230            }
231    
232            public MBThread remove(long threadId)
233                    throws NoSuchThreadException, SystemException {
234                    Session session = null;
235    
236                    try {
237                            session = openSession();
238    
239                            MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
240                                            new Long(threadId));
241    
242                            if (mbThread == null) {
243                                    if (_log.isWarnEnabled()) {
244                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
245                                    }
246    
247                                    throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
248                                            threadId);
249                            }
250    
251                            return remove(mbThread);
252                    }
253                    catch (NoSuchThreadException nsee) {
254                            throw nsee;
255                    }
256                    catch (Exception e) {
257                            throw processException(e);
258                    }
259                    finally {
260                            closeSession(session);
261                    }
262            }
263    
264            protected MBThread removeImpl(MBThread mbThread) throws SystemException {
265                    mbThread = toUnwrappedModel(mbThread);
266    
267                    Session session = null;
268    
269                    try {
270                            session = openSession();
271    
272                            if (mbThread.isCachedModel() || BatchSessionUtil.isEnabled()) {
273                                    Object staleObject = session.get(MBThreadImpl.class,
274                                                    mbThread.getPrimaryKeyObj());
275    
276                                    if (staleObject != null) {
277                                            session.evict(staleObject);
278                                    }
279                            }
280    
281                            session.delete(mbThread);
282    
283                            session.flush();
284                    }
285                    catch (Exception e) {
286                            throw processException(e);
287                    }
288                    finally {
289                            closeSession(session);
290                    }
291    
292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
293    
294                    EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
295                            MBThreadImpl.class, mbThread.getPrimaryKey());
296    
297                    return mbThread;
298            }
299    
300            public MBThread updateImpl(
301                    com.liferay.portlet.messageboards.model.MBThread mbThread, boolean merge)
302                    throws SystemException {
303                    mbThread = toUnwrappedModel(mbThread);
304    
305                    Session session = null;
306    
307                    try {
308                            session = openSession();
309    
310                            BatchSessionUtil.update(session, mbThread, merge);
311    
312                            mbThread.setNew(false);
313                    }
314                    catch (Exception e) {
315                            throw processException(e);
316                    }
317                    finally {
318                            closeSession(session);
319                    }
320    
321                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
322    
323                    EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
324                            MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
325    
326                    return mbThread;
327            }
328    
329            protected MBThread toUnwrappedModel(MBThread mbThread) {
330                    if (mbThread instanceof MBThreadImpl) {
331                            return mbThread;
332                    }
333    
334                    MBThreadImpl mbThreadImpl = new MBThreadImpl();
335    
336                    mbThreadImpl.setNew(mbThread.isNew());
337                    mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
338    
339                    mbThreadImpl.setThreadId(mbThread.getThreadId());
340                    mbThreadImpl.setGroupId(mbThread.getGroupId());
341                    mbThreadImpl.setCategoryId(mbThread.getCategoryId());
342                    mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
343                    mbThreadImpl.setMessageCount(mbThread.getMessageCount());
344                    mbThreadImpl.setViewCount(mbThread.getViewCount());
345                    mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
346                    mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
347                    mbThreadImpl.setPriority(mbThread.getPriority());
348                    mbThreadImpl.setStatus(mbThread.getStatus());
349                    mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
350                    mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
351                    mbThreadImpl.setStatusDate(mbThread.getStatusDate());
352    
353                    return mbThreadImpl;
354            }
355    
356            public MBThread findByPrimaryKey(Serializable primaryKey)
357                    throws NoSuchModelException, SystemException {
358                    return findByPrimaryKey(((Long)primaryKey).longValue());
359            }
360    
361            public MBThread findByPrimaryKey(long threadId)
362                    throws NoSuchThreadException, SystemException {
363                    MBThread mbThread = fetchByPrimaryKey(threadId);
364    
365                    if (mbThread == null) {
366                            if (_log.isWarnEnabled()) {
367                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
368                            }
369    
370                            throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
371                                    threadId);
372                    }
373    
374                    return mbThread;
375            }
376    
377            public MBThread fetchByPrimaryKey(Serializable primaryKey)
378                    throws SystemException {
379                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
380            }
381    
382            public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
383                    MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
384                                    MBThreadImpl.class, threadId, this);
385    
386                    if (mbThread == null) {
387                            Session session = null;
388    
389                            try {
390                                    session = openSession();
391    
392                                    mbThread = (MBThread)session.get(MBThreadImpl.class,
393                                                    new Long(threadId));
394                            }
395                            catch (Exception e) {
396                                    throw processException(e);
397                            }
398                            finally {
399                                    if (mbThread != null) {
400                                            cacheResult(mbThread);
401                                    }
402    
403                                    closeSession(session);
404                            }
405                    }
406    
407                    return mbThread;
408            }
409    
410            public List<MBThread> findByGroupId(long groupId) throws SystemException {
411                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
412            }
413    
414            public List<MBThread> findByGroupId(long groupId, int start, int end)
415                    throws SystemException {
416                    return findByGroupId(groupId, start, end, null);
417            }
418    
419            public List<MBThread> findByGroupId(long groupId, int start, int end,
420                    OrderByComparator orderByComparator) throws SystemException {
421                    Object[] finderArgs = new Object[] {
422                                    groupId,
423                                    
424                                    String.valueOf(start), String.valueOf(end),
425                                    String.valueOf(orderByComparator)
426                            };
427    
428                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
429                                    finderArgs, this);
430    
431                    if (list == null) {
432                            Session session = null;
433    
434                            try {
435                                    session = openSession();
436    
437                                    StringBundler query = null;
438    
439                                    if (orderByComparator != null) {
440                                            query = new StringBundler(3 +
441                                                            (orderByComparator.getOrderByFields().length * 3));
442                                    }
443                                    else {
444                                            query = new StringBundler(3);
445                                    }
446    
447                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
448    
449                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
450    
451                                    if (orderByComparator != null) {
452                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
453                                                    orderByComparator);
454                                    }
455    
456                                    else {
457                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
458                                    }
459    
460                                    String sql = query.toString();
461    
462                                    Query q = session.createQuery(sql);
463    
464                                    QueryPos qPos = QueryPos.getInstance(q);
465    
466                                    qPos.add(groupId);
467    
468                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
469                                                    end);
470                            }
471                            catch (Exception e) {
472                                    throw processException(e);
473                            }
474                            finally {
475                                    if (list == null) {
476                                            list = new ArrayList<MBThread>();
477                                    }
478    
479                                    cacheResult(list);
480    
481                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
482                                            finderArgs, list);
483    
484                                    closeSession(session);
485                            }
486                    }
487    
488                    return list;
489            }
490    
491            public MBThread findByGroupId_First(long groupId,
492                    OrderByComparator orderByComparator)
493                    throws NoSuchThreadException, SystemException {
494                    List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
495    
496                    if (list.isEmpty()) {
497                            StringBundler msg = new StringBundler(4);
498    
499                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
500    
501                            msg.append("groupId=");
502                            msg.append(groupId);
503    
504                            msg.append(StringPool.CLOSE_CURLY_BRACE);
505    
506                            throw new NoSuchThreadException(msg.toString());
507                    }
508                    else {
509                            return list.get(0);
510                    }
511            }
512    
513            public MBThread findByGroupId_Last(long groupId,
514                    OrderByComparator orderByComparator)
515                    throws NoSuchThreadException, SystemException {
516                    int count = countByGroupId(groupId);
517    
518                    List<MBThread> list = findByGroupId(groupId, count - 1, count,
519                                    orderByComparator);
520    
521                    if (list.isEmpty()) {
522                            StringBundler msg = new StringBundler(4);
523    
524                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
525    
526                            msg.append("groupId=");
527                            msg.append(groupId);
528    
529                            msg.append(StringPool.CLOSE_CURLY_BRACE);
530    
531                            throw new NoSuchThreadException(msg.toString());
532                    }
533                    else {
534                            return list.get(0);
535                    }
536            }
537    
538            public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
539                    OrderByComparator orderByComparator)
540                    throws NoSuchThreadException, SystemException {
541                    MBThread mbThread = findByPrimaryKey(threadId);
542    
543                    Session session = null;
544    
545                    try {
546                            session = openSession();
547    
548                            MBThread[] array = new MBThreadImpl[3];
549    
550                            array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
551                                            orderByComparator, true);
552    
553                            array[1] = mbThread;
554    
555                            array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
556                                            orderByComparator, false);
557    
558                            return array;
559                    }
560                    catch (Exception e) {
561                            throw processException(e);
562                    }
563                    finally {
564                            closeSession(session);
565                    }
566            }
567    
568            protected MBThread getByGroupId_PrevAndNext(Session session,
569                    MBThread mbThread, long groupId, OrderByComparator orderByComparator,
570                    boolean previous) {
571                    StringBundler query = null;
572    
573                    if (orderByComparator != null) {
574                            query = new StringBundler(6 +
575                                            (orderByComparator.getOrderByFields().length * 6));
576                    }
577                    else {
578                            query = new StringBundler(3);
579                    }
580    
581                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
582    
583                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
584    
585                    if (orderByComparator != null) {
586                            String[] orderByFields = orderByComparator.getOrderByFields();
587    
588                            if (orderByFields.length > 0) {
589                                    query.append(WHERE_AND);
590                            }
591    
592                            for (int i = 0; i < orderByFields.length; i++) {
593                                    query.append(_ORDER_BY_ENTITY_ALIAS);
594                                    query.append(orderByFields[i]);
595    
596                                    if ((i + 1) < orderByFields.length) {
597                                            if (orderByComparator.isAscending() ^ previous) {
598                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
599                                            }
600                                            else {
601                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
602                                            }
603                                    }
604                                    else {
605                                            if (orderByComparator.isAscending() ^ previous) {
606                                                    query.append(WHERE_GREATER_THAN);
607                                            }
608                                            else {
609                                                    query.append(WHERE_LESSER_THAN);
610                                            }
611                                    }
612                            }
613    
614                            query.append(ORDER_BY_CLAUSE);
615    
616                            for (int i = 0; i < orderByFields.length; i++) {
617                                    query.append(_ORDER_BY_ENTITY_ALIAS);
618                                    query.append(orderByFields[i]);
619    
620                                    if ((i + 1) < orderByFields.length) {
621                                            if (orderByComparator.isAscending() ^ previous) {
622                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
623                                            }
624                                            else {
625                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
626                                            }
627                                    }
628                                    else {
629                                            if (orderByComparator.isAscending() ^ previous) {
630                                                    query.append(ORDER_BY_ASC);
631                                            }
632                                            else {
633                                                    query.append(ORDER_BY_DESC);
634                                            }
635                                    }
636                            }
637                    }
638    
639                    else {
640                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
641                    }
642    
643                    String sql = query.toString();
644    
645                    Query q = session.createQuery(sql);
646    
647                    q.setFirstResult(0);
648                    q.setMaxResults(2);
649    
650                    QueryPos qPos = QueryPos.getInstance(q);
651    
652                    qPos.add(groupId);
653    
654                    if (orderByComparator != null) {
655                            Object[] values = orderByComparator.getOrderByValues(mbThread);
656    
657                            for (Object value : values) {
658                                    qPos.add(value);
659                            }
660                    }
661    
662                    List<MBThread> list = q.list();
663    
664                    if (list.size() == 2) {
665                            return list.get(1);
666                    }
667                    else {
668                            return null;
669                    }
670            }
671    
672            public List<MBThread> findByG_C(long groupId, long categoryId)
673                    throws SystemException {
674                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
675                            QueryUtil.ALL_POS, null);
676            }
677    
678            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
679                    int end) throws SystemException {
680                    return findByG_C(groupId, categoryId, start, end, null);
681            }
682    
683            public List<MBThread> findByG_C(long groupId, long categoryId, int start,
684                    int end, OrderByComparator orderByComparator) throws SystemException {
685                    Object[] finderArgs = new Object[] {
686                                    groupId, categoryId,
687                                    
688                                    String.valueOf(start), String.valueOf(end),
689                                    String.valueOf(orderByComparator)
690                            };
691    
692                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
693                                    finderArgs, this);
694    
695                    if (list == null) {
696                            Session session = null;
697    
698                            try {
699                                    session = openSession();
700    
701                                    StringBundler query = null;
702    
703                                    if (orderByComparator != null) {
704                                            query = new StringBundler(4 +
705                                                            (orderByComparator.getOrderByFields().length * 3));
706                                    }
707                                    else {
708                                            query = new StringBundler(4);
709                                    }
710    
711                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
712    
713                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
714    
715                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
716    
717                                    if (orderByComparator != null) {
718                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
719                                                    orderByComparator);
720                                    }
721    
722                                    else {
723                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
724                                    }
725    
726                                    String sql = query.toString();
727    
728                                    Query q = session.createQuery(sql);
729    
730                                    QueryPos qPos = QueryPos.getInstance(q);
731    
732                                    qPos.add(groupId);
733    
734                                    qPos.add(categoryId);
735    
736                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
737                                                    end);
738                            }
739                            catch (Exception e) {
740                                    throw processException(e);
741                            }
742                            finally {
743                                    if (list == null) {
744                                            list = new ArrayList<MBThread>();
745                                    }
746    
747                                    cacheResult(list);
748    
749                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
750                                            list);
751    
752                                    closeSession(session);
753                            }
754                    }
755    
756                    return list;
757            }
758    
759            public MBThread findByG_C_First(long groupId, long categoryId,
760                    OrderByComparator orderByComparator)
761                    throws NoSuchThreadException, SystemException {
762                    List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
763                                    orderByComparator);
764    
765                    if (list.isEmpty()) {
766                            StringBundler msg = new StringBundler(6);
767    
768                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
769    
770                            msg.append("groupId=");
771                            msg.append(groupId);
772    
773                            msg.append(", categoryId=");
774                            msg.append(categoryId);
775    
776                            msg.append(StringPool.CLOSE_CURLY_BRACE);
777    
778                            throw new NoSuchThreadException(msg.toString());
779                    }
780                    else {
781                            return list.get(0);
782                    }
783            }
784    
785            public MBThread findByG_C_Last(long groupId, long categoryId,
786                    OrderByComparator orderByComparator)
787                    throws NoSuchThreadException, SystemException {
788                    int count = countByG_C(groupId, categoryId);
789    
790                    List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
791                                    orderByComparator);
792    
793                    if (list.isEmpty()) {
794                            StringBundler msg = new StringBundler(6);
795    
796                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
797    
798                            msg.append("groupId=");
799                            msg.append(groupId);
800    
801                            msg.append(", categoryId=");
802                            msg.append(categoryId);
803    
804                            msg.append(StringPool.CLOSE_CURLY_BRACE);
805    
806                            throw new NoSuchThreadException(msg.toString());
807                    }
808                    else {
809                            return list.get(0);
810                    }
811            }
812    
813            public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
814                    long categoryId, OrderByComparator orderByComparator)
815                    throws NoSuchThreadException, SystemException {
816                    MBThread mbThread = findByPrimaryKey(threadId);
817    
818                    Session session = null;
819    
820                    try {
821                            session = openSession();
822    
823                            MBThread[] array = new MBThreadImpl[3];
824    
825                            array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
826                                            categoryId, orderByComparator, true);
827    
828                            array[1] = mbThread;
829    
830                            array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
831                                            categoryId, orderByComparator, false);
832    
833                            return array;
834                    }
835                    catch (Exception e) {
836                            throw processException(e);
837                    }
838                    finally {
839                            closeSession(session);
840                    }
841            }
842    
843            protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
844                    long groupId, long categoryId, OrderByComparator orderByComparator,
845                    boolean previous) {
846                    StringBundler query = null;
847    
848                    if (orderByComparator != null) {
849                            query = new StringBundler(6 +
850                                            (orderByComparator.getOrderByFields().length * 6));
851                    }
852                    else {
853                            query = new StringBundler(3);
854                    }
855    
856                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
857    
858                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
859    
860                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
861    
862                    if (orderByComparator != null) {
863                            String[] orderByFields = orderByComparator.getOrderByFields();
864    
865                            if (orderByFields.length > 0) {
866                                    query.append(WHERE_AND);
867                            }
868    
869                            for (int i = 0; i < orderByFields.length; i++) {
870                                    query.append(_ORDER_BY_ENTITY_ALIAS);
871                                    query.append(orderByFields[i]);
872    
873                                    if ((i + 1) < orderByFields.length) {
874                                            if (orderByComparator.isAscending() ^ previous) {
875                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
876                                            }
877                                            else {
878                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
879                                            }
880                                    }
881                                    else {
882                                            if (orderByComparator.isAscending() ^ previous) {
883                                                    query.append(WHERE_GREATER_THAN);
884                                            }
885                                            else {
886                                                    query.append(WHERE_LESSER_THAN);
887                                            }
888                                    }
889                            }
890    
891                            query.append(ORDER_BY_CLAUSE);
892    
893                            for (int i = 0; i < orderByFields.length; i++) {
894                                    query.append(_ORDER_BY_ENTITY_ALIAS);
895                                    query.append(orderByFields[i]);
896    
897                                    if ((i + 1) < orderByFields.length) {
898                                            if (orderByComparator.isAscending() ^ previous) {
899                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
900                                            }
901                                            else {
902                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
903                                            }
904                                    }
905                                    else {
906                                            if (orderByComparator.isAscending() ^ previous) {
907                                                    query.append(ORDER_BY_ASC);
908                                            }
909                                            else {
910                                                    query.append(ORDER_BY_DESC);
911                                            }
912                                    }
913                            }
914                    }
915    
916                    else {
917                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
918                    }
919    
920                    String sql = query.toString();
921    
922                    Query q = session.createQuery(sql);
923    
924                    q.setFirstResult(0);
925                    q.setMaxResults(2);
926    
927                    QueryPos qPos = QueryPos.getInstance(q);
928    
929                    qPos.add(groupId);
930    
931                    qPos.add(categoryId);
932    
933                    if (orderByComparator != null) {
934                            Object[] values = orderByComparator.getOrderByValues(mbThread);
935    
936                            for (Object value : values) {
937                                    qPos.add(value);
938                            }
939                    }
940    
941                    List<MBThread> list = q.list();
942    
943                    if (list.size() == 2) {
944                            return list.get(1);
945                    }
946                    else {
947                            return null;
948                    }
949            }
950    
951            public List<MBThread> findByG_C(long groupId, long[] categoryIds)
952                    throws SystemException {
953                    return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
954                            QueryUtil.ALL_POS, null);
955            }
956    
957            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
958                    int start, int end) throws SystemException {
959                    return findByG_C(groupId, categoryIds, start, end, null);
960            }
961    
962            public List<MBThread> findByG_C(long groupId, long[] categoryIds,
963                    int start, int end, OrderByComparator orderByComparator)
964                    throws SystemException {
965                    Object[] finderArgs = new Object[] {
966                                    groupId, StringUtil.merge(categoryIds),
967                                    
968                                    String.valueOf(start), String.valueOf(end),
969                                    String.valueOf(orderByComparator)
970                            };
971    
972                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
973                                    finderArgs, this);
974    
975                    if (list == null) {
976                            Session session = null;
977    
978                            try {
979                                    session = openSession();
980    
981                                    StringBundler query = new StringBundler();
982    
983                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
984    
985                                    boolean conjunctionable = false;
986    
987                                    if (conjunctionable) {
988                                            query.append(WHERE_AND);
989                                    }
990    
991                                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
992    
993                                    conjunctionable = true;
994    
995                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
996                                            if (conjunctionable) {
997                                                    query.append(WHERE_AND);
998                                            }
999    
1000                                            query.append(StringPool.OPEN_PARENTHESIS);
1001    
1002                                            for (int i = 0; i < categoryIds.length; i++) {
1003                                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
1004    
1005                                                    if ((i + 1) < categoryIds.length) {
1006                                                            query.append(WHERE_OR);
1007                                                    }
1008                                            }
1009    
1010                                            query.append(StringPool.CLOSE_PARENTHESIS);
1011    
1012                                            conjunctionable = true;
1013                                    }
1014    
1015                                    if (orderByComparator != null) {
1016                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1017                                                    orderByComparator);
1018                                    }
1019    
1020                                    else {
1021                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1022                                    }
1023    
1024                                    String sql = query.toString();
1025    
1026                                    Query q = session.createQuery(sql);
1027    
1028                                    QueryPos qPos = QueryPos.getInstance(q);
1029    
1030                                    qPos.add(groupId);
1031    
1032                                    if (categoryIds != null) {
1033                                            qPos.add(categoryIds);
1034                                    }
1035    
1036                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1037                                                    end);
1038                            }
1039                            catch (Exception e) {
1040                                    throw processException(e);
1041                            }
1042                            finally {
1043                                    if (list == null) {
1044                                            list = new ArrayList<MBThread>();
1045                                    }
1046    
1047                                    cacheResult(list);
1048    
1049                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
1050                                            list);
1051    
1052                                    closeSession(session);
1053                            }
1054                    }
1055    
1056                    return list;
1057            }
1058    
1059            public List<MBThread> findByG_NotC(long groupId, long categoryId)
1060                    throws SystemException {
1061                    return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
1062                            QueryUtil.ALL_POS, null);
1063            }
1064    
1065            public List<MBThread> findByG_NotC(long groupId, long categoryId,
1066                    int start, int end) throws SystemException {
1067                    return findByG_NotC(groupId, categoryId, start, end, null);
1068            }
1069    
1070            public List<MBThread> findByG_NotC(long groupId, long categoryId,
1071                    int start, int end, OrderByComparator orderByComparator)
1072                    throws SystemException {
1073                    Object[] finderArgs = new Object[] {
1074                                    groupId, categoryId,
1075                                    
1076                                    String.valueOf(start), String.valueOf(end),
1077                                    String.valueOf(orderByComparator)
1078                            };
1079    
1080                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTC,
1081                                    finderArgs, this);
1082    
1083                    if (list == null) {
1084                            Session session = null;
1085    
1086                            try {
1087                                    session = openSession();
1088    
1089                                    StringBundler query = null;
1090    
1091                                    if (orderByComparator != null) {
1092                                            query = new StringBundler(4 +
1093                                                            (orderByComparator.getOrderByFields().length * 3));
1094                                    }
1095                                    else {
1096                                            query = new StringBundler(4);
1097                                    }
1098    
1099                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1100    
1101                                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
1102    
1103                                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
1104    
1105                                    if (orderByComparator != null) {
1106                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1107                                                    orderByComparator);
1108                                    }
1109    
1110                                    else {
1111                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1112                                    }
1113    
1114                                    String sql = query.toString();
1115    
1116                                    Query q = session.createQuery(sql);
1117    
1118                                    QueryPos qPos = QueryPos.getInstance(q);
1119    
1120                                    qPos.add(groupId);
1121    
1122                                    qPos.add(categoryId);
1123    
1124                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1125                                                    end);
1126                            }
1127                            catch (Exception e) {
1128                                    throw processException(e);
1129                            }
1130                            finally {
1131                                    if (list == null) {
1132                                            list = new ArrayList<MBThread>();
1133                                    }
1134    
1135                                    cacheResult(list);
1136    
1137                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTC,
1138                                            finderArgs, list);
1139    
1140                                    closeSession(session);
1141                            }
1142                    }
1143    
1144                    return list;
1145            }
1146    
1147            public MBThread findByG_NotC_First(long groupId, long categoryId,
1148                    OrderByComparator orderByComparator)
1149                    throws NoSuchThreadException, SystemException {
1150                    List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
1151                                    orderByComparator);
1152    
1153                    if (list.isEmpty()) {
1154                            StringBundler msg = new StringBundler(6);
1155    
1156                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1157    
1158                            msg.append("groupId=");
1159                            msg.append(groupId);
1160    
1161                            msg.append(", categoryId=");
1162                            msg.append(categoryId);
1163    
1164                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1165    
1166                            throw new NoSuchThreadException(msg.toString());
1167                    }
1168                    else {
1169                            return list.get(0);
1170                    }
1171            }
1172    
1173            public MBThread findByG_NotC_Last(long groupId, long categoryId,
1174                    OrderByComparator orderByComparator)
1175                    throws NoSuchThreadException, SystemException {
1176                    int count = countByG_NotC(groupId, categoryId);
1177    
1178                    List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
1179                                    count, orderByComparator);
1180    
1181                    if (list.isEmpty()) {
1182                            StringBundler msg = new StringBundler(6);
1183    
1184                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1185    
1186                            msg.append("groupId=");
1187                            msg.append(groupId);
1188    
1189                            msg.append(", categoryId=");
1190                            msg.append(categoryId);
1191    
1192                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1193    
1194                            throw new NoSuchThreadException(msg.toString());
1195                    }
1196                    else {
1197                            return list.get(0);
1198                    }
1199            }
1200    
1201            public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
1202                    long categoryId, OrderByComparator orderByComparator)
1203                    throws NoSuchThreadException, SystemException {
1204                    MBThread mbThread = findByPrimaryKey(threadId);
1205    
1206                    Session session = null;
1207    
1208                    try {
1209                            session = openSession();
1210    
1211                            MBThread[] array = new MBThreadImpl[3];
1212    
1213                            array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
1214                                            categoryId, orderByComparator, true);
1215    
1216                            array[1] = mbThread;
1217    
1218                            array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
1219                                            categoryId, orderByComparator, false);
1220    
1221                            return array;
1222                    }
1223                    catch (Exception e) {
1224                            throw processException(e);
1225                    }
1226                    finally {
1227                            closeSession(session);
1228                    }
1229            }
1230    
1231            protected MBThread getByG_NotC_PrevAndNext(Session session,
1232                    MBThread mbThread, long groupId, long categoryId,
1233                    OrderByComparator orderByComparator, boolean previous) {
1234                    StringBundler query = null;
1235    
1236                    if (orderByComparator != null) {
1237                            query = new StringBundler(6 +
1238                                            (orderByComparator.getOrderByFields().length * 6));
1239                    }
1240                    else {
1241                            query = new StringBundler(3);
1242                    }
1243    
1244                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1245    
1246                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
1247    
1248                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
1249    
1250                    if (orderByComparator != null) {
1251                            String[] orderByFields = orderByComparator.getOrderByFields();
1252    
1253                            if (orderByFields.length > 0) {
1254                                    query.append(WHERE_AND);
1255                            }
1256    
1257                            for (int i = 0; i < orderByFields.length; i++) {
1258                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1259                                    query.append(orderByFields[i]);
1260    
1261                                    if ((i + 1) < orderByFields.length) {
1262                                            if (orderByComparator.isAscending() ^ previous) {
1263                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1264                                            }
1265                                            else {
1266                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1267                                            }
1268                                    }
1269                                    else {
1270                                            if (orderByComparator.isAscending() ^ previous) {
1271                                                    query.append(WHERE_GREATER_THAN);
1272                                            }
1273                                            else {
1274                                                    query.append(WHERE_LESSER_THAN);
1275                                            }
1276                                    }
1277                            }
1278    
1279                            query.append(ORDER_BY_CLAUSE);
1280    
1281                            for (int i = 0; i < orderByFields.length; i++) {
1282                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1283                                    query.append(orderByFields[i]);
1284    
1285                                    if ((i + 1) < orderByFields.length) {
1286                                            if (orderByComparator.isAscending() ^ previous) {
1287                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1288                                            }
1289                                            else {
1290                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1291                                            }
1292                                    }
1293                                    else {
1294                                            if (orderByComparator.isAscending() ^ previous) {
1295                                                    query.append(ORDER_BY_ASC);
1296                                            }
1297                                            else {
1298                                                    query.append(ORDER_BY_DESC);
1299                                            }
1300                                    }
1301                            }
1302                    }
1303    
1304                    else {
1305                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1306                    }
1307    
1308                    String sql = query.toString();
1309    
1310                    Query q = session.createQuery(sql);
1311    
1312                    q.setFirstResult(0);
1313                    q.setMaxResults(2);
1314    
1315                    QueryPos qPos = QueryPos.getInstance(q);
1316    
1317                    qPos.add(groupId);
1318    
1319                    qPos.add(categoryId);
1320    
1321                    if (orderByComparator != null) {
1322                            Object[] values = orderByComparator.getOrderByValues(mbThread);
1323    
1324                            for (Object value : values) {
1325                                    qPos.add(value);
1326                            }
1327                    }
1328    
1329                    List<MBThread> list = q.list();
1330    
1331                    if (list.size() == 2) {
1332                            return list.get(1);
1333                    }
1334                    else {
1335                            return null;
1336                    }
1337            }
1338    
1339            public List<MBThread> findByG_S(long groupId, int status)
1340                    throws SystemException {
1341                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1342                            null);
1343            }
1344    
1345            public List<MBThread> findByG_S(long groupId, int status, int start, int end)
1346                    throws SystemException {
1347                    return findByG_S(groupId, status, start, end, null);
1348            }
1349    
1350            public List<MBThread> findByG_S(long groupId, int status, int start,
1351                    int end, OrderByComparator orderByComparator) throws SystemException {
1352                    Object[] finderArgs = new Object[] {
1353                                    groupId, status,
1354                                    
1355                                    String.valueOf(start), String.valueOf(end),
1356                                    String.valueOf(orderByComparator)
1357                            };
1358    
1359                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
1360                                    finderArgs, this);
1361    
1362                    if (list == null) {
1363                            Session session = null;
1364    
1365                            try {
1366                                    session = openSession();
1367    
1368                                    StringBundler query = null;
1369    
1370                                    if (orderByComparator != null) {
1371                                            query = new StringBundler(4 +
1372                                                            (orderByComparator.getOrderByFields().length * 3));
1373                                    }
1374                                    else {
1375                                            query = new StringBundler(4);
1376                                    }
1377    
1378                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1379    
1380                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1381    
1382                                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
1383    
1384                                    if (orderByComparator != null) {
1385                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1386                                                    orderByComparator);
1387                                    }
1388    
1389                                    else {
1390                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1391                                    }
1392    
1393                                    String sql = query.toString();
1394    
1395                                    Query q = session.createQuery(sql);
1396    
1397                                    QueryPos qPos = QueryPos.getInstance(q);
1398    
1399                                    qPos.add(groupId);
1400    
1401                                    qPos.add(status);
1402    
1403                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1404                                                    end);
1405                            }
1406                            catch (Exception e) {
1407                                    throw processException(e);
1408                            }
1409                            finally {
1410                                    if (list == null) {
1411                                            list = new ArrayList<MBThread>();
1412                                    }
1413    
1414                                    cacheResult(list);
1415    
1416                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S, finderArgs,
1417                                            list);
1418    
1419                                    closeSession(session);
1420                            }
1421                    }
1422    
1423                    return list;
1424            }
1425    
1426            public MBThread findByG_S_First(long groupId, int status,
1427                    OrderByComparator orderByComparator)
1428                    throws NoSuchThreadException, SystemException {
1429                    List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
1430    
1431                    if (list.isEmpty()) {
1432                            StringBundler msg = new StringBundler(6);
1433    
1434                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1435    
1436                            msg.append("groupId=");
1437                            msg.append(groupId);
1438    
1439                            msg.append(", status=");
1440                            msg.append(status);
1441    
1442                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1443    
1444                            throw new NoSuchThreadException(msg.toString());
1445                    }
1446                    else {
1447                            return list.get(0);
1448                    }
1449            }
1450    
1451            public MBThread findByG_S_Last(long groupId, int status,
1452                    OrderByComparator orderByComparator)
1453                    throws NoSuchThreadException, SystemException {
1454                    int count = countByG_S(groupId, status);
1455    
1456                    List<MBThread> list = findByG_S(groupId, status, count - 1, count,
1457                                    orderByComparator);
1458    
1459                    if (list.isEmpty()) {
1460                            StringBundler msg = new StringBundler(6);
1461    
1462                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1463    
1464                            msg.append("groupId=");
1465                            msg.append(groupId);
1466    
1467                            msg.append(", status=");
1468                            msg.append(status);
1469    
1470                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1471    
1472                            throw new NoSuchThreadException(msg.toString());
1473                    }
1474                    else {
1475                            return list.get(0);
1476                    }
1477            }
1478    
1479            public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
1480                    int status, OrderByComparator orderByComparator)
1481                    throws NoSuchThreadException, SystemException {
1482                    MBThread mbThread = findByPrimaryKey(threadId);
1483    
1484                    Session session = null;
1485    
1486                    try {
1487                            session = openSession();
1488    
1489                            MBThread[] array = new MBThreadImpl[3];
1490    
1491                            array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
1492                                            orderByComparator, true);
1493    
1494                            array[1] = mbThread;
1495    
1496                            array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
1497                                            orderByComparator, false);
1498    
1499                            return array;
1500                    }
1501                    catch (Exception e) {
1502                            throw processException(e);
1503                    }
1504                    finally {
1505                            closeSession(session);
1506                    }
1507            }
1508    
1509            protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
1510                    long groupId, int status, OrderByComparator orderByComparator,
1511                    boolean previous) {
1512                    StringBundler query = null;
1513    
1514                    if (orderByComparator != null) {
1515                            query = new StringBundler(6 +
1516                                            (orderByComparator.getOrderByFields().length * 6));
1517                    }
1518                    else {
1519                            query = new StringBundler(3);
1520                    }
1521    
1522                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1523    
1524                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1525    
1526                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
1527    
1528                    if (orderByComparator != null) {
1529                            String[] orderByFields = orderByComparator.getOrderByFields();
1530    
1531                            if (orderByFields.length > 0) {
1532                                    query.append(WHERE_AND);
1533                            }
1534    
1535                            for (int i = 0; i < orderByFields.length; i++) {
1536                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1537                                    query.append(orderByFields[i]);
1538    
1539                                    if ((i + 1) < orderByFields.length) {
1540                                            if (orderByComparator.isAscending() ^ previous) {
1541                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1542                                            }
1543                                            else {
1544                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1545                                            }
1546                                    }
1547                                    else {
1548                                            if (orderByComparator.isAscending() ^ previous) {
1549                                                    query.append(WHERE_GREATER_THAN);
1550                                            }
1551                                            else {
1552                                                    query.append(WHERE_LESSER_THAN);
1553                                            }
1554                                    }
1555                            }
1556    
1557                            query.append(ORDER_BY_CLAUSE);
1558    
1559                            for (int i = 0; i < orderByFields.length; i++) {
1560                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1561                                    query.append(orderByFields[i]);
1562    
1563                                    if ((i + 1) < orderByFields.length) {
1564                                            if (orderByComparator.isAscending() ^ previous) {
1565                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1566                                            }
1567                                            else {
1568                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1569                                            }
1570                                    }
1571                                    else {
1572                                            if (orderByComparator.isAscending() ^ previous) {
1573                                                    query.append(ORDER_BY_ASC);
1574                                            }
1575                                            else {
1576                                                    query.append(ORDER_BY_DESC);
1577                                            }
1578                                    }
1579                            }
1580                    }
1581    
1582                    else {
1583                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1584                    }
1585    
1586                    String sql = query.toString();
1587    
1588                    Query q = session.createQuery(sql);
1589    
1590                    q.setFirstResult(0);
1591                    q.setMaxResults(2);
1592    
1593                    QueryPos qPos = QueryPos.getInstance(q);
1594    
1595                    qPos.add(groupId);
1596    
1597                    qPos.add(status);
1598    
1599                    if (orderByComparator != null) {
1600                            Object[] values = orderByComparator.getOrderByValues(mbThread);
1601    
1602                            for (Object value : values) {
1603                                    qPos.add(value);
1604                            }
1605                    }
1606    
1607                    List<MBThread> list = q.list();
1608    
1609                    if (list.size() == 2) {
1610                            return list.get(1);
1611                    }
1612                    else {
1613                            return null;
1614                    }
1615            }
1616    
1617            public List<MBThread> findByC_P(long categoryId, double priority)
1618                    throws SystemException {
1619                    return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
1620                            QueryUtil.ALL_POS, null);
1621            }
1622    
1623            public List<MBThread> findByC_P(long categoryId, double priority,
1624                    int start, int end) throws SystemException {
1625                    return findByC_P(categoryId, priority, start, end, null);
1626            }
1627    
1628            public List<MBThread> findByC_P(long categoryId, double priority,
1629                    int start, int end, OrderByComparator orderByComparator)
1630                    throws SystemException {
1631                    Object[] finderArgs = new Object[] {
1632                                    categoryId, priority,
1633                                    
1634                                    String.valueOf(start), String.valueOf(end),
1635                                    String.valueOf(orderByComparator)
1636                            };
1637    
1638                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
1639                                    finderArgs, this);
1640    
1641                    if (list == null) {
1642                            Session session = null;
1643    
1644                            try {
1645                                    session = openSession();
1646    
1647                                    StringBundler query = null;
1648    
1649                                    if (orderByComparator != null) {
1650                                            query = new StringBundler(4 +
1651                                                            (orderByComparator.getOrderByFields().length * 3));
1652                                    }
1653                                    else {
1654                                            query = new StringBundler(4);
1655                                    }
1656    
1657                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1658    
1659                                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1660    
1661                                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1662    
1663                                    if (orderByComparator != null) {
1664                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1665                                                    orderByComparator);
1666                                    }
1667    
1668                                    else {
1669                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1670                                    }
1671    
1672                                    String sql = query.toString();
1673    
1674                                    Query q = session.createQuery(sql);
1675    
1676                                    QueryPos qPos = QueryPos.getInstance(q);
1677    
1678                                    qPos.add(categoryId);
1679    
1680                                    qPos.add(priority);
1681    
1682                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1683                                                    end);
1684                            }
1685                            catch (Exception e) {
1686                                    throw processException(e);
1687                            }
1688                            finally {
1689                                    if (list == null) {
1690                                            list = new ArrayList<MBThread>();
1691                                    }
1692    
1693                                    cacheResult(list);
1694    
1695                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
1696                                            list);
1697    
1698                                    closeSession(session);
1699                            }
1700                    }
1701    
1702                    return list;
1703            }
1704    
1705            public MBThread findByC_P_First(long categoryId, double priority,
1706                    OrderByComparator orderByComparator)
1707                    throws NoSuchThreadException, SystemException {
1708                    List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
1709                                    orderByComparator);
1710    
1711                    if (list.isEmpty()) {
1712                            StringBundler msg = new StringBundler(6);
1713    
1714                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1715    
1716                            msg.append("categoryId=");
1717                            msg.append(categoryId);
1718    
1719                            msg.append(", priority=");
1720                            msg.append(priority);
1721    
1722                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1723    
1724                            throw new NoSuchThreadException(msg.toString());
1725                    }
1726                    else {
1727                            return list.get(0);
1728                    }
1729            }
1730    
1731            public MBThread findByC_P_Last(long categoryId, double priority,
1732                    OrderByComparator orderByComparator)
1733                    throws NoSuchThreadException, SystemException {
1734                    int count = countByC_P(categoryId, priority);
1735    
1736                    List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
1737                                    orderByComparator);
1738    
1739                    if (list.isEmpty()) {
1740                            StringBundler msg = new StringBundler(6);
1741    
1742                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1743    
1744                            msg.append("categoryId=");
1745                            msg.append(categoryId);
1746    
1747                            msg.append(", priority=");
1748                            msg.append(priority);
1749    
1750                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1751    
1752                            throw new NoSuchThreadException(msg.toString());
1753                    }
1754                    else {
1755                            return list.get(0);
1756                    }
1757            }
1758    
1759            public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
1760                    double priority, OrderByComparator orderByComparator)
1761                    throws NoSuchThreadException, SystemException {
1762                    MBThread mbThread = findByPrimaryKey(threadId);
1763    
1764                    Session session = null;
1765    
1766                    try {
1767                            session = openSession();
1768    
1769                            MBThread[] array = new MBThreadImpl[3];
1770    
1771                            array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
1772                                            priority, orderByComparator, true);
1773    
1774                            array[1] = mbThread;
1775    
1776                            array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
1777                                            priority, orderByComparator, false);
1778    
1779                            return array;
1780                    }
1781                    catch (Exception e) {
1782                            throw processException(e);
1783                    }
1784                    finally {
1785                            closeSession(session);
1786                    }
1787            }
1788    
1789            protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
1790                    long categoryId, double priority, OrderByComparator orderByComparator,
1791                    boolean previous) {
1792                    StringBundler query = null;
1793    
1794                    if (orderByComparator != null) {
1795                            query = new StringBundler(6 +
1796                                            (orderByComparator.getOrderByFields().length * 6));
1797                    }
1798                    else {
1799                            query = new StringBundler(3);
1800                    }
1801    
1802                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1803    
1804                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1805    
1806                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1807    
1808                    if (orderByComparator != null) {
1809                            String[] orderByFields = orderByComparator.getOrderByFields();
1810    
1811                            if (orderByFields.length > 0) {
1812                                    query.append(WHERE_AND);
1813                            }
1814    
1815                            for (int i = 0; i < orderByFields.length; i++) {
1816                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1817                                    query.append(orderByFields[i]);
1818    
1819                                    if ((i + 1) < orderByFields.length) {
1820                                            if (orderByComparator.isAscending() ^ previous) {
1821                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1822                                            }
1823                                            else {
1824                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1825                                            }
1826                                    }
1827                                    else {
1828                                            if (orderByComparator.isAscending() ^ previous) {
1829                                                    query.append(WHERE_GREATER_THAN);
1830                                            }
1831                                            else {
1832                                                    query.append(WHERE_LESSER_THAN);
1833                                            }
1834                                    }
1835                            }
1836    
1837                            query.append(ORDER_BY_CLAUSE);
1838    
1839                            for (int i = 0; i < orderByFields.length; i++) {
1840                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1841                                    query.append(orderByFields[i]);
1842    
1843                                    if ((i + 1) < orderByFields.length) {
1844                                            if (orderByComparator.isAscending() ^ previous) {
1845                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1846                                            }
1847                                            else {
1848                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1849                                            }
1850                                    }
1851                                    else {
1852                                            if (orderByComparator.isAscending() ^ previous) {
1853                                                    query.append(ORDER_BY_ASC);
1854                                            }
1855                                            else {
1856                                                    query.append(ORDER_BY_DESC);
1857                                            }
1858                                    }
1859                            }
1860                    }
1861    
1862                    else {
1863                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1864                    }
1865    
1866                    String sql = query.toString();
1867    
1868                    Query q = session.createQuery(sql);
1869    
1870                    q.setFirstResult(0);
1871                    q.setMaxResults(2);
1872    
1873                    QueryPos qPos = QueryPos.getInstance(q);
1874    
1875                    qPos.add(categoryId);
1876    
1877                    qPos.add(priority);
1878    
1879                    if (orderByComparator != null) {
1880                            Object[] values = orderByComparator.getOrderByValues(mbThread);
1881    
1882                            for (Object value : values) {
1883                                    qPos.add(value);
1884                            }
1885                    }
1886    
1887                    List<MBThread> list = q.list();
1888    
1889                    if (list.size() == 2) {
1890                            return list.get(1);
1891                    }
1892                    else {
1893                            return null;
1894                    }
1895            }
1896    
1897            public List<MBThread> findByG_C_L(long groupId, long categoryId,
1898                    Date lastPostDate) throws SystemException {
1899                    return findByG_C_L(groupId, categoryId, lastPostDate,
1900                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1901            }
1902    
1903            public List<MBThread> findByG_C_L(long groupId, long categoryId,
1904                    Date lastPostDate, int start, int end) throws SystemException {
1905                    return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
1906            }
1907    
1908            public List<MBThread> findByG_C_L(long groupId, long categoryId,
1909                    Date lastPostDate, int start, int end,
1910                    OrderByComparator orderByComparator) throws SystemException {
1911                    Object[] finderArgs = new Object[] {
1912                                    groupId, categoryId, lastPostDate,
1913                                    
1914                                    String.valueOf(start), String.valueOf(end),
1915                                    String.valueOf(orderByComparator)
1916                            };
1917    
1918                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_L,
1919                                    finderArgs, this);
1920    
1921                    if (list == null) {
1922                            Session session = null;
1923    
1924                            try {
1925                                    session = openSession();
1926    
1927                                    StringBundler query = null;
1928    
1929                                    if (orderByComparator != null) {
1930                                            query = new StringBundler(5 +
1931                                                            (orderByComparator.getOrderByFields().length * 3));
1932                                    }
1933                                    else {
1934                                            query = new StringBundler(5);
1935                                    }
1936    
1937                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
1938    
1939                                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
1940    
1941                                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
1942    
1943                                    if (lastPostDate == null) {
1944                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
1945                                    }
1946                                    else {
1947                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
1948                                    }
1949    
1950                                    if (orderByComparator != null) {
1951                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1952                                                    orderByComparator);
1953                                    }
1954    
1955                                    else {
1956                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1957                                    }
1958    
1959                                    String sql = query.toString();
1960    
1961                                    Query q = session.createQuery(sql);
1962    
1963                                    QueryPos qPos = QueryPos.getInstance(q);
1964    
1965                                    qPos.add(groupId);
1966    
1967                                    qPos.add(categoryId);
1968    
1969                                    if (lastPostDate != null) {
1970                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
1971                                    }
1972    
1973                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1974                                                    end);
1975                            }
1976                            catch (Exception e) {
1977                                    throw processException(e);
1978                            }
1979                            finally {
1980                                    if (list == null) {
1981                                            list = new ArrayList<MBThread>();
1982                                    }
1983    
1984                                    cacheResult(list);
1985    
1986                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_L,
1987                                            finderArgs, list);
1988    
1989                                    closeSession(session);
1990                            }
1991                    }
1992    
1993                    return list;
1994            }
1995    
1996            public MBThread findByG_C_L_First(long groupId, long categoryId,
1997                    Date lastPostDate, OrderByComparator orderByComparator)
1998                    throws NoSuchThreadException, SystemException {
1999                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
2000                                    1, orderByComparator);
2001    
2002                    if (list.isEmpty()) {
2003                            StringBundler msg = new StringBundler(8);
2004    
2005                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2006    
2007                            msg.append("groupId=");
2008                            msg.append(groupId);
2009    
2010                            msg.append(", categoryId=");
2011                            msg.append(categoryId);
2012    
2013                            msg.append(", lastPostDate=");
2014                            msg.append(lastPostDate);
2015    
2016                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2017    
2018                            throw new NoSuchThreadException(msg.toString());
2019                    }
2020                    else {
2021                            return list.get(0);
2022                    }
2023            }
2024    
2025            public MBThread findByG_C_L_Last(long groupId, long categoryId,
2026                    Date lastPostDate, OrderByComparator orderByComparator)
2027                    throws NoSuchThreadException, SystemException {
2028                    int count = countByG_C_L(groupId, categoryId, lastPostDate);
2029    
2030                    List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
2031                                    count - 1, count, orderByComparator);
2032    
2033                    if (list.isEmpty()) {
2034                            StringBundler msg = new StringBundler(8);
2035    
2036                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2037    
2038                            msg.append("groupId=");
2039                            msg.append(groupId);
2040    
2041                            msg.append(", categoryId=");
2042                            msg.append(categoryId);
2043    
2044                            msg.append(", lastPostDate=");
2045                            msg.append(lastPostDate);
2046    
2047                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2048    
2049                            throw new NoSuchThreadException(msg.toString());
2050                    }
2051                    else {
2052                            return list.get(0);
2053                    }
2054            }
2055    
2056            public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
2057                    long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
2058                    throws NoSuchThreadException, SystemException {
2059                    MBThread mbThread = findByPrimaryKey(threadId);
2060    
2061                    Session session = null;
2062    
2063                    try {
2064                            session = openSession();
2065    
2066                            MBThread[] array = new MBThreadImpl[3];
2067    
2068                            array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
2069                                            categoryId, lastPostDate, orderByComparator, true);
2070    
2071                            array[1] = mbThread;
2072    
2073                            array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
2074                                            categoryId, lastPostDate, orderByComparator, false);
2075    
2076                            return array;
2077                    }
2078                    catch (Exception e) {
2079                            throw processException(e);
2080                    }
2081                    finally {
2082                            closeSession(session);
2083                    }
2084            }
2085    
2086            protected MBThread getByG_C_L_PrevAndNext(Session session,
2087                    MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
2088                    OrderByComparator orderByComparator, boolean previous) {
2089                    StringBundler query = null;
2090    
2091                    if (orderByComparator != null) {
2092                            query = new StringBundler(6 +
2093                                            (orderByComparator.getOrderByFields().length * 6));
2094                    }
2095                    else {
2096                            query = new StringBundler(3);
2097                    }
2098    
2099                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2100    
2101                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
2102    
2103                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
2104    
2105                    if (lastPostDate == null) {
2106                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
2107                    }
2108                    else {
2109                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
2110                    }
2111    
2112                    if (orderByComparator != null) {
2113                            String[] orderByFields = orderByComparator.getOrderByFields();
2114    
2115                            if (orderByFields.length > 0) {
2116                                    query.append(WHERE_AND);
2117                            }
2118    
2119                            for (int i = 0; i < orderByFields.length; i++) {
2120                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2121                                    query.append(orderByFields[i]);
2122    
2123                                    if ((i + 1) < orderByFields.length) {
2124                                            if (orderByComparator.isAscending() ^ previous) {
2125                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2126                                            }
2127                                            else {
2128                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2129                                            }
2130                                    }
2131                                    else {
2132                                            if (orderByComparator.isAscending() ^ previous) {
2133                                                    query.append(WHERE_GREATER_THAN);
2134                                            }
2135                                            else {
2136                                                    query.append(WHERE_LESSER_THAN);
2137                                            }
2138                                    }
2139                            }
2140    
2141                            query.append(ORDER_BY_CLAUSE);
2142    
2143                            for (int i = 0; i < orderByFields.length; i++) {
2144                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2145                                    query.append(orderByFields[i]);
2146    
2147                                    if ((i + 1) < orderByFields.length) {
2148                                            if (orderByComparator.isAscending() ^ previous) {
2149                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2150                                            }
2151                                            else {
2152                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2153                                            }
2154                                    }
2155                                    else {
2156                                            if (orderByComparator.isAscending() ^ previous) {
2157                                                    query.append(ORDER_BY_ASC);
2158                                            }
2159                                            else {
2160                                                    query.append(ORDER_BY_DESC);
2161                                            }
2162                                    }
2163                            }
2164                    }
2165    
2166                    else {
2167                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2168                    }
2169    
2170                    String sql = query.toString();
2171    
2172                    Query q = session.createQuery(sql);
2173    
2174                    q.setFirstResult(0);
2175                    q.setMaxResults(2);
2176    
2177                    QueryPos qPos = QueryPos.getInstance(q);
2178    
2179                    qPos.add(groupId);
2180    
2181                    qPos.add(categoryId);
2182    
2183                    if (lastPostDate != null) {
2184                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
2185                    }
2186    
2187                    if (orderByComparator != null) {
2188                            Object[] values = orderByComparator.getOrderByValues(mbThread);
2189    
2190                            for (Object value : values) {
2191                                    qPos.add(value);
2192                            }
2193                    }
2194    
2195                    List<MBThread> list = q.list();
2196    
2197                    if (list.size() == 2) {
2198                            return list.get(1);
2199                    }
2200                    else {
2201                            return null;
2202                    }
2203            }
2204    
2205            public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
2206                    throws SystemException {
2207                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
2208                            QueryUtil.ALL_POS, null);
2209            }
2210    
2211            public List<MBThread> findByG_C_S(long groupId, long categoryId,
2212                    int status, int start, int end) throws SystemException {
2213                    return findByG_C_S(groupId, categoryId, status, start, end, null);
2214            }
2215    
2216            public List<MBThread> findByG_C_S(long groupId, long categoryId,
2217                    int status, int start, int end, OrderByComparator orderByComparator)
2218                    throws SystemException {
2219                    Object[] finderArgs = new Object[] {
2220                                    groupId, categoryId, status,
2221                                    
2222                                    String.valueOf(start), String.valueOf(end),
2223                                    String.valueOf(orderByComparator)
2224                            };
2225    
2226                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
2227                                    finderArgs, this);
2228    
2229                    if (list == null) {
2230                            Session session = null;
2231    
2232                            try {
2233                                    session = openSession();
2234    
2235                                    StringBundler query = null;
2236    
2237                                    if (orderByComparator != null) {
2238                                            query = new StringBundler(5 +
2239                                                            (orderByComparator.getOrderByFields().length * 3));
2240                                    }
2241                                    else {
2242                                            query = new StringBundler(5);
2243                                    }
2244    
2245                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2246    
2247                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
2248    
2249                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
2250    
2251                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
2252    
2253                                    if (orderByComparator != null) {
2254                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2255                                                    orderByComparator);
2256                                    }
2257    
2258                                    else {
2259                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2260                                    }
2261    
2262                                    String sql = query.toString();
2263    
2264                                    Query q = session.createQuery(sql);
2265    
2266                                    QueryPos qPos = QueryPos.getInstance(q);
2267    
2268                                    qPos.add(groupId);
2269    
2270                                    qPos.add(categoryId);
2271    
2272                                    qPos.add(status);
2273    
2274                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2275                                                    end);
2276                            }
2277                            catch (Exception e) {
2278                                    throw processException(e);
2279                            }
2280                            finally {
2281                                    if (list == null) {
2282                                            list = new ArrayList<MBThread>();
2283                                    }
2284    
2285                                    cacheResult(list);
2286    
2287                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
2288                                            finderArgs, list);
2289    
2290                                    closeSession(session);
2291                            }
2292                    }
2293    
2294                    return list;
2295            }
2296    
2297            public MBThread findByG_C_S_First(long groupId, long categoryId,
2298                    int status, OrderByComparator orderByComparator)
2299                    throws NoSuchThreadException, SystemException {
2300                    List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
2301                                    orderByComparator);
2302    
2303                    if (list.isEmpty()) {
2304                            StringBundler msg = new StringBundler(8);
2305    
2306                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2307    
2308                            msg.append("groupId=");
2309                            msg.append(groupId);
2310    
2311                            msg.append(", categoryId=");
2312                            msg.append(categoryId);
2313    
2314                            msg.append(", status=");
2315                            msg.append(status);
2316    
2317                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2318    
2319                            throw new NoSuchThreadException(msg.toString());
2320                    }
2321                    else {
2322                            return list.get(0);
2323                    }
2324            }
2325    
2326            public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
2327                    OrderByComparator orderByComparator)
2328                    throws NoSuchThreadException, SystemException {
2329                    int count = countByG_C_S(groupId, categoryId, status);
2330    
2331                    List<MBThread> list = findByG_C_S(groupId, categoryId, status,
2332                                    count - 1, count, orderByComparator);
2333    
2334                    if (list.isEmpty()) {
2335                            StringBundler msg = new StringBundler(8);
2336    
2337                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2338    
2339                            msg.append("groupId=");
2340                            msg.append(groupId);
2341    
2342                            msg.append(", categoryId=");
2343                            msg.append(categoryId);
2344    
2345                            msg.append(", status=");
2346                            msg.append(status);
2347    
2348                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2349    
2350                            throw new NoSuchThreadException(msg.toString());
2351                    }
2352                    else {
2353                            return list.get(0);
2354                    }
2355            }
2356    
2357            public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
2358                    long categoryId, int status, OrderByComparator orderByComparator)
2359                    throws NoSuchThreadException, SystemException {
2360                    MBThread mbThread = findByPrimaryKey(threadId);
2361    
2362                    Session session = null;
2363    
2364                    try {
2365                            session = openSession();
2366    
2367                            MBThread[] array = new MBThreadImpl[3];
2368    
2369                            array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
2370                                            categoryId, status, orderByComparator, true);
2371    
2372                            array[1] = mbThread;
2373    
2374                            array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
2375                                            categoryId, status, orderByComparator, false);
2376    
2377                            return array;
2378                    }
2379                    catch (Exception e) {
2380                            throw processException(e);
2381                    }
2382                    finally {
2383                            closeSession(session);
2384                    }
2385            }
2386    
2387            protected MBThread getByG_C_S_PrevAndNext(Session session,
2388                    MBThread mbThread, long groupId, long categoryId, int status,
2389                    OrderByComparator orderByComparator, boolean previous) {
2390                    StringBundler query = null;
2391    
2392                    if (orderByComparator != null) {
2393                            query = new StringBundler(6 +
2394                                            (orderByComparator.getOrderByFields().length * 6));
2395                    }
2396                    else {
2397                            query = new StringBundler(3);
2398                    }
2399    
2400                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2401    
2402                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
2403    
2404                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
2405    
2406                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
2407    
2408                    if (orderByComparator != null) {
2409                            String[] orderByFields = orderByComparator.getOrderByFields();
2410    
2411                            if (orderByFields.length > 0) {
2412                                    query.append(WHERE_AND);
2413                            }
2414    
2415                            for (int i = 0; i < orderByFields.length; i++) {
2416                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2417                                    query.append(orderByFields[i]);
2418    
2419                                    if ((i + 1) < orderByFields.length) {
2420                                            if (orderByComparator.isAscending() ^ previous) {
2421                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2422                                            }
2423                                            else {
2424                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2425                                            }
2426                                    }
2427                                    else {
2428                                            if (orderByComparator.isAscending() ^ previous) {
2429                                                    query.append(WHERE_GREATER_THAN);
2430                                            }
2431                                            else {
2432                                                    query.append(WHERE_LESSER_THAN);
2433                                            }
2434                                    }
2435                            }
2436    
2437                            query.append(ORDER_BY_CLAUSE);
2438    
2439                            for (int i = 0; i < orderByFields.length; i++) {
2440                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2441                                    query.append(orderByFields[i]);
2442    
2443                                    if ((i + 1) < orderByFields.length) {
2444                                            if (orderByComparator.isAscending() ^ previous) {
2445                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2446                                            }
2447                                            else {
2448                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2449                                            }
2450                                    }
2451                                    else {
2452                                            if (orderByComparator.isAscending() ^ previous) {
2453                                                    query.append(ORDER_BY_ASC);
2454                                            }
2455                                            else {
2456                                                    query.append(ORDER_BY_DESC);
2457                                            }
2458                                    }
2459                            }
2460                    }
2461    
2462                    else {
2463                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2464                    }
2465    
2466                    String sql = query.toString();
2467    
2468                    Query q = session.createQuery(sql);
2469    
2470                    q.setFirstResult(0);
2471                    q.setMaxResults(2);
2472    
2473                    QueryPos qPos = QueryPos.getInstance(q);
2474    
2475                    qPos.add(groupId);
2476    
2477                    qPos.add(categoryId);
2478    
2479                    qPos.add(status);
2480    
2481                    if (orderByComparator != null) {
2482                            Object[] values = orderByComparator.getOrderByValues(mbThread);
2483    
2484                            for (Object value : values) {
2485                                    qPos.add(value);
2486                            }
2487                    }
2488    
2489                    List<MBThread> list = q.list();
2490    
2491                    if (list.size() == 2) {
2492                            return list.get(1);
2493                    }
2494                    else {
2495                            return null;
2496                    }
2497            }
2498    
2499            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
2500                    int status) throws SystemException {
2501                    return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
2502                            QueryUtil.ALL_POS, null);
2503            }
2504    
2505            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
2506                    int status, int start, int end) throws SystemException {
2507                    return findByG_C_S(groupId, categoryIds, status, start, end, null);
2508            }
2509    
2510            public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
2511                    int status, int start, int end, OrderByComparator orderByComparator)
2512                    throws SystemException {
2513                    Object[] finderArgs = new Object[] {
2514                                    groupId, StringUtil.merge(categoryIds), status,
2515                                    
2516                                    String.valueOf(start), String.valueOf(end),
2517                                    String.valueOf(orderByComparator)
2518                            };
2519    
2520                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
2521                                    finderArgs, this);
2522    
2523                    if (list == null) {
2524                            Session session = null;
2525    
2526                            try {
2527                                    session = openSession();
2528    
2529                                    StringBundler query = new StringBundler();
2530    
2531                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2532    
2533                                    boolean conjunctionable = false;
2534    
2535                                    if (conjunctionable) {
2536                                            query.append(WHERE_AND);
2537                                    }
2538    
2539                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
2540    
2541                                    conjunctionable = true;
2542    
2543                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
2544                                            if (conjunctionable) {
2545                                                    query.append(WHERE_AND);
2546                                            }
2547    
2548                                            query.append(StringPool.OPEN_PARENTHESIS);
2549    
2550                                            for (int i = 0; i < categoryIds.length; i++) {
2551                                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
2552    
2553                                                    if ((i + 1) < categoryIds.length) {
2554                                                            query.append(WHERE_OR);
2555                                                    }
2556                                            }
2557    
2558                                            query.append(StringPool.CLOSE_PARENTHESIS);
2559    
2560                                            conjunctionable = true;
2561                                    }
2562    
2563                                    if (conjunctionable) {
2564                                            query.append(WHERE_AND);
2565                                    }
2566    
2567                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
2568    
2569                                    conjunctionable = true;
2570    
2571                                    if (orderByComparator != null) {
2572                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2573                                                    orderByComparator);
2574                                    }
2575    
2576                                    else {
2577                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2578                                    }
2579    
2580                                    String sql = query.toString();
2581    
2582                                    Query q = session.createQuery(sql);
2583    
2584                                    QueryPos qPos = QueryPos.getInstance(q);
2585    
2586                                    qPos.add(groupId);
2587    
2588                                    if (categoryIds != null) {
2589                                            qPos.add(categoryIds);
2590                                    }
2591    
2592                                    qPos.add(status);
2593    
2594                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2595                                                    end);
2596                            }
2597                            catch (Exception e) {
2598                                    throw processException(e);
2599                            }
2600                            finally {
2601                                    if (list == null) {
2602                                            list = new ArrayList<MBThread>();
2603                                    }
2604    
2605                                    cacheResult(list);
2606    
2607                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
2608                                            finderArgs, list);
2609    
2610                                    closeSession(session);
2611                            }
2612                    }
2613    
2614                    return list;
2615            }
2616    
2617            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
2618                    int status) throws SystemException {
2619                    return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
2620                            QueryUtil.ALL_POS, null);
2621            }
2622    
2623            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
2624                    int status, int start, int end) throws SystemException {
2625                    return findByG_NotC_S(groupId, categoryId, status, start, end, null);
2626            }
2627    
2628            public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
2629                    int status, int start, int end, OrderByComparator orderByComparator)
2630                    throws SystemException {
2631                    Object[] finderArgs = new Object[] {
2632                                    groupId, categoryId, status,
2633                                    
2634                                    String.valueOf(start), String.valueOf(end),
2635                                    String.valueOf(orderByComparator)
2636                            };
2637    
2638                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTC_S,
2639                                    finderArgs, this);
2640    
2641                    if (list == null) {
2642                            Session session = null;
2643    
2644                            try {
2645                                    session = openSession();
2646    
2647                                    StringBundler query = null;
2648    
2649                                    if (orderByComparator != null) {
2650                                            query = new StringBundler(5 +
2651                                                            (orderByComparator.getOrderByFields().length * 3));
2652                                    }
2653                                    else {
2654                                            query = new StringBundler(5);
2655                                    }
2656    
2657                                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2658    
2659                                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
2660    
2661                                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
2662    
2663                                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
2664    
2665                                    if (orderByComparator != null) {
2666                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2667                                                    orderByComparator);
2668                                    }
2669    
2670                                    else {
2671                                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2672                                    }
2673    
2674                                    String sql = query.toString();
2675    
2676                                    Query q = session.createQuery(sql);
2677    
2678                                    QueryPos qPos = QueryPos.getInstance(q);
2679    
2680                                    qPos.add(groupId);
2681    
2682                                    qPos.add(categoryId);
2683    
2684                                    qPos.add(status);
2685    
2686                                    list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
2687                                                    end);
2688                            }
2689                            catch (Exception e) {
2690                                    throw processException(e);
2691                            }
2692                            finally {
2693                                    if (list == null) {
2694                                            list = new ArrayList<MBThread>();
2695                                    }
2696    
2697                                    cacheResult(list);
2698    
2699                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTC_S,
2700                                            finderArgs, list);
2701    
2702                                    closeSession(session);
2703                            }
2704                    }
2705    
2706                    return list;
2707            }
2708    
2709            public MBThread findByG_NotC_S_First(long groupId, long categoryId,
2710                    int status, OrderByComparator orderByComparator)
2711                    throws NoSuchThreadException, SystemException {
2712                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
2713                                    orderByComparator);
2714    
2715                    if (list.isEmpty()) {
2716                            StringBundler msg = new StringBundler(8);
2717    
2718                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2719    
2720                            msg.append("groupId=");
2721                            msg.append(groupId);
2722    
2723                            msg.append(", categoryId=");
2724                            msg.append(categoryId);
2725    
2726                            msg.append(", status=");
2727                            msg.append(status);
2728    
2729                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2730    
2731                            throw new NoSuchThreadException(msg.toString());
2732                    }
2733                    else {
2734                            return list.get(0);
2735                    }
2736            }
2737    
2738            public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
2739                    int status, OrderByComparator orderByComparator)
2740                    throws NoSuchThreadException, SystemException {
2741                    int count = countByG_NotC_S(groupId, categoryId, status);
2742    
2743                    List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
2744                                    count - 1, count, orderByComparator);
2745    
2746                    if (list.isEmpty()) {
2747                            StringBundler msg = new StringBundler(8);
2748    
2749                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2750    
2751                            msg.append("groupId=");
2752                            msg.append(groupId);
2753    
2754                            msg.append(", categoryId=");
2755                            msg.append(categoryId);
2756    
2757                            msg.append(", status=");
2758                            msg.append(status);
2759    
2760                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2761    
2762                            throw new NoSuchThreadException(msg.toString());
2763                    }
2764                    else {
2765                            return list.get(0);
2766                    }
2767            }
2768    
2769            public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
2770                    long categoryId, int status, OrderByComparator orderByComparator)
2771                    throws NoSuchThreadException, SystemException {
2772                    MBThread mbThread = findByPrimaryKey(threadId);
2773    
2774                    Session session = null;
2775    
2776                    try {
2777                            session = openSession();
2778    
2779                            MBThread[] array = new MBThreadImpl[3];
2780    
2781                            array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
2782                                            categoryId, status, orderByComparator, true);
2783    
2784                            array[1] = mbThread;
2785    
2786                            array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
2787                                            categoryId, status, orderByComparator, false);
2788    
2789                            return array;
2790                    }
2791                    catch (Exception e) {
2792                            throw processException(e);
2793                    }
2794                    finally {
2795                            closeSession(session);
2796                    }
2797            }
2798    
2799            protected MBThread getByG_NotC_S_PrevAndNext(Session session,
2800                    MBThread mbThread, long groupId, long categoryId, int status,
2801                    OrderByComparator orderByComparator, boolean previous) {
2802                    StringBundler query = null;
2803    
2804                    if (orderByComparator != null) {
2805                            query = new StringBundler(6 +
2806                                            (orderByComparator.getOrderByFields().length * 6));
2807                    }
2808                    else {
2809                            query = new StringBundler(3);
2810                    }
2811    
2812                    query.append(_SQL_SELECT_MBTHREAD_WHERE);
2813    
2814                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
2815    
2816                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
2817    
2818                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
2819    
2820                    if (orderByComparator != null) {
2821                            String[] orderByFields = orderByComparator.getOrderByFields();
2822    
2823                            if (orderByFields.length > 0) {
2824                                    query.append(WHERE_AND);
2825                            }
2826    
2827                            for (int i = 0; i < orderByFields.length; i++) {
2828                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2829                                    query.append(orderByFields[i]);
2830    
2831                                    if ((i + 1) < orderByFields.length) {
2832                                            if (orderByComparator.isAscending() ^ previous) {
2833                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2834                                            }
2835                                            else {
2836                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2837                                            }
2838                                    }
2839                                    else {
2840                                            if (orderByComparator.isAscending() ^ previous) {
2841                                                    query.append(WHERE_GREATER_THAN);
2842                                            }
2843                                            else {
2844                                                    query.append(WHERE_LESSER_THAN);
2845                                            }
2846                                    }
2847                            }
2848    
2849                            query.append(ORDER_BY_CLAUSE);
2850    
2851                            for (int i = 0; i < orderByFields.length; i++) {
2852                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2853                                    query.append(orderByFields[i]);
2854    
2855                                    if ((i + 1) < orderByFields.length) {
2856                                            if (orderByComparator.isAscending() ^ previous) {
2857                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2858                                            }
2859                                            else {
2860                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2861                                            }
2862                                    }
2863                                    else {
2864                                            if (orderByComparator.isAscending() ^ previous) {
2865                                                    query.append(ORDER_BY_ASC);
2866                                            }
2867                                            else {
2868                                                    query.append(ORDER_BY_DESC);
2869                                            }
2870                                    }
2871                            }
2872                    }
2873    
2874                    else {
2875                            query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2876                    }
2877    
2878                    String sql = query.toString();
2879    
2880                    Query q = session.createQuery(sql);
2881    
2882                    q.setFirstResult(0);
2883                    q.setMaxResults(2);
2884    
2885                    QueryPos qPos = QueryPos.getInstance(q);
2886    
2887                    qPos.add(groupId);
2888    
2889                    qPos.add(categoryId);
2890    
2891                    qPos.add(status);
2892    
2893                    if (orderByComparator != null) {
2894                            Object[] values = orderByComparator.getOrderByValues(mbThread);
2895    
2896                            for (Object value : values) {
2897                                    qPos.add(value);
2898                            }
2899                    }
2900    
2901                    List<MBThread> list = q.list();
2902    
2903                    if (list.size() == 2) {
2904                            return list.get(1);
2905                    }
2906                    else {
2907                            return null;
2908                    }
2909            }
2910    
2911            public List<MBThread> findAll() throws SystemException {
2912                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2913            }
2914    
2915            public List<MBThread> findAll(int start, int end) throws SystemException {
2916                    return findAll(start, end, null);
2917            }
2918    
2919            public List<MBThread> findAll(int start, int end,
2920                    OrderByComparator orderByComparator) throws SystemException {
2921                    Object[] finderArgs = new Object[] {
2922                                    String.valueOf(start), String.valueOf(end),
2923                                    String.valueOf(orderByComparator)
2924                            };
2925    
2926                    List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2927                                    finderArgs, this);
2928    
2929                    if (list == null) {
2930                            Session session = null;
2931    
2932                            try {
2933                                    session = openSession();
2934    
2935                                    StringBundler query = null;
2936                                    String sql = null;
2937    
2938                                    if (orderByComparator != null) {
2939                                            query = new StringBundler(2 +
2940                                                            (orderByComparator.getOrderByFields().length * 3));
2941    
2942                                            query.append(_SQL_SELECT_MBTHREAD);
2943    
2944                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2945                                                    orderByComparator);
2946    
2947                                            sql = query.toString();
2948                                    }
2949                                    else {
2950                                            sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
2951                                    }
2952    
2953                                    Query q = session.createQuery(sql);
2954    
2955                                    if (orderByComparator == null) {
2956                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2957                                                            start, end, false);
2958    
2959                                            Collections.sort(list);
2960                                    }
2961                                    else {
2962                                            list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2963                                                            start, end);
2964                                    }
2965                            }
2966                            catch (Exception e) {
2967                                    throw processException(e);
2968                            }
2969                            finally {
2970                                    if (list == null) {
2971                                            list = new ArrayList<MBThread>();
2972                                    }
2973    
2974                                    cacheResult(list);
2975    
2976                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2977    
2978                                    closeSession(session);
2979                            }
2980                    }
2981    
2982                    return list;
2983            }
2984    
2985            public void removeByGroupId(long groupId) throws SystemException {
2986                    for (MBThread mbThread : findByGroupId(groupId)) {
2987                            remove(mbThread);
2988                    }
2989            }
2990    
2991            public void removeByG_C(long groupId, long categoryId)
2992                    throws SystemException {
2993                    for (MBThread mbThread : findByG_C(groupId, categoryId)) {
2994                            remove(mbThread);
2995                    }
2996            }
2997    
2998            public void removeByG_NotC(long groupId, long categoryId)
2999                    throws SystemException {
3000                    for (MBThread mbThread : findByG_NotC(groupId, categoryId)) {
3001                            remove(mbThread);
3002                    }
3003            }
3004    
3005            public void removeByG_S(long groupId, int status) throws SystemException {
3006                    for (MBThread mbThread : findByG_S(groupId, status)) {
3007                            remove(mbThread);
3008                    }
3009            }
3010    
3011            public void removeByC_P(long categoryId, double priority)
3012                    throws SystemException {
3013                    for (MBThread mbThread : findByC_P(categoryId, priority)) {
3014                            remove(mbThread);
3015                    }
3016            }
3017    
3018            public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
3019                    throws SystemException {
3020                    for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate)) {
3021                            remove(mbThread);
3022                    }
3023            }
3024    
3025            public void removeByG_C_S(long groupId, long categoryId, int status)
3026                    throws SystemException {
3027                    for (MBThread mbThread : findByG_C_S(groupId, categoryId, status)) {
3028                            remove(mbThread);
3029                    }
3030            }
3031    
3032            public void removeByG_NotC_S(long groupId, long categoryId, int status)
3033                    throws SystemException {
3034                    for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status)) {
3035                            remove(mbThread);
3036                    }
3037            }
3038    
3039            public void removeAll() throws SystemException {
3040                    for (MBThread mbThread : findAll()) {
3041                            remove(mbThread);
3042                    }
3043            }
3044    
3045            public int countByGroupId(long groupId) throws SystemException {
3046                    Object[] finderArgs = new Object[] { groupId };
3047    
3048                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3049                                    finderArgs, this);
3050    
3051                    if (count == null) {
3052                            Session session = null;
3053    
3054                            try {
3055                                    session = openSession();
3056    
3057                                    StringBundler query = new StringBundler(2);
3058    
3059                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3060    
3061                                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3062    
3063                                    String sql = query.toString();
3064    
3065                                    Query q = session.createQuery(sql);
3066    
3067                                    QueryPos qPos = QueryPos.getInstance(q);
3068    
3069                                    qPos.add(groupId);
3070    
3071                                    count = (Long)q.uniqueResult();
3072                            }
3073                            catch (Exception e) {
3074                                    throw processException(e);
3075                            }
3076                            finally {
3077                                    if (count == null) {
3078                                            count = Long.valueOf(0);
3079                                    }
3080    
3081                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3082                                            finderArgs, count);
3083    
3084                                    closeSession(session);
3085                            }
3086                    }
3087    
3088                    return count.intValue();
3089            }
3090    
3091            public int countByG_C(long groupId, long categoryId)
3092                    throws SystemException {
3093                    Object[] finderArgs = new Object[] { groupId, categoryId };
3094    
3095                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
3096                                    finderArgs, this);
3097    
3098                    if (count == null) {
3099                            Session session = null;
3100    
3101                            try {
3102                                    session = openSession();
3103    
3104                                    StringBundler query = new StringBundler(3);
3105    
3106                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3107    
3108                                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3109    
3110                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3111    
3112                                    String sql = query.toString();
3113    
3114                                    Query q = session.createQuery(sql);
3115    
3116                                    QueryPos qPos = QueryPos.getInstance(q);
3117    
3118                                    qPos.add(groupId);
3119    
3120                                    qPos.add(categoryId);
3121    
3122                                    count = (Long)q.uniqueResult();
3123                            }
3124                            catch (Exception e) {
3125                                    throw processException(e);
3126                            }
3127                            finally {
3128                                    if (count == null) {
3129                                            count = Long.valueOf(0);
3130                                    }
3131    
3132                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
3133                                            count);
3134    
3135                                    closeSession(session);
3136                            }
3137                    }
3138    
3139                    return count.intValue();
3140            }
3141    
3142            public int countByG_C(long groupId, long[] categoryIds)
3143                    throws SystemException {
3144                    Object[] finderArgs = new Object[] {
3145                                    groupId, StringUtil.merge(categoryIds)
3146                            };
3147    
3148                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
3149                                    finderArgs, this);
3150    
3151                    if (count == null) {
3152                            Session session = null;
3153    
3154                            try {
3155                                    session = openSession();
3156    
3157                                    StringBundler query = new StringBundler();
3158    
3159                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3160    
3161                                    boolean conjunctionable = false;
3162    
3163                                    if (conjunctionable) {
3164                                            query.append(WHERE_AND);
3165                                    }
3166    
3167                                    query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3168    
3169                                    conjunctionable = true;
3170    
3171                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
3172                                            if (conjunctionable) {
3173                                                    query.append(WHERE_AND);
3174                                            }
3175    
3176                                            query.append(StringPool.OPEN_PARENTHESIS);
3177    
3178                                            for (int i = 0; i < categoryIds.length; i++) {
3179                                                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3180    
3181                                                    if ((i + 1) < categoryIds.length) {
3182                                                            query.append(WHERE_OR);
3183                                                    }
3184                                            }
3185    
3186                                            query.append(StringPool.CLOSE_PARENTHESIS);
3187    
3188                                            conjunctionable = true;
3189                                    }
3190    
3191                                    String sql = query.toString();
3192    
3193                                    Query q = session.createQuery(sql);
3194    
3195                                    QueryPos qPos = QueryPos.getInstance(q);
3196    
3197                                    qPos.add(groupId);
3198    
3199                                    if (categoryIds != null) {
3200                                            qPos.add(categoryIds);
3201                                    }
3202    
3203                                    count = (Long)q.uniqueResult();
3204                            }
3205                            catch (Exception e) {
3206                                    throw processException(e);
3207                            }
3208                            finally {
3209                                    if (count == null) {
3210                                            count = Long.valueOf(0);
3211                                    }
3212    
3213                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
3214                                            count);
3215    
3216                                    closeSession(session);
3217                            }
3218                    }
3219    
3220                    return count.intValue();
3221            }
3222    
3223            public int countByG_NotC(long groupId, long categoryId)
3224                    throws SystemException {
3225                    Object[] finderArgs = new Object[] { groupId, categoryId };
3226    
3227                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC,
3228                                    finderArgs, this);
3229    
3230                    if (count == null) {
3231                            Session session = null;
3232    
3233                            try {
3234                                    session = openSession();
3235    
3236                                    StringBundler query = new StringBundler(3);
3237    
3238                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3239    
3240                                    query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3241    
3242                                    query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3243    
3244                                    String sql = query.toString();
3245    
3246                                    Query q = session.createQuery(sql);
3247    
3248                                    QueryPos qPos = QueryPos.getInstance(q);
3249    
3250                                    qPos.add(groupId);
3251    
3252                                    qPos.add(categoryId);
3253    
3254                                    count = (Long)q.uniqueResult();
3255                            }
3256                            catch (Exception e) {
3257                                    throw processException(e);
3258                            }
3259                            finally {
3260                                    if (count == null) {
3261                                            count = Long.valueOf(0);
3262                                    }
3263    
3264                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC,
3265                                            finderArgs, count);
3266    
3267                                    closeSession(session);
3268                            }
3269                    }
3270    
3271                    return count.intValue();
3272            }
3273    
3274            public int countByG_S(long groupId, int status) throws SystemException {
3275                    Object[] finderArgs = new Object[] { groupId, status };
3276    
3277                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
3278                                    finderArgs, this);
3279    
3280                    if (count == null) {
3281                            Session session = null;
3282    
3283                            try {
3284                                    session = openSession();
3285    
3286                                    StringBundler query = new StringBundler(3);
3287    
3288                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3289    
3290                                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3291    
3292                                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
3293    
3294                                    String sql = query.toString();
3295    
3296                                    Query q = session.createQuery(sql);
3297    
3298                                    QueryPos qPos = QueryPos.getInstance(q);
3299    
3300                                    qPos.add(groupId);
3301    
3302                                    qPos.add(status);
3303    
3304                                    count = (Long)q.uniqueResult();
3305                            }
3306                            catch (Exception e) {
3307                                    throw processException(e);
3308                            }
3309                            finally {
3310                                    if (count == null) {
3311                                            count = Long.valueOf(0);
3312                                    }
3313    
3314                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
3315                                            count);
3316    
3317                                    closeSession(session);
3318                            }
3319                    }
3320    
3321                    return count.intValue();
3322            }
3323    
3324            public int countByC_P(long categoryId, double priority)
3325                    throws SystemException {
3326                    Object[] finderArgs = new Object[] { categoryId, priority };
3327    
3328                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
3329                                    finderArgs, this);
3330    
3331                    if (count == null) {
3332                            Session session = null;
3333    
3334                            try {
3335                                    session = openSession();
3336    
3337                                    StringBundler query = new StringBundler(3);
3338    
3339                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3340    
3341                                    query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
3342    
3343                                    query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
3344    
3345                                    String sql = query.toString();
3346    
3347                                    Query q = session.createQuery(sql);
3348    
3349                                    QueryPos qPos = QueryPos.getInstance(q);
3350    
3351                                    qPos.add(categoryId);
3352    
3353                                    qPos.add(priority);
3354    
3355                                    count = (Long)q.uniqueResult();
3356                            }
3357                            catch (Exception e) {
3358                                    throw processException(e);
3359                            }
3360                            finally {
3361                                    if (count == null) {
3362                                            count = Long.valueOf(0);
3363                                    }
3364    
3365                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
3366                                            count);
3367    
3368                                    closeSession(session);
3369                            }
3370                    }
3371    
3372                    return count.intValue();
3373            }
3374    
3375            public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
3376                    throws SystemException {
3377                    Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
3378    
3379                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_L,
3380                                    finderArgs, this);
3381    
3382                    if (count == null) {
3383                            Session session = null;
3384    
3385                            try {
3386                                    session = openSession();
3387    
3388                                    StringBundler query = new StringBundler(4);
3389    
3390                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3391    
3392                                    query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
3393    
3394                                    query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
3395    
3396                                    if (lastPostDate == null) {
3397                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
3398                                    }
3399                                    else {
3400                                            query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
3401                                    }
3402    
3403                                    String sql = query.toString();
3404    
3405                                    Query q = session.createQuery(sql);
3406    
3407                                    QueryPos qPos = QueryPos.getInstance(q);
3408    
3409                                    qPos.add(groupId);
3410    
3411                                    qPos.add(categoryId);
3412    
3413                                    if (lastPostDate != null) {
3414                                            qPos.add(CalendarUtil.getTimestamp(lastPostDate));
3415                                    }
3416    
3417                                    count = (Long)q.uniqueResult();
3418                            }
3419                            catch (Exception e) {
3420                                    throw processException(e);
3421                            }
3422                            finally {
3423                                    if (count == null) {
3424                                            count = Long.valueOf(0);
3425                                    }
3426    
3427                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_L,
3428                                            finderArgs, count);
3429    
3430                                    closeSession(session);
3431                            }
3432                    }
3433    
3434                    return count.intValue();
3435            }
3436    
3437            public int countByG_C_S(long groupId, long categoryId, int status)
3438                    throws SystemException {
3439                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
3440    
3441                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
3442                                    finderArgs, this);
3443    
3444                    if (count == null) {
3445                            Session session = null;
3446    
3447                            try {
3448                                    session = openSession();
3449    
3450                                    StringBundler query = new StringBundler(4);
3451    
3452                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3453    
3454                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
3455    
3456                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
3457    
3458                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
3459    
3460                                    String sql = query.toString();
3461    
3462                                    Query q = session.createQuery(sql);
3463    
3464                                    QueryPos qPos = QueryPos.getInstance(q);
3465    
3466                                    qPos.add(groupId);
3467    
3468                                    qPos.add(categoryId);
3469    
3470                                    qPos.add(status);
3471    
3472                                    count = (Long)q.uniqueResult();
3473                            }
3474                            catch (Exception e) {
3475                                    throw processException(e);
3476                            }
3477                            finally {
3478                                    if (count == null) {
3479                                            count = Long.valueOf(0);
3480                                    }
3481    
3482                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
3483                                            finderArgs, count);
3484    
3485                                    closeSession(session);
3486                            }
3487                    }
3488    
3489                    return count.intValue();
3490            }
3491    
3492            public int countByG_C_S(long groupId, long[] categoryIds, int status)
3493                    throws SystemException {
3494                    Object[] finderArgs = new Object[] {
3495                                    groupId, StringUtil.merge(categoryIds), status
3496                            };
3497    
3498                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
3499                                    finderArgs, this);
3500    
3501                    if (count == null) {
3502                            Session session = null;
3503    
3504                            try {
3505                                    session = openSession();
3506    
3507                                    StringBundler query = new StringBundler();
3508    
3509                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3510    
3511                                    boolean conjunctionable = false;
3512    
3513                                    if (conjunctionable) {
3514                                            query.append(WHERE_AND);
3515                                    }
3516    
3517                                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
3518    
3519                                    conjunctionable = true;
3520    
3521                                    if ((categoryIds == null) || (categoryIds.length > 0)) {
3522                                            if (conjunctionable) {
3523                                                    query.append(WHERE_AND);
3524                                            }
3525    
3526                                            query.append(StringPool.OPEN_PARENTHESIS);
3527    
3528                                            for (int i = 0; i < categoryIds.length; i++) {
3529                                                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
3530    
3531                                                    if ((i + 1) < categoryIds.length) {
3532                                                            query.append(WHERE_OR);
3533                                                    }
3534                                            }
3535    
3536                                            query.append(StringPool.CLOSE_PARENTHESIS);
3537    
3538                                            conjunctionable = true;
3539                                    }
3540    
3541                                    if (conjunctionable) {
3542                                            query.append(WHERE_AND);
3543                                    }
3544    
3545                                    query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
3546    
3547                                    conjunctionable = true;
3548    
3549                                    String sql = query.toString();
3550    
3551                                    Query q = session.createQuery(sql);
3552    
3553                                    QueryPos qPos = QueryPos.getInstance(q);
3554    
3555                                    qPos.add(groupId);
3556    
3557                                    if (categoryIds != null) {
3558                                            qPos.add(categoryIds);
3559                                    }
3560    
3561                                    qPos.add(status);
3562    
3563                                    count = (Long)q.uniqueResult();
3564                            }
3565                            catch (Exception e) {
3566                                    throw processException(e);
3567                            }
3568                            finally {
3569                                    if (count == null) {
3570                                            count = Long.valueOf(0);
3571                                    }
3572    
3573                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
3574                                            finderArgs, count);
3575    
3576                                    closeSession(session);
3577                            }
3578                    }
3579    
3580                    return count.intValue();
3581            }
3582    
3583            public int countByG_NotC_S(long groupId, long categoryId, int status)
3584                    throws SystemException {
3585                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
3586    
3587                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
3588                                    finderArgs, this);
3589    
3590                    if (count == null) {
3591                            Session session = null;
3592    
3593                            try {
3594                                    session = openSession();
3595    
3596                                    StringBundler query = new StringBundler(4);
3597    
3598                                    query.append(_SQL_COUNT_MBTHREAD_WHERE);
3599    
3600                                    query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
3601    
3602                                    query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
3603    
3604                                    query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
3605    
3606                                    String sql = query.toString();
3607    
3608                                    Query q = session.createQuery(sql);
3609    
3610                                    QueryPos qPos = QueryPos.getInstance(q);
3611    
3612                                    qPos.add(groupId);
3613    
3614                                    qPos.add(categoryId);
3615    
3616                                    qPos.add(status);
3617    
3618                                    count = (Long)q.uniqueResult();
3619                            }
3620                            catch (Exception e) {
3621                                    throw processException(e);
3622                            }
3623                            finally {
3624                                    if (count == null) {
3625                                            count = Long.valueOf(0);
3626                                    }
3627    
3628                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTC_S,
3629                                            finderArgs, count);
3630    
3631                                    closeSession(session);
3632                            }
3633                    }
3634    
3635                    return count.intValue();
3636            }
3637    
3638            public int countAll() throws SystemException {
3639                    Object[] finderArgs = new Object[0];
3640    
3641                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3642                                    finderArgs, this);
3643    
3644                    if (count == null) {
3645                            Session session = null;
3646    
3647                            try {
3648                                    session = openSession();
3649    
3650                                    Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
3651    
3652                                    count = (Long)q.uniqueResult();
3653                            }
3654                            catch (Exception e) {
3655                                    throw processException(e);
3656                            }
3657                            finally {
3658                                    if (count == null) {
3659                                            count = Long.valueOf(0);
3660                                    }
3661    
3662                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3663                                            count);
3664    
3665                                    closeSession(session);
3666                            }
3667                    }
3668    
3669                    return count.intValue();
3670            }
3671    
3672            public void afterPropertiesSet() {
3673                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3674                                            com.liferay.portal.util.PropsUtil.get(
3675                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
3676    
3677                    if (listenerClassNames.length > 0) {
3678                            try {
3679                                    List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
3680    
3681                                    for (String listenerClassName : listenerClassNames) {
3682                                            listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
3683                                                            listenerClassName));
3684                                    }
3685    
3686                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3687                            }
3688                            catch (Exception e) {
3689                                    _log.error(e);
3690                            }
3691                    }
3692            }
3693    
3694            @BeanReference(type = MBBanPersistence.class)
3695            protected MBBanPersistence mbBanPersistence;
3696            @BeanReference(type = MBCategoryPersistence.class)
3697            protected MBCategoryPersistence mbCategoryPersistence;
3698            @BeanReference(type = MBDiscussionPersistence.class)
3699            protected MBDiscussionPersistence mbDiscussionPersistence;
3700            @BeanReference(type = MBMailingListPersistence.class)
3701            protected MBMailingListPersistence mbMailingListPersistence;
3702            @BeanReference(type = MBMessagePersistence.class)
3703            protected MBMessagePersistence mbMessagePersistence;
3704            @BeanReference(type = MBMessageFlagPersistence.class)
3705            protected MBMessageFlagPersistence mbMessageFlagPersistence;
3706            @BeanReference(type = MBStatsUserPersistence.class)
3707            protected MBStatsUserPersistence mbStatsUserPersistence;
3708            @BeanReference(type = MBThreadPersistence.class)
3709            protected MBThreadPersistence mbThreadPersistence;
3710            @BeanReference(type = LockPersistence.class)
3711            protected LockPersistence lockPersistence;
3712            @BeanReference(type = ResourcePersistence.class)
3713            protected ResourcePersistence resourcePersistence;
3714            @BeanReference(type = UserPersistence.class)
3715            protected UserPersistence userPersistence;
3716            @BeanReference(type = WorkflowInstanceLinkPersistence.class)
3717            protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
3718            @BeanReference(type = AssetEntryPersistence.class)
3719            protected AssetEntryPersistence assetEntryPersistence;
3720            @BeanReference(type = RatingsStatsPersistence.class)
3721            protected RatingsStatsPersistence ratingsStatsPersistence;
3722            @BeanReference(type = SocialActivityPersistence.class)
3723            protected SocialActivityPersistence socialActivityPersistence;
3724            private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
3725            private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
3726            private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
3727            private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
3728            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ?";
3729            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
3730            private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
3731                    _removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
3732            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
3733            private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
3734                    _removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
3735            private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
3736            private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
3737            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
3738            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ?";
3739            private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
3740            private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
3741            private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
3742            private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
3743            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
3744            private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
3745            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
3746            private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
3747                    _removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
3748            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
3749            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
3750                    _removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
3751            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
3752            private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
3753                    _removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
3754            private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
3755            private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
3756            private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
3757    
3758            private static String _removeConjunction(String sql) {
3759                    int pos = sql.indexOf(" AND ");
3760    
3761                    if (pos != -1) {
3762                            sql = sql.substring(0, pos);
3763                    }
3764    
3765                    return sql;
3766            }
3767    
3768            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
3769            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
3770            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
3771            private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
3772    }