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