1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.messageboards.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.kernel.exception.SystemException;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.CalendarUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.ModelListener;
37  import com.liferay.portal.service.persistence.BatchSessionUtil;
38  import com.liferay.portal.service.persistence.LockPersistence;
39  import com.liferay.portal.service.persistence.ResourcePersistence;
40  import com.liferay.portal.service.persistence.UserPersistence;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
44  import com.liferay.portlet.messageboards.NoSuchThreadException;
45  import com.liferay.portlet.messageboards.model.MBThread;
46  import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
47  import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
48  import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
49  import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
50  
51  import java.io.Serializable;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.Date;
56  import java.util.List;
57  
58  /**
59   * <a href="MBThreadPersistenceImpl.java.html"><b><i>View Source</i></b></a>
60   *
61   * <p>
62   * ServiceBuilder generated this class. Modifications in this class will be
63   * overwritten the next time is generated.
64   * </p>
65   *
66   * @author    Brian Wing Shun Chan
67   * @see       MBThreadPersistence
68   * @see       MBThreadUtil
69   * @generated
70   */
71  public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
72      implements MBThreadPersistence {
73      public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
74      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
75          ".List";
76      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
77              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
78              "findByGroupId", new String[] { Long.class.getName() });
79      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
80              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
81              "findByGroupId",
82              new String[] {
83                  Long.class.getName(),
84                  
85              "java.lang.Integer", "java.lang.Integer",
86                  "com.liferay.portal.kernel.util.OrderByComparator"
87              });
88      public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
89              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
90              "countByGroupId", new String[] { Long.class.getName() });
91      public static final FinderPath FINDER_PATH_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
92              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
93              "findByG_C",
94              new String[] { Long.class.getName(), Long.class.getName() });
95      public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
96              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
97              "findByG_C",
98              new String[] {
99                  Long.class.getName(), Long.class.getName(),
100                 
101             "java.lang.Integer", "java.lang.Integer",
102                 "com.liferay.portal.kernel.util.OrderByComparator"
103             });
104     public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
105             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106             "countByG_C",
107             new String[] { Long.class.getName(), Long.class.getName() });
108     public static final FinderPath FINDER_PATH_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
109             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110             "findByG_S",
111             new String[] { Long.class.getName(), Integer.class.getName() });
112     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
113             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114             "findByG_S",
115             new String[] {
116                 Long.class.getName(), Integer.class.getName(),
117                 
118             "java.lang.Integer", "java.lang.Integer",
119                 "com.liferay.portal.kernel.util.OrderByComparator"
120             });
121     public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
122             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123             "countByG_S",
124             new String[] { Long.class.getName(), Integer.class.getName() });
125     public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
126             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
127             "findByC_P",
128             new String[] { Long.class.getName(), Double.class.getName() });
129     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
130             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
131             "findByC_P",
132             new String[] {
133                 Long.class.getName(), Double.class.getName(),
134                 
135             "java.lang.Integer", "java.lang.Integer",
136                 "com.liferay.portal.kernel.util.OrderByComparator"
137             });
138     public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
139             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
140             "countByC_P",
141             new String[] { Long.class.getName(), Double.class.getName() });
142     public static final FinderPath FINDER_PATH_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
143             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144             "findByG_C_L",
145             new String[] {
146                 Long.class.getName(), Long.class.getName(), Date.class.getName()
147             });
148     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
149             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
150             "findByG_C_L",
151             new String[] {
152                 Long.class.getName(), Long.class.getName(), Date.class.getName(),
153                 
154             "java.lang.Integer", "java.lang.Integer",
155                 "com.liferay.portal.kernel.util.OrderByComparator"
156             });
157     public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
158             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
159             "countByG_C_L",
160             new String[] {
161                 Long.class.getName(), Long.class.getName(), Date.class.getName()
162             });
163     public static final FinderPath FINDER_PATH_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
164             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
165             "findByG_C_S",
166             new String[] {
167                 Long.class.getName(), Long.class.getName(),
168                 Integer.class.getName()
169             });
170     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
171             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
172             "findByG_C_S",
173             new String[] {
174                 Long.class.getName(), Long.class.getName(),
175                 Integer.class.getName(),
176                 
177             "java.lang.Integer", "java.lang.Integer",
178                 "com.liferay.portal.kernel.util.OrderByComparator"
179             });
180     public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
181             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
182             "countByG_C_S",
183             new String[] {
184                 Long.class.getName(), Long.class.getName(),
185                 Integer.class.getName()
186             });
187     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
188             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
189             "findAll", new String[0]);
190     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
191             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
192             "countAll", new String[0]);
193 
194     public void cacheResult(MBThread mbThread) {
195         EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
196             MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
197     }
198 
199     public void cacheResult(List<MBThread> mbThreads) {
200         for (MBThread mbThread : mbThreads) {
201             if (EntityCacheUtil.getResult(
202                         MBThreadModelImpl.ENTITY_CACHE_ENABLED,
203                         MBThreadImpl.class, mbThread.getPrimaryKey(), this) == null) {
204                 cacheResult(mbThread);
205             }
206         }
207     }
208 
209     public void clearCache() {
210         CacheRegistry.clear(MBThreadImpl.class.getName());
211         EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
212         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
213         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
214     }
215 
216     public MBThread create(long threadId) {
217         MBThread mbThread = new MBThreadImpl();
218 
219         mbThread.setNew(true);
220         mbThread.setPrimaryKey(threadId);
221 
222         return mbThread;
223     }
224 
225     public MBThread remove(Serializable primaryKey)
226         throws NoSuchModelException, SystemException {
227         return remove(((Long)primaryKey).longValue());
228     }
229 
230     public MBThread remove(long threadId)
231         throws NoSuchThreadException, SystemException {
232         Session session = null;
233 
234         try {
235             session = openSession();
236 
237             MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
238                     new Long(threadId));
239 
240             if (mbThread == null) {
241                 if (_log.isWarnEnabled()) {
242                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
243                 }
244 
245                 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
246                     threadId);
247             }
248 
249             return remove(mbThread);
250         }
251         catch (NoSuchThreadException nsee) {
252             throw nsee;
253         }
254         catch (Exception e) {
255             throw processException(e);
256         }
257         finally {
258             closeSession(session);
259         }
260     }
261 
262     public MBThread remove(MBThread mbThread) throws SystemException {
263         for (ModelListener<MBThread> listener : listeners) {
264             listener.onBeforeRemove(mbThread);
265         }
266 
267         mbThread = removeImpl(mbThread);
268 
269         for (ModelListener<MBThread> listener : listeners) {
270             listener.onAfterRemove(mbThread);
271         }
272 
273         return mbThread;
274     }
275 
276     protected MBThread removeImpl(MBThread mbThread) throws SystemException {
277         mbThread = toUnwrappedModel(mbThread);
278 
279         Session session = null;
280 
281         try {
282             session = openSession();
283 
284             if (mbThread.isCachedModel() || BatchSessionUtil.isEnabled()) {
285                 Object staleObject = session.get(MBThreadImpl.class,
286                         mbThread.getPrimaryKeyObj());
287 
288                 if (staleObject != null) {
289                     session.evict(staleObject);
290                 }
291             }
292 
293             session.delete(mbThread);
294 
295             session.flush();
296         }
297         catch (Exception e) {
298             throw processException(e);
299         }
300         finally {
301             closeSession(session);
302         }
303 
304         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
305 
306         EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
307             MBThreadImpl.class, mbThread.getPrimaryKey());
308 
309         return mbThread;
310     }
311 
312     public MBThread updateImpl(
313         com.liferay.portlet.messageboards.model.MBThread mbThread, boolean merge)
314         throws SystemException {
315         mbThread = toUnwrappedModel(mbThread);
316 
317         Session session = null;
318 
319         try {
320             session = openSession();
321 
322             BatchSessionUtil.update(session, mbThread, merge);
323 
324             mbThread.setNew(false);
325         }
326         catch (Exception e) {
327             throw processException(e);
328         }
329         finally {
330             closeSession(session);
331         }
332 
333         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
334 
335         EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
336             MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
337 
338         return mbThread;
339     }
340 
341     protected MBThread toUnwrappedModel(MBThread mbThread) {
342         if (mbThread instanceof MBThreadImpl) {
343             return mbThread;
344         }
345 
346         MBThreadImpl mbThreadImpl = new MBThreadImpl();
347 
348         mbThreadImpl.setNew(mbThread.isNew());
349         mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
350 
351         mbThreadImpl.setThreadId(mbThread.getThreadId());
352         mbThreadImpl.setGroupId(mbThread.getGroupId());
353         mbThreadImpl.setCategoryId(mbThread.getCategoryId());
354         mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
355         mbThreadImpl.setMessageCount(mbThread.getMessageCount());
356         mbThreadImpl.setViewCount(mbThread.getViewCount());
357         mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
358         mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
359         mbThreadImpl.setPriority(mbThread.getPriority());
360         mbThreadImpl.setStatus(mbThread.getStatus());
361         mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
362         mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
363         mbThreadImpl.setStatusDate(mbThread.getStatusDate());
364 
365         return mbThreadImpl;
366     }
367 
368     public MBThread findByPrimaryKey(Serializable primaryKey)
369         throws NoSuchModelException, SystemException {
370         return findByPrimaryKey(((Long)primaryKey).longValue());
371     }
372 
373     public MBThread findByPrimaryKey(long threadId)
374         throws NoSuchThreadException, SystemException {
375         MBThread mbThread = fetchByPrimaryKey(threadId);
376 
377         if (mbThread == null) {
378             if (_log.isWarnEnabled()) {
379                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
380             }
381 
382             throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
383                 threadId);
384         }
385 
386         return mbThread;
387     }
388 
389     public MBThread fetchByPrimaryKey(Serializable primaryKey)
390         throws SystemException {
391         return fetchByPrimaryKey(((Long)primaryKey).longValue());
392     }
393 
394     public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
395         MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
396                 MBThreadImpl.class, threadId, this);
397 
398         if (mbThread == null) {
399             Session session = null;
400 
401             try {
402                 session = openSession();
403 
404                 mbThread = (MBThread)session.get(MBThreadImpl.class,
405                         new Long(threadId));
406             }
407             catch (Exception e) {
408                 throw processException(e);
409             }
410             finally {
411                 if (mbThread != null) {
412                     cacheResult(mbThread);
413                 }
414 
415                 closeSession(session);
416             }
417         }
418 
419         return mbThread;
420     }
421 
422     public List<MBThread> findByGroupId(long groupId) throws SystemException {
423         Object[] finderArgs = new Object[] { new Long(groupId) };
424 
425         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
426                 finderArgs, this);
427 
428         if (list == null) {
429             Session session = null;
430 
431             try {
432                 session = openSession();
433 
434                 StringBundler query = new StringBundler(3);
435 
436                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
437 
438                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
439 
440                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
441 
442                 String sql = query.toString();
443 
444                 Query q = session.createQuery(sql);
445 
446                 QueryPos qPos = QueryPos.getInstance(q);
447 
448                 qPos.add(groupId);
449 
450                 list = q.list();
451             }
452             catch (Exception e) {
453                 throw processException(e);
454             }
455             finally {
456                 if (list == null) {
457                     list = new ArrayList<MBThread>();
458                 }
459 
460                 cacheResult(list);
461 
462                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
463                     finderArgs, list);
464 
465                 closeSession(session);
466             }
467         }
468 
469         return list;
470     }
471 
472     public List<MBThread> findByGroupId(long groupId, int start, int end)
473         throws SystemException {
474         return findByGroupId(groupId, start, end, null);
475     }
476 
477     public List<MBThread> findByGroupId(long groupId, int start, int end,
478         OrderByComparator orderByComparator) throws SystemException {
479         Object[] finderArgs = new Object[] {
480                 new Long(groupId),
481                 
482                 String.valueOf(start), String.valueOf(end),
483                 String.valueOf(orderByComparator)
484             };
485 
486         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
487                 finderArgs, this);
488 
489         if (list == null) {
490             Session session = null;
491 
492             try {
493                 session = openSession();
494 
495                 StringBundler query = null;
496 
497                 if (orderByComparator != null) {
498                     query = new StringBundler(3 +
499                             (orderByComparator.getOrderByFields().length * 3));
500                 }
501                 else {
502                     query = new StringBundler(3);
503                 }
504 
505                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
506 
507                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
508 
509                 if (orderByComparator != null) {
510                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
511                         orderByComparator);
512                 }
513 
514                 else {
515                     query.append(MBThreadModelImpl.ORDER_BY_JPQL);
516                 }
517 
518                 String sql = query.toString();
519 
520                 Query q = session.createQuery(sql);
521 
522                 QueryPos qPos = QueryPos.getInstance(q);
523 
524                 qPos.add(groupId);
525 
526                 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
527                         end);
528             }
529             catch (Exception e) {
530                 throw processException(e);
531             }
532             finally {
533                 if (list == null) {
534                     list = new ArrayList<MBThread>();
535                 }
536 
537                 cacheResult(list);
538 
539                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
540                     finderArgs, list);
541 
542                 closeSession(session);
543             }
544         }
545 
546         return list;
547     }
548 
549     public MBThread findByGroupId_First(long groupId,
550         OrderByComparator orderByComparator)
551         throws NoSuchThreadException, SystemException {
552         List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
553 
554         if (list.isEmpty()) {
555             StringBundler msg = new StringBundler(4);
556 
557             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
558 
559             msg.append("groupId=");
560             msg.append(groupId);
561 
562             msg.append(StringPool.CLOSE_CURLY_BRACE);
563 
564             throw new NoSuchThreadException(msg.toString());
565         }
566         else {
567             return list.get(0);
568         }
569     }
570 
571     public MBThread findByGroupId_Last(long groupId,
572         OrderByComparator orderByComparator)
573         throws NoSuchThreadException, SystemException {
574         int count = countByGroupId(groupId);
575 
576         List<MBThread> list = findByGroupId(groupId, count - 1, count,
577                 orderByComparator);
578 
579         if (list.isEmpty()) {
580             StringBundler msg = new StringBundler(4);
581 
582             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
583 
584             msg.append("groupId=");
585             msg.append(groupId);
586 
587             msg.append(StringPool.CLOSE_CURLY_BRACE);
588 
589             throw new NoSuchThreadException(msg.toString());
590         }
591         else {
592             return list.get(0);
593         }
594     }
595 
596     public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
597         OrderByComparator orderByComparator)
598         throws NoSuchThreadException, SystemException {
599         MBThread mbThread = findByPrimaryKey(threadId);
600 
601         int count = countByGroupId(groupId);
602 
603         Session session = null;
604 
605         try {
606             session = openSession();
607 
608             StringBundler query = null;
609 
610             if (orderByComparator != null) {
611                 query = new StringBundler(3 +
612                         (orderByComparator.getOrderByFields().length * 3));
613             }
614             else {
615                 query = new StringBundler(3);
616             }
617 
618             query.append(_SQL_SELECT_MBTHREAD_WHERE);
619 
620             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
621 
622             if (orderByComparator != null) {
623                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
624                     orderByComparator);
625             }
626 
627             else {
628                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
629             }
630 
631             String sql = query.toString();
632 
633             Query q = session.createQuery(sql);
634 
635             QueryPos qPos = QueryPos.getInstance(q);
636 
637             qPos.add(groupId);
638 
639             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
640                     orderByComparator, mbThread);
641 
642             MBThread[] array = new MBThreadImpl[3];
643 
644             array[0] = (MBThread)objArray[0];
645             array[1] = (MBThread)objArray[1];
646             array[2] = (MBThread)objArray[2];
647 
648             return array;
649         }
650         catch (Exception e) {
651             throw processException(e);
652         }
653         finally {
654             closeSession(session);
655         }
656     }
657 
658     public List<MBThread> findByG_C(long groupId, long categoryId)
659         throws SystemException {
660         Object[] finderArgs = new Object[] {
661                 new Long(groupId), new Long(categoryId)
662             };
663 
664         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C,
665                 finderArgs, this);
666 
667         if (list == null) {
668             Session session = null;
669 
670             try {
671                 session = openSession();
672 
673                 StringBundler query = new StringBundler(4);
674 
675                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
676 
677                 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
678 
679                 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
680 
681                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
682 
683                 String sql = query.toString();
684 
685                 Query q = session.createQuery(sql);
686 
687                 QueryPos qPos = QueryPos.getInstance(q);
688 
689                 qPos.add(groupId);
690 
691                 qPos.add(categoryId);
692 
693                 list = q.list();
694             }
695             catch (Exception e) {
696                 throw processException(e);
697             }
698             finally {
699                 if (list == null) {
700                     list = new ArrayList<MBThread>();
701                 }
702 
703                 cacheResult(list);
704 
705                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C, finderArgs,
706                     list);
707 
708                 closeSession(session);
709             }
710         }
711 
712         return list;
713     }
714 
715     public List<MBThread> findByG_C(long groupId, long categoryId, int start,
716         int end) throws SystemException {
717         return findByG_C(groupId, categoryId, start, end, null);
718     }
719 
720     public List<MBThread> findByG_C(long groupId, long categoryId, int start,
721         int end, OrderByComparator orderByComparator) throws SystemException {
722         Object[] finderArgs = new Object[] {
723                 new Long(groupId), new Long(categoryId),
724                 
725                 String.valueOf(start), String.valueOf(end),
726                 String.valueOf(orderByComparator)
727             };
728 
729         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_C,
730                 finderArgs, this);
731 
732         if (list == null) {
733             Session session = null;
734 
735             try {
736                 session = openSession();
737 
738                 StringBundler query = null;
739 
740                 if (orderByComparator != null) {
741                     query = new StringBundler(4 +
742                             (orderByComparator.getOrderByFields().length * 3));
743                 }
744                 else {
745                     query = new StringBundler(4);
746                 }
747 
748                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
749 
750                 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
751 
752                 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
753 
754                 if (orderByComparator != null) {
755                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
756                         orderByComparator);
757                 }
758 
759                 else {
760                     query.append(MBThreadModelImpl.ORDER_BY_JPQL);
761                 }
762 
763                 String sql = query.toString();
764 
765                 Query q = session.createQuery(sql);
766 
767                 QueryPos qPos = QueryPos.getInstance(q);
768 
769                 qPos.add(groupId);
770 
771                 qPos.add(categoryId);
772 
773                 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
774                         end);
775             }
776             catch (Exception e) {
777                 throw processException(e);
778             }
779             finally {
780                 if (list == null) {
781                     list = new ArrayList<MBThread>();
782                 }
783 
784                 cacheResult(list);
785 
786                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_C,
787                     finderArgs, list);
788 
789                 closeSession(session);
790             }
791         }
792 
793         return list;
794     }
795 
796     public MBThread findByG_C_First(long groupId, long categoryId,
797         OrderByComparator orderByComparator)
798         throws NoSuchThreadException, SystemException {
799         List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
800                 orderByComparator);
801 
802         if (list.isEmpty()) {
803             StringBundler msg = new StringBundler(6);
804 
805             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806 
807             msg.append("groupId=");
808             msg.append(groupId);
809 
810             msg.append(", categoryId=");
811             msg.append(categoryId);
812 
813             msg.append(StringPool.CLOSE_CURLY_BRACE);
814 
815             throw new NoSuchThreadException(msg.toString());
816         }
817         else {
818             return list.get(0);
819         }
820     }
821 
822     public MBThread findByG_C_Last(long groupId, long categoryId,
823         OrderByComparator orderByComparator)
824         throws NoSuchThreadException, SystemException {
825         int count = countByG_C(groupId, categoryId);
826 
827         List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
828                 orderByComparator);
829 
830         if (list.isEmpty()) {
831             StringBundler msg = new StringBundler(6);
832 
833             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
834 
835             msg.append("groupId=");
836             msg.append(groupId);
837 
838             msg.append(", categoryId=");
839             msg.append(categoryId);
840 
841             msg.append(StringPool.CLOSE_CURLY_BRACE);
842 
843             throw new NoSuchThreadException(msg.toString());
844         }
845         else {
846             return list.get(0);
847         }
848     }
849 
850     public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
851         long categoryId, OrderByComparator orderByComparator)
852         throws NoSuchThreadException, SystemException {
853         MBThread mbThread = findByPrimaryKey(threadId);
854 
855         int count = countByG_C(groupId, categoryId);
856 
857         Session session = null;
858 
859         try {
860             session = openSession();
861 
862             StringBundler query = null;
863 
864             if (orderByComparator != null) {
865                 query = new StringBundler(4 +
866                         (orderByComparator.getOrderByFields().length * 3));
867             }
868             else {
869                 query = new StringBundler(4);
870             }
871 
872             query.append(_SQL_SELECT_MBTHREAD_WHERE);
873 
874             query.append(_FINDER_COLUMN_G_C_GROUPID_2);
875 
876             query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
877 
878             if (orderByComparator != null) {
879                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
880                     orderByComparator);
881             }
882 
883             else {
884                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
885             }
886 
887             String sql = query.toString();
888 
889             Query q = session.createQuery(sql);
890 
891             QueryPos qPos = QueryPos.getInstance(q);
892 
893             qPos.add(groupId);
894 
895             qPos.add(categoryId);
896 
897             Object[] objArray = QueryUtil.getPrevAndNext(q, count,
898                     orderByComparator, mbThread);
899 
900             MBThread[] array = new MBThreadImpl[3];
901 
902             array[0] = (MBThread)objArray[0];
903             array[1] = (MBThread)objArray[1];
904             array[2] = (MBThread)objArray[2];
905 
906             return array;
907         }
908         catch (Exception e) {
909             throw processException(e);
910         }
911         finally {
912             closeSession(session);
913         }
914     }
915 
916     public List<MBThread> findByG_S(long groupId, int status)
917         throws SystemException {
918         Object[] finderArgs = new Object[] {
919                 new Long(groupId), new Integer(status)
920             };
921 
922         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_S,
923                 finderArgs, this);
924 
925         if (list == null) {
926             Session session = null;
927 
928             try {
929                 session = openSession();
930 
931                 StringBundler query = new StringBundler(4);
932 
933                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
934 
935                 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
936 
937                 query.append(_FINDER_COLUMN_G_S_STATUS_2);
938 
939                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
940 
941                 String sql = query.toString();
942 
943                 Query q = session.createQuery(sql);
944 
945                 QueryPos qPos = QueryPos.getInstance(q);
946 
947                 qPos.add(groupId);
948 
949                 qPos.add(status);
950 
951                 list = q.list();
952             }
953             catch (Exception e) {
954                 throw processException(e);
955             }
956             finally {
957                 if (list == null) {
958                     list = new ArrayList<MBThread>();
959                 }
960 
961                 cacheResult(list);
962 
963                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_S, finderArgs,
964                     list);
965 
966                 closeSession(session);
967             }
968         }
969 
970         return list;
971     }
972 
973     public List<MBThread> findByG_S(long groupId, int status, int start, int end)
974         throws SystemException {
975         return findByG_S(groupId, status, start, end, null);
976     }
977 
978     public List<MBThread> findByG_S(long groupId, int status, int start,
979         int end, OrderByComparator orderByComparator) throws SystemException {
980         Object[] finderArgs = new Object[] {
981                 new Long(groupId), new Integer(status),
982                 
983                 String.valueOf(start), String.valueOf(end),
984                 String.valueOf(orderByComparator)
985             };
986 
987         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_S,
988                 finderArgs, this);
989 
990         if (list == null) {
991             Session session = null;
992 
993             try {
994                 session = openSession();
995 
996                 StringBundler query = null;
997 
998                 if (orderByComparator != null) {
999                     query = new StringBundler(4 +
1000                            (orderByComparator.getOrderByFields().length * 3));
1001                }
1002                else {
1003                    query = new StringBundler(4);
1004                }
1005
1006                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1007
1008                query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1009
1010                query.append(_FINDER_COLUMN_G_S_STATUS_2);
1011
1012                if (orderByComparator != null) {
1013                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1014                        orderByComparator);
1015                }
1016
1017                else {
1018                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1019                }
1020
1021                String sql = query.toString();
1022
1023                Query q = session.createQuery(sql);
1024
1025                QueryPos qPos = QueryPos.getInstance(q);
1026
1027                qPos.add(groupId);
1028
1029                qPos.add(status);
1030
1031                list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1032                        end);
1033            }
1034            catch (Exception e) {
1035                throw processException(e);
1036            }
1037            finally {
1038                if (list == null) {
1039                    list = new ArrayList<MBThread>();
1040                }
1041
1042                cacheResult(list);
1043
1044                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_S,
1045                    finderArgs, list);
1046
1047                closeSession(session);
1048            }
1049        }
1050
1051        return list;
1052    }
1053
1054    public MBThread findByG_S_First(long groupId, int status,
1055        OrderByComparator orderByComparator)
1056        throws NoSuchThreadException, SystemException {
1057        List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
1058
1059        if (list.isEmpty()) {
1060            StringBundler msg = new StringBundler(6);
1061
1062            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1063
1064            msg.append("groupId=");
1065            msg.append(groupId);
1066
1067            msg.append(", status=");
1068            msg.append(status);
1069
1070            msg.append(StringPool.CLOSE_CURLY_BRACE);
1071
1072            throw new NoSuchThreadException(msg.toString());
1073        }
1074        else {
1075            return list.get(0);
1076        }
1077    }
1078
1079    public MBThread findByG_S_Last(long groupId, int status,
1080        OrderByComparator orderByComparator)
1081        throws NoSuchThreadException, SystemException {
1082        int count = countByG_S(groupId, status);
1083
1084        List<MBThread> list = findByG_S(groupId, status, count - 1, count,
1085                orderByComparator);
1086
1087        if (list.isEmpty()) {
1088            StringBundler msg = new StringBundler(6);
1089
1090            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1091
1092            msg.append("groupId=");
1093            msg.append(groupId);
1094
1095            msg.append(", status=");
1096            msg.append(status);
1097
1098            msg.append(StringPool.CLOSE_CURLY_BRACE);
1099
1100            throw new NoSuchThreadException(msg.toString());
1101        }
1102        else {
1103            return list.get(0);
1104        }
1105    }
1106
1107    public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
1108        int status, OrderByComparator orderByComparator)
1109        throws NoSuchThreadException, SystemException {
1110        MBThread mbThread = findByPrimaryKey(threadId);
1111
1112        int count = countByG_S(groupId, status);
1113
1114        Session session = null;
1115
1116        try {
1117            session = openSession();
1118
1119            StringBundler query = null;
1120
1121            if (orderByComparator != null) {
1122                query = new StringBundler(4 +
1123                        (orderByComparator.getOrderByFields().length * 3));
1124            }
1125            else {
1126                query = new StringBundler(4);
1127            }
1128
1129            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1130
1131            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
1132
1133            query.append(_FINDER_COLUMN_G_S_STATUS_2);
1134
1135            if (orderByComparator != null) {
1136                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1137                    orderByComparator);
1138            }
1139
1140            else {
1141                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1142            }
1143
1144            String sql = query.toString();
1145
1146            Query q = session.createQuery(sql);
1147
1148            QueryPos qPos = QueryPos.getInstance(q);
1149
1150            qPos.add(groupId);
1151
1152            qPos.add(status);
1153
1154            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1155                    orderByComparator, mbThread);
1156
1157            MBThread[] array = new MBThreadImpl[3];
1158
1159            array[0] = (MBThread)objArray[0];
1160            array[1] = (MBThread)objArray[1];
1161            array[2] = (MBThread)objArray[2];
1162
1163            return array;
1164        }
1165        catch (Exception e) {
1166            throw processException(e);
1167        }
1168        finally {
1169            closeSession(session);
1170        }
1171    }
1172
1173    public List<MBThread> findByC_P(long categoryId, double priority)
1174        throws SystemException {
1175        Object[] finderArgs = new Object[] {
1176                new Long(categoryId), new Double(priority)
1177            };
1178
1179        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
1180                finderArgs, this);
1181
1182        if (list == null) {
1183            Session session = null;
1184
1185            try {
1186                session = openSession();
1187
1188                StringBundler query = new StringBundler(4);
1189
1190                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1191
1192                query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1193
1194                query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1195
1196                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1197
1198                String sql = query.toString();
1199
1200                Query q = session.createQuery(sql);
1201
1202                QueryPos qPos = QueryPos.getInstance(q);
1203
1204                qPos.add(categoryId);
1205
1206                qPos.add(priority);
1207
1208                list = q.list();
1209            }
1210            catch (Exception e) {
1211                throw processException(e);
1212            }
1213            finally {
1214                if (list == null) {
1215                    list = new ArrayList<MBThread>();
1216                }
1217
1218                cacheResult(list);
1219
1220                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
1221                    list);
1222
1223                closeSession(session);
1224            }
1225        }
1226
1227        return list;
1228    }
1229
1230    public List<MBThread> findByC_P(long categoryId, double priority,
1231        int start, int end) throws SystemException {
1232        return findByC_P(categoryId, priority, start, end, null);
1233    }
1234
1235    public List<MBThread> findByC_P(long categoryId, double priority,
1236        int start, int end, OrderByComparator orderByComparator)
1237        throws SystemException {
1238        Object[] finderArgs = new Object[] {
1239                new Long(categoryId), new Double(priority),
1240                
1241                String.valueOf(start), String.valueOf(end),
1242                String.valueOf(orderByComparator)
1243            };
1244
1245        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_P,
1246                finderArgs, this);
1247
1248        if (list == null) {
1249            Session session = null;
1250
1251            try {
1252                session = openSession();
1253
1254                StringBundler query = null;
1255
1256                if (orderByComparator != null) {
1257                    query = new StringBundler(4 +
1258                            (orderByComparator.getOrderByFields().length * 3));
1259                }
1260                else {
1261                    query = new StringBundler(4);
1262                }
1263
1264                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1265
1266                query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1267
1268                query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1269
1270                if (orderByComparator != null) {
1271                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1272                        orderByComparator);
1273                }
1274
1275                else {
1276                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1277                }
1278
1279                String sql = query.toString();
1280
1281                Query q = session.createQuery(sql);
1282
1283                QueryPos qPos = QueryPos.getInstance(q);
1284
1285                qPos.add(categoryId);
1286
1287                qPos.add(priority);
1288
1289                list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1290                        end);
1291            }
1292            catch (Exception e) {
1293                throw processException(e);
1294            }
1295            finally {
1296                if (list == null) {
1297                    list = new ArrayList<MBThread>();
1298                }
1299
1300                cacheResult(list);
1301
1302                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_P,
1303                    finderArgs, list);
1304
1305                closeSession(session);
1306            }
1307        }
1308
1309        return list;
1310    }
1311
1312    public MBThread findByC_P_First(long categoryId, double priority,
1313        OrderByComparator orderByComparator)
1314        throws NoSuchThreadException, SystemException {
1315        List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
1316                orderByComparator);
1317
1318        if (list.isEmpty()) {
1319            StringBundler msg = new StringBundler(6);
1320
1321            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1322
1323            msg.append("categoryId=");
1324            msg.append(categoryId);
1325
1326            msg.append(", priority=");
1327            msg.append(priority);
1328
1329            msg.append(StringPool.CLOSE_CURLY_BRACE);
1330
1331            throw new NoSuchThreadException(msg.toString());
1332        }
1333        else {
1334            return list.get(0);
1335        }
1336    }
1337
1338    public MBThread findByC_P_Last(long categoryId, double priority,
1339        OrderByComparator orderByComparator)
1340        throws NoSuchThreadException, SystemException {
1341        int count = countByC_P(categoryId, priority);
1342
1343        List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
1344                orderByComparator);
1345
1346        if (list.isEmpty()) {
1347            StringBundler msg = new StringBundler(6);
1348
1349            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1350
1351            msg.append("categoryId=");
1352            msg.append(categoryId);
1353
1354            msg.append(", priority=");
1355            msg.append(priority);
1356
1357            msg.append(StringPool.CLOSE_CURLY_BRACE);
1358
1359            throw new NoSuchThreadException(msg.toString());
1360        }
1361        else {
1362            return list.get(0);
1363        }
1364    }
1365
1366    public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
1367        double priority, OrderByComparator orderByComparator)
1368        throws NoSuchThreadException, SystemException {
1369        MBThread mbThread = findByPrimaryKey(threadId);
1370
1371        int count = countByC_P(categoryId, priority);
1372
1373        Session session = null;
1374
1375        try {
1376            session = openSession();
1377
1378            StringBundler query = null;
1379
1380            if (orderByComparator != null) {
1381                query = new StringBundler(4 +
1382                        (orderByComparator.getOrderByFields().length * 3));
1383            }
1384            else {
1385                query = new StringBundler(4);
1386            }
1387
1388            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1389
1390            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1391
1392            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1393
1394            if (orderByComparator != null) {
1395                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1396                    orderByComparator);
1397            }
1398
1399            else {
1400                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1401            }
1402
1403            String sql = query.toString();
1404
1405            Query q = session.createQuery(sql);
1406
1407            QueryPos qPos = QueryPos.getInstance(q);
1408
1409            qPos.add(categoryId);
1410
1411            qPos.add(priority);
1412
1413            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1414                    orderByComparator, mbThread);
1415
1416            MBThread[] array = new MBThreadImpl[3];
1417
1418            array[0] = (MBThread)objArray[0];
1419            array[1] = (MBThread)objArray[1];
1420            array[2] = (MBThread)objArray[2];
1421
1422            return array;
1423        }
1424        catch (Exception e) {
1425            throw processException(e);
1426        }
1427        finally {
1428            closeSession(session);
1429        }
1430    }
1431
1432    public List<MBThread> findByG_C_L(long groupId, long categoryId,
1433        Date lastPostDate) throws SystemException {
1434        Object[] finderArgs = new Object[] {
1435                new Long(groupId), new Long(categoryId),
1436                
1437                lastPostDate
1438            };
1439
1440        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_L,
1441                finderArgs, this);
1442
1443        if (list == null) {
1444            Session session = null;
1445
1446            try {
1447                session = openSession();
1448
1449                StringBundler query = new StringBundler(5);
1450
1451                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1452
1453                query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
1454
1455                query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
1456
1457                if (lastPostDate == null) {
1458                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
1459                }
1460                else {
1461                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
1462                }
1463
1464                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1465
1466                String sql = query.toString();
1467
1468                Query q = session.createQuery(sql);
1469
1470                QueryPos qPos = QueryPos.getInstance(q);
1471
1472                qPos.add(groupId);
1473
1474                qPos.add(categoryId);
1475
1476                if (lastPostDate != null) {
1477                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
1478                }
1479
1480                list = q.list();
1481            }
1482            catch (Exception e) {
1483                throw processException(e);
1484            }
1485            finally {
1486                if (list == null) {
1487                    list = new ArrayList<MBThread>();
1488                }
1489
1490                cacheResult(list);
1491
1492                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_L,
1493                    finderArgs, list);
1494
1495                closeSession(session);
1496            }
1497        }
1498
1499        return list;
1500    }
1501
1502    public List<MBThread> findByG_C_L(long groupId, long categoryId,
1503        Date lastPostDate, int start, int end) throws SystemException {
1504        return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
1505    }
1506
1507    public List<MBThread> findByG_C_L(long groupId, long categoryId,
1508        Date lastPostDate, int start, int end,
1509        OrderByComparator orderByComparator) throws SystemException {
1510        Object[] finderArgs = new Object[] {
1511                new Long(groupId), new Long(categoryId),
1512                
1513                lastPostDate,
1514                
1515                String.valueOf(start), String.valueOf(end),
1516                String.valueOf(orderByComparator)
1517            };
1518
1519        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_C_L,
1520                finderArgs, this);
1521
1522        if (list == null) {
1523            Session session = null;
1524
1525            try {
1526                session = openSession();
1527
1528                StringBundler query = null;
1529
1530                if (orderByComparator != null) {
1531                    query = new StringBundler(5 +
1532                            (orderByComparator.getOrderByFields().length * 3));
1533                }
1534                else {
1535                    query = new StringBundler(5);
1536                }
1537
1538                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1539
1540                query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
1541
1542                query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
1543
1544                if (lastPostDate == null) {
1545                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
1546                }
1547                else {
1548                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
1549                }
1550
1551                if (orderByComparator != null) {
1552                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1553                        orderByComparator);
1554                }
1555
1556                else {
1557                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1558                }
1559
1560                String sql = query.toString();
1561
1562                Query q = session.createQuery(sql);
1563
1564                QueryPos qPos = QueryPos.getInstance(q);
1565
1566                qPos.add(groupId);
1567
1568                qPos.add(categoryId);
1569
1570                if (lastPostDate != null) {
1571                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
1572                }
1573
1574                list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1575                        end);
1576            }
1577            catch (Exception e) {
1578                throw processException(e);
1579            }
1580            finally {
1581                if (list == null) {
1582                    list = new ArrayList<MBThread>();
1583                }
1584
1585                cacheResult(list);
1586
1587                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_C_L,
1588                    finderArgs, list);
1589
1590                closeSession(session);
1591            }
1592        }
1593
1594        return list;
1595    }
1596
1597    public MBThread findByG_C_L_First(long groupId, long categoryId,
1598        Date lastPostDate, OrderByComparator orderByComparator)
1599        throws NoSuchThreadException, SystemException {
1600        List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
1601                1, orderByComparator);
1602
1603        if (list.isEmpty()) {
1604            StringBundler msg = new StringBundler(8);
1605
1606            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1607
1608            msg.append("groupId=");
1609            msg.append(groupId);
1610
1611            msg.append(", categoryId=");
1612            msg.append(categoryId);
1613
1614            msg.append(", lastPostDate=");
1615            msg.append(lastPostDate);
1616
1617            msg.append(StringPool.CLOSE_CURLY_BRACE);
1618
1619            throw new NoSuchThreadException(msg.toString());
1620        }
1621        else {
1622            return list.get(0);
1623        }
1624    }
1625
1626    public MBThread findByG_C_L_Last(long groupId, long categoryId,
1627        Date lastPostDate, OrderByComparator orderByComparator)
1628        throws NoSuchThreadException, SystemException {
1629        int count = countByG_C_L(groupId, categoryId, lastPostDate);
1630
1631        List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
1632                count - 1, count, orderByComparator);
1633
1634        if (list.isEmpty()) {
1635            StringBundler msg = new StringBundler(8);
1636
1637            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1638
1639            msg.append("groupId=");
1640            msg.append(groupId);
1641
1642            msg.append(", categoryId=");
1643            msg.append(categoryId);
1644
1645            msg.append(", lastPostDate=");
1646            msg.append(lastPostDate);
1647
1648            msg.append(StringPool.CLOSE_CURLY_BRACE);
1649
1650            throw new NoSuchThreadException(msg.toString());
1651        }
1652        else {
1653            return list.get(0);
1654        }
1655    }
1656
1657    public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
1658        long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
1659        throws NoSuchThreadException, SystemException {
1660        MBThread mbThread = findByPrimaryKey(threadId);
1661
1662        int count = countByG_C_L(groupId, categoryId, lastPostDate);
1663
1664        Session session = null;
1665
1666        try {
1667            session = openSession();
1668
1669            StringBundler query = null;
1670
1671            if (orderByComparator != null) {
1672                query = new StringBundler(5 +
1673                        (orderByComparator.getOrderByFields().length * 3));
1674            }
1675            else {
1676                query = new StringBundler(5);
1677            }
1678
1679            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1680
1681            query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
1682
1683            query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
1684
1685            if (lastPostDate == null) {
1686                query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
1687            }
1688            else {
1689                query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
1690            }
1691
1692            if (orderByComparator != null) {
1693                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1694                    orderByComparator);
1695            }
1696
1697            else {
1698                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1699            }
1700
1701            String sql = query.toString();
1702
1703            Query q = session.createQuery(sql);
1704
1705            QueryPos qPos = QueryPos.getInstance(q);
1706
1707            qPos.add(groupId);
1708
1709            qPos.add(categoryId);
1710
1711            if (lastPostDate != null) {
1712                qPos.add(CalendarUtil.getTimestamp(lastPostDate));
1713            }
1714
1715            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1716                    orderByComparator, mbThread);
1717
1718            MBThread[] array = new MBThreadImpl[3];
1719
1720            array[0] = (MBThread)objArray[0];
1721            array[1] = (MBThread)objArray[1];
1722            array[2] = (MBThread)objArray[2];
1723
1724            return array;
1725        }
1726        catch (Exception e) {
1727            throw processException(e);
1728        }
1729        finally {
1730            closeSession(session);
1731        }
1732    }
1733
1734    public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
1735        throws SystemException {
1736        Object[] finderArgs = new Object[] {
1737                new Long(groupId), new Long(categoryId), new Integer(status)
1738            };
1739
1740        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_C_S,
1741                finderArgs, this);
1742
1743        if (list == null) {
1744            Session session = null;
1745
1746            try {
1747                session = openSession();
1748
1749                StringBundler query = new StringBundler(5);
1750
1751                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1752
1753                query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
1754
1755                query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
1756
1757                query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
1758
1759                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1760
1761                String sql = query.toString();
1762
1763                Query q = session.createQuery(sql);
1764
1765                QueryPos qPos = QueryPos.getInstance(q);
1766
1767                qPos.add(groupId);
1768
1769                qPos.add(categoryId);
1770
1771                qPos.add(status);
1772
1773                list = q.list();
1774            }
1775            catch (Exception e) {
1776                throw processException(e);
1777            }
1778            finally {
1779                if (list == null) {
1780                    list = new ArrayList<MBThread>();
1781                }
1782
1783                cacheResult(list);
1784
1785                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_C_S,
1786                    finderArgs, list);
1787
1788                closeSession(session);
1789            }
1790        }
1791
1792        return list;
1793    }
1794
1795    public List<MBThread> findByG_C_S(long groupId, long categoryId,
1796        int status, int start, int end) throws SystemException {
1797        return findByG_C_S(groupId, categoryId, status, start, end, null);
1798    }
1799
1800    public List<MBThread> findByG_C_S(long groupId, long categoryId,
1801        int status, int start, int end, OrderByComparator orderByComparator)
1802        throws SystemException {
1803        Object[] finderArgs = new Object[] {
1804                new Long(groupId), new Long(categoryId), new Integer(status),
1805                
1806                String.valueOf(start), String.valueOf(end),
1807                String.valueOf(orderByComparator)
1808            };
1809
1810        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_C_S,
1811                finderArgs, this);
1812
1813        if (list == null) {
1814            Session session = null;
1815
1816            try {
1817                session = openSession();
1818
1819                StringBundler query = null;
1820
1821                if (orderByComparator != null) {
1822                    query = new StringBundler(5 +
1823                            (orderByComparator.getOrderByFields().length * 3));
1824                }
1825                else {
1826                    query = new StringBundler(5);
1827                }
1828
1829                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1830
1831                query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
1832
1833                query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
1834
1835                query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
1836
1837                if (orderByComparator != null) {
1838                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1839                        orderByComparator);
1840                }
1841
1842                else {
1843                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1844                }
1845
1846                String sql = query.toString();
1847
1848                Query q = session.createQuery(sql);
1849
1850                QueryPos qPos = QueryPos.getInstance(q);
1851
1852                qPos.add(groupId);
1853
1854                qPos.add(categoryId);
1855
1856                qPos.add(status);
1857
1858                list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1859                        end);
1860            }
1861            catch (Exception e) {
1862                throw processException(e);
1863            }
1864            finally {
1865                if (list == null) {
1866                    list = new ArrayList<MBThread>();
1867                }
1868
1869                cacheResult(list);
1870
1871                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_C_S,
1872                    finderArgs, list);
1873
1874                closeSession(session);
1875            }
1876        }
1877
1878        return list;
1879    }
1880
1881    public MBThread findByG_C_S_First(long groupId, long categoryId,
1882        int status, OrderByComparator orderByComparator)
1883        throws NoSuchThreadException, SystemException {
1884        List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
1885                orderByComparator);
1886
1887        if (list.isEmpty()) {
1888            StringBundler msg = new StringBundler(8);
1889
1890            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1891
1892            msg.append("groupId=");
1893            msg.append(groupId);
1894
1895            msg.append(", categoryId=");
1896            msg.append(categoryId);
1897
1898            msg.append(", status=");
1899            msg.append(status);
1900
1901            msg.append(StringPool.CLOSE_CURLY_BRACE);
1902
1903            throw new NoSuchThreadException(msg.toString());
1904        }
1905        else {
1906            return list.get(0);
1907        }
1908    }
1909
1910    public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
1911        OrderByComparator orderByComparator)
1912        throws NoSuchThreadException, SystemException {
1913        int count = countByG_C_S(groupId, categoryId, status);
1914
1915        List<MBThread> list = findByG_C_S(groupId, categoryId, status,
1916                count - 1, count, orderByComparator);
1917
1918        if (list.isEmpty()) {
1919            StringBundler msg = new StringBundler(8);
1920
1921            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1922
1923            msg.append("groupId=");
1924            msg.append(groupId);
1925
1926            msg.append(", categoryId=");
1927            msg.append(categoryId);
1928
1929            msg.append(", status=");
1930            msg.append(status);
1931
1932            msg.append(StringPool.CLOSE_CURLY_BRACE);
1933
1934            throw new NoSuchThreadException(msg.toString());
1935        }
1936        else {
1937            return list.get(0);
1938        }
1939    }
1940
1941    public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
1942        long categoryId, int status, OrderByComparator orderByComparator)
1943        throws NoSuchThreadException, SystemException {
1944        MBThread mbThread = findByPrimaryKey(threadId);
1945
1946        int count = countByG_C_S(groupId, categoryId, status);
1947
1948        Session session = null;
1949
1950        try {
1951            session = openSession();
1952
1953            StringBundler query = null;
1954
1955            if (orderByComparator != null) {
1956                query = new StringBundler(5 +
1957                        (orderByComparator.getOrderByFields().length * 3));
1958            }
1959            else {
1960                query = new StringBundler(5);
1961            }
1962
1963            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1964
1965            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
1966
1967            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
1968
1969            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
1970
1971            if (orderByComparator != null) {
1972                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1973                    orderByComparator);
1974            }
1975
1976            else {
1977                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1978            }
1979
1980            String sql = query.toString();
1981
1982            Query q = session.createQuery(sql);
1983
1984            QueryPos qPos = QueryPos.getInstance(q);
1985
1986            qPos.add(groupId);
1987
1988            qPos.add(categoryId);
1989
1990            qPos.add(status);
1991
1992            Object[] objArray = QueryUtil.getPrevAndNext(q, count,
1993                    orderByComparator, mbThread);
1994
1995            MBThread[] array = new MBThreadImpl[3];
1996
1997            array[0] = (MBThread)objArray[0];
1998            array[1] = (MBThread)objArray[1];
1999            array[2] = (MBThread)objArray[2];
2000
2001            return array;
2002        }
2003        catch (Exception e) {
2004            throw processException(e);
2005        }
2006        finally {
2007            closeSession(session);
2008        }
2009    }
2010
2011    public List<MBThread> findAll() throws SystemException {
2012        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2013    }
2014
2015    public List<MBThread> findAll(int start, int end) throws SystemException {
2016        return findAll(start, end, null);
2017    }
2018
2019    public List<MBThread> findAll(int start, int end,
2020        OrderByComparator orderByComparator) throws SystemException {
2021        Object[] finderArgs = new Object[] {
2022                String.valueOf(start), String.valueOf(end),
2023                String.valueOf(orderByComparator)
2024            };
2025
2026        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2027                finderArgs, this);
2028
2029        if (list == null) {
2030            Session session = null;
2031
2032            try {
2033                session = openSession();
2034
2035                StringBundler query = null;
2036                String sql = null;
2037
2038                if (orderByComparator != null) {
2039                    query = new StringBundler(2 +
2040                            (orderByComparator.getOrderByFields().length * 3));
2041
2042                    query.append(_SQL_SELECT_MBTHREAD);
2043
2044                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2045                        orderByComparator);
2046
2047                    sql = query.toString();
2048                }
2049
2050                else {
2051                    sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
2052                }
2053
2054                Query q = session.createQuery(sql);
2055
2056                if (orderByComparator == null) {
2057                    list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2058                            start, end, false);
2059
2060                    Collections.sort(list);
2061                }
2062                else {
2063                    list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2064                            start, end);
2065                }
2066            }
2067            catch (Exception e) {
2068                throw processException(e);
2069            }
2070            finally {
2071                if (list == null) {
2072                    list = new ArrayList<MBThread>();
2073                }
2074
2075                cacheResult(list);
2076
2077                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2078
2079                closeSession(session);
2080            }
2081        }
2082
2083        return list;
2084    }
2085
2086    public void removeByGroupId(long groupId) throws SystemException {
2087        for (MBThread mbThread : findByGroupId(groupId)) {
2088            remove(mbThread);
2089        }
2090    }
2091
2092    public void removeByG_C(long groupId, long categoryId)
2093        throws SystemException {
2094        for (MBThread mbThread : findByG_C(groupId, categoryId)) {
2095            remove(mbThread);
2096        }
2097    }
2098
2099    public void removeByG_S(long groupId, int status) throws SystemException {
2100        for (MBThread mbThread : findByG_S(groupId, status)) {
2101            remove(mbThread);
2102        }
2103    }
2104
2105    public void removeByC_P(long categoryId, double priority)
2106        throws SystemException {
2107        for (MBThread mbThread : findByC_P(categoryId, priority)) {
2108            remove(mbThread);
2109        }
2110    }
2111
2112    public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
2113        throws SystemException {
2114        for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate)) {
2115            remove(mbThread);
2116        }
2117    }
2118
2119    public void removeByG_C_S(long groupId, long categoryId, int status)
2120        throws SystemException {
2121        for (MBThread mbThread : findByG_C_S(groupId, categoryId, status)) {
2122            remove(mbThread);
2123        }
2124    }
2125
2126    public void removeAll() throws SystemException {
2127        for (MBThread mbThread : findAll()) {
2128            remove(mbThread);
2129        }
2130    }
2131
2132    public int countByGroupId(long groupId) throws SystemException {
2133        Object[] finderArgs = new Object[] { new Long(groupId) };
2134
2135        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2136                finderArgs, this);
2137
2138        if (count == null) {
2139            Session session = null;
2140
2141            try {
2142                session = openSession();
2143
2144                StringBundler query = new StringBundler(2);
2145
2146                query.append(_SQL_COUNT_MBTHREAD_WHERE);
2147
2148                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2149
2150                String sql = query.toString();
2151
2152                Query q = session.createQuery(sql);
2153
2154                QueryPos qPos = QueryPos.getInstance(q);
2155
2156                qPos.add(groupId);
2157
2158                count = (Long)q.uniqueResult();
2159            }
2160            catch (Exception e) {
2161                throw processException(e);
2162            }
2163            finally {
2164                if (count == null) {
2165                    count = Long.valueOf(0);
2166                }
2167
2168                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2169                    finderArgs, count);
2170
2171                closeSession(session);
2172            }
2173        }
2174
2175        return count.intValue();
2176    }
2177
2178    public int countByG_C(long groupId, long categoryId)
2179        throws SystemException {
2180        Object[] finderArgs = new Object[] {
2181                new Long(groupId), new Long(categoryId)
2182            };
2183
2184        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C,
2185                finderArgs, this);
2186
2187        if (count == null) {
2188            Session session = null;
2189
2190            try {
2191                session = openSession();
2192
2193                StringBundler query = new StringBundler(3);
2194
2195                query.append(_SQL_COUNT_MBTHREAD_WHERE);
2196
2197                query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2198
2199                query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2200
2201                String sql = query.toString();
2202
2203                Query q = session.createQuery(sql);
2204
2205                QueryPos qPos = QueryPos.getInstance(q);
2206
2207                qPos.add(groupId);
2208
2209                qPos.add(categoryId);
2210
2211                count = (Long)q.uniqueResult();
2212            }
2213            catch (Exception e) {
2214                throw processException(e);
2215            }
2216            finally {
2217                if (count == null) {
2218                    count = Long.valueOf(0);
2219                }
2220
2221                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C, finderArgs,
2222                    count);
2223
2224                closeSession(session);
2225            }
2226        }
2227
2228        return count.intValue();
2229    }
2230
2231    public int countByG_S(long groupId, int status) throws SystemException {
2232        Object[] finderArgs = new Object[] {
2233                new Long(groupId), new Integer(status)
2234            };
2235
2236        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_S,
2237                finderArgs, this);
2238
2239        if (count == null) {
2240            Session session = null;
2241
2242            try {
2243                session = openSession();
2244
2245                StringBundler query = new StringBundler(3);
2246
2247                query.append(_SQL_COUNT_MBTHREAD_WHERE);
2248
2249                query.append(_FINDER_COLUMN_G_S_GROUPID_2);
2250
2251                query.append(_FINDER_COLUMN_G_S_STATUS_2);
2252
2253                String sql = query.toString();
2254
2255                Query q = session.createQuery(sql);
2256
2257                QueryPos qPos = QueryPos.getInstance(q);
2258
2259                qPos.add(groupId);
2260
2261                qPos.add(status);
2262
2263                count = (Long)q.uniqueResult();
2264            }
2265            catch (Exception e) {
2266                throw processException(e);
2267            }
2268            finally {
2269                if (count == null) {
2270                    count = Long.valueOf(0);
2271                }
2272
2273                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_S, finderArgs,
2274                    count);
2275
2276                closeSession(session);
2277            }
2278        }
2279
2280        return count.intValue();
2281    }
2282
2283    public int countByC_P(long categoryId, double priority)
2284        throws SystemException {
2285        Object[] finderArgs = new Object[] {
2286                new Long(categoryId), new Double(priority)
2287            };
2288
2289        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
2290                finderArgs, this);
2291
2292        if (count == null) {
2293            Session session = null;
2294
2295            try {
2296                session = openSession();
2297
2298                StringBundler query = new StringBundler(3);
2299
2300                query.append(_SQL_COUNT_MBTHREAD_WHERE);
2301
2302                query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
2303
2304                query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
2305
2306                String sql = query.toString();
2307
2308                Query q = session.createQuery(sql);
2309
2310                QueryPos qPos = QueryPos.getInstance(q);
2311
2312                qPos.add(categoryId);
2313
2314                qPos.add(priority);
2315
2316                count = (Long)q.uniqueResult();
2317            }
2318            catch (Exception e) {
2319                throw processException(e);
2320            }
2321            finally {
2322                if (count == null) {
2323                    count = Long.valueOf(0);
2324                }
2325
2326                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
2327                    count);
2328
2329                closeSession(session);
2330            }
2331        }
2332
2333        return count.intValue();
2334    }
2335
2336    public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
2337        throws SystemException {
2338        Object[] finderArgs = new Object[] {
2339                new Long(groupId), new Long(categoryId),
2340                
2341                lastPostDate
2342            };
2343
2344        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_L,
2345                finderArgs, this);
2346
2347        if (count == null) {
2348            Session session = null;
2349
2350            try {
2351                session = openSession();
2352
2353                StringBundler query = new StringBundler(4);
2354
2355                query.append(_SQL_COUNT_MBTHREAD_WHERE);
2356
2357                query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
2358
2359                query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
2360
2361                if (lastPostDate == null) {
2362                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
2363                }
2364                else {
2365                    query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
2366                }
2367
2368                String sql = query.toString();
2369
2370                Query q = session.createQuery(sql);
2371
2372                QueryPos qPos = QueryPos.getInstance(q);
2373
2374                qPos.add(groupId);
2375
2376                qPos.add(categoryId);
2377
2378                if (lastPostDate != null) {
2379                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
2380                }
2381
2382                count = (Long)q.uniqueResult();
2383            }
2384            catch (Exception e) {
2385                throw processException(e);
2386            }
2387            finally {
2388                if (count == null) {
2389                    count = Long.valueOf(0);
2390                }
2391
2392                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_L,
2393                    finderArgs, count);
2394
2395                closeSession(session);
2396            }
2397        }
2398
2399        return count.intValue();
2400    }
2401
2402    public int countByG_C_S(long groupId, long categoryId, int status)
2403        throws SystemException {
2404        Object[] finderArgs = new Object[] {
2405                new Long(groupId), new Long(categoryId), new Integer(status)
2406            };
2407
2408        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_C_S,
2409                finderArgs, this);
2410
2411        if (count == null) {
2412            Session session = null;
2413
2414            try {
2415                session = openSession();
2416
2417                StringBundler query = new StringBundler(4);
2418
2419                query.append(_SQL_COUNT_MBTHREAD_WHERE);
2420
2421                query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
2422
2423                query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
2424
2425                query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
2426
2427                String sql = query.toString();
2428
2429                Query q = session.createQuery(sql);
2430
2431                QueryPos qPos = QueryPos.getInstance(q);
2432
2433                qPos.add(groupId);
2434
2435                qPos.add(categoryId);
2436
2437                qPos.add(status);
2438
2439                count = (Long)q.uniqueResult();
2440            }
2441            catch (Exception e) {
2442                throw processException(e);
2443            }
2444            finally {
2445                if (count == null) {
2446                    count = Long.valueOf(0);
2447                }
2448
2449                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_C_S,
2450                    finderArgs, count);
2451
2452                closeSession(session);
2453            }
2454        }
2455
2456        return count.intValue();
2457    }
2458
2459    public int countAll() throws SystemException {
2460        Object[] finderArgs = new Object[0];
2461
2462        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2463                finderArgs, this);
2464
2465        if (count == null) {
2466            Session session = null;
2467
2468            try {
2469                session = openSession();
2470
2471                Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
2472
2473                count = (Long)q.uniqueResult();
2474            }
2475            catch (Exception e) {
2476                throw processException(e);
2477            }
2478            finally {
2479                if (count == null) {
2480                    count = Long.valueOf(0);
2481                }
2482
2483                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2484                    count);
2485
2486                closeSession(session);
2487            }
2488        }
2489
2490        return count.intValue();
2491    }
2492
2493    public void afterPropertiesSet() {
2494        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2495                    com.liferay.portal.util.PropsUtil.get(
2496                        "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
2497
2498        if (listenerClassNames.length > 0) {
2499            try {
2500                List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
2501
2502                for (String listenerClassName : listenerClassNames) {
2503                    listenersList.add((ModelListener<MBThread>)Class.forName(
2504                            listenerClassName).newInstance());
2505                }
2506
2507                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2508            }
2509            catch (Exception e) {
2510                _log.error(e);
2511            }
2512        }
2513    }
2514
2515    @BeanReference(type = MBBanPersistence.class)
2516    protected MBBanPersistence mbBanPersistence;
2517    @BeanReference(type = MBCategoryPersistence.class)
2518    protected MBCategoryPersistence mbCategoryPersistence;
2519    @BeanReference(type = MBDiscussionPersistence.class)
2520    protected MBDiscussionPersistence mbDiscussionPersistence;
2521    @BeanReference(type = MBMailingListPersistence.class)
2522    protected MBMailingListPersistence mbMailingListPersistence;
2523    @BeanReference(type = MBMessagePersistence.class)
2524    protected MBMessagePersistence mbMessagePersistence;
2525    @BeanReference(type = MBMessageFlagPersistence.class)
2526    protected MBMessageFlagPersistence mbMessageFlagPersistence;
2527    @BeanReference(type = MBStatsUserPersistence.class)
2528    protected MBStatsUserPersistence mbStatsUserPersistence;
2529    @BeanReference(type = MBThreadPersistence.class)
2530    protected MBThreadPersistence mbThreadPersistence;
2531    @BeanReference(type = LockPersistence.class)
2532    protected LockPersistence lockPersistence;
2533    @BeanReference(type = ResourcePersistence.class)
2534    protected ResourcePersistence resourcePersistence;
2535    @BeanReference(type = UserPersistence.class)
2536    protected UserPersistence userPersistence;
2537    @BeanReference(type = AssetEntryPersistence.class)
2538    protected AssetEntryPersistence assetEntryPersistence;
2539    @BeanReference(type = RatingsStatsPersistence.class)
2540    protected RatingsStatsPersistence ratingsStatsPersistence;
2541    @BeanReference(type = SocialActivityPersistence.class)
2542    protected SocialActivityPersistence socialActivityPersistence;
2543    private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
2544    private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
2545    private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
2546    private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
2547    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ?";
2548    private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
2549    private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
2550    private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
2551    private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ?";
2552    private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
2553    private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
2554    private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
2555    private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
2556    private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
2557    private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
2558    private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
2559    private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
2560    private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
2561    private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
2562    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
2563    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
2564    private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
2565}