001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.messageboards.NoSuchDiscussionException;
044 import com.liferay.portlet.messageboards.model.MBDiscussion;
045 import com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl;
046 import com.liferay.portlet.messageboards.model.impl.MBDiscussionModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class MBDiscussionPersistenceImpl extends BasePersistenceImpl<MBDiscussion>
067 implements MBDiscussionPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = MBDiscussionImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
079 new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
080 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassNameId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
089 new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
090 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
092 new String[] { Long.class.getName() },
093 MBDiscussionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
095 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
097 new String[] { Long.class.getName() });
098 public static final FinderPath FINDER_PATH_FETCH_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
099 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
100 FINDER_CLASS_NAME_ENTITY, "fetchByThreadId",
101 new String[] { Long.class.getName() },
102 MBDiscussionModelImpl.THREADID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
104 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
106 new String[] { Long.class.getName() });
107 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
108 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
109 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
110 new String[] { Long.class.getName(), Long.class.getName() },
111 MBDiscussionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
112 MBDiscussionModelImpl.CLASSPK_COLUMN_BITMASK);
113 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
114 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
116 new String[] { Long.class.getName(), Long.class.getName() });
117 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
118 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
119 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
120 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
121 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
122 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
123 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
124 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
126
127
132 public void cacheResult(MBDiscussion mbDiscussion) {
133 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
134 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
135
136 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
137 new Object[] { Long.valueOf(mbDiscussion.getThreadId()) },
138 mbDiscussion);
139
140 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
141 new Object[] {
142 Long.valueOf(mbDiscussion.getClassNameId()),
143 Long.valueOf(mbDiscussion.getClassPK())
144 }, mbDiscussion);
145
146 mbDiscussion.resetOriginalValues();
147 }
148
149
154 public void cacheResult(List<MBDiscussion> mbDiscussions) {
155 for (MBDiscussion mbDiscussion : mbDiscussions) {
156 if (EntityCacheUtil.getResult(
157 MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
158 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey()) == null) {
159 cacheResult(mbDiscussion);
160 }
161 else {
162 mbDiscussion.resetOriginalValues();
163 }
164 }
165 }
166
167
174 @Override
175 public void clearCache() {
176 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
177 CacheRegistryUtil.clear(MBDiscussionImpl.class.getName());
178 }
179
180 EntityCacheUtil.clearCache(MBDiscussionImpl.class.getName());
181
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
185 }
186
187
194 @Override
195 public void clearCache(MBDiscussion mbDiscussion) {
196 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
197 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
198
199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
201
202 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
203 new Object[] { Long.valueOf(mbDiscussion.getThreadId()) });
204
205 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
206 new Object[] {
207 Long.valueOf(mbDiscussion.getClassNameId()),
208 Long.valueOf(mbDiscussion.getClassPK())
209 });
210 }
211
212
218 public MBDiscussion create(long discussionId) {
219 MBDiscussion mbDiscussion = new MBDiscussionImpl();
220
221 mbDiscussion.setNew(true);
222 mbDiscussion.setPrimaryKey(discussionId);
223
224 return mbDiscussion;
225 }
226
227
235 @Override
236 public MBDiscussion remove(Serializable primaryKey)
237 throws NoSuchModelException, SystemException {
238 return remove(((Long)primaryKey).longValue());
239 }
240
241
249 public MBDiscussion remove(long discussionId)
250 throws NoSuchDiscussionException, SystemException {
251 Session session = null;
252
253 try {
254 session = openSession();
255
256 MBDiscussion mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
257 Long.valueOf(discussionId));
258
259 if (mbDiscussion == null) {
260 if (_log.isWarnEnabled()) {
261 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + discussionId);
262 }
263
264 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
265 discussionId);
266 }
267
268 return mbDiscussionPersistence.remove(mbDiscussion);
269 }
270 catch (NoSuchDiscussionException nsee) {
271 throw nsee;
272 }
273 catch (Exception e) {
274 throw processException(e);
275 }
276 finally {
277 closeSession(session);
278 }
279 }
280
281
288 @Override
289 public MBDiscussion remove(MBDiscussion mbDiscussion)
290 throws SystemException {
291 return super.remove(mbDiscussion);
292 }
293
294 @Override
295 protected MBDiscussion removeImpl(MBDiscussion mbDiscussion)
296 throws SystemException {
297 mbDiscussion = toUnwrappedModel(mbDiscussion);
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.delete(session, mbDiscussion);
305 }
306 catch (Exception e) {
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312
313 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
315
316 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
317
318 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
319 new Object[] { Long.valueOf(mbDiscussionModelImpl.getThreadId()) });
320
321 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
322 new Object[] {
323 Long.valueOf(mbDiscussionModelImpl.getClassNameId()),
324 Long.valueOf(mbDiscussionModelImpl.getClassPK())
325 });
326
327 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
328 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
329
330 return mbDiscussion;
331 }
332
333 @Override
334 public MBDiscussion updateImpl(
335 com.liferay.portlet.messageboards.model.MBDiscussion mbDiscussion,
336 boolean merge) throws SystemException {
337 mbDiscussion = toUnwrappedModel(mbDiscussion);
338
339 boolean isNew = mbDiscussion.isNew();
340
341 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
342
343 Session session = null;
344
345 try {
346 session = openSession();
347
348 BatchSessionUtil.update(session, mbDiscussion, merge);
349
350 mbDiscussion.setNew(false);
351 }
352 catch (Exception e) {
353 throw processException(e);
354 }
355 finally {
356 closeSession(session);
357 }
358
359 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
360
361 if (isNew || !MBDiscussionModelImpl.COLUMN_BITMASK_ENABLED) {
362 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
363 }
364
365 else {
366 if ((mbDiscussionModelImpl.getColumnBitmask() &
367 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
368 Object[] args = new Object[] {
369 Long.valueOf(mbDiscussionModelImpl.getOriginalClassNameId())
370 };
371
372 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
373 args);
374 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
375 args);
376
377 args = new Object[] {
378 Long.valueOf(mbDiscussionModelImpl.getClassNameId())
379 };
380
381 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
382 args);
383 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
384 args);
385 }
386 }
387
388 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
389 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
390
391 if (isNew) {
392 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
393 new Object[] { Long.valueOf(mbDiscussion.getThreadId()) },
394 mbDiscussion);
395
396 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
397 new Object[] {
398 Long.valueOf(mbDiscussion.getClassNameId()),
399 Long.valueOf(mbDiscussion.getClassPK())
400 }, mbDiscussion);
401 }
402 else {
403 if ((mbDiscussionModelImpl.getColumnBitmask() &
404 FINDER_PATH_FETCH_BY_THREADID.getColumnBitmask()) != 0) {
405 Object[] args = new Object[] {
406 Long.valueOf(mbDiscussionModelImpl.getOriginalThreadId())
407 };
408
409 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
410 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID, args);
411
412 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
413 new Object[] { Long.valueOf(mbDiscussion.getThreadId()) },
414 mbDiscussion);
415 }
416
417 if ((mbDiscussionModelImpl.getColumnBitmask() &
418 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
419 Object[] args = new Object[] {
420 Long.valueOf(mbDiscussionModelImpl.getOriginalClassNameId()),
421 Long.valueOf(mbDiscussionModelImpl.getOriginalClassPK())
422 };
423
424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
425 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
426
427 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
428 new Object[] {
429 Long.valueOf(mbDiscussion.getClassNameId()),
430 Long.valueOf(mbDiscussion.getClassPK())
431 }, mbDiscussion);
432 }
433 }
434
435 return mbDiscussion;
436 }
437
438 protected MBDiscussion toUnwrappedModel(MBDiscussion mbDiscussion) {
439 if (mbDiscussion instanceof MBDiscussionImpl) {
440 return mbDiscussion;
441 }
442
443 MBDiscussionImpl mbDiscussionImpl = new MBDiscussionImpl();
444
445 mbDiscussionImpl.setNew(mbDiscussion.isNew());
446 mbDiscussionImpl.setPrimaryKey(mbDiscussion.getPrimaryKey());
447
448 mbDiscussionImpl.setDiscussionId(mbDiscussion.getDiscussionId());
449 mbDiscussionImpl.setClassNameId(mbDiscussion.getClassNameId());
450 mbDiscussionImpl.setClassPK(mbDiscussion.getClassPK());
451 mbDiscussionImpl.setThreadId(mbDiscussion.getThreadId());
452
453 return mbDiscussionImpl;
454 }
455
456
464 @Override
465 public MBDiscussion findByPrimaryKey(Serializable primaryKey)
466 throws NoSuchModelException, SystemException {
467 return findByPrimaryKey(((Long)primaryKey).longValue());
468 }
469
470
478 public MBDiscussion findByPrimaryKey(long discussionId)
479 throws NoSuchDiscussionException, SystemException {
480 MBDiscussion mbDiscussion = fetchByPrimaryKey(discussionId);
481
482 if (mbDiscussion == null) {
483 if (_log.isWarnEnabled()) {
484 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + discussionId);
485 }
486
487 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
488 discussionId);
489 }
490
491 return mbDiscussion;
492 }
493
494
501 @Override
502 public MBDiscussion fetchByPrimaryKey(Serializable primaryKey)
503 throws SystemException {
504 return fetchByPrimaryKey(((Long)primaryKey).longValue());
505 }
506
507
514 public MBDiscussion fetchByPrimaryKey(long discussionId)
515 throws SystemException {
516 MBDiscussion mbDiscussion = (MBDiscussion)EntityCacheUtil.getResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
517 MBDiscussionImpl.class, discussionId);
518
519 if (mbDiscussion == _nullMBDiscussion) {
520 return null;
521 }
522
523 if (mbDiscussion == null) {
524 Session session = null;
525
526 boolean hasException = false;
527
528 try {
529 session = openSession();
530
531 mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
532 Long.valueOf(discussionId));
533 }
534 catch (Exception e) {
535 hasException = true;
536
537 throw processException(e);
538 }
539 finally {
540 if (mbDiscussion != null) {
541 cacheResult(mbDiscussion);
542 }
543 else if (!hasException) {
544 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
545 MBDiscussionImpl.class, discussionId, _nullMBDiscussion);
546 }
547
548 closeSession(session);
549 }
550 }
551
552 return mbDiscussion;
553 }
554
555
562 public List<MBDiscussion> findByClassNameId(long classNameId)
563 throws SystemException {
564 return findByClassNameId(classNameId, QueryUtil.ALL_POS,
565 QueryUtil.ALL_POS, null);
566 }
567
568
581 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
582 int end) throws SystemException {
583 return findByClassNameId(classNameId, start, end, null);
584 }
585
586
600 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
601 int end, OrderByComparator orderByComparator) throws SystemException {
602 FinderPath finderPath = null;
603 Object[] finderArgs = null;
604
605 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
606 (orderByComparator == null)) {
607 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
608 finderArgs = new Object[] { classNameId };
609 }
610 else {
611 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
612 finderArgs = new Object[] { classNameId, start, end, orderByComparator };
613 }
614
615 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(finderPath,
616 finderArgs, this);
617
618 if (list == null) {
619 StringBundler query = null;
620
621 if (orderByComparator != null) {
622 query = new StringBundler(3 +
623 (orderByComparator.getOrderByFields().length * 3));
624 }
625 else {
626 query = new StringBundler(2);
627 }
628
629 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
630
631 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
632
633 if (orderByComparator != null) {
634 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
635 orderByComparator);
636 }
637
638 String sql = query.toString();
639
640 Session session = null;
641
642 try {
643 session = openSession();
644
645 Query q = session.createQuery(sql);
646
647 QueryPos qPos = QueryPos.getInstance(q);
648
649 qPos.add(classNameId);
650
651 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
652 start, end);
653 }
654 catch (Exception e) {
655 throw processException(e);
656 }
657 finally {
658 if (list == null) {
659 FinderCacheUtil.removeResult(finderPath, finderArgs);
660 }
661 else {
662 cacheResult(list);
663
664 FinderCacheUtil.putResult(finderPath, finderArgs, list);
665 }
666
667 closeSession(session);
668 }
669 }
670
671 return list;
672 }
673
674
687 public MBDiscussion findByClassNameId_First(long classNameId,
688 OrderByComparator orderByComparator)
689 throws NoSuchDiscussionException, SystemException {
690 List<MBDiscussion> list = findByClassNameId(classNameId, 0, 1,
691 orderByComparator);
692
693 if (list.isEmpty()) {
694 StringBundler msg = new StringBundler(4);
695
696 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
697
698 msg.append("classNameId=");
699 msg.append(classNameId);
700
701 msg.append(StringPool.CLOSE_CURLY_BRACE);
702
703 throw new NoSuchDiscussionException(msg.toString());
704 }
705 else {
706 return list.get(0);
707 }
708 }
709
710
723 public MBDiscussion findByClassNameId_Last(long classNameId,
724 OrderByComparator orderByComparator)
725 throws NoSuchDiscussionException, SystemException {
726 int count = countByClassNameId(classNameId);
727
728 List<MBDiscussion> list = findByClassNameId(classNameId, count - 1,
729 count, orderByComparator);
730
731 if (list.isEmpty()) {
732 StringBundler msg = new StringBundler(4);
733
734 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
735
736 msg.append("classNameId=");
737 msg.append(classNameId);
738
739 msg.append(StringPool.CLOSE_CURLY_BRACE);
740
741 throw new NoSuchDiscussionException(msg.toString());
742 }
743 else {
744 return list.get(0);
745 }
746 }
747
748
762 public MBDiscussion[] findByClassNameId_PrevAndNext(long discussionId,
763 long classNameId, OrderByComparator orderByComparator)
764 throws NoSuchDiscussionException, SystemException {
765 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
766
767 Session session = null;
768
769 try {
770 session = openSession();
771
772 MBDiscussion[] array = new MBDiscussionImpl[3];
773
774 array[0] = getByClassNameId_PrevAndNext(session, mbDiscussion,
775 classNameId, orderByComparator, true);
776
777 array[1] = mbDiscussion;
778
779 array[2] = getByClassNameId_PrevAndNext(session, mbDiscussion,
780 classNameId, orderByComparator, false);
781
782 return array;
783 }
784 catch (Exception e) {
785 throw processException(e);
786 }
787 finally {
788 closeSession(session);
789 }
790 }
791
792 protected MBDiscussion getByClassNameId_PrevAndNext(Session session,
793 MBDiscussion mbDiscussion, long classNameId,
794 OrderByComparator orderByComparator, boolean previous) {
795 StringBundler query = null;
796
797 if (orderByComparator != null) {
798 query = new StringBundler(6 +
799 (orderByComparator.getOrderByFields().length * 6));
800 }
801 else {
802 query = new StringBundler(3);
803 }
804
805 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
806
807 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
808
809 if (orderByComparator != null) {
810 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
811
812 if (orderByConditionFields.length > 0) {
813 query.append(WHERE_AND);
814 }
815
816 for (int i = 0; i < orderByConditionFields.length; i++) {
817 query.append(_ORDER_BY_ENTITY_ALIAS);
818 query.append(orderByConditionFields[i]);
819
820 if ((i + 1) < orderByConditionFields.length) {
821 if (orderByComparator.isAscending() ^ previous) {
822 query.append(WHERE_GREATER_THAN_HAS_NEXT);
823 }
824 else {
825 query.append(WHERE_LESSER_THAN_HAS_NEXT);
826 }
827 }
828 else {
829 if (orderByComparator.isAscending() ^ previous) {
830 query.append(WHERE_GREATER_THAN);
831 }
832 else {
833 query.append(WHERE_LESSER_THAN);
834 }
835 }
836 }
837
838 query.append(ORDER_BY_CLAUSE);
839
840 String[] orderByFields = orderByComparator.getOrderByFields();
841
842 for (int i = 0; i < orderByFields.length; i++) {
843 query.append(_ORDER_BY_ENTITY_ALIAS);
844 query.append(orderByFields[i]);
845
846 if ((i + 1) < orderByFields.length) {
847 if (orderByComparator.isAscending() ^ previous) {
848 query.append(ORDER_BY_ASC_HAS_NEXT);
849 }
850 else {
851 query.append(ORDER_BY_DESC_HAS_NEXT);
852 }
853 }
854 else {
855 if (orderByComparator.isAscending() ^ previous) {
856 query.append(ORDER_BY_ASC);
857 }
858 else {
859 query.append(ORDER_BY_DESC);
860 }
861 }
862 }
863 }
864
865 String sql = query.toString();
866
867 Query q = session.createQuery(sql);
868
869 q.setFirstResult(0);
870 q.setMaxResults(2);
871
872 QueryPos qPos = QueryPos.getInstance(q);
873
874 qPos.add(classNameId);
875
876 if (orderByComparator != null) {
877 Object[] values = orderByComparator.getOrderByConditionValues(mbDiscussion);
878
879 for (Object value : values) {
880 qPos.add(value);
881 }
882 }
883
884 List<MBDiscussion> list = q.list();
885
886 if (list.size() == 2) {
887 return list.get(1);
888 }
889 else {
890 return null;
891 }
892 }
893
894
902 public MBDiscussion findByThreadId(long threadId)
903 throws NoSuchDiscussionException, SystemException {
904 MBDiscussion mbDiscussion = fetchByThreadId(threadId);
905
906 if (mbDiscussion == null) {
907 StringBundler msg = new StringBundler(4);
908
909 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
910
911 msg.append("threadId=");
912 msg.append(threadId);
913
914 msg.append(StringPool.CLOSE_CURLY_BRACE);
915
916 if (_log.isWarnEnabled()) {
917 _log.warn(msg.toString());
918 }
919
920 throw new NoSuchDiscussionException(msg.toString());
921 }
922
923 return mbDiscussion;
924 }
925
926
933 public MBDiscussion fetchByThreadId(long threadId)
934 throws SystemException {
935 return fetchByThreadId(threadId, true);
936 }
937
938
946 public MBDiscussion fetchByThreadId(long threadId, boolean retrieveFromCache)
947 throws SystemException {
948 Object[] finderArgs = new Object[] { threadId };
949
950 Object result = null;
951
952 if (retrieveFromCache) {
953 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THREADID,
954 finderArgs, this);
955 }
956
957 if (result == null) {
958 StringBundler query = new StringBundler(2);
959
960 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
961
962 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
963
964 String sql = query.toString();
965
966 Session session = null;
967
968 try {
969 session = openSession();
970
971 Query q = session.createQuery(sql);
972
973 QueryPos qPos = QueryPos.getInstance(q);
974
975 qPos.add(threadId);
976
977 List<MBDiscussion> list = q.list();
978
979 result = list;
980
981 MBDiscussion mbDiscussion = null;
982
983 if (list.isEmpty()) {
984 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
985 finderArgs, list);
986 }
987 else {
988 mbDiscussion = list.get(0);
989
990 cacheResult(mbDiscussion);
991
992 if ((mbDiscussion.getThreadId() != threadId)) {
993 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
994 finderArgs, mbDiscussion);
995 }
996 }
997
998 return mbDiscussion;
999 }
1000 catch (Exception e) {
1001 throw processException(e);
1002 }
1003 finally {
1004 if (result == null) {
1005 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
1006 finderArgs);
1007 }
1008
1009 closeSession(session);
1010 }
1011 }
1012 else {
1013 if (result instanceof List<?>) {
1014 return null;
1015 }
1016 else {
1017 return (MBDiscussion)result;
1018 }
1019 }
1020 }
1021
1022
1031 public MBDiscussion findByC_C(long classNameId, long classPK)
1032 throws NoSuchDiscussionException, SystemException {
1033 MBDiscussion mbDiscussion = fetchByC_C(classNameId, classPK);
1034
1035 if (mbDiscussion == null) {
1036 StringBundler msg = new StringBundler(6);
1037
1038 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1039
1040 msg.append("classNameId=");
1041 msg.append(classNameId);
1042
1043 msg.append(", classPK=");
1044 msg.append(classPK);
1045
1046 msg.append(StringPool.CLOSE_CURLY_BRACE);
1047
1048 if (_log.isWarnEnabled()) {
1049 _log.warn(msg.toString());
1050 }
1051
1052 throw new NoSuchDiscussionException(msg.toString());
1053 }
1054
1055 return mbDiscussion;
1056 }
1057
1058
1066 public MBDiscussion fetchByC_C(long classNameId, long classPK)
1067 throws SystemException {
1068 return fetchByC_C(classNameId, classPK, true);
1069 }
1070
1071
1080 public MBDiscussion fetchByC_C(long classNameId, long classPK,
1081 boolean retrieveFromCache) throws SystemException {
1082 Object[] finderArgs = new Object[] { classNameId, classPK };
1083
1084 Object result = null;
1085
1086 if (retrieveFromCache) {
1087 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
1088 finderArgs, this);
1089 }
1090
1091 if (result == null) {
1092 StringBundler query = new StringBundler(3);
1093
1094 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
1095
1096 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1097
1098 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1099
1100 String sql = query.toString();
1101
1102 Session session = null;
1103
1104 try {
1105 session = openSession();
1106
1107 Query q = session.createQuery(sql);
1108
1109 QueryPos qPos = QueryPos.getInstance(q);
1110
1111 qPos.add(classNameId);
1112
1113 qPos.add(classPK);
1114
1115 List<MBDiscussion> list = q.list();
1116
1117 result = list;
1118
1119 MBDiscussion mbDiscussion = null;
1120
1121 if (list.isEmpty()) {
1122 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1123 finderArgs, list);
1124 }
1125 else {
1126 mbDiscussion = list.get(0);
1127
1128 cacheResult(mbDiscussion);
1129
1130 if ((mbDiscussion.getClassNameId() != classNameId) ||
1131 (mbDiscussion.getClassPK() != classPK)) {
1132 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1133 finderArgs, mbDiscussion);
1134 }
1135 }
1136
1137 return mbDiscussion;
1138 }
1139 catch (Exception e) {
1140 throw processException(e);
1141 }
1142 finally {
1143 if (result == null) {
1144 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
1145 finderArgs);
1146 }
1147
1148 closeSession(session);
1149 }
1150 }
1151 else {
1152 if (result instanceof List<?>) {
1153 return null;
1154 }
1155 else {
1156 return (MBDiscussion)result;
1157 }
1158 }
1159 }
1160
1161
1167 public List<MBDiscussion> findAll() throws SystemException {
1168 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1169 }
1170
1171
1183 public List<MBDiscussion> findAll(int start, int end)
1184 throws SystemException {
1185 return findAll(start, end, null);
1186 }
1187
1188
1201 public List<MBDiscussion> findAll(int start, int end,
1202 OrderByComparator orderByComparator) throws SystemException {
1203 FinderPath finderPath = null;
1204 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1205
1206 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1207 (orderByComparator == null)) {
1208 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1209 finderArgs = FINDER_ARGS_EMPTY;
1210 }
1211 else {
1212 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1213 finderArgs = new Object[] { start, end, orderByComparator };
1214 }
1215
1216 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(finderPath,
1217 finderArgs, this);
1218
1219 if (list == null) {
1220 StringBundler query = null;
1221 String sql = null;
1222
1223 if (orderByComparator != null) {
1224 query = new StringBundler(2 +
1225 (orderByComparator.getOrderByFields().length * 3));
1226
1227 query.append(_SQL_SELECT_MBDISCUSSION);
1228
1229 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1230 orderByComparator);
1231
1232 sql = query.toString();
1233 }
1234 else {
1235 sql = _SQL_SELECT_MBDISCUSSION;
1236 }
1237
1238 Session session = null;
1239
1240 try {
1241 session = openSession();
1242
1243 Query q = session.createQuery(sql);
1244
1245 if (orderByComparator == null) {
1246 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1247 start, end, false);
1248
1249 Collections.sort(list);
1250 }
1251 else {
1252 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1253 start, end);
1254 }
1255 }
1256 catch (Exception e) {
1257 throw processException(e);
1258 }
1259 finally {
1260 if (list == null) {
1261 FinderCacheUtil.removeResult(finderPath, finderArgs);
1262 }
1263 else {
1264 cacheResult(list);
1265
1266 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1267 }
1268
1269 closeSession(session);
1270 }
1271 }
1272
1273 return list;
1274 }
1275
1276
1282 public void removeByClassNameId(long classNameId) throws SystemException {
1283 for (MBDiscussion mbDiscussion : findByClassNameId(classNameId)) {
1284 mbDiscussionPersistence.remove(mbDiscussion);
1285 }
1286 }
1287
1288
1294 public void removeByThreadId(long threadId)
1295 throws NoSuchDiscussionException, SystemException {
1296 MBDiscussion mbDiscussion = findByThreadId(threadId);
1297
1298 mbDiscussionPersistence.remove(mbDiscussion);
1299 }
1300
1301
1308 public void removeByC_C(long classNameId, long classPK)
1309 throws NoSuchDiscussionException, SystemException {
1310 MBDiscussion mbDiscussion = findByC_C(classNameId, classPK);
1311
1312 mbDiscussionPersistence.remove(mbDiscussion);
1313 }
1314
1315
1320 public void removeAll() throws SystemException {
1321 for (MBDiscussion mbDiscussion : findAll()) {
1322 mbDiscussionPersistence.remove(mbDiscussion);
1323 }
1324 }
1325
1326
1333 public int countByClassNameId(long classNameId) throws SystemException {
1334 Object[] finderArgs = new Object[] { classNameId };
1335
1336 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1337 finderArgs, this);
1338
1339 if (count == null) {
1340 StringBundler query = new StringBundler(2);
1341
1342 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1343
1344 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1345
1346 String sql = query.toString();
1347
1348 Session session = null;
1349
1350 try {
1351 session = openSession();
1352
1353 Query q = session.createQuery(sql);
1354
1355 QueryPos qPos = QueryPos.getInstance(q);
1356
1357 qPos.add(classNameId);
1358
1359 count = (Long)q.uniqueResult();
1360 }
1361 catch (Exception e) {
1362 throw processException(e);
1363 }
1364 finally {
1365 if (count == null) {
1366 count = Long.valueOf(0);
1367 }
1368
1369 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1370 finderArgs, count);
1371
1372 closeSession(session);
1373 }
1374 }
1375
1376 return count.intValue();
1377 }
1378
1379
1386 public int countByThreadId(long threadId) throws SystemException {
1387 Object[] finderArgs = new Object[] { threadId };
1388
1389 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
1390 finderArgs, this);
1391
1392 if (count == null) {
1393 StringBundler query = new StringBundler(2);
1394
1395 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1396
1397 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1398
1399 String sql = query.toString();
1400
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 Query q = session.createQuery(sql);
1407
1408 QueryPos qPos = QueryPos.getInstance(q);
1409
1410 qPos.add(threadId);
1411
1412 count = (Long)q.uniqueResult();
1413 }
1414 catch (Exception e) {
1415 throw processException(e);
1416 }
1417 finally {
1418 if (count == null) {
1419 count = Long.valueOf(0);
1420 }
1421
1422 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
1423 finderArgs, count);
1424
1425 closeSession(session);
1426 }
1427 }
1428
1429 return count.intValue();
1430 }
1431
1432
1440 public int countByC_C(long classNameId, long classPK)
1441 throws SystemException {
1442 Object[] finderArgs = new Object[] { classNameId, classPK };
1443
1444 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1445 finderArgs, this);
1446
1447 if (count == null) {
1448 StringBundler query = new StringBundler(3);
1449
1450 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1451
1452 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1453
1454 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1455
1456 String sql = query.toString();
1457
1458 Session session = null;
1459
1460 try {
1461 session = openSession();
1462
1463 Query q = session.createQuery(sql);
1464
1465 QueryPos qPos = QueryPos.getInstance(q);
1466
1467 qPos.add(classNameId);
1468
1469 qPos.add(classPK);
1470
1471 count = (Long)q.uniqueResult();
1472 }
1473 catch (Exception e) {
1474 throw processException(e);
1475 }
1476 finally {
1477 if (count == null) {
1478 count = Long.valueOf(0);
1479 }
1480
1481 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1482 count);
1483
1484 closeSession(session);
1485 }
1486 }
1487
1488 return count.intValue();
1489 }
1490
1491
1497 public int countAll() throws SystemException {
1498 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1499 FINDER_ARGS_EMPTY, this);
1500
1501 if (count == null) {
1502 Session session = null;
1503
1504 try {
1505 session = openSession();
1506
1507 Query q = session.createQuery(_SQL_COUNT_MBDISCUSSION);
1508
1509 count = (Long)q.uniqueResult();
1510 }
1511 catch (Exception e) {
1512 throw processException(e);
1513 }
1514 finally {
1515 if (count == null) {
1516 count = Long.valueOf(0);
1517 }
1518
1519 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1520 FINDER_ARGS_EMPTY, count);
1521
1522 closeSession(session);
1523 }
1524 }
1525
1526 return count.intValue();
1527 }
1528
1529
1532 public void afterPropertiesSet() {
1533 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1534 com.liferay.portal.util.PropsUtil.get(
1535 "value.object.listener.com.liferay.portlet.messageboards.model.MBDiscussion")));
1536
1537 if (listenerClassNames.length > 0) {
1538 try {
1539 List<ModelListener<MBDiscussion>> listenersList = new ArrayList<ModelListener<MBDiscussion>>();
1540
1541 for (String listenerClassName : listenerClassNames) {
1542 listenersList.add((ModelListener<MBDiscussion>)InstanceFactory.newInstance(
1543 listenerClassName));
1544 }
1545
1546 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1547 }
1548 catch (Exception e) {
1549 _log.error(e);
1550 }
1551 }
1552 }
1553
1554 public void destroy() {
1555 EntityCacheUtil.removeCache(MBDiscussionImpl.class.getName());
1556 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1557 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1558 }
1559
1560 @BeanReference(type = MBBanPersistence.class)
1561 protected MBBanPersistence mbBanPersistence;
1562 @BeanReference(type = MBCategoryPersistence.class)
1563 protected MBCategoryPersistence mbCategoryPersistence;
1564 @BeanReference(type = MBDiscussionPersistence.class)
1565 protected MBDiscussionPersistence mbDiscussionPersistence;
1566 @BeanReference(type = MBMailingListPersistence.class)
1567 protected MBMailingListPersistence mbMailingListPersistence;
1568 @BeanReference(type = MBMessagePersistence.class)
1569 protected MBMessagePersistence mbMessagePersistence;
1570 @BeanReference(type = MBStatsUserPersistence.class)
1571 protected MBStatsUserPersistence mbStatsUserPersistence;
1572 @BeanReference(type = MBThreadPersistence.class)
1573 protected MBThreadPersistence mbThreadPersistence;
1574 @BeanReference(type = MBThreadFlagPersistence.class)
1575 protected MBThreadFlagPersistence mbThreadFlagPersistence;
1576 @BeanReference(type = ResourcePersistence.class)
1577 protected ResourcePersistence resourcePersistence;
1578 @BeanReference(type = UserPersistence.class)
1579 protected UserPersistence userPersistence;
1580 private static final String _SQL_SELECT_MBDISCUSSION = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion";
1581 private static final String _SQL_SELECT_MBDISCUSSION_WHERE = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ";
1582 private static final String _SQL_COUNT_MBDISCUSSION = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion";
1583 private static final String _SQL_COUNT_MBDISCUSSION_WHERE = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion WHERE ";
1584 private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "mbDiscussion.classNameId = ?";
1585 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbDiscussion.threadId = ?";
1586 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbDiscussion.classNameId = ? AND ";
1587 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbDiscussion.classPK = ?";
1588 private static final String _ORDER_BY_ENTITY_ALIAS = "mbDiscussion.";
1589 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBDiscussion exists with the primary key ";
1590 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBDiscussion exists with the key {";
1591 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1592 private static Log _log = LogFactoryUtil.getLog(MBDiscussionPersistenceImpl.class);
1593 private static MBDiscussion _nullMBDiscussion = new MBDiscussionImpl() {
1594 @Override
1595 public Object clone() {
1596 return this;
1597 }
1598
1599 @Override
1600 public CacheModel<MBDiscussion> toCacheModel() {
1601 return _nullMBDiscussionCacheModel;
1602 }
1603 };
1604
1605 private static CacheModel<MBDiscussion> _nullMBDiscussionCacheModel = new CacheModel<MBDiscussion>() {
1606 public MBDiscussion toEntityModel() {
1607 return _nullMBDiscussion;
1608 }
1609 };
1610 }