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