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