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