001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.SQLQuery;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.ArrayUtil;
030 import com.liferay.portal.kernel.util.CalendarUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.SetUtil;
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.kernel.uuid.PortalUUIDUtil;
041 import com.liferay.portal.model.CacheModel;
042 import com.liferay.portal.model.ModelListener;
043 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import com.liferay.portlet.messageboards.NoSuchThreadException;
047 import com.liferay.portlet.messageboards.model.MBThread;
048 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
049 import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
050
051 import java.io.Serializable;
052
053 import java.util.ArrayList;
054 import java.util.Collections;
055 import java.util.Date;
056 import java.util.List;
057 import java.util.Set;
058
059
071 public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
072 implements MBThreadPersistence {
073
078 public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
079 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List1";
081 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List2";
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
084 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
087 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
090 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
093 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
094 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
095 new String[] {
096 String.class.getName(),
097
098 Integer.class.getName(), Integer.class.getName(),
099 OrderByComparator.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
102 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
104 new String[] { String.class.getName() },
105 MBThreadModelImpl.UUID_COLUMN_BITMASK |
106 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
107 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
108 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
109 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111 new String[] { String.class.getName() });
112
113
120 @Override
121 public List<MBThread> findByUuid(String uuid) throws SystemException {
122 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
138 @Override
139 public List<MBThread> findByUuid(String uuid, int start, int end)
140 throws SystemException {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
158 @Override
159 public List<MBThread> findByUuid(String uuid, int start, int end,
160 OrderByComparator orderByComparator) throws SystemException {
161 boolean pagination = true;
162 FinderPath finderPath = null;
163 Object[] finderArgs = null;
164
165 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
166 (orderByComparator == null)) {
167 pagination = false;
168 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
169 finderArgs = new Object[] { uuid };
170 }
171 else {
172 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
173 finderArgs = new Object[] { uuid, start, end, orderByComparator };
174 }
175
176 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (MBThread mbThread : list) {
181 if (!Validator.equals(uuid, mbThread.getUuid())) {
182 list = null;
183
184 break;
185 }
186 }
187 }
188
189 if (list == null) {
190 StringBundler query = null;
191
192 if (orderByComparator != null) {
193 query = new StringBundler(3 +
194 (orderByComparator.getOrderByFields().length * 3));
195 }
196 else {
197 query = new StringBundler(3);
198 }
199
200 query.append(_SQL_SELECT_MBTHREAD_WHERE);
201
202 boolean bindUuid = false;
203
204 if (uuid == null) {
205 query.append(_FINDER_COLUMN_UUID_UUID_1);
206 }
207 else if (uuid.equals(StringPool.BLANK)) {
208 query.append(_FINDER_COLUMN_UUID_UUID_3);
209 }
210 else {
211 bindUuid = true;
212
213 query.append(_FINDER_COLUMN_UUID_UUID_2);
214 }
215
216 if (orderByComparator != null) {
217 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
218 orderByComparator);
219 }
220 else
221 if (pagination) {
222 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
223 }
224
225 String sql = query.toString();
226
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 Query q = session.createQuery(sql);
233
234 QueryPos qPos = QueryPos.getInstance(q);
235
236 if (bindUuid) {
237 qPos.add(uuid);
238 }
239
240 if (!pagination) {
241 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
242 start, end, false);
243
244 Collections.sort(list);
245
246 list = new UnmodifiableList<MBThread>(list);
247 }
248 else {
249 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
250 start, end);
251 }
252
253 cacheResult(list);
254
255 FinderCacheUtil.putResult(finderPath, finderArgs, list);
256 }
257 catch (Exception e) {
258 FinderCacheUtil.removeResult(finderPath, finderArgs);
259
260 throw processException(e);
261 }
262 finally {
263 closeSession(session);
264 }
265 }
266
267 return list;
268 }
269
270
279 @Override
280 public MBThread findByUuid_First(String uuid,
281 OrderByComparator orderByComparator)
282 throws NoSuchThreadException, SystemException {
283 MBThread mbThread = fetchByUuid_First(uuid, orderByComparator);
284
285 if (mbThread != null) {
286 return mbThread;
287 }
288
289 StringBundler msg = new StringBundler(4);
290
291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
292
293 msg.append("uuid=");
294 msg.append(uuid);
295
296 msg.append(StringPool.CLOSE_CURLY_BRACE);
297
298 throw new NoSuchThreadException(msg.toString());
299 }
300
301
309 @Override
310 public MBThread fetchByUuid_First(String uuid,
311 OrderByComparator orderByComparator) throws SystemException {
312 List<MBThread> list = findByUuid(uuid, 0, 1, orderByComparator);
313
314 if (!list.isEmpty()) {
315 return list.get(0);
316 }
317
318 return null;
319 }
320
321
330 @Override
331 public MBThread findByUuid_Last(String uuid,
332 OrderByComparator orderByComparator)
333 throws NoSuchThreadException, SystemException {
334 MBThread mbThread = fetchByUuid_Last(uuid, orderByComparator);
335
336 if (mbThread != null) {
337 return mbThread;
338 }
339
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("uuid=");
345 msg.append(uuid);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchThreadException(msg.toString());
350 }
351
352
360 @Override
361 public MBThread fetchByUuid_Last(String uuid,
362 OrderByComparator orderByComparator) throws SystemException {
363 int count = countByUuid(uuid);
364
365 if (count == 0) {
366 return null;
367 }
368
369 List<MBThread> list = findByUuid(uuid, count - 1, count,
370 orderByComparator);
371
372 if (!list.isEmpty()) {
373 return list.get(0);
374 }
375
376 return null;
377 }
378
379
389 @Override
390 public MBThread[] findByUuid_PrevAndNext(long threadId, String uuid,
391 OrderByComparator orderByComparator)
392 throws NoSuchThreadException, SystemException {
393 MBThread mbThread = findByPrimaryKey(threadId);
394
395 Session session = null;
396
397 try {
398 session = openSession();
399
400 MBThread[] array = new MBThreadImpl[3];
401
402 array[0] = getByUuid_PrevAndNext(session, mbThread, uuid,
403 orderByComparator, true);
404
405 array[1] = mbThread;
406
407 array[2] = getByUuid_PrevAndNext(session, mbThread, uuid,
408 orderByComparator, false);
409
410 return array;
411 }
412 catch (Exception e) {
413 throw processException(e);
414 }
415 finally {
416 closeSession(session);
417 }
418 }
419
420 protected MBThread getByUuid_PrevAndNext(Session session,
421 MBThread mbThread, String uuid, OrderByComparator orderByComparator,
422 boolean previous) {
423 StringBundler query = null;
424
425 if (orderByComparator != null) {
426 query = new StringBundler(6 +
427 (orderByComparator.getOrderByFields().length * 6));
428 }
429 else {
430 query = new StringBundler(3);
431 }
432
433 query.append(_SQL_SELECT_MBTHREAD_WHERE);
434
435 boolean bindUuid = false;
436
437 if (uuid == null) {
438 query.append(_FINDER_COLUMN_UUID_UUID_1);
439 }
440 else if (uuid.equals(StringPool.BLANK)) {
441 query.append(_FINDER_COLUMN_UUID_UUID_3);
442 }
443 else {
444 bindUuid = true;
445
446 query.append(_FINDER_COLUMN_UUID_UUID_2);
447 }
448
449 if (orderByComparator != null) {
450 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
451
452 if (orderByConditionFields.length > 0) {
453 query.append(WHERE_AND);
454 }
455
456 for (int i = 0; i < orderByConditionFields.length; i++) {
457 query.append(_ORDER_BY_ENTITY_ALIAS);
458 query.append(orderByConditionFields[i]);
459
460 if ((i + 1) < orderByConditionFields.length) {
461 if (orderByComparator.isAscending() ^ previous) {
462 query.append(WHERE_GREATER_THAN_HAS_NEXT);
463 }
464 else {
465 query.append(WHERE_LESSER_THAN_HAS_NEXT);
466 }
467 }
468 else {
469 if (orderByComparator.isAscending() ^ previous) {
470 query.append(WHERE_GREATER_THAN);
471 }
472 else {
473 query.append(WHERE_LESSER_THAN);
474 }
475 }
476 }
477
478 query.append(ORDER_BY_CLAUSE);
479
480 String[] orderByFields = orderByComparator.getOrderByFields();
481
482 for (int i = 0; i < orderByFields.length; i++) {
483 query.append(_ORDER_BY_ENTITY_ALIAS);
484 query.append(orderByFields[i]);
485
486 if ((i + 1) < orderByFields.length) {
487 if (orderByComparator.isAscending() ^ previous) {
488 query.append(ORDER_BY_ASC_HAS_NEXT);
489 }
490 else {
491 query.append(ORDER_BY_DESC_HAS_NEXT);
492 }
493 }
494 else {
495 if (orderByComparator.isAscending() ^ previous) {
496 query.append(ORDER_BY_ASC);
497 }
498 else {
499 query.append(ORDER_BY_DESC);
500 }
501 }
502 }
503 }
504 else {
505 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
506 }
507
508 String sql = query.toString();
509
510 Query q = session.createQuery(sql);
511
512 q.setFirstResult(0);
513 q.setMaxResults(2);
514
515 QueryPos qPos = QueryPos.getInstance(q);
516
517 if (bindUuid) {
518 qPos.add(uuid);
519 }
520
521 if (orderByComparator != null) {
522 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
523
524 for (Object value : values) {
525 qPos.add(value);
526 }
527 }
528
529 List<MBThread> list = q.list();
530
531 if (list.size() == 2) {
532 return list.get(1);
533 }
534 else {
535 return null;
536 }
537 }
538
539
545 @Override
546 public void removeByUuid(String uuid) throws SystemException {
547 for (MBThread mbThread : findByUuid(uuid, QueryUtil.ALL_POS,
548 QueryUtil.ALL_POS, null)) {
549 remove(mbThread);
550 }
551 }
552
553
560 @Override
561 public int countByUuid(String uuid) throws SystemException {
562 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
563
564 Object[] finderArgs = new Object[] { uuid };
565
566 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
567 this);
568
569 if (count == null) {
570 StringBundler query = new StringBundler(2);
571
572 query.append(_SQL_COUNT_MBTHREAD_WHERE);
573
574 boolean bindUuid = false;
575
576 if (uuid == null) {
577 query.append(_FINDER_COLUMN_UUID_UUID_1);
578 }
579 else if (uuid.equals(StringPool.BLANK)) {
580 query.append(_FINDER_COLUMN_UUID_UUID_3);
581 }
582 else {
583 bindUuid = true;
584
585 query.append(_FINDER_COLUMN_UUID_UUID_2);
586 }
587
588 String sql = query.toString();
589
590 Session session = null;
591
592 try {
593 session = openSession();
594
595 Query q = session.createQuery(sql);
596
597 QueryPos qPos = QueryPos.getInstance(q);
598
599 if (bindUuid) {
600 qPos.add(uuid);
601 }
602
603 count = (Long)q.uniqueResult();
604
605 FinderCacheUtil.putResult(finderPath, finderArgs, count);
606 }
607 catch (Exception e) {
608 FinderCacheUtil.removeResult(finderPath, finderArgs);
609
610 throw processException(e);
611 }
612 finally {
613 closeSession(session);
614 }
615 }
616
617 return count.intValue();
618 }
619
620 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbThread.uuid IS NULL";
621 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbThread.uuid = ?";
622 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '')";
623 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
624 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
625 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
626 new String[] { String.class.getName(), Long.class.getName() },
627 MBThreadModelImpl.UUID_COLUMN_BITMASK |
628 MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
629 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
630 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
631 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
632 new String[] { String.class.getName(), Long.class.getName() });
633
634
643 @Override
644 public MBThread findByUUID_G(String uuid, long groupId)
645 throws NoSuchThreadException, SystemException {
646 MBThread mbThread = fetchByUUID_G(uuid, groupId);
647
648 if (mbThread == null) {
649 StringBundler msg = new StringBundler(6);
650
651 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
652
653 msg.append("uuid=");
654 msg.append(uuid);
655
656 msg.append(", groupId=");
657 msg.append(groupId);
658
659 msg.append(StringPool.CLOSE_CURLY_BRACE);
660
661 if (_log.isWarnEnabled()) {
662 _log.warn(msg.toString());
663 }
664
665 throw new NoSuchThreadException(msg.toString());
666 }
667
668 return mbThread;
669 }
670
671
679 @Override
680 public MBThread fetchByUUID_G(String uuid, long groupId)
681 throws SystemException {
682 return fetchByUUID_G(uuid, groupId, true);
683 }
684
685
694 @Override
695 public MBThread fetchByUUID_G(String uuid, long groupId,
696 boolean retrieveFromCache) throws SystemException {
697 Object[] finderArgs = new Object[] { uuid, groupId };
698
699 Object result = null;
700
701 if (retrieveFromCache) {
702 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
703 finderArgs, this);
704 }
705
706 if (result instanceof MBThread) {
707 MBThread mbThread = (MBThread)result;
708
709 if (!Validator.equals(uuid, mbThread.getUuid()) ||
710 (groupId != mbThread.getGroupId())) {
711 result = null;
712 }
713 }
714
715 if (result == null) {
716 StringBundler query = new StringBundler(4);
717
718 query.append(_SQL_SELECT_MBTHREAD_WHERE);
719
720 boolean bindUuid = false;
721
722 if (uuid == null) {
723 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
724 }
725 else if (uuid.equals(StringPool.BLANK)) {
726 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
727 }
728 else {
729 bindUuid = true;
730
731 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
732 }
733
734 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
735
736 String sql = query.toString();
737
738 Session session = null;
739
740 try {
741 session = openSession();
742
743 Query q = session.createQuery(sql);
744
745 QueryPos qPos = QueryPos.getInstance(q);
746
747 if (bindUuid) {
748 qPos.add(uuid);
749 }
750
751 qPos.add(groupId);
752
753 List<MBThread> list = q.list();
754
755 if (list.isEmpty()) {
756 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs, list);
758 }
759 else {
760 MBThread mbThread = list.get(0);
761
762 result = mbThread;
763
764 cacheResult(mbThread);
765
766 if ((mbThread.getUuid() == null) ||
767 !mbThread.getUuid().equals(uuid) ||
768 (mbThread.getGroupId() != groupId)) {
769 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
770 finderArgs, mbThread);
771 }
772 }
773 }
774 catch (Exception e) {
775 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
776 finderArgs);
777
778 throw processException(e);
779 }
780 finally {
781 closeSession(session);
782 }
783 }
784
785 if (result instanceof List<?>) {
786 return null;
787 }
788 else {
789 return (MBThread)result;
790 }
791 }
792
793
801 @Override
802 public MBThread removeByUUID_G(String uuid, long groupId)
803 throws NoSuchThreadException, SystemException {
804 MBThread mbThread = findByUUID_G(uuid, groupId);
805
806 return remove(mbThread);
807 }
808
809
817 @Override
818 public int countByUUID_G(String uuid, long groupId)
819 throws SystemException {
820 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
821
822 Object[] finderArgs = new Object[] { uuid, groupId };
823
824 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
825 this);
826
827 if (count == null) {
828 StringBundler query = new StringBundler(3);
829
830 query.append(_SQL_COUNT_MBTHREAD_WHERE);
831
832 boolean bindUuid = false;
833
834 if (uuid == null) {
835 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
836 }
837 else if (uuid.equals(StringPool.BLANK)) {
838 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
839 }
840 else {
841 bindUuid = true;
842
843 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
844 }
845
846 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
847
848 String sql = query.toString();
849
850 Session session = null;
851
852 try {
853 session = openSession();
854
855 Query q = session.createQuery(sql);
856
857 QueryPos qPos = QueryPos.getInstance(q);
858
859 if (bindUuid) {
860 qPos.add(uuid);
861 }
862
863 qPos.add(groupId);
864
865 count = (Long)q.uniqueResult();
866
867 FinderCacheUtil.putResult(finderPath, finderArgs, count);
868 }
869 catch (Exception e) {
870 FinderCacheUtil.removeResult(finderPath, finderArgs);
871
872 throw processException(e);
873 }
874 finally {
875 closeSession(session);
876 }
877 }
878
879 return count.intValue();
880 }
881
882 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbThread.uuid IS NULL AND ";
883 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbThread.uuid = ? AND ";
884 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
885 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbThread.groupId = ?";
886 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
887 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
888 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
889 new String[] {
890 String.class.getName(), Long.class.getName(),
891
892 Integer.class.getName(), Integer.class.getName(),
893 OrderByComparator.class.getName()
894 });
895 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
896 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
897 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
898 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
899 new String[] { String.class.getName(), Long.class.getName() },
900 MBThreadModelImpl.UUID_COLUMN_BITMASK |
901 MBThreadModelImpl.COMPANYID_COLUMN_BITMASK |
902 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
903 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
904 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
905 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
906 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
907 new String[] { String.class.getName(), Long.class.getName() });
908
909
917 @Override
918 public List<MBThread> findByUuid_C(String uuid, long companyId)
919 throws SystemException {
920 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
921 QueryUtil.ALL_POS, null);
922 }
923
924
938 @Override
939 public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
940 int end) throws SystemException {
941 return findByUuid_C(uuid, companyId, start, end, null);
942 }
943
944
959 @Override
960 public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
961 int end, OrderByComparator orderByComparator) throws SystemException {
962 boolean pagination = true;
963 FinderPath finderPath = null;
964 Object[] finderArgs = null;
965
966 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
967 (orderByComparator == null)) {
968 pagination = false;
969 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
970 finderArgs = new Object[] { uuid, companyId };
971 }
972 else {
973 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
974 finderArgs = new Object[] {
975 uuid, companyId,
976
977 start, end, orderByComparator
978 };
979 }
980
981 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
982 finderArgs, this);
983
984 if ((list != null) && !list.isEmpty()) {
985 for (MBThread mbThread : list) {
986 if (!Validator.equals(uuid, mbThread.getUuid()) ||
987 (companyId != mbThread.getCompanyId())) {
988 list = null;
989
990 break;
991 }
992 }
993 }
994
995 if (list == null) {
996 StringBundler query = null;
997
998 if (orderByComparator != null) {
999 query = new StringBundler(4 +
1000 (orderByComparator.getOrderByFields().length * 3));
1001 }
1002 else {
1003 query = new StringBundler(4);
1004 }
1005
1006 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1007
1008 boolean bindUuid = false;
1009
1010 if (uuid == null) {
1011 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1012 }
1013 else if (uuid.equals(StringPool.BLANK)) {
1014 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1015 }
1016 else {
1017 bindUuid = true;
1018
1019 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1020 }
1021
1022 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1023
1024 if (orderByComparator != null) {
1025 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1026 orderByComparator);
1027 }
1028 else
1029 if (pagination) {
1030 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1031 }
1032
1033 String sql = query.toString();
1034
1035 Session session = null;
1036
1037 try {
1038 session = openSession();
1039
1040 Query q = session.createQuery(sql);
1041
1042 QueryPos qPos = QueryPos.getInstance(q);
1043
1044 if (bindUuid) {
1045 qPos.add(uuid);
1046 }
1047
1048 qPos.add(companyId);
1049
1050 if (!pagination) {
1051 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1052 start, end, false);
1053
1054 Collections.sort(list);
1055
1056 list = new UnmodifiableList<MBThread>(list);
1057 }
1058 else {
1059 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1060 start, end);
1061 }
1062
1063 cacheResult(list);
1064
1065 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1066 }
1067 catch (Exception e) {
1068 FinderCacheUtil.removeResult(finderPath, finderArgs);
1069
1070 throw processException(e);
1071 }
1072 finally {
1073 closeSession(session);
1074 }
1075 }
1076
1077 return list;
1078 }
1079
1080
1090 @Override
1091 public MBThread findByUuid_C_First(String uuid, long companyId,
1092 OrderByComparator orderByComparator)
1093 throws NoSuchThreadException, SystemException {
1094 MBThread mbThread = fetchByUuid_C_First(uuid, companyId,
1095 orderByComparator);
1096
1097 if (mbThread != null) {
1098 return mbThread;
1099 }
1100
1101 StringBundler msg = new StringBundler(6);
1102
1103 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1104
1105 msg.append("uuid=");
1106 msg.append(uuid);
1107
1108 msg.append(", companyId=");
1109 msg.append(companyId);
1110
1111 msg.append(StringPool.CLOSE_CURLY_BRACE);
1112
1113 throw new NoSuchThreadException(msg.toString());
1114 }
1115
1116
1125 @Override
1126 public MBThread fetchByUuid_C_First(String uuid, long companyId,
1127 OrderByComparator orderByComparator) throws SystemException {
1128 List<MBThread> list = findByUuid_C(uuid, companyId, 0, 1,
1129 orderByComparator);
1130
1131 if (!list.isEmpty()) {
1132 return list.get(0);
1133 }
1134
1135 return null;
1136 }
1137
1138
1148 @Override
1149 public MBThread findByUuid_C_Last(String uuid, long companyId,
1150 OrderByComparator orderByComparator)
1151 throws NoSuchThreadException, SystemException {
1152 MBThread mbThread = fetchByUuid_C_Last(uuid, companyId,
1153 orderByComparator);
1154
1155 if (mbThread != null) {
1156 return mbThread;
1157 }
1158
1159 StringBundler msg = new StringBundler(6);
1160
1161 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1162
1163 msg.append("uuid=");
1164 msg.append(uuid);
1165
1166 msg.append(", companyId=");
1167 msg.append(companyId);
1168
1169 msg.append(StringPool.CLOSE_CURLY_BRACE);
1170
1171 throw new NoSuchThreadException(msg.toString());
1172 }
1173
1174
1183 @Override
1184 public MBThread fetchByUuid_C_Last(String uuid, long companyId,
1185 OrderByComparator orderByComparator) throws SystemException {
1186 int count = countByUuid_C(uuid, companyId);
1187
1188 if (count == 0) {
1189 return null;
1190 }
1191
1192 List<MBThread> list = findByUuid_C(uuid, companyId, count - 1, count,
1193 orderByComparator);
1194
1195 if (!list.isEmpty()) {
1196 return list.get(0);
1197 }
1198
1199 return null;
1200 }
1201
1202
1213 @Override
1214 public MBThread[] findByUuid_C_PrevAndNext(long threadId, String uuid,
1215 long companyId, OrderByComparator orderByComparator)
1216 throws NoSuchThreadException, SystemException {
1217 MBThread mbThread = findByPrimaryKey(threadId);
1218
1219 Session session = null;
1220
1221 try {
1222 session = openSession();
1223
1224 MBThread[] array = new MBThreadImpl[3];
1225
1226 array[0] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1227 companyId, orderByComparator, true);
1228
1229 array[1] = mbThread;
1230
1231 array[2] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1232 companyId, orderByComparator, false);
1233
1234 return array;
1235 }
1236 catch (Exception e) {
1237 throw processException(e);
1238 }
1239 finally {
1240 closeSession(session);
1241 }
1242 }
1243
1244 protected MBThread getByUuid_C_PrevAndNext(Session session,
1245 MBThread mbThread, String uuid, long companyId,
1246 OrderByComparator orderByComparator, boolean previous) {
1247 StringBundler query = null;
1248
1249 if (orderByComparator != null) {
1250 query = new StringBundler(6 +
1251 (orderByComparator.getOrderByFields().length * 6));
1252 }
1253 else {
1254 query = new StringBundler(3);
1255 }
1256
1257 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1258
1259 boolean bindUuid = false;
1260
1261 if (uuid == null) {
1262 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1263 }
1264 else if (uuid.equals(StringPool.BLANK)) {
1265 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1266 }
1267 else {
1268 bindUuid = true;
1269
1270 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1271 }
1272
1273 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1274
1275 if (orderByComparator != null) {
1276 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1277
1278 if (orderByConditionFields.length > 0) {
1279 query.append(WHERE_AND);
1280 }
1281
1282 for (int i = 0; i < orderByConditionFields.length; i++) {
1283 query.append(_ORDER_BY_ENTITY_ALIAS);
1284 query.append(orderByConditionFields[i]);
1285
1286 if ((i + 1) < orderByConditionFields.length) {
1287 if (orderByComparator.isAscending() ^ previous) {
1288 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1289 }
1290 else {
1291 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1292 }
1293 }
1294 else {
1295 if (orderByComparator.isAscending() ^ previous) {
1296 query.append(WHERE_GREATER_THAN);
1297 }
1298 else {
1299 query.append(WHERE_LESSER_THAN);
1300 }
1301 }
1302 }
1303
1304 query.append(ORDER_BY_CLAUSE);
1305
1306 String[] orderByFields = orderByComparator.getOrderByFields();
1307
1308 for (int i = 0; i < orderByFields.length; i++) {
1309 query.append(_ORDER_BY_ENTITY_ALIAS);
1310 query.append(orderByFields[i]);
1311
1312 if ((i + 1) < orderByFields.length) {
1313 if (orderByComparator.isAscending() ^ previous) {
1314 query.append(ORDER_BY_ASC_HAS_NEXT);
1315 }
1316 else {
1317 query.append(ORDER_BY_DESC_HAS_NEXT);
1318 }
1319 }
1320 else {
1321 if (orderByComparator.isAscending() ^ previous) {
1322 query.append(ORDER_BY_ASC);
1323 }
1324 else {
1325 query.append(ORDER_BY_DESC);
1326 }
1327 }
1328 }
1329 }
1330 else {
1331 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1332 }
1333
1334 String sql = query.toString();
1335
1336 Query q = session.createQuery(sql);
1337
1338 q.setFirstResult(0);
1339 q.setMaxResults(2);
1340
1341 QueryPos qPos = QueryPos.getInstance(q);
1342
1343 if (bindUuid) {
1344 qPos.add(uuid);
1345 }
1346
1347 qPos.add(companyId);
1348
1349 if (orderByComparator != null) {
1350 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1351
1352 for (Object value : values) {
1353 qPos.add(value);
1354 }
1355 }
1356
1357 List<MBThread> list = q.list();
1358
1359 if (list.size() == 2) {
1360 return list.get(1);
1361 }
1362 else {
1363 return null;
1364 }
1365 }
1366
1367
1374 @Override
1375 public void removeByUuid_C(String uuid, long companyId)
1376 throws SystemException {
1377 for (MBThread mbThread : findByUuid_C(uuid, companyId,
1378 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1379 remove(mbThread);
1380 }
1381 }
1382
1383
1391 @Override
1392 public int countByUuid_C(String uuid, long companyId)
1393 throws SystemException {
1394 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1395
1396 Object[] finderArgs = new Object[] { uuid, companyId };
1397
1398 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1399 this);
1400
1401 if (count == null) {
1402 StringBundler query = new StringBundler(3);
1403
1404 query.append(_SQL_COUNT_MBTHREAD_WHERE);
1405
1406 boolean bindUuid = false;
1407
1408 if (uuid == null) {
1409 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1410 }
1411 else if (uuid.equals(StringPool.BLANK)) {
1412 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1413 }
1414 else {
1415 bindUuid = true;
1416
1417 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1418 }
1419
1420 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1421
1422 String sql = query.toString();
1423
1424 Session session = null;
1425
1426 try {
1427 session = openSession();
1428
1429 Query q = session.createQuery(sql);
1430
1431 QueryPos qPos = QueryPos.getInstance(q);
1432
1433 if (bindUuid) {
1434 qPos.add(uuid);
1435 }
1436
1437 qPos.add(companyId);
1438
1439 count = (Long)q.uniqueResult();
1440
1441 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1442 }
1443 catch (Exception e) {
1444 FinderCacheUtil.removeResult(finderPath, finderArgs);
1445
1446 throw processException(e);
1447 }
1448 finally {
1449 closeSession(session);
1450 }
1451 }
1452
1453 return count.intValue();
1454 }
1455
1456 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbThread.uuid IS NULL AND ";
1457 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbThread.uuid = ? AND ";
1458 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
1459 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbThread.companyId = ?";
1460 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1461 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1462 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1463 new String[] {
1464 Long.class.getName(),
1465
1466 Integer.class.getName(), Integer.class.getName(),
1467 OrderByComparator.class.getName()
1468 });
1469 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1470 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1471 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1472 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1473 new String[] { Long.class.getName() },
1474 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
1475 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
1476 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
1477 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1478 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1479 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1480 new String[] { Long.class.getName() });
1481
1482
1489 @Override
1490 public List<MBThread> findByGroupId(long groupId) throws SystemException {
1491 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1492 }
1493
1494
1507 @Override
1508 public List<MBThread> findByGroupId(long groupId, int start, int end)
1509 throws SystemException {
1510 return findByGroupId(groupId, start, end, null);
1511 }
1512
1513
1527 @Override
1528 public List<MBThread> findByGroupId(long groupId, int start, int end,
1529 OrderByComparator orderByComparator) throws SystemException {
1530 boolean pagination = true;
1531 FinderPath finderPath = null;
1532 Object[] finderArgs = null;
1533
1534 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1535 (orderByComparator == null)) {
1536 pagination = false;
1537 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1538 finderArgs = new Object[] { groupId };
1539 }
1540 else {
1541 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1542 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1543 }
1544
1545 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1546 finderArgs, this);
1547
1548 if ((list != null) && !list.isEmpty()) {
1549 for (MBThread mbThread : list) {
1550 if ((groupId != mbThread.getGroupId())) {
1551 list = null;
1552
1553 break;
1554 }
1555 }
1556 }
1557
1558 if (list == null) {
1559 StringBundler query = null;
1560
1561 if (orderByComparator != null) {
1562 query = new StringBundler(3 +
1563 (orderByComparator.getOrderByFields().length * 3));
1564 }
1565 else {
1566 query = new StringBundler(3);
1567 }
1568
1569 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1570
1571 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1572
1573 if (orderByComparator != null) {
1574 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1575 orderByComparator);
1576 }
1577 else
1578 if (pagination) {
1579 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1580 }
1581
1582 String sql = query.toString();
1583
1584 Session session = null;
1585
1586 try {
1587 session = openSession();
1588
1589 Query q = session.createQuery(sql);
1590
1591 QueryPos qPos = QueryPos.getInstance(q);
1592
1593 qPos.add(groupId);
1594
1595 if (!pagination) {
1596 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1597 start, end, false);
1598
1599 Collections.sort(list);
1600
1601 list = new UnmodifiableList<MBThread>(list);
1602 }
1603 else {
1604 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1605 start, end);
1606 }
1607
1608 cacheResult(list);
1609
1610 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1611 }
1612 catch (Exception e) {
1613 FinderCacheUtil.removeResult(finderPath, finderArgs);
1614
1615 throw processException(e);
1616 }
1617 finally {
1618 closeSession(session);
1619 }
1620 }
1621
1622 return list;
1623 }
1624
1625
1634 @Override
1635 public MBThread findByGroupId_First(long groupId,
1636 OrderByComparator orderByComparator)
1637 throws NoSuchThreadException, SystemException {
1638 MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
1639
1640 if (mbThread != null) {
1641 return mbThread;
1642 }
1643
1644 StringBundler msg = new StringBundler(4);
1645
1646 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1647
1648 msg.append("groupId=");
1649 msg.append(groupId);
1650
1651 msg.append(StringPool.CLOSE_CURLY_BRACE);
1652
1653 throw new NoSuchThreadException(msg.toString());
1654 }
1655
1656
1664 @Override
1665 public MBThread fetchByGroupId_First(long groupId,
1666 OrderByComparator orderByComparator) throws SystemException {
1667 List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1668
1669 if (!list.isEmpty()) {
1670 return list.get(0);
1671 }
1672
1673 return null;
1674 }
1675
1676
1685 @Override
1686 public MBThread findByGroupId_Last(long groupId,
1687 OrderByComparator orderByComparator)
1688 throws NoSuchThreadException, SystemException {
1689 MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
1690
1691 if (mbThread != null) {
1692 return mbThread;
1693 }
1694
1695 StringBundler msg = new StringBundler(4);
1696
1697 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1698
1699 msg.append("groupId=");
1700 msg.append(groupId);
1701
1702 msg.append(StringPool.CLOSE_CURLY_BRACE);
1703
1704 throw new NoSuchThreadException(msg.toString());
1705 }
1706
1707
1715 @Override
1716 public MBThread fetchByGroupId_Last(long groupId,
1717 OrderByComparator orderByComparator) throws SystemException {
1718 int count = countByGroupId(groupId);
1719
1720 if (count == 0) {
1721 return null;
1722 }
1723
1724 List<MBThread> list = findByGroupId(groupId, count - 1, count,
1725 orderByComparator);
1726
1727 if (!list.isEmpty()) {
1728 return list.get(0);
1729 }
1730
1731 return null;
1732 }
1733
1734
1744 @Override
1745 public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1746 OrderByComparator orderByComparator)
1747 throws NoSuchThreadException, SystemException {
1748 MBThread mbThread = findByPrimaryKey(threadId);
1749
1750 Session session = null;
1751
1752 try {
1753 session = openSession();
1754
1755 MBThread[] array = new MBThreadImpl[3];
1756
1757 array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1758 orderByComparator, true);
1759
1760 array[1] = mbThread;
1761
1762 array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1763 orderByComparator, false);
1764
1765 return array;
1766 }
1767 catch (Exception e) {
1768 throw processException(e);
1769 }
1770 finally {
1771 closeSession(session);
1772 }
1773 }
1774
1775 protected MBThread getByGroupId_PrevAndNext(Session session,
1776 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
1777 boolean previous) {
1778 StringBundler query = null;
1779
1780 if (orderByComparator != null) {
1781 query = new StringBundler(6 +
1782 (orderByComparator.getOrderByFields().length * 6));
1783 }
1784 else {
1785 query = new StringBundler(3);
1786 }
1787
1788 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1789
1790 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1791
1792 if (orderByComparator != null) {
1793 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1794
1795 if (orderByConditionFields.length > 0) {
1796 query.append(WHERE_AND);
1797 }
1798
1799 for (int i = 0; i < orderByConditionFields.length; i++) {
1800 query.append(_ORDER_BY_ENTITY_ALIAS);
1801 query.append(orderByConditionFields[i]);
1802
1803 if ((i + 1) < orderByConditionFields.length) {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1806 }
1807 else {
1808 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1809 }
1810 }
1811 else {
1812 if (orderByComparator.isAscending() ^ previous) {
1813 query.append(WHERE_GREATER_THAN);
1814 }
1815 else {
1816 query.append(WHERE_LESSER_THAN);
1817 }
1818 }
1819 }
1820
1821 query.append(ORDER_BY_CLAUSE);
1822
1823 String[] orderByFields = orderByComparator.getOrderByFields();
1824
1825 for (int i = 0; i < orderByFields.length; i++) {
1826 query.append(_ORDER_BY_ENTITY_ALIAS);
1827 query.append(orderByFields[i]);
1828
1829 if ((i + 1) < orderByFields.length) {
1830 if (orderByComparator.isAscending() ^ previous) {
1831 query.append(ORDER_BY_ASC_HAS_NEXT);
1832 }
1833 else {
1834 query.append(ORDER_BY_DESC_HAS_NEXT);
1835 }
1836 }
1837 else {
1838 if (orderByComparator.isAscending() ^ previous) {
1839 query.append(ORDER_BY_ASC);
1840 }
1841 else {
1842 query.append(ORDER_BY_DESC);
1843 }
1844 }
1845 }
1846 }
1847 else {
1848 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1849 }
1850
1851 String sql = query.toString();
1852
1853 Query q = session.createQuery(sql);
1854
1855 q.setFirstResult(0);
1856 q.setMaxResults(2);
1857
1858 QueryPos qPos = QueryPos.getInstance(q);
1859
1860 qPos.add(groupId);
1861
1862 if (orderByComparator != null) {
1863 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1864
1865 for (Object value : values) {
1866 qPos.add(value);
1867 }
1868 }
1869
1870 List<MBThread> list = q.list();
1871
1872 if (list.size() == 2) {
1873 return list.get(1);
1874 }
1875 else {
1876 return null;
1877 }
1878 }
1879
1880
1887 @Override
1888 public List<MBThread> filterFindByGroupId(long groupId)
1889 throws SystemException {
1890 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1891 QueryUtil.ALL_POS, null);
1892 }
1893
1894
1907 @Override
1908 public List<MBThread> filterFindByGroupId(long groupId, int start, int end)
1909 throws SystemException {
1910 return filterFindByGroupId(groupId, start, end, null);
1911 }
1912
1913
1927 @Override
1928 public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1929 OrderByComparator orderByComparator) throws SystemException {
1930 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1931 return findByGroupId(groupId, start, end, orderByComparator);
1932 }
1933
1934 StringBundler query = null;
1935
1936 if (orderByComparator != null) {
1937 query = new StringBundler(3 +
1938 (orderByComparator.getOrderByFields().length * 3));
1939 }
1940 else {
1941 query = new StringBundler(3);
1942 }
1943
1944 if (getDB().isSupportsInlineDistinct()) {
1945 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1946 }
1947 else {
1948 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1949 }
1950
1951 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1952
1953 if (!getDB().isSupportsInlineDistinct()) {
1954 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1955 }
1956
1957 if (orderByComparator != null) {
1958 if (getDB().isSupportsInlineDistinct()) {
1959 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1960 orderByComparator, true);
1961 }
1962 else {
1963 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1964 orderByComparator, true);
1965 }
1966 }
1967 else {
1968 if (getDB().isSupportsInlineDistinct()) {
1969 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1970 }
1971 else {
1972 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1973 }
1974 }
1975
1976 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1977 MBThread.class.getName(),
1978 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1979
1980 Session session = null;
1981
1982 try {
1983 session = openSession();
1984
1985 SQLQuery q = session.createSQLQuery(sql);
1986
1987 if (getDB().isSupportsInlineDistinct()) {
1988 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1989 }
1990 else {
1991 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1992 }
1993
1994 QueryPos qPos = QueryPos.getInstance(q);
1995
1996 qPos.add(groupId);
1997
1998 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1999 }
2000 catch (Exception e) {
2001 throw processException(e);
2002 }
2003 finally {
2004 closeSession(session);
2005 }
2006 }
2007
2008
2018 @Override
2019 public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
2020 long groupId, OrderByComparator orderByComparator)
2021 throws NoSuchThreadException, SystemException {
2022 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2023 return findByGroupId_PrevAndNext(threadId, groupId,
2024 orderByComparator);
2025 }
2026
2027 MBThread mbThread = findByPrimaryKey(threadId);
2028
2029 Session session = null;
2030
2031 try {
2032 session = openSession();
2033
2034 MBThread[] array = new MBThreadImpl[3];
2035
2036 array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
2037 groupId, orderByComparator, true);
2038
2039 array[1] = mbThread;
2040
2041 array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
2042 groupId, orderByComparator, false);
2043
2044 return array;
2045 }
2046 catch (Exception e) {
2047 throw processException(e);
2048 }
2049 finally {
2050 closeSession(session);
2051 }
2052 }
2053
2054 protected MBThread filterGetByGroupId_PrevAndNext(Session session,
2055 MBThread mbThread, long groupId, OrderByComparator orderByComparator,
2056 boolean previous) {
2057 StringBundler query = null;
2058
2059 if (orderByComparator != null) {
2060 query = new StringBundler(6 +
2061 (orderByComparator.getOrderByFields().length * 6));
2062 }
2063 else {
2064 query = new StringBundler(3);
2065 }
2066
2067 if (getDB().isSupportsInlineDistinct()) {
2068 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2069 }
2070 else {
2071 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2072 }
2073
2074 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2075
2076 if (!getDB().isSupportsInlineDistinct()) {
2077 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2078 }
2079
2080 if (orderByComparator != null) {
2081 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2082
2083 if (orderByConditionFields.length > 0) {
2084 query.append(WHERE_AND);
2085 }
2086
2087 for (int i = 0; i < orderByConditionFields.length; i++) {
2088 if (getDB().isSupportsInlineDistinct()) {
2089 query.append(_ORDER_BY_ENTITY_ALIAS);
2090 }
2091 else {
2092 query.append(_ORDER_BY_ENTITY_TABLE);
2093 }
2094
2095 query.append(orderByConditionFields[i]);
2096
2097 if ((i + 1) < orderByConditionFields.length) {
2098 if (orderByComparator.isAscending() ^ previous) {
2099 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2100 }
2101 else {
2102 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2103 }
2104 }
2105 else {
2106 if (orderByComparator.isAscending() ^ previous) {
2107 query.append(WHERE_GREATER_THAN);
2108 }
2109 else {
2110 query.append(WHERE_LESSER_THAN);
2111 }
2112 }
2113 }
2114
2115 query.append(ORDER_BY_CLAUSE);
2116
2117 String[] orderByFields = orderByComparator.getOrderByFields();
2118
2119 for (int i = 0; i < orderByFields.length; i++) {
2120 if (getDB().isSupportsInlineDistinct()) {
2121 query.append(_ORDER_BY_ENTITY_ALIAS);
2122 }
2123 else {
2124 query.append(_ORDER_BY_ENTITY_TABLE);
2125 }
2126
2127 query.append(orderByFields[i]);
2128
2129 if ((i + 1) < orderByFields.length) {
2130 if (orderByComparator.isAscending() ^ previous) {
2131 query.append(ORDER_BY_ASC_HAS_NEXT);
2132 }
2133 else {
2134 query.append(ORDER_BY_DESC_HAS_NEXT);
2135 }
2136 }
2137 else {
2138 if (orderByComparator.isAscending() ^ previous) {
2139 query.append(ORDER_BY_ASC);
2140 }
2141 else {
2142 query.append(ORDER_BY_DESC);
2143 }
2144 }
2145 }
2146 }
2147 else {
2148 if (getDB().isSupportsInlineDistinct()) {
2149 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2150 }
2151 else {
2152 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2153 }
2154 }
2155
2156 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2157 MBThread.class.getName(),
2158 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2159
2160 SQLQuery q = session.createSQLQuery(sql);
2161
2162 q.setFirstResult(0);
2163 q.setMaxResults(2);
2164
2165 if (getDB().isSupportsInlineDistinct()) {
2166 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2167 }
2168 else {
2169 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2170 }
2171
2172 QueryPos qPos = QueryPos.getInstance(q);
2173
2174 qPos.add(groupId);
2175
2176 if (orderByComparator != null) {
2177 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2178
2179 for (Object value : values) {
2180 qPos.add(value);
2181 }
2182 }
2183
2184 List<MBThread> list = q.list();
2185
2186 if (list.size() == 2) {
2187 return list.get(1);
2188 }
2189 else {
2190 return null;
2191 }
2192 }
2193
2194
2200 @Override
2201 public void removeByGroupId(long groupId) throws SystemException {
2202 for (MBThread mbThread : findByGroupId(groupId, QueryUtil.ALL_POS,
2203 QueryUtil.ALL_POS, null)) {
2204 remove(mbThread);
2205 }
2206 }
2207
2208
2215 @Override
2216 public int countByGroupId(long groupId) throws SystemException {
2217 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2218
2219 Object[] finderArgs = new Object[] { groupId };
2220
2221 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2222 this);
2223
2224 if (count == null) {
2225 StringBundler query = new StringBundler(2);
2226
2227 query.append(_SQL_COUNT_MBTHREAD_WHERE);
2228
2229 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2230
2231 String sql = query.toString();
2232
2233 Session session = null;
2234
2235 try {
2236 session = openSession();
2237
2238 Query q = session.createQuery(sql);
2239
2240 QueryPos qPos = QueryPos.getInstance(q);
2241
2242 qPos.add(groupId);
2243
2244 count = (Long)q.uniqueResult();
2245
2246 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2247 }
2248 catch (Exception e) {
2249 FinderCacheUtil.removeResult(finderPath, finderArgs);
2250
2251 throw processException(e);
2252 }
2253 finally {
2254 closeSession(session);
2255 }
2256 }
2257
2258 return count.intValue();
2259 }
2260
2261
2268 @Override
2269 public int filterCountByGroupId(long groupId) throws SystemException {
2270 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2271 return countByGroupId(groupId);
2272 }
2273
2274 StringBundler query = new StringBundler(2);
2275
2276 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2277
2278 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2279
2280 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2281 MBThread.class.getName(),
2282 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2283
2284 Session session = null;
2285
2286 try {
2287 session = openSession();
2288
2289 SQLQuery q = session.createSQLQuery(sql);
2290
2291 q.addScalar(COUNT_COLUMN_NAME,
2292 com.liferay.portal.kernel.dao.orm.Type.LONG);
2293
2294 QueryPos qPos = QueryPos.getInstance(q);
2295
2296 qPos.add(groupId);
2297
2298 Long count = (Long)q.uniqueResult();
2299
2300 return count.intValue();
2301 }
2302 catch (Exception e) {
2303 throw processException(e);
2304 }
2305 finally {
2306 closeSession(session);
2307 }
2308 }
2309
2310 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
2311 public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2312 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2313 FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
2314 new String[] { Long.class.getName() },
2315 MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
2316 public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2317 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2318 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
2319 new String[] { Long.class.getName() });
2320
2321
2329 @Override
2330 public MBThread findByRootMessageId(long rootMessageId)
2331 throws NoSuchThreadException, SystemException {
2332 MBThread mbThread = fetchByRootMessageId(rootMessageId);
2333
2334 if (mbThread == null) {
2335 StringBundler msg = new StringBundler(4);
2336
2337 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2338
2339 msg.append("rootMessageId=");
2340 msg.append(rootMessageId);
2341
2342 msg.append(StringPool.CLOSE_CURLY_BRACE);
2343
2344 if (_log.isWarnEnabled()) {
2345 _log.warn(msg.toString());
2346 }
2347
2348 throw new NoSuchThreadException(msg.toString());
2349 }
2350
2351 return mbThread;
2352 }
2353
2354
2361 @Override
2362 public MBThread fetchByRootMessageId(long rootMessageId)
2363 throws SystemException {
2364 return fetchByRootMessageId(rootMessageId, true);
2365 }
2366
2367
2375 @Override
2376 public MBThread fetchByRootMessageId(long rootMessageId,
2377 boolean retrieveFromCache) throws SystemException {
2378 Object[] finderArgs = new Object[] { rootMessageId };
2379
2380 Object result = null;
2381
2382 if (retrieveFromCache) {
2383 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2384 finderArgs, this);
2385 }
2386
2387 if (result instanceof MBThread) {
2388 MBThread mbThread = (MBThread)result;
2389
2390 if ((rootMessageId != mbThread.getRootMessageId())) {
2391 result = null;
2392 }
2393 }
2394
2395 if (result == null) {
2396 StringBundler query = new StringBundler(3);
2397
2398 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2399
2400 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2401
2402 String sql = query.toString();
2403
2404 Session session = null;
2405
2406 try {
2407 session = openSession();
2408
2409 Query q = session.createQuery(sql);
2410
2411 QueryPos qPos = QueryPos.getInstance(q);
2412
2413 qPos.add(rootMessageId);
2414
2415 List<MBThread> list = q.list();
2416
2417 if (list.isEmpty()) {
2418 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2419 finderArgs, list);
2420 }
2421 else {
2422 if ((list.size() > 1) && _log.isWarnEnabled()) {
2423 _log.warn(
2424 "MBThreadPersistenceImpl.fetchByRootMessageId(long, boolean) with parameters (" +
2425 StringUtil.merge(finderArgs) +
2426 ") 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.");
2427 }
2428
2429 MBThread mbThread = list.get(0);
2430
2431 result = mbThread;
2432
2433 cacheResult(mbThread);
2434
2435 if ((mbThread.getRootMessageId() != rootMessageId)) {
2436 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2437 finderArgs, mbThread);
2438 }
2439 }
2440 }
2441 catch (Exception e) {
2442 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2443 finderArgs);
2444
2445 throw processException(e);
2446 }
2447 finally {
2448 closeSession(session);
2449 }
2450 }
2451
2452 if (result instanceof List<?>) {
2453 return null;
2454 }
2455 else {
2456 return (MBThread)result;
2457 }
2458 }
2459
2460
2467 @Override
2468 public MBThread removeByRootMessageId(long rootMessageId)
2469 throws NoSuchThreadException, SystemException {
2470 MBThread mbThread = findByRootMessageId(rootMessageId);
2471
2472 return remove(mbThread);
2473 }
2474
2475
2482 @Override
2483 public int countByRootMessageId(long rootMessageId)
2484 throws SystemException {
2485 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROOTMESSAGEID;
2486
2487 Object[] finderArgs = new Object[] { rootMessageId };
2488
2489 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2490 this);
2491
2492 if (count == null) {
2493 StringBundler query = new StringBundler(2);
2494
2495 query.append(_SQL_COUNT_MBTHREAD_WHERE);
2496
2497 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2498
2499 String sql = query.toString();
2500
2501 Session session = null;
2502
2503 try {
2504 session = openSession();
2505
2506 Query q = session.createQuery(sql);
2507
2508 QueryPos qPos = QueryPos.getInstance(q);
2509
2510 qPos.add(rootMessageId);
2511
2512 count = (Long)q.uniqueResult();
2513
2514 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2515 }
2516 catch (Exception e) {
2517 FinderCacheUtil.removeResult(finderPath, finderArgs);
2518
2519 throw processException(e);
2520 }
2521 finally {
2522 closeSession(session);
2523 }
2524 }
2525
2526 return count.intValue();
2527 }
2528
2529 private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
2530 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2531 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2532 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
2533 new String[] {
2534 Long.class.getName(), Long.class.getName(),
2535
2536 Integer.class.getName(), Integer.class.getName(),
2537 OrderByComparator.class.getName()
2538 });
2539 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2540 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2541 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
2542 new String[] { Long.class.getName(), Long.class.getName() },
2543 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
2544 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
2545 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
2546 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
2547 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2548 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2549 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
2550 new String[] { Long.class.getName(), Long.class.getName() });
2551 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2552 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2553 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
2554 new String[] { Long.class.getName(), Long.class.getName() });
2555
2556
2564 @Override
2565 public List<MBThread> findByG_C(long groupId, long categoryId)
2566 throws SystemException {
2567 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2568 QueryUtil.ALL_POS, null);
2569 }
2570
2571
2585 @Override
2586 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2587 int end) throws SystemException {
2588 return findByG_C(groupId, categoryId, start, end, null);
2589 }
2590
2591
2606 @Override
2607 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2608 int end, OrderByComparator orderByComparator) throws SystemException {
2609 boolean pagination = true;
2610 FinderPath finderPath = null;
2611 Object[] finderArgs = null;
2612
2613 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2614 (orderByComparator == null)) {
2615 pagination = false;
2616 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
2617 finderArgs = new Object[] { groupId, categoryId };
2618 }
2619 else {
2620 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2621 finderArgs = new Object[] {
2622 groupId, categoryId,
2623
2624 start, end, orderByComparator
2625 };
2626 }
2627
2628 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2629 finderArgs, this);
2630
2631 if ((list != null) && !list.isEmpty()) {
2632 for (MBThread mbThread : list) {
2633 if ((groupId != mbThread.getGroupId()) ||
2634 (categoryId != mbThread.getCategoryId())) {
2635 list = null;
2636
2637 break;
2638 }
2639 }
2640 }
2641
2642 if (list == null) {
2643 StringBundler query = null;
2644
2645 if (orderByComparator != null) {
2646 query = new StringBundler(4 +
2647 (orderByComparator.getOrderByFields().length * 3));
2648 }
2649 else {
2650 query = new StringBundler(4);
2651 }
2652
2653 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2654
2655 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2656
2657 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2658
2659 if (orderByComparator != null) {
2660 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2661 orderByComparator);
2662 }
2663 else
2664 if (pagination) {
2665 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2666 }
2667
2668 String sql = query.toString();
2669
2670 Session session = null;
2671
2672 try {
2673 session = openSession();
2674
2675 Query q = session.createQuery(sql);
2676
2677 QueryPos qPos = QueryPos.getInstance(q);
2678
2679 qPos.add(groupId);
2680
2681 qPos.add(categoryId);
2682
2683 if (!pagination) {
2684 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2685 start, end, false);
2686
2687 Collections.sort(list);
2688
2689 list = new UnmodifiableList<MBThread>(list);
2690 }
2691 else {
2692 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2693 start, end);
2694 }
2695
2696 cacheResult(list);
2697
2698 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2699 }
2700 catch (Exception e) {
2701 FinderCacheUtil.removeResult(finderPath, finderArgs);
2702
2703 throw processException(e);
2704 }
2705 finally {
2706 closeSession(session);
2707 }
2708 }
2709
2710 return list;
2711 }
2712
2713
2723 @Override
2724 public MBThread findByG_C_First(long groupId, long categoryId,
2725 OrderByComparator orderByComparator)
2726 throws NoSuchThreadException, SystemException {
2727 MBThread mbThread = fetchByG_C_First(groupId, categoryId,
2728 orderByComparator);
2729
2730 if (mbThread != null) {
2731 return mbThread;
2732 }
2733
2734 StringBundler msg = new StringBundler(6);
2735
2736 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2737
2738 msg.append("groupId=");
2739 msg.append(groupId);
2740
2741 msg.append(", categoryId=");
2742 msg.append(categoryId);
2743
2744 msg.append(StringPool.CLOSE_CURLY_BRACE);
2745
2746 throw new NoSuchThreadException(msg.toString());
2747 }
2748
2749
2758 @Override
2759 public MBThread fetchByG_C_First(long groupId, long categoryId,
2760 OrderByComparator orderByComparator) throws SystemException {
2761 List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
2762 orderByComparator);
2763
2764 if (!list.isEmpty()) {
2765 return list.get(0);
2766 }
2767
2768 return null;
2769 }
2770
2771
2781 @Override
2782 public MBThread findByG_C_Last(long groupId, long categoryId,
2783 OrderByComparator orderByComparator)
2784 throws NoSuchThreadException, SystemException {
2785 MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
2786 orderByComparator);
2787
2788 if (mbThread != null) {
2789 return mbThread;
2790 }
2791
2792 StringBundler msg = new StringBundler(6);
2793
2794 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2795
2796 msg.append("groupId=");
2797 msg.append(groupId);
2798
2799 msg.append(", categoryId=");
2800 msg.append(categoryId);
2801
2802 msg.append(StringPool.CLOSE_CURLY_BRACE);
2803
2804 throw new NoSuchThreadException(msg.toString());
2805 }
2806
2807
2816 @Override
2817 public MBThread fetchByG_C_Last(long groupId, long categoryId,
2818 OrderByComparator orderByComparator) throws SystemException {
2819 int count = countByG_C(groupId, categoryId);
2820
2821 if (count == 0) {
2822 return null;
2823 }
2824
2825 List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
2826 orderByComparator);
2827
2828 if (!list.isEmpty()) {
2829 return list.get(0);
2830 }
2831
2832 return null;
2833 }
2834
2835
2846 @Override
2847 public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
2848 long categoryId, OrderByComparator orderByComparator)
2849 throws NoSuchThreadException, SystemException {
2850 MBThread mbThread = findByPrimaryKey(threadId);
2851
2852 Session session = null;
2853
2854 try {
2855 session = openSession();
2856
2857 MBThread[] array = new MBThreadImpl[3];
2858
2859 array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
2860 categoryId, orderByComparator, true);
2861
2862 array[1] = mbThread;
2863
2864 array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
2865 categoryId, orderByComparator, false);
2866
2867 return array;
2868 }
2869 catch (Exception e) {
2870 throw processException(e);
2871 }
2872 finally {
2873 closeSession(session);
2874 }
2875 }
2876
2877 protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
2878 long groupId, long categoryId, OrderByComparator orderByComparator,
2879 boolean previous) {
2880 StringBundler query = null;
2881
2882 if (orderByComparator != null) {
2883 query = new StringBundler(6 +
2884 (orderByComparator.getOrderByFields().length * 6));
2885 }
2886 else {
2887 query = new StringBundler(3);
2888 }
2889
2890 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2891
2892 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2893
2894 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2895
2896 if (orderByComparator != null) {
2897 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2898
2899 if (orderByConditionFields.length > 0) {
2900 query.append(WHERE_AND);
2901 }
2902
2903 for (int i = 0; i < orderByConditionFields.length; i++) {
2904 query.append(_ORDER_BY_ENTITY_ALIAS);
2905 query.append(orderByConditionFields[i]);
2906
2907 if ((i + 1) < orderByConditionFields.length) {
2908 if (orderByComparator.isAscending() ^ previous) {
2909 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2910 }
2911 else {
2912 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2913 }
2914 }
2915 else {
2916 if (orderByComparator.isAscending() ^ previous) {
2917 query.append(WHERE_GREATER_THAN);
2918 }
2919 else {
2920 query.append(WHERE_LESSER_THAN);
2921 }
2922 }
2923 }
2924
2925 query.append(ORDER_BY_CLAUSE);
2926
2927 String[] orderByFields = orderByComparator.getOrderByFields();
2928
2929 for (int i = 0; i < orderByFields.length; i++) {
2930 query.append(_ORDER_BY_ENTITY_ALIAS);
2931 query.append(orderByFields[i]);
2932
2933 if ((i + 1) < orderByFields.length) {
2934 if (orderByComparator.isAscending() ^ previous) {
2935 query.append(ORDER_BY_ASC_HAS_NEXT);
2936 }
2937 else {
2938 query.append(ORDER_BY_DESC_HAS_NEXT);
2939 }
2940 }
2941 else {
2942 if (orderByComparator.isAscending() ^ previous) {
2943 query.append(ORDER_BY_ASC);
2944 }
2945 else {
2946 query.append(ORDER_BY_DESC);
2947 }
2948 }
2949 }
2950 }
2951 else {
2952 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2953 }
2954
2955 String sql = query.toString();
2956
2957 Query q = session.createQuery(sql);
2958
2959 q.setFirstResult(0);
2960 q.setMaxResults(2);
2961
2962 QueryPos qPos = QueryPos.getInstance(q);
2963
2964 qPos.add(groupId);
2965
2966 qPos.add(categoryId);
2967
2968 if (orderByComparator != null) {
2969 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2970
2971 for (Object value : values) {
2972 qPos.add(value);
2973 }
2974 }
2975
2976 List<MBThread> list = q.list();
2977
2978 if (list.size() == 2) {
2979 return list.get(1);
2980 }
2981 else {
2982 return null;
2983 }
2984 }
2985
2986
2994 @Override
2995 public List<MBThread> filterFindByG_C(long groupId, long categoryId)
2996 throws SystemException {
2997 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2998 QueryUtil.ALL_POS, null);
2999 }
3000
3001
3015 @Override
3016 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
3017 int start, int end) throws SystemException {
3018 return filterFindByG_C(groupId, categoryId, start, end, null);
3019 }
3020
3021
3036 @Override
3037 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
3038 int start, int end, OrderByComparator orderByComparator)
3039 throws SystemException {
3040 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3041 return findByG_C(groupId, categoryId, start, end, orderByComparator);
3042 }
3043
3044 StringBundler query = null;
3045
3046 if (orderByComparator != null) {
3047 query = new StringBundler(4 +
3048 (orderByComparator.getOrderByFields().length * 3));
3049 }
3050 else {
3051 query = new StringBundler(4);
3052 }
3053
3054 if (getDB().isSupportsInlineDistinct()) {
3055 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3056 }
3057 else {
3058 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3059 }
3060
3061 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3062
3063 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3064
3065 if (!getDB().isSupportsInlineDistinct()) {
3066 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3067 }
3068
3069 if (orderByComparator != null) {
3070 if (getDB().isSupportsInlineDistinct()) {
3071 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3072 orderByComparator, true);
3073 }
3074 else {
3075 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3076 orderByComparator, true);
3077 }
3078 }
3079 else {
3080 if (getDB().isSupportsInlineDistinct()) {
3081 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3082 }
3083 else {
3084 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3085 }
3086 }
3087
3088 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3089 MBThread.class.getName(),
3090 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3091
3092 Session session = null;
3093
3094 try {
3095 session = openSession();
3096
3097 SQLQuery q = session.createSQLQuery(sql);
3098
3099 if (getDB().isSupportsInlineDistinct()) {
3100 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3101 }
3102 else {
3103 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3104 }
3105
3106 QueryPos qPos = QueryPos.getInstance(q);
3107
3108 qPos.add(groupId);
3109
3110 qPos.add(categoryId);
3111
3112 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3113 }
3114 catch (Exception e) {
3115 throw processException(e);
3116 }
3117 finally {
3118 closeSession(session);
3119 }
3120 }
3121
3122
3133 @Override
3134 public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
3135 long categoryId, OrderByComparator orderByComparator)
3136 throws NoSuchThreadException, SystemException {
3137 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3138 return findByG_C_PrevAndNext(threadId, groupId, categoryId,
3139 orderByComparator);
3140 }
3141
3142 MBThread mbThread = findByPrimaryKey(threadId);
3143
3144 Session session = null;
3145
3146 try {
3147 session = openSession();
3148
3149 MBThread[] array = new MBThreadImpl[3];
3150
3151 array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3152 categoryId, orderByComparator, true);
3153
3154 array[1] = mbThread;
3155
3156 array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3157 categoryId, orderByComparator, false);
3158
3159 return array;
3160 }
3161 catch (Exception e) {
3162 throw processException(e);
3163 }
3164 finally {
3165 closeSession(session);
3166 }
3167 }
3168
3169 protected MBThread filterGetByG_C_PrevAndNext(Session session,
3170 MBThread mbThread, long groupId, long categoryId,
3171 OrderByComparator orderByComparator, boolean previous) {
3172 StringBundler query = null;
3173
3174 if (orderByComparator != null) {
3175 query = new StringBundler(6 +
3176 (orderByComparator.getOrderByFields().length * 6));
3177 }
3178 else {
3179 query = new StringBundler(3);
3180 }
3181
3182 if (getDB().isSupportsInlineDistinct()) {
3183 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3184 }
3185 else {
3186 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3187 }
3188
3189 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3190
3191 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3192
3193 if (!getDB().isSupportsInlineDistinct()) {
3194 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3195 }
3196
3197 if (orderByComparator != null) {
3198 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3199
3200 if (orderByConditionFields.length > 0) {
3201 query.append(WHERE_AND);
3202 }
3203
3204 for (int i = 0; i < orderByConditionFields.length; i++) {
3205 if (getDB().isSupportsInlineDistinct()) {
3206 query.append(_ORDER_BY_ENTITY_ALIAS);
3207 }
3208 else {
3209 query.append(_ORDER_BY_ENTITY_TABLE);
3210 }
3211
3212 query.append(orderByConditionFields[i]);
3213
3214 if ((i + 1) < orderByConditionFields.length) {
3215 if (orderByComparator.isAscending() ^ previous) {
3216 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3217 }
3218 else {
3219 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3220 }
3221 }
3222 else {
3223 if (orderByComparator.isAscending() ^ previous) {
3224 query.append(WHERE_GREATER_THAN);
3225 }
3226 else {
3227 query.append(WHERE_LESSER_THAN);
3228 }
3229 }
3230 }
3231
3232 query.append(ORDER_BY_CLAUSE);
3233
3234 String[] orderByFields = orderByComparator.getOrderByFields();
3235
3236 for (int i = 0; i < orderByFields.length; i++) {
3237 if (getDB().isSupportsInlineDistinct()) {
3238 query.append(_ORDER_BY_ENTITY_ALIAS);
3239 }
3240 else {
3241 query.append(_ORDER_BY_ENTITY_TABLE);
3242 }
3243
3244 query.append(orderByFields[i]);
3245
3246 if ((i + 1) < orderByFields.length) {
3247 if (orderByComparator.isAscending() ^ previous) {
3248 query.append(ORDER_BY_ASC_HAS_NEXT);
3249 }
3250 else {
3251 query.append(ORDER_BY_DESC_HAS_NEXT);
3252 }
3253 }
3254 else {
3255 if (orderByComparator.isAscending() ^ previous) {
3256 query.append(ORDER_BY_ASC);
3257 }
3258 else {
3259 query.append(ORDER_BY_DESC);
3260 }
3261 }
3262 }
3263 }
3264 else {
3265 if (getDB().isSupportsInlineDistinct()) {
3266 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3267 }
3268 else {
3269 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3270 }
3271 }
3272
3273 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3274 MBThread.class.getName(),
3275 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3276
3277 SQLQuery q = session.createSQLQuery(sql);
3278
3279 q.setFirstResult(0);
3280 q.setMaxResults(2);
3281
3282 if (getDB().isSupportsInlineDistinct()) {
3283 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3284 }
3285 else {
3286 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3287 }
3288
3289 QueryPos qPos = QueryPos.getInstance(q);
3290
3291 qPos.add(groupId);
3292
3293 qPos.add(categoryId);
3294
3295 if (orderByComparator != null) {
3296 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3297
3298 for (Object value : values) {
3299 qPos.add(value);
3300 }
3301 }
3302
3303 List<MBThread> list = q.list();
3304
3305 if (list.size() == 2) {
3306 return list.get(1);
3307 }
3308 else {
3309 return null;
3310 }
3311 }
3312
3313
3321 @Override
3322 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds)
3323 throws SystemException {
3324 return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3325 QueryUtil.ALL_POS, null);
3326 }
3327
3328
3342 @Override
3343 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3344 int start, int end) throws SystemException {
3345 return filterFindByG_C(groupId, categoryIds, start, end, null);
3346 }
3347
3348
3363 @Override
3364 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3365 int start, int end, OrderByComparator orderByComparator)
3366 throws SystemException {
3367 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3368 return findByG_C(groupId, categoryIds, start, end, orderByComparator);
3369 }
3370
3371 StringBundler query = new StringBundler();
3372
3373 if (getDB().isSupportsInlineDistinct()) {
3374 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3375 }
3376 else {
3377 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3378 }
3379
3380 boolean conjunctionable = false;
3381
3382 if (conjunctionable) {
3383 query.append(WHERE_AND);
3384 }
3385
3386 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3387
3388 conjunctionable = true;
3389
3390 if ((categoryIds == null) || (categoryIds.length > 0)) {
3391 if (conjunctionable) {
3392 query.append(WHERE_AND);
3393 }
3394
3395 query.append(StringPool.OPEN_PARENTHESIS);
3396
3397 for (int i = 0; i < categoryIds.length; i++) {
3398 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3399
3400 if ((i + 1) < categoryIds.length) {
3401 query.append(WHERE_OR);
3402 }
3403 }
3404
3405 query.append(StringPool.CLOSE_PARENTHESIS);
3406
3407 conjunctionable = true;
3408 }
3409
3410 if (!getDB().isSupportsInlineDistinct()) {
3411 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3412 }
3413
3414 if (orderByComparator != null) {
3415 if (getDB().isSupportsInlineDistinct()) {
3416 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3417 orderByComparator, true);
3418 }
3419 else {
3420 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3421 orderByComparator, true);
3422 }
3423 }
3424 else {
3425 if (getDB().isSupportsInlineDistinct()) {
3426 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3427 }
3428 else {
3429 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3430 }
3431 }
3432
3433 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3434 MBThread.class.getName(),
3435 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3436
3437 Session session = null;
3438
3439 try {
3440 session = openSession();
3441
3442 SQLQuery q = session.createSQLQuery(sql);
3443
3444 if (getDB().isSupportsInlineDistinct()) {
3445 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3446 }
3447 else {
3448 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3449 }
3450
3451 QueryPos qPos = QueryPos.getInstance(q);
3452
3453 qPos.add(groupId);
3454
3455 if (categoryIds != null) {
3456 qPos.add(categoryIds);
3457 }
3458
3459 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3460 }
3461 catch (Exception e) {
3462 throw processException(e);
3463 }
3464 finally {
3465 closeSession(session);
3466 }
3467 }
3468
3469
3481 @Override
3482 public List<MBThread> findByG_C(long groupId, long[] categoryIds)
3483 throws SystemException {
3484 return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3485 QueryUtil.ALL_POS, null);
3486 }
3487
3488
3502 @Override
3503 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3504 int start, int end) throws SystemException {
3505 return findByG_C(groupId, categoryIds, start, end, null);
3506 }
3507
3508
3523 @Override
3524 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3525 int start, int end, OrderByComparator orderByComparator)
3526 throws SystemException {
3527 if ((categoryIds != null) && (categoryIds.length == 1)) {
3528 return findByG_C(groupId, categoryIds[0], start, end,
3529 orderByComparator);
3530 }
3531
3532 boolean pagination = true;
3533 Object[] finderArgs = null;
3534
3535 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3536 (orderByComparator == null)) {
3537 pagination = false;
3538 finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
3539 }
3540 else {
3541 finderArgs = new Object[] {
3542 groupId, StringUtil.merge(categoryIds),
3543
3544 start, end, orderByComparator
3545 };
3546 }
3547
3548 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3549 finderArgs, this);
3550
3551 if ((list != null) && !list.isEmpty()) {
3552 for (MBThread mbThread : list) {
3553 if ((groupId != mbThread.getGroupId()) ||
3554 !ArrayUtil.contains(categoryIds,
3555 mbThread.getCategoryId())) {
3556 list = null;
3557
3558 break;
3559 }
3560 }
3561 }
3562
3563 if (list == null) {
3564 StringBundler query = new StringBundler();
3565
3566 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3567
3568 boolean conjunctionable = false;
3569
3570 if (conjunctionable) {
3571 query.append(WHERE_AND);
3572 }
3573
3574 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3575
3576 conjunctionable = true;
3577
3578 if ((categoryIds == null) || (categoryIds.length > 0)) {
3579 if (conjunctionable) {
3580 query.append(WHERE_AND);
3581 }
3582
3583 query.append(StringPool.OPEN_PARENTHESIS);
3584
3585 for (int i = 0; i < categoryIds.length; i++) {
3586 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3587
3588 if ((i + 1) < categoryIds.length) {
3589 query.append(WHERE_OR);
3590 }
3591 }
3592
3593 query.append(StringPool.CLOSE_PARENTHESIS);
3594
3595 conjunctionable = true;
3596 }
3597
3598 if (orderByComparator != null) {
3599 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3600 orderByComparator);
3601 }
3602 else
3603 if (pagination) {
3604 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3605 }
3606
3607 String sql = query.toString();
3608
3609 Session session = null;
3610
3611 try {
3612 session = openSession();
3613
3614 Query q = session.createQuery(sql);
3615
3616 QueryPos qPos = QueryPos.getInstance(q);
3617
3618 qPos.add(groupId);
3619
3620 if (categoryIds != null) {
3621 qPos.add(categoryIds);
3622 }
3623
3624 if (!pagination) {
3625 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3626 start, end, false);
3627
3628 Collections.sort(list);
3629
3630 list = new UnmodifiableList<MBThread>(list);
3631 }
3632 else {
3633 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3634 start, end);
3635 }
3636
3637 cacheResult(list);
3638
3639 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3640 finderArgs, list);
3641 }
3642 catch (Exception e) {
3643 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3644 finderArgs);
3645
3646 throw processException(e);
3647 }
3648 finally {
3649 closeSession(session);
3650 }
3651 }
3652
3653 return list;
3654 }
3655
3656
3663 @Override
3664 public void removeByG_C(long groupId, long categoryId)
3665 throws SystemException {
3666 for (MBThread mbThread : findByG_C(groupId, categoryId,
3667 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3668 remove(mbThread);
3669 }
3670 }
3671
3672
3680 @Override
3681 public int countByG_C(long groupId, long categoryId)
3682 throws SystemException {
3683 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
3684
3685 Object[] finderArgs = new Object[] { groupId, categoryId };
3686
3687 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3688 this);
3689
3690 if (count == null) {
3691 StringBundler query = new StringBundler(3);
3692
3693 query.append(_SQL_COUNT_MBTHREAD_WHERE);
3694
3695 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3696
3697 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3698
3699 String sql = query.toString();
3700
3701 Session session = null;
3702
3703 try {
3704 session = openSession();
3705
3706 Query q = session.createQuery(sql);
3707
3708 QueryPos qPos = QueryPos.getInstance(q);
3709
3710 qPos.add(groupId);
3711
3712 qPos.add(categoryId);
3713
3714 count = (Long)q.uniqueResult();
3715
3716 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3717 }
3718 catch (Exception e) {
3719 FinderCacheUtil.removeResult(finderPath, finderArgs);
3720
3721 throw processException(e);
3722 }
3723 finally {
3724 closeSession(session);
3725 }
3726 }
3727
3728 return count.intValue();
3729 }
3730
3731
3739 @Override
3740 public int countByG_C(long groupId, long[] categoryIds)
3741 throws SystemException {
3742 Object[] finderArgs = new Object[] {
3743 groupId, StringUtil.merge(categoryIds)
3744 };
3745
3746 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3747 finderArgs, this);
3748
3749 if (count == null) {
3750 StringBundler query = new StringBundler();
3751
3752 query.append(_SQL_COUNT_MBTHREAD_WHERE);
3753
3754 boolean conjunctionable = false;
3755
3756 if (conjunctionable) {
3757 query.append(WHERE_AND);
3758 }
3759
3760 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3761
3762 conjunctionable = true;
3763
3764 if ((categoryIds == null) || (categoryIds.length > 0)) {
3765 if (conjunctionable) {
3766 query.append(WHERE_AND);
3767 }
3768
3769 query.append(StringPool.OPEN_PARENTHESIS);
3770
3771 for (int i = 0; i < categoryIds.length; i++) {
3772 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3773
3774 if ((i + 1) < categoryIds.length) {
3775 query.append(WHERE_OR);
3776 }
3777 }
3778
3779 query.append(StringPool.CLOSE_PARENTHESIS);
3780
3781 conjunctionable = true;
3782 }
3783
3784 String sql = query.toString();
3785
3786 Session session = null;
3787
3788 try {
3789 session = openSession();
3790
3791 Query q = session.createQuery(sql);
3792
3793 QueryPos qPos = QueryPos.getInstance(q);
3794
3795 qPos.add(groupId);
3796
3797 if (categoryIds != null) {
3798 qPos.add(categoryIds);
3799 }
3800
3801 count = (Long)q.uniqueResult();
3802
3803 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3804 finderArgs, count);
3805 }
3806 catch (Exception e) {
3807 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3808 finderArgs);
3809
3810 throw processException(e);
3811 }
3812 finally {
3813 closeSession(session);
3814 }
3815 }
3816
3817 return count.intValue();
3818 }
3819
3820
3828 @Override
3829 public int filterCountByG_C(long groupId, long categoryId)
3830 throws SystemException {
3831 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3832 return countByG_C(groupId, categoryId);
3833 }
3834
3835 StringBundler query = new StringBundler(3);
3836
3837 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3838
3839 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3840
3841 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3842
3843 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3844 MBThread.class.getName(),
3845 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3846
3847 Session session = null;
3848
3849 try {
3850 session = openSession();
3851
3852 SQLQuery q = session.createSQLQuery(sql);
3853
3854 q.addScalar(COUNT_COLUMN_NAME,
3855 com.liferay.portal.kernel.dao.orm.Type.LONG);
3856
3857 QueryPos qPos = QueryPos.getInstance(q);
3858
3859 qPos.add(groupId);
3860
3861 qPos.add(categoryId);
3862
3863 Long count = (Long)q.uniqueResult();
3864
3865 return count.intValue();
3866 }
3867 catch (Exception e) {
3868 throw processException(e);
3869 }
3870 finally {
3871 closeSession(session);
3872 }
3873 }
3874
3875
3883 @Override
3884 public int filterCountByG_C(long groupId, long[] categoryIds)
3885 throws SystemException {
3886 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3887 return countByG_C(groupId, categoryIds);
3888 }
3889
3890 StringBundler query = new StringBundler();
3891
3892 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3893
3894 boolean conjunctionable = false;
3895
3896 if (conjunctionable) {
3897 query.append(WHERE_AND);
3898 }
3899
3900 query.append(_FINDER_COLUMN_G_C_GROUPID_5);
3901
3902 conjunctionable = true;
3903
3904 if ((categoryIds == null) || (categoryIds.length > 0)) {
3905 if (conjunctionable) {
3906 query.append(WHERE_AND);
3907 }
3908
3909 query.append(StringPool.OPEN_PARENTHESIS);
3910
3911 for (int i = 0; i < categoryIds.length; i++) {
3912 query.append(_FINDER_COLUMN_G_C_CATEGORYID_5);
3913
3914 if ((i + 1) < categoryIds.length) {
3915 query.append(WHERE_OR);
3916 }
3917 }
3918
3919 query.append(StringPool.CLOSE_PARENTHESIS);
3920
3921 conjunctionable = true;
3922 }
3923
3924 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3925 MBThread.class.getName(),
3926 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3927
3928 Session session = null;
3929
3930 try {
3931 session = openSession();
3932
3933 SQLQuery q = session.createSQLQuery(sql);
3934
3935 q.addScalar(COUNT_COLUMN_NAME,
3936 com.liferay.portal.kernel.dao.orm.Type.LONG);
3937
3938 QueryPos qPos = QueryPos.getInstance(q);
3939
3940 qPos.add(groupId);
3941
3942 if (categoryIds != null) {
3943 qPos.add(categoryIds);
3944 }
3945
3946 Long count = (Long)q.uniqueResult();
3947
3948 return count.intValue();
3949 }
3950 catch (Exception e) {
3951 throw processException(e);
3952 }
3953 finally {
3954 closeSession(session);
3955 }
3956 }
3957
3958 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
3959 private static final String _FINDER_COLUMN_G_C_GROUPID_5 = "(" +
3960 removeConjunction(_FINDER_COLUMN_G_C_GROUPID_2) + ")";
3961 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
3962 private static final String _FINDER_COLUMN_G_C_CATEGORYID_5 = "(" +
3963 removeConjunction(_FINDER_COLUMN_G_C_CATEGORYID_2) + ")";
3964 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3965 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3966 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
3967 new String[] {
3968 Long.class.getName(), Long.class.getName(),
3969
3970 Integer.class.getName(), Integer.class.getName(),
3971 OrderByComparator.class.getName()
3972 });
3973 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3974 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
3975 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
3976 new String[] { Long.class.getName(), Long.class.getName() });
3977
3978
3986 @Override
3987 public List<MBThread> findByG_NotC(long groupId, long categoryId)
3988 throws SystemException {
3989 return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3990 QueryUtil.ALL_POS, null);
3991 }
3992
3993
4007 @Override
4008 public List<MBThread> findByG_NotC(long groupId, long categoryId,
4009 int start, int end) throws SystemException {
4010 return findByG_NotC(groupId, categoryId, start, end, null);
4011 }
4012
4013
4028 @Override
4029 public List<MBThread> findByG_NotC(long groupId, long categoryId,
4030 int start, int end, OrderByComparator orderByComparator)
4031 throws SystemException {
4032 boolean pagination = true;
4033 FinderPath finderPath = null;
4034 Object[] finderArgs = null;
4035
4036 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
4037 finderArgs = new Object[] {
4038 groupId, categoryId,
4039
4040 start, end, orderByComparator
4041 };
4042
4043 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4044 finderArgs, this);
4045
4046 if ((list != null) && !list.isEmpty()) {
4047 for (MBThread mbThread : list) {
4048 if ((groupId != mbThread.getGroupId()) ||
4049 (categoryId == mbThread.getCategoryId())) {
4050 list = null;
4051
4052 break;
4053 }
4054 }
4055 }
4056
4057 if (list == null) {
4058 StringBundler query = null;
4059
4060 if (orderByComparator != null) {
4061 query = new StringBundler(4 +
4062 (orderByComparator.getOrderByFields().length * 3));
4063 }
4064 else {
4065 query = new StringBundler(4);
4066 }
4067
4068 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4069
4070 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4071
4072 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4073
4074 if (orderByComparator != null) {
4075 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4076 orderByComparator);
4077 }
4078 else
4079 if (pagination) {
4080 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4081 }
4082
4083 String sql = query.toString();
4084
4085 Session session = null;
4086
4087 try {
4088 session = openSession();
4089
4090 Query q = session.createQuery(sql);
4091
4092 QueryPos qPos = QueryPos.getInstance(q);
4093
4094 qPos.add(groupId);
4095
4096 qPos.add(categoryId);
4097
4098 if (!pagination) {
4099 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4100 start, end, false);
4101
4102 Collections.sort(list);
4103
4104 list = new UnmodifiableList<MBThread>(list);
4105 }
4106 else {
4107 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4108 start, end);
4109 }
4110
4111 cacheResult(list);
4112
4113 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4114 }
4115 catch (Exception e) {
4116 FinderCacheUtil.removeResult(finderPath, finderArgs);
4117
4118 throw processException(e);
4119 }
4120 finally {
4121 closeSession(session);
4122 }
4123 }
4124
4125 return list;
4126 }
4127
4128
4138 @Override
4139 public MBThread findByG_NotC_First(long groupId, long categoryId,
4140 OrderByComparator orderByComparator)
4141 throws NoSuchThreadException, SystemException {
4142 MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
4143 orderByComparator);
4144
4145 if (mbThread != null) {
4146 return mbThread;
4147 }
4148
4149 StringBundler msg = new StringBundler(6);
4150
4151 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4152
4153 msg.append("groupId=");
4154 msg.append(groupId);
4155
4156 msg.append(", categoryId=");
4157 msg.append(categoryId);
4158
4159 msg.append(StringPool.CLOSE_CURLY_BRACE);
4160
4161 throw new NoSuchThreadException(msg.toString());
4162 }
4163
4164
4173 @Override
4174 public MBThread fetchByG_NotC_First(long groupId, long categoryId,
4175 OrderByComparator orderByComparator) throws SystemException {
4176 List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
4177 orderByComparator);
4178
4179 if (!list.isEmpty()) {
4180 return list.get(0);
4181 }
4182
4183 return null;
4184 }
4185
4186
4196 @Override
4197 public MBThread findByG_NotC_Last(long groupId, long categoryId,
4198 OrderByComparator orderByComparator)
4199 throws NoSuchThreadException, SystemException {
4200 MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
4201 orderByComparator);
4202
4203 if (mbThread != null) {
4204 return mbThread;
4205 }
4206
4207 StringBundler msg = new StringBundler(6);
4208
4209 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4210
4211 msg.append("groupId=");
4212 msg.append(groupId);
4213
4214 msg.append(", categoryId=");
4215 msg.append(categoryId);
4216
4217 msg.append(StringPool.CLOSE_CURLY_BRACE);
4218
4219 throw new NoSuchThreadException(msg.toString());
4220 }
4221
4222
4231 @Override
4232 public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
4233 OrderByComparator orderByComparator) throws SystemException {
4234 int count = countByG_NotC(groupId, categoryId);
4235
4236 if (count == 0) {
4237 return null;
4238 }
4239
4240 List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
4241 count, orderByComparator);
4242
4243 if (!list.isEmpty()) {
4244 return list.get(0);
4245 }
4246
4247 return null;
4248 }
4249
4250
4261 @Override
4262 public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
4263 long categoryId, OrderByComparator orderByComparator)
4264 throws NoSuchThreadException, SystemException {
4265 MBThread mbThread = findByPrimaryKey(threadId);
4266
4267 Session session = null;
4268
4269 try {
4270 session = openSession();
4271
4272 MBThread[] array = new MBThreadImpl[3];
4273
4274 array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4275 categoryId, orderByComparator, true);
4276
4277 array[1] = mbThread;
4278
4279 array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4280 categoryId, orderByComparator, false);
4281
4282 return array;
4283 }
4284 catch (Exception e) {
4285 throw processException(e);
4286 }
4287 finally {
4288 closeSession(session);
4289 }
4290 }
4291
4292 protected MBThread getByG_NotC_PrevAndNext(Session session,
4293 MBThread mbThread, long groupId, long categoryId,
4294 OrderByComparator orderByComparator, boolean previous) {
4295 StringBundler query = null;
4296
4297 if (orderByComparator != null) {
4298 query = new StringBundler(6 +
4299 (orderByComparator.getOrderByFields().length * 6));
4300 }
4301 else {
4302 query = new StringBundler(3);
4303 }
4304
4305 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4306
4307 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4308
4309 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4310
4311 if (orderByComparator != null) {
4312 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4313
4314 if (orderByConditionFields.length > 0) {
4315 query.append(WHERE_AND);
4316 }
4317
4318 for (int i = 0; i < orderByConditionFields.length; i++) {
4319 query.append(_ORDER_BY_ENTITY_ALIAS);
4320 query.append(orderByConditionFields[i]);
4321
4322 if ((i + 1) < orderByConditionFields.length) {
4323 if (orderByComparator.isAscending() ^ previous) {
4324 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4325 }
4326 else {
4327 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4328 }
4329 }
4330 else {
4331 if (orderByComparator.isAscending() ^ previous) {
4332 query.append(WHERE_GREATER_THAN);
4333 }
4334 else {
4335 query.append(WHERE_LESSER_THAN);
4336 }
4337 }
4338 }
4339
4340 query.append(ORDER_BY_CLAUSE);
4341
4342 String[] orderByFields = orderByComparator.getOrderByFields();
4343
4344 for (int i = 0; i < orderByFields.length; i++) {
4345 query.append(_ORDER_BY_ENTITY_ALIAS);
4346 query.append(orderByFields[i]);
4347
4348 if ((i + 1) < orderByFields.length) {
4349 if (orderByComparator.isAscending() ^ previous) {
4350 query.append(ORDER_BY_ASC_HAS_NEXT);
4351 }
4352 else {
4353 query.append(ORDER_BY_DESC_HAS_NEXT);
4354 }
4355 }
4356 else {
4357 if (orderByComparator.isAscending() ^ previous) {
4358 query.append(ORDER_BY_ASC);
4359 }
4360 else {
4361 query.append(ORDER_BY_DESC);
4362 }
4363 }
4364 }
4365 }
4366 else {
4367 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4368 }
4369
4370 String sql = query.toString();
4371
4372 Query q = session.createQuery(sql);
4373
4374 q.setFirstResult(0);
4375 q.setMaxResults(2);
4376
4377 QueryPos qPos = QueryPos.getInstance(q);
4378
4379 qPos.add(groupId);
4380
4381 qPos.add(categoryId);
4382
4383 if (orderByComparator != null) {
4384 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4385
4386 for (Object value : values) {
4387 qPos.add(value);
4388 }
4389 }
4390
4391 List<MBThread> list = q.list();
4392
4393 if (list.size() == 2) {
4394 return list.get(1);
4395 }
4396 else {
4397 return null;
4398 }
4399 }
4400
4401
4409 @Override
4410 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId)
4411 throws SystemException {
4412 return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
4413 QueryUtil.ALL_POS, null);
4414 }
4415
4416
4430 @Override
4431 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4432 int start, int end) throws SystemException {
4433 return filterFindByG_NotC(groupId, categoryId, start, end, null);
4434 }
4435
4436
4451 @Override
4452 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4453 int start, int end, OrderByComparator orderByComparator)
4454 throws SystemException {
4455 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4456 return findByG_NotC(groupId, categoryId, start, end,
4457 orderByComparator);
4458 }
4459
4460 StringBundler query = null;
4461
4462 if (orderByComparator != null) {
4463 query = new StringBundler(4 +
4464 (orderByComparator.getOrderByFields().length * 3));
4465 }
4466 else {
4467 query = new StringBundler(4);
4468 }
4469
4470 if (getDB().isSupportsInlineDistinct()) {
4471 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4472 }
4473 else {
4474 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4475 }
4476
4477 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4478
4479 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4480
4481 if (!getDB().isSupportsInlineDistinct()) {
4482 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4483 }
4484
4485 if (orderByComparator != null) {
4486 if (getDB().isSupportsInlineDistinct()) {
4487 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4488 orderByComparator, true);
4489 }
4490 else {
4491 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4492 orderByComparator, true);
4493 }
4494 }
4495 else {
4496 if (getDB().isSupportsInlineDistinct()) {
4497 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4498 }
4499 else {
4500 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4501 }
4502 }
4503
4504 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4505 MBThread.class.getName(),
4506 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4507
4508 Session session = null;
4509
4510 try {
4511 session = openSession();
4512
4513 SQLQuery q = session.createSQLQuery(sql);
4514
4515 if (getDB().isSupportsInlineDistinct()) {
4516 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4517 }
4518 else {
4519 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4520 }
4521
4522 QueryPos qPos = QueryPos.getInstance(q);
4523
4524 qPos.add(groupId);
4525
4526 qPos.add(categoryId);
4527
4528 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
4529 }
4530 catch (Exception e) {
4531 throw processException(e);
4532 }
4533 finally {
4534 closeSession(session);
4535 }
4536 }
4537
4538
4549 @Override
4550 public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
4551 long groupId, long categoryId, OrderByComparator orderByComparator)
4552 throws NoSuchThreadException, SystemException {
4553 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4554 return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
4555 orderByComparator);
4556 }
4557
4558 MBThread mbThread = findByPrimaryKey(threadId);
4559
4560 Session session = null;
4561
4562 try {
4563 session = openSession();
4564
4565 MBThread[] array = new MBThreadImpl[3];
4566
4567 array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4568 groupId, categoryId, orderByComparator, true);
4569
4570 array[1] = mbThread;
4571
4572 array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4573 groupId, categoryId, orderByComparator, false);
4574
4575 return array;
4576 }
4577 catch (Exception e) {
4578 throw processException(e);
4579 }
4580 finally {
4581 closeSession(session);
4582 }
4583 }
4584
4585 protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
4586 MBThread mbThread, long groupId, long categoryId,
4587 OrderByComparator orderByComparator, boolean previous) {
4588 StringBundler query = null;
4589
4590 if (orderByComparator != null) {
4591 query = new StringBundler(6 +
4592 (orderByComparator.getOrderByFields().length * 6));
4593 }
4594 else {
4595 query = new StringBundler(3);
4596 }
4597
4598 if (getDB().isSupportsInlineDistinct()) {
4599 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4600 }
4601 else {
4602 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4603 }
4604
4605 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4606
4607 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4608
4609 if (!getDB().isSupportsInlineDistinct()) {
4610 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4611 }
4612
4613 if (orderByComparator != null) {
4614 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4615
4616 if (orderByConditionFields.length > 0) {
4617 query.append(WHERE_AND);
4618 }
4619
4620 for (int i = 0; i < orderByConditionFields.length; i++) {
4621 if (getDB().isSupportsInlineDistinct()) {
4622 query.append(_ORDER_BY_ENTITY_ALIAS);
4623 }
4624 else {
4625 query.append(_ORDER_BY_ENTITY_TABLE);
4626 }
4627
4628 query.append(orderByConditionFields[i]);
4629
4630 if ((i + 1) < orderByConditionFields.length) {
4631 if (orderByComparator.isAscending() ^ previous) {
4632 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4633 }
4634 else {
4635 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4636 }
4637 }
4638 else {
4639 if (orderByComparator.isAscending() ^ previous) {
4640 query.append(WHERE_GREATER_THAN);
4641 }
4642 else {
4643 query.append(WHERE_LESSER_THAN);
4644 }
4645 }
4646 }
4647
4648 query.append(ORDER_BY_CLAUSE);
4649
4650 String[] orderByFields = orderByComparator.getOrderByFields();
4651
4652 for (int i = 0; i < orderByFields.length; i++) {
4653 if (getDB().isSupportsInlineDistinct()) {
4654 query.append(_ORDER_BY_ENTITY_ALIAS);
4655 }
4656 else {
4657 query.append(_ORDER_BY_ENTITY_TABLE);
4658 }
4659
4660 query.append(orderByFields[i]);
4661
4662 if ((i + 1) < orderByFields.length) {
4663 if (orderByComparator.isAscending() ^ previous) {
4664 query.append(ORDER_BY_ASC_HAS_NEXT);
4665 }
4666 else {
4667 query.append(ORDER_BY_DESC_HAS_NEXT);
4668 }
4669 }
4670 else {
4671 if (orderByComparator.isAscending() ^ previous) {
4672 query.append(ORDER_BY_ASC);
4673 }
4674 else {
4675 query.append(ORDER_BY_DESC);
4676 }
4677 }
4678 }
4679 }
4680 else {
4681 if (getDB().isSupportsInlineDistinct()) {
4682 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4683 }
4684 else {
4685 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4686 }
4687 }
4688
4689 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4690 MBThread.class.getName(),
4691 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4692
4693 SQLQuery q = session.createSQLQuery(sql);
4694
4695 q.setFirstResult(0);
4696 q.setMaxResults(2);
4697
4698 if (getDB().isSupportsInlineDistinct()) {
4699 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4700 }
4701 else {
4702 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4703 }
4704
4705 QueryPos qPos = QueryPos.getInstance(q);
4706
4707 qPos.add(groupId);
4708
4709 qPos.add(categoryId);
4710
4711 if (orderByComparator != null) {
4712 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4713
4714 for (Object value : values) {
4715 qPos.add(value);
4716 }
4717 }
4718
4719 List<MBThread> list = q.list();
4720
4721 if (list.size() == 2) {
4722 return list.get(1);
4723 }
4724 else {
4725 return null;
4726 }
4727 }
4728
4729
4736 @Override
4737 public void removeByG_NotC(long groupId, long categoryId)
4738 throws SystemException {
4739 for (MBThread mbThread : findByG_NotC(groupId, categoryId,
4740 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4741 remove(mbThread);
4742 }
4743 }
4744
4745
4753 @Override
4754 public int countByG_NotC(long groupId, long categoryId)
4755 throws SystemException {
4756 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC;
4757
4758 Object[] finderArgs = new Object[] { groupId, categoryId };
4759
4760 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4761 this);
4762
4763 if (count == null) {
4764 StringBundler query = new StringBundler(3);
4765
4766 query.append(_SQL_COUNT_MBTHREAD_WHERE);
4767
4768 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4769
4770 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4771
4772 String sql = query.toString();
4773
4774 Session session = null;
4775
4776 try {
4777 session = openSession();
4778
4779 Query q = session.createQuery(sql);
4780
4781 QueryPos qPos = QueryPos.getInstance(q);
4782
4783 qPos.add(groupId);
4784
4785 qPos.add(categoryId);
4786
4787 count = (Long)q.uniqueResult();
4788
4789 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4790 }
4791 catch (Exception e) {
4792 FinderCacheUtil.removeResult(finderPath, finderArgs);
4793
4794 throw processException(e);
4795 }
4796 finally {
4797 closeSession(session);
4798 }
4799 }
4800
4801 return count.intValue();
4802 }
4803
4804
4812 @Override
4813 public int filterCountByG_NotC(long groupId, long categoryId)
4814 throws SystemException {
4815 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4816 return countByG_NotC(groupId, categoryId);
4817 }
4818
4819 StringBundler query = new StringBundler(3);
4820
4821 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
4822
4823 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4824
4825 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4826
4827 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4828 MBThread.class.getName(),
4829 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4830
4831 Session session = null;
4832
4833 try {
4834 session = openSession();
4835
4836 SQLQuery q = session.createSQLQuery(sql);
4837
4838 q.addScalar(COUNT_COLUMN_NAME,
4839 com.liferay.portal.kernel.dao.orm.Type.LONG);
4840
4841 QueryPos qPos = QueryPos.getInstance(q);
4842
4843 qPos.add(groupId);
4844
4845 qPos.add(categoryId);
4846
4847 Long count = (Long)q.uniqueResult();
4848
4849 return count.intValue();
4850 }
4851 catch (Exception e) {
4852 throw processException(e);
4853 }
4854 finally {
4855 closeSession(session);
4856 }
4857 }
4858
4859 private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
4860 private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
4861 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4862 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4863 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4864 new String[] {
4865 Long.class.getName(), Integer.class.getName(),
4866
4867 Integer.class.getName(), Integer.class.getName(),
4868 OrderByComparator.class.getName()
4869 });
4870 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4871 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4872 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4873 new String[] { Long.class.getName(), Integer.class.getName() },
4874 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
4875 MBThreadModelImpl.STATUS_COLUMN_BITMASK |
4876 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
4877 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
4878 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4879 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4880 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4881 new String[] { Long.class.getName(), Integer.class.getName() });
4882
4883
4891 @Override
4892 public List<MBThread> findByG_S(long groupId, int status)
4893 throws SystemException {
4894 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4895 null);
4896 }
4897
4898
4912 @Override
4913 public List<MBThread> findByG_S(long groupId, int status, int start, int end)
4914 throws SystemException {
4915 return findByG_S(groupId, status, start, end, null);
4916 }
4917
4918
4933 @Override
4934 public List<MBThread> findByG_S(long groupId, int status, int start,
4935 int end, OrderByComparator orderByComparator) throws SystemException {
4936 boolean pagination = true;
4937 FinderPath finderPath = null;
4938 Object[] finderArgs = null;
4939
4940 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4941 (orderByComparator == null)) {
4942 pagination = false;
4943 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4944 finderArgs = new Object[] { groupId, status };
4945 }
4946 else {
4947 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4948 finderArgs = new Object[] {
4949 groupId, status,
4950
4951 start, end, orderByComparator
4952 };
4953 }
4954
4955 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4956 finderArgs, this);
4957
4958 if ((list != null) && !list.isEmpty()) {
4959 for (MBThread mbThread : list) {
4960 if ((groupId != mbThread.getGroupId()) ||
4961 (status != mbThread.getStatus())) {
4962 list = null;
4963
4964 break;
4965 }
4966 }
4967 }
4968
4969 if (list == null) {
4970 StringBundler query = null;
4971
4972 if (orderByComparator != null) {
4973 query = new StringBundler(4 +
4974 (orderByComparator.getOrderByFields().length * 3));
4975 }
4976 else {
4977 query = new StringBundler(4);
4978 }
4979
4980 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4981
4982 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4983
4984 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4985
4986 if (orderByComparator != null) {
4987 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4988 orderByComparator);
4989 }
4990 else
4991 if (pagination) {
4992 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4993 }
4994
4995 String sql = query.toString();
4996
4997 Session session = null;
4998
4999 try {
5000 session = openSession();
5001
5002 Query q = session.createQuery(sql);
5003
5004 QueryPos qPos = QueryPos.getInstance(q);
5005
5006 qPos.add(groupId);
5007
5008 qPos.add(status);
5009
5010 if (!pagination) {
5011 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5012 start, end, false);
5013
5014 Collections.sort(list);
5015
5016 list = new UnmodifiableList<MBThread>(list);
5017 }
5018 else {
5019 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5020 start, end);
5021 }
5022
5023 cacheResult(list);
5024
5025 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5026 }
5027 catch (Exception e) {
5028 FinderCacheUtil.removeResult(finderPath, finderArgs);
5029
5030 throw processException(e);
5031 }
5032 finally {
5033 closeSession(session);
5034 }
5035 }
5036
5037 return list;
5038 }
5039
5040
5050 @Override
5051 public MBThread findByG_S_First(long groupId, int status,
5052 OrderByComparator orderByComparator)
5053 throws NoSuchThreadException, SystemException {
5054 MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
5055
5056 if (mbThread != null) {
5057 return mbThread;
5058 }
5059
5060 StringBundler msg = new StringBundler(6);
5061
5062 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5063
5064 msg.append("groupId=");
5065 msg.append(groupId);
5066
5067 msg.append(", status=");
5068 msg.append(status);
5069
5070 msg.append(StringPool.CLOSE_CURLY_BRACE);
5071
5072 throw new NoSuchThreadException(msg.toString());
5073 }
5074
5075
5084 @Override
5085 public MBThread fetchByG_S_First(long groupId, int status,
5086 OrderByComparator orderByComparator) throws SystemException {
5087 List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
5088
5089 if (!list.isEmpty()) {
5090 return list.get(0);
5091 }
5092
5093 return null;
5094 }
5095
5096
5106 @Override
5107 public MBThread findByG_S_Last(long groupId, int status,
5108 OrderByComparator orderByComparator)
5109 throws NoSuchThreadException, SystemException {
5110 MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
5111
5112 if (mbThread != null) {
5113 return mbThread;
5114 }
5115
5116 StringBundler msg = new StringBundler(6);
5117
5118 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5119
5120 msg.append("groupId=");
5121 msg.append(groupId);
5122
5123 msg.append(", status=");
5124 msg.append(status);
5125
5126 msg.append(StringPool.CLOSE_CURLY_BRACE);
5127
5128 throw new NoSuchThreadException(msg.toString());
5129 }
5130
5131
5140 @Override
5141 public MBThread fetchByG_S_Last(long groupId, int status,
5142 OrderByComparator orderByComparator) throws SystemException {
5143 int count = countByG_S(groupId, status);
5144
5145 if (count == 0) {
5146 return null;
5147 }
5148
5149 List<MBThread> list = findByG_S(groupId, status, count - 1, count,
5150 orderByComparator);
5151
5152 if (!list.isEmpty()) {
5153 return list.get(0);
5154 }
5155
5156 return null;
5157 }
5158
5159
5170 @Override
5171 public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
5172 int status, OrderByComparator orderByComparator)
5173 throws NoSuchThreadException, SystemException {
5174 MBThread mbThread = findByPrimaryKey(threadId);
5175
5176 Session session = null;
5177
5178 try {
5179 session = openSession();
5180
5181 MBThread[] array = new MBThreadImpl[3];
5182
5183 array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5184 orderByComparator, true);
5185
5186 array[1] = mbThread;
5187
5188 array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5189 orderByComparator, false);
5190
5191 return array;
5192 }
5193 catch (Exception e) {
5194 throw processException(e);
5195 }
5196 finally {
5197 closeSession(session);
5198 }
5199 }
5200
5201 protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
5202 long groupId, int status, OrderByComparator orderByComparator,
5203 boolean previous) {
5204 StringBundler query = null;
5205
5206 if (orderByComparator != null) {
5207 query = new StringBundler(6 +
5208 (orderByComparator.getOrderByFields().length * 6));
5209 }
5210 else {
5211 query = new StringBundler(3);
5212 }
5213
5214 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5215
5216 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5217
5218 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5219
5220 if (orderByComparator != null) {
5221 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5222
5223 if (orderByConditionFields.length > 0) {
5224 query.append(WHERE_AND);
5225 }
5226
5227 for (int i = 0; i < orderByConditionFields.length; i++) {
5228 query.append(_ORDER_BY_ENTITY_ALIAS);
5229 query.append(orderByConditionFields[i]);
5230
5231 if ((i + 1) < orderByConditionFields.length) {
5232 if (orderByComparator.isAscending() ^ previous) {
5233 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5234 }
5235 else {
5236 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5237 }
5238 }
5239 else {
5240 if (orderByComparator.isAscending() ^ previous) {
5241 query.append(WHERE_GREATER_THAN);
5242 }
5243 else {
5244 query.append(WHERE_LESSER_THAN);
5245 }
5246 }
5247 }
5248
5249 query.append(ORDER_BY_CLAUSE);
5250
5251 String[] orderByFields = orderByComparator.getOrderByFields();
5252
5253 for (int i = 0; i < orderByFields.length; i++) {
5254 query.append(_ORDER_BY_ENTITY_ALIAS);
5255 query.append(orderByFields[i]);
5256
5257 if ((i + 1) < orderByFields.length) {
5258 if (orderByComparator.isAscending() ^ previous) {
5259 query.append(ORDER_BY_ASC_HAS_NEXT);
5260 }
5261 else {
5262 query.append(ORDER_BY_DESC_HAS_NEXT);
5263 }
5264 }
5265 else {
5266 if (orderByComparator.isAscending() ^ previous) {
5267 query.append(ORDER_BY_ASC);
5268 }
5269 else {
5270 query.append(ORDER_BY_DESC);
5271 }
5272 }
5273 }
5274 }
5275 else {
5276 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5277 }
5278
5279 String sql = query.toString();
5280
5281 Query q = session.createQuery(sql);
5282
5283 q.setFirstResult(0);
5284 q.setMaxResults(2);
5285
5286 QueryPos qPos = QueryPos.getInstance(q);
5287
5288 qPos.add(groupId);
5289
5290 qPos.add(status);
5291
5292 if (orderByComparator != null) {
5293 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5294
5295 for (Object value : values) {
5296 qPos.add(value);
5297 }
5298 }
5299
5300 List<MBThread> list = q.list();
5301
5302 if (list.size() == 2) {
5303 return list.get(1);
5304 }
5305 else {
5306 return null;
5307 }
5308 }
5309
5310
5318 @Override
5319 public List<MBThread> filterFindByG_S(long groupId, int status)
5320 throws SystemException {
5321 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
5322 QueryUtil.ALL_POS, null);
5323 }
5324
5325
5339 @Override
5340 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5341 int end) throws SystemException {
5342 return filterFindByG_S(groupId, status, start, end, null);
5343 }
5344
5345
5360 @Override
5361 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5362 int end, OrderByComparator orderByComparator) throws SystemException {
5363 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5364 return findByG_S(groupId, status, start, end, orderByComparator);
5365 }
5366
5367 StringBundler query = null;
5368
5369 if (orderByComparator != null) {
5370 query = new StringBundler(4 +
5371 (orderByComparator.getOrderByFields().length * 3));
5372 }
5373 else {
5374 query = new StringBundler(4);
5375 }
5376
5377 if (getDB().isSupportsInlineDistinct()) {
5378 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5379 }
5380 else {
5381 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5382 }
5383
5384 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5385
5386 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5387
5388 if (!getDB().isSupportsInlineDistinct()) {
5389 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5390 }
5391
5392 if (orderByComparator != null) {
5393 if (getDB().isSupportsInlineDistinct()) {
5394 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5395 orderByComparator, true);
5396 }
5397 else {
5398 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5399 orderByComparator, true);
5400 }
5401 }
5402 else {
5403 if (getDB().isSupportsInlineDistinct()) {
5404 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5405 }
5406 else {
5407 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5408 }
5409 }
5410
5411 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5412 MBThread.class.getName(),
5413 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5414
5415 Session session = null;
5416
5417 try {
5418 session = openSession();
5419
5420 SQLQuery q = session.createSQLQuery(sql);
5421
5422 if (getDB().isSupportsInlineDistinct()) {
5423 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5424 }
5425 else {
5426 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5427 }
5428
5429 QueryPos qPos = QueryPos.getInstance(q);
5430
5431 qPos.add(groupId);
5432
5433 qPos.add(status);
5434
5435 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5436 }
5437 catch (Exception e) {
5438 throw processException(e);
5439 }
5440 finally {
5441 closeSession(session);
5442 }
5443 }
5444
5445
5456 @Override
5457 public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
5458 int status, OrderByComparator orderByComparator)
5459 throws NoSuchThreadException, SystemException {
5460 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5461 return findByG_S_PrevAndNext(threadId, groupId, status,
5462 orderByComparator);
5463 }
5464
5465 MBThread mbThread = findByPrimaryKey(threadId);
5466
5467 Session session = null;
5468
5469 try {
5470 session = openSession();
5471
5472 MBThread[] array = new MBThreadImpl[3];
5473
5474 array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5475 status, orderByComparator, true);
5476
5477 array[1] = mbThread;
5478
5479 array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5480 status, orderByComparator, false);
5481
5482 return array;
5483 }
5484 catch (Exception e) {
5485 throw processException(e);
5486 }
5487 finally {
5488 closeSession(session);
5489 }
5490 }
5491
5492 protected MBThread filterGetByG_S_PrevAndNext(Session session,
5493 MBThread mbThread, long groupId, int status,
5494 OrderByComparator orderByComparator, boolean previous) {
5495 StringBundler query = null;
5496
5497 if (orderByComparator != null) {
5498 query = new StringBundler(6 +
5499 (orderByComparator.getOrderByFields().length * 6));
5500 }
5501 else {
5502 query = new StringBundler(3);
5503 }
5504
5505 if (getDB().isSupportsInlineDistinct()) {
5506 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5507 }
5508 else {
5509 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5510 }
5511
5512 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5513
5514 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5515
5516 if (!getDB().isSupportsInlineDistinct()) {
5517 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5518 }
5519
5520 if (orderByComparator != null) {
5521 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5522
5523 if (orderByConditionFields.length > 0) {
5524 query.append(WHERE_AND);
5525 }
5526
5527 for (int i = 0; i < orderByConditionFields.length; i++) {
5528 if (getDB().isSupportsInlineDistinct()) {
5529 query.append(_ORDER_BY_ENTITY_ALIAS);
5530 }
5531 else {
5532 query.append(_ORDER_BY_ENTITY_TABLE);
5533 }
5534
5535 query.append(orderByConditionFields[i]);
5536
5537 if ((i + 1) < orderByConditionFields.length) {
5538 if (orderByComparator.isAscending() ^ previous) {
5539 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5540 }
5541 else {
5542 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5543 }
5544 }
5545 else {
5546 if (orderByComparator.isAscending() ^ previous) {
5547 query.append(WHERE_GREATER_THAN);
5548 }
5549 else {
5550 query.append(WHERE_LESSER_THAN);
5551 }
5552 }
5553 }
5554
5555 query.append(ORDER_BY_CLAUSE);
5556
5557 String[] orderByFields = orderByComparator.getOrderByFields();
5558
5559 for (int i = 0; i < orderByFields.length; i++) {
5560 if (getDB().isSupportsInlineDistinct()) {
5561 query.append(_ORDER_BY_ENTITY_ALIAS);
5562 }
5563 else {
5564 query.append(_ORDER_BY_ENTITY_TABLE);
5565 }
5566
5567 query.append(orderByFields[i]);
5568
5569 if ((i + 1) < orderByFields.length) {
5570 if (orderByComparator.isAscending() ^ previous) {
5571 query.append(ORDER_BY_ASC_HAS_NEXT);
5572 }
5573 else {
5574 query.append(ORDER_BY_DESC_HAS_NEXT);
5575 }
5576 }
5577 else {
5578 if (orderByComparator.isAscending() ^ previous) {
5579 query.append(ORDER_BY_ASC);
5580 }
5581 else {
5582 query.append(ORDER_BY_DESC);
5583 }
5584 }
5585 }
5586 }
5587 else {
5588 if (getDB().isSupportsInlineDistinct()) {
5589 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5590 }
5591 else {
5592 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5593 }
5594 }
5595
5596 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5597 MBThread.class.getName(),
5598 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5599
5600 SQLQuery q = session.createSQLQuery(sql);
5601
5602 q.setFirstResult(0);
5603 q.setMaxResults(2);
5604
5605 if (getDB().isSupportsInlineDistinct()) {
5606 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5607 }
5608 else {
5609 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5610 }
5611
5612 QueryPos qPos = QueryPos.getInstance(q);
5613
5614 qPos.add(groupId);
5615
5616 qPos.add(status);
5617
5618 if (orderByComparator != null) {
5619 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5620
5621 for (Object value : values) {
5622 qPos.add(value);
5623 }
5624 }
5625
5626 List<MBThread> list = q.list();
5627
5628 if (list.size() == 2) {
5629 return list.get(1);
5630 }
5631 else {
5632 return null;
5633 }
5634 }
5635
5636
5643 @Override
5644 public void removeByG_S(long groupId, int status) throws SystemException {
5645 for (MBThread mbThread : findByG_S(groupId, status, QueryUtil.ALL_POS,
5646 QueryUtil.ALL_POS, null)) {
5647 remove(mbThread);
5648 }
5649 }
5650
5651
5659 @Override
5660 public int countByG_S(long groupId, int status) throws SystemException {
5661 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5662
5663 Object[] finderArgs = new Object[] { groupId, status };
5664
5665 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5666 this);
5667
5668 if (count == null) {
5669 StringBundler query = new StringBundler(3);
5670
5671 query.append(_SQL_COUNT_MBTHREAD_WHERE);
5672
5673 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5674
5675 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5676
5677 String sql = query.toString();
5678
5679 Session session = null;
5680
5681 try {
5682 session = openSession();
5683
5684 Query q = session.createQuery(sql);
5685
5686 QueryPos qPos = QueryPos.getInstance(q);
5687
5688 qPos.add(groupId);
5689
5690 qPos.add(status);
5691
5692 count = (Long)q.uniqueResult();
5693
5694 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5695 }
5696 catch (Exception e) {
5697 FinderCacheUtil.removeResult(finderPath, finderArgs);
5698
5699 throw processException(e);
5700 }
5701 finally {
5702 closeSession(session);
5703 }
5704 }
5705
5706 return count.intValue();
5707 }
5708
5709
5717 @Override
5718 public int filterCountByG_S(long groupId, int status)
5719 throws SystemException {
5720 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5721 return countByG_S(groupId, status);
5722 }
5723
5724 StringBundler query = new StringBundler(3);
5725
5726 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
5727
5728 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5729
5730 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5731
5732 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5733 MBThread.class.getName(),
5734 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5735
5736 Session session = null;
5737
5738 try {
5739 session = openSession();
5740
5741 SQLQuery q = session.createSQLQuery(sql);
5742
5743 q.addScalar(COUNT_COLUMN_NAME,
5744 com.liferay.portal.kernel.dao.orm.Type.LONG);
5745
5746 QueryPos qPos = QueryPos.getInstance(q);
5747
5748 qPos.add(groupId);
5749
5750 qPos.add(status);
5751
5752 Long count = (Long)q.uniqueResult();
5753
5754 return count.intValue();
5755 }
5756 catch (Exception e) {
5757 throw processException(e);
5758 }
5759 finally {
5760 closeSession(session);
5761 }
5762 }
5763
5764 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
5765 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
5766 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5767 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5768 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
5769 new String[] {
5770 Long.class.getName(), Double.class.getName(),
5771
5772 Integer.class.getName(), Integer.class.getName(),
5773 OrderByComparator.class.getName()
5774 });
5775 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5776 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5777 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
5778 new String[] { Long.class.getName(), Double.class.getName() },
5779 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
5780 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
5781 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
5782 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5783 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
5784 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
5785 new String[] { Long.class.getName(), Double.class.getName() });
5786
5787
5795 @Override
5796 public List<MBThread> findByC_P(long categoryId, double priority)
5797 throws SystemException {
5798 return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
5799 QueryUtil.ALL_POS, null);
5800 }
5801
5802
5816 @Override
5817 public List<MBThread> findByC_P(long categoryId, double priority,
5818 int start, int end) throws SystemException {
5819 return findByC_P(categoryId, priority, start, end, null);
5820 }
5821
5822
5837 @Override
5838 public List<MBThread> findByC_P(long categoryId, double priority,
5839 int start, int end, OrderByComparator orderByComparator)
5840 throws SystemException {
5841 boolean pagination = true;
5842 FinderPath finderPath = null;
5843 Object[] finderArgs = null;
5844
5845 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5846 (orderByComparator == null)) {
5847 pagination = false;
5848 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
5849 finderArgs = new Object[] { categoryId, priority };
5850 }
5851 else {
5852 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
5853 finderArgs = new Object[] {
5854 categoryId, priority,
5855
5856 start, end, orderByComparator
5857 };
5858 }
5859
5860 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5861 finderArgs, this);
5862
5863 if ((list != null) && !list.isEmpty()) {
5864 for (MBThread mbThread : list) {
5865 if ((categoryId != mbThread.getCategoryId()) ||
5866 (priority != mbThread.getPriority())) {
5867 list = null;
5868
5869 break;
5870 }
5871 }
5872 }
5873
5874 if (list == null) {
5875 StringBundler query = null;
5876
5877 if (orderByComparator != null) {
5878 query = new StringBundler(4 +
5879 (orderByComparator.getOrderByFields().length * 3));
5880 }
5881 else {
5882 query = new StringBundler(4);
5883 }
5884
5885 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5886
5887 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5888
5889 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5890
5891 if (orderByComparator != null) {
5892 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5893 orderByComparator);
5894 }
5895 else
5896 if (pagination) {
5897 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5898 }
5899
5900 String sql = query.toString();
5901
5902 Session session = null;
5903
5904 try {
5905 session = openSession();
5906
5907 Query q = session.createQuery(sql);
5908
5909 QueryPos qPos = QueryPos.getInstance(q);
5910
5911 qPos.add(categoryId);
5912
5913 qPos.add(priority);
5914
5915 if (!pagination) {
5916 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5917 start, end, false);
5918
5919 Collections.sort(list);
5920
5921 list = new UnmodifiableList<MBThread>(list);
5922 }
5923 else {
5924 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5925 start, end);
5926 }
5927
5928 cacheResult(list);
5929
5930 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5931 }
5932 catch (Exception e) {
5933 FinderCacheUtil.removeResult(finderPath, finderArgs);
5934
5935 throw processException(e);
5936 }
5937 finally {
5938 closeSession(session);
5939 }
5940 }
5941
5942 return list;
5943 }
5944
5945
5955 @Override
5956 public MBThread findByC_P_First(long categoryId, double priority,
5957 OrderByComparator orderByComparator)
5958 throws NoSuchThreadException, SystemException {
5959 MBThread mbThread = fetchByC_P_First(categoryId, priority,
5960 orderByComparator);
5961
5962 if (mbThread != null) {
5963 return mbThread;
5964 }
5965
5966 StringBundler msg = new StringBundler(6);
5967
5968 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5969
5970 msg.append("categoryId=");
5971 msg.append(categoryId);
5972
5973 msg.append(", priority=");
5974 msg.append(priority);
5975
5976 msg.append(StringPool.CLOSE_CURLY_BRACE);
5977
5978 throw new NoSuchThreadException(msg.toString());
5979 }
5980
5981
5990 @Override
5991 public MBThread fetchByC_P_First(long categoryId, double priority,
5992 OrderByComparator orderByComparator) throws SystemException {
5993 List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
5994 orderByComparator);
5995
5996 if (!list.isEmpty()) {
5997 return list.get(0);
5998 }
5999
6000 return null;
6001 }
6002
6003
6013 @Override
6014 public MBThread findByC_P_Last(long categoryId, double priority,
6015 OrderByComparator orderByComparator)
6016 throws NoSuchThreadException, SystemException {
6017 MBThread mbThread = fetchByC_P_Last(categoryId, priority,
6018 orderByComparator);
6019
6020 if (mbThread != null) {
6021 return mbThread;
6022 }
6023
6024 StringBundler msg = new StringBundler(6);
6025
6026 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6027
6028 msg.append("categoryId=");
6029 msg.append(categoryId);
6030
6031 msg.append(", priority=");
6032 msg.append(priority);
6033
6034 msg.append(StringPool.CLOSE_CURLY_BRACE);
6035
6036 throw new NoSuchThreadException(msg.toString());
6037 }
6038
6039
6048 @Override
6049 public MBThread fetchByC_P_Last(long categoryId, double priority,
6050 OrderByComparator orderByComparator) throws SystemException {
6051 int count = countByC_P(categoryId, priority);
6052
6053 if (count == 0) {
6054 return null;
6055 }
6056
6057 List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
6058 orderByComparator);
6059
6060 if (!list.isEmpty()) {
6061 return list.get(0);
6062 }
6063
6064 return null;
6065 }
6066
6067
6078 @Override
6079 public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
6080 double priority, OrderByComparator orderByComparator)
6081 throws NoSuchThreadException, SystemException {
6082 MBThread mbThread = findByPrimaryKey(threadId);
6083
6084 Session session = null;
6085
6086 try {
6087 session = openSession();
6088
6089 MBThread[] array = new MBThreadImpl[3];
6090
6091 array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
6092 priority, orderByComparator, true);
6093
6094 array[1] = mbThread;
6095
6096 array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
6097 priority, orderByComparator, false);
6098
6099 return array;
6100 }
6101 catch (Exception e) {
6102 throw processException(e);
6103 }
6104 finally {
6105 closeSession(session);
6106 }
6107 }
6108
6109 protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
6110 long categoryId, double priority, OrderByComparator orderByComparator,
6111 boolean previous) {
6112 StringBundler query = null;
6113
6114 if (orderByComparator != null) {
6115 query = new StringBundler(6 +
6116 (orderByComparator.getOrderByFields().length * 6));
6117 }
6118 else {
6119 query = new StringBundler(3);
6120 }
6121
6122 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6123
6124 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6125
6126 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6127
6128 if (orderByComparator != null) {
6129 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6130
6131 if (orderByConditionFields.length > 0) {
6132 query.append(WHERE_AND);
6133 }
6134
6135 for (int i = 0; i < orderByConditionFields.length; i++) {
6136 query.append(_ORDER_BY_ENTITY_ALIAS);
6137 query.append(orderByConditionFields[i]);
6138
6139 if ((i + 1) < orderByConditionFields.length) {
6140 if (orderByComparator.isAscending() ^ previous) {
6141 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6142 }
6143 else {
6144 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6145 }
6146 }
6147 else {
6148 if (orderByComparator.isAscending() ^ previous) {
6149 query.append(WHERE_GREATER_THAN);
6150 }
6151 else {
6152 query.append(WHERE_LESSER_THAN);
6153 }
6154 }
6155 }
6156
6157 query.append(ORDER_BY_CLAUSE);
6158
6159 String[] orderByFields = orderByComparator.getOrderByFields();
6160
6161 for (int i = 0; i < orderByFields.length; i++) {
6162 query.append(_ORDER_BY_ENTITY_ALIAS);
6163 query.append(orderByFields[i]);
6164
6165 if ((i + 1) < orderByFields.length) {
6166 if (orderByComparator.isAscending() ^ previous) {
6167 query.append(ORDER_BY_ASC_HAS_NEXT);
6168 }
6169 else {
6170 query.append(ORDER_BY_DESC_HAS_NEXT);
6171 }
6172 }
6173 else {
6174 if (orderByComparator.isAscending() ^ previous) {
6175 query.append(ORDER_BY_ASC);
6176 }
6177 else {
6178 query.append(ORDER_BY_DESC);
6179 }
6180 }
6181 }
6182 }
6183 else {
6184 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6185 }
6186
6187 String sql = query.toString();
6188
6189 Query q = session.createQuery(sql);
6190
6191 q.setFirstResult(0);
6192 q.setMaxResults(2);
6193
6194 QueryPos qPos = QueryPos.getInstance(q);
6195
6196 qPos.add(categoryId);
6197
6198 qPos.add(priority);
6199
6200 if (orderByComparator != null) {
6201 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6202
6203 for (Object value : values) {
6204 qPos.add(value);
6205 }
6206 }
6207
6208 List<MBThread> list = q.list();
6209
6210 if (list.size() == 2) {
6211 return list.get(1);
6212 }
6213 else {
6214 return null;
6215 }
6216 }
6217
6218
6225 @Override
6226 public void removeByC_P(long categoryId, double priority)
6227 throws SystemException {
6228 for (MBThread mbThread : findByC_P(categoryId, priority,
6229 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6230 remove(mbThread);
6231 }
6232 }
6233
6234
6242 @Override
6243 public int countByC_P(long categoryId, double priority)
6244 throws SystemException {
6245 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
6246
6247 Object[] finderArgs = new Object[] { categoryId, priority };
6248
6249 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6250 this);
6251
6252 if (count == null) {
6253 StringBundler query = new StringBundler(3);
6254
6255 query.append(_SQL_COUNT_MBTHREAD_WHERE);
6256
6257 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6258
6259 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6260
6261 String sql = query.toString();
6262
6263 Session session = null;
6264
6265 try {
6266 session = openSession();
6267
6268 Query q = session.createQuery(sql);
6269
6270 QueryPos qPos = QueryPos.getInstance(q);
6271
6272 qPos.add(categoryId);
6273
6274 qPos.add(priority);
6275
6276 count = (Long)q.uniqueResult();
6277
6278 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6279 }
6280 catch (Exception e) {
6281 FinderCacheUtil.removeResult(finderPath, finderArgs);
6282
6283 throw processException(e);
6284 }
6285 finally {
6286 closeSession(session);
6287 }
6288 }
6289
6290 return count.intValue();
6291 }
6292
6293 private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
6294 private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
6295 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6296 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6297 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
6298 new String[] {
6299 Date.class.getName(), Double.class.getName(),
6300
6301 Integer.class.getName(), Integer.class.getName(),
6302 OrderByComparator.class.getName()
6303 });
6304 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6305 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6306 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
6307 new String[] { Date.class.getName(), Double.class.getName() },
6308 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6309 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6310 public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6311 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6312 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
6313 new String[] { Date.class.getName(), Double.class.getName() });
6314
6315
6323 @Override
6324 public List<MBThread> findByL_P(Date lastPostDate, double priority)
6325 throws SystemException {
6326 return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
6327 QueryUtil.ALL_POS, null);
6328 }
6329
6330
6344 @Override
6345 public List<MBThread> findByL_P(Date lastPostDate, double priority,
6346 int start, int end) throws SystemException {
6347 return findByL_P(lastPostDate, priority, start, end, null);
6348 }
6349
6350
6365 @Override
6366 public List<MBThread> findByL_P(Date lastPostDate, double priority,
6367 int start, int end, OrderByComparator orderByComparator)
6368 throws SystemException {
6369 boolean pagination = true;
6370 FinderPath finderPath = null;
6371 Object[] finderArgs = null;
6372
6373 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6374 (orderByComparator == null)) {
6375 pagination = false;
6376 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
6377 finderArgs = new Object[] { lastPostDate, priority };
6378 }
6379 else {
6380 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
6381 finderArgs = new Object[] {
6382 lastPostDate, priority,
6383
6384 start, end, orderByComparator
6385 };
6386 }
6387
6388 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6389 finderArgs, this);
6390
6391 if ((list != null) && !list.isEmpty()) {
6392 for (MBThread mbThread : list) {
6393 if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
6394 (priority != mbThread.getPriority())) {
6395 list = null;
6396
6397 break;
6398 }
6399 }
6400 }
6401
6402 if (list == null) {
6403 StringBundler query = null;
6404
6405 if (orderByComparator != null) {
6406 query = new StringBundler(4 +
6407 (orderByComparator.getOrderByFields().length * 3));
6408 }
6409 else {
6410 query = new StringBundler(4);
6411 }
6412
6413 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6414
6415 boolean bindLastPostDate = false;
6416
6417 if (lastPostDate == null) {
6418 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6419 }
6420 else {
6421 bindLastPostDate = true;
6422
6423 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6424 }
6425
6426 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6427
6428 if (orderByComparator != null) {
6429 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6430 orderByComparator);
6431 }
6432 else
6433 if (pagination) {
6434 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6435 }
6436
6437 String sql = query.toString();
6438
6439 Session session = null;
6440
6441 try {
6442 session = openSession();
6443
6444 Query q = session.createQuery(sql);
6445
6446 QueryPos qPos = QueryPos.getInstance(q);
6447
6448 if (bindLastPostDate) {
6449 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6450 }
6451
6452 qPos.add(priority);
6453
6454 if (!pagination) {
6455 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6456 start, end, false);
6457
6458 Collections.sort(list);
6459
6460 list = new UnmodifiableList<MBThread>(list);
6461 }
6462 else {
6463 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6464 start, end);
6465 }
6466
6467 cacheResult(list);
6468
6469 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6470 }
6471 catch (Exception e) {
6472 FinderCacheUtil.removeResult(finderPath, finderArgs);
6473
6474 throw processException(e);
6475 }
6476 finally {
6477 closeSession(session);
6478 }
6479 }
6480
6481 return list;
6482 }
6483
6484
6494 @Override
6495 public MBThread findByL_P_First(Date lastPostDate, double priority,
6496 OrderByComparator orderByComparator)
6497 throws NoSuchThreadException, SystemException {
6498 MBThread mbThread = fetchByL_P_First(lastPostDate, priority,
6499 orderByComparator);
6500
6501 if (mbThread != null) {
6502 return mbThread;
6503 }
6504
6505 StringBundler msg = new StringBundler(6);
6506
6507 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6508
6509 msg.append("lastPostDate=");
6510 msg.append(lastPostDate);
6511
6512 msg.append(", priority=");
6513 msg.append(priority);
6514
6515 msg.append(StringPool.CLOSE_CURLY_BRACE);
6516
6517 throw new NoSuchThreadException(msg.toString());
6518 }
6519
6520
6529 @Override
6530 public MBThread fetchByL_P_First(Date lastPostDate, double priority,
6531 OrderByComparator orderByComparator) throws SystemException {
6532 List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
6533 orderByComparator);
6534
6535 if (!list.isEmpty()) {
6536 return list.get(0);
6537 }
6538
6539 return null;
6540 }
6541
6542
6552 @Override
6553 public MBThread findByL_P_Last(Date lastPostDate, double priority,
6554 OrderByComparator orderByComparator)
6555 throws NoSuchThreadException, SystemException {
6556 MBThread mbThread = fetchByL_P_Last(lastPostDate, priority,
6557 orderByComparator);
6558
6559 if (mbThread != null) {
6560 return mbThread;
6561 }
6562
6563 StringBundler msg = new StringBundler(6);
6564
6565 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6566
6567 msg.append("lastPostDate=");
6568 msg.append(lastPostDate);
6569
6570 msg.append(", priority=");
6571 msg.append(priority);
6572
6573 msg.append(StringPool.CLOSE_CURLY_BRACE);
6574
6575 throw new NoSuchThreadException(msg.toString());
6576 }
6577
6578
6587 @Override
6588 public MBThread fetchByL_P_Last(Date lastPostDate, double priority,
6589 OrderByComparator orderByComparator) throws SystemException {
6590 int count = countByL_P(lastPostDate, priority);
6591
6592 if (count == 0) {
6593 return null;
6594 }
6595
6596 List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
6597 count, orderByComparator);
6598
6599 if (!list.isEmpty()) {
6600 return list.get(0);
6601 }
6602
6603 return null;
6604 }
6605
6606
6617 @Override
6618 public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
6619 double priority, OrderByComparator orderByComparator)
6620 throws NoSuchThreadException, SystemException {
6621 MBThread mbThread = findByPrimaryKey(threadId);
6622
6623 Session session = null;
6624
6625 try {
6626 session = openSession();
6627
6628 MBThread[] array = new MBThreadImpl[3];
6629
6630 array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6631 priority, orderByComparator, true);
6632
6633 array[1] = mbThread;
6634
6635 array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6636 priority, orderByComparator, false);
6637
6638 return array;
6639 }
6640 catch (Exception e) {
6641 throw processException(e);
6642 }
6643 finally {
6644 closeSession(session);
6645 }
6646 }
6647
6648 protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
6649 Date lastPostDate, double priority,
6650 OrderByComparator orderByComparator, boolean previous) {
6651 StringBundler query = null;
6652
6653 if (orderByComparator != null) {
6654 query = new StringBundler(6 +
6655 (orderByComparator.getOrderByFields().length * 6));
6656 }
6657 else {
6658 query = new StringBundler(3);
6659 }
6660
6661 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6662
6663 boolean bindLastPostDate = false;
6664
6665 if (lastPostDate == null) {
6666 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6667 }
6668 else {
6669 bindLastPostDate = true;
6670
6671 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6672 }
6673
6674 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6675
6676 if (orderByComparator != null) {
6677 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6678
6679 if (orderByConditionFields.length > 0) {
6680 query.append(WHERE_AND);
6681 }
6682
6683 for (int i = 0; i < orderByConditionFields.length; i++) {
6684 query.append(_ORDER_BY_ENTITY_ALIAS);
6685 query.append(orderByConditionFields[i]);
6686
6687 if ((i + 1) < orderByConditionFields.length) {
6688 if (orderByComparator.isAscending() ^ previous) {
6689 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6690 }
6691 else {
6692 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6693 }
6694 }
6695 else {
6696 if (orderByComparator.isAscending() ^ previous) {
6697 query.append(WHERE_GREATER_THAN);
6698 }
6699 else {
6700 query.append(WHERE_LESSER_THAN);
6701 }
6702 }
6703 }
6704
6705 query.append(ORDER_BY_CLAUSE);
6706
6707 String[] orderByFields = orderByComparator.getOrderByFields();
6708
6709 for (int i = 0; i < orderByFields.length; i++) {
6710 query.append(_ORDER_BY_ENTITY_ALIAS);
6711 query.append(orderByFields[i]);
6712
6713 if ((i + 1) < orderByFields.length) {
6714 if (orderByComparator.isAscending() ^ previous) {
6715 query.append(ORDER_BY_ASC_HAS_NEXT);
6716 }
6717 else {
6718 query.append(ORDER_BY_DESC_HAS_NEXT);
6719 }
6720 }
6721 else {
6722 if (orderByComparator.isAscending() ^ previous) {
6723 query.append(ORDER_BY_ASC);
6724 }
6725 else {
6726 query.append(ORDER_BY_DESC);
6727 }
6728 }
6729 }
6730 }
6731 else {
6732 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6733 }
6734
6735 String sql = query.toString();
6736
6737 Query q = session.createQuery(sql);
6738
6739 q.setFirstResult(0);
6740 q.setMaxResults(2);
6741
6742 QueryPos qPos = QueryPos.getInstance(q);
6743
6744 if (bindLastPostDate) {
6745 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6746 }
6747
6748 qPos.add(priority);
6749
6750 if (orderByComparator != null) {
6751 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6752
6753 for (Object value : values) {
6754 qPos.add(value);
6755 }
6756 }
6757
6758 List<MBThread> list = q.list();
6759
6760 if (list.size() == 2) {
6761 return list.get(1);
6762 }
6763 else {
6764 return null;
6765 }
6766 }
6767
6768
6775 @Override
6776 public void removeByL_P(Date lastPostDate, double priority)
6777 throws SystemException {
6778 for (MBThread mbThread : findByL_P(lastPostDate, priority,
6779 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6780 remove(mbThread);
6781 }
6782 }
6783
6784
6792 @Override
6793 public int countByL_P(Date lastPostDate, double priority)
6794 throws SystemException {
6795 FinderPath finderPath = FINDER_PATH_COUNT_BY_L_P;
6796
6797 Object[] finderArgs = new Object[] { lastPostDate, priority };
6798
6799 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6800 this);
6801
6802 if (count == null) {
6803 StringBundler query = new StringBundler(3);
6804
6805 query.append(_SQL_COUNT_MBTHREAD_WHERE);
6806
6807 boolean bindLastPostDate = false;
6808
6809 if (lastPostDate == null) {
6810 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6811 }
6812 else {
6813 bindLastPostDate = true;
6814
6815 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6816 }
6817
6818 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6819
6820 String sql = query.toString();
6821
6822 Session session = null;
6823
6824 try {
6825 session = openSession();
6826
6827 Query q = session.createQuery(sql);
6828
6829 QueryPos qPos = QueryPos.getInstance(q);
6830
6831 if (bindLastPostDate) {
6832 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
6833 }
6834
6835 qPos.add(priority);
6836
6837 count = (Long)q.uniqueResult();
6838
6839 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6840 }
6841 catch (Exception e) {
6842 FinderCacheUtil.removeResult(finderPath, finderArgs);
6843
6844 throw processException(e);
6845 }
6846 finally {
6847 closeSession(session);
6848 }
6849 }
6850
6851 return count.intValue();
6852 }
6853
6854 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
6855 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
6856 private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
6857 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6858 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6859 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
6860 new String[] {
6861 Long.class.getName(), Long.class.getName(), Date.class.getName(),
6862
6863 Integer.class.getName(), Integer.class.getName(),
6864 OrderByComparator.class.getName()
6865 });
6866 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6867 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6868 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
6869 new String[] {
6870 Long.class.getName(), Long.class.getName(), Date.class.getName()
6871 },
6872 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
6873 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
6874 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6875 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6876 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6877 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6878 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
6879 new String[] {
6880 Long.class.getName(), Long.class.getName(), Date.class.getName()
6881 });
6882
6883
6892 @Override
6893 public List<MBThread> findByG_C_L(long groupId, long categoryId,
6894 Date lastPostDate) throws SystemException {
6895 return findByG_C_L(groupId, categoryId, lastPostDate,
6896 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6897 }
6898
6899
6914 @Override
6915 public List<MBThread> findByG_C_L(long groupId, long categoryId,
6916 Date lastPostDate, int start, int end) throws SystemException {
6917 return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
6918 }
6919
6920
6936 @Override
6937 public List<MBThread> findByG_C_L(long groupId, long categoryId,
6938 Date lastPostDate, int start, int end,
6939 OrderByComparator orderByComparator) throws SystemException {
6940 boolean pagination = true;
6941 FinderPath finderPath = null;
6942 Object[] finderArgs = null;
6943
6944 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6945 (orderByComparator == null)) {
6946 pagination = false;
6947 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
6948 finderArgs = new Object[] { groupId, categoryId, lastPostDate };
6949 }
6950 else {
6951 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
6952 finderArgs = new Object[] {
6953 groupId, categoryId, lastPostDate,
6954
6955 start, end, orderByComparator
6956 };
6957 }
6958
6959 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6960 finderArgs, this);
6961
6962 if ((list != null) && !list.isEmpty()) {
6963 for (MBThread mbThread : list) {
6964 if ((groupId != mbThread.getGroupId()) ||
6965 (categoryId != mbThread.getCategoryId()) ||
6966 !Validator.equals(lastPostDate,
6967 mbThread.getLastPostDate())) {
6968 list = null;
6969
6970 break;
6971 }
6972 }
6973 }
6974
6975 if (list == null) {
6976 StringBundler query = null;
6977
6978 if (orderByComparator != null) {
6979 query = new StringBundler(5 +
6980 (orderByComparator.getOrderByFields().length * 3));
6981 }
6982 else {
6983 query = new StringBundler(5);
6984 }
6985
6986 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6987
6988 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6989
6990 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6991
6992 boolean bindLastPostDate = false;
6993
6994 if (lastPostDate == null) {
6995 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6996 }
6997 else {
6998 bindLastPostDate = true;
6999
7000 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7001 }
7002
7003 if (orderByComparator != null) {
7004 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7005 orderByComparator);
7006 }
7007 else
7008 if (pagination) {
7009 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7010 }
7011
7012 String sql = query.toString();
7013
7014 Session session = null;
7015
7016 try {
7017 session = openSession();
7018
7019 Query q = session.createQuery(sql);
7020
7021 QueryPos qPos = QueryPos.getInstance(q);
7022
7023 qPos.add(groupId);
7024
7025 qPos.add(categoryId);
7026
7027 if (bindLastPostDate) {
7028 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7029 }
7030
7031 if (!pagination) {
7032 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7033 start, end, false);
7034
7035 Collections.sort(list);
7036
7037 list = new UnmodifiableList<MBThread>(list);
7038 }
7039 else {
7040 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7041 start, end);
7042 }
7043
7044 cacheResult(list);
7045
7046 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7047 }
7048 catch (Exception e) {
7049 FinderCacheUtil.removeResult(finderPath, finderArgs);
7050
7051 throw processException(e);
7052 }
7053 finally {
7054 closeSession(session);
7055 }
7056 }
7057
7058 return list;
7059 }
7060
7061
7072 @Override
7073 public MBThread findByG_C_L_First(long groupId, long categoryId,
7074 Date lastPostDate, OrderByComparator orderByComparator)
7075 throws NoSuchThreadException, SystemException {
7076 MBThread mbThread = fetchByG_C_L_First(groupId, categoryId,
7077 lastPostDate, orderByComparator);
7078
7079 if (mbThread != null) {
7080 return mbThread;
7081 }
7082
7083 StringBundler msg = new StringBundler(8);
7084
7085 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7086
7087 msg.append("groupId=");
7088 msg.append(groupId);
7089
7090 msg.append(", categoryId=");
7091 msg.append(categoryId);
7092
7093 msg.append(", lastPostDate=");
7094 msg.append(lastPostDate);
7095
7096 msg.append(StringPool.CLOSE_CURLY_BRACE);
7097
7098 throw new NoSuchThreadException(msg.toString());
7099 }
7100
7101
7111 @Override
7112 public MBThread fetchByG_C_L_First(long groupId, long categoryId,
7113 Date lastPostDate, OrderByComparator orderByComparator)
7114 throws SystemException {
7115 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
7116 1, orderByComparator);
7117
7118 if (!list.isEmpty()) {
7119 return list.get(0);
7120 }
7121
7122 return null;
7123 }
7124
7125
7136 @Override
7137 public MBThread findByG_C_L_Last(long groupId, long categoryId,
7138 Date lastPostDate, OrderByComparator orderByComparator)
7139 throws NoSuchThreadException, SystemException {
7140 MBThread mbThread = fetchByG_C_L_Last(groupId, categoryId,
7141 lastPostDate, orderByComparator);
7142
7143 if (mbThread != null) {
7144 return mbThread;
7145 }
7146
7147 StringBundler msg = new StringBundler(8);
7148
7149 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7150
7151 msg.append("groupId=");
7152 msg.append(groupId);
7153
7154 msg.append(", categoryId=");
7155 msg.append(categoryId);
7156
7157 msg.append(", lastPostDate=");
7158 msg.append(lastPostDate);
7159
7160 msg.append(StringPool.CLOSE_CURLY_BRACE);
7161
7162 throw new NoSuchThreadException(msg.toString());
7163 }
7164
7165
7175 @Override
7176 public MBThread fetchByG_C_L_Last(long groupId, long categoryId,
7177 Date lastPostDate, OrderByComparator orderByComparator)
7178 throws SystemException {
7179 int count = countByG_C_L(groupId, categoryId, lastPostDate);
7180
7181 if (count == 0) {
7182 return null;
7183 }
7184
7185 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
7186 count - 1, count, orderByComparator);
7187
7188 if (!list.isEmpty()) {
7189 return list.get(0);
7190 }
7191
7192 return null;
7193 }
7194
7195
7207 @Override
7208 public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
7209 long categoryId, Date lastPostDate, OrderByComparator orderByComparator)
7210 throws NoSuchThreadException, SystemException {
7211 MBThread mbThread = findByPrimaryKey(threadId);
7212
7213 Session session = null;
7214
7215 try {
7216 session = openSession();
7217
7218 MBThread[] array = new MBThreadImpl[3];
7219
7220 array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7221 categoryId, lastPostDate, orderByComparator, true);
7222
7223 array[1] = mbThread;
7224
7225 array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7226 categoryId, lastPostDate, orderByComparator, false);
7227
7228 return array;
7229 }
7230 catch (Exception e) {
7231 throw processException(e);
7232 }
7233 finally {
7234 closeSession(session);
7235 }
7236 }
7237
7238 protected MBThread getByG_C_L_PrevAndNext(Session session,
7239 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7240 OrderByComparator orderByComparator, boolean previous) {
7241 StringBundler query = null;
7242
7243 if (orderByComparator != null) {
7244 query = new StringBundler(6 +
7245 (orderByComparator.getOrderByFields().length * 6));
7246 }
7247 else {
7248 query = new StringBundler(3);
7249 }
7250
7251 query.append(_SQL_SELECT_MBTHREAD_WHERE);
7252
7253 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7254
7255 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7256
7257 boolean bindLastPostDate = false;
7258
7259 if (lastPostDate == null) {
7260 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7261 }
7262 else {
7263 bindLastPostDate = true;
7264
7265 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7266 }
7267
7268 if (orderByComparator != null) {
7269 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7270
7271 if (orderByConditionFields.length > 0) {
7272 query.append(WHERE_AND);
7273 }
7274
7275 for (int i = 0; i < orderByConditionFields.length; i++) {
7276 query.append(_ORDER_BY_ENTITY_ALIAS);
7277 query.append(orderByConditionFields[i]);
7278
7279 if ((i + 1) < orderByConditionFields.length) {
7280 if (orderByComparator.isAscending() ^ previous) {
7281 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7282 }
7283 else {
7284 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7285 }
7286 }
7287 else {
7288 if (orderByComparator.isAscending() ^ previous) {
7289 query.append(WHERE_GREATER_THAN);
7290 }
7291 else {
7292 query.append(WHERE_LESSER_THAN);
7293 }
7294 }
7295 }
7296
7297 query.append(ORDER_BY_CLAUSE);
7298
7299 String[] orderByFields = orderByComparator.getOrderByFields();
7300
7301 for (int i = 0; i < orderByFields.length; i++) {
7302 query.append(_ORDER_BY_ENTITY_ALIAS);
7303 query.append(orderByFields[i]);
7304
7305 if ((i + 1) < orderByFields.length) {
7306 if (orderByComparator.isAscending() ^ previous) {
7307 query.append(ORDER_BY_ASC_HAS_NEXT);
7308 }
7309 else {
7310 query.append(ORDER_BY_DESC_HAS_NEXT);
7311 }
7312 }
7313 else {
7314 if (orderByComparator.isAscending() ^ previous) {
7315 query.append(ORDER_BY_ASC);
7316 }
7317 else {
7318 query.append(ORDER_BY_DESC);
7319 }
7320 }
7321 }
7322 }
7323 else {
7324 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7325 }
7326
7327 String sql = query.toString();
7328
7329 Query q = session.createQuery(sql);
7330
7331 q.setFirstResult(0);
7332 q.setMaxResults(2);
7333
7334 QueryPos qPos = QueryPos.getInstance(q);
7335
7336 qPos.add(groupId);
7337
7338 qPos.add(categoryId);
7339
7340 if (bindLastPostDate) {
7341 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7342 }
7343
7344 if (orderByComparator != null) {
7345 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7346
7347 for (Object value : values) {
7348 qPos.add(value);
7349 }
7350 }
7351
7352 List<MBThread> list = q.list();
7353
7354 if (list.size() == 2) {
7355 return list.get(1);
7356 }
7357 else {
7358 return null;
7359 }
7360 }
7361
7362
7371 @Override
7372 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7373 Date lastPostDate) throws SystemException {
7374 return filterFindByG_C_L(groupId, categoryId, lastPostDate,
7375 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7376 }
7377
7378
7393 @Override
7394 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7395 Date lastPostDate, int start, int end) throws SystemException {
7396 return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
7397 null);
7398 }
7399
7400
7416 @Override
7417 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7418 Date lastPostDate, int start, int end,
7419 OrderByComparator orderByComparator) throws SystemException {
7420 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7421 return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
7422 orderByComparator);
7423 }
7424
7425 StringBundler query = null;
7426
7427 if (orderByComparator != null) {
7428 query = new StringBundler(5 +
7429 (orderByComparator.getOrderByFields().length * 3));
7430 }
7431 else {
7432 query = new StringBundler(5);
7433 }
7434
7435 if (getDB().isSupportsInlineDistinct()) {
7436 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7437 }
7438 else {
7439 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7440 }
7441
7442 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7443
7444 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7445
7446 boolean bindLastPostDate = false;
7447
7448 if (lastPostDate == null) {
7449 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7450 }
7451 else {
7452 bindLastPostDate = true;
7453
7454 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7455 }
7456
7457 if (!getDB().isSupportsInlineDistinct()) {
7458 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7459 }
7460
7461 if (orderByComparator != null) {
7462 if (getDB().isSupportsInlineDistinct()) {
7463 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7464 orderByComparator, true);
7465 }
7466 else {
7467 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7468 orderByComparator, true);
7469 }
7470 }
7471 else {
7472 if (getDB().isSupportsInlineDistinct()) {
7473 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7474 }
7475 else {
7476 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7477 }
7478 }
7479
7480 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7481 MBThread.class.getName(),
7482 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7483
7484 Session session = null;
7485
7486 try {
7487 session = openSession();
7488
7489 SQLQuery q = session.createSQLQuery(sql);
7490
7491 if (getDB().isSupportsInlineDistinct()) {
7492 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7493 }
7494 else {
7495 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7496 }
7497
7498 QueryPos qPos = QueryPos.getInstance(q);
7499
7500 qPos.add(groupId);
7501
7502 qPos.add(categoryId);
7503
7504 if (bindLastPostDate) {
7505 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7506 }
7507
7508 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7509 }
7510 catch (Exception e) {
7511 throw processException(e);
7512 }
7513 finally {
7514 closeSession(session);
7515 }
7516 }
7517
7518
7530 @Override
7531 public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
7532 long groupId, long categoryId, Date lastPostDate,
7533 OrderByComparator orderByComparator)
7534 throws NoSuchThreadException, SystemException {
7535 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7536 return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
7537 lastPostDate, orderByComparator);
7538 }
7539
7540 MBThread mbThread = findByPrimaryKey(threadId);
7541
7542 Session session = null;
7543
7544 try {
7545 session = openSession();
7546
7547 MBThread[] array = new MBThreadImpl[3];
7548
7549 array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7550 categoryId, lastPostDate, orderByComparator, true);
7551
7552 array[1] = mbThread;
7553
7554 array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7555 categoryId, lastPostDate, orderByComparator, false);
7556
7557 return array;
7558 }
7559 catch (Exception e) {
7560 throw processException(e);
7561 }
7562 finally {
7563 closeSession(session);
7564 }
7565 }
7566
7567 protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
7568 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7569 OrderByComparator orderByComparator, boolean previous) {
7570 StringBundler query = null;
7571
7572 if (orderByComparator != null) {
7573 query = new StringBundler(6 +
7574 (orderByComparator.getOrderByFields().length * 6));
7575 }
7576 else {
7577 query = new StringBundler(3);
7578 }
7579
7580 if (getDB().isSupportsInlineDistinct()) {
7581 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7582 }
7583 else {
7584 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7585 }
7586
7587 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7588
7589 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7590
7591 boolean bindLastPostDate = false;
7592
7593 if (lastPostDate == null) {
7594 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7595 }
7596 else {
7597 bindLastPostDate = true;
7598
7599 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7600 }
7601
7602 if (!getDB().isSupportsInlineDistinct()) {
7603 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7604 }
7605
7606 if (orderByComparator != null) {
7607 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7608
7609 if (orderByConditionFields.length > 0) {
7610 query.append(WHERE_AND);
7611 }
7612
7613 for (int i = 0; i < orderByConditionFields.length; i++) {
7614 if (getDB().isSupportsInlineDistinct()) {
7615 query.append(_ORDER_BY_ENTITY_ALIAS);
7616 }
7617 else {
7618 query.append(_ORDER_BY_ENTITY_TABLE);
7619 }
7620
7621 query.append(orderByConditionFields[i]);
7622
7623 if ((i + 1) < orderByConditionFields.length) {
7624 if (orderByComparator.isAscending() ^ previous) {
7625 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7626 }
7627 else {
7628 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7629 }
7630 }
7631 else {
7632 if (orderByComparator.isAscending() ^ previous) {
7633 query.append(WHERE_GREATER_THAN);
7634 }
7635 else {
7636 query.append(WHERE_LESSER_THAN);
7637 }
7638 }
7639 }
7640
7641 query.append(ORDER_BY_CLAUSE);
7642
7643 String[] orderByFields = orderByComparator.getOrderByFields();
7644
7645 for (int i = 0; i < orderByFields.length; i++) {
7646 if (getDB().isSupportsInlineDistinct()) {
7647 query.append(_ORDER_BY_ENTITY_ALIAS);
7648 }
7649 else {
7650 query.append(_ORDER_BY_ENTITY_TABLE);
7651 }
7652
7653 query.append(orderByFields[i]);
7654
7655 if ((i + 1) < orderByFields.length) {
7656 if (orderByComparator.isAscending() ^ previous) {
7657 query.append(ORDER_BY_ASC_HAS_NEXT);
7658 }
7659 else {
7660 query.append(ORDER_BY_DESC_HAS_NEXT);
7661 }
7662 }
7663 else {
7664 if (orderByComparator.isAscending() ^ previous) {
7665 query.append(ORDER_BY_ASC);
7666 }
7667 else {
7668 query.append(ORDER_BY_DESC);
7669 }
7670 }
7671 }
7672 }
7673 else {
7674 if (getDB().isSupportsInlineDistinct()) {
7675 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7676 }
7677 else {
7678 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7679 }
7680 }
7681
7682 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7683 MBThread.class.getName(),
7684 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7685
7686 SQLQuery q = session.createSQLQuery(sql);
7687
7688 q.setFirstResult(0);
7689 q.setMaxResults(2);
7690
7691 if (getDB().isSupportsInlineDistinct()) {
7692 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7693 }
7694 else {
7695 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7696 }
7697
7698 QueryPos qPos = QueryPos.getInstance(q);
7699
7700 qPos.add(groupId);
7701
7702 qPos.add(categoryId);
7703
7704 if (bindLastPostDate) {
7705 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7706 }
7707
7708 if (orderByComparator != null) {
7709 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7710
7711 for (Object value : values) {
7712 qPos.add(value);
7713 }
7714 }
7715
7716 List<MBThread> list = q.list();
7717
7718 if (list.size() == 2) {
7719 return list.get(1);
7720 }
7721 else {
7722 return null;
7723 }
7724 }
7725
7726
7734 @Override
7735 public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate)
7736 throws SystemException {
7737 for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate,
7738 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7739 remove(mbThread);
7740 }
7741 }
7742
7743
7752 @Override
7753 public int countByG_C_L(long groupId, long categoryId, Date lastPostDate)
7754 throws SystemException {
7755 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_L;
7756
7757 Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
7758
7759 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7760 this);
7761
7762 if (count == null) {
7763 StringBundler query = new StringBundler(4);
7764
7765 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7766
7767 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7768
7769 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7770
7771 boolean bindLastPostDate = false;
7772
7773 if (lastPostDate == null) {
7774 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7775 }
7776 else {
7777 bindLastPostDate = true;
7778
7779 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7780 }
7781
7782 String sql = query.toString();
7783
7784 Session session = null;
7785
7786 try {
7787 session = openSession();
7788
7789 Query q = session.createQuery(sql);
7790
7791 QueryPos qPos = QueryPos.getInstance(q);
7792
7793 qPos.add(groupId);
7794
7795 qPos.add(categoryId);
7796
7797 if (bindLastPostDate) {
7798 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7799 }
7800
7801 count = (Long)q.uniqueResult();
7802
7803 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7804 }
7805 catch (Exception e) {
7806 FinderCacheUtil.removeResult(finderPath, finderArgs);
7807
7808 throw processException(e);
7809 }
7810 finally {
7811 closeSession(session);
7812 }
7813 }
7814
7815 return count.intValue();
7816 }
7817
7818
7827 @Override
7828 public int filterCountByG_C_L(long groupId, long categoryId,
7829 Date lastPostDate) throws SystemException {
7830 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7831 return countByG_C_L(groupId, categoryId, lastPostDate);
7832 }
7833
7834 StringBundler query = new StringBundler(4);
7835
7836 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7837
7838 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7839
7840 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7841
7842 boolean bindLastPostDate = false;
7843
7844 if (lastPostDate == null) {
7845 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7846 }
7847 else {
7848 bindLastPostDate = true;
7849
7850 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7851 }
7852
7853 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7854 MBThread.class.getName(),
7855 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7856
7857 Session session = null;
7858
7859 try {
7860 session = openSession();
7861
7862 SQLQuery q = session.createSQLQuery(sql);
7863
7864 q.addScalar(COUNT_COLUMN_NAME,
7865 com.liferay.portal.kernel.dao.orm.Type.LONG);
7866
7867 QueryPos qPos = QueryPos.getInstance(q);
7868
7869 qPos.add(groupId);
7870
7871 qPos.add(categoryId);
7872
7873 if (bindLastPostDate) {
7874 qPos.add(CalendarUtil.getTimestamp(lastPostDate));
7875 }
7876
7877 Long count = (Long)q.uniqueResult();
7878
7879 return count.intValue();
7880 }
7881 catch (Exception e) {
7882 throw processException(e);
7883 }
7884 finally {
7885 closeSession(session);
7886 }
7887 }
7888
7889 private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
7890 private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
7891 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
7892 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
7893 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7894 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7895 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
7896 new String[] {
7897 Long.class.getName(), Long.class.getName(),
7898 Integer.class.getName(),
7899
7900 Integer.class.getName(), Integer.class.getName(),
7901 OrderByComparator.class.getName()
7902 });
7903 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7904 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7905 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
7906 new String[] {
7907 Long.class.getName(), Long.class.getName(),
7908 Integer.class.getName()
7909 },
7910 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
7911 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
7912 MBThreadModelImpl.STATUS_COLUMN_BITMASK |
7913 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
7914 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
7915 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7916 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7917 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
7918 new String[] {
7919 Long.class.getName(), Long.class.getName(),
7920 Integer.class.getName()
7921 });
7922 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7923 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7924 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
7925 new String[] {
7926 Long.class.getName(), Long.class.getName(),
7927 Integer.class.getName()
7928 });
7929
7930
7939 @Override
7940 public List<MBThread> findByG_C_S(long groupId, long categoryId, int status)
7941 throws SystemException {
7942 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
7943 QueryUtil.ALL_POS, null);
7944 }
7945
7946
7961 @Override
7962 public List<MBThread> findByG_C_S(long groupId, long categoryId,
7963 int status, int start, int end) throws SystemException {
7964 return findByG_C_S(groupId, categoryId, status, start, end, null);
7965 }
7966
7967
7983 @Override
7984 public List<MBThread> findByG_C_S(long groupId, long categoryId,
7985 int status, int start, int end, OrderByComparator orderByComparator)
7986 throws SystemException {
7987 boolean pagination = true;
7988 FinderPath finderPath = null;
7989 Object[] finderArgs = null;
7990
7991 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7992 (orderByComparator == null)) {
7993 pagination = false;
7994 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
7995 finderArgs = new Object[] { groupId, categoryId, status };
7996 }
7997 else {
7998 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
7999 finderArgs = new Object[] {
8000 groupId, categoryId, status,
8001
8002 start, end, orderByComparator
8003 };
8004 }
8005
8006 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
8007 finderArgs, this);
8008
8009 if ((list != null) && !list.isEmpty()) {
8010 for (MBThread mbThread : list) {
8011 if ((groupId != mbThread.getGroupId()) ||
8012 (categoryId != mbThread.getCategoryId()) ||
8013 (status != mbThread.getStatus())) {
8014 list = null;
8015
8016 break;
8017 }
8018 }
8019 }
8020
8021 if (list == null) {
8022 StringBundler query = null;
8023
8024 if (orderByComparator != null) {
8025 query = new StringBundler(5 +
8026 (orderByComparator.getOrderByFields().length * 3));
8027 }
8028 else {
8029 query = new StringBundler(5);
8030 }
8031
8032 query.append(_SQL_SELECT_MBTHREAD_WHERE);
8033
8034 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8035
8036 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8037
8038 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8039
8040 if (orderByComparator != null) {
8041 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8042 orderByComparator);
8043 }
8044 else
8045 if (pagination) {
8046 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8047 }
8048
8049 String sql = query.toString();
8050
8051 Session session = null;
8052
8053 try {
8054 session = openSession();
8055
8056 Query q = session.createQuery(sql);
8057
8058 QueryPos qPos = QueryPos.getInstance(q);
8059
8060 qPos.add(groupId);
8061
8062 qPos.add(categoryId);
8063
8064 qPos.add(status);
8065
8066 if (!pagination) {
8067 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8068 start, end, false);
8069
8070 Collections.sort(list);
8071
8072 list = new UnmodifiableList<MBThread>(list);
8073 }
8074 else {
8075 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8076 start, end);
8077 }
8078
8079 cacheResult(list);
8080
8081 FinderCacheUtil.putResult(finderPath, finderArgs, list);
8082 }
8083 catch (Exception e) {
8084 FinderCacheUtil.removeResult(finderPath, finderArgs);
8085
8086 throw processException(e);
8087 }
8088 finally {
8089 closeSession(session);
8090 }
8091 }
8092
8093 return list;
8094 }
8095
8096
8107 @Override
8108 public MBThread findByG_C_S_First(long groupId, long categoryId,
8109 int status, OrderByComparator orderByComparator)
8110 throws NoSuchThreadException, SystemException {
8111 MBThread mbThread = fetchByG_C_S_First(groupId, categoryId, status,
8112 orderByComparator);
8113
8114 if (mbThread != null) {
8115 return mbThread;
8116 }
8117
8118 StringBundler msg = new StringBundler(8);
8119
8120 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8121
8122 msg.append("groupId=");
8123 msg.append(groupId);
8124
8125 msg.append(", categoryId=");
8126 msg.append(categoryId);
8127
8128 msg.append(", status=");
8129 msg.append(status);
8130
8131 msg.append(StringPool.CLOSE_CURLY_BRACE);
8132
8133 throw new NoSuchThreadException(msg.toString());
8134 }
8135
8136
8146 @Override
8147 public MBThread fetchByG_C_S_First(long groupId, long categoryId,
8148 int status, OrderByComparator orderByComparator)
8149 throws SystemException {
8150 List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
8151 orderByComparator);
8152
8153 if (!list.isEmpty()) {
8154 return list.get(0);
8155 }
8156
8157 return null;
8158 }
8159
8160
8171 @Override
8172 public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
8173 OrderByComparator orderByComparator)
8174 throws NoSuchThreadException, SystemException {
8175 MBThread mbThread = fetchByG_C_S_Last(groupId, categoryId, status,
8176 orderByComparator);
8177
8178 if (mbThread != null) {
8179 return mbThread;
8180 }
8181
8182 StringBundler msg = new StringBundler(8);
8183
8184 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8185
8186 msg.append("groupId=");
8187 msg.append(groupId);
8188
8189 msg.append(", categoryId=");
8190 msg.append(categoryId);
8191
8192 msg.append(", status=");
8193 msg.append(status);
8194
8195 msg.append(StringPool.CLOSE_CURLY_BRACE);
8196
8197 throw new NoSuchThreadException(msg.toString());
8198 }
8199
8200
8210 @Override
8211 public MBThread fetchByG_C_S_Last(long groupId, long categoryId,
8212 int status, OrderByComparator orderByComparator)
8213 throws SystemException {
8214 int count = countByG_C_S(groupId, categoryId, status);
8215
8216 if (count == 0) {
8217 return null;
8218 }
8219
8220 List<MBThread> list = findByG_C_S(groupId, categoryId, status,
8221 count - 1, count, orderByComparator);
8222
8223 if (!list.isEmpty()) {
8224 return list.get(0);
8225 }
8226
8227 return null;
8228 }
8229
8230
8242 @Override
8243 public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
8244 long categoryId, int status, OrderByComparator orderByComparator)
8245 throws NoSuchThreadException, SystemException {
8246 MBThread mbThread = findByPrimaryKey(threadId);
8247
8248 Session session = null;
8249
8250 try {
8251 session = openSession();
8252
8253 MBThread[] array = new MBThreadImpl[3];
8254
8255 array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8256 categoryId, status, orderByComparator, true);
8257
8258 array[1] = mbThread;
8259
8260 array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8261 categoryId, status, orderByComparator, false);
8262
8263 return array;
8264 }
8265 catch (Exception e) {
8266 throw processException(e);
8267 }
8268 finally {
8269 closeSession(session);
8270 }
8271 }
8272
8273 protected MBThread getByG_C_S_PrevAndNext(Session session,
8274 MBThread mbThread, long groupId, long categoryId, int status,
8275 OrderByComparator orderByComparator, boolean previous) {
8276 StringBundler query = null;
8277
8278 if (orderByComparator != null) {
8279 query = new StringBundler(6 +
8280 (orderByComparator.getOrderByFields().length * 6));
8281 }
8282 else {
8283 query = new StringBundler(3);
8284 }
8285
8286 query.append(_SQL_SELECT_MBTHREAD_WHERE);
8287
8288 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8289
8290 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8291
8292 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8293
8294 if (orderByComparator != null) {
8295 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8296
8297 if (orderByConditionFields.length > 0) {
8298 query.append(WHERE_AND);
8299 }
8300
8301 for (int i = 0; i < orderByConditionFields.length; i++) {
8302 query.append(_ORDER_BY_ENTITY_ALIAS);
8303 query.append(orderByConditionFields[i]);
8304
8305 if ((i + 1) < orderByConditionFields.length) {
8306 if (orderByComparator.isAscending() ^ previous) {
8307 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8308 }
8309 else {
8310 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8311 }
8312 }
8313 else {
8314 if (orderByComparator.isAscending() ^ previous) {
8315 query.append(WHERE_GREATER_THAN);
8316 }
8317 else {
8318 query.append(WHERE_LESSER_THAN);
8319 }
8320 }
8321 }
8322
8323 query.append(ORDER_BY_CLAUSE);
8324
8325 String[] orderByFields = orderByComparator.getOrderByFields();
8326
8327 for (int i = 0; i < orderByFields.length; i++) {
8328 query.append(_ORDER_BY_ENTITY_ALIAS);
8329 query.append(orderByFields[i]);
8330
8331 if ((i + 1) < orderByFields.length) {
8332 if (orderByComparator.isAscending() ^ previous) {
8333 query.append(ORDER_BY_ASC_HAS_NEXT);
8334 }
8335 else {
8336 query.append(ORDER_BY_DESC_HAS_NEXT);
8337 }
8338 }
8339 else {
8340 if (orderByComparator.isAscending() ^ previous) {
8341 query.append(ORDER_BY_ASC);
8342 }
8343 else {
8344 query.append(ORDER_BY_DESC);
8345 }
8346 }
8347 }
8348 }
8349 else {
8350 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8351 }
8352
8353 String sql = query.toString();
8354
8355 Query q = session.createQuery(sql);
8356
8357 q.setFirstResult(0);
8358 q.setMaxResults(2);
8359
8360 QueryPos qPos = QueryPos.getInstance(q);
8361
8362 qPos.add(groupId);
8363
8364 qPos.add(categoryId);
8365
8366 qPos.add(status);
8367
8368 if (orderByComparator != null) {
8369 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8370
8371 for (Object value : values) {
8372 qPos.add(value);
8373 }
8374 }
8375
8376 List<MBThread> list = q.list();
8377
8378 if (list.size() == 2) {
8379 return list.get(1);
8380 }
8381 else {
8382 return null;
8383 }
8384 }
8385
8386
8395 @Override
8396 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8397 int status) throws SystemException {
8398 return filterFindByG_C_S(groupId, categoryId, status,
8399 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8400 }
8401
8402
8417 @Override
8418 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8419 int status, int start, int end) throws SystemException {
8420 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
8421 }
8422
8423
8439 @Override
8440 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8441 int status, int start, int end, OrderByComparator orderByComparator)
8442 throws SystemException {
8443 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8444 return findByG_C_S(groupId, categoryId, status, start, end,
8445 orderByComparator);
8446 }
8447
8448 StringBundler query = null;
8449
8450 if (orderByComparator != null) {
8451 query = new StringBundler(5 +
8452 (orderByComparator.getOrderByFields().length * 3));
8453 }
8454 else {
8455 query = new StringBundler(5);
8456 }
8457
8458 if (getDB().isSupportsInlineDistinct()) {
8459 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8460 }
8461 else {
8462 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8463 }
8464
8465 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8466
8467 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8468
8469 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8470
8471 if (!getDB().isSupportsInlineDistinct()) {
8472 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8473 }
8474
8475 if (orderByComparator != null) {
8476 if (getDB().isSupportsInlineDistinct()) {
8477 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8478 orderByComparator, true);
8479 }
8480 else {
8481 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8482 orderByComparator, true);
8483 }
8484 }
8485 else {
8486 if (getDB().isSupportsInlineDistinct()) {
8487 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8488 }
8489 else {
8490 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8491 }
8492 }
8493
8494 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8495 MBThread.class.getName(),
8496 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8497
8498 Session session = null;
8499
8500 try {
8501 session = openSession();
8502
8503 SQLQuery q = session.createSQLQuery(sql);
8504
8505 if (getDB().isSupportsInlineDistinct()) {
8506 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8507 }
8508 else {
8509 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8510 }
8511
8512 QueryPos qPos = QueryPos.getInstance(q);
8513
8514 qPos.add(groupId);
8515
8516 qPos.add(categoryId);
8517
8518 qPos.add(status);
8519
8520 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8521 }
8522 catch (Exception e) {
8523 throw processException(e);
8524 }
8525 finally {
8526 closeSession(session);
8527 }
8528 }
8529
8530
8542 @Override
8543 public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
8544 long groupId, long categoryId, int status,
8545 OrderByComparator orderByComparator)
8546 throws NoSuchThreadException, SystemException {
8547 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8548 return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
8549 status, orderByComparator);
8550 }
8551
8552 MBThread mbThread = findByPrimaryKey(threadId);
8553
8554 Session session = null;
8555
8556 try {
8557 session = openSession();
8558
8559 MBThread[] array = new MBThreadImpl[3];
8560
8561 array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8562 categoryId, status, orderByComparator, true);
8563
8564 array[1] = mbThread;
8565
8566 array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8567 categoryId, status, orderByComparator, false);
8568
8569 return array;
8570 }
8571 catch (Exception e) {
8572 throw processException(e);
8573 }
8574 finally {
8575 closeSession(session);
8576 }
8577 }
8578
8579 protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
8580 MBThread mbThread, long groupId, long categoryId, int status,
8581 OrderByComparator orderByComparator, boolean previous) {
8582 StringBundler query = null;
8583
8584 if (orderByComparator != null) {
8585 query = new StringBundler(6 +
8586 (orderByComparator.getOrderByFields().length * 6));
8587 }
8588 else {
8589 query = new StringBundler(3);
8590 }
8591
8592 if (getDB().isSupportsInlineDistinct()) {
8593 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8594 }
8595 else {
8596 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8597 }
8598
8599 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8600
8601 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8602
8603 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8604
8605 if (!getDB().isSupportsInlineDistinct()) {
8606 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8607 }
8608
8609 if (orderByComparator != null) {
8610 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8611
8612 if (orderByConditionFields.length > 0) {
8613 query.append(WHERE_AND);
8614 }
8615
8616 for (int i = 0; i < orderByConditionFields.length; i++) {
8617 if (getDB().isSupportsInlineDistinct()) {
8618 query.append(_ORDER_BY_ENTITY_ALIAS);
8619 }
8620 else {
8621 query.append(_ORDER_BY_ENTITY_TABLE);
8622 }
8623
8624 query.append(orderByConditionFields[i]);
8625
8626 if ((i + 1) < orderByConditionFields.length) {
8627 if (orderByComparator.isAscending() ^ previous) {
8628 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8629 }
8630 else {
8631 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8632 }
8633 }
8634 else {
8635 if (orderByComparator.isAscending() ^ previous) {
8636 query.append(WHERE_GREATER_THAN);
8637 }
8638 else {
8639 query.append(WHERE_LESSER_THAN);
8640 }
8641 }
8642 }
8643
8644 query.append(ORDER_BY_CLAUSE);
8645
8646 String[] orderByFields = orderByComparator.getOrderByFields();
8647
8648 for (int i = 0; i < orderByFields.length; i++) {
8649 if (getDB().isSupportsInlineDistinct()) {
8650 query.append(_ORDER_BY_ENTITY_ALIAS);
8651 }
8652 else {
8653 query.append(_ORDER_BY_ENTITY_TABLE);
8654 }
8655
8656 query.append(orderByFields[i]);
8657
8658 if ((i + 1) < orderByFields.length) {
8659 if (orderByComparator.isAscending() ^ previous) {
8660 query.append(ORDER_BY_ASC_HAS_NEXT);
8661 }
8662 else {
8663 query.append(ORDER_BY_DESC_HAS_NEXT);
8664 }
8665 }
8666 else {
8667 if (orderByComparator.isAscending() ^ previous) {
8668 query.append(ORDER_BY_ASC);
8669 }
8670 else {
8671 query.append(ORDER_BY_DESC);
8672 }
8673 }
8674 }
8675 }
8676 else {
8677 if (getDB().isSupportsInlineDistinct()) {
8678 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8679 }
8680 else {
8681 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8682 }
8683 }
8684
8685 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8686 MBThread.class.getName(),
8687 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8688
8689 SQLQuery q = session.createSQLQuery(sql);
8690
8691 q.setFirstResult(0);
8692 q.setMaxResults(2);
8693
8694 if (getDB().isSupportsInlineDistinct()) {
8695 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8696 }
8697 else {
8698 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8699 }
8700
8701 QueryPos qPos = QueryPos.getInstance(q);
8702
8703 qPos.add(groupId);
8704
8705 qPos.add(categoryId);
8706
8707 qPos.add(status);
8708
8709 if (orderByComparator != null) {
8710 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8711
8712 for (Object value : values) {
8713 qPos.add(value);
8714 }
8715 }
8716
8717 List<MBThread> list = q.list();
8718
8719 if (list.size() == 2) {
8720 return list.get(1);
8721 }
8722 else {
8723 return null;
8724 }
8725 }
8726
8727
8736 @Override
8737 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8738 int status) throws SystemException {
8739 return filterFindByG_C_S(groupId, categoryIds, status,
8740 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8741 }
8742
8743
8758 @Override
8759 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8760 int status, int start, int end) throws SystemException {
8761 return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
8762 }
8763
8764
8780 @Override
8781 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8782 int status, int start, int end, OrderByComparator orderByComparator)
8783 throws SystemException {
8784 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8785 return findByG_C_S(groupId, categoryIds, status, start, end,
8786 orderByComparator);
8787 }
8788
8789 StringBundler query = new StringBundler();
8790
8791 if (getDB().isSupportsInlineDistinct()) {
8792 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8793 }
8794 else {
8795 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8796 }
8797
8798 boolean conjunctionable = false;
8799
8800 if (conjunctionable) {
8801 query.append(WHERE_AND);
8802 }
8803
8804 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
8805
8806 conjunctionable = true;
8807
8808 if ((categoryIds == null) || (categoryIds.length > 0)) {
8809 if (conjunctionable) {
8810 query.append(WHERE_AND);
8811 }
8812
8813 query.append(StringPool.OPEN_PARENTHESIS);
8814
8815 for (int i = 0; i < categoryIds.length; i++) {
8816 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
8817
8818 if ((i + 1) < categoryIds.length) {
8819 query.append(WHERE_OR);
8820 }
8821 }
8822
8823 query.append(StringPool.CLOSE_PARENTHESIS);
8824
8825 conjunctionable = true;
8826 }
8827
8828 if (conjunctionable) {
8829 query.append(WHERE_AND);
8830 }
8831
8832 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
8833
8834 conjunctionable = true;
8835
8836 if (!getDB().isSupportsInlineDistinct()) {
8837 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8838 }
8839
8840 if (orderByComparator != null) {
8841 if (getDB().isSupportsInlineDistinct()) {
8842 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8843 orderByComparator, true);
8844 }
8845 else {
8846 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8847 orderByComparator, true);
8848 }
8849 }
8850 else {
8851 if (getDB().isSupportsInlineDistinct()) {
8852 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8853 }
8854 else {
8855 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8856 }
8857 }
8858
8859 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8860 MBThread.class.getName(),
8861 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8862
8863 Session session = null;
8864
8865 try {
8866 session = openSession();
8867
8868 SQLQuery q = session.createSQLQuery(sql);
8869
8870 if (getDB().isSupportsInlineDistinct()) {
8871 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8872 }
8873 else {
8874 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8875 }
8876
8877 QueryPos qPos = QueryPos.getInstance(q);
8878
8879 qPos.add(groupId);
8880
8881 if (categoryIds != null) {
8882 qPos.add(categoryIds);
8883 }
8884
8885 qPos.add(status);
8886
8887 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8888 }
8889 catch (Exception e) {
8890 throw processException(e);
8891 }
8892 finally {
8893 closeSession(session);
8894 }
8895 }
8896
8897
8910 @Override
8911 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8912 int status) throws SystemException {
8913 return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
8914 QueryUtil.ALL_POS, null);
8915 }
8916
8917
8932 @Override
8933 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8934 int status, int start, int end) throws SystemException {
8935 return findByG_C_S(groupId, categoryIds, status, start, end, null);
8936 }
8937
8938
8954 @Override
8955 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8956 int status, int start, int end, OrderByComparator orderByComparator)
8957 throws SystemException {
8958 if ((categoryIds != null) && (categoryIds.length == 1)) {
8959 return findByG_C_S(groupId, categoryIds[0], status, start, end,
8960 orderByComparator);
8961 }
8962
8963 boolean pagination = true;
8964 Object[] finderArgs = null;
8965
8966 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8967 (orderByComparator == null)) {
8968 pagination = false;
8969 finderArgs = new Object[] {
8970 groupId, StringUtil.merge(categoryIds), status
8971 };
8972 }
8973 else {
8974 finderArgs = new Object[] {
8975 groupId, StringUtil.merge(categoryIds), status,
8976
8977 start, end, orderByComparator
8978 };
8979 }
8980
8981 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8982 finderArgs, this);
8983
8984 if ((list != null) && !list.isEmpty()) {
8985 for (MBThread mbThread : list) {
8986 if ((groupId != mbThread.getGroupId()) ||
8987 !ArrayUtil.contains(categoryIds,
8988 mbThread.getCategoryId()) ||
8989 (status != mbThread.getStatus())) {
8990 list = null;
8991
8992 break;
8993 }
8994 }
8995 }
8996
8997 if (list == null) {
8998 StringBundler query = new StringBundler();
8999
9000 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9001
9002 boolean conjunctionable = false;
9003
9004 if (conjunctionable) {
9005 query.append(WHERE_AND);
9006 }
9007
9008 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
9009
9010 conjunctionable = true;
9011
9012 if ((categoryIds == null) || (categoryIds.length > 0)) {
9013 if (conjunctionable) {
9014 query.append(WHERE_AND);
9015 }
9016
9017 query.append(StringPool.OPEN_PARENTHESIS);
9018
9019 for (int i = 0; i < categoryIds.length; i++) {
9020 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9021
9022 if ((i + 1) < categoryIds.length) {
9023 query.append(WHERE_OR);
9024 }
9025 }
9026
9027 query.append(StringPool.CLOSE_PARENTHESIS);
9028
9029 conjunctionable = true;
9030 }
9031
9032 if (conjunctionable) {
9033 query.append(WHERE_AND);
9034 }
9035
9036 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9037
9038 conjunctionable = true;
9039
9040 if (orderByComparator != null) {
9041 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9042 orderByComparator);
9043 }
9044 else
9045 if (pagination) {
9046 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9047 }
9048
9049 String sql = query.toString();
9050
9051 Session session = null;
9052
9053 try {
9054 session = openSession();
9055
9056 Query q = session.createQuery(sql);
9057
9058 QueryPos qPos = QueryPos.getInstance(q);
9059
9060 qPos.add(groupId);
9061
9062 if (categoryIds != null) {
9063 qPos.add(categoryIds);
9064 }
9065
9066 qPos.add(status);
9067
9068 if (!pagination) {
9069 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9070 start, end, false);
9071
9072 Collections.sort(list);
9073
9074 list = new UnmodifiableList<MBThread>(list);
9075 }
9076 else {
9077 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9078 start, end);
9079 }
9080
9081 cacheResult(list);
9082
9083 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
9084 finderArgs, list);
9085 }
9086 catch (Exception e) {
9087 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
9088 finderArgs);
9089
9090 throw processException(e);
9091 }
9092 finally {
9093 closeSession(session);
9094 }
9095 }
9096
9097 return list;
9098 }
9099
9100
9108 @Override
9109 public void removeByG_C_S(long groupId, long categoryId, int status)
9110 throws SystemException {
9111 for (MBThread mbThread : findByG_C_S(groupId, categoryId, status,
9112 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9113 remove(mbThread);
9114 }
9115 }
9116
9117
9126 @Override
9127 public int countByG_C_S(long groupId, long categoryId, int status)
9128 throws SystemException {
9129 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
9130
9131 Object[] finderArgs = new Object[] { groupId, categoryId, status };
9132
9133 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9134 this);
9135
9136 if (count == null) {
9137 StringBundler query = new StringBundler(4);
9138
9139 query.append(_SQL_COUNT_MBTHREAD_WHERE);
9140
9141 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9142
9143 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
9144
9145 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9146
9147 String sql = query.toString();
9148
9149 Session session = null;
9150
9151 try {
9152 session = openSession();
9153
9154 Query q = session.createQuery(sql);
9155
9156 QueryPos qPos = QueryPos.getInstance(q);
9157
9158 qPos.add(groupId);
9159
9160 qPos.add(categoryId);
9161
9162 qPos.add(status);
9163
9164 count = (Long)q.uniqueResult();
9165
9166 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9167 }
9168 catch (Exception e) {
9169 FinderCacheUtil.removeResult(finderPath, finderArgs);
9170
9171 throw processException(e);
9172 }
9173 finally {
9174 closeSession(session);
9175 }
9176 }
9177
9178 return count.intValue();
9179 }
9180
9181
9190 @Override
9191 public int countByG_C_S(long groupId, long[] categoryIds, int status)
9192 throws SystemException {
9193 Object[] finderArgs = new Object[] {
9194 groupId, StringUtil.merge(categoryIds), status
9195 };
9196
9197 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9198 finderArgs, this);
9199
9200 if (count == null) {
9201 StringBundler query = new StringBundler();
9202
9203 query.append(_SQL_COUNT_MBTHREAD_WHERE);
9204
9205 boolean conjunctionable = false;
9206
9207 if (conjunctionable) {
9208 query.append(WHERE_AND);
9209 }
9210
9211 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
9212
9213 conjunctionable = true;
9214
9215 if ((categoryIds == null) || (categoryIds.length > 0)) {
9216 if (conjunctionable) {
9217 query.append(WHERE_AND);
9218 }
9219
9220 query.append(StringPool.OPEN_PARENTHESIS);
9221
9222 for (int i = 0; i < categoryIds.length; i++) {
9223 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9224
9225 if ((i + 1) < categoryIds.length) {
9226 query.append(WHERE_OR);
9227 }
9228 }
9229
9230 query.append(StringPool.CLOSE_PARENTHESIS);
9231
9232 conjunctionable = true;
9233 }
9234
9235 if (conjunctionable) {
9236 query.append(WHERE_AND);
9237 }
9238
9239 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9240
9241 conjunctionable = true;
9242
9243 String sql = query.toString();
9244
9245 Session session = null;
9246
9247 try {
9248 session = openSession();
9249
9250 Query q = session.createQuery(sql);
9251
9252 QueryPos qPos = QueryPos.getInstance(q);
9253
9254 qPos.add(groupId);
9255
9256 if (categoryIds != null) {
9257 qPos.add(categoryIds);
9258 }
9259
9260 qPos.add(status);
9261
9262 count = (Long)q.uniqueResult();
9263
9264 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9265 finderArgs, count);
9266 }
9267 catch (Exception e) {
9268 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
9269 finderArgs);
9270
9271 throw processException(e);
9272 }
9273 finally {
9274 closeSession(session);
9275 }
9276 }
9277
9278 return count.intValue();
9279 }
9280
9281
9290 @Override
9291 public int filterCountByG_C_S(long groupId, long categoryId, int status)
9292 throws SystemException {
9293 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9294 return countByG_C_S(groupId, categoryId, status);
9295 }
9296
9297 StringBundler query = new StringBundler(4);
9298
9299 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9300
9301 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9302
9303 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
9304
9305 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9306
9307 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9308 MBThread.class.getName(),
9309 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9310
9311 Session session = null;
9312
9313 try {
9314 session = openSession();
9315
9316 SQLQuery q = session.createSQLQuery(sql);
9317
9318 q.addScalar(COUNT_COLUMN_NAME,
9319 com.liferay.portal.kernel.dao.orm.Type.LONG);
9320
9321 QueryPos qPos = QueryPos.getInstance(q);
9322
9323 qPos.add(groupId);
9324
9325 qPos.add(categoryId);
9326
9327 qPos.add(status);
9328
9329 Long count = (Long)q.uniqueResult();
9330
9331 return count.intValue();
9332 }
9333 catch (Exception e) {
9334 throw processException(e);
9335 }
9336 finally {
9337 closeSession(session);
9338 }
9339 }
9340
9341
9350 @Override
9351 public int filterCountByG_C_S(long groupId, long[] categoryIds, int status)
9352 throws SystemException {
9353 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9354 return countByG_C_S(groupId, categoryIds, status);
9355 }
9356
9357 StringBundler query = new StringBundler();
9358
9359 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9360
9361 boolean conjunctionable = false;
9362
9363 if (conjunctionable) {
9364 query.append(WHERE_AND);
9365 }
9366
9367 query.append(_FINDER_COLUMN_G_C_S_GROUPID_5);
9368
9369 conjunctionable = true;
9370
9371 if ((categoryIds == null) || (categoryIds.length > 0)) {
9372 if (conjunctionable) {
9373 query.append(WHERE_AND);
9374 }
9375
9376 query.append(StringPool.OPEN_PARENTHESIS);
9377
9378 for (int i = 0; i < categoryIds.length; i++) {
9379 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_5);
9380
9381 if ((i + 1) < categoryIds.length) {
9382 query.append(WHERE_OR);
9383 }
9384 }
9385
9386 query.append(StringPool.CLOSE_PARENTHESIS);
9387
9388 conjunctionable = true;
9389 }
9390
9391 if (conjunctionable) {
9392 query.append(WHERE_AND);
9393 }
9394
9395 query.append(_FINDER_COLUMN_G_C_S_STATUS_5);
9396
9397 conjunctionable = true;
9398
9399 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9400 MBThread.class.getName(),
9401 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9402
9403 Session session = null;
9404
9405 try {
9406 session = openSession();
9407
9408 SQLQuery q = session.createSQLQuery(sql);
9409
9410 q.addScalar(COUNT_COLUMN_NAME,
9411 com.liferay.portal.kernel.dao.orm.Type.LONG);
9412
9413 QueryPos qPos = QueryPos.getInstance(q);
9414
9415 qPos.add(groupId);
9416
9417 if (categoryIds != null) {
9418 qPos.add(categoryIds);
9419 }
9420
9421 qPos.add(status);
9422
9423 Long count = (Long)q.uniqueResult();
9424
9425 return count.intValue();
9426 }
9427 catch (Exception e) {
9428 throw processException(e);
9429 }
9430 finally {
9431 closeSession(session);
9432 }
9433 }
9434
9435 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9436 private static final String _FINDER_COLUMN_G_C_S_GROUPID_5 = "(" +
9437 removeConjunction(_FINDER_COLUMN_G_C_S_GROUPID_2) + ")";
9438 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9439 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_5 = "(" +
9440 removeConjunction(_FINDER_COLUMN_G_C_S_CATEGORYID_2) + ")";
9441 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9442 private static final String _FINDER_COLUMN_G_C_S_STATUS_5 = "(" +
9443 removeConjunction(_FINDER_COLUMN_G_C_S_STATUS_2) + ")";
9444 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9445 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
9446 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_NotS",
9447 new String[] {
9448 Long.class.getName(), Long.class.getName(),
9449 Integer.class.getName(),
9450
9451 Integer.class.getName(), Integer.class.getName(),
9452 OrderByComparator.class.getName()
9453 });
9454 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS =
9455 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9456 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
9457 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_NotS",
9458 new String[] {
9459 Long.class.getName(), Long.class.getName(),
9460 Integer.class.getName()
9461 });
9462
9463
9472 @Override
9473 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9474 int status) throws SystemException {
9475 return findByG_C_NotS(groupId, categoryId, status, QueryUtil.ALL_POS,
9476 QueryUtil.ALL_POS, null);
9477 }
9478
9479
9494 @Override
9495 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9496 int status, int start, int end) throws SystemException {
9497 return findByG_C_NotS(groupId, categoryId, status, start, end, null);
9498 }
9499
9500
9516 @Override
9517 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9518 int status, int start, int end, OrderByComparator orderByComparator)
9519 throws SystemException {
9520 boolean pagination = true;
9521 FinderPath finderPath = null;
9522 Object[] finderArgs = null;
9523
9524 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS;
9525 finderArgs = new Object[] {
9526 groupId, categoryId, status,
9527
9528 start, end, orderByComparator
9529 };
9530
9531 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
9532 finderArgs, this);
9533
9534 if ((list != null) && !list.isEmpty()) {
9535 for (MBThread mbThread : list) {
9536 if ((groupId != mbThread.getGroupId()) ||
9537 (categoryId != mbThread.getCategoryId()) ||
9538 (status == mbThread.getStatus())) {
9539 list = null;
9540
9541 break;
9542 }
9543 }
9544 }
9545
9546 if (list == null) {
9547 StringBundler query = null;
9548
9549 if (orderByComparator != null) {
9550 query = new StringBundler(5 +
9551 (orderByComparator.getOrderByFields().length * 3));
9552 }
9553 else {
9554 query = new StringBundler(5);
9555 }
9556
9557 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9558
9559 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9560
9561 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9562
9563 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9564
9565 if (orderByComparator != null) {
9566 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9567 orderByComparator);
9568 }
9569 else
9570 if (pagination) {
9571 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9572 }
9573
9574 String sql = query.toString();
9575
9576 Session session = null;
9577
9578 try {
9579 session = openSession();
9580
9581 Query q = session.createQuery(sql);
9582
9583 QueryPos qPos = QueryPos.getInstance(q);
9584
9585 qPos.add(groupId);
9586
9587 qPos.add(categoryId);
9588
9589 qPos.add(status);
9590
9591 if (!pagination) {
9592 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9593 start, end, false);
9594
9595 Collections.sort(list);
9596
9597 list = new UnmodifiableList<MBThread>(list);
9598 }
9599 else {
9600 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9601 start, end);
9602 }
9603
9604 cacheResult(list);
9605
9606 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9607 }
9608 catch (Exception e) {
9609 FinderCacheUtil.removeResult(finderPath, finderArgs);
9610
9611 throw processException(e);
9612 }
9613 finally {
9614 closeSession(session);
9615 }
9616 }
9617
9618 return list;
9619 }
9620
9621
9632 @Override
9633 public MBThread findByG_C_NotS_First(long groupId, long categoryId,
9634 int status, OrderByComparator orderByComparator)
9635 throws NoSuchThreadException, SystemException {
9636 MBThread mbThread = fetchByG_C_NotS_First(groupId, categoryId, status,
9637 orderByComparator);
9638
9639 if (mbThread != null) {
9640 return mbThread;
9641 }
9642
9643 StringBundler msg = new StringBundler(8);
9644
9645 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9646
9647 msg.append("groupId=");
9648 msg.append(groupId);
9649
9650 msg.append(", categoryId=");
9651 msg.append(categoryId);
9652
9653 msg.append(", status=");
9654 msg.append(status);
9655
9656 msg.append(StringPool.CLOSE_CURLY_BRACE);
9657
9658 throw new NoSuchThreadException(msg.toString());
9659 }
9660
9661
9671 @Override
9672 public MBThread fetchByG_C_NotS_First(long groupId, long categoryId,
9673 int status, OrderByComparator orderByComparator)
9674 throws SystemException {
9675 List<MBThread> list = findByG_C_NotS(groupId, categoryId, status, 0, 1,
9676 orderByComparator);
9677
9678 if (!list.isEmpty()) {
9679 return list.get(0);
9680 }
9681
9682 return null;
9683 }
9684
9685
9696 @Override
9697 public MBThread findByG_C_NotS_Last(long groupId, long categoryId,
9698 int status, OrderByComparator orderByComparator)
9699 throws NoSuchThreadException, SystemException {
9700 MBThread mbThread = fetchByG_C_NotS_Last(groupId, categoryId, status,
9701 orderByComparator);
9702
9703 if (mbThread != null) {
9704 return mbThread;
9705 }
9706
9707 StringBundler msg = new StringBundler(8);
9708
9709 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9710
9711 msg.append("groupId=");
9712 msg.append(groupId);
9713
9714 msg.append(", categoryId=");
9715 msg.append(categoryId);
9716
9717 msg.append(", status=");
9718 msg.append(status);
9719
9720 msg.append(StringPool.CLOSE_CURLY_BRACE);
9721
9722 throw new NoSuchThreadException(msg.toString());
9723 }
9724
9725
9735 @Override
9736 public MBThread fetchByG_C_NotS_Last(long groupId, long categoryId,
9737 int status, OrderByComparator orderByComparator)
9738 throws SystemException {
9739 int count = countByG_C_NotS(groupId, categoryId, status);
9740
9741 if (count == 0) {
9742 return null;
9743 }
9744
9745 List<MBThread> list = findByG_C_NotS(groupId, categoryId, status,
9746 count - 1, count, orderByComparator);
9747
9748 if (!list.isEmpty()) {
9749 return list.get(0);
9750 }
9751
9752 return null;
9753 }
9754
9755
9767 @Override
9768 public MBThread[] findByG_C_NotS_PrevAndNext(long threadId, long groupId,
9769 long categoryId, int status, OrderByComparator orderByComparator)
9770 throws NoSuchThreadException, SystemException {
9771 MBThread mbThread = findByPrimaryKey(threadId);
9772
9773 Session session = null;
9774
9775 try {
9776 session = openSession();
9777
9778 MBThread[] array = new MBThreadImpl[3];
9779
9780 array[0] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9781 categoryId, status, orderByComparator, true);
9782
9783 array[1] = mbThread;
9784
9785 array[2] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9786 categoryId, status, orderByComparator, false);
9787
9788 return array;
9789 }
9790 catch (Exception e) {
9791 throw processException(e);
9792 }
9793 finally {
9794 closeSession(session);
9795 }
9796 }
9797
9798 protected MBThread getByG_C_NotS_PrevAndNext(Session session,
9799 MBThread mbThread, long groupId, long categoryId, int status,
9800 OrderByComparator orderByComparator, boolean previous) {
9801 StringBundler query = null;
9802
9803 if (orderByComparator != null) {
9804 query = new StringBundler(6 +
9805 (orderByComparator.getOrderByFields().length * 6));
9806 }
9807 else {
9808 query = new StringBundler(3);
9809 }
9810
9811 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9812
9813 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9814
9815 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9816
9817 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9818
9819 if (orderByComparator != null) {
9820 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9821
9822 if (orderByConditionFields.length > 0) {
9823 query.append(WHERE_AND);
9824 }
9825
9826 for (int i = 0; i < orderByConditionFields.length; i++) {
9827 query.append(_ORDER_BY_ENTITY_ALIAS);
9828 query.append(orderByConditionFields[i]);
9829
9830 if ((i + 1) < orderByConditionFields.length) {
9831 if (orderByComparator.isAscending() ^ previous) {
9832 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9833 }
9834 else {
9835 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9836 }
9837 }
9838 else {
9839 if (orderByComparator.isAscending() ^ previous) {
9840 query.append(WHERE_GREATER_THAN);
9841 }
9842 else {
9843 query.append(WHERE_LESSER_THAN);
9844 }
9845 }
9846 }
9847
9848 query.append(ORDER_BY_CLAUSE);
9849
9850 String[] orderByFields = orderByComparator.getOrderByFields();
9851
9852 for (int i = 0; i < orderByFields.length; i++) {
9853 query.append(_ORDER_BY_ENTITY_ALIAS);
9854 query.append(orderByFields[i]);
9855
9856 if ((i + 1) < orderByFields.length) {
9857 if (orderByComparator.isAscending() ^ previous) {
9858 query.append(ORDER_BY_ASC_HAS_NEXT);
9859 }
9860 else {
9861 query.append(ORDER_BY_DESC_HAS_NEXT);
9862 }
9863 }
9864 else {
9865 if (orderByComparator.isAscending() ^ previous) {
9866 query.append(ORDER_BY_ASC);
9867 }
9868 else {
9869 query.append(ORDER_BY_DESC);
9870 }
9871 }
9872 }
9873 }
9874 else {
9875 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9876 }
9877
9878 String sql = query.toString();
9879
9880 Query q = session.createQuery(sql);
9881
9882 q.setFirstResult(0);
9883 q.setMaxResults(2);
9884
9885 QueryPos qPos = QueryPos.getInstance(q);
9886
9887 qPos.add(groupId);
9888
9889 qPos.add(categoryId);
9890
9891 qPos.add(status);
9892
9893 if (orderByComparator != null) {
9894 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9895
9896 for (Object value : values) {
9897 qPos.add(value);
9898 }
9899 }
9900
9901 List<MBThread> list = q.list();
9902
9903 if (list.size() == 2) {
9904 return list.get(1);
9905 }
9906 else {
9907 return null;
9908 }
9909 }
9910
9911
9920 @Override
9921 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9922 int status) throws SystemException {
9923 return filterFindByG_C_NotS(groupId, categoryId, status,
9924 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9925 }
9926
9927
9942 @Override
9943 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9944 int status, int start, int end) throws SystemException {
9945 return filterFindByG_C_NotS(groupId, categoryId, status, start, end,
9946 null);
9947 }
9948
9949
9965 @Override
9966 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9967 int status, int start, int end, OrderByComparator orderByComparator)
9968 throws SystemException {
9969 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9970 return findByG_C_NotS(groupId, categoryId, status, start, end,
9971 orderByComparator);
9972 }
9973
9974 StringBundler query = null;
9975
9976 if (orderByComparator != null) {
9977 query = new StringBundler(5 +
9978 (orderByComparator.getOrderByFields().length * 3));
9979 }
9980 else {
9981 query = new StringBundler(5);
9982 }
9983
9984 if (getDB().isSupportsInlineDistinct()) {
9985 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9986 }
9987 else {
9988 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9989 }
9990
9991 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9992
9993 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9994
9995 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9996
9997 if (!getDB().isSupportsInlineDistinct()) {
9998 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9999 }
10000
10001 if (orderByComparator != null) {
10002 if (getDB().isSupportsInlineDistinct()) {
10003 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10004 orderByComparator, true);
10005 }
10006 else {
10007 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10008 orderByComparator, true);
10009 }
10010 }
10011 else {
10012 if (getDB().isSupportsInlineDistinct()) {
10013 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10014 }
10015 else {
10016 query.append(MBThreadModelImpl.ORDER_BY_SQL);
10017 }
10018 }
10019
10020 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10021 MBThread.class.getName(),
10022 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10023
10024 Session session = null;
10025
10026 try {
10027 session = openSession();
10028
10029 SQLQuery q = session.createSQLQuery(sql);
10030
10031 if (getDB().isSupportsInlineDistinct()) {
10032 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10033 }
10034 else {
10035 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10036 }
10037
10038 QueryPos qPos = QueryPos.getInstance(q);
10039
10040 qPos.add(groupId);
10041
10042 qPos.add(categoryId);
10043
10044 qPos.add(status);
10045
10046 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
10047 }
10048 catch (Exception e) {
10049 throw processException(e);
10050 }
10051 finally {
10052 closeSession(session);
10053 }
10054 }
10055
10056
10068 @Override
10069 public MBThread[] filterFindByG_C_NotS_PrevAndNext(long threadId,
10070 long groupId, long categoryId, int status,
10071 OrderByComparator orderByComparator)
10072 throws NoSuchThreadException, SystemException {
10073 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10074 return findByG_C_NotS_PrevAndNext(threadId, groupId, categoryId,
10075 status, orderByComparator);
10076 }
10077
10078 MBThread mbThread = findByPrimaryKey(threadId);
10079
10080 Session session = null;
10081
10082 try {
10083 session = openSession();
10084
10085 MBThread[] array = new MBThreadImpl[3];
10086
10087 array[0] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
10088 groupId, categoryId, status, orderByComparator, true);
10089
10090 array[1] = mbThread;
10091
10092 array[2] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
10093 groupId, categoryId, status, orderByComparator, false);
10094
10095 return array;
10096 }
10097 catch (Exception e) {
10098 throw processException(e);
10099 }
10100 finally {
10101 closeSession(session);
10102 }
10103 }
10104
10105 protected MBThread filterGetByG_C_NotS_PrevAndNext(Session session,
10106 MBThread mbThread, long groupId, long categoryId, int status,
10107 OrderByComparator orderByComparator, boolean previous) {
10108 StringBundler query = null;
10109
10110 if (orderByComparator != null) {
10111 query = new StringBundler(6 +
10112 (orderByComparator.getOrderByFields().length * 6));
10113 }
10114 else {
10115 query = new StringBundler(3);
10116 }
10117
10118 if (getDB().isSupportsInlineDistinct()) {
10119 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10120 }
10121 else {
10122 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10123 }
10124
10125 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10126
10127 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10128
10129 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10130
10131 if (!getDB().isSupportsInlineDistinct()) {
10132 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10133 }
10134
10135 if (orderByComparator != null) {
10136 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10137
10138 if (orderByConditionFields.length > 0) {
10139 query.append(WHERE_AND);
10140 }
10141
10142 for (int i = 0; i < orderByConditionFields.length; i++) {
10143 if (getDB().isSupportsInlineDistinct()) {
10144 query.append(_ORDER_BY_ENTITY_ALIAS);
10145 }
10146 else {
10147 query.append(_ORDER_BY_ENTITY_TABLE);
10148 }
10149
10150 query.append(orderByConditionFields[i]);
10151
10152 if ((i + 1) < orderByConditionFields.length) {
10153 if (orderByComparator.isAscending() ^ previous) {
10154 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10155 }
10156 else {
10157 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10158 }
10159 }
10160 else {
10161 if (orderByComparator.isAscending() ^ previous) {
10162 query.append(WHERE_GREATER_THAN);
10163 }
10164 else {
10165 query.append(WHERE_LESSER_THAN);
10166 }
10167 }
10168 }
10169
10170 query.append(ORDER_BY_CLAUSE);
10171
10172 String[] orderByFields = orderByComparator.getOrderByFields();
10173
10174 for (int i = 0; i < orderByFields.length; i++) {
10175 if (getDB().isSupportsInlineDistinct()) {
10176 query.append(_ORDER_BY_ENTITY_ALIAS);
10177 }
10178 else {
10179 query.append(_ORDER_BY_ENTITY_TABLE);
10180 }
10181
10182 query.append(orderByFields[i]);
10183
10184 if ((i + 1) < orderByFields.length) {
10185 if (orderByComparator.isAscending() ^ previous) {
10186 query.append(ORDER_BY_ASC_HAS_NEXT);
10187 }
10188 else {
10189 query.append(ORDER_BY_DESC_HAS_NEXT);
10190 }
10191 }
10192 else {
10193 if (orderByComparator.isAscending() ^ previous) {
10194 query.append(ORDER_BY_ASC);
10195 }
10196 else {
10197 query.append(ORDER_BY_DESC);
10198 }
10199 }
10200 }
10201 }
10202 else {
10203 if (getDB().isSupportsInlineDistinct()) {
10204 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10205 }
10206 else {
10207 query.append(MBThreadModelImpl.ORDER_BY_SQL);
10208 }
10209 }
10210
10211 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10212 MBThread.class.getName(),
10213 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10214
10215 SQLQuery q = session.createSQLQuery(sql);
10216
10217 q.setFirstResult(0);
10218 q.setMaxResults(2);
10219
10220 if (getDB().isSupportsInlineDistinct()) {
10221 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10222 }
10223 else {
10224 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10225 }
10226
10227 QueryPos qPos = QueryPos.getInstance(q);
10228
10229 qPos.add(groupId);
10230
10231 qPos.add(categoryId);
10232
10233 qPos.add(status);
10234
10235 if (orderByComparator != null) {
10236 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
10237
10238 for (Object value : values) {
10239 qPos.add(value);
10240 }
10241 }
10242
10243 List<MBThread> list = q.list();
10244
10245 if (list.size() == 2) {
10246 return list.get(1);
10247 }
10248 else {
10249 return null;
10250 }
10251 }
10252
10253
10262 @Override
10263 public List<MBThread> filterFindByG_C_NotS(long groupId,
10264 long[] categoryIds, int status) throws SystemException {
10265 return filterFindByG_C_NotS(groupId, categoryIds, status,
10266 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10267 }
10268
10269
10284 @Override
10285 public List<MBThread> filterFindByG_C_NotS(long groupId,
10286 long[] categoryIds, int status, int start, int end)
10287 throws SystemException {
10288 return filterFindByG_C_NotS(groupId, categoryIds, status, start, end,
10289 null);
10290 }
10291
10292
10308 @Override
10309 public List<MBThread> filterFindByG_C_NotS(long groupId,
10310 long[] categoryIds, int status, int start, int end,
10311 OrderByComparator orderByComparator) throws SystemException {
10312 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10313 return findByG_C_NotS(groupId, categoryIds, status, start, end,
10314 orderByComparator);
10315 }
10316
10317 StringBundler query = new StringBundler();
10318
10319 if (getDB().isSupportsInlineDistinct()) {
10320 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10321 }
10322 else {
10323 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10324 }
10325
10326 boolean conjunctionable = false;
10327
10328 if (conjunctionable) {
10329 query.append(WHERE_AND);
10330 }
10331
10332 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10333
10334 conjunctionable = true;
10335
10336 if ((categoryIds == null) || (categoryIds.length > 0)) {
10337 if (conjunctionable) {
10338 query.append(WHERE_AND);
10339 }
10340
10341 query.append(StringPool.OPEN_PARENTHESIS);
10342
10343 for (int i = 0; i < categoryIds.length; i++) {
10344 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10345
10346 if ((i + 1) < categoryIds.length) {
10347 query.append(WHERE_OR);
10348 }
10349 }
10350
10351 query.append(StringPool.CLOSE_PARENTHESIS);
10352
10353 conjunctionable = true;
10354 }
10355
10356 if (conjunctionable) {
10357 query.append(WHERE_AND);
10358 }
10359
10360 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10361
10362 conjunctionable = true;
10363
10364 if (!getDB().isSupportsInlineDistinct()) {
10365 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10366 }
10367
10368 if (orderByComparator != null) {
10369 if (getDB().isSupportsInlineDistinct()) {
10370 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10371 orderByComparator, true);
10372 }
10373 else {
10374 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10375 orderByComparator, true);
10376 }
10377 }
10378 else {
10379 if (getDB().isSupportsInlineDistinct()) {
10380 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10381 }
10382 else {
10383 query.append(MBThreadModelImpl.ORDER_BY_SQL);
10384 }
10385 }
10386
10387 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10388 MBThread.class.getName(),
10389 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10390
10391 Session session = null;
10392
10393 try {
10394 session = openSession();
10395
10396 SQLQuery q = session.createSQLQuery(sql);
10397
10398 if (getDB().isSupportsInlineDistinct()) {
10399 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10400 }
10401 else {
10402 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10403 }
10404
10405 QueryPos qPos = QueryPos.getInstance(q);
10406
10407 qPos.add(groupId);
10408
10409 if (categoryIds != null) {
10410 qPos.add(categoryIds);
10411 }
10412
10413 qPos.add(status);
10414
10415 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
10416 }
10417 catch (Exception e) {
10418 throw processException(e);
10419 }
10420 finally {
10421 closeSession(session);
10422 }
10423 }
10424
10425
10438 @Override
10439 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10440 int status) throws SystemException {
10441 return findByG_C_NotS(groupId, categoryIds, status, QueryUtil.ALL_POS,
10442 QueryUtil.ALL_POS, null);
10443 }
10444
10445
10460 @Override
10461 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10462 int status, int start, int end) throws SystemException {
10463 return findByG_C_NotS(groupId, categoryIds, status, start, end, null);
10464 }
10465
10466
10482 @Override
10483 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10484 int status, int start, int end, OrderByComparator orderByComparator)
10485 throws SystemException {
10486 if ((categoryIds != null) && (categoryIds.length == 1)) {
10487 return findByG_C_NotS(groupId, categoryIds[0], status, start, end,
10488 orderByComparator);
10489 }
10490
10491 boolean pagination = true;
10492 Object[] finderArgs = null;
10493
10494 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10495 (orderByComparator == null)) {
10496 pagination = false;
10497 finderArgs = new Object[] {
10498 groupId, StringUtil.merge(categoryIds), status
10499 };
10500 }
10501 else {
10502 finderArgs = new Object[] {
10503 groupId, StringUtil.merge(categoryIds), status,
10504
10505 start, end, orderByComparator
10506 };
10507 }
10508
10509 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10510 finderArgs, this);
10511
10512 if ((list != null) && !list.isEmpty()) {
10513 for (MBThread mbThread : list) {
10514 if ((groupId != mbThread.getGroupId()) ||
10515 !ArrayUtil.contains(categoryIds,
10516 mbThread.getCategoryId()) ||
10517 (status == mbThread.getStatus())) {
10518 list = null;
10519
10520 break;
10521 }
10522 }
10523 }
10524
10525 if (list == null) {
10526 StringBundler query = new StringBundler();
10527
10528 query.append(_SQL_SELECT_MBTHREAD_WHERE);
10529
10530 boolean conjunctionable = false;
10531
10532 if (conjunctionable) {
10533 query.append(WHERE_AND);
10534 }
10535
10536 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10537
10538 conjunctionable = true;
10539
10540 if ((categoryIds == null) || (categoryIds.length > 0)) {
10541 if (conjunctionable) {
10542 query.append(WHERE_AND);
10543 }
10544
10545 query.append(StringPool.OPEN_PARENTHESIS);
10546
10547 for (int i = 0; i < categoryIds.length; i++) {
10548 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10549
10550 if ((i + 1) < categoryIds.length) {
10551 query.append(WHERE_OR);
10552 }
10553 }
10554
10555 query.append(StringPool.CLOSE_PARENTHESIS);
10556
10557 conjunctionable = true;
10558 }
10559
10560 if (conjunctionable) {
10561 query.append(WHERE_AND);
10562 }
10563
10564 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10565
10566 conjunctionable = true;
10567
10568 if (orderByComparator != null) {
10569 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10570 orderByComparator);
10571 }
10572 else
10573 if (pagination) {
10574 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10575 }
10576
10577 String sql = query.toString();
10578
10579 Session session = null;
10580
10581 try {
10582 session = openSession();
10583
10584 Query q = session.createQuery(sql);
10585
10586 QueryPos qPos = QueryPos.getInstance(q);
10587
10588 qPos.add(groupId);
10589
10590 if (categoryIds != null) {
10591 qPos.add(categoryIds);
10592 }
10593
10594 qPos.add(status);
10595
10596 if (!pagination) {
10597 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10598 start, end, false);
10599
10600 Collections.sort(list);
10601
10602 list = new UnmodifiableList<MBThread>(list);
10603 }
10604 else {
10605 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10606 start, end);
10607 }
10608
10609 cacheResult(list);
10610
10611 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10612 finderArgs, list);
10613 }
10614 catch (Exception e) {
10615 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10616 finderArgs);
10617
10618 throw processException(e);
10619 }
10620 finally {
10621 closeSession(session);
10622 }
10623 }
10624
10625 return list;
10626 }
10627
10628
10636 @Override
10637 public void removeByG_C_NotS(long groupId, long categoryId, int status)
10638 throws SystemException {
10639 for (MBThread mbThread : findByG_C_NotS(groupId, categoryId, status,
10640 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10641 remove(mbThread);
10642 }
10643 }
10644
10645
10654 @Override
10655 public int countByG_C_NotS(long groupId, long categoryId, int status)
10656 throws SystemException {
10657 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS;
10658
10659 Object[] finderArgs = new Object[] { groupId, categoryId, status };
10660
10661 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10662 this);
10663
10664 if (count == null) {
10665 StringBundler query = new StringBundler(4);
10666
10667 query.append(_SQL_COUNT_MBTHREAD_WHERE);
10668
10669 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10670
10671 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10672
10673 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10674
10675 String sql = query.toString();
10676
10677 Session session = null;
10678
10679 try {
10680 session = openSession();
10681
10682 Query q = session.createQuery(sql);
10683
10684 QueryPos qPos = QueryPos.getInstance(q);
10685
10686 qPos.add(groupId);
10687
10688 qPos.add(categoryId);
10689
10690 qPos.add(status);
10691
10692 count = (Long)q.uniqueResult();
10693
10694 FinderCacheUtil.putResult(finderPath, finderArgs, count);
10695 }
10696 catch (Exception e) {
10697 FinderCacheUtil.removeResult(finderPath, finderArgs);
10698
10699 throw processException(e);
10700 }
10701 finally {
10702 closeSession(session);
10703 }
10704 }
10705
10706 return count.intValue();
10707 }
10708
10709
10718 @Override
10719 public int countByG_C_NotS(long groupId, long[] categoryIds, int status)
10720 throws SystemException {
10721 Object[] finderArgs = new Object[] {
10722 groupId, StringUtil.merge(categoryIds), status
10723 };
10724
10725 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10726 finderArgs, this);
10727
10728 if (count == null) {
10729 StringBundler query = new StringBundler();
10730
10731 query.append(_SQL_COUNT_MBTHREAD_WHERE);
10732
10733 boolean conjunctionable = false;
10734
10735 if (conjunctionable) {
10736 query.append(WHERE_AND);
10737 }
10738
10739 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10740
10741 conjunctionable = true;
10742
10743 if ((categoryIds == null) || (categoryIds.length > 0)) {
10744 if (conjunctionable) {
10745 query.append(WHERE_AND);
10746 }
10747
10748 query.append(StringPool.OPEN_PARENTHESIS);
10749
10750 for (int i = 0; i < categoryIds.length; i++) {
10751 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10752
10753 if ((i + 1) < categoryIds.length) {
10754 query.append(WHERE_OR);
10755 }
10756 }
10757
10758 query.append(StringPool.CLOSE_PARENTHESIS);
10759
10760 conjunctionable = true;
10761 }
10762
10763 if (conjunctionable) {
10764 query.append(WHERE_AND);
10765 }
10766
10767 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10768
10769 conjunctionable = true;
10770
10771 String sql = query.toString();
10772
10773 Session session = null;
10774
10775 try {
10776 session = openSession();
10777
10778 Query q = session.createQuery(sql);
10779
10780 QueryPos qPos = QueryPos.getInstance(q);
10781
10782 qPos.add(groupId);
10783
10784 if (categoryIds != null) {
10785 qPos.add(categoryIds);
10786 }
10787
10788 qPos.add(status);
10789
10790 count = (Long)q.uniqueResult();
10791
10792 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10793 finderArgs, count);
10794 }
10795 catch (Exception e) {
10796 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10797 finderArgs);
10798
10799 throw processException(e);
10800 }
10801 finally {
10802 closeSession(session);
10803 }
10804 }
10805
10806 return count.intValue();
10807 }
10808
10809
10818 @Override
10819 public int filterCountByG_C_NotS(long groupId, long categoryId, int status)
10820 throws SystemException {
10821 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10822 return countByG_C_NotS(groupId, categoryId, status);
10823 }
10824
10825 StringBundler query = new StringBundler(4);
10826
10827 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10828
10829 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10830
10831 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10832
10833 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10834
10835 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10836 MBThread.class.getName(),
10837 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10838
10839 Session session = null;
10840
10841 try {
10842 session = openSession();
10843
10844 SQLQuery q = session.createSQLQuery(sql);
10845
10846 q.addScalar(COUNT_COLUMN_NAME,
10847 com.liferay.portal.kernel.dao.orm.Type.LONG);
10848
10849 QueryPos qPos = QueryPos.getInstance(q);
10850
10851 qPos.add(groupId);
10852
10853 qPos.add(categoryId);
10854
10855 qPos.add(status);
10856
10857 Long count = (Long)q.uniqueResult();
10858
10859 return count.intValue();
10860 }
10861 catch (Exception e) {
10862 throw processException(e);
10863 }
10864 finally {
10865 closeSession(session);
10866 }
10867 }
10868
10869
10878 @Override
10879 public int filterCountByG_C_NotS(long groupId, long[] categoryIds,
10880 int status) throws SystemException {
10881 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10882 return countByG_C_NotS(groupId, categoryIds, status);
10883 }
10884
10885 StringBundler query = new StringBundler();
10886
10887 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10888
10889 boolean conjunctionable = false;
10890
10891 if (conjunctionable) {
10892 query.append(WHERE_AND);
10893 }
10894
10895 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_5);
10896
10897 conjunctionable = true;
10898
10899 if ((categoryIds == null) || (categoryIds.length > 0)) {
10900 if (conjunctionable) {
10901 query.append(WHERE_AND);
10902 }
10903
10904 query.append(StringPool.OPEN_PARENTHESIS);
10905
10906 for (int i = 0; i < categoryIds.length; i++) {
10907 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_5);
10908
10909 if ((i + 1) < categoryIds.length) {
10910 query.append(WHERE_OR);
10911 }
10912 }
10913
10914 query.append(StringPool.CLOSE_PARENTHESIS);
10915
10916 conjunctionable = true;
10917 }
10918
10919 if (conjunctionable) {
10920 query.append(WHERE_AND);
10921 }
10922
10923 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_5);
10924
10925 conjunctionable = true;
10926
10927 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10928 MBThread.class.getName(),
10929 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10930
10931 Session session = null;
10932
10933 try {
10934 session = openSession();
10935
10936 SQLQuery q = session.createSQLQuery(sql);
10937
10938 q.addScalar(COUNT_COLUMN_NAME,
10939 com.liferay.portal.kernel.dao.orm.Type.LONG);
10940
10941 QueryPos qPos = QueryPos.getInstance(q);
10942
10943 qPos.add(groupId);
10944
10945 if (categoryIds != null) {
10946 qPos.add(categoryIds);
10947 }
10948
10949 qPos.add(status);
10950
10951 Long count = (Long)q.uniqueResult();
10952
10953 return count.intValue();
10954 }
10955 catch (Exception e) {
10956 throw processException(e);
10957 }
10958 finally {
10959 closeSession(session);
10960 }
10961 }
10962
10963 private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
10964 private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_5 = "(" +
10965 removeConjunction(_FINDER_COLUMN_G_C_NOTS_GROUPID_2) + ")";
10966 private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
10967 private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_5 = "(" +
10968 removeConjunction(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2) + ")";
10969 private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_2 = "mbThread.status != ?";
10970 private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_5 = "(" +
10971 removeConjunction(_FINDER_COLUMN_G_C_NOTS_STATUS_2) + ")";
10972 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10973 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
10974 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
10975 new String[] {
10976 Long.class.getName(), Long.class.getName(),
10977 Integer.class.getName(),
10978
10979 Integer.class.getName(), Integer.class.getName(),
10980 OrderByComparator.class.getName()
10981 });
10982 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S =
10983 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10984 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
10985 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_S",
10986 new String[] {
10987 Long.class.getName(), Long.class.getName(),
10988 Integer.class.getName()
10989 });
10990
10991
11000 @Override
11001 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
11002 int status) throws SystemException {
11003 return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
11004 QueryUtil.ALL_POS, null);
11005 }
11006
11007
11022 @Override
11023 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
11024 int status, int start, int end) throws SystemException {
11025 return findByG_NotC_S(groupId, categoryId, status, start, end, null);
11026 }
11027
11028
11044 @Override
11045 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
11046 int status, int start, int end, OrderByComparator orderByComparator)
11047 throws SystemException {
11048 boolean pagination = true;
11049 FinderPath finderPath = null;
11050 Object[] finderArgs = null;
11051
11052 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
11053 finderArgs = new Object[] {
11054 groupId, categoryId, status,
11055
11056 start, end, orderByComparator
11057 };
11058
11059 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
11060 finderArgs, this);
11061
11062 if ((list != null) && !list.isEmpty()) {
11063 for (MBThread mbThread : list) {
11064 if ((groupId != mbThread.getGroupId()) ||
11065 (categoryId == mbThread.getCategoryId()) ||
11066 (status != mbThread.getStatus())) {
11067 list = null;
11068
11069 break;
11070 }
11071 }
11072 }
11073
11074 if (list == null) {
11075 StringBundler query = null;
11076
11077 if (orderByComparator != null) {
11078 query = new StringBundler(5 +
11079 (orderByComparator.getOrderByFields().length * 3));
11080 }
11081 else {
11082 query = new StringBundler(5);
11083 }
11084
11085 query.append(_SQL_SELECT_MBTHREAD_WHERE);
11086
11087 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11088
11089 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11090
11091 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11092
11093 if (orderByComparator != null) {
11094 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11095 orderByComparator);
11096 }
11097 else
11098 if (pagination) {
11099 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11100 }
11101
11102 String sql = query.toString();
11103
11104 Session session = null;
11105
11106 try {
11107 session = openSession();
11108
11109 Query q = session.createQuery(sql);
11110
11111 QueryPos qPos = QueryPos.getInstance(q);
11112
11113 qPos.add(groupId);
11114
11115 qPos.add(categoryId);
11116
11117 qPos.add(status);
11118
11119 if (!pagination) {
11120 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11121 start, end, false);
11122
11123 Collections.sort(list);
11124
11125 list = new UnmodifiableList<MBThread>(list);
11126 }
11127 else {
11128 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11129 start, end);
11130 }
11131
11132 cacheResult(list);
11133
11134 FinderCacheUtil.putResult(finderPath, finderArgs, list);
11135 }
11136 catch (Exception e) {
11137 FinderCacheUtil.removeResult(finderPath, finderArgs);
11138
11139 throw processException(e);
11140 }
11141 finally {
11142 closeSession(session);
11143 }
11144 }
11145
11146 return list;
11147 }
11148
11149
11160 @Override
11161 public MBThread findByG_NotC_S_First(long groupId, long categoryId,
11162 int status, OrderByComparator orderByComparator)
11163 throws NoSuchThreadException, SystemException {
11164 MBThread mbThread = fetchByG_NotC_S_First(groupId, categoryId, status,
11165 orderByComparator);
11166
11167 if (mbThread != null) {
11168 return mbThread;
11169 }
11170
11171 StringBundler msg = new StringBundler(8);
11172
11173 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11174
11175 msg.append("groupId=");
11176 msg.append(groupId);
11177
11178 msg.append(", categoryId=");
11179 msg.append(categoryId);
11180
11181 msg.append(", status=");
11182 msg.append(status);
11183
11184 msg.append(StringPool.CLOSE_CURLY_BRACE);
11185
11186 throw new NoSuchThreadException(msg.toString());
11187 }
11188
11189
11199 @Override
11200 public MBThread fetchByG_NotC_S_First(long groupId, long categoryId,
11201 int status, OrderByComparator orderByComparator)
11202 throws SystemException {
11203 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
11204 orderByComparator);
11205
11206 if (!list.isEmpty()) {
11207 return list.get(0);
11208 }
11209
11210 return null;
11211 }
11212
11213
11224 @Override
11225 public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
11226 int status, OrderByComparator orderByComparator)
11227 throws NoSuchThreadException, SystemException {
11228 MBThread mbThread = fetchByG_NotC_S_Last(groupId, categoryId, status,
11229 orderByComparator);
11230
11231 if (mbThread != null) {
11232 return mbThread;
11233 }
11234
11235 StringBundler msg = new StringBundler(8);
11236
11237 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11238
11239 msg.append("groupId=");
11240 msg.append(groupId);
11241
11242 msg.append(", categoryId=");
11243 msg.append(categoryId);
11244
11245 msg.append(", status=");
11246 msg.append(status);
11247
11248 msg.append(StringPool.CLOSE_CURLY_BRACE);
11249
11250 throw new NoSuchThreadException(msg.toString());
11251 }
11252
11253
11263 @Override
11264 public MBThread fetchByG_NotC_S_Last(long groupId, long categoryId,
11265 int status, OrderByComparator orderByComparator)
11266 throws SystemException {
11267 int count = countByG_NotC_S(groupId, categoryId, status);
11268
11269 if (count == 0) {
11270 return null;
11271 }
11272
11273 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
11274 count - 1, count, orderByComparator);
11275
11276 if (!list.isEmpty()) {
11277 return list.get(0);
11278 }
11279
11280 return null;
11281 }
11282
11283
11295 @Override
11296 public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
11297 long categoryId, int status, OrderByComparator orderByComparator)
11298 throws NoSuchThreadException, SystemException {
11299 MBThread mbThread = findByPrimaryKey(threadId);
11300
11301 Session session = null;
11302
11303 try {
11304 session = openSession();
11305
11306 MBThread[] array = new MBThreadImpl[3];
11307
11308 array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
11309 categoryId, status, orderByComparator, true);
11310
11311 array[1] = mbThread;
11312
11313 array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
11314 categoryId, status, orderByComparator, false);
11315
11316 return array;
11317 }
11318 catch (Exception e) {
11319 throw processException(e);
11320 }
11321 finally {
11322 closeSession(session);
11323 }
11324 }
11325
11326 protected MBThread getByG_NotC_S_PrevAndNext(Session session,
11327 MBThread mbThread, long groupId, long categoryId, int status,
11328 OrderByComparator orderByComparator, boolean previous) {
11329 StringBundler query = null;
11330
11331 if (orderByComparator != null) {
11332 query = new StringBundler(6 +
11333 (orderByComparator.getOrderByFields().length * 6));
11334 }
11335 else {
11336 query = new StringBundler(3);
11337 }
11338
11339 query.append(_SQL_SELECT_MBTHREAD_WHERE);
11340
11341 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11342
11343 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11344
11345 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11346
11347 if (orderByComparator != null) {
11348 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11349
11350 if (orderByConditionFields.length > 0) {
11351 query.append(WHERE_AND);
11352 }
11353
11354 for (int i = 0; i < orderByConditionFields.length; i++) {
11355 query.append(_ORDER_BY_ENTITY_ALIAS);
11356 query.append(orderByConditionFields[i]);
11357
11358 if ((i + 1) < orderByConditionFields.length) {
11359 if (orderByComparator.isAscending() ^ previous) {
11360 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11361 }
11362 else {
11363 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11364 }
11365 }
11366 else {
11367 if (orderByComparator.isAscending() ^ previous) {
11368 query.append(WHERE_GREATER_THAN);
11369 }
11370 else {
11371 query.append(WHERE_LESSER_THAN);
11372 }
11373 }
11374 }
11375
11376 query.append(ORDER_BY_CLAUSE);
11377
11378 String[] orderByFields = orderByComparator.getOrderByFields();
11379
11380 for (int i = 0; i < orderByFields.length; i++) {
11381 query.append(_ORDER_BY_ENTITY_ALIAS);
11382 query.append(orderByFields[i]);
11383
11384 if ((i + 1) < orderByFields.length) {
11385 if (orderByComparator.isAscending() ^ previous) {
11386 query.append(ORDER_BY_ASC_HAS_NEXT);
11387 }
11388 else {
11389 query.append(ORDER_BY_DESC_HAS_NEXT);
11390 }
11391 }
11392 else {
11393 if (orderByComparator.isAscending() ^ previous) {
11394 query.append(ORDER_BY_ASC);
11395 }
11396 else {
11397 query.append(ORDER_BY_DESC);
11398 }
11399 }
11400 }
11401 }
11402 else {
11403 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11404 }
11405
11406 String sql = query.toString();
11407
11408 Query q = session.createQuery(sql);
11409
11410 q.setFirstResult(0);
11411 q.setMaxResults(2);
11412
11413 QueryPos qPos = QueryPos.getInstance(q);
11414
11415 qPos.add(groupId);
11416
11417 qPos.add(categoryId);
11418
11419 qPos.add(status);
11420
11421 if (orderByComparator != null) {
11422 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11423
11424 for (Object value : values) {
11425 qPos.add(value);
11426 }
11427 }
11428
11429 List<MBThread> list = q.list();
11430
11431 if (list.size() == 2) {
11432 return list.get(1);
11433 }
11434 else {
11435 return null;
11436 }
11437 }
11438
11439
11448 @Override
11449 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11450 int status) throws SystemException {
11451 return filterFindByG_NotC_S(groupId, categoryId, status,
11452 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11453 }
11454
11455
11470 @Override
11471 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11472 int status, int start, int end) throws SystemException {
11473 return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
11474 null);
11475 }
11476
11477
11493 @Override
11494 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11495 int status, int start, int end, OrderByComparator orderByComparator)
11496 throws SystemException {
11497 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11498 return findByG_NotC_S(groupId, categoryId, status, start, end,
11499 orderByComparator);
11500 }
11501
11502 StringBundler query = null;
11503
11504 if (orderByComparator != null) {
11505 query = new StringBundler(5 +
11506 (orderByComparator.getOrderByFields().length * 3));
11507 }
11508 else {
11509 query = new StringBundler(5);
11510 }
11511
11512 if (getDB().isSupportsInlineDistinct()) {
11513 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11514 }
11515 else {
11516 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11517 }
11518
11519 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11520
11521 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11522
11523 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11524
11525 if (!getDB().isSupportsInlineDistinct()) {
11526 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11527 }
11528
11529 if (orderByComparator != null) {
11530 if (getDB().isSupportsInlineDistinct()) {
11531 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11532 orderByComparator, true);
11533 }
11534 else {
11535 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11536 orderByComparator, true);
11537 }
11538 }
11539 else {
11540 if (getDB().isSupportsInlineDistinct()) {
11541 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11542 }
11543 else {
11544 query.append(MBThreadModelImpl.ORDER_BY_SQL);
11545 }
11546 }
11547
11548 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11549 MBThread.class.getName(),
11550 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11551
11552 Session session = null;
11553
11554 try {
11555 session = openSession();
11556
11557 SQLQuery q = session.createSQLQuery(sql);
11558
11559 if (getDB().isSupportsInlineDistinct()) {
11560 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11561 }
11562 else {
11563 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11564 }
11565
11566 QueryPos qPos = QueryPos.getInstance(q);
11567
11568 qPos.add(groupId);
11569
11570 qPos.add(categoryId);
11571
11572 qPos.add(status);
11573
11574 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
11575 }
11576 catch (Exception e) {
11577 throw processException(e);
11578 }
11579 finally {
11580 closeSession(session);
11581 }
11582 }
11583
11584
11596 @Override
11597 public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
11598 long groupId, long categoryId, int status,
11599 OrderByComparator orderByComparator)
11600 throws NoSuchThreadException, SystemException {
11601 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11602 return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
11603 status, orderByComparator);
11604 }
11605
11606 MBThread mbThread = findByPrimaryKey(threadId);
11607
11608 Session session = null;
11609
11610 try {
11611 session = openSession();
11612
11613 MBThread[] array = new MBThreadImpl[3];
11614
11615 array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11616 groupId, categoryId, status, orderByComparator, true);
11617
11618 array[1] = mbThread;
11619
11620 array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11621 groupId, categoryId, status, orderByComparator, false);
11622
11623 return array;
11624 }
11625 catch (Exception e) {
11626 throw processException(e);
11627 }
11628 finally {
11629 closeSession(session);
11630 }
11631 }
11632
11633 protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
11634 MBThread mbThread, long groupId, long categoryId, int status,
11635 OrderByComparator orderByComparator, boolean previous) {
11636 StringBundler query = null;
11637
11638 if (orderByComparator != null) {
11639 query = new StringBundler(6 +
11640 (orderByComparator.getOrderByFields().length * 6));
11641 }
11642 else {
11643 query = new StringBundler(3);
11644 }
11645
11646 if (getDB().isSupportsInlineDistinct()) {
11647 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11648 }
11649 else {
11650 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11651 }
11652
11653 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11654
11655 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11656
11657 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11658
11659 if (!getDB().isSupportsInlineDistinct()) {
11660 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11661 }
11662
11663 if (orderByComparator != null) {
11664 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11665
11666 if (orderByConditionFields.length > 0) {
11667 query.append(WHERE_AND);
11668 }
11669
11670 for (int i = 0; i < orderByConditionFields.length; i++) {
11671 if (getDB().isSupportsInlineDistinct()) {
11672 query.append(_ORDER_BY_ENTITY_ALIAS);
11673 }
11674 else {
11675 query.append(_ORDER_BY_ENTITY_TABLE);
11676 }
11677
11678 query.append(orderByConditionFields[i]);
11679
11680 if ((i + 1) < orderByConditionFields.length) {
11681 if (orderByComparator.isAscending() ^ previous) {
11682 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11683 }
11684 else {
11685 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11686 }
11687 }
11688 else {
11689 if (orderByComparator.isAscending() ^ previous) {
11690 query.append(WHERE_GREATER_THAN);
11691 }
11692 else {
11693 query.append(WHERE_LESSER_THAN);
11694 }
11695 }
11696 }
11697
11698 query.append(ORDER_BY_CLAUSE);
11699
11700 String[] orderByFields = orderByComparator.getOrderByFields();
11701
11702 for (int i = 0; i < orderByFields.length; i++) {
11703 if (getDB().isSupportsInlineDistinct()) {
11704 query.append(_ORDER_BY_ENTITY_ALIAS);
11705 }
11706 else {
11707 query.append(_ORDER_BY_ENTITY_TABLE);
11708 }
11709
11710 query.append(orderByFields[i]);
11711
11712 if ((i + 1) < orderByFields.length) {
11713 if (orderByComparator.isAscending() ^ previous) {
11714 query.append(ORDER_BY_ASC_HAS_NEXT);
11715 }
11716 else {
11717 query.append(ORDER_BY_DESC_HAS_NEXT);
11718 }
11719 }
11720 else {
11721 if (orderByComparator.isAscending() ^ previous) {
11722 query.append(ORDER_BY_ASC);
11723 }
11724 else {
11725 query.append(ORDER_BY_DESC);
11726 }
11727 }
11728 }
11729 }
11730 else {
11731 if (getDB().isSupportsInlineDistinct()) {
11732 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11733 }
11734 else {
11735 query.append(MBThreadModelImpl.ORDER_BY_SQL);
11736 }
11737 }
11738
11739 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11740 MBThread.class.getName(),
11741 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11742
11743 SQLQuery q = session.createSQLQuery(sql);
11744
11745 q.setFirstResult(0);
11746 q.setMaxResults(2);
11747
11748 if (getDB().isSupportsInlineDistinct()) {
11749 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11750 }
11751 else {
11752 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11753 }
11754
11755 QueryPos qPos = QueryPos.getInstance(q);
11756
11757 qPos.add(groupId);
11758
11759 qPos.add(categoryId);
11760
11761 qPos.add(status);
11762
11763 if (orderByComparator != null) {
11764 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11765
11766 for (Object value : values) {
11767 qPos.add(value);
11768 }
11769 }
11770
11771 List<MBThread> list = q.list();
11772
11773 if (list.size() == 2) {
11774 return list.get(1);
11775 }
11776 else {
11777 return null;
11778 }
11779 }
11780
11781
11789 @Override
11790 public void removeByG_NotC_S(long groupId, long categoryId, int status)
11791 throws SystemException {
11792 for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status,
11793 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11794 remove(mbThread);
11795 }
11796 }
11797
11798
11807 @Override
11808 public int countByG_NotC_S(long groupId, long categoryId, int status)
11809 throws SystemException {
11810 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S;
11811
11812 Object[] finderArgs = new Object[] { groupId, categoryId, status };
11813
11814 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11815 this);
11816
11817 if (count == null) {
11818 StringBundler query = new StringBundler(4);
11819
11820 query.append(_SQL_COUNT_MBTHREAD_WHERE);
11821
11822 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11823
11824 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11825
11826 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11827
11828 String sql = query.toString();
11829
11830 Session session = null;
11831
11832 try {
11833 session = openSession();
11834
11835 Query q = session.createQuery(sql);
11836
11837 QueryPos qPos = QueryPos.getInstance(q);
11838
11839 qPos.add(groupId);
11840
11841 qPos.add(categoryId);
11842
11843 qPos.add(status);
11844
11845 count = (Long)q.uniqueResult();
11846
11847 FinderCacheUtil.putResult(finderPath, finderArgs, count);
11848 }
11849 catch (Exception e) {
11850 FinderCacheUtil.removeResult(finderPath, finderArgs);
11851
11852 throw processException(e);
11853 }
11854 finally {
11855 closeSession(session);
11856 }
11857 }
11858
11859 return count.intValue();
11860 }
11861
11862
11871 @Override
11872 public int filterCountByG_NotC_S(long groupId, long categoryId, int status)
11873 throws SystemException {
11874 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11875 return countByG_NotC_S(groupId, categoryId, status);
11876 }
11877
11878 StringBundler query = new StringBundler(4);
11879
11880 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
11881
11882 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11883
11884 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11885
11886 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11887
11888 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11889 MBThread.class.getName(),
11890 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11891
11892 Session session = null;
11893
11894 try {
11895 session = openSession();
11896
11897 SQLQuery q = session.createSQLQuery(sql);
11898
11899 q.addScalar(COUNT_COLUMN_NAME,
11900 com.liferay.portal.kernel.dao.orm.Type.LONG);
11901
11902 QueryPos qPos = QueryPos.getInstance(q);
11903
11904 qPos.add(groupId);
11905
11906 qPos.add(categoryId);
11907
11908 qPos.add(status);
11909
11910 Long count = (Long)q.uniqueResult();
11911
11912 return count.intValue();
11913 }
11914 catch (Exception e) {
11915 throw processException(e);
11916 }
11917 finally {
11918 closeSession(session);
11919 }
11920 }
11921
11922 private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
11923 private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
11924 private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
11925 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS =
11926 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11927 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
11928 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_NotS",
11929 new String[] {
11930 Long.class.getName(), Long.class.getName(),
11931 Integer.class.getName(),
11932
11933 Integer.class.getName(), Integer.class.getName(),
11934 OrderByComparator.class.getName()
11935 });
11936 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS =
11937 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11938 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
11939 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_NotS",
11940 new String[] {
11941 Long.class.getName(), Long.class.getName(),
11942 Integer.class.getName()
11943 });
11944
11945
11954 @Override
11955 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11956 int status) throws SystemException {
11957 return findByG_NotC_NotS(groupId, categoryId, status,
11958 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11959 }
11960
11961
11976 @Override
11977 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11978 int status, int start, int end) throws SystemException {
11979 return findByG_NotC_NotS(groupId, categoryId, status, start, end, null);
11980 }
11981
11982
11998 @Override
11999 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
12000 int status, int start, int end, OrderByComparator orderByComparator)
12001 throws SystemException {
12002 boolean pagination = true;
12003 FinderPath finderPath = null;
12004 Object[] finderArgs = null;
12005
12006 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS;
12007 finderArgs = new Object[] {
12008 groupId, categoryId, status,
12009
12010 start, end, orderByComparator
12011 };
12012
12013 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
12014 finderArgs, this);
12015
12016 if ((list != null) && !list.isEmpty()) {
12017 for (MBThread mbThread : list) {
12018 if ((groupId != mbThread.getGroupId()) ||
12019 (categoryId == mbThread.getCategoryId()) ||
12020 (status == mbThread.getStatus())) {
12021 list = null;
12022
12023 break;
12024 }
12025 }
12026 }
12027
12028 if (list == null) {
12029 StringBundler query = null;
12030
12031 if (orderByComparator != null) {
12032 query = new StringBundler(5 +
12033 (orderByComparator.getOrderByFields().length * 3));
12034 }
12035 else {
12036 query = new StringBundler(5);
12037 }
12038
12039 query.append(_SQL_SELECT_MBTHREAD_WHERE);
12040
12041 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12042
12043 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12044
12045 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12046
12047 if (orderByComparator != null) {
12048 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12049 orderByComparator);
12050 }
12051 else
12052 if (pagination) {
12053 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12054 }
12055
12056 String sql = query.toString();
12057
12058 Session session = null;
12059
12060 try {
12061 session = openSession();
12062
12063 Query q = session.createQuery(sql);
12064
12065 QueryPos qPos = QueryPos.getInstance(q);
12066
12067 qPos.add(groupId);
12068
12069 qPos.add(categoryId);
12070
12071 qPos.add(status);
12072
12073 if (!pagination) {
12074 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
12075 start, end, false);
12076
12077 Collections.sort(list);
12078
12079 list = new UnmodifiableList<MBThread>(list);
12080 }
12081 else {
12082 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
12083 start, end);
12084 }
12085
12086 cacheResult(list);
12087
12088 FinderCacheUtil.putResult(finderPath, finderArgs, list);
12089 }
12090 catch (Exception e) {
12091 FinderCacheUtil.removeResult(finderPath, finderArgs);
12092
12093 throw processException(e);
12094 }
12095 finally {
12096 closeSession(session);
12097 }
12098 }
12099
12100 return list;
12101 }
12102
12103
12114 @Override
12115 public MBThread findByG_NotC_NotS_First(long groupId, long categoryId,
12116 int status, OrderByComparator orderByComparator)
12117 throws NoSuchThreadException, SystemException {
12118 MBThread mbThread = fetchByG_NotC_NotS_First(groupId, categoryId,
12119 status, orderByComparator);
12120
12121 if (mbThread != null) {
12122 return mbThread;
12123 }
12124
12125 StringBundler msg = new StringBundler(8);
12126
12127 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12128
12129 msg.append("groupId=");
12130 msg.append(groupId);
12131
12132 msg.append(", categoryId=");
12133 msg.append(categoryId);
12134
12135 msg.append(", status=");
12136 msg.append(status);
12137
12138 msg.append(StringPool.CLOSE_CURLY_BRACE);
12139
12140 throw new NoSuchThreadException(msg.toString());
12141 }
12142
12143
12153 @Override
12154 public MBThread fetchByG_NotC_NotS_First(long groupId, long categoryId,
12155 int status, OrderByComparator orderByComparator)
12156 throws SystemException {
12157 List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status, 0,
12158 1, orderByComparator);
12159
12160 if (!list.isEmpty()) {
12161 return list.get(0);
12162 }
12163
12164 return null;
12165 }
12166
12167
12178 @Override
12179 public MBThread findByG_NotC_NotS_Last(long groupId, long categoryId,
12180 int status, OrderByComparator orderByComparator)
12181 throws NoSuchThreadException, SystemException {
12182 MBThread mbThread = fetchByG_NotC_NotS_Last(groupId, categoryId,
12183 status, orderByComparator);
12184
12185 if (mbThread != null) {
12186 return mbThread;
12187 }
12188
12189 StringBundler msg = new StringBundler(8);
12190
12191 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12192
12193 msg.append("groupId=");
12194 msg.append(groupId);
12195
12196 msg.append(", categoryId=");
12197 msg.append(categoryId);
12198
12199 msg.append(", status=");
12200 msg.append(status);
12201
12202 msg.append(StringPool.CLOSE_CURLY_BRACE);
12203
12204 throw new NoSuchThreadException(msg.toString());
12205 }
12206
12207
12217 @Override
12218 public MBThread fetchByG_NotC_NotS_Last(long groupId, long categoryId,
12219 int status, OrderByComparator orderByComparator)
12220 throws SystemException {
12221 int count = countByG_NotC_NotS(groupId, categoryId, status);
12222
12223 if (count == 0) {
12224 return null;
12225 }
12226
12227 List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status,
12228 count - 1, count, orderByComparator);
12229
12230 if (!list.isEmpty()) {
12231 return list.get(0);
12232 }
12233
12234 return null;
12235 }
12236
12237
12249 @Override
12250 public MBThread[] findByG_NotC_NotS_PrevAndNext(long threadId,
12251 long groupId, long categoryId, int status,
12252 OrderByComparator orderByComparator)
12253 throws NoSuchThreadException, SystemException {
12254 MBThread mbThread = findByPrimaryKey(threadId);
12255
12256 Session session = null;
12257
12258 try {
12259 session = openSession();
12260
12261 MBThread[] array = new MBThreadImpl[3];
12262
12263 array[0] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
12264 categoryId, status, orderByComparator, true);
12265
12266 array[1] = mbThread;
12267
12268 array[2] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
12269 categoryId, status, orderByComparator, false);
12270
12271 return array;
12272 }
12273 catch (Exception e) {
12274 throw processException(e);
12275 }
12276 finally {
12277 closeSession(session);
12278 }
12279 }
12280
12281 protected MBThread getByG_NotC_NotS_PrevAndNext(Session session,
12282 MBThread mbThread, long groupId, long categoryId, int status,
12283 OrderByComparator orderByComparator, boolean previous) {
12284 StringBundler query = null;
12285
12286 if (orderByComparator != null) {
12287 query = new StringBundler(6 +
12288 (orderByComparator.getOrderByFields().length * 6));
12289 }
12290 else {
12291 query = new StringBundler(3);
12292 }
12293
12294 query.append(_SQL_SELECT_MBTHREAD_WHERE);
12295
12296 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12297
12298 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12299
12300 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12301
12302 if (orderByComparator != null) {
12303 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12304
12305 if (orderByConditionFields.length > 0) {
12306 query.append(WHERE_AND);
12307 }
12308
12309 for (int i = 0; i < orderByConditionFields.length; i++) {
12310 query.append(_ORDER_BY_ENTITY_ALIAS);
12311 query.append(orderByConditionFields[i]);
12312
12313 if ((i + 1) < orderByConditionFields.length) {
12314 if (orderByComparator.isAscending() ^ previous) {
12315 query.append(WHERE_GREATER_THAN_HAS_NEXT);
12316 }
12317 else {
12318 query.append(WHERE_LESSER_THAN_HAS_NEXT);
12319 }
12320 }
12321 else {
12322 if (orderByComparator.isAscending() ^ previous) {
12323 query.append(WHERE_GREATER_THAN);
12324 }
12325 else {
12326 query.append(WHERE_LESSER_THAN);
12327 }
12328 }
12329 }
12330
12331 query.append(ORDER_BY_CLAUSE);
12332
12333 String[] orderByFields = orderByComparator.getOrderByFields();
12334
12335 for (int i = 0; i < orderByFields.length; i++) {
12336 query.append(_ORDER_BY_ENTITY_ALIAS);
12337 query.append(orderByFields[i]);
12338
12339 if ((i + 1) < orderByFields.length) {
12340 if (orderByComparator.isAscending() ^ previous) {
12341 query.append(ORDER_BY_ASC_HAS_NEXT);
12342 }
12343 else {
12344 query.append(ORDER_BY_DESC_HAS_NEXT);
12345 }
12346 }
12347 else {
12348 if (orderByComparator.isAscending() ^ previous) {
12349 query.append(ORDER_BY_ASC);
12350 }
12351 else {
12352 query.append(ORDER_BY_DESC);
12353 }
12354 }
12355 }
12356 }
12357 else {
12358 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12359 }
12360
12361 String sql = query.toString();
12362
12363 Query q = session.createQuery(sql);
12364
12365 q.setFirstResult(0);
12366 q.setMaxResults(2);
12367
12368 QueryPos qPos = QueryPos.getInstance(q);
12369
12370 qPos.add(groupId);
12371
12372 qPos.add(categoryId);
12373
12374 qPos.add(status);
12375
12376 if (orderByComparator != null) {
12377 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
12378
12379 for (Object value : values) {
12380 qPos.add(value);
12381 }
12382 }
12383
12384 List<MBThread> list = q.list();
12385
12386 if (list.size() == 2) {
12387 return list.get(1);
12388 }
12389 else {
12390 return null;
12391 }
12392 }
12393
12394
12403 @Override
12404 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12405 long categoryId, int status) throws SystemException {
12406 return filterFindByG_NotC_NotS(groupId, categoryId, status,
12407 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12408 }
12409
12410
12425 @Override
12426 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12427 long categoryId, int status, int start, int end)
12428 throws SystemException {
12429 return filterFindByG_NotC_NotS(groupId, categoryId, status, start, end,
12430 null);
12431 }
12432
12433
12449 @Override
12450 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12451 long categoryId, int status, int start, int end,
12452 OrderByComparator orderByComparator) throws SystemException {
12453 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12454 return findByG_NotC_NotS(groupId, categoryId, status, start, end,
12455 orderByComparator);
12456 }
12457
12458 StringBundler query = null;
12459
12460 if (orderByComparator != null) {
12461 query = new StringBundler(5 +
12462 (orderByComparator.getOrderByFields().length * 3));
12463 }
12464 else {
12465 query = new StringBundler(5);
12466 }
12467
12468 if (getDB().isSupportsInlineDistinct()) {
12469 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12470 }
12471 else {
12472 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12473 }
12474
12475 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12476
12477 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12478
12479 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12480
12481 if (!getDB().isSupportsInlineDistinct()) {
12482 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12483 }
12484
12485 if (orderByComparator != null) {
12486 if (getDB().isSupportsInlineDistinct()) {
12487 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12488 orderByComparator, true);
12489 }
12490 else {
12491 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12492 orderByComparator, true);
12493 }
12494 }
12495 else {
12496 if (getDB().isSupportsInlineDistinct()) {
12497 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12498 }
12499 else {
12500 query.append(MBThreadModelImpl.ORDER_BY_SQL);
12501 }
12502 }
12503
12504 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12505 MBThread.class.getName(),
12506 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12507
12508 Session session = null;
12509
12510 try {
12511 session = openSession();
12512
12513 SQLQuery q = session.createSQLQuery(sql);
12514
12515 if (getDB().isSupportsInlineDistinct()) {
12516 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12517 }
12518 else {
12519 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12520 }
12521
12522 QueryPos qPos = QueryPos.getInstance(q);
12523
12524 qPos.add(groupId);
12525
12526 qPos.add(categoryId);
12527
12528 qPos.add(status);
12529
12530 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
12531 }
12532 catch (Exception e) {
12533 throw processException(e);
12534 }
12535 finally {
12536 closeSession(session);
12537 }
12538 }
12539
12540
12552 @Override
12553 public MBThread[] filterFindByG_NotC_NotS_PrevAndNext(long threadId,
12554 long groupId, long categoryId, int status,
12555 OrderByComparator orderByComparator)
12556 throws NoSuchThreadException, SystemException {
12557 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12558 return findByG_NotC_NotS_PrevAndNext(threadId, groupId, categoryId,
12559 status, orderByComparator);
12560 }
12561
12562 MBThread mbThread = findByPrimaryKey(threadId);
12563
12564 Session session = null;
12565
12566 try {
12567 session = openSession();
12568
12569 MBThread[] array = new MBThreadImpl[3];
12570
12571 array[0] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12572 groupId, categoryId, status, orderByComparator, true);
12573
12574 array[1] = mbThread;
12575
12576 array[2] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12577 groupId, categoryId, status, orderByComparator, false);
12578
12579 return array;
12580 }
12581 catch (Exception e) {
12582 throw processException(e);
12583 }
12584 finally {
12585 closeSession(session);
12586 }
12587 }
12588
12589 protected MBThread filterGetByG_NotC_NotS_PrevAndNext(Session session,
12590 MBThread mbThread, long groupId, long categoryId, int status,
12591 OrderByComparator orderByComparator, boolean previous) {
12592 StringBundler query = null;
12593
12594 if (orderByComparator != null) {
12595 query = new StringBundler(6 +
12596 (orderByComparator.getOrderByFields().length * 6));
12597 }
12598 else {
12599 query = new StringBundler(3);
12600 }
12601
12602 if (getDB().isSupportsInlineDistinct()) {
12603 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12604 }
12605 else {
12606 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12607 }
12608
12609 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12610
12611 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12612
12613 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12614
12615 if (!getDB().isSupportsInlineDistinct()) {
12616 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12617 }
12618
12619 if (orderByComparator != null) {
12620 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12621
12622 if (orderByConditionFields.length > 0) {
12623 query.append(WHERE_AND);
12624 }
12625
12626 for (int i = 0; i < orderByConditionFields.length; i++) {
12627 if (getDB().isSupportsInlineDistinct()) {
12628 query.append(_ORDER_BY_ENTITY_ALIAS);
12629 }
12630 else {
12631 query.append(_ORDER_BY_ENTITY_TABLE);
12632 }
12633
12634 query.append(orderByConditionFields[i]);
12635
12636 if ((i + 1) < orderByConditionFields.length) {
12637 if (orderByComparator.isAscending() ^ previous) {
12638 query.append(WHERE_GREATER_THAN_HAS_NEXT);
12639 }
12640 else {
12641 query.append(WHERE_LESSER_THAN_HAS_NEXT);
12642 }
12643 }
12644 else {
12645 if (orderByComparator.isAscending() ^ previous) {
12646 query.append(WHERE_GREATER_THAN);
12647 }
12648 else {
12649 query.append(WHERE_LESSER_THAN);
12650 }
12651 }
12652 }
12653
12654 query.append(ORDER_BY_CLAUSE);
12655
12656 String[] orderByFields = orderByComparator.getOrderByFields();
12657
12658 for (int i = 0; i < orderByFields.length; i++) {
12659 if (getDB().isSupportsInlineDistinct()) {
12660 query.append(_ORDER_BY_ENTITY_ALIAS);
12661 }
12662 else {
12663 query.append(_ORDER_BY_ENTITY_TABLE);
12664 }
12665
12666 query.append(orderByFields[i]);
12667
12668 if ((i + 1) < orderByFields.length) {
12669 if (orderByComparator.isAscending() ^ previous) {
12670 query.append(ORDER_BY_ASC_HAS_NEXT);
12671 }
12672 else {
12673 query.append(ORDER_BY_DESC_HAS_NEXT);
12674 }
12675 }
12676 else {
12677 if (orderByComparator.isAscending() ^ previous) {
12678 query.append(ORDER_BY_ASC);
12679 }
12680 else {
12681 query.append(ORDER_BY_DESC);
12682 }
12683 }
12684 }
12685 }
12686 else {
12687 if (getDB().isSupportsInlineDistinct()) {
12688 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12689 }
12690 else {
12691 query.append(MBThreadModelImpl.ORDER_BY_SQL);
12692 }
12693 }
12694
12695 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12696 MBThread.class.getName(),
12697 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12698
12699 SQLQuery q = session.createSQLQuery(sql);
12700
12701 q.setFirstResult(0);
12702 q.setMaxResults(2);
12703
12704 if (getDB().isSupportsInlineDistinct()) {
12705 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12706 }
12707 else {
12708 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12709 }
12710
12711 QueryPos qPos = QueryPos.getInstance(q);
12712
12713 qPos.add(groupId);
12714
12715 qPos.add(categoryId);
12716
12717 qPos.add(status);
12718
12719 if (orderByComparator != null) {
12720 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
12721
12722 for (Object value : values) {
12723 qPos.add(value);
12724 }
12725 }
12726
12727 List<MBThread> list = q.list();
12728
12729 if (list.size() == 2) {
12730 return list.get(1);
12731 }
12732 else {
12733 return null;
12734 }
12735 }
12736
12737
12745 @Override
12746 public void removeByG_NotC_NotS(long groupId, long categoryId, int status)
12747 throws SystemException {
12748 for (MBThread mbThread : findByG_NotC_NotS(groupId, categoryId, status,
12749 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12750 remove(mbThread);
12751 }
12752 }
12753
12754
12763 @Override
12764 public int countByG_NotC_NotS(long groupId, long categoryId, int status)
12765 throws SystemException {
12766 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS;
12767
12768 Object[] finderArgs = new Object[] { groupId, categoryId, status };
12769
12770 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12771 this);
12772
12773 if (count == null) {
12774 StringBundler query = new StringBundler(4);
12775
12776 query.append(_SQL_COUNT_MBTHREAD_WHERE);
12777
12778 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12779
12780 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12781
12782 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12783
12784 String sql = query.toString();
12785
12786 Session session = null;
12787
12788 try {
12789 session = openSession();
12790
12791 Query q = session.createQuery(sql);
12792
12793 QueryPos qPos = QueryPos.getInstance(q);
12794
12795 qPos.add(groupId);
12796
12797 qPos.add(categoryId);
12798
12799 qPos.add(status);
12800
12801 count = (Long)q.uniqueResult();
12802
12803 FinderCacheUtil.putResult(finderPath, finderArgs, count);
12804 }
12805 catch (Exception e) {
12806 FinderCacheUtil.removeResult(finderPath, finderArgs);
12807
12808 throw processException(e);
12809 }
12810 finally {
12811 closeSession(session);
12812 }
12813 }
12814
12815 return count.intValue();
12816 }
12817
12818
12827 @Override
12828 public int filterCountByG_NotC_NotS(long groupId, long categoryId,
12829 int status) throws SystemException {
12830 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12831 return countByG_NotC_NotS(groupId, categoryId, status);
12832 }
12833
12834 StringBundler query = new StringBundler(4);
12835
12836 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
12837
12838 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12839
12840 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12841
12842 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12843
12844 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12845 MBThread.class.getName(),
12846 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12847
12848 Session session = null;
12849
12850 try {
12851 session = openSession();
12852
12853 SQLQuery q = session.createSQLQuery(sql);
12854
12855 q.addScalar(COUNT_COLUMN_NAME,
12856 com.liferay.portal.kernel.dao.orm.Type.LONG);
12857
12858 QueryPos qPos = QueryPos.getInstance(q);
12859
12860 qPos.add(groupId);
12861
12862 qPos.add(categoryId);
12863
12864 qPos.add(status);
12865
12866 Long count = (Long)q.uniqueResult();
12867
12868 return count.intValue();
12869 }
12870 catch (Exception e) {
12871 throw processException(e);
12872 }
12873 finally {
12874 closeSession(session);
12875 }
12876 }
12877
12878 private static final String _FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
12879 private static final String _FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
12880 private static final String _FINDER_COLUMN_G_NOTC_NOTS_STATUS_2 = "mbThread.status != ?";
12881
12882 public MBThreadPersistenceImpl() {
12883 setModelClass(MBThread.class);
12884 }
12885
12886
12891 @Override
12892 public void cacheResult(MBThread mbThread) {
12893 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12894 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
12895
12896 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
12897 new Object[] { mbThread.getUuid(), mbThread.getGroupId() }, mbThread);
12898
12899 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12900 new Object[] { mbThread.getRootMessageId() }, mbThread);
12901
12902 mbThread.resetOriginalValues();
12903 }
12904
12905
12910 @Override
12911 public void cacheResult(List<MBThread> mbThreads) {
12912 for (MBThread mbThread : mbThreads) {
12913 if (EntityCacheUtil.getResult(
12914 MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12915 MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
12916 cacheResult(mbThread);
12917 }
12918 else {
12919 mbThread.resetOriginalValues();
12920 }
12921 }
12922 }
12923
12924
12931 @Override
12932 public void clearCache() {
12933 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
12934 CacheRegistryUtil.clear(MBThreadImpl.class.getName());
12935 }
12936
12937 EntityCacheUtil.clearCache(MBThreadImpl.class.getName());
12938
12939 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
12940 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12941 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12942 }
12943
12944
12951 @Override
12952 public void clearCache(MBThread mbThread) {
12953 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12954 MBThreadImpl.class, mbThread.getPrimaryKey());
12955
12956 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12957 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12958
12959 clearUniqueFindersCache(mbThread);
12960 }
12961
12962 @Override
12963 public void clearCache(List<MBThread> mbThreads) {
12964 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12965 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12966
12967 for (MBThread mbThread : mbThreads) {
12968 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12969 MBThreadImpl.class, mbThread.getPrimaryKey());
12970
12971 clearUniqueFindersCache(mbThread);
12972 }
12973 }
12974
12975 protected void cacheUniqueFindersCache(MBThread mbThread) {
12976 if (mbThread.isNew()) {
12977 Object[] args = new Object[] {
12978 mbThread.getUuid(), mbThread.getGroupId()
12979 };
12980
12981 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12982 Long.valueOf(1));
12983 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12984 mbThread);
12985
12986 args = new Object[] { mbThread.getRootMessageId() };
12987
12988 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args,
12989 Long.valueOf(1));
12990 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args,
12991 mbThread);
12992 }
12993 else {
12994 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12995
12996 if ((mbThreadModelImpl.getColumnBitmask() &
12997 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12998 Object[] args = new Object[] {
12999 mbThread.getUuid(), mbThread.getGroupId()
13000 };
13001
13002 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
13003 Long.valueOf(1));
13004 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
13005 mbThread);
13006 }
13007
13008 if ((mbThreadModelImpl.getColumnBitmask() &
13009 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
13010 Object[] args = new Object[] { mbThread.getRootMessageId() };
13011
13012 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
13013 args, Long.valueOf(1));
13014 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
13015 args, mbThread);
13016 }
13017 }
13018 }
13019
13020 protected void clearUniqueFindersCache(MBThread mbThread) {
13021 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
13022
13023 Object[] args = new Object[] { mbThread.getUuid(), mbThread.getGroupId() };
13024
13025 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
13026 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
13027
13028 if ((mbThreadModelImpl.getColumnBitmask() &
13029 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
13030 args = new Object[] {
13031 mbThreadModelImpl.getOriginalUuid(),
13032 mbThreadModelImpl.getOriginalGroupId()
13033 };
13034
13035 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
13036 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
13037 }
13038
13039 args = new Object[] { mbThread.getRootMessageId() };
13040
13041 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args);
13042 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args);
13043
13044 if ((mbThreadModelImpl.getColumnBitmask() &
13045 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
13046 args = new Object[] { mbThreadModelImpl.getOriginalRootMessageId() };
13047
13048 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
13049 args);
13050 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
13051 args);
13052 }
13053 }
13054
13055
13061 @Override
13062 public MBThread create(long threadId) {
13063 MBThread mbThread = new MBThreadImpl();
13064
13065 mbThread.setNew(true);
13066 mbThread.setPrimaryKey(threadId);
13067
13068 String uuid = PortalUUIDUtil.generate();
13069
13070 mbThread.setUuid(uuid);
13071
13072 return mbThread;
13073 }
13074
13075
13083 @Override
13084 public MBThread remove(long threadId)
13085 throws NoSuchThreadException, SystemException {
13086 return remove((Serializable)threadId);
13087 }
13088
13089
13097 @Override
13098 public MBThread remove(Serializable primaryKey)
13099 throws NoSuchThreadException, SystemException {
13100 Session session = null;
13101
13102 try {
13103 session = openSession();
13104
13105 MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
13106 primaryKey);
13107
13108 if (mbThread == null) {
13109 if (_log.isWarnEnabled()) {
13110 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
13111 }
13112
13113 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
13114 primaryKey);
13115 }
13116
13117 return remove(mbThread);
13118 }
13119 catch (NoSuchThreadException nsee) {
13120 throw nsee;
13121 }
13122 catch (Exception e) {
13123 throw processException(e);
13124 }
13125 finally {
13126 closeSession(session);
13127 }
13128 }
13129
13130 @Override
13131 protected MBThread removeImpl(MBThread mbThread) throws SystemException {
13132 mbThread = toUnwrappedModel(mbThread);
13133
13134 Session session = null;
13135
13136 try {
13137 session = openSession();
13138
13139 if (!session.contains(mbThread)) {
13140 mbThread = (MBThread)session.get(MBThreadImpl.class,
13141 mbThread.getPrimaryKeyObj());
13142 }
13143
13144 if (mbThread != null) {
13145 session.delete(mbThread);
13146 }
13147 }
13148 catch (Exception e) {
13149 throw processException(e);
13150 }
13151 finally {
13152 closeSession(session);
13153 }
13154
13155 if (mbThread != null) {
13156 clearCache(mbThread);
13157 }
13158
13159 return mbThread;
13160 }
13161
13162 @Override
13163 public MBThread updateImpl(
13164 com.liferay.portlet.messageboards.model.MBThread mbThread)
13165 throws SystemException {
13166 mbThread = toUnwrappedModel(mbThread);
13167
13168 boolean isNew = mbThread.isNew();
13169
13170 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
13171
13172 if (Validator.isNull(mbThread.getUuid())) {
13173 String uuid = PortalUUIDUtil.generate();
13174
13175 mbThread.setUuid(uuid);
13176 }
13177
13178 Session session = null;
13179
13180 try {
13181 session = openSession();
13182
13183 if (mbThread.isNew()) {
13184 session.save(mbThread);
13185
13186 mbThread.setNew(false);
13187 }
13188 else {
13189 session.merge(mbThread);
13190 }
13191 }
13192 catch (Exception e) {
13193 throw processException(e);
13194 }
13195 finally {
13196 closeSession(session);
13197 }
13198
13199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13200
13201 if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
13202 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13203 }
13204
13205 else {
13206 if ((mbThreadModelImpl.getColumnBitmask() &
13207 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
13208 Object[] args = new Object[] { mbThreadModelImpl.getOriginalUuid() };
13209
13210 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
13211 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
13212 args);
13213
13214 args = new Object[] { mbThreadModelImpl.getUuid() };
13215
13216 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
13217 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
13218 args);
13219 }
13220
13221 if ((mbThreadModelImpl.getColumnBitmask() &
13222 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
13223 Object[] args = new Object[] {
13224 mbThreadModelImpl.getOriginalUuid(),
13225 mbThreadModelImpl.getOriginalCompanyId()
13226 };
13227
13228 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
13229 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
13230 args);
13231
13232 args = new Object[] {
13233 mbThreadModelImpl.getUuid(),
13234 mbThreadModelImpl.getCompanyId()
13235 };
13236
13237 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
13238 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
13239 args);
13240 }
13241
13242 if ((mbThreadModelImpl.getColumnBitmask() &
13243 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
13244 Object[] args = new Object[] {
13245 mbThreadModelImpl.getOriginalGroupId()
13246 };
13247
13248 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
13249 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
13250 args);
13251
13252 args = new Object[] { mbThreadModelImpl.getGroupId() };
13253
13254 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
13255 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
13256 args);
13257 }
13258
13259 if ((mbThreadModelImpl.getColumnBitmask() &
13260 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
13261 Object[] args = new Object[] {
13262 mbThreadModelImpl.getOriginalGroupId(),
13263 mbThreadModelImpl.getOriginalCategoryId()
13264 };
13265
13266 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
13267 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
13268 args);
13269
13270 args = new Object[] {
13271 mbThreadModelImpl.getGroupId(),
13272 mbThreadModelImpl.getCategoryId()
13273 };
13274
13275 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
13276 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
13277 args);
13278 }
13279
13280 if ((mbThreadModelImpl.getColumnBitmask() &
13281 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
13282 Object[] args = new Object[] {
13283 mbThreadModelImpl.getOriginalGroupId(),
13284 mbThreadModelImpl.getOriginalStatus()
13285 };
13286
13287 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
13288 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
13289 args);
13290
13291 args = new Object[] {
13292 mbThreadModelImpl.getGroupId(),
13293 mbThreadModelImpl.getStatus()
13294 };
13295
13296 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
13297 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
13298 args);
13299 }
13300
13301 if ((mbThreadModelImpl.getColumnBitmask() &
13302 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
13303 Object[] args = new Object[] {
13304 mbThreadModelImpl.getOriginalCategoryId(),
13305 mbThreadModelImpl.getOriginalPriority()
13306 };
13307
13308 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
13309 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
13310 args);
13311
13312 args = new Object[] {
13313 mbThreadModelImpl.getCategoryId(),
13314 mbThreadModelImpl.getPriority()
13315 };
13316
13317 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
13318 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
13319 args);
13320 }
13321
13322 if ((mbThreadModelImpl.getColumnBitmask() &
13323 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
13324 Object[] args = new Object[] {
13325 mbThreadModelImpl.getOriginalLastPostDate(),
13326 mbThreadModelImpl.getOriginalPriority()
13327 };
13328
13329 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
13330 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
13331 args);
13332
13333 args = new Object[] {
13334 mbThreadModelImpl.getLastPostDate(),
13335 mbThreadModelImpl.getPriority()
13336 };
13337
13338 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
13339 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
13340 args);
13341 }
13342
13343 if ((mbThreadModelImpl.getColumnBitmask() &
13344 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
13345 Object[] args = new Object[] {
13346 mbThreadModelImpl.getOriginalGroupId(),
13347 mbThreadModelImpl.getOriginalCategoryId(),
13348 mbThreadModelImpl.getOriginalLastPostDate()
13349 };
13350
13351 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
13352 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
13353 args);
13354
13355 args = new Object[] {
13356 mbThreadModelImpl.getGroupId(),
13357 mbThreadModelImpl.getCategoryId(),
13358 mbThreadModelImpl.getLastPostDate()
13359 };
13360
13361 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
13362 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
13363 args);
13364 }
13365
13366 if ((mbThreadModelImpl.getColumnBitmask() &
13367 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
13368 Object[] args = new Object[] {
13369 mbThreadModelImpl.getOriginalGroupId(),
13370 mbThreadModelImpl.getOriginalCategoryId(),
13371 mbThreadModelImpl.getOriginalStatus()
13372 };
13373
13374 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
13375 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
13376 args);
13377
13378 args = new Object[] {
13379 mbThreadModelImpl.getGroupId(),
13380 mbThreadModelImpl.getCategoryId(),
13381 mbThreadModelImpl.getStatus()
13382 };
13383
13384 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
13385 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
13386 args);
13387 }
13388 }
13389
13390 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13391 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
13392
13393 clearUniqueFindersCache(mbThread);
13394 cacheUniqueFindersCache(mbThread);
13395
13396 return mbThread;
13397 }
13398
13399 protected MBThread toUnwrappedModel(MBThread mbThread) {
13400 if (mbThread instanceof MBThreadImpl) {
13401 return mbThread;
13402 }
13403
13404 MBThreadImpl mbThreadImpl = new MBThreadImpl();
13405
13406 mbThreadImpl.setNew(mbThread.isNew());
13407 mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
13408
13409 mbThreadImpl.setUuid(mbThread.getUuid());
13410 mbThreadImpl.setThreadId(mbThread.getThreadId());
13411 mbThreadImpl.setGroupId(mbThread.getGroupId());
13412 mbThreadImpl.setCompanyId(mbThread.getCompanyId());
13413 mbThreadImpl.setUserId(mbThread.getUserId());
13414 mbThreadImpl.setUserName(mbThread.getUserName());
13415 mbThreadImpl.setCreateDate(mbThread.getCreateDate());
13416 mbThreadImpl.setModifiedDate(mbThread.getModifiedDate());
13417 mbThreadImpl.setCategoryId(mbThread.getCategoryId());
13418 mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
13419 mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
13420 mbThreadImpl.setMessageCount(mbThread.getMessageCount());
13421 mbThreadImpl.setViewCount(mbThread.getViewCount());
13422 mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
13423 mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
13424 mbThreadImpl.setPriority(mbThread.getPriority());
13425 mbThreadImpl.setQuestion(mbThread.isQuestion());
13426 mbThreadImpl.setStatus(mbThread.getStatus());
13427 mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
13428 mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
13429 mbThreadImpl.setStatusDate(mbThread.getStatusDate());
13430
13431 return mbThreadImpl;
13432 }
13433
13434
13442 @Override
13443 public MBThread findByPrimaryKey(Serializable primaryKey)
13444 throws NoSuchThreadException, SystemException {
13445 MBThread mbThread = fetchByPrimaryKey(primaryKey);
13446
13447 if (mbThread == null) {
13448 if (_log.isWarnEnabled()) {
13449 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
13450 }
13451
13452 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
13453 primaryKey);
13454 }
13455
13456 return mbThread;
13457 }
13458
13459
13467 @Override
13468 public MBThread findByPrimaryKey(long threadId)
13469 throws NoSuchThreadException, SystemException {
13470 return findByPrimaryKey((Serializable)threadId);
13471 }
13472
13473
13480 @Override
13481 public MBThread fetchByPrimaryKey(Serializable primaryKey)
13482 throws SystemException {
13483 MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13484 MBThreadImpl.class, primaryKey);
13485
13486 if (mbThread == _nullMBThread) {
13487 return null;
13488 }
13489
13490 if (mbThread == null) {
13491 Session session = null;
13492
13493 try {
13494 session = openSession();
13495
13496 mbThread = (MBThread)session.get(MBThreadImpl.class, primaryKey);
13497
13498 if (mbThread != null) {
13499 cacheResult(mbThread);
13500 }
13501 else {
13502 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13503 MBThreadImpl.class, primaryKey, _nullMBThread);
13504 }
13505 }
13506 catch (Exception e) {
13507 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13508 MBThreadImpl.class, primaryKey);
13509
13510 throw processException(e);
13511 }
13512 finally {
13513 closeSession(session);
13514 }
13515 }
13516
13517 return mbThread;
13518 }
13519
13520
13527 @Override
13528 public MBThread fetchByPrimaryKey(long threadId) throws SystemException {
13529 return fetchByPrimaryKey((Serializable)threadId);
13530 }
13531
13532
13538 @Override
13539 public List<MBThread> findAll() throws SystemException {
13540 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13541 }
13542
13543
13555 @Override
13556 public List<MBThread> findAll(int start, int end) throws SystemException {
13557 return findAll(start, end, null);
13558 }
13559
13560
13573 @Override
13574 public List<MBThread> findAll(int start, int end,
13575 OrderByComparator orderByComparator) throws SystemException {
13576 boolean pagination = true;
13577 FinderPath finderPath = null;
13578 Object[] finderArgs = null;
13579
13580 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13581 (orderByComparator == null)) {
13582 pagination = false;
13583 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
13584 finderArgs = FINDER_ARGS_EMPTY;
13585 }
13586 else {
13587 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
13588 finderArgs = new Object[] { start, end, orderByComparator };
13589 }
13590
13591 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
13592 finderArgs, this);
13593
13594 if (list == null) {
13595 StringBundler query = null;
13596 String sql = null;
13597
13598 if (orderByComparator != null) {
13599 query = new StringBundler(2 +
13600 (orderByComparator.getOrderByFields().length * 3));
13601
13602 query.append(_SQL_SELECT_MBTHREAD);
13603
13604 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13605 orderByComparator);
13606
13607 sql = query.toString();
13608 }
13609 else {
13610 sql = _SQL_SELECT_MBTHREAD;
13611
13612 if (pagination) {
13613 sql = sql.concat(MBThreadModelImpl.ORDER_BY_JPQL);
13614 }
13615 }
13616
13617 Session session = null;
13618
13619 try {
13620 session = openSession();
13621
13622 Query q = session.createQuery(sql);
13623
13624 if (!pagination) {
13625 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13626 start, end, false);
13627
13628 Collections.sort(list);
13629
13630 list = new UnmodifiableList<MBThread>(list);
13631 }
13632 else {
13633 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13634 start, end);
13635 }
13636
13637 cacheResult(list);
13638
13639 FinderCacheUtil.putResult(finderPath, finderArgs, list);
13640 }
13641 catch (Exception e) {
13642 FinderCacheUtil.removeResult(finderPath, finderArgs);
13643
13644 throw processException(e);
13645 }
13646 finally {
13647 closeSession(session);
13648 }
13649 }
13650
13651 return list;
13652 }
13653
13654
13659 @Override
13660 public void removeAll() throws SystemException {
13661 for (MBThread mbThread : findAll()) {
13662 remove(mbThread);
13663 }
13664 }
13665
13666
13672 @Override
13673 public int countAll() throws SystemException {
13674 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
13675 FINDER_ARGS_EMPTY, this);
13676
13677 if (count == null) {
13678 Session session = null;
13679
13680 try {
13681 session = openSession();
13682
13683 Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
13684
13685 count = (Long)q.uniqueResult();
13686
13687 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
13688 FINDER_ARGS_EMPTY, count);
13689 }
13690 catch (Exception e) {
13691 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
13692 FINDER_ARGS_EMPTY);
13693
13694 throw processException(e);
13695 }
13696 finally {
13697 closeSession(session);
13698 }
13699 }
13700
13701 return count.intValue();
13702 }
13703
13704 @Override
13705 protected Set<String> getBadColumnNames() {
13706 return _badColumnNames;
13707 }
13708
13709
13712 public void afterPropertiesSet() {
13713 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
13714 com.liferay.portal.util.PropsUtil.get(
13715 "value.object.listener.com.liferay.portlet.messageboards.model.MBThread")));
13716
13717 if (listenerClassNames.length > 0) {
13718 try {
13719 List<ModelListener<MBThread>> listenersList = new ArrayList<ModelListener<MBThread>>();
13720
13721 for (String listenerClassName : listenerClassNames) {
13722 listenersList.add((ModelListener<MBThread>)InstanceFactory.newInstance(
13723 getClassLoader(), listenerClassName));
13724 }
13725
13726 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
13727 }
13728 catch (Exception e) {
13729 _log.error(e);
13730 }
13731 }
13732 }
13733
13734 public void destroy() {
13735 EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
13736 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
13737 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13738 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13739 }
13740
13741 private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
13742 private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
13743 private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
13744 private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
13745 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
13746 private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
13747 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
13748 "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
13749 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
13750 ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
13751 private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
13752 private static final String _FILTER_ENTITY_ALIAS = "mbThread";
13753 private static final String _FILTER_ENTITY_TABLE = "MBThread";
13754 private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
13755 private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
13756 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
13757 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
13758 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
13759 private static Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
13760 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
13761 "uuid"
13762 });
13763 private static MBThread _nullMBThread = new MBThreadImpl() {
13764 @Override
13765 public Object clone() {
13766 return this;
13767 }
13768
13769 @Override
13770 public CacheModel<MBThread> toCacheModel() {
13771 return _nullMBThreadCacheModel;
13772 }
13773 };
13774
13775 private static CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
13776 @Override
13777 public MBThread toEntityModel() {
13778 return _nullMBThread;
13779 }
13780 };
13781 }