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