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.getOriginalUserId()),
337 new Long(mbMessageFlagModelImpl.getOriginalMessageId()),
338 new Integer(mbMessageFlagModelImpl.getOriginalFlag())
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 Session session = null;
568
569 try {
570 session = openSession();
571
572 StringBundler query = null;
573
574 if (orderByComparator != null) {
575 query = new StringBundler(3 +
576 (orderByComparator.getOrderByFields().length * 3));
577 }
578 else {
579 query = new StringBundler(2);
580 }
581
582 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
583
584 query.append(_FINDER_COLUMN_USERID_USERID_2);
585
586 if (orderByComparator != null) {
587 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
588 orderByComparator);
589 }
590
591 String sql = query.toString();
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 list = new ArrayList<MBMessageFlag>();
608 }
609
610 cacheResult(list);
611
612 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
613 finderArgs, list);
614
615 closeSession(session);
616 }
617 }
618
619 return list;
620 }
621
622
635 public MBMessageFlag findByUserId_First(long userId,
636 OrderByComparator orderByComparator)
637 throws NoSuchMessageFlagException, SystemException {
638 List<MBMessageFlag> list = findByUserId(userId, 0, 1, orderByComparator);
639
640 if (list.isEmpty()) {
641 StringBundler msg = new StringBundler(4);
642
643 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644
645 msg.append("userId=");
646 msg.append(userId);
647
648 msg.append(StringPool.CLOSE_CURLY_BRACE);
649
650 throw new NoSuchMessageFlagException(msg.toString());
651 }
652 else {
653 return list.get(0);
654 }
655 }
656
657
670 public MBMessageFlag findByUserId_Last(long userId,
671 OrderByComparator orderByComparator)
672 throws NoSuchMessageFlagException, SystemException {
673 int count = countByUserId(userId);
674
675 List<MBMessageFlag> list = findByUserId(userId, count - 1, count,
676 orderByComparator);
677
678 if (list.isEmpty()) {
679 StringBundler msg = new StringBundler(4);
680
681 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
682
683 msg.append("userId=");
684 msg.append(userId);
685
686 msg.append(StringPool.CLOSE_CURLY_BRACE);
687
688 throw new NoSuchMessageFlagException(msg.toString());
689 }
690 else {
691 return list.get(0);
692 }
693 }
694
695
709 public MBMessageFlag[] findByUserId_PrevAndNext(long messageFlagId,
710 long userId, OrderByComparator orderByComparator)
711 throws NoSuchMessageFlagException, SystemException {
712 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
713
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 MBMessageFlag[] array = new MBMessageFlagImpl[3];
720
721 array[0] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
722 orderByComparator, true);
723
724 array[1] = mbMessageFlag;
725
726 array[2] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
727 orderByComparator, false);
728
729 return array;
730 }
731 catch (Exception e) {
732 throw processException(e);
733 }
734 finally {
735 closeSession(session);
736 }
737 }
738
739 protected MBMessageFlag getByUserId_PrevAndNext(Session session,
740 MBMessageFlag mbMessageFlag, long userId,
741 OrderByComparator orderByComparator, boolean previous) {
742 StringBundler query = null;
743
744 if (orderByComparator != null) {
745 query = new StringBundler(6 +
746 (orderByComparator.getOrderByFields().length * 6));
747 }
748 else {
749 query = new StringBundler(3);
750 }
751
752 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
753
754 query.append(_FINDER_COLUMN_USERID_USERID_2);
755
756 if (orderByComparator != null) {
757 String[] orderByFields = orderByComparator.getOrderByFields();
758
759 if (orderByFields.length > 0) {
760 query.append(WHERE_AND);
761 }
762
763 for (int i = 0; i < orderByFields.length; i++) {
764 query.append(_ORDER_BY_ENTITY_ALIAS);
765 query.append(orderByFields[i]);
766
767 if ((i + 1) < orderByFields.length) {
768 if (orderByComparator.isAscending() ^ previous) {
769 query.append(WHERE_GREATER_THAN_HAS_NEXT);
770 }
771 else {
772 query.append(WHERE_LESSER_THAN_HAS_NEXT);
773 }
774 }
775 else {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(WHERE_GREATER_THAN);
778 }
779 else {
780 query.append(WHERE_LESSER_THAN);
781 }
782 }
783 }
784
785 query.append(ORDER_BY_CLAUSE);
786
787 for (int i = 0; i < orderByFields.length; i++) {
788 query.append(_ORDER_BY_ENTITY_ALIAS);
789 query.append(orderByFields[i]);
790
791 if ((i + 1) < orderByFields.length) {
792 if (orderByComparator.isAscending() ^ previous) {
793 query.append(ORDER_BY_ASC_HAS_NEXT);
794 }
795 else {
796 query.append(ORDER_BY_DESC_HAS_NEXT);
797 }
798 }
799 else {
800 if (orderByComparator.isAscending() ^ previous) {
801 query.append(ORDER_BY_ASC);
802 }
803 else {
804 query.append(ORDER_BY_DESC);
805 }
806 }
807 }
808 }
809
810 String sql = query.toString();
811
812 Query q = session.createQuery(sql);
813
814 q.setFirstResult(0);
815 q.setMaxResults(2);
816
817 QueryPos qPos = QueryPos.getInstance(q);
818
819 qPos.add(userId);
820
821 if (orderByComparator != null) {
822 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
823
824 for (Object value : values) {
825 qPos.add(value);
826 }
827 }
828
829 List<MBMessageFlag> list = q.list();
830
831 if (list.size() == 2) {
832 return list.get(1);
833 }
834 else {
835 return null;
836 }
837 }
838
839
846 public List<MBMessageFlag> findByThreadId(long threadId)
847 throws SystemException {
848 return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
849 null);
850 }
851
852
865 public List<MBMessageFlag> findByThreadId(long threadId, int start, int end)
866 throws SystemException {
867 return findByThreadId(threadId, start, end, null);
868 }
869
870
884 public List<MBMessageFlag> findByThreadId(long threadId, int start,
885 int end, OrderByComparator orderByComparator) throws SystemException {
886 Object[] finderArgs = new Object[] {
887 threadId,
888
889 String.valueOf(start), String.valueOf(end),
890 String.valueOf(orderByComparator)
891 };
892
893 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
894 finderArgs, this);
895
896 if (list == null) {
897 Session session = null;
898
899 try {
900 session = openSession();
901
902 StringBundler query = null;
903
904 if (orderByComparator != null) {
905 query = new StringBundler(3 +
906 (orderByComparator.getOrderByFields().length * 3));
907 }
908 else {
909 query = new StringBundler(2);
910 }
911
912 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
913
914 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
915
916 if (orderByComparator != null) {
917 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
918 orderByComparator);
919 }
920
921 String sql = query.toString();
922
923 Query q = session.createQuery(sql);
924
925 QueryPos qPos = QueryPos.getInstance(q);
926
927 qPos.add(threadId);
928
929 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
930 start, end);
931 }
932 catch (Exception e) {
933 throw processException(e);
934 }
935 finally {
936 if (list == null) {
937 list = new ArrayList<MBMessageFlag>();
938 }
939
940 cacheResult(list);
941
942 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
943 finderArgs, list);
944
945 closeSession(session);
946 }
947 }
948
949 return list;
950 }
951
952
965 public MBMessageFlag findByThreadId_First(long threadId,
966 OrderByComparator orderByComparator)
967 throws NoSuchMessageFlagException, SystemException {
968 List<MBMessageFlag> list = findByThreadId(threadId, 0, 1,
969 orderByComparator);
970
971 if (list.isEmpty()) {
972 StringBundler msg = new StringBundler(4);
973
974 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
975
976 msg.append("threadId=");
977 msg.append(threadId);
978
979 msg.append(StringPool.CLOSE_CURLY_BRACE);
980
981 throw new NoSuchMessageFlagException(msg.toString());
982 }
983 else {
984 return list.get(0);
985 }
986 }
987
988
1001 public MBMessageFlag findByThreadId_Last(long threadId,
1002 OrderByComparator orderByComparator)
1003 throws NoSuchMessageFlagException, SystemException {
1004 int count = countByThreadId(threadId);
1005
1006 List<MBMessageFlag> list = findByThreadId(threadId, count - 1, count,
1007 orderByComparator);
1008
1009 if (list.isEmpty()) {
1010 StringBundler msg = new StringBundler(4);
1011
1012 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1013
1014 msg.append("threadId=");
1015 msg.append(threadId);
1016
1017 msg.append(StringPool.CLOSE_CURLY_BRACE);
1018
1019 throw new NoSuchMessageFlagException(msg.toString());
1020 }
1021 else {
1022 return list.get(0);
1023 }
1024 }
1025
1026
1040 public MBMessageFlag[] findByThreadId_PrevAndNext(long messageFlagId,
1041 long threadId, OrderByComparator orderByComparator)
1042 throws NoSuchMessageFlagException, SystemException {
1043 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1044
1045 Session session = null;
1046
1047 try {
1048 session = openSession();
1049
1050 MBMessageFlag[] array = new MBMessageFlagImpl[3];
1051
1052 array[0] = getByThreadId_PrevAndNext(session, mbMessageFlag,
1053 threadId, orderByComparator, true);
1054
1055 array[1] = mbMessageFlag;
1056
1057 array[2] = getByThreadId_PrevAndNext(session, mbMessageFlag,
1058 threadId, orderByComparator, false);
1059
1060 return array;
1061 }
1062 catch (Exception e) {
1063 throw processException(e);
1064 }
1065 finally {
1066 closeSession(session);
1067 }
1068 }
1069
1070 protected MBMessageFlag getByThreadId_PrevAndNext(Session session,
1071 MBMessageFlag mbMessageFlag, long threadId,
1072 OrderByComparator orderByComparator, boolean previous) {
1073 StringBundler query = null;
1074
1075 if (orderByComparator != null) {
1076 query = new StringBundler(6 +
1077 (orderByComparator.getOrderByFields().length * 6));
1078 }
1079 else {
1080 query = new StringBundler(3);
1081 }
1082
1083 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1084
1085 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1086
1087 if (orderByComparator != null) {
1088 String[] orderByFields = orderByComparator.getOrderByFields();
1089
1090 if (orderByFields.length > 0) {
1091 query.append(WHERE_AND);
1092 }
1093
1094 for (int i = 0; i < orderByFields.length; i++) {
1095 query.append(_ORDER_BY_ENTITY_ALIAS);
1096 query.append(orderByFields[i]);
1097
1098 if ((i + 1) < orderByFields.length) {
1099 if (orderByComparator.isAscending() ^ previous) {
1100 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1101 }
1102 else {
1103 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1104 }
1105 }
1106 else {
1107 if (orderByComparator.isAscending() ^ previous) {
1108 query.append(WHERE_GREATER_THAN);
1109 }
1110 else {
1111 query.append(WHERE_LESSER_THAN);
1112 }
1113 }
1114 }
1115
1116 query.append(ORDER_BY_CLAUSE);
1117
1118 for (int i = 0; i < orderByFields.length; i++) {
1119 query.append(_ORDER_BY_ENTITY_ALIAS);
1120 query.append(orderByFields[i]);
1121
1122 if ((i + 1) < orderByFields.length) {
1123 if (orderByComparator.isAscending() ^ previous) {
1124 query.append(ORDER_BY_ASC_HAS_NEXT);
1125 }
1126 else {
1127 query.append(ORDER_BY_DESC_HAS_NEXT);
1128 }
1129 }
1130 else {
1131 if (orderByComparator.isAscending() ^ previous) {
1132 query.append(ORDER_BY_ASC);
1133 }
1134 else {
1135 query.append(ORDER_BY_DESC);
1136 }
1137 }
1138 }
1139 }
1140
1141 String sql = query.toString();
1142
1143 Query q = session.createQuery(sql);
1144
1145 q.setFirstResult(0);
1146 q.setMaxResults(2);
1147
1148 QueryPos qPos = QueryPos.getInstance(q);
1149
1150 qPos.add(threadId);
1151
1152 if (orderByComparator != null) {
1153 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1154
1155 for (Object value : values) {
1156 qPos.add(value);
1157 }
1158 }
1159
1160 List<MBMessageFlag> list = q.list();
1161
1162 if (list.size() == 2) {
1163 return list.get(1);
1164 }
1165 else {
1166 return null;
1167 }
1168 }
1169
1170
1177 public List<MBMessageFlag> findByMessageId(long messageId)
1178 throws SystemException {
1179 return findByMessageId(messageId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1180 null);
1181 }
1182
1183
1196 public List<MBMessageFlag> findByMessageId(long messageId, int start,
1197 int end) throws SystemException {
1198 return findByMessageId(messageId, start, end, null);
1199 }
1200
1201
1215 public List<MBMessageFlag> findByMessageId(long messageId, int start,
1216 int end, OrderByComparator orderByComparator) throws SystemException {
1217 Object[] finderArgs = new Object[] {
1218 messageId,
1219
1220 String.valueOf(start), String.valueOf(end),
1221 String.valueOf(orderByComparator)
1222 };
1223
1224 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_MESSAGEID,
1225 finderArgs, this);
1226
1227 if (list == null) {
1228 Session session = null;
1229
1230 try {
1231 session = openSession();
1232
1233 StringBundler query = null;
1234
1235 if (orderByComparator != null) {
1236 query = new StringBundler(3 +
1237 (orderByComparator.getOrderByFields().length * 3));
1238 }
1239 else {
1240 query = new StringBundler(2);
1241 }
1242
1243 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1244
1245 query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1246
1247 if (orderByComparator != null) {
1248 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1249 orderByComparator);
1250 }
1251
1252 String sql = query.toString();
1253
1254 Query q = session.createQuery(sql);
1255
1256 QueryPos qPos = QueryPos.getInstance(q);
1257
1258 qPos.add(messageId);
1259
1260 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1261 start, end);
1262 }
1263 catch (Exception e) {
1264 throw processException(e);
1265 }
1266 finally {
1267 if (list == null) {
1268 list = new ArrayList<MBMessageFlag>();
1269 }
1270
1271 cacheResult(list);
1272
1273 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_MESSAGEID,
1274 finderArgs, list);
1275
1276 closeSession(session);
1277 }
1278 }
1279
1280 return list;
1281 }
1282
1283
1296 public MBMessageFlag findByMessageId_First(long messageId,
1297 OrderByComparator orderByComparator)
1298 throws NoSuchMessageFlagException, SystemException {
1299 List<MBMessageFlag> list = findByMessageId(messageId, 0, 1,
1300 orderByComparator);
1301
1302 if (list.isEmpty()) {
1303 StringBundler msg = new StringBundler(4);
1304
1305 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1306
1307 msg.append("messageId=");
1308 msg.append(messageId);
1309
1310 msg.append(StringPool.CLOSE_CURLY_BRACE);
1311
1312 throw new NoSuchMessageFlagException(msg.toString());
1313 }
1314 else {
1315 return list.get(0);
1316 }
1317 }
1318
1319
1332 public MBMessageFlag findByMessageId_Last(long messageId,
1333 OrderByComparator orderByComparator)
1334 throws NoSuchMessageFlagException, SystemException {
1335 int count = countByMessageId(messageId);
1336
1337 List<MBMessageFlag> list = findByMessageId(messageId, count - 1, count,
1338 orderByComparator);
1339
1340 if (list.isEmpty()) {
1341 StringBundler msg = new StringBundler(4);
1342
1343 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1344
1345 msg.append("messageId=");
1346 msg.append(messageId);
1347
1348 msg.append(StringPool.CLOSE_CURLY_BRACE);
1349
1350 throw new NoSuchMessageFlagException(msg.toString());
1351 }
1352 else {
1353 return list.get(0);
1354 }
1355 }
1356
1357
1371 public MBMessageFlag[] findByMessageId_PrevAndNext(long messageFlagId,
1372 long messageId, OrderByComparator orderByComparator)
1373 throws NoSuchMessageFlagException, SystemException {
1374 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1375
1376 Session session = null;
1377
1378 try {
1379 session = openSession();
1380
1381 MBMessageFlag[] array = new MBMessageFlagImpl[3];
1382
1383 array[0] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1384 messageId, orderByComparator, true);
1385
1386 array[1] = mbMessageFlag;
1387
1388 array[2] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1389 messageId, orderByComparator, false);
1390
1391 return array;
1392 }
1393 catch (Exception e) {
1394 throw processException(e);
1395 }
1396 finally {
1397 closeSession(session);
1398 }
1399 }
1400
1401 protected MBMessageFlag getByMessageId_PrevAndNext(Session session,
1402 MBMessageFlag mbMessageFlag, long messageId,
1403 OrderByComparator orderByComparator, boolean previous) {
1404 StringBundler query = null;
1405
1406 if (orderByComparator != null) {
1407 query = new StringBundler(6 +
1408 (orderByComparator.getOrderByFields().length * 6));
1409 }
1410 else {
1411 query = new StringBundler(3);
1412 }
1413
1414 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1415
1416 query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1417
1418 if (orderByComparator != null) {
1419 String[] orderByFields = orderByComparator.getOrderByFields();
1420
1421 if (orderByFields.length > 0) {
1422 query.append(WHERE_AND);
1423 }
1424
1425 for (int i = 0; i < orderByFields.length; i++) {
1426 query.append(_ORDER_BY_ENTITY_ALIAS);
1427 query.append(orderByFields[i]);
1428
1429 if ((i + 1) < orderByFields.length) {
1430 if (orderByComparator.isAscending() ^ previous) {
1431 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1432 }
1433 else {
1434 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1435 }
1436 }
1437 else {
1438 if (orderByComparator.isAscending() ^ previous) {
1439 query.append(WHERE_GREATER_THAN);
1440 }
1441 else {
1442 query.append(WHERE_LESSER_THAN);
1443 }
1444 }
1445 }
1446
1447 query.append(ORDER_BY_CLAUSE);
1448
1449 for (int i = 0; i < orderByFields.length; i++) {
1450 query.append(_ORDER_BY_ENTITY_ALIAS);
1451 query.append(orderByFields[i]);
1452
1453 if ((i + 1) < orderByFields.length) {
1454 if (orderByComparator.isAscending() ^ previous) {
1455 query.append(ORDER_BY_ASC_HAS_NEXT);
1456 }
1457 else {
1458 query.append(ORDER_BY_DESC_HAS_NEXT);
1459 }
1460 }
1461 else {
1462 if (orderByComparator.isAscending() ^ previous) {
1463 query.append(ORDER_BY_ASC);
1464 }
1465 else {
1466 query.append(ORDER_BY_DESC);
1467 }
1468 }
1469 }
1470 }
1471
1472 String sql = query.toString();
1473
1474 Query q = session.createQuery(sql);
1475
1476 q.setFirstResult(0);
1477 q.setMaxResults(2);
1478
1479 QueryPos qPos = QueryPos.getInstance(q);
1480
1481 qPos.add(messageId);
1482
1483 if (orderByComparator != null) {
1484 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1485
1486 for (Object value : values) {
1487 qPos.add(value);
1488 }
1489 }
1490
1491 List<MBMessageFlag> list = q.list();
1492
1493 if (list.size() == 2) {
1494 return list.get(1);
1495 }
1496 else {
1497 return null;
1498 }
1499 }
1500
1501
1509 public List<MBMessageFlag> findByT_F(long threadId, int flag)
1510 throws SystemException {
1511 return findByT_F(threadId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1512 null);
1513 }
1514
1515
1529 public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1530 int end) throws SystemException {
1531 return findByT_F(threadId, flag, start, end, null);
1532 }
1533
1534
1549 public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1550 int end, OrderByComparator orderByComparator) throws SystemException {
1551 Object[] finderArgs = new Object[] {
1552 threadId, flag,
1553
1554 String.valueOf(start), String.valueOf(end),
1555 String.valueOf(orderByComparator)
1556 };
1557
1558 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_F,
1559 finderArgs, this);
1560
1561 if (list == null) {
1562 Session session = null;
1563
1564 try {
1565 session = openSession();
1566
1567 StringBundler query = null;
1568
1569 if (orderByComparator != null) {
1570 query = new StringBundler(4 +
1571 (orderByComparator.getOrderByFields().length * 3));
1572 }
1573 else {
1574 query = new StringBundler(3);
1575 }
1576
1577 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1578
1579 query.append(_FINDER_COLUMN_T_F_THREADID_2);
1580
1581 query.append(_FINDER_COLUMN_T_F_FLAG_2);
1582
1583 if (orderByComparator != null) {
1584 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1585 orderByComparator);
1586 }
1587
1588 String sql = query.toString();
1589
1590 Query q = session.createQuery(sql);
1591
1592 QueryPos qPos = QueryPos.getInstance(q);
1593
1594 qPos.add(threadId);
1595
1596 qPos.add(flag);
1597
1598 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1599 start, end);
1600 }
1601 catch (Exception e) {
1602 throw processException(e);
1603 }
1604 finally {
1605 if (list == null) {
1606 list = new ArrayList<MBMessageFlag>();
1607 }
1608
1609 cacheResult(list);
1610
1611 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_F, finderArgs,
1612 list);
1613
1614 closeSession(session);
1615 }
1616 }
1617
1618 return list;
1619 }
1620
1621
1635 public MBMessageFlag findByT_F_First(long threadId, int flag,
1636 OrderByComparator orderByComparator)
1637 throws NoSuchMessageFlagException, SystemException {
1638 List<MBMessageFlag> list = findByT_F(threadId, flag, 0, 1,
1639 orderByComparator);
1640
1641 if (list.isEmpty()) {
1642 StringBundler msg = new StringBundler(6);
1643
1644 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1645
1646 msg.append("threadId=");
1647 msg.append(threadId);
1648
1649 msg.append(", flag=");
1650 msg.append(flag);
1651
1652 msg.append(StringPool.CLOSE_CURLY_BRACE);
1653
1654 throw new NoSuchMessageFlagException(msg.toString());
1655 }
1656 else {
1657 return list.get(0);
1658 }
1659 }
1660
1661
1675 public MBMessageFlag findByT_F_Last(long threadId, int flag,
1676 OrderByComparator orderByComparator)
1677 throws NoSuchMessageFlagException, SystemException {
1678 int count = countByT_F(threadId, flag);
1679
1680 List<MBMessageFlag> list = findByT_F(threadId, flag, count - 1, count,
1681 orderByComparator);
1682
1683 if (list.isEmpty()) {
1684 StringBundler msg = new StringBundler(6);
1685
1686 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1687
1688 msg.append("threadId=");
1689 msg.append(threadId);
1690
1691 msg.append(", flag=");
1692 msg.append(flag);
1693
1694 msg.append(StringPool.CLOSE_CURLY_BRACE);
1695
1696 throw new NoSuchMessageFlagException(msg.toString());
1697 }
1698 else {
1699 return list.get(0);
1700 }
1701 }
1702
1703
1718 public MBMessageFlag[] findByT_F_PrevAndNext(long messageFlagId,
1719 long threadId, int flag, OrderByComparator orderByComparator)
1720 throws NoSuchMessageFlagException, SystemException {
1721 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1722
1723 Session session = null;
1724
1725 try {
1726 session = openSession();
1727
1728 MBMessageFlag[] array = new MBMessageFlagImpl[3];
1729
1730 array[0] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1731 flag, orderByComparator, true);
1732
1733 array[1] = mbMessageFlag;
1734
1735 array[2] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1736 flag, orderByComparator, false);
1737
1738 return array;
1739 }
1740 catch (Exception e) {
1741 throw processException(e);
1742 }
1743 finally {
1744 closeSession(session);
1745 }
1746 }
1747
1748 protected MBMessageFlag getByT_F_PrevAndNext(Session session,
1749 MBMessageFlag mbMessageFlag, long threadId, int flag,
1750 OrderByComparator orderByComparator, boolean previous) {
1751 StringBundler query = null;
1752
1753 if (orderByComparator != null) {
1754 query = new StringBundler(6 +
1755 (orderByComparator.getOrderByFields().length * 6));
1756 }
1757 else {
1758 query = new StringBundler(3);
1759 }
1760
1761 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1762
1763 query.append(_FINDER_COLUMN_T_F_THREADID_2);
1764
1765 query.append(_FINDER_COLUMN_T_F_FLAG_2);
1766
1767 if (orderByComparator != null) {
1768 String[] orderByFields = orderByComparator.getOrderByFields();
1769
1770 if (orderByFields.length > 0) {
1771 query.append(WHERE_AND);
1772 }
1773
1774 for (int i = 0; i < orderByFields.length; i++) {
1775 query.append(_ORDER_BY_ENTITY_ALIAS);
1776 query.append(orderByFields[i]);
1777
1778 if ((i + 1) < orderByFields.length) {
1779 if (orderByComparator.isAscending() ^ previous) {
1780 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1781 }
1782 else {
1783 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1784 }
1785 }
1786 else {
1787 if (orderByComparator.isAscending() ^ previous) {
1788 query.append(WHERE_GREATER_THAN);
1789 }
1790 else {
1791 query.append(WHERE_LESSER_THAN);
1792 }
1793 }
1794 }
1795
1796 query.append(ORDER_BY_CLAUSE);
1797
1798 for (int i = 0; i < orderByFields.length; i++) {
1799 query.append(_ORDER_BY_ENTITY_ALIAS);
1800 query.append(orderByFields[i]);
1801
1802 if ((i + 1) < orderByFields.length) {
1803 if (orderByComparator.isAscending() ^ previous) {
1804 query.append(ORDER_BY_ASC_HAS_NEXT);
1805 }
1806 else {
1807 query.append(ORDER_BY_DESC_HAS_NEXT);
1808 }
1809 }
1810 else {
1811 if (orderByComparator.isAscending() ^ previous) {
1812 query.append(ORDER_BY_ASC);
1813 }
1814 else {
1815 query.append(ORDER_BY_DESC);
1816 }
1817 }
1818 }
1819 }
1820
1821 String sql = query.toString();
1822
1823 Query q = session.createQuery(sql);
1824
1825 q.setFirstResult(0);
1826 q.setMaxResults(2);
1827
1828 QueryPos qPos = QueryPos.getInstance(q);
1829
1830 qPos.add(threadId);
1831
1832 qPos.add(flag);
1833
1834 if (orderByComparator != null) {
1835 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1836
1837 for (Object value : values) {
1838 qPos.add(value);
1839 }
1840 }
1841
1842 List<MBMessageFlag> list = q.list();
1843
1844 if (list.size() == 2) {
1845 return list.get(1);
1846 }
1847 else {
1848 return null;
1849 }
1850 }
1851
1852
1860 public List<MBMessageFlag> findByM_F(long messageId, int flag)
1861 throws SystemException {
1862 return findByM_F(messageId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1863 null);
1864 }
1865
1866
1880 public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1881 int end) throws SystemException {
1882 return findByM_F(messageId, flag, start, end, null);
1883 }
1884
1885
1900 public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1901 int end, OrderByComparator orderByComparator) throws SystemException {
1902 Object[] finderArgs = new Object[] {
1903 messageId, flag,
1904
1905 String.valueOf(start), String.valueOf(end),
1906 String.valueOf(orderByComparator)
1907 };
1908
1909 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_M_F,
1910 finderArgs, this);
1911
1912 if (list == null) {
1913 Session session = null;
1914
1915 try {
1916 session = openSession();
1917
1918 StringBundler query = null;
1919
1920 if (orderByComparator != null) {
1921 query = new StringBundler(4 +
1922 (orderByComparator.getOrderByFields().length * 3));
1923 }
1924 else {
1925 query = new StringBundler(3);
1926 }
1927
1928 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1929
1930 query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
1931
1932 query.append(_FINDER_COLUMN_M_F_FLAG_2);
1933
1934 if (orderByComparator != null) {
1935 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1936 orderByComparator);
1937 }
1938
1939 String sql = query.toString();
1940
1941 Query q = session.createQuery(sql);
1942
1943 QueryPos qPos = QueryPos.getInstance(q);
1944
1945 qPos.add(messageId);
1946
1947 qPos.add(flag);
1948
1949 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1950 start, end);
1951 }
1952 catch (Exception e) {
1953 throw processException(e);
1954 }
1955 finally {
1956 if (list == null) {
1957 list = new ArrayList<MBMessageFlag>();
1958 }
1959
1960 cacheResult(list);
1961
1962 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_M_F, finderArgs,
1963 list);
1964
1965 closeSession(session);
1966 }
1967 }
1968
1969 return list;
1970 }
1971
1972
1986 public MBMessageFlag findByM_F_First(long messageId, int flag,
1987 OrderByComparator orderByComparator)
1988 throws NoSuchMessageFlagException, SystemException {
1989 List<MBMessageFlag> list = findByM_F(messageId, flag, 0, 1,
1990 orderByComparator);
1991
1992 if (list.isEmpty()) {
1993 StringBundler msg = new StringBundler(6);
1994
1995 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1996
1997 msg.append("messageId=");
1998 msg.append(messageId);
1999
2000 msg.append(", flag=");
2001 msg.append(flag);
2002
2003 msg.append(StringPool.CLOSE_CURLY_BRACE);
2004
2005 throw new NoSuchMessageFlagException(msg.toString());
2006 }
2007 else {
2008 return list.get(0);
2009 }
2010 }
2011
2012
2026 public MBMessageFlag findByM_F_Last(long messageId, int flag,
2027 OrderByComparator orderByComparator)
2028 throws NoSuchMessageFlagException, SystemException {
2029 int count = countByM_F(messageId, flag);
2030
2031 List<MBMessageFlag> list = findByM_F(messageId, flag, count - 1, count,
2032 orderByComparator);
2033
2034 if (list.isEmpty()) {
2035 StringBundler msg = new StringBundler(6);
2036
2037 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2038
2039 msg.append("messageId=");
2040 msg.append(messageId);
2041
2042 msg.append(", flag=");
2043 msg.append(flag);
2044
2045 msg.append(StringPool.CLOSE_CURLY_BRACE);
2046
2047 throw new NoSuchMessageFlagException(msg.toString());
2048 }
2049 else {
2050 return list.get(0);
2051 }
2052 }
2053
2054
2069 public MBMessageFlag[] findByM_F_PrevAndNext(long messageFlagId,
2070 long messageId, int flag, OrderByComparator orderByComparator)
2071 throws NoSuchMessageFlagException, SystemException {
2072 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
2073
2074 Session session = null;
2075
2076 try {
2077 session = openSession();
2078
2079 MBMessageFlag[] array = new MBMessageFlagImpl[3];
2080
2081 array[0] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
2082 flag, orderByComparator, true);
2083
2084 array[1] = mbMessageFlag;
2085
2086 array[2] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
2087 flag, orderByComparator, false);
2088
2089 return array;
2090 }
2091 catch (Exception e) {
2092 throw processException(e);
2093 }
2094 finally {
2095 closeSession(session);
2096 }
2097 }
2098
2099 protected MBMessageFlag getByM_F_PrevAndNext(Session session,
2100 MBMessageFlag mbMessageFlag, long messageId, int flag,
2101 OrderByComparator orderByComparator, boolean previous) {
2102 StringBundler query = null;
2103
2104 if (orderByComparator != null) {
2105 query = new StringBundler(6 +
2106 (orderByComparator.getOrderByFields().length * 6));
2107 }
2108 else {
2109 query = new StringBundler(3);
2110 }
2111
2112 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2113
2114 query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
2115
2116 query.append(_FINDER_COLUMN_M_F_FLAG_2);
2117
2118 if (orderByComparator != null) {
2119 String[] orderByFields = orderByComparator.getOrderByFields();
2120
2121 if (orderByFields.length > 0) {
2122 query.append(WHERE_AND);
2123 }
2124
2125 for (int i = 0; i < orderByFields.length; i++) {
2126 query.append(_ORDER_BY_ENTITY_ALIAS);
2127 query.append(orderByFields[i]);
2128
2129 if ((i + 1) < orderByFields.length) {
2130 if (orderByComparator.isAscending() ^ previous) {
2131 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2132 }
2133 else {
2134 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2135 }
2136 }
2137 else {
2138 if (orderByComparator.isAscending() ^ previous) {
2139 query.append(WHERE_GREATER_THAN);
2140 }
2141 else {
2142 query.append(WHERE_LESSER_THAN);
2143 }
2144 }
2145 }
2146
2147 query.append(ORDER_BY_CLAUSE);
2148
2149 for (int i = 0; i < orderByFields.length; i++) {
2150 query.append(_ORDER_BY_ENTITY_ALIAS);
2151 query.append(orderByFields[i]);
2152
2153 if ((i + 1) < orderByFields.length) {
2154 if (orderByComparator.isAscending() ^ previous) {
2155 query.append(ORDER_BY_ASC_HAS_NEXT);
2156 }
2157 else {
2158 query.append(ORDER_BY_DESC_HAS_NEXT);
2159 }
2160 }
2161 else {
2162 if (orderByComparator.isAscending() ^ previous) {
2163 query.append(ORDER_BY_ASC);
2164 }
2165 else {
2166 query.append(ORDER_BY_DESC);
2167 }
2168 }
2169 }
2170 }
2171
2172 String sql = query.toString();
2173
2174 Query q = session.createQuery(sql);
2175
2176 q.setFirstResult(0);
2177 q.setMaxResults(2);
2178
2179 QueryPos qPos = QueryPos.getInstance(q);
2180
2181 qPos.add(messageId);
2182
2183 qPos.add(flag);
2184
2185 if (orderByComparator != null) {
2186 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2187
2188 for (Object value : values) {
2189 qPos.add(value);
2190 }
2191 }
2192
2193 List<MBMessageFlag> list = q.list();
2194
2195 if (list.size() == 2) {
2196 return list.get(1);
2197 }
2198 else {
2199 return null;
2200 }
2201 }
2202
2203
2212 public List<MBMessageFlag> findByU_T_F(long userId, long threadId, int flag)
2213 throws SystemException {
2214 return findByU_T_F(userId, threadId, flag, QueryUtil.ALL_POS,
2215 QueryUtil.ALL_POS, null);
2216 }
2217
2218
2233 public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
2234 int flag, int start, int end) throws SystemException {
2235 return findByU_T_F(userId, threadId, flag, start, end, null);
2236 }
2237
2238
2254 public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
2255 int flag, int start, int end, OrderByComparator orderByComparator)
2256 throws SystemException {
2257 Object[] finderArgs = new Object[] {
2258 userId, threadId, flag,
2259
2260 String.valueOf(start), String.valueOf(end),
2261 String.valueOf(orderByComparator)
2262 };
2263
2264 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_T_F,
2265 finderArgs, this);
2266
2267 if (list == null) {
2268 Session session = null;
2269
2270 try {
2271 session = openSession();
2272
2273 StringBundler query = null;
2274
2275 if (orderByComparator != null) {
2276 query = new StringBundler(5 +
2277 (orderByComparator.getOrderByFields().length * 3));
2278 }
2279 else {
2280 query = new StringBundler(4);
2281 }
2282
2283 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2284
2285 query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2286
2287 query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2288
2289 query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2290
2291 if (orderByComparator != null) {
2292 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2293 orderByComparator);
2294 }
2295
2296 String sql = query.toString();
2297
2298 Query q = session.createQuery(sql);
2299
2300 QueryPos qPos = QueryPos.getInstance(q);
2301
2302 qPos.add(userId);
2303
2304 qPos.add(threadId);
2305
2306 qPos.add(flag);
2307
2308 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2309 start, end);
2310 }
2311 catch (Exception e) {
2312 throw processException(e);
2313 }
2314 finally {
2315 if (list == null) {
2316 list = new ArrayList<MBMessageFlag>();
2317 }
2318
2319 cacheResult(list);
2320
2321 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_T_F,
2322 finderArgs, list);
2323
2324 closeSession(session);
2325 }
2326 }
2327
2328 return list;
2329 }
2330
2331
2346 public MBMessageFlag findByU_T_F_First(long userId, long threadId,
2347 int flag, OrderByComparator orderByComparator)
2348 throws NoSuchMessageFlagException, SystemException {
2349 List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag, 0, 1,
2350 orderByComparator);
2351
2352 if (list.isEmpty()) {
2353 StringBundler msg = new StringBundler(8);
2354
2355 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2356
2357 msg.append("userId=");
2358 msg.append(userId);
2359
2360 msg.append(", threadId=");
2361 msg.append(threadId);
2362
2363 msg.append(", flag=");
2364 msg.append(flag);
2365
2366 msg.append(StringPool.CLOSE_CURLY_BRACE);
2367
2368 throw new NoSuchMessageFlagException(msg.toString());
2369 }
2370 else {
2371 return list.get(0);
2372 }
2373 }
2374
2375
2390 public MBMessageFlag findByU_T_F_Last(long userId, long threadId, int flag,
2391 OrderByComparator orderByComparator)
2392 throws NoSuchMessageFlagException, SystemException {
2393 int count = countByU_T_F(userId, threadId, flag);
2394
2395 List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag,
2396 count - 1, count, orderByComparator);
2397
2398 if (list.isEmpty()) {
2399 StringBundler msg = new StringBundler(8);
2400
2401 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2402
2403 msg.append("userId=");
2404 msg.append(userId);
2405
2406 msg.append(", threadId=");
2407 msg.append(threadId);
2408
2409 msg.append(", flag=");
2410 msg.append(flag);
2411
2412 msg.append(StringPool.CLOSE_CURLY_BRACE);
2413
2414 throw new NoSuchMessageFlagException(msg.toString());
2415 }
2416 else {
2417 return list.get(0);
2418 }
2419 }
2420
2421
2437 public MBMessageFlag[] findByU_T_F_PrevAndNext(long messageFlagId,
2438 long userId, long threadId, int flag,
2439 OrderByComparator orderByComparator)
2440 throws NoSuchMessageFlagException, SystemException {
2441 MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
2442
2443 Session session = null;
2444
2445 try {
2446 session = openSession();
2447
2448 MBMessageFlag[] array = new MBMessageFlagImpl[3];
2449
2450 array[0] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
2451 threadId, flag, orderByComparator, true);
2452
2453 array[1] = mbMessageFlag;
2454
2455 array[2] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
2456 threadId, flag, orderByComparator, false);
2457
2458 return array;
2459 }
2460 catch (Exception e) {
2461 throw processException(e);
2462 }
2463 finally {
2464 closeSession(session);
2465 }
2466 }
2467
2468 protected MBMessageFlag getByU_T_F_PrevAndNext(Session session,
2469 MBMessageFlag mbMessageFlag, long userId, long threadId, int flag,
2470 OrderByComparator orderByComparator, boolean previous) {
2471 StringBundler query = null;
2472
2473 if (orderByComparator != null) {
2474 query = new StringBundler(6 +
2475 (orderByComparator.getOrderByFields().length * 6));
2476 }
2477 else {
2478 query = new StringBundler(3);
2479 }
2480
2481 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2482
2483 query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2484
2485 query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2486
2487 query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2488
2489 if (orderByComparator != null) {
2490 String[] orderByFields = orderByComparator.getOrderByFields();
2491
2492 if (orderByFields.length > 0) {
2493 query.append(WHERE_AND);
2494 }
2495
2496 for (int i = 0; i < orderByFields.length; i++) {
2497 query.append(_ORDER_BY_ENTITY_ALIAS);
2498 query.append(orderByFields[i]);
2499
2500 if ((i + 1) < orderByFields.length) {
2501 if (orderByComparator.isAscending() ^ previous) {
2502 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2503 }
2504 else {
2505 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2506 }
2507 }
2508 else {
2509 if (orderByComparator.isAscending() ^ previous) {
2510 query.append(WHERE_GREATER_THAN);
2511 }
2512 else {
2513 query.append(WHERE_LESSER_THAN);
2514 }
2515 }
2516 }
2517
2518 query.append(ORDER_BY_CLAUSE);
2519
2520 for (int i = 0; i < orderByFields.length; i++) {
2521 query.append(_ORDER_BY_ENTITY_ALIAS);
2522 query.append(orderByFields[i]);
2523
2524 if ((i + 1) < orderByFields.length) {
2525 if (orderByComparator.isAscending() ^ previous) {
2526 query.append(ORDER_BY_ASC_HAS_NEXT);
2527 }
2528 else {
2529 query.append(ORDER_BY_DESC_HAS_NEXT);
2530 }
2531 }
2532 else {
2533 if (orderByComparator.isAscending() ^ previous) {
2534 query.append(ORDER_BY_ASC);
2535 }
2536 else {
2537 query.append(ORDER_BY_DESC);
2538 }
2539 }
2540 }
2541 }
2542
2543 String sql = query.toString();
2544
2545 Query q = session.createQuery(sql);
2546
2547 q.setFirstResult(0);
2548 q.setMaxResults(2);
2549
2550 QueryPos qPos = QueryPos.getInstance(q);
2551
2552 qPos.add(userId);
2553
2554 qPos.add(threadId);
2555
2556 qPos.add(flag);
2557
2558 if (orderByComparator != null) {
2559 Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2560
2561 for (Object value : values) {
2562 qPos.add(value);
2563 }
2564 }
2565
2566 List<MBMessageFlag> list = q.list();
2567
2568 if (list.size() == 2) {
2569 return list.get(1);
2570 }
2571 else {
2572 return null;
2573 }
2574 }
2575
2576
2586 public MBMessageFlag findByU_M_F(long userId, long messageId, int flag)
2587 throws NoSuchMessageFlagException, SystemException {
2588 MBMessageFlag mbMessageFlag = fetchByU_M_F(userId, messageId, flag);
2589
2590 if (mbMessageFlag == null) {
2591 StringBundler msg = new StringBundler(8);
2592
2593 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2594
2595 msg.append("userId=");
2596 msg.append(userId);
2597
2598 msg.append(", messageId=");
2599 msg.append(messageId);
2600
2601 msg.append(", flag=");
2602 msg.append(flag);
2603
2604 msg.append(StringPool.CLOSE_CURLY_BRACE);
2605
2606 if (_log.isWarnEnabled()) {
2607 _log.warn(msg.toString());
2608 }
2609
2610 throw new NoSuchMessageFlagException(msg.toString());
2611 }
2612
2613 return mbMessageFlag;
2614 }
2615
2616
2625 public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag)
2626 throws SystemException {
2627 return fetchByU_M_F(userId, messageId, flag, true);
2628 }
2629
2630
2639 public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag,
2640 boolean retrieveFromCache) throws SystemException {
2641 Object[] finderArgs = new Object[] { userId, messageId, flag };
2642
2643 Object result = null;
2644
2645 if (retrieveFromCache) {
2646 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_M_F,
2647 finderArgs, this);
2648 }
2649
2650 if (result == null) {
2651 Session session = null;
2652
2653 try {
2654 session = openSession();
2655
2656 StringBundler query = new StringBundler(4);
2657
2658 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2659
2660 query.append(_FINDER_COLUMN_U_M_F_USERID_2);
2661
2662 query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
2663
2664 query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
2665
2666 String sql = query.toString();
2667
2668 Query q = session.createQuery(sql);
2669
2670 QueryPos qPos = QueryPos.getInstance(q);
2671
2672 qPos.add(userId);
2673
2674 qPos.add(messageId);
2675
2676 qPos.add(flag);
2677
2678 List<MBMessageFlag> list = q.list();
2679
2680 result = list;
2681
2682 MBMessageFlag mbMessageFlag = null;
2683
2684 if (list.isEmpty()) {
2685 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2686 finderArgs, list);
2687 }
2688 else {
2689 mbMessageFlag = list.get(0);
2690
2691 cacheResult(mbMessageFlag);
2692
2693 if ((mbMessageFlag.getUserId() != userId) ||
2694 (mbMessageFlag.getMessageId() != messageId) ||
2695 (mbMessageFlag.getFlag() != flag)) {
2696 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2697 finderArgs, mbMessageFlag);
2698 }
2699 }
2700
2701 return mbMessageFlag;
2702 }
2703 catch (Exception e) {
2704 throw processException(e);
2705 }
2706 finally {
2707 if (result == null) {
2708 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2709 finderArgs, new ArrayList<MBMessageFlag>());
2710 }
2711
2712 closeSession(session);
2713 }
2714 }
2715 else {
2716 if (result instanceof List<?>) {
2717 return null;
2718 }
2719 else {
2720 return (MBMessageFlag)result;
2721 }
2722 }
2723 }
2724
2725
2731 public List<MBMessageFlag> findAll() throws SystemException {
2732 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2733 }
2734
2735
2747 public List<MBMessageFlag> findAll(int start, int end)
2748 throws SystemException {
2749 return findAll(start, end, null);
2750 }
2751
2752
2765 public List<MBMessageFlag> findAll(int start, int end,
2766 OrderByComparator orderByComparator) throws SystemException {
2767 Object[] finderArgs = new Object[] {
2768 String.valueOf(start), String.valueOf(end),
2769 String.valueOf(orderByComparator)
2770 };
2771
2772 List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2773 finderArgs, this);
2774
2775 if (list == null) {
2776 Session session = null;
2777
2778 try {
2779 session = openSession();
2780
2781 StringBundler query = null;
2782 String sql = null;
2783
2784 if (orderByComparator != null) {
2785 query = new StringBundler(2 +
2786 (orderByComparator.getOrderByFields().length * 3));
2787
2788 query.append(_SQL_SELECT_MBMESSAGEFLAG);
2789
2790 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2791 orderByComparator);
2792
2793 sql = query.toString();
2794 }
2795 else {
2796 sql = _SQL_SELECT_MBMESSAGEFLAG;
2797 }
2798
2799 Query q = session.createQuery(sql);
2800
2801 if (orderByComparator == null) {
2802 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2803 start, end, false);
2804
2805 Collections.sort(list);
2806 }
2807 else {
2808 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2809 start, end);
2810 }
2811 }
2812 catch (Exception e) {
2813 throw processException(e);
2814 }
2815 finally {
2816 if (list == null) {
2817 list = new ArrayList<MBMessageFlag>();
2818 }
2819
2820 cacheResult(list);
2821
2822 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2823
2824 closeSession(session);
2825 }
2826 }
2827
2828 return list;
2829 }
2830
2831
2837 public void removeByUserId(long userId) throws SystemException {
2838 for (MBMessageFlag mbMessageFlag : findByUserId(userId)) {
2839 remove(mbMessageFlag);
2840 }
2841 }
2842
2843
2849 public void removeByThreadId(long threadId) throws SystemException {
2850 for (MBMessageFlag mbMessageFlag : findByThreadId(threadId)) {
2851 remove(mbMessageFlag);
2852 }
2853 }
2854
2855
2861 public void removeByMessageId(long messageId) throws SystemException {
2862 for (MBMessageFlag mbMessageFlag : findByMessageId(messageId)) {
2863 remove(mbMessageFlag);
2864 }
2865 }
2866
2867
2874 public void removeByT_F(long threadId, int flag) throws SystemException {
2875 for (MBMessageFlag mbMessageFlag : findByT_F(threadId, flag)) {
2876 remove(mbMessageFlag);
2877 }
2878 }
2879
2880
2887 public void removeByM_F(long messageId, int flag) throws SystemException {
2888 for (MBMessageFlag mbMessageFlag : findByM_F(messageId, flag)) {
2889 remove(mbMessageFlag);
2890 }
2891 }
2892
2893
2901 public void removeByU_T_F(long userId, long threadId, int flag)
2902 throws SystemException {
2903 for (MBMessageFlag mbMessageFlag : findByU_T_F(userId, threadId, flag)) {
2904 remove(mbMessageFlag);
2905 }
2906 }
2907
2908
2916 public void removeByU_M_F(long userId, long messageId, int flag)
2917 throws NoSuchMessageFlagException, SystemException {
2918 MBMessageFlag mbMessageFlag = findByU_M_F(userId, messageId, flag);
2919
2920 remove(mbMessageFlag);
2921 }
2922
2923
2928 public void removeAll() throws SystemException {
2929 for (MBMessageFlag mbMessageFlag : findAll()) {
2930 remove(mbMessageFlag);
2931 }
2932 }
2933
2934
2941 public int countByUserId(long userId) throws SystemException {
2942 Object[] finderArgs = new Object[] { userId };
2943
2944 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2945 finderArgs, this);
2946
2947 if (count == null) {
2948 Session session = null;
2949
2950 try {
2951 session = openSession();
2952
2953 StringBundler query = new StringBundler(2);
2954
2955 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2956
2957 query.append(_FINDER_COLUMN_USERID_USERID_2);
2958
2959 String sql = query.toString();
2960
2961 Query q = session.createQuery(sql);
2962
2963 QueryPos qPos = QueryPos.getInstance(q);
2964
2965 qPos.add(userId);
2966
2967 count = (Long)q.uniqueResult();
2968 }
2969 catch (Exception e) {
2970 throw processException(e);
2971 }
2972 finally {
2973 if (count == null) {
2974 count = Long.valueOf(0);
2975 }
2976
2977 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2978 finderArgs, count);
2979
2980 closeSession(session);
2981 }
2982 }
2983
2984 return count.intValue();
2985 }
2986
2987
2994 public int countByThreadId(long threadId) throws SystemException {
2995 Object[] finderArgs = new Object[] { threadId };
2996
2997 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
2998 finderArgs, this);
2999
3000 if (count == null) {
3001 Session session = null;
3002
3003 try {
3004 session = openSession();
3005
3006 StringBundler query = new StringBundler(2);
3007
3008 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3009
3010 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3011
3012 String sql = query.toString();
3013
3014 Query q = session.createQuery(sql);
3015
3016 QueryPos qPos = QueryPos.getInstance(q);
3017
3018 qPos.add(threadId);
3019
3020 count = (Long)q.uniqueResult();
3021 }
3022 catch (Exception e) {
3023 throw processException(e);
3024 }
3025 finally {
3026 if (count == null) {
3027 count = Long.valueOf(0);
3028 }
3029
3030 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
3031 finderArgs, count);
3032
3033 closeSession(session);
3034 }
3035 }
3036
3037 return count.intValue();
3038 }
3039
3040
3047 public int countByMessageId(long messageId) throws SystemException {
3048 Object[] finderArgs = new Object[] { messageId };
3049
3050 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MESSAGEID,
3051 finderArgs, this);
3052
3053 if (count == null) {
3054 Session session = null;
3055
3056 try {
3057 session = openSession();
3058
3059 StringBundler query = new StringBundler(2);
3060
3061 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3062
3063 query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
3064
3065 String sql = query.toString();
3066
3067 Query q = session.createQuery(sql);
3068
3069 QueryPos qPos = QueryPos.getInstance(q);
3070
3071 qPos.add(messageId);
3072
3073 count = (Long)q.uniqueResult();
3074 }
3075 catch (Exception e) {
3076 throw processException(e);
3077 }
3078 finally {
3079 if (count == null) {
3080 count = Long.valueOf(0);
3081 }
3082
3083 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MESSAGEID,
3084 finderArgs, count);
3085
3086 closeSession(session);
3087 }
3088 }
3089
3090 return count.intValue();
3091 }
3092
3093
3101 public int countByT_F(long threadId, int flag) throws SystemException {
3102 Object[] finderArgs = new Object[] { threadId, flag };
3103
3104 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_F,
3105 finderArgs, this);
3106
3107 if (count == null) {
3108 Session session = null;
3109
3110 try {
3111 session = openSession();
3112
3113 StringBundler query = new StringBundler(3);
3114
3115 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3116
3117 query.append(_FINDER_COLUMN_T_F_THREADID_2);
3118
3119 query.append(_FINDER_COLUMN_T_F_FLAG_2);
3120
3121 String sql = query.toString();
3122
3123 Query q = session.createQuery(sql);
3124
3125 QueryPos qPos = QueryPos.getInstance(q);
3126
3127 qPos.add(threadId);
3128
3129 qPos.add(flag);
3130
3131 count = (Long)q.uniqueResult();
3132 }
3133 catch (Exception e) {
3134 throw processException(e);
3135 }
3136 finally {
3137 if (count == null) {
3138 count = Long.valueOf(0);
3139 }
3140
3141 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_F, finderArgs,
3142 count);
3143
3144 closeSession(session);
3145 }
3146 }
3147
3148 return count.intValue();
3149 }
3150
3151
3159 public int countByM_F(long messageId, int flag) throws SystemException {
3160 Object[] finderArgs = new Object[] { messageId, flag };
3161
3162 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_M_F,
3163 finderArgs, this);
3164
3165 if (count == null) {
3166 Session session = null;
3167
3168 try {
3169 session = openSession();
3170
3171 StringBundler query = new StringBundler(3);
3172
3173 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3174
3175 query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
3176
3177 query.append(_FINDER_COLUMN_M_F_FLAG_2);
3178
3179 String sql = query.toString();
3180
3181 Query q = session.createQuery(sql);
3182
3183 QueryPos qPos = QueryPos.getInstance(q);
3184
3185 qPos.add(messageId);
3186
3187 qPos.add(flag);
3188
3189 count = (Long)q.uniqueResult();
3190 }
3191 catch (Exception e) {
3192 throw processException(e);
3193 }
3194 finally {
3195 if (count == null) {
3196 count = Long.valueOf(0);
3197 }
3198
3199 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_M_F, finderArgs,
3200 count);
3201
3202 closeSession(session);
3203 }
3204 }
3205
3206 return count.intValue();
3207 }
3208
3209
3218 public int countByU_T_F(long userId, long threadId, int flag)
3219 throws SystemException {
3220 Object[] finderArgs = new Object[] { userId, threadId, flag };
3221
3222 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T_F,
3223 finderArgs, this);
3224
3225 if (count == null) {
3226 Session session = null;
3227
3228 try {
3229 session = openSession();
3230
3231 StringBundler query = new StringBundler(4);
3232
3233 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3234
3235 query.append(_FINDER_COLUMN_U_T_F_USERID_2);
3236
3237 query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
3238
3239 query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
3240
3241 String sql = query.toString();
3242
3243 Query q = session.createQuery(sql);
3244
3245 QueryPos qPos = QueryPos.getInstance(q);
3246
3247 qPos.add(userId);
3248
3249 qPos.add(threadId);
3250
3251 qPos.add(flag);
3252
3253 count = (Long)q.uniqueResult();
3254 }
3255 catch (Exception e) {
3256 throw processException(e);
3257 }
3258 finally {
3259 if (count == null) {
3260 count = Long.valueOf(0);
3261 }
3262
3263 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T_F,
3264 finderArgs, count);
3265
3266 closeSession(session);
3267 }
3268 }
3269
3270 return count.intValue();
3271 }
3272
3273
3282 public int countByU_M_F(long userId, long messageId, int flag)
3283 throws SystemException {
3284 Object[] finderArgs = new Object[] { userId, messageId, flag };
3285
3286 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_M_F,
3287 finderArgs, this);
3288
3289 if (count == null) {
3290 Session session = null;
3291
3292 try {
3293 session = openSession();
3294
3295 StringBundler query = new StringBundler(4);
3296
3297 query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3298
3299 query.append(_FINDER_COLUMN_U_M_F_USERID_2);
3300
3301 query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
3302
3303 query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
3304
3305 String sql = query.toString();
3306
3307 Query q = session.createQuery(sql);
3308
3309 QueryPos qPos = QueryPos.getInstance(q);
3310
3311 qPos.add(userId);
3312
3313 qPos.add(messageId);
3314
3315 qPos.add(flag);
3316
3317 count = (Long)q.uniqueResult();
3318 }
3319 catch (Exception e) {
3320 throw processException(e);
3321 }
3322 finally {
3323 if (count == null) {
3324 count = Long.valueOf(0);
3325 }
3326
3327 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_M_F,
3328 finderArgs, count);
3329
3330 closeSession(session);
3331 }
3332 }
3333
3334 return count.intValue();
3335 }
3336
3337
3343 public int countAll() throws SystemException {
3344 Object[] finderArgs = new Object[0];
3345
3346 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3347 finderArgs, this);
3348
3349 if (count == null) {
3350 Session session = null;
3351
3352 try {
3353 session = openSession();
3354
3355 Query q = session.createQuery(_SQL_COUNT_MBMESSAGEFLAG);
3356
3357 count = (Long)q.uniqueResult();
3358 }
3359 catch (Exception e) {
3360 throw processException(e);
3361 }
3362 finally {
3363 if (count == null) {
3364 count = Long.valueOf(0);
3365 }
3366
3367 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3368 count);
3369
3370 closeSession(session);
3371 }
3372 }
3373
3374 return count.intValue();
3375 }
3376
3377
3380 public void afterPropertiesSet() {
3381 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3382 com.liferay.portal.util.PropsUtil.get(
3383 "value.object.listener.com.liferay.portlet.messageboards.model.MBMessageFlag")));
3384
3385 if (listenerClassNames.length > 0) {
3386 try {
3387 List<ModelListener<MBMessageFlag>> listenersList = new ArrayList<ModelListener<MBMessageFlag>>();
3388
3389 for (String listenerClassName : listenerClassNames) {
3390 listenersList.add((ModelListener<MBMessageFlag>)InstanceFactory.newInstance(
3391 listenerClassName));
3392 }
3393
3394 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3395 }
3396 catch (Exception e) {
3397 _log.error(e);
3398 }
3399 }
3400 }
3401
3402 public void destroy() {
3403 EntityCacheUtil.removeCache(MBMessageFlagImpl.class.getName());
3404 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3405 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3406 }
3407
3408 @BeanReference(type = MBBanPersistence.class)
3409 protected MBBanPersistence mbBanPersistence;
3410 @BeanReference(type = MBCategoryPersistence.class)
3411 protected MBCategoryPersistence mbCategoryPersistence;
3412 @BeanReference(type = MBDiscussionPersistence.class)
3413 protected MBDiscussionPersistence mbDiscussionPersistence;
3414 @BeanReference(type = MBMailingListPersistence.class)
3415 protected MBMailingListPersistence mbMailingListPersistence;
3416 @BeanReference(type = MBMessagePersistence.class)
3417 protected MBMessagePersistence mbMessagePersistence;
3418 @BeanReference(type = MBMessageFlagPersistence.class)
3419 protected MBMessageFlagPersistence mbMessageFlagPersistence;
3420 @BeanReference(type = MBStatsUserPersistence.class)
3421 protected MBStatsUserPersistence mbStatsUserPersistence;
3422 @BeanReference(type = MBThreadPersistence.class)
3423 protected MBThreadPersistence mbThreadPersistence;
3424 @BeanReference(type = ResourcePersistence.class)
3425 protected ResourcePersistence resourcePersistence;
3426 @BeanReference(type = UserPersistence.class)
3427 protected UserPersistence userPersistence;
3428 private static final String _SQL_SELECT_MBMESSAGEFLAG = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag";
3429 private static final String _SQL_SELECT_MBMESSAGEFLAG_WHERE = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag WHERE ";
3430 private static final String _SQL_COUNT_MBMESSAGEFLAG = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag";
3431 private static final String _SQL_COUNT_MBMESSAGEFLAG_WHERE = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag WHERE ";
3432 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessageFlag.userId = ?";
3433 private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessageFlag.threadId = ?";
3434 private static final String _FINDER_COLUMN_MESSAGEID_MESSAGEID_2 = "mbMessageFlag.messageId = ?";
3435 private static final String _FINDER_COLUMN_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
3436 private static final String _FINDER_COLUMN_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
3437 private static final String _FINDER_COLUMN_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
3438 private static final String _FINDER_COLUMN_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
3439 private static final String _FINDER_COLUMN_U_T_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
3440 private static final String _FINDER_COLUMN_U_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
3441 private static final String _FINDER_COLUMN_U_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
3442 private static final String _FINDER_COLUMN_U_M_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
3443 private static final String _FINDER_COLUMN_U_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
3444 private static final String _FINDER_COLUMN_U_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
3445 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessageFlag.";
3446 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessageFlag exists with the primary key ";
3447 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessageFlag exists with the key {";
3448 private static Log _log = LogFactoryUtil.getLog(MBMessageFlagPersistenceImpl.class);
3449 }