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