001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.BatchSessionUtil;
038 import com.liferay.portal.service.persistence.ResourcePersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.messageboards.NoSuchMessageFlagException;
043 import com.liferay.portlet.messageboards.model.MBMessageFlag;
044 import com.liferay.portlet.messageboards.model.impl.MBMessageFlagImpl;
045 import com.liferay.portlet.messageboards.model.impl.MBMessageFlagModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
069 public class MBMessageFlagPersistenceImpl extends BasePersistenceImpl<MBMessageFlag>
070 implements MBMessageFlagPersistence {
071 public static final String FINDER_CLASS_NAME_ENTITY = MBMessageFlagImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073 ".List";
074 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
075 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
076 FINDER_CLASS_NAME_LIST, "findByUserId",
077 new String[] {
078 Long.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
084 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
085 FINDER_CLASS_NAME_LIST, "countByUserId",
086 new String[] { Long.class.getName() });
087 public static final FinderPath FINDER_PATH_FIND_BY_THREADID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
088 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
089 FINDER_CLASS_NAME_LIST, "findByThreadId",
090 new String[] {
091 Long.class.getName(),
092
093 "java.lang.Integer", "java.lang.Integer",
094 "com.liferay.portal.kernel.util.OrderByComparator"
095 });
096 public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
097 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
098 FINDER_CLASS_NAME_LIST, "countByThreadId",
099 new String[] { Long.class.getName() });
100 public static final FinderPath FINDER_PATH_FIND_BY_MESSAGEID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
101 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
102 FINDER_CLASS_NAME_LIST, "findByMessageId",
103 new String[] {
104 Long.class.getName(),
105
106 "java.lang.Integer", "java.lang.Integer",
107 "com.liferay.portal.kernel.util.OrderByComparator"
108 });
109 public static final FinderPath FINDER_PATH_COUNT_BY_MESSAGEID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
110 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
111 FINDER_CLASS_NAME_LIST, "countByMessageId",
112 new String[] { Long.class.getName() });
113 public static final FinderPath FINDER_PATH_FIND_BY_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
114 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
115 FINDER_CLASS_NAME_LIST, "findByT_F",
116 new String[] {
117 Long.class.getName(), Integer.class.getName(),
118
119 "java.lang.Integer", "java.lang.Integer",
120 "com.liferay.portal.kernel.util.OrderByComparator"
121 });
122 public static final FinderPath FINDER_PATH_COUNT_BY_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
123 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
124 FINDER_CLASS_NAME_LIST, "countByT_F",
125 new String[] { Long.class.getName(), Integer.class.getName() });
126 public static final FinderPath FINDER_PATH_FIND_BY_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
127 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
128 FINDER_CLASS_NAME_LIST, "findByM_F",
129 new String[] {
130 Long.class.getName(), Integer.class.getName(),
131
132 "java.lang.Integer", "java.lang.Integer",
133 "com.liferay.portal.kernel.util.OrderByComparator"
134 });
135 public static final FinderPath FINDER_PATH_COUNT_BY_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
136 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
137 FINDER_CLASS_NAME_LIST, "countByM_F",
138 new String[] { Long.class.getName(), Integer.class.getName() });
139 public static final FinderPath FINDER_PATH_FIND_BY_U_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
140 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
141 FINDER_CLASS_NAME_LIST, "findByU_T_F",
142 new String[] {
143 Long.class.getName(), Long.class.getName(),
144 Integer.class.getName(),
145
146 "java.lang.Integer", "java.lang.Integer",
147 "com.liferay.portal.kernel.util.OrderByComparator"
148 });
149 public static final FinderPath FINDER_PATH_COUNT_BY_U_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
150 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
151 FINDER_CLASS_NAME_LIST, "countByU_T_F",
152 new String[] {
153 Long.class.getName(), Long.class.getName(),
154 Integer.class.getName()
155 });
156 public static final FinderPath FINDER_PATH_FETCH_BY_U_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
157 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
158 FINDER_CLASS_NAME_ENTITY, "fetchByU_M_F",
159 new String[] {
160 Long.class.getName(), Long.class.getName(),
161 Integer.class.getName()
162 });
163 public static final FinderPath FINDER_PATH_COUNT_BY_U_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
164 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
165 FINDER_CLASS_NAME_LIST, "countByU_M_F",
166 new String[] {
167 Long.class.getName(), Long.class.getName(),
168 Integer.class.getName()
169 });
170 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
171 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
172 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
173 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
174 MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
175 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
176
177
182 public void cacheResult(MBMessageFlag mbMessageFlag) {
183 EntityCacheUtil.putResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
184 MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
185 mbMessageFlag);
186
187 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
188 new Object[] {
189 new Long(mbMessageFlag.getUserId()),
190 new Long(mbMessageFlag.getMessageId()),
191 new Integer(mbMessageFlag.getFlag())
192 }, mbMessageFlag);
193 }
194
195
200 public void cacheResult(List<MBMessageFlag> mbMessageFlags) {
201 for (MBMessageFlag mbMessageFlag : mbMessageFlags) {
202 if (EntityCacheUtil.getResult(
203 MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
204 MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
205 this) == null) {
206 cacheResult(mbMessageFlag);
207 }
208 }
209 }
210
211
218 public void clearCache() {
219 CacheRegistryUtil.clear(MBMessageFlagImpl.class.getName());
220 EntityCacheUtil.clearCache(MBMessageFlagImpl.class.getName());
221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223 }
224
225
232 public void clearCache(MBMessageFlag mbMessageFlag) {
233 EntityCacheUtil.removeResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
234 MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey());
235
236 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
237 new Object[] {
238 new Long(mbMessageFlag.getUserId()),
239 new Long(mbMessageFlag.getMessageId()),
240 new Integer(mbMessageFlag.getFlag())
241 });
242 }
243
244
250 public MBMessageFlag create(long messageFlagId) {
251 MBMessageFlag mbMessageFlag = new MBMessageFlagImpl();
252
253 mbMessageFlag.setNew(true);
254 mbMessageFlag.setPrimaryKey(messageFlagId);
255
256 return mbMessageFlag;
257 }
258
259
267 public MBMessageFlag remove(Serializable primaryKey)
268 throws NoSuchModelException, SystemException {
269 return remove(((Long)primaryKey).longValue());
270 }
271
272
280 public MBMessageFlag remove(long messageFlagId)
281 throws NoSuchMessageFlagException, SystemException {
282 Session session = null;
283
284 try {
285 session = openSession();
286
287 MBMessageFlag mbMessageFlag = (MBMessageFlag)session.get(MBMessageFlagImpl.class,
288 new Long(messageFlagId));
289
290 if (mbMessageFlag == null) {
291 if (_log.isWarnEnabled()) {
292 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageFlagId);
293 }
294
295 throw new NoSuchMessageFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
296 messageFlagId);
297 }
298
299 return remove(mbMessageFlag);
300 }
301 catch (NoSuchMessageFlagException nsee) {
302 throw nsee;
303 }
304 catch (Exception e) {
305 throw processException(e);
306 }
307 finally {
308 closeSession(session);
309 }
310 }
311
312 protected MBMessageFlag removeImpl(MBMessageFlag mbMessageFlag)
313 throws SystemException {
314 mbMessageFlag = toUnwrappedModel(mbMessageFlag);
315
316 Session session = null;
317
318 try {
319 session = openSession();
320
321 BatchSessionUtil.delete(session, mbMessageFlag);
322 }
323 catch (Exception e) {
324 throw processException(e);
325 }
326 finally {
327 closeSession(session);
328 }
329
330 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
331
332 MBMessageFlagModelImpl mbMessageFlagModelImpl = (MBMessageFlagModelImpl)mbMessageFlag;
333
334 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
335 new Object[] {
336 new Long(mbMessageFlagModelImpl.getUserId()),
337 new Long(mbMessageFlagModelImpl.getMessageId()),
338 new Integer(mbMessageFlagModelImpl.getFlag())
339 });
340
341 EntityCacheUtil.removeResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
342 MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey());
343
344 return mbMessageFlag;
345 }
346
347 public MBMessageFlag updateImpl(
348 com.liferay.portlet.messageboards.model.MBMessageFlag mbMessageFlag,
349 boolean merge) throws SystemException {
350 mbMessageFlag = toUnwrappedModel(mbMessageFlag);
351
352 boolean isNew = mbMessageFlag.isNew();
353
354 MBMessageFlagModelImpl mbMessageFlagModelImpl = (MBMessageFlagModelImpl)mbMessageFlag;
355
356 Session session = null;
357
358 try {
359 session = openSession();
360
361 BatchSessionUtil.update(session, mbMessageFlag, merge);
362
363 mbMessageFlag.setNew(false);
364 }
365 catch (Exception e) {
366 throw processException(e);
367 }
368 finally {
369 closeSession(session);
370 }
371
372 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
373
374 EntityCacheUtil.putResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
375 MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
376 mbMessageFlag);
377
378 if (!isNew &&
379 ((mbMessageFlag.getUserId() != mbMessageFlagModelImpl.getOriginalUserId()) ||
380 (mbMessageFlag.getMessageId() != mbMessageFlagModelImpl.getOriginalMessageId()) ||
381 (mbMessageFlag.getFlag() != mbMessageFlagModelImpl.getOriginalFlag()))) {
382 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
383 new Object[] {
384 new Long(mbMessageFlagModelImpl.getOriginalUserId()),
385 new Long(mbMessageFlagModelImpl.getOriginalMessageId()),
386 new Integer(mbMessageFlagModelImpl.getOriginalFlag())
387 });
388 }
389
390 if (isNew ||
391 ((mbMessageFlag.getUserId() != mbMessageFlagModelImpl.getOriginalUserId()) ||
392 (mbMessageFlag.getMessageId() != mbMessageFlagModelImpl.getOriginalMessageId()) ||
393 (mbMessageFlag.getFlag() != mbMessageFlagModelImpl.getOriginalFlag()))) {
394 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
395 new Object[] {
396 new Long(mbMessageFlag.getUserId()),
397 new Long(mbMessageFlag.getMessageId()),
398 new Integer(mbMessageFlag.getFlag())
399 }, mbMessageFlag);
400 }
401
402 return mbMessageFlag;
403 }
404
405 protected MBMessageFlag toUnwrappedModel(MBMessageFlag mbMessageFlag) {
406 if (mbMessageFlag instanceof MBMessageFlagImpl) {
407 return mbMessageFlag;
408 }
409
410 MBMessageFlagImpl mbMessageFlagImpl = new MBMessageFlagImpl();
411
412 mbMessageFlagImpl.setNew(mbMessageFlag.isNew());
413 mbMessageFlagImpl.setPrimaryKey(mbMessageFlag.getPrimaryKey());
414
415 mbMessageFlagImpl.setMessageFlagId(mbMessageFlag.getMessageFlagId());
416 mbMessageFlagImpl.setUserId(mbMessageFlag.getUserId());
417 mbMessageFlagImpl.setModifiedDate(mbMessageFlag.getModifiedDate());
418 mbMessageFlagImpl.setThreadId(mbMessageFlag.getThreadId());
419 mbMessageFlagImpl.setMessageId(mbMessageFlag.getMessageId());
420 mbMessageFlagImpl.setFlag(mbMessageFlag.getFlag());
421
422 return mbMessageFlagImpl;
423 }
424
425
433 public MBMessageFlag findByPrimaryKey(Serializable primaryKey)
434 throws NoSuchModelException, SystemException {
435 return findByPrimaryKey(((Long)primaryKey).longValue());
436 }
437
438
446 public MBMessageFlag findByPrimaryKey(long messageFlagId)
447 throws NoSuchMessageFlagException, SystemException {
448 MBMessageFlag mbMessageFlag = fetchByPrimaryKey(messageFlagId);
449
450 if (mbMessageFlag == null) {
451 if (_log.isWarnEnabled()) {
452 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageFlagId);
453 }
454
455 throw new NoSuchMessageFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
456 messageFlagId);
457 }
458
459 return mbMessageFlag;
460 }
461
462
469 public MBMessageFlag fetchByPrimaryKey(Serializable primaryKey)
470 throws SystemException {
471 return fetchByPrimaryKey(((Long)primaryKey).longValue());
472 }
473
474
481 public MBMessageFlag fetchByPrimaryKey(long messageFlagId)
482 throws SystemException {
483 MBMessageFlag mbMessageFlag = (MBMessageFlag)EntityCacheUtil.getResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
484 MBMessageFlagImpl.class, messageFlagId, this);
485
486 if (mbMessageFlag == null) {
487 Session session = null;
488
489 try {
490 session = openSession();
491
492 mbMessageFlag = (MBMessageFlag)session.get(MBMessageFlagImpl.class,
493 new Long(messageFlagId));
494 }
495 catch (Exception e) {
496 throw processException(e);
497 }
498 finally {
499 if (mbMessageFlag != null) {
500 cacheResult(mbMessageFlag);
501 }
502
503 closeSession(session);
504 }
505 }
506
507 return mbMessageFlag;
508 }
509
510
517 public List<MBMessageFlag> findByUserId(long userId)
518 throws SystemException {
519 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
520 }
521
522
535 public List<MBMessageFlag> findByUserId(long userId, int start, int end)
536 throws SystemException {
537 return findByUserId(userId, start, end, null);
538 }
539
540
554 public List<MBMessageFlag> findByUserId(long userId, int start, int end,
555 OrderByComparator orderByComparator) throws SystemException {
556 Object[] finderArgs = new Object[] {
557 userId,
558
559 String.valueOf(start), String.valueOf(end),
560 String.valueOf(orderByComparator)
561 };
562
563 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
564 finderArgs, this);
565
566 if (list == null) {
567 StringBundler query = null;
568
569 if (orderByComparator != null) {
570 query = new StringBundler(3 +
571 (orderByComparator.getOrderByFields().length * 3));
572 }
573 else {
574 query = new StringBundler(2);
575 }
576
577 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
578
579 query.append(_FINDER_COLUMN_USERID_USERID_2);
580
581 if (orderByComparator != null) {
582 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
583 orderByComparator);
584 }
585
586 String sql = query.toString();
587
588 Session session = null;
589
590 try {
591 session = openSession();
592
593 Query q = session.createQuery(sql);
594
595 QueryPos qPos = QueryPos.getInstance(q);
596
597 qPos.add(userId);
598
599 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
600 start, end);
601 }
602 catch (Exception e) {
603 throw processException(e);
604 }
605 finally {
606 if (list == null) {
607 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
608 finderArgs);
609 }
610 else {
611 cacheResult(list);
612
613 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
614 finderArgs, list);
615 }
616
617 closeSession(session);
618 }
619 }
620
621 return list;
622 }
623
624
637 public MBMessageFlag findByUserId_First(long userId,
638 OrderByComparator orderByComparator)
639 throws NoSuchMessageFlagException, SystemException {
640 List<MBMessageFlag> list = findByUserId(userId, 0, 1, orderByComparator);
641
642 if (list.isEmpty()) {
643 StringBundler msg = new StringBundler(4);
644
645 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646
647 msg.append("userId=");
648 msg.append(userId);
649
650 msg.append(StringPool.CLOSE_CURLY_BRACE);
651
652 throw new NoSuchMessageFlagException(msg.toString());
653 }
654 else {
655 return list.get(0);
656 }
657 }
658
659
672 public MBMessageFlag findByUserId_Last(long userId,
673 OrderByComparator orderByComparator)
674 throws NoSuchMessageFlagException, SystemException {
675 int count = countByUserId(userId);
676
677 List<MBMessageFlag> list = findByUserId(userId, count - 1, count,
678 orderByComparator);
679
680 if (list.isEmpty()) {
681 StringBundler msg = new StringBundler(4);
682
683 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
684
685 msg.append("userId=");
686 msg.append(userId);
687
688 msg.append(StringPool.CLOSE_CURLY_BRACE);
689
690 throw new NoSuchMessageFlagException(msg.toString());
691 }
692 else {
693 return list.get(0);
694 }
695 }
696
697
711 public MBMessageFlag[] findByUserId_PrevAndNext(long messageFlagId,
712 long userId, OrderByComparator orderByComparator)
713 throws NoSuchMessageFlagException, SystemException {
714 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
715
716 Session session = null;
717
718 try {
719 session = openSession();
720
721 MBMessageFlag[] array = new MBMessageFlagImpl[3];
722
723 array[0] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
724 orderByComparator, true);
725
726 array[1] = mbMessageFlag;
727
728 array[2] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
729 orderByComparator, false);
730
731 return array;
732 }
733 catch (Exception e) {
734 throw processException(e);
735 }
736 finally {
737 closeSession(session);
738 }
739 }
740
741 protected MBMessageFlag getByUserId_PrevAndNext(Session session,
742 MBMessageFlag mbMessageFlag, long userId,
743 OrderByComparator orderByComparator, boolean previous) {
744 StringBundler query = null;
745
746 if (orderByComparator != null) {
747 query = new StringBundler(6 +
748 (orderByComparator.getOrderByFields().length * 6));
749 }
750 else {
751 query = new StringBundler(3);
752 }
753
754 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
755
756 query.append(_FINDER_COLUMN_USERID_USERID_2);
757
758 if (orderByComparator != null) {
759 String[] orderByFields = orderByComparator.getOrderByFields();
760
761 if (orderByFields.length > 0) {
762 query.append(WHERE_AND);
763 }
764
765 for (int i = 0; i < orderByFields.length; i++) {
766 query.append(_ORDER_BY_ENTITY_ALIAS);
767 query.append(orderByFields[i]);
768
769 if ((i + 1) < orderByFields.length) {
770 if (orderByComparator.isAscending() ^ previous) {
771 query.append(WHERE_GREATER_THAN_HAS_NEXT);
772 }
773 else {
774 query.append(WHERE_LESSER_THAN_HAS_NEXT);
775 }
776 }
777 else {
778 if (orderByComparator.isAscending() ^ previous) {
779 query.append(WHERE_GREATER_THAN);
780 }
781 else {
782 query.append(WHERE_LESSER_THAN);
783 }
784 }
785 }
786
787 query.append(ORDER_BY_CLAUSE);
788
789 for (int i = 0; i < orderByFields.length; i++) {
790 query.append(_ORDER_BY_ENTITY_ALIAS);
791 query.append(orderByFields[i]);
792
793 if ((i + 1) < orderByFields.length) {
794 if (orderByComparator.isAscending() ^ previous) {
795 query.append(ORDER_BY_ASC_HAS_NEXT);
796 }
797 else {
798 query.append(ORDER_BY_DESC_HAS_NEXT);
799 }
800 }
801 else {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(ORDER_BY_ASC);
804 }
805 else {
806 query.append(ORDER_BY_DESC);
807 }
808 }
809 }
810 }
811
812 String sql = query.toString();
813
814 Query q = session.createQuery(sql);
815
816 q.setFirstResult(0);
817 q.setMaxResults(2);
818
819 QueryPos qPos = QueryPos.getInstance(q);
820
821 qPos.add(userId);
822
823 if (orderByComparator != null) {
824 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
825
826 for (Object value : values) {
827 qPos.add(value);
828 }
829 }
830
831 List<MBMessageFlag> list = q.list();
832
833 if (list.size() == 2) {
834 return list.get(1);
835 }
836 else {
837 return null;
838 }
839 }
840
841
848 public List<MBMessageFlag> findByThreadId(long threadId)
849 throws SystemException {
850 return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
851 null);
852 }
853
854
867 public List<MBMessageFlag> findByThreadId(long threadId, int start, int end)
868 throws SystemException {
869 return findByThreadId(threadId, start, end, null);
870 }
871
872
886 public List<MBMessageFlag> findByThreadId(long threadId, int start,
887 int end, OrderByComparator orderByComparator) throws SystemException {
888 Object[] finderArgs = new Object[] {
889 threadId,
890
891 String.valueOf(start), String.valueOf(end),
892 String.valueOf(orderByComparator)
893 };
894
895 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
896 finderArgs, this);
897
898 if (list == null) {
899 StringBundler query = null;
900
901 if (orderByComparator != null) {
902 query = new StringBundler(3 +
903 (orderByComparator.getOrderByFields().length * 3));
904 }
905 else {
906 query = new StringBundler(2);
907 }
908
909 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
910
911 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
912
913 if (orderByComparator != null) {
914 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
915 orderByComparator);
916 }
917
918 String sql = query.toString();
919
920 Session session = null;
921
922 try {
923 session = openSession();
924
925 Query q = session.createQuery(sql);
926
927 QueryPos qPos = QueryPos.getInstance(q);
928
929 qPos.add(threadId);
930
931 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
932 start, end);
933 }
934 catch (Exception e) {
935 throw processException(e);
936 }
937 finally {
938 if (list == null) {
939 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_THREADID,
940 finderArgs);
941 }
942 else {
943 cacheResult(list);
944
945 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
946 finderArgs, list);
947 }
948
949 closeSession(session);
950 }
951 }
952
953 return list;
954 }
955
956
969 public MBMessageFlag findByThreadId_First(long threadId,
970 OrderByComparator orderByComparator)
971 throws NoSuchMessageFlagException, SystemException {
972 List<MBMessageFlag> list = findByThreadId(threadId, 0, 1,
973 orderByComparator);
974
975 if (list.isEmpty()) {
976 StringBundler msg = new StringBundler(4);
977
978 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
979
980 msg.append("threadId=");
981 msg.append(threadId);
982
983 msg.append(StringPool.CLOSE_CURLY_BRACE);
984
985 throw new NoSuchMessageFlagException(msg.toString());
986 }
987 else {
988 return list.get(0);
989 }
990 }
991
992
1005 public MBMessageFlag findByThreadId_Last(long threadId,
1006 OrderByComparator orderByComparator)
1007 throws NoSuchMessageFlagException, SystemException {
1008 int count = countByThreadId(threadId);
1009
1010 List<MBMessageFlag> list = findByThreadId(threadId, count - 1, count,
1011 orderByComparator);
1012
1013 if (list.isEmpty()) {
1014 StringBundler msg = new StringBundler(4);
1015
1016 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1017
1018 msg.append("threadId=");
1019 msg.append(threadId);
1020
1021 msg.append(StringPool.CLOSE_CURLY_BRACE);
1022
1023 throw new NoSuchMessageFlagException(msg.toString());
1024 }
1025 else {
1026 return list.get(0);
1027 }
1028 }
1029
1030
1044 public MBMessageFlag[] findByThreadId_PrevAndNext(long messageFlagId,
1045 long threadId, OrderByComparator orderByComparator)
1046 throws NoSuchMessageFlagException, SystemException {
1047 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1048
1049 Session session = null;
1050
1051 try {
1052 session = openSession();
1053
1054 MBMessageFlag[] array = new MBMessageFlagImpl[3];
1055
1056 array[0] = getByThreadId_PrevAndNext(session, mbMessageFlag,
1057 threadId, orderByComparator, true);
1058
1059 array[1] = mbMessageFlag;
1060
1061 array[2] = getByThreadId_PrevAndNext(session, mbMessageFlag,
1062 threadId, orderByComparator, false);
1063
1064 return array;
1065 }
1066 catch (Exception e) {
1067 throw processException(e);
1068 }
1069 finally {
1070 closeSession(session);
1071 }
1072 }
1073
1074 protected MBMessageFlag getByThreadId_PrevAndNext(Session session,
1075 MBMessageFlag mbMessageFlag, long threadId,
1076 OrderByComparator orderByComparator, boolean previous) {
1077 StringBundler query = null;
1078
1079 if (orderByComparator != null) {
1080 query = new StringBundler(6 +
1081 (orderByComparator.getOrderByFields().length * 6));
1082 }
1083 else {
1084 query = new StringBundler(3);
1085 }
1086
1087 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1088
1089 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1090
1091 if (orderByComparator != null) {
1092 String[] orderByFields = orderByComparator.getOrderByFields();
1093
1094 if (orderByFields.length > 0) {
1095 query.append(WHERE_AND);
1096 }
1097
1098 for (int i = 0; i < orderByFields.length; i++) {
1099 query.append(_ORDER_BY_ENTITY_ALIAS);
1100 query.append(orderByFields[i]);
1101
1102 if ((i + 1) < orderByFields.length) {
1103 if (orderByComparator.isAscending() ^ previous) {
1104 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1105 }
1106 else {
1107 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1108 }
1109 }
1110 else {
1111 if (orderByComparator.isAscending() ^ previous) {
1112 query.append(WHERE_GREATER_THAN);
1113 }
1114 else {
1115 query.append(WHERE_LESSER_THAN);
1116 }
1117 }
1118 }
1119
1120 query.append(ORDER_BY_CLAUSE);
1121
1122 for (int i = 0; i < orderByFields.length; i++) {
1123 query.append(_ORDER_BY_ENTITY_ALIAS);
1124 query.append(orderByFields[i]);
1125
1126 if ((i + 1) < orderByFields.length) {
1127 if (orderByComparator.isAscending() ^ previous) {
1128 query.append(ORDER_BY_ASC_HAS_NEXT);
1129 }
1130 else {
1131 query.append(ORDER_BY_DESC_HAS_NEXT);
1132 }
1133 }
1134 else {
1135 if (orderByComparator.isAscending() ^ previous) {
1136 query.append(ORDER_BY_ASC);
1137 }
1138 else {
1139 query.append(ORDER_BY_DESC);
1140 }
1141 }
1142 }
1143 }
1144
1145 String sql = query.toString();
1146
1147 Query q = session.createQuery(sql);
1148
1149 q.setFirstResult(0);
1150 q.setMaxResults(2);
1151
1152 QueryPos qPos = QueryPos.getInstance(q);
1153
1154 qPos.add(threadId);
1155
1156 if (orderByComparator != null) {
1157 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1158
1159 for (Object value : values) {
1160 qPos.add(value);
1161 }
1162 }
1163
1164 List<MBMessageFlag> list = q.list();
1165
1166 if (list.size() == 2) {
1167 return list.get(1);
1168 }
1169 else {
1170 return null;
1171 }
1172 }
1173
1174
1181 public List<MBMessageFlag> findByMessageId(long messageId)
1182 throws SystemException {
1183 return findByMessageId(messageId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1184 null);
1185 }
1186
1187
1200 public List<MBMessageFlag> findByMessageId(long messageId, int start,
1201 int end) throws SystemException {
1202 return findByMessageId(messageId, start, end, null);
1203 }
1204
1205
1219 public List<MBMessageFlag> findByMessageId(long messageId, int start,
1220 int end, OrderByComparator orderByComparator) throws SystemException {
1221 Object[] finderArgs = new Object[] {
1222 messageId,
1223
1224 String.valueOf(start), String.valueOf(end),
1225 String.valueOf(orderByComparator)
1226 };
1227
1228 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_MESSAGEID,
1229 finderArgs, this);
1230
1231 if (list == null) {
1232 StringBundler query = null;
1233
1234 if (orderByComparator != null) {
1235 query = new StringBundler(3 +
1236 (orderByComparator.getOrderByFields().length * 3));
1237 }
1238 else {
1239 query = new StringBundler(2);
1240 }
1241
1242 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1243
1244 query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1245
1246 if (orderByComparator != null) {
1247 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1248 orderByComparator);
1249 }
1250
1251 String sql = query.toString();
1252
1253 Session session = null;
1254
1255 try {
1256 session = openSession();
1257
1258 Query q = session.createQuery(sql);
1259
1260 QueryPos qPos = QueryPos.getInstance(q);
1261
1262 qPos.add(messageId);
1263
1264 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1265 start, end);
1266 }
1267 catch (Exception e) {
1268 throw processException(e);
1269 }
1270 finally {
1271 if (list == null) {
1272 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_MESSAGEID,
1273 finderArgs);
1274 }
1275 else {
1276 cacheResult(list);
1277
1278 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_MESSAGEID,
1279 finderArgs, list);
1280 }
1281
1282 closeSession(session);
1283 }
1284 }
1285
1286 return list;
1287 }
1288
1289
1302 public MBMessageFlag findByMessageId_First(long messageId,
1303 OrderByComparator orderByComparator)
1304 throws NoSuchMessageFlagException, SystemException {
1305 List<MBMessageFlag> list = findByMessageId(messageId, 0, 1,
1306 orderByComparator);
1307
1308 if (list.isEmpty()) {
1309 StringBundler msg = new StringBundler(4);
1310
1311 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1312
1313 msg.append("messageId=");
1314 msg.append(messageId);
1315
1316 msg.append(StringPool.CLOSE_CURLY_BRACE);
1317
1318 throw new NoSuchMessageFlagException(msg.toString());
1319 }
1320 else {
1321 return list.get(0);
1322 }
1323 }
1324
1325
1338 public MBMessageFlag findByMessageId_Last(long messageId,
1339 OrderByComparator orderByComparator)
1340 throws NoSuchMessageFlagException, SystemException {
1341 int count = countByMessageId(messageId);
1342
1343 List<MBMessageFlag> list = findByMessageId(messageId, count - 1, count,
1344 orderByComparator);
1345
1346 if (list.isEmpty()) {
1347 StringBundler msg = new StringBundler(4);
1348
1349 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1350
1351 msg.append("messageId=");
1352 msg.append(messageId);
1353
1354 msg.append(StringPool.CLOSE_CURLY_BRACE);
1355
1356 throw new NoSuchMessageFlagException(msg.toString());
1357 }
1358 else {
1359 return list.get(0);
1360 }
1361 }
1362
1363
1377 public MBMessageFlag[] findByMessageId_PrevAndNext(long messageFlagId,
1378 long messageId, OrderByComparator orderByComparator)
1379 throws NoSuchMessageFlagException, SystemException {
1380 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1381
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 MBMessageFlag[] array = new MBMessageFlagImpl[3];
1388
1389 array[0] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1390 messageId, orderByComparator, true);
1391
1392 array[1] = mbMessageFlag;
1393
1394 array[2] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1395 messageId, orderByComparator, false);
1396
1397 return array;
1398 }
1399 catch (Exception e) {
1400 throw processException(e);
1401 }
1402 finally {
1403 closeSession(session);
1404 }
1405 }
1406
1407 protected MBMessageFlag getByMessageId_PrevAndNext(Session session,
1408 MBMessageFlag mbMessageFlag, long messageId,
1409 OrderByComparator orderByComparator, boolean previous) {
1410 StringBundler query = null;
1411
1412 if (orderByComparator != null) {
1413 query = new StringBundler(6 +
1414 (orderByComparator.getOrderByFields().length * 6));
1415 }
1416 else {
1417 query = new StringBundler(3);
1418 }
1419
1420 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1421
1422 query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1423
1424 if (orderByComparator != null) {
1425 String[] orderByFields = orderByComparator.getOrderByFields();
1426
1427 if (orderByFields.length > 0) {
1428 query.append(WHERE_AND);
1429 }
1430
1431 for (int i = 0; i < orderByFields.length; i++) {
1432 query.append(_ORDER_BY_ENTITY_ALIAS);
1433 query.append(orderByFields[i]);
1434
1435 if ((i + 1) < orderByFields.length) {
1436 if (orderByComparator.isAscending() ^ previous) {
1437 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1438 }
1439 else {
1440 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1441 }
1442 }
1443 else {
1444 if (orderByComparator.isAscending() ^ previous) {
1445 query.append(WHERE_GREATER_THAN);
1446 }
1447 else {
1448 query.append(WHERE_LESSER_THAN);
1449 }
1450 }
1451 }
1452
1453 query.append(ORDER_BY_CLAUSE);
1454
1455 for (int i = 0; i < orderByFields.length; i++) {
1456 query.append(_ORDER_BY_ENTITY_ALIAS);
1457 query.append(orderByFields[i]);
1458
1459 if ((i + 1) < orderByFields.length) {
1460 if (orderByComparator.isAscending() ^ previous) {
1461 query.append(ORDER_BY_ASC_HAS_NEXT);
1462 }
1463 else {
1464 query.append(ORDER_BY_DESC_HAS_NEXT);
1465 }
1466 }
1467 else {
1468 if (orderByComparator.isAscending() ^ previous) {
1469 query.append(ORDER_BY_ASC);
1470 }
1471 else {
1472 query.append(ORDER_BY_DESC);
1473 }
1474 }
1475 }
1476 }
1477
1478 String sql = query.toString();
1479
1480 Query q = session.createQuery(sql);
1481
1482 q.setFirstResult(0);
1483 q.setMaxResults(2);
1484
1485 QueryPos qPos = QueryPos.getInstance(q);
1486
1487 qPos.add(messageId);
1488
1489 if (orderByComparator != null) {
1490 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1491
1492 for (Object value : values) {
1493 qPos.add(value);
1494 }
1495 }
1496
1497 List<MBMessageFlag> list = q.list();
1498
1499 if (list.size() == 2) {
1500 return list.get(1);
1501 }
1502 else {
1503 return null;
1504 }
1505 }
1506
1507
1515 public List<MBMessageFlag> findByT_F(long threadId, int flag)
1516 throws SystemException {
1517 return findByT_F(threadId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1518 null);
1519 }
1520
1521
1535 public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1536 int end) throws SystemException {
1537 return findByT_F(threadId, flag, start, end, null);
1538 }
1539
1540
1555 public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1556 int end, OrderByComparator orderByComparator) throws SystemException {
1557 Object[] finderArgs = new Object[] {
1558 threadId, flag,
1559
1560 String.valueOf(start), String.valueOf(end),
1561 String.valueOf(orderByComparator)
1562 };
1563
1564 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_F,
1565 finderArgs, this);
1566
1567 if (list == null) {
1568 StringBundler query = null;
1569
1570 if (orderByComparator != null) {
1571 query = new StringBundler(4 +
1572 (orderByComparator.getOrderByFields().length * 3));
1573 }
1574 else {
1575 query = new StringBundler(3);
1576 }
1577
1578 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1579
1580 query.append(_FINDER_COLUMN_T_F_THREADID_2);
1581
1582 query.append(_FINDER_COLUMN_T_F_FLAG_2);
1583
1584 if (orderByComparator != null) {
1585 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1586 orderByComparator);
1587 }
1588
1589 String sql = query.toString();
1590
1591 Session session = null;
1592
1593 try {
1594 session = openSession();
1595
1596 Query q = session.createQuery(sql);
1597
1598 QueryPos qPos = QueryPos.getInstance(q);
1599
1600 qPos.add(threadId);
1601
1602 qPos.add(flag);
1603
1604 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1605 start, end);
1606 }
1607 catch (Exception e) {
1608 throw processException(e);
1609 }
1610 finally {
1611 if (list == null) {
1612 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_T_F,
1613 finderArgs);
1614 }
1615 else {
1616 cacheResult(list);
1617
1618 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_F,
1619 finderArgs, list);
1620 }
1621
1622 closeSession(session);
1623 }
1624 }
1625
1626 return list;
1627 }
1628
1629
1643 public MBMessageFlag findByT_F_First(long threadId, int flag,
1644 OrderByComparator orderByComparator)
1645 throws NoSuchMessageFlagException, SystemException {
1646 List<MBMessageFlag> list = findByT_F(threadId, flag, 0, 1,
1647 orderByComparator);
1648
1649 if (list.isEmpty()) {
1650 StringBundler msg = new StringBundler(6);
1651
1652 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1653
1654 msg.append("threadId=");
1655 msg.append(threadId);
1656
1657 msg.append(", flag=");
1658 msg.append(flag);
1659
1660 msg.append(StringPool.CLOSE_CURLY_BRACE);
1661
1662 throw new NoSuchMessageFlagException(msg.toString());
1663 }
1664 else {
1665 return list.get(0);
1666 }
1667 }
1668
1669
1683 public MBMessageFlag findByT_F_Last(long threadId, int flag,
1684 OrderByComparator orderByComparator)
1685 throws NoSuchMessageFlagException, SystemException {
1686 int count = countByT_F(threadId, flag);
1687
1688 List<MBMessageFlag> list = findByT_F(threadId, flag, count - 1, count,
1689 orderByComparator);
1690
1691 if (list.isEmpty()) {
1692 StringBundler msg = new StringBundler(6);
1693
1694 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1695
1696 msg.append("threadId=");
1697 msg.append(threadId);
1698
1699 msg.append(", flag=");
1700 msg.append(flag);
1701
1702 msg.append(StringPool.CLOSE_CURLY_BRACE);
1703
1704 throw new NoSuchMessageFlagException(msg.toString());
1705 }
1706 else {
1707 return list.get(0);
1708 }
1709 }
1710
1711
1726 public MBMessageFlag[] findByT_F_PrevAndNext(long messageFlagId,
1727 long threadId, int flag, OrderByComparator orderByComparator)
1728 throws NoSuchMessageFlagException, SystemException {
1729 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1730
1731 Session session = null;
1732
1733 try {
1734 session = openSession();
1735
1736 MBMessageFlag[] array = new MBMessageFlagImpl[3];
1737
1738 array[0] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1739 flag, orderByComparator, true);
1740
1741 array[1] = mbMessageFlag;
1742
1743 array[2] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1744 flag, orderByComparator, false);
1745
1746 return array;
1747 }
1748 catch (Exception e) {
1749 throw processException(e);
1750 }
1751 finally {
1752 closeSession(session);
1753 }
1754 }
1755
1756 protected MBMessageFlag getByT_F_PrevAndNext(Session session,
1757 MBMessageFlag mbMessageFlag, long threadId, int flag,
1758 OrderByComparator orderByComparator, boolean previous) {
1759 StringBundler query = null;
1760
1761 if (orderByComparator != null) {
1762 query = new StringBundler(6 +
1763 (orderByComparator.getOrderByFields().length * 6));
1764 }
1765 else {
1766 query = new StringBundler(3);
1767 }
1768
1769 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1770
1771 query.append(_FINDER_COLUMN_T_F_THREADID_2);
1772
1773 query.append(_FINDER_COLUMN_T_F_FLAG_2);
1774
1775 if (orderByComparator != null) {
1776 String[] orderByFields = orderByComparator.getOrderByFields();
1777
1778 if (orderByFields.length > 0) {
1779 query.append(WHERE_AND);
1780 }
1781
1782 for (int i = 0; i < orderByFields.length; i++) {
1783 query.append(_ORDER_BY_ENTITY_ALIAS);
1784 query.append(orderByFields[i]);
1785
1786 if ((i + 1) < orderByFields.length) {
1787 if (orderByComparator.isAscending() ^ previous) {
1788 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1789 }
1790 else {
1791 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1792 }
1793 }
1794 else {
1795 if (orderByComparator.isAscending() ^ previous) {
1796 query.append(WHERE_GREATER_THAN);
1797 }
1798 else {
1799 query.append(WHERE_LESSER_THAN);
1800 }
1801 }
1802 }
1803
1804 query.append(ORDER_BY_CLAUSE);
1805
1806 for (int i = 0; i < orderByFields.length; i++) {
1807 query.append(_ORDER_BY_ENTITY_ALIAS);
1808 query.append(orderByFields[i]);
1809
1810 if ((i + 1) < orderByFields.length) {
1811 if (orderByComparator.isAscending() ^ previous) {
1812 query.append(ORDER_BY_ASC_HAS_NEXT);
1813 }
1814 else {
1815 query.append(ORDER_BY_DESC_HAS_NEXT);
1816 }
1817 }
1818 else {
1819 if (orderByComparator.isAscending() ^ previous) {
1820 query.append(ORDER_BY_ASC);
1821 }
1822 else {
1823 query.append(ORDER_BY_DESC);
1824 }
1825 }
1826 }
1827 }
1828
1829 String sql = query.toString();
1830
1831 Query q = session.createQuery(sql);
1832
1833 q.setFirstResult(0);
1834 q.setMaxResults(2);
1835
1836 QueryPos qPos = QueryPos.getInstance(q);
1837
1838 qPos.add(threadId);
1839
1840 qPos.add(flag);
1841
1842 if (orderByComparator != null) {
1843 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1844
1845 for (Object value : values) {
1846 qPos.add(value);
1847 }
1848 }
1849
1850 List<MBMessageFlag> list = q.list();
1851
1852 if (list.size() == 2) {
1853 return list.get(1);
1854 }
1855 else {
1856 return null;
1857 }
1858 }
1859
1860
1868 public List<MBMessageFlag> findByM_F(long messageId, int flag)
1869 throws SystemException {
1870 return findByM_F(messageId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1871 null);
1872 }
1873
1874
1888 public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1889 int end) throws SystemException {
1890 return findByM_F(messageId, flag, start, end, null);
1891 }
1892
1893
1908 public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1909 int end, OrderByComparator orderByComparator) throws SystemException {
1910 Object[] finderArgs = new Object[] {
1911 messageId, flag,
1912
1913 String.valueOf(start), String.valueOf(end),
1914 String.valueOf(orderByComparator)
1915 };
1916
1917 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_M_F,
1918 finderArgs, this);
1919
1920 if (list == null) {
1921 StringBundler query = null;
1922
1923 if (orderByComparator != null) {
1924 query = new StringBundler(4 +
1925 (orderByComparator.getOrderByFields().length * 3));
1926 }
1927 else {
1928 query = new StringBundler(3);
1929 }
1930
1931 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1932
1933 query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
1934
1935 query.append(_FINDER_COLUMN_M_F_FLAG_2);
1936
1937 if (orderByComparator != null) {
1938 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1939 orderByComparator);
1940 }
1941
1942 String sql = query.toString();
1943
1944 Session session = null;
1945
1946 try {
1947 session = openSession();
1948
1949 Query q = session.createQuery(sql);
1950
1951 QueryPos qPos = QueryPos.getInstance(q);
1952
1953 qPos.add(messageId);
1954
1955 qPos.add(flag);
1956
1957 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1958 start, end);
1959 }
1960 catch (Exception e) {
1961 throw processException(e);
1962 }
1963 finally {
1964 if (list == null) {
1965 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_M_F,
1966 finderArgs);
1967 }
1968 else {
1969 cacheResult(list);
1970
1971 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_M_F,
1972 finderArgs, list);
1973 }
1974
1975 closeSession(session);
1976 }
1977 }
1978
1979 return list;
1980 }
1981
1982
1996 public MBMessageFlag findByM_F_First(long messageId, int flag,
1997 OrderByComparator orderByComparator)
1998 throws NoSuchMessageFlagException, SystemException {
1999 List<MBMessageFlag> list = findByM_F(messageId, flag, 0, 1,
2000 orderByComparator);
2001
2002 if (list.isEmpty()) {
2003 StringBundler msg = new StringBundler(6);
2004
2005 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2006
2007 msg.append("messageId=");
2008 msg.append(messageId);
2009
2010 msg.append(", flag=");
2011 msg.append(flag);
2012
2013 msg.append(StringPool.CLOSE_CURLY_BRACE);
2014
2015 throw new NoSuchMessageFlagException(msg.toString());
2016 }
2017 else {
2018 return list.get(0);
2019 }
2020 }
2021
2022
2036 public MBMessageFlag findByM_F_Last(long messageId, int flag,
2037 OrderByComparator orderByComparator)
2038 throws NoSuchMessageFlagException, SystemException {
2039 int count = countByM_F(messageId, flag);
2040
2041 List<MBMessageFlag> list = findByM_F(messageId, flag, count - 1, count,
2042 orderByComparator);
2043
2044 if (list.isEmpty()) {
2045 StringBundler msg = new StringBundler(6);
2046
2047 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2048
2049 msg.append("messageId=");
2050 msg.append(messageId);
2051
2052 msg.append(", flag=");
2053 msg.append(flag);
2054
2055 msg.append(StringPool.CLOSE_CURLY_BRACE);
2056
2057 throw new NoSuchMessageFlagException(msg.toString());
2058 }
2059 else {
2060 return list.get(0);
2061 }
2062 }
2063
2064
2079 public MBMessageFlag[] findByM_F_PrevAndNext(long messageFlagId,
2080 long messageId, int flag, OrderByComparator orderByComparator)
2081 throws NoSuchMessageFlagException, SystemException {
2082 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
2083
2084 Session session = null;
2085
2086 try {
2087 session = openSession();
2088
2089 MBMessageFlag[] array = new MBMessageFlagImpl[3];
2090
2091 array[0] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
2092 flag, orderByComparator, true);
2093
2094 array[1] = mbMessageFlag;
2095
2096 array[2] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
2097 flag, orderByComparator, false);
2098
2099 return array;
2100 }
2101 catch (Exception e) {
2102 throw processException(e);
2103 }
2104 finally {
2105 closeSession(session);
2106 }
2107 }
2108
2109 protected MBMessageFlag getByM_F_PrevAndNext(Session session,
2110 MBMessageFlag mbMessageFlag, long messageId, int flag,
2111 OrderByComparator orderByComparator, boolean previous) {
2112 StringBundler query = null;
2113
2114 if (orderByComparator != null) {
2115 query = new StringBundler(6 +
2116 (orderByComparator.getOrderByFields().length * 6));
2117 }
2118 else {
2119 query = new StringBundler(3);
2120 }
2121
2122 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2123
2124 query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
2125
2126 query.append(_FINDER_COLUMN_M_F_FLAG_2);
2127
2128 if (orderByComparator != null) {
2129 String[] orderByFields = orderByComparator.getOrderByFields();
2130
2131 if (orderByFields.length > 0) {
2132 query.append(WHERE_AND);
2133 }
2134
2135 for (int i = 0; i < orderByFields.length; i++) {
2136 query.append(_ORDER_BY_ENTITY_ALIAS);
2137 query.append(orderByFields[i]);
2138
2139 if ((i + 1) < orderByFields.length) {
2140 if (orderByComparator.isAscending() ^ previous) {
2141 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2142 }
2143 else {
2144 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2145 }
2146 }
2147 else {
2148 if (orderByComparator.isAscending() ^ previous) {
2149 query.append(WHERE_GREATER_THAN);
2150 }
2151 else {
2152 query.append(WHERE_LESSER_THAN);
2153 }
2154 }
2155 }
2156
2157 query.append(ORDER_BY_CLAUSE);
2158
2159 for (int i = 0; i < orderByFields.length; i++) {
2160 query.append(_ORDER_BY_ENTITY_ALIAS);
2161 query.append(orderByFields[i]);
2162
2163 if ((i + 1) < orderByFields.length) {
2164 if (orderByComparator.isAscending() ^ previous) {
2165 query.append(ORDER_BY_ASC_HAS_NEXT);
2166 }
2167 else {
2168 query.append(ORDER_BY_DESC_HAS_NEXT);
2169 }
2170 }
2171 else {
2172 if (orderByComparator.isAscending() ^ previous) {
2173 query.append(ORDER_BY_ASC);
2174 }
2175 else {
2176 query.append(ORDER_BY_DESC);
2177 }
2178 }
2179 }
2180 }
2181
2182 String sql = query.toString();
2183
2184 Query q = session.createQuery(sql);
2185
2186 q.setFirstResult(0);
2187 q.setMaxResults(2);
2188
2189 QueryPos qPos = QueryPos.getInstance(q);
2190
2191 qPos.add(messageId);
2192
2193 qPos.add(flag);
2194
2195 if (orderByComparator != null) {
2196 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2197
2198 for (Object value : values) {
2199 qPos.add(value);
2200 }
2201 }
2202
2203 List<MBMessageFlag> list = q.list();
2204
2205 if (list.size() == 2) {
2206 return list.get(1);
2207 }
2208 else {
2209 return null;
2210 }
2211 }
2212
2213
2222 public List<MBMessageFlag> findByU_T_F(long userId, long threadId, int flag)
2223 throws SystemException {
2224 return findByU_T_F(userId, threadId, flag, QueryUtil.ALL_POS,
2225 QueryUtil.ALL_POS, null);
2226 }
2227
2228
2243 public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
2244 int flag, int start, int end) throws SystemException {
2245 return findByU_T_F(userId, threadId, flag, start, end, null);
2246 }
2247
2248
2264 public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
2265 int flag, int start, int end, OrderByComparator orderByComparator)
2266 throws SystemException {
2267 Object[] finderArgs = new Object[] {
2268 userId, threadId, flag,
2269
2270 String.valueOf(start), String.valueOf(end),
2271 String.valueOf(orderByComparator)
2272 };
2273
2274 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_T_F,
2275 finderArgs, this);
2276
2277 if (list == null) {
2278 StringBundler query = null;
2279
2280 if (orderByComparator != null) {
2281 query = new StringBundler(5 +
2282 (orderByComparator.getOrderByFields().length * 3));
2283 }
2284 else {
2285 query = new StringBundler(4);
2286 }
2287
2288 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2289
2290 query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2291
2292 query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2293
2294 query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2295
2296 if (orderByComparator != null) {
2297 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2298 orderByComparator);
2299 }
2300
2301 String sql = query.toString();
2302
2303 Session session = null;
2304
2305 try {
2306 session = openSession();
2307
2308 Query q = session.createQuery(sql);
2309
2310 QueryPos qPos = QueryPos.getInstance(q);
2311
2312 qPos.add(userId);
2313
2314 qPos.add(threadId);
2315
2316 qPos.add(flag);
2317
2318 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2319 start, end);
2320 }
2321 catch (Exception e) {
2322 throw processException(e);
2323 }
2324 finally {
2325 if (list == null) {
2326 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_U_T_F,
2327 finderArgs);
2328 }
2329 else {
2330 cacheResult(list);
2331
2332 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_T_F,
2333 finderArgs, list);
2334 }
2335
2336 closeSession(session);
2337 }
2338 }
2339
2340 return list;
2341 }
2342
2343
2358 public MBMessageFlag findByU_T_F_First(long userId, long threadId,
2359 int flag, OrderByComparator orderByComparator)
2360 throws NoSuchMessageFlagException, SystemException {
2361 List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag, 0, 1,
2362 orderByComparator);
2363
2364 if (list.isEmpty()) {
2365 StringBundler msg = new StringBundler(8);
2366
2367 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2368
2369 msg.append("userId=");
2370 msg.append(userId);
2371
2372 msg.append(", threadId=");
2373 msg.append(threadId);
2374
2375 msg.append(", flag=");
2376 msg.append(flag);
2377
2378 msg.append(StringPool.CLOSE_CURLY_BRACE);
2379
2380 throw new NoSuchMessageFlagException(msg.toString());
2381 }
2382 else {
2383 return list.get(0);
2384 }
2385 }
2386
2387
2402 public MBMessageFlag findByU_T_F_Last(long userId, long threadId, int flag,
2403 OrderByComparator orderByComparator)
2404 throws NoSuchMessageFlagException, SystemException {
2405 int count = countByU_T_F(userId, threadId, flag);
2406
2407 List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag,
2408 count - 1, count, orderByComparator);
2409
2410 if (list.isEmpty()) {
2411 StringBundler msg = new StringBundler(8);
2412
2413 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2414
2415 msg.append("userId=");
2416 msg.append(userId);
2417
2418 msg.append(", threadId=");
2419 msg.append(threadId);
2420
2421 msg.append(", flag=");
2422 msg.append(flag);
2423
2424 msg.append(StringPool.CLOSE_CURLY_BRACE);
2425
2426 throw new NoSuchMessageFlagException(msg.toString());
2427 }
2428 else {
2429 return list.get(0);
2430 }
2431 }
2432
2433
2449 public MBMessageFlag[] findByU_T_F_PrevAndNext(long messageFlagId,
2450 long userId, long threadId, int flag,
2451 OrderByComparator orderByComparator)
2452 throws NoSuchMessageFlagException, SystemException {
2453 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
2454
2455 Session session = null;
2456
2457 try {
2458 session = openSession();
2459
2460 MBMessageFlag[] array = new MBMessageFlagImpl[3];
2461
2462 array[0] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
2463 threadId, flag, orderByComparator, true);
2464
2465 array[1] = mbMessageFlag;
2466
2467 array[2] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
2468 threadId, flag, orderByComparator, false);
2469
2470 return array;
2471 }
2472 catch (Exception e) {
2473 throw processException(e);
2474 }
2475 finally {
2476 closeSession(session);
2477 }
2478 }
2479
2480 protected MBMessageFlag getByU_T_F_PrevAndNext(Session session,
2481 MBMessageFlag mbMessageFlag, long userId, long threadId, int flag,
2482 OrderByComparator orderByComparator, boolean previous) {
2483 StringBundler query = null;
2484
2485 if (orderByComparator != null) {
2486 query = new StringBundler(6 +
2487 (orderByComparator.getOrderByFields().length * 6));
2488 }
2489 else {
2490 query = new StringBundler(3);
2491 }
2492
2493 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2494
2495 query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2496
2497 query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2498
2499 query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2500
2501 if (orderByComparator != null) {
2502 String[] orderByFields = orderByComparator.getOrderByFields();
2503
2504 if (orderByFields.length > 0) {
2505 query.append(WHERE_AND);
2506 }
2507
2508 for (int i = 0; i < orderByFields.length; i++) {
2509 query.append(_ORDER_BY_ENTITY_ALIAS);
2510 query.append(orderByFields[i]);
2511
2512 if ((i + 1) < orderByFields.length) {
2513 if (orderByComparator.isAscending() ^ previous) {
2514 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2515 }
2516 else {
2517 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2518 }
2519 }
2520 else {
2521 if (orderByComparator.isAscending() ^ previous) {
2522 query.append(WHERE_GREATER_THAN);
2523 }
2524 else {
2525 query.append(WHERE_LESSER_THAN);
2526 }
2527 }
2528 }
2529
2530 query.append(ORDER_BY_CLAUSE);
2531
2532 for (int i = 0; i < orderByFields.length; i++) {
2533 query.append(_ORDER_BY_ENTITY_ALIAS);
2534 query.append(orderByFields[i]);
2535
2536 if ((i + 1) < orderByFields.length) {
2537 if (orderByComparator.isAscending() ^ previous) {
2538 query.append(ORDER_BY_ASC_HAS_NEXT);
2539 }
2540 else {
2541 query.append(ORDER_BY_DESC_HAS_NEXT);
2542 }
2543 }
2544 else {
2545 if (orderByComparator.isAscending() ^ previous) {
2546 query.append(ORDER_BY_ASC);
2547 }
2548 else {
2549 query.append(ORDER_BY_DESC);
2550 }
2551 }
2552 }
2553 }
2554
2555 String sql = query.toString();
2556
2557 Query q = session.createQuery(sql);
2558
2559 q.setFirstResult(0);
2560 q.setMaxResults(2);
2561
2562 QueryPos qPos = QueryPos.getInstance(q);
2563
2564 qPos.add(userId);
2565
2566 qPos.add(threadId);
2567
2568 qPos.add(flag);
2569
2570 if (orderByComparator != null) {
2571 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2572
2573 for (Object value : values) {
2574 qPos.add(value);
2575 }
2576 }
2577
2578 List<MBMessageFlag> list = q.list();
2579
2580 if (list.size() == 2) {
2581 return list.get(1);
2582 }
2583 else {
2584 return null;
2585 }
2586 }
2587
2588
2598 public MBMessageFlag findByU_M_F(long userId, long messageId, int flag)
2599 throws NoSuchMessageFlagException, SystemException {
2600 MBMessageFlag mbMessageFlag = fetchByU_M_F(userId, messageId, flag);
2601
2602 if (mbMessageFlag == null) {
2603 StringBundler msg = new StringBundler(8);
2604
2605 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2606
2607 msg.append("userId=");
2608 msg.append(userId);
2609
2610 msg.append(", messageId=");
2611 msg.append(messageId);
2612
2613 msg.append(", flag=");
2614 msg.append(flag);
2615
2616 msg.append(StringPool.CLOSE_CURLY_BRACE);
2617
2618 if (_log.isWarnEnabled()) {
2619 _log.warn(msg.toString());
2620 }
2621
2622 throw new NoSuchMessageFlagException(msg.toString());
2623 }
2624
2625 return mbMessageFlag;
2626 }
2627
2628
2637 public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag)
2638 throws SystemException {
2639 return fetchByU_M_F(userId, messageId, flag, true);
2640 }
2641
2642
2651 public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag,
2652 boolean retrieveFromCache) throws SystemException {
2653 Object[] finderArgs = new Object[] { userId, messageId, flag };
2654
2655 Object result = null;
2656
2657 if (retrieveFromCache) {
2658 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_M_F,
2659 finderArgs, this);
2660 }
2661
2662 if (result == null) {
2663 StringBundler query = new StringBundler(4);
2664
2665 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2666
2667 query.append(_FINDER_COLUMN_U_M_F_USERID_2);
2668
2669 query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
2670
2671 query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
2672
2673 String sql = query.toString();
2674
2675 Session session = null;
2676
2677 try {
2678 session = openSession();
2679
2680 Query q = session.createQuery(sql);
2681
2682 QueryPos qPos = QueryPos.getInstance(q);
2683
2684 qPos.add(userId);
2685
2686 qPos.add(messageId);
2687
2688 qPos.add(flag);
2689
2690 List<MBMessageFlag> list = q.list();
2691
2692 result = list;
2693
2694 MBMessageFlag mbMessageFlag = null;
2695
2696 if (list.isEmpty()) {
2697 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2698 finderArgs, list);
2699 }
2700 else {
2701 mbMessageFlag = list.get(0);
2702
2703 cacheResult(mbMessageFlag);
2704
2705 if ((mbMessageFlag.getUserId() != userId) ||
2706 (mbMessageFlag.getMessageId() != messageId) ||
2707 (mbMessageFlag.getFlag() != flag)) {
2708 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2709 finderArgs, mbMessageFlag);
2710 }
2711 }
2712
2713 return mbMessageFlag;
2714 }
2715 catch (Exception e) {
2716 throw processException(e);
2717 }
2718 finally {
2719 if (result == null) {
2720 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
2721 finderArgs);
2722 }
2723
2724 closeSession(session);
2725 }
2726 }
2727 else {
2728 if (result instanceof List<?>) {
2729 return null;
2730 }
2731 else {
2732 return (MBMessageFlag)result;
2733 }
2734 }
2735 }
2736
2737
2743 public List<MBMessageFlag> findAll() throws SystemException {
2744 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2745 }
2746
2747
2759 public List<MBMessageFlag> findAll(int start, int end)
2760 throws SystemException {
2761 return findAll(start, end, null);
2762 }
2763
2764
2777 public List<MBMessageFlag> findAll(int start, int end,
2778 OrderByComparator orderByComparator) throws SystemException {
2779 Object[] finderArgs = new Object[] {
2780 String.valueOf(start), String.valueOf(end),
2781 String.valueOf(orderByComparator)
2782 };
2783
2784 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2785 finderArgs, this);
2786
2787 if (list == null) {
2788 StringBundler query = null;
2789 String sql = null;
2790
2791 if (orderByComparator != null) {
2792 query = new StringBundler(2 +
2793 (orderByComparator.getOrderByFields().length * 3));
2794
2795 query.append(_SQL_SELECT_MBMESSAGEFLAG);
2796
2797 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2798 orderByComparator);
2799
2800 sql = query.toString();
2801 }
2802 else {
2803 sql = _SQL_SELECT_MBMESSAGEFLAG;
2804 }
2805
2806 Session session = null;
2807
2808 try {
2809 session = openSession();
2810
2811 Query q = session.createQuery(sql);
2812
2813 if (orderByComparator == null) {
2814 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2815 start, end, false);
2816
2817 Collections.sort(list);
2818 }
2819 else {
2820 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2821 start, end);
2822 }
2823 }
2824 catch (Exception e) {
2825 throw processException(e);
2826 }
2827 finally {
2828 if (list == null) {
2829 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
2830 finderArgs);
2831 }
2832 else {
2833 cacheResult(list);
2834
2835 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
2836 list);
2837 }
2838
2839 closeSession(session);
2840 }
2841 }
2842
2843 return list;
2844 }
2845
2846
2852 public void removeByUserId(long userId) throws SystemException {
2853 for (MBMessageFlag mbMessageFlag : findByUserId(userId)) {
2854 remove(mbMessageFlag);
2855 }
2856 }
2857
2858
2864 public void removeByThreadId(long threadId) throws SystemException {
2865 for (MBMessageFlag mbMessageFlag : findByThreadId(threadId)) {
2866 remove(mbMessageFlag);
2867 }
2868 }
2869
2870
2876 public void removeByMessageId(long messageId) throws SystemException {
2877 for (MBMessageFlag mbMessageFlag : findByMessageId(messageId)) {
2878 remove(mbMessageFlag);
2879 }
2880 }
2881
2882
2889 public void removeByT_F(long threadId, int flag) throws SystemException {
2890 for (MBMessageFlag mbMessageFlag : findByT_F(threadId, flag)) {
2891 remove(mbMessageFlag);
2892 }
2893 }
2894
2895
2902 public void removeByM_F(long messageId, int flag) throws SystemException {
2903 for (MBMessageFlag mbMessageFlag : findByM_F(messageId, flag)) {
2904 remove(mbMessageFlag);
2905 }
2906 }
2907
2908
2916 public void removeByU_T_F(long userId, long threadId, int flag)
2917 throws SystemException {
2918 for (MBMessageFlag mbMessageFlag : findByU_T_F(userId, threadId, flag)) {
2919 remove(mbMessageFlag);
2920 }
2921 }
2922
2923
2931 public void removeByU_M_F(long userId, long messageId, int flag)
2932 throws NoSuchMessageFlagException, SystemException {
2933 MBMessageFlag mbMessageFlag = findByU_M_F(userId, messageId, flag);
2934
2935 remove(mbMessageFlag);
2936 }
2937
2938
2943 public void removeAll() throws SystemException {
2944 for (MBMessageFlag mbMessageFlag : findAll()) {
2945 remove(mbMessageFlag);
2946 }
2947 }
2948
2949
2956 public int countByUserId(long userId) throws SystemException {
2957 Object[] finderArgs = new Object[] { userId };
2958
2959 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2960 finderArgs, this);
2961
2962 if (count == null) {
2963 StringBundler query = new StringBundler(2);
2964
2965 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2966
2967 query.append(_FINDER_COLUMN_USERID_USERID_2);
2968
2969 String sql = query.toString();
2970
2971 Session session = null;
2972
2973 try {
2974 session = openSession();
2975
2976 Query q = session.createQuery(sql);
2977
2978 QueryPos qPos = QueryPos.getInstance(q);
2979
2980 qPos.add(userId);
2981
2982 count = (Long)q.uniqueResult();
2983 }
2984 catch (Exception e) {
2985 throw processException(e);
2986 }
2987 finally {
2988 if (count == null) {
2989 count = Long.valueOf(0);
2990 }
2991
2992 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2993 finderArgs, count);
2994
2995 closeSession(session);
2996 }
2997 }
2998
2999 return count.intValue();
3000 }
3001
3002
3009 public int countByThreadId(long threadId) throws SystemException {
3010 Object[] finderArgs = new Object[] { threadId };
3011
3012 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
3013 finderArgs, this);
3014
3015 if (count == null) {
3016 StringBundler query = new StringBundler(2);
3017
3018 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3019
3020 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3021
3022 String sql = query.toString();
3023
3024 Session session = null;
3025
3026 try {
3027 session = openSession();
3028
3029 Query q = session.createQuery(sql);
3030
3031 QueryPos qPos = QueryPos.getInstance(q);
3032
3033 qPos.add(threadId);
3034
3035 count = (Long)q.uniqueResult();
3036 }
3037 catch (Exception e) {
3038 throw processException(e);
3039 }
3040 finally {
3041 if (count == null) {
3042 count = Long.valueOf(0);
3043 }
3044
3045 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
3046 finderArgs, count);
3047
3048 closeSession(session);
3049 }
3050 }
3051
3052 return count.intValue();
3053 }
3054
3055
3062 public int countByMessageId(long messageId) throws SystemException {
3063 Object[] finderArgs = new Object[] { messageId };
3064
3065 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MESSAGEID,
3066 finderArgs, this);
3067
3068 if (count == null) {
3069 StringBundler query = new StringBundler(2);
3070
3071 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3072
3073 query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
3074
3075 String sql = query.toString();
3076
3077 Session session = null;
3078
3079 try {
3080 session = openSession();
3081
3082 Query q = session.createQuery(sql);
3083
3084 QueryPos qPos = QueryPos.getInstance(q);
3085
3086 qPos.add(messageId);
3087
3088 count = (Long)q.uniqueResult();
3089 }
3090 catch (Exception e) {
3091 throw processException(e);
3092 }
3093 finally {
3094 if (count == null) {
3095 count = Long.valueOf(0);
3096 }
3097
3098 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MESSAGEID,
3099 finderArgs, count);
3100
3101 closeSession(session);
3102 }
3103 }
3104
3105 return count.intValue();
3106 }
3107
3108
3116 public int countByT_F(long threadId, int flag) throws SystemException {
3117 Object[] finderArgs = new Object[] { threadId, flag };
3118
3119 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_F,
3120 finderArgs, this);
3121
3122 if (count == null) {
3123 StringBundler query = new StringBundler(3);
3124
3125 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3126
3127 query.append(_FINDER_COLUMN_T_F_THREADID_2);
3128
3129 query.append(_FINDER_COLUMN_T_F_FLAG_2);
3130
3131 String sql = query.toString();
3132
3133 Session session = null;
3134
3135 try {
3136 session = openSession();
3137
3138 Query q = session.createQuery(sql);
3139
3140 QueryPos qPos = QueryPos.getInstance(q);
3141
3142 qPos.add(threadId);
3143
3144 qPos.add(flag);
3145
3146 count = (Long)q.uniqueResult();
3147 }
3148 catch (Exception e) {
3149 throw processException(e);
3150 }
3151 finally {
3152 if (count == null) {
3153 count = Long.valueOf(0);
3154 }
3155
3156 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_F, finderArgs,
3157 count);
3158
3159 closeSession(session);
3160 }
3161 }
3162
3163 return count.intValue();
3164 }
3165
3166
3174 public int countByM_F(long messageId, int flag) throws SystemException {
3175 Object[] finderArgs = new Object[] { messageId, flag };
3176
3177 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_M_F,
3178 finderArgs, this);
3179
3180 if (count == null) {
3181 StringBundler query = new StringBundler(3);
3182
3183 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3184
3185 query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
3186
3187 query.append(_FINDER_COLUMN_M_F_FLAG_2);
3188
3189 String sql = query.toString();
3190
3191 Session session = null;
3192
3193 try {
3194 session = openSession();
3195
3196 Query q = session.createQuery(sql);
3197
3198 QueryPos qPos = QueryPos.getInstance(q);
3199
3200 qPos.add(messageId);
3201
3202 qPos.add(flag);
3203
3204 count = (Long)q.uniqueResult();
3205 }
3206 catch (Exception e) {
3207 throw processException(e);
3208 }
3209 finally {
3210 if (count == null) {
3211 count = Long.valueOf(0);
3212 }
3213
3214 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_M_F, finderArgs,
3215 count);
3216
3217 closeSession(session);
3218 }
3219 }
3220
3221 return count.intValue();
3222 }
3223
3224
3233 public int countByU_T_F(long userId, long threadId, int flag)
3234 throws SystemException {
3235 Object[] finderArgs = new Object[] { userId, threadId, flag };
3236
3237 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T_F,
3238 finderArgs, this);
3239
3240 if (count == null) {
3241 StringBundler query = new StringBundler(4);
3242
3243 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3244
3245 query.append(_FINDER_COLUMN_U_T_F_USERID_2);
3246
3247 query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
3248
3249 query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
3250
3251 String sql = query.toString();
3252
3253 Session session = null;
3254
3255 try {
3256 session = openSession();
3257
3258 Query q = session.createQuery(sql);
3259
3260 QueryPos qPos = QueryPos.getInstance(q);
3261
3262 qPos.add(userId);
3263
3264 qPos.add(threadId);
3265
3266 qPos.add(flag);
3267
3268 count = (Long)q.uniqueResult();
3269 }
3270 catch (Exception e) {
3271 throw processException(e);
3272 }
3273 finally {
3274 if (count == null) {
3275 count = Long.valueOf(0);
3276 }
3277
3278 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T_F,
3279 finderArgs, count);
3280
3281 closeSession(session);
3282 }
3283 }
3284
3285 return count.intValue();
3286 }
3287
3288
3297 public int countByU_M_F(long userId, long messageId, int flag)
3298 throws SystemException {
3299 Object[] finderArgs = new Object[] { userId, messageId, flag };
3300
3301 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_M_F,
3302 finderArgs, this);
3303
3304 if (count == null) {
3305 StringBundler query = new StringBundler(4);
3306
3307 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3308
3309 query.append(_FINDER_COLUMN_U_M_F_USERID_2);
3310
3311 query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
3312
3313 query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
3314
3315 String sql = query.toString();
3316
3317 Session session = null;
3318
3319 try {
3320 session = openSession();
3321
3322 Query q = session.createQuery(sql);
3323
3324 QueryPos qPos = QueryPos.getInstance(q);
3325
3326 qPos.add(userId);
3327
3328 qPos.add(messageId);
3329
3330 qPos.add(flag);
3331
3332 count = (Long)q.uniqueResult();
3333 }
3334 catch (Exception e) {
3335 throw processException(e);
3336 }
3337 finally {
3338 if (count == null) {
3339 count = Long.valueOf(0);
3340 }
3341
3342 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_M_F,
3343 finderArgs, count);
3344
3345 closeSession(session);
3346 }
3347 }
3348
3349 return count.intValue();
3350 }
3351
3352
3358 public int countAll() throws SystemException {
3359 Object[] finderArgs = new Object[0];
3360
3361 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3362 finderArgs, this);
3363
3364 if (count == null) {
3365 Session session = null;
3366
3367 try {
3368 session = openSession();
3369
3370 Query q = session.createQuery(_SQL_COUNT_MBMESSAGEFLAG);
3371
3372 count = (Long)q.uniqueResult();
3373 }
3374 catch (Exception e) {
3375 throw processException(e);
3376 }
3377 finally {
3378 if (count == null) {
3379 count = Long.valueOf(0);
3380 }
3381
3382 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3383 count);
3384
3385 closeSession(session);
3386 }
3387 }
3388
3389 return count.intValue();
3390 }
3391
3392
3395 public void afterPropertiesSet() {
3396 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3397 com.liferay.portal.util.PropsUtil.get(
3398 "value.object.listener.com.liferay.portlet.messageboards.model.MBMessageFlag")));
3399
3400 if (listenerClassNames.length > 0) {
3401 try {
3402 List<ModelListener<MBMessageFlag>> listenersList = new ArrayList<ModelListener<MBMessageFlag>>();
3403
3404 for (String listenerClassName : listenerClassNames) {
3405 listenersList.add((ModelListener<MBMessageFlag>)InstanceFactory.newInstance(
3406 listenerClassName));
3407 }
3408
3409 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3410 }
3411 catch (Exception e) {
3412 _log.error(e);
3413 }
3414 }
3415 }
3416
3417 public void destroy() {
3418 EntityCacheUtil.removeCache(MBMessageFlagImpl.class.getName());
3419 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3420 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3421 }
3422
3423 @BeanReference(type = MBBanPersistence.class)
3424 protected MBBanPersistence mbBanPersistence;
3425 @BeanReference(type = MBCategoryPersistence.class)
3426 protected MBCategoryPersistence mbCategoryPersistence;
3427 @BeanReference(type = MBDiscussionPersistence.class)
3428 protected MBDiscussionPersistence mbDiscussionPersistence;
3429 @BeanReference(type = MBMailingListPersistence.class)
3430 protected MBMailingListPersistence mbMailingListPersistence;
3431 @BeanReference(type = MBMessagePersistence.class)
3432 protected MBMessagePersistence mbMessagePersistence;
3433 @BeanReference(type = MBMessageFlagPersistence.class)
3434 protected MBMessageFlagPersistence mbMessageFlagPersistence;
3435 @BeanReference(type = MBStatsUserPersistence.class)
3436 protected MBStatsUserPersistence mbStatsUserPersistence;
3437 @BeanReference(type = MBThreadPersistence.class)
3438 protected MBThreadPersistence mbThreadPersistence;
3439 @BeanReference(type = ResourcePersistence.class)
3440 protected ResourcePersistence resourcePersistence;
3441 @BeanReference(type = UserPersistence.class)
3442 protected UserPersistence userPersistence;
3443 private static final String _SQL_SELECT_MBMESSAGEFLAG = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag";
3444 private static final String _SQL_SELECT_MBMESSAGEFLAG_WHERE = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag WHERE ";
3445 private static final String _SQL_COUNT_MBMESSAGEFLAG = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag";
3446 private static final String _SQL_COUNT_MBMESSAGEFLAG_WHERE = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag WHERE ";
3447 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessageFlag.userId = ?";
3448 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessageFlag.threadId = ?";
3449 private static final String _FINDER_COLUMN_MESSAGEID_MESSAGEID_2 = "mbMessageFlag.messageId = ?";
3450 private static final String _FINDER_COLUMN_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
3451 private static final String _FINDER_COLUMN_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
3452 private static final String _FINDER_COLUMN_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
3453 private static final String _FINDER_COLUMN_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
3454 private static final String _FINDER_COLUMN_U_T_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
3455 private static final String _FINDER_COLUMN_U_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
3456 private static final String _FINDER_COLUMN_U_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
3457 private static final String _FINDER_COLUMN_U_M_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
3458 private static final String _FINDER_COLUMN_U_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
3459 private static final String _FINDER_COLUMN_U_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
3460 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessageFlag.";
3461 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessageFlag exists with the primary key ";
3462 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessageFlag exists with the key {";
3463 private static Log _log = LogFactoryUtil.getLog(MBMessageFlagPersistenceImpl.class);
3464 }