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.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.StringPool;
41 import com.liferay.portal.kernel.util.StringUtil;
42 import com.liferay.portal.model.ModelListener;
43 import com.liferay.portal.service.persistence.BatchSessionUtil;
44 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45
46 import com.liferay.portlet.messageboards.NoSuchDiscussionException;
47 import com.liferay.portlet.messageboards.model.MBDiscussion;
48 import com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl;
49 import com.liferay.portlet.messageboards.model.impl.MBDiscussionModelImpl;
50
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.List;
54
55
68 public class MBDiscussionPersistenceImpl extends BasePersistenceImpl
69 implements MBDiscussionPersistence {
70 public static final String FINDER_CLASS_NAME_ENTITY = MBDiscussionImpl.class.getName();
71 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
72 ".List";
73 public static final FinderPath FINDER_PATH_FIND_BY_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
74 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
75 "findByClassNameId", new String[] { Long.class.getName() });
76 public static final FinderPath FINDER_PATH_FIND_BY_OBC_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
77 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
78 "findByClassNameId",
79 new String[] {
80 Long.class.getName(),
81
82 "java.lang.Integer", "java.lang.Integer",
83 "com.liferay.portal.kernel.util.OrderByComparator"
84 });
85 public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
86 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
87 "countByClassNameId", new String[] { Long.class.getName() });
88 public static final FinderPath FINDER_PATH_FETCH_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
89 MBDiscussionModelImpl.FINDER_CACHE_ENABLED,
90 FINDER_CLASS_NAME_ENTITY, "fetchByThreadId",
91 new String[] { Long.class.getName() });
92 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
93 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
94 "countByThreadId", new String[] { Long.class.getName() });
95 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
96 MBDiscussionModelImpl.FINDER_CACHE_ENABLED,
97 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
98 new String[] { Long.class.getName(), Long.class.getName() });
99 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
100 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "countByC_C",
102 new String[] { Long.class.getName(), Long.class.getName() });
103 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
104 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
105 "findAll", new String[0]);
106 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
107 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108 "countAll", new String[0]);
109
110 public void cacheResult(MBDiscussion mbDiscussion) {
111 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
112 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
113
114 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
115 new Object[] { new Long(mbDiscussion.getThreadId()) }, mbDiscussion);
116
117 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
118 new Object[] {
119 new Long(mbDiscussion.getClassNameId()),
120 new Long(mbDiscussion.getClassPK())
121 }, mbDiscussion);
122 }
123
124 public void cacheResult(List<MBDiscussion> mbDiscussions) {
125 for (MBDiscussion mbDiscussion : mbDiscussions) {
126 if (EntityCacheUtil.getResult(
127 MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
128 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(),
129 this) == null) {
130 cacheResult(mbDiscussion);
131 }
132 }
133 }
134
135 public void clearCache() {
136 CacheRegistry.clear(MBDiscussionImpl.class.getName());
137 EntityCacheUtil.clearCache(MBDiscussionImpl.class.getName());
138 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
139 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
140 }
141
142 public MBDiscussion create(long discussionId) {
143 MBDiscussion mbDiscussion = new MBDiscussionImpl();
144
145 mbDiscussion.setNew(true);
146 mbDiscussion.setPrimaryKey(discussionId);
147
148 return mbDiscussion;
149 }
150
151 public MBDiscussion remove(long discussionId)
152 throws NoSuchDiscussionException, SystemException {
153 Session session = null;
154
155 try {
156 session = openSession();
157
158 MBDiscussion mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
159 new Long(discussionId));
160
161 if (mbDiscussion == null) {
162 if (_log.isWarnEnabled()) {
163 _log.warn("No MBDiscussion exists with the primary key " +
164 discussionId);
165 }
166
167 throw new NoSuchDiscussionException(
168 "No MBDiscussion exists with the primary key " +
169 discussionId);
170 }
171
172 return remove(mbDiscussion);
173 }
174 catch (NoSuchDiscussionException nsee) {
175 throw nsee;
176 }
177 catch (Exception e) {
178 throw processException(e);
179 }
180 finally {
181 closeSession(session);
182 }
183 }
184
185 public MBDiscussion remove(MBDiscussion mbDiscussion)
186 throws SystemException {
187 for (ModelListener<MBDiscussion> listener : listeners) {
188 listener.onBeforeRemove(mbDiscussion);
189 }
190
191 mbDiscussion = removeImpl(mbDiscussion);
192
193 for (ModelListener<MBDiscussion> listener : listeners) {
194 listener.onAfterRemove(mbDiscussion);
195 }
196
197 return mbDiscussion;
198 }
199
200 protected MBDiscussion removeImpl(MBDiscussion mbDiscussion)
201 throws SystemException {
202 Session session = null;
203
204 try {
205 session = openSession();
206
207 if (mbDiscussion.isCachedModel() || BatchSessionUtil.isEnabled()) {
208 Object staleObject = session.get(MBDiscussionImpl.class,
209 mbDiscussion.getPrimaryKeyObj());
210
211 if (staleObject != null) {
212 session.evict(staleObject);
213 }
214 }
215
216 session.delete(mbDiscussion);
217
218 session.flush();
219 }
220 catch (Exception e) {
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226
227 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
228
229 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
230
231 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
232 new Object[] { new Long(mbDiscussionModelImpl.getOriginalThreadId()) });
233
234 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
235 new Object[] {
236 new Long(mbDiscussionModelImpl.getOriginalClassNameId()),
237 new Long(mbDiscussionModelImpl.getOriginalClassPK())
238 });
239
240 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
241 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
242
243 return mbDiscussion;
244 }
245
246
249 public MBDiscussion update(MBDiscussion mbDiscussion)
250 throws SystemException {
251 if (_log.isWarnEnabled()) {
252 _log.warn(
253 "Using the deprecated update(MBDiscussion mbDiscussion) method. Use update(MBDiscussion mbDiscussion, boolean merge) instead.");
254 }
255
256 return update(mbDiscussion, false);
257 }
258
259
271 public MBDiscussion update(MBDiscussion mbDiscussion, boolean merge)
272 throws SystemException {
273 boolean isNew = mbDiscussion.isNew();
274
275 for (ModelListener<MBDiscussion> listener : listeners) {
276 if (isNew) {
277 listener.onBeforeCreate(mbDiscussion);
278 }
279 else {
280 listener.onBeforeUpdate(mbDiscussion);
281 }
282 }
283
284 mbDiscussion = updateImpl(mbDiscussion, merge);
285
286 for (ModelListener<MBDiscussion> listener : listeners) {
287 if (isNew) {
288 listener.onAfterCreate(mbDiscussion);
289 }
290 else {
291 listener.onAfterUpdate(mbDiscussion);
292 }
293 }
294
295 return mbDiscussion;
296 }
297
298 public MBDiscussion updateImpl(
299 com.liferay.portlet.messageboards.model.MBDiscussion mbDiscussion,
300 boolean merge) throws SystemException {
301 boolean isNew = mbDiscussion.isNew();
302
303 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
304
305 Session session = null;
306
307 try {
308 session = openSession();
309
310 BatchSessionUtil.update(session, mbDiscussion, merge);
311
312 mbDiscussion.setNew(false);
313 }
314 catch (Exception e) {
315 throw processException(e);
316 }
317 finally {
318 closeSession(session);
319 }
320
321 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
322
323 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
324 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
325
326 if (!isNew &&
327 (mbDiscussion.getThreadId() != mbDiscussionModelImpl.getOriginalThreadId())) {
328 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
329 new Object[] {
330 new Long(mbDiscussionModelImpl.getOriginalThreadId())
331 });
332 }
333
334 if (isNew ||
335 (mbDiscussion.getThreadId() != mbDiscussionModelImpl.getOriginalThreadId())) {
336 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
337 new Object[] { new Long(mbDiscussion.getThreadId()) },
338 mbDiscussion);
339 }
340
341 if (!isNew &&
342 ((mbDiscussion.getClassNameId() != mbDiscussionModelImpl.getOriginalClassNameId()) ||
343 (mbDiscussion.getClassPK() != mbDiscussionModelImpl.getOriginalClassPK()))) {
344 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
345 new Object[] {
346 new Long(mbDiscussionModelImpl.getOriginalClassNameId()),
347 new Long(mbDiscussionModelImpl.getOriginalClassPK())
348 });
349 }
350
351 if (isNew ||
352 ((mbDiscussion.getClassNameId() != mbDiscussionModelImpl.getOriginalClassNameId()) ||
353 (mbDiscussion.getClassPK() != mbDiscussionModelImpl.getOriginalClassPK()))) {
354 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
355 new Object[] {
356 new Long(mbDiscussion.getClassNameId()),
357 new Long(mbDiscussion.getClassPK())
358 }, mbDiscussion);
359 }
360
361 return mbDiscussion;
362 }
363
364 public MBDiscussion findByPrimaryKey(long discussionId)
365 throws NoSuchDiscussionException, SystemException {
366 MBDiscussion mbDiscussion = fetchByPrimaryKey(discussionId);
367
368 if (mbDiscussion == null) {
369 if (_log.isWarnEnabled()) {
370 _log.warn("No MBDiscussion exists with the primary key " +
371 discussionId);
372 }
373
374 throw new NoSuchDiscussionException(
375 "No MBDiscussion exists with the primary key " + discussionId);
376 }
377
378 return mbDiscussion;
379 }
380
381 public MBDiscussion fetchByPrimaryKey(long discussionId)
382 throws SystemException {
383 MBDiscussion mbDiscussion = (MBDiscussion)EntityCacheUtil.getResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
384 MBDiscussionImpl.class, discussionId, this);
385
386 if (mbDiscussion == null) {
387 Session session = null;
388
389 try {
390 session = openSession();
391
392 mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
393 new Long(discussionId));
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 if (mbDiscussion != null) {
400 cacheResult(mbDiscussion);
401 }
402
403 closeSession(session);
404 }
405 }
406
407 return mbDiscussion;
408 }
409
410 public List<MBDiscussion> findByClassNameId(long classNameId)
411 throws SystemException {
412 Object[] finderArgs = new Object[] { new Long(classNameId) };
413
414 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
415 finderArgs, this);
416
417 if (list == null) {
418 Session session = null;
419
420 try {
421 session = openSession();
422
423 StringBuilder query = new StringBuilder();
424
425 query.append(
426 "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ");
427
428 query.append("mbDiscussion.classNameId = ?");
429
430 query.append(" ");
431
432 Query q = session.createQuery(query.toString());
433
434 QueryPos qPos = QueryPos.getInstance(q);
435
436 qPos.add(classNameId);
437
438 list = q.list();
439 }
440 catch (Exception e) {
441 throw processException(e);
442 }
443 finally {
444 if (list == null) {
445 list = new ArrayList<MBDiscussion>();
446 }
447
448 cacheResult(list);
449
450 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
451 finderArgs, list);
452
453 closeSession(session);
454 }
455 }
456
457 return list;
458 }
459
460 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
461 int end) throws SystemException {
462 return findByClassNameId(classNameId, start, end, null);
463 }
464
465 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
466 int end, OrderByComparator obc) throws SystemException {
467 Object[] finderArgs = new Object[] {
468 new Long(classNameId),
469
470 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
471 };
472
473 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_CLASSNAMEID,
474 finderArgs, this);
475
476 if (list == null) {
477 Session session = null;
478
479 try {
480 session = openSession();
481
482 StringBuilder query = new StringBuilder();
483
484 query.append(
485 "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ");
486
487 query.append("mbDiscussion.classNameId = ?");
488
489 query.append(" ");
490
491 if (obc != null) {
492 query.append("ORDER BY ");
493
494 String[] orderByFields = obc.getOrderByFields();
495
496 for (int i = 0; i < orderByFields.length; i++) {
497 query.append("mbDiscussion.");
498 query.append(orderByFields[i]);
499
500 if (obc.isAscending()) {
501 query.append(" ASC");
502 }
503 else {
504 query.append(" DESC");
505 }
506
507 if ((i + 1) < orderByFields.length) {
508 query.append(", ");
509 }
510 }
511 }
512
513 Query q = session.createQuery(query.toString());
514
515 QueryPos qPos = QueryPos.getInstance(q);
516
517 qPos.add(classNameId);
518
519 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
520 start, end);
521 }
522 catch (Exception e) {
523 throw processException(e);
524 }
525 finally {
526 if (list == null) {
527 list = new ArrayList<MBDiscussion>();
528 }
529
530 cacheResult(list);
531
532 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_CLASSNAMEID,
533 finderArgs, list);
534
535 closeSession(session);
536 }
537 }
538
539 return list;
540 }
541
542 public MBDiscussion findByClassNameId_First(long classNameId,
543 OrderByComparator obc)
544 throws NoSuchDiscussionException, SystemException {
545 List<MBDiscussion> list = findByClassNameId(classNameId, 0, 1, obc);
546
547 if (list.isEmpty()) {
548 StringBuilder msg = new StringBuilder();
549
550 msg.append("No MBDiscussion exists with the key {");
551
552 msg.append("classNameId=" + classNameId);
553
554 msg.append(StringPool.CLOSE_CURLY_BRACE);
555
556 throw new NoSuchDiscussionException(msg.toString());
557 }
558 else {
559 return list.get(0);
560 }
561 }
562
563 public MBDiscussion findByClassNameId_Last(long classNameId,
564 OrderByComparator obc)
565 throws NoSuchDiscussionException, SystemException {
566 int count = countByClassNameId(classNameId);
567
568 List<MBDiscussion> list = findByClassNameId(classNameId, count - 1,
569 count, obc);
570
571 if (list.isEmpty()) {
572 StringBuilder msg = new StringBuilder();
573
574 msg.append("No MBDiscussion exists with the key {");
575
576 msg.append("classNameId=" + classNameId);
577
578 msg.append(StringPool.CLOSE_CURLY_BRACE);
579
580 throw new NoSuchDiscussionException(msg.toString());
581 }
582 else {
583 return list.get(0);
584 }
585 }
586
587 public MBDiscussion[] findByClassNameId_PrevAndNext(long discussionId,
588 long classNameId, OrderByComparator obc)
589 throws NoSuchDiscussionException, SystemException {
590 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
591
592 int count = countByClassNameId(classNameId);
593
594 Session session = null;
595
596 try {
597 session = openSession();
598
599 StringBuilder query = new StringBuilder();
600
601 query.append(
602 "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ");
603
604 query.append("mbDiscussion.classNameId = ?");
605
606 query.append(" ");
607
608 if (obc != null) {
609 query.append("ORDER BY ");
610
611 String[] orderByFields = obc.getOrderByFields();
612
613 for (int i = 0; i < orderByFields.length; i++) {
614 query.append("mbDiscussion.");
615 query.append(orderByFields[i]);
616
617 if (obc.isAscending()) {
618 query.append(" ASC");
619 }
620 else {
621 query.append(" DESC");
622 }
623
624 if ((i + 1) < orderByFields.length) {
625 query.append(", ");
626 }
627 }
628 }
629
630 Query q = session.createQuery(query.toString());
631
632 QueryPos qPos = QueryPos.getInstance(q);
633
634 qPos.add(classNameId);
635
636 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
637 mbDiscussion);
638
639 MBDiscussion[] array = new MBDiscussionImpl[3];
640
641 array[0] = (MBDiscussion)objArray[0];
642 array[1] = (MBDiscussion)objArray[1];
643 array[2] = (MBDiscussion)objArray[2];
644
645 return array;
646 }
647 catch (Exception e) {
648 throw processException(e);
649 }
650 finally {
651 closeSession(session);
652 }
653 }
654
655 public MBDiscussion findByThreadId(long threadId)
656 throws NoSuchDiscussionException, SystemException {
657 MBDiscussion mbDiscussion = fetchByThreadId(threadId);
658
659 if (mbDiscussion == null) {
660 StringBuilder msg = new StringBuilder();
661
662 msg.append("No MBDiscussion exists with the key {");
663
664 msg.append("threadId=" + threadId);
665
666 msg.append(StringPool.CLOSE_CURLY_BRACE);
667
668 if (_log.isWarnEnabled()) {
669 _log.warn(msg.toString());
670 }
671
672 throw new NoSuchDiscussionException(msg.toString());
673 }
674
675 return mbDiscussion;
676 }
677
678 public MBDiscussion fetchByThreadId(long threadId)
679 throws SystemException {
680 return fetchByThreadId(threadId, true);
681 }
682
683 public MBDiscussion fetchByThreadId(long threadId, boolean retrieveFromCache)
684 throws SystemException {
685 Object[] finderArgs = new Object[] { new Long(threadId) };
686
687 Object result = null;
688
689 if (retrieveFromCache) {
690 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THREADID,
691 finderArgs, this);
692 }
693
694 if (result == null) {
695 Session session = null;
696
697 try {
698 session = openSession();
699
700 StringBuilder query = new StringBuilder();
701
702 query.append(
703 "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ");
704
705 query.append("mbDiscussion.threadId = ?");
706
707 query.append(" ");
708
709 Query q = session.createQuery(query.toString());
710
711 QueryPos qPos = QueryPos.getInstance(q);
712
713 qPos.add(threadId);
714
715 List<MBDiscussion> list = q.list();
716
717 result = list;
718
719 MBDiscussion mbDiscussion = null;
720
721 if (list.isEmpty()) {
722 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
723 finderArgs, list);
724 }
725 else {
726 mbDiscussion = list.get(0);
727
728 cacheResult(mbDiscussion);
729
730 if ((mbDiscussion.getThreadId() != threadId)) {
731 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
732 finderArgs, mbDiscussion);
733 }
734 }
735
736 return mbDiscussion;
737 }
738 catch (Exception e) {
739 throw processException(e);
740 }
741 finally {
742 if (result == null) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
744 finderArgs, new ArrayList<MBDiscussion>());
745 }
746
747 closeSession(session);
748 }
749 }
750 else {
751 if (result instanceof List<?>) {
752 return null;
753 }
754 else {
755 return (MBDiscussion)result;
756 }
757 }
758 }
759
760 public MBDiscussion findByC_C(long classNameId, long classPK)
761 throws NoSuchDiscussionException, SystemException {
762 MBDiscussion mbDiscussion = fetchByC_C(classNameId, classPK);
763
764 if (mbDiscussion == null) {
765 StringBuilder msg = new StringBuilder();
766
767 msg.append("No MBDiscussion exists with the key {");
768
769 msg.append("classNameId=" + classNameId);
770
771 msg.append(", ");
772 msg.append("classPK=" + classPK);
773
774 msg.append(StringPool.CLOSE_CURLY_BRACE);
775
776 if (_log.isWarnEnabled()) {
777 _log.warn(msg.toString());
778 }
779
780 throw new NoSuchDiscussionException(msg.toString());
781 }
782
783 return mbDiscussion;
784 }
785
786 public MBDiscussion fetchByC_C(long classNameId, long classPK)
787 throws SystemException {
788 return fetchByC_C(classNameId, classPK, true);
789 }
790
791 public MBDiscussion fetchByC_C(long classNameId, long classPK,
792 boolean retrieveFromCache) throws SystemException {
793 Object[] finderArgs = new Object[] {
794 new Long(classNameId), new Long(classPK)
795 };
796
797 Object result = null;
798
799 if (retrieveFromCache) {
800 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
801 finderArgs, this);
802 }
803
804 if (result == null) {
805 Session session = null;
806
807 try {
808 session = openSession();
809
810 StringBuilder query = new StringBuilder();
811
812 query.append(
813 "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ");
814
815 query.append("mbDiscussion.classNameId = ?");
816
817 query.append(" AND ");
818
819 query.append("mbDiscussion.classPK = ?");
820
821 query.append(" ");
822
823 Query q = session.createQuery(query.toString());
824
825 QueryPos qPos = QueryPos.getInstance(q);
826
827 qPos.add(classNameId);
828
829 qPos.add(classPK);
830
831 List<MBDiscussion> list = q.list();
832
833 result = list;
834
835 MBDiscussion mbDiscussion = null;
836
837 if (list.isEmpty()) {
838 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
839 finderArgs, list);
840 }
841 else {
842 mbDiscussion = list.get(0);
843
844 cacheResult(mbDiscussion);
845
846 if ((mbDiscussion.getClassNameId() != classNameId) ||
847 (mbDiscussion.getClassPK() != classPK)) {
848 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
849 finderArgs, mbDiscussion);
850 }
851 }
852
853 return mbDiscussion;
854 }
855 catch (Exception e) {
856 throw processException(e);
857 }
858 finally {
859 if (result == null) {
860 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
861 finderArgs, new ArrayList<MBDiscussion>());
862 }
863
864 closeSession(session);
865 }
866 }
867 else {
868 if (result instanceof List<?>) {
869 return null;
870 }
871 else {
872 return (MBDiscussion)result;
873 }
874 }
875 }
876
877 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
878 throws SystemException {
879 Session session = null;
880
881 try {
882 session = openSession();
883
884 dynamicQuery.compile(session);
885
886 return dynamicQuery.list();
887 }
888 catch (Exception e) {
889 throw processException(e);
890 }
891 finally {
892 closeSession(session);
893 }
894 }
895
896 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
897 int start, int end) throws SystemException {
898 Session session = null;
899
900 try {
901 session = openSession();
902
903 dynamicQuery.setLimit(start, end);
904
905 dynamicQuery.compile(session);
906
907 return dynamicQuery.list();
908 }
909 catch (Exception e) {
910 throw processException(e);
911 }
912 finally {
913 closeSession(session);
914 }
915 }
916
917 public List<MBDiscussion> findAll() throws SystemException {
918 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
919 }
920
921 public List<MBDiscussion> findAll(int start, int end)
922 throws SystemException {
923 return findAll(start, end, null);
924 }
925
926 public List<MBDiscussion> findAll(int start, int end, OrderByComparator obc)
927 throws SystemException {
928 Object[] finderArgs = new Object[] {
929 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
930 };
931
932 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
933 finderArgs, this);
934
935 if (list == null) {
936 Session session = null;
937
938 try {
939 session = openSession();
940
941 StringBuilder query = new StringBuilder();
942
943 query.append(
944 "SELECT mbDiscussion FROM MBDiscussion mbDiscussion ");
945
946 if (obc != null) {
947 query.append("ORDER BY ");
948
949 String[] orderByFields = obc.getOrderByFields();
950
951 for (int i = 0; i < orderByFields.length; i++) {
952 query.append("mbDiscussion.");
953 query.append(orderByFields[i]);
954
955 if (obc.isAscending()) {
956 query.append(" ASC");
957 }
958 else {
959 query.append(" DESC");
960 }
961
962 if ((i + 1) < orderByFields.length) {
963 query.append(", ");
964 }
965 }
966 }
967
968 Query q = session.createQuery(query.toString());
969
970 if (obc == null) {
971 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
972 start, end, false);
973
974 Collections.sort(list);
975 }
976 else {
977 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
978 start, end);
979 }
980 }
981 catch (Exception e) {
982 throw processException(e);
983 }
984 finally {
985 if (list == null) {
986 list = new ArrayList<MBDiscussion>();
987 }
988
989 cacheResult(list);
990
991 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
992
993 closeSession(session);
994 }
995 }
996
997 return list;
998 }
999
1000 public void removeByClassNameId(long classNameId) throws SystemException {
1001 for (MBDiscussion mbDiscussion : findByClassNameId(classNameId)) {
1002 remove(mbDiscussion);
1003 }
1004 }
1005
1006 public void removeByThreadId(long threadId)
1007 throws NoSuchDiscussionException, SystemException {
1008 MBDiscussion mbDiscussion = findByThreadId(threadId);
1009
1010 remove(mbDiscussion);
1011 }
1012
1013 public void removeByC_C(long classNameId, long classPK)
1014 throws NoSuchDiscussionException, SystemException {
1015 MBDiscussion mbDiscussion = findByC_C(classNameId, classPK);
1016
1017 remove(mbDiscussion);
1018 }
1019
1020 public void removeAll() throws SystemException {
1021 for (MBDiscussion mbDiscussion : findAll()) {
1022 remove(mbDiscussion);
1023 }
1024 }
1025
1026 public int countByClassNameId(long classNameId) throws SystemException {
1027 Object[] finderArgs = new Object[] { new Long(classNameId) };
1028
1029 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1030 finderArgs, this);
1031
1032 if (count == null) {
1033 Session session = null;
1034
1035 try {
1036 session = openSession();
1037
1038 StringBuilder query = new StringBuilder();
1039
1040 query.append("SELECT COUNT(mbDiscussion) ");
1041 query.append("FROM MBDiscussion mbDiscussion WHERE ");
1042
1043 query.append("mbDiscussion.classNameId = ?");
1044
1045 query.append(" ");
1046
1047 Query q = session.createQuery(query.toString());
1048
1049 QueryPos qPos = QueryPos.getInstance(q);
1050
1051 qPos.add(classNameId);
1052
1053 count = (Long)q.uniqueResult();
1054 }
1055 catch (Exception e) {
1056 throw processException(e);
1057 }
1058 finally {
1059 if (count == null) {
1060 count = Long.valueOf(0);
1061 }
1062
1063 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1064 finderArgs, count);
1065
1066 closeSession(session);
1067 }
1068 }
1069
1070 return count.intValue();
1071 }
1072
1073 public int countByThreadId(long threadId) throws SystemException {
1074 Object[] finderArgs = new Object[] { new Long(threadId) };
1075
1076 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
1077 finderArgs, this);
1078
1079 if (count == null) {
1080 Session session = null;
1081
1082 try {
1083 session = openSession();
1084
1085 StringBuilder query = new StringBuilder();
1086
1087 query.append("SELECT COUNT(mbDiscussion) ");
1088 query.append("FROM MBDiscussion mbDiscussion WHERE ");
1089
1090 query.append("mbDiscussion.threadId = ?");
1091
1092 query.append(" ");
1093
1094 Query q = session.createQuery(query.toString());
1095
1096 QueryPos qPos = QueryPos.getInstance(q);
1097
1098 qPos.add(threadId);
1099
1100 count = (Long)q.uniqueResult();
1101 }
1102 catch (Exception e) {
1103 throw processException(e);
1104 }
1105 finally {
1106 if (count == null) {
1107 count = Long.valueOf(0);
1108 }
1109
1110 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
1111 finderArgs, count);
1112
1113 closeSession(session);
1114 }
1115 }
1116
1117 return count.intValue();
1118 }
1119
1120 public int countByC_C(long classNameId, long classPK)
1121 throws SystemException {
1122 Object[] finderArgs = new Object[] {
1123 new Long(classNameId), new Long(classPK)
1124 };
1125
1126 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1127 finderArgs, this);
1128
1129 if (count == null) {
1130 Session session = null;
1131
1132 try {
1133 session = openSession();
1134
1135 StringBuilder query = new StringBuilder();
1136
1137 query.append("SELECT COUNT(mbDiscussion) ");
1138 query.append("FROM MBDiscussion mbDiscussion WHERE ");
1139
1140 query.append("mbDiscussion.classNameId = ?");
1141
1142 query.append(" AND ");
1143
1144 query.append("mbDiscussion.classPK = ?");
1145
1146 query.append(" ");
1147
1148 Query q = session.createQuery(query.toString());
1149
1150 QueryPos qPos = QueryPos.getInstance(q);
1151
1152 qPos.add(classNameId);
1153
1154 qPos.add(classPK);
1155
1156 count = (Long)q.uniqueResult();
1157 }
1158 catch (Exception e) {
1159 throw processException(e);
1160 }
1161 finally {
1162 if (count == null) {
1163 count = Long.valueOf(0);
1164 }
1165
1166 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1167 count);
1168
1169 closeSession(session);
1170 }
1171 }
1172
1173 return count.intValue();
1174 }
1175
1176 public int countAll() throws SystemException {
1177 Object[] finderArgs = new Object[0];
1178
1179 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1180 finderArgs, this);
1181
1182 if (count == null) {
1183 Session session = null;
1184
1185 try {
1186 session = openSession();
1187
1188 Query q = session.createQuery(
1189 "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion");
1190
1191 count = (Long)q.uniqueResult();
1192 }
1193 catch (Exception e) {
1194 throw processException(e);
1195 }
1196 finally {
1197 if (count == null) {
1198 count = Long.valueOf(0);
1199 }
1200
1201 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1202 count);
1203
1204 closeSession(session);
1205 }
1206 }
1207
1208 return count.intValue();
1209 }
1210
1211 public void afterPropertiesSet() {
1212 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1213 com.liferay.portal.util.PropsUtil.get(
1214 "value.object.listener.com.liferay.portlet.messageboards.model.MBDiscussion")));
1215
1216 if (listenerClassNames.length > 0) {
1217 try {
1218 List<ModelListener<MBDiscussion>> listenersList = new ArrayList<ModelListener<MBDiscussion>>();
1219
1220 for (String listenerClassName : listenerClassNames) {
1221 listenersList.add((ModelListener<MBDiscussion>)Class.forName(
1222 listenerClassName).newInstance());
1223 }
1224
1225 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1226 }
1227 catch (Exception e) {
1228 _log.error(e);
1229 }
1230 }
1231 }
1232
1233 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence.impl")
1234 protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
1235 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence.impl")
1236 protected com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence mbCategoryPersistence;
1237 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence.impl")
1238 protected com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence mbDiscussionPersistence;
1239 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
1240 protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1241 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence.impl")
1242 protected com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence mbMessageFlagPersistence;
1243 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence.impl")
1244 protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
1245 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence.impl")
1246 protected com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence mbThreadPersistence;
1247 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
1248 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1249 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1250 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1251 private static Log _log = LogFactoryUtil.getLog(MBDiscussionPersistenceImpl.class);
1252}