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