001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.SQLQuery;
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.ArrayUtil;
031 import com.liferay.portal.kernel.util.CalendarUtil;
032 import com.liferay.portal.kernel.util.GetterUtil;
033 import com.liferay.portal.kernel.util.InstanceFactory;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.StringBundler;
036 import com.liferay.portal.kernel.util.StringPool;
037 import com.liferay.portal.kernel.util.StringUtil;
038 import com.liferay.portal.kernel.util.UnmodifiableList;
039 import com.liferay.portal.kernel.util.Validator;
040 import com.liferay.portal.model.CacheModel;
041 import com.liferay.portal.model.ModelListener;
042 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.messageboards.NoSuchThreadException;
046 import com.liferay.portlet.messageboards.model.MBThread;
047 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
048 import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.List;
056
057
069 public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
070 implements MBThreadPersistence {
071
076 public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.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(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
082 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.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(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
085 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
088 MBThreadModelImpl.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_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
091 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
092 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
093 new String[] {
094 Long.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_GROUPID =
100 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
101 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
103 new String[] { Long.class.getName() },
104 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
105 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
106 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
108 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
110 new String[] { Long.class.getName() });
111
112
119 public List<MBThread> findByGroupId(long groupId) throws SystemException {
120 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
136 public List<MBThread> findByGroupId(long groupId, int start, int end)
137 throws SystemException {
138 return findByGroupId(groupId, start, end, null);
139 }
140
141
155 public List<MBThread> findByGroupId(long groupId, int start, int end,
156 OrderByComparator orderByComparator) throws SystemException {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
165 finderArgs = new Object[] { groupId };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
169 finderArgs = new Object[] { groupId, start, end, orderByComparator };
170 }
171
172 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
173 finderArgs, this);
174
175 if ((list != null) && !list.isEmpty()) {
176 for (MBThread mbThread : list) {
177 if ((groupId != mbThread.getGroupId())) {
178 list = null;
179
180 break;
181 }
182 }
183 }
184
185 if (list == null) {
186 StringBundler query = null;
187
188 if (orderByComparator != null) {
189 query = new StringBundler(3 +
190 (orderByComparator.getOrderByFields().length * 3));
191 }
192 else {
193 query = new StringBundler(3);
194 }
195
196 query.append(_SQL_SELECT_MBTHREAD_WHERE);
197
198 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
199
200 if (orderByComparator != null) {
201 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
202 orderByComparator);
203 }
204 else
205 if (pagination) {
206 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
207 }
208
209 String sql = query.toString();
210
211 Session session = null;
212
213 try {
214 session = openSession();
215
216 Query q = session.createQuery(sql);
217
218 QueryPos qPos = QueryPos.getInstance(q);
219
220 qPos.add(groupId);
221
222 if (!pagination) {
223 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
224 start, end, false);
225
226 Collections.sort(list);
227
228 list = new UnmodifiableList<MBThread>(list);
229 }
230 else {
231 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
232 start, end);
233 }
234
235 cacheResult(list);
236
237 FinderCacheUtil.putResult(finderPath, finderArgs, list);
238 }
239 catch (Exception e) {
240 FinderCacheUtil.removeResult(finderPath, finderArgs);
241
242 throw processException(e);
243 }
244 finally {
245 closeSession(session);
246 }
247 }
248
249 return list;
250 }
251
252
261 public MBThread findByGroupId_First(long groupId,
262 OrderByComparator orderByComparator)
263 throws NoSuchThreadException, SystemException {
264 MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
265
266 if (mbThread != null) {
267 return mbThread;
268 }
269
270 StringBundler msg = new StringBundler(4);
271
272 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
273
274 msg.append("groupId=");
275 msg.append(groupId);
276
277 msg.append(StringPool.CLOSE_CURLY_BRACE);
278
279 throw new NoSuchThreadException(msg.toString());
280 }
281
282
290 public MBThread fetchByGroupId_First(long groupId,
291 OrderByComparator orderByComparator) throws SystemException {
292 List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
293
294 if (!list.isEmpty()) {
295 return list.get(0);
296 }
297
298 return null;
299 }
300
301
310 public MBThread findByGroupId_Last(long groupId,
311 OrderByComparator orderByComparator)
312 throws NoSuchThreadException, SystemException {
313 MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
314
315 if (mbThread != null) {
316 return mbThread;
317 }
318
319 StringBundler msg = new StringBundler(4);
320
321 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322
323 msg.append("groupId=");
324 msg.append(groupId);
325
326 msg.append(StringPool.CLOSE_CURLY_BRACE);
327
328 throw new NoSuchThreadException(msg.toString());
329 }
330
331
339 public MBThread fetchByGroupId_Last(long groupId,
340 OrderByComparator orderByComparator) throws SystemException {
341 int count = countByGroupId(groupId);
342
343 List<MBThread> list = findByGroupId(groupId, count - 1, count,
344 orderByComparator);
345
346 if (!list.isEmpty()) {
347 return list.get(0);
348 }
349
350 return null;
351 }
352
353
363 public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
364 OrderByComparator orderByComparator)
365 throws NoSuchThreadException, SystemException {
366 MBThread mbThread = findByPrimaryKey(threadId);
367
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 MBThread[] array = new MBThreadImpl[3];
374
375 array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
376 orderByComparator, true);
377
378 array[1] = mbThread;
379
380 array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
381 orderByComparator, false);
382
383 return array;
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392
393 protected MBThread getByGroupId_PrevAndNext(Session session,
394 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
395 boolean previous) {
396 StringBundler query = null;
397
398 if (orderByComparator != null) {
399 query = new StringBundler(6 +
400 (orderByComparator.getOrderByFields().length * 6));
401 }
402 else {
403 query = new StringBundler(3);
404 }
405
406 query.append(_SQL_SELECT_MBTHREAD_WHERE);
407
408 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
409
410 if (orderByComparator != null) {
411 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
412
413 if (orderByConditionFields.length > 0) {
414 query.append(WHERE_AND);
415 }
416
417 for (int i = 0; i < orderByConditionFields.length; i++) {
418 query.append(_ORDER_BY_ENTITY_ALIAS);
419 query.append(orderByConditionFields[i]);
420
421 if ((i + 1) < orderByConditionFields.length) {
422 if (orderByComparator.isAscending() ^ previous) {
423 query.append(WHERE_GREATER_THAN_HAS_NEXT);
424 }
425 else {
426 query.append(WHERE_LESSER_THAN_HAS_NEXT);
427 }
428 }
429 else {
430 if (orderByComparator.isAscending() ^ previous) {
431 query.append(WHERE_GREATER_THAN);
432 }
433 else {
434 query.append(WHERE_LESSER_THAN);
435 }
436 }
437 }
438
439 query.append(ORDER_BY_CLAUSE);
440
441 String[] orderByFields = orderByComparator.getOrderByFields();
442
443 for (int i = 0; i < orderByFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByFields[i]);
446
447 if ((i + 1) < orderByFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(ORDER_BY_ASC_HAS_NEXT);
450 }
451 else {
452 query.append(ORDER_BY_DESC_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(ORDER_BY_ASC);
458 }
459 else {
460 query.append(ORDER_BY_DESC);
461 }
462 }
463 }
464 }
465 else {
466 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
467 }
468
469 String sql = query.toString();
470
471 Query q = session.createQuery(sql);
472
473 q.setFirstResult(0);
474 q.setMaxResults(2);
475
476 QueryPos qPos = QueryPos.getInstance(q);
477
478 qPos.add(groupId);
479
480 if (orderByComparator != null) {
481 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
482
483 for (Object value : values) {
484 qPos.add(value);
485 }
486 }
487
488 List<MBThread> list = q.list();
489
490 if (list.size() == 2) {
491 return list.get(1);
492 }
493 else {
494 return null;
495 }
496 }
497
498
505 public List<MBThread> filterFindByGroupId(long groupId)
506 throws SystemException {
507 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
508 QueryUtil.ALL_POS, null);
509 }
510
511
524 public List<MBThread> filterFindByGroupId(long groupId, int start, int end)
525 throws SystemException {
526 return filterFindByGroupId(groupId, start, end, null);
527 }
528
529
543 public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
544 OrderByComparator orderByComparator) throws SystemException {
545 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
546 return findByGroupId(groupId, start, end, orderByComparator);
547 }
548
549 StringBundler query = null;
550
551 if (orderByComparator != null) {
552 query = new StringBundler(3 +
553 (orderByComparator.getOrderByFields().length * 3));
554 }
555 else {
556 query = new StringBundler(3);
557 }
558
559 if (getDB().isSupportsInlineDistinct()) {
560 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
561 }
562 else {
563 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
564 }
565
566 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
567
568 if (!getDB().isSupportsInlineDistinct()) {
569 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
570 }
571
572 if (orderByComparator != null) {
573 if (getDB().isSupportsInlineDistinct()) {
574 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
575 orderByComparator);
576 }
577 else {
578 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
579 orderByComparator);
580 }
581 }
582 else {
583 if (getDB().isSupportsInlineDistinct()) {
584 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
585 }
586 else {
587 query.append(MBThreadModelImpl.ORDER_BY_SQL);
588 }
589 }
590
591 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
592 MBThread.class.getName(),
593 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
594
595 Session session = null;
596
597 try {
598 session = openSession();
599
600 SQLQuery q = session.createSQLQuery(sql);
601
602 if (getDB().isSupportsInlineDistinct()) {
603 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
604 }
605 else {
606 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
607 }
608
609 QueryPos qPos = QueryPos.getInstance(q);
610
611 qPos.add(groupId);
612
613 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
614 }
615 catch (Exception e) {
616 throw processException(e);
617 }
618 finally {
619 closeSession(session);
620 }
621 }
622
623
633 public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
634 long groupId, OrderByComparator orderByComparator)
635 throws NoSuchThreadException, SystemException {
636 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
637 return findByGroupId_PrevAndNext(threadId, groupId,
638 orderByComparator);
639 }
640
641 MBThread mbThread = findByPrimaryKey(threadId);
642
643 Session session = null;
644
645 try {
646 session = openSession();
647
648 MBThread[] array = new MBThreadImpl[3];
649
650 array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
651 groupId, orderByComparator, true);
652
653 array[1] = mbThread;
654
655 array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
656 groupId, orderByComparator, false);
657
658 return array;
659 }
660 catch (Exception e) {
661 throw processException(e);
662 }
663 finally {
664 closeSession(session);
665 }
666 }
667
668 protected MBThread filterGetByGroupId_PrevAndNext(Session session,
669 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
670 boolean previous) {
671 StringBundler query = null;
672
673 if (orderByComparator != null) {
674 query = new StringBundler(6 +
675 (orderByComparator.getOrderByFields().length * 6));
676 }
677 else {
678 query = new StringBundler(3);
679 }
680
681 if (getDB().isSupportsInlineDistinct()) {
682 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
683 }
684 else {
685 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
686 }
687
688 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
689
690 if (!getDB().isSupportsInlineDistinct()) {
691 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
692 }
693
694 if (orderByComparator != null) {
695 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
696
697 if (orderByConditionFields.length > 0) {
698 query.append(WHERE_AND);
699 }
700
701 for (int i = 0; i < orderByConditionFields.length; i++) {
702 if (getDB().isSupportsInlineDistinct()) {
703 query.append(_ORDER_BY_ENTITY_ALIAS);
704 }
705 else {
706 query.append(_ORDER_BY_ENTITY_TABLE);
707 }
708
709 query.append(orderByConditionFields[i]);
710
711 if ((i + 1) < orderByConditionFields.length) {
712 if (orderByComparator.isAscending() ^ previous) {
713 query.append(WHERE_GREATER_THAN_HAS_NEXT);
714 }
715 else {
716 query.append(WHERE_LESSER_THAN_HAS_NEXT);
717 }
718 }
719 else {
720 if (orderByComparator.isAscending() ^ previous) {
721 query.append(WHERE_GREATER_THAN);
722 }
723 else {
724 query.append(WHERE_LESSER_THAN);
725 }
726 }
727 }
728
729 query.append(ORDER_BY_CLAUSE);
730
731 String[] orderByFields = orderByComparator.getOrderByFields();
732
733 for (int i = 0; i < orderByFields.length; i++) {
734 if (getDB().isSupportsInlineDistinct()) {
735 query.append(_ORDER_BY_ENTITY_ALIAS);
736 }
737 else {
738 query.append(_ORDER_BY_ENTITY_TABLE);
739 }
740
741 query.append(orderByFields[i]);
742
743 if ((i + 1) < orderByFields.length) {
744 if (orderByComparator.isAscending() ^ previous) {
745 query.append(ORDER_BY_ASC_HAS_NEXT);
746 }
747 else {
748 query.append(ORDER_BY_DESC_HAS_NEXT);
749 }
750 }
751 else {
752 if (orderByComparator.isAscending() ^ previous) {
753 query.append(ORDER_BY_ASC);
754 }
755 else {
756 query.append(ORDER_BY_DESC);
757 }
758 }
759 }
760 }
761 else {
762 if (getDB().isSupportsInlineDistinct()) {
763 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
764 }
765 else {
766 query.append(MBThreadModelImpl.ORDER_BY_SQL);
767 }
768 }
769
770 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
771 MBThread.class.getName(),
772 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
773
774 SQLQuery q = session.createSQLQuery(sql);
775
776 q.setFirstResult(0);
777 q.setMaxResults(2);
778
779 if (getDB().isSupportsInlineDistinct()) {
780 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
781 }
782 else {
783 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
784 }
785
786 QueryPos qPos = QueryPos.getInstance(q);
787
788 qPos.add(groupId);
789
790 if (orderByComparator != null) {
791 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
792
793 for (Object value : values) {
794 qPos.add(value);
795 }
796 }
797
798 List<MBThread> list = q.list();
799
800 if (list.size() == 2) {
801 return list.get(1);
802 }
803 else {
804 return null;
805 }
806 }
807
808
814 public void removeByGroupId(long groupId) throws SystemException {
815 for (MBThread mbThread : findByGroupId(groupId, QueryUtil.ALL_POS,
816 QueryUtil.ALL_POS, null)) {
817 remove(mbThread);
818 }
819 }
820
821
828 public int countByGroupId(long groupId) throws SystemException {
829 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
830
831 Object[] finderArgs = new Object[] { groupId };
832
833 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
834 this);
835
836 if (count == null) {
837 StringBundler query = new StringBundler(2);
838
839 query.append(_SQL_COUNT_MBTHREAD_WHERE);
840
841 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
842
843 String sql = query.toString();
844
845 Session session = null;
846
847 try {
848 session = openSession();
849
850 Query q = session.createQuery(sql);
851
852 QueryPos qPos = QueryPos.getInstance(q);
853
854 qPos.add(groupId);
855
856 count = (Long)q.uniqueResult();
857
858 FinderCacheUtil.putResult(finderPath, finderArgs, count);
859 }
860 catch (Exception e) {
861 FinderCacheUtil.removeResult(finderPath, finderArgs);
862
863 throw processException(e);
864 }
865 finally {
866 closeSession(session);
867 }
868 }
869
870 return count.intValue();
871 }
872
873
880 public int filterCountByGroupId(long groupId) throws SystemException {
881 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
882 return countByGroupId(groupId);
883 }
884
885 StringBundler query = new StringBundler(2);
886
887 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
888
889 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
890
891 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
892 MBThread.class.getName(),
893 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
894
895 Session session = null;
896
897 try {
898 session = openSession();
899
900 SQLQuery q = session.createSQLQuery(sql);
901
902 q.addScalar(COUNT_COLUMN_NAME,
903 com.liferay.portal.kernel.dao.orm.Type.LONG);
904
905 QueryPos qPos = QueryPos.getInstance(q);
906
907 qPos.add(groupId);
908
909 Long count = (Long)q.uniqueResult();
910
911 return count.intValue();
912 }
913 catch (Exception e) {
914 throw processException(e);
915 }
916 finally {
917 closeSession(session);
918 }
919 }
920
921 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
922 public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
923 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
924 FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
925 new String[] { Long.class.getName() },
926 MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
927 public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
928 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
929 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
930 new String[] { Long.class.getName() });
931
932
940 public MBThread findByRootMessageId(long rootMessageId)
941 throws NoSuchThreadException, SystemException {
942 MBThread mbThread = fetchByRootMessageId(rootMessageId);
943
944 if (mbThread == null) {
945 StringBundler msg = new StringBundler(4);
946
947 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
948
949 msg.append("rootMessageId=");
950 msg.append(rootMessageId);
951
952 msg.append(StringPool.CLOSE_CURLY_BRACE);
953
954 if (_log.isWarnEnabled()) {
955 _log.warn(msg.toString());
956 }
957
958 throw new NoSuchThreadException(msg.toString());
959 }
960
961 return mbThread;
962 }
963
964
971 public MBThread fetchByRootMessageId(long rootMessageId)
972 throws SystemException {
973 return fetchByRootMessageId(rootMessageId, true);
974 }
975
976
984 public MBThread fetchByRootMessageId(long rootMessageId,
985 boolean retrieveFromCache) throws SystemException {
986 Object[] finderArgs = new Object[] { rootMessageId };
987
988 Object result = null;
989
990 if (retrieveFromCache) {
991 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
992 finderArgs, this);
993 }
994
995 if (result instanceof MBThread) {
996 MBThread mbThread = (MBThread)result;
997
998 if ((rootMessageId != mbThread.getRootMessageId())) {
999 result = null;
1000 }
1001 }
1002
1003 if (result == null) {
1004 StringBundler query = new StringBundler(3);
1005
1006 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1007
1008 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
1009
1010 String sql = query.toString();
1011
1012 Session session = null;
1013
1014 try {
1015 session = openSession();
1016
1017 Query q = session.createQuery(sql);
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 qPos.add(rootMessageId);
1022
1023 List<MBThread> list = q.list();
1024
1025 if (list.isEmpty()) {
1026 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1027 finderArgs, list);
1028 }
1029 else {
1030 if ((list.size() > 1) && _log.isWarnEnabled()) {
1031 _log.warn(
1032 "MBThreadPersistenceImpl.fetchByRootMessageId(long, boolean) with parameters (" +
1033 StringUtil.merge(finderArgs) +
1034 ") yields a result set with more than 1 result. This violates the logical unique restriction. There is no order guarantee on which result is returned by this finder.");
1035 }
1036
1037 MBThread mbThread = list.get(0);
1038
1039 result = mbThread;
1040
1041 cacheResult(mbThread);
1042
1043 if ((mbThread.getRootMessageId() != rootMessageId)) {
1044 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1045 finderArgs, mbThread);
1046 }
1047 }
1048 }
1049 catch (Exception e) {
1050 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
1051 finderArgs);
1052
1053 throw processException(e);
1054 }
1055 finally {
1056 closeSession(session);
1057 }
1058 }
1059
1060 if (result instanceof List<?>) {
1061 return null;
1062 }
1063 else {
1064 return (MBThread)result;
1065 }
1066 }
1067
1068
1075 public MBThread removeByRootMessageId(long rootMessageId)
1076 throws NoSuchThreadException, SystemException {
1077 MBThread mbThread = findByRootMessageId(rootMessageId);
1078
1079 return remove(mbThread);
1080 }
1081
1082
1089 public int countByRootMessageId(long rootMessageId)
1090 throws SystemException {
1091 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROOTMESSAGEID;
1092
1093 Object[] finderArgs = new Object[] { rootMessageId };
1094
1095 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1096 this);
1097
1098 if (count == null) {
1099 StringBundler query = new StringBundler(2);
1100
1101 query.append(_SQL_COUNT_MBTHREAD_WHERE);
1102
1103 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
1104
1105 String sql = query.toString();
1106
1107 Session session = null;
1108
1109 try {
1110 session = openSession();
1111
1112 Query q = session.createQuery(sql);
1113
1114 QueryPos qPos = QueryPos.getInstance(q);
1115
1116 qPos.add(rootMessageId);
1117
1118 count = (Long)q.uniqueResult();
1119
1120 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1121 }
1122 catch (Exception e) {
1123 FinderCacheUtil.removeResult(finderPath, finderArgs);
1124
1125 throw processException(e);
1126 }
1127 finally {
1128 closeSession(session);
1129 }
1130 }
1131
1132 return count.intValue();
1133 }
1134
1135 private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
1136 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1137 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1138 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
1139 new String[] {
1140 Long.class.getName(), Long.class.getName(),
1141
1142 Integer.class.getName(), Integer.class.getName(),
1143 OrderByComparator.class.getName()
1144 });
1145 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1146 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1147 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
1148 new String[] { Long.class.getName(), Long.class.getName() },
1149 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
1150 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
1151 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
1152 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
1153 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1154 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1155 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
1156 new String[] { Long.class.getName(), Long.class.getName() });
1157 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1158 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1159 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
1160 new String[] { Long.class.getName(), Long.class.getName() });
1161
1162
1170 public List<MBThread> findByG_C(long groupId, long categoryId)
1171 throws SystemException {
1172 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
1173 QueryUtil.ALL_POS, null);
1174 }
1175
1176
1190 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1191 int end) throws SystemException {
1192 return findByG_C(groupId, categoryId, start, end, null);
1193 }
1194
1195
1210 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
1211 int end, OrderByComparator orderByComparator) throws SystemException {
1212 boolean pagination = true;
1213 FinderPath finderPath = null;
1214 Object[] finderArgs = null;
1215
1216 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1217 (orderByComparator == null)) {
1218 pagination = false;
1219 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
1220 finderArgs = new Object[] { groupId, categoryId };
1221 }
1222 else {
1223 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
1224 finderArgs = new Object[] {
1225 groupId, categoryId,
1226
1227 start, end, orderByComparator
1228 };
1229 }
1230
1231 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1232 finderArgs, this);
1233
1234 if ((list != null) && !list.isEmpty()) {
1235 for (MBThread mbThread : list) {
1236 if ((groupId != mbThread.getGroupId()) ||
1237 (categoryId != mbThread.getCategoryId())) {
1238 list = null;
1239
1240 break;
1241 }
1242 }
1243 }
1244
1245 if (list == null) {
1246 StringBundler query = null;
1247
1248 if (orderByComparator != null) {
1249 query = new StringBundler(4 +
1250 (orderByComparator.getOrderByFields().length * 3));
1251 }
1252 else {
1253 query = new StringBundler(4);
1254 }
1255
1256 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1257
1258 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1259
1260 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1261
1262 if (orderByComparator != null) {
1263 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1264 orderByComparator);
1265 }
1266 else
1267 if (pagination) {
1268 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1269 }
1270
1271 String sql = query.toString();
1272
1273 Session session = null;
1274
1275 try {
1276 session = openSession();
1277
1278 Query q = session.createQuery(sql);
1279
1280 QueryPos qPos = QueryPos.getInstance(q);
1281
1282 qPos.add(groupId);
1283
1284 qPos.add(categoryId);
1285
1286 if (!pagination) {
1287 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1288 start, end, false);
1289
1290 Collections.sort(list);
1291
1292 list = new UnmodifiableList<MBThread>(list);
1293 }
1294 else {
1295 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1296 start, end);
1297 }
1298
1299 cacheResult(list);
1300
1301 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1302 }
1303 catch (Exception e) {
1304 FinderCacheUtil.removeResult(finderPath, finderArgs);
1305
1306 throw processException(e);
1307 }
1308 finally {
1309 closeSession(session);
1310 }
1311 }
1312
1313 return list;
1314 }
1315
1316
1326 public MBThread findByG_C_First(long groupId, long categoryId,
1327 OrderByComparator orderByComparator)
1328 throws NoSuchThreadException, SystemException {
1329 MBThread mbThread = fetchByG_C_First(groupId, categoryId,
1330 orderByComparator);
1331
1332 if (mbThread != null) {
1333 return mbThread;
1334 }
1335
1336 StringBundler msg = new StringBundler(6);
1337
1338 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1339
1340 msg.append("groupId=");
1341 msg.append(groupId);
1342
1343 msg.append(", categoryId=");
1344 msg.append(categoryId);
1345
1346 msg.append(StringPool.CLOSE_CURLY_BRACE);
1347
1348 throw new NoSuchThreadException(msg.toString());
1349 }
1350
1351
1360 public MBThread fetchByG_C_First(long groupId, long categoryId,
1361 OrderByComparator orderByComparator) throws SystemException {
1362 List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
1363 orderByComparator);
1364
1365 if (!list.isEmpty()) {
1366 return list.get(0);
1367 }
1368
1369 return null;
1370 }
1371
1372
1382 public MBThread findByG_C_Last(long groupId, long categoryId,
1383 OrderByComparator orderByComparator)
1384 throws NoSuchThreadException, SystemException {
1385 MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
1386 orderByComparator);
1387
1388 if (mbThread != null) {
1389 return mbThread;
1390 }
1391
1392 StringBundler msg = new StringBundler(6);
1393
1394 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1395
1396 msg.append("groupId=");
1397 msg.append(groupId);
1398
1399 msg.append(", categoryId=");
1400 msg.append(categoryId);
1401
1402 msg.append(StringPool.CLOSE_CURLY_BRACE);
1403
1404 throw new NoSuchThreadException(msg.toString());
1405 }
1406
1407
1416 public MBThread fetchByG_C_Last(long groupId, long categoryId,
1417 OrderByComparator orderByComparator) throws SystemException {
1418 int count = countByG_C(groupId, categoryId);
1419
1420 List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
1421 orderByComparator);
1422
1423 if (!list.isEmpty()) {
1424 return list.get(0);
1425 }
1426
1427 return null;
1428 }
1429
1430
1441 public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
1442 long categoryId, OrderByComparator orderByComparator)
1443 throws NoSuchThreadException, SystemException {
1444 MBThread mbThread = findByPrimaryKey(threadId);
1445
1446 Session session = null;
1447
1448 try {
1449 session = openSession();
1450
1451 MBThread[] array = new MBThreadImpl[3];
1452
1453 array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
1454 categoryId, orderByComparator, true);
1455
1456 array[1] = mbThread;
1457
1458 array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
1459 categoryId, orderByComparator, false);
1460
1461 return array;
1462 }
1463 catch (Exception e) {
1464 throw processException(e);
1465 }
1466 finally {
1467 closeSession(session);
1468 }
1469 }
1470
1471 protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
1472 long groupId, long categoryId, OrderByComparator orderByComparator,
1473 boolean previous) {
1474 StringBundler query = null;
1475
1476 if (orderByComparator != null) {
1477 query = new StringBundler(6 +
1478 (orderByComparator.getOrderByFields().length * 6));
1479 }
1480 else {
1481 query = new StringBundler(3);
1482 }
1483
1484 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1485
1486 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1487
1488 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1489
1490 if (orderByComparator != null) {
1491 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1492
1493 if (orderByConditionFields.length > 0) {
1494 query.append(WHERE_AND);
1495 }
1496
1497 for (int i = 0; i < orderByConditionFields.length; i++) {
1498 query.append(_ORDER_BY_ENTITY_ALIAS);
1499 query.append(orderByConditionFields[i]);
1500
1501 if ((i + 1) < orderByConditionFields.length) {
1502 if (orderByComparator.isAscending() ^ previous) {
1503 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1504 }
1505 else {
1506 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1507 }
1508 }
1509 else {
1510 if (orderByComparator.isAscending() ^ previous) {
1511 query.append(WHERE_GREATER_THAN);
1512 }
1513 else {
1514 query.append(WHERE_LESSER_THAN);
1515 }
1516 }
1517 }
1518
1519 query.append(ORDER_BY_CLAUSE);
1520
1521 String[] orderByFields = orderByComparator.getOrderByFields();
1522
1523 for (int i = 0; i < orderByFields.length; i++) {
1524 query.append(_ORDER_BY_ENTITY_ALIAS);
1525 query.append(orderByFields[i]);
1526
1527 if ((i + 1) < orderByFields.length) {
1528 if (orderByComparator.isAscending() ^ previous) {
1529 query.append(ORDER_BY_ASC_HAS_NEXT);
1530 }
1531 else {
1532 query.append(ORDER_BY_DESC_HAS_NEXT);
1533 }
1534 }
1535 else {
1536 if (orderByComparator.isAscending() ^ previous) {
1537 query.append(ORDER_BY_ASC);
1538 }
1539 else {
1540 query.append(ORDER_BY_DESC);
1541 }
1542 }
1543 }
1544 }
1545 else {
1546 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1547 }
1548
1549 String sql = query.toString();
1550
1551 Query q = session.createQuery(sql);
1552
1553 q.setFirstResult(0);
1554 q.setMaxResults(2);
1555
1556 QueryPos qPos = QueryPos.getInstance(q);
1557
1558 qPos.add(groupId);
1559
1560 qPos.add(categoryId);
1561
1562 if (orderByComparator != null) {
1563 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1564
1565 for (Object value : values) {
1566 qPos.add(value);
1567 }
1568 }
1569
1570 List<MBThread> list = q.list();
1571
1572 if (list.size() == 2) {
1573 return list.get(1);
1574 }
1575 else {
1576 return null;
1577 }
1578 }
1579
1580
1588 public List<MBThread> filterFindByG_C(long groupId, long categoryId)
1589 throws SystemException {
1590 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
1591 QueryUtil.ALL_POS, null);
1592 }
1593
1594
1608 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
1609 int start, int end) throws SystemException {
1610 return filterFindByG_C(groupId, categoryId, start, end, null);
1611 }
1612
1613
1628 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
1629 int start, int end, OrderByComparator orderByComparator)
1630 throws SystemException {
1631 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1632 return findByG_C(groupId, categoryId, start, end, orderByComparator);
1633 }
1634
1635 StringBundler query = null;
1636
1637 if (orderByComparator != null) {
1638 query = new StringBundler(4 +
1639 (orderByComparator.getOrderByFields().length * 3));
1640 }
1641 else {
1642 query = new StringBundler(4);
1643 }
1644
1645 if (getDB().isSupportsInlineDistinct()) {
1646 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1647 }
1648 else {
1649 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1650 }
1651
1652 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1653
1654 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1655
1656 if (!getDB().isSupportsInlineDistinct()) {
1657 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1658 }
1659
1660 if (orderByComparator != null) {
1661 if (getDB().isSupportsInlineDistinct()) {
1662 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1663 orderByComparator);
1664 }
1665 else {
1666 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1667 orderByComparator);
1668 }
1669 }
1670 else {
1671 if (getDB().isSupportsInlineDistinct()) {
1672 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1673 }
1674 else {
1675 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1676 }
1677 }
1678
1679 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1680 MBThread.class.getName(),
1681 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1682
1683 Session session = null;
1684
1685 try {
1686 session = openSession();
1687
1688 SQLQuery q = session.createSQLQuery(sql);
1689
1690 if (getDB().isSupportsInlineDistinct()) {
1691 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1692 }
1693 else {
1694 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1695 }
1696
1697 QueryPos qPos = QueryPos.getInstance(q);
1698
1699 qPos.add(groupId);
1700
1701 qPos.add(categoryId);
1702
1703 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1704 }
1705 catch (Exception e) {
1706 throw processException(e);
1707 }
1708 finally {
1709 closeSession(session);
1710 }
1711 }
1712
1713
1724 public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
1725 long categoryId, OrderByComparator orderByComparator)
1726 throws NoSuchThreadException, SystemException {
1727 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1728 return findByG_C_PrevAndNext(threadId, groupId, categoryId,
1729 orderByComparator);
1730 }
1731
1732 MBThread mbThread = findByPrimaryKey(threadId);
1733
1734 Session session = null;
1735
1736 try {
1737 session = openSession();
1738
1739 MBThread[] array = new MBThreadImpl[3];
1740
1741 array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
1742 categoryId, orderByComparator, true);
1743
1744 array[1] = mbThread;
1745
1746 array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
1747 categoryId, orderByComparator, false);
1748
1749 return array;
1750 }
1751 catch (Exception e) {
1752 throw processException(e);
1753 }
1754 finally {
1755 closeSession(session);
1756 }
1757 }
1758
1759 protected MBThread filterGetByG_C_PrevAndNext(Session session,
1760 MBThread mbThread, long groupId, long categoryId,
1761 OrderByComparator orderByComparator, boolean previous) {
1762 StringBundler query = null;
1763
1764 if (orderByComparator != null) {
1765 query = new StringBundler(6 +
1766 (orderByComparator.getOrderByFields().length * 6));
1767 }
1768 else {
1769 query = new StringBundler(3);
1770 }
1771
1772 if (getDB().isSupportsInlineDistinct()) {
1773 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1774 }
1775 else {
1776 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1777 }
1778
1779 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
1780
1781 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
1782
1783 if (!getDB().isSupportsInlineDistinct()) {
1784 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1785 }
1786
1787 if (orderByComparator != null) {
1788 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1789
1790 if (orderByConditionFields.length > 0) {
1791 query.append(WHERE_AND);
1792 }
1793
1794 for (int i = 0; i < orderByConditionFields.length; i++) {
1795 if (getDB().isSupportsInlineDistinct()) {
1796 query.append(_ORDER_BY_ENTITY_ALIAS);
1797 }
1798 else {
1799 query.append(_ORDER_BY_ENTITY_TABLE);
1800 }
1801
1802 query.append(orderByConditionFields[i]);
1803
1804 if ((i + 1) < orderByConditionFields.length) {
1805 if (orderByComparator.isAscending() ^ previous) {
1806 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1807 }
1808 else {
1809 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1810 }
1811 }
1812 else {
1813 if (orderByComparator.isAscending() ^ previous) {
1814 query.append(WHERE_GREATER_THAN);
1815 }
1816 else {
1817 query.append(WHERE_LESSER_THAN);
1818 }
1819 }
1820 }
1821
1822 query.append(ORDER_BY_CLAUSE);
1823
1824 String[] orderByFields = orderByComparator.getOrderByFields();
1825
1826 for (int i = 0; i < orderByFields.length; i++) {
1827 if (getDB().isSupportsInlineDistinct()) {
1828 query.append(_ORDER_BY_ENTITY_ALIAS);
1829 }
1830 else {
1831 query.append(_ORDER_BY_ENTITY_TABLE);
1832 }
1833
1834 query.append(orderByFields[i]);
1835
1836 if ((i + 1) < orderByFields.length) {
1837 if (orderByComparator.isAscending() ^ previous) {
1838 query.append(ORDER_BY_ASC_HAS_NEXT);
1839 }
1840 else {
1841 query.append(ORDER_BY_DESC_HAS_NEXT);
1842 }
1843 }
1844 else {
1845 if (orderByComparator.isAscending() ^ previous) {
1846 query.append(ORDER_BY_ASC);
1847 }
1848 else {
1849 query.append(ORDER_BY_DESC);
1850 }
1851 }
1852 }
1853 }
1854 else {
1855 if (getDB().isSupportsInlineDistinct()) {
1856 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1857 }
1858 else {
1859 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1860 }
1861 }
1862
1863 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1864 MBThread.class.getName(),
1865 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1866
1867 SQLQuery q = session.createSQLQuery(sql);
1868
1869 q.setFirstResult(0);
1870 q.setMaxResults(2);
1871
1872 if (getDB().isSupportsInlineDistinct()) {
1873 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1874 }
1875 else {
1876 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1877 }
1878
1879 QueryPos qPos = QueryPos.getInstance(q);
1880
1881 qPos.add(groupId);
1882
1883 qPos.add(categoryId);
1884
1885 if (orderByComparator != null) {
1886 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1887
1888 for (Object value : values) {
1889 qPos.add(value);
1890 }
1891 }
1892
1893 List<MBThread> list = q.list();
1894
1895 if (list.size() == 2) {
1896 return list.get(1);
1897 }
1898 else {
1899 return null;
1900 }
1901 }
1902
1903
1911 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds)
1912 throws SystemException {
1913 return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
1914 QueryUtil.ALL_POS, null);
1915 }
1916
1917
1931 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
1932 int start, int end) throws SystemException {
1933 return filterFindByG_C(groupId, categoryIds, start, end, null);
1934 }
1935
1936
1951 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
1952 int start, int end, OrderByComparator orderByComparator)
1953 throws SystemException {
1954 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1955 return findByG_C(groupId, categoryIds, start, end, orderByComparator);
1956 }
1957
1958 StringBundler query = new StringBundler();
1959
1960 if (getDB().isSupportsInlineDistinct()) {
1961 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1962 }
1963 else {
1964 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1965 }
1966
1967 boolean conjunctionable = false;
1968
1969 if (conjunctionable) {
1970 query.append(WHERE_AND);
1971 }
1972
1973 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
1974
1975 conjunctionable = true;
1976
1977 if ((categoryIds == null) || (categoryIds.length > 0)) {
1978 if (conjunctionable) {
1979 query.append(WHERE_AND);
1980 }
1981
1982 query.append(StringPool.OPEN_PARENTHESIS);
1983
1984 for (int i = 0; i < categoryIds.length; i++) {
1985 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
1986
1987 if ((i + 1) < categoryIds.length) {
1988 query.append(WHERE_OR);
1989 }
1990 }
1991
1992 query.append(StringPool.CLOSE_PARENTHESIS);
1993
1994 conjunctionable = true;
1995 }
1996
1997 if (!getDB().isSupportsInlineDistinct()) {
1998 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1999 }
2000
2001 if (orderByComparator != null) {
2002 if (getDB().isSupportsInlineDistinct()) {
2003 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2004 orderByComparator);
2005 }
2006 else {
2007 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2008 orderByComparator);
2009 }
2010 }
2011 else {
2012 if (getDB().isSupportsInlineDistinct()) {
2013 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2014 }
2015 else {
2016 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2017 }
2018 }
2019
2020 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2021 MBThread.class.getName(),
2022 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2023
2024 Session session = null;
2025
2026 try {
2027 session = openSession();
2028
2029 SQLQuery q = session.createSQLQuery(sql);
2030
2031 if (getDB().isSupportsInlineDistinct()) {
2032 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2033 }
2034 else {
2035 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2036 }
2037
2038 QueryPos qPos = QueryPos.getInstance(q);
2039
2040 qPos.add(groupId);
2041
2042 if (categoryIds != null) {
2043 qPos.add(categoryIds);
2044 }
2045
2046 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
2047 }
2048 catch (Exception e) {
2049 throw processException(e);
2050 }
2051 finally {
2052 closeSession(session);
2053 }
2054 }
2055
2056
2068 public List<MBThread> findByG_C(long groupId, long[] categoryIds)
2069 throws SystemException {
2070 return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
2071 QueryUtil.ALL_POS, null);
2072 }
2073
2074
2088 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2089 int start, int end) throws SystemException {
2090 return findByG_C(groupId, categoryIds, start, end, null);
2091 }
2092
2093
2108 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
2109 int start, int end, OrderByComparator orderByComparator)
2110 throws SystemException {
2111 if ((categoryIds != null) && (categoryIds.length == 1)) {
2112 return findByG_C(groupId, categoryIds[0], start, end,
2113 orderByComparator);
2114 }
2115
2116 boolean pagination = true;
2117 Object[] finderArgs = null;
2118
2119 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2120 (orderByComparator == null)) {
2121 pagination = false;
2122 finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
2123 }
2124 else {
2125 finderArgs = new Object[] {
2126 groupId, StringUtil.merge(categoryIds),
2127
2128 start, end, orderByComparator
2129 };
2130 }
2131
2132 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
2133 finderArgs, this);
2134
2135 if ((list != null) && !list.isEmpty()) {
2136 for (MBThread mbThread : list) {
2137 if ((groupId != mbThread.getGroupId()) ||
2138 !ArrayUtil.contains(categoryIds,
2139 mbThread.getCategoryId())) {
2140 list = null;
2141
2142 break;
2143 }
2144 }
2145 }
2146
2147 if (list == null) {
2148 StringBundler query = new StringBundler();
2149
2150 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2151
2152 boolean conjunctionable = false;
2153
2154 if (conjunctionable) {
2155 query.append(WHERE_AND);
2156 }
2157
2158 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2159
2160 conjunctionable = true;
2161
2162 if ((categoryIds == null) || (categoryIds.length > 0)) {
2163 if (conjunctionable) {
2164 query.append(WHERE_AND);
2165 }
2166
2167 query.append(StringPool.OPEN_PARENTHESIS);
2168
2169 for (int i = 0; i < categoryIds.length; i++) {
2170 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2171
2172 if ((i + 1) < categoryIds.length) {
2173 query.append(WHERE_OR);
2174 }
2175 }
2176
2177 query.append(StringPool.CLOSE_PARENTHESIS);
2178
2179 conjunctionable = true;
2180 }
2181
2182 if (orderByComparator != null) {
2183 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2184 orderByComparator);
2185 }
2186 else
2187 if (pagination) {
2188 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2189 }
2190
2191 String sql = query.toString();
2192
2193 Session session = null;
2194
2195 try {
2196 session = openSession();
2197
2198 Query q = session.createQuery(sql);
2199
2200 QueryPos qPos = QueryPos.getInstance(q);
2201
2202 qPos.add(groupId);
2203
2204 if (categoryIds != null) {
2205 qPos.add(categoryIds);
2206 }
2207
2208 if (!pagination) {
2209 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2210 start, end, false);
2211
2212 Collections.sort(list);
2213
2214 list = new UnmodifiableList<MBThread>(list);
2215 }
2216 else {
2217 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2218 start, end);
2219 }
2220
2221 cacheResult(list);
2222
2223 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
2224 finderArgs, list);
2225 }
2226 catch (Exception e) {
2227 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
2228 finderArgs);
2229
2230 throw processException(e);
2231 }
2232 finally {
2233 closeSession(session);
2234 }
2235 }
2236
2237 return list;
2238 }
2239
2240
2247 public void removeByG_C(long groupId, long categoryId)
2248 throws SystemException {
2249 for (MBThread mbThread : findByG_C(groupId, categoryId,
2250 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2251 remove(mbThread);
2252 }
2253 }
2254
2255
2263 public int countByG_C(long groupId, long categoryId)
2264 throws SystemException {
2265 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
2266
2267 Object[] finderArgs = new Object[] { groupId, categoryId };
2268
2269 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2270 this);
2271
2272 if (count == null) {
2273 StringBundler query = new StringBundler(3);
2274
2275 query.append(_SQL_COUNT_MBTHREAD_WHERE);
2276
2277 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2278
2279 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2280
2281 String sql = query.toString();
2282
2283 Session session = null;
2284
2285 try {
2286 session = openSession();
2287
2288 Query q = session.createQuery(sql);
2289
2290 QueryPos qPos = QueryPos.getInstance(q);
2291
2292 qPos.add(groupId);
2293
2294 qPos.add(categoryId);
2295
2296 count = (Long)q.uniqueResult();
2297
2298 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2299 }
2300 catch (Exception e) {
2301 FinderCacheUtil.removeResult(finderPath, finderArgs);
2302
2303 throw processException(e);
2304 }
2305 finally {
2306 closeSession(session);
2307 }
2308 }
2309
2310 return count.intValue();
2311 }
2312
2313
2321 public int countByG_C(long groupId, long[] categoryIds)
2322 throws SystemException {
2323 Object[] finderArgs = new Object[] {
2324 groupId, StringUtil.merge(categoryIds)
2325 };
2326
2327 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
2328 finderArgs, this);
2329
2330 if (count == null) {
2331 StringBundler query = new StringBundler();
2332
2333 query.append(_SQL_COUNT_MBTHREAD_WHERE);
2334
2335 boolean conjunctionable = false;
2336
2337 if (conjunctionable) {
2338 query.append(WHERE_AND);
2339 }
2340
2341 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2342
2343 conjunctionable = true;
2344
2345 if ((categoryIds == null) || (categoryIds.length > 0)) {
2346 if (conjunctionable) {
2347 query.append(WHERE_AND);
2348 }
2349
2350 query.append(StringPool.OPEN_PARENTHESIS);
2351
2352 for (int i = 0; i < categoryIds.length; i++) {
2353 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2354
2355 if ((i + 1) < categoryIds.length) {
2356 query.append(WHERE_OR);
2357 }
2358 }
2359
2360 query.append(StringPool.CLOSE_PARENTHESIS);
2361
2362 conjunctionable = true;
2363 }
2364
2365 String sql = query.toString();
2366
2367 Session session = null;
2368
2369 try {
2370 session = openSession();
2371
2372 Query q = session.createQuery(sql);
2373
2374 QueryPos qPos = QueryPos.getInstance(q);
2375
2376 qPos.add(groupId);
2377
2378 if (categoryIds != null) {
2379 qPos.add(categoryIds);
2380 }
2381
2382 count = (Long)q.uniqueResult();
2383
2384 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
2385 finderArgs, count);
2386 }
2387 catch (Exception e) {
2388 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
2389 finderArgs);
2390
2391 throw processException(e);
2392 }
2393 finally {
2394 closeSession(session);
2395 }
2396 }
2397
2398 return count.intValue();
2399 }
2400
2401
2409 public int filterCountByG_C(long groupId, long categoryId)
2410 throws SystemException {
2411 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2412 return countByG_C(groupId, categoryId);
2413 }
2414
2415 StringBundler query = new StringBundler(3);
2416
2417 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2418
2419 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2420
2421 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2422
2423 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2424 MBThread.class.getName(),
2425 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2426
2427 Session session = null;
2428
2429 try {
2430 session = openSession();
2431
2432 SQLQuery q = session.createSQLQuery(sql);
2433
2434 q.addScalar(COUNT_COLUMN_NAME,
2435 com.liferay.portal.kernel.dao.orm.Type.LONG);
2436
2437 QueryPos qPos = QueryPos.getInstance(q);
2438
2439 qPos.add(groupId);
2440
2441 qPos.add(categoryId);
2442
2443 Long count = (Long)q.uniqueResult();
2444
2445 return count.intValue();
2446 }
2447 catch (Exception e) {
2448 throw processException(e);
2449 }
2450 finally {
2451 closeSession(session);
2452 }
2453 }
2454
2455
2463 public int filterCountByG_C(long groupId, long[] categoryIds)
2464 throws SystemException {
2465 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2466 return countByG_C(groupId, categoryIds);
2467 }
2468
2469 StringBundler query = new StringBundler();
2470
2471 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2472
2473 boolean conjunctionable = false;
2474
2475 if (conjunctionable) {
2476 query.append(WHERE_AND);
2477 }
2478
2479 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
2480
2481 conjunctionable = true;
2482
2483 if ((categoryIds == null) || (categoryIds.length > 0)) {
2484 if (conjunctionable) {
2485 query.append(WHERE_AND);
2486 }
2487
2488 query.append(StringPool.OPEN_PARENTHESIS);
2489
2490 for (int i = 0; i < categoryIds.length; i++) {
2491 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
2492
2493 if ((i + 1) < categoryIds.length) {
2494 query.append(WHERE_OR);
2495 }
2496 }
2497
2498 query.append(StringPool.CLOSE_PARENTHESIS);
2499
2500 conjunctionable = true;
2501 }
2502
2503 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2504 MBThread.class.getName(),
2505 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2506
2507 Session session = null;
2508
2509 try {
2510 session = openSession();
2511
2512 SQLQuery q = session.createSQLQuery(sql);
2513
2514 q.addScalar(COUNT_COLUMN_NAME,
2515 com.liferay.portal.kernel.dao.orm.Type.LONG);
2516
2517 QueryPos qPos = QueryPos.getInstance(q);
2518
2519 qPos.add(groupId);
2520
2521 if (categoryIds != null) {
2522 qPos.add(categoryIds);
2523 }
2524
2525 Long count = (Long)q.uniqueResult();
2526
2527 return count.intValue();
2528 }
2529 catch (Exception e) {
2530 throw processException(e);
2531 }
2532 finally {
2533 closeSession(session);
2534 }
2535 }
2536
2537 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
2538 private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
2539 _removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
2540 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
2541 private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
2542 _removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
2543 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2544 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2545 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
2546 new String[] {
2547 Long.class.getName(), Long.class.getName(),
2548
2549 Integer.class.getName(), Integer.class.getName(),
2550 OrderByComparator.class.getName()
2551 });
2552 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2553 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2554 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
2555 new String[] { Long.class.getName(), Long.class.getName() });
2556
2557
2565 public List<MBThread> findByG_NotC(long groupId, long categoryId)
2566 throws SystemException {
2567 return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
2568 QueryUtil.ALL_POS, null);
2569 }
2570
2571
2585 public List<MBThread> findByG_NotC(long groupId, long categoryId,
2586 int start, int end) throws SystemException {
2587 return findByG_NotC(groupId, categoryId, start, end, null);
2588 }
2589
2590
2605 public List<MBThread> findByG_NotC(long groupId, long categoryId,
2606 int start, int end, OrderByComparator orderByComparator)
2607 throws SystemException {
2608 boolean pagination = true;
2609 FinderPath finderPath = null;
2610 Object[] finderArgs = null;
2611
2612 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
2613 finderArgs = new Object[] {
2614 groupId, categoryId,
2615
2616 start, end, orderByComparator
2617 };
2618
2619 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2620 finderArgs, this);
2621
2622 if ((list != null) && !list.isEmpty()) {
2623 for (MBThread mbThread : list) {
2624 if ((groupId != mbThread.getGroupId()) ||
2625 (categoryId != mbThread.getCategoryId())) {
2626 list = null;
2627
2628 break;
2629 }
2630 }
2631 }
2632
2633 if (list == null) {
2634 StringBundler query = null;
2635
2636 if (orderByComparator != null) {
2637 query = new StringBundler(4 +
2638 (orderByComparator.getOrderByFields().length * 3));
2639 }
2640 else {
2641 query = new StringBundler(4);
2642 }
2643
2644 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2645
2646 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
2647
2648 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
2649
2650 if (orderByComparator != null) {
2651 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2652 orderByComparator);
2653 }
2654 else
2655 if (pagination) {
2656 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2657 }
2658
2659 String sql = query.toString();
2660
2661 Session session = null;
2662
2663 try {
2664 session = openSession();
2665
2666 Query q = session.createQuery(sql);
2667
2668 QueryPos qPos = QueryPos.getInstance(q);
2669
2670 qPos.add(groupId);
2671
2672 qPos.add(categoryId);
2673
2674 if (!pagination) {
2675 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2676 start, end, false);
2677
2678 Collections.sort(list);
2679
2680 list = new UnmodifiableList<MBThread>(list);
2681 }
2682 else {
2683 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2684 start, end);
2685 }
2686
2687 cacheResult(list);
2688
2689 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2690 }
2691 catch (Exception e) {
2692 FinderCacheUtil.removeResult(finderPath, finderArgs);
2693
2694 throw processException(e);
2695 }
2696 finally {
2697 closeSession(session);
2698 }
2699 }
2700
2701 return list;
2702 }
2703
2704
2714 public MBThread findByG_NotC_First(long groupId, long categoryId,
2715 OrderByComparator orderByComparator)
2716 throws NoSuchThreadException, SystemException {
2717 MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
2718 orderByComparator);
2719
2720 if (mbThread != null) {
2721 return mbThread;
2722 }
2723
2724 StringBundler msg = new StringBundler(6);
2725
2726 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2727
2728 msg.append("groupId=");
2729 msg.append(groupId);
2730
2731 msg.append(", categoryId=");
2732 msg.append(categoryId);
2733
2734 msg.append(StringPool.CLOSE_CURLY_BRACE);
2735
2736 throw new NoSuchThreadException(msg.toString());
2737 }
2738
2739
2748 public MBThread fetchByG_NotC_First(long groupId, long categoryId,
2749 OrderByComparator orderByComparator) throws SystemException {
2750 List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
2751 orderByComparator);
2752
2753 if (!list.isEmpty()) {
2754 return list.get(0);
2755 }
2756
2757 return null;
2758 }
2759
2760
2770 public MBThread findByG_NotC_Last(long groupId, long categoryId,
2771 OrderByComparator orderByComparator)
2772 throws NoSuchThreadException, SystemException {
2773 MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
2774 orderByComparator);
2775
2776 if (mbThread != null) {
2777 return mbThread;
2778 }
2779
2780 StringBundler msg = new StringBundler(6);
2781
2782 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2783
2784 msg.append("groupId=");
2785 msg.append(groupId);
2786
2787 msg.append(", categoryId=");
2788 msg.append(categoryId);
2789
2790 msg.append(StringPool.CLOSE_CURLY_BRACE);
2791
2792 throw new NoSuchThreadException(msg.toString());
2793 }
2794
2795
2804 public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
2805 OrderByComparator orderByComparator) throws SystemException {
2806 int count = countByG_NotC(groupId, categoryId);
2807
2808 List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
2809 count, orderByComparator);
2810
2811 if (!list.isEmpty()) {
2812 return list.get(0);
2813 }
2814
2815 return null;
2816 }
2817
2818
2829 public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
2830 long categoryId, OrderByComparator orderByComparator)
2831 throws NoSuchThreadException, SystemException {
2832 MBThread mbThread = findByPrimaryKey(threadId);
2833
2834 Session session = null;
2835
2836 try {
2837 session = openSession();
2838
2839 MBThread[] array = new MBThreadImpl[3];
2840
2841 array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2842 categoryId, orderByComparator, true);
2843
2844 array[1] = mbThread;
2845
2846 array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
2847 categoryId, orderByComparator, false);
2848
2849 return array;
2850 }
2851 catch (Exception e) {
2852 throw processException(e);
2853 }
2854 finally {
2855 closeSession(session);
2856 }
2857 }
2858
2859 protected MBThread getByG_NotC_PrevAndNext(Session session,
2860 MBThread mbThread, long groupId, long categoryId,
2861 OrderByComparator orderByComparator, boolean previous) {
2862 StringBundler query = null;
2863
2864 if (orderByComparator != null) {
2865 query = new StringBundler(6 +
2866 (orderByComparator.getOrderByFields().length * 6));
2867 }
2868 else {
2869 query = new StringBundler(3);
2870 }
2871
2872 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2873
2874 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
2875
2876 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
2877
2878 if (orderByComparator != null) {
2879 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2880
2881 if (orderByConditionFields.length > 0) {
2882 query.append(WHERE_AND);
2883 }
2884
2885 for (int i = 0; i < orderByConditionFields.length; i++) {
2886 query.append(_ORDER_BY_ENTITY_ALIAS);
2887 query.append(orderByConditionFields[i]);
2888
2889 if ((i + 1) < orderByConditionFields.length) {
2890 if (orderByComparator.isAscending() ^ previous) {
2891 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2892 }
2893 else {
2894 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2895 }
2896 }
2897 else {
2898 if (orderByComparator.isAscending() ^ previous) {
2899 query.append(WHERE_GREATER_THAN);
2900 }
2901 else {
2902 query.append(WHERE_LESSER_THAN);
2903 }
2904 }
2905 }
2906
2907 query.append(ORDER_BY_CLAUSE);
2908
2909 String[] orderByFields = orderByComparator.getOrderByFields();
2910
2911 for (int i = 0; i < orderByFields.length; i++) {
2912 query.append(_ORDER_BY_ENTITY_ALIAS);
2913 query.append(orderByFields[i]);
2914
2915 if ((i + 1) < orderByFields.length) {
2916 if (orderByComparator.isAscending() ^ previous) {
2917 query.append(ORDER_BY_ASC_HAS_NEXT);
2918 }
2919 else {
2920 query.append(ORDER_BY_DESC_HAS_NEXT);
2921 }
2922 }
2923 else {
2924 if (orderByComparator.isAscending() ^ previous) {
2925 query.append(ORDER_BY_ASC);
2926 }
2927 else {
2928 query.append(ORDER_BY_DESC);
2929 }
2930 }
2931 }
2932 }
2933 else {
2934 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2935 }
2936
2937 String sql = query.toString();
2938
2939 Query q = session.createQuery(sql);
2940
2941 q.setFirstResult(0);
2942 q.setMaxResults(2);
2943
2944 QueryPos qPos = QueryPos.getInstance(q);
2945
2946 qPos.add(groupId);
2947
2948 qPos.add(categoryId);
2949
2950 if (orderByComparator != null) {
2951 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2952
2953 for (Object value : values) {
2954 qPos.add(value);
2955 }
2956 }
2957
2958 List<MBThread> list = q.list();
2959
2960 if (list.size() == 2) {
2961 return list.get(1);
2962 }
2963 else {
2964 return null;
2965 }
2966 }
2967
2968
2976 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId)
2977 throws SystemException {
2978 return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
2979 QueryUtil.ALL_POS, null);
2980 }
2981
2982
2996 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
2997 int start, int end) throws SystemException {
2998 return filterFindByG_NotC(groupId, categoryId, start, end, null);
2999 }
3000
3001
3016 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
3017 int start, int end, OrderByComparator orderByComparator)
3018 throws SystemException {
3019 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3020 return findByG_NotC(groupId, categoryId, start, end,
3021 orderByComparator);
3022 }
3023
3024 StringBundler query = null;
3025
3026 if (orderByComparator != null) {
3027 query = new StringBundler(4 +
3028 (orderByComparator.getOrderByFields().length * 3));
3029 }
3030 else {
3031 query = new StringBundler(4);
3032 }
3033
3034 if (getDB().isSupportsInlineDistinct()) {
3035 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3036 }
3037 else {
3038 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3039 }
3040
3041 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3042
3043 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3044
3045 if (!getDB().isSupportsInlineDistinct()) {
3046 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3047 }
3048
3049 if (orderByComparator != null) {
3050 if (getDB().isSupportsInlineDistinct()) {
3051 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3052 orderByComparator);
3053 }
3054 else {
3055 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3056 orderByComparator);
3057 }
3058 }
3059 else {
3060 if (getDB().isSupportsInlineDistinct()) {
3061 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3062 }
3063 else {
3064 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3065 }
3066 }
3067
3068 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3069 MBThread.class.getName(),
3070 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3071
3072 Session session = null;
3073
3074 try {
3075 session = openSession();
3076
3077 SQLQuery q = session.createSQLQuery(sql);
3078
3079 if (getDB().isSupportsInlineDistinct()) {
3080 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3081 }
3082 else {
3083 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3084 }
3085
3086 QueryPos qPos = QueryPos.getInstance(q);
3087
3088 qPos.add(groupId);
3089
3090 qPos.add(categoryId);
3091
3092 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3093 }
3094 catch (Exception e) {
3095 throw processException(e);
3096 }
3097 finally {
3098 closeSession(session);
3099 }
3100 }
3101
3102
3113 public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
3114 long groupId, long categoryId, OrderByComparator orderByComparator)
3115 throws NoSuchThreadException, SystemException {
3116 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3117 return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
3118 orderByComparator);
3119 }
3120
3121 MBThread mbThread = findByPrimaryKey(threadId);
3122
3123 Session session = null;
3124
3125 try {
3126 session = openSession();
3127
3128 MBThread[] array = new MBThreadImpl[3];
3129
3130 array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3131 groupId, categoryId, orderByComparator, true);
3132
3133 array[1] = mbThread;
3134
3135 array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
3136 groupId, categoryId, orderByComparator, false);
3137
3138 return array;
3139 }
3140 catch (Exception e) {
3141 throw processException(e);
3142 }
3143 finally {
3144 closeSession(session);
3145 }
3146 }
3147
3148 protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
3149 MBThread mbThread, long groupId, long categoryId,
3150 OrderByComparator orderByComparator, boolean previous) {
3151 StringBundler query = null;
3152
3153 if (orderByComparator != null) {
3154 query = new StringBundler(6 +
3155 (orderByComparator.getOrderByFields().length * 6));
3156 }
3157 else {
3158 query = new StringBundler(3);
3159 }
3160
3161 if (getDB().isSupportsInlineDistinct()) {
3162 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3163 }
3164 else {
3165 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3166 }
3167
3168 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3169
3170 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3171
3172 if (!getDB().isSupportsInlineDistinct()) {
3173 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3174 }
3175
3176 if (orderByComparator != null) {
3177 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3178
3179 if (orderByConditionFields.length > 0) {
3180 query.append(WHERE_AND);
3181 }
3182
3183 for (int i = 0; i < orderByConditionFields.length; i++) {
3184 if (getDB().isSupportsInlineDistinct()) {
3185 query.append(_ORDER_BY_ENTITY_ALIAS);
3186 }
3187 else {
3188 query.append(_ORDER_BY_ENTITY_TABLE);
3189 }
3190
3191 query.append(orderByConditionFields[i]);
3192
3193 if ((i + 1) < orderByConditionFields.length) {
3194 if (orderByComparator.isAscending() ^ previous) {
3195 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3196 }
3197 else {
3198 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3199 }
3200 }
3201 else {
3202 if (orderByComparator.isAscending() ^ previous) {
3203 query.append(WHERE_GREATER_THAN);
3204 }
3205 else {
3206 query.append(WHERE_LESSER_THAN);
3207 }
3208 }
3209 }
3210
3211 query.append(ORDER_BY_CLAUSE);
3212
3213 String[] orderByFields = orderByComparator.getOrderByFields();
3214
3215 for (int i = 0; i < orderByFields.length; i++) {
3216 if (getDB().isSupportsInlineDistinct()) {
3217 query.append(_ORDER_BY_ENTITY_ALIAS);
3218 }
3219 else {
3220 query.append(_ORDER_BY_ENTITY_TABLE);
3221 }
3222
3223 query.append(orderByFields[i]);
3224
3225 if ((i + 1) < orderByFields.length) {
3226 if (orderByComparator.isAscending() ^ previous) {
3227 query.append(ORDER_BY_ASC_HAS_NEXT);
3228 }
3229 else {
3230 query.append(ORDER_BY_DESC_HAS_NEXT);
3231 }
3232 }
3233 else {
3234 if (orderByComparator.isAscending() ^ previous) {
3235 query.append(ORDER_BY_ASC);
3236 }
3237 else {
3238 query.append(ORDER_BY_DESC);
3239 }
3240 }
3241 }
3242 }
3243 else {
3244 if (getDB().isSupportsInlineDistinct()) {
3245 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3246 }
3247 else {
3248 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3249 }
3250 }
3251
3252 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3253 MBThread.class.getName(),
3254 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3255
3256 SQLQuery q = session.createSQLQuery(sql);
3257
3258 q.setFirstResult(0);
3259 q.setMaxResults(2);
3260
3261 if (getDB().isSupportsInlineDistinct()) {
3262 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3263 }
3264 else {
3265 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3266 }
3267
3268 QueryPos qPos = QueryPos.getInstance(q);
3269
3270 qPos.add(groupId);
3271
3272 qPos.add(categoryId);
3273
3274 if (orderByComparator != null) {
3275 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3276
3277 for (Object value : values) {
3278 qPos.add(value);
3279 }
3280 }
3281
3282 List<MBThread> list = q.list();
3283
3284 if (list.size() == 2) {
3285 return list.get(1);
3286 }
3287 else {
3288 return null;
3289 }
3290 }
3291
3292
3299 public void removeByG_NotC(long groupId, long categoryId)
3300 throws SystemException {
3301 for (MBThread mbThread : findByG_NotC(groupId, categoryId,
3302 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3303 remove(mbThread);
3304 }
3305 }
3306
3307
3315 public int countByG_NotC(long groupId, long categoryId)
3316 throws SystemException {
3317 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC;
3318
3319 Object[] finderArgs = new Object[] { groupId, categoryId };
3320
3321 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3322 this);
3323
3324 if (count == null) {
3325 StringBundler query = new StringBundler(3);
3326
3327 query.append(_SQL_COUNT_MBTHREAD_WHERE);
3328
3329 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3330
3331 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3332
3333 String sql = query.toString();
3334
3335 Session session = null;
3336
3337 try {
3338 session = openSession();
3339
3340 Query q = session.createQuery(sql);
3341
3342 QueryPos qPos = QueryPos.getInstance(q);
3343
3344 qPos.add(groupId);
3345
3346 qPos.add(categoryId);
3347
3348 count = (Long)q.uniqueResult();
3349
3350 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3351 }
3352 catch (Exception e) {
3353 FinderCacheUtil.removeResult(finderPath, finderArgs);
3354
3355 throw processException(e);
3356 }
3357 finally {
3358 closeSession(session);
3359 }
3360 }
3361
3362 return count.intValue();
3363 }
3364
3365
3373 public int filterCountByG_NotC(long groupId, long categoryId)
3374 throws SystemException {
3375 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3376 return countByG_NotC(groupId, categoryId);
3377 }
3378
3379 StringBundler query = new StringBundler(3);
3380
3381 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3382
3383 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3384
3385 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3386
3387 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3388 MBThread.class.getName(),
3389 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3390
3391 Session session = null;
3392
3393 try {
3394 session = openSession();
3395
3396 SQLQuery q = session.createSQLQuery(sql);
3397
3398 q.addScalar(COUNT_COLUMN_NAME,
3399 com.liferay.portal.kernel.dao.orm.Type.LONG);
3400
3401 QueryPos qPos = QueryPos.getInstance(q);
3402
3403 qPos.add(groupId);
3404
3405 qPos.add(categoryId);
3406
3407 Long count = (Long)q.uniqueResult();
3408
3409 return count.intValue();
3410 }
3411 catch (Exception e) {
3412 throw processException(e);
3413 }
3414 finally {
3415 closeSession(session);
3416 }
3417 }
3418
3419 private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
3420 private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
3421 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3422 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3423 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
3424 new String[] {
3425 Long.class.getName(), Integer.class.getName(),
3426
3427 Integer.class.getName(), Integer.class.getName(),
3428 OrderByComparator.class.getName()
3429 });
3430 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3431 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3432 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
3433 new String[] { Long.class.getName(), Integer.class.getName() },
3434 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
3435 MBThreadModelImpl.STATUS_COLUMN_BITMASK |
3436 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
3437 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
3438 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3439 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
3440 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
3441 new String[] { Long.class.getName(), Integer.class.getName() });
3442
3443
3451 public List<MBThread> findByG_S(long groupId, int status)
3452 throws SystemException {
3453 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3454 null);
3455 }
3456
3457
3471 public List<MBThread> findByG_S(long groupId, int status, int start, int end)
3472 throws SystemException {
3473 return findByG_S(groupId, status, start, end, null);
3474 }
3475
3476
3491 public List<MBThread> findByG_S(long groupId, int status, int start,
3492 int end, OrderByComparator orderByComparator) throws SystemException {
3493 boolean pagination = true;
3494 FinderPath finderPath = null;
3495 Object[] finderArgs = null;
3496
3497 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3498 (orderByComparator == null)) {
3499 pagination = false;
3500 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
3501 finderArgs = new Object[] { groupId, status };
3502 }
3503 else {
3504 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
3505 finderArgs = new Object[] {
3506 groupId, status,
3507
3508 start, end, orderByComparator
3509 };
3510 }
3511
3512 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3513 finderArgs, this);
3514
3515 if ((list != null) && !list.isEmpty()) {
3516 for (MBThread mbThread : list) {
3517 if ((groupId != mbThread.getGroupId()) ||
3518 (status != mbThread.getStatus())) {
3519 list = null;
3520
3521 break;
3522 }
3523 }
3524 }
3525
3526 if (list == null) {
3527 StringBundler query = null;
3528
3529 if (orderByComparator != null) {
3530 query = new StringBundler(4 +
3531 (orderByComparator.getOrderByFields().length * 3));
3532 }
3533 else {
3534 query = new StringBundler(4);
3535 }
3536
3537 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3538
3539 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3540
3541 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3542
3543 if (orderByComparator != null) {
3544 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3545 orderByComparator);
3546 }
3547 else
3548 if (pagination) {
3549 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3550 }
3551
3552 String sql = query.toString();
3553
3554 Session session = null;
3555
3556 try {
3557 session = openSession();
3558
3559 Query q = session.createQuery(sql);
3560
3561 QueryPos qPos = QueryPos.getInstance(q);
3562
3563 qPos.add(groupId);
3564
3565 qPos.add(status);
3566
3567 if (!pagination) {
3568 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3569 start, end, false);
3570
3571 Collections.sort(list);
3572
3573 list = new UnmodifiableList<MBThread>(list);
3574 }
3575 else {
3576 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3577 start, end);
3578 }
3579
3580 cacheResult(list);
3581
3582 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3583 }
3584 catch (Exception e) {
3585 FinderCacheUtil.removeResult(finderPath, finderArgs);
3586
3587 throw processException(e);
3588 }
3589 finally {
3590 closeSession(session);
3591 }
3592 }
3593
3594 return list;
3595 }
3596
3597
3607 public MBThread findByG_S_First(long groupId, int status,
3608 OrderByComparator orderByComparator)
3609 throws NoSuchThreadException, SystemException {
3610 MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
3611
3612 if (mbThread != null) {
3613 return mbThread;
3614 }
3615
3616 StringBundler msg = new StringBundler(6);
3617
3618 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3619
3620 msg.append("groupId=");
3621 msg.append(groupId);
3622
3623 msg.append(", status=");
3624 msg.append(status);
3625
3626 msg.append(StringPool.CLOSE_CURLY_BRACE);
3627
3628 throw new NoSuchThreadException(msg.toString());
3629 }
3630
3631
3640 public MBThread fetchByG_S_First(long groupId, int status,
3641 OrderByComparator orderByComparator) throws SystemException {
3642 List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
3643
3644 if (!list.isEmpty()) {
3645 return list.get(0);
3646 }
3647
3648 return null;
3649 }
3650
3651
3661 public MBThread findByG_S_Last(long groupId, int status,
3662 OrderByComparator orderByComparator)
3663 throws NoSuchThreadException, SystemException {
3664 MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
3665
3666 if (mbThread != null) {
3667 return mbThread;
3668 }
3669
3670 StringBundler msg = new StringBundler(6);
3671
3672 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3673
3674 msg.append("groupId=");
3675 msg.append(groupId);
3676
3677 msg.append(", status=");
3678 msg.append(status);
3679
3680 msg.append(StringPool.CLOSE_CURLY_BRACE);
3681
3682 throw new NoSuchThreadException(msg.toString());
3683 }
3684
3685
3694 public MBThread fetchByG_S_Last(long groupId, int status,
3695 OrderByComparator orderByComparator) throws SystemException {
3696 int count = countByG_S(groupId, status);
3697
3698 List<MBThread> list = findByG_S(groupId, status, count - 1, count,
3699 orderByComparator);
3700
3701 if (!list.isEmpty()) {
3702 return list.get(0);
3703 }
3704
3705 return null;
3706 }
3707
3708
3719 public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
3720 int status, OrderByComparator orderByComparator)
3721 throws NoSuchThreadException, SystemException {
3722 MBThread mbThread = findByPrimaryKey(threadId);
3723
3724 Session session = null;
3725
3726 try {
3727 session = openSession();
3728
3729 MBThread[] array = new MBThreadImpl[3];
3730
3731 array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3732 orderByComparator, true);
3733
3734 array[1] = mbThread;
3735
3736 array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
3737 orderByComparator, false);
3738
3739 return array;
3740 }
3741 catch (Exception e) {
3742 throw processException(e);
3743 }
3744 finally {
3745 closeSession(session);
3746 }
3747 }
3748
3749 protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
3750 long groupId, int status, OrderByComparator orderByComparator,
3751 boolean previous) {
3752 StringBundler query = null;
3753
3754 if (orderByComparator != null) {
3755 query = new StringBundler(6 +
3756 (orderByComparator.getOrderByFields().length * 6));
3757 }
3758 else {
3759 query = new StringBundler(3);
3760 }
3761
3762 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3763
3764 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3765
3766 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3767
3768 if (orderByComparator != null) {
3769 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3770
3771 if (orderByConditionFields.length > 0) {
3772 query.append(WHERE_AND);
3773 }
3774
3775 for (int i = 0; i < orderByConditionFields.length; i++) {
3776 query.append(_ORDER_BY_ENTITY_ALIAS);
3777 query.append(orderByConditionFields[i]);
3778
3779 if ((i + 1) < orderByConditionFields.length) {
3780 if (orderByComparator.isAscending() ^ previous) {
3781 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3782 }
3783 else {
3784 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3785 }
3786 }
3787 else {
3788 if (orderByComparator.isAscending() ^ previous) {
3789 query.append(WHERE_GREATER_THAN);
3790 }
3791 else {
3792 query.append(WHERE_LESSER_THAN);
3793 }
3794 }
3795 }
3796
3797 query.append(ORDER_BY_CLAUSE);
3798
3799 String[] orderByFields = orderByComparator.getOrderByFields();
3800
3801 for (int i = 0; i < orderByFields.length; i++) {
3802 query.append(_ORDER_BY_ENTITY_ALIAS);
3803 query.append(orderByFields[i]);
3804
3805 if ((i + 1) < orderByFields.length) {
3806 if (orderByComparator.isAscending() ^ previous) {
3807 query.append(ORDER_BY_ASC_HAS_NEXT);
3808 }
3809 else {
3810 query.append(ORDER_BY_DESC_HAS_NEXT);
3811 }
3812 }
3813 else {
3814 if (orderByComparator.isAscending() ^ previous) {
3815 query.append(ORDER_BY_ASC);
3816 }
3817 else {
3818 query.append(ORDER_BY_DESC);
3819 }
3820 }
3821 }
3822 }
3823 else {
3824 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3825 }
3826
3827 String sql = query.toString();
3828
3829 Query q = session.createQuery(sql);
3830
3831 q.setFirstResult(0);
3832 q.setMaxResults(2);
3833
3834 QueryPos qPos = QueryPos.getInstance(q);
3835
3836 qPos.add(groupId);
3837
3838 qPos.add(status);
3839
3840 if (orderByComparator != null) {
3841 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3842
3843 for (Object value : values) {
3844 qPos.add(value);
3845 }
3846 }
3847
3848 List<MBThread> list = q.list();
3849
3850 if (list.size() == 2) {
3851 return list.get(1);
3852 }
3853 else {
3854 return null;
3855 }
3856 }
3857
3858
3866 public List<MBThread> filterFindByG_S(long groupId, int status)
3867 throws SystemException {
3868 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
3869 QueryUtil.ALL_POS, null);
3870 }
3871
3872
3886 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3887 int end) throws SystemException {
3888 return filterFindByG_S(groupId, status, start, end, null);
3889 }
3890
3891
3906 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
3907 int end, OrderByComparator orderByComparator) throws SystemException {
3908 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3909 return findByG_S(groupId, status, start, end, orderByComparator);
3910 }
3911
3912 StringBundler query = null;
3913
3914 if (orderByComparator != null) {
3915 query = new StringBundler(4 +
3916 (orderByComparator.getOrderByFields().length * 3));
3917 }
3918 else {
3919 query = new StringBundler(4);
3920 }
3921
3922 if (getDB().isSupportsInlineDistinct()) {
3923 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3924 }
3925 else {
3926 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3927 }
3928
3929 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
3930
3931 query.append(_FINDER_COLUMN_G_S_STATUS_2);
3932
3933 if (!getDB().isSupportsInlineDistinct()) {
3934 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3935 }
3936
3937 if (orderByComparator != null) {
3938 if (getDB().isSupportsInlineDistinct()) {
3939 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3940 orderByComparator);
3941 }
3942 else {
3943 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3944 orderByComparator);
3945 }
3946 }
3947 else {
3948 if (getDB().isSupportsInlineDistinct()) {
3949 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3950 }
3951 else {
3952 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3953 }
3954 }
3955
3956 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3957 MBThread.class.getName(),
3958 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3959
3960 Session session = null;
3961
3962 try {
3963 session = openSession();
3964
3965 SQLQuery q = session.createSQLQuery(sql);
3966
3967 if (getDB().isSupportsInlineDistinct()) {
3968 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3969 }
3970 else {
3971 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3972 }
3973
3974 QueryPos qPos = QueryPos.getInstance(q);
3975
3976 qPos.add(groupId);
3977
3978 qPos.add(status);
3979
3980 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3981 }
3982 catch (Exception e) {
3983 throw processException(e);
3984 }
3985 finally {
3986 closeSession(session);
3987 }
3988 }
3989
3990
4001 public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
4002 int status, OrderByComparator orderByComparator)
4003 throws NoSuchThreadException, SystemException {
4004 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4005 return findByG_S_PrevAndNext(threadId, groupId, status,
4006 orderByComparator);
4007 }
4008
4009 MBThread mbThread = findByPrimaryKey(threadId);
4010
4011 Session session = null;
4012
4013 try {
4014 session = openSession();
4015
4016 MBThread[] array = new MBThreadImpl[3];
4017
4018 array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
4019 status, orderByComparator, true);
4020
4021 array[1] = mbThread;
4022
4023 array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
4024 status, orderByComparator, false);
4025
4026 return array;
4027 }
4028 catch (Exception e) {
4029 throw processException(e);
4030 }
4031 finally {
4032 closeSession(session);
4033 }
4034 }
4035
4036 protected MBThread filterGetByG_S_PrevAndNext(Session session,
4037 MBThread mbThread, long groupId, int status,
4038 OrderByComparator orderByComparator, boolean previous) {
4039 StringBundler query = null;
4040
4041 if (orderByComparator != null) {
4042 query = new StringBundler(6 +
4043 (orderByComparator.getOrderByFields().length * 6));
4044 }
4045 else {
4046 query = new StringBundler(3);
4047 }
4048
4049 if (getDB().isSupportsInlineDistinct()) {
4050 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4051 }
4052 else {
4053 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4054 }
4055
4056 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4057
4058 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4059
4060 if (!getDB().isSupportsInlineDistinct()) {
4061 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4062 }
4063
4064 if (orderByComparator != null) {
4065 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4066
4067 if (orderByConditionFields.length > 0) {
4068 query.append(WHERE_AND);
4069 }
4070
4071 for (int i = 0; i < orderByConditionFields.length; i++) {
4072 if (getDB().isSupportsInlineDistinct()) {
4073 query.append(_ORDER_BY_ENTITY_ALIAS);
4074 }
4075 else {
4076 query.append(_ORDER_BY_ENTITY_TABLE);
4077 }
4078
4079 query.append(orderByConditionFields[i]);
4080
4081 if ((i + 1) < orderByConditionFields.length) {
4082 if (orderByComparator.isAscending() ^ previous) {
4083 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4084 }
4085 else {
4086 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4087 }
4088 }
4089 else {
4090 if (orderByComparator.isAscending() ^ previous) {
4091 query.append(WHERE_GREATER_THAN);
4092 }
4093 else {
4094 query.append(WHERE_LESSER_THAN);
4095 }
4096 }
4097 }
4098
4099 query.append(ORDER_BY_CLAUSE);
4100
4101 String[] orderByFields = orderByComparator.getOrderByFields();
4102
4103 for (int i = 0; i < orderByFields.length; i++) {
4104 if (getDB().isSupportsInlineDistinct()) {
4105 query.append(_ORDER_BY_ENTITY_ALIAS);
4106 }
4107 else {
4108 query.append(_ORDER_BY_ENTITY_TABLE);
4109 }
4110
4111 query.append(orderByFields[i]);
4112
4113 if ((i + 1) < orderByFields.length) {
4114 if (orderByComparator.isAscending() ^ previous) {
4115 query.append(ORDER_BY_ASC_HAS_NEXT);
4116 }
4117 else {
4118 query.append(ORDER_BY_DESC_HAS_NEXT);
4119 }
4120 }
4121 else {
4122 if (orderByComparator.isAscending() ^ previous) {
4123 query.append(ORDER_BY_ASC);
4124 }
4125 else {
4126 query.append(ORDER_BY_DESC);
4127 }
4128 }
4129 }
4130 }
4131 else {
4132 if (getDB().isSupportsInlineDistinct()) {
4133 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4134 }
4135 else {
4136 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4137 }
4138 }
4139
4140 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4141 MBThread.class.getName(),
4142 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4143
4144 SQLQuery q = session.createSQLQuery(sql);
4145
4146 q.setFirstResult(0);
4147 q.setMaxResults(2);
4148
4149 if (getDB().isSupportsInlineDistinct()) {
4150 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4151 }
4152 else {
4153 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4154 }
4155
4156 QueryPos qPos = QueryPos.getInstance(q);
4157
4158 qPos.add(groupId);
4159
4160 qPos.add(status);
4161
4162 if (orderByComparator != null) {
4163 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4164
4165 for (Object value : values) {
4166 qPos.add(value);
4167 }
4168 }
4169
4170 List<MBThread> list = q.list();
4171
4172 if (list.size() == 2) {
4173 return list.get(1);
4174 }
4175 else {
4176 return null;
4177 }
4178 }
4179
4180
4187 public void removeByG_S(long groupId, int status) throws SystemException {
4188 for (MBThread mbThread : findByG_S(groupId, status, QueryUtil.ALL_POS,
4189 QueryUtil.ALL_POS, null)) {
4190 remove(mbThread);
4191 }
4192 }
4193
4194
4202 public int countByG_S(long groupId, int status) throws SystemException {
4203 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
4204
4205 Object[] finderArgs = new Object[] { groupId, status };
4206
4207 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4208 this);
4209
4210 if (count == null) {
4211 StringBundler query = new StringBundler(3);
4212
4213 query.append(_SQL_COUNT_MBTHREAD_WHERE);
4214
4215 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4216
4217 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4218
4219 String sql = query.toString();
4220
4221 Session session = null;
4222
4223 try {
4224 session = openSession();
4225
4226 Query q = session.createQuery(sql);
4227
4228 QueryPos qPos = QueryPos.getInstance(q);
4229
4230 qPos.add(groupId);
4231
4232 qPos.add(status);
4233
4234 count = (Long)q.uniqueResult();
4235
4236 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4237 }
4238 catch (Exception e) {
4239 FinderCacheUtil.removeResult(finderPath, finderArgs);
4240
4241 throw processException(e);
4242 }
4243 finally {
4244 closeSession(session);
4245 }
4246 }
4247
4248 return count.intValue();
4249 }
4250
4251
4259 public int filterCountByG_S(long groupId, int status)
4260 throws SystemException {
4261 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4262 return countByG_S(groupId, status);
4263 }
4264
4265 StringBundler query = new StringBundler(3);
4266
4267 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
4268
4269 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4270
4271 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4272
4273 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4274 MBThread.class.getName(),
4275 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4276
4277 Session session = null;
4278
4279 try {
4280 session = openSession();
4281
4282 SQLQuery q = session.createSQLQuery(sql);
4283
4284 q.addScalar(COUNT_COLUMN_NAME,
4285 com.liferay.portal.kernel.dao.orm.Type.LONG);
4286
4287 QueryPos qPos = QueryPos.getInstance(q);
4288
4289 qPos.add(groupId);
4290
4291 qPos.add(status);
4292
4293 Long count = (Long)q.uniqueResult();
4294
4295 return count.intValue();
4296 }
4297 catch (Exception e) {
4298 throw processException(e);
4299 }
4300 finally {
4301 closeSession(session);
4302 }
4303 }
4304
4305 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
4306 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
4307 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4308 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4309 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
4310 new String[] {
4311 Long.class.getName(), Double.class.getName(),
4312
4313 Integer.class.getName(), Integer.class.getName(),
4314 OrderByComparator.class.getName()
4315 });
4316 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4317 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4318 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
4319 new String[] { Long.class.getName(), Double.class.getName() },
4320 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
4321 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
4322 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
4323 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4324 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4325 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
4326 new String[] { Long.class.getName(), Double.class.getName() });
4327
4328
4336 public List<MBThread> findByC_P(long categoryId, double priority)
4337 throws SystemException {
4338 return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
4339 QueryUtil.ALL_POS, null);
4340 }
4341
4342
4356 public List<MBThread> findByC_P(long categoryId, double priority,
4357 int start, int end) throws SystemException {
4358 return findByC_P(categoryId, priority, start, end, null);
4359 }
4360
4361
4376 public List<MBThread> findByC_P(long categoryId, double priority,
4377 int start, int end, OrderByComparator orderByComparator)
4378 throws SystemException {
4379 boolean pagination = true;
4380 FinderPath finderPath = null;
4381 Object[] finderArgs = null;
4382
4383 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4384 (orderByComparator == null)) {
4385 pagination = false;
4386 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
4387 finderArgs = new Object[] { categoryId, priority };
4388 }
4389 else {
4390 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
4391 finderArgs = new Object[] {
4392 categoryId, priority,
4393
4394 start, end, orderByComparator
4395 };
4396 }
4397
4398 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4399 finderArgs, this);
4400
4401 if ((list != null) && !list.isEmpty()) {
4402 for (MBThread mbThread : list) {
4403 if ((categoryId != mbThread.getCategoryId()) ||
4404 (priority != mbThread.getPriority())) {
4405 list = null;
4406
4407 break;
4408 }
4409 }
4410 }
4411
4412 if (list == null) {
4413 StringBundler query = null;
4414
4415 if (orderByComparator != null) {
4416 query = new StringBundler(4 +
4417 (orderByComparator.getOrderByFields().length * 3));
4418 }
4419 else {
4420 query = new StringBundler(4);
4421 }
4422
4423 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4424
4425 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4426
4427 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4428
4429 if (orderByComparator != null) {
4430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4431 orderByComparator);
4432 }
4433 else
4434 if (pagination) {
4435 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4436 }
4437
4438 String sql = query.toString();
4439
4440 Session session = null;
4441
4442 try {
4443 session = openSession();
4444
4445 Query q = session.createQuery(sql);
4446
4447 QueryPos qPos = QueryPos.getInstance(q);
4448
4449 qPos.add(categoryId);
4450
4451 qPos.add(priority);
4452
4453 if (!pagination) {
4454 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4455 start, end, false);
4456
4457 Collections.sort(list);
4458
4459 list = new UnmodifiableList<MBThread>(list);
4460 }
4461 else {
4462 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4463 start, end);
4464 }
4465
4466 cacheResult(list);
4467
4468 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4469 }
4470 catch (Exception e) {
4471 FinderCacheUtil.removeResult(finderPath, finderArgs);
4472
4473 throw processException(e);
4474 }
4475 finally {
4476 closeSession(session);
4477 }
4478 }
4479
4480 return list;
4481 }
4482
4483
4493 public MBThread findByC_P_First(long categoryId, double priority,
4494 OrderByComparator orderByComparator)
4495 throws NoSuchThreadException, SystemException {
4496 MBThread mbThread = fetchByC_P_First(categoryId, priority,
4497 orderByComparator);
4498
4499 if (mbThread != null) {
4500 return mbThread;
4501 }
4502
4503 StringBundler msg = new StringBundler(6);
4504
4505 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4506
4507 msg.append("categoryId=");
4508 msg.append(categoryId);
4509
4510 msg.append(", priority=");
4511 msg.append(priority);
4512
4513 msg.append(StringPool.CLOSE_CURLY_BRACE);
4514
4515 throw new NoSuchThreadException(msg.toString());
4516 }
4517
4518
4527 public MBThread fetchByC_P_First(long categoryId, double priority,
4528 OrderByComparator orderByComparator) throws SystemException {
4529 List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
4530 orderByComparator);
4531
4532 if (!list.isEmpty()) {
4533 return list.get(0);
4534 }
4535
4536 return null;
4537 }
4538
4539
4549 public MBThread findByC_P_Last(long categoryId, double priority,
4550 OrderByComparator orderByComparator)
4551 throws NoSuchThreadException, SystemException {
4552 MBThread mbThread = fetchByC_P_Last(categoryId, priority,
4553 orderByComparator);
4554
4555 if (mbThread != null) {
4556 return mbThread;
4557 }
4558
4559 StringBundler msg = new StringBundler(6);
4560
4561 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4562
4563 msg.append("categoryId=");
4564 msg.append(categoryId);
4565
4566 msg.append(", priority=");
4567 msg.append(priority);
4568
4569 msg.append(StringPool.CLOSE_CURLY_BRACE);
4570
4571 throw new NoSuchThreadException(msg.toString());
4572 }
4573
4574
4583 public MBThread fetchByC_P_Last(long categoryId, double priority,
4584 OrderByComparator orderByComparator) throws SystemException {
4585 int count = countByC_P(categoryId, priority);
4586
4587 List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
4588 orderByComparator);
4589
4590 if (!list.isEmpty()) {
4591 return list.get(0);
4592 }
4593
4594 return null;
4595 }
4596
4597
4608 public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
4609 double priority, OrderByComparator orderByComparator)
4610 throws NoSuchThreadException, SystemException {
4611 MBThread mbThread = findByPrimaryKey(threadId);
4612
4613 Session session = null;
4614
4615 try {
4616 session = openSession();
4617
4618 MBThread[] array = new MBThreadImpl[3];
4619
4620 array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4621 priority, orderByComparator, true);
4622
4623 array[1] = mbThread;
4624
4625 array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
4626 priority, orderByComparator, false);
4627
4628 return array;
4629 }
4630 catch (Exception e) {
4631 throw processException(e);
4632 }
4633 finally {
4634 closeSession(session);
4635 }
4636 }
4637
4638 protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
4639 long categoryId, double priority, OrderByComparator orderByComparator,
4640 boolean previous) {
4641 StringBundler query = null;
4642
4643 if (orderByComparator != null) {
4644 query = new StringBundler(6 +
4645 (orderByComparator.getOrderByFields().length * 6));
4646 }
4647 else {
4648 query = new StringBundler(3);
4649 }
4650
4651 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4652
4653 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4654
4655 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4656
4657 if (orderByComparator != null) {
4658 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4659
4660 if (orderByConditionFields.length > 0) {
4661 query.append(WHERE_AND);
4662 }
4663
4664 for (int i = 0; i < orderByConditionFields.length; i++) {
4665 query.append(_ORDER_BY_ENTITY_ALIAS);
4666 query.append(orderByConditionFields[i]);
4667
4668 if ((i + 1) < orderByConditionFields.length) {
4669 if (orderByComparator.isAscending() ^ previous) {
4670 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4671 }
4672 else {
4673 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4674 }
4675 }
4676 else {
4677 if (orderByComparator.isAscending() ^ previous) {
4678 query.append(WHERE_GREATER_THAN);
4679 }
4680 else {
4681 query.append(WHERE_LESSER_THAN);
4682 }
4683 }
4684 }
4685
4686 query.append(ORDER_BY_CLAUSE);
4687
4688 String[] orderByFields = orderByComparator.getOrderByFields();
4689
4690 for (int i = 0; i < orderByFields.length; i++) {
4691 query.append(_ORDER_BY_ENTITY_ALIAS);
4692 query.append(orderByFields[i]);
4693
4694 if ((i + 1) < orderByFields.length) {
4695 if (orderByComparator.isAscending() ^ previous) {
4696 query.append(ORDER_BY_ASC_HAS_NEXT);
4697 }
4698 else {
4699 query.append(ORDER_BY_DESC_HAS_NEXT);
4700 }
4701 }
4702 else {
4703 if (orderByComparator.isAscending() ^ previous) {
4704 query.append(ORDER_BY_ASC);
4705 }
4706 else {
4707 query.append(ORDER_BY_DESC);
4708 }
4709 }
4710 }
4711 }
4712 else {
4713 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4714 }
4715
4716 String sql = query.toString();
4717
4718 Query q = session.createQuery(sql);
4719
4720 q.setFirstResult(0);
4721 q.setMaxResults(2);
4722
4723 QueryPos qPos = QueryPos.getInstance(q);
4724
4725 qPos.add(categoryId);
4726
4727 qPos.add(priority);
4728
4729 if (orderByComparator != null) {
4730 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4731
4732 for (Object value : values) {
4733 qPos.add(value);
4734 }
4735 }
4736
4737 List<MBThread> list = q.list();
4738
4739 if (list.size() == 2) {
4740 return list.get(1);
4741 }
4742 else {
4743 return null;
4744 }
4745 }
4746
4747
4754 public void removeByC_P(long categoryId, double priority)
4755 throws SystemException {
4756 for (MBThread mbThread : findByC_P(categoryId, priority,
4757 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4758 remove(mbThread);
4759 }
4760 }
4761
4762
4770 public int countByC_P(long categoryId, double priority)
4771 throws SystemException {
4772 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
4773
4774 Object[] finderArgs = new Object[] { categoryId, priority };
4775
4776 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4777 this);
4778
4779 if (count == null) {
4780 StringBundler query = new StringBundler(3);
4781
4782 query.append(_SQL_COUNT_MBTHREAD_WHERE);
4783
4784 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
4785
4786 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
4787
4788 String sql = query.toString();
4789
4790 Session session = null;
4791
4792 try {
4793 session = openSession();
4794
4795 Query q = session.createQuery(sql);
4796
4797 QueryPos qPos = QueryPos.getInstance(q);
4798
4799 qPos.add(categoryId);
4800
4801 qPos.add(priority);
4802
4803 count = (Long)q.uniqueResult();
4804
4805 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4806 }
4807 catch (Exception e) {
4808 FinderCacheUtil.removeResult(finderPath, finderArgs);
4809
4810 throw processException(e);
4811 }
4812 finally {
4813 closeSession(session);
4814 }
4815 }
4816
4817 return count.intValue();
4818 }
4819
4820 private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
4821 private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
4822 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4823 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4824 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
4825 new String[] {
4826 Date.class.getName(), Double.class.getName(),
4827
4828 Integer.class.getName(), Integer.class.getName(),
4829 OrderByComparator.class.getName()
4830 });
4831 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4832 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4833 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
4834 new String[] { Date.class.getName(), Double.class.getName() },
4835 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
4836 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
4837 public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4838 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4839 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
4840 new String[] { Date.class.getName(), Double.class.getName() });
4841
4842
4850 public List<MBThread> findByL_P(Date lastPostDate, double priority)
4851 throws SystemException {
4852 return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
4853 QueryUtil.ALL_POS, null);
4854 }
4855
4856
4870 public List<MBThread> findByL_P(Date lastPostDate, double priority,
4871 int start, int end) throws SystemException {
4872 return findByL_P(lastPostDate, priority, start, end, null);
4873 }
4874
4875
4890 public List<MBThread> findByL_P(Date lastPostDate, double priority,
4891 int start, int end, OrderByComparator orderByComparator)
4892 throws SystemException {
4893 boolean pagination = true;
4894 FinderPath finderPath = null;
4895 Object[] finderArgs = null;
4896
4897 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4898 (orderByComparator == null)) {
4899 pagination = false;
4900 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
4901 finderArgs = new Object[] { lastPostDate, priority };
4902 }
4903 else {
4904 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
4905 finderArgs = new Object[] {
4906 lastPostDate, priority,
4907
4908 start, end, orderByComparator
4909 };
4910 }
4911
4912 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4913 finderArgs, this);
4914
4915 if ((list != null) && !list.isEmpty()) {
4916 for (MBThread mbThread : list) {
4917 if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
4918 (priority != mbThread.getPriority())) {
4919 list = null;
4920
4921 break;
4922 }
4923 }
4924 }
4925
4926 if (list == null) {
4927 StringBundler query = null;
4928
4929 if (orderByComparator != null) {
4930 query = new StringBundler(4 +
4931 (orderByComparator.getOrderByFields().length * 3));
4932 }
4933 else {
4934 query = new StringBundler(4);
4935 }
4936
4937 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4938
4939 if (lastPostDate == null) {
4940 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
4941 }
4942 else {
4943 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
4944 }
4945
4946 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
4947
4948 if (orderByComparator != null) {
4949 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4950 orderByComparator);
4951 }
4952 else
4953 if (pagination) {
4954 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4955 }
4956
4957 String sql = query.toString();
4958
4959 Session session = null;
4960
4961 try {
4962 session = openSession();
4963
4964 Query q = session.createQuery(sql);
4965
4966 QueryPos qPos = QueryPos.getInstance(q);
4967
4968 if (lastPostDate != null) {
4969 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
4970 }
4971
4972 qPos.add(priority);
4973
4974 if (!pagination) {
4975 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4976 start, end, false);
4977
4978 Collections.sort(list);
4979
4980 list = new UnmodifiableList<MBThread>(list);
4981 }
4982 else {
4983 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4984 start, end);
4985 }
4986
4987 cacheResult(list);
4988
4989 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4990 }
4991 catch (Exception e) {
4992 FinderCacheUtil.removeResult(finderPath, finderArgs);
4993
4994 throw processException(e);
4995 }
4996 finally {
4997 closeSession(session);
4998 }
4999 }
5000
5001 return list;
5002 }
5003
5004
5014 public MBThread findByL_P_First(Date lastPostDate, double priority,
5015 OrderByComparator orderByComparator)
5016 throws NoSuchThreadException, SystemException {
5017 MBThread mbThread = fetchByL_P_First(lastPostDate, priority,
5018 orderByComparator);
5019
5020 if (mbThread != null) {
5021 return mbThread;
5022 }
5023
5024 StringBundler msg = new StringBundler(6);
5025
5026 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5027
5028 msg.append("lastPostDate=");
5029 msg.append(lastPostDate);
5030
5031 msg.append(", priority=");
5032 msg.append(priority);
5033
5034 msg.append(StringPool.CLOSE_CURLY_BRACE);
5035
5036 throw new NoSuchThreadException(msg.toString());
5037 }
5038
5039
5048 public MBThread fetchByL_P_First(Date lastPostDate, double priority,
5049 OrderByComparator orderByComparator) throws SystemException {
5050 List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
5051 orderByComparator);
5052
5053 if (!list.isEmpty()) {
5054 return list.get(0);
5055 }
5056
5057 return null;
5058 }
5059
5060
5070 public MBThread findByL_P_Last(Date lastPostDate, double priority,
5071 OrderByComparator orderByComparator)
5072 throws NoSuchThreadException, SystemException {
5073 MBThread mbThread = fetchByL_P_Last(lastPostDate, priority,
5074 orderByComparator);
5075
5076 if (mbThread != null) {
5077 return mbThread;
5078 }
5079
5080 StringBundler msg = new StringBundler(6);
5081
5082 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5083
5084 msg.append("lastPostDate=");
5085 msg.append(lastPostDate);
5086
5087 msg.append(", priority=");
5088 msg.append(priority);
5089
5090 msg.append(StringPool.CLOSE_CURLY_BRACE);
5091
5092 throw new NoSuchThreadException(msg.toString());
5093 }
5094
5095
5104 public MBThread fetchByL_P_Last(Date lastPostDate, double priority,
5105 OrderByComparator orderByComparator) throws SystemException {
5106 int count = countByL_P(lastPostDate, priority);
5107
5108 List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
5109 count, orderByComparator);
5110
5111 if (!list.isEmpty()) {
5112 return list.get(0);
5113 }
5114
5115 return null;
5116 }
5117
5118
5129 public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
5130 double priority, OrderByComparator orderByComparator)
5131 throws NoSuchThreadException, SystemException {
5132 MBThread mbThread = findByPrimaryKey(threadId);
5133
5134 Session session = null;
5135
5136 try {
5137 session = openSession();
5138
5139 MBThread[] array = new MBThreadImpl[3];
5140
5141 array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
5142 priority, orderByComparator, true);
5143
5144 array[1] = mbThread;
5145
5146 array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
5147 priority, orderByComparator, false);
5148
5149 return array;
5150 }
5151 catch (Exception e) {
5152 throw processException(e);
5153 }
5154 finally {
5155 closeSession(session);
5156 }
5157 }
5158
5159 protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
5160 Date lastPostDate, double priority,
5161 OrderByComparator orderByComparator, boolean previous) {
5162 StringBundler query = null;
5163
5164 if (orderByComparator != null) {
5165 query = new StringBundler(6 +
5166 (orderByComparator.getOrderByFields().length * 6));
5167 }
5168 else {
5169 query = new StringBundler(3);
5170 }
5171
5172 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5173
5174 if (lastPostDate == null) {
5175 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
5176 }
5177 else {
5178 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
5179 }
5180
5181 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
5182
5183 if (orderByComparator != null) {
5184 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5185
5186 if (orderByConditionFields.length > 0) {
5187 query.append(WHERE_AND);
5188 }
5189
5190 for (int i = 0; i < orderByConditionFields.length; i++) {
5191 query.append(_ORDER_BY_ENTITY_ALIAS);
5192 query.append(orderByConditionFields[i]);
5193
5194 if ((i + 1) < orderByConditionFields.length) {
5195 if (orderByComparator.isAscending() ^ previous) {
5196 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5197 }
5198 else {
5199 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5200 }
5201 }
5202 else {
5203 if (orderByComparator.isAscending() ^ previous) {
5204 query.append(WHERE_GREATER_THAN);
5205 }
5206 else {
5207 query.append(WHERE_LESSER_THAN);
5208 }
5209 }
5210 }
5211
5212 query.append(ORDER_BY_CLAUSE);
5213
5214 String[] orderByFields = orderByComparator.getOrderByFields();
5215
5216 for (int i = 0; i < orderByFields.length; i++) {
5217 query.append(_ORDER_BY_ENTITY_ALIAS);
5218 query.append(orderByFields[i]);
5219
5220 if ((i + 1) < orderByFields.length) {
5221 if (orderByComparator.isAscending() ^ previous) {
5222 query.append(ORDER_BY_ASC_HAS_NEXT);
5223 }
5224 else {
5225 query.append(ORDER_BY_DESC_HAS_NEXT);
5226 }
5227 }
5228 else {
5229 if (orderByComparator.isAscending() ^ previous) {
5230 query.append(ORDER_BY_ASC);
5231 }
5232 else {
5233 query.append(ORDER_BY_DESC);
5234 }
5235 }
5236 }
5237 }
5238 else {
5239 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5240 }
5241
5242 String sql = query.toString();
5243
5244 Query q = session.createQuery(sql);
5245
5246 q.setFirstResult(0);
5247 q.setMaxResults(2);
5248
5249 QueryPos qPos = QueryPos.getInstance(q);
5250
5251 if (lastPostDate != null) {
5252 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5253 }
5254
5255 qPos.add(priority);
5256
5257 if (orderByComparator != null) {
5258 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5259
5260 for (Object value : values) {
5261 qPos.add(value);
5262 }
5263 }
5264
5265 List<MBThread> list = q.list();
5266
5267 if (list.size() == 2) {
5268 return list.get(1);
5269 }
5270 else {
5271 return null;
5272 }
5273 }
5274
5275
5282 public void removeByL_P(Date lastPostDate, double priority)
5283 throws SystemException {
5284 for (MBThread mbThread : findByL_P(lastPostDate, priority,
5285 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5286 remove(mbThread);
5287 }
5288 }
5289
5290
5298 public int countByL_P(Date lastPostDate, double priority)
5299 throws SystemException {
5300 FinderPath finderPath = FINDER_PATH_COUNT_BY_L_P;
5301
5302 Object[] finderArgs = new Object[] { lastPostDate, priority };
5303
5304 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5305 this);
5306
5307 if (count == null) {
5308 StringBundler query = new StringBundler(3);
5309
5310 query.append(_SQL_COUNT_MBTHREAD_WHERE);
5311
5312 if (lastPostDate == null) {
5313 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
5314 }
5315 else {
5316 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
5317 }
5318
5319 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
5320
5321 String sql = query.toString();
5322
5323 Session session = null;
5324
5325 try {
5326 session = openSession();
5327
5328 Query q = session.createQuery(sql);
5329
5330 QueryPos qPos = QueryPos.getInstance(q);
5331
5332 if (lastPostDate != null) {
5333 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5334 }
5335
5336 qPos.add(priority);
5337
5338 count = (Long)q.uniqueResult();
5339
5340 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5341 }
5342 catch (Exception e) {
5343 FinderCacheUtil.removeResult(finderPath, finderArgs);
5344
5345 throw processException(e);
5346 }
5347 finally {
5348 closeSession(session);
5349 }
5350 }
5351
5352 return count.intValue();
5353 }
5354
5355 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
5356 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
5357 private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
5358 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5359 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5360 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
5361 new String[] {
5362 Long.class.getName(), Long.class.getName(), Date.class.getName(),
5363
5364 Integer.class.getName(), Integer.class.getName(),
5365 OrderByComparator.class.getName()
5366 });
5367 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5368 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5369 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
5370 new String[] {
5371 Long.class.getName(), Long.class.getName(), Date.class.getName()
5372 },
5373 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
5374 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
5375 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
5376 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
5377 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5378 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
5379 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
5380 new String[] {
5381 Long.class.getName(), Long.class.getName(), Date.class.getName()
5382 });
5383
5384
5393 public List<MBThread> findByG_C_L(long groupId, long categoryId,
5394 Date lastPostDate) throws SystemException {
5395 return findByG_C_L(groupId, categoryId, lastPostDate,
5396 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5397 }
5398
5399
5414 public List<MBThread> findByG_C_L(long groupId, long categoryId,
5415 Date lastPostDate, int start, int end) throws SystemException {
5416 return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
5417 }
5418
5419
5435 public List<MBThread> findByG_C_L(long groupId, long categoryId,
5436 Date lastPostDate, int start, int end,
5437 OrderByComparator orderByComparator) throws SystemException {
5438 boolean pagination = true;
5439 FinderPath finderPath = null;
5440 Object[] finderArgs = null;
5441
5442 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5443 (orderByComparator == null)) {
5444 pagination = false;
5445 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
5446 finderArgs = new Object[] { groupId, categoryId, lastPostDate };
5447 }
5448 else {
5449 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
5450 finderArgs = new Object[] {
5451 groupId, categoryId, lastPostDate,
5452
5453 start, end, orderByComparator
5454 };
5455 }
5456
5457 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5458 finderArgs, this);
5459
5460 if ((list != null) && !list.isEmpty()) {
5461 for (MBThread mbThread : list) {
5462 if ((groupId != mbThread.getGroupId()) ||
5463 (categoryId != mbThread.getCategoryId()) ||
5464 !Validator.equals(lastPostDate,
5465 mbThread.getLastPostDate())) {
5466 list = null;
5467
5468 break;
5469 }
5470 }
5471 }
5472
5473 if (list == null) {
5474 StringBundler query = null;
5475
5476 if (orderByComparator != null) {
5477 query = new StringBundler(5 +
5478 (orderByComparator.getOrderByFields().length * 3));
5479 }
5480 else {
5481 query = new StringBundler(5);
5482 }
5483
5484 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5485
5486 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5487
5488 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5489
5490 if (lastPostDate == null) {
5491 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5492 }
5493 else {
5494 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5495 }
5496
5497 if (orderByComparator != null) {
5498 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5499 orderByComparator);
5500 }
5501 else
5502 if (pagination) {
5503 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5504 }
5505
5506 String sql = query.toString();
5507
5508 Session session = null;
5509
5510 try {
5511 session = openSession();
5512
5513 Query q = session.createQuery(sql);
5514
5515 QueryPos qPos = QueryPos.getInstance(q);
5516
5517 qPos.add(groupId);
5518
5519 qPos.add(categoryId);
5520
5521 if (lastPostDate != null) {
5522 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5523 }
5524
5525 if (!pagination) {
5526 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5527 start, end, false);
5528
5529 Collections.sort(list);
5530
5531 list = new UnmodifiableList<MBThread>(list);
5532 }
5533 else {
5534 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5535 start, end);
5536 }
5537
5538 cacheResult(list);
5539
5540 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5541 }
5542 catch (Exception e) {
5543 FinderCacheUtil.removeResult(finderPath, finderArgs);
5544
5545 throw processException(e);
5546 }
5547 finally {
5548 closeSession(session);
5549 }
5550 }
5551
5552 return list;
5553 }
5554
5555
5566 public MBThread findByG_C_L_First(long groupId, long categoryId,
5567 Date lastPostDate, OrderByComparator orderByComparator)
5568 throws NoSuchThreadException, SystemException {
5569 MBThread mbThread = fetchByG_C_L_First(groupId, categoryId,
5570 lastPostDate, orderByComparator);
5571
5572 if (mbThread != null) {
5573 return mbThread;
5574 }
5575
5576 StringBundler msg = new StringBundler(8);
5577
5578 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5579
5580 msg.append("groupId=");
5581 msg.append(groupId);
5582
5583 msg.append(", categoryId=");
5584 msg.append(categoryId);
5585
5586 msg.append(", lastPostDate=");
5587 msg.append(lastPostDate);
5588
5589 msg.append(StringPool.CLOSE_CURLY_BRACE);
5590
5591 throw new NoSuchThreadException(msg.toString());
5592 }
5593
5594
5604 public MBThread fetchByG_C_L_First(long groupId, long categoryId,
5605 Date lastPostDate, OrderByComparator orderByComparator)
5606 throws SystemException {
5607 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
5608 1, orderByComparator);
5609
5610 if (!list.isEmpty()) {
5611 return list.get(0);
5612 }
5613
5614 return null;
5615 }
5616
5617
5628 public MBThread findByG_C_L_Last(long groupId, long categoryId,
5629 Date lastPostDate, OrderByComparator orderByComparator)
5630 throws NoSuchThreadException, SystemException {
5631 MBThread mbThread = fetchByG_C_L_Last(groupId, categoryId,
5632 lastPostDate, orderByComparator);
5633
5634 if (mbThread != null) {
5635 return mbThread;
5636 }
5637
5638 StringBundler msg = new StringBundler(8);
5639
5640 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5641
5642 msg.append("groupId=");
5643 msg.append(groupId);
5644
5645 msg.append(", categoryId=");
5646 msg.append(categoryId);
5647
5648 msg.append(", lastPostDate=");
5649 msg.append(lastPostDate);
5650
5651 msg.append(StringPool.CLOSE_CURLY_BRACE);
5652
5653 throw new NoSuchThreadException(msg.toString());
5654 }
5655
5656
5666 public MBThread fetchByG_C_L_Last(long groupId, long categoryId,
5667 Date lastPostDate, OrderByComparator orderByComparator)
5668 throws SystemException {
5669 int count = countByG_C_L(groupId, categoryId, lastPostDate);
5670
5671 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
5672 count - 1, count, orderByComparator);
5673
5674 if (!list.isEmpty()) {
5675 return list.get(0);
5676 }
5677
5678 return null;
5679 }
5680
5681
5693 public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
5694 long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
5695 throws NoSuchThreadException, SystemException {
5696 MBThread mbThread = findByPrimaryKey(threadId);
5697
5698 Session session = null;
5699
5700 try {
5701 session = openSession();
5702
5703 MBThread[] array = new MBThreadImpl[3];
5704
5705 array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5706 categoryId, lastPostDate, orderByComparator, true);
5707
5708 array[1] = mbThread;
5709
5710 array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
5711 categoryId, lastPostDate, orderByComparator, false);
5712
5713 return array;
5714 }
5715 catch (Exception e) {
5716 throw processException(e);
5717 }
5718 finally {
5719 closeSession(session);
5720 }
5721 }
5722
5723 protected MBThread getByG_C_L_PrevAndNext(Session session,
5724 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
5725 OrderByComparator orderByComparator, boolean previous) {
5726 StringBundler query = null;
5727
5728 if (orderByComparator != null) {
5729 query = new StringBundler(6 +
5730 (orderByComparator.getOrderByFields().length * 6));
5731 }
5732 else {
5733 query = new StringBundler(3);
5734 }
5735
5736 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5737
5738 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5739
5740 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5741
5742 if (lastPostDate == null) {
5743 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5744 }
5745 else {
5746 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5747 }
5748
5749 if (orderByComparator != null) {
5750 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5751
5752 if (orderByConditionFields.length > 0) {
5753 query.append(WHERE_AND);
5754 }
5755
5756 for (int i = 0; i < orderByConditionFields.length; i++) {
5757 query.append(_ORDER_BY_ENTITY_ALIAS);
5758 query.append(orderByConditionFields[i]);
5759
5760 if ((i + 1) < orderByConditionFields.length) {
5761 if (orderByComparator.isAscending() ^ previous) {
5762 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5763 }
5764 else {
5765 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5766 }
5767 }
5768 else {
5769 if (orderByComparator.isAscending() ^ previous) {
5770 query.append(WHERE_GREATER_THAN);
5771 }
5772 else {
5773 query.append(WHERE_LESSER_THAN);
5774 }
5775 }
5776 }
5777
5778 query.append(ORDER_BY_CLAUSE);
5779
5780 String[] orderByFields = orderByComparator.getOrderByFields();
5781
5782 for (int i = 0; i < orderByFields.length; i++) {
5783 query.append(_ORDER_BY_ENTITY_ALIAS);
5784 query.append(orderByFields[i]);
5785
5786 if ((i + 1) < orderByFields.length) {
5787 if (orderByComparator.isAscending() ^ previous) {
5788 query.append(ORDER_BY_ASC_HAS_NEXT);
5789 }
5790 else {
5791 query.append(ORDER_BY_DESC_HAS_NEXT);
5792 }
5793 }
5794 else {
5795 if (orderByComparator.isAscending() ^ previous) {
5796 query.append(ORDER_BY_ASC);
5797 }
5798 else {
5799 query.append(ORDER_BY_DESC);
5800 }
5801 }
5802 }
5803 }
5804 else {
5805 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5806 }
5807
5808 String sql = query.toString();
5809
5810 Query q = session.createQuery(sql);
5811
5812 q.setFirstResult(0);
5813 q.setMaxResults(2);
5814
5815 QueryPos qPos = QueryPos.getInstance(q);
5816
5817 qPos.add(groupId);
5818
5819 qPos.add(categoryId);
5820
5821 if (lastPostDate != null) {
5822 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5823 }
5824
5825 if (orderByComparator != null) {
5826 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5827
5828 for (Object value : values) {
5829 qPos.add(value);
5830 }
5831 }
5832
5833 List<MBThread> list = q.list();
5834
5835 if (list.size() == 2) {
5836 return list.get(1);
5837 }
5838 else {
5839 return null;
5840 }
5841 }
5842
5843
5852 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5853 Date lastPostDate) throws SystemException {
5854 return filterFindByG_C_L(groupId, categoryId, lastPostDate,
5855 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5856 }
5857
5858
5873 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5874 Date lastPostDate, int start, int end) throws SystemException {
5875 return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
5876 null);
5877 }
5878
5879
5895 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
5896 Date lastPostDate, int start, int end,
5897 OrderByComparator orderByComparator) throws SystemException {
5898 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5899 return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
5900 orderByComparator);
5901 }
5902
5903 StringBundler query = null;
5904
5905 if (orderByComparator != null) {
5906 query = new StringBundler(5 +
5907 (orderByComparator.getOrderByFields().length * 3));
5908 }
5909 else {
5910 query = new StringBundler(5);
5911 }
5912
5913 if (getDB().isSupportsInlineDistinct()) {
5914 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5915 }
5916 else {
5917 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5918 }
5919
5920 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
5921
5922 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
5923
5924 if (lastPostDate == null) {
5925 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
5926 }
5927 else {
5928 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
5929 }
5930
5931 if (!getDB().isSupportsInlineDistinct()) {
5932 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5933 }
5934
5935 if (orderByComparator != null) {
5936 if (getDB().isSupportsInlineDistinct()) {
5937 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5938 orderByComparator);
5939 }
5940 else {
5941 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5942 orderByComparator);
5943 }
5944 }
5945 else {
5946 if (getDB().isSupportsInlineDistinct()) {
5947 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5948 }
5949 else {
5950 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5951 }
5952 }
5953
5954 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5955 MBThread.class.getName(),
5956 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5957
5958 Session session = null;
5959
5960 try {
5961 session = openSession();
5962
5963 SQLQuery q = session.createSQLQuery(sql);
5964
5965 if (getDB().isSupportsInlineDistinct()) {
5966 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5967 }
5968 else {
5969 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5970 }
5971
5972 QueryPos qPos = QueryPos.getInstance(q);
5973
5974 qPos.add(groupId);
5975
5976 qPos.add(categoryId);
5977
5978 if (lastPostDate != null) {
5979 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
5980 }
5981
5982 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5983 }
5984 catch (Exception e) {
5985 throw processException(e);
5986 }
5987 finally {
5988 closeSession(session);
5989 }
5990 }
5991
5992
6004 public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
6005 long groupId, long categoryId, Date lastPostDate,
6006 OrderByComparator orderByComparator)
6007 throws NoSuchThreadException, SystemException {
6008 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6009 return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
6010 lastPostDate, orderByComparator);
6011 }
6012
6013 MBThread mbThread = findByPrimaryKey(threadId);
6014
6015 Session session = null;
6016
6017 try {
6018 session = openSession();
6019
6020 MBThread[] array = new MBThreadImpl[3];
6021
6022 array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
6023 categoryId, lastPostDate, orderByComparator, true);
6024
6025 array[1] = mbThread;
6026
6027 array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
6028 categoryId, lastPostDate, orderByComparator, false);
6029
6030 return array;
6031 }
6032 catch (Exception e) {
6033 throw processException(e);
6034 }
6035 finally {
6036 closeSession(session);
6037 }
6038 }
6039
6040 protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
6041 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
6042 OrderByComparator orderByComparator, boolean previous) {
6043 StringBundler query = null;
6044
6045 if (orderByComparator != null) {
6046 query = new StringBundler(6 +
6047 (orderByComparator.getOrderByFields().length * 6));
6048 }
6049 else {
6050 query = new StringBundler(3);
6051 }
6052
6053 if (getDB().isSupportsInlineDistinct()) {
6054 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6055 }
6056 else {
6057 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6058 }
6059
6060 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6061
6062 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6063
6064 if (lastPostDate == null) {
6065 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6066 }
6067 else {
6068 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
6069 }
6070
6071 if (!getDB().isSupportsInlineDistinct()) {
6072 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6073 }
6074
6075 if (orderByComparator != null) {
6076 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6077
6078 if (orderByConditionFields.length > 0) {
6079 query.append(WHERE_AND);
6080 }
6081
6082 for (int i = 0; i < orderByConditionFields.length; i++) {
6083 if (getDB().isSupportsInlineDistinct()) {
6084 query.append(_ORDER_BY_ENTITY_ALIAS);
6085 }
6086 else {
6087 query.append(_ORDER_BY_ENTITY_TABLE);
6088 }
6089
6090 query.append(orderByConditionFields[i]);
6091
6092 if ((i + 1) < orderByConditionFields.length) {
6093 if (orderByComparator.isAscending() ^ previous) {
6094 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6095 }
6096 else {
6097 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6098 }
6099 }
6100 else {
6101 if (orderByComparator.isAscending() ^ previous) {
6102 query.append(WHERE_GREATER_THAN);
6103 }
6104 else {
6105 query.append(WHERE_LESSER_THAN);
6106 }
6107 }
6108 }
6109
6110 query.append(ORDER_BY_CLAUSE);
6111
6112 String[] orderByFields = orderByComparator.getOrderByFields();
6113
6114 for (int i = 0; i < orderByFields.length; i++) {
6115 if (getDB().isSupportsInlineDistinct()) {
6116 query.append(_ORDER_BY_ENTITY_ALIAS);
6117 }
6118 else {
6119 query.append(_ORDER_BY_ENTITY_TABLE);
6120 }
6121
6122 query.append(orderByFields[i]);
6123
6124 if ((i + 1) < orderByFields.length) {
6125 if (orderByComparator.isAscending() ^ previous) {
6126 query.append(ORDER_BY_ASC_HAS_NEXT);
6127 }
6128 else {
6129 query.append(ORDER_BY_DESC_HAS_NEXT);
6130 }
6131 }
6132 else {
6133 if (orderByComparator.isAscending() ^ previous) {
6134 query.append(ORDER_BY_ASC);
6135 }
6136 else {
6137 query.append(ORDER_BY_DESC);
6138 }
6139 }
6140 }
6141 }
6142 else {
6143 if (getDB().isSupportsInlineDistinct()) {
6144 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6145 }
6146 else {
6147 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6148 }
6149 }
6150
6151 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6152 MBThread.class.getName(),
6153 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6154
6155 SQLQuery q = session.createSQLQuery(sql);
6156
6157 q.setFirstResult(0);
6158 q.setMaxResults(2);
6159
6160 if (getDB().isSupportsInlineDistinct()) {
6161 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6162 }
6163 else {
6164 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6165 }
6166
6167 QueryPos qPos = QueryPos.getInstance(q);
6168
6169 qPos.add(groupId);
6170
6171 qPos.add(categoryId);
6172
6173 if (lastPostDate != null) {
6174 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6175 }
6176
6177 if (orderByComparator != null) {
6178 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6179
6180 for (Object value : values) {
6181 qPos.add(value);
6182 }
6183 }
6184
6185 List<MBThread> list = q.list();
6186
6187 if (list.size() == 2) {
6188 return list.get(1);
6189 }
6190 else {
6191 return null;
6192 }
6193 }
6194
6195
6203 public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
6204 throws SystemException {
6205 for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate,
6206 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6207 remove(mbThread);
6208 }
6209 }
6210
6211
6220 public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
6221 throws SystemException {
6222 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_L;
6223
6224 Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
6225
6226 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6227 this);
6228
6229 if (count == null) {
6230 StringBundler query = new StringBundler(4);
6231
6232 query.append(_SQL_COUNT_MBTHREAD_WHERE);
6233
6234 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6235
6236 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6237
6238 if (lastPostDate == null) {
6239 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6240 }
6241 else {
6242 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
6243 }
6244
6245 String sql = query.toString();
6246
6247 Session session = null;
6248
6249 try {
6250 session = openSession();
6251
6252 Query q = session.createQuery(sql);
6253
6254 QueryPos qPos = QueryPos.getInstance(q);
6255
6256 qPos.add(groupId);
6257
6258 qPos.add(categoryId);
6259
6260 if (lastPostDate != null) {
6261 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6262 }
6263
6264 count = (Long)q.uniqueResult();
6265
6266 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6267 }
6268 catch (Exception e) {
6269 FinderCacheUtil.removeResult(finderPath, finderArgs);
6270
6271 throw processException(e);
6272 }
6273 finally {
6274 closeSession(session);
6275 }
6276 }
6277
6278 return count.intValue();
6279 }
6280
6281
6290 public int filterCountByG_C_L(long groupId, long categoryId,
6291 Date lastPostDate) throws SystemException {
6292 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6293 return countByG_C_L(groupId, categoryId, lastPostDate);
6294 }
6295
6296 StringBundler query = new StringBundler(4);
6297
6298 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
6299
6300 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6301
6302 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6303
6304 if (lastPostDate == null) {
6305 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6306 }
6307 else {
6308 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
6309 }
6310
6311 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6312 MBThread.class.getName(),
6313 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6314
6315 Session session = null;
6316
6317 try {
6318 session = openSession();
6319
6320 SQLQuery q = session.createSQLQuery(sql);
6321
6322 q.addScalar(COUNT_COLUMN_NAME,
6323 com.liferay.portal.kernel.dao.orm.Type.LONG);
6324
6325 QueryPos qPos = QueryPos.getInstance(q);
6326
6327 qPos.add(groupId);
6328
6329 qPos.add(categoryId);
6330
6331 if (lastPostDate != null) {
6332 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6333 }
6334
6335 Long count = (Long)q.uniqueResult();
6336
6337 return count.intValue();
6338 }
6339 catch (Exception e) {
6340 throw processException(e);
6341 }
6342 finally {
6343 closeSession(session);
6344 }
6345 }
6346
6347 private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
6348 private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
6349 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
6350 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
6351 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6352 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6353 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
6354 new String[] {
6355 Long.class.getName(), Long.class.getName(),
6356 Integer.class.getName(),
6357
6358 Integer.class.getName(), Integer.class.getName(),
6359 OrderByComparator.class.getName()
6360 });
6361 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6362 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6363 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
6364 new String[] {
6365 Long.class.getName(), Long.class.getName(),
6366 Integer.class.getName()
6367 },
6368 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
6369 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
6370 MBThreadModelImpl.STATUS_COLUMN_BITMASK |
6371 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
6372 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
6373 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6374 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6375 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
6376 new String[] {
6377 Long.class.getName(), Long.class.getName(),
6378 Integer.class.getName()
6379 });
6380 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6381 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6382 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
6383 new String[] {
6384 Long.class.getName(), Long.class.getName(),
6385 Integer.class.getName()
6386 });
6387
6388
6397 public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
6398 throws SystemException {
6399 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
6400 QueryUtil.ALL_POS, null);
6401 }
6402
6403
6418 public List<MBThread> findByG_C_S(long groupId, long categoryId,
6419 int status, int start, int end) throws SystemException {
6420 return findByG_C_S(groupId, categoryId, status, start, end, null);
6421 }
6422
6423
6439 public List<MBThread> findByG_C_S(long groupId, long categoryId,
6440 int status, int start, int end, OrderByComparator orderByComparator)
6441 throws SystemException {
6442 boolean pagination = true;
6443 FinderPath finderPath = null;
6444 Object[] finderArgs = null;
6445
6446 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6447 (orderByComparator == null)) {
6448 pagination = false;
6449 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
6450 finderArgs = new Object[] { groupId, categoryId, status };
6451 }
6452 else {
6453 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
6454 finderArgs = new Object[] {
6455 groupId, categoryId, status,
6456
6457 start, end, orderByComparator
6458 };
6459 }
6460
6461 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6462 finderArgs, this);
6463
6464 if ((list != null) && !list.isEmpty()) {
6465 for (MBThread mbThread : list) {
6466 if ((groupId != mbThread.getGroupId()) ||
6467 (categoryId != mbThread.getCategoryId()) ||
6468 (status != mbThread.getStatus())) {
6469 list = null;
6470
6471 break;
6472 }
6473 }
6474 }
6475
6476 if (list == null) {
6477 StringBundler query = null;
6478
6479 if (orderByComparator != null) {
6480 query = new StringBundler(5 +
6481 (orderByComparator.getOrderByFields().length * 3));
6482 }
6483 else {
6484 query = new StringBundler(5);
6485 }
6486
6487 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6488
6489 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6490
6491 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6492
6493 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6494
6495 if (orderByComparator != null) {
6496 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6497 orderByComparator);
6498 }
6499 else
6500 if (pagination) {
6501 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6502 }
6503
6504 String sql = query.toString();
6505
6506 Session session = null;
6507
6508 try {
6509 session = openSession();
6510
6511 Query q = session.createQuery(sql);
6512
6513 QueryPos qPos = QueryPos.getInstance(q);
6514
6515 qPos.add(groupId);
6516
6517 qPos.add(categoryId);
6518
6519 qPos.add(status);
6520
6521 if (!pagination) {
6522 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6523 start, end, false);
6524
6525 Collections.sort(list);
6526
6527 list = new UnmodifiableList<MBThread>(list);
6528 }
6529 else {
6530 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6531 start, end);
6532 }
6533
6534 cacheResult(list);
6535
6536 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6537 }
6538 catch (Exception e) {
6539 FinderCacheUtil.removeResult(finderPath, finderArgs);
6540
6541 throw processException(e);
6542 }
6543 finally {
6544 closeSession(session);
6545 }
6546 }
6547
6548 return list;
6549 }
6550
6551
6562 public MBThread findByG_C_S_First(long groupId, long categoryId,
6563 int status, OrderByComparator orderByComparator)
6564 throws NoSuchThreadException, SystemException {
6565 MBThread mbThread = fetchByG_C_S_First(groupId, categoryId, status,
6566 orderByComparator);
6567
6568 if (mbThread != null) {
6569 return mbThread;
6570 }
6571
6572 StringBundler msg = new StringBundler(8);
6573
6574 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6575
6576 msg.append("groupId=");
6577 msg.append(groupId);
6578
6579 msg.append(", categoryId=");
6580 msg.append(categoryId);
6581
6582 msg.append(", status=");
6583 msg.append(status);
6584
6585 msg.append(StringPool.CLOSE_CURLY_BRACE);
6586
6587 throw new NoSuchThreadException(msg.toString());
6588 }
6589
6590
6600 public MBThread fetchByG_C_S_First(long groupId, long categoryId,
6601 int status, OrderByComparator orderByComparator)
6602 throws SystemException {
6603 List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
6604 orderByComparator);
6605
6606 if (!list.isEmpty()) {
6607 return list.get(0);
6608 }
6609
6610 return null;
6611 }
6612
6613
6624 public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
6625 OrderByComparator orderByComparator)
6626 throws NoSuchThreadException, SystemException {
6627 MBThread mbThread = fetchByG_C_S_Last(groupId, categoryId, status,
6628 orderByComparator);
6629
6630 if (mbThread != null) {
6631 return mbThread;
6632 }
6633
6634 StringBundler msg = new StringBundler(8);
6635
6636 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6637
6638 msg.append("groupId=");
6639 msg.append(groupId);
6640
6641 msg.append(", categoryId=");
6642 msg.append(categoryId);
6643
6644 msg.append(", status=");
6645 msg.append(status);
6646
6647 msg.append(StringPool.CLOSE_CURLY_BRACE);
6648
6649 throw new NoSuchThreadException(msg.toString());
6650 }
6651
6652
6662 public MBThread fetchByG_C_S_Last(long groupId, long categoryId,
6663 int status, OrderByComparator orderByComparator)
6664 throws SystemException {
6665 int count = countByG_C_S(groupId, categoryId, status);
6666
6667 List<MBThread> list = findByG_C_S(groupId, categoryId, status,
6668 count - 1, count, orderByComparator);
6669
6670 if (!list.isEmpty()) {
6671 return list.get(0);
6672 }
6673
6674 return null;
6675 }
6676
6677
6689 public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
6690 long categoryId, int status, OrderByComparator orderByComparator)
6691 throws NoSuchThreadException, SystemException {
6692 MBThread mbThread = findByPrimaryKey(threadId);
6693
6694 Session session = null;
6695
6696 try {
6697 session = openSession();
6698
6699 MBThread[] array = new MBThreadImpl[3];
6700
6701 array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
6702 categoryId, status, orderByComparator, true);
6703
6704 array[1] = mbThread;
6705
6706 array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
6707 categoryId, status, orderByComparator, false);
6708
6709 return array;
6710 }
6711 catch (Exception e) {
6712 throw processException(e);
6713 }
6714 finally {
6715 closeSession(session);
6716 }
6717 }
6718
6719 protected MBThread getByG_C_S_PrevAndNext(Session session,
6720 MBThread mbThread, long groupId, long categoryId, int status,
6721 OrderByComparator orderByComparator, boolean previous) {
6722 StringBundler query = null;
6723
6724 if (orderByComparator != null) {
6725 query = new StringBundler(6 +
6726 (orderByComparator.getOrderByFields().length * 6));
6727 }
6728 else {
6729 query = new StringBundler(3);
6730 }
6731
6732 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6733
6734 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6735
6736 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6737
6738 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6739
6740 if (orderByComparator != null) {
6741 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6742
6743 if (orderByConditionFields.length > 0) {
6744 query.append(WHERE_AND);
6745 }
6746
6747 for (int i = 0; i < orderByConditionFields.length; i++) {
6748 query.append(_ORDER_BY_ENTITY_ALIAS);
6749 query.append(orderByConditionFields[i]);
6750
6751 if ((i + 1) < orderByConditionFields.length) {
6752 if (orderByComparator.isAscending() ^ previous) {
6753 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6754 }
6755 else {
6756 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6757 }
6758 }
6759 else {
6760 if (orderByComparator.isAscending() ^ previous) {
6761 query.append(WHERE_GREATER_THAN);
6762 }
6763 else {
6764 query.append(WHERE_LESSER_THAN);
6765 }
6766 }
6767 }
6768
6769 query.append(ORDER_BY_CLAUSE);
6770
6771 String[] orderByFields = orderByComparator.getOrderByFields();
6772
6773 for (int i = 0; i < orderByFields.length; i++) {
6774 query.append(_ORDER_BY_ENTITY_ALIAS);
6775 query.append(orderByFields[i]);
6776
6777 if ((i + 1) < orderByFields.length) {
6778 if (orderByComparator.isAscending() ^ previous) {
6779 query.append(ORDER_BY_ASC_HAS_NEXT);
6780 }
6781 else {
6782 query.append(ORDER_BY_DESC_HAS_NEXT);
6783 }
6784 }
6785 else {
6786 if (orderByComparator.isAscending() ^ previous) {
6787 query.append(ORDER_BY_ASC);
6788 }
6789 else {
6790 query.append(ORDER_BY_DESC);
6791 }
6792 }
6793 }
6794 }
6795 else {
6796 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6797 }
6798
6799 String sql = query.toString();
6800
6801 Query q = session.createQuery(sql);
6802
6803 q.setFirstResult(0);
6804 q.setMaxResults(2);
6805
6806 QueryPos qPos = QueryPos.getInstance(q);
6807
6808 qPos.add(groupId);
6809
6810 qPos.add(categoryId);
6811
6812 qPos.add(status);
6813
6814 if (orderByComparator != null) {
6815 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6816
6817 for (Object value : values) {
6818 qPos.add(value);
6819 }
6820 }
6821
6822 List<MBThread> list = q.list();
6823
6824 if (list.size() == 2) {
6825 return list.get(1);
6826 }
6827 else {
6828 return null;
6829 }
6830 }
6831
6832
6841 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6842 int status) throws SystemException {
6843 return filterFindByG_C_S(groupId, categoryId, status,
6844 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6845 }
6846
6847
6862 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6863 int status, int start, int end) throws SystemException {
6864 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
6865 }
6866
6867
6883 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
6884 int status, int start, int end, OrderByComparator orderByComparator)
6885 throws SystemException {
6886 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6887 return findByG_C_S(groupId, categoryId, status, start, end,
6888 orderByComparator);
6889 }
6890
6891 StringBundler query = null;
6892
6893 if (orderByComparator != null) {
6894 query = new StringBundler(5 +
6895 (orderByComparator.getOrderByFields().length * 3));
6896 }
6897 else {
6898 query = new StringBundler(5);
6899 }
6900
6901 if (getDB().isSupportsInlineDistinct()) {
6902 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
6903 }
6904 else {
6905 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
6906 }
6907
6908 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
6909
6910 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
6911
6912 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
6913
6914 if (!getDB().isSupportsInlineDistinct()) {
6915 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
6916 }
6917
6918 if (orderByComparator != null) {
6919 if (getDB().isSupportsInlineDistinct()) {
6920 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6921 orderByComparator);
6922 }
6923 else {
6924 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6925 orderByComparator);
6926 }
6927 }
6928 else {
6929 if (getDB().isSupportsInlineDistinct()) {
6930 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6931 }
6932 else {
6933 query.append(MBThreadModelImpl.ORDER_BY_SQL);
6934 }
6935 }
6936
6937 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6938 MBThread.class.getName(),
6939 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6940
6941 Session session = null;
6942
6943 try {
6944 session = openSession();
6945
6946 SQLQuery q = session.createSQLQuery(sql);
6947
6948 if (getDB().isSupportsInlineDistinct()) {
6949 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
6950 }
6951 else {
6952 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
6953 }
6954
6955 QueryPos qPos = QueryPos.getInstance(q);
6956
6957 qPos.add(groupId);
6958
6959 qPos.add(categoryId);
6960
6961 qPos.add(status);
6962
6963 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
6964 }
6965 catch (Exception e) {
6966 throw processException(e);
6967 }
6968 finally {
6969 closeSession(session);
6970 }
6971 }
6972
6973
6985 public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
6986 long groupId, long categoryId, int status,
6987 OrderByComparator orderByComparator)
6988 throws NoSuchThreadException, SystemException {
6989 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6990 return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
6991 status, orderByComparator);
6992 }
6993
6994 MBThread mbThread = findByPrimaryKey(threadId);
6995
6996 Session session = null;
6997
6998 try {
6999 session = openSession();
7000
7001 MBThread[] array = new MBThreadImpl[3];
7002
7003 array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
7004 categoryId, status, orderByComparator, true);
7005
7006 array[1] = mbThread;
7007
7008 array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
7009 categoryId, status, orderByComparator, false);
7010
7011 return array;
7012 }
7013 catch (Exception e) {
7014 throw processException(e);
7015 }
7016 finally {
7017 closeSession(session);
7018 }
7019 }
7020
7021 protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
7022 MBThread mbThread, long groupId, long categoryId, int status,
7023 OrderByComparator orderByComparator, boolean previous) {
7024 StringBundler query = null;
7025
7026 if (orderByComparator != null) {
7027 query = new StringBundler(6 +
7028 (orderByComparator.getOrderByFields().length * 6));
7029 }
7030 else {
7031 query = new StringBundler(3);
7032 }
7033
7034 if (getDB().isSupportsInlineDistinct()) {
7035 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7036 }
7037 else {
7038 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7039 }
7040
7041 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7042
7043 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7044
7045 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7046
7047 if (!getDB().isSupportsInlineDistinct()) {
7048 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7049 }
7050
7051 if (orderByComparator != null) {
7052 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7053
7054 if (orderByConditionFields.length > 0) {
7055 query.append(WHERE_AND);
7056 }
7057
7058 for (int i = 0; i < orderByConditionFields.length; i++) {
7059 if (getDB().isSupportsInlineDistinct()) {
7060 query.append(_ORDER_BY_ENTITY_ALIAS);
7061 }
7062 else {
7063 query.append(_ORDER_BY_ENTITY_TABLE);
7064 }
7065
7066 query.append(orderByConditionFields[i]);
7067
7068 if ((i + 1) < orderByConditionFields.length) {
7069 if (orderByComparator.isAscending() ^ previous) {
7070 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7071 }
7072 else {
7073 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7074 }
7075 }
7076 else {
7077 if (orderByComparator.isAscending() ^ previous) {
7078 query.append(WHERE_GREATER_THAN);
7079 }
7080 else {
7081 query.append(WHERE_LESSER_THAN);
7082 }
7083 }
7084 }
7085
7086 query.append(ORDER_BY_CLAUSE);
7087
7088 String[] orderByFields = orderByComparator.getOrderByFields();
7089
7090 for (int i = 0; i < orderByFields.length; i++) {
7091 if (getDB().isSupportsInlineDistinct()) {
7092 query.append(_ORDER_BY_ENTITY_ALIAS);
7093 }
7094 else {
7095 query.append(_ORDER_BY_ENTITY_TABLE);
7096 }
7097
7098 query.append(orderByFields[i]);
7099
7100 if ((i + 1) < orderByFields.length) {
7101 if (orderByComparator.isAscending() ^ previous) {
7102 query.append(ORDER_BY_ASC_HAS_NEXT);
7103 }
7104 else {
7105 query.append(ORDER_BY_DESC_HAS_NEXT);
7106 }
7107 }
7108 else {
7109 if (orderByComparator.isAscending() ^ previous) {
7110 query.append(ORDER_BY_ASC);
7111 }
7112 else {
7113 query.append(ORDER_BY_DESC);
7114 }
7115 }
7116 }
7117 }
7118 else {
7119 if (getDB().isSupportsInlineDistinct()) {
7120 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7121 }
7122 else {
7123 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7124 }
7125 }
7126
7127 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7128 MBThread.class.getName(),
7129 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7130
7131 SQLQuery q = session.createSQLQuery(sql);
7132
7133 q.setFirstResult(0);
7134 q.setMaxResults(2);
7135
7136 if (getDB().isSupportsInlineDistinct()) {
7137 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7138 }
7139 else {
7140 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7141 }
7142
7143 QueryPos qPos = QueryPos.getInstance(q);
7144
7145 qPos.add(groupId);
7146
7147 qPos.add(categoryId);
7148
7149 qPos.add(status);
7150
7151 if (orderByComparator != null) {
7152 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7153
7154 for (Object value : values) {
7155 qPos.add(value);
7156 }
7157 }
7158
7159 List<MBThread> list = q.list();
7160
7161 if (list.size() == 2) {
7162 return list.get(1);
7163 }
7164 else {
7165 return null;
7166 }
7167 }
7168
7169
7178 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
7179 int status) throws SystemException {
7180 return filterFindByG_C_S(groupId, categoryIds, status,
7181 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7182 }
7183
7184
7199 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
7200 int status, int start, int end) throws SystemException {
7201 return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
7202 }
7203
7204
7220 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
7221 int status, int start, int end, OrderByComparator orderByComparator)
7222 throws SystemException {
7223 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7224 return findByG_C_S(groupId, categoryIds, status, start, end,
7225 orderByComparator);
7226 }
7227
7228 StringBundler query = new StringBundler();
7229
7230 if (getDB().isSupportsInlineDistinct()) {
7231 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7232 }
7233 else {
7234 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7235 }
7236
7237 boolean conjunctionable = false;
7238
7239 if (conjunctionable) {
7240 query.append(WHERE_AND);
7241 }
7242
7243 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
7244
7245 conjunctionable = true;
7246
7247 if ((categoryIds == null) || (categoryIds.length > 0)) {
7248 if (conjunctionable) {
7249 query.append(WHERE_AND);
7250 }
7251
7252 query.append(StringPool.OPEN_PARENTHESIS);
7253
7254 for (int i = 0; i < categoryIds.length; i++) {
7255 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
7256
7257 if ((i + 1) < categoryIds.length) {
7258 query.append(WHERE_OR);
7259 }
7260 }
7261
7262 query.append(StringPool.CLOSE_PARENTHESIS);
7263
7264 conjunctionable = true;
7265 }
7266
7267 if (conjunctionable) {
7268 query.append(WHERE_AND);
7269 }
7270
7271 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
7272
7273 conjunctionable = true;
7274
7275 if (!getDB().isSupportsInlineDistinct()) {
7276 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7277 }
7278
7279 if (orderByComparator != null) {
7280 if (getDB().isSupportsInlineDistinct()) {
7281 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7282 orderByComparator);
7283 }
7284 else {
7285 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7286 orderByComparator);
7287 }
7288 }
7289 else {
7290 if (getDB().isSupportsInlineDistinct()) {
7291 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7292 }
7293 else {
7294 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7295 }
7296 }
7297
7298 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7299 MBThread.class.getName(),
7300 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7301
7302 Session session = null;
7303
7304 try {
7305 session = openSession();
7306
7307 SQLQuery q = session.createSQLQuery(sql);
7308
7309 if (getDB().isSupportsInlineDistinct()) {
7310 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7311 }
7312 else {
7313 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7314 }
7315
7316 QueryPos qPos = QueryPos.getInstance(q);
7317
7318 qPos.add(groupId);
7319
7320 if (categoryIds != null) {
7321 qPos.add(categoryIds);
7322 }
7323
7324 qPos.add(status);
7325
7326 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7327 }
7328 catch (Exception e) {
7329 throw processException(e);
7330 }
7331 finally {
7332 closeSession(session);
7333 }
7334 }
7335
7336
7349 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
7350 int status) throws SystemException {
7351 return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
7352 QueryUtil.ALL_POS, null);
7353 }
7354
7355
7370 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
7371 int status, int start, int end) throws SystemException {
7372 return findByG_C_S(groupId, categoryIds, status, start, end, null);
7373 }
7374
7375
7391 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
7392 int status, int start, int end, OrderByComparator orderByComparator)
7393 throws SystemException {
7394 if ((categoryIds != null) && (categoryIds.length == 1)) {
7395 return findByG_C_S(groupId, categoryIds[0], status, start, end,
7396 orderByComparator);
7397 }
7398
7399 boolean pagination = true;
7400 Object[] finderArgs = null;
7401
7402 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7403 (orderByComparator == null)) {
7404 pagination = false;
7405 finderArgs = new Object[] {
7406 groupId, StringUtil.merge(categoryIds), status
7407 };
7408 }
7409 else {
7410 finderArgs = new Object[] {
7411 groupId, StringUtil.merge(categoryIds), status,
7412
7413 start, end, orderByComparator
7414 };
7415 }
7416
7417 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
7418 finderArgs, this);
7419
7420 if ((list != null) && !list.isEmpty()) {
7421 for (MBThread mbThread : list) {
7422 if ((groupId != mbThread.getGroupId()) ||
7423 !ArrayUtil.contains(categoryIds,
7424 mbThread.getCategoryId()) ||
7425 (status != mbThread.getStatus())) {
7426 list = null;
7427
7428 break;
7429 }
7430 }
7431 }
7432
7433 if (list == null) {
7434 StringBundler query = new StringBundler();
7435
7436 query.append(_SQL_SELECT_MBTHREAD_WHERE);
7437
7438 boolean conjunctionable = false;
7439
7440 if (conjunctionable) {
7441 query.append(WHERE_AND);
7442 }
7443
7444 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
7445
7446 conjunctionable = true;
7447
7448 if ((categoryIds == null) || (categoryIds.length > 0)) {
7449 if (conjunctionable) {
7450 query.append(WHERE_AND);
7451 }
7452
7453 query.append(StringPool.OPEN_PARENTHESIS);
7454
7455 for (int i = 0; i < categoryIds.length; i++) {
7456 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
7457
7458 if ((i + 1) < categoryIds.length) {
7459 query.append(WHERE_OR);
7460 }
7461 }
7462
7463 query.append(StringPool.CLOSE_PARENTHESIS);
7464
7465 conjunctionable = true;
7466 }
7467
7468 if (conjunctionable) {
7469 query.append(WHERE_AND);
7470 }
7471
7472 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
7473
7474 conjunctionable = true;
7475
7476 if (orderByComparator != null) {
7477 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7478 orderByComparator);
7479 }
7480 else
7481 if (pagination) {
7482 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7483 }
7484
7485 String sql = query.toString();
7486
7487 Session session = null;
7488
7489 try {
7490 session = openSession();
7491
7492 Query q = session.createQuery(sql);
7493
7494 QueryPos qPos = QueryPos.getInstance(q);
7495
7496 qPos.add(groupId);
7497
7498 if (categoryIds != null) {
7499 qPos.add(categoryIds);
7500 }
7501
7502 qPos.add(status);
7503
7504 if (!pagination) {
7505 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7506 start, end, false);
7507
7508 Collections.sort(list);
7509
7510 list = new UnmodifiableList<MBThread>(list);
7511 }
7512 else {
7513 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7514 start, end);
7515 }
7516
7517 cacheResult(list);
7518
7519 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
7520 finderArgs, list);
7521 }
7522 catch (Exception e) {
7523 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
7524 finderArgs);
7525
7526 throw processException(e);
7527 }
7528 finally {
7529 closeSession(session);
7530 }
7531 }
7532
7533 return list;
7534 }
7535
7536
7544 public void removeByG_C_S(long groupId, long categoryId, int status)
7545 throws SystemException {
7546 for (MBThread mbThread : findByG_C_S(groupId, categoryId, status,
7547 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7548 remove(mbThread);
7549 }
7550 }
7551
7552
7561 public int countByG_C_S(long groupId, long categoryId, int status)
7562 throws SystemException {
7563 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
7564
7565 Object[] finderArgs = new Object[] { groupId, categoryId, status };
7566
7567 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7568 this);
7569
7570 if (count == null) {
7571 StringBundler query = new StringBundler(4);
7572
7573 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7574
7575 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7576
7577 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7578
7579 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7580
7581 String sql = query.toString();
7582
7583 Session session = null;
7584
7585 try {
7586 session = openSession();
7587
7588 Query q = session.createQuery(sql);
7589
7590 QueryPos qPos = QueryPos.getInstance(q);
7591
7592 qPos.add(groupId);
7593
7594 qPos.add(categoryId);
7595
7596 qPos.add(status);
7597
7598 count = (Long)q.uniqueResult();
7599
7600 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7601 }
7602 catch (Exception e) {
7603 FinderCacheUtil.removeResult(finderPath, finderArgs);
7604
7605 throw processException(e);
7606 }
7607 finally {
7608 closeSession(session);
7609 }
7610 }
7611
7612 return count.intValue();
7613 }
7614
7615
7624 public int countByG_C_S(long groupId, long[] categoryIds, int status)
7625 throws SystemException {
7626 Object[] finderArgs = new Object[] {
7627 groupId, StringUtil.merge(categoryIds), status
7628 };
7629
7630 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
7631 finderArgs, this);
7632
7633 if (count == null) {
7634 StringBundler query = new StringBundler();
7635
7636 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7637
7638 boolean conjunctionable = false;
7639
7640 if (conjunctionable) {
7641 query.append(WHERE_AND);
7642 }
7643
7644 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
7645
7646 conjunctionable = true;
7647
7648 if ((categoryIds == null) || (categoryIds.length > 0)) {
7649 if (conjunctionable) {
7650 query.append(WHERE_AND);
7651 }
7652
7653 query.append(StringPool.OPEN_PARENTHESIS);
7654
7655 for (int i = 0; i < categoryIds.length; i++) {
7656 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
7657
7658 if ((i + 1) < categoryIds.length) {
7659 query.append(WHERE_OR);
7660 }
7661 }
7662
7663 query.append(StringPool.CLOSE_PARENTHESIS);
7664
7665 conjunctionable = true;
7666 }
7667
7668 if (conjunctionable) {
7669 query.append(WHERE_AND);
7670 }
7671
7672 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
7673
7674 conjunctionable = true;
7675
7676 String sql = query.toString();
7677
7678 Session session = null;
7679
7680 try {
7681 session = openSession();
7682
7683 Query q = session.createQuery(sql);
7684
7685 QueryPos qPos = QueryPos.getInstance(q);
7686
7687 qPos.add(groupId);
7688
7689 if (categoryIds != null) {
7690 qPos.add(categoryIds);
7691 }
7692
7693 qPos.add(status);
7694
7695 count = (Long)q.uniqueResult();
7696
7697 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
7698 finderArgs, count);
7699 }
7700 catch (Exception e) {
7701 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
7702 finderArgs);
7703
7704 throw processException(e);
7705 }
7706 finally {
7707 closeSession(session);
7708 }
7709 }
7710
7711 return count.intValue();
7712 }
7713
7714
7723 public int filterCountByG_C_S(long groupId, long categoryId, int status)
7724 throws SystemException {
7725 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7726 return countByG_C_S(groupId, categoryId, status);
7727 }
7728
7729 StringBundler query = new StringBundler(4);
7730
7731 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7732
7733 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7734
7735 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7736
7737 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7738
7739 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7740 MBThread.class.getName(),
7741 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7742
7743 Session session = null;
7744
7745 try {
7746 session = openSession();
7747
7748 SQLQuery q = session.createSQLQuery(sql);
7749
7750 q.addScalar(COUNT_COLUMN_NAME,
7751 com.liferay.portal.kernel.dao.orm.Type.LONG);
7752
7753 QueryPos qPos = QueryPos.getInstance(q);
7754
7755 qPos.add(groupId);
7756
7757 qPos.add(categoryId);
7758
7759 qPos.add(status);
7760
7761 Long count = (Long)q.uniqueResult();
7762
7763 return count.intValue();
7764 }
7765 catch (Exception e) {
7766 throw processException(e);
7767 }
7768 finally {
7769 closeSession(session);
7770 }
7771 }
7772
7773
7782 public int filterCountByG_C_S(long groupId, long[] categoryIds, int status)
7783 throws SystemException {
7784 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7785 return countByG_C_S(groupId, categoryIds, status);
7786 }
7787
7788 StringBundler query = new StringBundler();
7789
7790 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7791
7792 boolean conjunctionable = false;
7793
7794 if (conjunctionable) {
7795 query.append(WHERE_AND);
7796 }
7797
7798 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
7799
7800 conjunctionable = true;
7801
7802 if ((categoryIds == null) || (categoryIds.length > 0)) {
7803 if (conjunctionable) {
7804 query.append(WHERE_AND);
7805 }
7806
7807 query.append(StringPool.OPEN_PARENTHESIS);
7808
7809 for (int i = 0; i < categoryIds.length; i++) {
7810 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
7811
7812 if ((i + 1) < categoryIds.length) {
7813 query.append(WHERE_OR);
7814 }
7815 }
7816
7817 query.append(StringPool.CLOSE_PARENTHESIS);
7818
7819 conjunctionable = true;
7820 }
7821
7822 if (conjunctionable) {
7823 query.append(WHERE_AND);
7824 }
7825
7826 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
7827
7828 conjunctionable = true;
7829
7830 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7831 MBThread.class.getName(),
7832 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7833
7834 Session session = null;
7835
7836 try {
7837 session = openSession();
7838
7839 SQLQuery q = session.createSQLQuery(sql);
7840
7841 q.addScalar(COUNT_COLUMN_NAME,
7842 com.liferay.portal.kernel.dao.orm.Type.LONG);
7843
7844 QueryPos qPos = QueryPos.getInstance(q);
7845
7846 qPos.add(groupId);
7847
7848 if (categoryIds != null) {
7849 qPos.add(categoryIds);
7850 }
7851
7852 qPos.add(status);
7853
7854 Long count = (Long)q.uniqueResult();
7855
7856 return count.intValue();
7857 }
7858 catch (Exception e) {
7859 throw processException(e);
7860 }
7861 finally {
7862 closeSession(session);
7863 }
7864 }
7865
7866 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
7867 private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
7868 _removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
7869 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
7870 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
7871 _removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
7872 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
7873 private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
7874 _removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
7875 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7876 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7877 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_NotS",
7878 new String[] {
7879 Long.class.getName(), Long.class.getName(),
7880 Integer.class.getName(),
7881
7882 Integer.class.getName(), Integer.class.getName(),
7883 OrderByComparator.class.getName()
7884 });
7885 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS =
7886 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7887 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7888 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_NotS",
7889 new String[] {
7890 Long.class.getName(), Long.class.getName(),
7891 Integer.class.getName()
7892 });
7893
7894
7903 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
7904 int status) throws SystemException {
7905 return findByG_C_NotS(groupId, categoryId, status, QueryUtil.ALL_POS,
7906 QueryUtil.ALL_POS, null);
7907 }
7908
7909
7924 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
7925 int status, int start, int end) throws SystemException {
7926 return findByG_C_NotS(groupId, categoryId, status, start, end, null);
7927 }
7928
7929
7945 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
7946 int status, int start, int end, OrderByComparator orderByComparator)
7947 throws SystemException {
7948 boolean pagination = true;
7949 FinderPath finderPath = null;
7950 Object[] finderArgs = null;
7951
7952 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS;
7953 finderArgs = new Object[] {
7954 groupId, categoryId, status,
7955
7956 start, end, orderByComparator
7957 };
7958
7959 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7960 finderArgs, this);
7961
7962 if ((list != null) && !list.isEmpty()) {
7963 for (MBThread mbThread : list) {
7964 if ((groupId != mbThread.getGroupId()) ||
7965 (categoryId != mbThread.getCategoryId()) ||
7966 (status != mbThread.getStatus())) {
7967 list = null;
7968
7969 break;
7970 }
7971 }
7972 }
7973
7974 if (list == null) {
7975 StringBundler query = null;
7976
7977 if (orderByComparator != null) {
7978 query = new StringBundler(5 +
7979 (orderByComparator.getOrderByFields().length * 3));
7980 }
7981 else {
7982 query = new StringBundler(5);
7983 }
7984
7985 query.append(_SQL_SELECT_MBTHREAD_WHERE);
7986
7987 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
7988
7989 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
7990
7991 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
7992
7993 if (orderByComparator != null) {
7994 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7995 orderByComparator);
7996 }
7997 else
7998 if (pagination) {
7999 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8000 }
8001
8002 String sql = query.toString();
8003
8004 Session session = null;
8005
8006 try {
8007 session = openSession();
8008
8009 Query q = session.createQuery(sql);
8010
8011 QueryPos qPos = QueryPos.getInstance(q);
8012
8013 qPos.add(groupId);
8014
8015 qPos.add(categoryId);
8016
8017 qPos.add(status);
8018
8019 if (!pagination) {
8020 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8021 start, end, false);
8022
8023 Collections.sort(list);
8024
8025 list = new UnmodifiableList<MBThread>(list);
8026 }
8027 else {
8028 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8029 start, end);
8030 }
8031
8032 cacheResult(list);
8033
8034 FinderCacheUtil.putResult(finderPath, finderArgs, list);
8035 }
8036 catch (Exception e) {
8037 FinderCacheUtil.removeResult(finderPath, finderArgs);
8038
8039 throw processException(e);
8040 }
8041 finally {
8042 closeSession(session);
8043 }
8044 }
8045
8046 return list;
8047 }
8048
8049
8060 public MBThread findByG_C_NotS_First(long groupId, long categoryId,
8061 int status, OrderByComparator orderByComparator)
8062 throws NoSuchThreadException, SystemException {
8063 MBThread mbThread = fetchByG_C_NotS_First(groupId, categoryId, status,
8064 orderByComparator);
8065
8066 if (mbThread != null) {
8067 return mbThread;
8068 }
8069
8070 StringBundler msg = new StringBundler(8);
8071
8072 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8073
8074 msg.append("groupId=");
8075 msg.append(groupId);
8076
8077 msg.append(", categoryId=");
8078 msg.append(categoryId);
8079
8080 msg.append(", status=");
8081 msg.append(status);
8082
8083 msg.append(StringPool.CLOSE_CURLY_BRACE);
8084
8085 throw new NoSuchThreadException(msg.toString());
8086 }
8087
8088
8098 public MBThread fetchByG_C_NotS_First(long groupId, long categoryId,
8099 int status, OrderByComparator orderByComparator)
8100 throws SystemException {
8101 List<MBThread> list = findByG_C_NotS(groupId, categoryId, status, 0, 1,
8102 orderByComparator);
8103
8104 if (!list.isEmpty()) {
8105 return list.get(0);
8106 }
8107
8108 return null;
8109 }
8110
8111
8122 public MBThread findByG_C_NotS_Last(long groupId, long categoryId,
8123 int status, OrderByComparator orderByComparator)
8124 throws NoSuchThreadException, SystemException {
8125 MBThread mbThread = fetchByG_C_NotS_Last(groupId, categoryId, status,
8126 orderByComparator);
8127
8128 if (mbThread != null) {
8129 return mbThread;
8130 }
8131
8132 StringBundler msg = new StringBundler(8);
8133
8134 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8135
8136 msg.append("groupId=");
8137 msg.append(groupId);
8138
8139 msg.append(", categoryId=");
8140 msg.append(categoryId);
8141
8142 msg.append(", status=");
8143 msg.append(status);
8144
8145 msg.append(StringPool.CLOSE_CURLY_BRACE);
8146
8147 throw new NoSuchThreadException(msg.toString());
8148 }
8149
8150
8160 public MBThread fetchByG_C_NotS_Last(long groupId, long categoryId,
8161 int status, OrderByComparator orderByComparator)
8162 throws SystemException {
8163 int count = countByG_C_NotS(groupId, categoryId, status);
8164
8165 List<MBThread> list = findByG_C_NotS(groupId, categoryId, status,
8166 count - 1, count, orderByComparator);
8167
8168 if (!list.isEmpty()) {
8169 return list.get(0);
8170 }
8171
8172 return null;
8173 }
8174
8175
8187 public MBThread[] findByG_C_NotS_PrevAndNext(long threadId, long groupId,
8188 long categoryId, int status, OrderByComparator orderByComparator)
8189 throws NoSuchThreadException, SystemException {
8190 MBThread mbThread = findByPrimaryKey(threadId);
8191
8192 Session session = null;
8193
8194 try {
8195 session = openSession();
8196
8197 MBThread[] array = new MBThreadImpl[3];
8198
8199 array[0] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
8200 categoryId, status, orderByComparator, true);
8201
8202 array[1] = mbThread;
8203
8204 array[2] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
8205 categoryId, status, orderByComparator, false);
8206
8207 return array;
8208 }
8209 catch (Exception e) {
8210 throw processException(e);
8211 }
8212 finally {
8213 closeSession(session);
8214 }
8215 }
8216
8217 protected MBThread getByG_C_NotS_PrevAndNext(Session session,
8218 MBThread mbThread, long groupId, long categoryId, int status,
8219 OrderByComparator orderByComparator, boolean previous) {
8220 StringBundler query = null;
8221
8222 if (orderByComparator != null) {
8223 query = new StringBundler(6 +
8224 (orderByComparator.getOrderByFields().length * 6));
8225 }
8226 else {
8227 query = new StringBundler(3);
8228 }
8229
8230 query.append(_SQL_SELECT_MBTHREAD_WHERE);
8231
8232 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
8233
8234 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
8235
8236 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
8237
8238 if (orderByComparator != null) {
8239 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8240
8241 if (orderByConditionFields.length > 0) {
8242 query.append(WHERE_AND);
8243 }
8244
8245 for (int i = 0; i < orderByConditionFields.length; i++) {
8246 query.append(_ORDER_BY_ENTITY_ALIAS);
8247 query.append(orderByConditionFields[i]);
8248
8249 if ((i + 1) < orderByConditionFields.length) {
8250 if (orderByComparator.isAscending() ^ previous) {
8251 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8252 }
8253 else {
8254 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8255 }
8256 }
8257 else {
8258 if (orderByComparator.isAscending() ^ previous) {
8259 query.append(WHERE_GREATER_THAN);
8260 }
8261 else {
8262 query.append(WHERE_LESSER_THAN);
8263 }
8264 }
8265 }
8266
8267 query.append(ORDER_BY_CLAUSE);
8268
8269 String[] orderByFields = orderByComparator.getOrderByFields();
8270
8271 for (int i = 0; i < orderByFields.length; i++) {
8272 query.append(_ORDER_BY_ENTITY_ALIAS);
8273 query.append(orderByFields[i]);
8274
8275 if ((i + 1) < orderByFields.length) {
8276 if (orderByComparator.isAscending() ^ previous) {
8277 query.append(ORDER_BY_ASC_HAS_NEXT);
8278 }
8279 else {
8280 query.append(ORDER_BY_DESC_HAS_NEXT);
8281 }
8282 }
8283 else {
8284 if (orderByComparator.isAscending() ^ previous) {
8285 query.append(ORDER_BY_ASC);
8286 }
8287 else {
8288 query.append(ORDER_BY_DESC);
8289 }
8290 }
8291 }
8292 }
8293 else {
8294 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8295 }
8296
8297 String sql = query.toString();
8298
8299 Query q = session.createQuery(sql);
8300
8301 q.setFirstResult(0);
8302 q.setMaxResults(2);
8303
8304 QueryPos qPos = QueryPos.getInstance(q);
8305
8306 qPos.add(groupId);
8307
8308 qPos.add(categoryId);
8309
8310 qPos.add(status);
8311
8312 if (orderByComparator != null) {
8313 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8314
8315 for (Object value : values) {
8316 qPos.add(value);
8317 }
8318 }
8319
8320 List<MBThread> list = q.list();
8321
8322 if (list.size() == 2) {
8323 return list.get(1);
8324 }
8325 else {
8326 return null;
8327 }
8328 }
8329
8330
8339 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
8340 int status) throws SystemException {
8341 return filterFindByG_C_NotS(groupId, categoryId, status,
8342 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8343 }
8344
8345
8360 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
8361 int status, int start, int end) throws SystemException {
8362 return filterFindByG_C_NotS(groupId, categoryId, status, start, end,
8363 null);
8364 }
8365
8366
8382 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
8383 int status, int start, int end, OrderByComparator orderByComparator)
8384 throws SystemException {
8385 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8386 return findByG_C_NotS(groupId, categoryId, status, start, end,
8387 orderByComparator);
8388 }
8389
8390 StringBundler query = null;
8391
8392 if (orderByComparator != null) {
8393 query = new StringBundler(5 +
8394 (orderByComparator.getOrderByFields().length * 3));
8395 }
8396 else {
8397 query = new StringBundler(5);
8398 }
8399
8400 if (getDB().isSupportsInlineDistinct()) {
8401 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8402 }
8403 else {
8404 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8405 }
8406
8407 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
8408
8409 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
8410
8411 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
8412
8413 if (!getDB().isSupportsInlineDistinct()) {
8414 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8415 }
8416
8417 if (orderByComparator != null) {
8418 if (getDB().isSupportsInlineDistinct()) {
8419 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8420 orderByComparator);
8421 }
8422 else {
8423 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8424 orderByComparator);
8425 }
8426 }
8427 else {
8428 if (getDB().isSupportsInlineDistinct()) {
8429 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8430 }
8431 else {
8432 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8433 }
8434 }
8435
8436 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8437 MBThread.class.getName(),
8438 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8439
8440 Session session = null;
8441
8442 try {
8443 session = openSession();
8444
8445 SQLQuery q = session.createSQLQuery(sql);
8446
8447 if (getDB().isSupportsInlineDistinct()) {
8448 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8449 }
8450 else {
8451 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8452 }
8453
8454 QueryPos qPos = QueryPos.getInstance(q);
8455
8456 qPos.add(groupId);
8457
8458 qPos.add(categoryId);
8459
8460 qPos.add(status);
8461
8462 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8463 }
8464 catch (Exception e) {
8465 throw processException(e);
8466 }
8467 finally {
8468 closeSession(session);
8469 }
8470 }
8471
8472
8484 public MBThread[] filterFindByG_C_NotS_PrevAndNext(long threadId,
8485 long groupId, long categoryId, int status,
8486 OrderByComparator orderByComparator)
8487 throws NoSuchThreadException, SystemException {
8488 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8489 return findByG_C_NotS_PrevAndNext(threadId, groupId, categoryId,
8490 status, orderByComparator);
8491 }
8492
8493 MBThread mbThread = findByPrimaryKey(threadId);
8494
8495 Session session = null;
8496
8497 try {
8498 session = openSession();
8499
8500 MBThread[] array = new MBThreadImpl[3];
8501
8502 array[0] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
8503 groupId, categoryId, status, orderByComparator, true);
8504
8505 array[1] = mbThread;
8506
8507 array[2] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
8508 groupId, categoryId, status, orderByComparator, false);
8509
8510 return array;
8511 }
8512 catch (Exception e) {
8513 throw processException(e);
8514 }
8515 finally {
8516 closeSession(session);
8517 }
8518 }
8519
8520 protected MBThread filterGetByG_C_NotS_PrevAndNext(Session session,
8521 MBThread mbThread, long groupId, long categoryId, int status,
8522 OrderByComparator orderByComparator, boolean previous) {
8523 StringBundler query = null;
8524
8525 if (orderByComparator != null) {
8526 query = new StringBundler(6 +
8527 (orderByComparator.getOrderByFields().length * 6));
8528 }
8529 else {
8530 query = new StringBundler(3);
8531 }
8532
8533 if (getDB().isSupportsInlineDistinct()) {
8534 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8535 }
8536 else {
8537 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8538 }
8539
8540 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
8541
8542 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
8543
8544 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
8545
8546 if (!getDB().isSupportsInlineDistinct()) {
8547 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8548 }
8549
8550 if (orderByComparator != null) {
8551 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8552
8553 if (orderByConditionFields.length > 0) {
8554 query.append(WHERE_AND);
8555 }
8556
8557 for (int i = 0; i < orderByConditionFields.length; i++) {
8558 if (getDB().isSupportsInlineDistinct()) {
8559 query.append(_ORDER_BY_ENTITY_ALIAS);
8560 }
8561 else {
8562 query.append(_ORDER_BY_ENTITY_TABLE);
8563 }
8564
8565 query.append(orderByConditionFields[i]);
8566
8567 if ((i + 1) < orderByConditionFields.length) {
8568 if (orderByComparator.isAscending() ^ previous) {
8569 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8570 }
8571 else {
8572 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8573 }
8574 }
8575 else {
8576 if (orderByComparator.isAscending() ^ previous) {
8577 query.append(WHERE_GREATER_THAN);
8578 }
8579 else {
8580 query.append(WHERE_LESSER_THAN);
8581 }
8582 }
8583 }
8584
8585 query.append(ORDER_BY_CLAUSE);
8586
8587 String[] orderByFields = orderByComparator.getOrderByFields();
8588
8589 for (int i = 0; i < orderByFields.length; i++) {
8590 if (getDB().isSupportsInlineDistinct()) {
8591 query.append(_ORDER_BY_ENTITY_ALIAS);
8592 }
8593 else {
8594 query.append(_ORDER_BY_ENTITY_TABLE);
8595 }
8596
8597 query.append(orderByFields[i]);
8598
8599 if ((i + 1) < orderByFields.length) {
8600 if (orderByComparator.isAscending() ^ previous) {
8601 query.append(ORDER_BY_ASC_HAS_NEXT);
8602 }
8603 else {
8604 query.append(ORDER_BY_DESC_HAS_NEXT);
8605 }
8606 }
8607 else {
8608 if (orderByComparator.isAscending() ^ previous) {
8609 query.append(ORDER_BY_ASC);
8610 }
8611 else {
8612 query.append(ORDER_BY_DESC);
8613 }
8614 }
8615 }
8616 }
8617 else {
8618 if (getDB().isSupportsInlineDistinct()) {
8619 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8620 }
8621 else {
8622 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8623 }
8624 }
8625
8626 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8627 MBThread.class.getName(),
8628 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8629
8630 SQLQuery q = session.createSQLQuery(sql);
8631
8632 q.setFirstResult(0);
8633 q.setMaxResults(2);
8634
8635 if (getDB().isSupportsInlineDistinct()) {
8636 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8637 }
8638 else {
8639 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8640 }
8641
8642 QueryPos qPos = QueryPos.getInstance(q);
8643
8644 qPos.add(groupId);
8645
8646 qPos.add(categoryId);
8647
8648 qPos.add(status);
8649
8650 if (orderByComparator != null) {
8651 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8652
8653 for (Object value : values) {
8654 qPos.add(value);
8655 }
8656 }
8657
8658 List<MBThread> list = q.list();
8659
8660 if (list.size() == 2) {
8661 return list.get(1);
8662 }
8663 else {
8664 return null;
8665 }
8666 }
8667
8668
8677 public List<MBThread> filterFindByG_C_NotS(long groupId,
8678 long[] categoryIds, int status) throws SystemException {
8679 return filterFindByG_C_NotS(groupId, categoryIds, status,
8680 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8681 }
8682
8683
8698 public List<MBThread> filterFindByG_C_NotS(long groupId,
8699 long[] categoryIds, int status, int start, int end)
8700 throws SystemException {
8701 return filterFindByG_C_NotS(groupId, categoryIds, status, start, end,
8702 null);
8703 }
8704
8705
8721 public List<MBThread> filterFindByG_C_NotS(long groupId,
8722 long[] categoryIds, int status, int start, int end,
8723 OrderByComparator orderByComparator) throws SystemException {
8724 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8725 return findByG_C_NotS(groupId, categoryIds, status, start, end,
8726 orderByComparator);
8727 }
8728
8729 StringBundler query = new StringBundler();
8730
8731 if (getDB().isSupportsInlineDistinct()) {
8732 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8733 }
8734 else {
8735 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8736 }
8737
8738 boolean conjunctionable = false;
8739
8740 if (conjunctionable) {
8741 query.append(WHERE_AND);
8742 }
8743
8744 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
8745
8746 conjunctionable = true;
8747
8748 if ((categoryIds == null) || (categoryIds.length > 0)) {
8749 if (conjunctionable) {
8750 query.append(WHERE_AND);
8751 }
8752
8753 query.append(StringPool.OPEN_PARENTHESIS);
8754
8755 for (int i = 0; i < categoryIds.length; i++) {
8756 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
8757
8758 if ((i + 1) < categoryIds.length) {
8759 query.append(WHERE_OR);
8760 }
8761 }
8762
8763 query.append(StringPool.CLOSE_PARENTHESIS);
8764
8765 conjunctionable = true;
8766 }
8767
8768 if (conjunctionable) {
8769 query.append(WHERE_AND);
8770 }
8771
8772 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
8773
8774 conjunctionable = true;
8775
8776 if (!getDB().isSupportsInlineDistinct()) {
8777 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8778 }
8779
8780 if (orderByComparator != null) {
8781 if (getDB().isSupportsInlineDistinct()) {
8782 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8783 orderByComparator);
8784 }
8785 else {
8786 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8787 orderByComparator);
8788 }
8789 }
8790 else {
8791 if (getDB().isSupportsInlineDistinct()) {
8792 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8793 }
8794 else {
8795 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8796 }
8797 }
8798
8799 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8800 MBThread.class.getName(),
8801 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8802
8803 Session session = null;
8804
8805 try {
8806 session = openSession();
8807
8808 SQLQuery q = session.createSQLQuery(sql);
8809
8810 if (getDB().isSupportsInlineDistinct()) {
8811 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8812 }
8813 else {
8814 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8815 }
8816
8817 QueryPos qPos = QueryPos.getInstance(q);
8818
8819 qPos.add(groupId);
8820
8821 if (categoryIds != null) {
8822 qPos.add(categoryIds);
8823 }
8824
8825 qPos.add(status);
8826
8827 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8828 }
8829 catch (Exception e) {
8830 throw processException(e);
8831 }
8832 finally {
8833 closeSession(session);
8834 }
8835 }
8836
8837
8850 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
8851 int status) throws SystemException {
8852 return findByG_C_NotS(groupId, categoryIds, status, QueryUtil.ALL_POS,
8853 QueryUtil.ALL_POS, null);
8854 }
8855
8856
8871 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
8872 int status, int start, int end) throws SystemException {
8873 return findByG_C_NotS(groupId, categoryIds, status, start, end, null);
8874 }
8875
8876
8892 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
8893 int status, int start, int end, OrderByComparator orderByComparator)
8894 throws SystemException {
8895 if ((categoryIds != null) && (categoryIds.length == 1)) {
8896 return findByG_C_NotS(groupId, categoryIds[0], status, start, end,
8897 orderByComparator);
8898 }
8899
8900 boolean pagination = true;
8901 Object[] finderArgs = null;
8902
8903 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8904 (orderByComparator == null)) {
8905 pagination = false;
8906 finderArgs = new Object[] {
8907 groupId, StringUtil.merge(categoryIds), status
8908 };
8909 }
8910 else {
8911 finderArgs = new Object[] {
8912 groupId, StringUtil.merge(categoryIds), status,
8913
8914 start, end, orderByComparator
8915 };
8916 }
8917
8918 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
8919 finderArgs, this);
8920
8921 if ((list != null) && !list.isEmpty()) {
8922 for (MBThread mbThread : list) {
8923 if ((groupId != mbThread.getGroupId()) ||
8924 !ArrayUtil.contains(categoryIds,
8925 mbThread.getCategoryId()) ||
8926 (status != mbThread.getStatus())) {
8927 list = null;
8928
8929 break;
8930 }
8931 }
8932 }
8933
8934 if (list == null) {
8935 StringBundler query = new StringBundler();
8936
8937 query.append(_SQL_SELECT_MBTHREAD_WHERE);
8938
8939 boolean conjunctionable = false;
8940
8941 if (conjunctionable) {
8942 query.append(WHERE_AND);
8943 }
8944
8945 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
8946
8947 conjunctionable = true;
8948
8949 if ((categoryIds == null) || (categoryIds.length > 0)) {
8950 if (conjunctionable) {
8951 query.append(WHERE_AND);
8952 }
8953
8954 query.append(StringPool.OPEN_PARENTHESIS);
8955
8956 for (int i = 0; i < categoryIds.length; i++) {
8957 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
8958
8959 if ((i + 1) < categoryIds.length) {
8960 query.append(WHERE_OR);
8961 }
8962 }
8963
8964 query.append(StringPool.CLOSE_PARENTHESIS);
8965
8966 conjunctionable = true;
8967 }
8968
8969 if (conjunctionable) {
8970 query.append(WHERE_AND);
8971 }
8972
8973 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
8974
8975 conjunctionable = true;
8976
8977 if (orderByComparator != null) {
8978 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8979 orderByComparator);
8980 }
8981 else
8982 if (pagination) {
8983 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8984 }
8985
8986 String sql = query.toString();
8987
8988 Session session = null;
8989
8990 try {
8991 session = openSession();
8992
8993 Query q = session.createQuery(sql);
8994
8995 QueryPos qPos = QueryPos.getInstance(q);
8996
8997 qPos.add(groupId);
8998
8999 if (categoryIds != null) {
9000 qPos.add(categoryIds);
9001 }
9002
9003 qPos.add(status);
9004
9005 if (!pagination) {
9006 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9007 start, end, false);
9008
9009 Collections.sort(list);
9010
9011 list = new UnmodifiableList<MBThread>(list);
9012 }
9013 else {
9014 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9015 start, end);
9016 }
9017
9018 cacheResult(list);
9019
9020 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
9021 finderArgs, list);
9022 }
9023 catch (Exception e) {
9024 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
9025 finderArgs);
9026
9027 throw processException(e);
9028 }
9029 finally {
9030 closeSession(session);
9031 }
9032 }
9033
9034 return list;
9035 }
9036
9037
9045 public void removeByG_C_NotS(long groupId, long categoryId, int status)
9046 throws SystemException {
9047 for (MBThread mbThread : findByG_C_NotS(groupId, categoryId, status,
9048 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9049 remove(mbThread);
9050 }
9051 }
9052
9053
9062 public int countByG_C_NotS(long groupId, long categoryId, int status)
9063 throws SystemException {
9064 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS;
9065
9066 Object[] finderArgs = new Object[] { groupId, categoryId, status };
9067
9068 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9069 this);
9070
9071 if (count == null) {
9072 StringBundler query = new StringBundler(4);
9073
9074 query.append(_SQL_COUNT_MBTHREAD_WHERE);
9075
9076 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9077
9078 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9079
9080 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9081
9082 String sql = query.toString();
9083
9084 Session session = null;
9085
9086 try {
9087 session = openSession();
9088
9089 Query q = session.createQuery(sql);
9090
9091 QueryPos qPos = QueryPos.getInstance(q);
9092
9093 qPos.add(groupId);
9094
9095 qPos.add(categoryId);
9096
9097 qPos.add(status);
9098
9099 count = (Long)q.uniqueResult();
9100
9101 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9102 }
9103 catch (Exception e) {
9104 FinderCacheUtil.removeResult(finderPath, finderArgs);
9105
9106 throw processException(e);
9107 }
9108 finally {
9109 closeSession(session);
9110 }
9111 }
9112
9113 return count.intValue();
9114 }
9115
9116
9125 public int countByG_C_NotS(long groupId, long[] categoryIds, int status)
9126 throws SystemException {
9127 Object[] finderArgs = new Object[] {
9128 groupId, StringUtil.merge(categoryIds), status
9129 };
9130
9131 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
9132 finderArgs, this);
9133
9134 if (count == null) {
9135 StringBundler query = new StringBundler();
9136
9137 query.append(_SQL_COUNT_MBTHREAD_WHERE);
9138
9139 boolean conjunctionable = false;
9140
9141 if (conjunctionable) {
9142 query.append(WHERE_AND);
9143 }
9144
9145 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
9146
9147 conjunctionable = true;
9148
9149 if ((categoryIds == null) || (categoryIds.length > 0)) {
9150 if (conjunctionable) {
9151 query.append(WHERE_AND);
9152 }
9153
9154 query.append(StringPool.OPEN_PARENTHESIS);
9155
9156 for (int i = 0; i < categoryIds.length; i++) {
9157 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
9158
9159 if ((i + 1) < categoryIds.length) {
9160 query.append(WHERE_OR);
9161 }
9162 }
9163
9164 query.append(StringPool.CLOSE_PARENTHESIS);
9165
9166 conjunctionable = true;
9167 }
9168
9169 if (conjunctionable) {
9170 query.append(WHERE_AND);
9171 }
9172
9173 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
9174
9175 conjunctionable = true;
9176
9177 String sql = query.toString();
9178
9179 Session session = null;
9180
9181 try {
9182 session = openSession();
9183
9184 Query q = session.createQuery(sql);
9185
9186 QueryPos qPos = QueryPos.getInstance(q);
9187
9188 qPos.add(groupId);
9189
9190 if (categoryIds != null) {
9191 qPos.add(categoryIds);
9192 }
9193
9194 qPos.add(status);
9195
9196 count = (Long)q.uniqueResult();
9197
9198 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
9199 finderArgs, count);
9200 }
9201 catch (Exception e) {
9202 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
9203 finderArgs);
9204
9205 throw processException(e);
9206 }
9207 finally {
9208 closeSession(session);
9209 }
9210 }
9211
9212 return count.intValue();
9213 }
9214
9215
9224 public int filterCountByG_C_NotS(long groupId, long categoryId, int status)
9225 throws SystemException {
9226 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9227 return countByG_C_NotS(groupId, categoryId, status);
9228 }
9229
9230 StringBundler query = new StringBundler(4);
9231
9232 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9233
9234 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9235
9236 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9237
9238 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9239
9240 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9241 MBThread.class.getName(),
9242 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9243
9244 Session session = null;
9245
9246 try {
9247 session = openSession();
9248
9249 SQLQuery q = session.createSQLQuery(sql);
9250
9251 q.addScalar(COUNT_COLUMN_NAME,
9252 com.liferay.portal.kernel.dao.orm.Type.LONG);
9253
9254 QueryPos qPos = QueryPos.getInstance(q);
9255
9256 qPos.add(groupId);
9257
9258 qPos.add(categoryId);
9259
9260 qPos.add(status);
9261
9262 Long count = (Long)q.uniqueResult();
9263
9264 return count.intValue();
9265 }
9266 catch (Exception e) {
9267 throw processException(e);
9268 }
9269 finally {
9270 closeSession(session);
9271 }
9272 }
9273
9274
9283 public int filterCountByG_C_NotS(long groupId, long[] categoryIds,
9284 int status) throws SystemException {
9285 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9286 return countByG_C_NotS(groupId, categoryIds, status);
9287 }
9288
9289 StringBundler query = new StringBundler();
9290
9291 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9292
9293 boolean conjunctionable = false;
9294
9295 if (conjunctionable) {
9296 query.append(WHERE_AND);
9297 }
9298
9299 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
9300
9301 conjunctionable = true;
9302
9303 if ((categoryIds == null) || (categoryIds.length > 0)) {
9304 if (conjunctionable) {
9305 query.append(WHERE_AND);
9306 }
9307
9308 query.append(StringPool.OPEN_PARENTHESIS);
9309
9310 for (int i = 0; i < categoryIds.length; i++) {
9311 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
9312
9313 if ((i + 1) < categoryIds.length) {
9314 query.append(WHERE_OR);
9315 }
9316 }
9317
9318 query.append(StringPool.CLOSE_PARENTHESIS);
9319
9320 conjunctionable = true;
9321 }
9322
9323 if (conjunctionable) {
9324 query.append(WHERE_AND);
9325 }
9326
9327 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
9328
9329 conjunctionable = true;
9330
9331 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9332 MBThread.class.getName(),
9333 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9334
9335 Session session = null;
9336
9337 try {
9338 session = openSession();
9339
9340 SQLQuery q = session.createSQLQuery(sql);
9341
9342 q.addScalar(COUNT_COLUMN_NAME,
9343 com.liferay.portal.kernel.dao.orm.Type.LONG);
9344
9345 QueryPos qPos = QueryPos.getInstance(q);
9346
9347 qPos.add(groupId);
9348
9349 if (categoryIds != null) {
9350 qPos.add(categoryIds);
9351 }
9352
9353 qPos.add(status);
9354
9355 Long count = (Long)q.uniqueResult();
9356
9357 return count.intValue();
9358 }
9359 catch (Exception e) {
9360 throw processException(e);
9361 }
9362 finally {
9363 closeSession(session);
9364 }
9365 }
9366
9367 private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
9368 private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_5 = "(" +
9369 _removeConjunction(_FINDER_COLUMN_G_C_NOTS_GROUPID_2) + ")";
9370 private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9371 private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_5 = "(" +
9372 _removeConjunction(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2) + ")";
9373 private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_2 = "mbThread.status != ?";
9374 private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_5 = "(" +
9375 _removeConjunction(_FINDER_COLUMN_G_C_NOTS_STATUS_2) + ")";
9376 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9377 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
9378 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
9379 new String[] {
9380 Long.class.getName(), Long.class.getName(),
9381 Integer.class.getName(),
9382
9383 Integer.class.getName(), Integer.class.getName(),
9384 OrderByComparator.class.getName()
9385 });
9386 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S =
9387 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9388 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
9389 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_S",
9390 new String[] {
9391 Long.class.getName(), Long.class.getName(),
9392 Integer.class.getName()
9393 });
9394
9395
9404 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
9405 int status) throws SystemException {
9406 return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
9407 QueryUtil.ALL_POS, null);
9408 }
9409
9410
9425 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
9426 int status, int start, int end) throws SystemException {
9427 return findByG_NotC_S(groupId, categoryId, status, start, end, null);
9428 }
9429
9430
9446 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
9447 int status, int start, int end, OrderByComparator orderByComparator)
9448 throws SystemException {
9449 boolean pagination = true;
9450 FinderPath finderPath = null;
9451 Object[] finderArgs = null;
9452
9453 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
9454 finderArgs = new Object[] {
9455 groupId, categoryId, status,
9456
9457 start, end, orderByComparator
9458 };
9459
9460 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
9461 finderArgs, this);
9462
9463 if ((list != null) && !list.isEmpty()) {
9464 for (MBThread mbThread : list) {
9465 if ((groupId != mbThread.getGroupId()) ||
9466 (categoryId != mbThread.getCategoryId()) ||
9467 (status != mbThread.getStatus())) {
9468 list = null;
9469
9470 break;
9471 }
9472 }
9473 }
9474
9475 if (list == null) {
9476 StringBundler query = null;
9477
9478 if (orderByComparator != null) {
9479 query = new StringBundler(5 +
9480 (orderByComparator.getOrderByFields().length * 3));
9481 }
9482 else {
9483 query = new StringBundler(5);
9484 }
9485
9486 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9487
9488 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9489
9490 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9491
9492 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9493
9494 if (orderByComparator != null) {
9495 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9496 orderByComparator);
9497 }
9498 else
9499 if (pagination) {
9500 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9501 }
9502
9503 String sql = query.toString();
9504
9505 Session session = null;
9506
9507 try {
9508 session = openSession();
9509
9510 Query q = session.createQuery(sql);
9511
9512 QueryPos qPos = QueryPos.getInstance(q);
9513
9514 qPos.add(groupId);
9515
9516 qPos.add(categoryId);
9517
9518 qPos.add(status);
9519
9520 if (!pagination) {
9521 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9522 start, end, false);
9523
9524 Collections.sort(list);
9525
9526 list = new UnmodifiableList<MBThread>(list);
9527 }
9528 else {
9529 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9530 start, end);
9531 }
9532
9533 cacheResult(list);
9534
9535 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9536 }
9537 catch (Exception e) {
9538 FinderCacheUtil.removeResult(finderPath, finderArgs);
9539
9540 throw processException(e);
9541 }
9542 finally {
9543 closeSession(session);
9544 }
9545 }
9546
9547 return list;
9548 }
9549
9550
9561 public MBThread findByG_NotC_S_First(long groupId, long categoryId,
9562 int status, OrderByComparator orderByComparator)
9563 throws NoSuchThreadException, SystemException {
9564 MBThread mbThread = fetchByG_NotC_S_First(groupId, categoryId, status,
9565 orderByComparator);
9566
9567 if (mbThread != null) {
9568 return mbThread;
9569 }
9570
9571 StringBundler msg = new StringBundler(8);
9572
9573 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9574
9575 msg.append("groupId=");
9576 msg.append(groupId);
9577
9578 msg.append(", categoryId=");
9579 msg.append(categoryId);
9580
9581 msg.append(", status=");
9582 msg.append(status);
9583
9584 msg.append(StringPool.CLOSE_CURLY_BRACE);
9585
9586 throw new NoSuchThreadException(msg.toString());
9587 }
9588
9589
9599 public MBThread fetchByG_NotC_S_First(long groupId, long categoryId,
9600 int status, OrderByComparator orderByComparator)
9601 throws SystemException {
9602 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
9603 orderByComparator);
9604
9605 if (!list.isEmpty()) {
9606 return list.get(0);
9607 }
9608
9609 return null;
9610 }
9611
9612
9623 public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
9624 int status, OrderByComparator orderByComparator)
9625 throws NoSuchThreadException, SystemException {
9626 MBThread mbThread = fetchByG_NotC_S_Last(groupId, categoryId, status,
9627 orderByComparator);
9628
9629 if (mbThread != null) {
9630 return mbThread;
9631 }
9632
9633 StringBundler msg = new StringBundler(8);
9634
9635 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9636
9637 msg.append("groupId=");
9638 msg.append(groupId);
9639
9640 msg.append(", categoryId=");
9641 msg.append(categoryId);
9642
9643 msg.append(", status=");
9644 msg.append(status);
9645
9646 msg.append(StringPool.CLOSE_CURLY_BRACE);
9647
9648 throw new NoSuchThreadException(msg.toString());
9649 }
9650
9651
9661 public MBThread fetchByG_NotC_S_Last(long groupId, long categoryId,
9662 int status, OrderByComparator orderByComparator)
9663 throws SystemException {
9664 int count = countByG_NotC_S(groupId, categoryId, status);
9665
9666 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
9667 count - 1, count, orderByComparator);
9668
9669 if (!list.isEmpty()) {
9670 return list.get(0);
9671 }
9672
9673 return null;
9674 }
9675
9676
9688 public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
9689 long categoryId, int status, OrderByComparator orderByComparator)
9690 throws NoSuchThreadException, SystemException {
9691 MBThread mbThread = findByPrimaryKey(threadId);
9692
9693 Session session = null;
9694
9695 try {
9696 session = openSession();
9697
9698 MBThread[] array = new MBThreadImpl[3];
9699
9700 array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
9701 categoryId, status, orderByComparator, true);
9702
9703 array[1] = mbThread;
9704
9705 array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
9706 categoryId, status, orderByComparator, false);
9707
9708 return array;
9709 }
9710 catch (Exception e) {
9711 throw processException(e);
9712 }
9713 finally {
9714 closeSession(session);
9715 }
9716 }
9717
9718 protected MBThread getByG_NotC_S_PrevAndNext(Session session,
9719 MBThread mbThread, long groupId, long categoryId, int status,
9720 OrderByComparator orderByComparator, boolean previous) {
9721 StringBundler query = null;
9722
9723 if (orderByComparator != null) {
9724 query = new StringBundler(6 +
9725 (orderByComparator.getOrderByFields().length * 6));
9726 }
9727 else {
9728 query = new StringBundler(3);
9729 }
9730
9731 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9732
9733 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9734
9735 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9736
9737 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9738
9739 if (orderByComparator != null) {
9740 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9741
9742 if (orderByConditionFields.length > 0) {
9743 query.append(WHERE_AND);
9744 }
9745
9746 for (int i = 0; i < orderByConditionFields.length; i++) {
9747 query.append(_ORDER_BY_ENTITY_ALIAS);
9748 query.append(orderByConditionFields[i]);
9749
9750 if ((i + 1) < orderByConditionFields.length) {
9751 if (orderByComparator.isAscending() ^ previous) {
9752 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9753 }
9754 else {
9755 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9756 }
9757 }
9758 else {
9759 if (orderByComparator.isAscending() ^ previous) {
9760 query.append(WHERE_GREATER_THAN);
9761 }
9762 else {
9763 query.append(WHERE_LESSER_THAN);
9764 }
9765 }
9766 }
9767
9768 query.append(ORDER_BY_CLAUSE);
9769
9770 String[] orderByFields = orderByComparator.getOrderByFields();
9771
9772 for (int i = 0; i < orderByFields.length; i++) {
9773 query.append(_ORDER_BY_ENTITY_ALIAS);
9774 query.append(orderByFields[i]);
9775
9776 if ((i + 1) < orderByFields.length) {
9777 if (orderByComparator.isAscending() ^ previous) {
9778 query.append(ORDER_BY_ASC_HAS_NEXT);
9779 }
9780 else {
9781 query.append(ORDER_BY_DESC_HAS_NEXT);
9782 }
9783 }
9784 else {
9785 if (orderByComparator.isAscending() ^ previous) {
9786 query.append(ORDER_BY_ASC);
9787 }
9788 else {
9789 query.append(ORDER_BY_DESC);
9790 }
9791 }
9792 }
9793 }
9794 else {
9795 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9796 }
9797
9798 String sql = query.toString();
9799
9800 Query q = session.createQuery(sql);
9801
9802 q.setFirstResult(0);
9803 q.setMaxResults(2);
9804
9805 QueryPos qPos = QueryPos.getInstance(q);
9806
9807 qPos.add(groupId);
9808
9809 qPos.add(categoryId);
9810
9811 qPos.add(status);
9812
9813 if (orderByComparator != null) {
9814 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9815
9816 for (Object value : values) {
9817 qPos.add(value);
9818 }
9819 }
9820
9821 List<MBThread> list = q.list();
9822
9823 if (list.size() == 2) {
9824 return list.get(1);
9825 }
9826 else {
9827 return null;
9828 }
9829 }
9830
9831
9840 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
9841 int status) throws SystemException {
9842 return filterFindByG_NotC_S(groupId, categoryId, status,
9843 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9844 }
9845
9846
9861 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
9862 int status, int start, int end) throws SystemException {
9863 return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
9864 null);
9865 }
9866
9867
9883 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
9884 int status, int start, int end, OrderByComparator orderByComparator)
9885 throws SystemException {
9886 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9887 return findByG_NotC_S(groupId, categoryId, status, start, end,
9888 orderByComparator);
9889 }
9890
9891 StringBundler query = null;
9892
9893 if (orderByComparator != null) {
9894 query = new StringBundler(5 +
9895 (orderByComparator.getOrderByFields().length * 3));
9896 }
9897 else {
9898 query = new StringBundler(5);
9899 }
9900
9901 if (getDB().isSupportsInlineDistinct()) {
9902 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9903 }
9904 else {
9905 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9906 }
9907
9908 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
9909
9910 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
9911
9912 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
9913
9914 if (!getDB().isSupportsInlineDistinct()) {
9915 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9916 }
9917
9918 if (orderByComparator != null) {
9919 if (getDB().isSupportsInlineDistinct()) {
9920 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9921 orderByComparator);
9922 }
9923 else {
9924 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9925 orderByComparator);
9926 }
9927 }
9928 else {
9929 if (getDB().isSupportsInlineDistinct()) {
9930 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9931 }
9932 else {
9933 query.append(MBThreadModelImpl.ORDER_BY_SQL);
9934 }
9935 }
9936
9937 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9938 MBThread.class.getName(),
9939 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9940
9941 Session session = null;
9942
9943 try {
9944 session = openSession();
9945
9946 SQLQuery q = session.createSQLQuery(sql);
9947
9948 if (getDB().isSupportsInlineDistinct()) {
9949 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
9950 }
9951 else {
9952 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
9953 }
9954
9955 QueryPos qPos = QueryPos.getInstance(q);
9956
9957 qPos.add(groupId);
9958
9959 qPos.add(categoryId);
9960
9961 qPos.add(status);
9962
9963 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
9964 }
9965 catch (Exception e) {
9966 throw processException(e);
9967 }
9968 finally {
9969 closeSession(session);
9970 }
9971 }
9972
9973
9985 public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
9986 long groupId, long categoryId, int status,
9987 OrderByComparator orderByComparator)
9988 throws NoSuchThreadException, SystemException {
9989 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9990 return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
9991 status, orderByComparator);
9992 }
9993
9994 MBThread mbThread = findByPrimaryKey(threadId);
9995
9996 Session session = null;
9997
9998 try {
9999 session = openSession();
10000
10001 MBThread[] array = new MBThreadImpl[3];
10002
10003 array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
10004 groupId, categoryId, status, orderByComparator, true);
10005
10006 array[1] = mbThread;
10007
10008 array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
10009 groupId, categoryId, status, orderByComparator, false);
10010
10011 return array;
10012 }
10013 catch (Exception e) {
10014 throw processException(e);
10015 }
10016 finally {
10017 closeSession(session);
10018 }
10019 }
10020
10021 protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
10022 MBThread mbThread, long groupId, long categoryId, int status,
10023 OrderByComparator orderByComparator, boolean previous) {
10024 StringBundler query = null;
10025
10026 if (orderByComparator != null) {
10027 query = new StringBundler(6 +
10028 (orderByComparator.getOrderByFields().length * 6));
10029 }
10030 else {
10031 query = new StringBundler(3);
10032 }
10033
10034 if (getDB().isSupportsInlineDistinct()) {
10035 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10036 }
10037 else {
10038 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10039 }
10040
10041 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10042
10043 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10044
10045 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10046
10047 if (!getDB().isSupportsInlineDistinct()) {
10048 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10049 }
10050
10051 if (orderByComparator != null) {
10052 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10053
10054 if (orderByConditionFields.length > 0) {
10055 query.append(WHERE_AND);
10056 }
10057
10058 for (int i = 0; i < orderByConditionFields.length; i++) {
10059 if (getDB().isSupportsInlineDistinct()) {
10060 query.append(_ORDER_BY_ENTITY_ALIAS);
10061 }
10062 else {
10063 query.append(_ORDER_BY_ENTITY_TABLE);
10064 }
10065
10066 query.append(orderByConditionFields[i]);
10067
10068 if ((i + 1) < orderByConditionFields.length) {
10069 if (orderByComparator.isAscending() ^ previous) {
10070 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10071 }
10072 else {
10073 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10074 }
10075 }
10076 else {
10077 if (orderByComparator.isAscending() ^ previous) {
10078 query.append(WHERE_GREATER_THAN);
10079 }
10080 else {
10081 query.append(WHERE_LESSER_THAN);
10082 }
10083 }
10084 }
10085
10086 query.append(ORDER_BY_CLAUSE);
10087
10088 String[] orderByFields = orderByComparator.getOrderByFields();
10089
10090 for (int i = 0; i < orderByFields.length; i++) {
10091 if (getDB().isSupportsInlineDistinct()) {
10092 query.append(_ORDER_BY_ENTITY_ALIAS);
10093 }
10094 else {
10095 query.append(_ORDER_BY_ENTITY_TABLE);
10096 }
10097
10098 query.append(orderByFields[i]);
10099
10100 if ((i + 1) < orderByFields.length) {
10101 if (orderByComparator.isAscending() ^ previous) {
10102 query.append(ORDER_BY_ASC_HAS_NEXT);
10103 }
10104 else {
10105 query.append(ORDER_BY_DESC_HAS_NEXT);
10106 }
10107 }
10108 else {
10109 if (orderByComparator.isAscending() ^ previous) {
10110 query.append(ORDER_BY_ASC);
10111 }
10112 else {
10113 query.append(ORDER_BY_DESC);
10114 }
10115 }
10116 }
10117 }
10118 else {
10119 if (getDB().isSupportsInlineDistinct()) {
10120 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10121 }
10122 else {
10123 query.append(MBThreadModelImpl.ORDER_BY_SQL);
10124 }
10125 }
10126
10127 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10128 MBThread.class.getName(),
10129 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10130
10131 SQLQuery q = session.createSQLQuery(sql);
10132
10133 q.setFirstResult(0);
10134 q.setMaxResults(2);
10135
10136 if (getDB().isSupportsInlineDistinct()) {
10137 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10138 }
10139 else {
10140 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10141 }
10142
10143 QueryPos qPos = QueryPos.getInstance(q);
10144
10145 qPos.add(groupId);
10146
10147 qPos.add(categoryId);
10148
10149 qPos.add(status);
10150
10151 if (orderByComparator != null) {
10152 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
10153
10154 for (Object value : values) {
10155 qPos.add(value);
10156 }
10157 }
10158
10159 List<MBThread> list = q.list();
10160
10161 if (list.size() == 2) {
10162 return list.get(1);
10163 }
10164 else {
10165 return null;
10166 }
10167 }
10168
10169
10177 public void removeByG_NotC_S(long groupId, long categoryId, int status)
10178 throws SystemException {
10179 for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status,
10180 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10181 remove(mbThread);
10182 }
10183 }
10184
10185
10194 public int countByG_NotC_S(long groupId, long categoryId, int status)
10195 throws SystemException {
10196 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S;
10197
10198 Object[] finderArgs = new Object[] { groupId, categoryId, status };
10199
10200 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10201 this);
10202
10203 if (count == null) {
10204 StringBundler query = new StringBundler(4);
10205
10206 query.append(_SQL_COUNT_MBTHREAD_WHERE);
10207
10208 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10209
10210 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10211
10212 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10213
10214 String sql = query.toString();
10215
10216 Session session = null;
10217
10218 try {
10219 session = openSession();
10220
10221 Query q = session.createQuery(sql);
10222
10223 QueryPos qPos = QueryPos.getInstance(q);
10224
10225 qPos.add(groupId);
10226
10227 qPos.add(categoryId);
10228
10229 qPos.add(status);
10230
10231 count = (Long)q.uniqueResult();
10232
10233 FinderCacheUtil.putResult(finderPath, finderArgs, count);
10234 }
10235 catch (Exception e) {
10236 FinderCacheUtil.removeResult(finderPath, finderArgs);
10237
10238 throw processException(e);
10239 }
10240 finally {
10241 closeSession(session);
10242 }
10243 }
10244
10245 return count.intValue();
10246 }
10247
10248
10257 public int filterCountByG_NotC_S(long groupId, long categoryId, int status)
10258 throws SystemException {
10259 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10260 return countByG_NotC_S(groupId, categoryId, status);
10261 }
10262
10263 StringBundler query = new StringBundler(4);
10264
10265 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10266
10267 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10268
10269 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10270
10271 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10272
10273 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10274 MBThread.class.getName(),
10275 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10276
10277 Session session = null;
10278
10279 try {
10280 session = openSession();
10281
10282 SQLQuery q = session.createSQLQuery(sql);
10283
10284 q.addScalar(COUNT_COLUMN_NAME,
10285 com.liferay.portal.kernel.dao.orm.Type.LONG);
10286
10287 QueryPos qPos = QueryPos.getInstance(q);
10288
10289 qPos.add(groupId);
10290
10291 qPos.add(categoryId);
10292
10293 qPos.add(status);
10294
10295 Long count = (Long)q.uniqueResult();
10296
10297 return count.intValue();
10298 }
10299 catch (Exception e) {
10300 throw processException(e);
10301 }
10302 finally {
10303 closeSession(session);
10304 }
10305 }
10306
10307 private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
10308 private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
10309 private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
10310 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS =
10311 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10312 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
10313 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_NotS",
10314 new String[] {
10315 Long.class.getName(), Long.class.getName(),
10316 Integer.class.getName(),
10317
10318 Integer.class.getName(), Integer.class.getName(),
10319 OrderByComparator.class.getName()
10320 });
10321 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS =
10322 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10323 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
10324 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_NotS",
10325 new String[] {
10326 Long.class.getName(), Long.class.getName(),
10327 Integer.class.getName()
10328 });
10329
10330
10339 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
10340 int status) throws SystemException {
10341 return findByG_NotC_NotS(groupId, categoryId, status,
10342 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10343 }
10344
10345
10360 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
10361 int status, int start, int end) throws SystemException {
10362 return findByG_NotC_NotS(groupId, categoryId, status, start, end, null);
10363 }
10364
10365
10381 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
10382 int status, int start, int end, OrderByComparator orderByComparator)
10383 throws SystemException {
10384 boolean pagination = true;
10385 FinderPath finderPath = null;
10386 Object[] finderArgs = null;
10387
10388 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS;
10389 finderArgs = new Object[] {
10390 groupId, categoryId, status,
10391
10392 start, end, orderByComparator
10393 };
10394
10395 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
10396 finderArgs, this);
10397
10398 if ((list != null) && !list.isEmpty()) {
10399 for (MBThread mbThread : list) {
10400 if ((groupId != mbThread.getGroupId()) ||
10401 (categoryId != mbThread.getCategoryId()) ||
10402 (status != mbThread.getStatus())) {
10403 list = null;
10404
10405 break;
10406 }
10407 }
10408 }
10409
10410 if (list == null) {
10411 StringBundler query = null;
10412
10413 if (orderByComparator != null) {
10414 query = new StringBundler(5 +
10415 (orderByComparator.getOrderByFields().length * 3));
10416 }
10417 else {
10418 query = new StringBundler(5);
10419 }
10420
10421 query.append(_SQL_SELECT_MBTHREAD_WHERE);
10422
10423 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
10424
10425 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
10426
10427 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
10428
10429 if (orderByComparator != null) {
10430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10431 orderByComparator);
10432 }
10433 else
10434 if (pagination) {
10435 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10436 }
10437
10438 String sql = query.toString();
10439
10440 Session session = null;
10441
10442 try {
10443 session = openSession();
10444
10445 Query q = session.createQuery(sql);
10446
10447 QueryPos qPos = QueryPos.getInstance(q);
10448
10449 qPos.add(groupId);
10450
10451 qPos.add(categoryId);
10452
10453 qPos.add(status);
10454
10455 if (!pagination) {
10456 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10457 start, end, false);
10458
10459 Collections.sort(list);
10460
10461 list = new UnmodifiableList<MBThread>(list);
10462 }
10463 else {
10464 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10465 start, end);
10466 }
10467
10468 cacheResult(list);
10469
10470 FinderCacheUtil.putResult(finderPath, finderArgs, list);
10471 }
10472 catch (Exception e) {
10473 FinderCacheUtil.removeResult(finderPath, finderArgs);
10474
10475 throw processException(e);
10476 }
10477 finally {
10478 closeSession(session);
10479 }
10480 }
10481
10482 return list;
10483 }
10484
10485
10496 public MBThread findByG_NotC_NotS_First(long groupId, long categoryId,
10497 int status, OrderByComparator orderByComparator)
10498 throws NoSuchThreadException, SystemException {
10499 MBThread mbThread = fetchByG_NotC_NotS_First(groupId, categoryId,
10500 status, orderByComparator);
10501
10502 if (mbThread != null) {
10503 return mbThread;
10504 }
10505
10506 StringBundler msg = new StringBundler(8);
10507
10508 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10509
10510 msg.append("groupId=");
10511 msg.append(groupId);
10512
10513 msg.append(", categoryId=");
10514 msg.append(categoryId);
10515
10516 msg.append(", status=");
10517 msg.append(status);
10518
10519 msg.append(StringPool.CLOSE_CURLY_BRACE);
10520
10521 throw new NoSuchThreadException(msg.toString());
10522 }
10523
10524
10534 public MBThread fetchByG_NotC_NotS_First(long groupId, long categoryId,
10535 int status, OrderByComparator orderByComparator)
10536 throws SystemException {
10537 List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status, 0,
10538 1, orderByComparator);
10539
10540 if (!list.isEmpty()) {
10541 return list.get(0);
10542 }
10543
10544 return null;
10545 }
10546
10547
10558 public MBThread findByG_NotC_NotS_Last(long groupId, long categoryId,
10559 int status, OrderByComparator orderByComparator)
10560 throws NoSuchThreadException, SystemException {
10561 MBThread mbThread = fetchByG_NotC_NotS_Last(groupId, categoryId,
10562 status, orderByComparator);
10563
10564 if (mbThread != null) {
10565 return mbThread;
10566 }
10567
10568 StringBundler msg = new StringBundler(8);
10569
10570 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10571
10572 msg.append("groupId=");
10573 msg.append(groupId);
10574
10575 msg.append(", categoryId=");
10576 msg.append(categoryId);
10577
10578 msg.append(", status=");
10579 msg.append(status);
10580
10581 msg.append(StringPool.CLOSE_CURLY_BRACE);
10582
10583 throw new NoSuchThreadException(msg.toString());
10584 }
10585
10586
10596 public MBThread fetchByG_NotC_NotS_Last(long groupId, long categoryId,
10597 int status, OrderByComparator orderByComparator)
10598 throws SystemException {
10599 int count = countByG_NotC_NotS(groupId, categoryId, status);
10600
10601 List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status,
10602 count - 1, count, orderByComparator);
10603
10604 if (!list.isEmpty()) {
10605 return list.get(0);
10606 }
10607
10608 return null;
10609 }
10610
10611
10623 public MBThread[] findByG_NotC_NotS_PrevAndNext(long threadId,
10624 long groupId, long categoryId, int status,
10625 OrderByComparator orderByComparator)
10626 throws NoSuchThreadException, SystemException {
10627 MBThread mbThread = findByPrimaryKey(threadId);
10628
10629 Session session = null;
10630
10631 try {
10632 session = openSession();
10633
10634 MBThread[] array = new MBThreadImpl[3];
10635
10636 array[0] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
10637 categoryId, status, orderByComparator, true);
10638
10639 array[1] = mbThread;
10640
10641 array[2] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
10642 categoryId, status, orderByComparator, false);
10643
10644 return array;
10645 }
10646 catch (Exception e) {
10647 throw processException(e);
10648 }
10649 finally {
10650 closeSession(session);
10651 }
10652 }
10653
10654 protected MBThread getByG_NotC_NotS_PrevAndNext(Session session,
10655 MBThread mbThread, long groupId, long categoryId, int status,
10656 OrderByComparator orderByComparator, boolean previous) {
10657 StringBundler query = null;
10658
10659 if (orderByComparator != null) {
10660 query = new StringBundler(6 +
10661 (orderByComparator.getOrderByFields().length * 6));
10662 }
10663 else {
10664 query = new StringBundler(3);
10665 }
10666
10667 query.append(_SQL_SELECT_MBTHREAD_WHERE);
10668
10669 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
10670
10671 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
10672
10673 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
10674
10675 if (orderByComparator != null) {
10676 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10677
10678 if (orderByConditionFields.length > 0) {
10679 query.append(WHERE_AND);
10680 }
10681
10682 for (int i = 0; i < orderByConditionFields.length; i++) {
10683 query.append(_ORDER_BY_ENTITY_ALIAS);
10684 query.append(orderByConditionFields[i]);
10685
10686 if ((i + 1) < orderByConditionFields.length) {
10687 if (orderByComparator.isAscending() ^ previous) {
10688 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10689 }
10690 else {
10691 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10692 }
10693 }
10694 else {
10695 if (orderByComparator.isAscending() ^ previous) {
10696 query.append(WHERE_GREATER_THAN);
10697 }
10698 else {
10699 query.append(WHERE_LESSER_THAN);
10700 }
10701 }
10702 }
10703
10704 query.append(ORDER_BY_CLAUSE);
10705
10706 String[] orderByFields = orderByComparator.getOrderByFields();
10707
10708 for (int i = 0; i < orderByFields.length; i++) {
10709 query.append(_ORDER_BY_ENTITY_ALIAS);
10710 query.append(orderByFields[i]);
10711
10712 if ((i + 1) < orderByFields.length) {
10713 if (orderByComparator.isAscending() ^ previous) {
10714 query.append(ORDER_BY_ASC_HAS_NEXT);
10715 }
10716 else {
10717 query.append(ORDER_BY_DESC_HAS_NEXT);
10718 }
10719 }
10720 else {
10721 if (orderByComparator.isAscending() ^ previous) {
10722 query.append(ORDER_BY_ASC);
10723 }
10724 else {
10725 query.append(ORDER_BY_DESC);
10726 }
10727 }
10728 }
10729 }
10730 else {
10731 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10732 }
10733
10734 String sql = query.toString();
10735
10736 Query q = session.createQuery(sql);
10737
10738 q.setFirstResult(0);
10739 q.setMaxResults(2);
10740
10741 QueryPos qPos = QueryPos.getInstance(q);
10742
10743 qPos.add(groupId);
10744
10745 qPos.add(categoryId);
10746
10747 qPos.add(status);
10748
10749 if (orderByComparator != null) {
10750 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
10751
10752 for (Object value : values) {
10753 qPos.add(value);
10754 }
10755 }
10756
10757 List<MBThread> list = q.list();
10758
10759 if (list.size() == 2) {
10760 return list.get(1);
10761 }
10762 else {
10763 return null;
10764 }
10765 }
10766
10767
10776 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
10777 long categoryId, int status) throws SystemException {
10778 return filterFindByG_NotC_NotS(groupId, categoryId, status,
10779 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10780 }
10781
10782
10797 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
10798 long categoryId, int status, int start, int end)
10799 throws SystemException {
10800 return filterFindByG_NotC_NotS(groupId, categoryId, status, start, end,
10801 null);
10802 }
10803
10804
10820 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
10821 long categoryId, int status, int start, int end,
10822 OrderByComparator orderByComparator) throws SystemException {
10823 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10824 return findByG_NotC_NotS(groupId, categoryId, status, start, end,
10825 orderByComparator);
10826 }
10827
10828 StringBundler query = null;
10829
10830 if (orderByComparator != null) {
10831 query = new StringBundler(5 +
10832 (orderByComparator.getOrderByFields().length * 3));
10833 }
10834 else {
10835 query = new StringBundler(5);
10836 }
10837
10838 if (getDB().isSupportsInlineDistinct()) {
10839 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10840 }
10841 else {
10842 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10843 }
10844
10845 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
10846
10847 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
10848
10849 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
10850
10851 if (!getDB().isSupportsInlineDistinct()) {
10852 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10853 }
10854
10855 if (orderByComparator != null) {
10856 if (getDB().isSupportsInlineDistinct()) {
10857 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10858 orderByComparator);
10859 }
10860 else {
10861 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10862 orderByComparator);
10863 }
10864 }
10865 else {
10866 if (getDB().isSupportsInlineDistinct()) {
10867 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10868 }
10869 else {
10870 query.append(MBThreadModelImpl.ORDER_BY_SQL);
10871 }
10872 }
10873
10874 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10875 MBThread.class.getName(),
10876 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10877
10878 Session session = null;
10879
10880 try {
10881 session = openSession();
10882
10883 SQLQuery q = session.createSQLQuery(sql);
10884
10885 if (getDB().isSupportsInlineDistinct()) {
10886 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10887 }
10888 else {
10889 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10890 }
10891
10892 QueryPos qPos = QueryPos.getInstance(q);
10893
10894 qPos.add(groupId);
10895
10896 qPos.add(categoryId);
10897
10898 qPos.add(status);
10899
10900 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
10901 }
10902 catch (Exception e) {
10903 throw processException(e);
10904 }
10905 finally {
10906 closeSession(session);
10907 }
10908 }
10909
10910
10922 public MBThread[] filterFindByG_NotC_NotS_PrevAndNext(long threadId,
10923 long groupId, long categoryId, int status,
10924 OrderByComparator orderByComparator)
10925 throws NoSuchThreadException, SystemException {
10926 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10927 return findByG_NotC_NotS_PrevAndNext(threadId, groupId, categoryId,
10928 status, orderByComparator);
10929 }
10930
10931 MBThread mbThread = findByPrimaryKey(threadId);
10932
10933 Session session = null;
10934
10935 try {
10936 session = openSession();
10937
10938 MBThread[] array = new MBThreadImpl[3];
10939
10940 array[0] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
10941 groupId, categoryId, status, orderByComparator, true);
10942
10943 array[1] = mbThread;
10944
10945 array[2] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
10946 groupId, categoryId, status, orderByComparator, false);
10947
10948 return array;
10949 }
10950 catch (Exception e) {
10951 throw processException(e);
10952 }
10953 finally {
10954 closeSession(session);
10955 }
10956 }
10957
10958 protected MBThread filterGetByG_NotC_NotS_PrevAndNext(Session session,
10959 MBThread mbThread, long groupId, long categoryId, int status,
10960 OrderByComparator orderByComparator, boolean previous) {
10961 StringBundler query = null;
10962
10963 if (orderByComparator != null) {
10964 query = new StringBundler(6 +
10965 (orderByComparator.getOrderByFields().length * 6));
10966 }
10967 else {
10968 query = new StringBundler(3);
10969 }
10970
10971 if (getDB().isSupportsInlineDistinct()) {
10972 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10973 }
10974 else {
10975 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10976 }
10977
10978 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
10979
10980 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
10981
10982 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
10983
10984 if (!getDB().isSupportsInlineDistinct()) {
10985 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10986 }
10987
10988 if (orderByComparator != null) {
10989 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10990
10991 if (orderByConditionFields.length > 0) {
10992 query.append(WHERE_AND);
10993 }
10994
10995 for (int i = 0; i < orderByConditionFields.length; i++) {
10996 if (getDB().isSupportsInlineDistinct()) {
10997 query.append(_ORDER_BY_ENTITY_ALIAS);
10998 }
10999 else {
11000 query.append(_ORDER_BY_ENTITY_TABLE);
11001 }
11002
11003 query.append(orderByConditionFields[i]);
11004
11005 if ((i + 1) < orderByConditionFields.length) {
11006 if (orderByComparator.isAscending() ^ previous) {
11007 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11008 }
11009 else {
11010 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11011 }
11012 }
11013 else {
11014 if (orderByComparator.isAscending() ^ previous) {
11015 query.append(WHERE_GREATER_THAN);
11016 }
11017 else {
11018 query.append(WHERE_LESSER_THAN);
11019 }
11020 }
11021 }
11022
11023 query.append(ORDER_BY_CLAUSE);
11024
11025 String[] orderByFields = orderByComparator.getOrderByFields();
11026
11027 for (int i = 0; i < orderByFields.length; i++) {
11028 if (getDB().isSupportsInlineDistinct()) {
11029 query.append(_ORDER_BY_ENTITY_ALIAS);
11030 }
11031 else {
11032 query.append(_ORDER_BY_ENTITY_TABLE);
11033 }
11034
11035 query.append(orderByFields[i]);
11036
11037 if ((i + 1) < orderByFields.length) {
11038 if (orderByComparator.isAscending() ^ previous) {
11039 query.append(ORDER_BY_ASC_HAS_NEXT);
11040 }
11041 else {
11042 query.append(ORDER_BY_DESC_HAS_NEXT);
11043 }
11044 }
11045 else {
11046 if (orderByComparator.isAscending() ^ previous) {
11047 query.append(ORDER_BY_ASC);
11048 }
11049 else {
11050 query.append(ORDER_BY_DESC);
11051 }
11052 }
11053 }
11054 }
11055 else {
11056 if (getDB().isSupportsInlineDistinct()) {
11057 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11058 }
11059 else {
11060 query.append(MBThreadModelImpl.ORDER_BY_SQL);
11061 }
11062 }
11063
11064 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11065 MBThread.class.getName(),
11066 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11067
11068 SQLQuery q = session.createSQLQuery(sql);
11069
11070 q.setFirstResult(0);
11071 q.setMaxResults(2);
11072
11073 if (getDB().isSupportsInlineDistinct()) {
11074 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11075 }
11076 else {
11077 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11078 }
11079
11080 QueryPos qPos = QueryPos.getInstance(q);
11081
11082 qPos.add(groupId);
11083
11084 qPos.add(categoryId);
11085
11086 qPos.add(status);
11087
11088 if (orderByComparator != null) {
11089 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11090
11091 for (Object value : values) {
11092 qPos.add(value);
11093 }
11094 }
11095
11096 List<MBThread> list = q.list();
11097
11098 if (list.size() == 2) {
11099 return list.get(1);
11100 }
11101 else {
11102 return null;
11103 }
11104 }
11105
11106
11114 public void removeByG_NotC_NotS(long groupId, long categoryId, int status)
11115 throws SystemException {
11116 for (MBThread mbThread : findByG_NotC_NotS(groupId, categoryId, status,
11117 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11118 remove(mbThread);
11119 }
11120 }
11121
11122
11131 public int countByG_NotC_NotS(long groupId, long categoryId, int status)
11132 throws SystemException {
11133 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS;
11134
11135 Object[] finderArgs = new Object[] { groupId, categoryId, status };
11136
11137 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11138 this);
11139
11140 if (count == null) {
11141 StringBundler query = new StringBundler(4);
11142
11143 query.append(_SQL_COUNT_MBTHREAD_WHERE);
11144
11145 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11146
11147 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11148
11149 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11150
11151 String sql = query.toString();
11152
11153 Session session = null;
11154
11155 try {
11156 session = openSession();
11157
11158 Query q = session.createQuery(sql);
11159
11160 QueryPos qPos = QueryPos.getInstance(q);
11161
11162 qPos.add(groupId);
11163
11164 qPos.add(categoryId);
11165
11166 qPos.add(status);
11167
11168 count = (Long)q.uniqueResult();
11169
11170 FinderCacheUtil.putResult(finderPath, finderArgs, count);
11171 }
11172 catch (Exception e) {
11173 FinderCacheUtil.removeResult(finderPath, finderArgs);
11174
11175 throw processException(e);
11176 }
11177 finally {
11178 closeSession(session);
11179 }
11180 }
11181
11182 return count.intValue();
11183 }
11184
11185
11194 public int filterCountByG_NotC_NotS(long groupId, long categoryId,
11195 int status) throws SystemException {
11196 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11197 return countByG_NotC_NotS(groupId, categoryId, status);
11198 }
11199
11200 StringBundler query = new StringBundler(4);
11201
11202 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
11203
11204 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11205
11206 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11207
11208 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11209
11210 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11211 MBThread.class.getName(),
11212 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11213
11214 Session session = null;
11215
11216 try {
11217 session = openSession();
11218
11219 SQLQuery q = session.createSQLQuery(sql);
11220
11221 q.addScalar(COUNT_COLUMN_NAME,
11222 com.liferay.portal.kernel.dao.orm.Type.LONG);
11223
11224 QueryPos qPos = QueryPos.getInstance(q);
11225
11226 qPos.add(groupId);
11227
11228 qPos.add(categoryId);
11229
11230 qPos.add(status);
11231
11232 Long count = (Long)q.uniqueResult();
11233
11234 return count.intValue();
11235 }
11236 catch (Exception e) {
11237 throw processException(e);
11238 }
11239 finally {
11240 closeSession(session);
11241 }
11242 }
11243
11244 private static final String _FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
11245 private static final String _FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
11246 private static final String _FINDER_COLUMN_G_NOTC_NOTS_STATUS_2 = "mbThread.status != ?";
11247
11248
11253 public void cacheResult(MBThread mbThread) {
11254 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11255 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
11256
11257 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
11258 new Object[] { Long.valueOf(mbThread.getRootMessageId()) }, mbThread);
11259
11260 mbThread.resetOriginalValues();
11261 }
11262
11263
11268 public void cacheResult(List<MBThread> mbThreads) {
11269 for (MBThread mbThread : mbThreads) {
11270 if (EntityCacheUtil.getResult(
11271 MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11272 MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
11273 cacheResult(mbThread);
11274 }
11275 else {
11276 mbThread.resetOriginalValues();
11277 }
11278 }
11279 }
11280
11281
11288 @Override
11289 public void clearCache() {
11290 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
11291 CacheRegistryUtil.clear(MBThreadImpl.class.getName());
11292 }
11293
11294 EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
11295
11296 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
11297 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11298 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11299 }
11300
11301
11308 @Override
11309 public void clearCache(MBThread mbThread) {
11310 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11311 MBThreadImpl.class, mbThread.getPrimaryKey());
11312
11313 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11315
11316 clearUniqueFindersCache(mbThread);
11317 }
11318
11319 @Override
11320 public void clearCache(List<MBThread> mbThreads) {
11321 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11322 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11323
11324 for (MBThread mbThread : mbThreads) {
11325 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11326 MBThreadImpl.class, mbThread.getPrimaryKey());
11327
11328 clearUniqueFindersCache(mbThread);
11329 }
11330 }
11331
11332 protected void cacheUniqueFindersCache(MBThread mbThread) {
11333 if (mbThread.isNew()) {
11334 Object[] args = new Object[] {
11335 Long.valueOf(mbThread.getRootMessageId())
11336 };
11337
11338 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args,
11339 Long.valueOf(1));
11340 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args,
11341 mbThread);
11342 }
11343 else {
11344 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
11345
11346 if ((mbThreadModelImpl.getColumnBitmask() &
11347 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
11348 Object[] args = new Object[] {
11349 Long.valueOf(mbThread.getRootMessageId())
11350 };
11351
11352 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
11353 args, Long.valueOf(1));
11354 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
11355 args, mbThread);
11356 }
11357 }
11358 }
11359
11360 protected void clearUniqueFindersCache(MBThread mbThread) {
11361 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
11362
11363 Object[] args = new Object[] { Long.valueOf(mbThread.getRootMessageId()) };
11364
11365 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args);
11366 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args);
11367
11368 if ((mbThreadModelImpl.getColumnBitmask() &
11369 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
11370 args = new Object[] {
11371 Long.valueOf(mbThreadModelImpl.getOriginalRootMessageId())
11372 };
11373
11374 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
11375 args);
11376 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
11377 args);
11378 }
11379 }
11380
11381
11387 public MBThread create(long threadId) {
11388 MBThread mbThread = new MBThreadImpl();
11389
11390 mbThread.setNew(true);
11391 mbThread.setPrimaryKey(threadId);
11392
11393 return mbThread;
11394 }
11395
11396
11404 public MBThread remove(long threadId)
11405 throws NoSuchThreadException, SystemException {
11406 return remove(Long.valueOf(threadId));
11407 }
11408
11409
11417 @Override
11418 public MBThread remove(Serializable primaryKey)
11419 throws NoSuchThreadException, SystemException {
11420 Session session = null;
11421
11422 try {
11423 session = openSession();
11424
11425 MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
11426 primaryKey);
11427
11428 if (mbThread == null) {
11429 if (_log.isWarnEnabled()) {
11430 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
11431 }
11432
11433 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11434 primaryKey);
11435 }
11436
11437 return remove(mbThread);
11438 }
11439 catch (NoSuchThreadException nsee) {
11440 throw nsee;
11441 }
11442 catch (Exception e) {
11443 throw processException(e);
11444 }
11445 finally {
11446 closeSession(session);
11447 }
11448 }
11449
11450 @Override
11451 protected MBThread removeImpl(MBThread mbThread) throws SystemException {
11452 mbThread = toUnwrappedModel(mbThread);
11453
11454 Session session = null;
11455
11456 try {
11457 session = openSession();
11458
11459 if (!session.contains(mbThread)) {
11460 mbThread = (MBThread)session.get(MBThreadImpl.class,
11461 mbThread.getPrimaryKeyObj());
11462 }
11463
11464 if (mbThread != null) {
11465 session.delete(mbThread);
11466 }
11467 }
11468 catch (Exception e) {
11469 throw processException(e);
11470 }
11471 finally {
11472 closeSession(session);
11473 }
11474
11475 if (mbThread != null) {
11476 clearCache(mbThread);
11477 }
11478
11479 return mbThread;
11480 }
11481
11482 @Override
11483 public MBThread updateImpl(
11484 com.liferay.portlet.messageboards.model.MBThread mbThread)
11485 throws SystemException {
11486 mbThread = toUnwrappedModel(mbThread);
11487
11488 boolean isNew = mbThread.isNew();
11489
11490 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
11491
11492 Session session = null;
11493
11494 try {
11495 session = openSession();
11496
11497 if (mbThread.isNew()) {
11498 session.save(mbThread);
11499
11500 mbThread.setNew(false);
11501 }
11502 else {
11503 session.merge(mbThread);
11504 }
11505 }
11506 catch (Exception e) {
11507 throw processException(e);
11508 }
11509 finally {
11510 closeSession(session);
11511 }
11512
11513 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
11514
11515 if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
11516 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
11517 }
11518
11519 else {
11520 if ((mbThreadModelImpl.getColumnBitmask() &
11521 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
11522 Object[] args = new Object[] {
11523 Long.valueOf(mbThreadModelImpl.getOriginalGroupId())
11524 };
11525
11526 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11527 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11528 args);
11529
11530 args = new Object[] { Long.valueOf(mbThreadModelImpl.getGroupId()) };
11531
11532 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
11533 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
11534 args);
11535 }
11536
11537 if ((mbThreadModelImpl.getColumnBitmask() &
11538 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
11539 Object[] args = new Object[] {
11540 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
11541 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId())
11542 };
11543
11544 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
11545 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
11546 args);
11547
11548 args = new Object[] {
11549 Long.valueOf(mbThreadModelImpl.getGroupId()),
11550 Long.valueOf(mbThreadModelImpl.getCategoryId())
11551 };
11552
11553 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
11554 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
11555 args);
11556 }
11557
11558 if ((mbThreadModelImpl.getColumnBitmask() &
11559 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
11560 Object[] args = new Object[] {
11561 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
11562 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
11563 };
11564
11565 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
11566 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
11567 args);
11568
11569 args = new Object[] {
11570 Long.valueOf(mbThreadModelImpl.getGroupId()),
11571 Integer.valueOf(mbThreadModelImpl.getStatus())
11572 };
11573
11574 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
11575 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
11576 args);
11577 }
11578
11579 if ((mbThreadModelImpl.getColumnBitmask() &
11580 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
11581 Object[] args = new Object[] {
11582 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
11583 Double.valueOf(mbThreadModelImpl.getOriginalPriority())
11584 };
11585
11586 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
11587 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
11588 args);
11589
11590 args = new Object[] {
11591 Long.valueOf(mbThreadModelImpl.getCategoryId()),
11592 Double.valueOf(mbThreadModelImpl.getPriority())
11593 };
11594
11595 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
11596 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
11597 args);
11598 }
11599
11600 if ((mbThreadModelImpl.getColumnBitmask() &
11601 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
11602 Object[] args = new Object[] {
11603 mbThreadModelImpl.getOriginalLastPostDate(),
11604 Double.valueOf(mbThreadModelImpl.getOriginalPriority())
11605 };
11606
11607 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
11608 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
11609 args);
11610
11611 args = new Object[] {
11612 mbThreadModelImpl.getLastPostDate(),
11613 Double.valueOf(mbThreadModelImpl.getPriority())
11614 };
11615
11616 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
11617 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
11618 args);
11619 }
11620
11621 if ((mbThreadModelImpl.getColumnBitmask() &
11622 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
11623 Object[] args = new Object[] {
11624 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
11625 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
11626
11627 mbThreadModelImpl.getOriginalLastPostDate()
11628 };
11629
11630 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
11631 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
11632 args);
11633
11634 args = new Object[] {
11635 Long.valueOf(mbThreadModelImpl.getGroupId()),
11636 Long.valueOf(mbThreadModelImpl.getCategoryId()),
11637
11638 mbThreadModelImpl.getLastPostDate()
11639 };
11640
11641 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
11642 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
11643 args);
11644 }
11645
11646 if ((mbThreadModelImpl.getColumnBitmask() &
11647 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
11648 Object[] args = new Object[] {
11649 Long.valueOf(mbThreadModelImpl.getOriginalGroupId()),
11650 Long.valueOf(mbThreadModelImpl.getOriginalCategoryId()),
11651 Integer.valueOf(mbThreadModelImpl.getOriginalStatus())
11652 };
11653
11654 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
11655 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
11656 args);
11657
11658 args = new Object[] {
11659 Long.valueOf(mbThreadModelImpl.getGroupId()),
11660 Long.valueOf(mbThreadModelImpl.getCategoryId()),
11661 Integer.valueOf(mbThreadModelImpl.getStatus())
11662 };
11663
11664 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
11665 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
11666 args);
11667 }
11668 }
11669
11670 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11671 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
11672
11673 clearUniqueFindersCache(mbThread);
11674 cacheUniqueFindersCache(mbThread);
11675
11676 return mbThread;
11677 }
11678
11679 protected MBThread toUnwrappedModel(MBThread mbThread) {
11680 if (mbThread instanceof MBThreadImpl) {
11681 return mbThread;
11682 }
11683
11684 MBThreadImpl mbThreadImpl = new MBThreadImpl();
11685
11686 mbThreadImpl.setNew(mbThread.isNew());
11687 mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
11688
11689 mbThreadImpl.setThreadId(mbThread.getThreadId());
11690 mbThreadImpl.setGroupId(mbThread.getGroupId());
11691 mbThreadImpl.setCompanyId(mbThread.getCompanyId());
11692 mbThreadImpl.setCategoryId(mbThread.getCategoryId());
11693 mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
11694 mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
11695 mbThreadImpl.setMessageCount(mbThread.getMessageCount());
11696 mbThreadImpl.setViewCount(mbThread.getViewCount());
11697 mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
11698 mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
11699 mbThreadImpl.setPriority(mbThread.getPriority());
11700 mbThreadImpl.setQuestion(mbThread.isQuestion());
11701 mbThreadImpl.setStatus(mbThread.getStatus());
11702 mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
11703 mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
11704 mbThreadImpl.setStatusDate(mbThread.getStatusDate());
11705
11706 return mbThreadImpl;
11707 }
11708
11709
11717 @Override
11718 public MBThread findByPrimaryKey(Serializable primaryKey)
11719 throws NoSuchModelException, SystemException {
11720 return findByPrimaryKey(((Long)primaryKey).longValue());
11721 }
11722
11723
11731 public MBThread findByPrimaryKey(long threadId)
11732 throws NoSuchThreadException, SystemException {
11733 MBThread mbThread = fetchByPrimaryKey(threadId);
11734
11735 if (mbThread == null) {
11736 if (_log.isWarnEnabled()) {
11737 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadId);
11738 }
11739
11740 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
11741 threadId);
11742 }
11743
11744 return mbThread;
11745 }
11746
11747
11754 @Override
11755 public MBThread fetchByPrimaryKey(Serializable primaryKey)
11756 throws SystemException {
11757 return fetchByPrimaryKey(((Long)primaryKey).longValue());
11758 }
11759
11760
11767 public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
11768 MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11769 MBThreadImpl.class, threadId);
11770
11771 if (mbThread == _nullMBThread) {
11772 return null;
11773 }
11774
11775 if (mbThread == null) {
11776 Session session = null;
11777
11778 try {
11779 session = openSession();
11780
11781 mbThread = (MBThread)session.get(MBThreadImpl.class,
11782 Long.valueOf(threadId));
11783
11784 if (mbThread != null) {
11785 cacheResult(mbThread);
11786 }
11787 else {
11788 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11789 MBThreadImpl.class, threadId, _nullMBThread);
11790 }
11791 }
11792 catch (Exception e) {
11793 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11794 MBThreadImpl.class, threadId);
11795
11796 throw processException(e);
11797 }
11798 finally {
11799 closeSession(session);
11800 }
11801 }
11802
11803 return mbThread;
11804 }
11805
11806
11812 public List<MBThread> findAll() throws SystemException {
11813 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11814 }
11815
11816
11828 public List<MBThread> findAll(int start, int end) throws SystemException {
11829 return findAll(start, end, null);
11830 }
11831
11832
11845 public List<MBThread> findAll(int start, int end,
11846 OrderByComparator orderByComparator) throws SystemException {
11847 boolean pagination = true;
11848 FinderPath finderPath = null;
11849 Object[] finderArgs = null;
11850
11851 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11852 (orderByComparator == null)) {
11853 pagination = false;
11854 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
11855 finderArgs = FINDER_ARGS_EMPTY;
11856 }
11857 else {
11858 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
11859 finderArgs = new Object[] { start, end, orderByComparator };
11860 }
11861
11862 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
11863 finderArgs, this);
11864
11865 if (list == null) {
11866 StringBundler query = null;
11867 String sql = null;
11868
11869 if (orderByComparator != null) {
11870 query = new StringBundler(2 +
11871 (orderByComparator.getOrderByFields().length * 3));
11872
11873 query.append(_SQL_SELECT_MBTHREAD);
11874
11875 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11876 orderByComparator);
11877
11878 sql = query.toString();
11879 }
11880 else {
11881 sql = _SQL_SELECT_MBTHREAD;
11882
11883 if (pagination) {
11884 sql = sql.concat(MBThreadModelImpl.ORDER_BY_JPQL);
11885 }
11886 }
11887
11888 Session session = null;
11889
11890 try {
11891 session = openSession();
11892
11893 Query q = session.createQuery(sql);
11894
11895 if (!pagination) {
11896 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11897 start, end, false);
11898
11899 Collections.sort(list);
11900
11901 list = new UnmodifiableList<MBThread>(list);
11902 }
11903 else {
11904 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11905 start, end);
11906 }
11907
11908 cacheResult(list);
11909
11910 FinderCacheUtil.putResult(finderPath, finderArgs, list);
11911 }
11912 catch (Exception e) {
11913 FinderCacheUtil.removeResult(finderPath, finderArgs);
11914
11915 throw processException(e);
11916 }
11917 finally {
11918 closeSession(session);
11919 }
11920 }
11921
11922 return list;
11923 }
11924
11925
11930 public void removeAll() throws SystemException {
11931 for (MBThread mbThread : findAll()) {
11932 remove(mbThread);
11933 }
11934 }
11935
11936
11942 public int countAll() throws SystemException {
11943 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
11944 FINDER_ARGS_EMPTY, this);
11945
11946 if (count == null) {
11947 Session session = null;
11948
11949 try {
11950 session = openSession();
11951
11952 Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
11953
11954 count = (Long)q.uniqueResult();
11955
11956 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
11957 FINDER_ARGS_EMPTY, count);
11958 }
11959 catch (Exception e) {
11960 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
11961 FINDER_ARGS_EMPTY);
11962
11963 throw processException(e);
11964 }
11965 finally {
11966 closeSession(session);
11967 }
11968 }
11969
11970 return count.intValue();
11971 }
11972
11973
11976 public void afterPropertiesSet() {
11977 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
11978 com.liferay.portal.util.PropsUtil.get(
11979 "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
11980
11981 if (listenerClassNames.length > 0) {
11982 try {
11983 List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
11984
11985 for (String listenerClassName : listenerClassNames) {
11986 listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
11987 listenerClassName));
11988 }
11989
11990 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
11991 }
11992 catch (Exception e) {
11993 _log.error(e);
11994 }
11995 }
11996 }
11997
11998 public void destroy() {
11999 EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
12000 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
12001 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12002 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12003 }
12004
12005 private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
12006 private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
12007 private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
12008 private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
12009
12010 private static String _removeConjunction(String sql) {
12011 int pos = sql.indexOf(" AND ");
12012
12013 if (pos != -1) {
12014 sql = sql.substring(0, pos);
12015 }
12016
12017 return sql;
12018 }
12019
12020 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
12021 private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
12022 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
12023 "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
12024 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
12025 ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
12026 private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
12027 private static final String _FILTER_ENTITY_ALIAS = "mbThread";
12028 private static final String _FILTER_ENTITY_TABLE = "MBThread";
12029 private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
12030 private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
12031 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
12032 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
12033 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
12034 private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
12035 private static MBThread _nullMBThread = new MBThreadImpl() {
12036 @Override
12037 public Object clone() {
12038 return this;
12039 }
12040
12041 @Override
12042 public CacheModel<MBThread> toCacheModel() {
12043 return _nullMBThreadCacheModel;
12044 }
12045 };
12046
12047 private static CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
12048 public MBThread toEntityModel() {
12049 return _nullMBThread;
12050 }
12051 };
12052 }