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