001
014
015 package com.liferay.portlet.messageboards.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.SQLQuery;
026 import com.liferay.portal.kernel.dao.orm.Session;
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.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portal.service.ServiceContextThreadLocal;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.messageboards.NoSuchThreadException;
044 import com.liferay.portlet.messageboards.model.MBThread;
045 import com.liferay.portlet.messageboards.model.impl.MBThreadImpl;
046 import com.liferay.portlet.messageboards.model.impl.MBThreadModelImpl;
047 import com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence;
048
049 import java.io.Serializable;
050
051 import java.sql.Timestamp;
052
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.HashMap;
056 import java.util.HashSet;
057 import java.util.Iterator;
058 import java.util.List;
059 import java.util.Map;
060 import java.util.Set;
061
062
074 @ProviderType
075 public class MBThreadPersistenceImpl extends BasePersistenceImpl<MBThread>
076 implements MBThreadPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = MBThreadImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
088 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
091 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
094 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
097 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
099 new String[] {
100 String.class.getName(),
101
102 Integer.class.getName(), Integer.class.getName(),
103 OrderByComparator.class.getName()
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
106 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108 new String[] { String.class.getName() },
109 MBThreadModelImpl.UUID_COLUMN_BITMASK |
110 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
111 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
112 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
113 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
115 new String[] { String.class.getName() });
116
117
123 @Override
124 public List<MBThread> findByUuid(String uuid) {
125 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
126 }
127
128
140 @Override
141 public List<MBThread> findByUuid(String uuid, int start, int end) {
142 return findByUuid(uuid, start, end, null);
143 }
144
145
158 @Override
159 public List<MBThread> findByUuid(String uuid, int start, int end,
160 OrderByComparator<MBThread> orderByComparator) {
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 = Collections.unmodifiableList(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
278 @Override
279 public MBThread findByUuid_First(String uuid,
280 OrderByComparator<MBThread> orderByComparator)
281 throws NoSuchThreadException {
282 MBThread mbThread = fetchByUuid_First(uuid, orderByComparator);
283
284 if (mbThread != null) {
285 return mbThread;
286 }
287
288 StringBundler msg = new StringBundler(4);
289
290 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
291
292 msg.append("uuid=");
293 msg.append(uuid);
294
295 msg.append(StringPool.CLOSE_CURLY_BRACE);
296
297 throw new NoSuchThreadException(msg.toString());
298 }
299
300
307 @Override
308 public MBThread fetchByUuid_First(String uuid,
309 OrderByComparator<MBThread> orderByComparator) {
310 List<MBThread> list = findByUuid(uuid, 0, 1, orderByComparator);
311
312 if (!list.isEmpty()) {
313 return list.get(0);
314 }
315
316 return null;
317 }
318
319
327 @Override
328 public MBThread findByUuid_Last(String uuid,
329 OrderByComparator<MBThread> orderByComparator)
330 throws NoSuchThreadException {
331 MBThread mbThread = fetchByUuid_Last(uuid, orderByComparator);
332
333 if (mbThread != null) {
334 return mbThread;
335 }
336
337 StringBundler msg = new StringBundler(4);
338
339 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340
341 msg.append("uuid=");
342 msg.append(uuid);
343
344 msg.append(StringPool.CLOSE_CURLY_BRACE);
345
346 throw new NoSuchThreadException(msg.toString());
347 }
348
349
356 @Override
357 public MBThread fetchByUuid_Last(String uuid,
358 OrderByComparator<MBThread> orderByComparator) {
359 int count = countByUuid(uuid);
360
361 if (count == 0) {
362 return null;
363 }
364
365 List<MBThread> list = findByUuid(uuid, count - 1, count,
366 orderByComparator);
367
368 if (!list.isEmpty()) {
369 return list.get(0);
370 }
371
372 return null;
373 }
374
375
384 @Override
385 public MBThread[] findByUuid_PrevAndNext(long threadId, String uuid,
386 OrderByComparator<MBThread> orderByComparator)
387 throws NoSuchThreadException {
388 MBThread mbThread = findByPrimaryKey(threadId);
389
390 Session session = null;
391
392 try {
393 session = openSession();
394
395 MBThread[] array = new MBThreadImpl[3];
396
397 array[0] = getByUuid_PrevAndNext(session, mbThread, uuid,
398 orderByComparator, true);
399
400 array[1] = mbThread;
401
402 array[2] = getByUuid_PrevAndNext(session, mbThread, uuid,
403 orderByComparator, false);
404
405 return array;
406 }
407 catch (Exception e) {
408 throw processException(e);
409 }
410 finally {
411 closeSession(session);
412 }
413 }
414
415 protected MBThread getByUuid_PrevAndNext(Session session,
416 MBThread mbThread, String uuid,
417 OrderByComparator<MBThread> orderByComparator, boolean previous) {
418 StringBundler query = null;
419
420 if (orderByComparator != null) {
421 query = new StringBundler(6 +
422 (orderByComparator.getOrderByFields().length * 6));
423 }
424 else {
425 query = new StringBundler(3);
426 }
427
428 query.append(_SQL_SELECT_MBTHREAD_WHERE);
429
430 boolean bindUuid = false;
431
432 if (uuid == null) {
433 query.append(_FINDER_COLUMN_UUID_UUID_1);
434 }
435 else if (uuid.equals(StringPool.BLANK)) {
436 query.append(_FINDER_COLUMN_UUID_UUID_3);
437 }
438 else {
439 bindUuid = true;
440
441 query.append(_FINDER_COLUMN_UUID_UUID_2);
442 }
443
444 if (orderByComparator != null) {
445 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446
447 if (orderByConditionFields.length > 0) {
448 query.append(WHERE_AND);
449 }
450
451 for (int i = 0; i < orderByConditionFields.length; i++) {
452 query.append(_ORDER_BY_ENTITY_ALIAS);
453 query.append(orderByConditionFields[i]);
454
455 if ((i + 1) < orderByConditionFields.length) {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN_HAS_NEXT);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN_HAS_NEXT);
461 }
462 }
463 else {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN);
469 }
470 }
471 }
472
473 query.append(ORDER_BY_CLAUSE);
474
475 String[] orderByFields = orderByComparator.getOrderByFields();
476
477 for (int i = 0; i < orderByFields.length; i++) {
478 query.append(_ORDER_BY_ENTITY_ALIAS);
479 query.append(orderByFields[i]);
480
481 if ((i + 1) < orderByFields.length) {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC_HAS_NEXT);
484 }
485 else {
486 query.append(ORDER_BY_DESC_HAS_NEXT);
487 }
488 }
489 else {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC);
492 }
493 else {
494 query.append(ORDER_BY_DESC);
495 }
496 }
497 }
498 }
499 else {
500 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
501 }
502
503 String sql = query.toString();
504
505 Query q = session.createQuery(sql);
506
507 q.setFirstResult(0);
508 q.setMaxResults(2);
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 if (bindUuid) {
513 qPos.add(uuid);
514 }
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<MBThread> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
539 @Override
540 public void removeByUuid(String uuid) {
541 for (MBThread mbThread : findByUuid(uuid, QueryUtil.ALL_POS,
542 QueryUtil.ALL_POS, null)) {
543 remove(mbThread);
544 }
545 }
546
547
553 @Override
554 public int countByUuid(String uuid) {
555 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
556
557 Object[] finderArgs = new Object[] { uuid };
558
559 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
560 this);
561
562 if (count == null) {
563 StringBundler query = new StringBundler(2);
564
565 query.append(_SQL_COUNT_MBTHREAD_WHERE);
566
567 boolean bindUuid = false;
568
569 if (uuid == null) {
570 query.append(_FINDER_COLUMN_UUID_UUID_1);
571 }
572 else if (uuid.equals(StringPool.BLANK)) {
573 query.append(_FINDER_COLUMN_UUID_UUID_3);
574 }
575 else {
576 bindUuid = true;
577
578 query.append(_FINDER_COLUMN_UUID_UUID_2);
579 }
580
581 String sql = query.toString();
582
583 Session session = null;
584
585 try {
586 session = openSession();
587
588 Query q = session.createQuery(sql);
589
590 QueryPos qPos = QueryPos.getInstance(q);
591
592 if (bindUuid) {
593 qPos.add(uuid);
594 }
595
596 count = (Long)q.uniqueResult();
597
598 FinderCacheUtil.putResult(finderPath, finderArgs, count);
599 }
600 catch (Exception e) {
601 FinderCacheUtil.removeResult(finderPath, finderArgs);
602
603 throw processException(e);
604 }
605 finally {
606 closeSession(session);
607 }
608 }
609
610 return count.intValue();
611 }
612
613 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbThread.uuid IS NULL";
614 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbThread.uuid = ?";
615 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '')";
616 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
617 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
618 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
619 new String[] { String.class.getName(), Long.class.getName() },
620 MBThreadModelImpl.UUID_COLUMN_BITMASK |
621 MBThreadModelImpl.GROUPID_COLUMN_BITMASK);
622 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
623 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
624 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
625 new String[] { String.class.getName(), Long.class.getName() });
626
627
635 @Override
636 public MBThread findByUUID_G(String uuid, long groupId)
637 throws NoSuchThreadException {
638 MBThread mbThread = fetchByUUID_G(uuid, groupId);
639
640 if (mbThread == null) {
641 StringBundler msg = new StringBundler(6);
642
643 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644
645 msg.append("uuid=");
646 msg.append(uuid);
647
648 msg.append(", groupId=");
649 msg.append(groupId);
650
651 msg.append(StringPool.CLOSE_CURLY_BRACE);
652
653 if (_log.isWarnEnabled()) {
654 _log.warn(msg.toString());
655 }
656
657 throw new NoSuchThreadException(msg.toString());
658 }
659
660 return mbThread;
661 }
662
663
670 @Override
671 public MBThread fetchByUUID_G(String uuid, long groupId) {
672 return fetchByUUID_G(uuid, groupId, true);
673 }
674
675
683 @Override
684 public MBThread fetchByUUID_G(String uuid, long groupId,
685 boolean retrieveFromCache) {
686 Object[] finderArgs = new Object[] { uuid, groupId };
687
688 Object result = null;
689
690 if (retrieveFromCache) {
691 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
692 finderArgs, this);
693 }
694
695 if (result instanceof MBThread) {
696 MBThread mbThread = (MBThread)result;
697
698 if (!Validator.equals(uuid, mbThread.getUuid()) ||
699 (groupId != mbThread.getGroupId())) {
700 result = null;
701 }
702 }
703
704 if (result == null) {
705 StringBundler query = new StringBundler(4);
706
707 query.append(_SQL_SELECT_MBTHREAD_WHERE);
708
709 boolean bindUuid = false;
710
711 if (uuid == null) {
712 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
713 }
714 else if (uuid.equals(StringPool.BLANK)) {
715 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
716 }
717 else {
718 bindUuid = true;
719
720 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
721 }
722
723 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
724
725 String sql = query.toString();
726
727 Session session = null;
728
729 try {
730 session = openSession();
731
732 Query q = session.createQuery(sql);
733
734 QueryPos qPos = QueryPos.getInstance(q);
735
736 if (bindUuid) {
737 qPos.add(uuid);
738 }
739
740 qPos.add(groupId);
741
742 List<MBThread> list = q.list();
743
744 if (list.isEmpty()) {
745 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
746 finderArgs, list);
747 }
748 else {
749 MBThread mbThread = list.get(0);
750
751 result = mbThread;
752
753 cacheResult(mbThread);
754
755 if ((mbThread.getUuid() == null) ||
756 !mbThread.getUuid().equals(uuid) ||
757 (mbThread.getGroupId() != groupId)) {
758 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
759 finderArgs, mbThread);
760 }
761 }
762 }
763 catch (Exception e) {
764 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
765 finderArgs);
766
767 throw processException(e);
768 }
769 finally {
770 closeSession(session);
771 }
772 }
773
774 if (result instanceof List<?>) {
775 return null;
776 }
777 else {
778 return (MBThread)result;
779 }
780 }
781
782
789 @Override
790 public MBThread removeByUUID_G(String uuid, long groupId)
791 throws NoSuchThreadException {
792 MBThread mbThread = findByUUID_G(uuid, groupId);
793
794 return remove(mbThread);
795 }
796
797
804 @Override
805 public int countByUUID_G(String uuid, long groupId) {
806 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
807
808 Object[] finderArgs = new Object[] { uuid, groupId };
809
810 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
811 this);
812
813 if (count == null) {
814 StringBundler query = new StringBundler(3);
815
816 query.append(_SQL_COUNT_MBTHREAD_WHERE);
817
818 boolean bindUuid = false;
819
820 if (uuid == null) {
821 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
822 }
823 else if (uuid.equals(StringPool.BLANK)) {
824 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
825 }
826 else {
827 bindUuid = true;
828
829 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
830 }
831
832 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
833
834 String sql = query.toString();
835
836 Session session = null;
837
838 try {
839 session = openSession();
840
841 Query q = session.createQuery(sql);
842
843 QueryPos qPos = QueryPos.getInstance(q);
844
845 if (bindUuid) {
846 qPos.add(uuid);
847 }
848
849 qPos.add(groupId);
850
851 count = (Long)q.uniqueResult();
852
853 FinderCacheUtil.putResult(finderPath, finderArgs, count);
854 }
855 catch (Exception e) {
856 FinderCacheUtil.removeResult(finderPath, finderArgs);
857
858 throw processException(e);
859 }
860 finally {
861 closeSession(session);
862 }
863 }
864
865 return count.intValue();
866 }
867
868 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbThread.uuid IS NULL AND ";
869 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbThread.uuid = ? AND ";
870 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
871 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbThread.groupId = ?";
872 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
873 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
874 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
875 new String[] {
876 String.class.getName(), Long.class.getName(),
877
878 Integer.class.getName(), Integer.class.getName(),
879 OrderByComparator.class.getName()
880 });
881 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
882 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
883 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
884 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
885 new String[] { String.class.getName(), Long.class.getName() },
886 MBThreadModelImpl.UUID_COLUMN_BITMASK |
887 MBThreadModelImpl.COMPANYID_COLUMN_BITMASK |
888 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
889 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
890 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
891 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
892 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
893 new String[] { String.class.getName(), Long.class.getName() });
894
895
902 @Override
903 public List<MBThread> findByUuid_C(String uuid, long companyId) {
904 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
905 QueryUtil.ALL_POS, null);
906 }
907
908
921 @Override
922 public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
923 int end) {
924 return findByUuid_C(uuid, companyId, start, end, null);
925 }
926
927
941 @Override
942 public List<MBThread> findByUuid_C(String uuid, long companyId, int start,
943 int end, OrderByComparator<MBThread> orderByComparator) {
944 boolean pagination = true;
945 FinderPath finderPath = null;
946 Object[] finderArgs = null;
947
948 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
949 (orderByComparator == null)) {
950 pagination = false;
951 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
952 finderArgs = new Object[] { uuid, companyId };
953 }
954 else {
955 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
956 finderArgs = new Object[] {
957 uuid, companyId,
958
959 start, end, orderByComparator
960 };
961 }
962
963 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
964 finderArgs, this);
965
966 if ((list != null) && !list.isEmpty()) {
967 for (MBThread mbThread : list) {
968 if (!Validator.equals(uuid, mbThread.getUuid()) ||
969 (companyId != mbThread.getCompanyId())) {
970 list = null;
971
972 break;
973 }
974 }
975 }
976
977 if (list == null) {
978 StringBundler query = null;
979
980 if (orderByComparator != null) {
981 query = new StringBundler(4 +
982 (orderByComparator.getOrderByFields().length * 3));
983 }
984 else {
985 query = new StringBundler(4);
986 }
987
988 query.append(_SQL_SELECT_MBTHREAD_WHERE);
989
990 boolean bindUuid = false;
991
992 if (uuid == null) {
993 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
994 }
995 else if (uuid.equals(StringPool.BLANK)) {
996 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
997 }
998 else {
999 bindUuid = true;
1000
1001 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1002 }
1003
1004 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1005
1006 if (orderByComparator != null) {
1007 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1008 orderByComparator);
1009 }
1010 else
1011 if (pagination) {
1012 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1013 }
1014
1015 String sql = query.toString();
1016
1017 Session session = null;
1018
1019 try {
1020 session = openSession();
1021
1022 Query q = session.createQuery(sql);
1023
1024 QueryPos qPos = QueryPos.getInstance(q);
1025
1026 if (bindUuid) {
1027 qPos.add(uuid);
1028 }
1029
1030 qPos.add(companyId);
1031
1032 if (!pagination) {
1033 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1034 start, end, false);
1035
1036 Collections.sort(list);
1037
1038 list = Collections.unmodifiableList(list);
1039 }
1040 else {
1041 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1042 start, end);
1043 }
1044
1045 cacheResult(list);
1046
1047 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1048 }
1049 catch (Exception e) {
1050 FinderCacheUtil.removeResult(finderPath, finderArgs);
1051
1052 throw processException(e);
1053 }
1054 finally {
1055 closeSession(session);
1056 }
1057 }
1058
1059 return list;
1060 }
1061
1062
1071 @Override
1072 public MBThread findByUuid_C_First(String uuid, long companyId,
1073 OrderByComparator<MBThread> orderByComparator)
1074 throws NoSuchThreadException {
1075 MBThread mbThread = fetchByUuid_C_First(uuid, companyId,
1076 orderByComparator);
1077
1078 if (mbThread != null) {
1079 return mbThread;
1080 }
1081
1082 StringBundler msg = new StringBundler(6);
1083
1084 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1085
1086 msg.append("uuid=");
1087 msg.append(uuid);
1088
1089 msg.append(", companyId=");
1090 msg.append(companyId);
1091
1092 msg.append(StringPool.CLOSE_CURLY_BRACE);
1093
1094 throw new NoSuchThreadException(msg.toString());
1095 }
1096
1097
1105 @Override
1106 public MBThread fetchByUuid_C_First(String uuid, long companyId,
1107 OrderByComparator<MBThread> orderByComparator) {
1108 List<MBThread> list = findByUuid_C(uuid, companyId, 0, 1,
1109 orderByComparator);
1110
1111 if (!list.isEmpty()) {
1112 return list.get(0);
1113 }
1114
1115 return null;
1116 }
1117
1118
1127 @Override
1128 public MBThread findByUuid_C_Last(String uuid, long companyId,
1129 OrderByComparator<MBThread> orderByComparator)
1130 throws NoSuchThreadException {
1131 MBThread mbThread = fetchByUuid_C_Last(uuid, companyId,
1132 orderByComparator);
1133
1134 if (mbThread != null) {
1135 return mbThread;
1136 }
1137
1138 StringBundler msg = new StringBundler(6);
1139
1140 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1141
1142 msg.append("uuid=");
1143 msg.append(uuid);
1144
1145 msg.append(", companyId=");
1146 msg.append(companyId);
1147
1148 msg.append(StringPool.CLOSE_CURLY_BRACE);
1149
1150 throw new NoSuchThreadException(msg.toString());
1151 }
1152
1153
1161 @Override
1162 public MBThread fetchByUuid_C_Last(String uuid, long companyId,
1163 OrderByComparator<MBThread> orderByComparator) {
1164 int count = countByUuid_C(uuid, companyId);
1165
1166 if (count == 0) {
1167 return null;
1168 }
1169
1170 List<MBThread> list = findByUuid_C(uuid, companyId, count - 1, count,
1171 orderByComparator);
1172
1173 if (!list.isEmpty()) {
1174 return list.get(0);
1175 }
1176
1177 return null;
1178 }
1179
1180
1190 @Override
1191 public MBThread[] findByUuid_C_PrevAndNext(long threadId, String uuid,
1192 long companyId, OrderByComparator<MBThread> orderByComparator)
1193 throws NoSuchThreadException {
1194 MBThread mbThread = findByPrimaryKey(threadId);
1195
1196 Session session = null;
1197
1198 try {
1199 session = openSession();
1200
1201 MBThread[] array = new MBThreadImpl[3];
1202
1203 array[0] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1204 companyId, orderByComparator, true);
1205
1206 array[1] = mbThread;
1207
1208 array[2] = getByUuid_C_PrevAndNext(session, mbThread, uuid,
1209 companyId, orderByComparator, false);
1210
1211 return array;
1212 }
1213 catch (Exception e) {
1214 throw processException(e);
1215 }
1216 finally {
1217 closeSession(session);
1218 }
1219 }
1220
1221 protected MBThread getByUuid_C_PrevAndNext(Session session,
1222 MBThread mbThread, String uuid, long companyId,
1223 OrderByComparator<MBThread> orderByComparator, boolean previous) {
1224 StringBundler query = null;
1225
1226 if (orderByComparator != null) {
1227 query = new StringBundler(6 +
1228 (orderByComparator.getOrderByFields().length * 6));
1229 }
1230 else {
1231 query = new StringBundler(3);
1232 }
1233
1234 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1235
1236 boolean bindUuid = false;
1237
1238 if (uuid == null) {
1239 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1240 }
1241 else if (uuid.equals(StringPool.BLANK)) {
1242 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1243 }
1244 else {
1245 bindUuid = true;
1246
1247 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1248 }
1249
1250 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1251
1252 if (orderByComparator != null) {
1253 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1254
1255 if (orderByConditionFields.length > 0) {
1256 query.append(WHERE_AND);
1257 }
1258
1259 for (int i = 0; i < orderByConditionFields.length; i++) {
1260 query.append(_ORDER_BY_ENTITY_ALIAS);
1261 query.append(orderByConditionFields[i]);
1262
1263 if ((i + 1) < orderByConditionFields.length) {
1264 if (orderByComparator.isAscending() ^ previous) {
1265 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1266 }
1267 else {
1268 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1269 }
1270 }
1271 else {
1272 if (orderByComparator.isAscending() ^ previous) {
1273 query.append(WHERE_GREATER_THAN);
1274 }
1275 else {
1276 query.append(WHERE_LESSER_THAN);
1277 }
1278 }
1279 }
1280
1281 query.append(ORDER_BY_CLAUSE);
1282
1283 String[] orderByFields = orderByComparator.getOrderByFields();
1284
1285 for (int i = 0; i < orderByFields.length; i++) {
1286 query.append(_ORDER_BY_ENTITY_ALIAS);
1287 query.append(orderByFields[i]);
1288
1289 if ((i + 1) < orderByFields.length) {
1290 if (orderByComparator.isAscending() ^ previous) {
1291 query.append(ORDER_BY_ASC_HAS_NEXT);
1292 }
1293 else {
1294 query.append(ORDER_BY_DESC_HAS_NEXT);
1295 }
1296 }
1297 else {
1298 if (orderByComparator.isAscending() ^ previous) {
1299 query.append(ORDER_BY_ASC);
1300 }
1301 else {
1302 query.append(ORDER_BY_DESC);
1303 }
1304 }
1305 }
1306 }
1307 else {
1308 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1309 }
1310
1311 String sql = query.toString();
1312
1313 Query q = session.createQuery(sql);
1314
1315 q.setFirstResult(0);
1316 q.setMaxResults(2);
1317
1318 QueryPos qPos = QueryPos.getInstance(q);
1319
1320 if (bindUuid) {
1321 qPos.add(uuid);
1322 }
1323
1324 qPos.add(companyId);
1325
1326 if (orderByComparator != null) {
1327 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1328
1329 for (Object value : values) {
1330 qPos.add(value);
1331 }
1332 }
1333
1334 List<MBThread> list = q.list();
1335
1336 if (list.size() == 2) {
1337 return list.get(1);
1338 }
1339 else {
1340 return null;
1341 }
1342 }
1343
1344
1350 @Override
1351 public void removeByUuid_C(String uuid, long companyId) {
1352 for (MBThread mbThread : findByUuid_C(uuid, companyId,
1353 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1354 remove(mbThread);
1355 }
1356 }
1357
1358
1365 @Override
1366 public int countByUuid_C(String uuid, long companyId) {
1367 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1368
1369 Object[] finderArgs = new Object[] { uuid, companyId };
1370
1371 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1372 this);
1373
1374 if (count == null) {
1375 StringBundler query = new StringBundler(3);
1376
1377 query.append(_SQL_COUNT_MBTHREAD_WHERE);
1378
1379 boolean bindUuid = false;
1380
1381 if (uuid == null) {
1382 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1383 }
1384 else if (uuid.equals(StringPool.BLANK)) {
1385 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1386 }
1387 else {
1388 bindUuid = true;
1389
1390 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1391 }
1392
1393 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1394
1395 String sql = query.toString();
1396
1397 Session session = null;
1398
1399 try {
1400 session = openSession();
1401
1402 Query q = session.createQuery(sql);
1403
1404 QueryPos qPos = QueryPos.getInstance(q);
1405
1406 if (bindUuid) {
1407 qPos.add(uuid);
1408 }
1409
1410 qPos.add(companyId);
1411
1412 count = (Long)q.uniqueResult();
1413
1414 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1415 }
1416 catch (Exception e) {
1417 FinderCacheUtil.removeResult(finderPath, finderArgs);
1418
1419 throw processException(e);
1420 }
1421 finally {
1422 closeSession(session);
1423 }
1424 }
1425
1426 return count.intValue();
1427 }
1428
1429 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbThread.uuid IS NULL AND ";
1430 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbThread.uuid = ? AND ";
1431 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbThread.uuid IS NULL OR mbThread.uuid = '') AND ";
1432 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbThread.companyId = ?";
1433 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1434 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1435 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1436 new String[] {
1437 Long.class.getName(),
1438
1439 Integer.class.getName(), Integer.class.getName(),
1440 OrderByComparator.class.getName()
1441 });
1442 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1443 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1444 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
1445 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1446 new String[] { Long.class.getName() },
1447 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
1448 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
1449 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
1450 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
1451 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
1452 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1453 new String[] { Long.class.getName() });
1454
1455
1461 @Override
1462 public List<MBThread> findByGroupId(long groupId) {
1463 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1464 }
1465
1466
1478 @Override
1479 public List<MBThread> findByGroupId(long groupId, int start, int end) {
1480 return findByGroupId(groupId, start, end, null);
1481 }
1482
1483
1496 @Override
1497 public List<MBThread> findByGroupId(long groupId, int start, int end,
1498 OrderByComparator<MBThread> orderByComparator) {
1499 boolean pagination = true;
1500 FinderPath finderPath = null;
1501 Object[] finderArgs = null;
1502
1503 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1504 (orderByComparator == null)) {
1505 pagination = false;
1506 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1507 finderArgs = new Object[] { groupId };
1508 }
1509 else {
1510 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1511 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1512 }
1513
1514 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
1515 finderArgs, this);
1516
1517 if ((list != null) && !list.isEmpty()) {
1518 for (MBThread mbThread : list) {
1519 if ((groupId != mbThread.getGroupId())) {
1520 list = null;
1521
1522 break;
1523 }
1524 }
1525 }
1526
1527 if (list == null) {
1528 StringBundler query = null;
1529
1530 if (orderByComparator != null) {
1531 query = new StringBundler(3 +
1532 (orderByComparator.getOrderByFields().length * 3));
1533 }
1534 else {
1535 query = new StringBundler(3);
1536 }
1537
1538 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1539
1540 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1541
1542 if (orderByComparator != null) {
1543 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1544 orderByComparator);
1545 }
1546 else
1547 if (pagination) {
1548 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1549 }
1550
1551 String sql = query.toString();
1552
1553 Session session = null;
1554
1555 try {
1556 session = openSession();
1557
1558 Query q = session.createQuery(sql);
1559
1560 QueryPos qPos = QueryPos.getInstance(q);
1561
1562 qPos.add(groupId);
1563
1564 if (!pagination) {
1565 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1566 start, end, false);
1567
1568 Collections.sort(list);
1569
1570 list = Collections.unmodifiableList(list);
1571 }
1572 else {
1573 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
1574 start, end);
1575 }
1576
1577 cacheResult(list);
1578
1579 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1580 }
1581 catch (Exception e) {
1582 FinderCacheUtil.removeResult(finderPath, finderArgs);
1583
1584 throw processException(e);
1585 }
1586 finally {
1587 closeSession(session);
1588 }
1589 }
1590
1591 return list;
1592 }
1593
1594
1602 @Override
1603 public MBThread findByGroupId_First(long groupId,
1604 OrderByComparator<MBThread> orderByComparator)
1605 throws NoSuchThreadException {
1606 MBThread mbThread = fetchByGroupId_First(groupId, orderByComparator);
1607
1608 if (mbThread != null) {
1609 return mbThread;
1610 }
1611
1612 StringBundler msg = new StringBundler(4);
1613
1614 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1615
1616 msg.append("groupId=");
1617 msg.append(groupId);
1618
1619 msg.append(StringPool.CLOSE_CURLY_BRACE);
1620
1621 throw new NoSuchThreadException(msg.toString());
1622 }
1623
1624
1631 @Override
1632 public MBThread fetchByGroupId_First(long groupId,
1633 OrderByComparator<MBThread> orderByComparator) {
1634 List<MBThread> list = findByGroupId(groupId, 0, 1, orderByComparator);
1635
1636 if (!list.isEmpty()) {
1637 return list.get(0);
1638 }
1639
1640 return null;
1641 }
1642
1643
1651 @Override
1652 public MBThread findByGroupId_Last(long groupId,
1653 OrderByComparator<MBThread> orderByComparator)
1654 throws NoSuchThreadException {
1655 MBThread mbThread = fetchByGroupId_Last(groupId, orderByComparator);
1656
1657 if (mbThread != null) {
1658 return mbThread;
1659 }
1660
1661 StringBundler msg = new StringBundler(4);
1662
1663 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1664
1665 msg.append("groupId=");
1666 msg.append(groupId);
1667
1668 msg.append(StringPool.CLOSE_CURLY_BRACE);
1669
1670 throw new NoSuchThreadException(msg.toString());
1671 }
1672
1673
1680 @Override
1681 public MBThread fetchByGroupId_Last(long groupId,
1682 OrderByComparator<MBThread> orderByComparator) {
1683 int count = countByGroupId(groupId);
1684
1685 if (count == 0) {
1686 return null;
1687 }
1688
1689 List<MBThread> list = findByGroupId(groupId, count - 1, count,
1690 orderByComparator);
1691
1692 if (!list.isEmpty()) {
1693 return list.get(0);
1694 }
1695
1696 return null;
1697 }
1698
1699
1708 @Override
1709 public MBThread[] findByGroupId_PrevAndNext(long threadId, long groupId,
1710 OrderByComparator<MBThread> orderByComparator)
1711 throws NoSuchThreadException {
1712 MBThread mbThread = findByPrimaryKey(threadId);
1713
1714 Session session = null;
1715
1716 try {
1717 session = openSession();
1718
1719 MBThread[] array = new MBThreadImpl[3];
1720
1721 array[0] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1722 orderByComparator, true);
1723
1724 array[1] = mbThread;
1725
1726 array[2] = getByGroupId_PrevAndNext(session, mbThread, groupId,
1727 orderByComparator, false);
1728
1729 return array;
1730 }
1731 catch (Exception e) {
1732 throw processException(e);
1733 }
1734 finally {
1735 closeSession(session);
1736 }
1737 }
1738
1739 protected MBThread getByGroupId_PrevAndNext(Session session,
1740 MBThread mbThread, long groupId,
1741 OrderByComparator<MBThread> orderByComparator, boolean previous) {
1742 StringBundler query = null;
1743
1744 if (orderByComparator != null) {
1745 query = new StringBundler(6 +
1746 (orderByComparator.getOrderByFields().length * 6));
1747 }
1748 else {
1749 query = new StringBundler(3);
1750 }
1751
1752 query.append(_SQL_SELECT_MBTHREAD_WHERE);
1753
1754 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1755
1756 if (orderByComparator != null) {
1757 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1758
1759 if (orderByConditionFields.length > 0) {
1760 query.append(WHERE_AND);
1761 }
1762
1763 for (int i = 0; i < orderByConditionFields.length; i++) {
1764 query.append(_ORDER_BY_ENTITY_ALIAS);
1765 query.append(orderByConditionFields[i]);
1766
1767 if ((i + 1) < orderByConditionFields.length) {
1768 if (orderByComparator.isAscending() ^ previous) {
1769 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1770 }
1771 else {
1772 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1773 }
1774 }
1775 else {
1776 if (orderByComparator.isAscending() ^ previous) {
1777 query.append(WHERE_GREATER_THAN);
1778 }
1779 else {
1780 query.append(WHERE_LESSER_THAN);
1781 }
1782 }
1783 }
1784
1785 query.append(ORDER_BY_CLAUSE);
1786
1787 String[] orderByFields = orderByComparator.getOrderByFields();
1788
1789 for (int i = 0; i < orderByFields.length; i++) {
1790 query.append(_ORDER_BY_ENTITY_ALIAS);
1791 query.append(orderByFields[i]);
1792
1793 if ((i + 1) < orderByFields.length) {
1794 if (orderByComparator.isAscending() ^ previous) {
1795 query.append(ORDER_BY_ASC_HAS_NEXT);
1796 }
1797 else {
1798 query.append(ORDER_BY_DESC_HAS_NEXT);
1799 }
1800 }
1801 else {
1802 if (orderByComparator.isAscending() ^ previous) {
1803 query.append(ORDER_BY_ASC);
1804 }
1805 else {
1806 query.append(ORDER_BY_DESC);
1807 }
1808 }
1809 }
1810 }
1811 else {
1812 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1813 }
1814
1815 String sql = query.toString();
1816
1817 Query q = session.createQuery(sql);
1818
1819 q.setFirstResult(0);
1820 q.setMaxResults(2);
1821
1822 QueryPos qPos = QueryPos.getInstance(q);
1823
1824 qPos.add(groupId);
1825
1826 if (orderByComparator != null) {
1827 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
1828
1829 for (Object value : values) {
1830 qPos.add(value);
1831 }
1832 }
1833
1834 List<MBThread> list = q.list();
1835
1836 if (list.size() == 2) {
1837 return list.get(1);
1838 }
1839 else {
1840 return null;
1841 }
1842 }
1843
1844
1850 @Override
1851 public List<MBThread> filterFindByGroupId(long groupId) {
1852 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1853 QueryUtil.ALL_POS, null);
1854 }
1855
1856
1868 @Override
1869 public List<MBThread> filterFindByGroupId(long groupId, int start, int end) {
1870 return filterFindByGroupId(groupId, start, end, null);
1871 }
1872
1873
1886 @Override
1887 public List<MBThread> filterFindByGroupId(long groupId, int start, int end,
1888 OrderByComparator<MBThread> orderByComparator) {
1889 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1890 return findByGroupId(groupId, start, end, orderByComparator);
1891 }
1892
1893 StringBundler query = null;
1894
1895 if (orderByComparator != null) {
1896 query = new StringBundler(3 +
1897 (orderByComparator.getOrderByFields().length * 3));
1898 }
1899 else {
1900 query = new StringBundler(3);
1901 }
1902
1903 if (getDB().isSupportsInlineDistinct()) {
1904 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
1905 }
1906 else {
1907 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
1908 }
1909
1910 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1911
1912 if (!getDB().isSupportsInlineDistinct()) {
1913 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
1914 }
1915
1916 if (orderByComparator != null) {
1917 if (getDB().isSupportsInlineDistinct()) {
1918 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1919 orderByComparator, true);
1920 }
1921 else {
1922 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1923 orderByComparator, true);
1924 }
1925 }
1926 else {
1927 if (getDB().isSupportsInlineDistinct()) {
1928 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
1929 }
1930 else {
1931 query.append(MBThreadModelImpl.ORDER_BY_SQL);
1932 }
1933 }
1934
1935 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1936 MBThread.class.getName(),
1937 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1938
1939 Session session = null;
1940
1941 try {
1942 session = openSession();
1943
1944 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1945
1946 if (getDB().isSupportsInlineDistinct()) {
1947 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
1948 }
1949 else {
1950 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
1951 }
1952
1953 QueryPos qPos = QueryPos.getInstance(q);
1954
1955 qPos.add(groupId);
1956
1957 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
1958 }
1959 catch (Exception e) {
1960 throw processException(e);
1961 }
1962 finally {
1963 closeSession(session);
1964 }
1965 }
1966
1967
1976 @Override
1977 public MBThread[] filterFindByGroupId_PrevAndNext(long threadId,
1978 long groupId, OrderByComparator<MBThread> orderByComparator)
1979 throws NoSuchThreadException {
1980 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1981 return findByGroupId_PrevAndNext(threadId, groupId,
1982 orderByComparator);
1983 }
1984
1985 MBThread mbThread = findByPrimaryKey(threadId);
1986
1987 Session session = null;
1988
1989 try {
1990 session = openSession();
1991
1992 MBThread[] array = new MBThreadImpl[3];
1993
1994 array[0] = filterGetByGroupId_PrevAndNext(session, mbThread,
1995 groupId, orderByComparator, true);
1996
1997 array[1] = mbThread;
1998
1999 array[2] = filterGetByGroupId_PrevAndNext(session, mbThread,
2000 groupId, orderByComparator, false);
2001
2002 return array;
2003 }
2004 catch (Exception e) {
2005 throw processException(e);
2006 }
2007 finally {
2008 closeSession(session);
2009 }
2010 }
2011
2012 protected MBThread filterGetByGroupId_PrevAndNext(Session session,
2013 MBThread mbThread, long groupId,
2014 OrderByComparator<MBThread> orderByComparator, boolean previous) {
2015 StringBundler query = null;
2016
2017 if (orderByComparator != null) {
2018 query = new StringBundler(6 +
2019 (orderByComparator.getOrderByFields().length * 6));
2020 }
2021 else {
2022 query = new StringBundler(3);
2023 }
2024
2025 if (getDB().isSupportsInlineDistinct()) {
2026 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2027 }
2028 else {
2029 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2030 }
2031
2032 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2033
2034 if (!getDB().isSupportsInlineDistinct()) {
2035 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
2036 }
2037
2038 if (orderByComparator != null) {
2039 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2040
2041 if (orderByConditionFields.length > 0) {
2042 query.append(WHERE_AND);
2043 }
2044
2045 for (int i = 0; i < orderByConditionFields.length; i++) {
2046 if (getDB().isSupportsInlineDistinct()) {
2047 query.append(_ORDER_BY_ENTITY_ALIAS);
2048 }
2049 else {
2050 query.append(_ORDER_BY_ENTITY_TABLE);
2051 }
2052
2053 query.append(orderByConditionFields[i]);
2054
2055 if ((i + 1) < orderByConditionFields.length) {
2056 if (orderByComparator.isAscending() ^ previous) {
2057 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2058 }
2059 else {
2060 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2061 }
2062 }
2063 else {
2064 if (orderByComparator.isAscending() ^ previous) {
2065 query.append(WHERE_GREATER_THAN);
2066 }
2067 else {
2068 query.append(WHERE_LESSER_THAN);
2069 }
2070 }
2071 }
2072
2073 query.append(ORDER_BY_CLAUSE);
2074
2075 String[] orderByFields = orderByComparator.getOrderByFields();
2076
2077 for (int i = 0; i < orderByFields.length; i++) {
2078 if (getDB().isSupportsInlineDistinct()) {
2079 query.append(_ORDER_BY_ENTITY_ALIAS);
2080 }
2081 else {
2082 query.append(_ORDER_BY_ENTITY_TABLE);
2083 }
2084
2085 query.append(orderByFields[i]);
2086
2087 if ((i + 1) < orderByFields.length) {
2088 if (orderByComparator.isAscending() ^ previous) {
2089 query.append(ORDER_BY_ASC_HAS_NEXT);
2090 }
2091 else {
2092 query.append(ORDER_BY_DESC_HAS_NEXT);
2093 }
2094 }
2095 else {
2096 if (orderByComparator.isAscending() ^ previous) {
2097 query.append(ORDER_BY_ASC);
2098 }
2099 else {
2100 query.append(ORDER_BY_DESC);
2101 }
2102 }
2103 }
2104 }
2105 else {
2106 if (getDB().isSupportsInlineDistinct()) {
2107 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2108 }
2109 else {
2110 query.append(MBThreadModelImpl.ORDER_BY_SQL);
2111 }
2112 }
2113
2114 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2115 MBThread.class.getName(),
2116 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2117
2118 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2119
2120 q.setFirstResult(0);
2121 q.setMaxResults(2);
2122
2123 if (getDB().isSupportsInlineDistinct()) {
2124 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
2125 }
2126 else {
2127 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
2128 }
2129
2130 QueryPos qPos = QueryPos.getInstance(q);
2131
2132 qPos.add(groupId);
2133
2134 if (orderByComparator != null) {
2135 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2136
2137 for (Object value : values) {
2138 qPos.add(value);
2139 }
2140 }
2141
2142 List<MBThread> list = q.list();
2143
2144 if (list.size() == 2) {
2145 return list.get(1);
2146 }
2147 else {
2148 return null;
2149 }
2150 }
2151
2152
2157 @Override
2158 public void removeByGroupId(long groupId) {
2159 for (MBThread mbThread : findByGroupId(groupId, QueryUtil.ALL_POS,
2160 QueryUtil.ALL_POS, null)) {
2161 remove(mbThread);
2162 }
2163 }
2164
2165
2171 @Override
2172 public int countByGroupId(long groupId) {
2173 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2174
2175 Object[] finderArgs = new Object[] { groupId };
2176
2177 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2178 this);
2179
2180 if (count == null) {
2181 StringBundler query = new StringBundler(2);
2182
2183 query.append(_SQL_COUNT_MBTHREAD_WHERE);
2184
2185 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2186
2187 String sql = query.toString();
2188
2189 Session session = null;
2190
2191 try {
2192 session = openSession();
2193
2194 Query q = session.createQuery(sql);
2195
2196 QueryPos qPos = QueryPos.getInstance(q);
2197
2198 qPos.add(groupId);
2199
2200 count = (Long)q.uniqueResult();
2201
2202 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2203 }
2204 catch (Exception e) {
2205 FinderCacheUtil.removeResult(finderPath, finderArgs);
2206
2207 throw processException(e);
2208 }
2209 finally {
2210 closeSession(session);
2211 }
2212 }
2213
2214 return count.intValue();
2215 }
2216
2217
2223 @Override
2224 public int filterCountByGroupId(long groupId) {
2225 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2226 return countByGroupId(groupId);
2227 }
2228
2229 StringBundler query = new StringBundler(2);
2230
2231 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
2232
2233 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2234
2235 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2236 MBThread.class.getName(),
2237 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2238
2239 Session session = null;
2240
2241 try {
2242 session = openSession();
2243
2244 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2245
2246 q.addScalar(COUNT_COLUMN_NAME,
2247 com.liferay.portal.kernel.dao.orm.Type.LONG);
2248
2249 QueryPos qPos = QueryPos.getInstance(q);
2250
2251 qPos.add(groupId);
2252
2253 Long count = (Long)q.uniqueResult();
2254
2255 return count.intValue();
2256 }
2257 catch (Exception e) {
2258 throw processException(e);
2259 }
2260 finally {
2261 closeSession(session);
2262 }
2263 }
2264
2265 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbThread.groupId = ? AND mbThread.categoryId != -1";
2266 public static final FinderPath FINDER_PATH_FETCH_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2267 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2268 FINDER_CLASS_NAME_ENTITY, "fetchByRootMessageId",
2269 new String[] { Long.class.getName() },
2270 MBThreadModelImpl.ROOTMESSAGEID_COLUMN_BITMASK);
2271 public static final FinderPath FINDER_PATH_COUNT_BY_ROOTMESSAGEID = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2272 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2273 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByRootMessageId",
2274 new String[] { Long.class.getName() });
2275
2276
2283 @Override
2284 public MBThread findByRootMessageId(long rootMessageId)
2285 throws NoSuchThreadException {
2286 MBThread mbThread = fetchByRootMessageId(rootMessageId);
2287
2288 if (mbThread == null) {
2289 StringBundler msg = new StringBundler(4);
2290
2291 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2292
2293 msg.append("rootMessageId=");
2294 msg.append(rootMessageId);
2295
2296 msg.append(StringPool.CLOSE_CURLY_BRACE);
2297
2298 if (_log.isWarnEnabled()) {
2299 _log.warn(msg.toString());
2300 }
2301
2302 throw new NoSuchThreadException(msg.toString());
2303 }
2304
2305 return mbThread;
2306 }
2307
2308
2314 @Override
2315 public MBThread fetchByRootMessageId(long rootMessageId) {
2316 return fetchByRootMessageId(rootMessageId, true);
2317 }
2318
2319
2326 @Override
2327 public MBThread fetchByRootMessageId(long rootMessageId,
2328 boolean retrieveFromCache) {
2329 Object[] finderArgs = new Object[] { rootMessageId };
2330
2331 Object result = null;
2332
2333 if (retrieveFromCache) {
2334 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2335 finderArgs, this);
2336 }
2337
2338 if (result instanceof MBThread) {
2339 MBThread mbThread = (MBThread)result;
2340
2341 if ((rootMessageId != mbThread.getRootMessageId())) {
2342 result = null;
2343 }
2344 }
2345
2346 if (result == null) {
2347 StringBundler query = new StringBundler(3);
2348
2349 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2350
2351 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2352
2353 String sql = query.toString();
2354
2355 Session session = null;
2356
2357 try {
2358 session = openSession();
2359
2360 Query q = session.createQuery(sql);
2361
2362 QueryPos qPos = QueryPos.getInstance(q);
2363
2364 qPos.add(rootMessageId);
2365
2366 List<MBThread> list = q.list();
2367
2368 if (list.isEmpty()) {
2369 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2370 finderArgs, list);
2371 }
2372 else {
2373 if ((list.size() > 1) && _log.isWarnEnabled()) {
2374 _log.warn(
2375 "MBThreadPersistenceImpl.fetchByRootMessageId(long, boolean) with parameters (" +
2376 StringUtil.merge(finderArgs) +
2377 ") 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.");
2378 }
2379
2380 MBThread mbThread = list.get(0);
2381
2382 result = mbThread;
2383
2384 cacheResult(mbThread);
2385
2386 if ((mbThread.getRootMessageId() != rootMessageId)) {
2387 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2388 finderArgs, mbThread);
2389 }
2390 }
2391 }
2392 catch (Exception e) {
2393 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
2394 finderArgs);
2395
2396 throw processException(e);
2397 }
2398 finally {
2399 closeSession(session);
2400 }
2401 }
2402
2403 if (result instanceof List<?>) {
2404 return null;
2405 }
2406 else {
2407 return (MBThread)result;
2408 }
2409 }
2410
2411
2417 @Override
2418 public MBThread removeByRootMessageId(long rootMessageId)
2419 throws NoSuchThreadException {
2420 MBThread mbThread = findByRootMessageId(rootMessageId);
2421
2422 return remove(mbThread);
2423 }
2424
2425
2431 @Override
2432 public int countByRootMessageId(long rootMessageId) {
2433 FinderPath finderPath = FINDER_PATH_COUNT_BY_ROOTMESSAGEID;
2434
2435 Object[] finderArgs = new Object[] { rootMessageId };
2436
2437 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2438 this);
2439
2440 if (count == null) {
2441 StringBundler query = new StringBundler(2);
2442
2443 query.append(_SQL_COUNT_MBTHREAD_WHERE);
2444
2445 query.append(_FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2);
2446
2447 String sql = query.toString();
2448
2449 Session session = null;
2450
2451 try {
2452 session = openSession();
2453
2454 Query q = session.createQuery(sql);
2455
2456 QueryPos qPos = QueryPos.getInstance(q);
2457
2458 qPos.add(rootMessageId);
2459
2460 count = (Long)q.uniqueResult();
2461
2462 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2463 }
2464 catch (Exception e) {
2465 FinderCacheUtil.removeResult(finderPath, finderArgs);
2466
2467 throw processException(e);
2468 }
2469 finally {
2470 closeSession(session);
2471 }
2472 }
2473
2474 return count.intValue();
2475 }
2476
2477 private static final String _FINDER_COLUMN_ROOTMESSAGEID_ROOTMESSAGEID_2 = "mbThread.rootMessageId = ?";
2478 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2479 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2480 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
2481 new String[] {
2482 Long.class.getName(), Long.class.getName(),
2483
2484 Integer.class.getName(), Integer.class.getName(),
2485 OrderByComparator.class.getName()
2486 });
2487 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2488 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
2489 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
2490 new String[] { Long.class.getName(), Long.class.getName() },
2491 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
2492 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
2493 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
2494 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
2495 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2496 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2497 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
2498 new String[] { Long.class.getName(), Long.class.getName() });
2499 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
2500 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
2501 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C",
2502 new String[] { Long.class.getName(), Long.class.getName() });
2503
2504
2511 @Override
2512 public List<MBThread> findByG_C(long groupId, long categoryId) {
2513 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2514 QueryUtil.ALL_POS, null);
2515 }
2516
2517
2530 @Override
2531 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2532 int end) {
2533 return findByG_C(groupId, categoryId, start, end, null);
2534 }
2535
2536
2550 @Override
2551 public List<MBThread> findByG_C(long groupId, long categoryId, int start,
2552 int end, OrderByComparator<MBThread> orderByComparator) {
2553 boolean pagination = true;
2554 FinderPath finderPath = null;
2555 Object[] finderArgs = null;
2556
2557 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2558 (orderByComparator == null)) {
2559 pagination = false;
2560 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
2561 finderArgs = new Object[] { groupId, categoryId };
2562 }
2563 else {
2564 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
2565 finderArgs = new Object[] {
2566 groupId, categoryId,
2567
2568 start, end, orderByComparator
2569 };
2570 }
2571
2572 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
2573 finderArgs, this);
2574
2575 if ((list != null) && !list.isEmpty()) {
2576 for (MBThread mbThread : list) {
2577 if ((groupId != mbThread.getGroupId()) ||
2578 (categoryId != mbThread.getCategoryId())) {
2579 list = null;
2580
2581 break;
2582 }
2583 }
2584 }
2585
2586 if (list == null) {
2587 StringBundler query = null;
2588
2589 if (orderByComparator != null) {
2590 query = new StringBundler(4 +
2591 (orderByComparator.getOrderByFields().length * 3));
2592 }
2593 else {
2594 query = new StringBundler(4);
2595 }
2596
2597 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2598
2599 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2600
2601 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2602
2603 if (orderByComparator != null) {
2604 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2605 orderByComparator);
2606 }
2607 else
2608 if (pagination) {
2609 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2610 }
2611
2612 String sql = query.toString();
2613
2614 Session session = null;
2615
2616 try {
2617 session = openSession();
2618
2619 Query q = session.createQuery(sql);
2620
2621 QueryPos qPos = QueryPos.getInstance(q);
2622
2623 qPos.add(groupId);
2624
2625 qPos.add(categoryId);
2626
2627 if (!pagination) {
2628 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2629 start, end, false);
2630
2631 Collections.sort(list);
2632
2633 list = Collections.unmodifiableList(list);
2634 }
2635 else {
2636 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
2637 start, end);
2638 }
2639
2640 cacheResult(list);
2641
2642 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2643 }
2644 catch (Exception e) {
2645 FinderCacheUtil.removeResult(finderPath, finderArgs);
2646
2647 throw processException(e);
2648 }
2649 finally {
2650 closeSession(session);
2651 }
2652 }
2653
2654 return list;
2655 }
2656
2657
2666 @Override
2667 public MBThread findByG_C_First(long groupId, long categoryId,
2668 OrderByComparator<MBThread> orderByComparator)
2669 throws NoSuchThreadException {
2670 MBThread mbThread = fetchByG_C_First(groupId, categoryId,
2671 orderByComparator);
2672
2673 if (mbThread != null) {
2674 return mbThread;
2675 }
2676
2677 StringBundler msg = new StringBundler(6);
2678
2679 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2680
2681 msg.append("groupId=");
2682 msg.append(groupId);
2683
2684 msg.append(", categoryId=");
2685 msg.append(categoryId);
2686
2687 msg.append(StringPool.CLOSE_CURLY_BRACE);
2688
2689 throw new NoSuchThreadException(msg.toString());
2690 }
2691
2692
2700 @Override
2701 public MBThread fetchByG_C_First(long groupId, long categoryId,
2702 OrderByComparator<MBThread> orderByComparator) {
2703 List<MBThread> list = findByG_C(groupId, categoryId, 0, 1,
2704 orderByComparator);
2705
2706 if (!list.isEmpty()) {
2707 return list.get(0);
2708 }
2709
2710 return null;
2711 }
2712
2713
2722 @Override
2723 public MBThread findByG_C_Last(long groupId, long categoryId,
2724 OrderByComparator<MBThread> orderByComparator)
2725 throws NoSuchThreadException {
2726 MBThread mbThread = fetchByG_C_Last(groupId, categoryId,
2727 orderByComparator);
2728
2729 if (mbThread != null) {
2730 return mbThread;
2731 }
2732
2733 StringBundler msg = new StringBundler(6);
2734
2735 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2736
2737 msg.append("groupId=");
2738 msg.append(groupId);
2739
2740 msg.append(", categoryId=");
2741 msg.append(categoryId);
2742
2743 msg.append(StringPool.CLOSE_CURLY_BRACE);
2744
2745 throw new NoSuchThreadException(msg.toString());
2746 }
2747
2748
2756 @Override
2757 public MBThread fetchByG_C_Last(long groupId, long categoryId,
2758 OrderByComparator<MBThread> orderByComparator) {
2759 int count = countByG_C(groupId, categoryId);
2760
2761 if (count == 0) {
2762 return null;
2763 }
2764
2765 List<MBThread> list = findByG_C(groupId, categoryId, count - 1, count,
2766 orderByComparator);
2767
2768 if (!list.isEmpty()) {
2769 return list.get(0);
2770 }
2771
2772 return null;
2773 }
2774
2775
2785 @Override
2786 public MBThread[] findByG_C_PrevAndNext(long threadId, long groupId,
2787 long categoryId, OrderByComparator<MBThread> orderByComparator)
2788 throws NoSuchThreadException {
2789 MBThread mbThread = findByPrimaryKey(threadId);
2790
2791 Session session = null;
2792
2793 try {
2794 session = openSession();
2795
2796 MBThread[] array = new MBThreadImpl[3];
2797
2798 array[0] = getByG_C_PrevAndNext(session, mbThread, groupId,
2799 categoryId, orderByComparator, true);
2800
2801 array[1] = mbThread;
2802
2803 array[2] = getByG_C_PrevAndNext(session, mbThread, groupId,
2804 categoryId, orderByComparator, false);
2805
2806 return array;
2807 }
2808 catch (Exception e) {
2809 throw processException(e);
2810 }
2811 finally {
2812 closeSession(session);
2813 }
2814 }
2815
2816 protected MBThread getByG_C_PrevAndNext(Session session, MBThread mbThread,
2817 long groupId, long categoryId,
2818 OrderByComparator<MBThread> orderByComparator, boolean previous) {
2819 StringBundler query = null;
2820
2821 if (orderByComparator != null) {
2822 query = new StringBundler(6 +
2823 (orderByComparator.getOrderByFields().length * 6));
2824 }
2825 else {
2826 query = new StringBundler(3);
2827 }
2828
2829 query.append(_SQL_SELECT_MBTHREAD_WHERE);
2830
2831 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2832
2833 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2834
2835 if (orderByComparator != null) {
2836 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2837
2838 if (orderByConditionFields.length > 0) {
2839 query.append(WHERE_AND);
2840 }
2841
2842 for (int i = 0; i < orderByConditionFields.length; i++) {
2843 query.append(_ORDER_BY_ENTITY_ALIAS);
2844 query.append(orderByConditionFields[i]);
2845
2846 if ((i + 1) < orderByConditionFields.length) {
2847 if (orderByComparator.isAscending() ^ previous) {
2848 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2849 }
2850 else {
2851 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2852 }
2853 }
2854 else {
2855 if (orderByComparator.isAscending() ^ previous) {
2856 query.append(WHERE_GREATER_THAN);
2857 }
2858 else {
2859 query.append(WHERE_LESSER_THAN);
2860 }
2861 }
2862 }
2863
2864 query.append(ORDER_BY_CLAUSE);
2865
2866 String[] orderByFields = orderByComparator.getOrderByFields();
2867
2868 for (int i = 0; i < orderByFields.length; i++) {
2869 query.append(_ORDER_BY_ENTITY_ALIAS);
2870 query.append(orderByFields[i]);
2871
2872 if ((i + 1) < orderByFields.length) {
2873 if (orderByComparator.isAscending() ^ previous) {
2874 query.append(ORDER_BY_ASC_HAS_NEXT);
2875 }
2876 else {
2877 query.append(ORDER_BY_DESC_HAS_NEXT);
2878 }
2879 }
2880 else {
2881 if (orderByComparator.isAscending() ^ previous) {
2882 query.append(ORDER_BY_ASC);
2883 }
2884 else {
2885 query.append(ORDER_BY_DESC);
2886 }
2887 }
2888 }
2889 }
2890 else {
2891 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
2892 }
2893
2894 String sql = query.toString();
2895
2896 Query q = session.createQuery(sql);
2897
2898 q.setFirstResult(0);
2899 q.setMaxResults(2);
2900
2901 QueryPos qPos = QueryPos.getInstance(q);
2902
2903 qPos.add(groupId);
2904
2905 qPos.add(categoryId);
2906
2907 if (orderByComparator != null) {
2908 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
2909
2910 for (Object value : values) {
2911 qPos.add(value);
2912 }
2913 }
2914
2915 List<MBThread> list = q.list();
2916
2917 if (list.size() == 2) {
2918 return list.get(1);
2919 }
2920 else {
2921 return null;
2922 }
2923 }
2924
2925
2932 @Override
2933 public List<MBThread> filterFindByG_C(long groupId, long categoryId) {
2934 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
2935 QueryUtil.ALL_POS, null);
2936 }
2937
2938
2951 @Override
2952 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2953 int start, int end) {
2954 return filterFindByG_C(groupId, categoryId, start, end, null);
2955 }
2956
2957
2971 @Override
2972 public List<MBThread> filterFindByG_C(long groupId, long categoryId,
2973 int start, int end, OrderByComparator<MBThread> orderByComparator) {
2974 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2975 return findByG_C(groupId, categoryId, start, end, orderByComparator);
2976 }
2977
2978 StringBundler query = null;
2979
2980 if (orderByComparator != null) {
2981 query = new StringBundler(4 +
2982 (orderByComparator.getOrderByFields().length * 3));
2983 }
2984 else {
2985 query = new StringBundler(4);
2986 }
2987
2988 if (getDB().isSupportsInlineDistinct()) {
2989 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
2990 }
2991 else {
2992 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
2993 }
2994
2995 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2996
2997 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2998
2999 if (!getDB().isSupportsInlineDistinct()) {
3000 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3001 }
3002
3003 if (orderByComparator != null) {
3004 if (getDB().isSupportsInlineDistinct()) {
3005 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3006 orderByComparator, true);
3007 }
3008 else {
3009 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3010 orderByComparator, true);
3011 }
3012 }
3013 else {
3014 if (getDB().isSupportsInlineDistinct()) {
3015 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3016 }
3017 else {
3018 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3019 }
3020 }
3021
3022 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3023 MBThread.class.getName(),
3024 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3025
3026 Session session = null;
3027
3028 try {
3029 session = openSession();
3030
3031 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3032
3033 if (getDB().isSupportsInlineDistinct()) {
3034 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3035 }
3036 else {
3037 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3038 }
3039
3040 QueryPos qPos = QueryPos.getInstance(q);
3041
3042 qPos.add(groupId);
3043
3044 qPos.add(categoryId);
3045
3046 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3047 }
3048 catch (Exception e) {
3049 throw processException(e);
3050 }
3051 finally {
3052 closeSession(session);
3053 }
3054 }
3055
3056
3066 @Override
3067 public MBThread[] filterFindByG_C_PrevAndNext(long threadId, long groupId,
3068 long categoryId, OrderByComparator<MBThread> orderByComparator)
3069 throws NoSuchThreadException {
3070 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3071 return findByG_C_PrevAndNext(threadId, groupId, categoryId,
3072 orderByComparator);
3073 }
3074
3075 MBThread mbThread = findByPrimaryKey(threadId);
3076
3077 Session session = null;
3078
3079 try {
3080 session = openSession();
3081
3082 MBThread[] array = new MBThreadImpl[3];
3083
3084 array[0] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3085 categoryId, orderByComparator, true);
3086
3087 array[1] = mbThread;
3088
3089 array[2] = filterGetByG_C_PrevAndNext(session, mbThread, groupId,
3090 categoryId, orderByComparator, false);
3091
3092 return array;
3093 }
3094 catch (Exception e) {
3095 throw processException(e);
3096 }
3097 finally {
3098 closeSession(session);
3099 }
3100 }
3101
3102 protected MBThread filterGetByG_C_PrevAndNext(Session session,
3103 MBThread mbThread, long groupId, long categoryId,
3104 OrderByComparator<MBThread> orderByComparator, boolean previous) {
3105 StringBundler query = null;
3106
3107 if (orderByComparator != null) {
3108 query = new StringBundler(6 +
3109 (orderByComparator.getOrderByFields().length * 6));
3110 }
3111 else {
3112 query = new StringBundler(3);
3113 }
3114
3115 if (getDB().isSupportsInlineDistinct()) {
3116 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3117 }
3118 else {
3119 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3120 }
3121
3122 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3123
3124 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3125
3126 if (!getDB().isSupportsInlineDistinct()) {
3127 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3128 }
3129
3130 if (orderByComparator != null) {
3131 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3132
3133 if (orderByConditionFields.length > 0) {
3134 query.append(WHERE_AND);
3135 }
3136
3137 for (int i = 0; i < orderByConditionFields.length; i++) {
3138 if (getDB().isSupportsInlineDistinct()) {
3139 query.append(_ORDER_BY_ENTITY_ALIAS);
3140 }
3141 else {
3142 query.append(_ORDER_BY_ENTITY_TABLE);
3143 }
3144
3145 query.append(orderByConditionFields[i]);
3146
3147 if ((i + 1) < orderByConditionFields.length) {
3148 if (orderByComparator.isAscending() ^ previous) {
3149 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3150 }
3151 else {
3152 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3153 }
3154 }
3155 else {
3156 if (orderByComparator.isAscending() ^ previous) {
3157 query.append(WHERE_GREATER_THAN);
3158 }
3159 else {
3160 query.append(WHERE_LESSER_THAN);
3161 }
3162 }
3163 }
3164
3165 query.append(ORDER_BY_CLAUSE);
3166
3167 String[] orderByFields = orderByComparator.getOrderByFields();
3168
3169 for (int i = 0; i < orderByFields.length; i++) {
3170 if (getDB().isSupportsInlineDistinct()) {
3171 query.append(_ORDER_BY_ENTITY_ALIAS);
3172 }
3173 else {
3174 query.append(_ORDER_BY_ENTITY_TABLE);
3175 }
3176
3177 query.append(orderByFields[i]);
3178
3179 if ((i + 1) < orderByFields.length) {
3180 if (orderByComparator.isAscending() ^ previous) {
3181 query.append(ORDER_BY_ASC_HAS_NEXT);
3182 }
3183 else {
3184 query.append(ORDER_BY_DESC_HAS_NEXT);
3185 }
3186 }
3187 else {
3188 if (orderByComparator.isAscending() ^ previous) {
3189 query.append(ORDER_BY_ASC);
3190 }
3191 else {
3192 query.append(ORDER_BY_DESC);
3193 }
3194 }
3195 }
3196 }
3197 else {
3198 if (getDB().isSupportsInlineDistinct()) {
3199 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3200 }
3201 else {
3202 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3203 }
3204 }
3205
3206 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3207 MBThread.class.getName(),
3208 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3209
3210 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3211
3212 q.setFirstResult(0);
3213 q.setMaxResults(2);
3214
3215 if (getDB().isSupportsInlineDistinct()) {
3216 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3217 }
3218 else {
3219 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3220 }
3221
3222 QueryPos qPos = QueryPos.getInstance(q);
3223
3224 qPos.add(groupId);
3225
3226 qPos.add(categoryId);
3227
3228 if (orderByComparator != null) {
3229 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
3230
3231 for (Object value : values) {
3232 qPos.add(value);
3233 }
3234 }
3235
3236 List<MBThread> list = q.list();
3237
3238 if (list.size() == 2) {
3239 return list.get(1);
3240 }
3241 else {
3242 return null;
3243 }
3244 }
3245
3246
3253 @Override
3254 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds) {
3255 return filterFindByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3256 QueryUtil.ALL_POS, null);
3257 }
3258
3259
3272 @Override
3273 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3274 int start, int end) {
3275 return filterFindByG_C(groupId, categoryIds, start, end, null);
3276 }
3277
3278
3292 @Override
3293 public List<MBThread> filterFindByG_C(long groupId, long[] categoryIds,
3294 int start, int end, OrderByComparator<MBThread> orderByComparator) {
3295 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3296 return findByG_C(groupId, categoryIds, start, end, orderByComparator);
3297 }
3298
3299 if (categoryIds == null) {
3300 categoryIds = new long[0];
3301 }
3302 else {
3303 categoryIds = ArrayUtil.unique(categoryIds);
3304 }
3305
3306 StringBundler query = new StringBundler();
3307
3308 if (getDB().isSupportsInlineDistinct()) {
3309 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
3310 }
3311 else {
3312 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
3313 }
3314
3315 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3316
3317 if (categoryIds.length > 0) {
3318 query.append(StringPool.OPEN_PARENTHESIS);
3319
3320 query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3321
3322 query.append(StringUtil.merge(categoryIds));
3323
3324 query.append(StringPool.CLOSE_PARENTHESIS);
3325
3326 query.append(StringPool.CLOSE_PARENTHESIS);
3327 }
3328
3329 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3330 query.index() - 1);
3331
3332 if (!getDB().isSupportsInlineDistinct()) {
3333 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
3334 }
3335
3336 if (orderByComparator != null) {
3337 if (getDB().isSupportsInlineDistinct()) {
3338 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3339 orderByComparator, true);
3340 }
3341 else {
3342 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3343 orderByComparator, true);
3344 }
3345 }
3346 else {
3347 if (getDB().isSupportsInlineDistinct()) {
3348 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3349 }
3350 else {
3351 query.append(MBThreadModelImpl.ORDER_BY_SQL);
3352 }
3353 }
3354
3355 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3356 MBThread.class.getName(),
3357 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3358
3359 Session session = null;
3360
3361 try {
3362 session = openSession();
3363
3364 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3365
3366 if (getDB().isSupportsInlineDistinct()) {
3367 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
3368 }
3369 else {
3370 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
3371 }
3372
3373 QueryPos qPos = QueryPos.getInstance(q);
3374
3375 qPos.add(groupId);
3376
3377 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
3378 }
3379 catch (Exception e) {
3380 throw processException(e);
3381 }
3382 finally {
3383 closeSession(session);
3384 }
3385 }
3386
3387
3398 @Override
3399 public List<MBThread> findByG_C(long groupId, long[] categoryIds) {
3400 return findByG_C(groupId, categoryIds, QueryUtil.ALL_POS,
3401 QueryUtil.ALL_POS, null);
3402 }
3403
3404
3417 @Override
3418 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3419 int start, int end) {
3420 return findByG_C(groupId, categoryIds, start, end, null);
3421 }
3422
3423
3437 @Override
3438 public List<MBThread> findByG_C(long groupId, long[] categoryIds,
3439 int start, int end, OrderByComparator<MBThread> orderByComparator) {
3440 if (categoryIds == null) {
3441 categoryIds = new long[0];
3442 }
3443 else {
3444 categoryIds = ArrayUtil.unique(categoryIds);
3445 }
3446
3447 if (categoryIds.length == 1) {
3448 return findByG_C(groupId, categoryIds[0], start, end,
3449 orderByComparator);
3450 }
3451
3452 boolean pagination = true;
3453 Object[] finderArgs = null;
3454
3455 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3456 (orderByComparator == null)) {
3457 pagination = false;
3458 finderArgs = new Object[] { groupId, StringUtil.merge(categoryIds) };
3459 }
3460 else {
3461 finderArgs = new Object[] {
3462 groupId, StringUtil.merge(categoryIds),
3463
3464 start, end, orderByComparator
3465 };
3466 }
3467
3468 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3469 finderArgs, this);
3470
3471 if ((list != null) && !list.isEmpty()) {
3472 for (MBThread mbThread : list) {
3473 if ((groupId != mbThread.getGroupId()) ||
3474 !ArrayUtil.contains(categoryIds,
3475 mbThread.getCategoryId())) {
3476 list = null;
3477
3478 break;
3479 }
3480 }
3481 }
3482
3483 if (list == null) {
3484 StringBundler query = new StringBundler();
3485
3486 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3487
3488 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3489
3490 if (categoryIds.length > 0) {
3491 query.append(StringPool.OPEN_PARENTHESIS);
3492
3493 query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3494
3495 query.append(StringUtil.merge(categoryIds));
3496
3497 query.append(StringPool.CLOSE_PARENTHESIS);
3498
3499 query.append(StringPool.CLOSE_PARENTHESIS);
3500 }
3501
3502 query.setStringAt(removeConjunction(query.stringAt(query.index() -
3503 1)), query.index() - 1);
3504
3505 if (orderByComparator != null) {
3506 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3507 orderByComparator);
3508 }
3509 else
3510 if (pagination) {
3511 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3512 }
3513
3514 String sql = query.toString();
3515
3516 Session session = null;
3517
3518 try {
3519 session = openSession();
3520
3521 Query q = session.createQuery(sql);
3522
3523 QueryPos qPos = QueryPos.getInstance(q);
3524
3525 qPos.add(groupId);
3526
3527 if (!pagination) {
3528 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3529 start, end, false);
3530
3531 Collections.sort(list);
3532
3533 list = Collections.unmodifiableList(list);
3534 }
3535 else {
3536 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3537 start, end);
3538 }
3539
3540 cacheResult(list);
3541
3542 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3543 finderArgs, list);
3544 }
3545 catch (Exception e) {
3546 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C,
3547 finderArgs);
3548
3549 throw processException(e);
3550 }
3551 finally {
3552 closeSession(session);
3553 }
3554 }
3555
3556 return list;
3557 }
3558
3559
3565 @Override
3566 public void removeByG_C(long groupId, long categoryId) {
3567 for (MBThread mbThread : findByG_C(groupId, categoryId,
3568 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3569 remove(mbThread);
3570 }
3571 }
3572
3573
3580 @Override
3581 public int countByG_C(long groupId, long categoryId) {
3582 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
3583
3584 Object[] finderArgs = new Object[] { groupId, categoryId };
3585
3586 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3587 this);
3588
3589 if (count == null) {
3590 StringBundler query = new StringBundler(3);
3591
3592 query.append(_SQL_COUNT_MBTHREAD_WHERE);
3593
3594 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3595
3596 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3597
3598 String sql = query.toString();
3599
3600 Session session = null;
3601
3602 try {
3603 session = openSession();
3604
3605 Query q = session.createQuery(sql);
3606
3607 QueryPos qPos = QueryPos.getInstance(q);
3608
3609 qPos.add(groupId);
3610
3611 qPos.add(categoryId);
3612
3613 count = (Long)q.uniqueResult();
3614
3615 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3616 }
3617 catch (Exception e) {
3618 FinderCacheUtil.removeResult(finderPath, finderArgs);
3619
3620 throw processException(e);
3621 }
3622 finally {
3623 closeSession(session);
3624 }
3625 }
3626
3627 return count.intValue();
3628 }
3629
3630
3637 @Override
3638 public int countByG_C(long groupId, long[] categoryIds) {
3639 if (categoryIds == null) {
3640 categoryIds = new long[0];
3641 }
3642 else {
3643 categoryIds = ArrayUtil.unique(categoryIds);
3644 }
3645
3646 Object[] finderArgs = new Object[] {
3647 groupId, StringUtil.merge(categoryIds)
3648 };
3649
3650 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3651 finderArgs, this);
3652
3653 if (count == null) {
3654 StringBundler query = new StringBundler();
3655
3656 query.append(_SQL_COUNT_MBTHREAD_WHERE);
3657
3658 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3659
3660 if (categoryIds.length > 0) {
3661 query.append(StringPool.OPEN_PARENTHESIS);
3662
3663 query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3664
3665 query.append(StringUtil.merge(categoryIds));
3666
3667 query.append(StringPool.CLOSE_PARENTHESIS);
3668
3669 query.append(StringPool.CLOSE_PARENTHESIS);
3670 }
3671
3672 query.setStringAt(removeConjunction(query.stringAt(query.index() -
3673 1)), query.index() - 1);
3674
3675 String sql = query.toString();
3676
3677 Session session = null;
3678
3679 try {
3680 session = openSession();
3681
3682 Query q = session.createQuery(sql);
3683
3684 QueryPos qPos = QueryPos.getInstance(q);
3685
3686 qPos.add(groupId);
3687
3688 count = (Long)q.uniqueResult();
3689
3690 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3691 finderArgs, count);
3692 }
3693 catch (Exception e) {
3694 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C,
3695 finderArgs);
3696
3697 throw processException(e);
3698 }
3699 finally {
3700 closeSession(session);
3701 }
3702 }
3703
3704 return count.intValue();
3705 }
3706
3707
3714 @Override
3715 public int filterCountByG_C(long groupId, long categoryId) {
3716 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3717 return countByG_C(groupId, categoryId);
3718 }
3719
3720 StringBundler query = new StringBundler(3);
3721
3722 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3723
3724 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3725
3726 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
3727
3728 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3729 MBThread.class.getName(),
3730 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3731
3732 Session session = null;
3733
3734 try {
3735 session = openSession();
3736
3737 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3738
3739 q.addScalar(COUNT_COLUMN_NAME,
3740 com.liferay.portal.kernel.dao.orm.Type.LONG);
3741
3742 QueryPos qPos = QueryPos.getInstance(q);
3743
3744 qPos.add(groupId);
3745
3746 qPos.add(categoryId);
3747
3748 Long count = (Long)q.uniqueResult();
3749
3750 return count.intValue();
3751 }
3752 catch (Exception e) {
3753 throw processException(e);
3754 }
3755 finally {
3756 closeSession(session);
3757 }
3758 }
3759
3760
3767 @Override
3768 public int filterCountByG_C(long groupId, long[] categoryIds) {
3769 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3770 return countByG_C(groupId, categoryIds);
3771 }
3772
3773 if (categoryIds == null) {
3774 categoryIds = new long[0];
3775 }
3776 else {
3777 categoryIds = ArrayUtil.unique(categoryIds);
3778 }
3779
3780 StringBundler query = new StringBundler();
3781
3782 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
3783
3784 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
3785
3786 if (categoryIds.length > 0) {
3787 query.append(StringPool.OPEN_PARENTHESIS);
3788
3789 query.append(_FINDER_COLUMN_G_C_CATEGORYID_7);
3790
3791 query.append(StringUtil.merge(categoryIds));
3792
3793 query.append(StringPool.CLOSE_PARENTHESIS);
3794
3795 query.append(StringPool.CLOSE_PARENTHESIS);
3796 }
3797
3798 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3799 query.index() - 1);
3800
3801 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3802 MBThread.class.getName(),
3803 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3804
3805 Session session = null;
3806
3807 try {
3808 session = openSession();
3809
3810 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3811
3812 q.addScalar(COUNT_COLUMN_NAME,
3813 com.liferay.portal.kernel.dao.orm.Type.LONG);
3814
3815 QueryPos qPos = QueryPos.getInstance(q);
3816
3817 qPos.add(groupId);
3818
3819 Long count = (Long)q.uniqueResult();
3820
3821 return count.intValue();
3822 }
3823 catch (Exception e) {
3824 throw processException(e);
3825 }
3826 finally {
3827 closeSession(session);
3828 }
3829 }
3830
3831 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbThread.groupId = ? AND ";
3832 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbThread.categoryId = ?";
3833 private static final String _FINDER_COLUMN_G_C_CATEGORYID_7 = "mbThread.categoryId IN (";
3834 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3835 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
3836 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC",
3837 new String[] {
3838 Long.class.getName(), Long.class.getName(),
3839
3840 Integer.class.getName(), Integer.class.getName(),
3841 OrderByComparator.class.getName()
3842 });
3843 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
3844 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
3845 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC",
3846 new String[] { Long.class.getName(), Long.class.getName() });
3847
3848
3855 @Override
3856 public List<MBThread> findByG_NotC(long groupId, long categoryId) {
3857 return findByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
3858 QueryUtil.ALL_POS, null);
3859 }
3860
3861
3874 @Override
3875 public List<MBThread> findByG_NotC(long groupId, long categoryId,
3876 int start, int end) {
3877 return findByG_NotC(groupId, categoryId, start, end, null);
3878 }
3879
3880
3894 @Override
3895 public List<MBThread> findByG_NotC(long groupId, long categoryId,
3896 int start, int end, OrderByComparator<MBThread> orderByComparator) {
3897 boolean pagination = true;
3898 FinderPath finderPath = null;
3899 Object[] finderArgs = null;
3900
3901 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC;
3902 finderArgs = new Object[] {
3903 groupId, categoryId,
3904
3905 start, end, orderByComparator
3906 };
3907
3908 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
3909 finderArgs, this);
3910
3911 if ((list != null) && !list.isEmpty()) {
3912 for (MBThread mbThread : list) {
3913 if ((groupId != mbThread.getGroupId()) ||
3914 (categoryId == mbThread.getCategoryId())) {
3915 list = null;
3916
3917 break;
3918 }
3919 }
3920 }
3921
3922 if (list == null) {
3923 StringBundler query = null;
3924
3925 if (orderByComparator != null) {
3926 query = new StringBundler(4 +
3927 (orderByComparator.getOrderByFields().length * 3));
3928 }
3929 else {
3930 query = new StringBundler(4);
3931 }
3932
3933 query.append(_SQL_SELECT_MBTHREAD_WHERE);
3934
3935 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
3936
3937 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
3938
3939 if (orderByComparator != null) {
3940 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3941 orderByComparator);
3942 }
3943 else
3944 if (pagination) {
3945 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
3946 }
3947
3948 String sql = query.toString();
3949
3950 Session session = null;
3951
3952 try {
3953 session = openSession();
3954
3955 Query q = session.createQuery(sql);
3956
3957 QueryPos qPos = QueryPos.getInstance(q);
3958
3959 qPos.add(groupId);
3960
3961 qPos.add(categoryId);
3962
3963 if (!pagination) {
3964 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3965 start, end, false);
3966
3967 Collections.sort(list);
3968
3969 list = Collections.unmodifiableList(list);
3970 }
3971 else {
3972 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
3973 start, end);
3974 }
3975
3976 cacheResult(list);
3977
3978 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3979 }
3980 catch (Exception e) {
3981 FinderCacheUtil.removeResult(finderPath, finderArgs);
3982
3983 throw processException(e);
3984 }
3985 finally {
3986 closeSession(session);
3987 }
3988 }
3989
3990 return list;
3991 }
3992
3993
4002 @Override
4003 public MBThread findByG_NotC_First(long groupId, long categoryId,
4004 OrderByComparator<MBThread> orderByComparator)
4005 throws NoSuchThreadException {
4006 MBThread mbThread = fetchByG_NotC_First(groupId, categoryId,
4007 orderByComparator);
4008
4009 if (mbThread != null) {
4010 return mbThread;
4011 }
4012
4013 StringBundler msg = new StringBundler(6);
4014
4015 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4016
4017 msg.append("groupId=");
4018 msg.append(groupId);
4019
4020 msg.append(", categoryId=");
4021 msg.append(categoryId);
4022
4023 msg.append(StringPool.CLOSE_CURLY_BRACE);
4024
4025 throw new NoSuchThreadException(msg.toString());
4026 }
4027
4028
4036 @Override
4037 public MBThread fetchByG_NotC_First(long groupId, long categoryId,
4038 OrderByComparator<MBThread> orderByComparator) {
4039 List<MBThread> list = findByG_NotC(groupId, categoryId, 0, 1,
4040 orderByComparator);
4041
4042 if (!list.isEmpty()) {
4043 return list.get(0);
4044 }
4045
4046 return null;
4047 }
4048
4049
4058 @Override
4059 public MBThread findByG_NotC_Last(long groupId, long categoryId,
4060 OrderByComparator<MBThread> orderByComparator)
4061 throws NoSuchThreadException {
4062 MBThread mbThread = fetchByG_NotC_Last(groupId, categoryId,
4063 orderByComparator);
4064
4065 if (mbThread != null) {
4066 return mbThread;
4067 }
4068
4069 StringBundler msg = new StringBundler(6);
4070
4071 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4072
4073 msg.append("groupId=");
4074 msg.append(groupId);
4075
4076 msg.append(", categoryId=");
4077 msg.append(categoryId);
4078
4079 msg.append(StringPool.CLOSE_CURLY_BRACE);
4080
4081 throw new NoSuchThreadException(msg.toString());
4082 }
4083
4084
4092 @Override
4093 public MBThread fetchByG_NotC_Last(long groupId, long categoryId,
4094 OrderByComparator<MBThread> orderByComparator) {
4095 int count = countByG_NotC(groupId, categoryId);
4096
4097 if (count == 0) {
4098 return null;
4099 }
4100
4101 List<MBThread> list = findByG_NotC(groupId, categoryId, count - 1,
4102 count, orderByComparator);
4103
4104 if (!list.isEmpty()) {
4105 return list.get(0);
4106 }
4107
4108 return null;
4109 }
4110
4111
4121 @Override
4122 public MBThread[] findByG_NotC_PrevAndNext(long threadId, long groupId,
4123 long categoryId, OrderByComparator<MBThread> orderByComparator)
4124 throws NoSuchThreadException {
4125 MBThread mbThread = findByPrimaryKey(threadId);
4126
4127 Session session = null;
4128
4129 try {
4130 session = openSession();
4131
4132 MBThread[] array = new MBThreadImpl[3];
4133
4134 array[0] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4135 categoryId, orderByComparator, true);
4136
4137 array[1] = mbThread;
4138
4139 array[2] = getByG_NotC_PrevAndNext(session, mbThread, groupId,
4140 categoryId, orderByComparator, false);
4141
4142 return array;
4143 }
4144 catch (Exception e) {
4145 throw processException(e);
4146 }
4147 finally {
4148 closeSession(session);
4149 }
4150 }
4151
4152 protected MBThread getByG_NotC_PrevAndNext(Session session,
4153 MBThread mbThread, long groupId, long categoryId,
4154 OrderByComparator<MBThread> orderByComparator, boolean previous) {
4155 StringBundler query = null;
4156
4157 if (orderByComparator != null) {
4158 query = new StringBundler(6 +
4159 (orderByComparator.getOrderByFields().length * 6));
4160 }
4161 else {
4162 query = new StringBundler(3);
4163 }
4164
4165 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4166
4167 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4168
4169 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4170
4171 if (orderByComparator != null) {
4172 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4173
4174 if (orderByConditionFields.length > 0) {
4175 query.append(WHERE_AND);
4176 }
4177
4178 for (int i = 0; i < orderByConditionFields.length; i++) {
4179 query.append(_ORDER_BY_ENTITY_ALIAS);
4180 query.append(orderByConditionFields[i]);
4181
4182 if ((i + 1) < orderByConditionFields.length) {
4183 if (orderByComparator.isAscending() ^ previous) {
4184 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4185 }
4186 else {
4187 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4188 }
4189 }
4190 else {
4191 if (orderByComparator.isAscending() ^ previous) {
4192 query.append(WHERE_GREATER_THAN);
4193 }
4194 else {
4195 query.append(WHERE_LESSER_THAN);
4196 }
4197 }
4198 }
4199
4200 query.append(ORDER_BY_CLAUSE);
4201
4202 String[] orderByFields = orderByComparator.getOrderByFields();
4203
4204 for (int i = 0; i < orderByFields.length; i++) {
4205 query.append(_ORDER_BY_ENTITY_ALIAS);
4206 query.append(orderByFields[i]);
4207
4208 if ((i + 1) < orderByFields.length) {
4209 if (orderByComparator.isAscending() ^ previous) {
4210 query.append(ORDER_BY_ASC_HAS_NEXT);
4211 }
4212 else {
4213 query.append(ORDER_BY_DESC_HAS_NEXT);
4214 }
4215 }
4216 else {
4217 if (orderByComparator.isAscending() ^ previous) {
4218 query.append(ORDER_BY_ASC);
4219 }
4220 else {
4221 query.append(ORDER_BY_DESC);
4222 }
4223 }
4224 }
4225 }
4226 else {
4227 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4228 }
4229
4230 String sql = query.toString();
4231
4232 Query q = session.createQuery(sql);
4233
4234 q.setFirstResult(0);
4235 q.setMaxResults(2);
4236
4237 QueryPos qPos = QueryPos.getInstance(q);
4238
4239 qPos.add(groupId);
4240
4241 qPos.add(categoryId);
4242
4243 if (orderByComparator != null) {
4244 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4245
4246 for (Object value : values) {
4247 qPos.add(value);
4248 }
4249 }
4250
4251 List<MBThread> list = q.list();
4252
4253 if (list.size() == 2) {
4254 return list.get(1);
4255 }
4256 else {
4257 return null;
4258 }
4259 }
4260
4261
4268 @Override
4269 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId) {
4270 return filterFindByG_NotC(groupId, categoryId, QueryUtil.ALL_POS,
4271 QueryUtil.ALL_POS, null);
4272 }
4273
4274
4287 @Override
4288 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4289 int start, int end) {
4290 return filterFindByG_NotC(groupId, categoryId, start, end, null);
4291 }
4292
4293
4307 @Override
4308 public List<MBThread> filterFindByG_NotC(long groupId, long categoryId,
4309 int start, int end, OrderByComparator<MBThread> orderByComparator) {
4310 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4311 return findByG_NotC(groupId, categoryId, start, end,
4312 orderByComparator);
4313 }
4314
4315 StringBundler query = null;
4316
4317 if (orderByComparator != null) {
4318 query = new StringBundler(4 +
4319 (orderByComparator.getOrderByFields().length * 3));
4320 }
4321 else {
4322 query = new StringBundler(4);
4323 }
4324
4325 if (getDB().isSupportsInlineDistinct()) {
4326 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4327 }
4328 else {
4329 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4330 }
4331
4332 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4333
4334 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4335
4336 if (!getDB().isSupportsInlineDistinct()) {
4337 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4338 }
4339
4340 if (orderByComparator != null) {
4341 if (getDB().isSupportsInlineDistinct()) {
4342 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4343 orderByComparator, true);
4344 }
4345 else {
4346 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4347 orderByComparator, true);
4348 }
4349 }
4350 else {
4351 if (getDB().isSupportsInlineDistinct()) {
4352 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4353 }
4354 else {
4355 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4356 }
4357 }
4358
4359 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4360 MBThread.class.getName(),
4361 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4362
4363 Session session = null;
4364
4365 try {
4366 session = openSession();
4367
4368 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4369
4370 if (getDB().isSupportsInlineDistinct()) {
4371 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4372 }
4373 else {
4374 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4375 }
4376
4377 QueryPos qPos = QueryPos.getInstance(q);
4378
4379 qPos.add(groupId);
4380
4381 qPos.add(categoryId);
4382
4383 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
4384 }
4385 catch (Exception e) {
4386 throw processException(e);
4387 }
4388 finally {
4389 closeSession(session);
4390 }
4391 }
4392
4393
4403 @Override
4404 public MBThread[] filterFindByG_NotC_PrevAndNext(long threadId,
4405 long groupId, long categoryId,
4406 OrderByComparator<MBThread> orderByComparator)
4407 throws NoSuchThreadException {
4408 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4409 return findByG_NotC_PrevAndNext(threadId, groupId, categoryId,
4410 orderByComparator);
4411 }
4412
4413 MBThread mbThread = findByPrimaryKey(threadId);
4414
4415 Session session = null;
4416
4417 try {
4418 session = openSession();
4419
4420 MBThread[] array = new MBThreadImpl[3];
4421
4422 array[0] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4423 groupId, categoryId, orderByComparator, true);
4424
4425 array[1] = mbThread;
4426
4427 array[2] = filterGetByG_NotC_PrevAndNext(session, mbThread,
4428 groupId, categoryId, orderByComparator, false);
4429
4430 return array;
4431 }
4432 catch (Exception e) {
4433 throw processException(e);
4434 }
4435 finally {
4436 closeSession(session);
4437 }
4438 }
4439
4440 protected MBThread filterGetByG_NotC_PrevAndNext(Session session,
4441 MBThread mbThread, long groupId, long categoryId,
4442 OrderByComparator<MBThread> orderByComparator, boolean previous) {
4443 StringBundler query = null;
4444
4445 if (orderByComparator != null) {
4446 query = new StringBundler(6 +
4447 (orderByComparator.getOrderByFields().length * 6));
4448 }
4449 else {
4450 query = new StringBundler(3);
4451 }
4452
4453 if (getDB().isSupportsInlineDistinct()) {
4454 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
4455 }
4456 else {
4457 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
4458 }
4459
4460 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4461
4462 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4463
4464 if (!getDB().isSupportsInlineDistinct()) {
4465 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
4466 }
4467
4468 if (orderByComparator != null) {
4469 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4470
4471 if (orderByConditionFields.length > 0) {
4472 query.append(WHERE_AND);
4473 }
4474
4475 for (int i = 0; i < orderByConditionFields.length; i++) {
4476 if (getDB().isSupportsInlineDistinct()) {
4477 query.append(_ORDER_BY_ENTITY_ALIAS);
4478 }
4479 else {
4480 query.append(_ORDER_BY_ENTITY_TABLE);
4481 }
4482
4483 query.append(orderByConditionFields[i]);
4484
4485 if ((i + 1) < orderByConditionFields.length) {
4486 if (orderByComparator.isAscending() ^ previous) {
4487 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4488 }
4489 else {
4490 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4491 }
4492 }
4493 else {
4494 if (orderByComparator.isAscending() ^ previous) {
4495 query.append(WHERE_GREATER_THAN);
4496 }
4497 else {
4498 query.append(WHERE_LESSER_THAN);
4499 }
4500 }
4501 }
4502
4503 query.append(ORDER_BY_CLAUSE);
4504
4505 String[] orderByFields = orderByComparator.getOrderByFields();
4506
4507 for (int i = 0; i < orderByFields.length; i++) {
4508 if (getDB().isSupportsInlineDistinct()) {
4509 query.append(_ORDER_BY_ENTITY_ALIAS);
4510 }
4511 else {
4512 query.append(_ORDER_BY_ENTITY_TABLE);
4513 }
4514
4515 query.append(orderByFields[i]);
4516
4517 if ((i + 1) < orderByFields.length) {
4518 if (orderByComparator.isAscending() ^ previous) {
4519 query.append(ORDER_BY_ASC_HAS_NEXT);
4520 }
4521 else {
4522 query.append(ORDER_BY_DESC_HAS_NEXT);
4523 }
4524 }
4525 else {
4526 if (orderByComparator.isAscending() ^ previous) {
4527 query.append(ORDER_BY_ASC);
4528 }
4529 else {
4530 query.append(ORDER_BY_DESC);
4531 }
4532 }
4533 }
4534 }
4535 else {
4536 if (getDB().isSupportsInlineDistinct()) {
4537 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4538 }
4539 else {
4540 query.append(MBThreadModelImpl.ORDER_BY_SQL);
4541 }
4542 }
4543
4544 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4545 MBThread.class.getName(),
4546 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4547
4548 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4549
4550 q.setFirstResult(0);
4551 q.setMaxResults(2);
4552
4553 if (getDB().isSupportsInlineDistinct()) {
4554 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
4555 }
4556 else {
4557 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
4558 }
4559
4560 QueryPos qPos = QueryPos.getInstance(q);
4561
4562 qPos.add(groupId);
4563
4564 qPos.add(categoryId);
4565
4566 if (orderByComparator != null) {
4567 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
4568
4569 for (Object value : values) {
4570 qPos.add(value);
4571 }
4572 }
4573
4574 List<MBThread> list = q.list();
4575
4576 if (list.size() == 2) {
4577 return list.get(1);
4578 }
4579 else {
4580 return null;
4581 }
4582 }
4583
4584
4590 @Override
4591 public void removeByG_NotC(long groupId, long categoryId) {
4592 for (MBThread mbThread : findByG_NotC(groupId, categoryId,
4593 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4594 remove(mbThread);
4595 }
4596 }
4597
4598
4605 @Override
4606 public int countByG_NotC(long groupId, long categoryId) {
4607 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC;
4608
4609 Object[] finderArgs = new Object[] { groupId, categoryId };
4610
4611 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4612 this);
4613
4614 if (count == null) {
4615 StringBundler query = new StringBundler(3);
4616
4617 query.append(_SQL_COUNT_MBTHREAD_WHERE);
4618
4619 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4620
4621 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4622
4623 String sql = query.toString();
4624
4625 Session session = null;
4626
4627 try {
4628 session = openSession();
4629
4630 Query q = session.createQuery(sql);
4631
4632 QueryPos qPos = QueryPos.getInstance(q);
4633
4634 qPos.add(groupId);
4635
4636 qPos.add(categoryId);
4637
4638 count = (Long)q.uniqueResult();
4639
4640 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4641 }
4642 catch (Exception e) {
4643 FinderCacheUtil.removeResult(finderPath, finderArgs);
4644
4645 throw processException(e);
4646 }
4647 finally {
4648 closeSession(session);
4649 }
4650 }
4651
4652 return count.intValue();
4653 }
4654
4655
4662 @Override
4663 public int filterCountByG_NotC(long groupId, long categoryId) {
4664 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4665 return countByG_NotC(groupId, categoryId);
4666 }
4667
4668 StringBundler query = new StringBundler(3);
4669
4670 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
4671
4672 query.append(_FINDER_COLUMN_G_NOTC_GROUPID_2);
4673
4674 query.append(_FINDER_COLUMN_G_NOTC_CATEGORYID_2);
4675
4676 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4677 MBThread.class.getName(),
4678 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4679
4680 Session session = null;
4681
4682 try {
4683 session = openSession();
4684
4685 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4686
4687 q.addScalar(COUNT_COLUMN_NAME,
4688 com.liferay.portal.kernel.dao.orm.Type.LONG);
4689
4690 QueryPos qPos = QueryPos.getInstance(q);
4691
4692 qPos.add(groupId);
4693
4694 qPos.add(categoryId);
4695
4696 Long count = (Long)q.uniqueResult();
4697
4698 return count.intValue();
4699 }
4700 catch (Exception e) {
4701 throw processException(e);
4702 }
4703 finally {
4704 closeSession(session);
4705 }
4706 }
4707
4708 private static final String _FINDER_COLUMN_G_NOTC_GROUPID_2 = "mbThread.groupId = ? AND ";
4709 private static final String _FINDER_COLUMN_G_NOTC_CATEGORYID_2 = "mbThread.categoryId != ?";
4710 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4711 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4712 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4713 new String[] {
4714 Long.class.getName(), Integer.class.getName(),
4715
4716 Integer.class.getName(), Integer.class.getName(),
4717 OrderByComparator.class.getName()
4718 });
4719 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4720 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
4721 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4722 new String[] { Long.class.getName(), Integer.class.getName() },
4723 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
4724 MBThreadModelImpl.STATUS_COLUMN_BITMASK |
4725 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
4726 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
4727 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
4728 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
4729 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4730 new String[] { Long.class.getName(), Integer.class.getName() });
4731
4732
4739 @Override
4740 public List<MBThread> findByG_S(long groupId, int status) {
4741 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4742 null);
4743 }
4744
4745
4758 @Override
4759 public List<MBThread> findByG_S(long groupId, int status, int start, int end) {
4760 return findByG_S(groupId, status, start, end, null);
4761 }
4762
4763
4777 @Override
4778 public List<MBThread> findByG_S(long groupId, int status, int start,
4779 int end, OrderByComparator<MBThread> orderByComparator) {
4780 boolean pagination = true;
4781 FinderPath finderPath = null;
4782 Object[] finderArgs = null;
4783
4784 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4785 (orderByComparator == null)) {
4786 pagination = false;
4787 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4788 finderArgs = new Object[] { groupId, status };
4789 }
4790 else {
4791 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4792 finderArgs = new Object[] {
4793 groupId, status,
4794
4795 start, end, orderByComparator
4796 };
4797 }
4798
4799 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
4800 finderArgs, this);
4801
4802 if ((list != null) && !list.isEmpty()) {
4803 for (MBThread mbThread : list) {
4804 if ((groupId != mbThread.getGroupId()) ||
4805 (status != mbThread.getStatus())) {
4806 list = null;
4807
4808 break;
4809 }
4810 }
4811 }
4812
4813 if (list == null) {
4814 StringBundler query = null;
4815
4816 if (orderByComparator != null) {
4817 query = new StringBundler(4 +
4818 (orderByComparator.getOrderByFields().length * 3));
4819 }
4820 else {
4821 query = new StringBundler(4);
4822 }
4823
4824 query.append(_SQL_SELECT_MBTHREAD_WHERE);
4825
4826 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4827
4828 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4829
4830 if (orderByComparator != null) {
4831 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4832 orderByComparator);
4833 }
4834 else
4835 if (pagination) {
4836 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
4837 }
4838
4839 String sql = query.toString();
4840
4841 Session session = null;
4842
4843 try {
4844 session = openSession();
4845
4846 Query q = session.createQuery(sql);
4847
4848 QueryPos qPos = QueryPos.getInstance(q);
4849
4850 qPos.add(groupId);
4851
4852 qPos.add(status);
4853
4854 if (!pagination) {
4855 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4856 start, end, false);
4857
4858 Collections.sort(list);
4859
4860 list = Collections.unmodifiableList(list);
4861 }
4862 else {
4863 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
4864 start, end);
4865 }
4866
4867 cacheResult(list);
4868
4869 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4870 }
4871 catch (Exception e) {
4872 FinderCacheUtil.removeResult(finderPath, finderArgs);
4873
4874 throw processException(e);
4875 }
4876 finally {
4877 closeSession(session);
4878 }
4879 }
4880
4881 return list;
4882 }
4883
4884
4893 @Override
4894 public MBThread findByG_S_First(long groupId, int status,
4895 OrderByComparator<MBThread> orderByComparator)
4896 throws NoSuchThreadException {
4897 MBThread mbThread = fetchByG_S_First(groupId, status, orderByComparator);
4898
4899 if (mbThread != null) {
4900 return mbThread;
4901 }
4902
4903 StringBundler msg = new StringBundler(6);
4904
4905 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4906
4907 msg.append("groupId=");
4908 msg.append(groupId);
4909
4910 msg.append(", status=");
4911 msg.append(status);
4912
4913 msg.append(StringPool.CLOSE_CURLY_BRACE);
4914
4915 throw new NoSuchThreadException(msg.toString());
4916 }
4917
4918
4926 @Override
4927 public MBThread fetchByG_S_First(long groupId, int status,
4928 OrderByComparator<MBThread> orderByComparator) {
4929 List<MBThread> list = findByG_S(groupId, status, 0, 1, orderByComparator);
4930
4931 if (!list.isEmpty()) {
4932 return list.get(0);
4933 }
4934
4935 return null;
4936 }
4937
4938
4947 @Override
4948 public MBThread findByG_S_Last(long groupId, int status,
4949 OrderByComparator<MBThread> orderByComparator)
4950 throws NoSuchThreadException {
4951 MBThread mbThread = fetchByG_S_Last(groupId, status, orderByComparator);
4952
4953 if (mbThread != null) {
4954 return mbThread;
4955 }
4956
4957 StringBundler msg = new StringBundler(6);
4958
4959 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4960
4961 msg.append("groupId=");
4962 msg.append(groupId);
4963
4964 msg.append(", status=");
4965 msg.append(status);
4966
4967 msg.append(StringPool.CLOSE_CURLY_BRACE);
4968
4969 throw new NoSuchThreadException(msg.toString());
4970 }
4971
4972
4980 @Override
4981 public MBThread fetchByG_S_Last(long groupId, int status,
4982 OrderByComparator<MBThread> orderByComparator) {
4983 int count = countByG_S(groupId, status);
4984
4985 if (count == 0) {
4986 return null;
4987 }
4988
4989 List<MBThread> list = findByG_S(groupId, status, count - 1, count,
4990 orderByComparator);
4991
4992 if (!list.isEmpty()) {
4993 return list.get(0);
4994 }
4995
4996 return null;
4997 }
4998
4999
5009 @Override
5010 public MBThread[] findByG_S_PrevAndNext(long threadId, long groupId,
5011 int status, OrderByComparator<MBThread> orderByComparator)
5012 throws NoSuchThreadException {
5013 MBThread mbThread = findByPrimaryKey(threadId);
5014
5015 Session session = null;
5016
5017 try {
5018 session = openSession();
5019
5020 MBThread[] array = new MBThreadImpl[3];
5021
5022 array[0] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5023 orderByComparator, true);
5024
5025 array[1] = mbThread;
5026
5027 array[2] = getByG_S_PrevAndNext(session, mbThread, groupId, status,
5028 orderByComparator, false);
5029
5030 return array;
5031 }
5032 catch (Exception e) {
5033 throw processException(e);
5034 }
5035 finally {
5036 closeSession(session);
5037 }
5038 }
5039
5040 protected MBThread getByG_S_PrevAndNext(Session session, MBThread mbThread,
5041 long groupId, int status,
5042 OrderByComparator<MBThread> orderByComparator, boolean previous) {
5043 StringBundler query = null;
5044
5045 if (orderByComparator != null) {
5046 query = new StringBundler(6 +
5047 (orderByComparator.getOrderByFields().length * 6));
5048 }
5049 else {
5050 query = new StringBundler(3);
5051 }
5052
5053 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5054
5055 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5056
5057 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5058
5059 if (orderByComparator != null) {
5060 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5061
5062 if (orderByConditionFields.length > 0) {
5063 query.append(WHERE_AND);
5064 }
5065
5066 for (int i = 0; i < orderByConditionFields.length; i++) {
5067 query.append(_ORDER_BY_ENTITY_ALIAS);
5068 query.append(orderByConditionFields[i]);
5069
5070 if ((i + 1) < orderByConditionFields.length) {
5071 if (orderByComparator.isAscending() ^ previous) {
5072 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5073 }
5074 else {
5075 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5076 }
5077 }
5078 else {
5079 if (orderByComparator.isAscending() ^ previous) {
5080 query.append(WHERE_GREATER_THAN);
5081 }
5082 else {
5083 query.append(WHERE_LESSER_THAN);
5084 }
5085 }
5086 }
5087
5088 query.append(ORDER_BY_CLAUSE);
5089
5090 String[] orderByFields = orderByComparator.getOrderByFields();
5091
5092 for (int i = 0; i < orderByFields.length; i++) {
5093 query.append(_ORDER_BY_ENTITY_ALIAS);
5094 query.append(orderByFields[i]);
5095
5096 if ((i + 1) < orderByFields.length) {
5097 if (orderByComparator.isAscending() ^ previous) {
5098 query.append(ORDER_BY_ASC_HAS_NEXT);
5099 }
5100 else {
5101 query.append(ORDER_BY_DESC_HAS_NEXT);
5102 }
5103 }
5104 else {
5105 if (orderByComparator.isAscending() ^ previous) {
5106 query.append(ORDER_BY_ASC);
5107 }
5108 else {
5109 query.append(ORDER_BY_DESC);
5110 }
5111 }
5112 }
5113 }
5114 else {
5115 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5116 }
5117
5118 String sql = query.toString();
5119
5120 Query q = session.createQuery(sql);
5121
5122 q.setFirstResult(0);
5123 q.setMaxResults(2);
5124
5125 QueryPos qPos = QueryPos.getInstance(q);
5126
5127 qPos.add(groupId);
5128
5129 qPos.add(status);
5130
5131 if (orderByComparator != null) {
5132 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5133
5134 for (Object value : values) {
5135 qPos.add(value);
5136 }
5137 }
5138
5139 List<MBThread> list = q.list();
5140
5141 if (list.size() == 2) {
5142 return list.get(1);
5143 }
5144 else {
5145 return null;
5146 }
5147 }
5148
5149
5156 @Override
5157 public List<MBThread> filterFindByG_S(long groupId, int status) {
5158 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
5159 QueryUtil.ALL_POS, null);
5160 }
5161
5162
5175 @Override
5176 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5177 int end) {
5178 return filterFindByG_S(groupId, status, start, end, null);
5179 }
5180
5181
5195 @Override
5196 public List<MBThread> filterFindByG_S(long groupId, int status, int start,
5197 int end, OrderByComparator<MBThread> orderByComparator) {
5198 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5199 return findByG_S(groupId, status, start, end, orderByComparator);
5200 }
5201
5202 StringBundler query = null;
5203
5204 if (orderByComparator != null) {
5205 query = new StringBundler(4 +
5206 (orderByComparator.getOrderByFields().length * 3));
5207 }
5208 else {
5209 query = new StringBundler(4);
5210 }
5211
5212 if (getDB().isSupportsInlineDistinct()) {
5213 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5214 }
5215 else {
5216 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5217 }
5218
5219 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5220
5221 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5222
5223 if (!getDB().isSupportsInlineDistinct()) {
5224 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5225 }
5226
5227 if (orderByComparator != null) {
5228 if (getDB().isSupportsInlineDistinct()) {
5229 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5230 orderByComparator, true);
5231 }
5232 else {
5233 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5234 orderByComparator, true);
5235 }
5236 }
5237 else {
5238 if (getDB().isSupportsInlineDistinct()) {
5239 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5240 }
5241 else {
5242 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5243 }
5244 }
5245
5246 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5247 MBThread.class.getName(),
5248 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5249
5250 Session session = null;
5251
5252 try {
5253 session = openSession();
5254
5255 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5256
5257 if (getDB().isSupportsInlineDistinct()) {
5258 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5259 }
5260 else {
5261 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5262 }
5263
5264 QueryPos qPos = QueryPos.getInstance(q);
5265
5266 qPos.add(groupId);
5267
5268 qPos.add(status);
5269
5270 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
5271 }
5272 catch (Exception e) {
5273 throw processException(e);
5274 }
5275 finally {
5276 closeSession(session);
5277 }
5278 }
5279
5280
5290 @Override
5291 public MBThread[] filterFindByG_S_PrevAndNext(long threadId, long groupId,
5292 int status, OrderByComparator<MBThread> orderByComparator)
5293 throws NoSuchThreadException {
5294 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5295 return findByG_S_PrevAndNext(threadId, groupId, status,
5296 orderByComparator);
5297 }
5298
5299 MBThread mbThread = findByPrimaryKey(threadId);
5300
5301 Session session = null;
5302
5303 try {
5304 session = openSession();
5305
5306 MBThread[] array = new MBThreadImpl[3];
5307
5308 array[0] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5309 status, orderByComparator, true);
5310
5311 array[1] = mbThread;
5312
5313 array[2] = filterGetByG_S_PrevAndNext(session, mbThread, groupId,
5314 status, orderByComparator, false);
5315
5316 return array;
5317 }
5318 catch (Exception e) {
5319 throw processException(e);
5320 }
5321 finally {
5322 closeSession(session);
5323 }
5324 }
5325
5326 protected MBThread filterGetByG_S_PrevAndNext(Session session,
5327 MBThread mbThread, long groupId, int status,
5328 OrderByComparator<MBThread> orderByComparator, boolean previous) {
5329 StringBundler query = null;
5330
5331 if (orderByComparator != null) {
5332 query = new StringBundler(6 +
5333 (orderByComparator.getOrderByFields().length * 6));
5334 }
5335 else {
5336 query = new StringBundler(3);
5337 }
5338
5339 if (getDB().isSupportsInlineDistinct()) {
5340 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
5341 }
5342 else {
5343 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
5344 }
5345
5346 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5347
5348 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5349
5350 if (!getDB().isSupportsInlineDistinct()) {
5351 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
5352 }
5353
5354 if (orderByComparator != null) {
5355 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5356
5357 if (orderByConditionFields.length > 0) {
5358 query.append(WHERE_AND);
5359 }
5360
5361 for (int i = 0; i < orderByConditionFields.length; i++) {
5362 if (getDB().isSupportsInlineDistinct()) {
5363 query.append(_ORDER_BY_ENTITY_ALIAS);
5364 }
5365 else {
5366 query.append(_ORDER_BY_ENTITY_TABLE);
5367 }
5368
5369 query.append(orderByConditionFields[i]);
5370
5371 if ((i + 1) < orderByConditionFields.length) {
5372 if (orderByComparator.isAscending() ^ previous) {
5373 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5374 }
5375 else {
5376 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5377 }
5378 }
5379 else {
5380 if (orderByComparator.isAscending() ^ previous) {
5381 query.append(WHERE_GREATER_THAN);
5382 }
5383 else {
5384 query.append(WHERE_LESSER_THAN);
5385 }
5386 }
5387 }
5388
5389 query.append(ORDER_BY_CLAUSE);
5390
5391 String[] orderByFields = orderByComparator.getOrderByFields();
5392
5393 for (int i = 0; i < orderByFields.length; i++) {
5394 if (getDB().isSupportsInlineDistinct()) {
5395 query.append(_ORDER_BY_ENTITY_ALIAS);
5396 }
5397 else {
5398 query.append(_ORDER_BY_ENTITY_TABLE);
5399 }
5400
5401 query.append(orderByFields[i]);
5402
5403 if ((i + 1) < orderByFields.length) {
5404 if (orderByComparator.isAscending() ^ previous) {
5405 query.append(ORDER_BY_ASC_HAS_NEXT);
5406 }
5407 else {
5408 query.append(ORDER_BY_DESC_HAS_NEXT);
5409 }
5410 }
5411 else {
5412 if (orderByComparator.isAscending() ^ previous) {
5413 query.append(ORDER_BY_ASC);
5414 }
5415 else {
5416 query.append(ORDER_BY_DESC);
5417 }
5418 }
5419 }
5420 }
5421 else {
5422 if (getDB().isSupportsInlineDistinct()) {
5423 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5424 }
5425 else {
5426 query.append(MBThreadModelImpl.ORDER_BY_SQL);
5427 }
5428 }
5429
5430 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5431 MBThread.class.getName(),
5432 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5433
5434 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5435
5436 q.setFirstResult(0);
5437 q.setMaxResults(2);
5438
5439 if (getDB().isSupportsInlineDistinct()) {
5440 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
5441 }
5442 else {
5443 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
5444 }
5445
5446 QueryPos qPos = QueryPos.getInstance(q);
5447
5448 qPos.add(groupId);
5449
5450 qPos.add(status);
5451
5452 if (orderByComparator != null) {
5453 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
5454
5455 for (Object value : values) {
5456 qPos.add(value);
5457 }
5458 }
5459
5460 List<MBThread> list = q.list();
5461
5462 if (list.size() == 2) {
5463 return list.get(1);
5464 }
5465 else {
5466 return null;
5467 }
5468 }
5469
5470
5476 @Override
5477 public void removeByG_S(long groupId, int status) {
5478 for (MBThread mbThread : findByG_S(groupId, status, QueryUtil.ALL_POS,
5479 QueryUtil.ALL_POS, null)) {
5480 remove(mbThread);
5481 }
5482 }
5483
5484
5491 @Override
5492 public int countByG_S(long groupId, int status) {
5493 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5494
5495 Object[] finderArgs = new Object[] { groupId, status };
5496
5497 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5498 this);
5499
5500 if (count == null) {
5501 StringBundler query = new StringBundler(3);
5502
5503 query.append(_SQL_COUNT_MBTHREAD_WHERE);
5504
5505 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5506
5507 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5508
5509 String sql = query.toString();
5510
5511 Session session = null;
5512
5513 try {
5514 session = openSession();
5515
5516 Query q = session.createQuery(sql);
5517
5518 QueryPos qPos = QueryPos.getInstance(q);
5519
5520 qPos.add(groupId);
5521
5522 qPos.add(status);
5523
5524 count = (Long)q.uniqueResult();
5525
5526 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5527 }
5528 catch (Exception e) {
5529 FinderCacheUtil.removeResult(finderPath, finderArgs);
5530
5531 throw processException(e);
5532 }
5533 finally {
5534 closeSession(session);
5535 }
5536 }
5537
5538 return count.intValue();
5539 }
5540
5541
5548 @Override
5549 public int filterCountByG_S(long groupId, int status) {
5550 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5551 return countByG_S(groupId, status);
5552 }
5553
5554 StringBundler query = new StringBundler(3);
5555
5556 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
5557
5558 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5559
5560 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5561
5562 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5563 MBThread.class.getName(),
5564 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5565
5566 Session session = null;
5567
5568 try {
5569 session = openSession();
5570
5571 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5572
5573 q.addScalar(COUNT_COLUMN_NAME,
5574 com.liferay.portal.kernel.dao.orm.Type.LONG);
5575
5576 QueryPos qPos = QueryPos.getInstance(q);
5577
5578 qPos.add(groupId);
5579
5580 qPos.add(status);
5581
5582 Long count = (Long)q.uniqueResult();
5583
5584 return count.intValue();
5585 }
5586 catch (Exception e) {
5587 throw processException(e);
5588 }
5589 finally {
5590 closeSession(session);
5591 }
5592 }
5593
5594 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbThread.groupId = ? AND ";
5595 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbThread.status = ? AND mbThread.categoryId != -1";
5596 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5597 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5598 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_P",
5599 new String[] {
5600 Long.class.getName(), Double.class.getName(),
5601
5602 Integer.class.getName(), Integer.class.getName(),
5603 OrderByComparator.class.getName()
5604 });
5605 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5606 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
5607 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_P",
5608 new String[] { Long.class.getName(), Double.class.getName() },
5609 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
5610 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
5611 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
5612 public static final FinderPath FINDER_PATH_COUNT_BY_C_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
5613 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
5614 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_P",
5615 new String[] { Long.class.getName(), Double.class.getName() });
5616
5617
5624 @Override
5625 public List<MBThread> findByC_P(long categoryId, double priority) {
5626 return findByC_P(categoryId, priority, QueryUtil.ALL_POS,
5627 QueryUtil.ALL_POS, null);
5628 }
5629
5630
5643 @Override
5644 public List<MBThread> findByC_P(long categoryId, double priority,
5645 int start, int end) {
5646 return findByC_P(categoryId, priority, start, end, null);
5647 }
5648
5649
5663 @Override
5664 public List<MBThread> findByC_P(long categoryId, double priority,
5665 int start, int end, OrderByComparator<MBThread> orderByComparator) {
5666 boolean pagination = true;
5667 FinderPath finderPath = null;
5668 Object[] finderArgs = null;
5669
5670 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5671 (orderByComparator == null)) {
5672 pagination = false;
5673 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P;
5674 finderArgs = new Object[] { categoryId, priority };
5675 }
5676 else {
5677 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_P;
5678 finderArgs = new Object[] {
5679 categoryId, priority,
5680
5681 start, end, orderByComparator
5682 };
5683 }
5684
5685 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
5686 finderArgs, this);
5687
5688 if ((list != null) && !list.isEmpty()) {
5689 for (MBThread mbThread : list) {
5690 if ((categoryId != mbThread.getCategoryId()) ||
5691 (priority != mbThread.getPriority())) {
5692 list = null;
5693
5694 break;
5695 }
5696 }
5697 }
5698
5699 if (list == null) {
5700 StringBundler query = null;
5701
5702 if (orderByComparator != null) {
5703 query = new StringBundler(4 +
5704 (orderByComparator.getOrderByFields().length * 3));
5705 }
5706 else {
5707 query = new StringBundler(4);
5708 }
5709
5710 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5711
5712 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5713
5714 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5715
5716 if (orderByComparator != null) {
5717 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5718 orderByComparator);
5719 }
5720 else
5721 if (pagination) {
5722 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
5723 }
5724
5725 String sql = query.toString();
5726
5727 Session session = null;
5728
5729 try {
5730 session = openSession();
5731
5732 Query q = session.createQuery(sql);
5733
5734 QueryPos qPos = QueryPos.getInstance(q);
5735
5736 qPos.add(categoryId);
5737
5738 qPos.add(priority);
5739
5740 if (!pagination) {
5741 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5742 start, end, false);
5743
5744 Collections.sort(list);
5745
5746 list = Collections.unmodifiableList(list);
5747 }
5748 else {
5749 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
5750 start, end);
5751 }
5752
5753 cacheResult(list);
5754
5755 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5756 }
5757 catch (Exception e) {
5758 FinderCacheUtil.removeResult(finderPath, finderArgs);
5759
5760 throw processException(e);
5761 }
5762 finally {
5763 closeSession(session);
5764 }
5765 }
5766
5767 return list;
5768 }
5769
5770
5779 @Override
5780 public MBThread findByC_P_First(long categoryId, double priority,
5781 OrderByComparator<MBThread> orderByComparator)
5782 throws NoSuchThreadException {
5783 MBThread mbThread = fetchByC_P_First(categoryId, priority,
5784 orderByComparator);
5785
5786 if (mbThread != null) {
5787 return mbThread;
5788 }
5789
5790 StringBundler msg = new StringBundler(6);
5791
5792 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5793
5794 msg.append("categoryId=");
5795 msg.append(categoryId);
5796
5797 msg.append(", priority=");
5798 msg.append(priority);
5799
5800 msg.append(StringPool.CLOSE_CURLY_BRACE);
5801
5802 throw new NoSuchThreadException(msg.toString());
5803 }
5804
5805
5813 @Override
5814 public MBThread fetchByC_P_First(long categoryId, double priority,
5815 OrderByComparator<MBThread> orderByComparator) {
5816 List<MBThread> list = findByC_P(categoryId, priority, 0, 1,
5817 orderByComparator);
5818
5819 if (!list.isEmpty()) {
5820 return list.get(0);
5821 }
5822
5823 return null;
5824 }
5825
5826
5835 @Override
5836 public MBThread findByC_P_Last(long categoryId, double priority,
5837 OrderByComparator<MBThread> orderByComparator)
5838 throws NoSuchThreadException {
5839 MBThread mbThread = fetchByC_P_Last(categoryId, priority,
5840 orderByComparator);
5841
5842 if (mbThread != null) {
5843 return mbThread;
5844 }
5845
5846 StringBundler msg = new StringBundler(6);
5847
5848 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5849
5850 msg.append("categoryId=");
5851 msg.append(categoryId);
5852
5853 msg.append(", priority=");
5854 msg.append(priority);
5855
5856 msg.append(StringPool.CLOSE_CURLY_BRACE);
5857
5858 throw new NoSuchThreadException(msg.toString());
5859 }
5860
5861
5869 @Override
5870 public MBThread fetchByC_P_Last(long categoryId, double priority,
5871 OrderByComparator<MBThread> orderByComparator) {
5872 int count = countByC_P(categoryId, priority);
5873
5874 if (count == 0) {
5875 return null;
5876 }
5877
5878 List<MBThread> list = findByC_P(categoryId, priority, count - 1, count,
5879 orderByComparator);
5880
5881 if (!list.isEmpty()) {
5882 return list.get(0);
5883 }
5884
5885 return null;
5886 }
5887
5888
5898 @Override
5899 public MBThread[] findByC_P_PrevAndNext(long threadId, long categoryId,
5900 double priority, OrderByComparator<MBThread> orderByComparator)
5901 throws NoSuchThreadException {
5902 MBThread mbThread = findByPrimaryKey(threadId);
5903
5904 Session session = null;
5905
5906 try {
5907 session = openSession();
5908
5909 MBThread[] array = new MBThreadImpl[3];
5910
5911 array[0] = getByC_P_PrevAndNext(session, mbThread, categoryId,
5912 priority, orderByComparator, true);
5913
5914 array[1] = mbThread;
5915
5916 array[2] = getByC_P_PrevAndNext(session, mbThread, categoryId,
5917 priority, orderByComparator, false);
5918
5919 return array;
5920 }
5921 catch (Exception e) {
5922 throw processException(e);
5923 }
5924 finally {
5925 closeSession(session);
5926 }
5927 }
5928
5929 protected MBThread getByC_P_PrevAndNext(Session session, MBThread mbThread,
5930 long categoryId, double priority,
5931 OrderByComparator<MBThread> orderByComparator, boolean previous) {
5932 StringBundler query = null;
5933
5934 if (orderByComparator != null) {
5935 query = new StringBundler(6 +
5936 (orderByComparator.getOrderByFields().length * 6));
5937 }
5938 else {
5939 query = new StringBundler(3);
5940 }
5941
5942 query.append(_SQL_SELECT_MBTHREAD_WHERE);
5943
5944 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
5945
5946 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
5947
5948 if (orderByComparator != null) {
5949 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5950
5951 if (orderByConditionFields.length > 0) {
5952 query.append(WHERE_AND);
5953 }
5954
5955 for (int i = 0; i < orderByConditionFields.length; i++) {
5956 query.append(_ORDER_BY_ENTITY_ALIAS);
5957 query.append(orderByConditionFields[i]);
5958
5959 if ((i + 1) < orderByConditionFields.length) {
5960 if (orderByComparator.isAscending() ^ previous) {
5961 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5962 }
5963 else {
5964 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5965 }
5966 }
5967 else {
5968 if (orderByComparator.isAscending() ^ previous) {
5969 query.append(WHERE_GREATER_THAN);
5970 }
5971 else {
5972 query.append(WHERE_LESSER_THAN);
5973 }
5974 }
5975 }
5976
5977 query.append(ORDER_BY_CLAUSE);
5978
5979 String[] orderByFields = orderByComparator.getOrderByFields();
5980
5981 for (int i = 0; i < orderByFields.length; i++) {
5982 query.append(_ORDER_BY_ENTITY_ALIAS);
5983 query.append(orderByFields[i]);
5984
5985 if ((i + 1) < orderByFields.length) {
5986 if (orderByComparator.isAscending() ^ previous) {
5987 query.append(ORDER_BY_ASC_HAS_NEXT);
5988 }
5989 else {
5990 query.append(ORDER_BY_DESC_HAS_NEXT);
5991 }
5992 }
5993 else {
5994 if (orderByComparator.isAscending() ^ previous) {
5995 query.append(ORDER_BY_ASC);
5996 }
5997 else {
5998 query.append(ORDER_BY_DESC);
5999 }
6000 }
6001 }
6002 }
6003 else {
6004 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6005 }
6006
6007 String sql = query.toString();
6008
6009 Query q = session.createQuery(sql);
6010
6011 q.setFirstResult(0);
6012 q.setMaxResults(2);
6013
6014 QueryPos qPos = QueryPos.getInstance(q);
6015
6016 qPos.add(categoryId);
6017
6018 qPos.add(priority);
6019
6020 if (orderByComparator != null) {
6021 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6022
6023 for (Object value : values) {
6024 qPos.add(value);
6025 }
6026 }
6027
6028 List<MBThread> list = q.list();
6029
6030 if (list.size() == 2) {
6031 return list.get(1);
6032 }
6033 else {
6034 return null;
6035 }
6036 }
6037
6038
6044 @Override
6045 public void removeByC_P(long categoryId, double priority) {
6046 for (MBThread mbThread : findByC_P(categoryId, priority,
6047 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6048 remove(mbThread);
6049 }
6050 }
6051
6052
6059 @Override
6060 public int countByC_P(long categoryId, double priority) {
6061 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_P;
6062
6063 Object[] finderArgs = new Object[] { categoryId, priority };
6064
6065 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6066 this);
6067
6068 if (count == null) {
6069 StringBundler query = new StringBundler(3);
6070
6071 query.append(_SQL_COUNT_MBTHREAD_WHERE);
6072
6073 query.append(_FINDER_COLUMN_C_P_CATEGORYID_2);
6074
6075 query.append(_FINDER_COLUMN_C_P_PRIORITY_2);
6076
6077 String sql = query.toString();
6078
6079 Session session = null;
6080
6081 try {
6082 session = openSession();
6083
6084 Query q = session.createQuery(sql);
6085
6086 QueryPos qPos = QueryPos.getInstance(q);
6087
6088 qPos.add(categoryId);
6089
6090 qPos.add(priority);
6091
6092 count = (Long)q.uniqueResult();
6093
6094 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6095 }
6096 catch (Exception e) {
6097 FinderCacheUtil.removeResult(finderPath, finderArgs);
6098
6099 throw processException(e);
6100 }
6101 finally {
6102 closeSession(session);
6103 }
6104 }
6105
6106 return count.intValue();
6107 }
6108
6109 private static final String _FINDER_COLUMN_C_P_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
6110 private static final String _FINDER_COLUMN_C_P_PRIORITY_2 = "mbThread.priority = ?";
6111 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6112 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6113 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByL_P",
6114 new String[] {
6115 Date.class.getName(), Double.class.getName(),
6116
6117 Integer.class.getName(), Integer.class.getName(),
6118 OrderByComparator.class.getName()
6119 });
6120 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6121 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6122 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByL_P",
6123 new String[] { Date.class.getName(), Double.class.getName() },
6124 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6125 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6126 public static final FinderPath FINDER_PATH_COUNT_BY_L_P = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6127 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByL_P",
6129 new String[] { Date.class.getName(), Double.class.getName() });
6130
6131
6138 @Override
6139 public List<MBThread> findByL_P(Date lastPostDate, double priority) {
6140 return findByL_P(lastPostDate, priority, QueryUtil.ALL_POS,
6141 QueryUtil.ALL_POS, null);
6142 }
6143
6144
6157 @Override
6158 public List<MBThread> findByL_P(Date lastPostDate, double priority,
6159 int start, int end) {
6160 return findByL_P(lastPostDate, priority, start, end, null);
6161 }
6162
6163
6177 @Override
6178 public List<MBThread> findByL_P(Date lastPostDate, double priority,
6179 int start, int end, OrderByComparator<MBThread> orderByComparator) {
6180 boolean pagination = true;
6181 FinderPath finderPath = null;
6182 Object[] finderArgs = null;
6183
6184 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6185 (orderByComparator == null)) {
6186 pagination = false;
6187 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P;
6188 finderArgs = new Object[] { lastPostDate, priority };
6189 }
6190 else {
6191 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_L_P;
6192 finderArgs = new Object[] {
6193 lastPostDate, priority,
6194
6195 start, end, orderByComparator
6196 };
6197 }
6198
6199 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6200 finderArgs, this);
6201
6202 if ((list != null) && !list.isEmpty()) {
6203 for (MBThread mbThread : list) {
6204 if (!Validator.equals(lastPostDate, mbThread.getLastPostDate()) ||
6205 (priority != mbThread.getPriority())) {
6206 list = null;
6207
6208 break;
6209 }
6210 }
6211 }
6212
6213 if (list == null) {
6214 StringBundler query = null;
6215
6216 if (orderByComparator != null) {
6217 query = new StringBundler(4 +
6218 (orderByComparator.getOrderByFields().length * 3));
6219 }
6220 else {
6221 query = new StringBundler(4);
6222 }
6223
6224 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6225
6226 boolean bindLastPostDate = false;
6227
6228 if (lastPostDate == null) {
6229 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6230 }
6231 else {
6232 bindLastPostDate = true;
6233
6234 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6235 }
6236
6237 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6238
6239 if (orderByComparator != null) {
6240 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6241 orderByComparator);
6242 }
6243 else
6244 if (pagination) {
6245 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6246 }
6247
6248 String sql = query.toString();
6249
6250 Session session = null;
6251
6252 try {
6253 session = openSession();
6254
6255 Query q = session.createQuery(sql);
6256
6257 QueryPos qPos = QueryPos.getInstance(q);
6258
6259 if (bindLastPostDate) {
6260 qPos.add(new Timestamp(lastPostDate.getTime()));
6261 }
6262
6263 qPos.add(priority);
6264
6265 if (!pagination) {
6266 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6267 start, end, false);
6268
6269 Collections.sort(list);
6270
6271 list = Collections.unmodifiableList(list);
6272 }
6273 else {
6274 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6275 start, end);
6276 }
6277
6278 cacheResult(list);
6279
6280 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6281 }
6282 catch (Exception e) {
6283 FinderCacheUtil.removeResult(finderPath, finderArgs);
6284
6285 throw processException(e);
6286 }
6287 finally {
6288 closeSession(session);
6289 }
6290 }
6291
6292 return list;
6293 }
6294
6295
6304 @Override
6305 public MBThread findByL_P_First(Date lastPostDate, double priority,
6306 OrderByComparator<MBThread> orderByComparator)
6307 throws NoSuchThreadException {
6308 MBThread mbThread = fetchByL_P_First(lastPostDate, priority,
6309 orderByComparator);
6310
6311 if (mbThread != null) {
6312 return mbThread;
6313 }
6314
6315 StringBundler msg = new StringBundler(6);
6316
6317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6318
6319 msg.append("lastPostDate=");
6320 msg.append(lastPostDate);
6321
6322 msg.append(", priority=");
6323 msg.append(priority);
6324
6325 msg.append(StringPool.CLOSE_CURLY_BRACE);
6326
6327 throw new NoSuchThreadException(msg.toString());
6328 }
6329
6330
6338 @Override
6339 public MBThread fetchByL_P_First(Date lastPostDate, double priority,
6340 OrderByComparator<MBThread> orderByComparator) {
6341 List<MBThread> list = findByL_P(lastPostDate, priority, 0, 1,
6342 orderByComparator);
6343
6344 if (!list.isEmpty()) {
6345 return list.get(0);
6346 }
6347
6348 return null;
6349 }
6350
6351
6360 @Override
6361 public MBThread findByL_P_Last(Date lastPostDate, double priority,
6362 OrderByComparator<MBThread> orderByComparator)
6363 throws NoSuchThreadException {
6364 MBThread mbThread = fetchByL_P_Last(lastPostDate, priority,
6365 orderByComparator);
6366
6367 if (mbThread != null) {
6368 return mbThread;
6369 }
6370
6371 StringBundler msg = new StringBundler(6);
6372
6373 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6374
6375 msg.append("lastPostDate=");
6376 msg.append(lastPostDate);
6377
6378 msg.append(", priority=");
6379 msg.append(priority);
6380
6381 msg.append(StringPool.CLOSE_CURLY_BRACE);
6382
6383 throw new NoSuchThreadException(msg.toString());
6384 }
6385
6386
6394 @Override
6395 public MBThread fetchByL_P_Last(Date lastPostDate, double priority,
6396 OrderByComparator<MBThread> orderByComparator) {
6397 int count = countByL_P(lastPostDate, priority);
6398
6399 if (count == 0) {
6400 return null;
6401 }
6402
6403 List<MBThread> list = findByL_P(lastPostDate, priority, count - 1,
6404 count, orderByComparator);
6405
6406 if (!list.isEmpty()) {
6407 return list.get(0);
6408 }
6409
6410 return null;
6411 }
6412
6413
6423 @Override
6424 public MBThread[] findByL_P_PrevAndNext(long threadId, Date lastPostDate,
6425 double priority, OrderByComparator<MBThread> orderByComparator)
6426 throws NoSuchThreadException {
6427 MBThread mbThread = findByPrimaryKey(threadId);
6428
6429 Session session = null;
6430
6431 try {
6432 session = openSession();
6433
6434 MBThread[] array = new MBThreadImpl[3];
6435
6436 array[0] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6437 priority, orderByComparator, true);
6438
6439 array[1] = mbThread;
6440
6441 array[2] = getByL_P_PrevAndNext(session, mbThread, lastPostDate,
6442 priority, orderByComparator, false);
6443
6444 return array;
6445 }
6446 catch (Exception e) {
6447 throw processException(e);
6448 }
6449 finally {
6450 closeSession(session);
6451 }
6452 }
6453
6454 protected MBThread getByL_P_PrevAndNext(Session session, MBThread mbThread,
6455 Date lastPostDate, double priority,
6456 OrderByComparator<MBThread> orderByComparator, boolean previous) {
6457 StringBundler query = null;
6458
6459 if (orderByComparator != null) {
6460 query = new StringBundler(6 +
6461 (orderByComparator.getOrderByFields().length * 6));
6462 }
6463 else {
6464 query = new StringBundler(3);
6465 }
6466
6467 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6468
6469 boolean bindLastPostDate = false;
6470
6471 if (lastPostDate == null) {
6472 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6473 }
6474 else {
6475 bindLastPostDate = true;
6476
6477 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6478 }
6479
6480 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6481
6482 if (orderByComparator != null) {
6483 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6484
6485 if (orderByConditionFields.length > 0) {
6486 query.append(WHERE_AND);
6487 }
6488
6489 for (int i = 0; i < orderByConditionFields.length; i++) {
6490 query.append(_ORDER_BY_ENTITY_ALIAS);
6491 query.append(orderByConditionFields[i]);
6492
6493 if ((i + 1) < orderByConditionFields.length) {
6494 if (orderByComparator.isAscending() ^ previous) {
6495 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6496 }
6497 else {
6498 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6499 }
6500 }
6501 else {
6502 if (orderByComparator.isAscending() ^ previous) {
6503 query.append(WHERE_GREATER_THAN);
6504 }
6505 else {
6506 query.append(WHERE_LESSER_THAN);
6507 }
6508 }
6509 }
6510
6511 query.append(ORDER_BY_CLAUSE);
6512
6513 String[] orderByFields = orderByComparator.getOrderByFields();
6514
6515 for (int i = 0; i < orderByFields.length; i++) {
6516 query.append(_ORDER_BY_ENTITY_ALIAS);
6517 query.append(orderByFields[i]);
6518
6519 if ((i + 1) < orderByFields.length) {
6520 if (orderByComparator.isAscending() ^ previous) {
6521 query.append(ORDER_BY_ASC_HAS_NEXT);
6522 }
6523 else {
6524 query.append(ORDER_BY_DESC_HAS_NEXT);
6525 }
6526 }
6527 else {
6528 if (orderByComparator.isAscending() ^ previous) {
6529 query.append(ORDER_BY_ASC);
6530 }
6531 else {
6532 query.append(ORDER_BY_DESC);
6533 }
6534 }
6535 }
6536 }
6537 else {
6538 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6539 }
6540
6541 String sql = query.toString();
6542
6543 Query q = session.createQuery(sql);
6544
6545 q.setFirstResult(0);
6546 q.setMaxResults(2);
6547
6548 QueryPos qPos = QueryPos.getInstance(q);
6549
6550 if (bindLastPostDate) {
6551 qPos.add(new Timestamp(lastPostDate.getTime()));
6552 }
6553
6554 qPos.add(priority);
6555
6556 if (orderByComparator != null) {
6557 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
6558
6559 for (Object value : values) {
6560 qPos.add(value);
6561 }
6562 }
6563
6564 List<MBThread> list = q.list();
6565
6566 if (list.size() == 2) {
6567 return list.get(1);
6568 }
6569 else {
6570 return null;
6571 }
6572 }
6573
6574
6580 @Override
6581 public void removeByL_P(Date lastPostDate, double priority) {
6582 for (MBThread mbThread : findByL_P(lastPostDate, priority,
6583 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6584 remove(mbThread);
6585 }
6586 }
6587
6588
6595 @Override
6596 public int countByL_P(Date lastPostDate, double priority) {
6597 FinderPath finderPath = FINDER_PATH_COUNT_BY_L_P;
6598
6599 Object[] finderArgs = new Object[] { lastPostDate, priority };
6600
6601 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6602 this);
6603
6604 if (count == null) {
6605 StringBundler query = new StringBundler(3);
6606
6607 query.append(_SQL_COUNT_MBTHREAD_WHERE);
6608
6609 boolean bindLastPostDate = false;
6610
6611 if (lastPostDate == null) {
6612 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_1);
6613 }
6614 else {
6615 bindLastPostDate = true;
6616
6617 query.append(_FINDER_COLUMN_L_P_LASTPOSTDATE_2);
6618 }
6619
6620 query.append(_FINDER_COLUMN_L_P_PRIORITY_2);
6621
6622 String sql = query.toString();
6623
6624 Session session = null;
6625
6626 try {
6627 session = openSession();
6628
6629 Query q = session.createQuery(sql);
6630
6631 QueryPos qPos = QueryPos.getInstance(q);
6632
6633 if (bindLastPostDate) {
6634 qPos.add(new Timestamp(lastPostDate.getTime()));
6635 }
6636
6637 qPos.add(priority);
6638
6639 count = (Long)q.uniqueResult();
6640
6641 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6642 }
6643 catch (Exception e) {
6644 FinderCacheUtil.removeResult(finderPath, finderArgs);
6645
6646 throw processException(e);
6647 }
6648 finally {
6649 closeSession(session);
6650 }
6651 }
6652
6653 return count.intValue();
6654 }
6655
6656 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL AND ";
6657 private static final String _FINDER_COLUMN_L_P_LASTPOSTDATE_2 = "mbThread.lastPostDate = ? AND ";
6658 private static final String _FINDER_COLUMN_L_P_PRIORITY_2 = "mbThread.priority = ? AND mbThread.categoryId != -1";
6659 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6660 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6661 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_L",
6662 new String[] {
6663 Long.class.getName(), Long.class.getName(), Date.class.getName(),
6664
6665 Integer.class.getName(), Integer.class.getName(),
6666 OrderByComparator.class.getName()
6667 });
6668 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6669 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
6670 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_L",
6671 new String[] {
6672 Long.class.getName(), Long.class.getName(), Date.class.getName()
6673 },
6674 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
6675 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
6676 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
6677 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK);
6678 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_L = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
6679 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
6680 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_L",
6681 new String[] {
6682 Long.class.getName(), Long.class.getName(), Date.class.getName()
6683 });
6684
6685
6693 @Override
6694 public List<MBThread> findByG_C_L(long groupId, long categoryId,
6695 Date lastPostDate) {
6696 return findByG_C_L(groupId, categoryId, lastPostDate,
6697 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6698 }
6699
6700
6714 @Override
6715 public List<MBThread> findByG_C_L(long groupId, long categoryId,
6716 Date lastPostDate, int start, int end) {
6717 return findByG_C_L(groupId, categoryId, lastPostDate, start, end, null);
6718 }
6719
6720
6735 @Override
6736 public List<MBThread> findByG_C_L(long groupId, long categoryId,
6737 Date lastPostDate, int start, int end,
6738 OrderByComparator<MBThread> orderByComparator) {
6739 boolean pagination = true;
6740 FinderPath finderPath = null;
6741 Object[] finderArgs = null;
6742
6743 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6744 (orderByComparator == null)) {
6745 pagination = false;
6746 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L;
6747 finderArgs = new Object[] { groupId, categoryId, lastPostDate };
6748 }
6749 else {
6750 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_L;
6751 finderArgs = new Object[] {
6752 groupId, categoryId, lastPostDate,
6753
6754 start, end, orderByComparator
6755 };
6756 }
6757
6758 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
6759 finderArgs, this);
6760
6761 if ((list != null) && !list.isEmpty()) {
6762 for (MBThread mbThread : list) {
6763 if ((groupId != mbThread.getGroupId()) ||
6764 (categoryId != mbThread.getCategoryId()) ||
6765 !Validator.equals(lastPostDate,
6766 mbThread.getLastPostDate())) {
6767 list = null;
6768
6769 break;
6770 }
6771 }
6772 }
6773
6774 if (list == null) {
6775 StringBundler query = null;
6776
6777 if (orderByComparator != null) {
6778 query = new StringBundler(5 +
6779 (orderByComparator.getOrderByFields().length * 3));
6780 }
6781 else {
6782 query = new StringBundler(5);
6783 }
6784
6785 query.append(_SQL_SELECT_MBTHREAD_WHERE);
6786
6787 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
6788
6789 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
6790
6791 boolean bindLastPostDate = false;
6792
6793 if (lastPostDate == null) {
6794 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
6795 }
6796 else {
6797 bindLastPostDate = true;
6798
6799 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
6800 }
6801
6802 if (orderByComparator != null) {
6803 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6804 orderByComparator);
6805 }
6806 else
6807 if (pagination) {
6808 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
6809 }
6810
6811 String sql = query.toString();
6812
6813 Session session = null;
6814
6815 try {
6816 session = openSession();
6817
6818 Query q = session.createQuery(sql);
6819
6820 QueryPos qPos = QueryPos.getInstance(q);
6821
6822 qPos.add(groupId);
6823
6824 qPos.add(categoryId);
6825
6826 if (bindLastPostDate) {
6827 qPos.add(new Timestamp(lastPostDate.getTime()));
6828 }
6829
6830 if (!pagination) {
6831 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6832 start, end, false);
6833
6834 Collections.sort(list);
6835
6836 list = Collections.unmodifiableList(list);
6837 }
6838 else {
6839 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
6840 start, end);
6841 }
6842
6843 cacheResult(list);
6844
6845 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6846 }
6847 catch (Exception e) {
6848 FinderCacheUtil.removeResult(finderPath, finderArgs);
6849
6850 throw processException(e);
6851 }
6852 finally {
6853 closeSession(session);
6854 }
6855 }
6856
6857 return list;
6858 }
6859
6860
6870 @Override
6871 public MBThread findByG_C_L_First(long groupId, long categoryId,
6872 Date lastPostDate, OrderByComparator<MBThread> orderByComparator)
6873 throws NoSuchThreadException {
6874 MBThread mbThread = fetchByG_C_L_First(groupId, categoryId,
6875 lastPostDate, orderByComparator);
6876
6877 if (mbThread != null) {
6878 return mbThread;
6879 }
6880
6881 StringBundler msg = new StringBundler(8);
6882
6883 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6884
6885 msg.append("groupId=");
6886 msg.append(groupId);
6887
6888 msg.append(", categoryId=");
6889 msg.append(categoryId);
6890
6891 msg.append(", lastPostDate=");
6892 msg.append(lastPostDate);
6893
6894 msg.append(StringPool.CLOSE_CURLY_BRACE);
6895
6896 throw new NoSuchThreadException(msg.toString());
6897 }
6898
6899
6908 @Override
6909 public MBThread fetchByG_C_L_First(long groupId, long categoryId,
6910 Date lastPostDate, OrderByComparator<MBThread> orderByComparator) {
6911 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate, 0,
6912 1, orderByComparator);
6913
6914 if (!list.isEmpty()) {
6915 return list.get(0);
6916 }
6917
6918 return null;
6919 }
6920
6921
6931 @Override
6932 public MBThread findByG_C_L_Last(long groupId, long categoryId,
6933 Date lastPostDate, OrderByComparator<MBThread> orderByComparator)
6934 throws NoSuchThreadException {
6935 MBThread mbThread = fetchByG_C_L_Last(groupId, categoryId,
6936 lastPostDate, orderByComparator);
6937
6938 if (mbThread != null) {
6939 return mbThread;
6940 }
6941
6942 StringBundler msg = new StringBundler(8);
6943
6944 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6945
6946 msg.append("groupId=");
6947 msg.append(groupId);
6948
6949 msg.append(", categoryId=");
6950 msg.append(categoryId);
6951
6952 msg.append(", lastPostDate=");
6953 msg.append(lastPostDate);
6954
6955 msg.append(StringPool.CLOSE_CURLY_BRACE);
6956
6957 throw new NoSuchThreadException(msg.toString());
6958 }
6959
6960
6969 @Override
6970 public MBThread fetchByG_C_L_Last(long groupId, long categoryId,
6971 Date lastPostDate, OrderByComparator<MBThread> orderByComparator) {
6972 int count = countByG_C_L(groupId, categoryId, lastPostDate);
6973
6974 if (count == 0) {
6975 return null;
6976 }
6977
6978 List<MBThread> list = findByG_C_L(groupId, categoryId, lastPostDate,
6979 count - 1, count, orderByComparator);
6980
6981 if (!list.isEmpty()) {
6982 return list.get(0);
6983 }
6984
6985 return null;
6986 }
6987
6988
6999 @Override
7000 public MBThread[] findByG_C_L_PrevAndNext(long threadId, long groupId,
7001 long categoryId, Date lastPostDate,
7002 OrderByComparator<MBThread> orderByComparator)
7003 throws NoSuchThreadException {
7004 MBThread mbThread = findByPrimaryKey(threadId);
7005
7006 Session session = null;
7007
7008 try {
7009 session = openSession();
7010
7011 MBThread[] array = new MBThreadImpl[3];
7012
7013 array[0] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7014 categoryId, lastPostDate, orderByComparator, true);
7015
7016 array[1] = mbThread;
7017
7018 array[2] = getByG_C_L_PrevAndNext(session, mbThread, groupId,
7019 categoryId, lastPostDate, orderByComparator, false);
7020
7021 return array;
7022 }
7023 catch (Exception e) {
7024 throw processException(e);
7025 }
7026 finally {
7027 closeSession(session);
7028 }
7029 }
7030
7031 protected MBThread getByG_C_L_PrevAndNext(Session session,
7032 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7033 OrderByComparator<MBThread> orderByComparator, boolean previous) {
7034 StringBundler query = null;
7035
7036 if (orderByComparator != null) {
7037 query = new StringBundler(6 +
7038 (orderByComparator.getOrderByFields().length * 6));
7039 }
7040 else {
7041 query = new StringBundler(3);
7042 }
7043
7044 query.append(_SQL_SELECT_MBTHREAD_WHERE);
7045
7046 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7047
7048 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7049
7050 boolean bindLastPostDate = false;
7051
7052 if (lastPostDate == null) {
7053 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7054 }
7055 else {
7056 bindLastPostDate = true;
7057
7058 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7059 }
7060
7061 if (orderByComparator != null) {
7062 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7063
7064 if (orderByConditionFields.length > 0) {
7065 query.append(WHERE_AND);
7066 }
7067
7068 for (int i = 0; i < orderByConditionFields.length; i++) {
7069 query.append(_ORDER_BY_ENTITY_ALIAS);
7070 query.append(orderByConditionFields[i]);
7071
7072 if ((i + 1) < orderByConditionFields.length) {
7073 if (orderByComparator.isAscending() ^ previous) {
7074 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7075 }
7076 else {
7077 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7078 }
7079 }
7080 else {
7081 if (orderByComparator.isAscending() ^ previous) {
7082 query.append(WHERE_GREATER_THAN);
7083 }
7084 else {
7085 query.append(WHERE_LESSER_THAN);
7086 }
7087 }
7088 }
7089
7090 query.append(ORDER_BY_CLAUSE);
7091
7092 String[] orderByFields = orderByComparator.getOrderByFields();
7093
7094 for (int i = 0; i < orderByFields.length; i++) {
7095 query.append(_ORDER_BY_ENTITY_ALIAS);
7096 query.append(orderByFields[i]);
7097
7098 if ((i + 1) < orderByFields.length) {
7099 if (orderByComparator.isAscending() ^ previous) {
7100 query.append(ORDER_BY_ASC_HAS_NEXT);
7101 }
7102 else {
7103 query.append(ORDER_BY_DESC_HAS_NEXT);
7104 }
7105 }
7106 else {
7107 if (orderByComparator.isAscending() ^ previous) {
7108 query.append(ORDER_BY_ASC);
7109 }
7110 else {
7111 query.append(ORDER_BY_DESC);
7112 }
7113 }
7114 }
7115 }
7116 else {
7117 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7118 }
7119
7120 String sql = query.toString();
7121
7122 Query q = session.createQuery(sql);
7123
7124 q.setFirstResult(0);
7125 q.setMaxResults(2);
7126
7127 QueryPos qPos = QueryPos.getInstance(q);
7128
7129 qPos.add(groupId);
7130
7131 qPos.add(categoryId);
7132
7133 if (bindLastPostDate) {
7134 qPos.add(new Timestamp(lastPostDate.getTime()));
7135 }
7136
7137 if (orderByComparator != null) {
7138 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7139
7140 for (Object value : values) {
7141 qPos.add(value);
7142 }
7143 }
7144
7145 List<MBThread> list = q.list();
7146
7147 if (list.size() == 2) {
7148 return list.get(1);
7149 }
7150 else {
7151 return null;
7152 }
7153 }
7154
7155
7163 @Override
7164 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7165 Date lastPostDate) {
7166 return filterFindByG_C_L(groupId, categoryId, lastPostDate,
7167 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7168 }
7169
7170
7184 @Override
7185 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7186 Date lastPostDate, int start, int end) {
7187 return filterFindByG_C_L(groupId, categoryId, lastPostDate, start, end,
7188 null);
7189 }
7190
7191
7206 @Override
7207 public List<MBThread> filterFindByG_C_L(long groupId, long categoryId,
7208 Date lastPostDate, int start, int end,
7209 OrderByComparator<MBThread> orderByComparator) {
7210 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7211 return findByG_C_L(groupId, categoryId, lastPostDate, start, end,
7212 orderByComparator);
7213 }
7214
7215 StringBundler query = null;
7216
7217 if (orderByComparator != null) {
7218 query = new StringBundler(5 +
7219 (orderByComparator.getOrderByFields().length * 3));
7220 }
7221 else {
7222 query = new StringBundler(5);
7223 }
7224
7225 if (getDB().isSupportsInlineDistinct()) {
7226 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7227 }
7228 else {
7229 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7230 }
7231
7232 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7233
7234 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7235
7236 boolean bindLastPostDate = false;
7237
7238 if (lastPostDate == null) {
7239 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7240 }
7241 else {
7242 bindLastPostDate = true;
7243
7244 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7245 }
7246
7247 if (!getDB().isSupportsInlineDistinct()) {
7248 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7249 }
7250
7251 if (orderByComparator != null) {
7252 if (getDB().isSupportsInlineDistinct()) {
7253 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7254 orderByComparator, true);
7255 }
7256 else {
7257 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7258 orderByComparator, true);
7259 }
7260 }
7261 else {
7262 if (getDB().isSupportsInlineDistinct()) {
7263 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7264 }
7265 else {
7266 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7267 }
7268 }
7269
7270 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7271 MBThread.class.getName(),
7272 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7273
7274 Session session = null;
7275
7276 try {
7277 session = openSession();
7278
7279 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7280
7281 if (getDB().isSupportsInlineDistinct()) {
7282 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7283 }
7284 else {
7285 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7286 }
7287
7288 QueryPos qPos = QueryPos.getInstance(q);
7289
7290 qPos.add(groupId);
7291
7292 qPos.add(categoryId);
7293
7294 if (bindLastPostDate) {
7295 qPos.add(new Timestamp(lastPostDate.getTime()));
7296 }
7297
7298 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
7299 }
7300 catch (Exception e) {
7301 throw processException(e);
7302 }
7303 finally {
7304 closeSession(session);
7305 }
7306 }
7307
7308
7319 @Override
7320 public MBThread[] filterFindByG_C_L_PrevAndNext(long threadId,
7321 long groupId, long categoryId, Date lastPostDate,
7322 OrderByComparator<MBThread> orderByComparator)
7323 throws NoSuchThreadException {
7324 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7325 return findByG_C_L_PrevAndNext(threadId, groupId, categoryId,
7326 lastPostDate, orderByComparator);
7327 }
7328
7329 MBThread mbThread = findByPrimaryKey(threadId);
7330
7331 Session session = null;
7332
7333 try {
7334 session = openSession();
7335
7336 MBThread[] array = new MBThreadImpl[3];
7337
7338 array[0] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7339 categoryId, lastPostDate, orderByComparator, true);
7340
7341 array[1] = mbThread;
7342
7343 array[2] = filterGetByG_C_L_PrevAndNext(session, mbThread, groupId,
7344 categoryId, lastPostDate, orderByComparator, false);
7345
7346 return array;
7347 }
7348 catch (Exception e) {
7349 throw processException(e);
7350 }
7351 finally {
7352 closeSession(session);
7353 }
7354 }
7355
7356 protected MBThread filterGetByG_C_L_PrevAndNext(Session session,
7357 MBThread mbThread, long groupId, long categoryId, Date lastPostDate,
7358 OrderByComparator<MBThread> orderByComparator, boolean previous) {
7359 StringBundler query = null;
7360
7361 if (orderByComparator != null) {
7362 query = new StringBundler(6 +
7363 (orderByComparator.getOrderByFields().length * 6));
7364 }
7365 else {
7366 query = new StringBundler(3);
7367 }
7368
7369 if (getDB().isSupportsInlineDistinct()) {
7370 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
7371 }
7372 else {
7373 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
7374 }
7375
7376 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7377
7378 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7379
7380 boolean bindLastPostDate = false;
7381
7382 if (lastPostDate == null) {
7383 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7384 }
7385 else {
7386 bindLastPostDate = true;
7387
7388 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7389 }
7390
7391 if (!getDB().isSupportsInlineDistinct()) {
7392 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
7393 }
7394
7395 if (orderByComparator != null) {
7396 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7397
7398 if (orderByConditionFields.length > 0) {
7399 query.append(WHERE_AND);
7400 }
7401
7402 for (int i = 0; i < orderByConditionFields.length; i++) {
7403 if (getDB().isSupportsInlineDistinct()) {
7404 query.append(_ORDER_BY_ENTITY_ALIAS);
7405 }
7406 else {
7407 query.append(_ORDER_BY_ENTITY_TABLE);
7408 }
7409
7410 query.append(orderByConditionFields[i]);
7411
7412 if ((i + 1) < orderByConditionFields.length) {
7413 if (orderByComparator.isAscending() ^ previous) {
7414 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7415 }
7416 else {
7417 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7418 }
7419 }
7420 else {
7421 if (orderByComparator.isAscending() ^ previous) {
7422 query.append(WHERE_GREATER_THAN);
7423 }
7424 else {
7425 query.append(WHERE_LESSER_THAN);
7426 }
7427 }
7428 }
7429
7430 query.append(ORDER_BY_CLAUSE);
7431
7432 String[] orderByFields = orderByComparator.getOrderByFields();
7433
7434 for (int i = 0; i < orderByFields.length; i++) {
7435 if (getDB().isSupportsInlineDistinct()) {
7436 query.append(_ORDER_BY_ENTITY_ALIAS);
7437 }
7438 else {
7439 query.append(_ORDER_BY_ENTITY_TABLE);
7440 }
7441
7442 query.append(orderByFields[i]);
7443
7444 if ((i + 1) < orderByFields.length) {
7445 if (orderByComparator.isAscending() ^ previous) {
7446 query.append(ORDER_BY_ASC_HAS_NEXT);
7447 }
7448 else {
7449 query.append(ORDER_BY_DESC_HAS_NEXT);
7450 }
7451 }
7452 else {
7453 if (orderByComparator.isAscending() ^ previous) {
7454 query.append(ORDER_BY_ASC);
7455 }
7456 else {
7457 query.append(ORDER_BY_DESC);
7458 }
7459 }
7460 }
7461 }
7462 else {
7463 if (getDB().isSupportsInlineDistinct()) {
7464 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7465 }
7466 else {
7467 query.append(MBThreadModelImpl.ORDER_BY_SQL);
7468 }
7469 }
7470
7471 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7472 MBThread.class.getName(),
7473 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7474
7475 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7476
7477 q.setFirstResult(0);
7478 q.setMaxResults(2);
7479
7480 if (getDB().isSupportsInlineDistinct()) {
7481 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
7482 }
7483 else {
7484 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
7485 }
7486
7487 QueryPos qPos = QueryPos.getInstance(q);
7488
7489 qPos.add(groupId);
7490
7491 qPos.add(categoryId);
7492
7493 if (bindLastPostDate) {
7494 qPos.add(new Timestamp(lastPostDate.getTime()));
7495 }
7496
7497 if (orderByComparator != null) {
7498 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
7499
7500 for (Object value : values) {
7501 qPos.add(value);
7502 }
7503 }
7504
7505 List<MBThread> list = q.list();
7506
7507 if (list.size() == 2) {
7508 return list.get(1);
7509 }
7510 else {
7511 return null;
7512 }
7513 }
7514
7515
7522 @Override
7523 public void removeByG_C_L(long groupId, long categoryId, Date lastPostDate) {
7524 for (MBThread mbThread : findByG_C_L(groupId, categoryId, lastPostDate,
7525 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7526 remove(mbThread);
7527 }
7528 }
7529
7530
7538 @Override
7539 public int countByG_C_L(long groupId, long categoryId, Date lastPostDate) {
7540 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_L;
7541
7542 Object[] finderArgs = new Object[] { groupId, categoryId, lastPostDate };
7543
7544 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7545 this);
7546
7547 if (count == null) {
7548 StringBundler query = new StringBundler(4);
7549
7550 query.append(_SQL_COUNT_MBTHREAD_WHERE);
7551
7552 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7553
7554 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7555
7556 boolean bindLastPostDate = false;
7557
7558 if (lastPostDate == null) {
7559 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7560 }
7561 else {
7562 bindLastPostDate = true;
7563
7564 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7565 }
7566
7567 String sql = query.toString();
7568
7569 Session session = null;
7570
7571 try {
7572 session = openSession();
7573
7574 Query q = session.createQuery(sql);
7575
7576 QueryPos qPos = QueryPos.getInstance(q);
7577
7578 qPos.add(groupId);
7579
7580 qPos.add(categoryId);
7581
7582 if (bindLastPostDate) {
7583 qPos.add(new Timestamp(lastPostDate.getTime()));
7584 }
7585
7586 count = (Long)q.uniqueResult();
7587
7588 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7589 }
7590 catch (Exception e) {
7591 FinderCacheUtil.removeResult(finderPath, finderArgs);
7592
7593 throw processException(e);
7594 }
7595 finally {
7596 closeSession(session);
7597 }
7598 }
7599
7600 return count.intValue();
7601 }
7602
7603
7611 @Override
7612 public int filterCountByG_C_L(long groupId, long categoryId,
7613 Date lastPostDate) {
7614 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7615 return countByG_C_L(groupId, categoryId, lastPostDate);
7616 }
7617
7618 StringBundler query = new StringBundler(4);
7619
7620 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
7621
7622 query.append(_FINDER_COLUMN_G_C_L_GROUPID_2);
7623
7624 query.append(_FINDER_COLUMN_G_C_L_CATEGORYID_2);
7625
7626 boolean bindLastPostDate = false;
7627
7628 if (lastPostDate == null) {
7629 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_1);
7630 }
7631 else {
7632 bindLastPostDate = true;
7633
7634 query.append(_FINDER_COLUMN_G_C_L_LASTPOSTDATE_2);
7635 }
7636
7637 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7638 MBThread.class.getName(),
7639 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7640
7641 Session session = null;
7642
7643 try {
7644 session = openSession();
7645
7646 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7647
7648 q.addScalar(COUNT_COLUMN_NAME,
7649 com.liferay.portal.kernel.dao.orm.Type.LONG);
7650
7651 QueryPos qPos = QueryPos.getInstance(q);
7652
7653 qPos.add(groupId);
7654
7655 qPos.add(categoryId);
7656
7657 if (bindLastPostDate) {
7658 qPos.add(new Timestamp(lastPostDate.getTime()));
7659 }
7660
7661 Long count = (Long)q.uniqueResult();
7662
7663 return count.intValue();
7664 }
7665 catch (Exception e) {
7666 throw processException(e);
7667 }
7668 finally {
7669 closeSession(session);
7670 }
7671 }
7672
7673 private static final String _FINDER_COLUMN_G_C_L_GROUPID_2 = "mbThread.groupId = ? AND ";
7674 private static final String _FINDER_COLUMN_G_C_L_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
7675 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_1 = "mbThread.lastPostDate IS NULL";
7676 private static final String _FINDER_COLUMN_G_C_L_LASTPOSTDATE_2 = "mbThread.lastPostDate = ?";
7677 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7678 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7679 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
7680 new String[] {
7681 Long.class.getName(), Long.class.getName(),
7682 Integer.class.getName(),
7683
7684 Integer.class.getName(), Integer.class.getName(),
7685 OrderByComparator.class.getName()
7686 });
7687 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7688 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
7689 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
7690 new String[] {
7691 Long.class.getName(), Long.class.getName(),
7692 Integer.class.getName()
7693 },
7694 MBThreadModelImpl.GROUPID_COLUMN_BITMASK |
7695 MBThreadModelImpl.CATEGORYID_COLUMN_BITMASK |
7696 MBThreadModelImpl.STATUS_COLUMN_BITMASK |
7697 MBThreadModelImpl.PRIORITY_COLUMN_BITMASK |
7698 MBThreadModelImpl.LASTPOSTDATE_COLUMN_BITMASK);
7699 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7700 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7701 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
7702 new String[] {
7703 Long.class.getName(), Long.class.getName(),
7704 Integer.class.getName()
7705 });
7706 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
7707 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
7708 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_S",
7709 new String[] {
7710 Long.class.getName(), Long.class.getName(),
7711 Integer.class.getName()
7712 });
7713
7714
7722 @Override
7723 public List<MBThread> findByG_C_S(long groupId, long categoryId, int status) {
7724 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
7725 QueryUtil.ALL_POS, null);
7726 }
7727
7728
7742 @Override
7743 public List<MBThread> findByG_C_S(long groupId, long categoryId,
7744 int status, int start, int end) {
7745 return findByG_C_S(groupId, categoryId, status, start, end, null);
7746 }
7747
7748
7763 @Override
7764 public List<MBThread> findByG_C_S(long groupId, long categoryId,
7765 int status, int start, int end,
7766 OrderByComparator<MBThread> orderByComparator) {
7767 boolean pagination = true;
7768 FinderPath finderPath = null;
7769 Object[] finderArgs = null;
7770
7771 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7772 (orderByComparator == null)) {
7773 pagination = false;
7774 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
7775 finderArgs = new Object[] { groupId, categoryId, status };
7776 }
7777 else {
7778 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
7779 finderArgs = new Object[] {
7780 groupId, categoryId, status,
7781
7782 start, end, orderByComparator
7783 };
7784 }
7785
7786 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
7787 finderArgs, this);
7788
7789 if ((list != null) && !list.isEmpty()) {
7790 for (MBThread mbThread : list) {
7791 if ((groupId != mbThread.getGroupId()) ||
7792 (categoryId != mbThread.getCategoryId()) ||
7793 (status != mbThread.getStatus())) {
7794 list = null;
7795
7796 break;
7797 }
7798 }
7799 }
7800
7801 if (list == null) {
7802 StringBundler query = null;
7803
7804 if (orderByComparator != null) {
7805 query = new StringBundler(5 +
7806 (orderByComparator.getOrderByFields().length * 3));
7807 }
7808 else {
7809 query = new StringBundler(5);
7810 }
7811
7812 query.append(_SQL_SELECT_MBTHREAD_WHERE);
7813
7814 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
7815
7816 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
7817
7818 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
7819
7820 if (orderByComparator != null) {
7821 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7822 orderByComparator);
7823 }
7824 else
7825 if (pagination) {
7826 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
7827 }
7828
7829 String sql = query.toString();
7830
7831 Session session = null;
7832
7833 try {
7834 session = openSession();
7835
7836 Query q = session.createQuery(sql);
7837
7838 QueryPos qPos = QueryPos.getInstance(q);
7839
7840 qPos.add(groupId);
7841
7842 qPos.add(categoryId);
7843
7844 qPos.add(status);
7845
7846 if (!pagination) {
7847 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7848 start, end, false);
7849
7850 Collections.sort(list);
7851
7852 list = Collections.unmodifiableList(list);
7853 }
7854 else {
7855 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
7856 start, end);
7857 }
7858
7859 cacheResult(list);
7860
7861 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7862 }
7863 catch (Exception e) {
7864 FinderCacheUtil.removeResult(finderPath, finderArgs);
7865
7866 throw processException(e);
7867 }
7868 finally {
7869 closeSession(session);
7870 }
7871 }
7872
7873 return list;
7874 }
7875
7876
7886 @Override
7887 public MBThread findByG_C_S_First(long groupId, long categoryId,
7888 int status, OrderByComparator<MBThread> orderByComparator)
7889 throws NoSuchThreadException {
7890 MBThread mbThread = fetchByG_C_S_First(groupId, categoryId, status,
7891 orderByComparator);
7892
7893 if (mbThread != null) {
7894 return mbThread;
7895 }
7896
7897 StringBundler msg = new StringBundler(8);
7898
7899 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7900
7901 msg.append("groupId=");
7902 msg.append(groupId);
7903
7904 msg.append(", categoryId=");
7905 msg.append(categoryId);
7906
7907 msg.append(", status=");
7908 msg.append(status);
7909
7910 msg.append(StringPool.CLOSE_CURLY_BRACE);
7911
7912 throw new NoSuchThreadException(msg.toString());
7913 }
7914
7915
7924 @Override
7925 public MBThread fetchByG_C_S_First(long groupId, long categoryId,
7926 int status, OrderByComparator<MBThread> orderByComparator) {
7927 List<MBThread> list = findByG_C_S(groupId, categoryId, status, 0, 1,
7928 orderByComparator);
7929
7930 if (!list.isEmpty()) {
7931 return list.get(0);
7932 }
7933
7934 return null;
7935 }
7936
7937
7947 @Override
7948 public MBThread findByG_C_S_Last(long groupId, long categoryId, int status,
7949 OrderByComparator<MBThread> orderByComparator)
7950 throws NoSuchThreadException {
7951 MBThread mbThread = fetchByG_C_S_Last(groupId, categoryId, status,
7952 orderByComparator);
7953
7954 if (mbThread != null) {
7955 return mbThread;
7956 }
7957
7958 StringBundler msg = new StringBundler(8);
7959
7960 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7961
7962 msg.append("groupId=");
7963 msg.append(groupId);
7964
7965 msg.append(", categoryId=");
7966 msg.append(categoryId);
7967
7968 msg.append(", status=");
7969 msg.append(status);
7970
7971 msg.append(StringPool.CLOSE_CURLY_BRACE);
7972
7973 throw new NoSuchThreadException(msg.toString());
7974 }
7975
7976
7985 @Override
7986 public MBThread fetchByG_C_S_Last(long groupId, long categoryId,
7987 int status, OrderByComparator<MBThread> orderByComparator) {
7988 int count = countByG_C_S(groupId, categoryId, status);
7989
7990 if (count == 0) {
7991 return null;
7992 }
7993
7994 List<MBThread> list = findByG_C_S(groupId, categoryId, status,
7995 count - 1, count, orderByComparator);
7996
7997 if (!list.isEmpty()) {
7998 return list.get(0);
7999 }
8000
8001 return null;
8002 }
8003
8004
8015 @Override
8016 public MBThread[] findByG_C_S_PrevAndNext(long threadId, long groupId,
8017 long categoryId, int status,
8018 OrderByComparator<MBThread> orderByComparator)
8019 throws NoSuchThreadException {
8020 MBThread mbThread = findByPrimaryKey(threadId);
8021
8022 Session session = null;
8023
8024 try {
8025 session = openSession();
8026
8027 MBThread[] array = new MBThreadImpl[3];
8028
8029 array[0] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8030 categoryId, status, orderByComparator, true);
8031
8032 array[1] = mbThread;
8033
8034 array[2] = getByG_C_S_PrevAndNext(session, mbThread, groupId,
8035 categoryId, status, orderByComparator, false);
8036
8037 return array;
8038 }
8039 catch (Exception e) {
8040 throw processException(e);
8041 }
8042 finally {
8043 closeSession(session);
8044 }
8045 }
8046
8047 protected MBThread getByG_C_S_PrevAndNext(Session session,
8048 MBThread mbThread, long groupId, long categoryId, int status,
8049 OrderByComparator<MBThread> orderByComparator, boolean previous) {
8050 StringBundler query = null;
8051
8052 if (orderByComparator != null) {
8053 query = new StringBundler(6 +
8054 (orderByComparator.getOrderByFields().length * 6));
8055 }
8056 else {
8057 query = new StringBundler(3);
8058 }
8059
8060 query.append(_SQL_SELECT_MBTHREAD_WHERE);
8061
8062 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8063
8064 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8065
8066 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8067
8068 if (orderByComparator != null) {
8069 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8070
8071 if (orderByConditionFields.length > 0) {
8072 query.append(WHERE_AND);
8073 }
8074
8075 for (int i = 0; i < orderByConditionFields.length; i++) {
8076 query.append(_ORDER_BY_ENTITY_ALIAS);
8077 query.append(orderByConditionFields[i]);
8078
8079 if ((i + 1) < orderByConditionFields.length) {
8080 if (orderByComparator.isAscending() ^ previous) {
8081 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8082 }
8083 else {
8084 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8085 }
8086 }
8087 else {
8088 if (orderByComparator.isAscending() ^ previous) {
8089 query.append(WHERE_GREATER_THAN);
8090 }
8091 else {
8092 query.append(WHERE_LESSER_THAN);
8093 }
8094 }
8095 }
8096
8097 query.append(ORDER_BY_CLAUSE);
8098
8099 String[] orderByFields = orderByComparator.getOrderByFields();
8100
8101 for (int i = 0; i < orderByFields.length; i++) {
8102 query.append(_ORDER_BY_ENTITY_ALIAS);
8103 query.append(orderByFields[i]);
8104
8105 if ((i + 1) < orderByFields.length) {
8106 if (orderByComparator.isAscending() ^ previous) {
8107 query.append(ORDER_BY_ASC_HAS_NEXT);
8108 }
8109 else {
8110 query.append(ORDER_BY_DESC_HAS_NEXT);
8111 }
8112 }
8113 else {
8114 if (orderByComparator.isAscending() ^ previous) {
8115 query.append(ORDER_BY_ASC);
8116 }
8117 else {
8118 query.append(ORDER_BY_DESC);
8119 }
8120 }
8121 }
8122 }
8123 else {
8124 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8125 }
8126
8127 String sql = query.toString();
8128
8129 Query q = session.createQuery(sql);
8130
8131 q.setFirstResult(0);
8132 q.setMaxResults(2);
8133
8134 QueryPos qPos = QueryPos.getInstance(q);
8135
8136 qPos.add(groupId);
8137
8138 qPos.add(categoryId);
8139
8140 qPos.add(status);
8141
8142 if (orderByComparator != null) {
8143 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8144
8145 for (Object value : values) {
8146 qPos.add(value);
8147 }
8148 }
8149
8150 List<MBThread> list = q.list();
8151
8152 if (list.size() == 2) {
8153 return list.get(1);
8154 }
8155 else {
8156 return null;
8157 }
8158 }
8159
8160
8168 @Override
8169 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8170 int status) {
8171 return filterFindByG_C_S(groupId, categoryId, status,
8172 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8173 }
8174
8175
8189 @Override
8190 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8191 int status, int start, int end) {
8192 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
8193 }
8194
8195
8210 @Override
8211 public List<MBThread> filterFindByG_C_S(long groupId, long categoryId,
8212 int status, int start, int end,
8213 OrderByComparator<MBThread> orderByComparator) {
8214 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8215 return findByG_C_S(groupId, categoryId, status, start, end,
8216 orderByComparator);
8217 }
8218
8219 StringBundler query = null;
8220
8221 if (orderByComparator != null) {
8222 query = new StringBundler(5 +
8223 (orderByComparator.getOrderByFields().length * 3));
8224 }
8225 else {
8226 query = new StringBundler(5);
8227 }
8228
8229 if (getDB().isSupportsInlineDistinct()) {
8230 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8231 }
8232 else {
8233 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8234 }
8235
8236 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8237
8238 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8239
8240 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8241
8242 if (!getDB().isSupportsInlineDistinct()) {
8243 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8244 }
8245
8246 if (orderByComparator != null) {
8247 if (getDB().isSupportsInlineDistinct()) {
8248 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8249 orderByComparator, true);
8250 }
8251 else {
8252 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8253 orderByComparator, true);
8254 }
8255 }
8256 else {
8257 if (getDB().isSupportsInlineDistinct()) {
8258 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8259 }
8260 else {
8261 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8262 }
8263 }
8264
8265 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8266 MBThread.class.getName(),
8267 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8268
8269 Session session = null;
8270
8271 try {
8272 session = openSession();
8273
8274 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8275
8276 if (getDB().isSupportsInlineDistinct()) {
8277 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8278 }
8279 else {
8280 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8281 }
8282
8283 QueryPos qPos = QueryPos.getInstance(q);
8284
8285 qPos.add(groupId);
8286
8287 qPos.add(categoryId);
8288
8289 qPos.add(status);
8290
8291 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8292 }
8293 catch (Exception e) {
8294 throw processException(e);
8295 }
8296 finally {
8297 closeSession(session);
8298 }
8299 }
8300
8301
8312 @Override
8313 public MBThread[] filterFindByG_C_S_PrevAndNext(long threadId,
8314 long groupId, long categoryId, int status,
8315 OrderByComparator<MBThread> orderByComparator)
8316 throws NoSuchThreadException {
8317 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8318 return findByG_C_S_PrevAndNext(threadId, groupId, categoryId,
8319 status, orderByComparator);
8320 }
8321
8322 MBThread mbThread = findByPrimaryKey(threadId);
8323
8324 Session session = null;
8325
8326 try {
8327 session = openSession();
8328
8329 MBThread[] array = new MBThreadImpl[3];
8330
8331 array[0] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8332 categoryId, status, orderByComparator, true);
8333
8334 array[1] = mbThread;
8335
8336 array[2] = filterGetByG_C_S_PrevAndNext(session, mbThread, groupId,
8337 categoryId, status, orderByComparator, false);
8338
8339 return array;
8340 }
8341 catch (Exception e) {
8342 throw processException(e);
8343 }
8344 finally {
8345 closeSession(session);
8346 }
8347 }
8348
8349 protected MBThread filterGetByG_C_S_PrevAndNext(Session session,
8350 MBThread mbThread, long groupId, long categoryId, int status,
8351 OrderByComparator<MBThread> orderByComparator, boolean previous) {
8352 StringBundler query = null;
8353
8354 if (orderByComparator != null) {
8355 query = new StringBundler(6 +
8356 (orderByComparator.getOrderByFields().length * 6));
8357 }
8358 else {
8359 query = new StringBundler(3);
8360 }
8361
8362 if (getDB().isSupportsInlineDistinct()) {
8363 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8364 }
8365 else {
8366 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8367 }
8368
8369 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8370
8371 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8372
8373 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8374
8375 if (!getDB().isSupportsInlineDistinct()) {
8376 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8377 }
8378
8379 if (orderByComparator != null) {
8380 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8381
8382 if (orderByConditionFields.length > 0) {
8383 query.append(WHERE_AND);
8384 }
8385
8386 for (int i = 0; i < orderByConditionFields.length; i++) {
8387 if (getDB().isSupportsInlineDistinct()) {
8388 query.append(_ORDER_BY_ENTITY_ALIAS);
8389 }
8390 else {
8391 query.append(_ORDER_BY_ENTITY_TABLE);
8392 }
8393
8394 query.append(orderByConditionFields[i]);
8395
8396 if ((i + 1) < orderByConditionFields.length) {
8397 if (orderByComparator.isAscending() ^ previous) {
8398 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8399 }
8400 else {
8401 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8402 }
8403 }
8404 else {
8405 if (orderByComparator.isAscending() ^ previous) {
8406 query.append(WHERE_GREATER_THAN);
8407 }
8408 else {
8409 query.append(WHERE_LESSER_THAN);
8410 }
8411 }
8412 }
8413
8414 query.append(ORDER_BY_CLAUSE);
8415
8416 String[] orderByFields = orderByComparator.getOrderByFields();
8417
8418 for (int i = 0; i < orderByFields.length; i++) {
8419 if (getDB().isSupportsInlineDistinct()) {
8420 query.append(_ORDER_BY_ENTITY_ALIAS);
8421 }
8422 else {
8423 query.append(_ORDER_BY_ENTITY_TABLE);
8424 }
8425
8426 query.append(orderByFields[i]);
8427
8428 if ((i + 1) < orderByFields.length) {
8429 if (orderByComparator.isAscending() ^ previous) {
8430 query.append(ORDER_BY_ASC_HAS_NEXT);
8431 }
8432 else {
8433 query.append(ORDER_BY_DESC_HAS_NEXT);
8434 }
8435 }
8436 else {
8437 if (orderByComparator.isAscending() ^ previous) {
8438 query.append(ORDER_BY_ASC);
8439 }
8440 else {
8441 query.append(ORDER_BY_DESC);
8442 }
8443 }
8444 }
8445 }
8446 else {
8447 if (getDB().isSupportsInlineDistinct()) {
8448 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8449 }
8450 else {
8451 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8452 }
8453 }
8454
8455 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8456 MBThread.class.getName(),
8457 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8458
8459 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8460
8461 q.setFirstResult(0);
8462 q.setMaxResults(2);
8463
8464 if (getDB().isSupportsInlineDistinct()) {
8465 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8466 }
8467 else {
8468 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8469 }
8470
8471 QueryPos qPos = QueryPos.getInstance(q);
8472
8473 qPos.add(groupId);
8474
8475 qPos.add(categoryId);
8476
8477 qPos.add(status);
8478
8479 if (orderByComparator != null) {
8480 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
8481
8482 for (Object value : values) {
8483 qPos.add(value);
8484 }
8485 }
8486
8487 List<MBThread> list = q.list();
8488
8489 if (list.size() == 2) {
8490 return list.get(1);
8491 }
8492 else {
8493 return null;
8494 }
8495 }
8496
8497
8505 @Override
8506 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8507 int status) {
8508 return filterFindByG_C_S(groupId, categoryIds, status,
8509 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8510 }
8511
8512
8526 @Override
8527 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8528 int status, int start, int end) {
8529 return filterFindByG_C_S(groupId, categoryIds, status, start, end, null);
8530 }
8531
8532
8547 @Override
8548 public List<MBThread> filterFindByG_C_S(long groupId, long[] categoryIds,
8549 int status, int start, int end,
8550 OrderByComparator<MBThread> orderByComparator) {
8551 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8552 return findByG_C_S(groupId, categoryIds, status, start, end,
8553 orderByComparator);
8554 }
8555
8556 if (categoryIds == null) {
8557 categoryIds = new long[0];
8558 }
8559 else {
8560 categoryIds = ArrayUtil.unique(categoryIds);
8561 }
8562
8563 StringBundler query = new StringBundler();
8564
8565 if (getDB().isSupportsInlineDistinct()) {
8566 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
8567 }
8568 else {
8569 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
8570 }
8571
8572 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8573
8574 if (categoryIds.length > 0) {
8575 query.append(StringPool.OPEN_PARENTHESIS);
8576
8577 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
8578
8579 query.append(StringUtil.merge(categoryIds));
8580
8581 query.append(StringPool.CLOSE_PARENTHESIS);
8582
8583 query.append(StringPool.CLOSE_PARENTHESIS);
8584
8585 query.append(WHERE_AND);
8586 }
8587
8588 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8589
8590 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
8591 query.index() - 1);
8592
8593 if (!getDB().isSupportsInlineDistinct()) {
8594 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
8595 }
8596
8597 if (orderByComparator != null) {
8598 if (getDB().isSupportsInlineDistinct()) {
8599 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8600 orderByComparator, true);
8601 }
8602 else {
8603 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8604 orderByComparator, true);
8605 }
8606 }
8607 else {
8608 if (getDB().isSupportsInlineDistinct()) {
8609 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8610 }
8611 else {
8612 query.append(MBThreadModelImpl.ORDER_BY_SQL);
8613 }
8614 }
8615
8616 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8617 MBThread.class.getName(),
8618 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8619
8620 Session session = null;
8621
8622 try {
8623 session = openSession();
8624
8625 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8626
8627 if (getDB().isSupportsInlineDistinct()) {
8628 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
8629 }
8630 else {
8631 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
8632 }
8633
8634 QueryPos qPos = QueryPos.getInstance(q);
8635
8636 qPos.add(groupId);
8637
8638 qPos.add(status);
8639
8640 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
8641 }
8642 catch (Exception e) {
8643 throw processException(e);
8644 }
8645 finally {
8646 closeSession(session);
8647 }
8648 }
8649
8650
8662 @Override
8663 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8664 int status) {
8665 return findByG_C_S(groupId, categoryIds, status, QueryUtil.ALL_POS,
8666 QueryUtil.ALL_POS, null);
8667 }
8668
8669
8683 @Override
8684 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8685 int status, int start, int end) {
8686 return findByG_C_S(groupId, categoryIds, status, start, end, null);
8687 }
8688
8689
8704 @Override
8705 public List<MBThread> findByG_C_S(long groupId, long[] categoryIds,
8706 int status, int start, int end,
8707 OrderByComparator<MBThread> orderByComparator) {
8708 if (categoryIds == null) {
8709 categoryIds = new long[0];
8710 }
8711 else {
8712 categoryIds = ArrayUtil.unique(categoryIds);
8713 }
8714
8715 if (categoryIds.length == 1) {
8716 return findByG_C_S(groupId, categoryIds[0], status, start, end,
8717 orderByComparator);
8718 }
8719
8720 boolean pagination = true;
8721 Object[] finderArgs = null;
8722
8723 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8724 (orderByComparator == null)) {
8725 pagination = false;
8726 finderArgs = new Object[] {
8727 groupId, StringUtil.merge(categoryIds), status
8728 };
8729 }
8730 else {
8731 finderArgs = new Object[] {
8732 groupId, StringUtil.merge(categoryIds), status,
8733
8734 start, end, orderByComparator
8735 };
8736 }
8737
8738 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8739 finderArgs, this);
8740
8741 if ((list != null) && !list.isEmpty()) {
8742 for (MBThread mbThread : list) {
8743 if ((groupId != mbThread.getGroupId()) ||
8744 !ArrayUtil.contains(categoryIds,
8745 mbThread.getCategoryId()) ||
8746 (status != mbThread.getStatus())) {
8747 list = null;
8748
8749 break;
8750 }
8751 }
8752 }
8753
8754 if (list == null) {
8755 StringBundler query = new StringBundler();
8756
8757 query.append(_SQL_SELECT_MBTHREAD_WHERE);
8758
8759 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8760
8761 if (categoryIds.length > 0) {
8762 query.append(StringPool.OPEN_PARENTHESIS);
8763
8764 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
8765
8766 query.append(StringUtil.merge(categoryIds));
8767
8768 query.append(StringPool.CLOSE_PARENTHESIS);
8769
8770 query.append(StringPool.CLOSE_PARENTHESIS);
8771
8772 query.append(WHERE_AND);
8773 }
8774
8775 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8776
8777 query.setStringAt(removeConjunction(query.stringAt(query.index() -
8778 1)), query.index() - 1);
8779
8780 if (orderByComparator != null) {
8781 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8782 orderByComparator);
8783 }
8784 else
8785 if (pagination) {
8786 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
8787 }
8788
8789 String sql = query.toString();
8790
8791 Session session = null;
8792
8793 try {
8794 session = openSession();
8795
8796 Query q = session.createQuery(sql);
8797
8798 QueryPos qPos = QueryPos.getInstance(q);
8799
8800 qPos.add(groupId);
8801
8802 qPos.add(status);
8803
8804 if (!pagination) {
8805 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8806 start, end, false);
8807
8808 Collections.sort(list);
8809
8810 list = Collections.unmodifiableList(list);
8811 }
8812 else {
8813 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
8814 start, end);
8815 }
8816
8817 cacheResult(list);
8818
8819 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8820 finderArgs, list);
8821 }
8822 catch (Exception e) {
8823 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S,
8824 finderArgs);
8825
8826 throw processException(e);
8827 }
8828 finally {
8829 closeSession(session);
8830 }
8831 }
8832
8833 return list;
8834 }
8835
8836
8843 @Override
8844 public void removeByG_C_S(long groupId, long categoryId, int status) {
8845 for (MBThread mbThread : findByG_C_S(groupId, categoryId, status,
8846 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8847 remove(mbThread);
8848 }
8849 }
8850
8851
8859 @Override
8860 public int countByG_C_S(long groupId, long categoryId, int status) {
8861 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
8862
8863 Object[] finderArgs = new Object[] { groupId, categoryId, status };
8864
8865 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8866 this);
8867
8868 if (count == null) {
8869 StringBundler query = new StringBundler(4);
8870
8871 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8872
8873 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8874
8875 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
8876
8877 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8878
8879 String sql = query.toString();
8880
8881 Session session = null;
8882
8883 try {
8884 session = openSession();
8885
8886 Query q = session.createQuery(sql);
8887
8888 QueryPos qPos = QueryPos.getInstance(q);
8889
8890 qPos.add(groupId);
8891
8892 qPos.add(categoryId);
8893
8894 qPos.add(status);
8895
8896 count = (Long)q.uniqueResult();
8897
8898 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8899 }
8900 catch (Exception e) {
8901 FinderCacheUtil.removeResult(finderPath, finderArgs);
8902
8903 throw processException(e);
8904 }
8905 finally {
8906 closeSession(session);
8907 }
8908 }
8909
8910 return count.intValue();
8911 }
8912
8913
8921 @Override
8922 public int countByG_C_S(long groupId, long[] categoryIds, int status) {
8923 if (categoryIds == null) {
8924 categoryIds = new long[0];
8925 }
8926 else {
8927 categoryIds = ArrayUtil.unique(categoryIds);
8928 }
8929
8930 Object[] finderArgs = new Object[] {
8931 groupId, StringUtil.merge(categoryIds), status
8932 };
8933
8934 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8935 finderArgs, this);
8936
8937 if (count == null) {
8938 StringBundler query = new StringBundler();
8939
8940 query.append(_SQL_COUNT_MBTHREAD_WHERE);
8941
8942 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
8943
8944 if (categoryIds.length > 0) {
8945 query.append(StringPool.OPEN_PARENTHESIS);
8946
8947 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
8948
8949 query.append(StringUtil.merge(categoryIds));
8950
8951 query.append(StringPool.CLOSE_PARENTHESIS);
8952
8953 query.append(StringPool.CLOSE_PARENTHESIS);
8954
8955 query.append(WHERE_AND);
8956 }
8957
8958 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
8959
8960 query.setStringAt(removeConjunction(query.stringAt(query.index() -
8961 1)), query.index() - 1);
8962
8963 String sql = query.toString();
8964
8965 Session session = null;
8966
8967 try {
8968 session = openSession();
8969
8970 Query q = session.createQuery(sql);
8971
8972 QueryPos qPos = QueryPos.getInstance(q);
8973
8974 qPos.add(groupId);
8975
8976 qPos.add(status);
8977
8978 count = (Long)q.uniqueResult();
8979
8980 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8981 finderArgs, count);
8982 }
8983 catch (Exception e) {
8984 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_S,
8985 finderArgs);
8986
8987 throw processException(e);
8988 }
8989 finally {
8990 closeSession(session);
8991 }
8992 }
8993
8994 return count.intValue();
8995 }
8996
8997
9005 @Override
9006 public int filterCountByG_C_S(long groupId, long categoryId, int status) {
9007 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9008 return countByG_C_S(groupId, categoryId, status);
9009 }
9010
9011 StringBundler query = new StringBundler(4);
9012
9013 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9014
9015 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9016
9017 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
9018
9019 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9020
9021 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9022 MBThread.class.getName(),
9023 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9024
9025 Session session = null;
9026
9027 try {
9028 session = openSession();
9029
9030 SQLQuery q = session.createSynchronizedSQLQuery(sql);
9031
9032 q.addScalar(COUNT_COLUMN_NAME,
9033 com.liferay.portal.kernel.dao.orm.Type.LONG);
9034
9035 QueryPos qPos = QueryPos.getInstance(q);
9036
9037 qPos.add(groupId);
9038
9039 qPos.add(categoryId);
9040
9041 qPos.add(status);
9042
9043 Long count = (Long)q.uniqueResult();
9044
9045 return count.intValue();
9046 }
9047 catch (Exception e) {
9048 throw processException(e);
9049 }
9050 finally {
9051 closeSession(session);
9052 }
9053 }
9054
9055
9063 @Override
9064 public int filterCountByG_C_S(long groupId, long[] categoryIds, int status) {
9065 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9066 return countByG_C_S(groupId, categoryIds, status);
9067 }
9068
9069 if (categoryIds == null) {
9070 categoryIds = new long[0];
9071 }
9072 else {
9073 categoryIds = ArrayUtil.unique(categoryIds);
9074 }
9075
9076 StringBundler query = new StringBundler();
9077
9078 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
9079
9080 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
9081
9082 if (categoryIds.length > 0) {
9083 query.append(StringPool.OPEN_PARENTHESIS);
9084
9085 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_7);
9086
9087 query.append(StringUtil.merge(categoryIds));
9088
9089 query.append(StringPool.CLOSE_PARENTHESIS);
9090
9091 query.append(StringPool.CLOSE_PARENTHESIS);
9092
9093 query.append(WHERE_AND);
9094 }
9095
9096 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
9097
9098 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
9099 query.index() - 1);
9100
9101 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9102 MBThread.class.getName(),
9103 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9104
9105 Session session = null;
9106
9107 try {
9108 session = openSession();
9109
9110 SQLQuery q = session.createSynchronizedSQLQuery(sql);
9111
9112 q.addScalar(COUNT_COLUMN_NAME,
9113 com.liferay.portal.kernel.dao.orm.Type.LONG);
9114
9115 QueryPos qPos = QueryPos.getInstance(q);
9116
9117 qPos.add(groupId);
9118
9119 qPos.add(status);
9120
9121 Long count = (Long)q.uniqueResult();
9122
9123 return count.intValue();
9124 }
9125 catch (Exception e) {
9126 throw processException(e);
9127 }
9128 finally {
9129 closeSession(session);
9130 }
9131 }
9132
9133 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbThread.groupId = ? AND ";
9134 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
9135 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_7 = "mbThread.categoryId IN (";
9136 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbThread.status = ?";
9137 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9138 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
9139 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_NotS",
9140 new String[] {
9141 Long.class.getName(), Long.class.getName(),
9142 Integer.class.getName(),
9143
9144 Integer.class.getName(), Integer.class.getName(),
9145 OrderByComparator.class.getName()
9146 });
9147 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS =
9148 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
9149 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
9150 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_C_NotS",
9151 new String[] {
9152 Long.class.getName(), Long.class.getName(),
9153 Integer.class.getName()
9154 });
9155
9156
9164 @Override
9165 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9166 int status) {
9167 return findByG_C_NotS(groupId, categoryId, status, QueryUtil.ALL_POS,
9168 QueryUtil.ALL_POS, null);
9169 }
9170
9171
9185 @Override
9186 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9187 int status, int start, int end) {
9188 return findByG_C_NotS(groupId, categoryId, status, start, end, null);
9189 }
9190
9191
9206 @Override
9207 public List<MBThread> findByG_C_NotS(long groupId, long categoryId,
9208 int status, int start, int end,
9209 OrderByComparator<MBThread> orderByComparator) {
9210 boolean pagination = true;
9211 FinderPath finderPath = null;
9212 Object[] finderArgs = null;
9213
9214 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS;
9215 finderArgs = new Object[] {
9216 groupId, categoryId, status,
9217
9218 start, end, orderByComparator
9219 };
9220
9221 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
9222 finderArgs, this);
9223
9224 if ((list != null) && !list.isEmpty()) {
9225 for (MBThread mbThread : list) {
9226 if ((groupId != mbThread.getGroupId()) ||
9227 (categoryId != mbThread.getCategoryId()) ||
9228 (status == mbThread.getStatus())) {
9229 list = null;
9230
9231 break;
9232 }
9233 }
9234 }
9235
9236 if (list == null) {
9237 StringBundler query = null;
9238
9239 if (orderByComparator != null) {
9240 query = new StringBundler(5 +
9241 (orderByComparator.getOrderByFields().length * 3));
9242 }
9243 else {
9244 query = new StringBundler(5);
9245 }
9246
9247 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9248
9249 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9250
9251 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9252
9253 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9254
9255 if (orderByComparator != null) {
9256 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9257 orderByComparator);
9258 }
9259 else
9260 if (pagination) {
9261 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9262 }
9263
9264 String sql = query.toString();
9265
9266 Session session = null;
9267
9268 try {
9269 session = openSession();
9270
9271 Query q = session.createQuery(sql);
9272
9273 QueryPos qPos = QueryPos.getInstance(q);
9274
9275 qPos.add(groupId);
9276
9277 qPos.add(categoryId);
9278
9279 qPos.add(status);
9280
9281 if (!pagination) {
9282 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9283 start, end, false);
9284
9285 Collections.sort(list);
9286
9287 list = Collections.unmodifiableList(list);
9288 }
9289 else {
9290 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
9291 start, end);
9292 }
9293
9294 cacheResult(list);
9295
9296 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9297 }
9298 catch (Exception e) {
9299 FinderCacheUtil.removeResult(finderPath, finderArgs);
9300
9301 throw processException(e);
9302 }
9303 finally {
9304 closeSession(session);
9305 }
9306 }
9307
9308 return list;
9309 }
9310
9311
9321 @Override
9322 public MBThread findByG_C_NotS_First(long groupId, long categoryId,
9323 int status, OrderByComparator<MBThread> orderByComparator)
9324 throws NoSuchThreadException {
9325 MBThread mbThread = fetchByG_C_NotS_First(groupId, categoryId, status,
9326 orderByComparator);
9327
9328 if (mbThread != null) {
9329 return mbThread;
9330 }
9331
9332 StringBundler msg = new StringBundler(8);
9333
9334 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9335
9336 msg.append("groupId=");
9337 msg.append(groupId);
9338
9339 msg.append(", categoryId=");
9340 msg.append(categoryId);
9341
9342 msg.append(", status=");
9343 msg.append(status);
9344
9345 msg.append(StringPool.CLOSE_CURLY_BRACE);
9346
9347 throw new NoSuchThreadException(msg.toString());
9348 }
9349
9350
9359 @Override
9360 public MBThread fetchByG_C_NotS_First(long groupId, long categoryId,
9361 int status, OrderByComparator<MBThread> orderByComparator) {
9362 List<MBThread> list = findByG_C_NotS(groupId, categoryId, status, 0, 1,
9363 orderByComparator);
9364
9365 if (!list.isEmpty()) {
9366 return list.get(0);
9367 }
9368
9369 return null;
9370 }
9371
9372
9382 @Override
9383 public MBThread findByG_C_NotS_Last(long groupId, long categoryId,
9384 int status, OrderByComparator<MBThread> orderByComparator)
9385 throws NoSuchThreadException {
9386 MBThread mbThread = fetchByG_C_NotS_Last(groupId, categoryId, status,
9387 orderByComparator);
9388
9389 if (mbThread != null) {
9390 return mbThread;
9391 }
9392
9393 StringBundler msg = new StringBundler(8);
9394
9395 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9396
9397 msg.append("groupId=");
9398 msg.append(groupId);
9399
9400 msg.append(", categoryId=");
9401 msg.append(categoryId);
9402
9403 msg.append(", status=");
9404 msg.append(status);
9405
9406 msg.append(StringPool.CLOSE_CURLY_BRACE);
9407
9408 throw new NoSuchThreadException(msg.toString());
9409 }
9410
9411
9420 @Override
9421 public MBThread fetchByG_C_NotS_Last(long groupId, long categoryId,
9422 int status, OrderByComparator<MBThread> orderByComparator) {
9423 int count = countByG_C_NotS(groupId, categoryId, status);
9424
9425 if (count == 0) {
9426 return null;
9427 }
9428
9429 List<MBThread> list = findByG_C_NotS(groupId, categoryId, status,
9430 count - 1, count, orderByComparator);
9431
9432 if (!list.isEmpty()) {
9433 return list.get(0);
9434 }
9435
9436 return null;
9437 }
9438
9439
9450 @Override
9451 public MBThread[] findByG_C_NotS_PrevAndNext(long threadId, long groupId,
9452 long categoryId, int status,
9453 OrderByComparator<MBThread> orderByComparator)
9454 throws NoSuchThreadException {
9455 MBThread mbThread = findByPrimaryKey(threadId);
9456
9457 Session session = null;
9458
9459 try {
9460 session = openSession();
9461
9462 MBThread[] array = new MBThreadImpl[3];
9463
9464 array[0] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9465 categoryId, status, orderByComparator, true);
9466
9467 array[1] = mbThread;
9468
9469 array[2] = getByG_C_NotS_PrevAndNext(session, mbThread, groupId,
9470 categoryId, status, orderByComparator, false);
9471
9472 return array;
9473 }
9474 catch (Exception e) {
9475 throw processException(e);
9476 }
9477 finally {
9478 closeSession(session);
9479 }
9480 }
9481
9482 protected MBThread getByG_C_NotS_PrevAndNext(Session session,
9483 MBThread mbThread, long groupId, long categoryId, int status,
9484 OrderByComparator<MBThread> orderByComparator, boolean previous) {
9485 StringBundler query = null;
9486
9487 if (orderByComparator != null) {
9488 query = new StringBundler(6 +
9489 (orderByComparator.getOrderByFields().length * 6));
9490 }
9491 else {
9492 query = new StringBundler(3);
9493 }
9494
9495 query.append(_SQL_SELECT_MBTHREAD_WHERE);
9496
9497 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9498
9499 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9500
9501 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9502
9503 if (orderByComparator != null) {
9504 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9505
9506 if (orderByConditionFields.length > 0) {
9507 query.append(WHERE_AND);
9508 }
9509
9510 for (int i = 0; i < orderByConditionFields.length; i++) {
9511 query.append(_ORDER_BY_ENTITY_ALIAS);
9512 query.append(orderByConditionFields[i]);
9513
9514 if ((i + 1) < orderByConditionFields.length) {
9515 if (orderByComparator.isAscending() ^ previous) {
9516 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9517 }
9518 else {
9519 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9520 }
9521 }
9522 else {
9523 if (orderByComparator.isAscending() ^ previous) {
9524 query.append(WHERE_GREATER_THAN);
9525 }
9526 else {
9527 query.append(WHERE_LESSER_THAN);
9528 }
9529 }
9530 }
9531
9532 query.append(ORDER_BY_CLAUSE);
9533
9534 String[] orderByFields = orderByComparator.getOrderByFields();
9535
9536 for (int i = 0; i < orderByFields.length; i++) {
9537 query.append(_ORDER_BY_ENTITY_ALIAS);
9538 query.append(orderByFields[i]);
9539
9540 if ((i + 1) < orderByFields.length) {
9541 if (orderByComparator.isAscending() ^ previous) {
9542 query.append(ORDER_BY_ASC_HAS_NEXT);
9543 }
9544 else {
9545 query.append(ORDER_BY_DESC_HAS_NEXT);
9546 }
9547 }
9548 else {
9549 if (orderByComparator.isAscending() ^ previous) {
9550 query.append(ORDER_BY_ASC);
9551 }
9552 else {
9553 query.append(ORDER_BY_DESC);
9554 }
9555 }
9556 }
9557 }
9558 else {
9559 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9560 }
9561
9562 String sql = query.toString();
9563
9564 Query q = session.createQuery(sql);
9565
9566 q.setFirstResult(0);
9567 q.setMaxResults(2);
9568
9569 QueryPos qPos = QueryPos.getInstance(q);
9570
9571 qPos.add(groupId);
9572
9573 qPos.add(categoryId);
9574
9575 qPos.add(status);
9576
9577 if (orderByComparator != null) {
9578 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9579
9580 for (Object value : values) {
9581 qPos.add(value);
9582 }
9583 }
9584
9585 List<MBThread> list = q.list();
9586
9587 if (list.size() == 2) {
9588 return list.get(1);
9589 }
9590 else {
9591 return null;
9592 }
9593 }
9594
9595
9603 @Override
9604 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9605 int status) {
9606 return filterFindByG_C_NotS(groupId, categoryId, status,
9607 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9608 }
9609
9610
9624 @Override
9625 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9626 int status, int start, int end) {
9627 return filterFindByG_C_NotS(groupId, categoryId, status, start, end,
9628 null);
9629 }
9630
9631
9646 @Override
9647 public List<MBThread> filterFindByG_C_NotS(long groupId, long categoryId,
9648 int status, int start, int end,
9649 OrderByComparator<MBThread> orderByComparator) {
9650 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9651 return findByG_C_NotS(groupId, categoryId, status, start, end,
9652 orderByComparator);
9653 }
9654
9655 StringBundler query = null;
9656
9657 if (orderByComparator != null) {
9658 query = new StringBundler(5 +
9659 (orderByComparator.getOrderByFields().length * 3));
9660 }
9661 else {
9662 query = new StringBundler(5);
9663 }
9664
9665 if (getDB().isSupportsInlineDistinct()) {
9666 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9667 }
9668 else {
9669 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9670 }
9671
9672 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9673
9674 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9675
9676 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9677
9678 if (!getDB().isSupportsInlineDistinct()) {
9679 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9680 }
9681
9682 if (orderByComparator != null) {
9683 if (getDB().isSupportsInlineDistinct()) {
9684 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9685 orderByComparator, true);
9686 }
9687 else {
9688 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9689 orderByComparator, true);
9690 }
9691 }
9692 else {
9693 if (getDB().isSupportsInlineDistinct()) {
9694 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9695 }
9696 else {
9697 query.append(MBThreadModelImpl.ORDER_BY_SQL);
9698 }
9699 }
9700
9701 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9702 MBThread.class.getName(),
9703 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9704
9705 Session session = null;
9706
9707 try {
9708 session = openSession();
9709
9710 SQLQuery q = session.createSynchronizedSQLQuery(sql);
9711
9712 if (getDB().isSupportsInlineDistinct()) {
9713 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
9714 }
9715 else {
9716 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
9717 }
9718
9719 QueryPos qPos = QueryPos.getInstance(q);
9720
9721 qPos.add(groupId);
9722
9723 qPos.add(categoryId);
9724
9725 qPos.add(status);
9726
9727 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
9728 }
9729 catch (Exception e) {
9730 throw processException(e);
9731 }
9732 finally {
9733 closeSession(session);
9734 }
9735 }
9736
9737
9748 @Override
9749 public MBThread[] filterFindByG_C_NotS_PrevAndNext(long threadId,
9750 long groupId, long categoryId, int status,
9751 OrderByComparator<MBThread> orderByComparator)
9752 throws NoSuchThreadException {
9753 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9754 return findByG_C_NotS_PrevAndNext(threadId, groupId, categoryId,
9755 status, orderByComparator);
9756 }
9757
9758 MBThread mbThread = findByPrimaryKey(threadId);
9759
9760 Session session = null;
9761
9762 try {
9763 session = openSession();
9764
9765 MBThread[] array = new MBThreadImpl[3];
9766
9767 array[0] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
9768 groupId, categoryId, status, orderByComparator, true);
9769
9770 array[1] = mbThread;
9771
9772 array[2] = filterGetByG_C_NotS_PrevAndNext(session, mbThread,
9773 groupId, categoryId, status, orderByComparator, false);
9774
9775 return array;
9776 }
9777 catch (Exception e) {
9778 throw processException(e);
9779 }
9780 finally {
9781 closeSession(session);
9782 }
9783 }
9784
9785 protected MBThread filterGetByG_C_NotS_PrevAndNext(Session session,
9786 MBThread mbThread, long groupId, long categoryId, int status,
9787 OrderByComparator<MBThread> orderByComparator, boolean previous) {
9788 StringBundler query = null;
9789
9790 if (orderByComparator != null) {
9791 query = new StringBundler(6 +
9792 (orderByComparator.getOrderByFields().length * 6));
9793 }
9794 else {
9795 query = new StringBundler(3);
9796 }
9797
9798 if (getDB().isSupportsInlineDistinct()) {
9799 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
9800 }
9801 else {
9802 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
9803 }
9804
9805 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
9806
9807 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
9808
9809 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
9810
9811 if (!getDB().isSupportsInlineDistinct()) {
9812 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
9813 }
9814
9815 if (orderByComparator != null) {
9816 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9817
9818 if (orderByConditionFields.length > 0) {
9819 query.append(WHERE_AND);
9820 }
9821
9822 for (int i = 0; i < orderByConditionFields.length; i++) {
9823 if (getDB().isSupportsInlineDistinct()) {
9824 query.append(_ORDER_BY_ENTITY_ALIAS);
9825 }
9826 else {
9827 query.append(_ORDER_BY_ENTITY_TABLE);
9828 }
9829
9830 query.append(orderByConditionFields[i]);
9831
9832 if ((i + 1) < orderByConditionFields.length) {
9833 if (orderByComparator.isAscending() ^ previous) {
9834 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9835 }
9836 else {
9837 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9838 }
9839 }
9840 else {
9841 if (orderByComparator.isAscending() ^ previous) {
9842 query.append(WHERE_GREATER_THAN);
9843 }
9844 else {
9845 query.append(WHERE_LESSER_THAN);
9846 }
9847 }
9848 }
9849
9850 query.append(ORDER_BY_CLAUSE);
9851
9852 String[] orderByFields = orderByComparator.getOrderByFields();
9853
9854 for (int i = 0; i < orderByFields.length; i++) {
9855 if (getDB().isSupportsInlineDistinct()) {
9856 query.append(_ORDER_BY_ENTITY_ALIAS);
9857 }
9858 else {
9859 query.append(_ORDER_BY_ENTITY_TABLE);
9860 }
9861
9862 query.append(orderByFields[i]);
9863
9864 if ((i + 1) < orderByFields.length) {
9865 if (orderByComparator.isAscending() ^ previous) {
9866 query.append(ORDER_BY_ASC_HAS_NEXT);
9867 }
9868 else {
9869 query.append(ORDER_BY_DESC_HAS_NEXT);
9870 }
9871 }
9872 else {
9873 if (orderByComparator.isAscending() ^ previous) {
9874 query.append(ORDER_BY_ASC);
9875 }
9876 else {
9877 query.append(ORDER_BY_DESC);
9878 }
9879 }
9880 }
9881 }
9882 else {
9883 if (getDB().isSupportsInlineDistinct()) {
9884 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
9885 }
9886 else {
9887 query.append(MBThreadModelImpl.ORDER_BY_SQL);
9888 }
9889 }
9890
9891 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9892 MBThread.class.getName(),
9893 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9894
9895 SQLQuery q = session.createSynchronizedSQLQuery(sql);
9896
9897 q.setFirstResult(0);
9898 q.setMaxResults(2);
9899
9900 if (getDB().isSupportsInlineDistinct()) {
9901 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
9902 }
9903 else {
9904 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
9905 }
9906
9907 QueryPos qPos = QueryPos.getInstance(q);
9908
9909 qPos.add(groupId);
9910
9911 qPos.add(categoryId);
9912
9913 qPos.add(status);
9914
9915 if (orderByComparator != null) {
9916 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
9917
9918 for (Object value : values) {
9919 qPos.add(value);
9920 }
9921 }
9922
9923 List<MBThread> list = q.list();
9924
9925 if (list.size() == 2) {
9926 return list.get(1);
9927 }
9928 else {
9929 return null;
9930 }
9931 }
9932
9933
9941 @Override
9942 public List<MBThread> filterFindByG_C_NotS(long groupId,
9943 long[] categoryIds, int status) {
9944 return filterFindByG_C_NotS(groupId, categoryIds, status,
9945 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9946 }
9947
9948
9962 @Override
9963 public List<MBThread> filterFindByG_C_NotS(long groupId,
9964 long[] categoryIds, int status, int start, int end) {
9965 return filterFindByG_C_NotS(groupId, categoryIds, status, start, end,
9966 null);
9967 }
9968
9969
9984 @Override
9985 public List<MBThread> filterFindByG_C_NotS(long groupId,
9986 long[] categoryIds, int status, int start, int end,
9987 OrderByComparator<MBThread> orderByComparator) {
9988 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9989 return findByG_C_NotS(groupId, categoryIds, status, start, end,
9990 orderByComparator);
9991 }
9992
9993 if (categoryIds == null) {
9994 categoryIds = new long[0];
9995 }
9996 else {
9997 categoryIds = ArrayUtil.unique(categoryIds);
9998 }
9999
10000 StringBundler query = new StringBundler();
10001
10002 if (getDB().isSupportsInlineDistinct()) {
10003 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
10004 }
10005 else {
10006 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
10007 }
10008
10009 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10010
10011 if (categoryIds.length > 0) {
10012 query.append(StringPool.OPEN_PARENTHESIS);
10013
10014 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10015
10016 query.append(StringUtil.merge(categoryIds));
10017
10018 query.append(StringPool.CLOSE_PARENTHESIS);
10019
10020 query.append(StringPool.CLOSE_PARENTHESIS);
10021
10022 query.append(WHERE_AND);
10023 }
10024
10025 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10026
10027 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
10028 query.index() - 1);
10029
10030 if (!getDB().isSupportsInlineDistinct()) {
10031 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
10032 }
10033
10034 if (orderByComparator != null) {
10035 if (getDB().isSupportsInlineDistinct()) {
10036 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10037 orderByComparator, true);
10038 }
10039 else {
10040 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
10041 orderByComparator, true);
10042 }
10043 }
10044 else {
10045 if (getDB().isSupportsInlineDistinct()) {
10046 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10047 }
10048 else {
10049 query.append(MBThreadModelImpl.ORDER_BY_SQL);
10050 }
10051 }
10052
10053 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10054 MBThread.class.getName(),
10055 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10056
10057 Session session = null;
10058
10059 try {
10060 session = openSession();
10061
10062 SQLQuery q = session.createSynchronizedSQLQuery(sql);
10063
10064 if (getDB().isSupportsInlineDistinct()) {
10065 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
10066 }
10067 else {
10068 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
10069 }
10070
10071 QueryPos qPos = QueryPos.getInstance(q);
10072
10073 qPos.add(groupId);
10074
10075 qPos.add(status);
10076
10077 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
10078 }
10079 catch (Exception e) {
10080 throw processException(e);
10081 }
10082 finally {
10083 closeSession(session);
10084 }
10085 }
10086
10087
10099 @Override
10100 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10101 int status) {
10102 return findByG_C_NotS(groupId, categoryIds, status, QueryUtil.ALL_POS,
10103 QueryUtil.ALL_POS, null);
10104 }
10105
10106
10120 @Override
10121 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10122 int status, int start, int end) {
10123 return findByG_C_NotS(groupId, categoryIds, status, start, end, null);
10124 }
10125
10126
10141 @Override
10142 public List<MBThread> findByG_C_NotS(long groupId, long[] categoryIds,
10143 int status, int start, int end,
10144 OrderByComparator<MBThread> orderByComparator) {
10145 if (categoryIds == null) {
10146 categoryIds = new long[0];
10147 }
10148 else {
10149 categoryIds = ArrayUtil.unique(categoryIds);
10150 }
10151
10152 if (categoryIds.length == 1) {
10153 return findByG_C_NotS(groupId, categoryIds[0], status, start, end,
10154 orderByComparator);
10155 }
10156
10157 boolean pagination = true;
10158 Object[] finderArgs = null;
10159
10160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10161 (orderByComparator == null)) {
10162 pagination = false;
10163 finderArgs = new Object[] {
10164 groupId, StringUtil.merge(categoryIds), status
10165 };
10166 }
10167 else {
10168 finderArgs = new Object[] {
10169 groupId, StringUtil.merge(categoryIds), status,
10170
10171 start, end, orderByComparator
10172 };
10173 }
10174
10175 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10176 finderArgs, this);
10177
10178 if ((list != null) && !list.isEmpty()) {
10179 for (MBThread mbThread : list) {
10180 if ((groupId != mbThread.getGroupId()) ||
10181 !ArrayUtil.contains(categoryIds,
10182 mbThread.getCategoryId()) ||
10183 (status != mbThread.getStatus())) {
10184 list = null;
10185
10186 break;
10187 }
10188 }
10189 }
10190
10191 if (list == null) {
10192 StringBundler query = new StringBundler();
10193
10194 query.append(_SQL_SELECT_MBTHREAD_WHERE);
10195
10196 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10197
10198 if (categoryIds.length > 0) {
10199 query.append(StringPool.OPEN_PARENTHESIS);
10200
10201 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10202
10203 query.append(StringUtil.merge(categoryIds));
10204
10205 query.append(StringPool.CLOSE_PARENTHESIS);
10206
10207 query.append(StringPool.CLOSE_PARENTHESIS);
10208
10209 query.append(WHERE_AND);
10210 }
10211
10212 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10213
10214 query.setStringAt(removeConjunction(query.stringAt(query.index() -
10215 1)), query.index() - 1);
10216
10217 if (orderByComparator != null) {
10218 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10219 orderByComparator);
10220 }
10221 else
10222 if (pagination) {
10223 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10224 }
10225
10226 String sql = query.toString();
10227
10228 Session session = null;
10229
10230 try {
10231 session = openSession();
10232
10233 Query q = session.createQuery(sql);
10234
10235 QueryPos qPos = QueryPos.getInstance(q);
10236
10237 qPos.add(groupId);
10238
10239 qPos.add(status);
10240
10241 if (!pagination) {
10242 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10243 start, end, false);
10244
10245 Collections.sort(list);
10246
10247 list = Collections.unmodifiableList(list);
10248 }
10249 else {
10250 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10251 start, end);
10252 }
10253
10254 cacheResult(list);
10255
10256 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10257 finderArgs, list);
10258 }
10259 catch (Exception e) {
10260 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_NOTS,
10261 finderArgs);
10262
10263 throw processException(e);
10264 }
10265 finally {
10266 closeSession(session);
10267 }
10268 }
10269
10270 return list;
10271 }
10272
10273
10280 @Override
10281 public void removeByG_C_NotS(long groupId, long categoryId, int status) {
10282 for (MBThread mbThread : findByG_C_NotS(groupId, categoryId, status,
10283 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10284 remove(mbThread);
10285 }
10286 }
10287
10288
10296 @Override
10297 public int countByG_C_NotS(long groupId, long categoryId, int status) {
10298 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS;
10299
10300 Object[] finderArgs = new Object[] { groupId, categoryId, status };
10301
10302 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10303 this);
10304
10305 if (count == null) {
10306 StringBundler query = new StringBundler(4);
10307
10308 query.append(_SQL_COUNT_MBTHREAD_WHERE);
10309
10310 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10311
10312 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10313
10314 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10315
10316 String sql = query.toString();
10317
10318 Session session = null;
10319
10320 try {
10321 session = openSession();
10322
10323 Query q = session.createQuery(sql);
10324
10325 QueryPos qPos = QueryPos.getInstance(q);
10326
10327 qPos.add(groupId);
10328
10329 qPos.add(categoryId);
10330
10331 qPos.add(status);
10332
10333 count = (Long)q.uniqueResult();
10334
10335 FinderCacheUtil.putResult(finderPath, finderArgs, count);
10336 }
10337 catch (Exception e) {
10338 FinderCacheUtil.removeResult(finderPath, finderArgs);
10339
10340 throw processException(e);
10341 }
10342 finally {
10343 closeSession(session);
10344 }
10345 }
10346
10347 return count.intValue();
10348 }
10349
10350
10358 @Override
10359 public int countByG_C_NotS(long groupId, long[] categoryIds, int status) {
10360 if (categoryIds == null) {
10361 categoryIds = new long[0];
10362 }
10363 else {
10364 categoryIds = ArrayUtil.unique(categoryIds);
10365 }
10366
10367 Object[] finderArgs = new Object[] {
10368 groupId, StringUtil.merge(categoryIds), status
10369 };
10370
10371 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10372 finderArgs, this);
10373
10374 if (count == null) {
10375 StringBundler query = new StringBundler();
10376
10377 query.append(_SQL_COUNT_MBTHREAD_WHERE);
10378
10379 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10380
10381 if (categoryIds.length > 0) {
10382 query.append(StringPool.OPEN_PARENTHESIS);
10383
10384 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10385
10386 query.append(StringUtil.merge(categoryIds));
10387
10388 query.append(StringPool.CLOSE_PARENTHESIS);
10389
10390 query.append(StringPool.CLOSE_PARENTHESIS);
10391
10392 query.append(WHERE_AND);
10393 }
10394
10395 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10396
10397 query.setStringAt(removeConjunction(query.stringAt(query.index() -
10398 1)), query.index() - 1);
10399
10400 String sql = query.toString();
10401
10402 Session session = null;
10403
10404 try {
10405 session = openSession();
10406
10407 Query q = session.createQuery(sql);
10408
10409 QueryPos qPos = QueryPos.getInstance(q);
10410
10411 qPos.add(groupId);
10412
10413 qPos.add(status);
10414
10415 count = (Long)q.uniqueResult();
10416
10417 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10418 finderArgs, count);
10419 }
10420 catch (Exception e) {
10421 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_C_NOTS,
10422 finderArgs);
10423
10424 throw processException(e);
10425 }
10426 finally {
10427 closeSession(session);
10428 }
10429 }
10430
10431 return count.intValue();
10432 }
10433
10434
10442 @Override
10443 public int filterCountByG_C_NotS(long groupId, long categoryId, int status) {
10444 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10445 return countByG_C_NotS(groupId, categoryId, status);
10446 }
10447
10448 StringBundler query = new StringBundler(4);
10449
10450 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10451
10452 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10453
10454 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_2);
10455
10456 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10457
10458 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10459 MBThread.class.getName(),
10460 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10461
10462 Session session = null;
10463
10464 try {
10465 session = openSession();
10466
10467 SQLQuery q = session.createSynchronizedSQLQuery(sql);
10468
10469 q.addScalar(COUNT_COLUMN_NAME,
10470 com.liferay.portal.kernel.dao.orm.Type.LONG);
10471
10472 QueryPos qPos = QueryPos.getInstance(q);
10473
10474 qPos.add(groupId);
10475
10476 qPos.add(categoryId);
10477
10478 qPos.add(status);
10479
10480 Long count = (Long)q.uniqueResult();
10481
10482 return count.intValue();
10483 }
10484 catch (Exception e) {
10485 throw processException(e);
10486 }
10487 finally {
10488 closeSession(session);
10489 }
10490 }
10491
10492
10500 @Override
10501 public int filterCountByG_C_NotS(long groupId, long[] categoryIds,
10502 int status) {
10503 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
10504 return countByG_C_NotS(groupId, categoryIds, status);
10505 }
10506
10507 if (categoryIds == null) {
10508 categoryIds = new long[0];
10509 }
10510 else {
10511 categoryIds = ArrayUtil.unique(categoryIds);
10512 }
10513
10514 StringBundler query = new StringBundler();
10515
10516 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
10517
10518 query.append(_FINDER_COLUMN_G_C_NOTS_GROUPID_2);
10519
10520 if (categoryIds.length > 0) {
10521 query.append(StringPool.OPEN_PARENTHESIS);
10522
10523 query.append(_FINDER_COLUMN_G_C_NOTS_CATEGORYID_7);
10524
10525 query.append(StringUtil.merge(categoryIds));
10526
10527 query.append(StringPool.CLOSE_PARENTHESIS);
10528
10529 query.append(StringPool.CLOSE_PARENTHESIS);
10530
10531 query.append(WHERE_AND);
10532 }
10533
10534 query.append(_FINDER_COLUMN_G_C_NOTS_STATUS_2);
10535
10536 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
10537 query.index() - 1);
10538
10539 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
10540 MBThread.class.getName(),
10541 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
10542
10543 Session session = null;
10544
10545 try {
10546 session = openSession();
10547
10548 SQLQuery q = session.createSynchronizedSQLQuery(sql);
10549
10550 q.addScalar(COUNT_COLUMN_NAME,
10551 com.liferay.portal.kernel.dao.orm.Type.LONG);
10552
10553 QueryPos qPos = QueryPos.getInstance(q);
10554
10555 qPos.add(groupId);
10556
10557 qPos.add(status);
10558
10559 Long count = (Long)q.uniqueResult();
10560
10561 return count.intValue();
10562 }
10563 catch (Exception e) {
10564 throw processException(e);
10565 }
10566 finally {
10567 closeSession(session);
10568 }
10569 }
10570
10571 private static final String _FINDER_COLUMN_G_C_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
10572 private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_2 = "mbThread.categoryId = ? AND ";
10573 private static final String _FINDER_COLUMN_G_C_NOTS_CATEGORYID_7 = "mbThread.categoryId IN (";
10574 private static final String _FINDER_COLUMN_G_C_NOTS_STATUS_2 = "mbThread.status != ?";
10575 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S = new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10576 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
10577 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_S",
10578 new String[] {
10579 Long.class.getName(), Long.class.getName(),
10580 Integer.class.getName(),
10581
10582 Integer.class.getName(), Integer.class.getName(),
10583 OrderByComparator.class.getName()
10584 });
10585 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S =
10586 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
10587 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
10588 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_S",
10589 new String[] {
10590 Long.class.getName(), Long.class.getName(),
10591 Integer.class.getName()
10592 });
10593
10594
10602 @Override
10603 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10604 int status) {
10605 return findByG_NotC_S(groupId, categoryId, status, QueryUtil.ALL_POS,
10606 QueryUtil.ALL_POS, null);
10607 }
10608
10609
10623 @Override
10624 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10625 int status, int start, int end) {
10626 return findByG_NotC_S(groupId, categoryId, status, start, end, null);
10627 }
10628
10629
10644 @Override
10645 public List<MBThread> findByG_NotC_S(long groupId, long categoryId,
10646 int status, int start, int end,
10647 OrderByComparator<MBThread> orderByComparator) {
10648 boolean pagination = true;
10649 FinderPath finderPath = null;
10650 Object[] finderArgs = null;
10651
10652 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_S;
10653 finderArgs = new Object[] {
10654 groupId, categoryId, status,
10655
10656 start, end, orderByComparator
10657 };
10658
10659 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
10660 finderArgs, this);
10661
10662 if ((list != null) && !list.isEmpty()) {
10663 for (MBThread mbThread : list) {
10664 if ((groupId != mbThread.getGroupId()) ||
10665 (categoryId == mbThread.getCategoryId()) ||
10666 (status != mbThread.getStatus())) {
10667 list = null;
10668
10669 break;
10670 }
10671 }
10672 }
10673
10674 if (list == null) {
10675 StringBundler query = null;
10676
10677 if (orderByComparator != null) {
10678 query = new StringBundler(5 +
10679 (orderByComparator.getOrderByFields().length * 3));
10680 }
10681 else {
10682 query = new StringBundler(5);
10683 }
10684
10685 query.append(_SQL_SELECT_MBTHREAD_WHERE);
10686
10687 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10688
10689 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10690
10691 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10692
10693 if (orderByComparator != null) {
10694 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10695 orderByComparator);
10696 }
10697 else
10698 if (pagination) {
10699 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10700 }
10701
10702 String sql = query.toString();
10703
10704 Session session = null;
10705
10706 try {
10707 session = openSession();
10708
10709 Query q = session.createQuery(sql);
10710
10711 QueryPos qPos = QueryPos.getInstance(q);
10712
10713 qPos.add(groupId);
10714
10715 qPos.add(categoryId);
10716
10717 qPos.add(status);
10718
10719 if (!pagination) {
10720 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10721 start, end, false);
10722
10723 Collections.sort(list);
10724
10725 list = Collections.unmodifiableList(list);
10726 }
10727 else {
10728 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
10729 start, end);
10730 }
10731
10732 cacheResult(list);
10733
10734 FinderCacheUtil.putResult(finderPath, finderArgs, list);
10735 }
10736 catch (Exception e) {
10737 FinderCacheUtil.removeResult(finderPath, finderArgs);
10738
10739 throw processException(e);
10740 }
10741 finally {
10742 closeSession(session);
10743 }
10744 }
10745
10746 return list;
10747 }
10748
10749
10759 @Override
10760 public MBThread findByG_NotC_S_First(long groupId, long categoryId,
10761 int status, OrderByComparator<MBThread> orderByComparator)
10762 throws NoSuchThreadException {
10763 MBThread mbThread = fetchByG_NotC_S_First(groupId, categoryId, status,
10764 orderByComparator);
10765
10766 if (mbThread != null) {
10767 return mbThread;
10768 }
10769
10770 StringBundler msg = new StringBundler(8);
10771
10772 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10773
10774 msg.append("groupId=");
10775 msg.append(groupId);
10776
10777 msg.append(", categoryId=");
10778 msg.append(categoryId);
10779
10780 msg.append(", status=");
10781 msg.append(status);
10782
10783 msg.append(StringPool.CLOSE_CURLY_BRACE);
10784
10785 throw new NoSuchThreadException(msg.toString());
10786 }
10787
10788
10797 @Override
10798 public MBThread fetchByG_NotC_S_First(long groupId, long categoryId,
10799 int status, OrderByComparator<MBThread> orderByComparator) {
10800 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status, 0, 1,
10801 orderByComparator);
10802
10803 if (!list.isEmpty()) {
10804 return list.get(0);
10805 }
10806
10807 return null;
10808 }
10809
10810
10820 @Override
10821 public MBThread findByG_NotC_S_Last(long groupId, long categoryId,
10822 int status, OrderByComparator<MBThread> orderByComparator)
10823 throws NoSuchThreadException {
10824 MBThread mbThread = fetchByG_NotC_S_Last(groupId, categoryId, status,
10825 orderByComparator);
10826
10827 if (mbThread != null) {
10828 return mbThread;
10829 }
10830
10831 StringBundler msg = new StringBundler(8);
10832
10833 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10834
10835 msg.append("groupId=");
10836 msg.append(groupId);
10837
10838 msg.append(", categoryId=");
10839 msg.append(categoryId);
10840
10841 msg.append(", status=");
10842 msg.append(status);
10843
10844 msg.append(StringPool.CLOSE_CURLY_BRACE);
10845
10846 throw new NoSuchThreadException(msg.toString());
10847 }
10848
10849
10858 @Override
10859 public MBThread fetchByG_NotC_S_Last(long groupId, long categoryId,
10860 int status, OrderByComparator<MBThread> orderByComparator) {
10861 int count = countByG_NotC_S(groupId, categoryId, status);
10862
10863 if (count == 0) {
10864 return null;
10865 }
10866
10867 List<MBThread> list = findByG_NotC_S(groupId, categoryId, status,
10868 count - 1, count, orderByComparator);
10869
10870 if (!list.isEmpty()) {
10871 return list.get(0);
10872 }
10873
10874 return null;
10875 }
10876
10877
10888 @Override
10889 public MBThread[] findByG_NotC_S_PrevAndNext(long threadId, long groupId,
10890 long categoryId, int status,
10891 OrderByComparator<MBThread> orderByComparator)
10892 throws NoSuchThreadException {
10893 MBThread mbThread = findByPrimaryKey(threadId);
10894
10895 Session session = null;
10896
10897 try {
10898 session = openSession();
10899
10900 MBThread[] array = new MBThreadImpl[3];
10901
10902 array[0] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
10903 categoryId, status, orderByComparator, true);
10904
10905 array[1] = mbThread;
10906
10907 array[2] = getByG_NotC_S_PrevAndNext(session, mbThread, groupId,
10908 categoryId, status, orderByComparator, false);
10909
10910 return array;
10911 }
10912 catch (Exception e) {
10913 throw processException(e);
10914 }
10915 finally {
10916 closeSession(session);
10917 }
10918 }
10919
10920 protected MBThread getByG_NotC_S_PrevAndNext(Session session,
10921 MBThread mbThread, long groupId, long categoryId, int status,
10922 OrderByComparator<MBThread> orderByComparator, boolean previous) {
10923 StringBundler query = null;
10924
10925 if (orderByComparator != null) {
10926 query = new StringBundler(6 +
10927 (orderByComparator.getOrderByFields().length * 6));
10928 }
10929 else {
10930 query = new StringBundler(3);
10931 }
10932
10933 query.append(_SQL_SELECT_MBTHREAD_WHERE);
10934
10935 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
10936
10937 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
10938
10939 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
10940
10941 if (orderByComparator != null) {
10942 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10943
10944 if (orderByConditionFields.length > 0) {
10945 query.append(WHERE_AND);
10946 }
10947
10948 for (int i = 0; i < orderByConditionFields.length; i++) {
10949 query.append(_ORDER_BY_ENTITY_ALIAS);
10950 query.append(orderByConditionFields[i]);
10951
10952 if ((i + 1) < orderByConditionFields.length) {
10953 if (orderByComparator.isAscending() ^ previous) {
10954 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10955 }
10956 else {
10957 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10958 }
10959 }
10960 else {
10961 if (orderByComparator.isAscending() ^ previous) {
10962 query.append(WHERE_GREATER_THAN);
10963 }
10964 else {
10965 query.append(WHERE_LESSER_THAN);
10966 }
10967 }
10968 }
10969
10970 query.append(ORDER_BY_CLAUSE);
10971
10972 String[] orderByFields = orderByComparator.getOrderByFields();
10973
10974 for (int i = 0; i < orderByFields.length; i++) {
10975 query.append(_ORDER_BY_ENTITY_ALIAS);
10976 query.append(orderByFields[i]);
10977
10978 if ((i + 1) < orderByFields.length) {
10979 if (orderByComparator.isAscending() ^ previous) {
10980 query.append(ORDER_BY_ASC_HAS_NEXT);
10981 }
10982 else {
10983 query.append(ORDER_BY_DESC_HAS_NEXT);
10984 }
10985 }
10986 else {
10987 if (orderByComparator.isAscending() ^ previous) {
10988 query.append(ORDER_BY_ASC);
10989 }
10990 else {
10991 query.append(ORDER_BY_DESC);
10992 }
10993 }
10994 }
10995 }
10996 else {
10997 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
10998 }
10999
11000 String sql = query.toString();
11001
11002 Query q = session.createQuery(sql);
11003
11004 q.setFirstResult(0);
11005 q.setMaxResults(2);
11006
11007 QueryPos qPos = QueryPos.getInstance(q);
11008
11009 qPos.add(groupId);
11010
11011 qPos.add(categoryId);
11012
11013 qPos.add(status);
11014
11015 if (orderByComparator != null) {
11016 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11017
11018 for (Object value : values) {
11019 qPos.add(value);
11020 }
11021 }
11022
11023 List<MBThread> list = q.list();
11024
11025 if (list.size() == 2) {
11026 return list.get(1);
11027 }
11028 else {
11029 return null;
11030 }
11031 }
11032
11033
11041 @Override
11042 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11043 int status) {
11044 return filterFindByG_NotC_S(groupId, categoryId, status,
11045 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11046 }
11047
11048
11062 @Override
11063 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11064 int status, int start, int end) {
11065 return filterFindByG_NotC_S(groupId, categoryId, status, start, end,
11066 null);
11067 }
11068
11069
11084 @Override
11085 public List<MBThread> filterFindByG_NotC_S(long groupId, long categoryId,
11086 int status, int start, int end,
11087 OrderByComparator<MBThread> orderByComparator) {
11088 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11089 return findByG_NotC_S(groupId, categoryId, status, start, end,
11090 orderByComparator);
11091 }
11092
11093 StringBundler query = null;
11094
11095 if (orderByComparator != null) {
11096 query = new StringBundler(5 +
11097 (orderByComparator.getOrderByFields().length * 3));
11098 }
11099 else {
11100 query = new StringBundler(5);
11101 }
11102
11103 if (getDB().isSupportsInlineDistinct()) {
11104 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11105 }
11106 else {
11107 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11108 }
11109
11110 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11111
11112 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11113
11114 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11115
11116 if (!getDB().isSupportsInlineDistinct()) {
11117 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11118 }
11119
11120 if (orderByComparator != null) {
11121 if (getDB().isSupportsInlineDistinct()) {
11122 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11123 orderByComparator, true);
11124 }
11125 else {
11126 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11127 orderByComparator, true);
11128 }
11129 }
11130 else {
11131 if (getDB().isSupportsInlineDistinct()) {
11132 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11133 }
11134 else {
11135 query.append(MBThreadModelImpl.ORDER_BY_SQL);
11136 }
11137 }
11138
11139 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11140 MBThread.class.getName(),
11141 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11142
11143 Session session = null;
11144
11145 try {
11146 session = openSession();
11147
11148 SQLQuery q = session.createSynchronizedSQLQuery(sql);
11149
11150 if (getDB().isSupportsInlineDistinct()) {
11151 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11152 }
11153 else {
11154 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11155 }
11156
11157 QueryPos qPos = QueryPos.getInstance(q);
11158
11159 qPos.add(groupId);
11160
11161 qPos.add(categoryId);
11162
11163 qPos.add(status);
11164
11165 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
11166 }
11167 catch (Exception e) {
11168 throw processException(e);
11169 }
11170 finally {
11171 closeSession(session);
11172 }
11173 }
11174
11175
11186 @Override
11187 public MBThread[] filterFindByG_NotC_S_PrevAndNext(long threadId,
11188 long groupId, long categoryId, int status,
11189 OrderByComparator<MBThread> orderByComparator)
11190 throws NoSuchThreadException {
11191 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11192 return findByG_NotC_S_PrevAndNext(threadId, groupId, categoryId,
11193 status, orderByComparator);
11194 }
11195
11196 MBThread mbThread = findByPrimaryKey(threadId);
11197
11198 Session session = null;
11199
11200 try {
11201 session = openSession();
11202
11203 MBThread[] array = new MBThreadImpl[3];
11204
11205 array[0] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11206 groupId, categoryId, status, orderByComparator, true);
11207
11208 array[1] = mbThread;
11209
11210 array[2] = filterGetByG_NotC_S_PrevAndNext(session, mbThread,
11211 groupId, categoryId, status, orderByComparator, false);
11212
11213 return array;
11214 }
11215 catch (Exception e) {
11216 throw processException(e);
11217 }
11218 finally {
11219 closeSession(session);
11220 }
11221 }
11222
11223 protected MBThread filterGetByG_NotC_S_PrevAndNext(Session session,
11224 MBThread mbThread, long groupId, long categoryId, int status,
11225 OrderByComparator<MBThread> orderByComparator, boolean previous) {
11226 StringBundler query = null;
11227
11228 if (orderByComparator != null) {
11229 query = new StringBundler(6 +
11230 (orderByComparator.getOrderByFields().length * 6));
11231 }
11232 else {
11233 query = new StringBundler(3);
11234 }
11235
11236 if (getDB().isSupportsInlineDistinct()) {
11237 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
11238 }
11239 else {
11240 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
11241 }
11242
11243 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11244
11245 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11246
11247 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11248
11249 if (!getDB().isSupportsInlineDistinct()) {
11250 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
11251 }
11252
11253 if (orderByComparator != null) {
11254 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11255
11256 if (orderByConditionFields.length > 0) {
11257 query.append(WHERE_AND);
11258 }
11259
11260 for (int i = 0; i < orderByConditionFields.length; i++) {
11261 if (getDB().isSupportsInlineDistinct()) {
11262 query.append(_ORDER_BY_ENTITY_ALIAS);
11263 }
11264 else {
11265 query.append(_ORDER_BY_ENTITY_TABLE);
11266 }
11267
11268 query.append(orderByConditionFields[i]);
11269
11270 if ((i + 1) < orderByConditionFields.length) {
11271 if (orderByComparator.isAscending() ^ previous) {
11272 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11273 }
11274 else {
11275 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11276 }
11277 }
11278 else {
11279 if (orderByComparator.isAscending() ^ previous) {
11280 query.append(WHERE_GREATER_THAN);
11281 }
11282 else {
11283 query.append(WHERE_LESSER_THAN);
11284 }
11285 }
11286 }
11287
11288 query.append(ORDER_BY_CLAUSE);
11289
11290 String[] orderByFields = orderByComparator.getOrderByFields();
11291
11292 for (int i = 0; i < orderByFields.length; i++) {
11293 if (getDB().isSupportsInlineDistinct()) {
11294 query.append(_ORDER_BY_ENTITY_ALIAS);
11295 }
11296 else {
11297 query.append(_ORDER_BY_ENTITY_TABLE);
11298 }
11299
11300 query.append(orderByFields[i]);
11301
11302 if ((i + 1) < orderByFields.length) {
11303 if (orderByComparator.isAscending() ^ previous) {
11304 query.append(ORDER_BY_ASC_HAS_NEXT);
11305 }
11306 else {
11307 query.append(ORDER_BY_DESC_HAS_NEXT);
11308 }
11309 }
11310 else {
11311 if (orderByComparator.isAscending() ^ previous) {
11312 query.append(ORDER_BY_ASC);
11313 }
11314 else {
11315 query.append(ORDER_BY_DESC);
11316 }
11317 }
11318 }
11319 }
11320 else {
11321 if (getDB().isSupportsInlineDistinct()) {
11322 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11323 }
11324 else {
11325 query.append(MBThreadModelImpl.ORDER_BY_SQL);
11326 }
11327 }
11328
11329 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11330 MBThread.class.getName(),
11331 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11332
11333 SQLQuery q = session.createSynchronizedSQLQuery(sql);
11334
11335 q.setFirstResult(0);
11336 q.setMaxResults(2);
11337
11338 if (getDB().isSupportsInlineDistinct()) {
11339 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
11340 }
11341 else {
11342 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
11343 }
11344
11345 QueryPos qPos = QueryPos.getInstance(q);
11346
11347 qPos.add(groupId);
11348
11349 qPos.add(categoryId);
11350
11351 qPos.add(status);
11352
11353 if (orderByComparator != null) {
11354 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11355
11356 for (Object value : values) {
11357 qPos.add(value);
11358 }
11359 }
11360
11361 List<MBThread> list = q.list();
11362
11363 if (list.size() == 2) {
11364 return list.get(1);
11365 }
11366 else {
11367 return null;
11368 }
11369 }
11370
11371
11378 @Override
11379 public void removeByG_NotC_S(long groupId, long categoryId, int status) {
11380 for (MBThread mbThread : findByG_NotC_S(groupId, categoryId, status,
11381 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11382 remove(mbThread);
11383 }
11384 }
11385
11386
11394 @Override
11395 public int countByG_NotC_S(long groupId, long categoryId, int status) {
11396 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_S;
11397
11398 Object[] finderArgs = new Object[] { groupId, categoryId, status };
11399
11400 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11401 this);
11402
11403 if (count == null) {
11404 StringBundler query = new StringBundler(4);
11405
11406 query.append(_SQL_COUNT_MBTHREAD_WHERE);
11407
11408 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11409
11410 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11411
11412 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11413
11414 String sql = query.toString();
11415
11416 Session session = null;
11417
11418 try {
11419 session = openSession();
11420
11421 Query q = session.createQuery(sql);
11422
11423 QueryPos qPos = QueryPos.getInstance(q);
11424
11425 qPos.add(groupId);
11426
11427 qPos.add(categoryId);
11428
11429 qPos.add(status);
11430
11431 count = (Long)q.uniqueResult();
11432
11433 FinderCacheUtil.putResult(finderPath, finderArgs, count);
11434 }
11435 catch (Exception e) {
11436 FinderCacheUtil.removeResult(finderPath, finderArgs);
11437
11438 throw processException(e);
11439 }
11440 finally {
11441 closeSession(session);
11442 }
11443 }
11444
11445 return count.intValue();
11446 }
11447
11448
11456 @Override
11457 public int filterCountByG_NotC_S(long groupId, long categoryId, int status) {
11458 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11459 return countByG_NotC_S(groupId, categoryId, status);
11460 }
11461
11462 StringBundler query = new StringBundler(4);
11463
11464 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
11465
11466 query.append(_FINDER_COLUMN_G_NOTC_S_GROUPID_2);
11467
11468 query.append(_FINDER_COLUMN_G_NOTC_S_CATEGORYID_2);
11469
11470 query.append(_FINDER_COLUMN_G_NOTC_S_STATUS_2);
11471
11472 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11473 MBThread.class.getName(),
11474 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11475
11476 Session session = null;
11477
11478 try {
11479 session = openSession();
11480
11481 SQLQuery q = session.createSynchronizedSQLQuery(sql);
11482
11483 q.addScalar(COUNT_COLUMN_NAME,
11484 com.liferay.portal.kernel.dao.orm.Type.LONG);
11485
11486 QueryPos qPos = QueryPos.getInstance(q);
11487
11488 qPos.add(groupId);
11489
11490 qPos.add(categoryId);
11491
11492 qPos.add(status);
11493
11494 Long count = (Long)q.uniqueResult();
11495
11496 return count.intValue();
11497 }
11498 catch (Exception e) {
11499 throw processException(e);
11500 }
11501 finally {
11502 closeSession(session);
11503 }
11504 }
11505
11506 private static final String _FINDER_COLUMN_G_NOTC_S_GROUPID_2 = "mbThread.groupId = ? AND ";
11507 private static final String _FINDER_COLUMN_G_NOTC_S_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
11508 private static final String _FINDER_COLUMN_G_NOTC_S_STATUS_2 = "mbThread.status = ?";
11509 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS =
11510 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11511 MBThreadModelImpl.FINDER_CACHE_ENABLED, MBThreadImpl.class,
11512 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotC_NotS",
11513 new String[] {
11514 Long.class.getName(), Long.class.getName(),
11515 Integer.class.getName(),
11516
11517 Integer.class.getName(), Integer.class.getName(),
11518 OrderByComparator.class.getName()
11519 });
11520 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS =
11521 new FinderPath(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
11522 MBThreadModelImpl.FINDER_CACHE_ENABLED, Long.class,
11523 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotC_NotS",
11524 new String[] {
11525 Long.class.getName(), Long.class.getName(),
11526 Integer.class.getName()
11527 });
11528
11529
11537 @Override
11538 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11539 int status) {
11540 return findByG_NotC_NotS(groupId, categoryId, status,
11541 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11542 }
11543
11544
11558 @Override
11559 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11560 int status, int start, int end) {
11561 return findByG_NotC_NotS(groupId, categoryId, status, start, end, null);
11562 }
11563
11564
11579 @Override
11580 public List<MBThread> findByG_NotC_NotS(long groupId, long categoryId,
11581 int status, int start, int end,
11582 OrderByComparator<MBThread> orderByComparator) {
11583 boolean pagination = true;
11584 FinderPath finderPath = null;
11585 Object[] finderArgs = null;
11586
11587 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTC_NOTS;
11588 finderArgs = new Object[] {
11589 groupId, categoryId, status,
11590
11591 start, end, orderByComparator
11592 };
11593
11594 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
11595 finderArgs, this);
11596
11597 if ((list != null) && !list.isEmpty()) {
11598 for (MBThread mbThread : list) {
11599 if ((groupId != mbThread.getGroupId()) ||
11600 (categoryId == mbThread.getCategoryId()) ||
11601 (status == mbThread.getStatus())) {
11602 list = null;
11603
11604 break;
11605 }
11606 }
11607 }
11608
11609 if (list == null) {
11610 StringBundler query = null;
11611
11612 if (orderByComparator != null) {
11613 query = new StringBundler(5 +
11614 (orderByComparator.getOrderByFields().length * 3));
11615 }
11616 else {
11617 query = new StringBundler(5);
11618 }
11619
11620 query.append(_SQL_SELECT_MBTHREAD_WHERE);
11621
11622 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11623
11624 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11625
11626 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11627
11628 if (orderByComparator != null) {
11629 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11630 orderByComparator);
11631 }
11632 else
11633 if (pagination) {
11634 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11635 }
11636
11637 String sql = query.toString();
11638
11639 Session session = null;
11640
11641 try {
11642 session = openSession();
11643
11644 Query q = session.createQuery(sql);
11645
11646 QueryPos qPos = QueryPos.getInstance(q);
11647
11648 qPos.add(groupId);
11649
11650 qPos.add(categoryId);
11651
11652 qPos.add(status);
11653
11654 if (!pagination) {
11655 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11656 start, end, false);
11657
11658 Collections.sort(list);
11659
11660 list = Collections.unmodifiableList(list);
11661 }
11662 else {
11663 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
11664 start, end);
11665 }
11666
11667 cacheResult(list);
11668
11669 FinderCacheUtil.putResult(finderPath, finderArgs, list);
11670 }
11671 catch (Exception e) {
11672 FinderCacheUtil.removeResult(finderPath, finderArgs);
11673
11674 throw processException(e);
11675 }
11676 finally {
11677 closeSession(session);
11678 }
11679 }
11680
11681 return list;
11682 }
11683
11684
11694 @Override
11695 public MBThread findByG_NotC_NotS_First(long groupId, long categoryId,
11696 int status, OrderByComparator<MBThread> orderByComparator)
11697 throws NoSuchThreadException {
11698 MBThread mbThread = fetchByG_NotC_NotS_First(groupId, categoryId,
11699 status, orderByComparator);
11700
11701 if (mbThread != null) {
11702 return mbThread;
11703 }
11704
11705 StringBundler msg = new StringBundler(8);
11706
11707 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11708
11709 msg.append("groupId=");
11710 msg.append(groupId);
11711
11712 msg.append(", categoryId=");
11713 msg.append(categoryId);
11714
11715 msg.append(", status=");
11716 msg.append(status);
11717
11718 msg.append(StringPool.CLOSE_CURLY_BRACE);
11719
11720 throw new NoSuchThreadException(msg.toString());
11721 }
11722
11723
11732 @Override
11733 public MBThread fetchByG_NotC_NotS_First(long groupId, long categoryId,
11734 int status, OrderByComparator<MBThread> orderByComparator) {
11735 List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status, 0,
11736 1, orderByComparator);
11737
11738 if (!list.isEmpty()) {
11739 return list.get(0);
11740 }
11741
11742 return null;
11743 }
11744
11745
11755 @Override
11756 public MBThread findByG_NotC_NotS_Last(long groupId, long categoryId,
11757 int status, OrderByComparator<MBThread> orderByComparator)
11758 throws NoSuchThreadException {
11759 MBThread mbThread = fetchByG_NotC_NotS_Last(groupId, categoryId,
11760 status, orderByComparator);
11761
11762 if (mbThread != null) {
11763 return mbThread;
11764 }
11765
11766 StringBundler msg = new StringBundler(8);
11767
11768 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11769
11770 msg.append("groupId=");
11771 msg.append(groupId);
11772
11773 msg.append(", categoryId=");
11774 msg.append(categoryId);
11775
11776 msg.append(", status=");
11777 msg.append(status);
11778
11779 msg.append(StringPool.CLOSE_CURLY_BRACE);
11780
11781 throw new NoSuchThreadException(msg.toString());
11782 }
11783
11784
11793 @Override
11794 public MBThread fetchByG_NotC_NotS_Last(long groupId, long categoryId,
11795 int status, OrderByComparator<MBThread> orderByComparator) {
11796 int count = countByG_NotC_NotS(groupId, categoryId, status);
11797
11798 if (count == 0) {
11799 return null;
11800 }
11801
11802 List<MBThread> list = findByG_NotC_NotS(groupId, categoryId, status,
11803 count - 1, count, orderByComparator);
11804
11805 if (!list.isEmpty()) {
11806 return list.get(0);
11807 }
11808
11809 return null;
11810 }
11811
11812
11823 @Override
11824 public MBThread[] findByG_NotC_NotS_PrevAndNext(long threadId,
11825 long groupId, long categoryId, int status,
11826 OrderByComparator<MBThread> orderByComparator)
11827 throws NoSuchThreadException {
11828 MBThread mbThread = findByPrimaryKey(threadId);
11829
11830 Session session = null;
11831
11832 try {
11833 session = openSession();
11834
11835 MBThread[] array = new MBThreadImpl[3];
11836
11837 array[0] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
11838 categoryId, status, orderByComparator, true);
11839
11840 array[1] = mbThread;
11841
11842 array[2] = getByG_NotC_NotS_PrevAndNext(session, mbThread, groupId,
11843 categoryId, status, orderByComparator, false);
11844
11845 return array;
11846 }
11847 catch (Exception e) {
11848 throw processException(e);
11849 }
11850 finally {
11851 closeSession(session);
11852 }
11853 }
11854
11855 protected MBThread getByG_NotC_NotS_PrevAndNext(Session session,
11856 MBThread mbThread, long groupId, long categoryId, int status,
11857 OrderByComparator<MBThread> orderByComparator, boolean previous) {
11858 StringBundler query = null;
11859
11860 if (orderByComparator != null) {
11861 query = new StringBundler(6 +
11862 (orderByComparator.getOrderByFields().length * 6));
11863 }
11864 else {
11865 query = new StringBundler(3);
11866 }
11867
11868 query.append(_SQL_SELECT_MBTHREAD_WHERE);
11869
11870 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
11871
11872 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
11873
11874 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
11875
11876 if (orderByComparator != null) {
11877 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11878
11879 if (orderByConditionFields.length > 0) {
11880 query.append(WHERE_AND);
11881 }
11882
11883 for (int i = 0; i < orderByConditionFields.length; i++) {
11884 query.append(_ORDER_BY_ENTITY_ALIAS);
11885 query.append(orderByConditionFields[i]);
11886
11887 if ((i + 1) < orderByConditionFields.length) {
11888 if (orderByComparator.isAscending() ^ previous) {
11889 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11890 }
11891 else {
11892 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11893 }
11894 }
11895 else {
11896 if (orderByComparator.isAscending() ^ previous) {
11897 query.append(WHERE_GREATER_THAN);
11898 }
11899 else {
11900 query.append(WHERE_LESSER_THAN);
11901 }
11902 }
11903 }
11904
11905 query.append(ORDER_BY_CLAUSE);
11906
11907 String[] orderByFields = orderByComparator.getOrderByFields();
11908
11909 for (int i = 0; i < orderByFields.length; i++) {
11910 query.append(_ORDER_BY_ENTITY_ALIAS);
11911 query.append(orderByFields[i]);
11912
11913 if ((i + 1) < orderByFields.length) {
11914 if (orderByComparator.isAscending() ^ previous) {
11915 query.append(ORDER_BY_ASC_HAS_NEXT);
11916 }
11917 else {
11918 query.append(ORDER_BY_DESC_HAS_NEXT);
11919 }
11920 }
11921 else {
11922 if (orderByComparator.isAscending() ^ previous) {
11923 query.append(ORDER_BY_ASC);
11924 }
11925 else {
11926 query.append(ORDER_BY_DESC);
11927 }
11928 }
11929 }
11930 }
11931 else {
11932 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
11933 }
11934
11935 String sql = query.toString();
11936
11937 Query q = session.createQuery(sql);
11938
11939 q.setFirstResult(0);
11940 q.setMaxResults(2);
11941
11942 QueryPos qPos = QueryPos.getInstance(q);
11943
11944 qPos.add(groupId);
11945
11946 qPos.add(categoryId);
11947
11948 qPos.add(status);
11949
11950 if (orderByComparator != null) {
11951 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
11952
11953 for (Object value : values) {
11954 qPos.add(value);
11955 }
11956 }
11957
11958 List<MBThread> list = q.list();
11959
11960 if (list.size() == 2) {
11961 return list.get(1);
11962 }
11963 else {
11964 return null;
11965 }
11966 }
11967
11968
11976 @Override
11977 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
11978 long categoryId, int status) {
11979 return filterFindByG_NotC_NotS(groupId, categoryId, status,
11980 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
11981 }
11982
11983
11997 @Override
11998 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
11999 long categoryId, int status, int start, int end) {
12000 return filterFindByG_NotC_NotS(groupId, categoryId, status, start, end,
12001 null);
12002 }
12003
12004
12019 @Override
12020 public List<MBThread> filterFindByG_NotC_NotS(long groupId,
12021 long categoryId, int status, int start, int end,
12022 OrderByComparator<MBThread> orderByComparator) {
12023 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12024 return findByG_NotC_NotS(groupId, categoryId, status, start, end,
12025 orderByComparator);
12026 }
12027
12028 StringBundler query = null;
12029
12030 if (orderByComparator != null) {
12031 query = new StringBundler(5 +
12032 (orderByComparator.getOrderByFields().length * 3));
12033 }
12034 else {
12035 query = new StringBundler(5);
12036 }
12037
12038 if (getDB().isSupportsInlineDistinct()) {
12039 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12040 }
12041 else {
12042 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12043 }
12044
12045 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12046
12047 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12048
12049 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12050
12051 if (!getDB().isSupportsInlineDistinct()) {
12052 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12053 }
12054
12055 if (orderByComparator != null) {
12056 if (getDB().isSupportsInlineDistinct()) {
12057 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12058 orderByComparator, true);
12059 }
12060 else {
12061 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12062 orderByComparator, true);
12063 }
12064 }
12065 else {
12066 if (getDB().isSupportsInlineDistinct()) {
12067 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12068 }
12069 else {
12070 query.append(MBThreadModelImpl.ORDER_BY_SQL);
12071 }
12072 }
12073
12074 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12075 MBThread.class.getName(),
12076 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12077
12078 Session session = null;
12079
12080 try {
12081 session = openSession();
12082
12083 SQLQuery q = session.createSynchronizedSQLQuery(sql);
12084
12085 if (getDB().isSupportsInlineDistinct()) {
12086 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12087 }
12088 else {
12089 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12090 }
12091
12092 QueryPos qPos = QueryPos.getInstance(q);
12093
12094 qPos.add(groupId);
12095
12096 qPos.add(categoryId);
12097
12098 qPos.add(status);
12099
12100 return (List<MBThread>)QueryUtil.list(q, getDialect(), start, end);
12101 }
12102 catch (Exception e) {
12103 throw processException(e);
12104 }
12105 finally {
12106 closeSession(session);
12107 }
12108 }
12109
12110
12121 @Override
12122 public MBThread[] filterFindByG_NotC_NotS_PrevAndNext(long threadId,
12123 long groupId, long categoryId, int status,
12124 OrderByComparator<MBThread> orderByComparator)
12125 throws NoSuchThreadException {
12126 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12127 return findByG_NotC_NotS_PrevAndNext(threadId, groupId, categoryId,
12128 status, orderByComparator);
12129 }
12130
12131 MBThread mbThread = findByPrimaryKey(threadId);
12132
12133 Session session = null;
12134
12135 try {
12136 session = openSession();
12137
12138 MBThread[] array = new MBThreadImpl[3];
12139
12140 array[0] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12141 groupId, categoryId, status, orderByComparator, true);
12142
12143 array[1] = mbThread;
12144
12145 array[2] = filterGetByG_NotC_NotS_PrevAndNext(session, mbThread,
12146 groupId, categoryId, status, orderByComparator, false);
12147
12148 return array;
12149 }
12150 catch (Exception e) {
12151 throw processException(e);
12152 }
12153 finally {
12154 closeSession(session);
12155 }
12156 }
12157
12158 protected MBThread filterGetByG_NotC_NotS_PrevAndNext(Session session,
12159 MBThread mbThread, long groupId, long categoryId, int status,
12160 OrderByComparator<MBThread> orderByComparator, boolean previous) {
12161 StringBundler query = null;
12162
12163 if (orderByComparator != null) {
12164 query = new StringBundler(6 +
12165 (orderByComparator.getOrderByFields().length * 6));
12166 }
12167 else {
12168 query = new StringBundler(3);
12169 }
12170
12171 if (getDB().isSupportsInlineDistinct()) {
12172 query.append(_FILTER_SQL_SELECT_MBTHREAD_WHERE);
12173 }
12174 else {
12175 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1);
12176 }
12177
12178 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12179
12180 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12181
12182 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12183
12184 if (!getDB().isSupportsInlineDistinct()) {
12185 query.append(_FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2);
12186 }
12187
12188 if (orderByComparator != null) {
12189 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12190
12191 if (orderByConditionFields.length > 0) {
12192 query.append(WHERE_AND);
12193 }
12194
12195 for (int i = 0; i < orderByConditionFields.length; i++) {
12196 if (getDB().isSupportsInlineDistinct()) {
12197 query.append(_ORDER_BY_ENTITY_ALIAS);
12198 }
12199 else {
12200 query.append(_ORDER_BY_ENTITY_TABLE);
12201 }
12202
12203 query.append(orderByConditionFields[i]);
12204
12205 if ((i + 1) < orderByConditionFields.length) {
12206 if (orderByComparator.isAscending() ^ previous) {
12207 query.append(WHERE_GREATER_THAN_HAS_NEXT);
12208 }
12209 else {
12210 query.append(WHERE_LESSER_THAN_HAS_NEXT);
12211 }
12212 }
12213 else {
12214 if (orderByComparator.isAscending() ^ previous) {
12215 query.append(WHERE_GREATER_THAN);
12216 }
12217 else {
12218 query.append(WHERE_LESSER_THAN);
12219 }
12220 }
12221 }
12222
12223 query.append(ORDER_BY_CLAUSE);
12224
12225 String[] orderByFields = orderByComparator.getOrderByFields();
12226
12227 for (int i = 0; i < orderByFields.length; i++) {
12228 if (getDB().isSupportsInlineDistinct()) {
12229 query.append(_ORDER_BY_ENTITY_ALIAS);
12230 }
12231 else {
12232 query.append(_ORDER_BY_ENTITY_TABLE);
12233 }
12234
12235 query.append(orderByFields[i]);
12236
12237 if ((i + 1) < orderByFields.length) {
12238 if (orderByComparator.isAscending() ^ previous) {
12239 query.append(ORDER_BY_ASC_HAS_NEXT);
12240 }
12241 else {
12242 query.append(ORDER_BY_DESC_HAS_NEXT);
12243 }
12244 }
12245 else {
12246 if (orderByComparator.isAscending() ^ previous) {
12247 query.append(ORDER_BY_ASC);
12248 }
12249 else {
12250 query.append(ORDER_BY_DESC);
12251 }
12252 }
12253 }
12254 }
12255 else {
12256 if (getDB().isSupportsInlineDistinct()) {
12257 query.append(MBThreadModelImpl.ORDER_BY_JPQL);
12258 }
12259 else {
12260 query.append(MBThreadModelImpl.ORDER_BY_SQL);
12261 }
12262 }
12263
12264 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12265 MBThread.class.getName(),
12266 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12267
12268 SQLQuery q = session.createSynchronizedSQLQuery(sql);
12269
12270 q.setFirstResult(0);
12271 q.setMaxResults(2);
12272
12273 if (getDB().isSupportsInlineDistinct()) {
12274 q.addEntity(_FILTER_ENTITY_ALIAS, MBThreadImpl.class);
12275 }
12276 else {
12277 q.addEntity(_FILTER_ENTITY_TABLE, MBThreadImpl.class);
12278 }
12279
12280 QueryPos qPos = QueryPos.getInstance(q);
12281
12282 qPos.add(groupId);
12283
12284 qPos.add(categoryId);
12285
12286 qPos.add(status);
12287
12288 if (orderByComparator != null) {
12289 Object[] values = orderByComparator.getOrderByConditionValues(mbThread);
12290
12291 for (Object value : values) {
12292 qPos.add(value);
12293 }
12294 }
12295
12296 List<MBThread> list = q.list();
12297
12298 if (list.size() == 2) {
12299 return list.get(1);
12300 }
12301 else {
12302 return null;
12303 }
12304 }
12305
12306
12313 @Override
12314 public void removeByG_NotC_NotS(long groupId, long categoryId, int status) {
12315 for (MBThread mbThread : findByG_NotC_NotS(groupId, categoryId, status,
12316 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12317 remove(mbThread);
12318 }
12319 }
12320
12321
12329 @Override
12330 public int countByG_NotC_NotS(long groupId, long categoryId, int status) {
12331 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTC_NOTS;
12332
12333 Object[] finderArgs = new Object[] { groupId, categoryId, status };
12334
12335 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12336 this);
12337
12338 if (count == null) {
12339 StringBundler query = new StringBundler(4);
12340
12341 query.append(_SQL_COUNT_MBTHREAD_WHERE);
12342
12343 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12344
12345 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12346
12347 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12348
12349 String sql = query.toString();
12350
12351 Session session = null;
12352
12353 try {
12354 session = openSession();
12355
12356 Query q = session.createQuery(sql);
12357
12358 QueryPos qPos = QueryPos.getInstance(q);
12359
12360 qPos.add(groupId);
12361
12362 qPos.add(categoryId);
12363
12364 qPos.add(status);
12365
12366 count = (Long)q.uniqueResult();
12367
12368 FinderCacheUtil.putResult(finderPath, finderArgs, count);
12369 }
12370 catch (Exception e) {
12371 FinderCacheUtil.removeResult(finderPath, finderArgs);
12372
12373 throw processException(e);
12374 }
12375 finally {
12376 closeSession(session);
12377 }
12378 }
12379
12380 return count.intValue();
12381 }
12382
12383
12391 @Override
12392 public int filterCountByG_NotC_NotS(long groupId, long categoryId,
12393 int status) {
12394 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12395 return countByG_NotC_NotS(groupId, categoryId, status);
12396 }
12397
12398 StringBundler query = new StringBundler(4);
12399
12400 query.append(_FILTER_SQL_COUNT_MBTHREAD_WHERE);
12401
12402 query.append(_FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2);
12403
12404 query.append(_FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2);
12405
12406 query.append(_FINDER_COLUMN_G_NOTC_NOTS_STATUS_2);
12407
12408 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12409 MBThread.class.getName(),
12410 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12411
12412 Session session = null;
12413
12414 try {
12415 session = openSession();
12416
12417 SQLQuery q = session.createSynchronizedSQLQuery(sql);
12418
12419 q.addScalar(COUNT_COLUMN_NAME,
12420 com.liferay.portal.kernel.dao.orm.Type.LONG);
12421
12422 QueryPos qPos = QueryPos.getInstance(q);
12423
12424 qPos.add(groupId);
12425
12426 qPos.add(categoryId);
12427
12428 qPos.add(status);
12429
12430 Long count = (Long)q.uniqueResult();
12431
12432 return count.intValue();
12433 }
12434 catch (Exception e) {
12435 throw processException(e);
12436 }
12437 finally {
12438 closeSession(session);
12439 }
12440 }
12441
12442 private static final String _FINDER_COLUMN_G_NOTC_NOTS_GROUPID_2 = "mbThread.groupId = ? AND ";
12443 private static final String _FINDER_COLUMN_G_NOTC_NOTS_CATEGORYID_2 = "mbThread.categoryId != ? AND ";
12444 private static final String _FINDER_COLUMN_G_NOTC_NOTS_STATUS_2 = "mbThread.status != ?";
12445
12446 public MBThreadPersistenceImpl() {
12447 setModelClass(MBThread.class);
12448 }
12449
12450
12455 @Override
12456 public void cacheResult(MBThread mbThread) {
12457 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12458 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread);
12459
12460 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
12461 new Object[] { mbThread.getUuid(), mbThread.getGroupId() }, mbThread);
12462
12463 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12464 new Object[] { mbThread.getRootMessageId() }, mbThread);
12465
12466 mbThread.resetOriginalValues();
12467 }
12468
12469
12474 @Override
12475 public void cacheResult(List<MBThread> mbThreads) {
12476 for (MBThread mbThread : mbThreads) {
12477 if (EntityCacheUtil.getResult(
12478 MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12479 MBThreadImpl.class, mbThread.getPrimaryKey()) == null) {
12480 cacheResult(mbThread);
12481 }
12482 else {
12483 mbThread.resetOriginalValues();
12484 }
12485 }
12486 }
12487
12488
12495 @Override
12496 public void clearCache() {
12497 EntityCacheUtil.clearCache(MBThreadImpl.class);
12498
12499 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
12500 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12501 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12502 }
12503
12504
12511 @Override
12512 public void clearCache(MBThread mbThread) {
12513 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12514 MBThreadImpl.class, mbThread.getPrimaryKey());
12515
12516 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12517 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12518
12519 clearUniqueFindersCache(mbThread);
12520 }
12521
12522 @Override
12523 public void clearCache(List<MBThread> mbThreads) {
12524 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12525 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12526
12527 for (MBThread mbThread : mbThreads) {
12528 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12529 MBThreadImpl.class, mbThread.getPrimaryKey());
12530
12531 clearUniqueFindersCache(mbThread);
12532 }
12533 }
12534
12535 protected void cacheUniqueFindersCache(MBThread mbThread) {
12536 if (mbThread.isNew()) {
12537 Object[] args = new Object[] {
12538 mbThread.getUuid(), mbThread.getGroupId()
12539 };
12540
12541 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12542 Long.valueOf(1));
12543 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12544 mbThread);
12545
12546 args = new Object[] { mbThread.getRootMessageId() };
12547
12548 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args,
12549 Long.valueOf(1));
12550 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args,
12551 mbThread);
12552 }
12553 else {
12554 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12555
12556 if ((mbThreadModelImpl.getColumnBitmask() &
12557 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12558 Object[] args = new Object[] {
12559 mbThread.getUuid(), mbThread.getGroupId()
12560 };
12561
12562 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
12563 Long.valueOf(1));
12564 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
12565 mbThread);
12566 }
12567
12568 if ((mbThreadModelImpl.getColumnBitmask() &
12569 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
12570 Object[] args = new Object[] { mbThread.getRootMessageId() };
12571
12572 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
12573 args, Long.valueOf(1));
12574 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12575 args, mbThread);
12576 }
12577 }
12578 }
12579
12580 protected void clearUniqueFindersCache(MBThread mbThread) {
12581 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12582
12583 Object[] args = new Object[] { mbThread.getUuid(), mbThread.getGroupId() };
12584
12585 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12586 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12587
12588 if ((mbThreadModelImpl.getColumnBitmask() &
12589 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
12590 args = new Object[] {
12591 mbThreadModelImpl.getOriginalUuid(),
12592 mbThreadModelImpl.getOriginalGroupId()
12593 };
12594
12595 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
12596 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
12597 }
12598
12599 args = new Object[] { mbThread.getRootMessageId() };
12600
12601 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID, args);
12602 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID, args);
12603
12604 if ((mbThreadModelImpl.getColumnBitmask() &
12605 FINDER_PATH_FETCH_BY_ROOTMESSAGEID.getColumnBitmask()) != 0) {
12606 args = new Object[] { mbThreadModelImpl.getOriginalRootMessageId() };
12607
12608 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_ROOTMESSAGEID,
12609 args);
12610 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_ROOTMESSAGEID,
12611 args);
12612 }
12613 }
12614
12615
12621 @Override
12622 public MBThread create(long threadId) {
12623 MBThread mbThread = new MBThreadImpl();
12624
12625 mbThread.setNew(true);
12626 mbThread.setPrimaryKey(threadId);
12627
12628 String uuid = PortalUUIDUtil.generate();
12629
12630 mbThread.setUuid(uuid);
12631
12632 return mbThread;
12633 }
12634
12635
12642 @Override
12643 public MBThread remove(long threadId) throws NoSuchThreadException {
12644 return remove((Serializable)threadId);
12645 }
12646
12647
12654 @Override
12655 public MBThread remove(Serializable primaryKey)
12656 throws NoSuchThreadException {
12657 Session session = null;
12658
12659 try {
12660 session = openSession();
12661
12662 MBThread mbThread = (MBThread)session.get(MBThreadImpl.class,
12663 primaryKey);
12664
12665 if (mbThread == null) {
12666 if (_log.isWarnEnabled()) {
12667 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
12668 }
12669
12670 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
12671 primaryKey);
12672 }
12673
12674 return remove(mbThread);
12675 }
12676 catch (NoSuchThreadException nsee) {
12677 throw nsee;
12678 }
12679 catch (Exception e) {
12680 throw processException(e);
12681 }
12682 finally {
12683 closeSession(session);
12684 }
12685 }
12686
12687 @Override
12688 protected MBThread removeImpl(MBThread mbThread) {
12689 mbThread = toUnwrappedModel(mbThread);
12690
12691 Session session = null;
12692
12693 try {
12694 session = openSession();
12695
12696 if (!session.contains(mbThread)) {
12697 mbThread = (MBThread)session.get(MBThreadImpl.class,
12698 mbThread.getPrimaryKeyObj());
12699 }
12700
12701 if (mbThread != null) {
12702 session.delete(mbThread);
12703 }
12704 }
12705 catch (Exception e) {
12706 throw processException(e);
12707 }
12708 finally {
12709 closeSession(session);
12710 }
12711
12712 if (mbThread != null) {
12713 clearCache(mbThread);
12714 }
12715
12716 return mbThread;
12717 }
12718
12719 @Override
12720 public MBThread updateImpl(MBThread mbThread) {
12721 mbThread = toUnwrappedModel(mbThread);
12722
12723 boolean isNew = mbThread.isNew();
12724
12725 MBThreadModelImpl mbThreadModelImpl = (MBThreadModelImpl)mbThread;
12726
12727 if (Validator.isNull(mbThread.getUuid())) {
12728 String uuid = PortalUUIDUtil.generate();
12729
12730 mbThread.setUuid(uuid);
12731 }
12732
12733 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
12734
12735 Date now = new Date();
12736
12737 if (isNew && (mbThread.getCreateDate() == null)) {
12738 if (serviceContext == null) {
12739 mbThread.setCreateDate(now);
12740 }
12741 else {
12742 mbThread.setCreateDate(serviceContext.getCreateDate(now));
12743 }
12744 }
12745
12746 if (!mbThreadModelImpl.hasSetModifiedDate()) {
12747 if (serviceContext == null) {
12748 mbThread.setModifiedDate(now);
12749 }
12750 else {
12751 mbThread.setModifiedDate(serviceContext.getModifiedDate(now));
12752 }
12753 }
12754
12755 Session session = null;
12756
12757 try {
12758 session = openSession();
12759
12760 if (mbThread.isNew()) {
12761 session.save(mbThread);
12762
12763 mbThread.setNew(false);
12764 }
12765 else {
12766 session.merge(mbThread);
12767 }
12768 }
12769 catch (Exception e) {
12770 throw processException(e);
12771 }
12772 finally {
12773 closeSession(session);
12774 }
12775
12776 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
12777
12778 if (isNew || !MBThreadModelImpl.COLUMN_BITMASK_ENABLED) {
12779 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
12780 }
12781
12782 else {
12783 if ((mbThreadModelImpl.getColumnBitmask() &
12784 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
12785 Object[] args = new Object[] { mbThreadModelImpl.getOriginalUuid() };
12786
12787 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12788 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12789 args);
12790
12791 args = new Object[] { mbThreadModelImpl.getUuid() };
12792
12793 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
12794 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
12795 args);
12796 }
12797
12798 if ((mbThreadModelImpl.getColumnBitmask() &
12799 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
12800 Object[] args = new Object[] {
12801 mbThreadModelImpl.getOriginalUuid(),
12802 mbThreadModelImpl.getOriginalCompanyId()
12803 };
12804
12805 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12806 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12807 args);
12808
12809 args = new Object[] {
12810 mbThreadModelImpl.getUuid(),
12811 mbThreadModelImpl.getCompanyId()
12812 };
12813
12814 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
12815 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
12816 args);
12817 }
12818
12819 if ((mbThreadModelImpl.getColumnBitmask() &
12820 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
12821 Object[] args = new Object[] {
12822 mbThreadModelImpl.getOriginalGroupId()
12823 };
12824
12825 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12826 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12827 args);
12828
12829 args = new Object[] { mbThreadModelImpl.getGroupId() };
12830
12831 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
12832 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
12833 args);
12834 }
12835
12836 if ((mbThreadModelImpl.getColumnBitmask() &
12837 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
12838 Object[] args = new Object[] {
12839 mbThreadModelImpl.getOriginalGroupId(),
12840 mbThreadModelImpl.getOriginalCategoryId()
12841 };
12842
12843 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
12844 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
12845 args);
12846
12847 args = new Object[] {
12848 mbThreadModelImpl.getGroupId(),
12849 mbThreadModelImpl.getCategoryId()
12850 };
12851
12852 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
12853 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
12854 args);
12855 }
12856
12857 if ((mbThreadModelImpl.getColumnBitmask() &
12858 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
12859 Object[] args = new Object[] {
12860 mbThreadModelImpl.getOriginalGroupId(),
12861 mbThreadModelImpl.getOriginalStatus()
12862 };
12863
12864 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
12865 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
12866 args);
12867
12868 args = new Object[] {
12869 mbThreadModelImpl.getGroupId(),
12870 mbThreadModelImpl.getStatus()
12871 };
12872
12873 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
12874 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
12875 args);
12876 }
12877
12878 if ((mbThreadModelImpl.getColumnBitmask() &
12879 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P.getColumnBitmask()) != 0) {
12880 Object[] args = new Object[] {
12881 mbThreadModelImpl.getOriginalCategoryId(),
12882 mbThreadModelImpl.getOriginalPriority()
12883 };
12884
12885 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
12886 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
12887 args);
12888
12889 args = new Object[] {
12890 mbThreadModelImpl.getCategoryId(),
12891 mbThreadModelImpl.getPriority()
12892 };
12893
12894 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_P, args);
12895 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_P,
12896 args);
12897 }
12898
12899 if ((mbThreadModelImpl.getColumnBitmask() &
12900 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P.getColumnBitmask()) != 0) {
12901 Object[] args = new Object[] {
12902 mbThreadModelImpl.getOriginalLastPostDate(),
12903 mbThreadModelImpl.getOriginalPriority()
12904 };
12905
12906 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
12907 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
12908 args);
12909
12910 args = new Object[] {
12911 mbThreadModelImpl.getLastPostDate(),
12912 mbThreadModelImpl.getPriority()
12913 };
12914
12915 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_L_P, args);
12916 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_L_P,
12917 args);
12918 }
12919
12920 if ((mbThreadModelImpl.getColumnBitmask() &
12921 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L.getColumnBitmask()) != 0) {
12922 Object[] args = new Object[] {
12923 mbThreadModelImpl.getOriginalGroupId(),
12924 mbThreadModelImpl.getOriginalCategoryId(),
12925 mbThreadModelImpl.getOriginalLastPostDate()
12926 };
12927
12928 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
12929 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
12930 args);
12931
12932 args = new Object[] {
12933 mbThreadModelImpl.getGroupId(),
12934 mbThreadModelImpl.getCategoryId(),
12935 mbThreadModelImpl.getLastPostDate()
12936 };
12937
12938 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_L, args);
12939 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_L,
12940 args);
12941 }
12942
12943 if ((mbThreadModelImpl.getColumnBitmask() &
12944 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
12945 Object[] args = new Object[] {
12946 mbThreadModelImpl.getOriginalGroupId(),
12947 mbThreadModelImpl.getOriginalCategoryId(),
12948 mbThreadModelImpl.getOriginalStatus()
12949 };
12950
12951 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
12952 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
12953 args);
12954
12955 args = new Object[] {
12956 mbThreadModelImpl.getGroupId(),
12957 mbThreadModelImpl.getCategoryId(),
12958 mbThreadModelImpl.getStatus()
12959 };
12960
12961 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
12962 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
12963 args);
12964 }
12965 }
12966
12967 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
12968 MBThreadImpl.class, mbThread.getPrimaryKey(), mbThread, false);
12969
12970 clearUniqueFindersCache(mbThread);
12971 cacheUniqueFindersCache(mbThread);
12972
12973 mbThread.resetOriginalValues();
12974
12975 return mbThread;
12976 }
12977
12978 protected MBThread toUnwrappedModel(MBThread mbThread) {
12979 if (mbThread instanceof MBThreadImpl) {
12980 return mbThread;
12981 }
12982
12983 MBThreadImpl mbThreadImpl = new MBThreadImpl();
12984
12985 mbThreadImpl.setNew(mbThread.isNew());
12986 mbThreadImpl.setPrimaryKey(mbThread.getPrimaryKey());
12987
12988 mbThreadImpl.setUuid(mbThread.getUuid());
12989 mbThreadImpl.setThreadId(mbThread.getThreadId());
12990 mbThreadImpl.setGroupId(mbThread.getGroupId());
12991 mbThreadImpl.setCompanyId(mbThread.getCompanyId());
12992 mbThreadImpl.setUserId(mbThread.getUserId());
12993 mbThreadImpl.setUserName(mbThread.getUserName());
12994 mbThreadImpl.setCreateDate(mbThread.getCreateDate());
12995 mbThreadImpl.setModifiedDate(mbThread.getModifiedDate());
12996 mbThreadImpl.setCategoryId(mbThread.getCategoryId());
12997 mbThreadImpl.setRootMessageId(mbThread.getRootMessageId());
12998 mbThreadImpl.setRootMessageUserId(mbThread.getRootMessageUserId());
12999 mbThreadImpl.setMessageCount(mbThread.getMessageCount());
13000 mbThreadImpl.setViewCount(mbThread.getViewCount());
13001 mbThreadImpl.setLastPostByUserId(mbThread.getLastPostByUserId());
13002 mbThreadImpl.setLastPostDate(mbThread.getLastPostDate());
13003 mbThreadImpl.setPriority(mbThread.getPriority());
13004 mbThreadImpl.setQuestion(mbThread.isQuestion());
13005 mbThreadImpl.setStatus(mbThread.getStatus());
13006 mbThreadImpl.setStatusByUserId(mbThread.getStatusByUserId());
13007 mbThreadImpl.setStatusByUserName(mbThread.getStatusByUserName());
13008 mbThreadImpl.setStatusDate(mbThread.getStatusDate());
13009
13010 return mbThreadImpl;
13011 }
13012
13013
13020 @Override
13021 public MBThread findByPrimaryKey(Serializable primaryKey)
13022 throws NoSuchThreadException {
13023 MBThread mbThread = fetchByPrimaryKey(primaryKey);
13024
13025 if (mbThread == null) {
13026 if (_log.isWarnEnabled()) {
13027 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
13028 }
13029
13030 throw new NoSuchThreadException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
13031 primaryKey);
13032 }
13033
13034 return mbThread;
13035 }
13036
13037
13044 @Override
13045 public MBThread findByPrimaryKey(long threadId)
13046 throws NoSuchThreadException {
13047 return findByPrimaryKey((Serializable)threadId);
13048 }
13049
13050
13056 @Override
13057 public MBThread fetchByPrimaryKey(Serializable primaryKey) {
13058 MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13059 MBThreadImpl.class, primaryKey);
13060
13061 if (mbThread == _nullMBThread) {
13062 return null;
13063 }
13064
13065 if (mbThread == null) {
13066 Session session = null;
13067
13068 try {
13069 session = openSession();
13070
13071 mbThread = (MBThread)session.get(MBThreadImpl.class, primaryKey);
13072
13073 if (mbThread != null) {
13074 cacheResult(mbThread);
13075 }
13076 else {
13077 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13078 MBThreadImpl.class, primaryKey, _nullMBThread);
13079 }
13080 }
13081 catch (Exception e) {
13082 EntityCacheUtil.removeResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13083 MBThreadImpl.class, primaryKey);
13084
13085 throw processException(e);
13086 }
13087 finally {
13088 closeSession(session);
13089 }
13090 }
13091
13092 return mbThread;
13093 }
13094
13095
13101 @Override
13102 public MBThread fetchByPrimaryKey(long threadId) {
13103 return fetchByPrimaryKey((Serializable)threadId);
13104 }
13105
13106 @Override
13107 public Map<Serializable, MBThread> fetchByPrimaryKeys(
13108 Set<Serializable> primaryKeys) {
13109 if (primaryKeys.isEmpty()) {
13110 return Collections.emptyMap();
13111 }
13112
13113 Map<Serializable, MBThread> map = new HashMap<Serializable, MBThread>();
13114
13115 if (primaryKeys.size() == 1) {
13116 Iterator<Serializable> iterator = primaryKeys.iterator();
13117
13118 Serializable primaryKey = iterator.next();
13119
13120 MBThread mbThread = fetchByPrimaryKey(primaryKey);
13121
13122 if (mbThread != null) {
13123 map.put(primaryKey, mbThread);
13124 }
13125
13126 return map;
13127 }
13128
13129 Set<Serializable> uncachedPrimaryKeys = null;
13130
13131 for (Serializable primaryKey : primaryKeys) {
13132 MBThread mbThread = (MBThread)EntityCacheUtil.getResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13133 MBThreadImpl.class, primaryKey);
13134
13135 if (mbThread == null) {
13136 if (uncachedPrimaryKeys == null) {
13137 uncachedPrimaryKeys = new HashSet<Serializable>();
13138 }
13139
13140 uncachedPrimaryKeys.add(primaryKey);
13141 }
13142 else {
13143 map.put(primaryKey, mbThread);
13144 }
13145 }
13146
13147 if (uncachedPrimaryKeys == null) {
13148 return map;
13149 }
13150
13151 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
13152 1);
13153
13154 query.append(_SQL_SELECT_MBTHREAD_WHERE_PKS_IN);
13155
13156 for (Serializable primaryKey : uncachedPrimaryKeys) {
13157 query.append(String.valueOf(primaryKey));
13158
13159 query.append(StringPool.COMMA);
13160 }
13161
13162 query.setIndex(query.index() - 1);
13163
13164 query.append(StringPool.CLOSE_PARENTHESIS);
13165
13166 String sql = query.toString();
13167
13168 Session session = null;
13169
13170 try {
13171 session = openSession();
13172
13173 Query q = session.createQuery(sql);
13174
13175 for (MBThread mbThread : (List<MBThread>)q.list()) {
13176 map.put(mbThread.getPrimaryKeyObj(), mbThread);
13177
13178 cacheResult(mbThread);
13179
13180 uncachedPrimaryKeys.remove(mbThread.getPrimaryKeyObj());
13181 }
13182
13183 for (Serializable primaryKey : uncachedPrimaryKeys) {
13184 EntityCacheUtil.putResult(MBThreadModelImpl.ENTITY_CACHE_ENABLED,
13185 MBThreadImpl.class, primaryKey, _nullMBThread);
13186 }
13187 }
13188 catch (Exception e) {
13189 throw processException(e);
13190 }
13191 finally {
13192 closeSession(session);
13193 }
13194
13195 return map;
13196 }
13197
13198
13203 @Override
13204 public List<MBThread> findAll() {
13205 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13206 }
13207
13208
13219 @Override
13220 public List<MBThread> findAll(int start, int end) {
13221 return findAll(start, end, null);
13222 }
13223
13224
13236 @Override
13237 public List<MBThread> findAll(int start, int end,
13238 OrderByComparator<MBThread> orderByComparator) {
13239 boolean pagination = true;
13240 FinderPath finderPath = null;
13241 Object[] finderArgs = null;
13242
13243 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13244 (orderByComparator == null)) {
13245 pagination = false;
13246 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
13247 finderArgs = FINDER_ARGS_EMPTY;
13248 }
13249 else {
13250 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
13251 finderArgs = new Object[] { start, end, orderByComparator };
13252 }
13253
13254 List<MBThread> list = (List<MBThread>)FinderCacheUtil.getResult(finderPath,
13255 finderArgs, this);
13256
13257 if (list == null) {
13258 StringBundler query = null;
13259 String sql = null;
13260
13261 if (orderByComparator != null) {
13262 query = new StringBundler(2 +
13263 (orderByComparator.getOrderByFields().length * 3));
13264
13265 query.append(_SQL_SELECT_MBTHREAD);
13266
13267 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13268 orderByComparator);
13269
13270 sql = query.toString();
13271 }
13272 else {
13273 sql = _SQL_SELECT_MBTHREAD;
13274
13275 if (pagination) {
13276 sql = sql.concat(MBThreadModelImpl.ORDER_BY_JPQL);
13277 }
13278 }
13279
13280 Session session = null;
13281
13282 try {
13283 session = openSession();
13284
13285 Query q = session.createQuery(sql);
13286
13287 if (!pagination) {
13288 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13289 start, end, false);
13290
13291 Collections.sort(list);
13292
13293 list = Collections.unmodifiableList(list);
13294 }
13295 else {
13296 list = (List<MBThread>)QueryUtil.list(q, getDialect(),
13297 start, end);
13298 }
13299
13300 cacheResult(list);
13301
13302 FinderCacheUtil.putResult(finderPath, finderArgs, list);
13303 }
13304 catch (Exception e) {
13305 FinderCacheUtil.removeResult(finderPath, finderArgs);
13306
13307 throw processException(e);
13308 }
13309 finally {
13310 closeSession(session);
13311 }
13312 }
13313
13314 return list;
13315 }
13316
13317
13321 @Override
13322 public void removeAll() {
13323 for (MBThread mbThread : findAll()) {
13324 remove(mbThread);
13325 }
13326 }
13327
13328
13333 @Override
13334 public int countAll() {
13335 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
13336 FINDER_ARGS_EMPTY, this);
13337
13338 if (count == null) {
13339 Session session = null;
13340
13341 try {
13342 session = openSession();
13343
13344 Query q = session.createQuery(_SQL_COUNT_MBTHREAD);
13345
13346 count = (Long)q.uniqueResult();
13347
13348 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
13349 FINDER_ARGS_EMPTY, count);
13350 }
13351 catch (Exception e) {
13352 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
13353 FINDER_ARGS_EMPTY);
13354
13355 throw processException(e);
13356 }
13357 finally {
13358 closeSession(session);
13359 }
13360 }
13361
13362 return count.intValue();
13363 }
13364
13365 @Override
13366 protected Set<String> getBadColumnNames() {
13367 return _badColumnNames;
13368 }
13369
13370
13373 public void afterPropertiesSet() {
13374 }
13375
13376 public void destroy() {
13377 EntityCacheUtil.removeCache(MBThreadImpl.class.getName());
13378 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
13379 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
13380 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
13381 }
13382
13383 private static final String _SQL_SELECT_MBTHREAD = "SELECT mbThread FROM MBThread mbThread";
13384 private static final String _SQL_SELECT_MBTHREAD_WHERE_PKS_IN = "SELECT mbThread FROM MBThread mbThread WHERE threadId IN (";
13385 private static final String _SQL_SELECT_MBTHREAD_WHERE = "SELECT mbThread FROM MBThread mbThread WHERE ";
13386 private static final String _SQL_COUNT_MBTHREAD = "SELECT COUNT(mbThread) FROM MBThread mbThread";
13387 private static final String _SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(mbThread) FROM MBThread mbThread WHERE ";
13388 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbThread.threadId";
13389 private static final String _FILTER_SQL_SELECT_MBTHREAD_WHERE = "SELECT DISTINCT {mbThread.*} FROM MBThread mbThread WHERE ";
13390 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_1 =
13391 "SELECT {MBThread.*} FROM (SELECT DISTINCT mbThread.threadId FROM MBThread mbThread WHERE ";
13392 private static final String _FILTER_SQL_SELECT_MBTHREAD_NO_INLINE_DISTINCT_WHERE_2 =
13393 ") TEMP_TABLE INNER JOIN MBThread ON TEMP_TABLE.threadId = MBThread.threadId";
13394 private static final String _FILTER_SQL_COUNT_MBTHREAD_WHERE = "SELECT COUNT(DISTINCT mbThread.threadId) AS COUNT_VALUE FROM MBThread mbThread WHERE ";
13395 private static final String _FILTER_ENTITY_ALIAS = "mbThread";
13396 private static final String _FILTER_ENTITY_TABLE = "MBThread";
13397 private static final String _ORDER_BY_ENTITY_ALIAS = "mbThread.";
13398 private static final String _ORDER_BY_ENTITY_TABLE = "MBThread.";
13399 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThread exists with the primary key ";
13400 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThread exists with the key {";
13401 private static final Log _log = LogFactoryUtil.getLog(MBThreadPersistenceImpl.class);
13402 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
13403 "uuid"
13404 });
13405 private static final MBThread _nullMBThread = new MBThreadImpl() {
13406 @Override
13407 public Object clone() {
13408 return this;
13409 }
13410
13411 @Override
13412 public CacheModel<MBThread> toCacheModel() {
13413 return _nullMBThreadCacheModel;
13414 }
13415 };
13416
13417 private static final CacheModel<MBThread> _nullMBThreadCacheModel = new CacheModel<MBThread>() {
13418 @Override
13419 public MBThread toEntityModel() {
13420 return _nullMBThread;
13421 }
13422 };
13423 }