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