1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   * 
13   */
14  
15  package com.liferay.portlet.messageboards.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.SystemException;
19  import com.liferay.portal.kernel.annotation.BeanReference;
20  import com.liferay.portal.kernel.cache.CacheRegistry;
21  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
22  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24  import com.liferay.portal.kernel.dao.orm.FinderPath;
25  import com.liferay.portal.kernel.dao.orm.Query;
26  import com.liferay.portal.kernel.dao.orm.QueryPos;
27  import com.liferay.portal.kernel.dao.orm.QueryUtil;
28  import com.liferay.portal.kernel.dao.orm.Session;
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_CATEGORYID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
87              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
88              "findByCategoryId", new String[] { Long.class.getName() });
89      public static final FinderPath FINDER_PATH_FIND_BY_OBC_CATEGORYID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
90              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
91              "findByCategoryId",
92              new String[] {
93                  Long.class.getName(),
94                  
95              "java.lang.Integer", "java.lang.Integer",
96                  "com.liferay.portal.kernel.util.OrderByComparator"
97              });
98      public static final FinderPath FINDER_PATH_COUNT_BY_CATEGORYID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
99              MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100             "countByCategoryId", new String[] { Long.class.getName() });
101     public static final FinderPath FINDER_PATH_FIND_BY_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
102             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103             "findByC_L",
104             new String[] { Long.class.getName(), Date.class.getName() });
105     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
106             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107             "findByC_L",
108             new String[] {
109                 Long.class.getName(), Date.class.getName(),
110                 
111             "java.lang.Integer", "java.lang.Integer",
112                 "com.liferay.portal.kernel.util.OrderByComparator"
113             });
114     public static final FinderPath FINDER_PATH_COUNT_BY_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
115             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116             "countByC_L",
117             new String[] { Long.class.getName(), Date.class.getName() });
118     public static final FinderPath FINDER_PATH_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
119             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120             "findByC_P",
121             new String[] { Long.class.getName(), Double.class.getName() });
122     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
123             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124             "findByC_P",
125             new String[] {
126                 Long.class.getName(), Double.class.getName(),
127                 
128             "java.lang.Integer", "java.lang.Integer",
129                 "com.liferay.portal.kernel.util.OrderByComparator"
130             });
131     public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
132             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133             "countByC_P",
134             new String[] { Long.class.getName(), Double.class.getName() });
135     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
136             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137             "findAll", new String[0]);
138     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
139             MBThreadModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
140             "countAll", new String[0]);
141 
142     public void cacheResult(MBThread mbThread) {
143         EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
144             MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
145     }
146 
147     public void cacheResult(List<MBThread> mbThreads) {
148         for (MBThread mbThread : mbThreads) {
149             if (EntityCacheUtil.getResult(
150                         MBThreadModelImpl.ENTITY_CACHE_ENABLED,
151                         MBThreadImpl.class, mbThread.getPrimaryKey(), this) == null) {
152                 cacheResult(mbThread);
153             }
154         }
155     }
156 
157     public void clearCache() {
158         CacheRegistry.clear(MBThreadImpl.class.getName());
159         EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
160         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
161         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
162     }
163 
164     public MBThread create(long threadId) {
165         MBThread mbThread = new MBThreadImpl();
166 
167         mbThread.setNew(true);
168         mbThread.setPrimaryKey(threadId);
169 
170         return mbThread;
171     }
172 
173     public MBThread remove(Serializable primaryKey)
174         throws NoSuchModelException, SystemException {
175         return remove(((Long)primaryKey).longValue());
176     }
177 
178     public MBThread remove(long threadId)
179         throws NoSuchThreadException, SystemException {
180         Session session = null;
181 
182         try {
183             session = openSession();
184 
185             MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
186                     new Long(threadId));
187 
188             if (mbThread == null) {
189                 if (_log.isWarnEnabled()) {
190                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
191                 }
192 
193                 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
194                     threadId);
195             }
196 
197             return remove(mbThread);
198         }
199         catch (NoSuchThreadException nsee) {
200             throw nsee;
201         }
202         catch (Exception e) {
203             throw processException(e);
204         }
205         finally {
206             closeSession(session);
207         }
208     }
209 
210     public MBThread remove(MBThread mbThread) throws SystemException {
211         for (ModelListener<MBThread> listener : listeners) {
212             listener.onBeforeRemove(mbThread);
213         }
214 
215         mbThread = removeImpl(mbThread);
216 
217         for (ModelListener<MBThread> listener : listeners) {
218             listener.onAfterRemove(mbThread);
219         }
220 
221         return mbThread;
222     }
223 
224     protected MBThread removeImpl(MBThread mbThread) throws SystemException {
225         mbThread = toUnwrappedModel(mbThread);
226 
227         Session session = null;
228 
229         try {
230             session = openSession();
231 
232             if (mbThread.isCachedModel() || BatchSessionUtil.isEnabled()) {
233                 Object staleObject = session.get(MBThreadImpl.class,
234                         mbThread.getPrimaryKeyObj());
235 
236                 if (staleObject != null) {
237                     session.evict(staleObject);
238                 }
239             }
240 
241             session.delete(mbThread);
242 
243             session.flush();
244         }
245         catch (Exception e) {
246             throw processException(e);
247         }
248         finally {
249             closeSession(session);
250         }
251 
252         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
253 
254         EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
255             MBThreadImpl.class, mbThread.getPrimaryKey());
256 
257         return mbThread;
258     }
259 
260     /**
261      * @deprecated Use {@link BasePersistence#update(com.liferay.portal.model.BaseModel, boolean)}.
262      */
263     public MBThread update(MBThread mbThread) throws SystemException {
264         if (_log.isWarnEnabled()) {
265             _log.warn(
266                 "Using the deprecated update(MBThread mbThread) method. Use update(MBThread mbThread, boolean merge) instead.");
267         }
268 
269         return update(mbThread, false);
270     }
271 
272     public MBThread updateImpl(
273         com.liferay.portlet.messageboards.model.MBThread mbThread, boolean merge)
274         throws SystemException {
275         mbThread = toUnwrappedModel(mbThread);
276 
277         Session session = null;
278 
279         try {
280             session = openSession();
281 
282             BatchSessionUtil.update(session, mbThread, merge);
283 
284             mbThread.setNew(false);
285         }
286         catch (Exception e) {
287             throw processException(e);
288         }
289         finally {
290             closeSession(session);
291         }
292 
293         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
294 
295         EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
296             MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
297 
298         return mbThread;
299     }
300 
301     protected MBThread toUnwrappedModel(MBThread mbThread) {
302         if (mbThread instanceof MBThreadImpl) {
303             return mbThread;
304         }
305 
306         MBThreadImpl mbThreadImpl = new MBThreadImpl();
307 
308         mbThreadImpl.setNew(mbThread.isNew());
309         mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
310 
311         mbThreadImpl.setThreadId(mbThread.getThreadId());
312         mbThreadImpl.setGroupId(mbThread.getGroupId());
313         mbThreadImpl.setCategoryId(mbThread.getCategoryId());
314         mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
315         mbThreadImpl.setMessageCount(mbThread.getMessageCount());
316         mbThreadImpl.setViewCount(mbThread.getViewCount());
317         mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
318         mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
319         mbThreadImpl.setPriority(mbThread.getPriority());
320 
321         return mbThreadImpl;
322     }
323 
324     public MBThread findByPrimaryKey(Serializable primaryKey)
325         throws NoSuchModelException, SystemException {
326         return findByPrimaryKey(((Long)primaryKey).longValue());
327     }
328 
329     public MBThread findByPrimaryKey(long threadId)
330         throws NoSuchThreadException, SystemException {
331         MBThread mbThread = fetchByPrimaryKey(threadId);
332 
333         if (mbThread == null) {
334             if (_log.isWarnEnabled()) {
335                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
336             }
337 
338             throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
339                 threadId);
340         }
341 
342         return mbThread;
343     }
344 
345     public MBThread fetchByPrimaryKey(Serializable primaryKey)
346         throws SystemException {
347         return fetchByPrimaryKey(((Long)primaryKey).longValue());
348     }
349 
350     public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
351         MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
352                 MBThreadImpl.class, threadId, this);
353 
354         if (mbThread == null) {
355             Session session = null;
356 
357             try {
358                 session = openSession();
359 
360                 mbThread = (MBThread)session.get(MBThreadImpl.class,
361                         new Long(threadId));
362             }
363             catch (Exception e) {
364                 throw processException(e);
365             }
366             finally {
367                 if (mbThread != null) {
368                     cacheResult(mbThread);
369                 }
370 
371                 closeSession(session);
372             }
373         }
374 
375         return mbThread;
376     }
377 
378     public List<MBThread> findByGroupId(long groupId) throws SystemException {
379         Object[] finderArgs = new Object[] { new Long(groupId) };
380 
381         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
382                 finderArgs, this);
383 
384         if (list == null) {
385             Session session = null;
386 
387             try {
388                 session = openSession();
389 
390                 StringBundler query = new StringBundler(3);
391 
392                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
393 
394                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
395 
396                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
397 
398                 String sql = query.toString();
399 
400                 Query q = session.createQuery(sql);
401 
402                 QueryPos qPos = QueryPos.getInstance(q);
403 
404                 qPos.add(groupId);
405 
406                 list = q.list();
407             }
408             catch (Exception e) {
409                 throw processException(e);
410             }
411             finally {
412                 if (list == null) {
413                     list = new ArrayList<MBThread>();
414                 }
415 
416                 cacheResult(list);
417 
418                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
419                     finderArgs, list);
420 
421                 closeSession(session);
422             }
423         }
424 
425         return list;
426     }
427 
428     public List<MBThread> findByGroupId(long groupId, int start, int end)
429         throws SystemException {
430         return findByGroupId(groupId, start, end, null);
431     }
432 
433     public List<MBThread> findByGroupId(long groupId, int start, int end,
434         OrderByComparator obc) throws SystemException {
435         Object[] finderArgs = new Object[] {
436                 new Long(groupId),
437                 
438                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
439             };
440 
441         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
442                 finderArgs, this);
443 
444         if (list == null) {
445             Session session = null;
446 
447             try {
448                 session = openSession();
449 
450                 StringBundler query = null;
451 
452                 if (obc != null) {
453                     query = new StringBundler(3 +
454                             (obc.getOrderByFields().length * 3));
455                 }
456                 else {
457                     query = new StringBundler(3);
458                 }
459 
460                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
461 
462                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
463 
464                 if (obc != null) {
465                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
466                 }
467 
468                 else {
469                     query.append(MBThreadModelImpl.ORDER_BY_JPQL);
470                 }
471 
472                 String sql = query.toString();
473 
474                 Query q = session.createQuery(sql);
475 
476                 QueryPos qPos = QueryPos.getInstance(q);
477 
478                 qPos.add(groupId);
479 
480                 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
481                         end);
482             }
483             catch (Exception e) {
484                 throw processException(e);
485             }
486             finally {
487                 if (list == null) {
488                     list = new ArrayList<MBThread>();
489                 }
490 
491                 cacheResult(list);
492 
493                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
494                     finderArgs, list);
495 
496                 closeSession(session);
497             }
498         }
499 
500         return list;
501     }
502 
503     public MBThread findByGroupId_First(long groupId, OrderByComparator obc)
504         throws NoSuchThreadException, SystemException {
505         List<MBThread> list = findByGroupId(groupId, 0, 1, obc);
506 
507         if (list.isEmpty()) {
508             StringBundler msg = new StringBundler(4);
509 
510             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
511 
512             msg.append("groupId=");
513             msg.append(groupId);
514 
515             msg.append(StringPool.CLOSE_CURLY_BRACE);
516 
517             throw new NoSuchThreadException(msg.toString());
518         }
519         else {
520             return list.get(0);
521         }
522     }
523 
524     public MBThread findByGroupId_Last(long groupId, OrderByComparator obc)
525         throws NoSuchThreadException, SystemException {
526         int count = countByGroupId(groupId);
527 
528         List<MBThread> list = findByGroupId(groupId, count - 1, count, obc);
529 
530         if (list.isEmpty()) {
531             StringBundler msg = new StringBundler(4);
532 
533             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
534 
535             msg.append("groupId=");
536             msg.append(groupId);
537 
538             msg.append(StringPool.CLOSE_CURLY_BRACE);
539 
540             throw new NoSuchThreadException(msg.toString());
541         }
542         else {
543             return list.get(0);
544         }
545     }
546 
547     public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
548         OrderByComparator obc) throws NoSuchThreadException, SystemException {
549         MBThread mbThread = findByPrimaryKey(threadId);
550 
551         int count = countByGroupId(groupId);
552 
553         Session session = null;
554 
555         try {
556             session = openSession();
557 
558             StringBundler query = null;
559 
560             if (obc != null) {
561                 query = new StringBundler(3 +
562                         (obc.getOrderByFields().length * 3));
563             }
564             else {
565                 query = new StringBundler(3);
566             }
567 
568             query.append(_SQL_SELECT_MBTHREAD_WHERE);
569 
570             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
571 
572             if (obc != null) {
573                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
574             }
575 
576             else {
577                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
578             }
579 
580             String sql = query.toString();
581 
582             Query q = session.createQuery(sql);
583 
584             QueryPos qPos = QueryPos.getInstance(q);
585 
586             qPos.add(groupId);
587 
588             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, mbThread);
589 
590             MBThread[] array = new MBThreadImpl[3];
591 
592             array[0] = (MBThread)objArray[0];
593             array[1] = (MBThread)objArray[1];
594             array[2] = (MBThread)objArray[2];
595 
596             return array;
597         }
598         catch (Exception e) {
599             throw processException(e);
600         }
601         finally {
602             closeSession(session);
603         }
604     }
605 
606     public List<MBThread> findByCategoryId(long categoryId)
607         throws SystemException {
608         Object[] finderArgs = new Object[] { new Long(categoryId) };
609 
610         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CATEGORYID,
611                 finderArgs, this);
612 
613         if (list == null) {
614             Session session = null;
615 
616             try {
617                 session = openSession();
618 
619                 StringBundler query = new StringBundler(3);
620 
621                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
622 
623                 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
624 
625                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
626 
627                 String sql = query.toString();
628 
629                 Query q = session.createQuery(sql);
630 
631                 QueryPos qPos = QueryPos.getInstance(q);
632 
633                 qPos.add(categoryId);
634 
635                 list = q.list();
636             }
637             catch (Exception e) {
638                 throw processException(e);
639             }
640             finally {
641                 if (list == null) {
642                     list = new ArrayList<MBThread>();
643                 }
644 
645                 cacheResult(list);
646 
647                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CATEGORYID,
648                     finderArgs, list);
649 
650                 closeSession(session);
651             }
652         }
653 
654         return list;
655     }
656 
657     public List<MBThread> findByCategoryId(long categoryId, int start, int end)
658         throws SystemException {
659         return findByCategoryId(categoryId, start, end, null);
660     }
661 
662     public List<MBThread> findByCategoryId(long categoryId, int start, int end,
663         OrderByComparator obc) throws SystemException {
664         Object[] finderArgs = new Object[] {
665                 new Long(categoryId),
666                 
667                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
668             };
669 
670         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_CATEGORYID,
671                 finderArgs, this);
672 
673         if (list == null) {
674             Session session = null;
675 
676             try {
677                 session = openSession();
678 
679                 StringBundler query = null;
680 
681                 if (obc != null) {
682                     query = new StringBundler(3 +
683                             (obc.getOrderByFields().length * 3));
684                 }
685                 else {
686                     query = new StringBundler(3);
687                 }
688 
689                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
690 
691                 query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
692 
693                 if (obc != null) {
694                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
695                 }
696 
697                 else {
698                     query.append(MBThreadModelImpl.ORDER_BY_JPQL);
699                 }
700 
701                 String sql = query.toString();
702 
703                 Query q = session.createQuery(sql);
704 
705                 QueryPos qPos = QueryPos.getInstance(q);
706 
707                 qPos.add(categoryId);
708 
709                 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
710                         end);
711             }
712             catch (Exception e) {
713                 throw processException(e);
714             }
715             finally {
716                 if (list == null) {
717                     list = new ArrayList<MBThread>();
718                 }
719 
720                 cacheResult(list);
721 
722                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_CATEGORYID,
723                     finderArgs, list);
724 
725                 closeSession(session);
726             }
727         }
728 
729         return list;
730     }
731 
732     public MBThread findByCategoryId_First(long categoryId,
733         OrderByComparator obc) throws NoSuchThreadException, SystemException {
734         List<MBThread> list = findByCategoryId(categoryId, 0, 1, obc);
735 
736         if (list.isEmpty()) {
737             StringBundler msg = new StringBundler(4);
738 
739             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
740 
741             msg.append("categoryId=");
742             msg.append(categoryId);
743 
744             msg.append(StringPool.CLOSE_CURLY_BRACE);
745 
746             throw new NoSuchThreadException(msg.toString());
747         }
748         else {
749             return list.get(0);
750         }
751     }
752 
753     public MBThread findByCategoryId_Last(long categoryId, OrderByComparator obc)
754         throws NoSuchThreadException, SystemException {
755         int count = countByCategoryId(categoryId);
756 
757         List<MBThread> list = findByCategoryId(categoryId, count - 1, count, obc);
758 
759         if (list.isEmpty()) {
760             StringBundler msg = new StringBundler(4);
761 
762             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
763 
764             msg.append("categoryId=");
765             msg.append(categoryId);
766 
767             msg.append(StringPool.CLOSE_CURLY_BRACE);
768 
769             throw new NoSuchThreadException(msg.toString());
770         }
771         else {
772             return list.get(0);
773         }
774     }
775 
776     public MBThread[] findByCategoryId_PrevAndNext(long threadId,
777         long categoryId, OrderByComparator obc)
778         throws NoSuchThreadException, SystemException {
779         MBThread mbThread = findByPrimaryKey(threadId);
780 
781         int count = countByCategoryId(categoryId);
782 
783         Session session = null;
784 
785         try {
786             session = openSession();
787 
788             StringBundler query = null;
789 
790             if (obc != null) {
791                 query = new StringBundler(3 +
792                         (obc.getOrderByFields().length * 3));
793             }
794             else {
795                 query = new StringBundler(3);
796             }
797 
798             query.append(_SQL_SELECT_MBTHREAD_WHERE);
799 
800             query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
801 
802             if (obc != null) {
803                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
804             }
805 
806             else {
807                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
808             }
809 
810             String sql = query.toString();
811 
812             Query q = session.createQuery(sql);
813 
814             QueryPos qPos = QueryPos.getInstance(q);
815 
816             qPos.add(categoryId);
817 
818             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, mbThread);
819 
820             MBThread[] array = new MBThreadImpl[3];
821 
822             array[0] = (MBThread)objArray[0];
823             array[1] = (MBThread)objArray[1];
824             array[2] = (MBThread)objArray[2];
825 
826             return array;
827         }
828         catch (Exception e) {
829             throw processException(e);
830         }
831         finally {
832             closeSession(session);
833         }
834     }
835 
836     public List<MBThread> findByC_L(long categoryId, Date lastPostDate)
837         throws SystemException {
838         Object[] finderArgs = new Object[] { new Long(categoryId), lastPostDate };
839 
840         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_L,
841                 finderArgs, this);
842 
843         if (list == null) {
844             Session session = null;
845 
846             try {
847                 session = openSession();
848 
849                 StringBundler query = new StringBundler(4);
850 
851                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
852 
853                 query.append(_FINDER_COLUMN_C_L_CATEGORYID_2);
854 
855                 if (lastPostDate == null) {
856                     query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_1);
857                 }
858                 else {
859                     query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_2);
860                 }
861 
862                 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
863 
864                 String sql = query.toString();
865 
866                 Query q = session.createQuery(sql);
867 
868                 QueryPos qPos = QueryPos.getInstance(q);
869 
870                 qPos.add(categoryId);
871 
872                 if (lastPostDate != null) {
873                     qPos.add(CalendarUtil.getTimestamp(lastPostDate));
874                 }
875 
876                 list = q.list();
877             }
878             catch (Exception e) {
879                 throw processException(e);
880             }
881             finally {
882                 if (list == null) {
883                     list = new ArrayList<MBThread>();
884                 }
885 
886                 cacheResult(list);
887 
888                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_L, finderArgs,
889                     list);
890 
891                 closeSession(session);
892             }
893         }
894 
895         return list;
896     }
897 
898     public List<MBThread> findByC_L(long categoryId, Date lastPostDate,
899         int start, int end) throws SystemException {
900         return findByC_L(categoryId, lastPostDate, start, end, null);
901     }
902 
903     public List<MBThread> findByC_L(long categoryId, Date lastPostDate,
904         int start, int end, OrderByComparator obc) throws SystemException {
905         Object[] finderArgs = new Object[] {
906                 new Long(categoryId),
907                 
908                 lastPostDate,
909                 
910                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
911             };
912 
913         List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_L,
914                 finderArgs, this);
915 
916         if (list == null) {
917             Session session = null;
918 
919             try {
920                 session = openSession();
921 
922                 StringBundler query = null;
923 
924                 if (obc != null) {
925                     query = new StringBundler(4 +
926                             (obc.getOrderByFields().length * 3));
927                 }
928                 else {
929                     query = new StringBundler(4);
930                 }
931 
932                 query.append(_SQL_SELECT_MBTHREAD_WHERE);
933 
934                 query.append(_FINDER_COLUMN_C_L_CATEGORYID_2);
935 
936                 if (lastPostDate == null) {
937                     query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_1);
938                 }
939                 else {
940                     query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_2);
941                 }
942 
943                 if (obc != null) {
944                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
945                 }
946 
947                 else {
948                     query.append(MBThreadModelImpl.ORDER_BY_JPQL);
949                 }
950 
951                 String sql = query.toString();
952 
953                 Query q = session.createQuery(sql);
954 
955                 QueryPos qPos = QueryPos.getInstance(q);
956 
957                 qPos.add(categoryId);
958 
959                 if (lastPostDate != null) {
960                     qPos.add(CalendarUtil.getTimestamp(lastPostDate));
961                 }
962 
963                 list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
964                         end);
965             }
966             catch (Exception e) {
967                 throw processException(e);
968             }
969             finally {
970                 if (list == null) {
971                     list = new ArrayList<MBThread>();
972                 }
973 
974                 cacheResult(list);
975 
976                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_L,
977                     finderArgs, list);
978 
979                 closeSession(session);
980             }
981         }
982 
983         return list;
984     }
985 
986     public MBThread findByC_L_First(long categoryId, Date lastPostDate,
987         OrderByComparator obc) throws NoSuchThreadException, SystemException {
988         List<MBThread> list = findByC_L(categoryId, lastPostDate, 0, 1, obc);
989 
990         if (list.isEmpty()) {
991             StringBundler msg = new StringBundler(6);
992 
993             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
994 
995             msg.append("categoryId=");
996             msg.append(categoryId);
997 
998             msg.append(", lastPostDate=");
999             msg.append(lastPostDate);
1000
1001            msg.append(StringPool.CLOSE_CURLY_BRACE);
1002
1003            throw new NoSuchThreadException(msg.toString());
1004        }
1005        else {
1006            return list.get(0);
1007        }
1008    }
1009
1010    public MBThread findByC_L_Last(long categoryId, Date lastPostDate,
1011        OrderByComparator obc) throws NoSuchThreadException, SystemException {
1012        int count = countByC_L(categoryId, lastPostDate);
1013
1014        List<MBThread> list = findByC_L(categoryId, lastPostDate, count - 1,
1015                count, obc);
1016
1017        if (list.isEmpty()) {
1018            StringBundler msg = new StringBundler(6);
1019
1020            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1021
1022            msg.append("categoryId=");
1023            msg.append(categoryId);
1024
1025            msg.append(", lastPostDate=");
1026            msg.append(lastPostDate);
1027
1028            msg.append(StringPool.CLOSE_CURLY_BRACE);
1029
1030            throw new NoSuchThreadException(msg.toString());
1031        }
1032        else {
1033            return list.get(0);
1034        }
1035    }
1036
1037    public MBThread[] findByC_L_PrevAndNext(long threadId, long categoryId,
1038        Date lastPostDate, OrderByComparator obc)
1039        throws NoSuchThreadException, SystemException {
1040        MBThread mbThread = findByPrimaryKey(threadId);
1041
1042        int count = countByC_L(categoryId, lastPostDate);
1043
1044        Session session = null;
1045
1046        try {
1047            session = openSession();
1048
1049            StringBundler query = null;
1050
1051            if (obc != null) {
1052                query = new StringBundler(4 +
1053                        (obc.getOrderByFields().length * 3));
1054            }
1055            else {
1056                query = new StringBundler(4);
1057            }
1058
1059            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1060
1061            query.append(_FINDER_COLUMN_C_L_CATEGORYID_2);
1062
1063            if (lastPostDate == null) {
1064                query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_1);
1065            }
1066            else {
1067                query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_2);
1068            }
1069
1070            if (obc != null) {
1071                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1072            }
1073
1074            else {
1075                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1076            }
1077
1078            String sql = query.toString();
1079
1080            Query q = session.createQuery(sql);
1081
1082            QueryPos qPos = QueryPos.getInstance(q);
1083
1084            qPos.add(categoryId);
1085
1086            if (lastPostDate != null) {
1087                qPos.add(CalendarUtil.getTimestamp(lastPostDate));
1088            }
1089
1090            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, mbThread);
1091
1092            MBThread[] array = new MBThreadImpl[3];
1093
1094            array[0] = (MBThread)objArray[0];
1095            array[1] = (MBThread)objArray[1];
1096            array[2] = (MBThread)objArray[2];
1097
1098            return array;
1099        }
1100        catch (Exception e) {
1101            throw processException(e);
1102        }
1103        finally {
1104            closeSession(session);
1105        }
1106    }
1107
1108    public List<MBThread> findByC_P(long categoryId, double priority)
1109        throws SystemException {
1110        Object[] finderArgs = new Object[] {
1111                new Long(categoryId), new Double(priority)
1112            };
1113
1114        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_P,
1115                finderArgs, this);
1116
1117        if (list == null) {
1118            Session session = null;
1119
1120            try {
1121                session = openSession();
1122
1123                StringBundler query = new StringBundler(4);
1124
1125                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1126
1127                query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1128
1129                query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1130
1131                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1132
1133                String sql = query.toString();
1134
1135                Query q = session.createQuery(sql);
1136
1137                QueryPos qPos = QueryPos.getInstance(q);
1138
1139                qPos.add(categoryId);
1140
1141                qPos.add(priority);
1142
1143                list = q.list();
1144            }
1145            catch (Exception e) {
1146                throw processException(e);
1147            }
1148            finally {
1149                if (list == null) {
1150                    list = new ArrayList<MBThread>();
1151                }
1152
1153                cacheResult(list);
1154
1155                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_P, finderArgs,
1156                    list);
1157
1158                closeSession(session);
1159            }
1160        }
1161
1162        return list;
1163    }
1164
1165    public List<MBThread> findByC_P(long categoryId, double priority,
1166        int start, int end) throws SystemException {
1167        return findByC_P(categoryId, priority, start, end, null);
1168    }
1169
1170    public List<MBThread> findByC_P(long categoryId, double priority,
1171        int start, int end, OrderByComparator obc) throws SystemException {
1172        Object[] finderArgs = new Object[] {
1173                new Long(categoryId), new Double(priority),
1174                
1175                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1176            };
1177
1178        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_P,
1179                finderArgs, this);
1180
1181        if (list == null) {
1182            Session session = null;
1183
1184            try {
1185                session = openSession();
1186
1187                StringBundler query = null;
1188
1189                if (obc != null) {
1190                    query = new StringBundler(4 +
1191                            (obc.getOrderByFields().length * 3));
1192                }
1193                else {
1194                    query = new StringBundler(4);
1195                }
1196
1197                query.append(_SQL_SELECT_MBTHREAD_WHERE);
1198
1199                query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1200
1201                query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1202
1203                if (obc != null) {
1204                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1205                }
1206
1207                else {
1208                    query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1209                }
1210
1211                String sql = query.toString();
1212
1213                Query q = session.createQuery(sql);
1214
1215                QueryPos qPos = QueryPos.getInstance(q);
1216
1217                qPos.add(categoryId);
1218
1219                qPos.add(priority);
1220
1221                list = (List<MBThread>)QueryUtil.list(q, getDialect(), start,
1222                        end);
1223            }
1224            catch (Exception e) {
1225                throw processException(e);
1226            }
1227            finally {
1228                if (list == null) {
1229                    list = new ArrayList<MBThread>();
1230                }
1231
1232                cacheResult(list);
1233
1234                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_P,
1235                    finderArgs, list);
1236
1237                closeSession(session);
1238            }
1239        }
1240
1241        return list;
1242    }
1243
1244    public MBThread findByC_P_First(long categoryId, double priority,
1245        OrderByComparator obc) throws NoSuchThreadException, SystemException {
1246        List<MBThread> list = findByC_P(categoryId, priority, 0, 1, obc);
1247
1248        if (list.isEmpty()) {
1249            StringBundler msg = new StringBundler(6);
1250
1251            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1252
1253            msg.append("categoryId=");
1254            msg.append(categoryId);
1255
1256            msg.append(", priority=");
1257            msg.append(priority);
1258
1259            msg.append(StringPool.CLOSE_CURLY_BRACE);
1260
1261            throw new NoSuchThreadException(msg.toString());
1262        }
1263        else {
1264            return list.get(0);
1265        }
1266    }
1267
1268    public MBThread findByC_P_Last(long categoryId, double priority,
1269        OrderByComparator obc) throws NoSuchThreadException, SystemException {
1270        int count = countByC_P(categoryId, priority);
1271
1272        List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
1273                obc);
1274
1275        if (list.isEmpty()) {
1276            StringBundler msg = new StringBundler(6);
1277
1278            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1279
1280            msg.append("categoryId=");
1281            msg.append(categoryId);
1282
1283            msg.append(", priority=");
1284            msg.append(priority);
1285
1286            msg.append(StringPool.CLOSE_CURLY_BRACE);
1287
1288            throw new NoSuchThreadException(msg.toString());
1289        }
1290        else {
1291            return list.get(0);
1292        }
1293    }
1294
1295    public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
1296        double priority, OrderByComparator obc)
1297        throws NoSuchThreadException, SystemException {
1298        MBThread mbThread = findByPrimaryKey(threadId);
1299
1300        int count = countByC_P(categoryId, priority);
1301
1302        Session session = null;
1303
1304        try {
1305            session = openSession();
1306
1307            StringBundler query = null;
1308
1309            if (obc != null) {
1310                query = new StringBundler(4 +
1311                        (obc.getOrderByFields().length * 3));
1312            }
1313            else {
1314                query = new StringBundler(4);
1315            }
1316
1317            query.append(_SQL_SELECT_MBTHREAD_WHERE);
1318
1319            query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1320
1321            query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1322
1323            if (obc != null) {
1324                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1325            }
1326
1327            else {
1328                query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1329            }
1330
1331            String sql = query.toString();
1332
1333            Query q = session.createQuery(sql);
1334
1335            QueryPos qPos = QueryPos.getInstance(q);
1336
1337            qPos.add(categoryId);
1338
1339            qPos.add(priority);
1340
1341            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc, mbThread);
1342
1343            MBThread[] array = new MBThreadImpl[3];
1344
1345            array[0] = (MBThread)objArray[0];
1346            array[1] = (MBThread)objArray[1];
1347            array[2] = (MBThread)objArray[2];
1348
1349            return array;
1350        }
1351        catch (Exception e) {
1352            throw processException(e);
1353        }
1354        finally {
1355            closeSession(session);
1356        }
1357    }
1358
1359    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1360        throws SystemException {
1361        Session session = null;
1362
1363        try {
1364            session = openSession();
1365
1366            dynamicQuery.compile(session);
1367
1368            return dynamicQuery.list();
1369        }
1370        catch (Exception e) {
1371            throw processException(e);
1372        }
1373        finally {
1374            closeSession(session);
1375        }
1376    }
1377
1378    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1379        int start, int end) throws SystemException {
1380        Session session = null;
1381
1382        try {
1383            session = openSession();
1384
1385            dynamicQuery.setLimit(start, end);
1386
1387            dynamicQuery.compile(session);
1388
1389            return dynamicQuery.list();
1390        }
1391        catch (Exception e) {
1392            throw processException(e);
1393        }
1394        finally {
1395            closeSession(session);
1396        }
1397    }
1398
1399    public List<MBThread> findAll() throws SystemException {
1400        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1401    }
1402
1403    public List<MBThread> findAll(int start, int end) throws SystemException {
1404        return findAll(start, end, null);
1405    }
1406
1407    public List<MBThread> findAll(int start, int end, OrderByComparator obc)
1408        throws SystemException {
1409        Object[] finderArgs = new Object[] {
1410                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1411            };
1412
1413        List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1414                finderArgs, this);
1415
1416        if (list == null) {
1417            Session session = null;
1418
1419            try {
1420                session = openSession();
1421
1422                StringBundler query = null;
1423                String sql = null;
1424
1425                if (obc != null) {
1426                    query = new StringBundler(2 +
1427                            (obc.getOrderByFields().length * 3));
1428
1429                    query.append(_SQL_SELECT_MBTHREAD);
1430
1431                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1432
1433                    sql = query.toString();
1434                }
1435
1436                else {
1437                    sql = _SQL_SELECT_MBTHREAD.concat(MBThreadModelImpl.ORDER_BY_JPQL);
1438                }
1439
1440                Query q = session.createQuery(sql);
1441
1442                if (obc == null) {
1443                    list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1444                            start, end, false);
1445
1446                    Collections.sort(list);
1447                }
1448                else {
1449                    list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1450                            start, end);
1451                }
1452            }
1453            catch (Exception e) {
1454                throw processException(e);
1455            }
1456            finally {
1457                if (list == null) {
1458                    list = new ArrayList<MBThread>();
1459                }
1460
1461                cacheResult(list);
1462
1463                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1464
1465                closeSession(session);
1466            }
1467        }
1468
1469        return list;
1470    }
1471
1472    public void removeByGroupId(long groupId) throws SystemException {
1473        for (MBThread mbThread : findByGroupId(groupId)) {
1474            remove(mbThread);
1475        }
1476    }
1477
1478    public void removeByCategoryId(long categoryId) throws SystemException {
1479        for (MBThread mbThread : findByCategoryId(categoryId)) {
1480            remove(mbThread);
1481        }
1482    }
1483
1484    public void removeByC_L(long categoryId, Date lastPostDate)
1485        throws SystemException {
1486        for (MBThread mbThread : findByC_L(categoryId, lastPostDate)) {
1487            remove(mbThread);
1488        }
1489    }
1490
1491    public void removeByC_P(long categoryId, double priority)
1492        throws SystemException {
1493        for (MBThread mbThread : findByC_P(categoryId, priority)) {
1494            remove(mbThread);
1495        }
1496    }
1497
1498    public void removeAll() throws SystemException {
1499        for (MBThread mbThread : findAll()) {
1500            remove(mbThread);
1501        }
1502    }
1503
1504    public int countByGroupId(long groupId) throws SystemException {
1505        Object[] finderArgs = new Object[] { new Long(groupId) };
1506
1507        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1508                finderArgs, this);
1509
1510        if (count == null) {
1511            Session session = null;
1512
1513            try {
1514                session = openSession();
1515
1516                StringBundler query = new StringBundler(2);
1517
1518                query.append(_SQL_COUNT_MBTHREAD_WHERE);
1519
1520                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1521
1522                String sql = query.toString();
1523
1524                Query q = session.createQuery(sql);
1525
1526                QueryPos qPos = QueryPos.getInstance(q);
1527
1528                qPos.add(groupId);
1529
1530                count = (Long)q.uniqueResult();
1531            }
1532            catch (Exception e) {
1533                throw processException(e);
1534            }
1535            finally {
1536                if (count == null) {
1537                    count = Long.valueOf(0);
1538                }
1539
1540                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1541                    finderArgs, count);
1542
1543                closeSession(session);
1544            }
1545        }
1546
1547        return count.intValue();
1548    }
1549
1550    public int countByCategoryId(long categoryId) throws SystemException {
1551        Object[] finderArgs = new Object[] { new Long(categoryId) };
1552
1553        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1554                finderArgs, this);
1555
1556        if (count == null) {
1557            Session session = null;
1558
1559            try {
1560                session = openSession();
1561
1562                StringBundler query = new StringBundler(2);
1563
1564                query.append(_SQL_COUNT_MBTHREAD_WHERE);
1565
1566                query.append(_FINDER_COLUMN_CATEGORYID_CATEGORYID_2);
1567
1568                String sql = query.toString();
1569
1570                Query q = session.createQuery(sql);
1571
1572                QueryPos qPos = QueryPos.getInstance(q);
1573
1574                qPos.add(categoryId);
1575
1576                count = (Long)q.uniqueResult();
1577            }
1578            catch (Exception e) {
1579                throw processException(e);
1580            }
1581            finally {
1582                if (count == null) {
1583                    count = Long.valueOf(0);
1584                }
1585
1586                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CATEGORYID,
1587                    finderArgs, count);
1588
1589                closeSession(session);
1590            }
1591        }
1592
1593        return count.intValue();
1594    }
1595
1596    public int countByC_L(long categoryId, Date lastPostDate)
1597        throws SystemException {
1598        Object[] finderArgs = new Object[] { new Long(categoryId), lastPostDate };
1599
1600        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_L,
1601                finderArgs, this);
1602
1603        if (count == null) {
1604            Session session = null;
1605
1606            try {
1607                session = openSession();
1608
1609                StringBundler query = new StringBundler(3);
1610
1611                query.append(_SQL_COUNT_MBTHREAD_WHERE);
1612
1613                query.append(_FINDER_COLUMN_C_L_CATEGORYID_2);
1614
1615                if (lastPostDate == null) {
1616                    query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_1);
1617                }
1618                else {
1619                    query.append(_FINDER_COLUMN_C_L_LASTPOSTDATE_2);
1620                }
1621
1622                String sql = query.toString();
1623
1624                Query q = session.createQuery(sql);
1625
1626                QueryPos qPos = QueryPos.getInstance(q);
1627
1628                qPos.add(categoryId);
1629
1630                if (lastPostDate != null) {
1631                    qPos.add(CalendarUtil.getTimestamp(lastPostDate));
1632                }
1633
1634                count = (Long)q.uniqueResult();
1635            }
1636            catch (Exception e) {
1637                throw processException(e);
1638            }
1639            finally {
1640                if (count == null) {
1641                    count = Long.valueOf(0);
1642                }
1643
1644                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L, finderArgs,
1645                    count);
1646
1647                closeSession(session);
1648            }
1649        }
1650
1651        return count.intValue();
1652    }
1653
1654    public int countByC_P(long categoryId, double priority)
1655        throws SystemException {
1656        Object[] finderArgs = new Object[] {
1657                new Long(categoryId), new Double(priority)
1658            };
1659
1660        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_P,
1661                finderArgs, this);
1662
1663        if (count == null) {
1664            Session session = null;
1665
1666            try {
1667                session = openSession();
1668
1669                StringBundler query = new StringBundler(3);
1670
1671                query.append(_SQL_COUNT_MBTHREAD_WHERE);
1672
1673                query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
1674
1675                query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
1676
1677                String sql = query.toString();
1678
1679                Query q = session.createQuery(sql);
1680
1681                QueryPos qPos = QueryPos.getInstance(q);
1682
1683                qPos.add(categoryId);
1684
1685                qPos.add(priority);
1686
1687                count = (Long)q.uniqueResult();
1688            }
1689            catch (Exception e) {
1690                throw processException(e);
1691            }
1692            finally {
1693                if (count == null) {
1694                    count = Long.valueOf(0);
1695                }
1696
1697                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_P, finderArgs,
1698                    count);
1699
1700                closeSession(session);
1701            }
1702        }
1703
1704        return count.intValue();
1705    }
1706
1707    public int countAll() throws SystemException {
1708        Object[] finderArgs = new Object[0];
1709
1710        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1711                finderArgs, this);
1712
1713        if (count == null) {
1714            Session session = null;
1715
1716            try {
1717                session = openSession();
1718
1719                Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
1720
1721                count = (Long)q.uniqueResult();
1722            }
1723            catch (Exception e) {
1724                throw processException(e);
1725            }
1726            finally {
1727                if (count == null) {
1728                    count = Long.valueOf(0);
1729                }
1730
1731                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1732                    count);
1733
1734                closeSession(session);
1735            }
1736        }
1737
1738        return count.intValue();
1739    }
1740
1741    public void afterPropertiesSet() {
1742        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1743                    com.liferay.portal.util.PropsUtil.get(
1744                        "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
1745
1746        if (listenerClassNames.length > 0) {
1747            try {
1748                List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
1749
1750                for (String listenerClassName : listenerClassNames) {
1751                    listenersList.add((ModelListener<MBThread>)Class.forName(
1752                            listenerClassName).newInstance());
1753                }
1754
1755                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1756            }
1757            catch (Exception e) {
1758                _log.error(e);
1759            }
1760        }
1761    }
1762
1763    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence")
1764    protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
1765    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence")
1766    protected com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence mbCategoryPersistence;
1767    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence")
1768    protected com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence mbDiscussionPersistence;
1769    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence")
1770    protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1771    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence")
1772    protected com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence mbMessageFlagPersistence;
1773    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence")
1774    protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
1775    @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence")
1776    protected com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence mbThreadPersistence;
1777    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1778    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1779    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1780    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1781    @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence")
1782    protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
1783    @BeanReference(name = "com.liferay.portlet.social.service.persistence.SocialActivityPersistence")
1784    protected com.liferay.portlet.social.service.persistence.SocialActivityPersistence socialActivityPersistence;
1785    @BeanReference(name = "com.liferay.portlet.tags.service.persistence.TagsAssetPersistence")
1786    protected com.liferay.portlet.tags.service.persistence.TagsAssetPersistence tagsAssetPersistence;
1787    private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
1788    private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
1789    private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
1790    private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
1791    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ?";
1792    private static final String _FINDER_COLUMN_CATEGORYID_CATEGORYID_2 = "mbThread.categoryId = ?";
1793    private static final String _FINDER_COLUMN_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
1794    private static final String _FINDER_COLUMN_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
1795    private static final String _FINDER_COLUMN_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
1796    private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
1797    private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
1798    private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
1799    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
1800    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
1801    private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
1802}