001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.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.ModelListener;
037 import com.liferay.portal.service.persistence.BatchSessionUtil;
038 import com.liferay.portal.service.persistence.ResourcePersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.messageboards.NoSuchDiscussionException;
043 import com.liferay.portlet.messageboards.model.MBDiscussion;
044 import com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl;
045 import com.liferay.portlet.messageboards.model.impl.MBDiscussionModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
069 public class MBDiscussionPersistenceImpl extends BasePersistenceImpl<MBDiscussion>
070 implements MBDiscussionPersistence {
071 public static final String FINDER_CLASS_NAME_ENTITY = MBDiscussionImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073 ".List";
074 public static final FinderPath FINDER_PATH_FIND_BY_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
075 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076 "findByClassNameId",
077 new String[] {
078 Long.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
084 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085 "countByClassNameId", new String[] { Long.class.getName() });
086 public static final FinderPath FINDER_PATH_FETCH_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
087 MBDiscussionModelImpl.FINDER_CACHE_ENABLED,
088 FINDER_CLASS_NAME_ENTITY, "fetchByThreadId",
089 new String[] { Long.class.getName() });
090 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
091 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
092 "countByThreadId", new String[] { Long.class.getName() });
093 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
094 MBDiscussionModelImpl.FINDER_CACHE_ENABLED,
095 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
096 new String[] { Long.class.getName(), Long.class.getName() });
097 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
098 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
099 "countByC_C",
100 new String[] { Long.class.getName(), Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
102 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "findAll", new String[0]);
104 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
105 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106 "countAll", new String[0]);
107
108
113 public void cacheResult(MBDiscussion mbDiscussion) {
114 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
115 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
116
117 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
118 new Object[] { new Long(mbDiscussion.getThreadId()) }, mbDiscussion);
119
120 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
121 new Object[] {
122 new Long(mbDiscussion.getClassNameId()),
123 new Long(mbDiscussion.getClassPK())
124 }, mbDiscussion);
125 }
126
127
132 public void cacheResult(List<MBDiscussion> mbDiscussions) {
133 for (MBDiscussion mbDiscussion : mbDiscussions) {
134 if (EntityCacheUtil.getResult(
135 MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
136 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(),
137 this) == null) {
138 cacheResult(mbDiscussion);
139 }
140 }
141 }
142
143
150 public void clearCache() {
151 CacheRegistryUtil.clear(MBDiscussionImpl.class.getName());
152 EntityCacheUtil.clearCache(MBDiscussionImpl.class.getName());
153 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
154 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
155 }
156
157
164 public void clearCache(MBDiscussion mbDiscussion) {
165 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
166 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
167
168 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
169 new Object[] { new Long(mbDiscussion.getThreadId()) });
170
171 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
172 new Object[] {
173 new Long(mbDiscussion.getClassNameId()),
174 new Long(mbDiscussion.getClassPK())
175 });
176 }
177
178
184 public MBDiscussion create(long discussionId) {
185 MBDiscussion mbDiscussion = new MBDiscussionImpl();
186
187 mbDiscussion.setNew(true);
188 mbDiscussion.setPrimaryKey(discussionId);
189
190 return mbDiscussion;
191 }
192
193
201 public MBDiscussion remove(Serializable primaryKey)
202 throws NoSuchModelException, SystemException {
203 return remove(((Long)primaryKey).longValue());
204 }
205
206
214 public MBDiscussion remove(long discussionId)
215 throws NoSuchDiscussionException, SystemException {
216 Session session = null;
217
218 try {
219 session = openSession();
220
221 MBDiscussion mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
222 new Long(discussionId));
223
224 if (mbDiscussion == null) {
225 if (_log.isWarnEnabled()) {
226 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + discussionId);
227 }
228
229 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
230 discussionId);
231 }
232
233 return remove(mbDiscussion);
234 }
235 catch (NoSuchDiscussionException nsee) {
236 throw nsee;
237 }
238 catch (Exception e) {
239 throw processException(e);
240 }
241 finally {
242 closeSession(session);
243 }
244 }
245
246 protected MBDiscussion removeImpl(MBDiscussion mbDiscussion)
247 throws SystemException {
248 mbDiscussion = toUnwrappedModel(mbDiscussion);
249
250 Session session = null;
251
252 try {
253 session = openSession();
254
255 if (mbDiscussion.isCachedModel() || BatchSessionUtil.isEnabled()) {
256 Object staleObject = session.get(MBDiscussionImpl.class,
257 mbDiscussion.getPrimaryKeyObj());
258
259 if (staleObject != null) {
260 session.evict(staleObject);
261 }
262 }
263
264 session.delete(mbDiscussion);
265
266 session.flush();
267 }
268 catch (Exception e) {
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274
275 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
276
277 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
278
279 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
280 new Object[] { new Long(mbDiscussionModelImpl.getOriginalThreadId()) });
281
282 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
283 new Object[] {
284 new Long(mbDiscussionModelImpl.getOriginalClassNameId()),
285 new Long(mbDiscussionModelImpl.getOriginalClassPK())
286 });
287
288 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
289 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
290
291 return mbDiscussion;
292 }
293
294 public MBDiscussion updateImpl(
295 com.liferay.portlet.messageboards.model.MBDiscussion mbDiscussion,
296 boolean merge) throws SystemException {
297 mbDiscussion = toUnwrappedModel(mbDiscussion);
298
299 boolean isNew = mbDiscussion.isNew();
300
301 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
302
303 Session session = null;
304
305 try {
306 session = openSession();
307
308 BatchSessionUtil.update(session, mbDiscussion, merge);
309
310 mbDiscussion.setNew(false);
311 }
312 catch (Exception e) {
313 throw processException(e);
314 }
315 finally {
316 closeSession(session);
317 }
318
319 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
320
321 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
322 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
323
324 if (!isNew &&
325 (mbDiscussion.getThreadId() != mbDiscussionModelImpl.getOriginalThreadId())) {
326 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
327 new Object[] {
328 new Long(mbDiscussionModelImpl.getOriginalThreadId())
329 });
330 }
331
332 if (isNew ||
333 (mbDiscussion.getThreadId() != mbDiscussionModelImpl.getOriginalThreadId())) {
334 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
335 new Object[] { new Long(mbDiscussion.getThreadId()) },
336 mbDiscussion);
337 }
338
339 if (!isNew &&
340 ((mbDiscussion.getClassNameId() != mbDiscussionModelImpl.getOriginalClassNameId()) ||
341 (mbDiscussion.getClassPK() != mbDiscussionModelImpl.getOriginalClassPK()))) {
342 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
343 new Object[] {
344 new Long(mbDiscussionModelImpl.getOriginalClassNameId()),
345 new Long(mbDiscussionModelImpl.getOriginalClassPK())
346 });
347 }
348
349 if (isNew ||
350 ((mbDiscussion.getClassNameId() != mbDiscussionModelImpl.getOriginalClassNameId()) ||
351 (mbDiscussion.getClassPK() != mbDiscussionModelImpl.getOriginalClassPK()))) {
352 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
353 new Object[] {
354 new Long(mbDiscussion.getClassNameId()),
355 new Long(mbDiscussion.getClassPK())
356 }, mbDiscussion);
357 }
358
359 return mbDiscussion;
360 }
361
362 protected MBDiscussion toUnwrappedModel(MBDiscussion mbDiscussion) {
363 if (mbDiscussion instanceof MBDiscussionImpl) {
364 return mbDiscussion;
365 }
366
367 MBDiscussionImpl mbDiscussionImpl = new MBDiscussionImpl();
368
369 mbDiscussionImpl.setNew(mbDiscussion.isNew());
370 mbDiscussionImpl.setPrimaryKey(mbDiscussion.getPrimaryKey());
371
372 mbDiscussionImpl.setDiscussionId(mbDiscussion.getDiscussionId());
373 mbDiscussionImpl.setClassNameId(mbDiscussion.getClassNameId());
374 mbDiscussionImpl.setClassPK(mbDiscussion.getClassPK());
375 mbDiscussionImpl.setThreadId(mbDiscussion.getThreadId());
376
377 return mbDiscussionImpl;
378 }
379
380
388 public MBDiscussion findByPrimaryKey(Serializable primaryKey)
389 throws NoSuchModelException, SystemException {
390 return findByPrimaryKey(((Long)primaryKey).longValue());
391 }
392
393
401 public MBDiscussion findByPrimaryKey(long discussionId)
402 throws NoSuchDiscussionException, SystemException {
403 MBDiscussion mbDiscussion = fetchByPrimaryKey(discussionId);
404
405 if (mbDiscussion == null) {
406 if (_log.isWarnEnabled()) {
407 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + discussionId);
408 }
409
410 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
411 discussionId);
412 }
413
414 return mbDiscussion;
415 }
416
417
424 public MBDiscussion fetchByPrimaryKey(Serializable primaryKey)
425 throws SystemException {
426 return fetchByPrimaryKey(((Long)primaryKey).longValue());
427 }
428
429
436 public MBDiscussion fetchByPrimaryKey(long discussionId)
437 throws SystemException {
438 MBDiscussion mbDiscussion = (MBDiscussion)EntityCacheUtil.getResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
439 MBDiscussionImpl.class, discussionId, this);
440
441 if (mbDiscussion == null) {
442 Session session = null;
443
444 try {
445 session = openSession();
446
447 mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
448 new Long(discussionId));
449 }
450 catch (Exception e) {
451 throw processException(e);
452 }
453 finally {
454 if (mbDiscussion != null) {
455 cacheResult(mbDiscussion);
456 }
457
458 closeSession(session);
459 }
460 }
461
462 return mbDiscussion;
463 }
464
465
472 public List<MBDiscussion> findByClassNameId(long classNameId)
473 throws SystemException {
474 return findByClassNameId(classNameId, QueryUtil.ALL_POS,
475 QueryUtil.ALL_POS, null);
476 }
477
478
491 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
492 int end) throws SystemException {
493 return findByClassNameId(classNameId, start, end, null);
494 }
495
496
510 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
511 int end, OrderByComparator orderByComparator) throws SystemException {
512 Object[] finderArgs = new Object[] {
513 classNameId,
514
515 String.valueOf(start), String.valueOf(end),
516 String.valueOf(orderByComparator)
517 };
518
519 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
520 finderArgs, this);
521
522 if (list == null) {
523 Session session = null;
524
525 try {
526 session = openSession();
527
528 StringBundler query = null;
529
530 if (orderByComparator != null) {
531 query = new StringBundler(3 +
532 (orderByComparator.getOrderByFields().length * 3));
533 }
534 else {
535 query = new StringBundler(2);
536 }
537
538 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
539
540 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
541
542 if (orderByComparator != null) {
543 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
544 orderByComparator);
545 }
546
547 String sql = query.toString();
548
549 Query q = session.createQuery(sql);
550
551 QueryPos qPos = QueryPos.getInstance(q);
552
553 qPos.add(classNameId);
554
555 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
556 start, end);
557 }
558 catch (Exception e) {
559 throw processException(e);
560 }
561 finally {
562 if (list == null) {
563 list = new ArrayList<MBDiscussion>();
564 }
565
566 cacheResult(list);
567
568 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
569 finderArgs, list);
570
571 closeSession(session);
572 }
573 }
574
575 return list;
576 }
577
578
591 public MBDiscussion findByClassNameId_First(long classNameId,
592 OrderByComparator orderByComparator)
593 throws NoSuchDiscussionException, SystemException {
594 List<MBDiscussion> list = findByClassNameId(classNameId, 0, 1,
595 orderByComparator);
596
597 if (list.isEmpty()) {
598 StringBundler msg = new StringBundler(4);
599
600 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
601
602 msg.append("classNameId=");
603 msg.append(classNameId);
604
605 msg.append(StringPool.CLOSE_CURLY_BRACE);
606
607 throw new NoSuchDiscussionException(msg.toString());
608 }
609 else {
610 return list.get(0);
611 }
612 }
613
614
627 public MBDiscussion findByClassNameId_Last(long classNameId,
628 OrderByComparator orderByComparator)
629 throws NoSuchDiscussionException, SystemException {
630 int count = countByClassNameId(classNameId);
631
632 List<MBDiscussion> list = findByClassNameId(classNameId, count - 1,
633 count, orderByComparator);
634
635 if (list.isEmpty()) {
636 StringBundler msg = new StringBundler(4);
637
638 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
639
640 msg.append("classNameId=");
641 msg.append(classNameId);
642
643 msg.append(StringPool.CLOSE_CURLY_BRACE);
644
645 throw new NoSuchDiscussionException(msg.toString());
646 }
647 else {
648 return list.get(0);
649 }
650 }
651
652
666 public MBDiscussion[] findByClassNameId_PrevAndNext(long discussionId,
667 long classNameId, OrderByComparator orderByComparator)
668 throws NoSuchDiscussionException, SystemException {
669 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
670
671 Session session = null;
672
673 try {
674 session = openSession();
675
676 MBDiscussion[] array = new MBDiscussionImpl[3];
677
678 array[0] = getByClassNameId_PrevAndNext(session, mbDiscussion,
679 classNameId, orderByComparator, true);
680
681 array[1] = mbDiscussion;
682
683 array[2] = getByClassNameId_PrevAndNext(session, mbDiscussion,
684 classNameId, orderByComparator, false);
685
686 return array;
687 }
688 catch (Exception e) {
689 throw processException(e);
690 }
691 finally {
692 closeSession(session);
693 }
694 }
695
696 protected MBDiscussion getByClassNameId_PrevAndNext(Session session,
697 MBDiscussion mbDiscussion, long classNameId,
698 OrderByComparator orderByComparator, boolean previous) {
699 StringBundler query = null;
700
701 if (orderByComparator != null) {
702 query = new StringBundler(6 +
703 (orderByComparator.getOrderByFields().length * 6));
704 }
705 else {
706 query = new StringBundler(3);
707 }
708
709 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
710
711 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
712
713 if (orderByComparator != null) {
714 String[] orderByFields = orderByComparator.getOrderByFields();
715
716 if (orderByFields.length > 0) {
717 query.append(WHERE_AND);
718 }
719
720 for (int i = 0; i < orderByFields.length; i++) {
721 query.append(_ORDER_BY_ENTITY_ALIAS);
722 query.append(orderByFields[i]);
723
724 if ((i + 1) < orderByFields.length) {
725 if (orderByComparator.isAscending() ^ previous) {
726 query.append(WHERE_GREATER_THAN_HAS_NEXT);
727 }
728 else {
729 query.append(WHERE_LESSER_THAN_HAS_NEXT);
730 }
731 }
732 else {
733 if (orderByComparator.isAscending() ^ previous) {
734 query.append(WHERE_GREATER_THAN);
735 }
736 else {
737 query.append(WHERE_LESSER_THAN);
738 }
739 }
740 }
741
742 query.append(ORDER_BY_CLAUSE);
743
744 for (int i = 0; i < orderByFields.length; i++) {
745 query.append(_ORDER_BY_ENTITY_ALIAS);
746 query.append(orderByFields[i]);
747
748 if ((i + 1) < orderByFields.length) {
749 if (orderByComparator.isAscending() ^ previous) {
750 query.append(ORDER_BY_ASC_HAS_NEXT);
751 }
752 else {
753 query.append(ORDER_BY_DESC_HAS_NEXT);
754 }
755 }
756 else {
757 if (orderByComparator.isAscending() ^ previous) {
758 query.append(ORDER_BY_ASC);
759 }
760 else {
761 query.append(ORDER_BY_DESC);
762 }
763 }
764 }
765 }
766
767 String sql = query.toString();
768
769 Query q = session.createQuery(sql);
770
771 q.setFirstResult(0);
772 q.setMaxResults(2);
773
774 QueryPos qPos = QueryPos.getInstance(q);
775
776 qPos.add(classNameId);
777
778 if (orderByComparator != null) {
779 Object[] values = orderByComparator.getOrderByValues(mbDiscussion);
780
781 for (Object value : values) {
782 qPos.add(value);
783 }
784 }
785
786 List<MBDiscussion> list = q.list();
787
788 if (list.size() == 2) {
789 return list.get(1);
790 }
791 else {
792 return null;
793 }
794 }
795
796
804 public MBDiscussion findByThreadId(long threadId)
805 throws NoSuchDiscussionException, SystemException {
806 MBDiscussion mbDiscussion = fetchByThreadId(threadId);
807
808 if (mbDiscussion == null) {
809 StringBundler msg = new StringBundler(4);
810
811 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
812
813 msg.append("threadId=");
814 msg.append(threadId);
815
816 msg.append(StringPool.CLOSE_CURLY_BRACE);
817
818 if (_log.isWarnEnabled()) {
819 _log.warn(msg.toString());
820 }
821
822 throw new NoSuchDiscussionException(msg.toString());
823 }
824
825 return mbDiscussion;
826 }
827
828
835 public MBDiscussion fetchByThreadId(long threadId)
836 throws SystemException {
837 return fetchByThreadId(threadId, true);
838 }
839
840
847 public MBDiscussion fetchByThreadId(long threadId, boolean retrieveFromCache)
848 throws SystemException {
849 Object[] finderArgs = new Object[] { threadId };
850
851 Object result = null;
852
853 if (retrieveFromCache) {
854 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THREADID,
855 finderArgs, this);
856 }
857
858 if (result == null) {
859 Session session = null;
860
861 try {
862 session = openSession();
863
864 StringBundler query = new StringBundler(2);
865
866 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
867
868 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
869
870 String sql = query.toString();
871
872 Query q = session.createQuery(sql);
873
874 QueryPos qPos = QueryPos.getInstance(q);
875
876 qPos.add(threadId);
877
878 List<MBDiscussion> list = q.list();
879
880 result = list;
881
882 MBDiscussion mbDiscussion = null;
883
884 if (list.isEmpty()) {
885 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
886 finderArgs, list);
887 }
888 else {
889 mbDiscussion = list.get(0);
890
891 cacheResult(mbDiscussion);
892
893 if ((mbDiscussion.getThreadId() != threadId)) {
894 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
895 finderArgs, mbDiscussion);
896 }
897 }
898
899 return mbDiscussion;
900 }
901 catch (Exception e) {
902 throw processException(e);
903 }
904 finally {
905 if (result == null) {
906 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
907 finderArgs, new ArrayList<MBDiscussion>());
908 }
909
910 closeSession(session);
911 }
912 }
913 else {
914 if (result instanceof List<?>) {
915 return null;
916 }
917 else {
918 return (MBDiscussion)result;
919 }
920 }
921 }
922
923
932 public MBDiscussion findByC_C(long classNameId, long classPK)
933 throws NoSuchDiscussionException, SystemException {
934 MBDiscussion mbDiscussion = fetchByC_C(classNameId, classPK);
935
936 if (mbDiscussion == null) {
937 StringBundler msg = new StringBundler(6);
938
939 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
940
941 msg.append("classNameId=");
942 msg.append(classNameId);
943
944 msg.append(", classPK=");
945 msg.append(classPK);
946
947 msg.append(StringPool.CLOSE_CURLY_BRACE);
948
949 if (_log.isWarnEnabled()) {
950 _log.warn(msg.toString());
951 }
952
953 throw new NoSuchDiscussionException(msg.toString());
954 }
955
956 return mbDiscussion;
957 }
958
959
967 public MBDiscussion fetchByC_C(long classNameId, long classPK)
968 throws SystemException {
969 return fetchByC_C(classNameId, classPK, true);
970 }
971
972
980 public MBDiscussion fetchByC_C(long classNameId, long classPK,
981 boolean retrieveFromCache) throws SystemException {
982 Object[] finderArgs = new Object[] { classNameId, classPK };
983
984 Object result = null;
985
986 if (retrieveFromCache) {
987 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
988 finderArgs, this);
989 }
990
991 if (result == null) {
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 StringBundler query = new StringBundler(3);
998
999 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
1000
1001 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1002
1003 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1004
1005 String sql = query.toString();
1006
1007 Query q = session.createQuery(sql);
1008
1009 QueryPos qPos = QueryPos.getInstance(q);
1010
1011 qPos.add(classNameId);
1012
1013 qPos.add(classPK);
1014
1015 List<MBDiscussion> list = q.list();
1016
1017 result = list;
1018
1019 MBDiscussion mbDiscussion = null;
1020
1021 if (list.isEmpty()) {
1022 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1023 finderArgs, list);
1024 }
1025 else {
1026 mbDiscussion = list.get(0);
1027
1028 cacheResult(mbDiscussion);
1029
1030 if ((mbDiscussion.getClassNameId() != classNameId) ||
1031 (mbDiscussion.getClassPK() != classPK)) {
1032 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1033 finderArgs, mbDiscussion);
1034 }
1035 }
1036
1037 return mbDiscussion;
1038 }
1039 catch (Exception e) {
1040 throw processException(e);
1041 }
1042 finally {
1043 if (result == null) {
1044 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1045 finderArgs, new ArrayList<MBDiscussion>());
1046 }
1047
1048 closeSession(session);
1049 }
1050 }
1051 else {
1052 if (result instanceof List<?>) {
1053 return null;
1054 }
1055 else {
1056 return (MBDiscussion)result;
1057 }
1058 }
1059 }
1060
1061
1067 public List<MBDiscussion> findAll() throws SystemException {
1068 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1069 }
1070
1071
1083 public List<MBDiscussion> findAll(int start, int end)
1084 throws SystemException {
1085 return findAll(start, end, null);
1086 }
1087
1088
1101 public List<MBDiscussion> findAll(int start, int end,
1102 OrderByComparator orderByComparator) throws SystemException {
1103 Object[] finderArgs = new Object[] {
1104 String.valueOf(start), String.valueOf(end),
1105 String.valueOf(orderByComparator)
1106 };
1107
1108 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1109 finderArgs, this);
1110
1111 if (list == null) {
1112 Session session = null;
1113
1114 try {
1115 session = openSession();
1116
1117 StringBundler query = null;
1118 String sql = null;
1119
1120 if (orderByComparator != null) {
1121 query = new StringBundler(2 +
1122 (orderByComparator.getOrderByFields().length * 3));
1123
1124 query.append(_SQL_SELECT_MBDISCUSSION);
1125
1126 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1127 orderByComparator);
1128
1129 sql = query.toString();
1130 }
1131 else {
1132 sql = _SQL_SELECT_MBDISCUSSION;
1133 }
1134
1135 Query q = session.createQuery(sql);
1136
1137 if (orderByComparator == null) {
1138 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1139 start, end, false);
1140
1141 Collections.sort(list);
1142 }
1143 else {
1144 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1145 start, end);
1146 }
1147 }
1148 catch (Exception e) {
1149 throw processException(e);
1150 }
1151 finally {
1152 if (list == null) {
1153 list = new ArrayList<MBDiscussion>();
1154 }
1155
1156 cacheResult(list);
1157
1158 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1159
1160 closeSession(session);
1161 }
1162 }
1163
1164 return list;
1165 }
1166
1167
1173 public void removeByClassNameId(long classNameId) throws SystemException {
1174 for (MBDiscussion mbDiscussion : findByClassNameId(classNameId)) {
1175 remove(mbDiscussion);
1176 }
1177 }
1178
1179
1185 public void removeByThreadId(long threadId)
1186 throws NoSuchDiscussionException, SystemException {
1187 MBDiscussion mbDiscussion = findByThreadId(threadId);
1188
1189 remove(mbDiscussion);
1190 }
1191
1192
1199 public void removeByC_C(long classNameId, long classPK)
1200 throws NoSuchDiscussionException, SystemException {
1201 MBDiscussion mbDiscussion = findByC_C(classNameId, classPK);
1202
1203 remove(mbDiscussion);
1204 }
1205
1206
1211 public void removeAll() throws SystemException {
1212 for (MBDiscussion mbDiscussion : findAll()) {
1213 remove(mbDiscussion);
1214 }
1215 }
1216
1217
1224 public int countByClassNameId(long classNameId) throws SystemException {
1225 Object[] finderArgs = new Object[] { classNameId };
1226
1227 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1228 finderArgs, this);
1229
1230 if (count == null) {
1231 Session session = null;
1232
1233 try {
1234 session = openSession();
1235
1236 StringBundler query = new StringBundler(2);
1237
1238 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1239
1240 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1241
1242 String sql = query.toString();
1243
1244 Query q = session.createQuery(sql);
1245
1246 QueryPos qPos = QueryPos.getInstance(q);
1247
1248 qPos.add(classNameId);
1249
1250 count = (Long)q.uniqueResult();
1251 }
1252 catch (Exception e) {
1253 throw processException(e);
1254 }
1255 finally {
1256 if (count == null) {
1257 count = Long.valueOf(0);
1258 }
1259
1260 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1261 finderArgs, count);
1262
1263 closeSession(session);
1264 }
1265 }
1266
1267 return count.intValue();
1268 }
1269
1270
1277 public int countByThreadId(long threadId) throws SystemException {
1278 Object[] finderArgs = new Object[] { threadId };
1279
1280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
1281 finderArgs, this);
1282
1283 if (count == null) {
1284 Session session = null;
1285
1286 try {
1287 session = openSession();
1288
1289 StringBundler query = new StringBundler(2);
1290
1291 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1292
1293 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1294
1295 String sql = query.toString();
1296
1297 Query q = session.createQuery(sql);
1298
1299 QueryPos qPos = QueryPos.getInstance(q);
1300
1301 qPos.add(threadId);
1302
1303 count = (Long)q.uniqueResult();
1304 }
1305 catch (Exception e) {
1306 throw processException(e);
1307 }
1308 finally {
1309 if (count == null) {
1310 count = Long.valueOf(0);
1311 }
1312
1313 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
1314 finderArgs, count);
1315
1316 closeSession(session);
1317 }
1318 }
1319
1320 return count.intValue();
1321 }
1322
1323
1331 public int countByC_C(long classNameId, long classPK)
1332 throws SystemException {
1333 Object[] finderArgs = new Object[] { classNameId, classPK };
1334
1335 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1336 finderArgs, this);
1337
1338 if (count == null) {
1339 Session session = null;
1340
1341 try {
1342 session = openSession();
1343
1344 StringBundler query = new StringBundler(3);
1345
1346 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1347
1348 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1349
1350 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1351
1352 String sql = query.toString();
1353
1354 Query q = session.createQuery(sql);
1355
1356 QueryPos qPos = QueryPos.getInstance(q);
1357
1358 qPos.add(classNameId);
1359
1360 qPos.add(classPK);
1361
1362 count = (Long)q.uniqueResult();
1363 }
1364 catch (Exception e) {
1365 throw processException(e);
1366 }
1367 finally {
1368 if (count == null) {
1369 count = Long.valueOf(0);
1370 }
1371
1372 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1373 count);
1374
1375 closeSession(session);
1376 }
1377 }
1378
1379 return count.intValue();
1380 }
1381
1382
1388 public int countAll() throws SystemException {
1389 Object[] finderArgs = new Object[0];
1390
1391 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1392 finderArgs, this);
1393
1394 if (count == null) {
1395 Session session = null;
1396
1397 try {
1398 session = openSession();
1399
1400 Query q = session.createQuery(_SQL_COUNT_MBDISCUSSION);
1401
1402 count = (Long)q.uniqueResult();
1403 }
1404 catch (Exception e) {
1405 throw processException(e);
1406 }
1407 finally {
1408 if (count == null) {
1409 count = Long.valueOf(0);
1410 }
1411
1412 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1413 count);
1414
1415 closeSession(session);
1416 }
1417 }
1418
1419 return count.intValue();
1420 }
1421
1422
1425 public void afterPropertiesSet() {
1426 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1427 com.liferay.portal.util.PropsUtil.get(
1428 "value.object.listener.com.liferay.portlet.messageboards.model.MBDiscussion")));
1429
1430 if (listenerClassNames.length > 0) {
1431 try {
1432 List<ModelListener<MBDiscussion>> listenersList = new ArrayList<ModelListener<MBDiscussion>>();
1433
1434 for (String listenerClassName : listenerClassNames) {
1435 listenersList.add((ModelListener<MBDiscussion>)InstanceFactory.newInstance(
1436 listenerClassName));
1437 }
1438
1439 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1440 }
1441 catch (Exception e) {
1442 _log.error(e);
1443 }
1444 }
1445 }
1446
1447 @BeanReference(type = MBBanPersistence.class)
1448 protected MBBanPersistence mbBanPersistence;
1449 @BeanReference(type = MBCategoryPersistence.class)
1450 protected MBCategoryPersistence mbCategoryPersistence;
1451 @BeanReference(type = MBDiscussionPersistence.class)
1452 protected MBDiscussionPersistence mbDiscussionPersistence;
1453 @BeanReference(type = MBMailingListPersistence.class)
1454 protected MBMailingListPersistence mbMailingListPersistence;
1455 @BeanReference(type = MBMessagePersistence.class)
1456 protected MBMessagePersistence mbMessagePersistence;
1457 @BeanReference(type = MBMessageFlagPersistence.class)
1458 protected MBMessageFlagPersistence mbMessageFlagPersistence;
1459 @BeanReference(type = MBStatsUserPersistence.class)
1460 protected MBStatsUserPersistence mbStatsUserPersistence;
1461 @BeanReference(type = MBThreadPersistence.class)
1462 protected MBThreadPersistence mbThreadPersistence;
1463 @BeanReference(type = ResourcePersistence.class)
1464 protected ResourcePersistence resourcePersistence;
1465 @BeanReference(type = UserPersistence.class)
1466 protected UserPersistence userPersistence;
1467 private static final String _SQL_SELECT_MBDISCUSSION = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion";
1468 private static final String _SQL_SELECT_MBDISCUSSION_WHERE = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ";
1469 private static final String _SQL_COUNT_MBDISCUSSION = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion";
1470 private static final String _SQL_COUNT_MBDISCUSSION_WHERE = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion WHERE ";
1471 private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "mbDiscussion.classNameId = ?";
1472 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbDiscussion.threadId = ?";
1473 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbDiscussion.classNameId = ? AND ";
1474 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbDiscussion.classPK = ?";
1475 private static final String _ORDER_BY_ENTITY_ALIAS = "mbDiscussion.";
1476 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBDiscussion exists with the primary key ";
1477 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBDiscussion exists with the key {";
1478 private static Log _log = LogFactoryUtil.getLog(MBDiscussionPersistenceImpl.class);
1479 }