001
014
015 package com.liferay.portlet.messageboards.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.OrderByComparator;
029 import com.liferay.portal.kernel.util.SetUtil;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
034 import com.liferay.portal.model.CacheModel;
035 import com.liferay.portal.service.ServiceContext;
036 import com.liferay.portal.service.ServiceContextThreadLocal;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038
039 import com.liferay.portlet.messageboards.NoSuchDiscussionException;
040 import com.liferay.portlet.messageboards.model.MBDiscussion;
041 import com.liferay.portlet.messageboards.model.impl.MBDiscussionImpl;
042 import com.liferay.portlet.messageboards.model.impl.MBDiscussionModelImpl;
043 import com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence;
044
045 import java.io.Serializable;
046
047 import java.util.Collections;
048 import java.util.Date;
049 import java.util.HashMap;
050 import java.util.HashSet;
051 import java.util.Iterator;
052 import java.util.List;
053 import java.util.Map;
054 import java.util.Set;
055
056
068 @ProviderType
069 public class MBDiscussionPersistenceImpl extends BasePersistenceImpl<MBDiscussion>
070 implements MBDiscussionPersistence {
071
076 public static final String FINDER_CLASS_NAME_ENTITY = MBDiscussionImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List1";
079 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List2";
081 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
082 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
083 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
085 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
088 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
091 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
092 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093 new String[] {
094 String.class.getName(),
095
096 Integer.class.getName(), Integer.class.getName(),
097 OrderByComparator.class.getName()
098 });
099 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
100 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102 new String[] { String.class.getName() },
103 MBDiscussionModelImpl.UUID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
105 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107 new String[] { String.class.getName() });
108
109
115 @Override
116 public List<MBDiscussion> findByUuid(String uuid) {
117 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
132 @Override
133 public List<MBDiscussion> findByUuid(String uuid, int start, int end) {
134 return findByUuid(uuid, start, end, null);
135 }
136
137
150 @Override
151 public List<MBDiscussion> findByUuid(String uuid, int start, int end,
152 OrderByComparator<MBDiscussion> orderByComparator) {
153 boolean pagination = true;
154 FinderPath finderPath = null;
155 Object[] finderArgs = null;
156
157 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
158 (orderByComparator == null)) {
159 pagination = false;
160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
161 finderArgs = new Object[] { uuid };
162 }
163 else {
164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
165 finderArgs = new Object[] { uuid, start, end, orderByComparator };
166 }
167
168 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(finderPath,
169 finderArgs, this);
170
171 if ((list != null) && !list.isEmpty()) {
172 for (MBDiscussion mbDiscussion : list) {
173 if (!Validator.equals(uuid, mbDiscussion.getUuid())) {
174 list = null;
175
176 break;
177 }
178 }
179 }
180
181 if (list == null) {
182 StringBundler query = null;
183
184 if (orderByComparator != null) {
185 query = new StringBundler(3 +
186 (orderByComparator.getOrderByFields().length * 3));
187 }
188 else {
189 query = new StringBundler(3);
190 }
191
192 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
193
194 boolean bindUuid = false;
195
196 if (uuid == null) {
197 query.append(_FINDER_COLUMN_UUID_UUID_1);
198 }
199 else if (uuid.equals(StringPool.BLANK)) {
200 query.append(_FINDER_COLUMN_UUID_UUID_3);
201 }
202 else {
203 bindUuid = true;
204
205 query.append(_FINDER_COLUMN_UUID_UUID_2);
206 }
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(MBDiscussionModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 if (bindUuid) {
229 qPos.add(uuid);
230 }
231
232 if (!pagination) {
233 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
234 start, end, false);
235
236 Collections.sort(list);
237
238 list = Collections.unmodifiableList(list);
239 }
240 else {
241 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
242 start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
270 @Override
271 public MBDiscussion findByUuid_First(String uuid,
272 OrderByComparator<MBDiscussion> orderByComparator)
273 throws NoSuchDiscussionException {
274 MBDiscussion mbDiscussion = fetchByUuid_First(uuid, orderByComparator);
275
276 if (mbDiscussion != null) {
277 return mbDiscussion;
278 }
279
280 StringBundler msg = new StringBundler(4);
281
282 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283
284 msg.append("uuid=");
285 msg.append(uuid);
286
287 msg.append(StringPool.CLOSE_CURLY_BRACE);
288
289 throw new NoSuchDiscussionException(msg.toString());
290 }
291
292
299 @Override
300 public MBDiscussion fetchByUuid_First(String uuid,
301 OrderByComparator<MBDiscussion> orderByComparator) {
302 List<MBDiscussion> list = findByUuid(uuid, 0, 1, orderByComparator);
303
304 if (!list.isEmpty()) {
305 return list.get(0);
306 }
307
308 return null;
309 }
310
311
319 @Override
320 public MBDiscussion findByUuid_Last(String uuid,
321 OrderByComparator<MBDiscussion> orderByComparator)
322 throws NoSuchDiscussionException {
323 MBDiscussion mbDiscussion = fetchByUuid_Last(uuid, orderByComparator);
324
325 if (mbDiscussion != null) {
326 return mbDiscussion;
327 }
328
329 StringBundler msg = new StringBundler(4);
330
331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332
333 msg.append("uuid=");
334 msg.append(uuid);
335
336 msg.append(StringPool.CLOSE_CURLY_BRACE);
337
338 throw new NoSuchDiscussionException(msg.toString());
339 }
340
341
348 @Override
349 public MBDiscussion fetchByUuid_Last(String uuid,
350 OrderByComparator<MBDiscussion> orderByComparator) {
351 int count = countByUuid(uuid);
352
353 if (count == 0) {
354 return null;
355 }
356
357 List<MBDiscussion> list = findByUuid(uuid, count - 1, count,
358 orderByComparator);
359
360 if (!list.isEmpty()) {
361 return list.get(0);
362 }
363
364 return null;
365 }
366
367
376 @Override
377 public MBDiscussion[] findByUuid_PrevAndNext(long discussionId,
378 String uuid, OrderByComparator<MBDiscussion> orderByComparator)
379 throws NoSuchDiscussionException {
380 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 MBDiscussion[] array = new MBDiscussionImpl[3];
388
389 array[0] = getByUuid_PrevAndNext(session, mbDiscussion, uuid,
390 orderByComparator, true);
391
392 array[1] = mbDiscussion;
393
394 array[2] = getByUuid_PrevAndNext(session, mbDiscussion, uuid,
395 orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected MBDiscussion getByUuid_PrevAndNext(Session session,
408 MBDiscussion mbDiscussion, String uuid,
409 OrderByComparator<MBDiscussion> orderByComparator, boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
421
422 boolean bindUuid = false;
423
424 if (uuid == null) {
425 query.append(_FINDER_COLUMN_UUID_UUID_1);
426 }
427 else if (uuid.equals(StringPool.BLANK)) {
428 query.append(_FINDER_COLUMN_UUID_UUID_3);
429 }
430 else {
431 bindUuid = true;
432
433 query.append(_FINDER_COLUMN_UUID_UUID_2);
434 }
435
436 if (orderByComparator != null) {
437 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
438
439 if (orderByConditionFields.length > 0) {
440 query.append(WHERE_AND);
441 }
442
443 for (int i = 0; i < orderByConditionFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByConditionFields[i]);
446
447 if ((i + 1) < orderByConditionFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(WHERE_GREATER_THAN_HAS_NEXT);
450 }
451 else {
452 query.append(WHERE_LESSER_THAN_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN);
461 }
462 }
463 }
464
465 query.append(ORDER_BY_CLAUSE);
466
467 String[] orderByFields = orderByComparator.getOrderByFields();
468
469 for (int i = 0; i < orderByFields.length; i++) {
470 query.append(_ORDER_BY_ENTITY_ALIAS);
471 query.append(orderByFields[i]);
472
473 if ((i + 1) < orderByFields.length) {
474 if (orderByComparator.isAscending() ^ previous) {
475 query.append(ORDER_BY_ASC_HAS_NEXT);
476 }
477 else {
478 query.append(ORDER_BY_DESC_HAS_NEXT);
479 }
480 }
481 else {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC);
484 }
485 else {
486 query.append(ORDER_BY_DESC);
487 }
488 }
489 }
490 }
491 else {
492 query.append(MBDiscussionModelImpl.ORDER_BY_JPQL);
493 }
494
495 String sql = query.toString();
496
497 Query q = session.createQuery(sql);
498
499 q.setFirstResult(0);
500 q.setMaxResults(2);
501
502 QueryPos qPos = QueryPos.getInstance(q);
503
504 if (bindUuid) {
505 qPos.add(uuid);
506 }
507
508 if (orderByComparator != null) {
509 Object[] values = orderByComparator.getOrderByConditionValues(mbDiscussion);
510
511 for (Object value : values) {
512 qPos.add(value);
513 }
514 }
515
516 List<MBDiscussion> list = q.list();
517
518 if (list.size() == 2) {
519 return list.get(1);
520 }
521 else {
522 return null;
523 }
524 }
525
526
531 @Override
532 public void removeByUuid(String uuid) {
533 for (MBDiscussion mbDiscussion : findByUuid(uuid, QueryUtil.ALL_POS,
534 QueryUtil.ALL_POS, null)) {
535 remove(mbDiscussion);
536 }
537 }
538
539
545 @Override
546 public int countByUuid(String uuid) {
547 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
548
549 Object[] finderArgs = new Object[] { uuid };
550
551 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552 this);
553
554 if (count == null) {
555 StringBundler query = new StringBundler(2);
556
557 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
558
559 boolean bindUuid = false;
560
561 if (uuid == null) {
562 query.append(_FINDER_COLUMN_UUID_UUID_1);
563 }
564 else if (uuid.equals(StringPool.BLANK)) {
565 query.append(_FINDER_COLUMN_UUID_UUID_3);
566 }
567 else {
568 bindUuid = true;
569
570 query.append(_FINDER_COLUMN_UUID_UUID_2);
571 }
572
573 String sql = query.toString();
574
575 Session session = null;
576
577 try {
578 session = openSession();
579
580 Query q = session.createQuery(sql);
581
582 QueryPos qPos = QueryPos.getInstance(q);
583
584 if (bindUuid) {
585 qPos.add(uuid);
586 }
587
588 count = (Long)q.uniqueResult();
589
590 FinderCacheUtil.putResult(finderPath, finderArgs, count);
591 }
592 catch (Exception e) {
593 FinderCacheUtil.removeResult(finderPath, finderArgs);
594
595 throw processException(e);
596 }
597 finally {
598 closeSession(session);
599 }
600 }
601
602 return count.intValue();
603 }
604
605 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbDiscussion.uuid IS NULL";
606 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbDiscussion.uuid = ?";
607 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbDiscussion.uuid IS NULL OR mbDiscussion.uuid = '')";
608 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
609 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
610 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
611 new String[] { String.class.getName(), Long.class.getName() },
612 MBDiscussionModelImpl.UUID_COLUMN_BITMASK |
613 MBDiscussionModelImpl.GROUPID_COLUMN_BITMASK);
614 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
615 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
616 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
617 new String[] { String.class.getName(), Long.class.getName() });
618
619
627 @Override
628 public MBDiscussion findByUUID_G(String uuid, long groupId)
629 throws NoSuchDiscussionException {
630 MBDiscussion mbDiscussion = fetchByUUID_G(uuid, groupId);
631
632 if (mbDiscussion == null) {
633 StringBundler msg = new StringBundler(6);
634
635 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
636
637 msg.append("uuid=");
638 msg.append(uuid);
639
640 msg.append(", groupId=");
641 msg.append(groupId);
642
643 msg.append(StringPool.CLOSE_CURLY_BRACE);
644
645 if (_log.isWarnEnabled()) {
646 _log.warn(msg.toString());
647 }
648
649 throw new NoSuchDiscussionException(msg.toString());
650 }
651
652 return mbDiscussion;
653 }
654
655
662 @Override
663 public MBDiscussion fetchByUUID_G(String uuid, long groupId) {
664 return fetchByUUID_G(uuid, groupId, true);
665 }
666
667
675 @Override
676 public MBDiscussion fetchByUUID_G(String uuid, long groupId,
677 boolean retrieveFromCache) {
678 Object[] finderArgs = new Object[] { uuid, groupId };
679
680 Object result = null;
681
682 if (retrieveFromCache) {
683 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
684 finderArgs, this);
685 }
686
687 if (result instanceof MBDiscussion) {
688 MBDiscussion mbDiscussion = (MBDiscussion)result;
689
690 if (!Validator.equals(uuid, mbDiscussion.getUuid()) ||
691 (groupId != mbDiscussion.getGroupId())) {
692 result = null;
693 }
694 }
695
696 if (result == null) {
697 StringBundler query = new StringBundler(4);
698
699 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
700
701 boolean bindUuid = false;
702
703 if (uuid == null) {
704 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
705 }
706 else if (uuid.equals(StringPool.BLANK)) {
707 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
708 }
709 else {
710 bindUuid = true;
711
712 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
713 }
714
715 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
716
717 String sql = query.toString();
718
719 Session session = null;
720
721 try {
722 session = openSession();
723
724 Query q = session.createQuery(sql);
725
726 QueryPos qPos = QueryPos.getInstance(q);
727
728 if (bindUuid) {
729 qPos.add(uuid);
730 }
731
732 qPos.add(groupId);
733
734 List<MBDiscussion> list = q.list();
735
736 if (list.isEmpty()) {
737 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
738 finderArgs, list);
739 }
740 else {
741 MBDiscussion mbDiscussion = list.get(0);
742
743 result = mbDiscussion;
744
745 cacheResult(mbDiscussion);
746
747 if ((mbDiscussion.getUuid() == null) ||
748 !mbDiscussion.getUuid().equals(uuid) ||
749 (mbDiscussion.getGroupId() != groupId)) {
750 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
751 finderArgs, mbDiscussion);
752 }
753 }
754 }
755 catch (Exception e) {
756 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs);
758
759 throw processException(e);
760 }
761 finally {
762 closeSession(session);
763 }
764 }
765
766 if (result instanceof List<?>) {
767 return null;
768 }
769 else {
770 return (MBDiscussion)result;
771 }
772 }
773
774
781 @Override
782 public MBDiscussion removeByUUID_G(String uuid, long groupId)
783 throws NoSuchDiscussionException {
784 MBDiscussion mbDiscussion = findByUUID_G(uuid, groupId);
785
786 return remove(mbDiscussion);
787 }
788
789
796 @Override
797 public int countByUUID_G(String uuid, long groupId) {
798 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
799
800 Object[] finderArgs = new Object[] { uuid, groupId };
801
802 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
803 this);
804
805 if (count == null) {
806 StringBundler query = new StringBundler(3);
807
808 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
809
810 boolean bindUuid = false;
811
812 if (uuid == null) {
813 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
814 }
815 else if (uuid.equals(StringPool.BLANK)) {
816 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
817 }
818 else {
819 bindUuid = true;
820
821 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
822 }
823
824 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
825
826 String sql = query.toString();
827
828 Session session = null;
829
830 try {
831 session = openSession();
832
833 Query q = session.createQuery(sql);
834
835 QueryPos qPos = QueryPos.getInstance(q);
836
837 if (bindUuid) {
838 qPos.add(uuid);
839 }
840
841 qPos.add(groupId);
842
843 count = (Long)q.uniqueResult();
844
845 FinderCacheUtil.putResult(finderPath, finderArgs, count);
846 }
847 catch (Exception e) {
848 FinderCacheUtil.removeResult(finderPath, finderArgs);
849
850 throw processException(e);
851 }
852 finally {
853 closeSession(session);
854 }
855 }
856
857 return count.intValue();
858 }
859
860 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbDiscussion.uuid IS NULL AND ";
861 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbDiscussion.uuid = ? AND ";
862 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbDiscussion.uuid IS NULL OR mbDiscussion.uuid = '') AND ";
863 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbDiscussion.groupId = ?";
864 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
865 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
866 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
867 new String[] {
868 String.class.getName(), Long.class.getName(),
869
870 Integer.class.getName(), Integer.class.getName(),
871 OrderByComparator.class.getName()
872 });
873 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
874 new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
875 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
876 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
877 new String[] { String.class.getName(), Long.class.getName() },
878 MBDiscussionModelImpl.UUID_COLUMN_BITMASK |
879 MBDiscussionModelImpl.COMPANYID_COLUMN_BITMASK);
880 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
881 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
882 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
883 new String[] { String.class.getName(), Long.class.getName() });
884
885
892 @Override
893 public List<MBDiscussion> findByUuid_C(String uuid, long companyId) {
894 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
895 QueryUtil.ALL_POS, null);
896 }
897
898
911 @Override
912 public List<MBDiscussion> findByUuid_C(String uuid, long companyId,
913 int start, int end) {
914 return findByUuid_C(uuid, companyId, start, end, null);
915 }
916
917
931 @Override
932 public List<MBDiscussion> findByUuid_C(String uuid, long companyId,
933 int start, int end, OrderByComparator<MBDiscussion> orderByComparator) {
934 boolean pagination = true;
935 FinderPath finderPath = null;
936 Object[] finderArgs = null;
937
938 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
939 (orderByComparator == null)) {
940 pagination = false;
941 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
942 finderArgs = new Object[] { uuid, companyId };
943 }
944 else {
945 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
946 finderArgs = new Object[] {
947 uuid, companyId,
948
949 start, end, orderByComparator
950 };
951 }
952
953 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(finderPath,
954 finderArgs, this);
955
956 if ((list != null) && !list.isEmpty()) {
957 for (MBDiscussion mbDiscussion : list) {
958 if (!Validator.equals(uuid, mbDiscussion.getUuid()) ||
959 (companyId != mbDiscussion.getCompanyId())) {
960 list = null;
961
962 break;
963 }
964 }
965 }
966
967 if (list == null) {
968 StringBundler query = null;
969
970 if (orderByComparator != null) {
971 query = new StringBundler(4 +
972 (orderByComparator.getOrderByFields().length * 3));
973 }
974 else {
975 query = new StringBundler(4);
976 }
977
978 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
979
980 boolean bindUuid = false;
981
982 if (uuid == null) {
983 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
984 }
985 else if (uuid.equals(StringPool.BLANK)) {
986 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
987 }
988 else {
989 bindUuid = true;
990
991 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
992 }
993
994 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
995
996 if (orderByComparator != null) {
997 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
998 orderByComparator);
999 }
1000 else
1001 if (pagination) {
1002 query.append(MBDiscussionModelImpl.ORDER_BY_JPQL);
1003 }
1004
1005 String sql = query.toString();
1006
1007 Session session = null;
1008
1009 try {
1010 session = openSession();
1011
1012 Query q = session.createQuery(sql);
1013
1014 QueryPos qPos = QueryPos.getInstance(q);
1015
1016 if (bindUuid) {
1017 qPos.add(uuid);
1018 }
1019
1020 qPos.add(companyId);
1021
1022 if (!pagination) {
1023 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1024 start, end, false);
1025
1026 Collections.sort(list);
1027
1028 list = Collections.unmodifiableList(list);
1029 }
1030 else {
1031 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1032 start, end);
1033 }
1034
1035 cacheResult(list);
1036
1037 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1038 }
1039 catch (Exception e) {
1040 FinderCacheUtil.removeResult(finderPath, finderArgs);
1041
1042 throw processException(e);
1043 }
1044 finally {
1045 closeSession(session);
1046 }
1047 }
1048
1049 return list;
1050 }
1051
1052
1061 @Override
1062 public MBDiscussion findByUuid_C_First(String uuid, long companyId,
1063 OrderByComparator<MBDiscussion> orderByComparator)
1064 throws NoSuchDiscussionException {
1065 MBDiscussion mbDiscussion = fetchByUuid_C_First(uuid, companyId,
1066 orderByComparator);
1067
1068 if (mbDiscussion != null) {
1069 return mbDiscussion;
1070 }
1071
1072 StringBundler msg = new StringBundler(6);
1073
1074 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1075
1076 msg.append("uuid=");
1077 msg.append(uuid);
1078
1079 msg.append(", companyId=");
1080 msg.append(companyId);
1081
1082 msg.append(StringPool.CLOSE_CURLY_BRACE);
1083
1084 throw new NoSuchDiscussionException(msg.toString());
1085 }
1086
1087
1095 @Override
1096 public MBDiscussion fetchByUuid_C_First(String uuid, long companyId,
1097 OrderByComparator<MBDiscussion> orderByComparator) {
1098 List<MBDiscussion> list = findByUuid_C(uuid, companyId, 0, 1,
1099 orderByComparator);
1100
1101 if (!list.isEmpty()) {
1102 return list.get(0);
1103 }
1104
1105 return null;
1106 }
1107
1108
1117 @Override
1118 public MBDiscussion findByUuid_C_Last(String uuid, long companyId,
1119 OrderByComparator<MBDiscussion> orderByComparator)
1120 throws NoSuchDiscussionException {
1121 MBDiscussion mbDiscussion = fetchByUuid_C_Last(uuid, companyId,
1122 orderByComparator);
1123
1124 if (mbDiscussion != null) {
1125 return mbDiscussion;
1126 }
1127
1128 StringBundler msg = new StringBundler(6);
1129
1130 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1131
1132 msg.append("uuid=");
1133 msg.append(uuid);
1134
1135 msg.append(", companyId=");
1136 msg.append(companyId);
1137
1138 msg.append(StringPool.CLOSE_CURLY_BRACE);
1139
1140 throw new NoSuchDiscussionException(msg.toString());
1141 }
1142
1143
1151 @Override
1152 public MBDiscussion fetchByUuid_C_Last(String uuid, long companyId,
1153 OrderByComparator<MBDiscussion> orderByComparator) {
1154 int count = countByUuid_C(uuid, companyId);
1155
1156 if (count == 0) {
1157 return null;
1158 }
1159
1160 List<MBDiscussion> list = findByUuid_C(uuid, companyId, count - 1,
1161 count, orderByComparator);
1162
1163 if (!list.isEmpty()) {
1164 return list.get(0);
1165 }
1166
1167 return null;
1168 }
1169
1170
1180 @Override
1181 public MBDiscussion[] findByUuid_C_PrevAndNext(long discussionId,
1182 String uuid, long companyId,
1183 OrderByComparator<MBDiscussion> orderByComparator)
1184 throws NoSuchDiscussionException {
1185 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
1186
1187 Session session = null;
1188
1189 try {
1190 session = openSession();
1191
1192 MBDiscussion[] array = new MBDiscussionImpl[3];
1193
1194 array[0] = getByUuid_C_PrevAndNext(session, mbDiscussion, uuid,
1195 companyId, orderByComparator, true);
1196
1197 array[1] = mbDiscussion;
1198
1199 array[2] = getByUuid_C_PrevAndNext(session, mbDiscussion, uuid,
1200 companyId, orderByComparator, false);
1201
1202 return array;
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 closeSession(session);
1209 }
1210 }
1211
1212 protected MBDiscussion getByUuid_C_PrevAndNext(Session session,
1213 MBDiscussion mbDiscussion, String uuid, long companyId,
1214 OrderByComparator<MBDiscussion> orderByComparator, boolean previous) {
1215 StringBundler query = null;
1216
1217 if (orderByComparator != null) {
1218 query = new StringBundler(6 +
1219 (orderByComparator.getOrderByFields().length * 6));
1220 }
1221 else {
1222 query = new StringBundler(3);
1223 }
1224
1225 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
1226
1227 boolean bindUuid = false;
1228
1229 if (uuid == null) {
1230 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1231 }
1232 else if (uuid.equals(StringPool.BLANK)) {
1233 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1234 }
1235 else {
1236 bindUuid = true;
1237
1238 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1239 }
1240
1241 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1242
1243 if (orderByComparator != null) {
1244 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1245
1246 if (orderByConditionFields.length > 0) {
1247 query.append(WHERE_AND);
1248 }
1249
1250 for (int i = 0; i < orderByConditionFields.length; i++) {
1251 query.append(_ORDER_BY_ENTITY_ALIAS);
1252 query.append(orderByConditionFields[i]);
1253
1254 if ((i + 1) < orderByConditionFields.length) {
1255 if (orderByComparator.isAscending() ^ previous) {
1256 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1257 }
1258 else {
1259 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1260 }
1261 }
1262 else {
1263 if (orderByComparator.isAscending() ^ previous) {
1264 query.append(WHERE_GREATER_THAN);
1265 }
1266 else {
1267 query.append(WHERE_LESSER_THAN);
1268 }
1269 }
1270 }
1271
1272 query.append(ORDER_BY_CLAUSE);
1273
1274 String[] orderByFields = orderByComparator.getOrderByFields();
1275
1276 for (int i = 0; i < orderByFields.length; i++) {
1277 query.append(_ORDER_BY_ENTITY_ALIAS);
1278 query.append(orderByFields[i]);
1279
1280 if ((i + 1) < orderByFields.length) {
1281 if (orderByComparator.isAscending() ^ previous) {
1282 query.append(ORDER_BY_ASC_HAS_NEXT);
1283 }
1284 else {
1285 query.append(ORDER_BY_DESC_HAS_NEXT);
1286 }
1287 }
1288 else {
1289 if (orderByComparator.isAscending() ^ previous) {
1290 query.append(ORDER_BY_ASC);
1291 }
1292 else {
1293 query.append(ORDER_BY_DESC);
1294 }
1295 }
1296 }
1297 }
1298 else {
1299 query.append(MBDiscussionModelImpl.ORDER_BY_JPQL);
1300 }
1301
1302 String sql = query.toString();
1303
1304 Query q = session.createQuery(sql);
1305
1306 q.setFirstResult(0);
1307 q.setMaxResults(2);
1308
1309 QueryPos qPos = QueryPos.getInstance(q);
1310
1311 if (bindUuid) {
1312 qPos.add(uuid);
1313 }
1314
1315 qPos.add(companyId);
1316
1317 if (orderByComparator != null) {
1318 Object[] values = orderByComparator.getOrderByConditionValues(mbDiscussion);
1319
1320 for (Object value : values) {
1321 qPos.add(value);
1322 }
1323 }
1324
1325 List<MBDiscussion> list = q.list();
1326
1327 if (list.size() == 2) {
1328 return list.get(1);
1329 }
1330 else {
1331 return null;
1332 }
1333 }
1334
1335
1341 @Override
1342 public void removeByUuid_C(String uuid, long companyId) {
1343 for (MBDiscussion mbDiscussion : findByUuid_C(uuid, companyId,
1344 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1345 remove(mbDiscussion);
1346 }
1347 }
1348
1349
1356 @Override
1357 public int countByUuid_C(String uuid, long companyId) {
1358 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1359
1360 Object[] finderArgs = new Object[] { uuid, companyId };
1361
1362 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1363 this);
1364
1365 if (count == null) {
1366 StringBundler query = new StringBundler(3);
1367
1368 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1369
1370 boolean bindUuid = false;
1371
1372 if (uuid == null) {
1373 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1374 }
1375 else if (uuid.equals(StringPool.BLANK)) {
1376 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1377 }
1378 else {
1379 bindUuid = true;
1380
1381 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1382 }
1383
1384 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1385
1386 String sql = query.toString();
1387
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 Query q = session.createQuery(sql);
1394
1395 QueryPos qPos = QueryPos.getInstance(q);
1396
1397 if (bindUuid) {
1398 qPos.add(uuid);
1399 }
1400
1401 qPos.add(companyId);
1402
1403 count = (Long)q.uniqueResult();
1404
1405 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1406 }
1407 catch (Exception e) {
1408 FinderCacheUtil.removeResult(finderPath, finderArgs);
1409
1410 throw processException(e);
1411 }
1412 finally {
1413 closeSession(session);
1414 }
1415 }
1416
1417 return count.intValue();
1418 }
1419
1420 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbDiscussion.uuid IS NULL AND ";
1421 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbDiscussion.uuid = ? AND ";
1422 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbDiscussion.uuid IS NULL OR mbDiscussion.uuid = '') AND ";
1423 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbDiscussion.companyId = ?";
1424 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID =
1425 new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
1426 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
1427 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByClassNameId",
1428 new String[] {
1429 Long.class.getName(),
1430
1431 Integer.class.getName(), Integer.class.getName(),
1432 OrderByComparator.class.getName()
1433 });
1434 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID =
1435 new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
1436 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
1437 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByClassNameId",
1438 new String[] { Long.class.getName() },
1439 MBDiscussionModelImpl.CLASSNAMEID_COLUMN_BITMASK);
1440 public static final FinderPath FINDER_PATH_COUNT_BY_CLASSNAMEID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
1441 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1442 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByClassNameId",
1443 new String[] { Long.class.getName() });
1444
1445
1451 @Override
1452 public List<MBDiscussion> findByClassNameId(long classNameId) {
1453 return findByClassNameId(classNameId, QueryUtil.ALL_POS,
1454 QueryUtil.ALL_POS, null);
1455 }
1456
1457
1469 @Override
1470 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
1471 int end) {
1472 return findByClassNameId(classNameId, start, end, null);
1473 }
1474
1475
1488 @Override
1489 public List<MBDiscussion> findByClassNameId(long classNameId, int start,
1490 int end, OrderByComparator<MBDiscussion> orderByComparator) {
1491 boolean pagination = true;
1492 FinderPath finderPath = null;
1493 Object[] finderArgs = null;
1494
1495 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1496 (orderByComparator == null)) {
1497 pagination = false;
1498 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID;
1499 finderArgs = new Object[] { classNameId };
1500 }
1501 else {
1502 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_CLASSNAMEID;
1503 finderArgs = new Object[] { classNameId, start, end, orderByComparator };
1504 }
1505
1506 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(finderPath,
1507 finderArgs, this);
1508
1509 if ((list != null) && !list.isEmpty()) {
1510 for (MBDiscussion mbDiscussion : list) {
1511 if ((classNameId != mbDiscussion.getClassNameId())) {
1512 list = null;
1513
1514 break;
1515 }
1516 }
1517 }
1518
1519 if (list == null) {
1520 StringBundler query = null;
1521
1522 if (orderByComparator != null) {
1523 query = new StringBundler(3 +
1524 (orderByComparator.getOrderByFields().length * 3));
1525 }
1526 else {
1527 query = new StringBundler(3);
1528 }
1529
1530 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
1531
1532 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1533
1534 if (orderByComparator != null) {
1535 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1536 orderByComparator);
1537 }
1538 else
1539 if (pagination) {
1540 query.append(MBDiscussionModelImpl.ORDER_BY_JPQL);
1541 }
1542
1543 String sql = query.toString();
1544
1545 Session session = null;
1546
1547 try {
1548 session = openSession();
1549
1550 Query q = session.createQuery(sql);
1551
1552 QueryPos qPos = QueryPos.getInstance(q);
1553
1554 qPos.add(classNameId);
1555
1556 if (!pagination) {
1557 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1558 start, end, false);
1559
1560 Collections.sort(list);
1561
1562 list = Collections.unmodifiableList(list);
1563 }
1564 else {
1565 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
1566 start, end);
1567 }
1568
1569 cacheResult(list);
1570
1571 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1572 }
1573 catch (Exception e) {
1574 FinderCacheUtil.removeResult(finderPath, finderArgs);
1575
1576 throw processException(e);
1577 }
1578 finally {
1579 closeSession(session);
1580 }
1581 }
1582
1583 return list;
1584 }
1585
1586
1594 @Override
1595 public MBDiscussion findByClassNameId_First(long classNameId,
1596 OrderByComparator<MBDiscussion> orderByComparator)
1597 throws NoSuchDiscussionException {
1598 MBDiscussion mbDiscussion = fetchByClassNameId_First(classNameId,
1599 orderByComparator);
1600
1601 if (mbDiscussion != null) {
1602 return mbDiscussion;
1603 }
1604
1605 StringBundler msg = new StringBundler(4);
1606
1607 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1608
1609 msg.append("classNameId=");
1610 msg.append(classNameId);
1611
1612 msg.append(StringPool.CLOSE_CURLY_BRACE);
1613
1614 throw new NoSuchDiscussionException(msg.toString());
1615 }
1616
1617
1624 @Override
1625 public MBDiscussion fetchByClassNameId_First(long classNameId,
1626 OrderByComparator<MBDiscussion> orderByComparator) {
1627 List<MBDiscussion> list = findByClassNameId(classNameId, 0, 1,
1628 orderByComparator);
1629
1630 if (!list.isEmpty()) {
1631 return list.get(0);
1632 }
1633
1634 return null;
1635 }
1636
1637
1645 @Override
1646 public MBDiscussion findByClassNameId_Last(long classNameId,
1647 OrderByComparator<MBDiscussion> orderByComparator)
1648 throws NoSuchDiscussionException {
1649 MBDiscussion mbDiscussion = fetchByClassNameId_Last(classNameId,
1650 orderByComparator);
1651
1652 if (mbDiscussion != null) {
1653 return mbDiscussion;
1654 }
1655
1656 StringBundler msg = new StringBundler(4);
1657
1658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1659
1660 msg.append("classNameId=");
1661 msg.append(classNameId);
1662
1663 msg.append(StringPool.CLOSE_CURLY_BRACE);
1664
1665 throw new NoSuchDiscussionException(msg.toString());
1666 }
1667
1668
1675 @Override
1676 public MBDiscussion fetchByClassNameId_Last(long classNameId,
1677 OrderByComparator<MBDiscussion> orderByComparator) {
1678 int count = countByClassNameId(classNameId);
1679
1680 if (count == 0) {
1681 return null;
1682 }
1683
1684 List<MBDiscussion> list = findByClassNameId(classNameId, count - 1,
1685 count, orderByComparator);
1686
1687 if (!list.isEmpty()) {
1688 return list.get(0);
1689 }
1690
1691 return null;
1692 }
1693
1694
1703 @Override
1704 public MBDiscussion[] findByClassNameId_PrevAndNext(long discussionId,
1705 long classNameId, OrderByComparator<MBDiscussion> orderByComparator)
1706 throws NoSuchDiscussionException {
1707 MBDiscussion mbDiscussion = findByPrimaryKey(discussionId);
1708
1709 Session session = null;
1710
1711 try {
1712 session = openSession();
1713
1714 MBDiscussion[] array = new MBDiscussionImpl[3];
1715
1716 array[0] = getByClassNameId_PrevAndNext(session, mbDiscussion,
1717 classNameId, orderByComparator, true);
1718
1719 array[1] = mbDiscussion;
1720
1721 array[2] = getByClassNameId_PrevAndNext(session, mbDiscussion,
1722 classNameId, orderByComparator, false);
1723
1724 return array;
1725 }
1726 catch (Exception e) {
1727 throw processException(e);
1728 }
1729 finally {
1730 closeSession(session);
1731 }
1732 }
1733
1734 protected MBDiscussion getByClassNameId_PrevAndNext(Session session,
1735 MBDiscussion mbDiscussion, long classNameId,
1736 OrderByComparator<MBDiscussion> orderByComparator, boolean previous) {
1737 StringBundler query = null;
1738
1739 if (orderByComparator != null) {
1740 query = new StringBundler(6 +
1741 (orderByComparator.getOrderByFields().length * 6));
1742 }
1743 else {
1744 query = new StringBundler(3);
1745 }
1746
1747 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
1748
1749 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1750
1751 if (orderByComparator != null) {
1752 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1753
1754 if (orderByConditionFields.length > 0) {
1755 query.append(WHERE_AND);
1756 }
1757
1758 for (int i = 0; i < orderByConditionFields.length; i++) {
1759 query.append(_ORDER_BY_ENTITY_ALIAS);
1760 query.append(orderByConditionFields[i]);
1761
1762 if ((i + 1) < orderByConditionFields.length) {
1763 if (orderByComparator.isAscending() ^ previous) {
1764 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1765 }
1766 else {
1767 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1768 }
1769 }
1770 else {
1771 if (orderByComparator.isAscending() ^ previous) {
1772 query.append(WHERE_GREATER_THAN);
1773 }
1774 else {
1775 query.append(WHERE_LESSER_THAN);
1776 }
1777 }
1778 }
1779
1780 query.append(ORDER_BY_CLAUSE);
1781
1782 String[] orderByFields = orderByComparator.getOrderByFields();
1783
1784 for (int i = 0; i < orderByFields.length; i++) {
1785 query.append(_ORDER_BY_ENTITY_ALIAS);
1786 query.append(orderByFields[i]);
1787
1788 if ((i + 1) < orderByFields.length) {
1789 if (orderByComparator.isAscending() ^ previous) {
1790 query.append(ORDER_BY_ASC_HAS_NEXT);
1791 }
1792 else {
1793 query.append(ORDER_BY_DESC_HAS_NEXT);
1794 }
1795 }
1796 else {
1797 if (orderByComparator.isAscending() ^ previous) {
1798 query.append(ORDER_BY_ASC);
1799 }
1800 else {
1801 query.append(ORDER_BY_DESC);
1802 }
1803 }
1804 }
1805 }
1806 else {
1807 query.append(MBDiscussionModelImpl.ORDER_BY_JPQL);
1808 }
1809
1810 String sql = query.toString();
1811
1812 Query q = session.createQuery(sql);
1813
1814 q.setFirstResult(0);
1815 q.setMaxResults(2);
1816
1817 QueryPos qPos = QueryPos.getInstance(q);
1818
1819 qPos.add(classNameId);
1820
1821 if (orderByComparator != null) {
1822 Object[] values = orderByComparator.getOrderByConditionValues(mbDiscussion);
1823
1824 for (Object value : values) {
1825 qPos.add(value);
1826 }
1827 }
1828
1829 List<MBDiscussion> list = q.list();
1830
1831 if (list.size() == 2) {
1832 return list.get(1);
1833 }
1834 else {
1835 return null;
1836 }
1837 }
1838
1839
1844 @Override
1845 public void removeByClassNameId(long classNameId) {
1846 for (MBDiscussion mbDiscussion : findByClassNameId(classNameId,
1847 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1848 remove(mbDiscussion);
1849 }
1850 }
1851
1852
1858 @Override
1859 public int countByClassNameId(long classNameId) {
1860 FinderPath finderPath = FINDER_PATH_COUNT_BY_CLASSNAMEID;
1861
1862 Object[] finderArgs = new Object[] { classNameId };
1863
1864 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1865 this);
1866
1867 if (count == null) {
1868 StringBundler query = new StringBundler(2);
1869
1870 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
1871
1872 query.append(_FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2);
1873
1874 String sql = query.toString();
1875
1876 Session session = null;
1877
1878 try {
1879 session = openSession();
1880
1881 Query q = session.createQuery(sql);
1882
1883 QueryPos qPos = QueryPos.getInstance(q);
1884
1885 qPos.add(classNameId);
1886
1887 count = (Long)q.uniqueResult();
1888
1889 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1890 }
1891 catch (Exception e) {
1892 FinderCacheUtil.removeResult(finderPath, finderArgs);
1893
1894 throw processException(e);
1895 }
1896 finally {
1897 closeSession(session);
1898 }
1899 }
1900
1901 return count.intValue();
1902 }
1903
1904 private static final String _FINDER_COLUMN_CLASSNAMEID_CLASSNAMEID_2 = "mbDiscussion.classNameId = ?";
1905 public static final FinderPath FINDER_PATH_FETCH_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
1906 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
1907 FINDER_CLASS_NAME_ENTITY, "fetchByThreadId",
1908 new String[] { Long.class.getName() },
1909 MBDiscussionModelImpl.THREADID_COLUMN_BITMASK);
1910 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
1911 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
1912 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
1913 new String[] { Long.class.getName() });
1914
1915
1922 @Override
1923 public MBDiscussion findByThreadId(long threadId)
1924 throws NoSuchDiscussionException {
1925 MBDiscussion mbDiscussion = fetchByThreadId(threadId);
1926
1927 if (mbDiscussion == null) {
1928 StringBundler msg = new StringBundler(4);
1929
1930 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1931
1932 msg.append("threadId=");
1933 msg.append(threadId);
1934
1935 msg.append(StringPool.CLOSE_CURLY_BRACE);
1936
1937 if (_log.isWarnEnabled()) {
1938 _log.warn(msg.toString());
1939 }
1940
1941 throw new NoSuchDiscussionException(msg.toString());
1942 }
1943
1944 return mbDiscussion;
1945 }
1946
1947
1953 @Override
1954 public MBDiscussion fetchByThreadId(long threadId) {
1955 return fetchByThreadId(threadId, true);
1956 }
1957
1958
1965 @Override
1966 public MBDiscussion fetchByThreadId(long threadId, boolean retrieveFromCache) {
1967 Object[] finderArgs = new Object[] { threadId };
1968
1969 Object result = null;
1970
1971 if (retrieveFromCache) {
1972 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_THREADID,
1973 finderArgs, this);
1974 }
1975
1976 if (result instanceof MBDiscussion) {
1977 MBDiscussion mbDiscussion = (MBDiscussion)result;
1978
1979 if ((threadId != mbDiscussion.getThreadId())) {
1980 result = null;
1981 }
1982 }
1983
1984 if (result == null) {
1985 StringBundler query = new StringBundler(3);
1986
1987 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
1988
1989 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1990
1991 String sql = query.toString();
1992
1993 Session session = null;
1994
1995 try {
1996 session = openSession();
1997
1998 Query q = session.createQuery(sql);
1999
2000 QueryPos qPos = QueryPos.getInstance(q);
2001
2002 qPos.add(threadId);
2003
2004 List<MBDiscussion> list = q.list();
2005
2006 if (list.isEmpty()) {
2007 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
2008 finderArgs, list);
2009 }
2010 else {
2011 MBDiscussion mbDiscussion = list.get(0);
2012
2013 result = mbDiscussion;
2014
2015 cacheResult(mbDiscussion);
2016
2017 if ((mbDiscussion.getThreadId() != threadId)) {
2018 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
2019 finderArgs, mbDiscussion);
2020 }
2021 }
2022 }
2023 catch (Exception e) {
2024 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID,
2025 finderArgs);
2026
2027 throw processException(e);
2028 }
2029 finally {
2030 closeSession(session);
2031 }
2032 }
2033
2034 if (result instanceof List<?>) {
2035 return null;
2036 }
2037 else {
2038 return (MBDiscussion)result;
2039 }
2040 }
2041
2042
2048 @Override
2049 public MBDiscussion removeByThreadId(long threadId)
2050 throws NoSuchDiscussionException {
2051 MBDiscussion mbDiscussion = findByThreadId(threadId);
2052
2053 return remove(mbDiscussion);
2054 }
2055
2056
2062 @Override
2063 public int countByThreadId(long threadId) {
2064 FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
2065
2066 Object[] finderArgs = new Object[] { threadId };
2067
2068 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2069 this);
2070
2071 if (count == null) {
2072 StringBundler query = new StringBundler(2);
2073
2074 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
2075
2076 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2077
2078 String sql = query.toString();
2079
2080 Session session = null;
2081
2082 try {
2083 session = openSession();
2084
2085 Query q = session.createQuery(sql);
2086
2087 QueryPos qPos = QueryPos.getInstance(q);
2088
2089 qPos.add(threadId);
2090
2091 count = (Long)q.uniqueResult();
2092
2093 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2094 }
2095 catch (Exception e) {
2096 FinderCacheUtil.removeResult(finderPath, finderArgs);
2097
2098 throw processException(e);
2099 }
2100 finally {
2101 closeSession(session);
2102 }
2103 }
2104
2105 return count.intValue();
2106 }
2107
2108 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbDiscussion.threadId = ?";
2109 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2110 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, MBDiscussionImpl.class,
2111 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
2112 new String[] { Long.class.getName(), Long.class.getName() },
2113 MBDiscussionModelImpl.CLASSNAMEID_COLUMN_BITMASK |
2114 MBDiscussionModelImpl.CLASSPK_COLUMN_BITMASK);
2115 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2116 MBDiscussionModelImpl.FINDER_CACHE_ENABLED, Long.class,
2117 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
2118 new String[] { Long.class.getName(), Long.class.getName() });
2119
2120
2128 @Override
2129 public MBDiscussion findByC_C(long classNameId, long classPK)
2130 throws NoSuchDiscussionException {
2131 MBDiscussion mbDiscussion = fetchByC_C(classNameId, classPK);
2132
2133 if (mbDiscussion == null) {
2134 StringBundler msg = new StringBundler(6);
2135
2136 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2137
2138 msg.append("classNameId=");
2139 msg.append(classNameId);
2140
2141 msg.append(", classPK=");
2142 msg.append(classPK);
2143
2144 msg.append(StringPool.CLOSE_CURLY_BRACE);
2145
2146 if (_log.isWarnEnabled()) {
2147 _log.warn(msg.toString());
2148 }
2149
2150 throw new NoSuchDiscussionException(msg.toString());
2151 }
2152
2153 return mbDiscussion;
2154 }
2155
2156
2163 @Override
2164 public MBDiscussion fetchByC_C(long classNameId, long classPK) {
2165 return fetchByC_C(classNameId, classPK, true);
2166 }
2167
2168
2176 @Override
2177 public MBDiscussion fetchByC_C(long classNameId, long classPK,
2178 boolean retrieveFromCache) {
2179 Object[] finderArgs = new Object[] { classNameId, classPK };
2180
2181 Object result = null;
2182
2183 if (retrieveFromCache) {
2184 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
2185 finderArgs, this);
2186 }
2187
2188 if (result instanceof MBDiscussion) {
2189 MBDiscussion mbDiscussion = (MBDiscussion)result;
2190
2191 if ((classNameId != mbDiscussion.getClassNameId()) ||
2192 (classPK != mbDiscussion.getClassPK())) {
2193 result = null;
2194 }
2195 }
2196
2197 if (result == null) {
2198 StringBundler query = new StringBundler(4);
2199
2200 query.append(_SQL_SELECT_MBDISCUSSION_WHERE);
2201
2202 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2203
2204 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2205
2206 String sql = query.toString();
2207
2208 Session session = null;
2209
2210 try {
2211 session = openSession();
2212
2213 Query q = session.createQuery(sql);
2214
2215 QueryPos qPos = QueryPos.getInstance(q);
2216
2217 qPos.add(classNameId);
2218
2219 qPos.add(classPK);
2220
2221 List<MBDiscussion> list = q.list();
2222
2223 if (list.isEmpty()) {
2224 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
2225 finderArgs, list);
2226 }
2227 else {
2228 MBDiscussion mbDiscussion = list.get(0);
2229
2230 result = mbDiscussion;
2231
2232 cacheResult(mbDiscussion);
2233
2234 if ((mbDiscussion.getClassNameId() != classNameId) ||
2235 (mbDiscussion.getClassPK() != classPK)) {
2236 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
2237 finderArgs, mbDiscussion);
2238 }
2239 }
2240 }
2241 catch (Exception e) {
2242 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
2243 finderArgs);
2244
2245 throw processException(e);
2246 }
2247 finally {
2248 closeSession(session);
2249 }
2250 }
2251
2252 if (result instanceof List<?>) {
2253 return null;
2254 }
2255 else {
2256 return (MBDiscussion)result;
2257 }
2258 }
2259
2260
2267 @Override
2268 public MBDiscussion removeByC_C(long classNameId, long classPK)
2269 throws NoSuchDiscussionException {
2270 MBDiscussion mbDiscussion = findByC_C(classNameId, classPK);
2271
2272 return remove(mbDiscussion);
2273 }
2274
2275
2282 @Override
2283 public int countByC_C(long classNameId, long classPK) {
2284 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
2285
2286 Object[] finderArgs = new Object[] { classNameId, classPK };
2287
2288 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2289 this);
2290
2291 if (count == null) {
2292 StringBundler query = new StringBundler(3);
2293
2294 query.append(_SQL_COUNT_MBDISCUSSION_WHERE);
2295
2296 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
2297
2298 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
2299
2300 String sql = query.toString();
2301
2302 Session session = null;
2303
2304 try {
2305 session = openSession();
2306
2307 Query q = session.createQuery(sql);
2308
2309 QueryPos qPos = QueryPos.getInstance(q);
2310
2311 qPos.add(classNameId);
2312
2313 qPos.add(classPK);
2314
2315 count = (Long)q.uniqueResult();
2316
2317 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2318 }
2319 catch (Exception e) {
2320 FinderCacheUtil.removeResult(finderPath, finderArgs);
2321
2322 throw processException(e);
2323 }
2324 finally {
2325 closeSession(session);
2326 }
2327 }
2328
2329 return count.intValue();
2330 }
2331
2332 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbDiscussion.classNameId = ? AND ";
2333 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbDiscussion.classPK = ?";
2334
2335 public MBDiscussionPersistenceImpl() {
2336 setModelClass(MBDiscussion.class);
2337 }
2338
2339
2344 @Override
2345 public void cacheResult(MBDiscussion mbDiscussion) {
2346 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2347 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion);
2348
2349 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2350 new Object[] { mbDiscussion.getUuid(), mbDiscussion.getGroupId() },
2351 mbDiscussion);
2352
2353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID,
2354 new Object[] { mbDiscussion.getThreadId() }, mbDiscussion);
2355
2356 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
2357 new Object[] {
2358 mbDiscussion.getClassNameId(), mbDiscussion.getClassPK()
2359 }, mbDiscussion);
2360
2361 mbDiscussion.resetOriginalValues();
2362 }
2363
2364
2369 @Override
2370 public void cacheResult(List<MBDiscussion> mbDiscussions) {
2371 for (MBDiscussion mbDiscussion : mbDiscussions) {
2372 if (EntityCacheUtil.getResult(
2373 MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2374 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey()) == null) {
2375 cacheResult(mbDiscussion);
2376 }
2377 else {
2378 mbDiscussion.resetOriginalValues();
2379 }
2380 }
2381 }
2382
2383
2390 @Override
2391 public void clearCache() {
2392 EntityCacheUtil.clearCache(MBDiscussionImpl.class);
2393
2394 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2395 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2396 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2397 }
2398
2399
2406 @Override
2407 public void clearCache(MBDiscussion mbDiscussion) {
2408 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2409 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
2410
2411 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2412 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2413
2414 clearUniqueFindersCache(mbDiscussion);
2415 }
2416
2417 @Override
2418 public void clearCache(List<MBDiscussion> mbDiscussions) {
2419 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2420 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2421
2422 for (MBDiscussion mbDiscussion : mbDiscussions) {
2423 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2424 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey());
2425
2426 clearUniqueFindersCache(mbDiscussion);
2427 }
2428 }
2429
2430 protected void cacheUniqueFindersCache(MBDiscussion mbDiscussion) {
2431 if (mbDiscussion.isNew()) {
2432 Object[] args = new Object[] {
2433 mbDiscussion.getUuid(), mbDiscussion.getGroupId()
2434 };
2435
2436 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2437 Long.valueOf(1));
2438 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2439 mbDiscussion);
2440
2441 args = new Object[] { mbDiscussion.getThreadId() };
2442
2443 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID, args,
2444 Long.valueOf(1));
2445 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID, args,
2446 mbDiscussion);
2447
2448 args = new Object[] {
2449 mbDiscussion.getClassNameId(), mbDiscussion.getClassPK()
2450 };
2451
2452 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
2453 Long.valueOf(1));
2454 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
2455 mbDiscussion);
2456 }
2457 else {
2458 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
2459
2460 if ((mbDiscussionModelImpl.getColumnBitmask() &
2461 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2462 Object[] args = new Object[] {
2463 mbDiscussion.getUuid(), mbDiscussion.getGroupId()
2464 };
2465
2466 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2467 Long.valueOf(1));
2468 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2469 mbDiscussion);
2470 }
2471
2472 if ((mbDiscussionModelImpl.getColumnBitmask() &
2473 FINDER_PATH_FETCH_BY_THREADID.getColumnBitmask()) != 0) {
2474 Object[] args = new Object[] { mbDiscussion.getThreadId() };
2475
2476 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID, args,
2477 Long.valueOf(1));
2478 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_THREADID, args,
2479 mbDiscussion);
2480 }
2481
2482 if ((mbDiscussionModelImpl.getColumnBitmask() &
2483 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
2484 Object[] args = new Object[] {
2485 mbDiscussion.getClassNameId(), mbDiscussion.getClassPK()
2486 };
2487
2488 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
2489 Long.valueOf(1));
2490 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
2491 mbDiscussion);
2492 }
2493 }
2494 }
2495
2496 protected void clearUniqueFindersCache(MBDiscussion mbDiscussion) {
2497 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
2498
2499 Object[] args = new Object[] {
2500 mbDiscussion.getUuid(), mbDiscussion.getGroupId()
2501 };
2502
2503 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2504 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2505
2506 if ((mbDiscussionModelImpl.getColumnBitmask() &
2507 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2508 args = new Object[] {
2509 mbDiscussionModelImpl.getOriginalUuid(),
2510 mbDiscussionModelImpl.getOriginalGroupId()
2511 };
2512
2513 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2514 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2515 }
2516
2517 args = new Object[] { mbDiscussion.getThreadId() };
2518
2519 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
2520 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID, args);
2521
2522 if ((mbDiscussionModelImpl.getColumnBitmask() &
2523 FINDER_PATH_FETCH_BY_THREADID.getColumnBitmask()) != 0) {
2524 args = new Object[] { mbDiscussionModelImpl.getOriginalThreadId() };
2525
2526 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
2527 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_THREADID, args);
2528 }
2529
2530 args = new Object[] {
2531 mbDiscussion.getClassNameId(), mbDiscussion.getClassPK()
2532 };
2533
2534 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2535 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
2536
2537 if ((mbDiscussionModelImpl.getColumnBitmask() &
2538 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
2539 args = new Object[] {
2540 mbDiscussionModelImpl.getOriginalClassNameId(),
2541 mbDiscussionModelImpl.getOriginalClassPK()
2542 };
2543
2544 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
2545 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
2546 }
2547 }
2548
2549
2555 @Override
2556 public MBDiscussion create(long discussionId) {
2557 MBDiscussion mbDiscussion = new MBDiscussionImpl();
2558
2559 mbDiscussion.setNew(true);
2560 mbDiscussion.setPrimaryKey(discussionId);
2561
2562 String uuid = PortalUUIDUtil.generate();
2563
2564 mbDiscussion.setUuid(uuid);
2565
2566 return mbDiscussion;
2567 }
2568
2569
2576 @Override
2577 public MBDiscussion remove(long discussionId)
2578 throws NoSuchDiscussionException {
2579 return remove((Serializable)discussionId);
2580 }
2581
2582
2589 @Override
2590 public MBDiscussion remove(Serializable primaryKey)
2591 throws NoSuchDiscussionException {
2592 Session session = null;
2593
2594 try {
2595 session = openSession();
2596
2597 MBDiscussion mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
2598 primaryKey);
2599
2600 if (mbDiscussion == null) {
2601 if (_log.isWarnEnabled()) {
2602 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2603 }
2604
2605 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2606 primaryKey);
2607 }
2608
2609 return remove(mbDiscussion);
2610 }
2611 catch (NoSuchDiscussionException nsee) {
2612 throw nsee;
2613 }
2614 catch (Exception e) {
2615 throw processException(e);
2616 }
2617 finally {
2618 closeSession(session);
2619 }
2620 }
2621
2622 @Override
2623 protected MBDiscussion removeImpl(MBDiscussion mbDiscussion) {
2624 mbDiscussion = toUnwrappedModel(mbDiscussion);
2625
2626 Session session = null;
2627
2628 try {
2629 session = openSession();
2630
2631 if (!session.contains(mbDiscussion)) {
2632 mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
2633 mbDiscussion.getPrimaryKeyObj());
2634 }
2635
2636 if (mbDiscussion != null) {
2637 session.delete(mbDiscussion);
2638 }
2639 }
2640 catch (Exception e) {
2641 throw processException(e);
2642 }
2643 finally {
2644 closeSession(session);
2645 }
2646
2647 if (mbDiscussion != null) {
2648 clearCache(mbDiscussion);
2649 }
2650
2651 return mbDiscussion;
2652 }
2653
2654 @Override
2655 public MBDiscussion updateImpl(MBDiscussion mbDiscussion) {
2656 mbDiscussion = toUnwrappedModel(mbDiscussion);
2657
2658 boolean isNew = mbDiscussion.isNew();
2659
2660 MBDiscussionModelImpl mbDiscussionModelImpl = (MBDiscussionModelImpl)mbDiscussion;
2661
2662 if (Validator.isNull(mbDiscussion.getUuid())) {
2663 String uuid = PortalUUIDUtil.generate();
2664
2665 mbDiscussion.setUuid(uuid);
2666 }
2667
2668 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2669
2670 Date now = new Date();
2671
2672 if (isNew && (mbDiscussion.getCreateDate() == null)) {
2673 if (serviceContext == null) {
2674 mbDiscussion.setCreateDate(now);
2675 }
2676 else {
2677 mbDiscussion.setCreateDate(serviceContext.getCreateDate(now));
2678 }
2679 }
2680
2681 if (!mbDiscussionModelImpl.hasSetModifiedDate()) {
2682 if (serviceContext == null) {
2683 mbDiscussion.setModifiedDate(now);
2684 }
2685 else {
2686 mbDiscussion.setModifiedDate(serviceContext.getModifiedDate(now));
2687 }
2688 }
2689
2690 Session session = null;
2691
2692 try {
2693 session = openSession();
2694
2695 if (mbDiscussion.isNew()) {
2696 session.save(mbDiscussion);
2697
2698 mbDiscussion.setNew(false);
2699 }
2700 else {
2701 session.merge(mbDiscussion);
2702 }
2703 }
2704 catch (Exception e) {
2705 throw processException(e);
2706 }
2707 finally {
2708 closeSession(session);
2709 }
2710
2711 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2712
2713 if (isNew || !MBDiscussionModelImpl.COLUMN_BITMASK_ENABLED) {
2714 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2715 }
2716
2717 else {
2718 if ((mbDiscussionModelImpl.getColumnBitmask() &
2719 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2720 Object[] args = new Object[] {
2721 mbDiscussionModelImpl.getOriginalUuid()
2722 };
2723
2724 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2725 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2726 args);
2727
2728 args = new Object[] { mbDiscussionModelImpl.getUuid() };
2729
2730 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2731 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2732 args);
2733 }
2734
2735 if ((mbDiscussionModelImpl.getColumnBitmask() &
2736 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2737 Object[] args = new Object[] {
2738 mbDiscussionModelImpl.getOriginalUuid(),
2739 mbDiscussionModelImpl.getOriginalCompanyId()
2740 };
2741
2742 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2743 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2744 args);
2745
2746 args = new Object[] {
2747 mbDiscussionModelImpl.getUuid(),
2748 mbDiscussionModelImpl.getCompanyId()
2749 };
2750
2751 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2752 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2753 args);
2754 }
2755
2756 if ((mbDiscussionModelImpl.getColumnBitmask() &
2757 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID.getColumnBitmask()) != 0) {
2758 Object[] args = new Object[] {
2759 mbDiscussionModelImpl.getOriginalClassNameId()
2760 };
2761
2762 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
2763 args);
2764 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
2765 args);
2766
2767 args = new Object[] { mbDiscussionModelImpl.getClassNameId() };
2768
2769 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_CLASSNAMEID,
2770 args);
2771 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_CLASSNAMEID,
2772 args);
2773 }
2774 }
2775
2776 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2777 MBDiscussionImpl.class, mbDiscussion.getPrimaryKey(), mbDiscussion,
2778 false);
2779
2780 clearUniqueFindersCache(mbDiscussion);
2781 cacheUniqueFindersCache(mbDiscussion);
2782
2783 mbDiscussion.resetOriginalValues();
2784
2785 return mbDiscussion;
2786 }
2787
2788 protected MBDiscussion toUnwrappedModel(MBDiscussion mbDiscussion) {
2789 if (mbDiscussion instanceof MBDiscussionImpl) {
2790 return mbDiscussion;
2791 }
2792
2793 MBDiscussionImpl mbDiscussionImpl = new MBDiscussionImpl();
2794
2795 mbDiscussionImpl.setNew(mbDiscussion.isNew());
2796 mbDiscussionImpl.setPrimaryKey(mbDiscussion.getPrimaryKey());
2797
2798 mbDiscussionImpl.setUuid(mbDiscussion.getUuid());
2799 mbDiscussionImpl.setDiscussionId(mbDiscussion.getDiscussionId());
2800 mbDiscussionImpl.setGroupId(mbDiscussion.getGroupId());
2801 mbDiscussionImpl.setCompanyId(mbDiscussion.getCompanyId());
2802 mbDiscussionImpl.setUserId(mbDiscussion.getUserId());
2803 mbDiscussionImpl.setUserName(mbDiscussion.getUserName());
2804 mbDiscussionImpl.setCreateDate(mbDiscussion.getCreateDate());
2805 mbDiscussionImpl.setModifiedDate(mbDiscussion.getModifiedDate());
2806 mbDiscussionImpl.setClassNameId(mbDiscussion.getClassNameId());
2807 mbDiscussionImpl.setClassPK(mbDiscussion.getClassPK());
2808 mbDiscussionImpl.setThreadId(mbDiscussion.getThreadId());
2809
2810 return mbDiscussionImpl;
2811 }
2812
2813
2820 @Override
2821 public MBDiscussion findByPrimaryKey(Serializable primaryKey)
2822 throws NoSuchDiscussionException {
2823 MBDiscussion mbDiscussion = fetchByPrimaryKey(primaryKey);
2824
2825 if (mbDiscussion == null) {
2826 if (_log.isWarnEnabled()) {
2827 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2828 }
2829
2830 throw new NoSuchDiscussionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2831 primaryKey);
2832 }
2833
2834 return mbDiscussion;
2835 }
2836
2837
2844 @Override
2845 public MBDiscussion findByPrimaryKey(long discussionId)
2846 throws NoSuchDiscussionException {
2847 return findByPrimaryKey((Serializable)discussionId);
2848 }
2849
2850
2856 @Override
2857 public MBDiscussion fetchByPrimaryKey(Serializable primaryKey) {
2858 MBDiscussion mbDiscussion = (MBDiscussion)EntityCacheUtil.getResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2859 MBDiscussionImpl.class, primaryKey);
2860
2861 if (mbDiscussion == _nullMBDiscussion) {
2862 return null;
2863 }
2864
2865 if (mbDiscussion == null) {
2866 Session session = null;
2867
2868 try {
2869 session = openSession();
2870
2871 mbDiscussion = (MBDiscussion)session.get(MBDiscussionImpl.class,
2872 primaryKey);
2873
2874 if (mbDiscussion != null) {
2875 cacheResult(mbDiscussion);
2876 }
2877 else {
2878 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2879 MBDiscussionImpl.class, primaryKey, _nullMBDiscussion);
2880 }
2881 }
2882 catch (Exception e) {
2883 EntityCacheUtil.removeResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2884 MBDiscussionImpl.class, primaryKey);
2885
2886 throw processException(e);
2887 }
2888 finally {
2889 closeSession(session);
2890 }
2891 }
2892
2893 return mbDiscussion;
2894 }
2895
2896
2902 @Override
2903 public MBDiscussion fetchByPrimaryKey(long discussionId) {
2904 return fetchByPrimaryKey((Serializable)discussionId);
2905 }
2906
2907 @Override
2908 public Map<Serializable, MBDiscussion> fetchByPrimaryKeys(
2909 Set<Serializable> primaryKeys) {
2910 if (primaryKeys.isEmpty()) {
2911 return Collections.emptyMap();
2912 }
2913
2914 Map<Serializable, MBDiscussion> map = new HashMap<Serializable, MBDiscussion>();
2915
2916 if (primaryKeys.size() == 1) {
2917 Iterator<Serializable> iterator = primaryKeys.iterator();
2918
2919 Serializable primaryKey = iterator.next();
2920
2921 MBDiscussion mbDiscussion = fetchByPrimaryKey(primaryKey);
2922
2923 if (mbDiscussion != null) {
2924 map.put(primaryKey, mbDiscussion);
2925 }
2926
2927 return map;
2928 }
2929
2930 Set<Serializable> uncachedPrimaryKeys = null;
2931
2932 for (Serializable primaryKey : primaryKeys) {
2933 MBDiscussion mbDiscussion = (MBDiscussion)EntityCacheUtil.getResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2934 MBDiscussionImpl.class, primaryKey);
2935
2936 if (mbDiscussion == null) {
2937 if (uncachedPrimaryKeys == null) {
2938 uncachedPrimaryKeys = new HashSet<Serializable>();
2939 }
2940
2941 uncachedPrimaryKeys.add(primaryKey);
2942 }
2943 else {
2944 map.put(primaryKey, mbDiscussion);
2945 }
2946 }
2947
2948 if (uncachedPrimaryKeys == null) {
2949 return map;
2950 }
2951
2952 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2953 1);
2954
2955 query.append(_SQL_SELECT_MBDISCUSSION_WHERE_PKS_IN);
2956
2957 for (Serializable primaryKey : uncachedPrimaryKeys) {
2958 query.append(String.valueOf(primaryKey));
2959
2960 query.append(StringPool.COMMA);
2961 }
2962
2963 query.setIndex(query.index() - 1);
2964
2965 query.append(StringPool.CLOSE_PARENTHESIS);
2966
2967 String sql = query.toString();
2968
2969 Session session = null;
2970
2971 try {
2972 session = openSession();
2973
2974 Query q = session.createQuery(sql);
2975
2976 for (MBDiscussion mbDiscussion : (List<MBDiscussion>)q.list()) {
2977 map.put(mbDiscussion.getPrimaryKeyObj(), mbDiscussion);
2978
2979 cacheResult(mbDiscussion);
2980
2981 uncachedPrimaryKeys.remove(mbDiscussion.getPrimaryKeyObj());
2982 }
2983
2984 for (Serializable primaryKey : uncachedPrimaryKeys) {
2985 EntityCacheUtil.putResult(MBDiscussionModelImpl.ENTITY_CACHE_ENABLED,
2986 MBDiscussionImpl.class, primaryKey, _nullMBDiscussion);
2987 }
2988 }
2989 catch (Exception e) {
2990 throw processException(e);
2991 }
2992 finally {
2993 closeSession(session);
2994 }
2995
2996 return map;
2997 }
2998
2999
3004 @Override
3005 public List<MBDiscussion> findAll() {
3006 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3007 }
3008
3009
3020 @Override
3021 public List<MBDiscussion> findAll(int start, int end) {
3022 return findAll(start, end, null);
3023 }
3024
3025
3037 @Override
3038 public List<MBDiscussion> findAll(int start, int end,
3039 OrderByComparator<MBDiscussion> orderByComparator) {
3040 boolean pagination = true;
3041 FinderPath finderPath = null;
3042 Object[] finderArgs = null;
3043
3044 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3045 (orderByComparator == null)) {
3046 pagination = false;
3047 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3048 finderArgs = FINDER_ARGS_EMPTY;
3049 }
3050 else {
3051 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3052 finderArgs = new Object[] { start, end, orderByComparator };
3053 }
3054
3055 List<MBDiscussion> list = (List<MBDiscussion>)FinderCacheUtil.getResult(finderPath,
3056 finderArgs, this);
3057
3058 if (list == null) {
3059 StringBundler query = null;
3060 String sql = null;
3061
3062 if (orderByComparator != null) {
3063 query = new StringBundler(2 +
3064 (orderByComparator.getOrderByFields().length * 3));
3065
3066 query.append(_SQL_SELECT_MBDISCUSSION);
3067
3068 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3069 orderByComparator);
3070
3071 sql = query.toString();
3072 }
3073 else {
3074 sql = _SQL_SELECT_MBDISCUSSION;
3075
3076 if (pagination) {
3077 sql = sql.concat(MBDiscussionModelImpl.ORDER_BY_JPQL);
3078 }
3079 }
3080
3081 Session session = null;
3082
3083 try {
3084 session = openSession();
3085
3086 Query q = session.createQuery(sql);
3087
3088 if (!pagination) {
3089 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
3090 start, end, false);
3091
3092 Collections.sort(list);
3093
3094 list = Collections.unmodifiableList(list);
3095 }
3096 else {
3097 list = (List<MBDiscussion>)QueryUtil.list(q, getDialect(),
3098 start, end);
3099 }
3100
3101 cacheResult(list);
3102
3103 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3104 }
3105 catch (Exception e) {
3106 FinderCacheUtil.removeResult(finderPath, finderArgs);
3107
3108 throw processException(e);
3109 }
3110 finally {
3111 closeSession(session);
3112 }
3113 }
3114
3115 return list;
3116 }
3117
3118
3122 @Override
3123 public void removeAll() {
3124 for (MBDiscussion mbDiscussion : findAll()) {
3125 remove(mbDiscussion);
3126 }
3127 }
3128
3129
3134 @Override
3135 public int countAll() {
3136 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3137 FINDER_ARGS_EMPTY, this);
3138
3139 if (count == null) {
3140 Session session = null;
3141
3142 try {
3143 session = openSession();
3144
3145 Query q = session.createQuery(_SQL_COUNT_MBDISCUSSION);
3146
3147 count = (Long)q.uniqueResult();
3148
3149 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3150 FINDER_ARGS_EMPTY, count);
3151 }
3152 catch (Exception e) {
3153 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3154 FINDER_ARGS_EMPTY);
3155
3156 throw processException(e);
3157 }
3158 finally {
3159 closeSession(session);
3160 }
3161 }
3162
3163 return count.intValue();
3164 }
3165
3166 @Override
3167 protected Set<String> getBadColumnNames() {
3168 return _badColumnNames;
3169 }
3170
3171
3174 public void afterPropertiesSet() {
3175 }
3176
3177 public void destroy() {
3178 EntityCacheUtil.removeCache(MBDiscussionImpl.class.getName());
3179 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3180 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3181 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3182 }
3183
3184 private static final String _SQL_SELECT_MBDISCUSSION = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion";
3185 private static final String _SQL_SELECT_MBDISCUSSION_WHERE_PKS_IN = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE discussionId IN (";
3186 private static final String _SQL_SELECT_MBDISCUSSION_WHERE = "SELECT mbDiscussion FROM MBDiscussion mbDiscussion WHERE ";
3187 private static final String _SQL_COUNT_MBDISCUSSION = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion";
3188 private static final String _SQL_COUNT_MBDISCUSSION_WHERE = "SELECT COUNT(mbDiscussion) FROM MBDiscussion mbDiscussion WHERE ";
3189 private static final String _ORDER_BY_ENTITY_ALIAS = "mbDiscussion.";
3190 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBDiscussion exists with the primary key ";
3191 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBDiscussion exists with the key {";
3192 private static final Log _log = LogFactoryUtil.getLog(MBDiscussionPersistenceImpl.class);
3193 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3194 "uuid"
3195 });
3196 private static final MBDiscussion _nullMBDiscussion = new MBDiscussionImpl() {
3197 @Override
3198 public Object clone() {
3199 return this;
3200 }
3201
3202 @Override
3203 public CacheModel<MBDiscussion> toCacheModel() {
3204 return _nullMBDiscussionCacheModel;
3205 }
3206 };
3207
3208 private static final CacheModel<MBDiscussion> _nullMBDiscussionCacheModel = new CacheModel<MBDiscussion>() {
3209 @Override
3210 public MBDiscussion toEntityModel() {
3211 return _nullMBDiscussion;
3212 }
3213 };
3214 }