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 BatchSessionUtil.delete(session, mbDiscussion);
256 }
257 catch (Exception e) {
258 throw processException(e);
259 }
260 finally {
261 closeSession(session);
262 }
263
264 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
265
266 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
267
268 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
269 new Object[] { new Long(mbDiscussionModelImpl.getOriginalThreadId()) });
270
271 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
272 new Object[] {
273 new Long(mbDiscussionModelImpl.getOriginalClassNameId()),
274 new Long(mbDiscussionModelImpl.getOriginalClassPK())
275 });
276
277 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
278 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
279
280 return mbDiscussion;
281 }
282
283 public MBDiscussion updateImpl(
284 com.liferay.portlet.messageboards.model.MBDiscussion mbDiscussion,
285 boolean merge) throws SystemException {
286 mbDiscussion = toUnwrappedModel(mbDiscussion);
287
288 boolean isNew = mbDiscussion.isNew();
289
290 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
291
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 BatchSessionUtil.update(session, mbDiscussion, merge);
298
299 mbDiscussion.setNew(false);
300 }
301 catch (Exception e) {
302 throw processException(e);
303 }
304 finally {
305 closeSession(session);
306 }
307
308 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
309
310 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
311 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
312
313 if (!isNew &&
314 (mbDiscussion.getThreadId() != mbDiscussionModelImpl.getOriginalThreadId())) {
315 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
316 new Object[] {
317 new Long(mbDiscussionModelImpl.getOriginalThreadId())
318 });
319 }
320
321 if (isNew ||
322 (mbDiscussion.getThreadId() != mbDiscussionModelImpl.getOriginalThreadId())) {
323 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
324 new Object[] { new Long(mbDiscussion.getThreadId()) },
325 mbDiscussion);
326 }
327
328 if (!isNew &&
329 ((mbDiscussion.getClassNameId() != mbDiscussionModelImpl.getOriginalClassNameId()) ||
330 (mbDiscussion.getClassPK() != mbDiscussionModelImpl.getOriginalClassPK()))) {
331 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
332 new Object[] {
333 new Long(mbDiscussionModelImpl.getOriginalClassNameId()),
334 new Long(mbDiscussionModelImpl.getOriginalClassPK())
335 });
336 }
337
338 if (isNew ||
339 ((mbDiscussion.getClassNameId() != mbDiscussionModelImpl.getOriginalClassNameId()) ||
340 (mbDiscussion.getClassPK() != mbDiscussionModelImpl.getOriginalClassPK()))) {
341 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
342 new Object[] {
343 new Long(mbDiscussion.getClassNameId()),
344 new Long(mbDiscussion.getClassPK())
345 }, mbDiscussion);
346 }
347
348 return mbDiscussion;
349 }
350
351 protected MBDiscussion toUnwrappedModel(MBDiscussion mbDiscussion) {
352 if (mbDiscussion instanceof MBDiscussionImpl) {
353 return mbDiscussion;
354 }
355
356 MBDiscussionImpl mbDiscussionImpl = new MBDiscussionImpl();
357
358 mbDiscussionImpl.setNew(mbDiscussion.isNew());
359 mbDiscussionImpl.setPrimaryKey(mbDiscussion.getPrimaryKey());
360
361 mbDiscussionImpl.setDiscussionId(mbDiscussion.getDiscussionId());
362 mbDiscussionImpl.setClassNameId(mbDiscussion.getClassNameId());
363 mbDiscussionImpl.setClassPK(mbDiscussion.getClassPK());
364 mbDiscussionImpl.setThreadId(mbDiscussion.getThreadId());
365
366 return mbDiscussionImpl;
367 }
368
369
377 public MBDiscussion findByPrimaryKey(Serializable primaryKey)
378 throws NoSuchModelException, SystemException {
379 return findByPrimaryKey(((Long)primaryKey).longValue());
380 }
381
382
390 public MBDiscussion findByPrimaryKey(long discussionId)
391 throws NoSuchDiscussionException, SystemException {
392 MBDiscussion mbDiscussion = fetchByPrimaryKey(discussionId);
393
394 if (mbDiscussion == null) {
395 if (_log.isWarnEnabled()) {
396 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + discussionId);
397 }
398
399 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400 discussionId);
401 }
402
403 return mbDiscussion;
404 }
405
406
413 public MBDiscussion fetchByPrimaryKey(Serializable primaryKey)
414 throws SystemException {
415 return fetchByPrimaryKey(((Long)primaryKey).longValue());
416 }
417
418
425 public MBDiscussion fetchByPrimaryKey(long discussionId)
426 throws SystemException {
427 MBDiscussion mbDiscussion = (MBDiscussion)EntityCacheUtil.getResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
428 MBDiscussionImpl.class, discussionId, this);
429
430 if (mbDiscussion == null) {
431 Session session = null;
432
433 try {
434 session = openSession();
435
436 mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
437 new Long(discussionId));
438 }
439 catch (Exception e) {
440 throw processException(e);
441 }
442 finally {
443 if (mbDiscussion != null) {
444 cacheResult(mbDiscussion);
445 }
446
447 closeSession(session);
448 }
449 }
450
451 return mbDiscussion;
452 }
453
454
461 public List<MBDiscussion> findByClassNameId(long classNameId)
462 throws SystemException {
463 return findByClassNameId(classNameId, QueryUtil.ALL_POS,
464 QueryUtil.ALL_POS, null);
465 }
466
467
480 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
481 int end) throws SystemException {
482 return findByClassNameId(classNameId, start, end, null);
483 }
484
485
499 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
500 int end, OrderByComparator orderByComparator) throws SystemException {
501 Object[] finderArgs = new Object[] {
502 classNameId,
503
504 String.valueOf(start), String.valueOf(end),
505 String.valueOf(orderByComparator)
506 };
507
508 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
509 finderArgs, this);
510
511 if (list == null) {
512 Session session = null;
513
514 try {
515 session = openSession();
516
517 StringBundler query = null;
518
519 if (orderByComparator != null) {
520 query = new StringBundler(3 +
521 (orderByComparator.getOrderByFields().length * 3));
522 }
523 else {
524 query = new StringBundler(2);
525 }
526
527 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
528
529 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
530
531 if (orderByComparator != null) {
532 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
533 orderByComparator);
534 }
535
536 String sql = query.toString();
537
538 Query q = session.createQuery(sql);
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(classNameId);
543
544 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
545 start, end);
546 }
547 catch (Exception e) {
548 throw processException(e);
549 }
550 finally {
551 if (list == null) {
552 list = new ArrayList<MBDiscussion>();
553 }
554
555 cacheResult(list);
556
557 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_CLASSNAMEID,
558 finderArgs, list);
559
560 closeSession(session);
561 }
562 }
563
564 return list;
565 }
566
567
580 public MBDiscussion findByClassNameId_First(long classNameId,
581 OrderByComparator orderByComparator)
582 throws NoSuchDiscussionException, SystemException {
583 List<MBDiscussion> list = findByClassNameId(classNameId, 0, 1,
584 orderByComparator);
585
586 if (list.isEmpty()) {
587 StringBundler msg = new StringBundler(4);
588
589 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
590
591 msg.append("classNameId=");
592 msg.append(classNameId);
593
594 msg.append(StringPool.CLOSE_CURLY_BRACE);
595
596 throw new NoSuchDiscussionException(msg.toString());
597 }
598 else {
599 return list.get(0);
600 }
601 }
602
603
616 public MBDiscussion findByClassNameId_Last(long classNameId,
617 OrderByComparator orderByComparator)
618 throws NoSuchDiscussionException, SystemException {
619 int count = countByClassNameId(classNameId);
620
621 List<MBDiscussion> list = findByClassNameId(classNameId, count - 1,
622 count, orderByComparator);
623
624 if (list.isEmpty()) {
625 StringBundler msg = new StringBundler(4);
626
627 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
628
629 msg.append("classNameId=");
630 msg.append(classNameId);
631
632 msg.append(StringPool.CLOSE_CURLY_BRACE);
633
634 throw new NoSuchDiscussionException(msg.toString());
635 }
636 else {
637 return list.get(0);
638 }
639 }
640
641
655 public MBDiscussion[] findByClassNameId_PrevAndNext(long discussionId,
656 long classNameId, OrderByComparator orderByComparator)
657 throws NoSuchDiscussionException, SystemException {
658 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
659
660 Session session = null;
661
662 try {
663 session = openSession();
664
665 MBDiscussion[] array = new MBDiscussionImpl[3];
666
667 array[0] = getByClassNameId_PrevAndNext(session, mbDiscussion,
668 classNameId, orderByComparator, true);
669
670 array[1] = mbDiscussion;
671
672 array[2] = getByClassNameId_PrevAndNext(session, mbDiscussion,
673 classNameId, orderByComparator, false);
674
675 return array;
676 }
677 catch (Exception e) {
678 throw processException(e);
679 }
680 finally {
681 closeSession(session);
682 }
683 }
684
685 protected MBDiscussion getByClassNameId_PrevAndNext(Session session,
686 MBDiscussion mbDiscussion, long classNameId,
687 OrderByComparator orderByComparator, boolean previous) {
688 StringBundler query = null;
689
690 if (orderByComparator != null) {
691 query = new StringBundler(6 +
692 (orderByComparator.getOrderByFields().length * 6));
693 }
694 else {
695 query = new StringBundler(3);
696 }
697
698 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
699
700 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
701
702 if (orderByComparator != null) {
703 String[] orderByFields = orderByComparator.getOrderByFields();
704
705 if (orderByFields.length > 0) {
706 query.append(WHERE_AND);
707 }
708
709 for (int i = 0; i < orderByFields.length; i++) {
710 query.append(_ORDER_BY_ENTITY_ALIAS);
711 query.append(orderByFields[i]);
712
713 if ((i + 1) < orderByFields.length) {
714 if (orderByComparator.isAscending() ^ previous) {
715 query.append(WHERE_GREATER_THAN_HAS_NEXT);
716 }
717 else {
718 query.append(WHERE_LESSER_THAN_HAS_NEXT);
719 }
720 }
721 else {
722 if (orderByComparator.isAscending() ^ previous) {
723 query.append(WHERE_GREATER_THAN);
724 }
725 else {
726 query.append(WHERE_LESSER_THAN);
727 }
728 }
729 }
730
731 query.append(ORDER_BY_CLAUSE);
732
733 for (int i = 0; i < orderByFields.length; i++) {
734 query.append(_ORDER_BY_ENTITY_ALIAS);
735 query.append(orderByFields[i]);
736
737 if ((i + 1) < orderByFields.length) {
738 if (orderByComparator.isAscending() ^ previous) {
739 query.append(ORDER_BY_ASC_HAS_NEXT);
740 }
741 else {
742 query.append(ORDER_BY_DESC_HAS_NEXT);
743 }
744 }
745 else {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(ORDER_BY_ASC);
748 }
749 else {
750 query.append(ORDER_BY_DESC);
751 }
752 }
753 }
754 }
755
756 String sql = query.toString();
757
758 Query q = session.createQuery(sql);
759
760 q.setFirstResult(0);
761 q.setMaxResults(2);
762
763 QueryPos qPos = QueryPos.getInstance(q);
764
765 qPos.add(classNameId);
766
767 if (orderByComparator != null) {
768 Object[] values = orderByComparator.getOrderByValues(mbDiscussion);
769
770 for (Object value : values) {
771 qPos.add(value);
772 }
773 }
774
775 List<MBDiscussion> list = q.list();
776
777 if (list.size() == 2) {
778 return list.get(1);
779 }
780 else {
781 return null;
782 }
783 }
784
785
793 public MBDiscussion findByThreadId(long threadId)
794 throws NoSuchDiscussionException, SystemException {
795 MBDiscussion mbDiscussion = fetchByThreadId(threadId);
796
797 if (mbDiscussion == null) {
798 StringBundler msg = new StringBundler(4);
799
800 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
801
802 msg.append("threadId=");
803 msg.append(threadId);
804
805 msg.append(StringPool.CLOSE_CURLY_BRACE);
806
807 if (_log.isWarnEnabled()) {
808 _log.warn(msg.toString());
809 }
810
811 throw new NoSuchDiscussionException(msg.toString());
812 }
813
814 return mbDiscussion;
815 }
816
817
824 public MBDiscussion fetchByThreadId(long threadId)
825 throws SystemException {
826 return fetchByThreadId(threadId, true);
827 }
828
829
836 public MBDiscussion fetchByThreadId(long threadId, boolean retrieveFromCache)
837 throws SystemException {
838 Object[] finderArgs = new Object[] { threadId };
839
840 Object result = null;
841
842 if (retrieveFromCache) {
843 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THREADID,
844 finderArgs, this);
845 }
846
847 if (result == null) {
848 Session session = null;
849
850 try {
851 session = openSession();
852
853 StringBundler query = new StringBundler(2);
854
855 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
856
857 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
858
859 String sql = query.toString();
860
861 Query q = session.createQuery(sql);
862
863 QueryPos qPos = QueryPos.getInstance(q);
864
865 qPos.add(threadId);
866
867 List<MBDiscussion> list = q.list();
868
869 result = list;
870
871 MBDiscussion mbDiscussion = null;
872
873 if (list.isEmpty()) {
874 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
875 finderArgs, list);
876 }
877 else {
878 mbDiscussion = list.get(0);
879
880 cacheResult(mbDiscussion);
881
882 if ((mbDiscussion.getThreadId() != threadId)) {
883 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
884 finderArgs, mbDiscussion);
885 }
886 }
887
888 return mbDiscussion;
889 }
890 catch (Exception e) {
891 throw processException(e);
892 }
893 finally {
894 if (result == null) {
895 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
896 finderArgs, new ArrayList<MBDiscussion>());
897 }
898
899 closeSession(session);
900 }
901 }
902 else {
903 if (result instanceof List<?>) {
904 return null;
905 }
906 else {
907 return (MBDiscussion)result;
908 }
909 }
910 }
911
912
921 public MBDiscussion findByC_C(long classNameId, long classPK)
922 throws NoSuchDiscussionException, SystemException {
923 MBDiscussion mbDiscussion = fetchByC_C(classNameId, classPK);
924
925 if (mbDiscussion == null) {
926 StringBundler msg = new StringBundler(6);
927
928 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
929
930 msg.append("classNameId=");
931 msg.append(classNameId);
932
933 msg.append(", classPK=");
934 msg.append(classPK);
935
936 msg.append(StringPool.CLOSE_CURLY_BRACE);
937
938 if (_log.isWarnEnabled()) {
939 _log.warn(msg.toString());
940 }
941
942 throw new NoSuchDiscussionException(msg.toString());
943 }
944
945 return mbDiscussion;
946 }
947
948
956 public MBDiscussion fetchByC_C(long classNameId, long classPK)
957 throws SystemException {
958 return fetchByC_C(classNameId, classPK, true);
959 }
960
961
969 public MBDiscussion fetchByC_C(long classNameId, long classPK,
970 boolean retrieveFromCache) throws SystemException {
971 Object[] finderArgs = new Object[] { classNameId, classPK };
972
973 Object result = null;
974
975 if (retrieveFromCache) {
976 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
977 finderArgs, this);
978 }
979
980 if (result == null) {
981 Session session = null;
982
983 try {
984 session = openSession();
985
986 StringBundler query = new StringBundler(3);
987
988 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
989
990 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
991
992 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
993
994 String sql = query.toString();
995
996 Query q = session.createQuery(sql);
997
998 QueryPos qPos = QueryPos.getInstance(q);
999
1000 qPos.add(classNameId);
1001
1002 qPos.add(classPK);
1003
1004 List<MBDiscussion> list = q.list();
1005
1006 result = list;
1007
1008 MBDiscussion mbDiscussion = null;
1009
1010 if (list.isEmpty()) {
1011 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1012 finderArgs, list);
1013 }
1014 else {
1015 mbDiscussion = list.get(0);
1016
1017 cacheResult(mbDiscussion);
1018
1019 if ((mbDiscussion.getClassNameId() != classNameId) ||
1020 (mbDiscussion.getClassPK() != classPK)) {
1021 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1022 finderArgs, mbDiscussion);
1023 }
1024 }
1025
1026 return mbDiscussion;
1027 }
1028 catch (Exception e) {
1029 throw processException(e);
1030 }
1031 finally {
1032 if (result == null) {
1033 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
1034 finderArgs, new ArrayList<MBDiscussion>());
1035 }
1036
1037 closeSession(session);
1038 }
1039 }
1040 else {
1041 if (result instanceof List<?>) {
1042 return null;
1043 }
1044 else {
1045 return (MBDiscussion)result;
1046 }
1047 }
1048 }
1049
1050
1056 public List<MBDiscussion> findAll() throws SystemException {
1057 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1058 }
1059
1060
1072 public List<MBDiscussion> findAll(int start, int end)
1073 throws SystemException {
1074 return findAll(start, end, null);
1075 }
1076
1077
1090 public List<MBDiscussion> findAll(int start, int end,
1091 OrderByComparator orderByComparator) throws SystemException {
1092 Object[] finderArgs = new Object[] {
1093 String.valueOf(start), String.valueOf(end),
1094 String.valueOf(orderByComparator)
1095 };
1096
1097 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1098 finderArgs, this);
1099
1100 if (list == null) {
1101 Session session = null;
1102
1103 try {
1104 session = openSession();
1105
1106 StringBundler query = null;
1107 String sql = null;
1108
1109 if (orderByComparator != null) {
1110 query = new StringBundler(2 +
1111 (orderByComparator.getOrderByFields().length * 3));
1112
1113 query.append(_SQL_SELECT_MBDISCUSSION);
1114
1115 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1116 orderByComparator);
1117
1118 sql = query.toString();
1119 }
1120 else {
1121 sql = _SQL_SELECT_MBDISCUSSION;
1122 }
1123
1124 Query q = session.createQuery(sql);
1125
1126 if (orderByComparator == null) {
1127 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1128 start, end, false);
1129
1130 Collections.sort(list);
1131 }
1132 else {
1133 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1134 start, end);
1135 }
1136 }
1137 catch (Exception e) {
1138 throw processException(e);
1139 }
1140 finally {
1141 if (list == null) {
1142 list = new ArrayList<MBDiscussion>();
1143 }
1144
1145 cacheResult(list);
1146
1147 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1148
1149 closeSession(session);
1150 }
1151 }
1152
1153 return list;
1154 }
1155
1156
1162 public void removeByClassNameId(long classNameId) throws SystemException {
1163 for (MBDiscussion mbDiscussion : findByClassNameId(classNameId)) {
1164 remove(mbDiscussion);
1165 }
1166 }
1167
1168
1174 public void removeByThreadId(long threadId)
1175 throws NoSuchDiscussionException, SystemException {
1176 MBDiscussion mbDiscussion = findByThreadId(threadId);
1177
1178 remove(mbDiscussion);
1179 }
1180
1181
1188 public void removeByC_C(long classNameId, long classPK)
1189 throws NoSuchDiscussionException, SystemException {
1190 MBDiscussion mbDiscussion = findByC_C(classNameId, classPK);
1191
1192 remove(mbDiscussion);
1193 }
1194
1195
1200 public void removeAll() throws SystemException {
1201 for (MBDiscussion mbDiscussion : findAll()) {
1202 remove(mbDiscussion);
1203 }
1204 }
1205
1206
1213 public int countByClassNameId(long classNameId) throws SystemException {
1214 Object[] finderArgs = new Object[] { classNameId };
1215
1216 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1217 finderArgs, this);
1218
1219 if (count == null) {
1220 Session session = null;
1221
1222 try {
1223 session = openSession();
1224
1225 StringBundler query = new StringBundler(2);
1226
1227 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1228
1229 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1230
1231 String sql = query.toString();
1232
1233 Query q = session.createQuery(sql);
1234
1235 QueryPos qPos = QueryPos.getInstance(q);
1236
1237 qPos.add(classNameId);
1238
1239 count = (Long)q.uniqueResult();
1240 }
1241 catch (Exception e) {
1242 throw processException(e);
1243 }
1244 finally {
1245 if (count == null) {
1246 count = Long.valueOf(0);
1247 }
1248
1249 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
1250 finderArgs, count);
1251
1252 closeSession(session);
1253 }
1254 }
1255
1256 return count.intValue();
1257 }
1258
1259
1266 public int countByThreadId(long threadId) throws SystemException {
1267 Object[] finderArgs = new Object[] { threadId };
1268
1269 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
1270 finderArgs, this);
1271
1272 if (count == null) {
1273 Session session = null;
1274
1275 try {
1276 session = openSession();
1277
1278 StringBundler query = new StringBundler(2);
1279
1280 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1281
1282 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1283
1284 String sql = query.toString();
1285
1286 Query q = session.createQuery(sql);
1287
1288 QueryPos qPos = QueryPos.getInstance(q);
1289
1290 qPos.add(threadId);
1291
1292 count = (Long)q.uniqueResult();
1293 }
1294 catch (Exception e) {
1295 throw processException(e);
1296 }
1297 finally {
1298 if (count == null) {
1299 count = Long.valueOf(0);
1300 }
1301
1302 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
1303 finderArgs, count);
1304
1305 closeSession(session);
1306 }
1307 }
1308
1309 return count.intValue();
1310 }
1311
1312
1320 public int countByC_C(long classNameId, long classPK)
1321 throws SystemException {
1322 Object[] finderArgs = new Object[] { classNameId, classPK };
1323
1324 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1325 finderArgs, this);
1326
1327 if (count == null) {
1328 Session session = null;
1329
1330 try {
1331 session = openSession();
1332
1333 StringBundler query = new StringBundler(3);
1334
1335 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1336
1337 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1338
1339 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1340
1341 String sql = query.toString();
1342
1343 Query q = session.createQuery(sql);
1344
1345 QueryPos qPos = QueryPos.getInstance(q);
1346
1347 qPos.add(classNameId);
1348
1349 qPos.add(classPK);
1350
1351 count = (Long)q.uniqueResult();
1352 }
1353 catch (Exception e) {
1354 throw processException(e);
1355 }
1356 finally {
1357 if (count == null) {
1358 count = Long.valueOf(0);
1359 }
1360
1361 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1362 count);
1363
1364 closeSession(session);
1365 }
1366 }
1367
1368 return count.intValue();
1369 }
1370
1371
1377 public int countAll() throws SystemException {
1378 Object[] finderArgs = new Object[0];
1379
1380 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1381 finderArgs, this);
1382
1383 if (count == null) {
1384 Session session = null;
1385
1386 try {
1387 session = openSession();
1388
1389 Query q = session.createQuery(_SQL_COUNT_MBDISCUSSION);
1390
1391 count = (Long)q.uniqueResult();
1392 }
1393 catch (Exception e) {
1394 throw processException(e);
1395 }
1396 finally {
1397 if (count == null) {
1398 count = Long.valueOf(0);
1399 }
1400
1401 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1402 count);
1403
1404 closeSession(session);
1405 }
1406 }
1407
1408 return count.intValue();
1409 }
1410
1411
1414 public void afterPropertiesSet() {
1415 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1416 com.liferay.portal.util.PropsUtil.get(
1417 "value.object.listener.com.liferay.portlet.messageboards.model.MBDiscussion")));
1418
1419 if (listenerClassNames.length > 0) {
1420 try {
1421 List<ModelListener<MBDiscussion>> listenersList = new ArrayList<ModelListener<MBDiscussion>>();
1422
1423 for (String listenerClassName : listenerClassNames) {
1424 listenersList.add((ModelListener<MBDiscussion>)InstanceFactory.newInstance(
1425 listenerClassName));
1426 }
1427
1428 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1429 }
1430 catch (Exception e) {
1431 _log.error(e);
1432 }
1433 }
1434 }
1435
1436 public void destroy() {
1437 EntityCacheUtil.removeCache(MBDiscussionImpl.class.getName());
1438 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1439 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1440 }
1441
1442 @BeanReference(type = MBBanPersistence.class)
1443 protected MBBanPersistence mbBanPersistence;
1444 @BeanReference(type = MBCategoryPersistence.class)
1445 protected MBCategoryPersistence mbCategoryPersistence;
1446 @BeanReference(type = MBDiscussionPersistence.class)
1447 protected MBDiscussionPersistence mbDiscussionPersistence;
1448 @BeanReference(type = MBMailingListPersistence.class)
1449 protected MBMailingListPersistence mbMailingListPersistence;
1450 @BeanReference(type = MBMessagePersistence.class)
1451 protected MBMessagePersistence mbMessagePersistence;
1452 @BeanReference(type = MBMessageFlagPersistence.class)
1453 protected MBMessageFlagPersistence mbMessageFlagPersistence;
1454 @BeanReference(type = MBStatsUserPersistence.class)
1455 protected MBStatsUserPersistence mbStatsUserPersistence;
1456 @BeanReference(type = MBThreadPersistence.class)
1457 protected MBThreadPersistence mbThreadPersistence;
1458 @BeanReference(type = ResourcePersistence.class)
1459 protected ResourcePersistence resourcePersistence;
1460 @BeanReference(type = UserPersistence.class)
1461 protected UserPersistence userPersistence;
1462 private static final String _SQL_SELECT_MBDISCUSSION = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion";
1463 private static final String _SQL_SELECT_MBDISCUSSION_WHERE = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ";
1464 private static final String _SQL_COUNT_MBDISCUSSION = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion";
1465 private static final String _SQL_COUNT_MBDISCUSSION_WHERE = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion WHERE ";
1466 private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "mbDiscussion.classNameId = ?";
1467 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbDiscussion.threadId = ?";
1468 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbDiscussion.classNameId = ? AND ";
1469 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbDiscussion.classPK = ?";
1470 private static final String _ORDER_BY_ENTITY_ALIAS = "mbDiscussion.";
1471 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBDiscussion exists with the primary key ";
1472 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBDiscussion exists with the key {";
1473 private static Log _log = LogFactoryUtil.getLog(MBDiscussionPersistenceImpl.class);
1474 }