001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.SQLQuery;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.sanitizer.Sanitizer;
031 import com.liferay.portal.kernel.sanitizer.SanitizerException;
032 import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
033 import com.liferay.portal.kernel.util.ArrayUtil;
034 import com.liferay.portal.kernel.util.ContentTypes;
035 import com.liferay.portal.kernel.util.GetterUtil;
036 import com.liferay.portal.kernel.util.InstanceFactory;
037 import com.liferay.portal.kernel.util.OrderByComparator;
038 import com.liferay.portal.kernel.util.StringBundler;
039 import com.liferay.portal.kernel.util.StringPool;
040 import com.liferay.portal.kernel.util.StringUtil;
041 import com.liferay.portal.kernel.util.UnmodifiableList;
042 import com.liferay.portal.kernel.util.Validator;
043 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044 import com.liferay.portal.model.CacheModel;
045 import com.liferay.portal.model.ModelListener;
046 import com.liferay.portal.security.auth.PrincipalThreadLocal;
047 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049
050 import com.liferay.portlet.messageboards.NoSuchMessageException;
051 import com.liferay.portlet.messageboards.model.MBMessage;
052 import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
053 import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
054
055 import java.io.Serializable;
056
057 import java.util.ArrayList;
058 import java.util.Collections;
059 import java.util.List;
060
061
073 public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
074 implements MBMessagePersistence {
075
080 public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List1";
083 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List2";
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
086 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
089 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
092 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
095 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097 new String[] {
098 String.class.getName(),
099
100 Integer.class.getName(), Integer.class.getName(),
101 OrderByComparator.class.getName()
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
104 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106 new String[] { String.class.getName() },
107 MBMessageModelImpl.UUID_COLUMN_BITMASK |
108 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
110 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112 new String[] { String.class.getName() });
113
114
121 public List<MBMessage> findByUuid(String uuid) throws SystemException {
122 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
138 public List<MBMessage> findByUuid(String uuid, int start, int end)
139 throws SystemException {
140 return findByUuid(uuid, start, end, null);
141 }
142
143
157 public List<MBMessage> findByUuid(String uuid, int start, int end,
158 OrderByComparator orderByComparator) throws SystemException {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171 finderArgs = new Object[] { uuid, start, end, orderByComparator };
172 }
173
174 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
175 finderArgs, this);
176
177 if ((list != null) && !list.isEmpty()) {
178 for (MBMessage mbMessage : list) {
179 if (!Validator.equals(uuid, mbMessage.getUuid())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(3 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(3);
196 }
197
198 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
199
200 if (uuid == null) {
201 query.append(_FINDER_COLUMN_UUID_UUID_1);
202 }
203 else {
204 if (uuid.equals(StringPool.BLANK)) {
205 query.append(_FINDER_COLUMN_UUID_UUID_3);
206 }
207 else {
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210 }
211
212 if (orderByComparator != null) {
213 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
214 orderByComparator);
215 }
216 else
217 if (pagination) {
218 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
219 }
220
221 String sql = query.toString();
222
223 Session session = null;
224
225 try {
226 session = openSession();
227
228 Query q = session.createQuery(sql);
229
230 QueryPos qPos = QueryPos.getInstance(q);
231
232 if (uuid != null) {
233 qPos.add(uuid);
234 }
235
236 if (!pagination) {
237 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
238 start, end, false);
239
240 Collections.sort(list);
241
242 list = new UnmodifiableList<MBMessage>(list);
243 }
244 else {
245 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
246 start, end);
247 }
248
249 cacheResult(list);
250
251 FinderCacheUtil.putResult(finderPath, finderArgs, list);
252 }
253 catch (Exception e) {
254 FinderCacheUtil.removeResult(finderPath, finderArgs);
255
256 throw processException(e);
257 }
258 finally {
259 closeSession(session);
260 }
261 }
262
263 return list;
264 }
265
266
275 public MBMessage findByUuid_First(String uuid,
276 OrderByComparator orderByComparator)
277 throws NoSuchMessageException, SystemException {
278 MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
279
280 if (mbMessage != null) {
281 return mbMessage;
282 }
283
284 StringBundler msg = new StringBundler(4);
285
286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
287
288 msg.append("uuid=");
289 msg.append(uuid);
290
291 msg.append(StringPool.CLOSE_CURLY_BRACE);
292
293 throw new NoSuchMessageException(msg.toString());
294 }
295
296
304 public MBMessage fetchByUuid_First(String uuid,
305 OrderByComparator orderByComparator) throws SystemException {
306 List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
307
308 if (!list.isEmpty()) {
309 return list.get(0);
310 }
311
312 return null;
313 }
314
315
324 public MBMessage findByUuid_Last(String uuid,
325 OrderByComparator orderByComparator)
326 throws NoSuchMessageException, SystemException {
327 MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
328
329 if (mbMessage != null) {
330 return mbMessage;
331 }
332
333 StringBundler msg = new StringBundler(4);
334
335 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336
337 msg.append("uuid=");
338 msg.append(uuid);
339
340 msg.append(StringPool.CLOSE_CURLY_BRACE);
341
342 throw new NoSuchMessageException(msg.toString());
343 }
344
345
353 public MBMessage fetchByUuid_Last(String uuid,
354 OrderByComparator orderByComparator) throws SystemException {
355 int count = countByUuid(uuid);
356
357 List<MBMessage> list = findByUuid(uuid, count - 1, count,
358 orderByComparator);
359
360 if (!list.isEmpty()) {
361 return list.get(0);
362 }
363
364 return null;
365 }
366
367
377 public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
378 OrderByComparator orderByComparator)
379 throws NoSuchMessageException, SystemException {
380 MBMessage mbMessage = findByPrimaryKey(messageId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 MBMessage[] array = new MBMessageImpl[3];
388
389 array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
390 orderByComparator, true);
391
392 array[1] = mbMessage;
393
394 array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
395 orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected MBMessage getByUuid_PrevAndNext(Session session,
408 MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
409 boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
421
422 if (uuid == null) {
423 query.append(_FINDER_COLUMN_UUID_UUID_1);
424 }
425 else {
426 if (uuid.equals(StringPool.BLANK)) {
427 query.append(_FINDER_COLUMN_UUID_UUID_3);
428 }
429 else {
430 query.append(_FINDER_COLUMN_UUID_UUID_2);
431 }
432 }
433
434 if (orderByComparator != null) {
435 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436
437 if (orderByConditionFields.length > 0) {
438 query.append(WHERE_AND);
439 }
440
441 for (int i = 0; i < orderByConditionFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByConditionFields[i]);
444
445 if ((i + 1) < orderByConditionFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN_HAS_NEXT);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN);
459 }
460 }
461 }
462
463 query.append(ORDER_BY_CLAUSE);
464
465 String[] orderByFields = orderByComparator.getOrderByFields();
466
467 for (int i = 0; i < orderByFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByFields[i]);
470
471 if ((i + 1) < orderByFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC_HAS_NEXT);
474 }
475 else {
476 query.append(ORDER_BY_DESC_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC);
482 }
483 else {
484 query.append(ORDER_BY_DESC);
485 }
486 }
487 }
488 }
489 else {
490 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 q.setFirstResult(0);
498 q.setMaxResults(2);
499
500 QueryPos qPos = QueryPos.getInstance(q);
501
502 if (uuid != null) {
503 qPos.add(uuid);
504 }
505
506 if (orderByComparator != null) {
507 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
508
509 for (Object value : values) {
510 qPos.add(value);
511 }
512 }
513
514 List<MBMessage> list = q.list();
515
516 if (list.size() == 2) {
517 return list.get(1);
518 }
519 else {
520 return null;
521 }
522 }
523
524
530 public void removeByUuid(String uuid) throws SystemException {
531 for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
532 QueryUtil.ALL_POS, null)) {
533 remove(mbMessage);
534 }
535 }
536
537
544 public int countByUuid(String uuid) throws SystemException {
545 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
546
547 Object[] finderArgs = new Object[] { uuid };
548
549 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
550 this);
551
552 if (count == null) {
553 StringBundler query = new StringBundler(2);
554
555 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
556
557 if (uuid == null) {
558 query.append(_FINDER_COLUMN_UUID_UUID_1);
559 }
560 else {
561 if (uuid.equals(StringPool.BLANK)) {
562 query.append(_FINDER_COLUMN_UUID_UUID_3);
563 }
564 else {
565 query.append(_FINDER_COLUMN_UUID_UUID_2);
566 }
567 }
568
569 String sql = query.toString();
570
571 Session session = null;
572
573 try {
574 session = openSession();
575
576 Query q = session.createQuery(sql);
577
578 QueryPos qPos = QueryPos.getInstance(q);
579
580 if (uuid != null) {
581 qPos.add(uuid);
582 }
583
584 count = (Long)q.uniqueResult();
585
586 FinderCacheUtil.putResult(finderPath, finderArgs, count);
587 }
588 catch (Exception e) {
589 FinderCacheUtil.removeResult(finderPath, finderArgs);
590
591 throw processException(e);
592 }
593 finally {
594 closeSession(session);
595 }
596 }
597
598 return count.intValue();
599 }
600
601 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
602 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
603 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?)";
604 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
605 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
606 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
607 new String[] { String.class.getName(), Long.class.getName() },
608 MBMessageModelImpl.UUID_COLUMN_BITMASK |
609 MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
610 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
611 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
612 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
613 new String[] { String.class.getName(), Long.class.getName() });
614
615
624 public MBMessage findByUUID_G(String uuid, long groupId)
625 throws NoSuchMessageException, SystemException {
626 MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
627
628 if (mbMessage == null) {
629 StringBundler msg = new StringBundler(6);
630
631 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
632
633 msg.append("uuid=");
634 msg.append(uuid);
635
636 msg.append(", groupId=");
637 msg.append(groupId);
638
639 msg.append(StringPool.CLOSE_CURLY_BRACE);
640
641 if (_log.isWarnEnabled()) {
642 _log.warn(msg.toString());
643 }
644
645 throw new NoSuchMessageException(msg.toString());
646 }
647
648 return mbMessage;
649 }
650
651
659 public MBMessage fetchByUUID_G(String uuid, long groupId)
660 throws SystemException {
661 return fetchByUUID_G(uuid, groupId, true);
662 }
663
664
673 public MBMessage fetchByUUID_G(String uuid, long groupId,
674 boolean retrieveFromCache) throws SystemException {
675 Object[] finderArgs = new Object[] { uuid, groupId };
676
677 Object result = null;
678
679 if (retrieveFromCache) {
680 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
681 finderArgs, this);
682 }
683
684 if (result instanceof MBMessage) {
685 MBMessage mbMessage = (MBMessage)result;
686
687 if (!Validator.equals(uuid, mbMessage.getUuid()) ||
688 (groupId != mbMessage.getGroupId())) {
689 result = null;
690 }
691 }
692
693 if (result == null) {
694 StringBundler query = new StringBundler(4);
695
696 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
697
698 if (uuid == null) {
699 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
700 }
701 else {
702 if (uuid.equals(StringPool.BLANK)) {
703 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
704 }
705 else {
706 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
707 }
708 }
709
710 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
711
712 String sql = query.toString();
713
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 Query q = session.createQuery(sql);
720
721 QueryPos qPos = QueryPos.getInstance(q);
722
723 if (uuid != null) {
724 qPos.add(uuid);
725 }
726
727 qPos.add(groupId);
728
729 List<MBMessage> list = q.list();
730
731 if (list.isEmpty()) {
732 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
733 finderArgs, list);
734 }
735 else {
736 MBMessage mbMessage = list.get(0);
737
738 result = mbMessage;
739
740 cacheResult(mbMessage);
741
742 if ((mbMessage.getUuid() == null) ||
743 !mbMessage.getUuid().equals(uuid) ||
744 (mbMessage.getGroupId() != groupId)) {
745 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
746 finderArgs, mbMessage);
747 }
748 }
749 }
750 catch (Exception e) {
751 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
752 finderArgs);
753
754 throw processException(e);
755 }
756 finally {
757 closeSession(session);
758 }
759 }
760
761 if (result instanceof List<?>) {
762 return null;
763 }
764 else {
765 return (MBMessage)result;
766 }
767 }
768
769
777 public MBMessage removeByUUID_G(String uuid, long groupId)
778 throws NoSuchMessageException, SystemException {
779 MBMessage mbMessage = findByUUID_G(uuid, groupId);
780
781 return remove(mbMessage);
782 }
783
784
792 public int countByUUID_G(String uuid, long groupId)
793 throws SystemException {
794 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
795
796 Object[] finderArgs = new Object[] { uuid, groupId };
797
798 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
799 this);
800
801 if (count == null) {
802 StringBundler query = new StringBundler(3);
803
804 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
805
806 if (uuid == null) {
807 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
808 }
809 else {
810 if (uuid.equals(StringPool.BLANK)) {
811 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
812 }
813 else {
814 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
815 }
816 }
817
818 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
819
820 String sql = query.toString();
821
822 Session session = null;
823
824 try {
825 session = openSession();
826
827 Query q = session.createQuery(sql);
828
829 QueryPos qPos = QueryPos.getInstance(q);
830
831 if (uuid != null) {
832 qPos.add(uuid);
833 }
834
835 qPos.add(groupId);
836
837 count = (Long)q.uniqueResult();
838
839 FinderCacheUtil.putResult(finderPath, finderArgs, count);
840 }
841 catch (Exception e) {
842 FinderCacheUtil.removeResult(finderPath, finderArgs);
843
844 throw processException(e);
845 }
846 finally {
847 closeSession(session);
848 }
849 }
850
851 return count.intValue();
852 }
853
854 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
855 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
856 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
857 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
858 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
859 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
860 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
861 new String[] {
862 String.class.getName(), Long.class.getName(),
863
864 Integer.class.getName(), Integer.class.getName(),
865 OrderByComparator.class.getName()
866 });
867 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
868 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
869 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
870 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
871 new String[] { String.class.getName(), Long.class.getName() },
872 MBMessageModelImpl.UUID_COLUMN_BITMASK |
873 MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
874 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
875 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
876 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
877 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
878 new String[] { String.class.getName(), Long.class.getName() });
879
880
888 public List<MBMessage> findByUuid_C(String uuid, long companyId)
889 throws SystemException {
890 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
891 QueryUtil.ALL_POS, null);
892 }
893
894
908 public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
909 int end) throws SystemException {
910 return findByUuid_C(uuid, companyId, start, end, null);
911 }
912
913
928 public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
929 int end, OrderByComparator orderByComparator) throws SystemException {
930 boolean pagination = true;
931 FinderPath finderPath = null;
932 Object[] finderArgs = null;
933
934 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
935 (orderByComparator == null)) {
936 pagination = false;
937 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
938 finderArgs = new Object[] { uuid, companyId };
939 }
940 else {
941 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
942 finderArgs = new Object[] {
943 uuid, companyId,
944
945 start, end, orderByComparator
946 };
947 }
948
949 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
950 finderArgs, this);
951
952 if ((list != null) && !list.isEmpty()) {
953 for (MBMessage mbMessage : list) {
954 if (!Validator.equals(uuid, mbMessage.getUuid()) ||
955 (companyId != mbMessage.getCompanyId())) {
956 list = null;
957
958 break;
959 }
960 }
961 }
962
963 if (list == null) {
964 StringBundler query = null;
965
966 if (orderByComparator != null) {
967 query = new StringBundler(4 +
968 (orderByComparator.getOrderByFields().length * 3));
969 }
970 else {
971 query = new StringBundler(4);
972 }
973
974 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
975
976 if (uuid == null) {
977 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
978 }
979 else {
980 if (uuid.equals(StringPool.BLANK)) {
981 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
982 }
983 else {
984 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
985 }
986 }
987
988 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
989
990 if (orderByComparator != null) {
991 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
992 orderByComparator);
993 }
994 else
995 if (pagination) {
996 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
997 }
998
999 String sql = query.toString();
1000
1001 Session session = null;
1002
1003 try {
1004 session = openSession();
1005
1006 Query q = session.createQuery(sql);
1007
1008 QueryPos qPos = QueryPos.getInstance(q);
1009
1010 if (uuid != null) {
1011 qPos.add(uuid);
1012 }
1013
1014 qPos.add(companyId);
1015
1016 if (!pagination) {
1017 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1018 start, end, false);
1019
1020 Collections.sort(list);
1021
1022 list = new UnmodifiableList<MBMessage>(list);
1023 }
1024 else {
1025 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1026 start, end);
1027 }
1028
1029 cacheResult(list);
1030
1031 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1032 }
1033 catch (Exception e) {
1034 FinderCacheUtil.removeResult(finderPath, finderArgs);
1035
1036 throw processException(e);
1037 }
1038 finally {
1039 closeSession(session);
1040 }
1041 }
1042
1043 return list;
1044 }
1045
1046
1056 public MBMessage findByUuid_C_First(String uuid, long companyId,
1057 OrderByComparator orderByComparator)
1058 throws NoSuchMessageException, SystemException {
1059 MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1060 orderByComparator);
1061
1062 if (mbMessage != null) {
1063 return mbMessage;
1064 }
1065
1066 StringBundler msg = new StringBundler(6);
1067
1068 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1069
1070 msg.append("uuid=");
1071 msg.append(uuid);
1072
1073 msg.append(", companyId=");
1074 msg.append(companyId);
1075
1076 msg.append(StringPool.CLOSE_CURLY_BRACE);
1077
1078 throw new NoSuchMessageException(msg.toString());
1079 }
1080
1081
1090 public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1091 OrderByComparator orderByComparator) throws SystemException {
1092 List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1093 orderByComparator);
1094
1095 if (!list.isEmpty()) {
1096 return list.get(0);
1097 }
1098
1099 return null;
1100 }
1101
1102
1112 public MBMessage findByUuid_C_Last(String uuid, long companyId,
1113 OrderByComparator orderByComparator)
1114 throws NoSuchMessageException, SystemException {
1115 MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1116 orderByComparator);
1117
1118 if (mbMessage != null) {
1119 return mbMessage;
1120 }
1121
1122 StringBundler msg = new StringBundler(6);
1123
1124 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1125
1126 msg.append("uuid=");
1127 msg.append(uuid);
1128
1129 msg.append(", companyId=");
1130 msg.append(companyId);
1131
1132 msg.append(StringPool.CLOSE_CURLY_BRACE);
1133
1134 throw new NoSuchMessageException(msg.toString());
1135 }
1136
1137
1146 public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1147 OrderByComparator orderByComparator) throws SystemException {
1148 int count = countByUuid_C(uuid, companyId);
1149
1150 List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1151 orderByComparator);
1152
1153 if (!list.isEmpty()) {
1154 return list.get(0);
1155 }
1156
1157 return null;
1158 }
1159
1160
1171 public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1172 long companyId, OrderByComparator orderByComparator)
1173 throws NoSuchMessageException, SystemException {
1174 MBMessage mbMessage = findByPrimaryKey(messageId);
1175
1176 Session session = null;
1177
1178 try {
1179 session = openSession();
1180
1181 MBMessage[] array = new MBMessageImpl[3];
1182
1183 array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1184 companyId, orderByComparator, true);
1185
1186 array[1] = mbMessage;
1187
1188 array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1189 companyId, orderByComparator, false);
1190
1191 return array;
1192 }
1193 catch (Exception e) {
1194 throw processException(e);
1195 }
1196 finally {
1197 closeSession(session);
1198 }
1199 }
1200
1201 protected MBMessage getByUuid_C_PrevAndNext(Session session,
1202 MBMessage mbMessage, String uuid, long companyId,
1203 OrderByComparator orderByComparator, boolean previous) {
1204 StringBundler query = null;
1205
1206 if (orderByComparator != null) {
1207 query = new StringBundler(6 +
1208 (orderByComparator.getOrderByFields().length * 6));
1209 }
1210 else {
1211 query = new StringBundler(3);
1212 }
1213
1214 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1215
1216 if (uuid == null) {
1217 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1218 }
1219 else {
1220 if (uuid.equals(StringPool.BLANK)) {
1221 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1222 }
1223 else {
1224 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1225 }
1226 }
1227
1228 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1229
1230 if (orderByComparator != null) {
1231 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1232
1233 if (orderByConditionFields.length > 0) {
1234 query.append(WHERE_AND);
1235 }
1236
1237 for (int i = 0; i < orderByConditionFields.length; i++) {
1238 query.append(_ORDER_BY_ENTITY_ALIAS);
1239 query.append(orderByConditionFields[i]);
1240
1241 if ((i + 1) < orderByConditionFields.length) {
1242 if (orderByComparator.isAscending() ^ previous) {
1243 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1244 }
1245 else {
1246 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1247 }
1248 }
1249 else {
1250 if (orderByComparator.isAscending() ^ previous) {
1251 query.append(WHERE_GREATER_THAN);
1252 }
1253 else {
1254 query.append(WHERE_LESSER_THAN);
1255 }
1256 }
1257 }
1258
1259 query.append(ORDER_BY_CLAUSE);
1260
1261 String[] orderByFields = orderByComparator.getOrderByFields();
1262
1263 for (int i = 0; i < orderByFields.length; i++) {
1264 query.append(_ORDER_BY_ENTITY_ALIAS);
1265 query.append(orderByFields[i]);
1266
1267 if ((i + 1) < orderByFields.length) {
1268 if (orderByComparator.isAscending() ^ previous) {
1269 query.append(ORDER_BY_ASC_HAS_NEXT);
1270 }
1271 else {
1272 query.append(ORDER_BY_DESC_HAS_NEXT);
1273 }
1274 }
1275 else {
1276 if (orderByComparator.isAscending() ^ previous) {
1277 query.append(ORDER_BY_ASC);
1278 }
1279 else {
1280 query.append(ORDER_BY_DESC);
1281 }
1282 }
1283 }
1284 }
1285 else {
1286 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1287 }
1288
1289 String sql = query.toString();
1290
1291 Query q = session.createQuery(sql);
1292
1293 q.setFirstResult(0);
1294 q.setMaxResults(2);
1295
1296 QueryPos qPos = QueryPos.getInstance(q);
1297
1298 if (uuid != null) {
1299 qPos.add(uuid);
1300 }
1301
1302 qPos.add(companyId);
1303
1304 if (orderByComparator != null) {
1305 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1306
1307 for (Object value : values) {
1308 qPos.add(value);
1309 }
1310 }
1311
1312 List<MBMessage> list = q.list();
1313
1314 if (list.size() == 2) {
1315 return list.get(1);
1316 }
1317 else {
1318 return null;
1319 }
1320 }
1321
1322
1329 public void removeByUuid_C(String uuid, long companyId)
1330 throws SystemException {
1331 for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1332 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1333 remove(mbMessage);
1334 }
1335 }
1336
1337
1345 public int countByUuid_C(String uuid, long companyId)
1346 throws SystemException {
1347 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1348
1349 Object[] finderArgs = new Object[] { uuid, companyId };
1350
1351 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1352 this);
1353
1354 if (count == null) {
1355 StringBundler query = new StringBundler(3);
1356
1357 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1358
1359 if (uuid == null) {
1360 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1361 }
1362 else {
1363 if (uuid.equals(StringPool.BLANK)) {
1364 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1365 }
1366 else {
1367 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1368 }
1369 }
1370
1371 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1372
1373 String sql = query.toString();
1374
1375 Session session = null;
1376
1377 try {
1378 session = openSession();
1379
1380 Query q = session.createQuery(sql);
1381
1382 QueryPos qPos = QueryPos.getInstance(q);
1383
1384 if (uuid != null) {
1385 qPos.add(uuid);
1386 }
1387
1388 qPos.add(companyId);
1389
1390 count = (Long)q.uniqueResult();
1391
1392 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1393 }
1394 catch (Exception e) {
1395 FinderCacheUtil.removeResult(finderPath, finderArgs);
1396
1397 throw processException(e);
1398 }
1399 finally {
1400 closeSession(session);
1401 }
1402 }
1403
1404 return count.intValue();
1405 }
1406
1407 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1408 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1409 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = ?) AND ";
1410 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1411 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1412 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1413 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1414 new String[] {
1415 Long.class.getName(),
1416
1417 Integer.class.getName(), Integer.class.getName(),
1418 OrderByComparator.class.getName()
1419 });
1420 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1421 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1422 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1423 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1424 new String[] { Long.class.getName() },
1425 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1426 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1427 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1428 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1429 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1430 new String[] { Long.class.getName() });
1431
1432
1439 public List<MBMessage> findByGroupId(long groupId)
1440 throws SystemException {
1441 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1442 }
1443
1444
1457 public List<MBMessage> findByGroupId(long groupId, int start, int end)
1458 throws SystemException {
1459 return findByGroupId(groupId, start, end, null);
1460 }
1461
1462
1476 public List<MBMessage> findByGroupId(long groupId, int start, int end,
1477 OrderByComparator orderByComparator) throws SystemException {
1478 boolean pagination = true;
1479 FinderPath finderPath = null;
1480 Object[] finderArgs = null;
1481
1482 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1483 (orderByComparator == null)) {
1484 pagination = false;
1485 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1486 finderArgs = new Object[] { groupId };
1487 }
1488 else {
1489 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1490 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1491 }
1492
1493 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1494 finderArgs, this);
1495
1496 if ((list != null) && !list.isEmpty()) {
1497 for (MBMessage mbMessage : list) {
1498 if ((groupId != mbMessage.getGroupId())) {
1499 list = null;
1500
1501 break;
1502 }
1503 }
1504 }
1505
1506 if (list == null) {
1507 StringBundler query = null;
1508
1509 if (orderByComparator != null) {
1510 query = new StringBundler(3 +
1511 (orderByComparator.getOrderByFields().length * 3));
1512 }
1513 else {
1514 query = new StringBundler(3);
1515 }
1516
1517 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1518
1519 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1520
1521 if (orderByComparator != null) {
1522 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1523 orderByComparator);
1524 }
1525 else
1526 if (pagination) {
1527 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1528 }
1529
1530 String sql = query.toString();
1531
1532 Session session = null;
1533
1534 try {
1535 session = openSession();
1536
1537 Query q = session.createQuery(sql);
1538
1539 QueryPos qPos = QueryPos.getInstance(q);
1540
1541 qPos.add(groupId);
1542
1543 if (!pagination) {
1544 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1545 start, end, false);
1546
1547 Collections.sort(list);
1548
1549 list = new UnmodifiableList<MBMessage>(list);
1550 }
1551 else {
1552 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1553 start, end);
1554 }
1555
1556 cacheResult(list);
1557
1558 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1559 }
1560 catch (Exception e) {
1561 FinderCacheUtil.removeResult(finderPath, finderArgs);
1562
1563 throw processException(e);
1564 }
1565 finally {
1566 closeSession(session);
1567 }
1568 }
1569
1570 return list;
1571 }
1572
1573
1582 public MBMessage findByGroupId_First(long groupId,
1583 OrderByComparator orderByComparator)
1584 throws NoSuchMessageException, SystemException {
1585 MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1586
1587 if (mbMessage != null) {
1588 return mbMessage;
1589 }
1590
1591 StringBundler msg = new StringBundler(4);
1592
1593 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1594
1595 msg.append("groupId=");
1596 msg.append(groupId);
1597
1598 msg.append(StringPool.CLOSE_CURLY_BRACE);
1599
1600 throw new NoSuchMessageException(msg.toString());
1601 }
1602
1603
1611 public MBMessage fetchByGroupId_First(long groupId,
1612 OrderByComparator orderByComparator) throws SystemException {
1613 List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1614
1615 if (!list.isEmpty()) {
1616 return list.get(0);
1617 }
1618
1619 return null;
1620 }
1621
1622
1631 public MBMessage findByGroupId_Last(long groupId,
1632 OrderByComparator orderByComparator)
1633 throws NoSuchMessageException, SystemException {
1634 MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1635
1636 if (mbMessage != null) {
1637 return mbMessage;
1638 }
1639
1640 StringBundler msg = new StringBundler(4);
1641
1642 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1643
1644 msg.append("groupId=");
1645 msg.append(groupId);
1646
1647 msg.append(StringPool.CLOSE_CURLY_BRACE);
1648
1649 throw new NoSuchMessageException(msg.toString());
1650 }
1651
1652
1660 public MBMessage fetchByGroupId_Last(long groupId,
1661 OrderByComparator orderByComparator) throws SystemException {
1662 int count = countByGroupId(groupId);
1663
1664 List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1665 orderByComparator);
1666
1667 if (!list.isEmpty()) {
1668 return list.get(0);
1669 }
1670
1671 return null;
1672 }
1673
1674
1684 public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1685 OrderByComparator orderByComparator)
1686 throws NoSuchMessageException, SystemException {
1687 MBMessage mbMessage = findByPrimaryKey(messageId);
1688
1689 Session session = null;
1690
1691 try {
1692 session = openSession();
1693
1694 MBMessage[] array = new MBMessageImpl[3];
1695
1696 array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1697 orderByComparator, true);
1698
1699 array[1] = mbMessage;
1700
1701 array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1702 orderByComparator, false);
1703
1704 return array;
1705 }
1706 catch (Exception e) {
1707 throw processException(e);
1708 }
1709 finally {
1710 closeSession(session);
1711 }
1712 }
1713
1714 protected MBMessage getByGroupId_PrevAndNext(Session session,
1715 MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1716 boolean previous) {
1717 StringBundler query = null;
1718
1719 if (orderByComparator != null) {
1720 query = new StringBundler(6 +
1721 (orderByComparator.getOrderByFields().length * 6));
1722 }
1723 else {
1724 query = new StringBundler(3);
1725 }
1726
1727 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1728
1729 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1730
1731 if (orderByComparator != null) {
1732 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1733
1734 if (orderByConditionFields.length > 0) {
1735 query.append(WHERE_AND);
1736 }
1737
1738 for (int i = 0; i < orderByConditionFields.length; i++) {
1739 query.append(_ORDER_BY_ENTITY_ALIAS);
1740 query.append(orderByConditionFields[i]);
1741
1742 if ((i + 1) < orderByConditionFields.length) {
1743 if (orderByComparator.isAscending() ^ previous) {
1744 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1745 }
1746 else {
1747 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1748 }
1749 }
1750 else {
1751 if (orderByComparator.isAscending() ^ previous) {
1752 query.append(WHERE_GREATER_THAN);
1753 }
1754 else {
1755 query.append(WHERE_LESSER_THAN);
1756 }
1757 }
1758 }
1759
1760 query.append(ORDER_BY_CLAUSE);
1761
1762 String[] orderByFields = orderByComparator.getOrderByFields();
1763
1764 for (int i = 0; i < orderByFields.length; i++) {
1765 query.append(_ORDER_BY_ENTITY_ALIAS);
1766 query.append(orderByFields[i]);
1767
1768 if ((i + 1) < orderByFields.length) {
1769 if (orderByComparator.isAscending() ^ previous) {
1770 query.append(ORDER_BY_ASC_HAS_NEXT);
1771 }
1772 else {
1773 query.append(ORDER_BY_DESC_HAS_NEXT);
1774 }
1775 }
1776 else {
1777 if (orderByComparator.isAscending() ^ previous) {
1778 query.append(ORDER_BY_ASC);
1779 }
1780 else {
1781 query.append(ORDER_BY_DESC);
1782 }
1783 }
1784 }
1785 }
1786 else {
1787 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1788 }
1789
1790 String sql = query.toString();
1791
1792 Query q = session.createQuery(sql);
1793
1794 q.setFirstResult(0);
1795 q.setMaxResults(2);
1796
1797 QueryPos qPos = QueryPos.getInstance(q);
1798
1799 qPos.add(groupId);
1800
1801 if (orderByComparator != null) {
1802 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1803
1804 for (Object value : values) {
1805 qPos.add(value);
1806 }
1807 }
1808
1809 List<MBMessage> list = q.list();
1810
1811 if (list.size() == 2) {
1812 return list.get(1);
1813 }
1814 else {
1815 return null;
1816 }
1817 }
1818
1819
1826 public List<MBMessage> filterFindByGroupId(long groupId)
1827 throws SystemException {
1828 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1829 QueryUtil.ALL_POS, null);
1830 }
1831
1832
1845 public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1846 throws SystemException {
1847 return filterFindByGroupId(groupId, start, end, null);
1848 }
1849
1850
1864 public List<MBMessage> filterFindByGroupId(long groupId, int start,
1865 int end, OrderByComparator orderByComparator) throws SystemException {
1866 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1867 return findByGroupId(groupId, start, end, orderByComparator);
1868 }
1869
1870 StringBundler query = null;
1871
1872 if (orderByComparator != null) {
1873 query = new StringBundler(3 +
1874 (orderByComparator.getOrderByFields().length * 3));
1875 }
1876 else {
1877 query = new StringBundler(3);
1878 }
1879
1880 if (getDB().isSupportsInlineDistinct()) {
1881 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1882 }
1883 else {
1884 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1885 }
1886
1887 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1888
1889 if (!getDB().isSupportsInlineDistinct()) {
1890 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1891 }
1892
1893 if (orderByComparator != null) {
1894 if (getDB().isSupportsInlineDistinct()) {
1895 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1896 orderByComparator);
1897 }
1898 else {
1899 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1900 orderByComparator);
1901 }
1902 }
1903 else {
1904 if (getDB().isSupportsInlineDistinct()) {
1905 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1906 }
1907 else {
1908 query.append(MBMessageModelImpl.ORDER_BY_SQL);
1909 }
1910 }
1911
1912 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1913 MBMessage.class.getName(),
1914 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1915
1916 Session session = null;
1917
1918 try {
1919 session = openSession();
1920
1921 SQLQuery q = session.createSQLQuery(sql);
1922
1923 if (getDB().isSupportsInlineDistinct()) {
1924 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1925 }
1926 else {
1927 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1928 }
1929
1930 QueryPos qPos = QueryPos.getInstance(q);
1931
1932 qPos.add(groupId);
1933
1934 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1935 }
1936 catch (Exception e) {
1937 throw processException(e);
1938 }
1939 finally {
1940 closeSession(session);
1941 }
1942 }
1943
1944
1954 public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
1955 long groupId, OrderByComparator orderByComparator)
1956 throws NoSuchMessageException, SystemException {
1957 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1958 return findByGroupId_PrevAndNext(messageId, groupId,
1959 orderByComparator);
1960 }
1961
1962 MBMessage mbMessage = findByPrimaryKey(messageId);
1963
1964 Session session = null;
1965
1966 try {
1967 session = openSession();
1968
1969 MBMessage[] array = new MBMessageImpl[3];
1970
1971 array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1972 groupId, orderByComparator, true);
1973
1974 array[1] = mbMessage;
1975
1976 array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1977 groupId, orderByComparator, false);
1978
1979 return array;
1980 }
1981 catch (Exception e) {
1982 throw processException(e);
1983 }
1984 finally {
1985 closeSession(session);
1986 }
1987 }
1988
1989 protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
1990 MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1991 boolean previous) {
1992 StringBundler query = null;
1993
1994 if (orderByComparator != null) {
1995 query = new StringBundler(6 +
1996 (orderByComparator.getOrderByFields().length * 6));
1997 }
1998 else {
1999 query = new StringBundler(3);
2000 }
2001
2002 if (getDB().isSupportsInlineDistinct()) {
2003 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2004 }
2005 else {
2006 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2007 }
2008
2009 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2010
2011 if (!getDB().isSupportsInlineDistinct()) {
2012 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2013 }
2014
2015 if (orderByComparator != null) {
2016 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2017
2018 if (orderByConditionFields.length > 0) {
2019 query.append(WHERE_AND);
2020 }
2021
2022 for (int i = 0; i < orderByConditionFields.length; i++) {
2023 if (getDB().isSupportsInlineDistinct()) {
2024 query.append(_ORDER_BY_ENTITY_ALIAS);
2025 }
2026 else {
2027 query.append(_ORDER_BY_ENTITY_TABLE);
2028 }
2029
2030 query.append(orderByConditionFields[i]);
2031
2032 if ((i + 1) < orderByConditionFields.length) {
2033 if (orderByComparator.isAscending() ^ previous) {
2034 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2035 }
2036 else {
2037 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2038 }
2039 }
2040 else {
2041 if (orderByComparator.isAscending() ^ previous) {
2042 query.append(WHERE_GREATER_THAN);
2043 }
2044 else {
2045 query.append(WHERE_LESSER_THAN);
2046 }
2047 }
2048 }
2049
2050 query.append(ORDER_BY_CLAUSE);
2051
2052 String[] orderByFields = orderByComparator.getOrderByFields();
2053
2054 for (int i = 0; i < orderByFields.length; i++) {
2055 if (getDB().isSupportsInlineDistinct()) {
2056 query.append(_ORDER_BY_ENTITY_ALIAS);
2057 }
2058 else {
2059 query.append(_ORDER_BY_ENTITY_TABLE);
2060 }
2061
2062 query.append(orderByFields[i]);
2063
2064 if ((i + 1) < orderByFields.length) {
2065 if (orderByComparator.isAscending() ^ previous) {
2066 query.append(ORDER_BY_ASC_HAS_NEXT);
2067 }
2068 else {
2069 query.append(ORDER_BY_DESC_HAS_NEXT);
2070 }
2071 }
2072 else {
2073 if (orderByComparator.isAscending() ^ previous) {
2074 query.append(ORDER_BY_ASC);
2075 }
2076 else {
2077 query.append(ORDER_BY_DESC);
2078 }
2079 }
2080 }
2081 }
2082 else {
2083 if (getDB().isSupportsInlineDistinct()) {
2084 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2085 }
2086 else {
2087 query.append(MBMessageModelImpl.ORDER_BY_SQL);
2088 }
2089 }
2090
2091 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2092 MBMessage.class.getName(),
2093 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2094
2095 SQLQuery q = session.createSQLQuery(sql);
2096
2097 q.setFirstResult(0);
2098 q.setMaxResults(2);
2099
2100 if (getDB().isSupportsInlineDistinct()) {
2101 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2102 }
2103 else {
2104 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2105 }
2106
2107 QueryPos qPos = QueryPos.getInstance(q);
2108
2109 qPos.add(groupId);
2110
2111 if (orderByComparator != null) {
2112 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2113
2114 for (Object value : values) {
2115 qPos.add(value);
2116 }
2117 }
2118
2119 List<MBMessage> list = q.list();
2120
2121 if (list.size() == 2) {
2122 return list.get(1);
2123 }
2124 else {
2125 return null;
2126 }
2127 }
2128
2129
2135 public void removeByGroupId(long groupId) throws SystemException {
2136 for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2137 QueryUtil.ALL_POS, null)) {
2138 remove(mbMessage);
2139 }
2140 }
2141
2142
2149 public int countByGroupId(long groupId) throws SystemException {
2150 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2151
2152 Object[] finderArgs = new Object[] { groupId };
2153
2154 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2155 this);
2156
2157 if (count == null) {
2158 StringBundler query = new StringBundler(2);
2159
2160 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2161
2162 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2163
2164 String sql = query.toString();
2165
2166 Session session = null;
2167
2168 try {
2169 session = openSession();
2170
2171 Query q = session.createQuery(sql);
2172
2173 QueryPos qPos = QueryPos.getInstance(q);
2174
2175 qPos.add(groupId);
2176
2177 count = (Long)q.uniqueResult();
2178
2179 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2180 }
2181 catch (Exception e) {
2182 FinderCacheUtil.removeResult(finderPath, finderArgs);
2183
2184 throw processException(e);
2185 }
2186 finally {
2187 closeSession(session);
2188 }
2189 }
2190
2191 return count.intValue();
2192 }
2193
2194
2201 public int filterCountByGroupId(long groupId) throws SystemException {
2202 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2203 return countByGroupId(groupId);
2204 }
2205
2206 StringBundler query = new StringBundler(2);
2207
2208 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2209
2210 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2211
2212 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2213 MBMessage.class.getName(),
2214 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2215
2216 Session session = null;
2217
2218 try {
2219 session = openSession();
2220
2221 SQLQuery q = session.createSQLQuery(sql);
2222
2223 q.addScalar(COUNT_COLUMN_NAME,
2224 com.liferay.portal.kernel.dao.orm.Type.LONG);
2225
2226 QueryPos qPos = QueryPos.getInstance(q);
2227
2228 qPos.add(groupId);
2229
2230 Long count = (Long)q.uniqueResult();
2231
2232 return count.intValue();
2233 }
2234 catch (Exception e) {
2235 throw processException(e);
2236 }
2237 finally {
2238 closeSession(session);
2239 }
2240 }
2241
2242 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2243 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2244 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2245 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2246 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2247 new String[] {
2248 Long.class.getName(),
2249
2250 Integer.class.getName(), Integer.class.getName(),
2251 OrderByComparator.class.getName()
2252 });
2253 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2254 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2255 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2256 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2257 new String[] { Long.class.getName() },
2258 MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2259 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2260 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2261 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2262 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2263 new String[] { Long.class.getName() });
2264
2265
2272 public List<MBMessage> findByCompanyId(long companyId)
2273 throws SystemException {
2274 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2275 null);
2276 }
2277
2278
2291 public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2292 throws SystemException {
2293 return findByCompanyId(companyId, start, end, null);
2294 }
2295
2296
2310 public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2311 OrderByComparator orderByComparator) throws SystemException {
2312 boolean pagination = true;
2313 FinderPath finderPath = null;
2314 Object[] finderArgs = null;
2315
2316 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2317 (orderByComparator == null)) {
2318 pagination = false;
2319 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2320 finderArgs = new Object[] { companyId };
2321 }
2322 else {
2323 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2324 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2325 }
2326
2327 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2328 finderArgs, this);
2329
2330 if ((list != null) && !list.isEmpty()) {
2331 for (MBMessage mbMessage : list) {
2332 if ((companyId != mbMessage.getCompanyId())) {
2333 list = null;
2334
2335 break;
2336 }
2337 }
2338 }
2339
2340 if (list == null) {
2341 StringBundler query = null;
2342
2343 if (orderByComparator != null) {
2344 query = new StringBundler(3 +
2345 (orderByComparator.getOrderByFields().length * 3));
2346 }
2347 else {
2348 query = new StringBundler(3);
2349 }
2350
2351 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2352
2353 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2354
2355 if (orderByComparator != null) {
2356 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2357 orderByComparator);
2358 }
2359 else
2360 if (pagination) {
2361 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2362 }
2363
2364 String sql = query.toString();
2365
2366 Session session = null;
2367
2368 try {
2369 session = openSession();
2370
2371 Query q = session.createQuery(sql);
2372
2373 QueryPos qPos = QueryPos.getInstance(q);
2374
2375 qPos.add(companyId);
2376
2377 if (!pagination) {
2378 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2379 start, end, false);
2380
2381 Collections.sort(list);
2382
2383 list = new UnmodifiableList<MBMessage>(list);
2384 }
2385 else {
2386 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2387 start, end);
2388 }
2389
2390 cacheResult(list);
2391
2392 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2393 }
2394 catch (Exception e) {
2395 FinderCacheUtil.removeResult(finderPath, finderArgs);
2396
2397 throw processException(e);
2398 }
2399 finally {
2400 closeSession(session);
2401 }
2402 }
2403
2404 return list;
2405 }
2406
2407
2416 public MBMessage findByCompanyId_First(long companyId,
2417 OrderByComparator orderByComparator)
2418 throws NoSuchMessageException, SystemException {
2419 MBMessage mbMessage = fetchByCompanyId_First(companyId,
2420 orderByComparator);
2421
2422 if (mbMessage != null) {
2423 return mbMessage;
2424 }
2425
2426 StringBundler msg = new StringBundler(4);
2427
2428 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2429
2430 msg.append("companyId=");
2431 msg.append(companyId);
2432
2433 msg.append(StringPool.CLOSE_CURLY_BRACE);
2434
2435 throw new NoSuchMessageException(msg.toString());
2436 }
2437
2438
2446 public MBMessage fetchByCompanyId_First(long companyId,
2447 OrderByComparator orderByComparator) throws SystemException {
2448 List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2449 orderByComparator);
2450
2451 if (!list.isEmpty()) {
2452 return list.get(0);
2453 }
2454
2455 return null;
2456 }
2457
2458
2467 public MBMessage findByCompanyId_Last(long companyId,
2468 OrderByComparator orderByComparator)
2469 throws NoSuchMessageException, SystemException {
2470 MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2471
2472 if (mbMessage != null) {
2473 return mbMessage;
2474 }
2475
2476 StringBundler msg = new StringBundler(4);
2477
2478 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2479
2480 msg.append("companyId=");
2481 msg.append(companyId);
2482
2483 msg.append(StringPool.CLOSE_CURLY_BRACE);
2484
2485 throw new NoSuchMessageException(msg.toString());
2486 }
2487
2488
2496 public MBMessage fetchByCompanyId_Last(long companyId,
2497 OrderByComparator orderByComparator) throws SystemException {
2498 int count = countByCompanyId(companyId);
2499
2500 List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2501 orderByComparator);
2502
2503 if (!list.isEmpty()) {
2504 return list.get(0);
2505 }
2506
2507 return null;
2508 }
2509
2510
2520 public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2521 long companyId, OrderByComparator orderByComparator)
2522 throws NoSuchMessageException, SystemException {
2523 MBMessage mbMessage = findByPrimaryKey(messageId);
2524
2525 Session session = null;
2526
2527 try {
2528 session = openSession();
2529
2530 MBMessage[] array = new MBMessageImpl[3];
2531
2532 array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2533 companyId, orderByComparator, true);
2534
2535 array[1] = mbMessage;
2536
2537 array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2538 companyId, orderByComparator, false);
2539
2540 return array;
2541 }
2542 catch (Exception e) {
2543 throw processException(e);
2544 }
2545 finally {
2546 closeSession(session);
2547 }
2548 }
2549
2550 protected MBMessage getByCompanyId_PrevAndNext(Session session,
2551 MBMessage mbMessage, long companyId,
2552 OrderByComparator orderByComparator, boolean previous) {
2553 StringBundler query = null;
2554
2555 if (orderByComparator != null) {
2556 query = new StringBundler(6 +
2557 (orderByComparator.getOrderByFields().length * 6));
2558 }
2559 else {
2560 query = new StringBundler(3);
2561 }
2562
2563 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2564
2565 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2566
2567 if (orderByComparator != null) {
2568 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2569
2570 if (orderByConditionFields.length > 0) {
2571 query.append(WHERE_AND);
2572 }
2573
2574 for (int i = 0; i < orderByConditionFields.length; i++) {
2575 query.append(_ORDER_BY_ENTITY_ALIAS);
2576 query.append(orderByConditionFields[i]);
2577
2578 if ((i + 1) < orderByConditionFields.length) {
2579 if (orderByComparator.isAscending() ^ previous) {
2580 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2581 }
2582 else {
2583 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2584 }
2585 }
2586 else {
2587 if (orderByComparator.isAscending() ^ previous) {
2588 query.append(WHERE_GREATER_THAN);
2589 }
2590 else {
2591 query.append(WHERE_LESSER_THAN);
2592 }
2593 }
2594 }
2595
2596 query.append(ORDER_BY_CLAUSE);
2597
2598 String[] orderByFields = orderByComparator.getOrderByFields();
2599
2600 for (int i = 0; i < orderByFields.length; i++) {
2601 query.append(_ORDER_BY_ENTITY_ALIAS);
2602 query.append(orderByFields[i]);
2603
2604 if ((i + 1) < orderByFields.length) {
2605 if (orderByComparator.isAscending() ^ previous) {
2606 query.append(ORDER_BY_ASC_HAS_NEXT);
2607 }
2608 else {
2609 query.append(ORDER_BY_DESC_HAS_NEXT);
2610 }
2611 }
2612 else {
2613 if (orderByComparator.isAscending() ^ previous) {
2614 query.append(ORDER_BY_ASC);
2615 }
2616 else {
2617 query.append(ORDER_BY_DESC);
2618 }
2619 }
2620 }
2621 }
2622 else {
2623 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2624 }
2625
2626 String sql = query.toString();
2627
2628 Query q = session.createQuery(sql);
2629
2630 q.setFirstResult(0);
2631 q.setMaxResults(2);
2632
2633 QueryPos qPos = QueryPos.getInstance(q);
2634
2635 qPos.add(companyId);
2636
2637 if (orderByComparator != null) {
2638 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2639
2640 for (Object value : values) {
2641 qPos.add(value);
2642 }
2643 }
2644
2645 List<MBMessage> list = q.list();
2646
2647 if (list.size() == 2) {
2648 return list.get(1);
2649 }
2650 else {
2651 return null;
2652 }
2653 }
2654
2655
2661 public void removeByCompanyId(long companyId) throws SystemException {
2662 for (MBMessage mbMessage : findByCompanyId(companyId,
2663 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2664 remove(mbMessage);
2665 }
2666 }
2667
2668
2675 public int countByCompanyId(long companyId) throws SystemException {
2676 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2677
2678 Object[] finderArgs = new Object[] { companyId };
2679
2680 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2681 this);
2682
2683 if (count == null) {
2684 StringBundler query = new StringBundler(2);
2685
2686 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2687
2688 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2689
2690 String sql = query.toString();
2691
2692 Session session = null;
2693
2694 try {
2695 session = openSession();
2696
2697 Query q = session.createQuery(sql);
2698
2699 QueryPos qPos = QueryPos.getInstance(q);
2700
2701 qPos.add(companyId);
2702
2703 count = (Long)q.uniqueResult();
2704
2705 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2706 }
2707 catch (Exception e) {
2708 FinderCacheUtil.removeResult(finderPath, finderArgs);
2709
2710 throw processException(e);
2711 }
2712 finally {
2713 closeSession(session);
2714 }
2715 }
2716
2717 return count.intValue();
2718 }
2719
2720 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2721 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2722 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2723 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
2724 new String[] {
2725 Long.class.getName(),
2726
2727 Integer.class.getName(), Integer.class.getName(),
2728 OrderByComparator.class.getName()
2729 });
2730 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
2731 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2732 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2733 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
2734 new String[] { Long.class.getName() },
2735 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
2736 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2737 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2738 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2739 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
2740 new String[] { Long.class.getName() });
2741
2742
2749 public List<MBMessage> findByThreadId(long threadId)
2750 throws SystemException {
2751 return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2752 null);
2753 }
2754
2755
2768 public List<MBMessage> findByThreadId(long threadId, int start, int end)
2769 throws SystemException {
2770 return findByThreadId(threadId, start, end, null);
2771 }
2772
2773
2787 public List<MBMessage> findByThreadId(long threadId, int start, int end,
2788 OrderByComparator orderByComparator) throws SystemException {
2789 boolean pagination = true;
2790 FinderPath finderPath = null;
2791 Object[] finderArgs = null;
2792
2793 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2794 (orderByComparator == null)) {
2795 pagination = false;
2796 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
2797 finderArgs = new Object[] { threadId };
2798 }
2799 else {
2800 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
2801 finderArgs = new Object[] { threadId, start, end, orderByComparator };
2802 }
2803
2804 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2805 finderArgs, this);
2806
2807 if ((list != null) && !list.isEmpty()) {
2808 for (MBMessage mbMessage : list) {
2809 if ((threadId != mbMessage.getThreadId())) {
2810 list = null;
2811
2812 break;
2813 }
2814 }
2815 }
2816
2817 if (list == null) {
2818 StringBundler query = null;
2819
2820 if (orderByComparator != null) {
2821 query = new StringBundler(3 +
2822 (orderByComparator.getOrderByFields().length * 3));
2823 }
2824 else {
2825 query = new StringBundler(3);
2826 }
2827
2828 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2829
2830 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2831
2832 if (orderByComparator != null) {
2833 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2834 orderByComparator);
2835 }
2836 else
2837 if (pagination) {
2838 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2839 }
2840
2841 String sql = query.toString();
2842
2843 Session session = null;
2844
2845 try {
2846 session = openSession();
2847
2848 Query q = session.createQuery(sql);
2849
2850 QueryPos qPos = QueryPos.getInstance(q);
2851
2852 qPos.add(threadId);
2853
2854 if (!pagination) {
2855 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2856 start, end, false);
2857
2858 Collections.sort(list);
2859
2860 list = new UnmodifiableList<MBMessage>(list);
2861 }
2862 else {
2863 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2864 start, end);
2865 }
2866
2867 cacheResult(list);
2868
2869 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2870 }
2871 catch (Exception e) {
2872 FinderCacheUtil.removeResult(finderPath, finderArgs);
2873
2874 throw processException(e);
2875 }
2876 finally {
2877 closeSession(session);
2878 }
2879 }
2880
2881 return list;
2882 }
2883
2884
2893 public MBMessage findByThreadId_First(long threadId,
2894 OrderByComparator orderByComparator)
2895 throws NoSuchMessageException, SystemException {
2896 MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
2897
2898 if (mbMessage != null) {
2899 return mbMessage;
2900 }
2901
2902 StringBundler msg = new StringBundler(4);
2903
2904 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2905
2906 msg.append("threadId=");
2907 msg.append(threadId);
2908
2909 msg.append(StringPool.CLOSE_CURLY_BRACE);
2910
2911 throw new NoSuchMessageException(msg.toString());
2912 }
2913
2914
2922 public MBMessage fetchByThreadId_First(long threadId,
2923 OrderByComparator orderByComparator) throws SystemException {
2924 List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
2925
2926 if (!list.isEmpty()) {
2927 return list.get(0);
2928 }
2929
2930 return null;
2931 }
2932
2933
2942 public MBMessage findByThreadId_Last(long threadId,
2943 OrderByComparator orderByComparator)
2944 throws NoSuchMessageException, SystemException {
2945 MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
2946
2947 if (mbMessage != null) {
2948 return mbMessage;
2949 }
2950
2951 StringBundler msg = new StringBundler(4);
2952
2953 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2954
2955 msg.append("threadId=");
2956 msg.append(threadId);
2957
2958 msg.append(StringPool.CLOSE_CURLY_BRACE);
2959
2960 throw new NoSuchMessageException(msg.toString());
2961 }
2962
2963
2971 public MBMessage fetchByThreadId_Last(long threadId,
2972 OrderByComparator orderByComparator) throws SystemException {
2973 int count = countByThreadId(threadId);
2974
2975 List<MBMessage> list = findByThreadId(threadId, count - 1, count,
2976 orderByComparator);
2977
2978 if (!list.isEmpty()) {
2979 return list.get(0);
2980 }
2981
2982 return null;
2983 }
2984
2985
2995 public MBMessage[] findByThreadId_PrevAndNext(long messageId,
2996 long threadId, OrderByComparator orderByComparator)
2997 throws NoSuchMessageException, SystemException {
2998 MBMessage mbMessage = findByPrimaryKey(messageId);
2999
3000 Session session = null;
3001
3002 try {
3003 session = openSession();
3004
3005 MBMessage[] array = new MBMessageImpl[3];
3006
3007 array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3008 orderByComparator, true);
3009
3010 array[1] = mbMessage;
3011
3012 array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3013 orderByComparator, false);
3014
3015 return array;
3016 }
3017 catch (Exception e) {
3018 throw processException(e);
3019 }
3020 finally {
3021 closeSession(session);
3022 }
3023 }
3024
3025 protected MBMessage getByThreadId_PrevAndNext(Session session,
3026 MBMessage mbMessage, long threadId,
3027 OrderByComparator orderByComparator, boolean previous) {
3028 StringBundler query = null;
3029
3030 if (orderByComparator != null) {
3031 query = new StringBundler(6 +
3032 (orderByComparator.getOrderByFields().length * 6));
3033 }
3034 else {
3035 query = new StringBundler(3);
3036 }
3037
3038 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3039
3040 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3041
3042 if (orderByComparator != null) {
3043 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3044
3045 if (orderByConditionFields.length > 0) {
3046 query.append(WHERE_AND);
3047 }
3048
3049 for (int i = 0; i < orderByConditionFields.length; i++) {
3050 query.append(_ORDER_BY_ENTITY_ALIAS);
3051 query.append(orderByConditionFields[i]);
3052
3053 if ((i + 1) < orderByConditionFields.length) {
3054 if (orderByComparator.isAscending() ^ previous) {
3055 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3056 }
3057 else {
3058 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3059 }
3060 }
3061 else {
3062 if (orderByComparator.isAscending() ^ previous) {
3063 query.append(WHERE_GREATER_THAN);
3064 }
3065 else {
3066 query.append(WHERE_LESSER_THAN);
3067 }
3068 }
3069 }
3070
3071 query.append(ORDER_BY_CLAUSE);
3072
3073 String[] orderByFields = orderByComparator.getOrderByFields();
3074
3075 for (int i = 0; i < orderByFields.length; i++) {
3076 query.append(_ORDER_BY_ENTITY_ALIAS);
3077 query.append(orderByFields[i]);
3078
3079 if ((i + 1) < orderByFields.length) {
3080 if (orderByComparator.isAscending() ^ previous) {
3081 query.append(ORDER_BY_ASC_HAS_NEXT);
3082 }
3083 else {
3084 query.append(ORDER_BY_DESC_HAS_NEXT);
3085 }
3086 }
3087 else {
3088 if (orderByComparator.isAscending() ^ previous) {
3089 query.append(ORDER_BY_ASC);
3090 }
3091 else {
3092 query.append(ORDER_BY_DESC);
3093 }
3094 }
3095 }
3096 }
3097 else {
3098 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3099 }
3100
3101 String sql = query.toString();
3102
3103 Query q = session.createQuery(sql);
3104
3105 q.setFirstResult(0);
3106 q.setMaxResults(2);
3107
3108 QueryPos qPos = QueryPos.getInstance(q);
3109
3110 qPos.add(threadId);
3111
3112 if (orderByComparator != null) {
3113 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3114
3115 for (Object value : values) {
3116 qPos.add(value);
3117 }
3118 }
3119
3120 List<MBMessage> list = q.list();
3121
3122 if (list.size() == 2) {
3123 return list.get(1);
3124 }
3125 else {
3126 return null;
3127 }
3128 }
3129
3130
3136 public void removeByThreadId(long threadId) throws SystemException {
3137 for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3138 QueryUtil.ALL_POS, null)) {
3139 remove(mbMessage);
3140 }
3141 }
3142
3143
3150 public int countByThreadId(long threadId) throws SystemException {
3151 FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3152
3153 Object[] finderArgs = new Object[] { threadId };
3154
3155 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3156 this);
3157
3158 if (count == null) {
3159 StringBundler query = new StringBundler(2);
3160
3161 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3162
3163 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3164
3165 String sql = query.toString();
3166
3167 Session session = null;
3168
3169 try {
3170 session = openSession();
3171
3172 Query q = session.createQuery(sql);
3173
3174 QueryPos qPos = QueryPos.getInstance(q);
3175
3176 qPos.add(threadId);
3177
3178 count = (Long)q.uniqueResult();
3179
3180 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3181 }
3182 catch (Exception e) {
3183 FinderCacheUtil.removeResult(finderPath, finderArgs);
3184
3185 throw processException(e);
3186 }
3187 finally {
3188 closeSession(session);
3189 }
3190 }
3191
3192 return count.intValue();
3193 }
3194
3195 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3196 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3197 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3198 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3199 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3200 new String[] {
3201 Long.class.getName(),
3202
3203 Integer.class.getName(), Integer.class.getName(),
3204 OrderByComparator.class.getName()
3205 });
3206 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3207 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3208 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3209 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3210 new String[] { Long.class.getName() },
3211 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3212 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3213 public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3214 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3215 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3216 new String[] { Long.class.getName() });
3217
3218
3225 public List<MBMessage> findByThreadReplies(long threadId)
3226 throws SystemException {
3227 return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3228 QueryUtil.ALL_POS, null);
3229 }
3230
3231
3244 public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3245 throws SystemException {
3246 return findByThreadReplies(threadId, start, end, null);
3247 }
3248
3249
3263 public List<MBMessage> findByThreadReplies(long threadId, int start,
3264 int end, OrderByComparator orderByComparator) throws SystemException {
3265 boolean pagination = true;
3266 FinderPath finderPath = null;
3267 Object[] finderArgs = null;
3268
3269 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3270 (orderByComparator == null)) {
3271 pagination = false;
3272 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3273 finderArgs = new Object[] { threadId };
3274 }
3275 else {
3276 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3277 finderArgs = new Object[] { threadId, start, end, orderByComparator };
3278 }
3279
3280 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3281 finderArgs, this);
3282
3283 if ((list != null) && !list.isEmpty()) {
3284 for (MBMessage mbMessage : list) {
3285 if ((threadId != mbMessage.getThreadId())) {
3286 list = null;
3287
3288 break;
3289 }
3290 }
3291 }
3292
3293 if (list == null) {
3294 StringBundler query = null;
3295
3296 if (orderByComparator != null) {
3297 query = new StringBundler(3 +
3298 (orderByComparator.getOrderByFields().length * 3));
3299 }
3300 else {
3301 query = new StringBundler(3);
3302 }
3303
3304 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3305
3306 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3307
3308 if (orderByComparator != null) {
3309 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3310 orderByComparator);
3311 }
3312 else
3313 if (pagination) {
3314 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3315 }
3316
3317 String sql = query.toString();
3318
3319 Session session = null;
3320
3321 try {
3322 session = openSession();
3323
3324 Query q = session.createQuery(sql);
3325
3326 QueryPos qPos = QueryPos.getInstance(q);
3327
3328 qPos.add(threadId);
3329
3330 if (!pagination) {
3331 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3332 start, end, false);
3333
3334 Collections.sort(list);
3335
3336 list = new UnmodifiableList<MBMessage>(list);
3337 }
3338 else {
3339 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3340 start, end);
3341 }
3342
3343 cacheResult(list);
3344
3345 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3346 }
3347 catch (Exception e) {
3348 FinderCacheUtil.removeResult(finderPath, finderArgs);
3349
3350 throw processException(e);
3351 }
3352 finally {
3353 closeSession(session);
3354 }
3355 }
3356
3357 return list;
3358 }
3359
3360
3369 public MBMessage findByThreadReplies_First(long threadId,
3370 OrderByComparator orderByComparator)
3371 throws NoSuchMessageException, SystemException {
3372 MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3373 orderByComparator);
3374
3375 if (mbMessage != null) {
3376 return mbMessage;
3377 }
3378
3379 StringBundler msg = new StringBundler(4);
3380
3381 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3382
3383 msg.append("threadId=");
3384 msg.append(threadId);
3385
3386 msg.append(StringPool.CLOSE_CURLY_BRACE);
3387
3388 throw new NoSuchMessageException(msg.toString());
3389 }
3390
3391
3399 public MBMessage fetchByThreadReplies_First(long threadId,
3400 OrderByComparator orderByComparator) throws SystemException {
3401 List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3402 orderByComparator);
3403
3404 if (!list.isEmpty()) {
3405 return list.get(0);
3406 }
3407
3408 return null;
3409 }
3410
3411
3420 public MBMessage findByThreadReplies_Last(long threadId,
3421 OrderByComparator orderByComparator)
3422 throws NoSuchMessageException, SystemException {
3423 MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3424 orderByComparator);
3425
3426 if (mbMessage != null) {
3427 return mbMessage;
3428 }
3429
3430 StringBundler msg = new StringBundler(4);
3431
3432 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3433
3434 msg.append("threadId=");
3435 msg.append(threadId);
3436
3437 msg.append(StringPool.CLOSE_CURLY_BRACE);
3438
3439 throw new NoSuchMessageException(msg.toString());
3440 }
3441
3442
3450 public MBMessage fetchByThreadReplies_Last(long threadId,
3451 OrderByComparator orderByComparator) throws SystemException {
3452 int count = countByThreadReplies(threadId);
3453
3454 List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3455 orderByComparator);
3456
3457 if (!list.isEmpty()) {
3458 return list.get(0);
3459 }
3460
3461 return null;
3462 }
3463
3464
3474 public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3475 long threadId, OrderByComparator orderByComparator)
3476 throws NoSuchMessageException, SystemException {
3477 MBMessage mbMessage = findByPrimaryKey(messageId);
3478
3479 Session session = null;
3480
3481 try {
3482 session = openSession();
3483
3484 MBMessage[] array = new MBMessageImpl[3];
3485
3486 array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3487 threadId, orderByComparator, true);
3488
3489 array[1] = mbMessage;
3490
3491 array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3492 threadId, orderByComparator, false);
3493
3494 return array;
3495 }
3496 catch (Exception e) {
3497 throw processException(e);
3498 }
3499 finally {
3500 closeSession(session);
3501 }
3502 }
3503
3504 protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3505 MBMessage mbMessage, long threadId,
3506 OrderByComparator orderByComparator, boolean previous) {
3507 StringBundler query = null;
3508
3509 if (orderByComparator != null) {
3510 query = new StringBundler(6 +
3511 (orderByComparator.getOrderByFields().length * 6));
3512 }
3513 else {
3514 query = new StringBundler(3);
3515 }
3516
3517 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3518
3519 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3520
3521 if (orderByComparator != null) {
3522 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3523
3524 if (orderByConditionFields.length > 0) {
3525 query.append(WHERE_AND);
3526 }
3527
3528 for (int i = 0; i < orderByConditionFields.length; i++) {
3529 query.append(_ORDER_BY_ENTITY_ALIAS);
3530 query.append(orderByConditionFields[i]);
3531
3532 if ((i + 1) < orderByConditionFields.length) {
3533 if (orderByComparator.isAscending() ^ previous) {
3534 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3535 }
3536 else {
3537 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3538 }
3539 }
3540 else {
3541 if (orderByComparator.isAscending() ^ previous) {
3542 query.append(WHERE_GREATER_THAN);
3543 }
3544 else {
3545 query.append(WHERE_LESSER_THAN);
3546 }
3547 }
3548 }
3549
3550 query.append(ORDER_BY_CLAUSE);
3551
3552 String[] orderByFields = orderByComparator.getOrderByFields();
3553
3554 for (int i = 0; i < orderByFields.length; i++) {
3555 query.append(_ORDER_BY_ENTITY_ALIAS);
3556 query.append(orderByFields[i]);
3557
3558 if ((i + 1) < orderByFields.length) {
3559 if (orderByComparator.isAscending() ^ previous) {
3560 query.append(ORDER_BY_ASC_HAS_NEXT);
3561 }
3562 else {
3563 query.append(ORDER_BY_DESC_HAS_NEXT);
3564 }
3565 }
3566 else {
3567 if (orderByComparator.isAscending() ^ previous) {
3568 query.append(ORDER_BY_ASC);
3569 }
3570 else {
3571 query.append(ORDER_BY_DESC);
3572 }
3573 }
3574 }
3575 }
3576 else {
3577 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3578 }
3579
3580 String sql = query.toString();
3581
3582 Query q = session.createQuery(sql);
3583
3584 q.setFirstResult(0);
3585 q.setMaxResults(2);
3586
3587 QueryPos qPos = QueryPos.getInstance(q);
3588
3589 qPos.add(threadId);
3590
3591 if (orderByComparator != null) {
3592 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3593
3594 for (Object value : values) {
3595 qPos.add(value);
3596 }
3597 }
3598
3599 List<MBMessage> list = q.list();
3600
3601 if (list.size() == 2) {
3602 return list.get(1);
3603 }
3604 else {
3605 return null;
3606 }
3607 }
3608
3609
3615 public void removeByThreadReplies(long threadId) throws SystemException {
3616 for (MBMessage mbMessage : findByThreadReplies(threadId,
3617 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3618 remove(mbMessage);
3619 }
3620 }
3621
3622
3629 public int countByThreadReplies(long threadId) throws SystemException {
3630 FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
3631
3632 Object[] finderArgs = new Object[] { threadId };
3633
3634 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3635 this);
3636
3637 if (count == null) {
3638 StringBundler query = new StringBundler(2);
3639
3640 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3641
3642 query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3643
3644 String sql = query.toString();
3645
3646 Session session = null;
3647
3648 try {
3649 session = openSession();
3650
3651 Query q = session.createQuery(sql);
3652
3653 QueryPos qPos = QueryPos.getInstance(q);
3654
3655 qPos.add(threadId);
3656
3657 count = (Long)q.uniqueResult();
3658
3659 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3660 }
3661 catch (Exception e) {
3662 FinderCacheUtil.removeResult(finderPath, finderArgs);
3663
3664 throw processException(e);
3665 }
3666 finally {
3667 closeSession(session);
3668 }
3669 }
3670
3671 return count.intValue();
3672 }
3673
3674 private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
3675 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3676 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3677 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
3678 new String[] {
3679 Long.class.getName(),
3680
3681 Integer.class.getName(), Integer.class.getName(),
3682 OrderByComparator.class.getName()
3683 });
3684 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
3685 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3686 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3687 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
3688 new String[] { Long.class.getName() },
3689 MBMessageModelImpl.USERID_COLUMN_BITMASK |
3690 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3691 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3692 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3693 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
3694 new String[] { Long.class.getName() });
3695
3696
3703 public List<MBMessage> findByUserId(long userId) throws SystemException {
3704 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3705 }
3706
3707
3720 public List<MBMessage> findByUserId(long userId, int start, int end)
3721 throws SystemException {
3722 return findByUserId(userId, start, end, null);
3723 }
3724
3725
3739 public List<MBMessage> findByUserId(long userId, int start, int end,
3740 OrderByComparator orderByComparator) throws SystemException {
3741 boolean pagination = true;
3742 FinderPath finderPath = null;
3743 Object[] finderArgs = null;
3744
3745 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3746 (orderByComparator == null)) {
3747 pagination = false;
3748 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3749 finderArgs = new Object[] { userId };
3750 }
3751 else {
3752 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3753 finderArgs = new Object[] { userId, start, end, orderByComparator };
3754 }
3755
3756 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3757 finderArgs, this);
3758
3759 if ((list != null) && !list.isEmpty()) {
3760 for (MBMessage mbMessage : list) {
3761 if ((userId != mbMessage.getUserId())) {
3762 list = null;
3763
3764 break;
3765 }
3766 }
3767 }
3768
3769 if (list == null) {
3770 StringBundler query = null;
3771
3772 if (orderByComparator != null) {
3773 query = new StringBundler(3 +
3774 (orderByComparator.getOrderByFields().length * 3));
3775 }
3776 else {
3777 query = new StringBundler(3);
3778 }
3779
3780 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3781
3782 query.append(_FINDER_COLUMN_USERID_USERID_2);
3783
3784 if (orderByComparator != null) {
3785 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3786 orderByComparator);
3787 }
3788 else
3789 if (pagination) {
3790 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3791 }
3792
3793 String sql = query.toString();
3794
3795 Session session = null;
3796
3797 try {
3798 session = openSession();
3799
3800 Query q = session.createQuery(sql);
3801
3802 QueryPos qPos = QueryPos.getInstance(q);
3803
3804 qPos.add(userId);
3805
3806 if (!pagination) {
3807 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3808 start, end, false);
3809
3810 Collections.sort(list);
3811
3812 list = new UnmodifiableList<MBMessage>(list);
3813 }
3814 else {
3815 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3816 start, end);
3817 }
3818
3819 cacheResult(list);
3820
3821 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3822 }
3823 catch (Exception e) {
3824 FinderCacheUtil.removeResult(finderPath, finderArgs);
3825
3826 throw processException(e);
3827 }
3828 finally {
3829 closeSession(session);
3830 }
3831 }
3832
3833 return list;
3834 }
3835
3836
3845 public MBMessage findByUserId_First(long userId,
3846 OrderByComparator orderByComparator)
3847 throws NoSuchMessageException, SystemException {
3848 MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3849
3850 if (mbMessage != null) {
3851 return mbMessage;
3852 }
3853
3854 StringBundler msg = new StringBundler(4);
3855
3856 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3857
3858 msg.append("userId=");
3859 msg.append(userId);
3860
3861 msg.append(StringPool.CLOSE_CURLY_BRACE);
3862
3863 throw new NoSuchMessageException(msg.toString());
3864 }
3865
3866
3874 public MBMessage fetchByUserId_First(long userId,
3875 OrderByComparator orderByComparator) throws SystemException {
3876 List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3877
3878 if (!list.isEmpty()) {
3879 return list.get(0);
3880 }
3881
3882 return null;
3883 }
3884
3885
3894 public MBMessage findByUserId_Last(long userId,
3895 OrderByComparator orderByComparator)
3896 throws NoSuchMessageException, SystemException {
3897 MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3898
3899 if (mbMessage != null) {
3900 return mbMessage;
3901 }
3902
3903 StringBundler msg = new StringBundler(4);
3904
3905 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3906
3907 msg.append("userId=");
3908 msg.append(userId);
3909
3910 msg.append(StringPool.CLOSE_CURLY_BRACE);
3911
3912 throw new NoSuchMessageException(msg.toString());
3913 }
3914
3915
3923 public MBMessage fetchByUserId_Last(long userId,
3924 OrderByComparator orderByComparator) throws SystemException {
3925 int count = countByUserId(userId);
3926
3927 List<MBMessage> list = findByUserId(userId, count - 1, count,
3928 orderByComparator);
3929
3930 if (!list.isEmpty()) {
3931 return list.get(0);
3932 }
3933
3934 return null;
3935 }
3936
3937
3947 public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3948 OrderByComparator orderByComparator)
3949 throws NoSuchMessageException, SystemException {
3950 MBMessage mbMessage = findByPrimaryKey(messageId);
3951
3952 Session session = null;
3953
3954 try {
3955 session = openSession();
3956
3957 MBMessage[] array = new MBMessageImpl[3];
3958
3959 array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3960 orderByComparator, true);
3961
3962 array[1] = mbMessage;
3963
3964 array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3965 orderByComparator, false);
3966
3967 return array;
3968 }
3969 catch (Exception e) {
3970 throw processException(e);
3971 }
3972 finally {
3973 closeSession(session);
3974 }
3975 }
3976
3977 protected MBMessage getByUserId_PrevAndNext(Session session,
3978 MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
3979 boolean previous) {
3980 StringBundler query = null;
3981
3982 if (orderByComparator != null) {
3983 query = new StringBundler(6 +
3984 (orderByComparator.getOrderByFields().length * 6));
3985 }
3986 else {
3987 query = new StringBundler(3);
3988 }
3989
3990 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3991
3992 query.append(_FINDER_COLUMN_USERID_USERID_2);
3993
3994 if (orderByComparator != null) {
3995 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3996
3997 if (orderByConditionFields.length > 0) {
3998 query.append(WHERE_AND);
3999 }
4000
4001 for (int i = 0; i < orderByConditionFields.length; i++) {
4002 query.append(_ORDER_BY_ENTITY_ALIAS);
4003 query.append(orderByConditionFields[i]);
4004
4005 if ((i + 1) < orderByConditionFields.length) {
4006 if (orderByComparator.isAscending() ^ previous) {
4007 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4008 }
4009 else {
4010 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4011 }
4012 }
4013 else {
4014 if (orderByComparator.isAscending() ^ previous) {
4015 query.append(WHERE_GREATER_THAN);
4016 }
4017 else {
4018 query.append(WHERE_LESSER_THAN);
4019 }
4020 }
4021 }
4022
4023 query.append(ORDER_BY_CLAUSE);
4024
4025 String[] orderByFields = orderByComparator.getOrderByFields();
4026
4027 for (int i = 0; i < orderByFields.length; i++) {
4028 query.append(_ORDER_BY_ENTITY_ALIAS);
4029 query.append(orderByFields[i]);
4030
4031 if ((i + 1) < orderByFields.length) {
4032 if (orderByComparator.isAscending() ^ previous) {
4033 query.append(ORDER_BY_ASC_HAS_NEXT);
4034 }
4035 else {
4036 query.append(ORDER_BY_DESC_HAS_NEXT);
4037 }
4038 }
4039 else {
4040 if (orderByComparator.isAscending() ^ previous) {
4041 query.append(ORDER_BY_ASC);
4042 }
4043 else {
4044 query.append(ORDER_BY_DESC);
4045 }
4046 }
4047 }
4048 }
4049 else {
4050 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4051 }
4052
4053 String sql = query.toString();
4054
4055 Query q = session.createQuery(sql);
4056
4057 q.setFirstResult(0);
4058 q.setMaxResults(2);
4059
4060 QueryPos qPos = QueryPos.getInstance(q);
4061
4062 qPos.add(userId);
4063
4064 if (orderByComparator != null) {
4065 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4066
4067 for (Object value : values) {
4068 qPos.add(value);
4069 }
4070 }
4071
4072 List<MBMessage> list = q.list();
4073
4074 if (list.size() == 2) {
4075 return list.get(1);
4076 }
4077 else {
4078 return null;
4079 }
4080 }
4081
4082
4088 public void removeByUserId(long userId) throws SystemException {
4089 for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
4090 QueryUtil.ALL_POS, null)) {
4091 remove(mbMessage);
4092 }
4093 }
4094
4095
4102 public int countByUserId(long userId) throws SystemException {
4103 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
4104
4105 Object[] finderArgs = new Object[] { userId };
4106
4107 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4108 this);
4109
4110 if (count == null) {
4111 StringBundler query = new StringBundler(2);
4112
4113 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4114
4115 query.append(_FINDER_COLUMN_USERID_USERID_2);
4116
4117 String sql = query.toString();
4118
4119 Session session = null;
4120
4121 try {
4122 session = openSession();
4123
4124 Query q = session.createQuery(sql);
4125
4126 QueryPos qPos = QueryPos.getInstance(q);
4127
4128 qPos.add(userId);
4129
4130 count = (Long)q.uniqueResult();
4131
4132 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4133 }
4134 catch (Exception e) {
4135 FinderCacheUtil.removeResult(finderPath, finderArgs);
4136
4137 throw processException(e);
4138 }
4139 finally {
4140 closeSession(session);
4141 }
4142 }
4143
4144 return count.intValue();
4145 }
4146
4147 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
4148 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4149 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4150 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4151 new String[] {
4152 Long.class.getName(), Long.class.getName(),
4153
4154 Integer.class.getName(), Integer.class.getName(),
4155 OrderByComparator.class.getName()
4156 });
4157 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4158 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4159 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4160 new String[] { Long.class.getName(), Long.class.getName() },
4161 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4162 MBMessageModelImpl.USERID_COLUMN_BITMASK |
4163 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4164 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4165 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4166 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4167 new String[] { Long.class.getName(), Long.class.getName() });
4168
4169
4177 public List<MBMessage> findByG_U(long groupId, long userId)
4178 throws SystemException {
4179 return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4180 null);
4181 }
4182
4183
4197 public List<MBMessage> findByG_U(long groupId, long userId, int start,
4198 int end) throws SystemException {
4199 return findByG_U(groupId, userId, start, end, null);
4200 }
4201
4202
4217 public List<MBMessage> findByG_U(long groupId, long userId, int start,
4218 int end, OrderByComparator orderByComparator) throws SystemException {
4219 boolean pagination = true;
4220 FinderPath finderPath = null;
4221 Object[] finderArgs = null;
4222
4223 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4224 (orderByComparator == null)) {
4225 pagination = false;
4226 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4227 finderArgs = new Object[] { groupId, userId };
4228 }
4229 else {
4230 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4231 finderArgs = new Object[] {
4232 groupId, userId,
4233
4234 start, end, orderByComparator
4235 };
4236 }
4237
4238 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4239 finderArgs, this);
4240
4241 if ((list != null) && !list.isEmpty()) {
4242 for (MBMessage mbMessage : list) {
4243 if ((groupId != mbMessage.getGroupId()) ||
4244 (userId != mbMessage.getUserId())) {
4245 list = null;
4246
4247 break;
4248 }
4249 }
4250 }
4251
4252 if (list == null) {
4253 StringBundler query = null;
4254
4255 if (orderByComparator != null) {
4256 query = new StringBundler(4 +
4257 (orderByComparator.getOrderByFields().length * 3));
4258 }
4259 else {
4260 query = new StringBundler(4);
4261 }
4262
4263 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4264
4265 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4266
4267 query.append(_FINDER_COLUMN_G_U_USERID_2);
4268
4269 if (orderByComparator != null) {
4270 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4271 orderByComparator);
4272 }
4273 else
4274 if (pagination) {
4275 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4276 }
4277
4278 String sql = query.toString();
4279
4280 Session session = null;
4281
4282 try {
4283 session = openSession();
4284
4285 Query q = session.createQuery(sql);
4286
4287 QueryPos qPos = QueryPos.getInstance(q);
4288
4289 qPos.add(groupId);
4290
4291 qPos.add(userId);
4292
4293 if (!pagination) {
4294 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4295 start, end, false);
4296
4297 Collections.sort(list);
4298
4299 list = new UnmodifiableList<MBMessage>(list);
4300 }
4301 else {
4302 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4303 start, end);
4304 }
4305
4306 cacheResult(list);
4307
4308 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4309 }
4310 catch (Exception e) {
4311 FinderCacheUtil.removeResult(finderPath, finderArgs);
4312
4313 throw processException(e);
4314 }
4315 finally {
4316 closeSession(session);
4317 }
4318 }
4319
4320 return list;
4321 }
4322
4323
4333 public MBMessage findByG_U_First(long groupId, long userId,
4334 OrderByComparator orderByComparator)
4335 throws NoSuchMessageException, SystemException {
4336 MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4337 orderByComparator);
4338
4339 if (mbMessage != null) {
4340 return mbMessage;
4341 }
4342
4343 StringBundler msg = new StringBundler(6);
4344
4345 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4346
4347 msg.append("groupId=");
4348 msg.append(groupId);
4349
4350 msg.append(", userId=");
4351 msg.append(userId);
4352
4353 msg.append(StringPool.CLOSE_CURLY_BRACE);
4354
4355 throw new NoSuchMessageException(msg.toString());
4356 }
4357
4358
4367 public MBMessage fetchByG_U_First(long groupId, long userId,
4368 OrderByComparator orderByComparator) throws SystemException {
4369 List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4370 orderByComparator);
4371
4372 if (!list.isEmpty()) {
4373 return list.get(0);
4374 }
4375
4376 return null;
4377 }
4378
4379
4389 public MBMessage findByG_U_Last(long groupId, long userId,
4390 OrderByComparator orderByComparator)
4391 throws NoSuchMessageException, SystemException {
4392 MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4393
4394 if (mbMessage != null) {
4395 return mbMessage;
4396 }
4397
4398 StringBundler msg = new StringBundler(6);
4399
4400 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4401
4402 msg.append("groupId=");
4403 msg.append(groupId);
4404
4405 msg.append(", userId=");
4406 msg.append(userId);
4407
4408 msg.append(StringPool.CLOSE_CURLY_BRACE);
4409
4410 throw new NoSuchMessageException(msg.toString());
4411 }
4412
4413
4422 public MBMessage fetchByG_U_Last(long groupId, long userId,
4423 OrderByComparator orderByComparator) throws SystemException {
4424 int count = countByG_U(groupId, userId);
4425
4426 List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4427 orderByComparator);
4428
4429 if (!list.isEmpty()) {
4430 return list.get(0);
4431 }
4432
4433 return null;
4434 }
4435
4436
4447 public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4448 long userId, OrderByComparator orderByComparator)
4449 throws NoSuchMessageException, SystemException {
4450 MBMessage mbMessage = findByPrimaryKey(messageId);
4451
4452 Session session = null;
4453
4454 try {
4455 session = openSession();
4456
4457 MBMessage[] array = new MBMessageImpl[3];
4458
4459 array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4460 userId, orderByComparator, true);
4461
4462 array[1] = mbMessage;
4463
4464 array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4465 userId, orderByComparator, false);
4466
4467 return array;
4468 }
4469 catch (Exception e) {
4470 throw processException(e);
4471 }
4472 finally {
4473 closeSession(session);
4474 }
4475 }
4476
4477 protected MBMessage getByG_U_PrevAndNext(Session session,
4478 MBMessage mbMessage, long groupId, long userId,
4479 OrderByComparator orderByComparator, boolean previous) {
4480 StringBundler query = null;
4481
4482 if (orderByComparator != null) {
4483 query = new StringBundler(6 +
4484 (orderByComparator.getOrderByFields().length * 6));
4485 }
4486 else {
4487 query = new StringBundler(3);
4488 }
4489
4490 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4491
4492 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4493
4494 query.append(_FINDER_COLUMN_G_U_USERID_2);
4495
4496 if (orderByComparator != null) {
4497 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4498
4499 if (orderByConditionFields.length > 0) {
4500 query.append(WHERE_AND);
4501 }
4502
4503 for (int i = 0; i < orderByConditionFields.length; i++) {
4504 query.append(_ORDER_BY_ENTITY_ALIAS);
4505 query.append(orderByConditionFields[i]);
4506
4507 if ((i + 1) < orderByConditionFields.length) {
4508 if (orderByComparator.isAscending() ^ previous) {
4509 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4510 }
4511 else {
4512 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4513 }
4514 }
4515 else {
4516 if (orderByComparator.isAscending() ^ previous) {
4517 query.append(WHERE_GREATER_THAN);
4518 }
4519 else {
4520 query.append(WHERE_LESSER_THAN);
4521 }
4522 }
4523 }
4524
4525 query.append(ORDER_BY_CLAUSE);
4526
4527 String[] orderByFields = orderByComparator.getOrderByFields();
4528
4529 for (int i = 0; i < orderByFields.length; i++) {
4530 query.append(_ORDER_BY_ENTITY_ALIAS);
4531 query.append(orderByFields[i]);
4532
4533 if ((i + 1) < orderByFields.length) {
4534 if (orderByComparator.isAscending() ^ previous) {
4535 query.append(ORDER_BY_ASC_HAS_NEXT);
4536 }
4537 else {
4538 query.append(ORDER_BY_DESC_HAS_NEXT);
4539 }
4540 }
4541 else {
4542 if (orderByComparator.isAscending() ^ previous) {
4543 query.append(ORDER_BY_ASC);
4544 }
4545 else {
4546 query.append(ORDER_BY_DESC);
4547 }
4548 }
4549 }
4550 }
4551 else {
4552 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4553 }
4554
4555 String sql = query.toString();
4556
4557 Query q = session.createQuery(sql);
4558
4559 q.setFirstResult(0);
4560 q.setMaxResults(2);
4561
4562 QueryPos qPos = QueryPos.getInstance(q);
4563
4564 qPos.add(groupId);
4565
4566 qPos.add(userId);
4567
4568 if (orderByComparator != null) {
4569 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4570
4571 for (Object value : values) {
4572 qPos.add(value);
4573 }
4574 }
4575
4576 List<MBMessage> list = q.list();
4577
4578 if (list.size() == 2) {
4579 return list.get(1);
4580 }
4581 else {
4582 return null;
4583 }
4584 }
4585
4586
4594 public List<MBMessage> filterFindByG_U(long groupId, long userId)
4595 throws SystemException {
4596 return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4597 QueryUtil.ALL_POS, null);
4598 }
4599
4600
4614 public List<MBMessage> filterFindByG_U(long groupId, long userId,
4615 int start, int end) throws SystemException {
4616 return filterFindByG_U(groupId, userId, start, end, null);
4617 }
4618
4619
4634 public List<MBMessage> filterFindByG_U(long groupId, long userId,
4635 int start, int end, OrderByComparator orderByComparator)
4636 throws SystemException {
4637 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4638 return findByG_U(groupId, userId, start, end, orderByComparator);
4639 }
4640
4641 StringBundler query = null;
4642
4643 if (orderByComparator != null) {
4644 query = new StringBundler(4 +
4645 (orderByComparator.getOrderByFields().length * 3));
4646 }
4647 else {
4648 query = new StringBundler(4);
4649 }
4650
4651 if (getDB().isSupportsInlineDistinct()) {
4652 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4653 }
4654 else {
4655 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4656 }
4657
4658 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4659
4660 query.append(_FINDER_COLUMN_G_U_USERID_2);
4661
4662 if (!getDB().isSupportsInlineDistinct()) {
4663 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4664 }
4665
4666 if (orderByComparator != null) {
4667 if (getDB().isSupportsInlineDistinct()) {
4668 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4669 orderByComparator);
4670 }
4671 else {
4672 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4673 orderByComparator);
4674 }
4675 }
4676 else {
4677 if (getDB().isSupportsInlineDistinct()) {
4678 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4679 }
4680 else {
4681 query.append(MBMessageModelImpl.ORDER_BY_SQL);
4682 }
4683 }
4684
4685 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4686 MBMessage.class.getName(),
4687 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4688
4689 Session session = null;
4690
4691 try {
4692 session = openSession();
4693
4694 SQLQuery q = session.createSQLQuery(sql);
4695
4696 if (getDB().isSupportsInlineDistinct()) {
4697 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4698 }
4699 else {
4700 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4701 }
4702
4703 QueryPos qPos = QueryPos.getInstance(q);
4704
4705 qPos.add(groupId);
4706
4707 qPos.add(userId);
4708
4709 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4710 }
4711 catch (Exception e) {
4712 throw processException(e);
4713 }
4714 finally {
4715 closeSession(session);
4716 }
4717 }
4718
4719
4730 public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4731 long groupId, long userId, OrderByComparator orderByComparator)
4732 throws NoSuchMessageException, SystemException {
4733 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4734 return findByG_U_PrevAndNext(messageId, groupId, userId,
4735 orderByComparator);
4736 }
4737
4738 MBMessage mbMessage = findByPrimaryKey(messageId);
4739
4740 Session session = null;
4741
4742 try {
4743 session = openSession();
4744
4745 MBMessage[] array = new MBMessageImpl[3];
4746
4747 array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4748 userId, orderByComparator, true);
4749
4750 array[1] = mbMessage;
4751
4752 array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4753 userId, orderByComparator, false);
4754
4755 return array;
4756 }
4757 catch (Exception e) {
4758 throw processException(e);
4759 }
4760 finally {
4761 closeSession(session);
4762 }
4763 }
4764
4765 protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4766 MBMessage mbMessage, long groupId, long userId,
4767 OrderByComparator orderByComparator, boolean previous) {
4768 StringBundler query = null;
4769
4770 if (orderByComparator != null) {
4771 query = new StringBundler(6 +
4772 (orderByComparator.getOrderByFields().length * 6));
4773 }
4774 else {
4775 query = new StringBundler(3);
4776 }
4777
4778 if (getDB().isSupportsInlineDistinct()) {
4779 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4780 }
4781 else {
4782 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4783 }
4784
4785 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4786
4787 query.append(_FINDER_COLUMN_G_U_USERID_2);
4788
4789 if (!getDB().isSupportsInlineDistinct()) {
4790 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4791 }
4792
4793 if (orderByComparator != null) {
4794 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4795
4796 if (orderByConditionFields.length > 0) {
4797 query.append(WHERE_AND);
4798 }
4799
4800 for (int i = 0; i < orderByConditionFields.length; i++) {
4801 if (getDB().isSupportsInlineDistinct()) {
4802 query.append(_ORDER_BY_ENTITY_ALIAS);
4803 }
4804 else {
4805 query.append(_ORDER_BY_ENTITY_TABLE);
4806 }
4807
4808 query.append(orderByConditionFields[i]);
4809
4810 if ((i + 1) < orderByConditionFields.length) {
4811 if (orderByComparator.isAscending() ^ previous) {
4812 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4813 }
4814 else {
4815 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4816 }
4817 }
4818 else {
4819 if (orderByComparator.isAscending() ^ previous) {
4820 query.append(WHERE_GREATER_THAN);
4821 }
4822 else {
4823 query.append(WHERE_LESSER_THAN);
4824 }
4825 }
4826 }
4827
4828 query.append(ORDER_BY_CLAUSE);
4829
4830 String[] orderByFields = orderByComparator.getOrderByFields();
4831
4832 for (int i = 0; i < orderByFields.length; i++) {
4833 if (getDB().isSupportsInlineDistinct()) {
4834 query.append(_ORDER_BY_ENTITY_ALIAS);
4835 }
4836 else {
4837 query.append(_ORDER_BY_ENTITY_TABLE);
4838 }
4839
4840 query.append(orderByFields[i]);
4841
4842 if ((i + 1) < orderByFields.length) {
4843 if (orderByComparator.isAscending() ^ previous) {
4844 query.append(ORDER_BY_ASC_HAS_NEXT);
4845 }
4846 else {
4847 query.append(ORDER_BY_DESC_HAS_NEXT);
4848 }
4849 }
4850 else {
4851 if (orderByComparator.isAscending() ^ previous) {
4852 query.append(ORDER_BY_ASC);
4853 }
4854 else {
4855 query.append(ORDER_BY_DESC);
4856 }
4857 }
4858 }
4859 }
4860 else {
4861 if (getDB().isSupportsInlineDistinct()) {
4862 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4863 }
4864 else {
4865 query.append(MBMessageModelImpl.ORDER_BY_SQL);
4866 }
4867 }
4868
4869 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4870 MBMessage.class.getName(),
4871 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4872
4873 SQLQuery q = session.createSQLQuery(sql);
4874
4875 q.setFirstResult(0);
4876 q.setMaxResults(2);
4877
4878 if (getDB().isSupportsInlineDistinct()) {
4879 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4880 }
4881 else {
4882 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4883 }
4884
4885 QueryPos qPos = QueryPos.getInstance(q);
4886
4887 qPos.add(groupId);
4888
4889 qPos.add(userId);
4890
4891 if (orderByComparator != null) {
4892 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4893
4894 for (Object value : values) {
4895 qPos.add(value);
4896 }
4897 }
4898
4899 List<MBMessage> list = q.list();
4900
4901 if (list.size() == 2) {
4902 return list.get(1);
4903 }
4904 else {
4905 return null;
4906 }
4907 }
4908
4909
4916 public void removeByG_U(long groupId, long userId)
4917 throws SystemException {
4918 for (MBMessage mbMessage : findByG_U(groupId, userId,
4919 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4920 remove(mbMessage);
4921 }
4922 }
4923
4924
4932 public int countByG_U(long groupId, long userId) throws SystemException {
4933 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
4934
4935 Object[] finderArgs = new Object[] { groupId, userId };
4936
4937 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4938 this);
4939
4940 if (count == null) {
4941 StringBundler query = new StringBundler(3);
4942
4943 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4944
4945 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4946
4947 query.append(_FINDER_COLUMN_G_U_USERID_2);
4948
4949 String sql = query.toString();
4950
4951 Session session = null;
4952
4953 try {
4954 session = openSession();
4955
4956 Query q = session.createQuery(sql);
4957
4958 QueryPos qPos = QueryPos.getInstance(q);
4959
4960 qPos.add(groupId);
4961
4962 qPos.add(userId);
4963
4964 count = (Long)q.uniqueResult();
4965
4966 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4967 }
4968 catch (Exception e) {
4969 FinderCacheUtil.removeResult(finderPath, finderArgs);
4970
4971 throw processException(e);
4972 }
4973 finally {
4974 closeSession(session);
4975 }
4976 }
4977
4978 return count.intValue();
4979 }
4980
4981
4989 public int filterCountByG_U(long groupId, long userId)
4990 throws SystemException {
4991 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4992 return countByG_U(groupId, userId);
4993 }
4994
4995 StringBundler query = new StringBundler(3);
4996
4997 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
4998
4999 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5000
5001 query.append(_FINDER_COLUMN_G_U_USERID_2);
5002
5003 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5004 MBMessage.class.getName(),
5005 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5006
5007 Session session = null;
5008
5009 try {
5010 session = openSession();
5011
5012 SQLQuery q = session.createSQLQuery(sql);
5013
5014 q.addScalar(COUNT_COLUMN_NAME,
5015 com.liferay.portal.kernel.dao.orm.Type.LONG);
5016
5017 QueryPos qPos = QueryPos.getInstance(q);
5018
5019 qPos.add(groupId);
5020
5021 qPos.add(userId);
5022
5023 Long count = (Long)q.uniqueResult();
5024
5025 return count.intValue();
5026 }
5027 catch (Exception e) {
5028 throw processException(e);
5029 }
5030 finally {
5031 closeSession(session);
5032 }
5033 }
5034
5035 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5036 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5037 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5038 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5039 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5040 new String[] {
5041 Long.class.getName(), Long.class.getName(),
5042
5043 Integer.class.getName(), Integer.class.getName(),
5044 OrderByComparator.class.getName()
5045 });
5046 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5047 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5048 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5049 new String[] { Long.class.getName(), Long.class.getName() },
5050 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5051 MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5052 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5053 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5054 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5055 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5056 new String[] { Long.class.getName(), Long.class.getName() });
5057
5058
5066 public List<MBMessage> findByG_C(long groupId, long categoryId)
5067 throws SystemException {
5068 return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5069 QueryUtil.ALL_POS, null);
5070 }
5071
5072
5086 public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5087 int end) throws SystemException {
5088 return findByG_C(groupId, categoryId, start, end, null);
5089 }
5090
5091
5106 public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5107 int end, OrderByComparator orderByComparator) throws SystemException {
5108 boolean pagination = true;
5109 FinderPath finderPath = null;
5110 Object[] finderArgs = null;
5111
5112 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5113 (orderByComparator == null)) {
5114 pagination = false;
5115 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5116 finderArgs = new Object[] { groupId, categoryId };
5117 }
5118 else {
5119 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5120 finderArgs = new Object[] {
5121 groupId, categoryId,
5122
5123 start, end, orderByComparator
5124 };
5125 }
5126
5127 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5128 finderArgs, this);
5129
5130 if ((list != null) && !list.isEmpty()) {
5131 for (MBMessage mbMessage : list) {
5132 if ((groupId != mbMessage.getGroupId()) ||
5133 (categoryId != mbMessage.getCategoryId())) {
5134 list = null;
5135
5136 break;
5137 }
5138 }
5139 }
5140
5141 if (list == null) {
5142 StringBundler query = null;
5143
5144 if (orderByComparator != null) {
5145 query = new StringBundler(4 +
5146 (orderByComparator.getOrderByFields().length * 3));
5147 }
5148 else {
5149 query = new StringBundler(4);
5150 }
5151
5152 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5153
5154 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5155
5156 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5157
5158 if (orderByComparator != null) {
5159 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5160 orderByComparator);
5161 }
5162 else
5163 if (pagination) {
5164 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5165 }
5166
5167 String sql = query.toString();
5168
5169 Session session = null;
5170
5171 try {
5172 session = openSession();
5173
5174 Query q = session.createQuery(sql);
5175
5176 QueryPos qPos = QueryPos.getInstance(q);
5177
5178 qPos.add(groupId);
5179
5180 qPos.add(categoryId);
5181
5182 if (!pagination) {
5183 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5184 start, end, false);
5185
5186 Collections.sort(list);
5187
5188 list = new UnmodifiableList<MBMessage>(list);
5189 }
5190 else {
5191 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5192 start, end);
5193 }
5194
5195 cacheResult(list);
5196
5197 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5198 }
5199 catch (Exception e) {
5200 FinderCacheUtil.removeResult(finderPath, finderArgs);
5201
5202 throw processException(e);
5203 }
5204 finally {
5205 closeSession(session);
5206 }
5207 }
5208
5209 return list;
5210 }
5211
5212
5222 public MBMessage findByG_C_First(long groupId, long categoryId,
5223 OrderByComparator orderByComparator)
5224 throws NoSuchMessageException, SystemException {
5225 MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5226 orderByComparator);
5227
5228 if (mbMessage != null) {
5229 return mbMessage;
5230 }
5231
5232 StringBundler msg = new StringBundler(6);
5233
5234 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5235
5236 msg.append("groupId=");
5237 msg.append(groupId);
5238
5239 msg.append(", categoryId=");
5240 msg.append(categoryId);
5241
5242 msg.append(StringPool.CLOSE_CURLY_BRACE);
5243
5244 throw new NoSuchMessageException(msg.toString());
5245 }
5246
5247
5256 public MBMessage fetchByG_C_First(long groupId, long categoryId,
5257 OrderByComparator orderByComparator) throws SystemException {
5258 List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5259 orderByComparator);
5260
5261 if (!list.isEmpty()) {
5262 return list.get(0);
5263 }
5264
5265 return null;
5266 }
5267
5268
5278 public MBMessage findByG_C_Last(long groupId, long categoryId,
5279 OrderByComparator orderByComparator)
5280 throws NoSuchMessageException, SystemException {
5281 MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5282 orderByComparator);
5283
5284 if (mbMessage != null) {
5285 return mbMessage;
5286 }
5287
5288 StringBundler msg = new StringBundler(6);
5289
5290 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5291
5292 msg.append("groupId=");
5293 msg.append(groupId);
5294
5295 msg.append(", categoryId=");
5296 msg.append(categoryId);
5297
5298 msg.append(StringPool.CLOSE_CURLY_BRACE);
5299
5300 throw new NoSuchMessageException(msg.toString());
5301 }
5302
5303
5312 public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5313 OrderByComparator orderByComparator) throws SystemException {
5314 int count = countByG_C(groupId, categoryId);
5315
5316 List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5317 orderByComparator);
5318
5319 if (!list.isEmpty()) {
5320 return list.get(0);
5321 }
5322
5323 return null;
5324 }
5325
5326
5337 public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5338 long categoryId, OrderByComparator orderByComparator)
5339 throws NoSuchMessageException, SystemException {
5340 MBMessage mbMessage = findByPrimaryKey(messageId);
5341
5342 Session session = null;
5343
5344 try {
5345 session = openSession();
5346
5347 MBMessage[] array = new MBMessageImpl[3];
5348
5349 array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5350 categoryId, orderByComparator, true);
5351
5352 array[1] = mbMessage;
5353
5354 array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5355 categoryId, orderByComparator, false);
5356
5357 return array;
5358 }
5359 catch (Exception e) {
5360 throw processException(e);
5361 }
5362 finally {
5363 closeSession(session);
5364 }
5365 }
5366
5367 protected MBMessage getByG_C_PrevAndNext(Session session,
5368 MBMessage mbMessage, long groupId, long categoryId,
5369 OrderByComparator orderByComparator, boolean previous) {
5370 StringBundler query = null;
5371
5372 if (orderByComparator != null) {
5373 query = new StringBundler(6 +
5374 (orderByComparator.getOrderByFields().length * 6));
5375 }
5376 else {
5377 query = new StringBundler(3);
5378 }
5379
5380 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5381
5382 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5383
5384 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5385
5386 if (orderByComparator != null) {
5387 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5388
5389 if (orderByConditionFields.length > 0) {
5390 query.append(WHERE_AND);
5391 }
5392
5393 for (int i = 0; i < orderByConditionFields.length; i++) {
5394 query.append(_ORDER_BY_ENTITY_ALIAS);
5395 query.append(orderByConditionFields[i]);
5396
5397 if ((i + 1) < orderByConditionFields.length) {
5398 if (orderByComparator.isAscending() ^ previous) {
5399 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5400 }
5401 else {
5402 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5403 }
5404 }
5405 else {
5406 if (orderByComparator.isAscending() ^ previous) {
5407 query.append(WHERE_GREATER_THAN);
5408 }
5409 else {
5410 query.append(WHERE_LESSER_THAN);
5411 }
5412 }
5413 }
5414
5415 query.append(ORDER_BY_CLAUSE);
5416
5417 String[] orderByFields = orderByComparator.getOrderByFields();
5418
5419 for (int i = 0; i < orderByFields.length; i++) {
5420 query.append(_ORDER_BY_ENTITY_ALIAS);
5421 query.append(orderByFields[i]);
5422
5423 if ((i + 1) < orderByFields.length) {
5424 if (orderByComparator.isAscending() ^ previous) {
5425 query.append(ORDER_BY_ASC_HAS_NEXT);
5426 }
5427 else {
5428 query.append(ORDER_BY_DESC_HAS_NEXT);
5429 }
5430 }
5431 else {
5432 if (orderByComparator.isAscending() ^ previous) {
5433 query.append(ORDER_BY_ASC);
5434 }
5435 else {
5436 query.append(ORDER_BY_DESC);
5437 }
5438 }
5439 }
5440 }
5441 else {
5442 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5443 }
5444
5445 String sql = query.toString();
5446
5447 Query q = session.createQuery(sql);
5448
5449 q.setFirstResult(0);
5450 q.setMaxResults(2);
5451
5452 QueryPos qPos = QueryPos.getInstance(q);
5453
5454 qPos.add(groupId);
5455
5456 qPos.add(categoryId);
5457
5458 if (orderByComparator != null) {
5459 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5460
5461 for (Object value : values) {
5462 qPos.add(value);
5463 }
5464 }
5465
5466 List<MBMessage> list = q.list();
5467
5468 if (list.size() == 2) {
5469 return list.get(1);
5470 }
5471 else {
5472 return null;
5473 }
5474 }
5475
5476
5484 public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5485 throws SystemException {
5486 return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5487 QueryUtil.ALL_POS, null);
5488 }
5489
5490
5504 public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5505 int start, int end) throws SystemException {
5506 return filterFindByG_C(groupId, categoryId, start, end, null);
5507 }
5508
5509
5524 public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5525 int start, int end, OrderByComparator orderByComparator)
5526 throws SystemException {
5527 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5528 return findByG_C(groupId, categoryId, start, end, orderByComparator);
5529 }
5530
5531 StringBundler query = null;
5532
5533 if (orderByComparator != null) {
5534 query = new StringBundler(4 +
5535 (orderByComparator.getOrderByFields().length * 3));
5536 }
5537 else {
5538 query = new StringBundler(4);
5539 }
5540
5541 if (getDB().isSupportsInlineDistinct()) {
5542 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5543 }
5544 else {
5545 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5546 }
5547
5548 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5549
5550 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5551
5552 if (!getDB().isSupportsInlineDistinct()) {
5553 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5554 }
5555
5556 if (orderByComparator != null) {
5557 if (getDB().isSupportsInlineDistinct()) {
5558 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5559 orderByComparator);
5560 }
5561 else {
5562 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5563 orderByComparator);
5564 }
5565 }
5566 else {
5567 if (getDB().isSupportsInlineDistinct()) {
5568 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5569 }
5570 else {
5571 query.append(MBMessageModelImpl.ORDER_BY_SQL);
5572 }
5573 }
5574
5575 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5576 MBMessage.class.getName(),
5577 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5578
5579 Session session = null;
5580
5581 try {
5582 session = openSession();
5583
5584 SQLQuery q = session.createSQLQuery(sql);
5585
5586 if (getDB().isSupportsInlineDistinct()) {
5587 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5588 }
5589 else {
5590 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5591 }
5592
5593 QueryPos qPos = QueryPos.getInstance(q);
5594
5595 qPos.add(groupId);
5596
5597 qPos.add(categoryId);
5598
5599 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5600 }
5601 catch (Exception e) {
5602 throw processException(e);
5603 }
5604 finally {
5605 closeSession(session);
5606 }
5607 }
5608
5609
5620 public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5621 long groupId, long categoryId, OrderByComparator orderByComparator)
5622 throws NoSuchMessageException, SystemException {
5623 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5624 return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5625 orderByComparator);
5626 }
5627
5628 MBMessage mbMessage = findByPrimaryKey(messageId);
5629
5630 Session session = null;
5631
5632 try {
5633 session = openSession();
5634
5635 MBMessage[] array = new MBMessageImpl[3];
5636
5637 array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5638 categoryId, orderByComparator, true);
5639
5640 array[1] = mbMessage;
5641
5642 array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5643 categoryId, orderByComparator, false);
5644
5645 return array;
5646 }
5647 catch (Exception e) {
5648 throw processException(e);
5649 }
5650 finally {
5651 closeSession(session);
5652 }
5653 }
5654
5655 protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5656 MBMessage mbMessage, long groupId, long categoryId,
5657 OrderByComparator orderByComparator, boolean previous) {
5658 StringBundler query = null;
5659
5660 if (orderByComparator != null) {
5661 query = new StringBundler(6 +
5662 (orderByComparator.getOrderByFields().length * 6));
5663 }
5664 else {
5665 query = new StringBundler(3);
5666 }
5667
5668 if (getDB().isSupportsInlineDistinct()) {
5669 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5670 }
5671 else {
5672 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5673 }
5674
5675 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5676
5677 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5678
5679 if (!getDB().isSupportsInlineDistinct()) {
5680 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5681 }
5682
5683 if (orderByComparator != null) {
5684 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5685
5686 if (orderByConditionFields.length > 0) {
5687 query.append(WHERE_AND);
5688 }
5689
5690 for (int i = 0; i < orderByConditionFields.length; i++) {
5691 if (getDB().isSupportsInlineDistinct()) {
5692 query.append(_ORDER_BY_ENTITY_ALIAS);
5693 }
5694 else {
5695 query.append(_ORDER_BY_ENTITY_TABLE);
5696 }
5697
5698 query.append(orderByConditionFields[i]);
5699
5700 if ((i + 1) < orderByConditionFields.length) {
5701 if (orderByComparator.isAscending() ^ previous) {
5702 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5703 }
5704 else {
5705 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5706 }
5707 }
5708 else {
5709 if (orderByComparator.isAscending() ^ previous) {
5710 query.append(WHERE_GREATER_THAN);
5711 }
5712 else {
5713 query.append(WHERE_LESSER_THAN);
5714 }
5715 }
5716 }
5717
5718 query.append(ORDER_BY_CLAUSE);
5719
5720 String[] orderByFields = orderByComparator.getOrderByFields();
5721
5722 for (int i = 0; i < orderByFields.length; i++) {
5723 if (getDB().isSupportsInlineDistinct()) {
5724 query.append(_ORDER_BY_ENTITY_ALIAS);
5725 }
5726 else {
5727 query.append(_ORDER_BY_ENTITY_TABLE);
5728 }
5729
5730 query.append(orderByFields[i]);
5731
5732 if ((i + 1) < orderByFields.length) {
5733 if (orderByComparator.isAscending() ^ previous) {
5734 query.append(ORDER_BY_ASC_HAS_NEXT);
5735 }
5736 else {
5737 query.append(ORDER_BY_DESC_HAS_NEXT);
5738 }
5739 }
5740 else {
5741 if (orderByComparator.isAscending() ^ previous) {
5742 query.append(ORDER_BY_ASC);
5743 }
5744 else {
5745 query.append(ORDER_BY_DESC);
5746 }
5747 }
5748 }
5749 }
5750 else {
5751 if (getDB().isSupportsInlineDistinct()) {
5752 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5753 }
5754 else {
5755 query.append(MBMessageModelImpl.ORDER_BY_SQL);
5756 }
5757 }
5758
5759 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5760 MBMessage.class.getName(),
5761 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5762
5763 SQLQuery q = session.createSQLQuery(sql);
5764
5765 q.setFirstResult(0);
5766 q.setMaxResults(2);
5767
5768 if (getDB().isSupportsInlineDistinct()) {
5769 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5770 }
5771 else {
5772 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5773 }
5774
5775 QueryPos qPos = QueryPos.getInstance(q);
5776
5777 qPos.add(groupId);
5778
5779 qPos.add(categoryId);
5780
5781 if (orderByComparator != null) {
5782 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5783
5784 for (Object value : values) {
5785 qPos.add(value);
5786 }
5787 }
5788
5789 List<MBMessage> list = q.list();
5790
5791 if (list.size() == 2) {
5792 return list.get(1);
5793 }
5794 else {
5795 return null;
5796 }
5797 }
5798
5799
5806 public void removeByG_C(long groupId, long categoryId)
5807 throws SystemException {
5808 for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5809 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5810 remove(mbMessage);
5811 }
5812 }
5813
5814
5822 public int countByG_C(long groupId, long categoryId)
5823 throws SystemException {
5824 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5825
5826 Object[] finderArgs = new Object[] { groupId, categoryId };
5827
5828 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5829 this);
5830
5831 if (count == null) {
5832 StringBundler query = new StringBundler(3);
5833
5834 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5835
5836 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5837
5838 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5839
5840 String sql = query.toString();
5841
5842 Session session = null;
5843
5844 try {
5845 session = openSession();
5846
5847 Query q = session.createQuery(sql);
5848
5849 QueryPos qPos = QueryPos.getInstance(q);
5850
5851 qPos.add(groupId);
5852
5853 qPos.add(categoryId);
5854
5855 count = (Long)q.uniqueResult();
5856
5857 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5858 }
5859 catch (Exception e) {
5860 FinderCacheUtil.removeResult(finderPath, finderArgs);
5861
5862 throw processException(e);
5863 }
5864 finally {
5865 closeSession(session);
5866 }
5867 }
5868
5869 return count.intValue();
5870 }
5871
5872
5880 public int filterCountByG_C(long groupId, long categoryId)
5881 throws SystemException {
5882 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5883 return countByG_C(groupId, categoryId);
5884 }
5885
5886 StringBundler query = new StringBundler(3);
5887
5888 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5889
5890 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5891
5892 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5893
5894 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5895 MBMessage.class.getName(),
5896 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5897
5898 Session session = null;
5899
5900 try {
5901 session = openSession();
5902
5903 SQLQuery q = session.createSQLQuery(sql);
5904
5905 q.addScalar(COUNT_COLUMN_NAME,
5906 com.liferay.portal.kernel.dao.orm.Type.LONG);
5907
5908 QueryPos qPos = QueryPos.getInstance(q);
5909
5910 qPos.add(groupId);
5911
5912 qPos.add(categoryId);
5913
5914 Long count = (Long)q.uniqueResult();
5915
5916 return count.intValue();
5917 }
5918 catch (Exception e) {
5919 throw processException(e);
5920 }
5921 finally {
5922 closeSession(session);
5923 }
5924 }
5925
5926 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
5927 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
5928 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5929 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5930 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
5931 new String[] {
5932 Long.class.getName(), Integer.class.getName(),
5933
5934 Integer.class.getName(), Integer.class.getName(),
5935 OrderByComparator.class.getName()
5936 });
5937 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5938 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5939 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
5940 new String[] { Long.class.getName(), Integer.class.getName() },
5941 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5942 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
5943 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5944 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5945 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5946 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
5947 new String[] { Long.class.getName(), Integer.class.getName() });
5948
5949
5957 public List<MBMessage> findByG_S(long groupId, int status)
5958 throws SystemException {
5959 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5960 null);
5961 }
5962
5963
5977 public List<MBMessage> findByG_S(long groupId, int status, int start,
5978 int end) throws SystemException {
5979 return findByG_S(groupId, status, start, end, null);
5980 }
5981
5982
5997 public List<MBMessage> findByG_S(long groupId, int status, int start,
5998 int end, OrderByComparator orderByComparator) throws SystemException {
5999 boolean pagination = true;
6000 FinderPath finderPath = null;
6001 Object[] finderArgs = null;
6002
6003 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6004 (orderByComparator == null)) {
6005 pagination = false;
6006 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6007 finderArgs = new Object[] { groupId, status };
6008 }
6009 else {
6010 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6011 finderArgs = new Object[] {
6012 groupId, status,
6013
6014 start, end, orderByComparator
6015 };
6016 }
6017
6018 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6019 finderArgs, this);
6020
6021 if ((list != null) && !list.isEmpty()) {
6022 for (MBMessage mbMessage : list) {
6023 if ((groupId != mbMessage.getGroupId()) ||
6024 (status != mbMessage.getStatus())) {
6025 list = null;
6026
6027 break;
6028 }
6029 }
6030 }
6031
6032 if (list == null) {
6033 StringBundler query = null;
6034
6035 if (orderByComparator != null) {
6036 query = new StringBundler(4 +
6037 (orderByComparator.getOrderByFields().length * 3));
6038 }
6039 else {
6040 query = new StringBundler(4);
6041 }
6042
6043 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6044
6045 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6046
6047 query.append(_FINDER_COLUMN_G_S_STATUS_2);
6048
6049 if (orderByComparator != null) {
6050 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6051 orderByComparator);
6052 }
6053 else
6054 if (pagination) {
6055 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6056 }
6057
6058 String sql = query.toString();
6059
6060 Session session = null;
6061
6062 try {
6063 session = openSession();
6064
6065 Query q = session.createQuery(sql);
6066
6067 QueryPos qPos = QueryPos.getInstance(q);
6068
6069 qPos.add(groupId);
6070
6071 qPos.add(status);
6072
6073 if (!pagination) {
6074 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6075 start, end, false);
6076
6077 Collections.sort(list);
6078
6079 list = new UnmodifiableList<MBMessage>(list);
6080 }
6081 else {
6082 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6083 start, end);
6084 }
6085
6086 cacheResult(list);
6087
6088 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6089 }
6090 catch (Exception e) {
6091 FinderCacheUtil.removeResult(finderPath, finderArgs);
6092
6093 throw processException(e);
6094 }
6095 finally {
6096 closeSession(session);
6097 }
6098 }
6099
6100 return list;
6101 }
6102
6103
6113 public MBMessage findByG_S_First(long groupId, int status,
6114 OrderByComparator orderByComparator)
6115 throws NoSuchMessageException, SystemException {
6116 MBMessage mbMessage = fetchByG_S_First(groupId, status,
6117 orderByComparator);
6118
6119 if (mbMessage != null) {
6120 return mbMessage;
6121 }
6122
6123 StringBundler msg = new StringBundler(6);
6124
6125 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6126
6127 msg.append("groupId=");
6128 msg.append(groupId);
6129
6130 msg.append(", status=");
6131 msg.append(status);
6132
6133 msg.append(StringPool.CLOSE_CURLY_BRACE);
6134
6135 throw new NoSuchMessageException(msg.toString());
6136 }
6137
6138
6147 public MBMessage fetchByG_S_First(long groupId, int status,
6148 OrderByComparator orderByComparator) throws SystemException {
6149 List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6150 orderByComparator);
6151
6152 if (!list.isEmpty()) {
6153 return list.get(0);
6154 }
6155
6156 return null;
6157 }
6158
6159
6169 public MBMessage findByG_S_Last(long groupId, int status,
6170 OrderByComparator orderByComparator)
6171 throws NoSuchMessageException, SystemException {
6172 MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6173
6174 if (mbMessage != null) {
6175 return mbMessage;
6176 }
6177
6178 StringBundler msg = new StringBundler(6);
6179
6180 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6181
6182 msg.append("groupId=");
6183 msg.append(groupId);
6184
6185 msg.append(", status=");
6186 msg.append(status);
6187
6188 msg.append(StringPool.CLOSE_CURLY_BRACE);
6189
6190 throw new NoSuchMessageException(msg.toString());
6191 }
6192
6193
6202 public MBMessage fetchByG_S_Last(long groupId, int status,
6203 OrderByComparator orderByComparator) throws SystemException {
6204 int count = countByG_S(groupId, status);
6205
6206 List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6207 orderByComparator);
6208
6209 if (!list.isEmpty()) {
6210 return list.get(0);
6211 }
6212
6213 return null;
6214 }
6215
6216
6227 public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6228 int status, OrderByComparator orderByComparator)
6229 throws NoSuchMessageException, SystemException {
6230 MBMessage mbMessage = findByPrimaryKey(messageId);
6231
6232 Session session = null;
6233
6234 try {
6235 session = openSession();
6236
6237 MBMessage[] array = new MBMessageImpl[3];
6238
6239 array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6240 status, orderByComparator, true);
6241
6242 array[1] = mbMessage;
6243
6244 array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6245 status, orderByComparator, false);
6246
6247 return array;
6248 }
6249 catch (Exception e) {
6250 throw processException(e);
6251 }
6252 finally {
6253 closeSession(session);
6254 }
6255 }
6256
6257 protected MBMessage getByG_S_PrevAndNext(Session session,
6258 MBMessage mbMessage, long groupId, int status,
6259 OrderByComparator orderByComparator, boolean previous) {
6260 StringBundler query = null;
6261
6262 if (orderByComparator != null) {
6263 query = new StringBundler(6 +
6264 (orderByComparator.getOrderByFields().length * 6));
6265 }
6266 else {
6267 query = new StringBundler(3);
6268 }
6269
6270 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6271
6272 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6273
6274 query.append(_FINDER_COLUMN_G_S_STATUS_2);
6275
6276 if (orderByComparator != null) {
6277 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6278
6279 if (orderByConditionFields.length > 0) {
6280 query.append(WHERE_AND);
6281 }
6282
6283 for (int i = 0; i < orderByConditionFields.length; i++) {
6284 query.append(_ORDER_BY_ENTITY_ALIAS);
6285 query.append(orderByConditionFields[i]);
6286
6287 if ((i + 1) < orderByConditionFields.length) {
6288 if (orderByComparator.isAscending() ^ previous) {
6289 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6290 }
6291 else {
6292 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6293 }
6294 }
6295 else {
6296 if (orderByComparator.isAscending() ^ previous) {
6297 query.append(WHERE_GREATER_THAN);
6298 }
6299 else {
6300 query.append(WHERE_LESSER_THAN);
6301 }
6302 }
6303 }
6304
6305 query.append(ORDER_BY_CLAUSE);
6306
6307 String[] orderByFields = orderByComparator.getOrderByFields();
6308
6309 for (int i = 0; i < orderByFields.length; i++) {
6310 query.append(_ORDER_BY_ENTITY_ALIAS);
6311 query.append(orderByFields[i]);
6312
6313 if ((i + 1) < orderByFields.length) {
6314 if (orderByComparator.isAscending() ^ previous) {
6315 query.append(ORDER_BY_ASC_HAS_NEXT);
6316 }
6317 else {
6318 query.append(ORDER_BY_DESC_HAS_NEXT);
6319 }
6320 }
6321 else {
6322 if (orderByComparator.isAscending() ^ previous) {
6323 query.append(ORDER_BY_ASC);
6324 }
6325 else {
6326 query.append(ORDER_BY_DESC);
6327 }
6328 }
6329 }
6330 }
6331 else {
6332 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6333 }
6334
6335 String sql = query.toString();
6336
6337 Query q = session.createQuery(sql);
6338
6339 q.setFirstResult(0);
6340 q.setMaxResults(2);
6341
6342 QueryPos qPos = QueryPos.getInstance(q);
6343
6344 qPos.add(groupId);
6345
6346 qPos.add(status);
6347
6348 if (orderByComparator != null) {
6349 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6350
6351 for (Object value : values) {
6352 qPos.add(value);
6353 }
6354 }
6355
6356 List<MBMessage> list = q.list();
6357
6358 if (list.size() == 2) {
6359 return list.get(1);
6360 }
6361 else {
6362 return null;
6363 }
6364 }
6365
6366
6374 public List<MBMessage> filterFindByG_S(long groupId, int status)
6375 throws SystemException {
6376 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6377 QueryUtil.ALL_POS, null);
6378 }
6379
6380
6394 public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6395 int end) throws SystemException {
6396 return filterFindByG_S(groupId, status, start, end, null);
6397 }
6398
6399
6414 public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6415 int end, OrderByComparator orderByComparator) throws SystemException {
6416 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6417 return findByG_S(groupId, status, start, end, orderByComparator);
6418 }
6419
6420 StringBundler query = null;
6421
6422 if (orderByComparator != null) {
6423 query = new StringBundler(4 +
6424 (orderByComparator.getOrderByFields().length * 3));
6425 }
6426 else {
6427 query = new StringBundler(4);
6428 }
6429
6430 if (getDB().isSupportsInlineDistinct()) {
6431 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6432 }
6433 else {
6434 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6435 }
6436
6437 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6438
6439 query.append(_FINDER_COLUMN_G_S_STATUS_2);
6440
6441 if (!getDB().isSupportsInlineDistinct()) {
6442 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6443 }
6444
6445 if (orderByComparator != null) {
6446 if (getDB().isSupportsInlineDistinct()) {
6447 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6448 orderByComparator);
6449 }
6450 else {
6451 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6452 orderByComparator);
6453 }
6454 }
6455 else {
6456 if (getDB().isSupportsInlineDistinct()) {
6457 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6458 }
6459 else {
6460 query.append(MBMessageModelImpl.ORDER_BY_SQL);
6461 }
6462 }
6463
6464 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6465 MBMessage.class.getName(),
6466 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6467
6468 Session session = null;
6469
6470 try {
6471 session = openSession();
6472
6473 SQLQuery q = session.createSQLQuery(sql);
6474
6475 if (getDB().isSupportsInlineDistinct()) {
6476 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6477 }
6478 else {
6479 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6480 }
6481
6482 QueryPos qPos = QueryPos.getInstance(q);
6483
6484 qPos.add(groupId);
6485
6486 qPos.add(status);
6487
6488 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6489 }
6490 catch (Exception e) {
6491 throw processException(e);
6492 }
6493 finally {
6494 closeSession(session);
6495 }
6496 }
6497
6498
6509 public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6510 long groupId, int status, OrderByComparator orderByComparator)
6511 throws NoSuchMessageException, SystemException {
6512 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6513 return findByG_S_PrevAndNext(messageId, groupId, status,
6514 orderByComparator);
6515 }
6516
6517 MBMessage mbMessage = findByPrimaryKey(messageId);
6518
6519 Session session = null;
6520
6521 try {
6522 session = openSession();
6523
6524 MBMessage[] array = new MBMessageImpl[3];
6525
6526 array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6527 status, orderByComparator, true);
6528
6529 array[1] = mbMessage;
6530
6531 array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6532 status, orderByComparator, false);
6533
6534 return array;
6535 }
6536 catch (Exception e) {
6537 throw processException(e);
6538 }
6539 finally {
6540 closeSession(session);
6541 }
6542 }
6543
6544 protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6545 MBMessage mbMessage, long groupId, int status,
6546 OrderByComparator orderByComparator, boolean previous) {
6547 StringBundler query = null;
6548
6549 if (orderByComparator != null) {
6550 query = new StringBundler(6 +
6551 (orderByComparator.getOrderByFields().length * 6));
6552 }
6553 else {
6554 query = new StringBundler(3);
6555 }
6556
6557 if (getDB().isSupportsInlineDistinct()) {
6558 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6559 }
6560 else {
6561 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6562 }
6563
6564 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6565
6566 query.append(_FINDER_COLUMN_G_S_STATUS_2);
6567
6568 if (!getDB().isSupportsInlineDistinct()) {
6569 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6570 }
6571
6572 if (orderByComparator != null) {
6573 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6574
6575 if (orderByConditionFields.length > 0) {
6576 query.append(WHERE_AND);
6577 }
6578
6579 for (int i = 0; i < orderByConditionFields.length; i++) {
6580 if (getDB().isSupportsInlineDistinct()) {
6581 query.append(_ORDER_BY_ENTITY_ALIAS);
6582 }
6583 else {
6584 query.append(_ORDER_BY_ENTITY_TABLE);
6585 }
6586
6587 query.append(orderByConditionFields[i]);
6588
6589 if ((i + 1) < orderByConditionFields.length) {
6590 if (orderByComparator.isAscending() ^ previous) {
6591 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6592 }
6593 else {
6594 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6595 }
6596 }
6597 else {
6598 if (orderByComparator.isAscending() ^ previous) {
6599 query.append(WHERE_GREATER_THAN);
6600 }
6601 else {
6602 query.append(WHERE_LESSER_THAN);
6603 }
6604 }
6605 }
6606
6607 query.append(ORDER_BY_CLAUSE);
6608
6609 String[] orderByFields = orderByComparator.getOrderByFields();
6610
6611 for (int i = 0; i < orderByFields.length; i++) {
6612 if (getDB().isSupportsInlineDistinct()) {
6613 query.append(_ORDER_BY_ENTITY_ALIAS);
6614 }
6615 else {
6616 query.append(_ORDER_BY_ENTITY_TABLE);
6617 }
6618
6619 query.append(orderByFields[i]);
6620
6621 if ((i + 1) < orderByFields.length) {
6622 if (orderByComparator.isAscending() ^ previous) {
6623 query.append(ORDER_BY_ASC_HAS_NEXT);
6624 }
6625 else {
6626 query.append(ORDER_BY_DESC_HAS_NEXT);
6627 }
6628 }
6629 else {
6630 if (orderByComparator.isAscending() ^ previous) {
6631 query.append(ORDER_BY_ASC);
6632 }
6633 else {
6634 query.append(ORDER_BY_DESC);
6635 }
6636 }
6637 }
6638 }
6639 else {
6640 if (getDB().isSupportsInlineDistinct()) {
6641 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6642 }
6643 else {
6644 query.append(MBMessageModelImpl.ORDER_BY_SQL);
6645 }
6646 }
6647
6648 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6649 MBMessage.class.getName(),
6650 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6651
6652 SQLQuery q = session.createSQLQuery(sql);
6653
6654 q.setFirstResult(0);
6655 q.setMaxResults(2);
6656
6657 if (getDB().isSupportsInlineDistinct()) {
6658 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6659 }
6660 else {
6661 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6662 }
6663
6664 QueryPos qPos = QueryPos.getInstance(q);
6665
6666 qPos.add(groupId);
6667
6668 qPos.add(status);
6669
6670 if (orderByComparator != null) {
6671 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6672
6673 for (Object value : values) {
6674 qPos.add(value);
6675 }
6676 }
6677
6678 List<MBMessage> list = q.list();
6679
6680 if (list.size() == 2) {
6681 return list.get(1);
6682 }
6683 else {
6684 return null;
6685 }
6686 }
6687
6688
6695 public void removeByG_S(long groupId, int status) throws SystemException {
6696 for (MBMessage mbMessage : findByG_S(groupId, status,
6697 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6698 remove(mbMessage);
6699 }
6700 }
6701
6702
6710 public int countByG_S(long groupId, int status) throws SystemException {
6711 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6712
6713 Object[] finderArgs = new Object[] { groupId, status };
6714
6715 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6716 this);
6717
6718 if (count == null) {
6719 StringBundler query = new StringBundler(3);
6720
6721 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6722
6723 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6724
6725 query.append(_FINDER_COLUMN_G_S_STATUS_2);
6726
6727 String sql = query.toString();
6728
6729 Session session = null;
6730
6731 try {
6732 session = openSession();
6733
6734 Query q = session.createQuery(sql);
6735
6736 QueryPos qPos = QueryPos.getInstance(q);
6737
6738 qPos.add(groupId);
6739
6740 qPos.add(status);
6741
6742 count = (Long)q.uniqueResult();
6743
6744 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6745 }
6746 catch (Exception e) {
6747 FinderCacheUtil.removeResult(finderPath, finderArgs);
6748
6749 throw processException(e);
6750 }
6751 finally {
6752 closeSession(session);
6753 }
6754 }
6755
6756 return count.intValue();
6757 }
6758
6759
6767 public int filterCountByG_S(long groupId, int status)
6768 throws SystemException {
6769 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6770 return countByG_S(groupId, status);
6771 }
6772
6773 StringBundler query = new StringBundler(3);
6774
6775 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6776
6777 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6778
6779 query.append(_FINDER_COLUMN_G_S_STATUS_2);
6780
6781 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6782 MBMessage.class.getName(),
6783 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6784
6785 Session session = null;
6786
6787 try {
6788 session = openSession();
6789
6790 SQLQuery q = session.createSQLQuery(sql);
6791
6792 q.addScalar(COUNT_COLUMN_NAME,
6793 com.liferay.portal.kernel.dao.orm.Type.LONG);
6794
6795 QueryPos qPos = QueryPos.getInstance(q);
6796
6797 qPos.add(groupId);
6798
6799 qPos.add(status);
6800
6801 Long count = (Long)q.uniqueResult();
6802
6803 return count.intValue();
6804 }
6805 catch (Exception e) {
6806 throw processException(e);
6807 }
6808 finally {
6809 closeSession(session);
6810 }
6811 }
6812
6813 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6814 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6815 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6816 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6817 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
6818 new String[] {
6819 Long.class.getName(), Integer.class.getName(),
6820
6821 Integer.class.getName(), Integer.class.getName(),
6822 OrderByComparator.class.getName()
6823 });
6824 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6825 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6826 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
6827 new String[] { Long.class.getName(), Integer.class.getName() },
6828 MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
6829 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6830 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6831 public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6832 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6833 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
6834 new String[] { Long.class.getName(), Integer.class.getName() });
6835
6836
6844 public List<MBMessage> findByC_S(long companyId, int status)
6845 throws SystemException {
6846 return findByC_S(companyId, status, QueryUtil.ALL_POS,
6847 QueryUtil.ALL_POS, null);
6848 }
6849
6850
6864 public List<MBMessage> findByC_S(long companyId, int status, int start,
6865 int end) throws SystemException {
6866 return findByC_S(companyId, status, start, end, null);
6867 }
6868
6869
6884 public List<MBMessage> findByC_S(long companyId, int status, int start,
6885 int end, OrderByComparator orderByComparator) throws SystemException {
6886 boolean pagination = true;
6887 FinderPath finderPath = null;
6888 Object[] finderArgs = null;
6889
6890 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6891 (orderByComparator == null)) {
6892 pagination = false;
6893 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6894 finderArgs = new Object[] { companyId, status };
6895 }
6896 else {
6897 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6898 finderArgs = new Object[] {
6899 companyId, status,
6900
6901 start, end, orderByComparator
6902 };
6903 }
6904
6905 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6906 finderArgs, this);
6907
6908 if ((list != null) && !list.isEmpty()) {
6909 for (MBMessage mbMessage : list) {
6910 if ((companyId != mbMessage.getCompanyId()) ||
6911 (status != mbMessage.getStatus())) {
6912 list = null;
6913
6914 break;
6915 }
6916 }
6917 }
6918
6919 if (list == null) {
6920 StringBundler query = null;
6921
6922 if (orderByComparator != null) {
6923 query = new StringBundler(4 +
6924 (orderByComparator.getOrderByFields().length * 3));
6925 }
6926 else {
6927 query = new StringBundler(4);
6928 }
6929
6930 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6931
6932 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6933
6934 query.append(_FINDER_COLUMN_C_S_STATUS_2);
6935
6936 if (orderByComparator != null) {
6937 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6938 orderByComparator);
6939 }
6940 else
6941 if (pagination) {
6942 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6943 }
6944
6945 String sql = query.toString();
6946
6947 Session session = null;
6948
6949 try {
6950 session = openSession();
6951
6952 Query q = session.createQuery(sql);
6953
6954 QueryPos qPos = QueryPos.getInstance(q);
6955
6956 qPos.add(companyId);
6957
6958 qPos.add(status);
6959
6960 if (!pagination) {
6961 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6962 start, end, false);
6963
6964 Collections.sort(list);
6965
6966 list = new UnmodifiableList<MBMessage>(list);
6967 }
6968 else {
6969 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6970 start, end);
6971 }
6972
6973 cacheResult(list);
6974
6975 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6976 }
6977 catch (Exception e) {
6978 FinderCacheUtil.removeResult(finderPath, finderArgs);
6979
6980 throw processException(e);
6981 }
6982 finally {
6983 closeSession(session);
6984 }
6985 }
6986
6987 return list;
6988 }
6989
6990
7000 public MBMessage findByC_S_First(long companyId, int status,
7001 OrderByComparator orderByComparator)
7002 throws NoSuchMessageException, SystemException {
7003 MBMessage mbMessage = fetchByC_S_First(companyId, status,
7004 orderByComparator);
7005
7006 if (mbMessage != null) {
7007 return mbMessage;
7008 }
7009
7010 StringBundler msg = new StringBundler(6);
7011
7012 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7013
7014 msg.append("companyId=");
7015 msg.append(companyId);
7016
7017 msg.append(", status=");
7018 msg.append(status);
7019
7020 msg.append(StringPool.CLOSE_CURLY_BRACE);
7021
7022 throw new NoSuchMessageException(msg.toString());
7023 }
7024
7025
7034 public MBMessage fetchByC_S_First(long companyId, int status,
7035 OrderByComparator orderByComparator) throws SystemException {
7036 List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7037 orderByComparator);
7038
7039 if (!list.isEmpty()) {
7040 return list.get(0);
7041 }
7042
7043 return null;
7044 }
7045
7046
7056 public MBMessage findByC_S_Last(long companyId, int status,
7057 OrderByComparator orderByComparator)
7058 throws NoSuchMessageException, SystemException {
7059 MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7060 orderByComparator);
7061
7062 if (mbMessage != null) {
7063 return mbMessage;
7064 }
7065
7066 StringBundler msg = new StringBundler(6);
7067
7068 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7069
7070 msg.append("companyId=");
7071 msg.append(companyId);
7072
7073 msg.append(", status=");
7074 msg.append(status);
7075
7076 msg.append(StringPool.CLOSE_CURLY_BRACE);
7077
7078 throw new NoSuchMessageException(msg.toString());
7079 }
7080
7081
7090 public MBMessage fetchByC_S_Last(long companyId, int status,
7091 OrderByComparator orderByComparator) throws SystemException {
7092 int count = countByC_S(companyId, status);
7093
7094 List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7095 orderByComparator);
7096
7097 if (!list.isEmpty()) {
7098 return list.get(0);
7099 }
7100
7101 return null;
7102 }
7103
7104
7115 public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7116 int status, OrderByComparator orderByComparator)
7117 throws NoSuchMessageException, SystemException {
7118 MBMessage mbMessage = findByPrimaryKey(messageId);
7119
7120 Session session = null;
7121
7122 try {
7123 session = openSession();
7124
7125 MBMessage[] array = new MBMessageImpl[3];
7126
7127 array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7128 status, orderByComparator, true);
7129
7130 array[1] = mbMessage;
7131
7132 array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7133 status, orderByComparator, false);
7134
7135 return array;
7136 }
7137 catch (Exception e) {
7138 throw processException(e);
7139 }
7140 finally {
7141 closeSession(session);
7142 }
7143 }
7144
7145 protected MBMessage getByC_S_PrevAndNext(Session session,
7146 MBMessage mbMessage, long companyId, int status,
7147 OrderByComparator orderByComparator, boolean previous) {
7148 StringBundler query = null;
7149
7150 if (orderByComparator != null) {
7151 query = new StringBundler(6 +
7152 (orderByComparator.getOrderByFields().length * 6));
7153 }
7154 else {
7155 query = new StringBundler(3);
7156 }
7157
7158 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7159
7160 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7161
7162 query.append(_FINDER_COLUMN_C_S_STATUS_2);
7163
7164 if (orderByComparator != null) {
7165 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7166
7167 if (orderByConditionFields.length > 0) {
7168 query.append(WHERE_AND);
7169 }
7170
7171 for (int i = 0; i < orderByConditionFields.length; i++) {
7172 query.append(_ORDER_BY_ENTITY_ALIAS);
7173 query.append(orderByConditionFields[i]);
7174
7175 if ((i + 1) < orderByConditionFields.length) {
7176 if (orderByComparator.isAscending() ^ previous) {
7177 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7178 }
7179 else {
7180 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7181 }
7182 }
7183 else {
7184 if (orderByComparator.isAscending() ^ previous) {
7185 query.append(WHERE_GREATER_THAN);
7186 }
7187 else {
7188 query.append(WHERE_LESSER_THAN);
7189 }
7190 }
7191 }
7192
7193 query.append(ORDER_BY_CLAUSE);
7194
7195 String[] orderByFields = orderByComparator.getOrderByFields();
7196
7197 for (int i = 0; i < orderByFields.length; i++) {
7198 query.append(_ORDER_BY_ENTITY_ALIAS);
7199 query.append(orderByFields[i]);
7200
7201 if ((i + 1) < orderByFields.length) {
7202 if (orderByComparator.isAscending() ^ previous) {
7203 query.append(ORDER_BY_ASC_HAS_NEXT);
7204 }
7205 else {
7206 query.append(ORDER_BY_DESC_HAS_NEXT);
7207 }
7208 }
7209 else {
7210 if (orderByComparator.isAscending() ^ previous) {
7211 query.append(ORDER_BY_ASC);
7212 }
7213 else {
7214 query.append(ORDER_BY_DESC);
7215 }
7216 }
7217 }
7218 }
7219 else {
7220 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7221 }
7222
7223 String sql = query.toString();
7224
7225 Query q = session.createQuery(sql);
7226
7227 q.setFirstResult(0);
7228 q.setMaxResults(2);
7229
7230 QueryPos qPos = QueryPos.getInstance(q);
7231
7232 qPos.add(companyId);
7233
7234 qPos.add(status);
7235
7236 if (orderByComparator != null) {
7237 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7238
7239 for (Object value : values) {
7240 qPos.add(value);
7241 }
7242 }
7243
7244 List<MBMessage> list = q.list();
7245
7246 if (list.size() == 2) {
7247 return list.get(1);
7248 }
7249 else {
7250 return null;
7251 }
7252 }
7253
7254
7261 public void removeByC_S(long companyId, int status)
7262 throws SystemException {
7263 for (MBMessage mbMessage : findByC_S(companyId, status,
7264 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7265 remove(mbMessage);
7266 }
7267 }
7268
7269
7277 public int countByC_S(long companyId, int status) throws SystemException {
7278 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7279
7280 Object[] finderArgs = new Object[] { companyId, status };
7281
7282 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7283 this);
7284
7285 if (count == null) {
7286 StringBundler query = new StringBundler(3);
7287
7288 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7289
7290 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7291
7292 query.append(_FINDER_COLUMN_C_S_STATUS_2);
7293
7294 String sql = query.toString();
7295
7296 Session session = null;
7297
7298 try {
7299 session = openSession();
7300
7301 Query q = session.createQuery(sql);
7302
7303 QueryPos qPos = QueryPos.getInstance(q);
7304
7305 qPos.add(companyId);
7306
7307 qPos.add(status);
7308
7309 count = (Long)q.uniqueResult();
7310
7311 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7312 }
7313 catch (Exception e) {
7314 FinderCacheUtil.removeResult(finderPath, finderArgs);
7315
7316 throw processException(e);
7317 }
7318 finally {
7319 closeSession(session);
7320 }
7321 }
7322
7323 return count.intValue();
7324 }
7325
7326 private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7327 private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7328 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7329 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7330 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7331 new String[] {
7332 Long.class.getName(), Long.class.getName(),
7333
7334 Integer.class.getName(), Integer.class.getName(),
7335 OrderByComparator.class.getName()
7336 });
7337 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7338 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7339 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7340 new String[] { Long.class.getName(), Long.class.getName() },
7341 MBMessageModelImpl.USERID_COLUMN_BITMASK |
7342 MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7343 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7344 public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7345 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7346 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7347 new String[] { Long.class.getName(), Long.class.getName() });
7348 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7349 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7350 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7351 new String[] { Long.class.getName(), Long.class.getName() });
7352
7353
7361 public List<MBMessage> findByU_C(long userId, long classNameId)
7362 throws SystemException {
7363 return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7364 QueryUtil.ALL_POS, null);
7365 }
7366
7367
7381 public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7382 int end) throws SystemException {
7383 return findByU_C(userId, classNameId, start, end, null);
7384 }
7385
7386
7401 public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7402 int end, OrderByComparator orderByComparator) throws SystemException {
7403 boolean pagination = true;
7404 FinderPath finderPath = null;
7405 Object[] finderArgs = null;
7406
7407 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7408 (orderByComparator == null)) {
7409 pagination = false;
7410 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7411 finderArgs = new Object[] { userId, classNameId };
7412 }
7413 else {
7414 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7415 finderArgs = new Object[] {
7416 userId, classNameId,
7417
7418 start, end, orderByComparator
7419 };
7420 }
7421
7422 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7423 finderArgs, this);
7424
7425 if ((list != null) && !list.isEmpty()) {
7426 for (MBMessage mbMessage : list) {
7427 if ((userId != mbMessage.getUserId()) ||
7428 (classNameId != mbMessage.getClassNameId())) {
7429 list = null;
7430
7431 break;
7432 }
7433 }
7434 }
7435
7436 if (list == null) {
7437 StringBundler query = null;
7438
7439 if (orderByComparator != null) {
7440 query = new StringBundler(4 +
7441 (orderByComparator.getOrderByFields().length * 3));
7442 }
7443 else {
7444 query = new StringBundler(4);
7445 }
7446
7447 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7448
7449 query.append(_FINDER_COLUMN_U_C_USERID_2);
7450
7451 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7452
7453 if (orderByComparator != null) {
7454 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7455 orderByComparator);
7456 }
7457 else
7458 if (pagination) {
7459 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7460 }
7461
7462 String sql = query.toString();
7463
7464 Session session = null;
7465
7466 try {
7467 session = openSession();
7468
7469 Query q = session.createQuery(sql);
7470
7471 QueryPos qPos = QueryPos.getInstance(q);
7472
7473 qPos.add(userId);
7474
7475 qPos.add(classNameId);
7476
7477 if (!pagination) {
7478 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7479 start, end, false);
7480
7481 Collections.sort(list);
7482
7483 list = new UnmodifiableList<MBMessage>(list);
7484 }
7485 else {
7486 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7487 start, end);
7488 }
7489
7490 cacheResult(list);
7491
7492 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7493 }
7494 catch (Exception e) {
7495 FinderCacheUtil.removeResult(finderPath, finderArgs);
7496
7497 throw processException(e);
7498 }
7499 finally {
7500 closeSession(session);
7501 }
7502 }
7503
7504 return list;
7505 }
7506
7507
7517 public MBMessage findByU_C_First(long userId, long classNameId,
7518 OrderByComparator orderByComparator)
7519 throws NoSuchMessageException, SystemException {
7520 MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7521 orderByComparator);
7522
7523 if (mbMessage != null) {
7524 return mbMessage;
7525 }
7526
7527 StringBundler msg = new StringBundler(6);
7528
7529 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7530
7531 msg.append("userId=");
7532 msg.append(userId);
7533
7534 msg.append(", classNameId=");
7535 msg.append(classNameId);
7536
7537 msg.append(StringPool.CLOSE_CURLY_BRACE);
7538
7539 throw new NoSuchMessageException(msg.toString());
7540 }
7541
7542
7551 public MBMessage fetchByU_C_First(long userId, long classNameId,
7552 OrderByComparator orderByComparator) throws SystemException {
7553 List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7554 orderByComparator);
7555
7556 if (!list.isEmpty()) {
7557 return list.get(0);
7558 }
7559
7560 return null;
7561 }
7562
7563
7573 public MBMessage findByU_C_Last(long userId, long classNameId,
7574 OrderByComparator orderByComparator)
7575 throws NoSuchMessageException, SystemException {
7576 MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7577 orderByComparator);
7578
7579 if (mbMessage != null) {
7580 return mbMessage;
7581 }
7582
7583 StringBundler msg = new StringBundler(6);
7584
7585 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7586
7587 msg.append("userId=");
7588 msg.append(userId);
7589
7590 msg.append(", classNameId=");
7591 msg.append(classNameId);
7592
7593 msg.append(StringPool.CLOSE_CURLY_BRACE);
7594
7595 throw new NoSuchMessageException(msg.toString());
7596 }
7597
7598
7607 public MBMessage fetchByU_C_Last(long userId, long classNameId,
7608 OrderByComparator orderByComparator) throws SystemException {
7609 int count = countByU_C(userId, classNameId);
7610
7611 List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7612 orderByComparator);
7613
7614 if (!list.isEmpty()) {
7615 return list.get(0);
7616 }
7617
7618 return null;
7619 }
7620
7621
7632 public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7633 long classNameId, OrderByComparator orderByComparator)
7634 throws NoSuchMessageException, SystemException {
7635 MBMessage mbMessage = findByPrimaryKey(messageId);
7636
7637 Session session = null;
7638
7639 try {
7640 session = openSession();
7641
7642 MBMessage[] array = new MBMessageImpl[3];
7643
7644 array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7645 classNameId, orderByComparator, true);
7646
7647 array[1] = mbMessage;
7648
7649 array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7650 classNameId, orderByComparator, false);
7651
7652 return array;
7653 }
7654 catch (Exception e) {
7655 throw processException(e);
7656 }
7657 finally {
7658 closeSession(session);
7659 }
7660 }
7661
7662 protected MBMessage getByU_C_PrevAndNext(Session session,
7663 MBMessage mbMessage, long userId, long classNameId,
7664 OrderByComparator orderByComparator, boolean previous) {
7665 StringBundler query = null;
7666
7667 if (orderByComparator != null) {
7668 query = new StringBundler(6 +
7669 (orderByComparator.getOrderByFields().length * 6));
7670 }
7671 else {
7672 query = new StringBundler(3);
7673 }
7674
7675 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7676
7677 query.append(_FINDER_COLUMN_U_C_USERID_2);
7678
7679 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7680
7681 if (orderByComparator != null) {
7682 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7683
7684 if (orderByConditionFields.length > 0) {
7685 query.append(WHERE_AND);
7686 }
7687
7688 for (int i = 0; i < orderByConditionFields.length; i++) {
7689 query.append(_ORDER_BY_ENTITY_ALIAS);
7690 query.append(orderByConditionFields[i]);
7691
7692 if ((i + 1) < orderByConditionFields.length) {
7693 if (orderByComparator.isAscending() ^ previous) {
7694 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7695 }
7696 else {
7697 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7698 }
7699 }
7700 else {
7701 if (orderByComparator.isAscending() ^ previous) {
7702 query.append(WHERE_GREATER_THAN);
7703 }
7704 else {
7705 query.append(WHERE_LESSER_THAN);
7706 }
7707 }
7708 }
7709
7710 query.append(ORDER_BY_CLAUSE);
7711
7712 String[] orderByFields = orderByComparator.getOrderByFields();
7713
7714 for (int i = 0; i < orderByFields.length; i++) {
7715 query.append(_ORDER_BY_ENTITY_ALIAS);
7716 query.append(orderByFields[i]);
7717
7718 if ((i + 1) < orderByFields.length) {
7719 if (orderByComparator.isAscending() ^ previous) {
7720 query.append(ORDER_BY_ASC_HAS_NEXT);
7721 }
7722 else {
7723 query.append(ORDER_BY_DESC_HAS_NEXT);
7724 }
7725 }
7726 else {
7727 if (orderByComparator.isAscending() ^ previous) {
7728 query.append(ORDER_BY_ASC);
7729 }
7730 else {
7731 query.append(ORDER_BY_DESC);
7732 }
7733 }
7734 }
7735 }
7736 else {
7737 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7738 }
7739
7740 String sql = query.toString();
7741
7742 Query q = session.createQuery(sql);
7743
7744 q.setFirstResult(0);
7745 q.setMaxResults(2);
7746
7747 QueryPos qPos = QueryPos.getInstance(q);
7748
7749 qPos.add(userId);
7750
7751 qPos.add(classNameId);
7752
7753 if (orderByComparator != null) {
7754 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7755
7756 for (Object value : values) {
7757 qPos.add(value);
7758 }
7759 }
7760
7761 List<MBMessage> list = q.list();
7762
7763 if (list.size() == 2) {
7764 return list.get(1);
7765 }
7766 else {
7767 return null;
7768 }
7769 }
7770
7771
7783 public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7784 throws SystemException {
7785 return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7786 QueryUtil.ALL_POS, null);
7787 }
7788
7789
7803 public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7804 int start, int end) throws SystemException {
7805 return findByU_C(userId, classNameIds, start, end, null);
7806 }
7807
7808
7823 public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7824 int start, int end, OrderByComparator orderByComparator)
7825 throws SystemException {
7826 if ((classNameIds != null) && (classNameIds.length == 1)) {
7827 return findByU_C(userId, classNameIds[0], start, end,
7828 orderByComparator);
7829 }
7830
7831 boolean pagination = true;
7832 Object[] finderArgs = null;
7833
7834 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7835 (orderByComparator == null)) {
7836 pagination = false;
7837 finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7838 }
7839 else {
7840 finderArgs = new Object[] {
7841 userId, StringUtil.merge(classNameIds),
7842
7843 start, end, orderByComparator
7844 };
7845 }
7846
7847 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7848 finderArgs, this);
7849
7850 if ((list != null) && !list.isEmpty()) {
7851 for (MBMessage mbMessage : list) {
7852 if ((userId != mbMessage.getUserId()) ||
7853 !ArrayUtil.contains(classNameIds,
7854 mbMessage.getClassNameId())) {
7855 list = null;
7856
7857 break;
7858 }
7859 }
7860 }
7861
7862 if (list == null) {
7863 StringBundler query = new StringBundler();
7864
7865 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7866
7867 boolean conjunctionable = false;
7868
7869 if (conjunctionable) {
7870 query.append(WHERE_AND);
7871 }
7872
7873 query.append(_FINDER_COLUMN_U_C_USERID_5);
7874
7875 conjunctionable = true;
7876
7877 if ((classNameIds == null) || (classNameIds.length > 0)) {
7878 if (conjunctionable) {
7879 query.append(WHERE_AND);
7880 }
7881
7882 query.append(StringPool.OPEN_PARENTHESIS);
7883
7884 for (int i = 0; i < classNameIds.length; i++) {
7885 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7886
7887 if ((i + 1) < classNameIds.length) {
7888 query.append(WHERE_OR);
7889 }
7890 }
7891
7892 query.append(StringPool.CLOSE_PARENTHESIS);
7893
7894 conjunctionable = true;
7895 }
7896
7897 if (orderByComparator != null) {
7898 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7899 orderByComparator);
7900 }
7901 else
7902 if (pagination) {
7903 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7904 }
7905
7906 String sql = query.toString();
7907
7908 Session session = null;
7909
7910 try {
7911 session = openSession();
7912
7913 Query q = session.createQuery(sql);
7914
7915 QueryPos qPos = QueryPos.getInstance(q);
7916
7917 qPos.add(userId);
7918
7919 if (classNameIds != null) {
7920 qPos.add(classNameIds);
7921 }
7922
7923 if (!pagination) {
7924 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7925 start, end, false);
7926
7927 Collections.sort(list);
7928
7929 list = new UnmodifiableList<MBMessage>(list);
7930 }
7931 else {
7932 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7933 start, end);
7934 }
7935
7936 cacheResult(list);
7937
7938 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7939 finderArgs, list);
7940 }
7941 catch (Exception e) {
7942 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7943 finderArgs);
7944
7945 throw processException(e);
7946 }
7947 finally {
7948 closeSession(session);
7949 }
7950 }
7951
7952 return list;
7953 }
7954
7955
7962 public void removeByU_C(long userId, long classNameId)
7963 throws SystemException {
7964 for (MBMessage mbMessage : findByU_C(userId, classNameId,
7965 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7966 remove(mbMessage);
7967 }
7968 }
7969
7970
7978 public int countByU_C(long userId, long classNameId)
7979 throws SystemException {
7980 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
7981
7982 Object[] finderArgs = new Object[] { userId, classNameId };
7983
7984 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7985 this);
7986
7987 if (count == null) {
7988 StringBundler query = new StringBundler(3);
7989
7990 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7991
7992 query.append(_FINDER_COLUMN_U_C_USERID_2);
7993
7994 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7995
7996 String sql = query.toString();
7997
7998 Session session = null;
7999
8000 try {
8001 session = openSession();
8002
8003 Query q = session.createQuery(sql);
8004
8005 QueryPos qPos = QueryPos.getInstance(q);
8006
8007 qPos.add(userId);
8008
8009 qPos.add(classNameId);
8010
8011 count = (Long)q.uniqueResult();
8012
8013 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8014 }
8015 catch (Exception e) {
8016 FinderCacheUtil.removeResult(finderPath, finderArgs);
8017
8018 throw processException(e);
8019 }
8020 finally {
8021 closeSession(session);
8022 }
8023 }
8024
8025 return count.intValue();
8026 }
8027
8028
8036 public int countByU_C(long userId, long[] classNameIds)
8037 throws SystemException {
8038 Object[] finderArgs = new Object[] {
8039 userId, StringUtil.merge(classNameIds)
8040 };
8041
8042 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8043 finderArgs, this);
8044
8045 if (count == null) {
8046 StringBundler query = new StringBundler();
8047
8048 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8049
8050 boolean conjunctionable = false;
8051
8052 if (conjunctionable) {
8053 query.append(WHERE_AND);
8054 }
8055
8056 query.append(_FINDER_COLUMN_U_C_USERID_5);
8057
8058 conjunctionable = true;
8059
8060 if ((classNameIds == null) || (classNameIds.length > 0)) {
8061 if (conjunctionable) {
8062 query.append(WHERE_AND);
8063 }
8064
8065 query.append(StringPool.OPEN_PARENTHESIS);
8066
8067 for (int i = 0; i < classNameIds.length; i++) {
8068 query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8069
8070 if ((i + 1) < classNameIds.length) {
8071 query.append(WHERE_OR);
8072 }
8073 }
8074
8075 query.append(StringPool.CLOSE_PARENTHESIS);
8076
8077 conjunctionable = true;
8078 }
8079
8080 String sql = query.toString();
8081
8082 Session session = null;
8083
8084 try {
8085 session = openSession();
8086
8087 Query q = session.createQuery(sql);
8088
8089 QueryPos qPos = QueryPos.getInstance(q);
8090
8091 qPos.add(userId);
8092
8093 if (classNameIds != null) {
8094 qPos.add(classNameIds);
8095 }
8096
8097 count = (Long)q.uniqueResult();
8098
8099 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8100 finderArgs, count);
8101 }
8102 catch (Exception e) {
8103 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8104 finderArgs);
8105
8106 throw processException(e);
8107 }
8108 finally {
8109 closeSession(session);
8110 }
8111 }
8112
8113 return count.intValue();
8114 }
8115
8116 private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8117 private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
8118 _removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
8119 private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8120 private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
8121 _removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
8122 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8123 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8124 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8125 new String[] {
8126 Long.class.getName(), Long.class.getName(),
8127
8128 Integer.class.getName(), Integer.class.getName(),
8129 OrderByComparator.class.getName()
8130 });
8131 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8132 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8133 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8134 new String[] { Long.class.getName(), Long.class.getName() },
8135 MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8136 MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8137 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8138 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8139 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8140 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8141 new String[] { Long.class.getName(), Long.class.getName() });
8142
8143
8151 public List<MBMessage> findByC_C(long classNameId, long classPK)
8152 throws SystemException {
8153 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8154 QueryUtil.ALL_POS, null);
8155 }
8156
8157
8171 public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8172 int end) throws SystemException {
8173 return findByC_C(classNameId, classPK, start, end, null);
8174 }
8175
8176
8191 public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8192 int end, OrderByComparator orderByComparator) throws SystemException {
8193 boolean pagination = true;
8194 FinderPath finderPath = null;
8195 Object[] finderArgs = null;
8196
8197 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8198 (orderByComparator == null)) {
8199 pagination = false;
8200 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8201 finderArgs = new Object[] { classNameId, classPK };
8202 }
8203 else {
8204 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8205 finderArgs = new Object[] {
8206 classNameId, classPK,
8207
8208 start, end, orderByComparator
8209 };
8210 }
8211
8212 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8213 finderArgs, this);
8214
8215 if ((list != null) && !list.isEmpty()) {
8216 for (MBMessage mbMessage : list) {
8217 if ((classNameId != mbMessage.getClassNameId()) ||
8218 (classPK != mbMessage.getClassPK())) {
8219 list = null;
8220
8221 break;
8222 }
8223 }
8224 }
8225
8226 if (list == null) {
8227 StringBundler query = null;
8228
8229 if (orderByComparator != null) {
8230 query = new StringBundler(4 +
8231 (orderByComparator.getOrderByFields().length * 3));
8232 }
8233 else {
8234 query = new StringBundler(4);
8235 }
8236
8237 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8238
8239 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8240
8241 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8242
8243 if (orderByComparator != null) {
8244 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8245 orderByComparator);
8246 }
8247 else
8248 if (pagination) {
8249 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8250 }
8251
8252 String sql = query.toString();
8253
8254 Session session = null;
8255
8256 try {
8257 session = openSession();
8258
8259 Query q = session.createQuery(sql);
8260
8261 QueryPos qPos = QueryPos.getInstance(q);
8262
8263 qPos.add(classNameId);
8264
8265 qPos.add(classPK);
8266
8267 if (!pagination) {
8268 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8269 start, end, false);
8270
8271 Collections.sort(list);
8272
8273 list = new UnmodifiableList<MBMessage>(list);
8274 }
8275 else {
8276 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8277 start, end);
8278 }
8279
8280 cacheResult(list);
8281
8282 FinderCacheUtil.putResult(finderPath, finderArgs, list);
8283 }
8284 catch (Exception e) {
8285 FinderCacheUtil.removeResult(finderPath, finderArgs);
8286
8287 throw processException(e);
8288 }
8289 finally {
8290 closeSession(session);
8291 }
8292 }
8293
8294 return list;
8295 }
8296
8297
8307 public MBMessage findByC_C_First(long classNameId, long classPK,
8308 OrderByComparator orderByComparator)
8309 throws NoSuchMessageException, SystemException {
8310 MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8311 orderByComparator);
8312
8313 if (mbMessage != null) {
8314 return mbMessage;
8315 }
8316
8317 StringBundler msg = new StringBundler(6);
8318
8319 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8320
8321 msg.append("classNameId=");
8322 msg.append(classNameId);
8323
8324 msg.append(", classPK=");
8325 msg.append(classPK);
8326
8327 msg.append(StringPool.CLOSE_CURLY_BRACE);
8328
8329 throw new NoSuchMessageException(msg.toString());
8330 }
8331
8332
8341 public MBMessage fetchByC_C_First(long classNameId, long classPK,
8342 OrderByComparator orderByComparator) throws SystemException {
8343 List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8344 orderByComparator);
8345
8346 if (!list.isEmpty()) {
8347 return list.get(0);
8348 }
8349
8350 return null;
8351 }
8352
8353
8363 public MBMessage findByC_C_Last(long classNameId, long classPK,
8364 OrderByComparator orderByComparator)
8365 throws NoSuchMessageException, SystemException {
8366 MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8367 orderByComparator);
8368
8369 if (mbMessage != null) {
8370 return mbMessage;
8371 }
8372
8373 StringBundler msg = new StringBundler(6);
8374
8375 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8376
8377 msg.append("classNameId=");
8378 msg.append(classNameId);
8379
8380 msg.append(", classPK=");
8381 msg.append(classPK);
8382
8383 msg.append(StringPool.CLOSE_CURLY_BRACE);
8384
8385 throw new NoSuchMessageException(msg.toString());
8386 }
8387
8388
8397 public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8398 OrderByComparator orderByComparator) throws SystemException {
8399 int count = countByC_C(classNameId, classPK);
8400
8401 List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8402 count, orderByComparator);
8403
8404 if (!list.isEmpty()) {
8405 return list.get(0);
8406 }
8407
8408 return null;
8409 }
8410
8411
8422 public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8423 long classPK, OrderByComparator orderByComparator)
8424 throws NoSuchMessageException, SystemException {
8425 MBMessage mbMessage = findByPrimaryKey(messageId);
8426
8427 Session session = null;
8428
8429 try {
8430 session = openSession();
8431
8432 MBMessage[] array = new MBMessageImpl[3];
8433
8434 array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8435 classPK, orderByComparator, true);
8436
8437 array[1] = mbMessage;
8438
8439 array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8440 classPK, orderByComparator, false);
8441
8442 return array;
8443 }
8444 catch (Exception e) {
8445 throw processException(e);
8446 }
8447 finally {
8448 closeSession(session);
8449 }
8450 }
8451
8452 protected MBMessage getByC_C_PrevAndNext(Session session,
8453 MBMessage mbMessage, long classNameId, long classPK,
8454 OrderByComparator orderByComparator, boolean previous) {
8455 StringBundler query = null;
8456
8457 if (orderByComparator != null) {
8458 query = new StringBundler(6 +
8459 (orderByComparator.getOrderByFields().length * 6));
8460 }
8461 else {
8462 query = new StringBundler(3);
8463 }
8464
8465 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8466
8467 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8468
8469 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8470
8471 if (orderByComparator != null) {
8472 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8473
8474 if (orderByConditionFields.length > 0) {
8475 query.append(WHERE_AND);
8476 }
8477
8478 for (int i = 0; i < orderByConditionFields.length; i++) {
8479 query.append(_ORDER_BY_ENTITY_ALIAS);
8480 query.append(orderByConditionFields[i]);
8481
8482 if ((i + 1) < orderByConditionFields.length) {
8483 if (orderByComparator.isAscending() ^ previous) {
8484 query.append(WHERE_GREATER_THAN_HAS_NEXT);
8485 }
8486 else {
8487 query.append(WHERE_LESSER_THAN_HAS_NEXT);
8488 }
8489 }
8490 else {
8491 if (orderByComparator.isAscending() ^ previous) {
8492 query.append(WHERE_GREATER_THAN);
8493 }
8494 else {
8495 query.append(WHERE_LESSER_THAN);
8496 }
8497 }
8498 }
8499
8500 query.append(ORDER_BY_CLAUSE);
8501
8502 String[] orderByFields = orderByComparator.getOrderByFields();
8503
8504 for (int i = 0; i < orderByFields.length; i++) {
8505 query.append(_ORDER_BY_ENTITY_ALIAS);
8506 query.append(orderByFields[i]);
8507
8508 if ((i + 1) < orderByFields.length) {
8509 if (orderByComparator.isAscending() ^ previous) {
8510 query.append(ORDER_BY_ASC_HAS_NEXT);
8511 }
8512 else {
8513 query.append(ORDER_BY_DESC_HAS_NEXT);
8514 }
8515 }
8516 else {
8517 if (orderByComparator.isAscending() ^ previous) {
8518 query.append(ORDER_BY_ASC);
8519 }
8520 else {
8521 query.append(ORDER_BY_DESC);
8522 }
8523 }
8524 }
8525 }
8526 else {
8527 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8528 }
8529
8530 String sql = query.toString();
8531
8532 Query q = session.createQuery(sql);
8533
8534 q.setFirstResult(0);
8535 q.setMaxResults(2);
8536
8537 QueryPos qPos = QueryPos.getInstance(q);
8538
8539 qPos.add(classNameId);
8540
8541 qPos.add(classPK);
8542
8543 if (orderByComparator != null) {
8544 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8545
8546 for (Object value : values) {
8547 qPos.add(value);
8548 }
8549 }
8550
8551 List<MBMessage> list = q.list();
8552
8553 if (list.size() == 2) {
8554 return list.get(1);
8555 }
8556 else {
8557 return null;
8558 }
8559 }
8560
8561
8568 public void removeByC_C(long classNameId, long classPK)
8569 throws SystemException {
8570 for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8571 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8572 remove(mbMessage);
8573 }
8574 }
8575
8576
8584 public int countByC_C(long classNameId, long classPK)
8585 throws SystemException {
8586 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8587
8588 Object[] finderArgs = new Object[] { classNameId, classPK };
8589
8590 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8591 this);
8592
8593 if (count == null) {
8594 StringBundler query = new StringBundler(3);
8595
8596 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8597
8598 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8599
8600 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8601
8602 String sql = query.toString();
8603
8604 Session session = null;
8605
8606 try {
8607 session = openSession();
8608
8609 Query q = session.createQuery(sql);
8610
8611 QueryPos qPos = QueryPos.getInstance(q);
8612
8613 qPos.add(classNameId);
8614
8615 qPos.add(classPK);
8616
8617 count = (Long)q.uniqueResult();
8618
8619 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8620 }
8621 catch (Exception e) {
8622 FinderCacheUtil.removeResult(finderPath, finderArgs);
8623
8624 throw processException(e);
8625 }
8626 finally {
8627 closeSession(session);
8628 }
8629 }
8630
8631 return count.intValue();
8632 }
8633
8634 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8635 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8636 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8637 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8638 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8639 new String[] {
8640 Long.class.getName(), Long.class.getName(),
8641
8642 Integer.class.getName(), Integer.class.getName(),
8643 OrderByComparator.class.getName()
8644 });
8645 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8646 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8647 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8648 new String[] { Long.class.getName(), Long.class.getName() },
8649 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8650 MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8651 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8652 public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8653 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8654 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8655 new String[] { Long.class.getName(), Long.class.getName() });
8656
8657
8665 public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8666 throws SystemException {
8667 return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8668 QueryUtil.ALL_POS, null);
8669 }
8670
8671
8685 public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8686 int start, int end) throws SystemException {
8687 return findByT_P(threadId, parentMessageId, start, end, null);
8688 }
8689
8690
8705 public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8706 int start, int end, OrderByComparator orderByComparator)
8707 throws SystemException {
8708 boolean pagination = true;
8709 FinderPath finderPath = null;
8710 Object[] finderArgs = null;
8711
8712 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8713 (orderByComparator == null)) {
8714 pagination = false;
8715 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8716 finderArgs = new Object[] { threadId, parentMessageId };
8717 }
8718 else {
8719 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8720 finderArgs = new Object[] {
8721 threadId, parentMessageId,
8722
8723 start, end, orderByComparator
8724 };
8725 }
8726
8727 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8728 finderArgs, this);
8729
8730 if ((list != null) && !list.isEmpty()) {
8731 for (MBMessage mbMessage : list) {
8732 if ((threadId != mbMessage.getThreadId()) ||
8733 (parentMessageId != mbMessage.getParentMessageId())) {
8734 list = null;
8735
8736 break;
8737 }
8738 }
8739 }
8740
8741 if (list == null) {
8742 StringBundler query = null;
8743
8744 if (orderByComparator != null) {
8745 query = new StringBundler(4 +
8746 (orderByComparator.getOrderByFields().length * 3));
8747 }
8748 else {
8749 query = new StringBundler(4);
8750 }
8751
8752 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8753
8754 query.append(_FINDER_COLUMN_T_P_THREADID_2);
8755
8756 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8757
8758 if (orderByComparator != null) {
8759 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8760 orderByComparator);
8761 }
8762 else
8763 if (pagination) {
8764 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8765 }
8766
8767 String sql = query.toString();
8768
8769 Session session = null;
8770
8771 try {
8772 session = openSession();
8773
8774 Query q = session.createQuery(sql);
8775
8776 QueryPos qPos = QueryPos.getInstance(q);
8777
8778 qPos.add(threadId);
8779
8780 qPos.add(parentMessageId);
8781
8782 if (!pagination) {
8783 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8784 start, end, false);
8785
8786 Collections.sort(list);
8787
8788 list = new UnmodifiableList<MBMessage>(list);
8789 }
8790 else {
8791 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8792 start, end);
8793 }
8794
8795 cacheResult(list);
8796
8797 FinderCacheUtil.putResult(finderPath, finderArgs, list);
8798 }
8799 catch (Exception e) {
8800 FinderCacheUtil.removeResult(finderPath, finderArgs);
8801
8802 throw processException(e);
8803 }
8804 finally {
8805 closeSession(session);
8806 }
8807 }
8808
8809 return list;
8810 }
8811
8812
8822 public MBMessage findByT_P_First(long threadId, long parentMessageId,
8823 OrderByComparator orderByComparator)
8824 throws NoSuchMessageException, SystemException {
8825 MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8826 orderByComparator);
8827
8828 if (mbMessage != null) {
8829 return mbMessage;
8830 }
8831
8832 StringBundler msg = new StringBundler(6);
8833
8834 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8835
8836 msg.append("threadId=");
8837 msg.append(threadId);
8838
8839 msg.append(", parentMessageId=");
8840 msg.append(parentMessageId);
8841
8842 msg.append(StringPool.CLOSE_CURLY_BRACE);
8843
8844 throw new NoSuchMessageException(msg.toString());
8845 }
8846
8847
8856 public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8857 OrderByComparator orderByComparator) throws SystemException {
8858 List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8859 orderByComparator);
8860
8861 if (!list.isEmpty()) {
8862 return list.get(0);
8863 }
8864
8865 return null;
8866 }
8867
8868
8878 public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8879 OrderByComparator orderByComparator)
8880 throws NoSuchMessageException, SystemException {
8881 MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8882 orderByComparator);
8883
8884 if (mbMessage != null) {
8885 return mbMessage;
8886 }
8887
8888 StringBundler msg = new StringBundler(6);
8889
8890 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8891
8892 msg.append("threadId=");
8893 msg.append(threadId);
8894
8895 msg.append(", parentMessageId=");
8896 msg.append(parentMessageId);
8897
8898 msg.append(StringPool.CLOSE_CURLY_BRACE);
8899
8900 throw new NoSuchMessageException(msg.toString());
8901 }
8902
8903
8912 public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8913 OrderByComparator orderByComparator) throws SystemException {
8914 int count = countByT_P(threadId, parentMessageId);
8915
8916 List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8917 count, orderByComparator);
8918
8919 if (!list.isEmpty()) {
8920 return list.get(0);
8921 }
8922
8923 return null;
8924 }
8925
8926
8937 public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8938 long parentMessageId, OrderByComparator orderByComparator)
8939 throws NoSuchMessageException, SystemException {
8940 MBMessage mbMessage = findByPrimaryKey(messageId);
8941
8942 Session session = null;
8943
8944 try {
8945 session = openSession();
8946
8947 MBMessage[] array = new MBMessageImpl[3];
8948
8949 array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8950 parentMessageId, orderByComparator, true);
8951
8952 array[1] = mbMessage;
8953
8954 array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8955 parentMessageId, orderByComparator, false);
8956
8957 return array;
8958 }
8959 catch (Exception e) {
8960 throw processException(e);
8961 }
8962 finally {
8963 closeSession(session);
8964 }
8965 }
8966
8967 protected MBMessage getByT_P_PrevAndNext(Session session,
8968 MBMessage mbMessage, long threadId, long parentMessageId,
8969 OrderByComparator orderByComparator, boolean previous) {
8970 StringBundler query = null;
8971
8972 if (orderByComparator != null) {
8973 query = new StringBundler(6 +
8974 (orderByComparator.getOrderByFields().length * 6));
8975 }
8976 else {
8977 query = new StringBundler(3);
8978 }
8979
8980 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8981
8982 query.append(_FINDER_COLUMN_T_P_THREADID_2);
8983
8984 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8985
8986 if (orderByComparator != null) {
8987 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8988
8989 if (orderByConditionFields.length > 0) {
8990 query.append(WHERE_AND);
8991 }
8992
8993 for (int i = 0; i < orderByConditionFields.length; i++) {
8994 query.append(_ORDER_BY_ENTITY_ALIAS);
8995 query.append(orderByConditionFields[i]);
8996
8997 if ((i + 1) < orderByConditionFields.length) {
8998 if (orderByComparator.isAscending() ^ previous) {
8999 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9000 }
9001 else {
9002 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9003 }
9004 }
9005 else {
9006 if (orderByComparator.isAscending() ^ previous) {
9007 query.append(WHERE_GREATER_THAN);
9008 }
9009 else {
9010 query.append(WHERE_LESSER_THAN);
9011 }
9012 }
9013 }
9014
9015 query.append(ORDER_BY_CLAUSE);
9016
9017 String[] orderByFields = orderByComparator.getOrderByFields();
9018
9019 for (int i = 0; i < orderByFields.length; i++) {
9020 query.append(_ORDER_BY_ENTITY_ALIAS);
9021 query.append(orderByFields[i]);
9022
9023 if ((i + 1) < orderByFields.length) {
9024 if (orderByComparator.isAscending() ^ previous) {
9025 query.append(ORDER_BY_ASC_HAS_NEXT);
9026 }
9027 else {
9028 query.append(ORDER_BY_DESC_HAS_NEXT);
9029 }
9030 }
9031 else {
9032 if (orderByComparator.isAscending() ^ previous) {
9033 query.append(ORDER_BY_ASC);
9034 }
9035 else {
9036 query.append(ORDER_BY_DESC);
9037 }
9038 }
9039 }
9040 }
9041 else {
9042 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9043 }
9044
9045 String sql = query.toString();
9046
9047 Query q = session.createQuery(sql);
9048
9049 q.setFirstResult(0);
9050 q.setMaxResults(2);
9051
9052 QueryPos qPos = QueryPos.getInstance(q);
9053
9054 qPos.add(threadId);
9055
9056 qPos.add(parentMessageId);
9057
9058 if (orderByComparator != null) {
9059 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9060
9061 for (Object value : values) {
9062 qPos.add(value);
9063 }
9064 }
9065
9066 List<MBMessage> list = q.list();
9067
9068 if (list.size() == 2) {
9069 return list.get(1);
9070 }
9071 else {
9072 return null;
9073 }
9074 }
9075
9076
9083 public void removeByT_P(long threadId, long parentMessageId)
9084 throws SystemException {
9085 for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9086 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9087 remove(mbMessage);
9088 }
9089 }
9090
9091
9099 public int countByT_P(long threadId, long parentMessageId)
9100 throws SystemException {
9101 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9102
9103 Object[] finderArgs = new Object[] { threadId, parentMessageId };
9104
9105 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9106 this);
9107
9108 if (count == null) {
9109 StringBundler query = new StringBundler(3);
9110
9111 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9112
9113 query.append(_FINDER_COLUMN_T_P_THREADID_2);
9114
9115 query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9116
9117 String sql = query.toString();
9118
9119 Session session = null;
9120
9121 try {
9122 session = openSession();
9123
9124 Query q = session.createQuery(sql);
9125
9126 QueryPos qPos = QueryPos.getInstance(q);
9127
9128 qPos.add(threadId);
9129
9130 qPos.add(parentMessageId);
9131
9132 count = (Long)q.uniqueResult();
9133
9134 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9135 }
9136 catch (Exception e) {
9137 FinderCacheUtil.removeResult(finderPath, finderArgs);
9138
9139 throw processException(e);
9140 }
9141 finally {
9142 closeSession(session);
9143 }
9144 }
9145
9146 return count.intValue();
9147 }
9148
9149 private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9150 private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9151 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9152 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9153 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9154 new String[] {
9155 Long.class.getName(), Boolean.class.getName(),
9156
9157 Integer.class.getName(), Integer.class.getName(),
9158 OrderByComparator.class.getName()
9159 });
9160 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9161 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9162 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9163 new String[] { Long.class.getName(), Boolean.class.getName() },
9164 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9165 MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9166 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9167 public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9168 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9169 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9170 new String[] { Long.class.getName(), Boolean.class.getName() });
9171
9172
9180 public List<MBMessage> findByT_A(long threadId, boolean answer)
9181 throws SystemException {
9182 return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9183 QueryUtil.ALL_POS, null);
9184 }
9185
9186
9200 public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9201 int end) throws SystemException {
9202 return findByT_A(threadId, answer, start, end, null);
9203 }
9204
9205
9220 public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9221 int end, OrderByComparator orderByComparator) throws SystemException {
9222 boolean pagination = true;
9223 FinderPath finderPath = null;
9224 Object[] finderArgs = null;
9225
9226 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9227 (orderByComparator == null)) {
9228 pagination = false;
9229 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9230 finderArgs = new Object[] { threadId, answer };
9231 }
9232 else {
9233 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9234 finderArgs = new Object[] {
9235 threadId, answer,
9236
9237 start, end, orderByComparator
9238 };
9239 }
9240
9241 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9242 finderArgs, this);
9243
9244 if ((list != null) && !list.isEmpty()) {
9245 for (MBMessage mbMessage : list) {
9246 if ((threadId != mbMessage.getThreadId()) ||
9247 (answer != mbMessage.getAnswer())) {
9248 list = null;
9249
9250 break;
9251 }
9252 }
9253 }
9254
9255 if (list == null) {
9256 StringBundler query = null;
9257
9258 if (orderByComparator != null) {
9259 query = new StringBundler(4 +
9260 (orderByComparator.getOrderByFields().length * 3));
9261 }
9262 else {
9263 query = new StringBundler(4);
9264 }
9265
9266 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9267
9268 query.append(_FINDER_COLUMN_T_A_THREADID_2);
9269
9270 query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9271
9272 if (orderByComparator != null) {
9273 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9274 orderByComparator);
9275 }
9276 else
9277 if (pagination) {
9278 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9279 }
9280
9281 String sql = query.toString();
9282
9283 Session session = null;
9284
9285 try {
9286 session = openSession();
9287
9288 Query q = session.createQuery(sql);
9289
9290 QueryPos qPos = QueryPos.getInstance(q);
9291
9292 qPos.add(threadId);
9293
9294 qPos.add(answer);
9295
9296 if (!pagination) {
9297 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9298 start, end, false);
9299
9300 Collections.sort(list);
9301
9302 list = new UnmodifiableList<MBMessage>(list);
9303 }
9304 else {
9305 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9306 start, end);
9307 }
9308
9309 cacheResult(list);
9310
9311 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9312 }
9313 catch (Exception e) {
9314 FinderCacheUtil.removeResult(finderPath, finderArgs);
9315
9316 throw processException(e);
9317 }
9318 finally {
9319 closeSession(session);
9320 }
9321 }
9322
9323 return list;
9324 }
9325
9326
9336 public MBMessage findByT_A_First(long threadId, boolean answer,
9337 OrderByComparator orderByComparator)
9338 throws NoSuchMessageException, SystemException {
9339 MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9340 orderByComparator);
9341
9342 if (mbMessage != null) {
9343 return mbMessage;
9344 }
9345
9346 StringBundler msg = new StringBundler(6);
9347
9348 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9349
9350 msg.append("threadId=");
9351 msg.append(threadId);
9352
9353 msg.append(", answer=");
9354 msg.append(answer);
9355
9356 msg.append(StringPool.CLOSE_CURLY_BRACE);
9357
9358 throw new NoSuchMessageException(msg.toString());
9359 }
9360
9361
9370 public MBMessage fetchByT_A_First(long threadId, boolean answer,
9371 OrderByComparator orderByComparator) throws SystemException {
9372 List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9373 orderByComparator);
9374
9375 if (!list.isEmpty()) {
9376 return list.get(0);
9377 }
9378
9379 return null;
9380 }
9381
9382
9392 public MBMessage findByT_A_Last(long threadId, boolean answer,
9393 OrderByComparator orderByComparator)
9394 throws NoSuchMessageException, SystemException {
9395 MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9396 orderByComparator);
9397
9398 if (mbMessage != null) {
9399 return mbMessage;
9400 }
9401
9402 StringBundler msg = new StringBundler(6);
9403
9404 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9405
9406 msg.append("threadId=");
9407 msg.append(threadId);
9408
9409 msg.append(", answer=");
9410 msg.append(answer);
9411
9412 msg.append(StringPool.CLOSE_CURLY_BRACE);
9413
9414 throw new NoSuchMessageException(msg.toString());
9415 }
9416
9417
9426 public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9427 OrderByComparator orderByComparator) throws SystemException {
9428 int count = countByT_A(threadId, answer);
9429
9430 List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9431 orderByComparator);
9432
9433 if (!list.isEmpty()) {
9434 return list.get(0);
9435 }
9436
9437 return null;
9438 }
9439
9440
9451 public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9452 boolean answer, OrderByComparator orderByComparator)
9453 throws NoSuchMessageException, SystemException {
9454 MBMessage mbMessage = findByPrimaryKey(messageId);
9455
9456 Session session = null;
9457
9458 try {
9459 session = openSession();
9460
9461 MBMessage[] array = new MBMessageImpl[3];
9462
9463 array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9464 answer, orderByComparator, true);
9465
9466 array[1] = mbMessage;
9467
9468 array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9469 answer, orderByComparator, false);
9470
9471 return array;
9472 }
9473 catch (Exception e) {
9474 throw processException(e);
9475 }
9476 finally {
9477 closeSession(session);
9478 }
9479 }
9480
9481 protected MBMessage getByT_A_PrevAndNext(Session session,
9482 MBMessage mbMessage, long threadId, boolean answer,
9483 OrderByComparator orderByComparator, boolean previous) {
9484 StringBundler query = null;
9485
9486 if (orderByComparator != null) {
9487 query = new StringBundler(6 +
9488 (orderByComparator.getOrderByFields().length * 6));
9489 }
9490 else {
9491 query = new StringBundler(3);
9492 }
9493
9494 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9495
9496 query.append(_FINDER_COLUMN_T_A_THREADID_2);
9497
9498 query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9499
9500 if (orderByComparator != null) {
9501 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9502
9503 if (orderByConditionFields.length > 0) {
9504 query.append(WHERE_AND);
9505 }
9506
9507 for (int i = 0; i < orderByConditionFields.length; i++) {
9508 query.append(_ORDER_BY_ENTITY_ALIAS);
9509 query.append(orderByConditionFields[i]);
9510
9511 if ((i + 1) < orderByConditionFields.length) {
9512 if (orderByComparator.isAscending() ^ previous) {
9513 query.append(WHERE_GREATER_THAN_HAS_NEXT);
9514 }
9515 else {
9516 query.append(WHERE_LESSER_THAN_HAS_NEXT);
9517 }
9518 }
9519 else {
9520 if (orderByComparator.isAscending() ^ previous) {
9521 query.append(WHERE_GREATER_THAN);
9522 }
9523 else {
9524 query.append(WHERE_LESSER_THAN);
9525 }
9526 }
9527 }
9528
9529 query.append(ORDER_BY_CLAUSE);
9530
9531 String[] orderByFields = orderByComparator.getOrderByFields();
9532
9533 for (int i = 0; i < orderByFields.length; i++) {
9534 query.append(_ORDER_BY_ENTITY_ALIAS);
9535 query.append(orderByFields[i]);
9536
9537 if ((i + 1) < orderByFields.length) {
9538 if (orderByComparator.isAscending() ^ previous) {
9539 query.append(ORDER_BY_ASC_HAS_NEXT);
9540 }
9541 else {
9542 query.append(ORDER_BY_DESC_HAS_NEXT);
9543 }
9544 }
9545 else {
9546 if (orderByComparator.isAscending() ^ previous) {
9547 query.append(ORDER_BY_ASC);
9548 }
9549 else {
9550 query.append(ORDER_BY_DESC);
9551 }
9552 }
9553 }
9554 }
9555 else {
9556 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9557 }
9558
9559 String sql = query.toString();
9560
9561 Query q = session.createQuery(sql);
9562
9563 q.setFirstResult(0);
9564 q.setMaxResults(2);
9565
9566 QueryPos qPos = QueryPos.getInstance(q);
9567
9568 qPos.add(threadId);
9569
9570 qPos.add(answer);
9571
9572 if (orderByComparator != null) {
9573 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9574
9575 for (Object value : values) {
9576 qPos.add(value);
9577 }
9578 }
9579
9580 List<MBMessage> list = q.list();
9581
9582 if (list.size() == 2) {
9583 return list.get(1);
9584 }
9585 else {
9586 return null;
9587 }
9588 }
9589
9590
9597 public void removeByT_A(long threadId, boolean answer)
9598 throws SystemException {
9599 for (MBMessage mbMessage : findByT_A(threadId, answer,
9600 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9601 remove(mbMessage);
9602 }
9603 }
9604
9605
9613 public int countByT_A(long threadId, boolean answer)
9614 throws SystemException {
9615 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9616
9617 Object[] finderArgs = new Object[] { threadId, answer };
9618
9619 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9620 this);
9621
9622 if (count == null) {
9623 StringBundler query = new StringBundler(3);
9624
9625 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9626
9627 query.append(_FINDER_COLUMN_T_A_THREADID_2);
9628
9629 query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9630
9631 String sql = query.toString();
9632
9633 Session session = null;
9634
9635 try {
9636 session = openSession();
9637
9638 Query q = session.createQuery(sql);
9639
9640 QueryPos qPos = QueryPos.getInstance(q);
9641
9642 qPos.add(threadId);
9643
9644 qPos.add(answer);
9645
9646 count = (Long)q.uniqueResult();
9647
9648 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9649 }
9650 catch (Exception e) {
9651 FinderCacheUtil.removeResult(finderPath, finderArgs);
9652
9653 throw processException(e);
9654 }
9655 finally {
9656 closeSession(session);
9657 }
9658 }
9659
9660 return count.intValue();
9661 }
9662
9663 private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9664 private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9665 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9666 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9667 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9668 new String[] {
9669 Long.class.getName(), Integer.class.getName(),
9670
9671 Integer.class.getName(), Integer.class.getName(),
9672 OrderByComparator.class.getName()
9673 });
9674 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9675 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9676 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9677 new String[] { Long.class.getName(), Integer.class.getName() },
9678 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9679 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9680 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9681 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9682 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9683 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9684 new String[] { Long.class.getName(), Integer.class.getName() });
9685
9686
9694 public List<MBMessage> findByT_S(long threadId, int status)
9695 throws SystemException {
9696 return findByT_S(threadId, status, QueryUtil.ALL_POS,
9697 QueryUtil.ALL_POS, null);
9698 }
9699
9700
9714 public List<MBMessage> findByT_S(long threadId, int status, int start,
9715 int end) throws SystemException {
9716 return findByT_S(threadId, status, start, end, null);
9717 }
9718
9719
9734 public List<MBMessage> findByT_S(long threadId, int status, int start,
9735 int end, OrderByComparator orderByComparator) throws SystemException {
9736 boolean pagination = true;
9737 FinderPath finderPath = null;
9738 Object[] finderArgs = null;
9739
9740 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9741 (orderByComparator == null)) {
9742 pagination = false;
9743 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9744 finderArgs = new Object[] { threadId, status };
9745 }
9746 else {
9747 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9748 finderArgs = new Object[] {
9749 threadId, status,
9750
9751 start, end, orderByComparator
9752 };
9753 }
9754
9755 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9756 finderArgs, this);
9757
9758 if ((list != null) && !list.isEmpty()) {
9759 for (MBMessage mbMessage : list) {
9760 if ((threadId != mbMessage.getThreadId()) ||
9761 (status != mbMessage.getStatus())) {
9762 list = null;
9763
9764 break;
9765 }
9766 }
9767 }
9768
9769 if (list == null) {
9770 StringBundler query = null;
9771
9772 if (orderByComparator != null) {
9773 query = new StringBundler(4 +
9774 (orderByComparator.getOrderByFields().length * 3));
9775 }
9776 else {
9777 query = new StringBundler(4);
9778 }
9779
9780 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9781
9782 query.append(_FINDER_COLUMN_T_S_THREADID_2);
9783
9784 query.append(_FINDER_COLUMN_T_S_STATUS_2);
9785
9786 if (orderByComparator != null) {
9787 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9788 orderByComparator);
9789 }
9790 else
9791 if (pagination) {
9792 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9793 }
9794
9795 String sql = query.toString();
9796
9797 Session session = null;
9798
9799 try {
9800 session = openSession();
9801
9802 Query q = session.createQuery(sql);
9803
9804 QueryPos qPos = QueryPos.getInstance(q);
9805
9806 qPos.add(threadId);
9807
9808 qPos.add(status);
9809
9810 if (!pagination) {
9811 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9812 start, end, false);
9813
9814 Collections.sort(list);
9815
9816 list = new UnmodifiableList<MBMessage>(list);
9817 }
9818 else {
9819 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9820 start, end);
9821 }
9822
9823 cacheResult(list);
9824
9825 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9826 }
9827 catch (Exception e) {
9828 FinderCacheUtil.removeResult(finderPath, finderArgs);
9829
9830 throw processException(e);
9831 }
9832 finally {
9833 closeSession(session);
9834 }
9835 }
9836
9837 return list;
9838 }
9839
9840
9850 public MBMessage findByT_S_First(long threadId, int status,
9851 OrderByComparator orderByComparator)
9852 throws NoSuchMessageException, SystemException {
9853 MBMessage mbMessage = fetchByT_S_First(threadId, status,
9854 orderByComparator);
9855
9856 if (mbMessage != null) {
9857 return mbMessage;
9858 }
9859
9860 StringBundler msg = new StringBundler(6);
9861
9862 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9863
9864 msg.append("threadId=");
9865 msg.append(threadId);
9866
9867 msg.append(", status=");
9868 msg.append(status);
9869
9870 msg.append(StringPool.CLOSE_CURLY_BRACE);
9871
9872 throw new NoSuchMessageException(msg.toString());
9873 }
9874
9875
9884 public MBMessage fetchByT_S_First(long threadId, int status,
9885 OrderByComparator orderByComparator) throws SystemException {
9886 List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9887 orderByComparator);
9888
9889 if (!list.isEmpty()) {
9890 return list.get(0);
9891 }
9892
9893 return null;
9894 }
9895
9896
9906 public MBMessage findByT_S_Last(long threadId, int status,
9907 OrderByComparator orderByComparator)
9908 throws NoSuchMessageException, SystemException {
9909 MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9910 orderByComparator);
9911
9912 if (mbMessage != null) {
9913 return mbMessage;
9914 }
9915
9916 StringBundler msg = new StringBundler(6);
9917
9918 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9919
9920 msg.append("threadId=");
9921 msg.append(threadId);
9922
9923 msg.append(", status=");
9924 msg.append(status);
9925
9926 msg.append(StringPool.CLOSE_CURLY_BRACE);
9927
9928 throw new NoSuchMessageException(msg.toString());
9929 }
9930
9931
9940 public MBMessage fetchByT_S_Last(long threadId, int status,
9941 OrderByComparator orderByComparator) throws SystemException {
9942 int count = countByT_S(threadId, status);
9943
9944 List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9945 orderByComparator);
9946
9947 if (!list.isEmpty()) {
9948 return list.get(0);
9949 }
9950
9951 return null;
9952 }
9953
9954
9965 public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9966 int status, OrderByComparator orderByComparator)
9967 throws NoSuchMessageException, SystemException {
9968 MBMessage mbMessage = findByPrimaryKey(messageId);
9969
9970 Session session = null;
9971
9972 try {
9973 session = openSession();
9974
9975 MBMessage[] array = new MBMessageImpl[3];
9976
9977 array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9978 status, orderByComparator, true);
9979
9980 array[1] = mbMessage;
9981
9982 array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9983 status, orderByComparator, false);
9984
9985 return array;
9986 }
9987 catch (Exception e) {
9988 throw processException(e);
9989 }
9990 finally {
9991 closeSession(session);
9992 }
9993 }
9994
9995 protected MBMessage getByT_S_PrevAndNext(Session session,
9996 MBMessage mbMessage, long threadId, int status,
9997 OrderByComparator orderByComparator, boolean previous) {
9998 StringBundler query = null;
9999
10000 if (orderByComparator != null) {
10001 query = new StringBundler(6 +
10002 (orderByComparator.getOrderByFields().length * 6));
10003 }
10004 else {
10005 query = new StringBundler(3);
10006 }
10007
10008 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10009
10010 query.append(_FINDER_COLUMN_T_S_THREADID_2);
10011
10012 query.append(_FINDER_COLUMN_T_S_STATUS_2);
10013
10014 if (orderByComparator != null) {
10015 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10016
10017 if (orderByConditionFields.length > 0) {
10018 query.append(WHERE_AND);
10019 }
10020
10021 for (int i = 0; i < orderByConditionFields.length; i++) {
10022 query.append(_ORDER_BY_ENTITY_ALIAS);
10023 query.append(orderByConditionFields[i]);
10024
10025 if ((i + 1) < orderByConditionFields.length) {
10026 if (orderByComparator.isAscending() ^ previous) {
10027 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10028 }
10029 else {
10030 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10031 }
10032 }
10033 else {
10034 if (orderByComparator.isAscending() ^ previous) {
10035 query.append(WHERE_GREATER_THAN);
10036 }
10037 else {
10038 query.append(WHERE_LESSER_THAN);
10039 }
10040 }
10041 }
10042
10043 query.append(ORDER_BY_CLAUSE);
10044
10045 String[] orderByFields = orderByComparator.getOrderByFields();
10046
10047 for (int i = 0; i < orderByFields.length; i++) {
10048 query.append(_ORDER_BY_ENTITY_ALIAS);
10049 query.append(orderByFields[i]);
10050
10051 if ((i + 1) < orderByFields.length) {
10052 if (orderByComparator.isAscending() ^ previous) {
10053 query.append(ORDER_BY_ASC_HAS_NEXT);
10054 }
10055 else {
10056 query.append(ORDER_BY_DESC_HAS_NEXT);
10057 }
10058 }
10059 else {
10060 if (orderByComparator.isAscending() ^ previous) {
10061 query.append(ORDER_BY_ASC);
10062 }
10063 else {
10064 query.append(ORDER_BY_DESC);
10065 }
10066 }
10067 }
10068 }
10069 else {
10070 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10071 }
10072
10073 String sql = query.toString();
10074
10075 Query q = session.createQuery(sql);
10076
10077 q.setFirstResult(0);
10078 q.setMaxResults(2);
10079
10080 QueryPos qPos = QueryPos.getInstance(q);
10081
10082 qPos.add(threadId);
10083
10084 qPos.add(status);
10085
10086 if (orderByComparator != null) {
10087 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10088
10089 for (Object value : values) {
10090 qPos.add(value);
10091 }
10092 }
10093
10094 List<MBMessage> list = q.list();
10095
10096 if (list.size() == 2) {
10097 return list.get(1);
10098 }
10099 else {
10100 return null;
10101 }
10102 }
10103
10104
10111 public void removeByT_S(long threadId, int status)
10112 throws SystemException {
10113 for (MBMessage mbMessage : findByT_S(threadId, status,
10114 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10115 remove(mbMessage);
10116 }
10117 }
10118
10119
10127 public int countByT_S(long threadId, int status) throws SystemException {
10128 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10129
10130 Object[] finderArgs = new Object[] { threadId, status };
10131
10132 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10133 this);
10134
10135 if (count == null) {
10136 StringBundler query = new StringBundler(3);
10137
10138 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10139
10140 query.append(_FINDER_COLUMN_T_S_THREADID_2);
10141
10142 query.append(_FINDER_COLUMN_T_S_STATUS_2);
10143
10144 String sql = query.toString();
10145
10146 Session session = null;
10147
10148 try {
10149 session = openSession();
10150
10151 Query q = session.createQuery(sql);
10152
10153 QueryPos qPos = QueryPos.getInstance(q);
10154
10155 qPos.add(threadId);
10156
10157 qPos.add(status);
10158
10159 count = (Long)q.uniqueResult();
10160
10161 FinderCacheUtil.putResult(finderPath, finderArgs, count);
10162 }
10163 catch (Exception e) {
10164 FinderCacheUtil.removeResult(finderPath, finderArgs);
10165
10166 throw processException(e);
10167 }
10168 finally {
10169 closeSession(session);
10170 }
10171 }
10172
10173 return count.intValue();
10174 }
10175
10176 private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10177 private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10178 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10179 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10180 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10181 new String[] {
10182 Long.class.getName(), Integer.class.getName(),
10183
10184 Integer.class.getName(), Integer.class.getName(),
10185 OrderByComparator.class.getName()
10186 });
10187 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10188 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10189 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10190 new String[] { Long.class.getName(), Integer.class.getName() },
10191 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10192 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10193 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10194 public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10195 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10196 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10197 new String[] { Long.class.getName(), Integer.class.getName() });
10198
10199
10207 public List<MBMessage> findByTR_S(long threadId, int status)
10208 throws SystemException {
10209 return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10210 QueryUtil.ALL_POS, null);
10211 }
10212
10213
10227 public List<MBMessage> findByTR_S(long threadId, int status, int start,
10228 int end) throws SystemException {
10229 return findByTR_S(threadId, status, start, end, null);
10230 }
10231
10232
10247 public List<MBMessage> findByTR_S(long threadId, int status, int start,
10248 int end, OrderByComparator orderByComparator) throws SystemException {
10249 boolean pagination = true;
10250 FinderPath finderPath = null;
10251 Object[] finderArgs = null;
10252
10253 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10254 (orderByComparator == null)) {
10255 pagination = false;
10256 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10257 finderArgs = new Object[] { threadId, status };
10258 }
10259 else {
10260 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10261 finderArgs = new Object[] {
10262 threadId, status,
10263
10264 start, end, orderByComparator
10265 };
10266 }
10267
10268 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10269 finderArgs, this);
10270
10271 if ((list != null) && !list.isEmpty()) {
10272 for (MBMessage mbMessage : list) {
10273 if ((threadId != mbMessage.getThreadId()) ||
10274 (status != mbMessage.getStatus())) {
10275 list = null;
10276
10277 break;
10278 }
10279 }
10280 }
10281
10282 if (list == null) {
10283 StringBundler query = null;
10284
10285 if (orderByComparator != null) {
10286 query = new StringBundler(4 +
10287 (orderByComparator.getOrderByFields().length * 3));
10288 }
10289 else {
10290 query = new StringBundler(4);
10291 }
10292
10293 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10294
10295 query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10296
10297 query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10298
10299 if (orderByComparator != null) {
10300 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10301 orderByComparator);
10302 }
10303 else
10304 if (pagination) {
10305 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10306 }
10307
10308 String sql = query.toString();
10309
10310 Session session = null;
10311
10312 try {
10313 session = openSession();
10314
10315 Query q = session.createQuery(sql);
10316
10317 QueryPos qPos = QueryPos.getInstance(q);
10318
10319 qPos.add(threadId);
10320
10321 qPos.add(status);
10322
10323 if (!pagination) {
10324 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10325 start, end, false);
10326
10327 Collections.sort(list);
10328
10329 list = new UnmodifiableList<MBMessage>(list);
10330 }
10331 else {
10332 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10333 start, end);
10334 }
10335
10336 cacheResult(list);
10337
10338 FinderCacheUtil.putResult(finderPath, finderArgs, list);
10339 }
10340 catch (Exception e) {
10341 FinderCacheUtil.removeResult(finderPath, finderArgs);
10342
10343 throw processException(e);
10344 }
10345 finally {
10346 closeSession(session);
10347 }
10348 }
10349
10350 return list;
10351 }
10352
10353
10363 public MBMessage findByTR_S_First(long threadId, int status,
10364 OrderByComparator orderByComparator)
10365 throws NoSuchMessageException, SystemException {
10366 MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10367 orderByComparator);
10368
10369 if (mbMessage != null) {
10370 return mbMessage;
10371 }
10372
10373 StringBundler msg = new StringBundler(6);
10374
10375 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10376
10377 msg.append("threadId=");
10378 msg.append(threadId);
10379
10380 msg.append(", status=");
10381 msg.append(status);
10382
10383 msg.append(StringPool.CLOSE_CURLY_BRACE);
10384
10385 throw new NoSuchMessageException(msg.toString());
10386 }
10387
10388
10397 public MBMessage fetchByTR_S_First(long threadId, int status,
10398 OrderByComparator orderByComparator) throws SystemException {
10399 List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10400 orderByComparator);
10401
10402 if (!list.isEmpty()) {
10403 return list.get(0);
10404 }
10405
10406 return null;
10407 }
10408
10409
10419 public MBMessage findByTR_S_Last(long threadId, int status,
10420 OrderByComparator orderByComparator)
10421 throws NoSuchMessageException, SystemException {
10422 MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10423 orderByComparator);
10424
10425 if (mbMessage != null) {
10426 return mbMessage;
10427 }
10428
10429 StringBundler msg = new StringBundler(6);
10430
10431 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10432
10433 msg.append("threadId=");
10434 msg.append(threadId);
10435
10436 msg.append(", status=");
10437 msg.append(status);
10438
10439 msg.append(StringPool.CLOSE_CURLY_BRACE);
10440
10441 throw new NoSuchMessageException(msg.toString());
10442 }
10443
10444
10453 public MBMessage fetchByTR_S_Last(long threadId, int status,
10454 OrderByComparator orderByComparator) throws SystemException {
10455 int count = countByTR_S(threadId, status);
10456
10457 List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10458 orderByComparator);
10459
10460 if (!list.isEmpty()) {
10461 return list.get(0);
10462 }
10463
10464 return null;
10465 }
10466
10467
10478 public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10479 int status, OrderByComparator orderByComparator)
10480 throws NoSuchMessageException, SystemException {
10481 MBMessage mbMessage = findByPrimaryKey(messageId);
10482
10483 Session session = null;
10484
10485 try {
10486 session = openSession();
10487
10488 MBMessage[] array = new MBMessageImpl[3];
10489
10490 array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10491 status, orderByComparator, true);
10492
10493 array[1] = mbMessage;
10494
10495 array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10496 status, orderByComparator, false);
10497
10498 return array;
10499 }
10500 catch (Exception e) {
10501 throw processException(e);
10502 }
10503 finally {
10504 closeSession(session);
10505 }
10506 }
10507
10508 protected MBMessage getByTR_S_PrevAndNext(Session session,
10509 MBMessage mbMessage, long threadId, int status,
10510 OrderByComparator orderByComparator, boolean previous) {
10511 StringBundler query = null;
10512
10513 if (orderByComparator != null) {
10514 query = new StringBundler(6 +
10515 (orderByComparator.getOrderByFields().length * 6));
10516 }
10517 else {
10518 query = new StringBundler(3);
10519 }
10520
10521 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10522
10523 query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10524
10525 query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10526
10527 if (orderByComparator != null) {
10528 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10529
10530 if (orderByConditionFields.length > 0) {
10531 query.append(WHERE_AND);
10532 }
10533
10534 for (int i = 0; i < orderByConditionFields.length; i++) {
10535 query.append(_ORDER_BY_ENTITY_ALIAS);
10536 query.append(orderByConditionFields[i]);
10537
10538 if ((i + 1) < orderByConditionFields.length) {
10539 if (orderByComparator.isAscending() ^ previous) {
10540 query.append(WHERE_GREATER_THAN_HAS_NEXT);
10541 }
10542 else {
10543 query.append(WHERE_LESSER_THAN_HAS_NEXT);
10544 }
10545 }
10546 else {
10547 if (orderByComparator.isAscending() ^ previous) {
10548 query.append(WHERE_GREATER_THAN);
10549 }
10550 else {
10551 query.append(WHERE_LESSER_THAN);
10552 }
10553 }
10554 }
10555
10556 query.append(ORDER_BY_CLAUSE);
10557
10558 String[] orderByFields = orderByComparator.getOrderByFields();
10559
10560 for (int i = 0; i < orderByFields.length; i++) {
10561 query.append(_ORDER_BY_ENTITY_ALIAS);
10562 query.append(orderByFields[i]);
10563
10564 if ((i + 1) < orderByFields.length) {
10565 if (orderByComparator.isAscending() ^ previous) {
10566 query.append(ORDER_BY_ASC_HAS_NEXT);
10567 }
10568 else {
10569 query.append(ORDER_BY_DESC_HAS_NEXT);
10570 }
10571 }
10572 else {
10573 if (orderByComparator.isAscending() ^ previous) {
10574 query.append(ORDER_BY_ASC);
10575 }
10576 else {
10577 query.append(ORDER_BY_DESC);
10578 }
10579 }
10580 }
10581 }
10582 else {
10583 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10584 }
10585
10586 String sql = query.toString();
10587
10588 Query q = session.createQuery(sql);
10589
10590 q.setFirstResult(0);
10591 q.setMaxResults(2);
10592
10593 QueryPos qPos = QueryPos.getInstance(q);
10594
10595 qPos.add(threadId);
10596
10597 qPos.add(status);
10598
10599 if (orderByComparator != null) {
10600 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10601
10602 for (Object value : values) {
10603 qPos.add(value);
10604 }
10605 }
10606
10607 List<MBMessage> list = q.list();
10608
10609 if (list.size() == 2) {
10610 return list.get(1);
10611 }
10612 else {
10613 return null;
10614 }
10615 }
10616
10617
10624 public void removeByTR_S(long threadId, int status)
10625 throws SystemException {
10626 for (MBMessage mbMessage : findByTR_S(threadId, status,
10627 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10628 remove(mbMessage);
10629 }
10630 }
10631
10632
10640 public int countByTR_S(long threadId, int status) throws SystemException {
10641 FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10642
10643 Object[] finderArgs = new Object[] { threadId, status };
10644
10645 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10646 this);
10647
10648 if (count == null) {
10649 StringBundler query = new StringBundler(3);
10650
10651 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10652
10653 query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10654
10655 query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10656
10657 String sql = query.toString();
10658
10659 Session session = null;
10660
10661 try {
10662 session = openSession();
10663
10664 Query q = session.createQuery(sql);
10665
10666 QueryPos qPos = QueryPos.getInstance(q);
10667
10668 qPos.add(threadId);
10669
10670 qPos.add(status);
10671
10672 count = (Long)q.uniqueResult();
10673
10674 FinderCacheUtil.putResult(finderPath, finderArgs, count);
10675 }
10676 catch (Exception e) {
10677 FinderCacheUtil.removeResult(finderPath, finderArgs);
10678
10679 throw processException(e);
10680 }
10681 finally {
10682 closeSession(session);
10683 }
10684 }
10685
10686 return count.intValue();
10687 }
10688
10689 private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10690 private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10691 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10692 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10693 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10694 new String[] {
10695 Long.class.getName(), Long.class.getName(),
10696 Integer.class.getName(),
10697
10698 Integer.class.getName(), Integer.class.getName(),
10699 OrderByComparator.class.getName()
10700 });
10701 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10702 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10703 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10704 new String[] {
10705 Long.class.getName(), Long.class.getName(),
10706 Integer.class.getName()
10707 },
10708 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10709 MBMessageModelImpl.USERID_COLUMN_BITMASK |
10710 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10711 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10712 public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10713 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10714 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10715 new String[] {
10716 Long.class.getName(), Long.class.getName(),
10717 Integer.class.getName()
10718 });
10719
10720
10729 public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
10730 throws SystemException {
10731 return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10732 QueryUtil.ALL_POS, null);
10733 }
10734
10735
10750 public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10751 int start, int end) throws SystemException {
10752 return findByG_U_S(groupId, userId, status, start, end, null);
10753 }
10754
10755
10771 public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10772 int start, int end, OrderByComparator orderByComparator)
10773 throws SystemException {
10774 boolean pagination = true;
10775 FinderPath finderPath = null;
10776 Object[] finderArgs = null;
10777
10778 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10779 (orderByComparator == null)) {
10780 pagination = false;
10781 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10782 finderArgs = new Object[] { groupId, userId, status };
10783 }
10784 else {
10785 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10786 finderArgs = new Object[] {
10787 groupId, userId, status,
10788
10789 start, end, orderByComparator
10790 };
10791 }
10792
10793 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10794 finderArgs, this);
10795
10796 if ((list != null) && !list.isEmpty()) {
10797 for (MBMessage mbMessage : list) {
10798 if ((groupId != mbMessage.getGroupId()) ||
10799 (userId != mbMessage.getUserId()) ||
10800 (status != mbMessage.getStatus())) {
10801 list = null;
10802
10803 break;
10804 }
10805 }
10806 }
10807
10808 if (list == null) {
10809 StringBundler query = null;
10810
10811 if (orderByComparator != null) {
10812 query = new StringBundler(5 +
10813 (orderByComparator.getOrderByFields().length * 3));
10814 }
10815 else {
10816 query = new StringBundler(5);
10817 }
10818
10819 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10820
10821 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10822
10823 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10824
10825 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10826
10827 if (orderByComparator != null) {
10828 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10829 orderByComparator);
10830 }
10831 else
10832 if (pagination) {
10833 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10834 }
10835
10836 String sql = query.toString();
10837
10838 Session session = null;
10839
10840 try {
10841 session = openSession();
10842
10843 Query q = session.createQuery(sql);
10844
10845 QueryPos qPos = QueryPos.getInstance(q);
10846
10847 qPos.add(groupId);
10848
10849 qPos.add(userId);
10850
10851 qPos.add(status);
10852
10853 if (!pagination) {
10854 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10855 start, end, false);
10856
10857 Collections.sort(list);
10858
10859 list = new UnmodifiableList<MBMessage>(list);
10860 }
10861 else {
10862 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10863 start, end);
10864 }
10865
10866 cacheResult(list);
10867
10868 FinderCacheUtil.putResult(finderPath, finderArgs, list);
10869 }
10870 catch (Exception e) {
10871 FinderCacheUtil.removeResult(finderPath, finderArgs);
10872
10873 throw processException(e);
10874 }
10875 finally {
10876 closeSession(session);
10877 }
10878 }
10879
10880 return list;
10881 }
10882
10883
10894 public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10895 OrderByComparator orderByComparator)
10896 throws NoSuchMessageException, SystemException {
10897 MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10898 orderByComparator);
10899
10900 if (mbMessage != null) {
10901 return mbMessage;
10902 }
10903
10904 StringBundler msg = new StringBundler(8);
10905
10906 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10907
10908 msg.append("groupId=");
10909 msg.append(groupId);
10910
10911 msg.append(", userId=");
10912 msg.append(userId);
10913
10914 msg.append(", status=");
10915 msg.append(status);
10916
10917 msg.append(StringPool.CLOSE_CURLY_BRACE);
10918
10919 throw new NoSuchMessageException(msg.toString());
10920 }
10921
10922
10932 public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10933 OrderByComparator orderByComparator) throws SystemException {
10934 List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10935 orderByComparator);
10936
10937 if (!list.isEmpty()) {
10938 return list.get(0);
10939 }
10940
10941 return null;
10942 }
10943
10944
10955 public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10956 OrderByComparator orderByComparator)
10957 throws NoSuchMessageException, SystemException {
10958 MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10959 orderByComparator);
10960
10961 if (mbMessage != null) {
10962 return mbMessage;
10963 }
10964
10965 StringBundler msg = new StringBundler(8);
10966
10967 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10968
10969 msg.append("groupId=");
10970 msg.append(groupId);
10971
10972 msg.append(", userId=");
10973 msg.append(userId);
10974
10975 msg.append(", status=");
10976 msg.append(status);
10977
10978 msg.append(StringPool.CLOSE_CURLY_BRACE);
10979
10980 throw new NoSuchMessageException(msg.toString());
10981 }
10982
10983
10993 public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
10994 OrderByComparator orderByComparator) throws SystemException {
10995 int count = countByG_U_S(groupId, userId, status);
10996
10997 List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
10998 count, orderByComparator);
10999
11000 if (!list.isEmpty()) {
11001 return list.get(0);
11002 }
11003
11004 return null;
11005 }
11006
11007
11019 public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11020 long userId, int status, OrderByComparator orderByComparator)
11021 throws NoSuchMessageException, SystemException {
11022 MBMessage mbMessage = findByPrimaryKey(messageId);
11023
11024 Session session = null;
11025
11026 try {
11027 session = openSession();
11028
11029 MBMessage[] array = new MBMessageImpl[3];
11030
11031 array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11032 userId, status, orderByComparator, true);
11033
11034 array[1] = mbMessage;
11035
11036 array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11037 userId, status, orderByComparator, false);
11038
11039 return array;
11040 }
11041 catch (Exception e) {
11042 throw processException(e);
11043 }
11044 finally {
11045 closeSession(session);
11046 }
11047 }
11048
11049 protected MBMessage getByG_U_S_PrevAndNext(Session session,
11050 MBMessage mbMessage, long groupId, long userId, int status,
11051 OrderByComparator orderByComparator, boolean previous) {
11052 StringBundler query = null;
11053
11054 if (orderByComparator != null) {
11055 query = new StringBundler(6 +
11056 (orderByComparator.getOrderByFields().length * 6));
11057 }
11058 else {
11059 query = new StringBundler(3);
11060 }
11061
11062 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11063
11064 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11065
11066 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11067
11068 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11069
11070 if (orderByComparator != null) {
11071 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11072
11073 if (orderByConditionFields.length > 0) {
11074 query.append(WHERE_AND);
11075 }
11076
11077 for (int i = 0; i < orderByConditionFields.length; i++) {
11078 query.append(_ORDER_BY_ENTITY_ALIAS);
11079 query.append(orderByConditionFields[i]);
11080
11081 if ((i + 1) < orderByConditionFields.length) {
11082 if (orderByComparator.isAscending() ^ previous) {
11083 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11084 }
11085 else {
11086 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11087 }
11088 }
11089 else {
11090 if (orderByComparator.isAscending() ^ previous) {
11091 query.append(WHERE_GREATER_THAN);
11092 }
11093 else {
11094 query.append(WHERE_LESSER_THAN);
11095 }
11096 }
11097 }
11098
11099 query.append(ORDER_BY_CLAUSE);
11100
11101 String[] orderByFields = orderByComparator.getOrderByFields();
11102
11103 for (int i = 0; i < orderByFields.length; i++) {
11104 query.append(_ORDER_BY_ENTITY_ALIAS);
11105 query.append(orderByFields[i]);
11106
11107 if ((i + 1) < orderByFields.length) {
11108 if (orderByComparator.isAscending() ^ previous) {
11109 query.append(ORDER_BY_ASC_HAS_NEXT);
11110 }
11111 else {
11112 query.append(ORDER_BY_DESC_HAS_NEXT);
11113 }
11114 }
11115 else {
11116 if (orderByComparator.isAscending() ^ previous) {
11117 query.append(ORDER_BY_ASC);
11118 }
11119 else {
11120 query.append(ORDER_BY_DESC);
11121 }
11122 }
11123 }
11124 }
11125 else {
11126 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11127 }
11128
11129 String sql = query.toString();
11130
11131 Query q = session.createQuery(sql);
11132
11133 q.setFirstResult(0);
11134 q.setMaxResults(2);
11135
11136 QueryPos qPos = QueryPos.getInstance(q);
11137
11138 qPos.add(groupId);
11139
11140 qPos.add(userId);
11141
11142 qPos.add(status);
11143
11144 if (orderByComparator != null) {
11145 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11146
11147 for (Object value : values) {
11148 qPos.add(value);
11149 }
11150 }
11151
11152 List<MBMessage> list = q.list();
11153
11154 if (list.size() == 2) {
11155 return list.get(1);
11156 }
11157 else {
11158 return null;
11159 }
11160 }
11161
11162
11171 public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11172 int status) throws SystemException {
11173 return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11174 QueryUtil.ALL_POS, null);
11175 }
11176
11177
11192 public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11193 int status, int start, int end) throws SystemException {
11194 return filterFindByG_U_S(groupId, userId, status, start, end, null);
11195 }
11196
11197
11213 public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11214 int status, int start, int end, OrderByComparator orderByComparator)
11215 throws SystemException {
11216 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11217 return findByG_U_S(groupId, userId, status, start, end,
11218 orderByComparator);
11219 }
11220
11221 StringBundler query = null;
11222
11223 if (orderByComparator != null) {
11224 query = new StringBundler(5 +
11225 (orderByComparator.getOrderByFields().length * 3));
11226 }
11227 else {
11228 query = new StringBundler(5);
11229 }
11230
11231 if (getDB().isSupportsInlineDistinct()) {
11232 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11233 }
11234 else {
11235 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11236 }
11237
11238 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11239
11240 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11241
11242 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11243
11244 if (!getDB().isSupportsInlineDistinct()) {
11245 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11246 }
11247
11248 if (orderByComparator != null) {
11249 if (getDB().isSupportsInlineDistinct()) {
11250 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11251 orderByComparator);
11252 }
11253 else {
11254 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11255 orderByComparator);
11256 }
11257 }
11258 else {
11259 if (getDB().isSupportsInlineDistinct()) {
11260 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11261 }
11262 else {
11263 query.append(MBMessageModelImpl.ORDER_BY_SQL);
11264 }
11265 }
11266
11267 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11268 MBMessage.class.getName(),
11269 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11270
11271 Session session = null;
11272
11273 try {
11274 session = openSession();
11275
11276 SQLQuery q = session.createSQLQuery(sql);
11277
11278 if (getDB().isSupportsInlineDistinct()) {
11279 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11280 }
11281 else {
11282 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11283 }
11284
11285 QueryPos qPos = QueryPos.getInstance(q);
11286
11287 qPos.add(groupId);
11288
11289 qPos.add(userId);
11290
11291 qPos.add(status);
11292
11293 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11294 }
11295 catch (Exception e) {
11296 throw processException(e);
11297 }
11298 finally {
11299 closeSession(session);
11300 }
11301 }
11302
11303
11315 public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11316 long groupId, long userId, int status,
11317 OrderByComparator orderByComparator)
11318 throws NoSuchMessageException, SystemException {
11319 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11320 return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11321 orderByComparator);
11322 }
11323
11324 MBMessage mbMessage = findByPrimaryKey(messageId);
11325
11326 Session session = null;
11327
11328 try {
11329 session = openSession();
11330
11331 MBMessage[] array = new MBMessageImpl[3];
11332
11333 array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11334 groupId, userId, status, orderByComparator, true);
11335
11336 array[1] = mbMessage;
11337
11338 array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11339 groupId, userId, status, orderByComparator, false);
11340
11341 return array;
11342 }
11343 catch (Exception e) {
11344 throw processException(e);
11345 }
11346 finally {
11347 closeSession(session);
11348 }
11349 }
11350
11351 protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11352 MBMessage mbMessage, long groupId, long userId, int status,
11353 OrderByComparator orderByComparator, boolean previous) {
11354 StringBundler query = null;
11355
11356 if (orderByComparator != null) {
11357 query = new StringBundler(6 +
11358 (orderByComparator.getOrderByFields().length * 6));
11359 }
11360 else {
11361 query = new StringBundler(3);
11362 }
11363
11364 if (getDB().isSupportsInlineDistinct()) {
11365 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11366 }
11367 else {
11368 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11369 }
11370
11371 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11372
11373 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11374
11375 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11376
11377 if (!getDB().isSupportsInlineDistinct()) {
11378 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11379 }
11380
11381 if (orderByComparator != null) {
11382 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11383
11384 if (orderByConditionFields.length > 0) {
11385 query.append(WHERE_AND);
11386 }
11387
11388 for (int i = 0; i < orderByConditionFields.length; i++) {
11389 if (getDB().isSupportsInlineDistinct()) {
11390 query.append(_ORDER_BY_ENTITY_ALIAS);
11391 }
11392 else {
11393 query.append(_ORDER_BY_ENTITY_TABLE);
11394 }
11395
11396 query.append(orderByConditionFields[i]);
11397
11398 if ((i + 1) < orderByConditionFields.length) {
11399 if (orderByComparator.isAscending() ^ previous) {
11400 query.append(WHERE_GREATER_THAN_HAS_NEXT);
11401 }
11402 else {
11403 query.append(WHERE_LESSER_THAN_HAS_NEXT);
11404 }
11405 }
11406 else {
11407 if (orderByComparator.isAscending() ^ previous) {
11408 query.append(WHERE_GREATER_THAN);
11409 }
11410 else {
11411 query.append(WHERE_LESSER_THAN);
11412 }
11413 }
11414 }
11415
11416 query.append(ORDER_BY_CLAUSE);
11417
11418 String[] orderByFields = orderByComparator.getOrderByFields();
11419
11420 for (int i = 0; i < orderByFields.length; i++) {
11421 if (getDB().isSupportsInlineDistinct()) {
11422 query.append(_ORDER_BY_ENTITY_ALIAS);
11423 }
11424 else {
11425 query.append(_ORDER_BY_ENTITY_TABLE);
11426 }
11427
11428 query.append(orderByFields[i]);
11429
11430 if ((i + 1) < orderByFields.length) {
11431 if (orderByComparator.isAscending() ^ previous) {
11432 query.append(ORDER_BY_ASC_HAS_NEXT);
11433 }
11434 else {
11435 query.append(ORDER_BY_DESC_HAS_NEXT);
11436 }
11437 }
11438 else {
11439 if (orderByComparator.isAscending() ^ previous) {
11440 query.append(ORDER_BY_ASC);
11441 }
11442 else {
11443 query.append(ORDER_BY_DESC);
11444 }
11445 }
11446 }
11447 }
11448 else {
11449 if (getDB().isSupportsInlineDistinct()) {
11450 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11451 }
11452 else {
11453 query.append(MBMessageModelImpl.ORDER_BY_SQL);
11454 }
11455 }
11456
11457 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11458 MBMessage.class.getName(),
11459 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11460
11461 SQLQuery q = session.createSQLQuery(sql);
11462
11463 q.setFirstResult(0);
11464 q.setMaxResults(2);
11465
11466 if (getDB().isSupportsInlineDistinct()) {
11467 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11468 }
11469 else {
11470 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11471 }
11472
11473 QueryPos qPos = QueryPos.getInstance(q);
11474
11475 qPos.add(groupId);
11476
11477 qPos.add(userId);
11478
11479 qPos.add(status);
11480
11481 if (orderByComparator != null) {
11482 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11483
11484 for (Object value : values) {
11485 qPos.add(value);
11486 }
11487 }
11488
11489 List<MBMessage> list = q.list();
11490
11491 if (list.size() == 2) {
11492 return list.get(1);
11493 }
11494 else {
11495 return null;
11496 }
11497 }
11498
11499
11507 public void removeByG_U_S(long groupId, long userId, int status)
11508 throws SystemException {
11509 for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11510 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11511 remove(mbMessage);
11512 }
11513 }
11514
11515
11524 public int countByG_U_S(long groupId, long userId, int status)
11525 throws SystemException {
11526 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11527
11528 Object[] finderArgs = new Object[] { groupId, userId, status };
11529
11530 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11531 this);
11532
11533 if (count == null) {
11534 StringBundler query = new StringBundler(4);
11535
11536 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11537
11538 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11539
11540 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11541
11542 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11543
11544 String sql = query.toString();
11545
11546 Session session = null;
11547
11548 try {
11549 session = openSession();
11550
11551 Query q = session.createQuery(sql);
11552
11553 QueryPos qPos = QueryPos.getInstance(q);
11554
11555 qPos.add(groupId);
11556
11557 qPos.add(userId);
11558
11559 qPos.add(status);
11560
11561 count = (Long)q.uniqueResult();
11562
11563 FinderCacheUtil.putResult(finderPath, finderArgs, count);
11564 }
11565 catch (Exception e) {
11566 FinderCacheUtil.removeResult(finderPath, finderArgs);
11567
11568 throw processException(e);
11569 }
11570 finally {
11571 closeSession(session);
11572 }
11573 }
11574
11575 return count.intValue();
11576 }
11577
11578
11587 public int filterCountByG_U_S(long groupId, long userId, int status)
11588 throws SystemException {
11589 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11590 return countByG_U_S(groupId, userId, status);
11591 }
11592
11593 StringBundler query = new StringBundler(4);
11594
11595 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11596
11597 query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11598
11599 query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11600
11601 query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11602
11603 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11604 MBMessage.class.getName(),
11605 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11606
11607 Session session = null;
11608
11609 try {
11610 session = openSession();
11611
11612 SQLQuery q = session.createSQLQuery(sql);
11613
11614 q.addScalar(COUNT_COLUMN_NAME,
11615 com.liferay.portal.kernel.dao.orm.Type.LONG);
11616
11617 QueryPos qPos = QueryPos.getInstance(q);
11618
11619 qPos.add(groupId);
11620
11621 qPos.add(userId);
11622
11623 qPos.add(status);
11624
11625 Long count = (Long)q.uniqueResult();
11626
11627 return count.intValue();
11628 }
11629 catch (Exception e) {
11630 throw processException(e);
11631 }
11632 finally {
11633 closeSession(session);
11634 }
11635 }
11636
11637 private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11638 private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11639 private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11640 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11641 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11642 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11643 new String[] {
11644 Long.class.getName(), Long.class.getName(), Long.class.getName(),
11645
11646 Integer.class.getName(), Integer.class.getName(),
11647 OrderByComparator.class.getName()
11648 });
11649 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11650 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11651 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11652 new String[] {
11653 Long.class.getName(), Long.class.getName(), Long.class.getName()
11654 },
11655 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11656 MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11657 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11658 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11659 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11660 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11661 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11662 new String[] {
11663 Long.class.getName(), Long.class.getName(), Long.class.getName()
11664 });
11665
11666
11675 public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11676 long threadId) throws SystemException {
11677 return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11678 QueryUtil.ALL_POS, null);
11679 }
11680
11681
11696 public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11697 long threadId, int start, int end) throws SystemException {
11698 return findByG_C_T(groupId, categoryId, threadId, start, end, null);
11699 }
11700
11701
11717 public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11718 long threadId, int start, int end, OrderByComparator orderByComparator)
11719 throws SystemException {
11720 boolean pagination = true;
11721 FinderPath finderPath = null;
11722 Object[] finderArgs = null;
11723
11724 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11725 (orderByComparator == null)) {
11726 pagination = false;
11727 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
11728 finderArgs = new Object[] { groupId, categoryId, threadId };
11729 }
11730 else {
11731 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
11732 finderArgs = new Object[] {
11733 groupId, categoryId, threadId,
11734
11735 start, end, orderByComparator
11736 };
11737 }
11738
11739 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11740 finderArgs, this);
11741
11742 if ((list != null) && !list.isEmpty()) {
11743 for (MBMessage mbMessage : list) {
11744 if ((groupId != mbMessage.getGroupId()) ||
11745 (categoryId != mbMessage.getCategoryId()) ||
11746 (threadId != mbMessage.getThreadId())) {
11747 list = null;
11748
11749 break;
11750 }
11751 }
11752 }
11753
11754 if (list == null) {
11755 StringBundler query = null;
11756
11757 if (orderByComparator != null) {
11758 query = new StringBundler(5 +
11759 (orderByComparator.getOrderByFields().length * 3));
11760 }
11761 else {
11762 query = new StringBundler(5);
11763 }
11764
11765 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11766
11767 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11768
11769 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11770
11771 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11772
11773 if (orderByComparator != null) {
11774 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11775 orderByComparator);
11776 }
11777 else
11778 if (pagination) {
11779 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11780 }
11781
11782 String sql = query.toString();
11783
11784 Session session = null;
11785
11786 try {
11787 session = openSession();
11788
11789 Query q = session.createQuery(sql);
11790
11791 QueryPos qPos = QueryPos.getInstance(q);
11792
11793 qPos.add(groupId);
11794
11795 qPos.add(categoryId);
11796
11797 qPos.add(threadId);
11798
11799 if (!pagination) {
11800 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11801 start, end, false);
11802
11803 Collections.sort(list);
11804
11805 list = new UnmodifiableList<MBMessage>(list);
11806 }
11807 else {
11808 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11809 start, end);
11810 }
11811
11812 cacheResult(list);
11813
11814 FinderCacheUtil.putResult(finderPath, finderArgs, list);
11815 }
11816 catch (Exception e) {
11817 FinderCacheUtil.removeResult(finderPath, finderArgs);
11818
11819 throw processException(e);
11820 }
11821 finally {
11822 closeSession(session);
11823 }
11824 }
11825
11826 return list;
11827 }
11828
11829
11840 public MBMessage findByG_C_T_First(long groupId, long categoryId,
11841 long threadId, OrderByComparator orderByComparator)
11842 throws NoSuchMessageException, SystemException {
11843 MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11844 orderByComparator);
11845
11846 if (mbMessage != null) {
11847 return mbMessage;
11848 }
11849
11850 StringBundler msg = new StringBundler(8);
11851
11852 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11853
11854 msg.append("groupId=");
11855 msg.append(groupId);
11856
11857 msg.append(", categoryId=");
11858 msg.append(categoryId);
11859
11860 msg.append(", threadId=");
11861 msg.append(threadId);
11862
11863 msg.append(StringPool.CLOSE_CURLY_BRACE);
11864
11865 throw new NoSuchMessageException(msg.toString());
11866 }
11867
11868
11878 public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11879 long threadId, OrderByComparator orderByComparator)
11880 throws SystemException {
11881 List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11882 orderByComparator);
11883
11884 if (!list.isEmpty()) {
11885 return list.get(0);
11886 }
11887
11888 return null;
11889 }
11890
11891
11902 public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11903 long threadId, OrderByComparator orderByComparator)
11904 throws NoSuchMessageException, SystemException {
11905 MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11906 orderByComparator);
11907
11908 if (mbMessage != null) {
11909 return mbMessage;
11910 }
11911
11912 StringBundler msg = new StringBundler(8);
11913
11914 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11915
11916 msg.append("groupId=");
11917 msg.append(groupId);
11918
11919 msg.append(", categoryId=");
11920 msg.append(categoryId);
11921
11922 msg.append(", threadId=");
11923 msg.append(threadId);
11924
11925 msg.append(StringPool.CLOSE_CURLY_BRACE);
11926
11927 throw new NoSuchMessageException(msg.toString());
11928 }
11929
11930
11940 public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11941 long threadId, OrderByComparator orderByComparator)
11942 throws SystemException {
11943 int count = countByG_C_T(groupId, categoryId, threadId);
11944
11945 List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11946 count - 1, count, orderByComparator);
11947
11948 if (!list.isEmpty()) {
11949 return list.get(0);
11950 }
11951
11952 return null;
11953 }
11954
11955
11967 public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11968 long categoryId, long threadId, OrderByComparator orderByComparator)
11969 throws NoSuchMessageException, SystemException {
11970 MBMessage mbMessage = findByPrimaryKey(messageId);
11971
11972 Session session = null;
11973
11974 try {
11975 session = openSession();
11976
11977 MBMessage[] array = new MBMessageImpl[3];
11978
11979 array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11980 categoryId, threadId, orderByComparator, true);
11981
11982 array[1] = mbMessage;
11983
11984 array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11985 categoryId, threadId, orderByComparator, false);
11986
11987 return array;
11988 }
11989 catch (Exception e) {
11990 throw processException(e);
11991 }
11992 finally {
11993 closeSession(session);
11994 }
11995 }
11996
11997 protected MBMessage getByG_C_T_PrevAndNext(Session session,
11998 MBMessage mbMessage, long groupId, long categoryId, long threadId,
11999 OrderByComparator orderByComparator, boolean previous) {
12000 StringBundler query = null;
12001
12002 if (orderByComparator != null) {
12003 query = new StringBundler(6 +
12004 (orderByComparator.getOrderByFields().length * 6));
12005 }
12006 else {
12007 query = new StringBundler(3);
12008 }
12009
12010 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12011
12012 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12013
12014 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12015
12016 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12017
12018 if (orderByComparator != null) {
12019 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12020
12021 if (orderByConditionFields.length > 0) {
12022 query.append(WHERE_AND);
12023 }
12024
12025 for (int i = 0; i < orderByConditionFields.length; i++) {
12026 query.append(_ORDER_BY_ENTITY_ALIAS);
12027 query.append(orderByConditionFields[i]);
12028
12029 if ((i + 1) < orderByConditionFields.length) {
12030 if (orderByComparator.isAscending() ^ previous) {
12031 query.append(WHERE_GREATER_THAN_HAS_NEXT);
12032 }
12033 else {
12034 query.append(WHERE_LESSER_THAN_HAS_NEXT);
12035 }
12036 }
12037 else {
12038 if (orderByComparator.isAscending() ^ previous) {
12039 query.append(WHERE_GREATER_THAN);
12040 }
12041 else {
12042 query.append(WHERE_LESSER_THAN);
12043 }
12044 }
12045 }
12046
12047 query.append(ORDER_BY_CLAUSE);
12048
12049 String[] orderByFields = orderByComparator.getOrderByFields();
12050
12051 for (int i = 0; i < orderByFields.length; i++) {
12052 query.append(_ORDER_BY_ENTITY_ALIAS);
12053 query.append(orderByFields[i]);
12054
12055 if ((i + 1) < orderByFields.length) {
12056 if (orderByComparator.isAscending() ^ previous) {
12057 query.append(ORDER_BY_ASC_HAS_NEXT);
12058 }
12059 else {
12060 query.append(ORDER_BY_DESC_HAS_NEXT);
12061 }
12062 }
12063 else {
12064 if (orderByComparator.isAscending() ^ previous) {
12065 query.append(ORDER_BY_ASC);
12066 }
12067 else {
12068 query.append(ORDER_BY_DESC);
12069 }
12070 }
12071 }
12072 }
12073 else {
12074 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12075 }
12076
12077 String sql = query.toString();
12078
12079 Query q = session.createQuery(sql);
12080
12081 q.setFirstResult(0);
12082 q.setMaxResults(2);
12083
12084 QueryPos qPos = QueryPos.getInstance(q);
12085
12086 qPos.add(groupId);
12087
12088 qPos.add(categoryId);
12089
12090 qPos.add(threadId);
12091
12092 if (orderByComparator != null) {
12093 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12094
12095 for (Object value : values) {
12096 qPos.add(value);
12097 }
12098 }
12099
12100 List<MBMessage> list = q.list();
12101
12102 if (list.size() == 2) {
12103 return list.get(1);
12104 }
12105 else {
12106 return null;
12107 }
12108 }
12109
12110
12119 public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12120 long threadId) throws SystemException {
12121 return filterFindByG_C_T(groupId, categoryId, threadId,
12122 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12123 }
12124
12125
12140 public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12141 long threadId, int start, int end) throws SystemException {
12142 return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12143 }
12144
12145
12161 public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12162 long threadId, int start, int end, OrderByComparator orderByComparator)
12163 throws SystemException {
12164 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12165 return findByG_C_T(groupId, categoryId, threadId, start, end,
12166 orderByComparator);
12167 }
12168
12169 StringBundler query = null;
12170
12171 if (orderByComparator != null) {
12172 query = new StringBundler(5 +
12173 (orderByComparator.getOrderByFields().length * 3));
12174 }
12175 else {
12176 query = new StringBundler(5);
12177 }
12178
12179 if (getDB().isSupportsInlineDistinct()) {
12180 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12181 }
12182 else {
12183 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12184 }
12185
12186 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12187
12188 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12189
12190 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12191
12192 if (!getDB().isSupportsInlineDistinct()) {
12193 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12194 }
12195
12196 if (orderByComparator != null) {
12197 if (getDB().isSupportsInlineDistinct()) {
12198 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12199 orderByComparator);
12200 }
12201 else {
12202 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12203 orderByComparator);
12204 }
12205 }
12206 else {
12207 if (getDB().isSupportsInlineDistinct()) {
12208 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12209 }
12210 else {
12211 query.append(MBMessageModelImpl.ORDER_BY_SQL);
12212 }
12213 }
12214
12215 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12216 MBMessage.class.getName(),
12217 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12218
12219 Session session = null;
12220
12221 try {
12222 session = openSession();
12223
12224 SQLQuery q = session.createSQLQuery(sql);
12225
12226 if (getDB().isSupportsInlineDistinct()) {
12227 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12228 }
12229 else {
12230 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12231 }
12232
12233 QueryPos qPos = QueryPos.getInstance(q);
12234
12235 qPos.add(groupId);
12236
12237 qPos.add(categoryId);
12238
12239 qPos.add(threadId);
12240
12241 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12242 }
12243 catch (Exception e) {
12244 throw processException(e);
12245 }
12246 finally {
12247 closeSession(session);
12248 }
12249 }
12250
12251
12263 public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12264 long groupId, long categoryId, long threadId,
12265 OrderByComparator orderByComparator)
12266 throws NoSuchMessageException, SystemException {
12267 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12268 return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12269 threadId, orderByComparator);
12270 }
12271
12272 MBMessage mbMessage = findByPrimaryKey(messageId);
12273
12274 Session session = null;
12275
12276 try {
12277 session = openSession();
12278
12279 MBMessage[] array = new MBMessageImpl[3];
12280
12281 array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12282 groupId, categoryId, threadId, orderByComparator, true);
12283
12284 array[1] = mbMessage;
12285
12286 array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12287 groupId, categoryId, threadId, orderByComparator, false);
12288
12289 return array;
12290 }
12291 catch (Exception e) {
12292 throw processException(e);
12293 }
12294 finally {
12295 closeSession(session);
12296 }
12297 }
12298
12299 protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12300 MBMessage mbMessage, long groupId, long categoryId, long threadId,
12301 OrderByComparator orderByComparator, boolean previous) {
12302 StringBundler query = null;
12303
12304 if (orderByComparator != null) {
12305 query = new StringBundler(6 +
12306 (orderByComparator.getOrderByFields().length * 6));
12307 }
12308 else {
12309 query = new StringBundler(3);
12310 }
12311
12312 if (getDB().isSupportsInlineDistinct()) {
12313 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12314 }
12315 else {
12316 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12317 }
12318
12319 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12320
12321 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12322
12323 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12324
12325 if (!getDB().isSupportsInlineDistinct()) {
12326 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12327 }
12328
12329 if (orderByComparator != null) {
12330 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12331
12332 if (orderByConditionFields.length > 0) {
12333 query.append(WHERE_AND);
12334 }
12335
12336 for (int i = 0; i < orderByConditionFields.length; i++) {
12337 if (getDB().isSupportsInlineDistinct()) {
12338 query.append(_ORDER_BY_ENTITY_ALIAS);
12339 }
12340 else {
12341 query.append(_ORDER_BY_ENTITY_TABLE);
12342 }
12343
12344 query.append(orderByConditionFields[i]);
12345
12346 if ((i + 1) < orderByConditionFields.length) {
12347 if (orderByComparator.isAscending() ^ previous) {
12348 query.append(WHERE_GREATER_THAN_HAS_NEXT);
12349 }
12350 else {
12351 query.append(WHERE_LESSER_THAN_HAS_NEXT);
12352 }
12353 }
12354 else {
12355 if (orderByComparator.isAscending() ^ previous) {
12356 query.append(WHERE_GREATER_THAN);
12357 }
12358 else {
12359 query.append(WHERE_LESSER_THAN);
12360 }
12361 }
12362 }
12363
12364 query.append(ORDER_BY_CLAUSE);
12365
12366 String[] orderByFields = orderByComparator.getOrderByFields();
12367
12368 for (int i = 0; i < orderByFields.length; i++) {
12369 if (getDB().isSupportsInlineDistinct()) {
12370 query.append(_ORDER_BY_ENTITY_ALIAS);
12371 }
12372 else {
12373 query.append(_ORDER_BY_ENTITY_TABLE);
12374 }
12375
12376 query.append(orderByFields[i]);
12377
12378 if ((i + 1) < orderByFields.length) {
12379 if (orderByComparator.isAscending() ^ previous) {
12380 query.append(ORDER_BY_ASC_HAS_NEXT);
12381 }
12382 else {
12383 query.append(ORDER_BY_DESC_HAS_NEXT);
12384 }
12385 }
12386 else {
12387 if (orderByComparator.isAscending() ^ previous) {
12388 query.append(ORDER_BY_ASC);
12389 }
12390 else {
12391 query.append(ORDER_BY_DESC);
12392 }
12393 }
12394 }
12395 }
12396 else {
12397 if (getDB().isSupportsInlineDistinct()) {
12398 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12399 }
12400 else {
12401 query.append(MBMessageModelImpl.ORDER_BY_SQL);
12402 }
12403 }
12404
12405 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12406 MBMessage.class.getName(),
12407 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12408
12409 SQLQuery q = session.createSQLQuery(sql);
12410
12411 q.setFirstResult(0);
12412 q.setMaxResults(2);
12413
12414 if (getDB().isSupportsInlineDistinct()) {
12415 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12416 }
12417 else {
12418 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12419 }
12420
12421 QueryPos qPos = QueryPos.getInstance(q);
12422
12423 qPos.add(groupId);
12424
12425 qPos.add(categoryId);
12426
12427 qPos.add(threadId);
12428
12429 if (orderByComparator != null) {
12430 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12431
12432 for (Object value : values) {
12433 qPos.add(value);
12434 }
12435 }
12436
12437 List<MBMessage> list = q.list();
12438
12439 if (list.size() == 2) {
12440 return list.get(1);
12441 }
12442 else {
12443 return null;
12444 }
12445 }
12446
12447
12455 public void removeByG_C_T(long groupId, long categoryId, long threadId)
12456 throws SystemException {
12457 for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12458 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12459 remove(mbMessage);
12460 }
12461 }
12462
12463
12472 public int countByG_C_T(long groupId, long categoryId, long threadId)
12473 throws SystemException {
12474 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12475
12476 Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12477
12478 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12479 this);
12480
12481 if (count == null) {
12482 StringBundler query = new StringBundler(4);
12483
12484 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12485
12486 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12487
12488 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12489
12490 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12491
12492 String sql = query.toString();
12493
12494 Session session = null;
12495
12496 try {
12497 session = openSession();
12498
12499 Query q = session.createQuery(sql);
12500
12501 QueryPos qPos = QueryPos.getInstance(q);
12502
12503 qPos.add(groupId);
12504
12505 qPos.add(categoryId);
12506
12507 qPos.add(threadId);
12508
12509 count = (Long)q.uniqueResult();
12510
12511 FinderCacheUtil.putResult(finderPath, finderArgs, count);
12512 }
12513 catch (Exception e) {
12514 FinderCacheUtil.removeResult(finderPath, finderArgs);
12515
12516 throw processException(e);
12517 }
12518 finally {
12519 closeSession(session);
12520 }
12521 }
12522
12523 return count.intValue();
12524 }
12525
12526
12535 public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
12536 throws SystemException {
12537 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12538 return countByG_C_T(groupId, categoryId, threadId);
12539 }
12540
12541 StringBundler query = new StringBundler(4);
12542
12543 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12544
12545 query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12546
12547 query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12548
12549 query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12550
12551 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12552 MBMessage.class.getName(),
12553 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12554
12555 Session session = null;
12556
12557 try {
12558 session = openSession();
12559
12560 SQLQuery q = session.createSQLQuery(sql);
12561
12562 q.addScalar(COUNT_COLUMN_NAME,
12563 com.liferay.portal.kernel.dao.orm.Type.LONG);
12564
12565 QueryPos qPos = QueryPos.getInstance(q);
12566
12567 qPos.add(groupId);
12568
12569 qPos.add(categoryId);
12570
12571 qPos.add(threadId);
12572
12573 Long count = (Long)q.uniqueResult();
12574
12575 return count.intValue();
12576 }
12577 catch (Exception e) {
12578 throw processException(e);
12579 }
12580 finally {
12581 closeSession(session);
12582 }
12583 }
12584
12585 private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12586 private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12587 private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12588 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12589 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12590 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12591 new String[] {
12592 Long.class.getName(), Long.class.getName(),
12593 Integer.class.getName(),
12594
12595 Integer.class.getName(), Integer.class.getName(),
12596 OrderByComparator.class.getName()
12597 });
12598 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12599 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12600 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12601 new String[] {
12602 Long.class.getName(), Long.class.getName(),
12603 Integer.class.getName()
12604 },
12605 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12606 MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12607 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12608 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12609 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12610 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12611 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12612 new String[] {
12613 Long.class.getName(), Long.class.getName(),
12614 Integer.class.getName()
12615 });
12616
12617
12626 public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
12627 throws SystemException {
12628 return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12629 QueryUtil.ALL_POS, null);
12630 }
12631
12632
12647 public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12648 int status, int start, int end) throws SystemException {
12649 return findByG_C_S(groupId, categoryId, status, start, end, null);
12650 }
12651
12652
12668 public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12669 int status, int start, int end, OrderByComparator orderByComparator)
12670 throws SystemException {
12671 boolean pagination = true;
12672 FinderPath finderPath = null;
12673 Object[] finderArgs = null;
12674
12675 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12676 (orderByComparator == null)) {
12677 pagination = false;
12678 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
12679 finderArgs = new Object[] { groupId, categoryId, status };
12680 }
12681 else {
12682 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
12683 finderArgs = new Object[] {
12684 groupId, categoryId, status,
12685
12686 start, end, orderByComparator
12687 };
12688 }
12689
12690 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12691 finderArgs, this);
12692
12693 if ((list != null) && !list.isEmpty()) {
12694 for (MBMessage mbMessage : list) {
12695 if ((groupId != mbMessage.getGroupId()) ||
12696 (categoryId != mbMessage.getCategoryId()) ||
12697 (status != mbMessage.getStatus())) {
12698 list = null;
12699
12700 break;
12701 }
12702 }
12703 }
12704
12705 if (list == null) {
12706 StringBundler query = null;
12707
12708 if (orderByComparator != null) {
12709 query = new StringBundler(5 +
12710 (orderByComparator.getOrderByFields().length * 3));
12711 }
12712 else {
12713 query = new StringBundler(5);
12714 }
12715
12716 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12717
12718 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12719
12720 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12721
12722 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12723
12724 if (orderByComparator != null) {
12725 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12726 orderByComparator);
12727 }
12728 else
12729 if (pagination) {
12730 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12731 }
12732
12733 String sql = query.toString();
12734
12735 Session session = null;
12736
12737 try {
12738 session = openSession();
12739
12740 Query q = session.createQuery(sql);
12741
12742 QueryPos qPos = QueryPos.getInstance(q);
12743
12744 qPos.add(groupId);
12745
12746 qPos.add(categoryId);
12747
12748 qPos.add(status);
12749
12750 if (!pagination) {
12751 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12752 start, end, false);
12753
12754 Collections.sort(list);
12755
12756 list = new UnmodifiableList<MBMessage>(list);
12757 }
12758 else {
12759 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12760 start, end);
12761 }
12762
12763 cacheResult(list);
12764
12765 FinderCacheUtil.putResult(finderPath, finderArgs, list);
12766 }
12767 catch (Exception e) {
12768 FinderCacheUtil.removeResult(finderPath, finderArgs);
12769
12770 throw processException(e);
12771 }
12772 finally {
12773 closeSession(session);
12774 }
12775 }
12776
12777 return list;
12778 }
12779
12780
12791 public MBMessage findByG_C_S_First(long groupId, long categoryId,
12792 int status, OrderByComparator orderByComparator)
12793 throws NoSuchMessageException, SystemException {
12794 MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
12795 orderByComparator);
12796
12797 if (mbMessage != null) {
12798 return mbMessage;
12799 }
12800
12801 StringBundler msg = new StringBundler(8);
12802
12803 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12804
12805 msg.append("groupId=");
12806 msg.append(groupId);
12807
12808 msg.append(", categoryId=");
12809 msg.append(categoryId);
12810
12811 msg.append(", status=");
12812 msg.append(status);
12813
12814 msg.append(StringPool.CLOSE_CURLY_BRACE);
12815
12816 throw new NoSuchMessageException(msg.toString());
12817 }
12818
12819
12829 public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
12830 int status, OrderByComparator orderByComparator)
12831 throws SystemException {
12832 List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
12833 orderByComparator);
12834
12835 if (!list.isEmpty()) {
12836 return list.get(0);
12837 }
12838
12839 return null;
12840 }
12841
12842
12853 public MBMessage findByG_C_S_Last(long groupId, long categoryId,
12854 int status, OrderByComparator orderByComparator)
12855 throws NoSuchMessageException, SystemException {
12856 MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
12857 orderByComparator);
12858
12859 if (mbMessage != null) {
12860 return mbMessage;
12861 }
12862
12863 StringBundler msg = new StringBundler(8);
12864
12865 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12866
12867 msg.append("groupId=");
12868 msg.append(groupId);
12869
12870 msg.append(", categoryId=");
12871 msg.append(categoryId);
12872
12873 msg.append(", status=");
12874 msg.append(status);
12875
12876 msg.append(StringPool.CLOSE_CURLY_BRACE);
12877
12878 throw new NoSuchMessageException(msg.toString());
12879 }
12880
12881
12891 public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
12892 int status, OrderByComparator orderByComparator)
12893 throws SystemException {
12894 int count = countByG_C_S(groupId, categoryId, status);
12895
12896 List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
12897 count - 1, count, orderByComparator);
12898
12899 if (!list.isEmpty()) {
12900 return list.get(0);
12901 }
12902
12903 return null;
12904 }
12905
12906
12918 public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
12919 long categoryId, int status, OrderByComparator orderByComparator)
12920 throws NoSuchMessageException, SystemException {
12921 MBMessage mbMessage = findByPrimaryKey(messageId);
12922
12923 Session session = null;
12924
12925 try {
12926 session = openSession();
12927
12928 MBMessage[] array = new MBMessageImpl[3];
12929
12930 array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12931 categoryId, status, orderByComparator, true);
12932
12933 array[1] = mbMessage;
12934
12935 array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12936 categoryId, status, orderByComparator, false);
12937
12938 return array;
12939 }
12940 catch (Exception e) {
12941 throw processException(e);
12942 }
12943 finally {
12944 closeSession(session);
12945 }
12946 }
12947
12948 protected MBMessage getByG_C_S_PrevAndNext(Session session,
12949 MBMessage mbMessage, long groupId, long categoryId, int status,
12950 OrderByComparator orderByComparator, boolean previous) {
12951 StringBundler query = null;
12952
12953 if (orderByComparator != null) {
12954 query = new StringBundler(6 +
12955 (orderByComparator.getOrderByFields().length * 6));
12956 }
12957 else {
12958 query = new StringBundler(3);
12959 }
12960
12961 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12962
12963 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12964
12965 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12966
12967 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12968
12969 if (orderByComparator != null) {
12970 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12971
12972 if (orderByConditionFields.length > 0) {
12973 query.append(WHERE_AND);
12974 }
12975
12976 for (int i = 0; i < orderByConditionFields.length; i++) {
12977 query.append(_ORDER_BY_ENTITY_ALIAS);
12978 query.append(orderByConditionFields[i]);
12979
12980 if ((i + 1) < orderByConditionFields.length) {
12981 if (orderByComparator.isAscending() ^ previous) {
12982 query.append(WHERE_GREATER_THAN_HAS_NEXT);
12983 }
12984 else {
12985 query.append(WHERE_LESSER_THAN_HAS_NEXT);
12986 }
12987 }
12988 else {
12989 if (orderByComparator.isAscending() ^ previous) {
12990 query.append(WHERE_GREATER_THAN);
12991 }
12992 else {
12993 query.append(WHERE_LESSER_THAN);
12994 }
12995 }
12996 }
12997
12998 query.append(ORDER_BY_CLAUSE);
12999
13000 String[] orderByFields = orderByComparator.getOrderByFields();
13001
13002 for (int i = 0; i < orderByFields.length; i++) {
13003 query.append(_ORDER_BY_ENTITY_ALIAS);
13004 query.append(orderByFields[i]);
13005
13006 if ((i + 1) < orderByFields.length) {
13007 if (orderByComparator.isAscending() ^ previous) {
13008 query.append(ORDER_BY_ASC_HAS_NEXT);
13009 }
13010 else {
13011 query.append(ORDER_BY_DESC_HAS_NEXT);
13012 }
13013 }
13014 else {
13015 if (orderByComparator.isAscending() ^ previous) {
13016 query.append(ORDER_BY_ASC);
13017 }
13018 else {
13019 query.append(ORDER_BY_DESC);
13020 }
13021 }
13022 }
13023 }
13024 else {
13025 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13026 }
13027
13028 String sql = query.toString();
13029
13030 Query q = session.createQuery(sql);
13031
13032 q.setFirstResult(0);
13033 q.setMaxResults(2);
13034
13035 QueryPos qPos = QueryPos.getInstance(q);
13036
13037 qPos.add(groupId);
13038
13039 qPos.add(categoryId);
13040
13041 qPos.add(status);
13042
13043 if (orderByComparator != null) {
13044 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13045
13046 for (Object value : values) {
13047 qPos.add(value);
13048 }
13049 }
13050
13051 List<MBMessage> list = q.list();
13052
13053 if (list.size() == 2) {
13054 return list.get(1);
13055 }
13056 else {
13057 return null;
13058 }
13059 }
13060
13061
13070 public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13071 int status) throws SystemException {
13072 return filterFindByG_C_S(groupId, categoryId, status,
13073 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13074 }
13075
13076
13091 public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13092 int status, int start, int end) throws SystemException {
13093 return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13094 }
13095
13096
13112 public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13113 int status, int start, int end, OrderByComparator orderByComparator)
13114 throws SystemException {
13115 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13116 return findByG_C_S(groupId, categoryId, status, start, end,
13117 orderByComparator);
13118 }
13119
13120 StringBundler query = null;
13121
13122 if (orderByComparator != null) {
13123 query = new StringBundler(5 +
13124 (orderByComparator.getOrderByFields().length * 3));
13125 }
13126 else {
13127 query = new StringBundler(5);
13128 }
13129
13130 if (getDB().isSupportsInlineDistinct()) {
13131 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13132 }
13133 else {
13134 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13135 }
13136
13137 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13138
13139 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13140
13141 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13142
13143 if (!getDB().isSupportsInlineDistinct()) {
13144 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13145 }
13146
13147 if (orderByComparator != null) {
13148 if (getDB().isSupportsInlineDistinct()) {
13149 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13150 orderByComparator);
13151 }
13152 else {
13153 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13154 orderByComparator);
13155 }
13156 }
13157 else {
13158 if (getDB().isSupportsInlineDistinct()) {
13159 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13160 }
13161 else {
13162 query.append(MBMessageModelImpl.ORDER_BY_SQL);
13163 }
13164 }
13165
13166 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13167 MBMessage.class.getName(),
13168 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13169
13170 Session session = null;
13171
13172 try {
13173 session = openSession();
13174
13175 SQLQuery q = session.createSQLQuery(sql);
13176
13177 if (getDB().isSupportsInlineDistinct()) {
13178 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13179 }
13180 else {
13181 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13182 }
13183
13184 QueryPos qPos = QueryPos.getInstance(q);
13185
13186 qPos.add(groupId);
13187
13188 qPos.add(categoryId);
13189
13190 qPos.add(status);
13191
13192 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13193 }
13194 catch (Exception e) {
13195 throw processException(e);
13196 }
13197 finally {
13198 closeSession(session);
13199 }
13200 }
13201
13202
13214 public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13215 long groupId, long categoryId, int status,
13216 OrderByComparator orderByComparator)
13217 throws NoSuchMessageException, SystemException {
13218 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13219 return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13220 status, orderByComparator);
13221 }
13222
13223 MBMessage mbMessage = findByPrimaryKey(messageId);
13224
13225 Session session = null;
13226
13227 try {
13228 session = openSession();
13229
13230 MBMessage[] array = new MBMessageImpl[3];
13231
13232 array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13233 groupId, categoryId, status, orderByComparator, true);
13234
13235 array[1] = mbMessage;
13236
13237 array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13238 groupId, categoryId, status, orderByComparator, false);
13239
13240 return array;
13241 }
13242 catch (Exception e) {
13243 throw processException(e);
13244 }
13245 finally {
13246 closeSession(session);
13247 }
13248 }
13249
13250 protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13251 MBMessage mbMessage, long groupId, long categoryId, int status,
13252 OrderByComparator orderByComparator, boolean previous) {
13253 StringBundler query = null;
13254
13255 if (orderByComparator != null) {
13256 query = new StringBundler(6 +
13257 (orderByComparator.getOrderByFields().length * 6));
13258 }
13259 else {
13260 query = new StringBundler(3);
13261 }
13262
13263 if (getDB().isSupportsInlineDistinct()) {
13264 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13265 }
13266 else {
13267 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13268 }
13269
13270 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13271
13272 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13273
13274 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13275
13276 if (!getDB().isSupportsInlineDistinct()) {
13277 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13278 }
13279
13280 if (orderByComparator != null) {
13281 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13282
13283 if (orderByConditionFields.length > 0) {
13284 query.append(WHERE_AND);
13285 }
13286
13287 for (int i = 0; i < orderByConditionFields.length; i++) {
13288 if (getDB().isSupportsInlineDistinct()) {
13289 query.append(_ORDER_BY_ENTITY_ALIAS);
13290 }
13291 else {
13292 query.append(_ORDER_BY_ENTITY_TABLE);
13293 }
13294
13295 query.append(orderByConditionFields[i]);
13296
13297 if ((i + 1) < orderByConditionFields.length) {
13298 if (orderByComparator.isAscending() ^ previous) {
13299 query.append(WHERE_GREATER_THAN_HAS_NEXT);
13300 }
13301 else {
13302 query.append(WHERE_LESSER_THAN_HAS_NEXT);
13303 }
13304 }
13305 else {
13306 if (orderByComparator.isAscending() ^ previous) {
13307 query.append(WHERE_GREATER_THAN);
13308 }
13309 else {
13310 query.append(WHERE_LESSER_THAN);
13311 }
13312 }
13313 }
13314
13315 query.append(ORDER_BY_CLAUSE);
13316
13317 String[] orderByFields = orderByComparator.getOrderByFields();
13318
13319 for (int i = 0; i < orderByFields.length; i++) {
13320 if (getDB().isSupportsInlineDistinct()) {
13321 query.append(_ORDER_BY_ENTITY_ALIAS);
13322 }
13323 else {
13324 query.append(_ORDER_BY_ENTITY_TABLE);
13325 }
13326
13327 query.append(orderByFields[i]);
13328
13329 if ((i + 1) < orderByFields.length) {
13330 if (orderByComparator.isAscending() ^ previous) {
13331 query.append(ORDER_BY_ASC_HAS_NEXT);
13332 }
13333 else {
13334 query.append(ORDER_BY_DESC_HAS_NEXT);
13335 }
13336 }
13337 else {
13338 if (orderByComparator.isAscending() ^ previous) {
13339 query.append(ORDER_BY_ASC);
13340 }
13341 else {
13342 query.append(ORDER_BY_DESC);
13343 }
13344 }
13345 }
13346 }
13347 else {
13348 if (getDB().isSupportsInlineDistinct()) {
13349 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13350 }
13351 else {
13352 query.append(MBMessageModelImpl.ORDER_BY_SQL);
13353 }
13354 }
13355
13356 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13357 MBMessage.class.getName(),
13358 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13359
13360 SQLQuery q = session.createSQLQuery(sql);
13361
13362 q.setFirstResult(0);
13363 q.setMaxResults(2);
13364
13365 if (getDB().isSupportsInlineDistinct()) {
13366 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13367 }
13368 else {
13369 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13370 }
13371
13372 QueryPos qPos = QueryPos.getInstance(q);
13373
13374 qPos.add(groupId);
13375
13376 qPos.add(categoryId);
13377
13378 qPos.add(status);
13379
13380 if (orderByComparator != null) {
13381 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13382
13383 for (Object value : values) {
13384 qPos.add(value);
13385 }
13386 }
13387
13388 List<MBMessage> list = q.list();
13389
13390 if (list.size() == 2) {
13391 return list.get(1);
13392 }
13393 else {
13394 return null;
13395 }
13396 }
13397
13398
13406 public void removeByG_C_S(long groupId, long categoryId, int status)
13407 throws SystemException {
13408 for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13409 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13410 remove(mbMessage);
13411 }
13412 }
13413
13414
13423 public int countByG_C_S(long groupId, long categoryId, int status)
13424 throws SystemException {
13425 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13426
13427 Object[] finderArgs = new Object[] { groupId, categoryId, status };
13428
13429 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13430 this);
13431
13432 if (count == null) {
13433 StringBundler query = new StringBundler(4);
13434
13435 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13436
13437 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13438
13439 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13440
13441 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13442
13443 String sql = query.toString();
13444
13445 Session session = null;
13446
13447 try {
13448 session = openSession();
13449
13450 Query q = session.createQuery(sql);
13451
13452 QueryPos qPos = QueryPos.getInstance(q);
13453
13454 qPos.add(groupId);
13455
13456 qPos.add(categoryId);
13457
13458 qPos.add(status);
13459
13460 count = (Long)q.uniqueResult();
13461
13462 FinderCacheUtil.putResult(finderPath, finderArgs, count);
13463 }
13464 catch (Exception e) {
13465 FinderCacheUtil.removeResult(finderPath, finderArgs);
13466
13467 throw processException(e);
13468 }
13469 finally {
13470 closeSession(session);
13471 }
13472 }
13473
13474 return count.intValue();
13475 }
13476
13477
13486 public int filterCountByG_C_S(long groupId, long categoryId, int status)
13487 throws SystemException {
13488 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13489 return countByG_C_S(groupId, categoryId, status);
13490 }
13491
13492 StringBundler query = new StringBundler(4);
13493
13494 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13495
13496 query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13497
13498 query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13499
13500 query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13501
13502 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13503 MBMessage.class.getName(),
13504 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13505
13506 Session session = null;
13507
13508 try {
13509 session = openSession();
13510
13511 SQLQuery q = session.createSQLQuery(sql);
13512
13513 q.addScalar(COUNT_COLUMN_NAME,
13514 com.liferay.portal.kernel.dao.orm.Type.LONG);
13515
13516 QueryPos qPos = QueryPos.getInstance(q);
13517
13518 qPos.add(groupId);
13519
13520 qPos.add(categoryId);
13521
13522 qPos.add(status);
13523
13524 Long count = (Long)q.uniqueResult();
13525
13526 return count.intValue();
13527 }
13528 catch (Exception e) {
13529 throw processException(e);
13530 }
13531 finally {
13532 closeSession(session);
13533 }
13534 }
13535
13536 private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13537 private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13538 private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13539 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13540 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13541 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13542 new String[] {
13543 Long.class.getName(), Long.class.getName(), Long.class.getName(),
13544
13545 Integer.class.getName(), Integer.class.getName(),
13546 OrderByComparator.class.getName()
13547 });
13548 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13549 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13550 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13551 new String[] {
13552 Long.class.getName(), Long.class.getName(), Long.class.getName()
13553 },
13554 MBMessageModelImpl.USERID_COLUMN_BITMASK |
13555 MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13556 MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13557 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13558 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13559 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13560 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13561 new String[] {
13562 Long.class.getName(), Long.class.getName(), Long.class.getName()
13563 });
13564
13565
13574 public List<MBMessage> findByU_C_C(long userId, long classNameId,
13575 long classPK) throws SystemException {
13576 return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13577 QueryUtil.ALL_POS, null);
13578 }
13579
13580
13595 public List<MBMessage> findByU_C_C(long userId, long classNameId,
13596 long classPK, int start, int end) throws SystemException {
13597 return findByU_C_C(userId, classNameId, classPK, start, end, null);
13598 }
13599
13600
13616 public List<MBMessage> findByU_C_C(long userId, long classNameId,
13617 long classPK, int start, int end, OrderByComparator orderByComparator)
13618 throws SystemException {
13619 boolean pagination = true;
13620 FinderPath finderPath = null;
13621 Object[] finderArgs = null;
13622
13623 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13624 (orderByComparator == null)) {
13625 pagination = false;
13626 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13627 finderArgs = new Object[] { userId, classNameId, classPK };
13628 }
13629 else {
13630 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13631 finderArgs = new Object[] {
13632 userId, classNameId, classPK,
13633
13634 start, end, orderByComparator
13635 };
13636 }
13637
13638 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13639 finderArgs, this);
13640
13641 if ((list != null) && !list.isEmpty()) {
13642 for (MBMessage mbMessage : list) {
13643 if ((userId != mbMessage.getUserId()) ||
13644 (classNameId != mbMessage.getClassNameId()) ||
13645 (classPK != mbMessage.getClassPK())) {
13646 list = null;
13647
13648 break;
13649 }
13650 }
13651 }
13652
13653 if (list == null) {
13654 StringBundler query = null;
13655
13656 if (orderByComparator != null) {
13657 query = new StringBundler(5 +
13658 (orderByComparator.getOrderByFields().length * 3));
13659 }
13660 else {
13661 query = new StringBundler(5);
13662 }
13663
13664 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13665
13666 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13667
13668 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13669
13670 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13671
13672 if (orderByComparator != null) {
13673 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13674 orderByComparator);
13675 }
13676 else
13677 if (pagination) {
13678 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13679 }
13680
13681 String sql = query.toString();
13682
13683 Session session = null;
13684
13685 try {
13686 session = openSession();
13687
13688 Query q = session.createQuery(sql);
13689
13690 QueryPos qPos = QueryPos.getInstance(q);
13691
13692 qPos.add(userId);
13693
13694 qPos.add(classNameId);
13695
13696 qPos.add(classPK);
13697
13698 if (!pagination) {
13699 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13700 start, end, false);
13701
13702 Collections.sort(list);
13703
13704 list = new UnmodifiableList<MBMessage>(list);
13705 }
13706 else {
13707 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13708 start, end);
13709 }
13710
13711 cacheResult(list);
13712
13713 FinderCacheUtil.putResult(finderPath, finderArgs, list);
13714 }
13715 catch (Exception e) {
13716 FinderCacheUtil.removeResult(finderPath, finderArgs);
13717
13718 throw processException(e);
13719 }
13720 finally {
13721 closeSession(session);
13722 }
13723 }
13724
13725 return list;
13726 }
13727
13728
13739 public MBMessage findByU_C_C_First(long userId, long classNameId,
13740 long classPK, OrderByComparator orderByComparator)
13741 throws NoSuchMessageException, SystemException {
13742 MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
13743 orderByComparator);
13744
13745 if (mbMessage != null) {
13746 return mbMessage;
13747 }
13748
13749 StringBundler msg = new StringBundler(8);
13750
13751 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13752
13753 msg.append("userId=");
13754 msg.append(userId);
13755
13756 msg.append(", classNameId=");
13757 msg.append(classNameId);
13758
13759 msg.append(", classPK=");
13760 msg.append(classPK);
13761
13762 msg.append(StringPool.CLOSE_CURLY_BRACE);
13763
13764 throw new NoSuchMessageException(msg.toString());
13765 }
13766
13767
13777 public MBMessage fetchByU_C_C_First(long userId, long classNameId,
13778 long classPK, OrderByComparator orderByComparator)
13779 throws SystemException {
13780 List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
13781 orderByComparator);
13782
13783 if (!list.isEmpty()) {
13784 return list.get(0);
13785 }
13786
13787 return null;
13788 }
13789
13790
13801 public MBMessage findByU_C_C_Last(long userId, long classNameId,
13802 long classPK, OrderByComparator orderByComparator)
13803 throws NoSuchMessageException, SystemException {
13804 MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
13805 orderByComparator);
13806
13807 if (mbMessage != null) {
13808 return mbMessage;
13809 }
13810
13811 StringBundler msg = new StringBundler(8);
13812
13813 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13814
13815 msg.append("userId=");
13816 msg.append(userId);
13817
13818 msg.append(", classNameId=");
13819 msg.append(classNameId);
13820
13821 msg.append(", classPK=");
13822 msg.append(classPK);
13823
13824 msg.append(StringPool.CLOSE_CURLY_BRACE);
13825
13826 throw new NoSuchMessageException(msg.toString());
13827 }
13828
13829
13839 public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
13840 long classPK, OrderByComparator orderByComparator)
13841 throws SystemException {
13842 int count = countByU_C_C(userId, classNameId, classPK);
13843
13844 List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
13845 count - 1, count, orderByComparator);
13846
13847 if (!list.isEmpty()) {
13848 return list.get(0);
13849 }
13850
13851 return null;
13852 }
13853
13854
13866 public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
13867 long classNameId, long classPK, OrderByComparator orderByComparator)
13868 throws NoSuchMessageException, SystemException {
13869 MBMessage mbMessage = findByPrimaryKey(messageId);
13870
13871 Session session = null;
13872
13873 try {
13874 session = openSession();
13875
13876 MBMessage[] array = new MBMessageImpl[3];
13877
13878 array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13879 classNameId, classPK, orderByComparator, true);
13880
13881 array[1] = mbMessage;
13882
13883 array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13884 classNameId, classPK, orderByComparator, false);
13885
13886 return array;
13887 }
13888 catch (Exception e) {
13889 throw processException(e);
13890 }
13891 finally {
13892 closeSession(session);
13893 }
13894 }
13895
13896 protected MBMessage getByU_C_C_PrevAndNext(Session session,
13897 MBMessage mbMessage, long userId, long classNameId, long classPK,
13898 OrderByComparator orderByComparator, boolean previous) {
13899 StringBundler query = null;
13900
13901 if (orderByComparator != null) {
13902 query = new StringBundler(6 +
13903 (orderByComparator.getOrderByFields().length * 6));
13904 }
13905 else {
13906 query = new StringBundler(3);
13907 }
13908
13909 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13910
13911 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13912
13913 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13914
13915 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13916
13917 if (orderByComparator != null) {
13918 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13919
13920 if (orderByConditionFields.length > 0) {
13921 query.append(WHERE_AND);
13922 }
13923
13924 for (int i = 0; i < orderByConditionFields.length; i++) {
13925 query.append(_ORDER_BY_ENTITY_ALIAS);
13926 query.append(orderByConditionFields[i]);
13927
13928 if ((i + 1) < orderByConditionFields.length) {
13929 if (orderByComparator.isAscending() ^ previous) {
13930 query.append(WHERE_GREATER_THAN_HAS_NEXT);
13931 }
13932 else {
13933 query.append(WHERE_LESSER_THAN_HAS_NEXT);
13934 }
13935 }
13936 else {
13937 if (orderByComparator.isAscending() ^ previous) {
13938 query.append(WHERE_GREATER_THAN);
13939 }
13940 else {
13941 query.append(WHERE_LESSER_THAN);
13942 }
13943 }
13944 }
13945
13946 query.append(ORDER_BY_CLAUSE);
13947
13948 String[] orderByFields = orderByComparator.getOrderByFields();
13949
13950 for (int i = 0; i < orderByFields.length; i++) {
13951 query.append(_ORDER_BY_ENTITY_ALIAS);
13952 query.append(orderByFields[i]);
13953
13954 if ((i + 1) < orderByFields.length) {
13955 if (orderByComparator.isAscending() ^ previous) {
13956 query.append(ORDER_BY_ASC_HAS_NEXT);
13957 }
13958 else {
13959 query.append(ORDER_BY_DESC_HAS_NEXT);
13960 }
13961 }
13962 else {
13963 if (orderByComparator.isAscending() ^ previous) {
13964 query.append(ORDER_BY_ASC);
13965 }
13966 else {
13967 query.append(ORDER_BY_DESC);
13968 }
13969 }
13970 }
13971 }
13972 else {
13973 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13974 }
13975
13976 String sql = query.toString();
13977
13978 Query q = session.createQuery(sql);
13979
13980 q.setFirstResult(0);
13981 q.setMaxResults(2);
13982
13983 QueryPos qPos = QueryPos.getInstance(q);
13984
13985 qPos.add(userId);
13986
13987 qPos.add(classNameId);
13988
13989 qPos.add(classPK);
13990
13991 if (orderByComparator != null) {
13992 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13993
13994 for (Object value : values) {
13995 qPos.add(value);
13996 }
13997 }
13998
13999 List<MBMessage> list = q.list();
14000
14001 if (list.size() == 2) {
14002 return list.get(1);
14003 }
14004 else {
14005 return null;
14006 }
14007 }
14008
14009
14017 public void removeByU_C_C(long userId, long classNameId, long classPK)
14018 throws SystemException {
14019 for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14020 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14021 remove(mbMessage);
14022 }
14023 }
14024
14025
14034 public int countByU_C_C(long userId, long classNameId, long classPK)
14035 throws SystemException {
14036 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14037
14038 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14039
14040 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14041 this);
14042
14043 if (count == null) {
14044 StringBundler query = new StringBundler(4);
14045
14046 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14047
14048 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14049
14050 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14051
14052 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14053
14054 String sql = query.toString();
14055
14056 Session session = null;
14057
14058 try {
14059 session = openSession();
14060
14061 Query q = session.createQuery(sql);
14062
14063 QueryPos qPos = QueryPos.getInstance(q);
14064
14065 qPos.add(userId);
14066
14067 qPos.add(classNameId);
14068
14069 qPos.add(classPK);
14070
14071 count = (Long)q.uniqueResult();
14072
14073 FinderCacheUtil.putResult(finderPath, finderArgs, count);
14074 }
14075 catch (Exception e) {
14076 FinderCacheUtil.removeResult(finderPath, finderArgs);
14077
14078 throw processException(e);
14079 }
14080 finally {
14081 closeSession(session);
14082 }
14083 }
14084
14085 return count.intValue();
14086 }
14087
14088 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14089 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14090 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14092 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14093 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14094 new String[] {
14095 Long.class.getName(), Long.class.getName(),
14096 Integer.class.getName(),
14097
14098 Integer.class.getName(), Integer.class.getName(),
14099 OrderByComparator.class.getName()
14100 });
14101 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14102 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14104 new String[] {
14105 Long.class.getName(), Long.class.getName(),
14106 Integer.class.getName()
14107 },
14108 MBMessageModelImpl.USERID_COLUMN_BITMASK |
14109 MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14110 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14111 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14112 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14113 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14114 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14115 new String[] {
14116 Long.class.getName(), Long.class.getName(),
14117 Integer.class.getName()
14118 });
14119 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14120 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14121 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14122 new String[] {
14123 Long.class.getName(), Long.class.getName(),
14124 Integer.class.getName()
14125 });
14126
14127
14136 public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
14137 throws SystemException {
14138 return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14139 QueryUtil.ALL_POS, null);
14140 }
14141
14142
14157 public List<MBMessage> findByU_C_S(long userId, long classNameId,
14158 int status, int start, int end) throws SystemException {
14159 return findByU_C_S(userId, classNameId, status, start, end, null);
14160 }
14161
14162
14178 public List<MBMessage> findByU_C_S(long userId, long classNameId,
14179 int status, int start, int end, OrderByComparator orderByComparator)
14180 throws SystemException {
14181 boolean pagination = true;
14182 FinderPath finderPath = null;
14183 Object[] finderArgs = null;
14184
14185 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14186 (orderByComparator == null)) {
14187 pagination = false;
14188 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14189 finderArgs = new Object[] { userId, classNameId, status };
14190 }
14191 else {
14192 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14193 finderArgs = new Object[] {
14194 userId, classNameId, status,
14195
14196 start, end, orderByComparator
14197 };
14198 }
14199
14200 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14201 finderArgs, this);
14202
14203 if ((list != null) && !list.isEmpty()) {
14204 for (MBMessage mbMessage : list) {
14205 if ((userId != mbMessage.getUserId()) ||
14206 (classNameId != mbMessage.getClassNameId()) ||
14207 (status != mbMessage.getStatus())) {
14208 list = null;
14209
14210 break;
14211 }
14212 }
14213 }
14214
14215 if (list == null) {
14216 StringBundler query = null;
14217
14218 if (orderByComparator != null) {
14219 query = new StringBundler(5 +
14220 (orderByComparator.getOrderByFields().length * 3));
14221 }
14222 else {
14223 query = new StringBundler(5);
14224 }
14225
14226 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14227
14228 query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14229
14230 query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14231
14232 query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14233
14234 if (orderByComparator != null) {
14235 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14236 orderByComparator);
14237 }
14238 else
14239 if (pagination) {
14240 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14241 }
14242
14243 String sql = query.toString();
14244
14245 Session session = null;
14246
14247 try {
14248 session = openSession();
14249
14250 Query q = session.createQuery(sql);
14251
14252 QueryPos qPos = QueryPos.getInstance(q);
14253
14254 qPos.add(userId);
14255
14256 qPos.add(classNameId);
14257
14258 qPos.add(status);
14259
14260 if (!pagination) {
14261 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14262 start, end, false);
14263
14264 Collections.sort(list);
14265
14266 list = new UnmodifiableList<MBMessage>(list);
14267 }
14268 else {
14269 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14270 start, end);
14271 }
14272
14273 cacheResult(list);
14274
14275 FinderCacheUtil.putResult(finderPath, finderArgs, list);
14276 }
14277 catch (Exception e) {
14278 FinderCacheUtil.removeResult(finderPath, finderArgs);
14279
14280 throw processException(e);
14281 }
14282 finally {
14283 closeSession(session);
14284 }
14285 }
14286
14287 return list;
14288 }
14289
14290
14301 public MBMessage findByU_C_S_First(long userId, long classNameId,
14302 int status, OrderByComparator orderByComparator)
14303 throws NoSuchMessageException, SystemException {
14304 MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14305 orderByComparator);
14306
14307 if (mbMessage != null) {
14308 return mbMessage;
14309 }
14310
14311 StringBundler msg = new StringBundler(8);
14312
14313 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14314
14315 msg.append("userId=");
14316 msg.append(userId);
14317
14318 msg.append(", classNameId=");
14319 msg.append(classNameId);
14320
14321 msg.append(", status=");
14322 msg.append(status);
14323
14324 msg.append(StringPool.CLOSE_CURLY_BRACE);
14325
14326 throw new NoSuchMessageException(msg.toString());
14327 }
14328
14329
14339 public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14340 int status, OrderByComparator orderByComparator)
14341 throws SystemException {
14342 List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14343 orderByComparator);
14344
14345 if (!list.isEmpty()) {
14346 return list.get(0);
14347 }
14348
14349 return null;
14350 }
14351
14352
14363 public MBMessage findByU_C_S_Last(long userId, long classNameId,
14364 int status, OrderByComparator orderByComparator)
14365 throws NoSuchMessageException, SystemException {
14366 MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14367 orderByComparator);
14368
14369 if (mbMessage != null) {
14370 return mbMessage;
14371 }
14372
14373 StringBundler msg = new StringBundler(8);
14374
14375 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14376
14377 msg.append("userId=");
14378 msg.append(userId);
14379
14380 msg.append(", classNameId=");
14381 msg.append(classNameId);
14382
14383 msg.append(", status=");
14384 msg.append(status);
14385
14386 msg.append(StringPool.CLOSE_CURLY_BRACE);
14387
14388 throw new NoSuchMessageException(msg.toString());
14389 }
14390
14391
14401 public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14402 int status, OrderByComparator orderByComparator)
14403 throws SystemException {
14404 int count = countByU_C_S(userId, classNameId, status);
14405
14406 List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14407 count - 1, count, orderByComparator);
14408
14409 if (!list.isEmpty()) {
14410 return list.get(0);
14411 }
14412
14413 return null;
14414 }
14415
14416
14428 public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14429 long classNameId, int status, OrderByComparator orderByComparator)
14430 throws NoSuchMessageException, SystemException {
14431 MBMessage mbMessage = findByPrimaryKey(messageId);
14432
14433 Session session = null;
14434
14435 try {
14436 session = openSession();
14437
14438 MBMessage[] array = new MBMessageImpl[3];
14439
14440 array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14441 classNameId, status, orderByComparator, true);
14442
14443 array[1] = mbMessage;
14444
14445 array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14446 classNameId, status, orderByComparator, false);
14447
14448 return array;
14449 }
14450 catch (Exception e) {
14451 throw processException(e);
14452 }
14453 finally {
14454 closeSession(session);
14455 }
14456 }
14457
14458 protected MBMessage getByU_C_S_PrevAndNext(Session session,
14459 MBMessage mbMessage, long userId, long classNameId, int status,
14460 OrderByComparator orderByComparator, boolean previous) {
14461 StringBundler query = null;
14462
14463 if (orderByComparator != null) {
14464 query = new StringBundler(6 +
14465 (orderByComparator.getOrderByFields().length * 6));
14466 }
14467 else {
14468 query = new StringBundler(3);
14469 }
14470
14471 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14472
14473 query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14474
14475 query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14476
14477 query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14478
14479 if (orderByComparator != null) {
14480 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14481
14482 if (orderByConditionFields.length > 0) {
14483 query.append(WHERE_AND);
14484 }
14485
14486 for (int i = 0; i < orderByConditionFields.length; i++) {
14487 query.append(_ORDER_BY_ENTITY_ALIAS);
14488 query.append(orderByConditionFields[i]);
14489
14490 if ((i + 1) < orderByConditionFields.length) {
14491 if (orderByComparator.isAscending() ^ previous) {
14492 query.append(WHERE_GREATER_THAN_HAS_NEXT);
14493 }
14494 else {
14495 query.append(WHERE_LESSER_THAN_HAS_NEXT);
14496 }
14497 }
14498 else {
14499 if (orderByComparator.isAscending() ^ previous) {
14500 query.append(WHERE_GREATER_THAN);
14501 }
14502 else {
14503 query.append(WHERE_LESSER_THAN);
14504 }
14505 }
14506 }
14507
14508 query.append(ORDER_BY_CLAUSE);
14509
14510 String[] orderByFields = orderByComparator.getOrderByFields();
14511
14512 for (int i = 0; i < orderByFields.length; i++) {
14513 query.append(_ORDER_BY_ENTITY_ALIAS);
14514 query.append(orderByFields[i]);
14515
14516 if ((i + 1) < orderByFields.length) {
14517 if (orderByComparator.isAscending() ^ previous) {
14518 query.append(ORDER_BY_ASC_HAS_NEXT);
14519 }
14520 else {
14521 query.append(ORDER_BY_DESC_HAS_NEXT);
14522 }
14523 }
14524 else {
14525 if (orderByComparator.isAscending() ^ previous) {
14526 query.append(ORDER_BY_ASC);
14527 }
14528 else {
14529 query.append(ORDER_BY_DESC);
14530 }
14531 }
14532 }
14533 }
14534 else {
14535 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14536 }
14537
14538 String sql = query.toString();
14539
14540 Query q = session.createQuery(sql);
14541
14542 q.setFirstResult(0);
14543 q.setMaxResults(2);
14544
14545 QueryPos qPos = QueryPos.getInstance(q);
14546
14547 qPos.add(userId);
14548
14549 qPos.add(classNameId);
14550
14551 qPos.add(status);
14552
14553 if (orderByComparator != null) {
14554 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14555
14556 for (Object value : values) {
14557 qPos.add(value);
14558 }
14559 }
14560
14561 List<MBMessage> list = q.list();
14562
14563 if (list.size() == 2) {
14564 return list.get(1);
14565 }
14566 else {
14567 return null;
14568 }
14569 }
14570
14571
14584 public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14585 int status) throws SystemException {
14586 return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14587 QueryUtil.ALL_POS, null);
14588 }
14589
14590
14605 public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14606 int status, int start, int end) throws SystemException {
14607 return findByU_C_S(userId, classNameIds, status, start, end, null);
14608 }
14609
14610
14626 public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14627 int status, int start, int end, OrderByComparator orderByComparator)
14628 throws SystemException {
14629 if ((classNameIds != null) && (classNameIds.length == 1)) {
14630 return findByU_C_S(userId, classNameIds[0], status, start, end,
14631 orderByComparator);
14632 }
14633
14634 boolean pagination = true;
14635 Object[] finderArgs = null;
14636
14637 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14638 (orderByComparator == null)) {
14639 pagination = false;
14640 finderArgs = new Object[] {
14641 userId, StringUtil.merge(classNameIds), status
14642 };
14643 }
14644 else {
14645 finderArgs = new Object[] {
14646 userId, StringUtil.merge(classNameIds), status,
14647
14648 start, end, orderByComparator
14649 };
14650 }
14651
14652 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14653 finderArgs, this);
14654
14655 if ((list != null) && !list.isEmpty()) {
14656 for (MBMessage mbMessage : list) {
14657 if ((userId != mbMessage.getUserId()) ||
14658 !ArrayUtil.contains(classNameIds,
14659 mbMessage.getClassNameId()) ||
14660 (status != mbMessage.getStatus())) {
14661 list = null;
14662
14663 break;
14664 }
14665 }
14666 }
14667
14668 if (list == null) {
14669 StringBundler query = new StringBundler();
14670
14671 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14672
14673 boolean conjunctionable = false;
14674
14675 if (conjunctionable) {
14676 query.append(WHERE_AND);
14677 }
14678
14679 query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14680
14681 conjunctionable = true;
14682
14683 if ((classNameIds == null) || (classNameIds.length > 0)) {
14684 if (conjunctionable) {
14685 query.append(WHERE_AND);
14686 }
14687
14688 query.append(StringPool.OPEN_PARENTHESIS);
14689
14690 for (int i = 0; i < classNameIds.length; i++) {
14691 query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14692
14693 if ((i + 1) < classNameIds.length) {
14694 query.append(WHERE_OR);
14695 }
14696 }
14697
14698 query.append(StringPool.CLOSE_PARENTHESIS);
14699
14700 conjunctionable = true;
14701 }
14702
14703 if (conjunctionable) {
14704 query.append(WHERE_AND);
14705 }
14706
14707 query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14708
14709 conjunctionable = true;
14710
14711 if (orderByComparator != null) {
14712 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14713 orderByComparator);
14714 }
14715 else
14716 if (pagination) {
14717 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14718 }
14719
14720 String sql = query.toString();
14721
14722 Session session = null;
14723
14724 try {
14725 session = openSession();
14726
14727 Query q = session.createQuery(sql);
14728
14729 QueryPos qPos = QueryPos.getInstance(q);
14730
14731 qPos.add(userId);
14732
14733 if (classNameIds != null) {
14734 qPos.add(classNameIds);
14735 }
14736
14737 qPos.add(status);
14738
14739 if (!pagination) {
14740 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14741 start, end, false);
14742
14743 Collections.sort(list);
14744
14745 list = new UnmodifiableList<MBMessage>(list);
14746 }
14747 else {
14748 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14749 start, end);
14750 }
14751
14752 cacheResult(list);
14753
14754 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14755 finderArgs, list);
14756 }
14757 catch (Exception e) {
14758 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14759 finderArgs);
14760
14761 throw processException(e);
14762 }
14763 finally {
14764 closeSession(session);
14765 }
14766 }
14767
14768 return list;
14769 }
14770
14771
14779 public void removeByU_C_S(long userId, long classNameId, int status)
14780 throws SystemException {
14781 for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
14782 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14783 remove(mbMessage);
14784 }
14785 }
14786
14787
14796 public int countByU_C_S(long userId, long classNameId, int status)
14797 throws SystemException {
14798 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
14799
14800 Object[] finderArgs = new Object[] { userId, classNameId, status };
14801
14802 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14803 this);
14804
14805 if (count == null) {
14806 StringBundler query = new StringBundler(4);
14807
14808 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14809
14810 query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14811
14812 query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14813
14814 query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14815
14816 String sql = query.toString();
14817
14818 Session session = null;
14819
14820 try {
14821 session = openSession();
14822
14823 Query q = session.createQuery(sql);
14824
14825 QueryPos qPos = QueryPos.getInstance(q);
14826
14827 qPos.add(userId);
14828
14829 qPos.add(classNameId);
14830
14831 qPos.add(status);
14832
14833 count = (Long)q.uniqueResult();
14834
14835 FinderCacheUtil.putResult(finderPath, finderArgs, count);
14836 }
14837 catch (Exception e) {
14838 FinderCacheUtil.removeResult(finderPath, finderArgs);
14839
14840 throw processException(e);
14841 }
14842 finally {
14843 closeSession(session);
14844 }
14845 }
14846
14847 return count.intValue();
14848 }
14849
14850
14859 public int countByU_C_S(long userId, long[] classNameIds, int status)
14860 throws SystemException {
14861 Object[] finderArgs = new Object[] {
14862 userId, StringUtil.merge(classNameIds), status
14863 };
14864
14865 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14866 finderArgs, this);
14867
14868 if (count == null) {
14869 StringBundler query = new StringBundler();
14870
14871 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14872
14873 boolean conjunctionable = false;
14874
14875 if (conjunctionable) {
14876 query.append(WHERE_AND);
14877 }
14878
14879 query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14880
14881 conjunctionable = true;
14882
14883 if ((classNameIds == null) || (classNameIds.length > 0)) {
14884 if (conjunctionable) {
14885 query.append(WHERE_AND);
14886 }
14887
14888 query.append(StringPool.OPEN_PARENTHESIS);
14889
14890 for (int i = 0; i < classNameIds.length; i++) {
14891 query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14892
14893 if ((i + 1) < classNameIds.length) {
14894 query.append(WHERE_OR);
14895 }
14896 }
14897
14898 query.append(StringPool.CLOSE_PARENTHESIS);
14899
14900 conjunctionable = true;
14901 }
14902
14903 if (conjunctionable) {
14904 query.append(WHERE_AND);
14905 }
14906
14907 query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14908
14909 conjunctionable = true;
14910
14911 String sql = query.toString();
14912
14913 Session session = null;
14914
14915 try {
14916 session = openSession();
14917
14918 Query q = session.createQuery(sql);
14919
14920 QueryPos qPos = QueryPos.getInstance(q);
14921
14922 qPos.add(userId);
14923
14924 if (classNameIds != null) {
14925 qPos.add(classNameIds);
14926 }
14927
14928 qPos.add(status);
14929
14930 count = (Long)q.uniqueResult();
14931
14932 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14933 finderArgs, count);
14934 }
14935 catch (Exception e) {
14936 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14937 finderArgs);
14938
14939 throw processException(e);
14940 }
14941 finally {
14942 closeSession(session);
14943 }
14944 }
14945
14946 return count.intValue();
14947 }
14948
14949 private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
14950 private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
14951 _removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
14952 private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14953 private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
14954 _removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
14955 private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
14956 private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
14957 _removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
14958 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14959 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14960 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
14961 new String[] {
14962 Long.class.getName(), Long.class.getName(),
14963 Integer.class.getName(),
14964
14965 Integer.class.getName(), Integer.class.getName(),
14966 OrderByComparator.class.getName()
14967 });
14968 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14969 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14970 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
14971 new String[] {
14972 Long.class.getName(), Long.class.getName(),
14973 Integer.class.getName()
14974 },
14975 MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14976 MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14977 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14978 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14979 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14980 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14981 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
14982 new String[] {
14983 Long.class.getName(), Long.class.getName(),
14984 Integer.class.getName()
14985 });
14986
14987
14996 public List<MBMessage> findByC_C_S(long classNameId, long classPK,
14997 int status) throws SystemException {
14998 return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
14999 QueryUtil.ALL_POS, null);
15000 }
15001
15002
15017 public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15018 int status, int start, int end) throws SystemException {
15019 return findByC_C_S(classNameId, classPK, status, start, end, null);
15020 }
15021
15022
15038 public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15039 int status, int start, int end, OrderByComparator orderByComparator)
15040 throws SystemException {
15041 boolean pagination = true;
15042 FinderPath finderPath = null;
15043 Object[] finderArgs = null;
15044
15045 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15046 (orderByComparator == null)) {
15047 pagination = false;
15048 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15049 finderArgs = new Object[] { classNameId, classPK, status };
15050 }
15051 else {
15052 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15053 finderArgs = new Object[] {
15054 classNameId, classPK, status,
15055
15056 start, end, orderByComparator
15057 };
15058 }
15059
15060 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15061 finderArgs, this);
15062
15063 if ((list != null) && !list.isEmpty()) {
15064 for (MBMessage mbMessage : list) {
15065 if ((classNameId != mbMessage.getClassNameId()) ||
15066 (classPK != mbMessage.getClassPK()) ||
15067 (status != mbMessage.getStatus())) {
15068 list = null;
15069
15070 break;
15071 }
15072 }
15073 }
15074
15075 if (list == null) {
15076 StringBundler query = null;
15077
15078 if (orderByComparator != null) {
15079 query = new StringBundler(5 +
15080 (orderByComparator.getOrderByFields().length * 3));
15081 }
15082 else {
15083 query = new StringBundler(5);
15084 }
15085
15086 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15087
15088 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15089
15090 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15091
15092 query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15093
15094 if (orderByComparator != null) {
15095 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15096 orderByComparator);
15097 }
15098 else
15099 if (pagination) {
15100 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15101 }
15102
15103 String sql = query.toString();
15104
15105 Session session = null;
15106
15107 try {
15108 session = openSession();
15109
15110 Query q = session.createQuery(sql);
15111
15112 QueryPos qPos = QueryPos.getInstance(q);
15113
15114 qPos.add(classNameId);
15115
15116 qPos.add(classPK);
15117
15118 qPos.add(status);
15119
15120 if (!pagination) {
15121 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15122 start, end, false);
15123
15124 Collections.sort(list);
15125
15126 list = new UnmodifiableList<MBMessage>(list);
15127 }
15128 else {
15129 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15130 start, end);
15131 }
15132
15133 cacheResult(list);
15134
15135 FinderCacheUtil.putResult(finderPath, finderArgs, list);
15136 }
15137 catch (Exception e) {
15138 FinderCacheUtil.removeResult(finderPath, finderArgs);
15139
15140 throw processException(e);
15141 }
15142 finally {
15143 closeSession(session);
15144 }
15145 }
15146
15147 return list;
15148 }
15149
15150
15161 public MBMessage findByC_C_S_First(long classNameId, long classPK,
15162 int status, OrderByComparator orderByComparator)
15163 throws NoSuchMessageException, SystemException {
15164 MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15165 orderByComparator);
15166
15167 if (mbMessage != null) {
15168 return mbMessage;
15169 }
15170
15171 StringBundler msg = new StringBundler(8);
15172
15173 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15174
15175 msg.append("classNameId=");
15176 msg.append(classNameId);
15177
15178 msg.append(", classPK=");
15179 msg.append(classPK);
15180
15181 msg.append(", status=");
15182 msg.append(status);
15183
15184 msg.append(StringPool.CLOSE_CURLY_BRACE);
15185
15186 throw new NoSuchMessageException(msg.toString());
15187 }
15188
15189
15199 public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15200 int status, OrderByComparator orderByComparator)
15201 throws SystemException {
15202 List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15203 orderByComparator);
15204
15205 if (!list.isEmpty()) {
15206 return list.get(0);
15207 }
15208
15209 return null;
15210 }
15211
15212
15223 public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15224 int status, OrderByComparator orderByComparator)
15225 throws NoSuchMessageException, SystemException {
15226 MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15227 orderByComparator);
15228
15229 if (mbMessage != null) {
15230 return mbMessage;
15231 }
15232
15233 StringBundler msg = new StringBundler(8);
15234
15235 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15236
15237 msg.append("classNameId=");
15238 msg.append(classNameId);
15239
15240 msg.append(", classPK=");
15241 msg.append(classPK);
15242
15243 msg.append(", status=");
15244 msg.append(status);
15245
15246 msg.append(StringPool.CLOSE_CURLY_BRACE);
15247
15248 throw new NoSuchMessageException(msg.toString());
15249 }
15250
15251
15261 public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15262 int status, OrderByComparator orderByComparator)
15263 throws SystemException {
15264 int count = countByC_C_S(classNameId, classPK, status);
15265
15266 List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15267 count - 1, count, orderByComparator);
15268
15269 if (!list.isEmpty()) {
15270 return list.get(0);
15271 }
15272
15273 return null;
15274 }
15275
15276
15288 public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15289 long classNameId, long classPK, int status,
15290 OrderByComparator orderByComparator)
15291 throws NoSuchMessageException, SystemException {
15292 MBMessage mbMessage = findByPrimaryKey(messageId);
15293
15294 Session session = null;
15295
15296 try {
15297 session = openSession();
15298
15299 MBMessage[] array = new MBMessageImpl[3];
15300
15301 array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15302 classPK, status, orderByComparator, true);
15303
15304 array[1] = mbMessage;
15305
15306 array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15307 classPK, status, orderByComparator, false);
15308
15309 return array;
15310 }
15311 catch (Exception e) {
15312 throw processException(e);
15313 }
15314 finally {
15315 closeSession(session);
15316 }
15317 }
15318
15319 protected MBMessage getByC_C_S_PrevAndNext(Session session,
15320 MBMessage mbMessage, long classNameId, long classPK, int status,
15321 OrderByComparator orderByComparator, boolean previous) {
15322 StringBundler query = null;
15323
15324 if (orderByComparator != null) {
15325 query = new StringBundler(6 +
15326 (orderByComparator.getOrderByFields().length * 6));
15327 }
15328 else {
15329 query = new StringBundler(3);
15330 }
15331
15332 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15333
15334 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15335
15336 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15337
15338 query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15339
15340 if (orderByComparator != null) {
15341 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15342
15343 if (orderByConditionFields.length > 0) {
15344 query.append(WHERE_AND);
15345 }
15346
15347 for (int i = 0; i < orderByConditionFields.length; i++) {
15348 query.append(_ORDER_BY_ENTITY_ALIAS);
15349 query.append(orderByConditionFields[i]);
15350
15351 if ((i + 1) < orderByConditionFields.length) {
15352 if (orderByComparator.isAscending() ^ previous) {
15353 query.append(WHERE_GREATER_THAN_HAS_NEXT);
15354 }
15355 else {
15356 query.append(WHERE_LESSER_THAN_HAS_NEXT);
15357 }
15358 }
15359 else {
15360 if (orderByComparator.isAscending() ^ previous) {
15361 query.append(WHERE_GREATER_THAN);
15362 }
15363 else {
15364 query.append(WHERE_LESSER_THAN);
15365 }
15366 }
15367 }
15368
15369 query.append(ORDER_BY_CLAUSE);
15370
15371 String[] orderByFields = orderByComparator.getOrderByFields();
15372
15373 for (int i = 0; i < orderByFields.length; i++) {
15374 query.append(_ORDER_BY_ENTITY_ALIAS);
15375 query.append(orderByFields[i]);
15376
15377 if ((i + 1) < orderByFields.length) {
15378 if (orderByComparator.isAscending() ^ previous) {
15379 query.append(ORDER_BY_ASC_HAS_NEXT);
15380 }
15381 else {
15382 query.append(ORDER_BY_DESC_HAS_NEXT);
15383 }
15384 }
15385 else {
15386 if (orderByComparator.isAscending() ^ previous) {
15387 query.append(ORDER_BY_ASC);
15388 }
15389 else {
15390 query.append(ORDER_BY_DESC);
15391 }
15392 }
15393 }
15394 }
15395 else {
15396 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15397 }
15398
15399 String sql = query.toString();
15400
15401 Query q = session.createQuery(sql);
15402
15403 q.setFirstResult(0);
15404 q.setMaxResults(2);
15405
15406 QueryPos qPos = QueryPos.getInstance(q);
15407
15408 qPos.add(classNameId);
15409
15410 qPos.add(classPK);
15411
15412 qPos.add(status);
15413
15414 if (orderByComparator != null) {
15415 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15416
15417 for (Object value : values) {
15418 qPos.add(value);
15419 }
15420 }
15421
15422 List<MBMessage> list = q.list();
15423
15424 if (list.size() == 2) {
15425 return list.get(1);
15426 }
15427 else {
15428 return null;
15429 }
15430 }
15431
15432
15440 public void removeByC_C_S(long classNameId, long classPK, int status)
15441 throws SystemException {
15442 for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15443 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15444 remove(mbMessage);
15445 }
15446 }
15447
15448
15457 public int countByC_C_S(long classNameId, long classPK, int status)
15458 throws SystemException {
15459 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15460
15461 Object[] finderArgs = new Object[] { classNameId, classPK, status };
15462
15463 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15464 this);
15465
15466 if (count == null) {
15467 StringBundler query = new StringBundler(4);
15468
15469 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15470
15471 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15472
15473 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15474
15475 query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15476
15477 String sql = query.toString();
15478
15479 Session session = null;
15480
15481 try {
15482 session = openSession();
15483
15484 Query q = session.createQuery(sql);
15485
15486 QueryPos qPos = QueryPos.getInstance(q);
15487
15488 qPos.add(classNameId);
15489
15490 qPos.add(classPK);
15491
15492 qPos.add(status);
15493
15494 count = (Long)q.uniqueResult();
15495
15496 FinderCacheUtil.putResult(finderPath, finderArgs, count);
15497 }
15498 catch (Exception e) {
15499 FinderCacheUtil.removeResult(finderPath, finderArgs);
15500
15501 throw processException(e);
15502 }
15503 finally {
15504 closeSession(session);
15505 }
15506 }
15507
15508 return count.intValue();
15509 }
15510
15511 private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15512 private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15513 private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15514 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15515 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15516 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
15517 new String[] {
15518 Long.class.getName(), Long.class.getName(), Long.class.getName(),
15519 Boolean.class.getName(),
15520
15521 Integer.class.getName(), Integer.class.getName(),
15522 OrderByComparator.class.getName()
15523 });
15524 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
15525 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15526 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15527 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
15528 new String[] {
15529 Long.class.getName(), Long.class.getName(), Long.class.getName(),
15530 Boolean.class.getName()
15531 },
15532 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15533 MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15534 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
15535 MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
15536 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15537 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15538 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15539 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
15540 new String[] {
15541 Long.class.getName(), Long.class.getName(), Long.class.getName(),
15542 Boolean.class.getName()
15543 });
15544
15545
15555 public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15556 long threadId, boolean answer) throws SystemException {
15557 return findByG_C_T_A(groupId, categoryId, threadId, answer,
15558 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15559 }
15560
15561
15577 public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15578 long threadId, boolean answer, int start, int end)
15579 throws SystemException {
15580 return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
15581 null);
15582 }
15583
15584
15601 public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15602 long threadId, boolean answer, int start, int end,
15603 OrderByComparator orderByComparator) throws SystemException {
15604 boolean pagination = true;
15605 FinderPath finderPath = null;
15606 Object[] finderArgs = null;
15607
15608 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15609 (orderByComparator == null)) {
15610 pagination = false;
15611 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
15612 finderArgs = new Object[] { groupId, categoryId, threadId, answer };
15613 }
15614 else {
15615 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
15616 finderArgs = new Object[] {
15617 groupId, categoryId, threadId, answer,
15618
15619 start, end, orderByComparator
15620 };
15621 }
15622
15623 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15624 finderArgs, this);
15625
15626 if ((list != null) && !list.isEmpty()) {
15627 for (MBMessage mbMessage : list) {
15628 if ((groupId != mbMessage.getGroupId()) ||
15629 (categoryId != mbMessage.getCategoryId()) ||
15630 (threadId != mbMessage.getThreadId()) ||
15631 (answer != mbMessage.getAnswer())) {
15632 list = null;
15633
15634 break;
15635 }
15636 }
15637 }
15638
15639 if (list == null) {
15640 StringBundler query = null;
15641
15642 if (orderByComparator != null) {
15643 query = new StringBundler(6 +
15644 (orderByComparator.getOrderByFields().length * 3));
15645 }
15646 else {
15647 query = new StringBundler(6);
15648 }
15649
15650 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15651
15652 query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15653
15654 query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15655
15656 query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15657
15658 query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15659
15660 if (orderByComparator != null) {
15661 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15662 orderByComparator);
15663 }
15664 else
15665 if (pagination) {
15666 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15667 }
15668
15669 String sql = query.toString();
15670
15671 Session session = null;
15672
15673 try {
15674 session = openSession();
15675
15676 Query q = session.createQuery(sql);
15677
15678 QueryPos qPos = QueryPos.getInstance(q);
15679
15680 qPos.add(groupId);
15681
15682 qPos.add(categoryId);
15683
15684 qPos.add(threadId);
15685
15686 qPos.add(answer);
15687
15688 if (!pagination) {
15689 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15690 start, end, false);
15691
15692 Collections.sort(list);
15693
15694 list = new UnmodifiableList<MBMessage>(list);
15695 }
15696 else {
15697 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15698 start, end);
15699 }
15700
15701 cacheResult(list);
15702
15703 FinderCacheUtil.putResult(finderPath, finderArgs, list);
15704 }
15705 catch (Exception e) {
15706 FinderCacheUtil.removeResult(finderPath, finderArgs);
15707
15708 throw processException(e);
15709 }
15710 finally {
15711 closeSession(session);
15712 }
15713 }
15714
15715 return list;
15716 }
15717
15718
15730 public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
15731 long threadId, boolean answer, OrderByComparator orderByComparator)
15732 throws NoSuchMessageException, SystemException {
15733 MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
15734 threadId, answer, orderByComparator);
15735
15736 if (mbMessage != null) {
15737 return mbMessage;
15738 }
15739
15740 StringBundler msg = new StringBundler(10);
15741
15742 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15743
15744 msg.append("groupId=");
15745 msg.append(groupId);
15746
15747 msg.append(", categoryId=");
15748 msg.append(categoryId);
15749
15750 msg.append(", threadId=");
15751 msg.append(threadId);
15752
15753 msg.append(", answer=");
15754 msg.append(answer);
15755
15756 msg.append(StringPool.CLOSE_CURLY_BRACE);
15757
15758 throw new NoSuchMessageException(msg.toString());
15759 }
15760
15761
15772 public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
15773 long threadId, boolean answer, OrderByComparator orderByComparator)
15774 throws SystemException {
15775 List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15776 answer, 0, 1, orderByComparator);
15777
15778 if (!list.isEmpty()) {
15779 return list.get(0);
15780 }
15781
15782 return null;
15783 }
15784
15785
15797 public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
15798 long threadId, boolean answer, OrderByComparator orderByComparator)
15799 throws NoSuchMessageException, SystemException {
15800 MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
15801 threadId, answer, orderByComparator);
15802
15803 if (mbMessage != null) {
15804 return mbMessage;
15805 }
15806
15807 StringBundler msg = new StringBundler(10);
15808
15809 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15810
15811 msg.append("groupId=");
15812 msg.append(groupId);
15813
15814 msg.append(", categoryId=");
15815 msg.append(categoryId);
15816
15817 msg.append(", threadId=");
15818 msg.append(threadId);
15819
15820 msg.append(", answer=");
15821 msg.append(answer);
15822
15823 msg.append(StringPool.CLOSE_CURLY_BRACE);
15824
15825 throw new NoSuchMessageException(msg.toString());
15826 }
15827
15828
15839 public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
15840 long threadId, boolean answer, OrderByComparator orderByComparator)
15841 throws SystemException {
15842 int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
15843
15844 List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15845 answer, count - 1, count, orderByComparator);
15846
15847 if (!list.isEmpty()) {
15848 return list.get(0);
15849 }
15850
15851 return null;
15852 }
15853
15854
15867 public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
15868 long categoryId, long threadId, boolean answer,
15869 OrderByComparator orderByComparator)
15870 throws NoSuchMessageException, SystemException {
15871 MBMessage mbMessage = findByPrimaryKey(messageId);
15872
15873 Session session = null;
15874
15875 try {
15876 session = openSession();
15877
15878 MBMessage[] array = new MBMessageImpl[3];
15879
15880 array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15881 categoryId, threadId, answer, orderByComparator, true);
15882
15883 array[1] = mbMessage;
15884
15885 array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15886 categoryId, threadId, answer, orderByComparator, false);
15887
15888 return array;
15889 }
15890 catch (Exception e) {
15891 throw processException(e);
15892 }
15893 finally {
15894 closeSession(session);
15895 }
15896 }
15897
15898 protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
15899 MBMessage mbMessage, long groupId, long categoryId, long threadId,
15900 boolean answer, OrderByComparator orderByComparator, boolean previous) {
15901 StringBundler query = null;
15902
15903 if (orderByComparator != null) {
15904 query = new StringBundler(6 +
15905 (orderByComparator.getOrderByFields().length * 6));
15906 }
15907 else {
15908 query = new StringBundler(3);
15909 }
15910
15911 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15912
15913 query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15914
15915 query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15916
15917 query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15918
15919 query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15920
15921 if (orderByComparator != null) {
15922 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15923
15924 if (orderByConditionFields.length > 0) {
15925 query.append(WHERE_AND);
15926 }
15927
15928 for (int i = 0; i < orderByConditionFields.length; i++) {
15929 query.append(_ORDER_BY_ENTITY_ALIAS);
15930 query.append(orderByConditionFields[i]);
15931
15932 if ((i + 1) < orderByConditionFields.length) {
15933 if (orderByComparator.isAscending() ^ previous) {
15934 query.append(WHERE_GREATER_THAN_HAS_NEXT);
15935 }
15936 else {
15937 query.append(WHERE_LESSER_THAN_HAS_NEXT);
15938 }
15939 }
15940 else {
15941 if (orderByComparator.isAscending() ^ previous) {
15942 query.append(WHERE_GREATER_THAN);
15943 }
15944 else {
15945 query.append(WHERE_LESSER_THAN);
15946 }
15947 }
15948 }
15949
15950 query.append(ORDER_BY_CLAUSE);
15951
15952 String[] orderByFields = orderByComparator.getOrderByFields();
15953
15954 for (int i = 0; i < orderByFields.length; i++) {
15955 query.append(_ORDER_BY_ENTITY_ALIAS);
15956 query.append(orderByFields[i]);
15957
15958 if ((i + 1) < orderByFields.length) {
15959 if (orderByComparator.isAscending() ^ previous) {
15960 query.append(ORDER_BY_ASC_HAS_NEXT);
15961 }
15962 else {
15963 query.append(ORDER_BY_DESC_HAS_NEXT);
15964 }
15965 }
15966 else {
15967 if (orderByComparator.isAscending() ^ previous) {
15968 query.append(ORDER_BY_ASC);
15969 }
15970 else {
15971 query.append(ORDER_BY_DESC);
15972 }
15973 }
15974 }
15975 }
15976 else {
15977 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15978 }
15979
15980 String sql = query.toString();
15981
15982 Query q = session.createQuery(sql);
15983
15984 q.setFirstResult(0);
15985 q.setMaxResults(2);
15986
15987 QueryPos qPos = QueryPos.getInstance(q);
15988
15989 qPos.add(groupId);
15990
15991 qPos.add(categoryId);
15992
15993 qPos.add(threadId);
15994
15995 qPos.add(answer);
15996
15997 if (orderByComparator != null) {
15998 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15999
16000 for (Object value : values) {
16001 qPos.add(value);
16002 }
16003 }
16004
16005 List<MBMessage> list = q.list();
16006
16007 if (list.size() == 2) {
16008 return list.get(1);
16009 }
16010 else {
16011 return null;
16012 }
16013 }
16014
16015
16025 public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16026 long threadId, boolean answer) throws SystemException {
16027 return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16028 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16029 }
16030
16031
16047 public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16048 long threadId, boolean answer, int start, int end)
16049 throws SystemException {
16050 return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16051 start, end, null);
16052 }
16053
16054
16071 public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16072 long threadId, boolean answer, int start, int end,
16073 OrderByComparator orderByComparator) throws SystemException {
16074 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16075 return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16076 end, orderByComparator);
16077 }
16078
16079 StringBundler query = null;
16080
16081 if (orderByComparator != null) {
16082 query = new StringBundler(6 +
16083 (orderByComparator.getOrderByFields().length * 3));
16084 }
16085 else {
16086 query = new StringBundler(6);
16087 }
16088
16089 if (getDB().isSupportsInlineDistinct()) {
16090 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16091 }
16092 else {
16093 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16094 }
16095
16096 query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16097
16098 query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16099
16100 query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16101
16102 query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16103
16104 if (!getDB().isSupportsInlineDistinct()) {
16105 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16106 }
16107
16108 if (orderByComparator != null) {
16109 if (getDB().isSupportsInlineDistinct()) {
16110 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16111 orderByComparator);
16112 }
16113 else {
16114 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16115 orderByComparator);
16116 }
16117 }
16118 else {
16119 if (getDB().isSupportsInlineDistinct()) {
16120 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16121 }
16122 else {
16123 query.append(MBMessageModelImpl.ORDER_BY_SQL);
16124 }
16125 }
16126
16127 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16128 MBMessage.class.getName(),
16129 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16130
16131 Session session = null;
16132
16133 try {
16134 session = openSession();
16135
16136 SQLQuery q = session.createSQLQuery(sql);
16137
16138 if (getDB().isSupportsInlineDistinct()) {
16139 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16140 }
16141 else {
16142 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16143 }
16144
16145 QueryPos qPos = QueryPos.getInstance(q);
16146
16147 qPos.add(groupId);
16148
16149 qPos.add(categoryId);
16150
16151 qPos.add(threadId);
16152
16153 qPos.add(answer);
16154
16155 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16156 }
16157 catch (Exception e) {
16158 throw processException(e);
16159 }
16160 finally {
16161 closeSession(session);
16162 }
16163 }
16164
16165
16178 public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16179 long groupId, long categoryId, long threadId, boolean answer,
16180 OrderByComparator orderByComparator)
16181 throws NoSuchMessageException, SystemException {
16182 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16183 return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16184 threadId, answer, orderByComparator);
16185 }
16186
16187 MBMessage mbMessage = findByPrimaryKey(messageId);
16188
16189 Session session = null;
16190
16191 try {
16192 session = openSession();
16193
16194 MBMessage[] array = new MBMessageImpl[3];
16195
16196 array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16197 groupId, categoryId, threadId, answer, orderByComparator,
16198 true);
16199
16200 array[1] = mbMessage;
16201
16202 array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16203 groupId, categoryId, threadId, answer, orderByComparator,
16204 false);
16205
16206 return array;
16207 }
16208 catch (Exception e) {
16209 throw processException(e);
16210 }
16211 finally {
16212 closeSession(session);
16213 }
16214 }
16215
16216 protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16217 MBMessage mbMessage, long groupId, long categoryId, long threadId,
16218 boolean answer, OrderByComparator orderByComparator, boolean previous) {
16219 StringBundler query = null;
16220
16221 if (orderByComparator != null) {
16222 query = new StringBundler(6 +
16223 (orderByComparator.getOrderByFields().length * 6));
16224 }
16225 else {
16226 query = new StringBundler(3);
16227 }
16228
16229 if (getDB().isSupportsInlineDistinct()) {
16230 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16231 }
16232 else {
16233 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16234 }
16235
16236 query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16237
16238 query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16239
16240 query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16241
16242 query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16243
16244 if (!getDB().isSupportsInlineDistinct()) {
16245 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16246 }
16247
16248 if (orderByComparator != null) {
16249 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16250
16251 if (orderByConditionFields.length > 0) {
16252 query.append(WHERE_AND);
16253 }
16254
16255 for (int i = 0; i < orderByConditionFields.length; i++) {
16256 if (getDB().isSupportsInlineDistinct()) {
16257 query.append(_ORDER_BY_ENTITY_ALIAS);
16258 }
16259 else {
16260 query.append(_ORDER_BY_ENTITY_TABLE);
16261 }
16262
16263 query.append(orderByConditionFields[i]);
16264
16265 if ((i + 1) < orderByConditionFields.length) {
16266 if (orderByComparator.isAscending() ^ previous) {
16267 query.append(WHERE_GREATER_THAN_HAS_NEXT);
16268 }
16269 else {
16270 query.append(WHERE_LESSER_THAN_HAS_NEXT);
16271 }
16272 }
16273 else {
16274 if (orderByComparator.isAscending() ^ previous) {
16275 query.append(WHERE_GREATER_THAN);
16276 }
16277 else {
16278 query.append(WHERE_LESSER_THAN);
16279 }
16280 }
16281 }
16282
16283 query.append(ORDER_BY_CLAUSE);
16284
16285 String[] orderByFields = orderByComparator.getOrderByFields();
16286
16287 for (int i = 0; i < orderByFields.length; i++) {
16288 if (getDB().isSupportsInlineDistinct()) {
16289 query.append(_ORDER_BY_ENTITY_ALIAS);
16290 }
16291 else {
16292 query.append(_ORDER_BY_ENTITY_TABLE);
16293 }
16294
16295 query.append(orderByFields[i]);
16296
16297 if ((i + 1) < orderByFields.length) {
16298 if (orderByComparator.isAscending() ^ previous) {
16299 query.append(ORDER_BY_ASC_HAS_NEXT);
16300 }
16301 else {
16302 query.append(ORDER_BY_DESC_HAS_NEXT);
16303 }
16304 }
16305 else {
16306 if (orderByComparator.isAscending() ^ previous) {
16307 query.append(ORDER_BY_ASC);
16308 }
16309 else {
16310 query.append(ORDER_BY_DESC);
16311 }
16312 }
16313 }
16314 }
16315 else {
16316 if (getDB().isSupportsInlineDistinct()) {
16317 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16318 }
16319 else {
16320 query.append(MBMessageModelImpl.ORDER_BY_SQL);
16321 }
16322 }
16323
16324 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16325 MBMessage.class.getName(),
16326 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16327
16328 SQLQuery q = session.createSQLQuery(sql);
16329
16330 q.setFirstResult(0);
16331 q.setMaxResults(2);
16332
16333 if (getDB().isSupportsInlineDistinct()) {
16334 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16335 }
16336 else {
16337 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16338 }
16339
16340 QueryPos qPos = QueryPos.getInstance(q);
16341
16342 qPos.add(groupId);
16343
16344 qPos.add(categoryId);
16345
16346 qPos.add(threadId);
16347
16348 qPos.add(answer);
16349
16350 if (orderByComparator != null) {
16351 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16352
16353 for (Object value : values) {
16354 qPos.add(value);
16355 }
16356 }
16357
16358 List<MBMessage> list = q.list();
16359
16360 if (list.size() == 2) {
16361 return list.get(1);
16362 }
16363 else {
16364 return null;
16365 }
16366 }
16367
16368
16377 public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16378 boolean answer) throws SystemException {
16379 for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16380 answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16381 remove(mbMessage);
16382 }
16383 }
16384
16385
16395 public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16396 boolean answer) throws SystemException {
16397 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
16398
16399 Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16400
16401 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16402 this);
16403
16404 if (count == null) {
16405 StringBundler query = new StringBundler(5);
16406
16407 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16408
16409 query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16410
16411 query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16412
16413 query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16414
16415 query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16416
16417 String sql = query.toString();
16418
16419 Session session = null;
16420
16421 try {
16422 session = openSession();
16423
16424 Query q = session.createQuery(sql);
16425
16426 QueryPos qPos = QueryPos.getInstance(q);
16427
16428 qPos.add(groupId);
16429
16430 qPos.add(categoryId);
16431
16432 qPos.add(threadId);
16433
16434 qPos.add(answer);
16435
16436 count = (Long)q.uniqueResult();
16437
16438 FinderCacheUtil.putResult(finderPath, finderArgs, count);
16439 }
16440 catch (Exception e) {
16441 FinderCacheUtil.removeResult(finderPath, finderArgs);
16442
16443 throw processException(e);
16444 }
16445 finally {
16446 closeSession(session);
16447 }
16448 }
16449
16450 return count.intValue();
16451 }
16452
16453
16463 public int filterCountByG_C_T_A(long groupId, long categoryId,
16464 long threadId, boolean answer) throws SystemException {
16465 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16466 return countByG_C_T_A(groupId, categoryId, threadId, answer);
16467 }
16468
16469 StringBundler query = new StringBundler(5);
16470
16471 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16472
16473 query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16474
16475 query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16476
16477 query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16478
16479 query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16480
16481 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16482 MBMessage.class.getName(),
16483 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16484
16485 Session session = null;
16486
16487 try {
16488 session = openSession();
16489
16490 SQLQuery q = session.createSQLQuery(sql);
16491
16492 q.addScalar(COUNT_COLUMN_NAME,
16493 com.liferay.portal.kernel.dao.orm.Type.LONG);
16494
16495 QueryPos qPos = QueryPos.getInstance(q);
16496
16497 qPos.add(groupId);
16498
16499 qPos.add(categoryId);
16500
16501 qPos.add(threadId);
16502
16503 qPos.add(answer);
16504
16505 Long count = (Long)q.uniqueResult();
16506
16507 return count.intValue();
16508 }
16509 catch (Exception e) {
16510 throw processException(e);
16511 }
16512 finally {
16513 closeSession(session);
16514 }
16515 }
16516
16517 private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
16518 private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
16519 private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
16520 private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
16521 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16522 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16523 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
16524 new String[] {
16525 Long.class.getName(), Long.class.getName(), Long.class.getName(),
16526 Integer.class.getName(),
16527
16528 Integer.class.getName(), Integer.class.getName(),
16529 OrderByComparator.class.getName()
16530 });
16531 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
16532 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16533 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16534 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
16535 new String[] {
16536 Long.class.getName(), Long.class.getName(), Long.class.getName(),
16537 Integer.class.getName()
16538 },
16539 MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16540 MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16541 MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16542 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
16543 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16544 public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16545 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16546 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
16547 new String[] {
16548 Long.class.getName(), Long.class.getName(), Long.class.getName(),
16549 Integer.class.getName()
16550 });
16551
16552
16562 public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16563 long threadId, int status) throws SystemException {
16564 return findByG_C_T_S(groupId, categoryId, threadId, status,
16565 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16566 }
16567
16568
16584 public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16585 long threadId, int status, int start, int end)
16586 throws SystemException {
16587 return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
16588 null);
16589 }
16590
16591
16608 public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16609 long threadId, int status, int start, int end,
16610 OrderByComparator orderByComparator) throws SystemException {
16611 boolean pagination = true;
16612 FinderPath finderPath = null;
16613 Object[] finderArgs = null;
16614
16615 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16616 (orderByComparator == null)) {
16617 pagination = false;
16618 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
16619 finderArgs = new Object[] { groupId, categoryId, threadId, status };
16620 }
16621 else {
16622 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
16623 finderArgs = new Object[] {
16624 groupId, categoryId, threadId, status,
16625
16626 start, end, orderByComparator
16627 };
16628 }
16629
16630 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16631 finderArgs, this);
16632
16633 if ((list != null) && !list.isEmpty()) {
16634 for (MBMessage mbMessage : list) {
16635 if ((groupId != mbMessage.getGroupId()) ||
16636 (categoryId != mbMessage.getCategoryId()) ||
16637 (threadId != mbMessage.getThreadId()) ||
16638 (status != mbMessage.getStatus())) {
16639 list = null;
16640
16641 break;
16642 }
16643 }
16644 }
16645
16646 if (list == null) {
16647 StringBundler query = null;
16648
16649 if (orderByComparator != null) {
16650 query = new StringBundler(6 +
16651 (orderByComparator.getOrderByFields().length * 3));
16652 }
16653 else {
16654 query = new StringBundler(6);
16655 }
16656
16657 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16658
16659 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16660
16661 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16662
16663 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16664
16665 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16666
16667 if (orderByComparator != null) {
16668 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16669 orderByComparator);
16670 }
16671 else
16672 if (pagination) {
16673 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16674 }
16675
16676 String sql = query.toString();
16677
16678 Session session = null;
16679
16680 try {
16681 session = openSession();
16682
16683 Query q = session.createQuery(sql);
16684
16685 QueryPos qPos = QueryPos.getInstance(q);
16686
16687 qPos.add(groupId);
16688
16689 qPos.add(categoryId);
16690
16691 qPos.add(threadId);
16692
16693 qPos.add(status);
16694
16695 if (!pagination) {
16696 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16697 start, end, false);
16698
16699 Collections.sort(list);
16700
16701 list = new UnmodifiableList<MBMessage>(list);
16702 }
16703 else {
16704 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16705 start, end);
16706 }
16707
16708 cacheResult(list);
16709
16710 FinderCacheUtil.putResult(finderPath, finderArgs, list);
16711 }
16712 catch (Exception e) {
16713 FinderCacheUtil.removeResult(finderPath, finderArgs);
16714
16715 throw processException(e);
16716 }
16717 finally {
16718 closeSession(session);
16719 }
16720 }
16721
16722 return list;
16723 }
16724
16725
16737 public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
16738 long threadId, int status, OrderByComparator orderByComparator)
16739 throws NoSuchMessageException, SystemException {
16740 MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
16741 threadId, status, orderByComparator);
16742
16743 if (mbMessage != null) {
16744 return mbMessage;
16745 }
16746
16747 StringBundler msg = new StringBundler(10);
16748
16749 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16750
16751 msg.append("groupId=");
16752 msg.append(groupId);
16753
16754 msg.append(", categoryId=");
16755 msg.append(categoryId);
16756
16757 msg.append(", threadId=");
16758 msg.append(threadId);
16759
16760 msg.append(", status=");
16761 msg.append(status);
16762
16763 msg.append(StringPool.CLOSE_CURLY_BRACE);
16764
16765 throw new NoSuchMessageException(msg.toString());
16766 }
16767
16768
16779 public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
16780 long threadId, int status, OrderByComparator orderByComparator)
16781 throws SystemException {
16782 List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16783 status, 0, 1, orderByComparator);
16784
16785 if (!list.isEmpty()) {
16786 return list.get(0);
16787 }
16788
16789 return null;
16790 }
16791
16792
16804 public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
16805 long threadId, int status, OrderByComparator orderByComparator)
16806 throws NoSuchMessageException, SystemException {
16807 MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
16808 threadId, status, orderByComparator);
16809
16810 if (mbMessage != null) {
16811 return mbMessage;
16812 }
16813
16814 StringBundler msg = new StringBundler(10);
16815
16816 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16817
16818 msg.append("groupId=");
16819 msg.append(groupId);
16820
16821 msg.append(", categoryId=");
16822 msg.append(categoryId);
16823
16824 msg.append(", threadId=");
16825 msg.append(threadId);
16826
16827 msg.append(", status=");
16828 msg.append(status);
16829
16830 msg.append(StringPool.CLOSE_CURLY_BRACE);
16831
16832 throw new NoSuchMessageException(msg.toString());
16833 }
16834
16835
16846 public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
16847 long threadId, int status, OrderByComparator orderByComparator)
16848 throws SystemException {
16849 int count = countByG_C_T_S(groupId, categoryId, threadId, status);
16850
16851 List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16852 status, count - 1, count, orderByComparator);
16853
16854 if (!list.isEmpty()) {
16855 return list.get(0);
16856 }
16857
16858 return null;
16859 }
16860
16861
16874 public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
16875 long categoryId, long threadId, int status,
16876 OrderByComparator orderByComparator)
16877 throws NoSuchMessageException, SystemException {
16878 MBMessage mbMessage = findByPrimaryKey(messageId);
16879
16880 Session session = null;
16881
16882 try {
16883 session = openSession();
16884
16885 MBMessage[] array = new MBMessageImpl[3];
16886
16887 array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16888 categoryId, threadId, status, orderByComparator, true);
16889
16890 array[1] = mbMessage;
16891
16892 array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16893 categoryId, threadId, status, orderByComparator, false);
16894
16895 return array;
16896 }
16897 catch (Exception e) {
16898 throw processException(e);
16899 }
16900 finally {
16901 closeSession(session);
16902 }
16903 }
16904
16905 protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
16906 MBMessage mbMessage, long groupId, long categoryId, long threadId,
16907 int status, OrderByComparator orderByComparator, boolean previous) {
16908 StringBundler query = null;
16909
16910 if (orderByComparator != null) {
16911 query = new StringBundler(6 +
16912 (orderByComparator.getOrderByFields().length * 6));
16913 }
16914 else {
16915 query = new StringBundler(3);
16916 }
16917
16918 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16919
16920 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16921
16922 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16923
16924 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16925
16926 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16927
16928 if (orderByComparator != null) {
16929 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16930
16931 if (orderByConditionFields.length > 0) {
16932 query.append(WHERE_AND);
16933 }
16934
16935 for (int i = 0; i < orderByConditionFields.length; i++) {
16936 query.append(_ORDER_BY_ENTITY_ALIAS);
16937 query.append(orderByConditionFields[i]);
16938
16939 if ((i + 1) < orderByConditionFields.length) {
16940 if (orderByComparator.isAscending() ^ previous) {
16941 query.append(WHERE_GREATER_THAN_HAS_NEXT);
16942 }
16943 else {
16944 query.append(WHERE_LESSER_THAN_HAS_NEXT);
16945 }
16946 }
16947 else {
16948 if (orderByComparator.isAscending() ^ previous) {
16949 query.append(WHERE_GREATER_THAN);
16950 }
16951 else {
16952 query.append(WHERE_LESSER_THAN);
16953 }
16954 }
16955 }
16956
16957 query.append(ORDER_BY_CLAUSE);
16958
16959 String[] orderByFields = orderByComparator.getOrderByFields();
16960
16961 for (int i = 0; i < orderByFields.length; i++) {
16962 query.append(_ORDER_BY_ENTITY_ALIAS);
16963 query.append(orderByFields[i]);
16964
16965 if ((i + 1) < orderByFields.length) {
16966 if (orderByComparator.isAscending() ^ previous) {
16967 query.append(ORDER_BY_ASC_HAS_NEXT);
16968 }
16969 else {
16970 query.append(ORDER_BY_DESC_HAS_NEXT);
16971 }
16972 }
16973 else {
16974 if (orderByComparator.isAscending() ^ previous) {
16975 query.append(ORDER_BY_ASC);
16976 }
16977 else {
16978 query.append(ORDER_BY_DESC);
16979 }
16980 }
16981 }
16982 }
16983 else {
16984 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16985 }
16986
16987 String sql = query.toString();
16988
16989 Query q = session.createQuery(sql);
16990
16991 q.setFirstResult(0);
16992 q.setMaxResults(2);
16993
16994 QueryPos qPos = QueryPos.getInstance(q);
16995
16996 qPos.add(groupId);
16997
16998 qPos.add(categoryId);
16999
17000 qPos.add(threadId);
17001
17002 qPos.add(status);
17003
17004 if (orderByComparator != null) {
17005 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17006
17007 for (Object value : values) {
17008 qPos.add(value);
17009 }
17010 }
17011
17012 List<MBMessage> list = q.list();
17013
17014 if (list.size() == 2) {
17015 return list.get(1);
17016 }
17017 else {
17018 return null;
17019 }
17020 }
17021
17022
17032 public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17033 long threadId, int status) throws SystemException {
17034 return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17035 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17036 }
17037
17038
17054 public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17055 long threadId, int status, int start, int end)
17056 throws SystemException {
17057 return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17058 start, end, null);
17059 }
17060
17061
17078 public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17079 long threadId, int status, int start, int end,
17080 OrderByComparator orderByComparator) throws SystemException {
17081 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17082 return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17083 end, orderByComparator);
17084 }
17085
17086 StringBundler query = null;
17087
17088 if (orderByComparator != null) {
17089 query = new StringBundler(6 +
17090 (orderByComparator.getOrderByFields().length * 3));
17091 }
17092 else {
17093 query = new StringBundler(6);
17094 }
17095
17096 if (getDB().isSupportsInlineDistinct()) {
17097 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17098 }
17099 else {
17100 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17101 }
17102
17103 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17104
17105 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17106
17107 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17108
17109 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17110
17111 if (!getDB().isSupportsInlineDistinct()) {
17112 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17113 }
17114
17115 if (orderByComparator != null) {
17116 if (getDB().isSupportsInlineDistinct()) {
17117 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17118 orderByComparator);
17119 }
17120 else {
17121 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17122 orderByComparator);
17123 }
17124 }
17125 else {
17126 if (getDB().isSupportsInlineDistinct()) {
17127 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17128 }
17129 else {
17130 query.append(MBMessageModelImpl.ORDER_BY_SQL);
17131 }
17132 }
17133
17134 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17135 MBMessage.class.getName(),
17136 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17137
17138 Session session = null;
17139
17140 try {
17141 session = openSession();
17142
17143 SQLQuery q = session.createSQLQuery(sql);
17144
17145 if (getDB().isSupportsInlineDistinct()) {
17146 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17147 }
17148 else {
17149 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17150 }
17151
17152 QueryPos qPos = QueryPos.getInstance(q);
17153
17154 qPos.add(groupId);
17155
17156 qPos.add(categoryId);
17157
17158 qPos.add(threadId);
17159
17160 qPos.add(status);
17161
17162 return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17163 }
17164 catch (Exception e) {
17165 throw processException(e);
17166 }
17167 finally {
17168 closeSession(session);
17169 }
17170 }
17171
17172
17185 public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17186 long groupId, long categoryId, long threadId, int status,
17187 OrderByComparator orderByComparator)
17188 throws NoSuchMessageException, SystemException {
17189 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17190 return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17191 threadId, status, orderByComparator);
17192 }
17193
17194 MBMessage mbMessage = findByPrimaryKey(messageId);
17195
17196 Session session = null;
17197
17198 try {
17199 session = openSession();
17200
17201 MBMessage[] array = new MBMessageImpl[3];
17202
17203 array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17204 groupId, categoryId, threadId, status, orderByComparator,
17205 true);
17206
17207 array[1] = mbMessage;
17208
17209 array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17210 groupId, categoryId, threadId, status, orderByComparator,
17211 false);
17212
17213 return array;
17214 }
17215 catch (Exception e) {
17216 throw processException(e);
17217 }
17218 finally {
17219 closeSession(session);
17220 }
17221 }
17222
17223 protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17224 MBMessage mbMessage, long groupId, long categoryId, long threadId,
17225 int status, OrderByComparator orderByComparator, boolean previous) {
17226 StringBundler query = null;
17227
17228 if (orderByComparator != null) {
17229 query = new StringBundler(6 +
17230 (orderByComparator.getOrderByFields().length * 6));
17231 }
17232 else {
17233 query = new StringBundler(3);
17234 }
17235
17236 if (getDB().isSupportsInlineDistinct()) {
17237 query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17238 }
17239 else {
17240 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17241 }
17242
17243 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17244
17245 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17246
17247 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17248
17249 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17250
17251 if (!getDB().isSupportsInlineDistinct()) {
17252 query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17253 }
17254
17255 if (orderByComparator != null) {
17256 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17257
17258 if (orderByConditionFields.length > 0) {
17259 query.append(WHERE_AND);
17260 }
17261
17262 for (int i = 0; i < orderByConditionFields.length; i++) {
17263 if (getDB().isSupportsInlineDistinct()) {
17264 query.append(_ORDER_BY_ENTITY_ALIAS);
17265 }
17266 else {
17267 query.append(_ORDER_BY_ENTITY_TABLE);
17268 }
17269
17270 query.append(orderByConditionFields[i]);
17271
17272 if ((i + 1) < orderByConditionFields.length) {
17273 if (orderByComparator.isAscending() ^ previous) {
17274 query.append(WHERE_GREATER_THAN_HAS_NEXT);
17275 }
17276 else {
17277 query.append(WHERE_LESSER_THAN_HAS_NEXT);
17278 }
17279 }
17280 else {
17281 if (orderByComparator.isAscending() ^ previous) {
17282 query.append(WHERE_GREATER_THAN);
17283 }
17284 else {
17285 query.append(WHERE_LESSER_THAN);
17286 }
17287 }
17288 }
17289
17290 query.append(ORDER_BY_CLAUSE);
17291
17292 String[] orderByFields = orderByComparator.getOrderByFields();
17293
17294 for (int i = 0; i < orderByFields.length; i++) {
17295 if (getDB().isSupportsInlineDistinct()) {
17296 query.append(_ORDER_BY_ENTITY_ALIAS);
17297 }
17298 else {
17299 query.append(_ORDER_BY_ENTITY_TABLE);
17300 }
17301
17302 query.append(orderByFields[i]);
17303
17304 if ((i + 1) < orderByFields.length) {
17305 if (orderByComparator.isAscending() ^ previous) {
17306 query.append(ORDER_BY_ASC_HAS_NEXT);
17307 }
17308 else {
17309 query.append(ORDER_BY_DESC_HAS_NEXT);
17310 }
17311 }
17312 else {
17313 if (orderByComparator.isAscending() ^ previous) {
17314 query.append(ORDER_BY_ASC);
17315 }
17316 else {
17317 query.append(ORDER_BY_DESC);
17318 }
17319 }
17320 }
17321 }
17322 else {
17323 if (getDB().isSupportsInlineDistinct()) {
17324 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17325 }
17326 else {
17327 query.append(MBMessageModelImpl.ORDER_BY_SQL);
17328 }
17329 }
17330
17331 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17332 MBMessage.class.getName(),
17333 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17334
17335 SQLQuery q = session.createSQLQuery(sql);
17336
17337 q.setFirstResult(0);
17338 q.setMaxResults(2);
17339
17340 if (getDB().isSupportsInlineDistinct()) {
17341 q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17342 }
17343 else {
17344 q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17345 }
17346
17347 QueryPos qPos = QueryPos.getInstance(q);
17348
17349 qPos.add(groupId);
17350
17351 qPos.add(categoryId);
17352
17353 qPos.add(threadId);
17354
17355 qPos.add(status);
17356
17357 if (orderByComparator != null) {
17358 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17359
17360 for (Object value : values) {
17361 qPos.add(value);
17362 }
17363 }
17364
17365 List<MBMessage> list = q.list();
17366
17367 if (list.size() == 2) {
17368 return list.get(1);
17369 }
17370 else {
17371 return null;
17372 }
17373 }
17374
17375
17384 public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
17385 int status) throws SystemException {
17386 for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
17387 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17388 remove(mbMessage);
17389 }
17390 }
17391
17392
17402 public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17403 int status) throws SystemException {
17404 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
17405
17406 Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17407
17408 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17409 this);
17410
17411 if (count == null) {
17412 StringBundler query = new StringBundler(5);
17413
17414 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17415
17416 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17417
17418 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17419
17420 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17421
17422 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17423
17424 String sql = query.toString();
17425
17426 Session session = null;
17427
17428 try {
17429 session = openSession();
17430
17431 Query q = session.createQuery(sql);
17432
17433 QueryPos qPos = QueryPos.getInstance(q);
17434
17435 qPos.add(groupId);
17436
17437 qPos.add(categoryId);
17438
17439 qPos.add(threadId);
17440
17441 qPos.add(status);
17442
17443 count = (Long)q.uniqueResult();
17444
17445 FinderCacheUtil.putResult(finderPath, finderArgs, count);
17446 }
17447 catch (Exception e) {
17448 FinderCacheUtil.removeResult(finderPath, finderArgs);
17449
17450 throw processException(e);
17451 }
17452 finally {
17453 closeSession(session);
17454 }
17455 }
17456
17457 return count.intValue();
17458 }
17459
17460
17470 public int filterCountByG_C_T_S(long groupId, long categoryId,
17471 long threadId, int status) throws SystemException {
17472 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17473 return countByG_C_T_S(groupId, categoryId, threadId, status);
17474 }
17475
17476 StringBundler query = new StringBundler(5);
17477
17478 query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17479
17480 query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17481
17482 query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17483
17484 query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17485
17486 query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17487
17488 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17489 MBMessage.class.getName(),
17490 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17491
17492 Session session = null;
17493
17494 try {
17495 session = openSession();
17496
17497 SQLQuery q = session.createSQLQuery(sql);
17498
17499 q.addScalar(COUNT_COLUMN_NAME,
17500 com.liferay.portal.kernel.dao.orm.Type.LONG);
17501
17502 QueryPos qPos = QueryPos.getInstance(q);
17503
17504 qPos.add(groupId);
17505
17506 qPos.add(categoryId);
17507
17508 qPos.add(threadId);
17509
17510 qPos.add(status);
17511
17512 Long count = (Long)q.uniqueResult();
17513
17514 return count.intValue();
17515 }
17516 catch (Exception e) {
17517 throw processException(e);
17518 }
17519 finally {
17520 closeSession(session);
17521 }
17522 }
17523
17524 private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17525 private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17526 private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17527 private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17528 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17529 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17530 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
17531 new String[] {
17532 Long.class.getName(), Long.class.getName(), Long.class.getName(),
17533 Integer.class.getName(),
17534
17535 Integer.class.getName(), Integer.class.getName(),
17536 OrderByComparator.class.getName()
17537 });
17538 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
17539 new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17540 MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17541 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
17542 new String[] {
17543 Long.class.getName(), Long.class.getName(), Long.class.getName(),
17544 Integer.class.getName()
17545 },
17546 MBMessageModelImpl.USERID_COLUMN_BITMASK |
17547 MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17548 MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
17549 MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17550 MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17551 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17552 MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17553 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
17554 new String[] {
17555 Long.class.getName(), Long.class.getName(), Long.class.getName(),
17556 Integer.class.getName()
17557 });
17558
17559
17569 public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17570 long classPK, int status) throws SystemException {
17571 return findByU_C_C_S(userId, classNameId, classPK, status,
17572 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17573 }
17574
17575
17591 public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17592 long classPK, int status, int start, int end) throws SystemException {
17593 return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
17594 null);
17595 }
17596
17597
17614 public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17615 long classPK, int status, int start, int end,
17616 OrderByComparator orderByComparator) throws SystemException {
17617 boolean pagination = true;
17618 FinderPath finderPath = null;
17619 Object[] finderArgs = null;
17620
17621 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17622 (orderByComparator == null)) {
17623 pagination = false;
17624 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
17625 finderArgs = new Object[] { userId, classNameId, classPK, status };
17626 }
17627 else {
17628 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
17629 finderArgs = new Object[] {
17630 userId, classNameId, classPK, status,
17631
17632 start, end, orderByComparator
17633 };
17634 }
17635
17636 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17637 finderArgs, this);
17638
17639 if ((list != null) && !list.isEmpty()) {
17640 for (MBMessage mbMessage : list) {
17641 if ((userId != mbMessage.getUserId()) ||
17642 (classNameId != mbMessage.getClassNameId()) ||
17643 (classPK != mbMessage.getClassPK()) ||
17644 (status != mbMessage.getStatus())) {
17645 list = null;
17646
17647 break;
17648 }
17649 }
17650 }
17651
17652 if (list == null) {
17653 StringBundler query = null;
17654
17655 if (orderByComparator != null) {
17656 query = new StringBundler(6 +
17657 (orderByComparator.getOrderByFields().length * 3));
17658 }
17659 else {
17660 query = new StringBundler(6);
17661 }
17662
17663 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17664
17665 query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17666
17667 query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17668
17669 query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17670
17671 query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17672
17673 if (orderByComparator != null) {
17674 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17675 orderByComparator);
17676 }
17677 else
17678 if (pagination) {
17679 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17680 }
17681
17682 String sql = query.toString();
17683
17684 Session session = null;
17685
17686 try {
17687 session = openSession();
17688
17689 Query q = session.createQuery(sql);
17690
17691 QueryPos qPos = QueryPos.getInstance(q);
17692
17693 qPos.add(userId);
17694
17695 qPos.add(classNameId);
17696
17697 qPos.add(classPK);
17698
17699 qPos.add(status);
17700
17701 if (!pagination) {
17702 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17703 start, end, false);
17704
17705 Collections.sort(list);
17706
17707 list = new UnmodifiableList<MBMessage>(list);
17708 }
17709 else {
17710 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17711 start, end);
17712 }
17713
17714 cacheResult(list);
17715
17716 FinderCacheUtil.putResult(finderPath, finderArgs, list);
17717 }
17718 catch (Exception e) {
17719 FinderCacheUtil.removeResult(finderPath, finderArgs);
17720
17721 throw processException(e);
17722 }
17723 finally {
17724 closeSession(session);
17725 }
17726 }
17727
17728 return list;
17729 }
17730
17731
17743 public MBMessage findByU_C_C_S_First(long userId, long classNameId,
17744 long classPK, int status, OrderByComparator orderByComparator)
17745 throws NoSuchMessageException, SystemException {
17746 MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
17747 classPK, status, orderByComparator);
17748
17749 if (mbMessage != null) {
17750 return mbMessage;
17751 }
17752
17753 StringBundler msg = new StringBundler(10);
17754
17755 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17756
17757 msg.append("userId=");
17758 msg.append(userId);
17759
17760 msg.append(", classNameId=");
17761 msg.append(classNameId);
17762
17763 msg.append(", classPK=");
17764 msg.append(classPK);
17765
17766 msg.append(", status=");
17767 msg.append(status);
17768
17769 msg.append(StringPool.CLOSE_CURLY_BRACE);
17770
17771 throw new NoSuchMessageException(msg.toString());
17772 }
17773
17774
17785 public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
17786 long classPK, int status, OrderByComparator orderByComparator)
17787 throws SystemException {
17788 List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17789 status, 0, 1, orderByComparator);
17790
17791 if (!list.isEmpty()) {
17792 return list.get(0);
17793 }
17794
17795 return null;
17796 }
17797
17798
17810 public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
17811 long classPK, int status, OrderByComparator orderByComparator)
17812 throws NoSuchMessageException, SystemException {
17813 MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
17814 status, orderByComparator);
17815
17816 if (mbMessage != null) {
17817 return mbMessage;
17818 }
17819
17820 StringBundler msg = new StringBundler(10);
17821
17822 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17823
17824 msg.append("userId=");
17825 msg.append(userId);
17826
17827 msg.append(", classNameId=");
17828 msg.append(classNameId);
17829
17830 msg.append(", classPK=");
17831 msg.append(classPK);
17832
17833 msg.append(", status=");
17834 msg.append(status);
17835
17836 msg.append(StringPool.CLOSE_CURLY_BRACE);
17837
17838 throw new NoSuchMessageException(msg.toString());
17839 }
17840
17841
17852 public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
17853 long classPK, int status, OrderByComparator orderByComparator)
17854 throws SystemException {
17855 int count = countByU_C_C_S(userId, classNameId, classPK, status);
17856
17857 List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17858 status, count - 1, count, orderByComparator);
17859
17860 if (!list.isEmpty()) {
17861 return list.get(0);
17862 }
17863
17864 return null;
17865 }
17866
17867
17880 public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
17881 long classNameId, long classPK, int status,
17882 OrderByComparator orderByComparator)
17883 throws NoSuchMessageException, SystemException {
17884 MBMessage mbMessage = findByPrimaryKey(messageId);
17885
17886 Session session = null;
17887
17888 try {
17889 session = openSession();
17890
17891 MBMessage[] array = new MBMessageImpl[3];
17892
17893 array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17894 classNameId, classPK, status, orderByComparator, true);
17895
17896 array[1] = mbMessage;
17897
17898 array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17899 classNameId, classPK, status, orderByComparator, false);
17900
17901 return array;
17902 }
17903 catch (Exception e) {
17904 throw processException(e);
17905 }
17906 finally {
17907 closeSession(session);
17908 }
17909 }
17910
17911 protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
17912 MBMessage mbMessage, long userId, long classNameId, long classPK,
17913 int status, OrderByComparator orderByComparator, boolean previous) {
17914 StringBundler query = null;
17915
17916 if (orderByComparator != null) {
17917 query = new StringBundler(6 +
17918 (orderByComparator.getOrderByFields().length * 6));
17919 }
17920 else {
17921 query = new StringBundler(3);
17922 }
17923
17924 query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17925
17926 query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17927
17928 query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17929
17930 query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17931
17932 query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17933
17934 if (orderByComparator != null) {
17935 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17936
17937 if (orderByConditionFields.length > 0) {
17938 query.append(WHERE_AND);
17939 }
17940
17941 for (int i = 0; i < orderByConditionFields.length; i++) {
17942 query.append(_ORDER_BY_ENTITY_ALIAS);
17943 query.append(orderByConditionFields[i]);
17944
17945 if ((i + 1) < orderByConditionFields.length) {
17946 if (orderByComparator.isAscending() ^ previous) {
17947 query.append(WHERE_GREATER_THAN_HAS_NEXT);
17948 }
17949 else {
17950 query.append(WHERE_LESSER_THAN_HAS_NEXT);
17951 }
17952 }
17953 else {
17954 if (orderByComparator.isAscending() ^ previous) {
17955 query.append(WHERE_GREATER_THAN);
17956 }
17957 else {
17958 query.append(WHERE_LESSER_THAN);
17959 }
17960 }
17961 }
17962
17963 query.append(ORDER_BY_CLAUSE);
17964
17965 String[] orderByFields = orderByComparator.getOrderByFields();
17966
17967 for (int i = 0; i < orderByFields.length; i++) {
17968 query.append(_ORDER_BY_ENTITY_ALIAS);
17969 query.append(orderByFields[i]);
17970
17971 if ((i + 1) < orderByFields.length) {
17972 if (orderByComparator.isAscending() ^ previous) {
17973 query.append(ORDER_BY_ASC_HAS_NEXT);
17974 }
17975 else {
17976 query.append(ORDER_BY_DESC_HAS_NEXT);
17977 }
17978 }
17979 else {
17980 if (orderByComparator.isAscending() ^ previous) {
17981 query.append(ORDER_BY_ASC);
17982 }
17983 else {
17984 query.append(ORDER_BY_DESC);
17985 }
17986 }
17987 }
17988 }
17989 else {
17990 query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17991 }
17992
17993 String sql = query.toString();
17994
17995 Query q = session.createQuery(sql);
17996
17997 q.setFirstResult(0);
17998 q.setMaxResults(2);
17999
18000 QueryPos qPos = QueryPos.getInstance(q);
18001
18002 qPos.add(userId);
18003
18004 qPos.add(classNameId);
18005
18006 qPos.add(classPK);
18007
18008 qPos.add(status);
18009
18010 if (orderByComparator != null) {
18011 Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18012
18013 for (Object value : values) {
18014 qPos.add(value);
18015 }
18016 }
18017
18018 List<MBMessage> list = q.list();
18019
18020 if (list.size() == 2) {
18021 return list.get(1);
18022 }
18023 else {
18024 return null;
18025 }
18026 }
18027
18028
18037 public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18038 int status) throws SystemException {
18039 for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18040 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18041 remove(mbMessage);
18042 }
18043 }
18044
18045
18055 public int countByU_C_C_S(long userId, long classNameId, long classPK,
18056 int status) throws SystemException {
18057 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18058
18059 Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18060
18061 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18062 this);
18063
18064 if (count == null) {
18065 StringBundler query = new StringBundler(5);
18066
18067 query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18068
18069 query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18070
18071 query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18072
18073 query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18074
18075 query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18076
18077 String sql = query.toString();
18078
18079 Session session = null;
18080
18081 try {
18082 session = openSession();
18083
18084 Query q = session.createQuery(sql);
18085
18086 QueryPos qPos = QueryPos.getInstance(q);
18087
18088 qPos.add(userId);
18089
18090 qPos.add(classNameId);
18091
18092 qPos.add(classPK);
18093
18094 qPos.add(status);
18095
18096 count = (Long)q.uniqueResult();
18097
18098 FinderCacheUtil.putResult(finderPath, finderArgs, count);
18099 }
18100 catch (Exception e) {
18101 FinderCacheUtil.removeResult(finderPath, finderArgs);
18102
18103 throw processException(e);
18104 }
18105 finally {
18106 closeSession(session);
18107 }
18108 }
18109
18110 return count.intValue();
18111 }
18112
18113 private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18114 private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18115 private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18116 private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18117
18118
18123 public void cacheResult(MBMessage mbMessage) {
18124 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18125 MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18126
18127 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18128 new Object[] {
18129 mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
18130 }, mbMessage);
18131
18132 mbMessage.resetOriginalValues();
18133 }
18134
18135
18140 public void cacheResult(List<MBMessage> mbMessages) {
18141 for (MBMessage mbMessage : mbMessages) {
18142 if (EntityCacheUtil.getResult(
18143 MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18144 MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18145 cacheResult(mbMessage);
18146 }
18147 else {
18148 mbMessage.resetOriginalValues();
18149 }
18150 }
18151 }
18152
18153
18160 @Override
18161 public void clearCache() {
18162 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
18163 CacheRegistryUtil.clear(MBMessageImpl.class.getName());
18164 }
18165
18166 EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
18167
18168 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18169 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18170 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18171 }
18172
18173
18180 @Override
18181 public void clearCache(MBMessage mbMessage) {
18182 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18183 MBMessageImpl.class, mbMessage.getPrimaryKey());
18184
18185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18187
18188 clearUniqueFindersCache(mbMessage);
18189 }
18190
18191 @Override
18192 public void clearCache(List<MBMessage> mbMessages) {
18193 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18195
18196 for (MBMessage mbMessage : mbMessages) {
18197 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18198 MBMessageImpl.class, mbMessage.getPrimaryKey());
18199
18200 clearUniqueFindersCache(mbMessage);
18201 }
18202 }
18203
18204 protected void cacheUniqueFindersCache(MBMessage mbMessage) {
18205 if (mbMessage.isNew()) {
18206 Object[] args = new Object[] {
18207 mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
18208 };
18209
18210 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18211 Long.valueOf(1));
18212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18213 mbMessage);
18214 }
18215 else {
18216 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18217
18218 if ((mbMessageModelImpl.getColumnBitmask() &
18219 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18220 Object[] args = new Object[] {
18221 mbMessage.getUuid(),
18222 Long.valueOf(mbMessage.getGroupId())
18223 };
18224
18225 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18226 Long.valueOf(1));
18227 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18228 mbMessage);
18229 }
18230 }
18231 }
18232
18233 protected void clearUniqueFindersCache(MBMessage mbMessage) {
18234 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18235
18236 Object[] args = new Object[] {
18237 mbMessage.getUuid(), Long.valueOf(mbMessage.getGroupId())
18238 };
18239
18240 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18241 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18242
18243 if ((mbMessageModelImpl.getColumnBitmask() &
18244 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18245 args = new Object[] {
18246 mbMessageModelImpl.getOriginalUuid(),
18247 Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
18248 };
18249
18250 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18251 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18252 }
18253 }
18254
18255
18261 public MBMessage create(long messageId) {
18262 MBMessage mbMessage = new MBMessageImpl();
18263
18264 mbMessage.setNew(true);
18265 mbMessage.setPrimaryKey(messageId);
18266
18267 String uuid = PortalUUIDUtil.generate();
18268
18269 mbMessage.setUuid(uuid);
18270
18271 return mbMessage;
18272 }
18273
18274
18282 public MBMessage remove(long messageId)
18283 throws NoSuchMessageException, SystemException {
18284 return remove(Long.valueOf(messageId));
18285 }
18286
18287
18295 @Override
18296 public MBMessage remove(Serializable primaryKey)
18297 throws NoSuchMessageException, SystemException {
18298 Session session = null;
18299
18300 try {
18301 session = openSession();
18302
18303 MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18304 primaryKey);
18305
18306 if (mbMessage == null) {
18307 if (_log.isWarnEnabled()) {
18308 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18309 }
18310
18311 throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18312 primaryKey);
18313 }
18314
18315 return remove(mbMessage);
18316 }
18317 catch (NoSuchMessageException nsee) {
18318 throw nsee;
18319 }
18320 catch (Exception e) {
18321 throw processException(e);
18322 }
18323 finally {
18324 closeSession(session);
18325 }
18326 }
18327
18328 @Override
18329 protected MBMessage removeImpl(MBMessage mbMessage)
18330 throws SystemException {
18331 mbMessage = toUnwrappedModel(mbMessage);
18332
18333 Session session = null;
18334
18335 try {
18336 session = openSession();
18337
18338 if (!session.contains(mbMessage)) {
18339 mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18340 mbMessage.getPrimaryKeyObj());
18341 }
18342
18343 if (mbMessage != null) {
18344 session.delete(mbMessage);
18345 }
18346 }
18347 catch (Exception e) {
18348 throw processException(e);
18349 }
18350 finally {
18351 closeSession(session);
18352 }
18353
18354 if (mbMessage != null) {
18355 clearCache(mbMessage);
18356 }
18357
18358 return mbMessage;
18359 }
18360
18361 @Override
18362 public MBMessage updateImpl(
18363 com.liferay.portlet.messageboards.model.MBMessage mbMessage)
18364 throws SystemException {
18365 mbMessage = toUnwrappedModel(mbMessage);
18366
18367 boolean isNew = mbMessage.isNew();
18368
18369 MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18370
18371 if (Validator.isNull(mbMessage.getUuid())) {
18372 String uuid = PortalUUIDUtil.generate();
18373
18374 mbMessage.setUuid(uuid);
18375 }
18376
18377 long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18378
18379 if (userId > 0) {
18380 long companyId = mbMessage.getCompanyId();
18381
18382 long groupId = mbMessage.getGroupId();
18383
18384 long messageId = 0;
18385
18386 if (!isNew) {
18387 messageId = mbMessage.getPrimaryKey();
18388 }
18389
18390 try {
18391 mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
18392 userId,
18393 com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
18394 messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18395 mbMessage.getSubject(), null));
18396 }
18397 catch (SanitizerException se) {
18398 throw new SystemException(se);
18399 }
18400 }
18401
18402 Session session = null;
18403
18404 try {
18405 session = openSession();
18406
18407 if (mbMessage.isNew()) {
18408 session.save(mbMessage);
18409
18410 mbMessage.setNew(false);
18411 }
18412 else {
18413 session.merge(mbMessage);
18414 }
18415 }
18416 catch (Exception e) {
18417 throw processException(e);
18418 }
18419 finally {
18420 closeSession(session);
18421 }
18422
18423 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18424
18425 if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
18426 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18427 }
18428
18429 else {
18430 if ((mbMessageModelImpl.getColumnBitmask() &
18431 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18432 Object[] args = new Object[] {
18433 mbMessageModelImpl.getOriginalUuid()
18434 };
18435
18436 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18437 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18438 args);
18439
18440 args = new Object[] { mbMessageModelImpl.getUuid() };
18441
18442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18443 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18444 args);
18445 }
18446
18447 if ((mbMessageModelImpl.getColumnBitmask() &
18448 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18449 Object[] args = new Object[] {
18450 mbMessageModelImpl.getOriginalUuid(),
18451 Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
18452 };
18453
18454 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18455 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18456 args);
18457
18458 args = new Object[] {
18459 mbMessageModelImpl.getUuid(),
18460 Long.valueOf(mbMessageModelImpl.getCompanyId())
18461 };
18462
18463 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18464 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18465 args);
18466 }
18467
18468 if ((mbMessageModelImpl.getColumnBitmask() &
18469 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
18470 Object[] args = new Object[] {
18471 Long.valueOf(mbMessageModelImpl.getOriginalGroupId())
18472 };
18473
18474 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18475 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18476 args);
18477
18478 args = new Object[] {
18479 Long.valueOf(mbMessageModelImpl.getGroupId())
18480 };
18481
18482 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18483 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18484 args);
18485 }
18486
18487 if ((mbMessageModelImpl.getColumnBitmask() &
18488 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
18489 Object[] args = new Object[] {
18490 Long.valueOf(mbMessageModelImpl.getOriginalCompanyId())
18491 };
18492
18493 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18494 args);
18495 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18496 args);
18497
18498 args = new Object[] {
18499 Long.valueOf(mbMessageModelImpl.getCompanyId())
18500 };
18501
18502 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18503 args);
18504 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18505 args);
18506 }
18507
18508 if ((mbMessageModelImpl.getColumnBitmask() &
18509 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
18510 Object[] args = new Object[] {
18511 Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
18512 };
18513
18514 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18515 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18516 args);
18517
18518 args = new Object[] {
18519 Long.valueOf(mbMessageModelImpl.getThreadId())
18520 };
18521
18522 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18523 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18524 args);
18525 }
18526
18527 if ((mbMessageModelImpl.getColumnBitmask() &
18528 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
18529 Object[] args = new Object[] {
18530 Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
18531 };
18532
18533 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18534 args);
18535 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18536 args);
18537
18538 args = new Object[] {
18539 Long.valueOf(mbMessageModelImpl.getThreadId())
18540 };
18541
18542 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18543 args);
18544 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18545 args);
18546 }
18547
18548 if ((mbMessageModelImpl.getColumnBitmask() &
18549 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
18550 Object[] args = new Object[] {
18551 Long.valueOf(mbMessageModelImpl.getOriginalUserId())
18552 };
18553
18554 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18555 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18556 args);
18557
18558 args = new Object[] { Long.valueOf(mbMessageModelImpl.getUserId()) };
18559
18560 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18561 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18562 args);
18563 }
18564
18565 if ((mbMessageModelImpl.getColumnBitmask() &
18566 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
18567 Object[] args = new Object[] {
18568 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18569 Long.valueOf(mbMessageModelImpl.getOriginalUserId())
18570 };
18571
18572 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18573 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18574 args);
18575
18576 args = new Object[] {
18577 Long.valueOf(mbMessageModelImpl.getGroupId()),
18578 Long.valueOf(mbMessageModelImpl.getUserId())
18579 };
18580
18581 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18582 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18583 args);
18584 }
18585
18586 if ((mbMessageModelImpl.getColumnBitmask() &
18587 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
18588 Object[] args = new Object[] {
18589 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18590 Long.valueOf(mbMessageModelImpl.getOriginalCategoryId())
18591 };
18592
18593 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18594 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18595 args);
18596
18597 args = new Object[] {
18598 Long.valueOf(mbMessageModelImpl.getGroupId()),
18599 Long.valueOf(mbMessageModelImpl.getCategoryId())
18600 };
18601
18602 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18603 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18604 args);
18605 }
18606
18607 if ((mbMessageModelImpl.getColumnBitmask() &
18608 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
18609 Object[] args = new Object[] {
18610 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18611 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18612 };
18613
18614 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18615 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18616 args);
18617
18618 args = new Object[] {
18619 Long.valueOf(mbMessageModelImpl.getGroupId()),
18620 Integer.valueOf(mbMessageModelImpl.getStatus())
18621 };
18622
18623 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18624 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18625 args);
18626 }
18627
18628 if ((mbMessageModelImpl.getColumnBitmask() &
18629 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
18630 Object[] args = new Object[] {
18631 Long.valueOf(mbMessageModelImpl.getOriginalCompanyId()),
18632 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18633 };
18634
18635 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18636 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18637 args);
18638
18639 args = new Object[] {
18640 Long.valueOf(mbMessageModelImpl.getCompanyId()),
18641 Integer.valueOf(mbMessageModelImpl.getStatus())
18642 };
18643
18644 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18645 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18646 args);
18647 }
18648
18649 if ((mbMessageModelImpl.getColumnBitmask() &
18650 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
18651 Object[] args = new Object[] {
18652 Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18653 Long.valueOf(mbMessageModelImpl.getOriginalClassNameId())
18654 };
18655
18656 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18657 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18658 args);
18659
18660 args = new Object[] {
18661 Long.valueOf(mbMessageModelImpl.getUserId()),
18662 Long.valueOf(mbMessageModelImpl.getClassNameId())
18663 };
18664
18665 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18666 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18667 args);
18668 }
18669
18670 if ((mbMessageModelImpl.getColumnBitmask() &
18671 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
18672 Object[] args = new Object[] {
18673 Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18674 Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
18675 };
18676
18677 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18678 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18679 args);
18680
18681 args = new Object[] {
18682 Long.valueOf(mbMessageModelImpl.getClassNameId()),
18683 Long.valueOf(mbMessageModelImpl.getClassPK())
18684 };
18685
18686 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18687 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18688 args);
18689 }
18690
18691 if ((mbMessageModelImpl.getColumnBitmask() &
18692 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
18693 Object[] args = new Object[] {
18694 Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18695 Long.valueOf(mbMessageModelImpl.getOriginalParentMessageId())
18696 };
18697
18698 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18699 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18700 args);
18701
18702 args = new Object[] {
18703 Long.valueOf(mbMessageModelImpl.getThreadId()),
18704 Long.valueOf(mbMessageModelImpl.getParentMessageId())
18705 };
18706
18707 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18708 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18709 args);
18710 }
18711
18712 if ((mbMessageModelImpl.getColumnBitmask() &
18713 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
18714 Object[] args = new Object[] {
18715 Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18716 Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
18717 };
18718
18719 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18720 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18721 args);
18722
18723 args = new Object[] {
18724 Long.valueOf(mbMessageModelImpl.getThreadId()),
18725 Boolean.valueOf(mbMessageModelImpl.getAnswer())
18726 };
18727
18728 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18729 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18730 args);
18731 }
18732
18733 if ((mbMessageModelImpl.getColumnBitmask() &
18734 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
18735 Object[] args = new Object[] {
18736 Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18737 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18738 };
18739
18740 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18741 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18742 args);
18743
18744 args = new Object[] {
18745 Long.valueOf(mbMessageModelImpl.getThreadId()),
18746 Integer.valueOf(mbMessageModelImpl.getStatus())
18747 };
18748
18749 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18750 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18751 args);
18752 }
18753
18754 if ((mbMessageModelImpl.getColumnBitmask() &
18755 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
18756 Object[] args = new Object[] {
18757 Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18758 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18759 };
18760
18761 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18762 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18763 args);
18764
18765 args = new Object[] {
18766 Long.valueOf(mbMessageModelImpl.getThreadId()),
18767 Integer.valueOf(mbMessageModelImpl.getStatus())
18768 };
18769
18770 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18771 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18772 args);
18773 }
18774
18775 if ((mbMessageModelImpl.getColumnBitmask() &
18776 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
18777 Object[] args = new Object[] {
18778 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18779 Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18780 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18781 };
18782
18783 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18784 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18785 args);
18786
18787 args = new Object[] {
18788 Long.valueOf(mbMessageModelImpl.getGroupId()),
18789 Long.valueOf(mbMessageModelImpl.getUserId()),
18790 Integer.valueOf(mbMessageModelImpl.getStatus())
18791 };
18792
18793 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18794 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18795 args);
18796 }
18797
18798 if ((mbMessageModelImpl.getColumnBitmask() &
18799 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
18800 Object[] args = new Object[] {
18801 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18802 Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18803 Long.valueOf(mbMessageModelImpl.getOriginalThreadId())
18804 };
18805
18806 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18807 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18808 args);
18809
18810 args = new Object[] {
18811 Long.valueOf(mbMessageModelImpl.getGroupId()),
18812 Long.valueOf(mbMessageModelImpl.getCategoryId()),
18813 Long.valueOf(mbMessageModelImpl.getThreadId())
18814 };
18815
18816 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18817 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18818 args);
18819 }
18820
18821 if ((mbMessageModelImpl.getColumnBitmask() &
18822 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
18823 Object[] args = new Object[] {
18824 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18825 Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18826 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18827 };
18828
18829 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18830 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18831 args);
18832
18833 args = new Object[] {
18834 Long.valueOf(mbMessageModelImpl.getGroupId()),
18835 Long.valueOf(mbMessageModelImpl.getCategoryId()),
18836 Integer.valueOf(mbMessageModelImpl.getStatus())
18837 };
18838
18839 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18840 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18841 args);
18842 }
18843
18844 if ((mbMessageModelImpl.getColumnBitmask() &
18845 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
18846 Object[] args = new Object[] {
18847 Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18848 Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18849 Long.valueOf(mbMessageModelImpl.getOriginalClassPK())
18850 };
18851
18852 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18853 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18854 args);
18855
18856 args = new Object[] {
18857 Long.valueOf(mbMessageModelImpl.getUserId()),
18858 Long.valueOf(mbMessageModelImpl.getClassNameId()),
18859 Long.valueOf(mbMessageModelImpl.getClassPK())
18860 };
18861
18862 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18863 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18864 args);
18865 }
18866
18867 if ((mbMessageModelImpl.getColumnBitmask() &
18868 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
18869 Object[] args = new Object[] {
18870 Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18871 Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18872 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18873 };
18874
18875 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18876 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18877 args);
18878
18879 args = new Object[] {
18880 Long.valueOf(mbMessageModelImpl.getUserId()),
18881 Long.valueOf(mbMessageModelImpl.getClassNameId()),
18882 Integer.valueOf(mbMessageModelImpl.getStatus())
18883 };
18884
18885 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18886 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18887 args);
18888 }
18889
18890 if ((mbMessageModelImpl.getColumnBitmask() &
18891 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
18892 Object[] args = new Object[] {
18893 Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18894 Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
18895 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18896 };
18897
18898 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18899 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18900 args);
18901
18902 args = new Object[] {
18903 Long.valueOf(mbMessageModelImpl.getClassNameId()),
18904 Long.valueOf(mbMessageModelImpl.getClassPK()),
18905 Integer.valueOf(mbMessageModelImpl.getStatus())
18906 };
18907
18908 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18909 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18910 args);
18911 }
18912
18913 if ((mbMessageModelImpl.getColumnBitmask() &
18914 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
18915 Object[] args = new Object[] {
18916 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18917 Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18918 Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18919 Boolean.valueOf(mbMessageModelImpl.getOriginalAnswer())
18920 };
18921
18922 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18923 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18924 args);
18925
18926 args = new Object[] {
18927 Long.valueOf(mbMessageModelImpl.getGroupId()),
18928 Long.valueOf(mbMessageModelImpl.getCategoryId()),
18929 Long.valueOf(mbMessageModelImpl.getThreadId()),
18930 Boolean.valueOf(mbMessageModelImpl.getAnswer())
18931 };
18932
18933 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18934 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18935 args);
18936 }
18937
18938 if ((mbMessageModelImpl.getColumnBitmask() &
18939 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
18940 Object[] args = new Object[] {
18941 Long.valueOf(mbMessageModelImpl.getOriginalGroupId()),
18942 Long.valueOf(mbMessageModelImpl.getOriginalCategoryId()),
18943 Long.valueOf(mbMessageModelImpl.getOriginalThreadId()),
18944 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18945 };
18946
18947 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18948 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18949 args);
18950
18951 args = new Object[] {
18952 Long.valueOf(mbMessageModelImpl.getGroupId()),
18953 Long.valueOf(mbMessageModelImpl.getCategoryId()),
18954 Long.valueOf(mbMessageModelImpl.getThreadId()),
18955 Integer.valueOf(mbMessageModelImpl.getStatus())
18956 };
18957
18958 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18959 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18960 args);
18961 }
18962
18963 if ((mbMessageModelImpl.getColumnBitmask() &
18964 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
18965 Object[] args = new Object[] {
18966 Long.valueOf(mbMessageModelImpl.getOriginalUserId()),
18967 Long.valueOf(mbMessageModelImpl.getOriginalClassNameId()),
18968 Long.valueOf(mbMessageModelImpl.getOriginalClassPK()),
18969 Integer.valueOf(mbMessageModelImpl.getOriginalStatus())
18970 };
18971
18972 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18973 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18974 args);
18975
18976 args = new Object[] {
18977 Long.valueOf(mbMessageModelImpl.getUserId()),
18978 Long.valueOf(mbMessageModelImpl.getClassNameId()),
18979 Long.valueOf(mbMessageModelImpl.getClassPK()),
18980 Integer.valueOf(mbMessageModelImpl.getStatus())
18981 };
18982
18983 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18984 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18985 args);
18986 }
18987 }
18988
18989 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18990 MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18991
18992 clearUniqueFindersCache(mbMessage);
18993 cacheUniqueFindersCache(mbMessage);
18994
18995 return mbMessage;
18996 }
18997
18998 protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
18999 if (mbMessage instanceof MBMessageImpl) {
19000 return mbMessage;
19001 }
19002
19003 MBMessageImpl mbMessageImpl = new MBMessageImpl();
19004
19005 mbMessageImpl.setNew(mbMessage.isNew());
19006 mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19007
19008 mbMessageImpl.setUuid(mbMessage.getUuid());
19009 mbMessageImpl.setMessageId(mbMessage.getMessageId());
19010 mbMessageImpl.setGroupId(mbMessage.getGroupId());
19011 mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19012 mbMessageImpl.setUserId(mbMessage.getUserId());
19013 mbMessageImpl.setUserName(mbMessage.getUserName());
19014 mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19015 mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19016 mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19017 mbMessageImpl.setClassPK(mbMessage.getClassPK());
19018 mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19019 mbMessageImpl.setThreadId(mbMessage.getThreadId());
19020 mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19021 mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19022 mbMessageImpl.setSubject(mbMessage.getSubject());
19023 mbMessageImpl.setBody(mbMessage.getBody());
19024 mbMessageImpl.setFormat(mbMessage.getFormat());
19025 mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19026 mbMessageImpl.setPriority(mbMessage.getPriority());
19027 mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19028 mbMessageImpl.setAnswer(mbMessage.isAnswer());
19029 mbMessageImpl.setStatus(mbMessage.getStatus());
19030 mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19031 mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19032 mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19033
19034 return mbMessageImpl;
19035 }
19036
19037
19045 @Override
19046 public MBMessage findByPrimaryKey(Serializable primaryKey)
19047 throws NoSuchModelException, SystemException {
19048 return findByPrimaryKey(((Long)primaryKey).longValue());
19049 }
19050
19051
19059 public MBMessage findByPrimaryKey(long messageId)
19060 throws NoSuchMessageException, SystemException {
19061 MBMessage mbMessage = fetchByPrimaryKey(messageId);
19062
19063 if (mbMessage == null) {
19064 if (_log.isWarnEnabled()) {
19065 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageId);
19066 }
19067
19068 throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19069 messageId);
19070 }
19071
19072 return mbMessage;
19073 }
19074
19075
19082 @Override
19083 public MBMessage fetchByPrimaryKey(Serializable primaryKey)
19084 throws SystemException {
19085 return fetchByPrimaryKey(((Long)primaryKey).longValue());
19086 }
19087
19088
19095 public MBMessage fetchByPrimaryKey(long messageId)
19096 throws SystemException {
19097 MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19098 MBMessageImpl.class, messageId);
19099
19100 if (mbMessage == _nullMBMessage) {
19101 return null;
19102 }
19103
19104 if (mbMessage == null) {
19105 Session session = null;
19106
19107 try {
19108 session = openSession();
19109
19110 mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19111 Long.valueOf(messageId));
19112
19113 if (mbMessage != null) {
19114 cacheResult(mbMessage);
19115 }
19116 else {
19117 EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19118 MBMessageImpl.class, messageId, _nullMBMessage);
19119 }
19120 }
19121 catch (Exception e) {
19122 EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19123 MBMessageImpl.class, messageId);
19124
19125 throw processException(e);
19126 }
19127 finally {
19128 closeSession(session);
19129 }
19130 }
19131
19132 return mbMessage;
19133 }
19134
19135
19141 public List<MBMessage> findAll() throws SystemException {
19142 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19143 }
19144
19145
19157 public List<MBMessage> findAll(int start, int end)
19158 throws SystemException {
19159 return findAll(start, end, null);
19160 }
19161
19162
19175 public List<MBMessage> findAll(int start, int end,
19176 OrderByComparator orderByComparator) throws SystemException {
19177 boolean pagination = true;
19178 FinderPath finderPath = null;
19179 Object[] finderArgs = null;
19180
19181 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19182 (orderByComparator == null)) {
19183 pagination = false;
19184 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19185 finderArgs = FINDER_ARGS_EMPTY;
19186 }
19187 else {
19188 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19189 finderArgs = new Object[] { start, end, orderByComparator };
19190 }
19191
19192 List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19193 finderArgs, this);
19194
19195 if (list == null) {
19196 StringBundler query = null;
19197 String sql = null;
19198
19199 if (orderByComparator != null) {
19200 query = new StringBundler(2 +
19201 (orderByComparator.getOrderByFields().length * 3));
19202
19203 query.append(_SQL_SELECT_MBMESSAGE);
19204
19205 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19206 orderByComparator);
19207
19208 sql = query.toString();
19209 }
19210 else {
19211 sql = _SQL_SELECT_MBMESSAGE;
19212
19213 if (pagination) {
19214 sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
19215 }
19216 }
19217
19218 Session session = null;
19219
19220 try {
19221 session = openSession();
19222
19223 Query q = session.createQuery(sql);
19224
19225 if (!pagination) {
19226 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19227 start, end, false);
19228
19229 Collections.sort(list);
19230
19231 list = new UnmodifiableList<MBMessage>(list);
19232 }
19233 else {
19234 list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19235 start, end);
19236 }
19237
19238 cacheResult(list);
19239
19240 FinderCacheUtil.putResult(finderPath, finderArgs, list);
19241 }
19242 catch (Exception e) {
19243 FinderCacheUtil.removeResult(finderPath, finderArgs);
19244
19245 throw processException(e);
19246 }
19247 finally {
19248 closeSession(session);
19249 }
19250 }
19251
19252 return list;
19253 }
19254
19255
19260 public void removeAll() throws SystemException {
19261 for (MBMessage mbMessage : findAll()) {
19262 remove(mbMessage);
19263 }
19264 }
19265
19266
19272 public int countAll() throws SystemException {
19273 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19274 FINDER_ARGS_EMPTY, this);
19275
19276 if (count == null) {
19277 Session session = null;
19278
19279 try {
19280 session = openSession();
19281
19282 Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
19283
19284 count = (Long)q.uniqueResult();
19285
19286 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19287 FINDER_ARGS_EMPTY, count);
19288 }
19289 catch (Exception e) {
19290 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19291 FINDER_ARGS_EMPTY);
19292
19293 throw processException(e);
19294 }
19295 finally {
19296 closeSession(session);
19297 }
19298 }
19299
19300 return count.intValue();
19301 }
19302
19303
19306 public void afterPropertiesSet() {
19307 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
19308 com.liferay.portal.util.PropsUtil.get(
19309 "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
19310
19311 if (listenerClassNames.length > 0) {
19312 try {
19313 List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
19314
19315 for (String listenerClassName : listenerClassNames) {
19316 listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
19317 listenerClassName));
19318 }
19319
19320 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
19321 }
19322 catch (Exception e) {
19323 _log.error(e);
19324 }
19325 }
19326 }
19327
19328 public void destroy() {
19329 EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
19330 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19331 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19332 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19333 }
19334
19335 private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19336 private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19337 private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19338 private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19339
19340 private static String _removeConjunction(String sql) {
19341 int pos = sql.indexOf(" AND ");
19342
19343 if (pos != -1) {
19344 sql = sql.substring(0, pos);
19345 }
19346
19347 return sql;
19348 }
19349
19350 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19351 private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19352 private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19353 "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19354 private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19355 ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19356 private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19357 private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19358 private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19359 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19360 private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19361 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19362 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19363 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19364 private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19365 private static MBMessage _nullMBMessage = new MBMessageImpl() {
19366 @Override
19367 public Object clone() {
19368 return this;
19369 }
19370
19371 @Override
19372 public CacheModel<MBMessage> toCacheModel() {
19373 return _nullMBMessageCacheModel;
19374 }
19375 };
19376
19377 private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19378 public MBMessage toEntityModel() {
19379 return _nullMBMessage;
19380 }
19381 };
19382 }