1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.messageboards.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
21  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderPath;
23  import com.liferay.portal.kernel.dao.orm.Query;
24  import com.liferay.portal.kernel.dao.orm.QueryPos;
25  import com.liferay.portal.kernel.dao.orm.QueryUtil;
26  import com.liferay.portal.kernel.dao.orm.Session;
27  import com.liferay.portal.kernel.exception.SystemException;
28  import com.liferay.portal.kernel.log.Log;
29  import com.liferay.portal.kernel.log.LogFactoryUtil;
30  import com.liferay.portal.kernel.util.GetterUtil;
31  import com.liferay.portal.kernel.util.InstanceFactory;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.ModelListener;
37  import com.liferay.portal.service.persistence.BatchSessionUtil;
38  import com.liferay.portal.service.persistence.ResourcePersistence;
39  import com.liferay.portal.service.persistence.UserPersistence;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.messageboards.NoSuchMessageFlagException;
43  import com.liferay.portlet.messageboards.model.MBMessageFlag;
44  import com.liferay.portlet.messageboards.model.impl.MBMessageFlagImpl;
45  import com.liferay.portlet.messageboards.model.impl.MBMessageFlagModelImpl;
46  
47  import java.io.Serializable;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.List;
52  
53  /**
54   * <a href="MBMessageFlagPersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * <p>
57   * ServiceBuilder generated this class. Modifications in this class will be
58   * overwritten the next time is generated.
59   * </p>
60   *
61   * @author    Brian Wing Shun Chan
62   * @see       MBMessageFlagPersistence
63   * @see       MBMessageFlagUtil
64   * @generated
65   */
66  public class MBMessageFlagPersistenceImpl extends BasePersistenceImpl<MBMessageFlag>
67      implements MBMessageFlagPersistence {
68      public static final String FINDER_CLASS_NAME_ENTITY = MBMessageFlagImpl.class.getName();
69      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70          ".List";
71      public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
72              MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
73              FINDER_CLASS_NAME_LIST, "findByUserId",
74              new String[] {
75                  Long.class.getName(),
76                  
77              "java.lang.Integer", "java.lang.Integer",
78                  "com.liferay.portal.kernel.util.OrderByComparator"
79              });
80      public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
81              MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
82              FINDER_CLASS_NAME_LIST, "countByUserId",
83              new String[] { Long.class.getName() });
84      public static final FinderPath FINDER_PATH_FIND_BY_THREADID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
85              MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
86              FINDER_CLASS_NAME_LIST, "findByThreadId",
87              new String[] {
88                  Long.class.getName(),
89                  
90              "java.lang.Integer", "java.lang.Integer",
91                  "com.liferay.portal.kernel.util.OrderByComparator"
92              });
93      public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
94              MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
95              FINDER_CLASS_NAME_LIST, "countByThreadId",
96              new String[] { Long.class.getName() });
97      public static final FinderPath FINDER_PATH_FIND_BY_MESSAGEID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
98              MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
99              FINDER_CLASS_NAME_LIST, "findByMessageId",
100             new String[] {
101                 Long.class.getName(),
102                 
103             "java.lang.Integer", "java.lang.Integer",
104                 "com.liferay.portal.kernel.util.OrderByComparator"
105             });
106     public static final FinderPath FINDER_PATH_COUNT_BY_MESSAGEID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
107             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
108             FINDER_CLASS_NAME_LIST, "countByMessageId",
109             new String[] { Long.class.getName() });
110     public static final FinderPath FINDER_PATH_FIND_BY_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
111             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
112             FINDER_CLASS_NAME_LIST, "findByT_F",
113             new String[] {
114                 Long.class.getName(), Integer.class.getName(),
115                 
116             "java.lang.Integer", "java.lang.Integer",
117                 "com.liferay.portal.kernel.util.OrderByComparator"
118             });
119     public static final FinderPath FINDER_PATH_COUNT_BY_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
120             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
121             FINDER_CLASS_NAME_LIST, "countByT_F",
122             new String[] { Long.class.getName(), Integer.class.getName() });
123     public static final FinderPath FINDER_PATH_FIND_BY_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
124             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
125             FINDER_CLASS_NAME_LIST, "findByM_F",
126             new String[] {
127                 Long.class.getName(), Integer.class.getName(),
128                 
129             "java.lang.Integer", "java.lang.Integer",
130                 "com.liferay.portal.kernel.util.OrderByComparator"
131             });
132     public static final FinderPath FINDER_PATH_COUNT_BY_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
133             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
134             FINDER_CLASS_NAME_LIST, "countByM_F",
135             new String[] { Long.class.getName(), Integer.class.getName() });
136     public static final FinderPath FINDER_PATH_FIND_BY_U_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
137             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
138             FINDER_CLASS_NAME_LIST, "findByU_T_F",
139             new String[] {
140                 Long.class.getName(), Long.class.getName(),
141                 Integer.class.getName(),
142                 
143             "java.lang.Integer", "java.lang.Integer",
144                 "com.liferay.portal.kernel.util.OrderByComparator"
145             });
146     public static final FinderPath FINDER_PATH_COUNT_BY_U_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
147             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
148             FINDER_CLASS_NAME_LIST, "countByU_T_F",
149             new String[] {
150                 Long.class.getName(), Long.class.getName(),
151                 Integer.class.getName()
152             });
153     public static final FinderPath FINDER_PATH_FETCH_BY_U_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
154             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
155             FINDER_CLASS_NAME_ENTITY, "fetchByU_M_F",
156             new String[] {
157                 Long.class.getName(), Long.class.getName(),
158                 Integer.class.getName()
159             });
160     public static final FinderPath FINDER_PATH_COUNT_BY_U_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
161             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
162             FINDER_CLASS_NAME_LIST, "countByU_M_F",
163             new String[] {
164                 Long.class.getName(), Long.class.getName(),
165                 Integer.class.getName()
166             });
167     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
168             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
169             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
170     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
171             MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
172             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
173 
174     public void cacheResult(MBMessageFlag mbMessageFlag) {
175         EntityCacheUtil.putResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
176             MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
177             mbMessageFlag);
178 
179         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
180             new Object[] {
181                 new Long(mbMessageFlag.getUserId()),
182                 new Long(mbMessageFlag.getMessageId()),
183                 new Integer(mbMessageFlag.getFlag())
184             }, mbMessageFlag);
185     }
186 
187     public void cacheResult(List<MBMessageFlag> mbMessageFlags) {
188         for (MBMessageFlag mbMessageFlag : mbMessageFlags) {
189             if (EntityCacheUtil.getResult(
190                         MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
191                         MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
192                         this) == null) {
193                 cacheResult(mbMessageFlag);
194             }
195         }
196     }
197 
198     public void clearCache() {
199         CacheRegistry.clear(MBMessageFlagImpl.class.getName());
200         EntityCacheUtil.clearCache(MBMessageFlagImpl.class.getName());
201         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
202         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
203     }
204 
205     public void clearCache(MBMessageFlag mbMessageFlag) {
206         EntityCacheUtil.removeResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
207             MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey());
208 
209         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
210             new Object[] {
211                 new Long(mbMessageFlag.getUserId()),
212                 new Long(mbMessageFlag.getMessageId()),
213                 new Integer(mbMessageFlag.getFlag())
214             });
215     }
216 
217     public MBMessageFlag create(long messageFlagId) {
218         MBMessageFlag mbMessageFlag = new MBMessageFlagImpl();
219 
220         mbMessageFlag.setNew(true);
221         mbMessageFlag.setPrimaryKey(messageFlagId);
222 
223         return mbMessageFlag;
224     }
225 
226     public MBMessageFlag remove(Serializable primaryKey)
227         throws NoSuchModelException, SystemException {
228         return remove(((Long)primaryKey).longValue());
229     }
230 
231     public MBMessageFlag remove(long messageFlagId)
232         throws NoSuchMessageFlagException, SystemException {
233         Session session = null;
234 
235         try {
236             session = openSession();
237 
238             MBMessageFlag mbMessageFlag = (MBMessageFlag)session.get(MBMessageFlagImpl.class,
239                     new Long(messageFlagId));
240 
241             if (mbMessageFlag == null) {
242                 if (_log.isWarnEnabled()) {
243                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageFlagId);
244                 }
245 
246                 throw new NoSuchMessageFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
247                     messageFlagId);
248             }
249 
250             return remove(mbMessageFlag);
251         }
252         catch (NoSuchMessageFlagException nsee) {
253             throw nsee;
254         }
255         catch (Exception e) {
256             throw processException(e);
257         }
258         finally {
259             closeSession(session);
260         }
261     }
262 
263     public MBMessageFlag remove(MBMessageFlag mbMessageFlag)
264         throws SystemException {
265         for (ModelListener<MBMessageFlag> listener : listeners) {
266             listener.onBeforeRemove(mbMessageFlag);
267         }
268 
269         mbMessageFlag = removeImpl(mbMessageFlag);
270 
271         for (ModelListener<MBMessageFlag> listener : listeners) {
272             listener.onAfterRemove(mbMessageFlag);
273         }
274 
275         return mbMessageFlag;
276     }
277 
278     protected MBMessageFlag removeImpl(MBMessageFlag mbMessageFlag)
279         throws SystemException {
280         mbMessageFlag = toUnwrappedModel(mbMessageFlag);
281 
282         Session session = null;
283 
284         try {
285             session = openSession();
286 
287             if (mbMessageFlag.isCachedModel() || BatchSessionUtil.isEnabled()) {
288                 Object staleObject = session.get(MBMessageFlagImpl.class,
289                         mbMessageFlag.getPrimaryKeyObj());
290 
291                 if (staleObject != null) {
292                     session.evict(staleObject);
293                 }
294             }
295 
296             session.delete(mbMessageFlag);
297 
298             session.flush();
299         }
300         catch (Exception e) {
301             throw processException(e);
302         }
303         finally {
304             closeSession(session);
305         }
306 
307         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
308 
309         MBMessageFlagModelImpl mbMessageFlagModelImpl = (MBMessageFlagModelImpl)mbMessageFlag;
310 
311         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
312             new Object[] {
313                 new Long(mbMessageFlagModelImpl.getOriginalUserId()),
314                 new Long(mbMessageFlagModelImpl.getOriginalMessageId()),
315                 new Integer(mbMessageFlagModelImpl.getOriginalFlag())
316             });
317 
318         EntityCacheUtil.removeResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
319             MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey());
320 
321         return mbMessageFlag;
322     }
323 
324     public MBMessageFlag updateImpl(
325         com.liferay.portlet.messageboards.model.MBMessageFlag mbMessageFlag,
326         boolean merge) throws SystemException {
327         mbMessageFlag = toUnwrappedModel(mbMessageFlag);
328 
329         boolean isNew = mbMessageFlag.isNew();
330 
331         MBMessageFlagModelImpl mbMessageFlagModelImpl = (MBMessageFlagModelImpl)mbMessageFlag;
332 
333         Session session = null;
334 
335         try {
336             session = openSession();
337 
338             BatchSessionUtil.update(session, mbMessageFlag, merge);
339 
340             mbMessageFlag.setNew(false);
341         }
342         catch (Exception e) {
343             throw processException(e);
344         }
345         finally {
346             closeSession(session);
347         }
348 
349         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
350 
351         EntityCacheUtil.putResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
352             MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
353             mbMessageFlag);
354 
355         if (!isNew &&
356                 ((mbMessageFlag.getUserId() != mbMessageFlagModelImpl.getOriginalUserId()) ||
357                 (mbMessageFlag.getMessageId() != mbMessageFlagModelImpl.getOriginalMessageId()) ||
358                 (mbMessageFlag.getFlag() != mbMessageFlagModelImpl.getOriginalFlag()))) {
359             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
360                 new Object[] {
361                     new Long(mbMessageFlagModelImpl.getOriginalUserId()),
362                     new Long(mbMessageFlagModelImpl.getOriginalMessageId()),
363                     new Integer(mbMessageFlagModelImpl.getOriginalFlag())
364                 });
365         }
366 
367         if (isNew ||
368                 ((mbMessageFlag.getUserId() != mbMessageFlagModelImpl.getOriginalUserId()) ||
369                 (mbMessageFlag.getMessageId() != mbMessageFlagModelImpl.getOriginalMessageId()) ||
370                 (mbMessageFlag.getFlag() != mbMessageFlagModelImpl.getOriginalFlag()))) {
371             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
372                 new Object[] {
373                     new Long(mbMessageFlag.getUserId()),
374                     new Long(mbMessageFlag.getMessageId()),
375                     new Integer(mbMessageFlag.getFlag())
376                 }, mbMessageFlag);
377         }
378 
379         return mbMessageFlag;
380     }
381 
382     protected MBMessageFlag toUnwrappedModel(MBMessageFlag mbMessageFlag) {
383         if (mbMessageFlag instanceof MBMessageFlagImpl) {
384             return mbMessageFlag;
385         }
386 
387         MBMessageFlagImpl mbMessageFlagImpl = new MBMessageFlagImpl();
388 
389         mbMessageFlagImpl.setNew(mbMessageFlag.isNew());
390         mbMessageFlagImpl.setPrimaryKey(mbMessageFlag.getPrimaryKey());
391 
392         mbMessageFlagImpl.setMessageFlagId(mbMessageFlag.getMessageFlagId());
393         mbMessageFlagImpl.setUserId(mbMessageFlag.getUserId());
394         mbMessageFlagImpl.setModifiedDate(mbMessageFlag.getModifiedDate());
395         mbMessageFlagImpl.setThreadId(mbMessageFlag.getThreadId());
396         mbMessageFlagImpl.setMessageId(mbMessageFlag.getMessageId());
397         mbMessageFlagImpl.setFlag(mbMessageFlag.getFlag());
398 
399         return mbMessageFlagImpl;
400     }
401 
402     public MBMessageFlag findByPrimaryKey(Serializable primaryKey)
403         throws NoSuchModelException, SystemException {
404         return findByPrimaryKey(((Long)primaryKey).longValue());
405     }
406 
407     public MBMessageFlag findByPrimaryKey(long messageFlagId)
408         throws NoSuchMessageFlagException, SystemException {
409         MBMessageFlag mbMessageFlag = fetchByPrimaryKey(messageFlagId);
410 
411         if (mbMessageFlag == null) {
412             if (_log.isWarnEnabled()) {
413                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageFlagId);
414             }
415 
416             throw new NoSuchMessageFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
417                 messageFlagId);
418         }
419 
420         return mbMessageFlag;
421     }
422 
423     public MBMessageFlag fetchByPrimaryKey(Serializable primaryKey)
424         throws SystemException {
425         return fetchByPrimaryKey(((Long)primaryKey).longValue());
426     }
427 
428     public MBMessageFlag fetchByPrimaryKey(long messageFlagId)
429         throws SystemException {
430         MBMessageFlag mbMessageFlag = (MBMessageFlag)EntityCacheUtil.getResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
431                 MBMessageFlagImpl.class, messageFlagId, this);
432 
433         if (mbMessageFlag == null) {
434             Session session = null;
435 
436             try {
437                 session = openSession();
438 
439                 mbMessageFlag = (MBMessageFlag)session.get(MBMessageFlagImpl.class,
440                         new Long(messageFlagId));
441             }
442             catch (Exception e) {
443                 throw processException(e);
444             }
445             finally {
446                 if (mbMessageFlag != null) {
447                     cacheResult(mbMessageFlag);
448                 }
449 
450                 closeSession(session);
451             }
452         }
453 
454         return mbMessageFlag;
455     }
456 
457     public List<MBMessageFlag> findByUserId(long userId)
458         throws SystemException {
459         return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
460     }
461 
462     public List<MBMessageFlag> findByUserId(long userId, int start, int end)
463         throws SystemException {
464         return findByUserId(userId, start, end, null);
465     }
466 
467     public List<MBMessageFlag> findByUserId(long userId, int start, int end,
468         OrderByComparator orderByComparator) throws SystemException {
469         Object[] finderArgs = new Object[] {
470                 new Long(userId),
471                 
472                 String.valueOf(start), String.valueOf(end),
473                 String.valueOf(orderByComparator)
474             };
475 
476         List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
477                 finderArgs, this);
478 
479         if (list == null) {
480             Session session = null;
481 
482             try {
483                 session = openSession();
484 
485                 StringBundler query = null;
486 
487                 if (orderByComparator != null) {
488                     query = new StringBundler(3 +
489                             (orderByComparator.getOrderByFields().length * 3));
490                 }
491                 else {
492                     query = new StringBundler(2);
493                 }
494 
495                 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
496 
497                 query.append(_FINDER_COLUMN_USERID_USERID_2);
498 
499                 if (orderByComparator != null) {
500                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
501                         orderByComparator);
502                 }
503 
504                 String sql = query.toString();
505 
506                 Query q = session.createQuery(sql);
507 
508                 QueryPos qPos = QueryPos.getInstance(q);
509 
510                 qPos.add(userId);
511 
512                 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
513                         start, end);
514             }
515             catch (Exception e) {
516                 throw processException(e);
517             }
518             finally {
519                 if (list == null) {
520                     list = new ArrayList<MBMessageFlag>();
521                 }
522 
523                 cacheResult(list);
524 
525                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
526                     finderArgs, list);
527 
528                 closeSession(session);
529             }
530         }
531 
532         return list;
533     }
534 
535     public MBMessageFlag findByUserId_First(long userId,
536         OrderByComparator orderByComparator)
537         throws NoSuchMessageFlagException, SystemException {
538         List<MBMessageFlag> list = findByUserId(userId, 0, 1, orderByComparator);
539 
540         if (list.isEmpty()) {
541             StringBundler msg = new StringBundler(4);
542 
543             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
544 
545             msg.append("userId=");
546             msg.append(userId);
547 
548             msg.append(StringPool.CLOSE_CURLY_BRACE);
549 
550             throw new NoSuchMessageFlagException(msg.toString());
551         }
552         else {
553             return list.get(0);
554         }
555     }
556 
557     public MBMessageFlag findByUserId_Last(long userId,
558         OrderByComparator orderByComparator)
559         throws NoSuchMessageFlagException, SystemException {
560         int count = countByUserId(userId);
561 
562         List<MBMessageFlag> list = findByUserId(userId, count - 1, count,
563                 orderByComparator);
564 
565         if (list.isEmpty()) {
566             StringBundler msg = new StringBundler(4);
567 
568             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
569 
570             msg.append("userId=");
571             msg.append(userId);
572 
573             msg.append(StringPool.CLOSE_CURLY_BRACE);
574 
575             throw new NoSuchMessageFlagException(msg.toString());
576         }
577         else {
578             return list.get(0);
579         }
580     }
581 
582     public MBMessageFlag[] findByUserId_PrevAndNext(long messageFlagId,
583         long userId, OrderByComparator orderByComparator)
584         throws NoSuchMessageFlagException, SystemException {
585         MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
586 
587         Session session = null;
588 
589         try {
590             session = openSession();
591 
592             MBMessageFlag[] array = new MBMessageFlagImpl[3];
593 
594             array[0] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
595                     orderByComparator, true);
596 
597             array[1] = mbMessageFlag;
598 
599             array[2] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
600                     orderByComparator, false);
601 
602             return array;
603         }
604         catch (Exception e) {
605             throw processException(e);
606         }
607         finally {
608             closeSession(session);
609         }
610     }
611 
612     protected MBMessageFlag getByUserId_PrevAndNext(Session session,
613         MBMessageFlag mbMessageFlag, long userId,
614         OrderByComparator orderByComparator, boolean previous) {
615         StringBundler query = null;
616 
617         if (orderByComparator != null) {
618             query = new StringBundler(6 +
619                     (orderByComparator.getOrderByFields().length * 6));
620         }
621         else {
622             query = new StringBundler(3);
623         }
624 
625         query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
626 
627         query.append(_FINDER_COLUMN_USERID_USERID_2);
628 
629         if (orderByComparator != null) {
630             String[] orderByFields = orderByComparator.getOrderByFields();
631 
632             if (orderByFields.length > 0) {
633                 query.append(WHERE_AND);
634             }
635 
636             for (int i = 0; i < orderByFields.length; i++) {
637                 query.append(_ORDER_BY_ENTITY_ALIAS);
638                 query.append(orderByFields[i]);
639 
640                 if ((i + 1) < orderByFields.length) {
641                     if (orderByComparator.isAscending() ^ previous) {
642                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
643                     }
644                     else {
645                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
646                     }
647                 }
648                 else {
649                     if (orderByComparator.isAscending() ^ previous) {
650                         query.append(WHERE_GREATER_THAN);
651                     }
652                     else {
653                         query.append(WHERE_LESSER_THAN);
654                     }
655                 }
656             }
657 
658             query.append(ORDER_BY_CLAUSE);
659 
660             for (int i = 0; i < orderByFields.length; i++) {
661                 query.append(_ORDER_BY_ENTITY_ALIAS);
662                 query.append(orderByFields[i]);
663 
664                 if ((i + 1) < orderByFields.length) {
665                     if (orderByComparator.isAscending() ^ previous) {
666                         query.append(ORDER_BY_ASC_HAS_NEXT);
667                     }
668                     else {
669                         query.append(ORDER_BY_DESC_HAS_NEXT);
670                     }
671                 }
672                 else {
673                     if (orderByComparator.isAscending() ^ previous) {
674                         query.append(ORDER_BY_ASC);
675                     }
676                     else {
677                         query.append(ORDER_BY_DESC);
678                     }
679                 }
680             }
681         }
682 
683         String sql = query.toString();
684 
685         Query q = session.createQuery(sql);
686 
687         q.setFirstResult(0);
688         q.setMaxResults(2);
689 
690         QueryPos qPos = QueryPos.getInstance(q);
691 
692         qPos.add(userId);
693 
694         if (orderByComparator != null) {
695             Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
696 
697             for (Object value : values) {
698                 qPos.add(value);
699             }
700         }
701 
702         List<MBMessageFlag> list = q.list();
703 
704         if (list.size() == 2) {
705             return list.get(1);
706         }
707         else {
708             return null;
709         }
710     }
711 
712     public List<MBMessageFlag> findByThreadId(long threadId)
713         throws SystemException {
714         return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
715             null);
716     }
717 
718     public List<MBMessageFlag> findByThreadId(long threadId, int start, int end)
719         throws SystemException {
720         return findByThreadId(threadId, start, end, null);
721     }
722 
723     public List<MBMessageFlag> findByThreadId(long threadId, int start,
724         int end, OrderByComparator orderByComparator) throws SystemException {
725         Object[] finderArgs = new Object[] {
726                 new Long(threadId),
727                 
728                 String.valueOf(start), String.valueOf(end),
729                 String.valueOf(orderByComparator)
730             };
731 
732         List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
733                 finderArgs, this);
734 
735         if (list == null) {
736             Session session = null;
737 
738             try {
739                 session = openSession();
740 
741                 StringBundler query = null;
742 
743                 if (orderByComparator != null) {
744                     query = new StringBundler(3 +
745                             (orderByComparator.getOrderByFields().length * 3));
746                 }
747                 else {
748                     query = new StringBundler(2);
749                 }
750 
751                 query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
752 
753                 query.append(_FINDER_COLUMN_THREADID_THREADID_2);
754 
755                 if (orderByComparator != null) {
756                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
757                         orderByComparator);
758                 }
759 
760                 String sql = query.toString();
761 
762                 Query q = session.createQuery(sql);
763 
764                 QueryPos qPos = QueryPos.getInstance(q);
765 
766                 qPos.add(threadId);
767 
768                 list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
769                         start, end);
770             }
771             catch (Exception e) {
772                 throw processException(e);
773             }
774             finally {
775                 if (list == null) {
776                     list = new ArrayList<MBMessageFlag>();
777                 }
778 
779                 cacheResult(list);
780 
781                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
782                     finderArgs, list);
783 
784                 closeSession(session);
785             }
786         }
787 
788         return list;
789     }
790 
791     public MBMessageFlag findByThreadId_First(long threadId,
792         OrderByComparator orderByComparator)
793         throws NoSuchMessageFlagException, SystemException {
794         List<MBMessageFlag> list = findByThreadId(threadId, 0, 1,
795                 orderByComparator);
796 
797         if (list.isEmpty()) {
798             StringBundler msg = new StringBundler(4);
799 
800             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
801 
802             msg.append("threadId=");
803             msg.append(threadId);
804 
805             msg.append(StringPool.CLOSE_CURLY_BRACE);
806 
807             throw new NoSuchMessageFlagException(msg.toString());
808         }
809         else {
810             return list.get(0);
811         }
812     }
813 
814     public MBMessageFlag findByThreadId_Last(long threadId,
815         OrderByComparator orderByComparator)
816         throws NoSuchMessageFlagException, SystemException {
817         int count = countByThreadId(threadId);
818 
819         List<MBMessageFlag> list = findByThreadId(threadId, count - 1, count,
820                 orderByComparator);
821 
822         if (list.isEmpty()) {
823             StringBundler msg = new StringBundler(4);
824 
825             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
826 
827             msg.append("threadId=");
828             msg.append(threadId);
829 
830             msg.append(StringPool.CLOSE_CURLY_BRACE);
831 
832             throw new NoSuchMessageFlagException(msg.toString());
833         }
834         else {
835             return list.get(0);
836         }
837     }
838 
839     public MBMessageFlag[] findByThreadId_PrevAndNext(long messageFlagId,
840         long threadId, OrderByComparator orderByComparator)
841         throws NoSuchMessageFlagException, SystemException {
842         MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
843 
844         Session session = null;
845 
846         try {
847             session = openSession();
848 
849             MBMessageFlag[] array = new MBMessageFlagImpl[3];
850 
851             array[0] = getByThreadId_PrevAndNext(session, mbMessageFlag,
852                     threadId, orderByComparator, true);
853 
854             array[1] = mbMessageFlag;
855 
856             array[2] = getByThreadId_PrevAndNext(session, mbMessageFlag,
857                     threadId, orderByComparator, false);
858 
859             return array;
860         }
861         catch (Exception e) {
862             throw processException(e);
863         }
864         finally {
865             closeSession(session);
866         }
867     }
868 
869     protected MBMessageFlag getByThreadId_PrevAndNext(Session session,
870         MBMessageFlag mbMessageFlag, long threadId,
871         OrderByComparator orderByComparator, boolean previous) {
872         StringBundler query = null;
873 
874         if (orderByComparator != null) {
875             query = new StringBundler(6 +
876                     (orderByComparator.getOrderByFields().length * 6));
877         }
878         else {
879             query = new StringBundler(3);
880         }
881 
882         query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
883 
884         query.append(_FINDER_COLUMN_THREADID_THREADID_2);
885 
886         if (orderByComparator != null) {
887             String[] orderByFields = orderByComparator.getOrderByFields();
888 
889             if (orderByFields.length > 0) {
890                 query.append(WHERE_AND);
891             }
892 
893             for (int i = 0; i < orderByFields.length; i++) {
894                 query.append(_ORDER_BY_ENTITY_ALIAS);
895                 query.append(orderByFields[i]);
896 
897                 if ((i + 1) < orderByFields.length) {
898                     if (orderByComparator.isAscending() ^ previous) {
899                         query.append(WHERE_GREATER_THAN_HAS_NEXT);
900                     }
901                     else {
902                         query.append(WHERE_LESSER_THAN_HAS_NEXT);
903                     }
904                 }
905                 else {
906                     if (orderByComparator.isAscending() ^ previous) {
907                         query.append(WHERE_GREATER_THAN);
908                     }
909                     else {
910                         query.append(WHERE_LESSER_THAN);
911                     }
912                 }
913             }
914 
915             query.append(ORDER_BY_CLAUSE);
916 
917             for (int i = 0; i < orderByFields.length; i++) {
918                 query.append(_ORDER_BY_ENTITY_ALIAS);
919                 query.append(orderByFields[i]);
920 
921                 if ((i + 1) < orderByFields.length) {
922                     if (orderByComparator.isAscending() ^ previous) {
923                         query.append(ORDER_BY_ASC_HAS_NEXT);
924                     }
925                     else {
926                         query.append(ORDER_BY_DESC_HAS_NEXT);
927                     }
928                 }
929                 else {
930                     if (orderByComparator.isAscending() ^ previous) {
931                         query.append(ORDER_BY_ASC);
932                     }
933                     else {
934                         query.append(ORDER_BY_DESC);
935                     }
936                 }
937             }
938         }
939 
940         String sql = query.toString();
941 
942         Query q = session.createQuery(sql);
943 
944         q.setFirstResult(0);
945         q.setMaxResults(2);
946 
947         QueryPos qPos = QueryPos.getInstance(q);
948 
949         qPos.add(threadId);
950 
951         if (orderByComparator != null) {
952             Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
953 
954             for (Object value : values) {
955                 qPos.add(value);
956             }
957         }
958 
959         List<MBMessageFlag> list = q.list();
960 
961         if (list.size() == 2) {
962             return list.get(1);
963         }
964         else {
965             return null;
966         }
967     }
968 
969     public List<MBMessageFlag> findByMessageId(long messageId)
970         throws SystemException {
971         return findByMessageId(messageId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
972             null);
973     }
974 
975     public List<MBMessageFlag> findByMessageId(long messageId, int start,
976         int end) throws SystemException {
977         return findByMessageId(messageId, start, end, null);
978     }
979 
980     public List<MBMessageFlag> findByMessageId(long messageId, int start,
981         int end, OrderByComparator orderByComparator) throws SystemException {
982         Object[] finderArgs = new Object[] {
983                 new Long(messageId),
984                 
985                 String.valueOf(start), String.valueOf(end),
986                 String.valueOf(orderByComparator)
987             };
988 
989         List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_MESSAGEID,
990                 finderArgs, this);
991 
992         if (list == null) {
993             Session session = null;
994 
995             try {
996                 session = openSession();
997 
998                 StringBundler query = null;
999 
1000                if (orderByComparator != null) {
1001                    query = new StringBundler(3 +
1002                            (orderByComparator.getOrderByFields().length * 3));
1003                }
1004                else {
1005                    query = new StringBundler(2);
1006                }
1007
1008                query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1009
1010                query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1011
1012                if (orderByComparator != null) {
1013                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1014                        orderByComparator);
1015                }
1016
1017                String sql = query.toString();
1018
1019                Query q = session.createQuery(sql);
1020
1021                QueryPos qPos = QueryPos.getInstance(q);
1022
1023                qPos.add(messageId);
1024
1025                list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1026                        start, end);
1027            }
1028            catch (Exception e) {
1029                throw processException(e);
1030            }
1031            finally {
1032                if (list == null) {
1033                    list = new ArrayList<MBMessageFlag>();
1034                }
1035
1036                cacheResult(list);
1037
1038                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_MESSAGEID,
1039                    finderArgs, list);
1040
1041                closeSession(session);
1042            }
1043        }
1044
1045        return list;
1046    }
1047
1048    public MBMessageFlag findByMessageId_First(long messageId,
1049        OrderByComparator orderByComparator)
1050        throws NoSuchMessageFlagException, SystemException {
1051        List<MBMessageFlag> list = findByMessageId(messageId, 0, 1,
1052                orderByComparator);
1053
1054        if (list.isEmpty()) {
1055            StringBundler msg = new StringBundler(4);
1056
1057            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1058
1059            msg.append("messageId=");
1060            msg.append(messageId);
1061
1062            msg.append(StringPool.CLOSE_CURLY_BRACE);
1063
1064            throw new NoSuchMessageFlagException(msg.toString());
1065        }
1066        else {
1067            return list.get(0);
1068        }
1069    }
1070
1071    public MBMessageFlag findByMessageId_Last(long messageId,
1072        OrderByComparator orderByComparator)
1073        throws NoSuchMessageFlagException, SystemException {
1074        int count = countByMessageId(messageId);
1075
1076        List<MBMessageFlag> list = findByMessageId(messageId, count - 1, count,
1077                orderByComparator);
1078
1079        if (list.isEmpty()) {
1080            StringBundler msg = new StringBundler(4);
1081
1082            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1083
1084            msg.append("messageId=");
1085            msg.append(messageId);
1086
1087            msg.append(StringPool.CLOSE_CURLY_BRACE);
1088
1089            throw new NoSuchMessageFlagException(msg.toString());
1090        }
1091        else {
1092            return list.get(0);
1093        }
1094    }
1095
1096    public MBMessageFlag[] findByMessageId_PrevAndNext(long messageFlagId,
1097        long messageId, OrderByComparator orderByComparator)
1098        throws NoSuchMessageFlagException, SystemException {
1099        MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1100
1101        Session session = null;
1102
1103        try {
1104            session = openSession();
1105
1106            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1107
1108            array[0] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1109                    messageId, orderByComparator, true);
1110
1111            array[1] = mbMessageFlag;
1112
1113            array[2] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1114                    messageId, orderByComparator, false);
1115
1116            return array;
1117        }
1118        catch (Exception e) {
1119            throw processException(e);
1120        }
1121        finally {
1122            closeSession(session);
1123        }
1124    }
1125
1126    protected MBMessageFlag getByMessageId_PrevAndNext(Session session,
1127        MBMessageFlag mbMessageFlag, long messageId,
1128        OrderByComparator orderByComparator, boolean previous) {
1129        StringBundler query = null;
1130
1131        if (orderByComparator != null) {
1132            query = new StringBundler(6 +
1133                    (orderByComparator.getOrderByFields().length * 6));
1134        }
1135        else {
1136            query = new StringBundler(3);
1137        }
1138
1139        query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1140
1141        query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1142
1143        if (orderByComparator != null) {
1144            String[] orderByFields = orderByComparator.getOrderByFields();
1145
1146            if (orderByFields.length > 0) {
1147                query.append(WHERE_AND);
1148            }
1149
1150            for (int i = 0; i < orderByFields.length; i++) {
1151                query.append(_ORDER_BY_ENTITY_ALIAS);
1152                query.append(orderByFields[i]);
1153
1154                if ((i + 1) < orderByFields.length) {
1155                    if (orderByComparator.isAscending() ^ previous) {
1156                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1157                    }
1158                    else {
1159                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1160                    }
1161                }
1162                else {
1163                    if (orderByComparator.isAscending() ^ previous) {
1164                        query.append(WHERE_GREATER_THAN);
1165                    }
1166                    else {
1167                        query.append(WHERE_LESSER_THAN);
1168                    }
1169                }
1170            }
1171
1172            query.append(ORDER_BY_CLAUSE);
1173
1174            for (int i = 0; i < orderByFields.length; i++) {
1175                query.append(_ORDER_BY_ENTITY_ALIAS);
1176                query.append(orderByFields[i]);
1177
1178                if ((i + 1) < orderByFields.length) {
1179                    if (orderByComparator.isAscending() ^ previous) {
1180                        query.append(ORDER_BY_ASC_HAS_NEXT);
1181                    }
1182                    else {
1183                        query.append(ORDER_BY_DESC_HAS_NEXT);
1184                    }
1185                }
1186                else {
1187                    if (orderByComparator.isAscending() ^ previous) {
1188                        query.append(ORDER_BY_ASC);
1189                    }
1190                    else {
1191                        query.append(ORDER_BY_DESC);
1192                    }
1193                }
1194            }
1195        }
1196
1197        String sql = query.toString();
1198
1199        Query q = session.createQuery(sql);
1200
1201        q.setFirstResult(0);
1202        q.setMaxResults(2);
1203
1204        QueryPos qPos = QueryPos.getInstance(q);
1205
1206        qPos.add(messageId);
1207
1208        if (orderByComparator != null) {
1209            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1210
1211            for (Object value : values) {
1212                qPos.add(value);
1213            }
1214        }
1215
1216        List<MBMessageFlag> list = q.list();
1217
1218        if (list.size() == 2) {
1219            return list.get(1);
1220        }
1221        else {
1222            return null;
1223        }
1224    }
1225
1226    public List<MBMessageFlag> findByT_F(long threadId, int flag)
1227        throws SystemException {
1228        return findByT_F(threadId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1229            null);
1230    }
1231
1232    public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1233        int end) throws SystemException {
1234        return findByT_F(threadId, flag, start, end, null);
1235    }
1236
1237    public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1238        int end, OrderByComparator orderByComparator) throws SystemException {
1239        Object[] finderArgs = new Object[] {
1240                new Long(threadId), new Integer(flag),
1241                
1242                String.valueOf(start), String.valueOf(end),
1243                String.valueOf(orderByComparator)
1244            };
1245
1246        List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_F,
1247                finderArgs, this);
1248
1249        if (list == null) {
1250            Session session = null;
1251
1252            try {
1253                session = openSession();
1254
1255                StringBundler query = null;
1256
1257                if (orderByComparator != null) {
1258                    query = new StringBundler(4 +
1259                            (orderByComparator.getOrderByFields().length * 3));
1260                }
1261                else {
1262                    query = new StringBundler(3);
1263                }
1264
1265                query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1266
1267                query.append(_FINDER_COLUMN_T_F_THREADID_2);
1268
1269                query.append(_FINDER_COLUMN_T_F_FLAG_2);
1270
1271                if (orderByComparator != null) {
1272                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1273                        orderByComparator);
1274                }
1275
1276                String sql = query.toString();
1277
1278                Query q = session.createQuery(sql);
1279
1280                QueryPos qPos = QueryPos.getInstance(q);
1281
1282                qPos.add(threadId);
1283
1284                qPos.add(flag);
1285
1286                list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1287                        start, end);
1288            }
1289            catch (Exception e) {
1290                throw processException(e);
1291            }
1292            finally {
1293                if (list == null) {
1294                    list = new ArrayList<MBMessageFlag>();
1295                }
1296
1297                cacheResult(list);
1298
1299                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_F, finderArgs,
1300                    list);
1301
1302                closeSession(session);
1303            }
1304        }
1305
1306        return list;
1307    }
1308
1309    public MBMessageFlag findByT_F_First(long threadId, int flag,
1310        OrderByComparator orderByComparator)
1311        throws NoSuchMessageFlagException, SystemException {
1312        List<MBMessageFlag> list = findByT_F(threadId, flag, 0, 1,
1313                orderByComparator);
1314
1315        if (list.isEmpty()) {
1316            StringBundler msg = new StringBundler(6);
1317
1318            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1319
1320            msg.append("threadId=");
1321            msg.append(threadId);
1322
1323            msg.append(", flag=");
1324            msg.append(flag);
1325
1326            msg.append(StringPool.CLOSE_CURLY_BRACE);
1327
1328            throw new NoSuchMessageFlagException(msg.toString());
1329        }
1330        else {
1331            return list.get(0);
1332        }
1333    }
1334
1335    public MBMessageFlag findByT_F_Last(long threadId, int flag,
1336        OrderByComparator orderByComparator)
1337        throws NoSuchMessageFlagException, SystemException {
1338        int count = countByT_F(threadId, flag);
1339
1340        List<MBMessageFlag> list = findByT_F(threadId, flag, count - 1, count,
1341                orderByComparator);
1342
1343        if (list.isEmpty()) {
1344            StringBundler msg = new StringBundler(6);
1345
1346            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1347
1348            msg.append("threadId=");
1349            msg.append(threadId);
1350
1351            msg.append(", flag=");
1352            msg.append(flag);
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    public MBMessageFlag[] findByT_F_PrevAndNext(long messageFlagId,
1364        long threadId, int flag, OrderByComparator orderByComparator)
1365        throws NoSuchMessageFlagException, SystemException {
1366        MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1367
1368        Session session = null;
1369
1370        try {
1371            session = openSession();
1372
1373            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1374
1375            array[0] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1376                    flag, orderByComparator, true);
1377
1378            array[1] = mbMessageFlag;
1379
1380            array[2] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1381                    flag, orderByComparator, false);
1382
1383            return array;
1384        }
1385        catch (Exception e) {
1386            throw processException(e);
1387        }
1388        finally {
1389            closeSession(session);
1390        }
1391    }
1392
1393    protected MBMessageFlag getByT_F_PrevAndNext(Session session,
1394        MBMessageFlag mbMessageFlag, long threadId, int flag,
1395        OrderByComparator orderByComparator, boolean previous) {
1396        StringBundler query = null;
1397
1398        if (orderByComparator != null) {
1399            query = new StringBundler(6 +
1400                    (orderByComparator.getOrderByFields().length * 6));
1401        }
1402        else {
1403            query = new StringBundler(3);
1404        }
1405
1406        query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1407
1408        query.append(_FINDER_COLUMN_T_F_THREADID_2);
1409
1410        query.append(_FINDER_COLUMN_T_F_FLAG_2);
1411
1412        if (orderByComparator != null) {
1413            String[] orderByFields = orderByComparator.getOrderByFields();
1414
1415            if (orderByFields.length > 0) {
1416                query.append(WHERE_AND);
1417            }
1418
1419            for (int i = 0; i < orderByFields.length; i++) {
1420                query.append(_ORDER_BY_ENTITY_ALIAS);
1421                query.append(orderByFields[i]);
1422
1423                if ((i + 1) < orderByFields.length) {
1424                    if (orderByComparator.isAscending() ^ previous) {
1425                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1426                    }
1427                    else {
1428                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1429                    }
1430                }
1431                else {
1432                    if (orderByComparator.isAscending() ^ previous) {
1433                        query.append(WHERE_GREATER_THAN);
1434                    }
1435                    else {
1436                        query.append(WHERE_LESSER_THAN);
1437                    }
1438                }
1439            }
1440
1441            query.append(ORDER_BY_CLAUSE);
1442
1443            for (int i = 0; i < orderByFields.length; i++) {
1444                query.append(_ORDER_BY_ENTITY_ALIAS);
1445                query.append(orderByFields[i]);
1446
1447                if ((i + 1) < orderByFields.length) {
1448                    if (orderByComparator.isAscending() ^ previous) {
1449                        query.append(ORDER_BY_ASC_HAS_NEXT);
1450                    }
1451                    else {
1452                        query.append(ORDER_BY_DESC_HAS_NEXT);
1453                    }
1454                }
1455                else {
1456                    if (orderByComparator.isAscending() ^ previous) {
1457                        query.append(ORDER_BY_ASC);
1458                    }
1459                    else {
1460                        query.append(ORDER_BY_DESC);
1461                    }
1462                }
1463            }
1464        }
1465
1466        String sql = query.toString();
1467
1468        Query q = session.createQuery(sql);
1469
1470        q.setFirstResult(0);
1471        q.setMaxResults(2);
1472
1473        QueryPos qPos = QueryPos.getInstance(q);
1474
1475        qPos.add(threadId);
1476
1477        qPos.add(flag);
1478
1479        if (orderByComparator != null) {
1480            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1481
1482            for (Object value : values) {
1483                qPos.add(value);
1484            }
1485        }
1486
1487        List<MBMessageFlag> list = q.list();
1488
1489        if (list.size() == 2) {
1490            return list.get(1);
1491        }
1492        else {
1493            return null;
1494        }
1495    }
1496
1497    public List<MBMessageFlag> findByM_F(long messageId, int flag)
1498        throws SystemException {
1499        return findByM_F(messageId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1500            null);
1501    }
1502
1503    public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1504        int end) throws SystemException {
1505        return findByM_F(messageId, flag, start, end, null);
1506    }
1507
1508    public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1509        int end, OrderByComparator orderByComparator) throws SystemException {
1510        Object[] finderArgs = new Object[] {
1511                new Long(messageId), new Integer(flag),
1512                
1513                String.valueOf(start), String.valueOf(end),
1514                String.valueOf(orderByComparator)
1515            };
1516
1517        List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_M_F,
1518                finderArgs, this);
1519
1520        if (list == null) {
1521            Session session = null;
1522
1523            try {
1524                session = openSession();
1525
1526                StringBundler query = null;
1527
1528                if (orderByComparator != null) {
1529                    query = new StringBundler(4 +
1530                            (orderByComparator.getOrderByFields().length * 3));
1531                }
1532                else {
1533                    query = new StringBundler(3);
1534                }
1535
1536                query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1537
1538                query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
1539
1540                query.append(_FINDER_COLUMN_M_F_FLAG_2);
1541
1542                if (orderByComparator != null) {
1543                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1544                        orderByComparator);
1545                }
1546
1547                String sql = query.toString();
1548
1549                Query q = session.createQuery(sql);
1550
1551                QueryPos qPos = QueryPos.getInstance(q);
1552
1553                qPos.add(messageId);
1554
1555                qPos.add(flag);
1556
1557                list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1558                        start, end);
1559            }
1560            catch (Exception e) {
1561                throw processException(e);
1562            }
1563            finally {
1564                if (list == null) {
1565                    list = new ArrayList<MBMessageFlag>();
1566                }
1567
1568                cacheResult(list);
1569
1570                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_M_F, finderArgs,
1571                    list);
1572
1573                closeSession(session);
1574            }
1575        }
1576
1577        return list;
1578    }
1579
1580    public MBMessageFlag findByM_F_First(long messageId, int flag,
1581        OrderByComparator orderByComparator)
1582        throws NoSuchMessageFlagException, SystemException {
1583        List<MBMessageFlag> list = findByM_F(messageId, flag, 0, 1,
1584                orderByComparator);
1585
1586        if (list.isEmpty()) {
1587            StringBundler msg = new StringBundler(6);
1588
1589            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1590
1591            msg.append("messageId=");
1592            msg.append(messageId);
1593
1594            msg.append(", flag=");
1595            msg.append(flag);
1596
1597            msg.append(StringPool.CLOSE_CURLY_BRACE);
1598
1599            throw new NoSuchMessageFlagException(msg.toString());
1600        }
1601        else {
1602            return list.get(0);
1603        }
1604    }
1605
1606    public MBMessageFlag findByM_F_Last(long messageId, int flag,
1607        OrderByComparator orderByComparator)
1608        throws NoSuchMessageFlagException, SystemException {
1609        int count = countByM_F(messageId, flag);
1610
1611        List<MBMessageFlag> list = findByM_F(messageId, flag, count - 1, count,
1612                orderByComparator);
1613
1614        if (list.isEmpty()) {
1615            StringBundler msg = new StringBundler(6);
1616
1617            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1618
1619            msg.append("messageId=");
1620            msg.append(messageId);
1621
1622            msg.append(", flag=");
1623            msg.append(flag);
1624
1625            msg.append(StringPool.CLOSE_CURLY_BRACE);
1626
1627            throw new NoSuchMessageFlagException(msg.toString());
1628        }
1629        else {
1630            return list.get(0);
1631        }
1632    }
1633
1634    public MBMessageFlag[] findByM_F_PrevAndNext(long messageFlagId,
1635        long messageId, int flag, OrderByComparator orderByComparator)
1636        throws NoSuchMessageFlagException, SystemException {
1637        MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1638
1639        Session session = null;
1640
1641        try {
1642            session = openSession();
1643
1644            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1645
1646            array[0] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
1647                    flag, orderByComparator, true);
1648
1649            array[1] = mbMessageFlag;
1650
1651            array[2] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
1652                    flag, orderByComparator, false);
1653
1654            return array;
1655        }
1656        catch (Exception e) {
1657            throw processException(e);
1658        }
1659        finally {
1660            closeSession(session);
1661        }
1662    }
1663
1664    protected MBMessageFlag getByM_F_PrevAndNext(Session session,
1665        MBMessageFlag mbMessageFlag, long messageId, int flag,
1666        OrderByComparator orderByComparator, boolean previous) {
1667        StringBundler query = null;
1668
1669        if (orderByComparator != null) {
1670            query = new StringBundler(6 +
1671                    (orderByComparator.getOrderByFields().length * 6));
1672        }
1673        else {
1674            query = new StringBundler(3);
1675        }
1676
1677        query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1678
1679        query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
1680
1681        query.append(_FINDER_COLUMN_M_F_FLAG_2);
1682
1683        if (orderByComparator != null) {
1684            String[] orderByFields = orderByComparator.getOrderByFields();
1685
1686            if (orderByFields.length > 0) {
1687                query.append(WHERE_AND);
1688            }
1689
1690            for (int i = 0; i < orderByFields.length; i++) {
1691                query.append(_ORDER_BY_ENTITY_ALIAS);
1692                query.append(orderByFields[i]);
1693
1694                if ((i + 1) < orderByFields.length) {
1695                    if (orderByComparator.isAscending() ^ previous) {
1696                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1697                    }
1698                    else {
1699                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1700                    }
1701                }
1702                else {
1703                    if (orderByComparator.isAscending() ^ previous) {
1704                        query.append(WHERE_GREATER_THAN);
1705                    }
1706                    else {
1707                        query.append(WHERE_LESSER_THAN);
1708                    }
1709                }
1710            }
1711
1712            query.append(ORDER_BY_CLAUSE);
1713
1714            for (int i = 0; i < orderByFields.length; i++) {
1715                query.append(_ORDER_BY_ENTITY_ALIAS);
1716                query.append(orderByFields[i]);
1717
1718                if ((i + 1) < orderByFields.length) {
1719                    if (orderByComparator.isAscending() ^ previous) {
1720                        query.append(ORDER_BY_ASC_HAS_NEXT);
1721                    }
1722                    else {
1723                        query.append(ORDER_BY_DESC_HAS_NEXT);
1724                    }
1725                }
1726                else {
1727                    if (orderByComparator.isAscending() ^ previous) {
1728                        query.append(ORDER_BY_ASC);
1729                    }
1730                    else {
1731                        query.append(ORDER_BY_DESC);
1732                    }
1733                }
1734            }
1735        }
1736
1737        String sql = query.toString();
1738
1739        Query q = session.createQuery(sql);
1740
1741        q.setFirstResult(0);
1742        q.setMaxResults(2);
1743
1744        QueryPos qPos = QueryPos.getInstance(q);
1745
1746        qPos.add(messageId);
1747
1748        qPos.add(flag);
1749
1750        if (orderByComparator != null) {
1751            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1752
1753            for (Object value : values) {
1754                qPos.add(value);
1755            }
1756        }
1757
1758        List<MBMessageFlag> list = q.list();
1759
1760        if (list.size() == 2) {
1761            return list.get(1);
1762        }
1763        else {
1764            return null;
1765        }
1766    }
1767
1768    public List<MBMessageFlag> findByU_T_F(long userId, long threadId, int flag)
1769        throws SystemException {
1770        return findByU_T_F(userId, threadId, flag, QueryUtil.ALL_POS,
1771            QueryUtil.ALL_POS, null);
1772    }
1773
1774    public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
1775        int flag, int start, int end) throws SystemException {
1776        return findByU_T_F(userId, threadId, flag, start, end, null);
1777    }
1778
1779    public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
1780        int flag, int start, int end, OrderByComparator orderByComparator)
1781        throws SystemException {
1782        Object[] finderArgs = new Object[] {
1783                new Long(userId), new Long(threadId), new Integer(flag),
1784                
1785                String.valueOf(start), String.valueOf(end),
1786                String.valueOf(orderByComparator)
1787            };
1788
1789        List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_T_F,
1790                finderArgs, this);
1791
1792        if (list == null) {
1793            Session session = null;
1794
1795            try {
1796                session = openSession();
1797
1798                StringBundler query = null;
1799
1800                if (orderByComparator != null) {
1801                    query = new StringBundler(5 +
1802                            (orderByComparator.getOrderByFields().length * 3));
1803                }
1804                else {
1805                    query = new StringBundler(4);
1806                }
1807
1808                query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1809
1810                query.append(_FINDER_COLUMN_U_T_F_USERID_2);
1811
1812                query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
1813
1814                query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
1815
1816                if (orderByComparator != null) {
1817                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1818                        orderByComparator);
1819                }
1820
1821                String sql = query.toString();
1822
1823                Query q = session.createQuery(sql);
1824
1825                QueryPos qPos = QueryPos.getInstance(q);
1826
1827                qPos.add(userId);
1828
1829                qPos.add(threadId);
1830
1831                qPos.add(flag);
1832
1833                list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1834                        start, end);
1835            }
1836            catch (Exception e) {
1837                throw processException(e);
1838            }
1839            finally {
1840                if (list == null) {
1841                    list = new ArrayList<MBMessageFlag>();
1842                }
1843
1844                cacheResult(list);
1845
1846                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_T_F,
1847                    finderArgs, list);
1848
1849                closeSession(session);
1850            }
1851        }
1852
1853        return list;
1854    }
1855
1856    public MBMessageFlag findByU_T_F_First(long userId, long threadId,
1857        int flag, OrderByComparator orderByComparator)
1858        throws NoSuchMessageFlagException, SystemException {
1859        List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag, 0, 1,
1860                orderByComparator);
1861
1862        if (list.isEmpty()) {
1863            StringBundler msg = new StringBundler(8);
1864
1865            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1866
1867            msg.append("userId=");
1868            msg.append(userId);
1869
1870            msg.append(", threadId=");
1871            msg.append(threadId);
1872
1873            msg.append(", flag=");
1874            msg.append(flag);
1875
1876            msg.append(StringPool.CLOSE_CURLY_BRACE);
1877
1878            throw new NoSuchMessageFlagException(msg.toString());
1879        }
1880        else {
1881            return list.get(0);
1882        }
1883    }
1884
1885    public MBMessageFlag findByU_T_F_Last(long userId, long threadId, int flag,
1886        OrderByComparator orderByComparator)
1887        throws NoSuchMessageFlagException, SystemException {
1888        int count = countByU_T_F(userId, threadId, flag);
1889
1890        List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag,
1891                count - 1, count, orderByComparator);
1892
1893        if (list.isEmpty()) {
1894            StringBundler msg = new StringBundler(8);
1895
1896            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1897
1898            msg.append("userId=");
1899            msg.append(userId);
1900
1901            msg.append(", threadId=");
1902            msg.append(threadId);
1903
1904            msg.append(", flag=");
1905            msg.append(flag);
1906
1907            msg.append(StringPool.CLOSE_CURLY_BRACE);
1908
1909            throw new NoSuchMessageFlagException(msg.toString());
1910        }
1911        else {
1912            return list.get(0);
1913        }
1914    }
1915
1916    public MBMessageFlag[] findByU_T_F_PrevAndNext(long messageFlagId,
1917        long userId, long threadId, int flag,
1918        OrderByComparator orderByComparator)
1919        throws NoSuchMessageFlagException, SystemException {
1920        MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1921
1922        Session session = null;
1923
1924        try {
1925            session = openSession();
1926
1927            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1928
1929            array[0] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
1930                    threadId, flag, orderByComparator, true);
1931
1932            array[1] = mbMessageFlag;
1933
1934            array[2] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
1935                    threadId, flag, orderByComparator, false);
1936
1937            return array;
1938        }
1939        catch (Exception e) {
1940            throw processException(e);
1941        }
1942        finally {
1943            closeSession(session);
1944        }
1945    }
1946
1947    protected MBMessageFlag getByU_T_F_PrevAndNext(Session session,
1948        MBMessageFlag mbMessageFlag, long userId, long threadId, int flag,
1949        OrderByComparator orderByComparator, boolean previous) {
1950        StringBundler query = null;
1951
1952        if (orderByComparator != null) {
1953            query = new StringBundler(6 +
1954                    (orderByComparator.getOrderByFields().length * 6));
1955        }
1956        else {
1957            query = new StringBundler(3);
1958        }
1959
1960        query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1961
1962        query.append(_FINDER_COLUMN_U_T_F_USERID_2);
1963
1964        query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
1965
1966        query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
1967
1968        if (orderByComparator != null) {
1969            String[] orderByFields = orderByComparator.getOrderByFields();
1970
1971            if (orderByFields.length > 0) {
1972                query.append(WHERE_AND);
1973            }
1974
1975            for (int i = 0; i < orderByFields.length; i++) {
1976                query.append(_ORDER_BY_ENTITY_ALIAS);
1977                query.append(orderByFields[i]);
1978
1979                if ((i + 1) < orderByFields.length) {
1980                    if (orderByComparator.isAscending() ^ previous) {
1981                        query.append(WHERE_GREATER_THAN_HAS_NEXT);
1982                    }
1983                    else {
1984                        query.append(WHERE_LESSER_THAN_HAS_NEXT);
1985                    }
1986                }
1987                else {
1988                    if (orderByComparator.isAscending() ^ previous) {
1989                        query.append(WHERE_GREATER_THAN);
1990                    }
1991                    else {
1992                        query.append(WHERE_LESSER_THAN);
1993                    }
1994                }
1995            }
1996
1997            query.append(ORDER_BY_CLAUSE);
1998
1999            for (int i = 0; i < orderByFields.length; i++) {
2000                query.append(_ORDER_BY_ENTITY_ALIAS);
2001                query.append(orderByFields[i]);
2002
2003                if ((i + 1) < orderByFields.length) {
2004                    if (orderByComparator.isAscending() ^ previous) {
2005                        query.append(ORDER_BY_ASC_HAS_NEXT);
2006                    }
2007                    else {
2008                        query.append(ORDER_BY_DESC_HAS_NEXT);
2009                    }
2010                }
2011                else {
2012                    if (orderByComparator.isAscending() ^ previous) {
2013                        query.append(ORDER_BY_ASC);
2014                    }
2015                    else {
2016                        query.append(ORDER_BY_DESC);
2017                    }
2018                }
2019            }
2020        }
2021
2022        String sql = query.toString();
2023
2024        Query q = session.createQuery(sql);
2025
2026        q.setFirstResult(0);
2027        q.setMaxResults(2);
2028
2029        QueryPos qPos = QueryPos.getInstance(q);
2030
2031        qPos.add(userId);
2032
2033        qPos.add(threadId);
2034
2035        qPos.add(flag);
2036
2037        if (orderByComparator != null) {
2038            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2039
2040            for (Object value : values) {
2041                qPos.add(value);
2042            }
2043        }
2044
2045        List<MBMessageFlag> list = q.list();
2046
2047        if (list.size() == 2) {
2048            return list.get(1);
2049        }
2050        else {
2051            return null;
2052        }
2053    }
2054
2055    public MBMessageFlag findByU_M_F(long userId, long messageId, int flag)
2056        throws NoSuchMessageFlagException, SystemException {
2057        MBMessageFlag mbMessageFlag = fetchByU_M_F(userId, messageId, flag);
2058
2059        if (mbMessageFlag == null) {
2060            StringBundler msg = new StringBundler(8);
2061
2062            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2063
2064            msg.append("userId=");
2065            msg.append(userId);
2066
2067            msg.append(", messageId=");
2068            msg.append(messageId);
2069
2070            msg.append(", flag=");
2071            msg.append(flag);
2072
2073            msg.append(StringPool.CLOSE_CURLY_BRACE);
2074
2075            if (_log.isWarnEnabled()) {
2076                _log.warn(msg.toString());
2077            }
2078
2079            throw new NoSuchMessageFlagException(msg.toString());
2080        }
2081
2082        return mbMessageFlag;
2083    }
2084
2085    public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag)
2086        throws SystemException {
2087        return fetchByU_M_F(userId, messageId, flag, true);
2088    }
2089
2090    public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag,
2091        boolean retrieveFromCache) throws SystemException {
2092        Object[] finderArgs = new Object[] {
2093                new Long(userId), new Long(messageId), new Integer(flag)
2094            };
2095
2096        Object result = null;
2097
2098        if (retrieveFromCache) {
2099            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_M_F,
2100                    finderArgs, this);
2101        }
2102
2103        if (result == null) {
2104            Session session = null;
2105
2106            try {
2107                session = openSession();
2108
2109                StringBundler query = new StringBundler(4);
2110
2111                query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2112
2113                query.append(_FINDER_COLUMN_U_M_F_USERID_2);
2114
2115                query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
2116
2117                query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
2118
2119                String sql = query.toString();
2120
2121                Query q = session.createQuery(sql);
2122
2123                QueryPos qPos = QueryPos.getInstance(q);
2124
2125                qPos.add(userId);
2126
2127                qPos.add(messageId);
2128
2129                qPos.add(flag);
2130
2131                List<MBMessageFlag> list = q.list();
2132
2133                result = list;
2134
2135                MBMessageFlag mbMessageFlag = null;
2136
2137                if (list.isEmpty()) {
2138                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2139                        finderArgs, list);
2140                }
2141                else {
2142                    mbMessageFlag = list.get(0);
2143
2144                    cacheResult(mbMessageFlag);
2145
2146                    if ((mbMessageFlag.getUserId() != userId) ||
2147                            (mbMessageFlag.getMessageId() != messageId) ||
2148                            (mbMessageFlag.getFlag() != flag)) {
2149                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2150                            finderArgs, mbMessageFlag);
2151                    }
2152                }
2153
2154                return mbMessageFlag;
2155            }
2156            catch (Exception e) {
2157                throw processException(e);
2158            }
2159            finally {
2160                if (result == null) {
2161                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2162                        finderArgs, new ArrayList<MBMessageFlag>());
2163                }
2164
2165                closeSession(session);
2166            }
2167        }
2168        else {
2169            if (result instanceof List<?>) {
2170                return null;
2171            }
2172            else {
2173                return (MBMessageFlag)result;
2174            }
2175        }
2176    }
2177
2178    public List<MBMessageFlag> findAll() throws SystemException {
2179        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2180    }
2181
2182    public List<MBMessageFlag> findAll(int start, int end)
2183        throws SystemException {
2184        return findAll(start, end, null);
2185    }
2186
2187    public List<MBMessageFlag> findAll(int start, int end,
2188        OrderByComparator orderByComparator) throws SystemException {
2189        Object[] finderArgs = new Object[] {
2190                String.valueOf(start), String.valueOf(end),
2191                String.valueOf(orderByComparator)
2192            };
2193
2194        List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2195                finderArgs, this);
2196
2197        if (list == null) {
2198            Session session = null;
2199
2200            try {
2201                session = openSession();
2202
2203                StringBundler query = null;
2204                String sql = null;
2205
2206                if (orderByComparator != null) {
2207                    query = new StringBundler(2 +
2208                            (orderByComparator.getOrderByFields().length * 3));
2209
2210                    query.append(_SQL_SELECT_MBMESSAGEFLAG);
2211
2212                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2213                        orderByComparator);
2214
2215                    sql = query.toString();
2216                }
2217
2218                sql = _SQL_SELECT_MBMESSAGEFLAG;
2219
2220                Query q = session.createQuery(sql);
2221
2222                if (orderByComparator == null) {
2223                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2224                            start, end, false);
2225
2226                    Collections.sort(list);
2227                }
2228                else {
2229                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2230                            start, end);
2231                }
2232            }
2233            catch (Exception e) {
2234                throw processException(e);
2235            }
2236            finally {
2237                if (list == null) {
2238                    list = new ArrayList<MBMessageFlag>();
2239                }
2240
2241                cacheResult(list);
2242
2243                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2244
2245                closeSession(session);
2246            }
2247        }
2248
2249        return list;
2250    }
2251
2252    public void removeByUserId(long userId) throws SystemException {
2253        for (MBMessageFlag mbMessageFlag : findByUserId(userId)) {
2254            remove(mbMessageFlag);
2255        }
2256    }
2257
2258    public void removeByThreadId(long threadId) throws SystemException {
2259        for (MBMessageFlag mbMessageFlag : findByThreadId(threadId)) {
2260            remove(mbMessageFlag);
2261        }
2262    }
2263
2264    public void removeByMessageId(long messageId) throws SystemException {
2265        for (MBMessageFlag mbMessageFlag : findByMessageId(messageId)) {
2266            remove(mbMessageFlag);
2267        }
2268    }
2269
2270    public void removeByT_F(long threadId, int flag) throws SystemException {
2271        for (MBMessageFlag mbMessageFlag : findByT_F(threadId, flag)) {
2272            remove(mbMessageFlag);
2273        }
2274    }
2275
2276    public void removeByM_F(long messageId, int flag) throws SystemException {
2277        for (MBMessageFlag mbMessageFlag : findByM_F(messageId, flag)) {
2278            remove(mbMessageFlag);
2279        }
2280    }
2281
2282    public void removeByU_T_F(long userId, long threadId, int flag)
2283        throws SystemException {
2284        for (MBMessageFlag mbMessageFlag : findByU_T_F(userId, threadId, flag)) {
2285            remove(mbMessageFlag);
2286        }
2287    }
2288
2289    public void removeByU_M_F(long userId, long messageId, int flag)
2290        throws NoSuchMessageFlagException, SystemException {
2291        MBMessageFlag mbMessageFlag = findByU_M_F(userId, messageId, flag);
2292
2293        remove(mbMessageFlag);
2294    }
2295
2296    public void removeAll() throws SystemException {
2297        for (MBMessageFlag mbMessageFlag : findAll()) {
2298            remove(mbMessageFlag);
2299        }
2300    }
2301
2302    public int countByUserId(long userId) throws SystemException {
2303        Object[] finderArgs = new Object[] { new Long(userId) };
2304
2305        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2306                finderArgs, this);
2307
2308        if (count == null) {
2309            Session session = null;
2310
2311            try {
2312                session = openSession();
2313
2314                StringBundler query = new StringBundler(2);
2315
2316                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2317
2318                query.append(_FINDER_COLUMN_USERID_USERID_2);
2319
2320                String sql = query.toString();
2321
2322                Query q = session.createQuery(sql);
2323
2324                QueryPos qPos = QueryPos.getInstance(q);
2325
2326                qPos.add(userId);
2327
2328                count = (Long)q.uniqueResult();
2329            }
2330            catch (Exception e) {
2331                throw processException(e);
2332            }
2333            finally {
2334                if (count == null) {
2335                    count = Long.valueOf(0);
2336                }
2337
2338                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2339                    finderArgs, count);
2340
2341                closeSession(session);
2342            }
2343        }
2344
2345        return count.intValue();
2346    }
2347
2348    public int countByThreadId(long threadId) throws SystemException {
2349        Object[] finderArgs = new Object[] { new Long(threadId) };
2350
2351        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
2352                finderArgs, this);
2353
2354        if (count == null) {
2355            Session session = null;
2356
2357            try {
2358                session = openSession();
2359
2360                StringBundler query = new StringBundler(2);
2361
2362                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2363
2364                query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2365
2366                String sql = query.toString();
2367
2368                Query q = session.createQuery(sql);
2369
2370                QueryPos qPos = QueryPos.getInstance(q);
2371
2372                qPos.add(threadId);
2373
2374                count = (Long)q.uniqueResult();
2375            }
2376            catch (Exception e) {
2377                throw processException(e);
2378            }
2379            finally {
2380                if (count == null) {
2381                    count = Long.valueOf(0);
2382                }
2383
2384                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
2385                    finderArgs, count);
2386
2387                closeSession(session);
2388            }
2389        }
2390
2391        return count.intValue();
2392    }
2393
2394    public int countByMessageId(long messageId) throws SystemException {
2395        Object[] finderArgs = new Object[] { new Long(messageId) };
2396
2397        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MESSAGEID,
2398                finderArgs, this);
2399
2400        if (count == null) {
2401            Session session = null;
2402
2403            try {
2404                session = openSession();
2405
2406                StringBundler query = new StringBundler(2);
2407
2408                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2409
2410                query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
2411
2412                String sql = query.toString();
2413
2414                Query q = session.createQuery(sql);
2415
2416                QueryPos qPos = QueryPos.getInstance(q);
2417
2418                qPos.add(messageId);
2419
2420                count = (Long)q.uniqueResult();
2421            }
2422            catch (Exception e) {
2423                throw processException(e);
2424            }
2425            finally {
2426                if (count == null) {
2427                    count = Long.valueOf(0);
2428                }
2429
2430                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MESSAGEID,
2431                    finderArgs, count);
2432
2433                closeSession(session);
2434            }
2435        }
2436
2437        return count.intValue();
2438    }
2439
2440    public int countByT_F(long threadId, int flag) throws SystemException {
2441        Object[] finderArgs = new Object[] { new Long(threadId), new Integer(flag) };
2442
2443        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_F,
2444                finderArgs, this);
2445
2446        if (count == null) {
2447            Session session = null;
2448
2449            try {
2450                session = openSession();
2451
2452                StringBundler query = new StringBundler(3);
2453
2454                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2455
2456                query.append(_FINDER_COLUMN_T_F_THREADID_2);
2457
2458                query.append(_FINDER_COLUMN_T_F_FLAG_2);
2459
2460                String sql = query.toString();
2461
2462                Query q = session.createQuery(sql);
2463
2464                QueryPos qPos = QueryPos.getInstance(q);
2465
2466                qPos.add(threadId);
2467
2468                qPos.add(flag);
2469
2470                count = (Long)q.uniqueResult();
2471            }
2472            catch (Exception e) {
2473                throw processException(e);
2474            }
2475            finally {
2476                if (count == null) {
2477                    count = Long.valueOf(0);
2478                }
2479
2480                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_F, finderArgs,
2481                    count);
2482
2483                closeSession(session);
2484            }
2485        }
2486
2487        return count.intValue();
2488    }
2489
2490    public int countByM_F(long messageId, int flag) throws SystemException {
2491        Object[] finderArgs = new Object[] {
2492                new Long(messageId), new Integer(flag)
2493            };
2494
2495        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_M_F,
2496                finderArgs, this);
2497
2498        if (count == null) {
2499            Session session = null;
2500
2501            try {
2502                session = openSession();
2503
2504                StringBundler query = new StringBundler(3);
2505
2506                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2507
2508                query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
2509
2510                query.append(_FINDER_COLUMN_M_F_FLAG_2);
2511
2512                String sql = query.toString();
2513
2514                Query q = session.createQuery(sql);
2515
2516                QueryPos qPos = QueryPos.getInstance(q);
2517
2518                qPos.add(messageId);
2519
2520                qPos.add(flag);
2521
2522                count = (Long)q.uniqueResult();
2523            }
2524            catch (Exception e) {
2525                throw processException(e);
2526            }
2527            finally {
2528                if (count == null) {
2529                    count = Long.valueOf(0);
2530                }
2531
2532                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_M_F, finderArgs,
2533                    count);
2534
2535                closeSession(session);
2536            }
2537        }
2538
2539        return count.intValue();
2540    }
2541
2542    public int countByU_T_F(long userId, long threadId, int flag)
2543        throws SystemException {
2544        Object[] finderArgs = new Object[] {
2545                new Long(userId), new Long(threadId), new Integer(flag)
2546            };
2547
2548        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T_F,
2549                finderArgs, this);
2550
2551        if (count == null) {
2552            Session session = null;
2553
2554            try {
2555                session = openSession();
2556
2557                StringBundler query = new StringBundler(4);
2558
2559                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2560
2561                query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2562
2563                query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2564
2565                query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2566
2567                String sql = query.toString();
2568
2569                Query q = session.createQuery(sql);
2570
2571                QueryPos qPos = QueryPos.getInstance(q);
2572
2573                qPos.add(userId);
2574
2575                qPos.add(threadId);
2576
2577                qPos.add(flag);
2578
2579                count = (Long)q.uniqueResult();
2580            }
2581            catch (Exception e) {
2582                throw processException(e);
2583            }
2584            finally {
2585                if (count == null) {
2586                    count = Long.valueOf(0);
2587                }
2588
2589                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T_F,
2590                    finderArgs, count);
2591
2592                closeSession(session);
2593            }
2594        }
2595
2596        return count.intValue();
2597    }
2598
2599    public int countByU_M_F(long userId, long messageId, int flag)
2600        throws SystemException {
2601        Object[] finderArgs = new Object[] {
2602                new Long(userId), new Long(messageId), new Integer(flag)
2603            };
2604
2605        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_M_F,
2606                finderArgs, this);
2607
2608        if (count == null) {
2609            Session session = null;
2610
2611            try {
2612                session = openSession();
2613
2614                StringBundler query = new StringBundler(4);
2615
2616                query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2617
2618                query.append(_FINDER_COLUMN_U_M_F_USERID_2);
2619
2620                query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
2621
2622                query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
2623
2624                String sql = query.toString();
2625
2626                Query q = session.createQuery(sql);
2627
2628                QueryPos qPos = QueryPos.getInstance(q);
2629
2630                qPos.add(userId);
2631
2632                qPos.add(messageId);
2633
2634                qPos.add(flag);
2635
2636                count = (Long)q.uniqueResult();
2637            }
2638            catch (Exception e) {
2639                throw processException(e);
2640            }
2641            finally {
2642                if (count == null) {
2643                    count = Long.valueOf(0);
2644                }
2645
2646                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_M_F,
2647                    finderArgs, count);
2648
2649                closeSession(session);
2650            }
2651        }
2652
2653        return count.intValue();
2654    }
2655
2656    public int countAll() throws SystemException {
2657        Object[] finderArgs = new Object[0];
2658
2659        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2660                finderArgs, this);
2661
2662        if (count == null) {
2663            Session session = null;
2664
2665            try {
2666                session = openSession();
2667
2668                Query q = session.createQuery(_SQL_COUNT_MBMESSAGEFLAG);
2669
2670                count = (Long)q.uniqueResult();
2671            }
2672            catch (Exception e) {
2673                throw processException(e);
2674            }
2675            finally {
2676                if (count == null) {
2677                    count = Long.valueOf(0);
2678                }
2679
2680                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2681                    count);
2682
2683                closeSession(session);
2684            }
2685        }
2686
2687        return count.intValue();
2688    }
2689
2690    public void afterPropertiesSet() {
2691        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2692                    com.liferay.portal.util.PropsUtil.get(
2693                        "value.object.listener.com.liferay.portlet.messageboards.model.MBMessageFlag")));
2694
2695        if (listenerClassNames.length > 0) {
2696            try {
2697                List<ModelListener<MBMessageFlag>> listenersList = new ArrayList<ModelListener<MBMessageFlag>>();
2698
2699                for (String listenerClassName : listenerClassNames) {
2700                    listenersList.add((ModelListener<MBMessageFlag>)InstanceFactory.newInstance(
2701                            listenerClassName));
2702                }
2703
2704                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2705            }
2706            catch (Exception e) {
2707                _log.error(e);
2708            }
2709        }
2710    }
2711
2712    @BeanReference(type = MBBanPersistence.class)
2713    protected MBBanPersistence mbBanPersistence;
2714    @BeanReference(type = MBCategoryPersistence.class)
2715    protected MBCategoryPersistence mbCategoryPersistence;
2716    @BeanReference(type = MBDiscussionPersistence.class)
2717    protected MBDiscussionPersistence mbDiscussionPersistence;
2718    @BeanReference(type = MBMailingListPersistence.class)
2719    protected MBMailingListPersistence mbMailingListPersistence;
2720    @BeanReference(type = MBMessagePersistence.class)
2721    protected MBMessagePersistence mbMessagePersistence;
2722    @BeanReference(type = MBMessageFlagPersistence.class)
2723    protected MBMessageFlagPersistence mbMessageFlagPersistence;
2724    @BeanReference(type = MBStatsUserPersistence.class)
2725    protected MBStatsUserPersistence mbStatsUserPersistence;
2726    @BeanReference(type = MBThreadPersistence.class)
2727    protected MBThreadPersistence mbThreadPersistence;
2728    @BeanReference(type = ResourcePersistence.class)
2729    protected ResourcePersistence resourcePersistence;
2730    @BeanReference(type = UserPersistence.class)
2731    protected UserPersistence userPersistence;
2732    private static final String _SQL_SELECT_MBMESSAGEFLAG = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag";
2733    private static final String _SQL_SELECT_MBMESSAGEFLAG_WHERE = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag WHERE ";
2734    private static final String _SQL_COUNT_MBMESSAGEFLAG = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag";
2735    private static final String _SQL_COUNT_MBMESSAGEFLAG_WHERE = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag WHERE ";
2736    private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessageFlag.userId = ?";
2737    private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessageFlag.threadId = ?";
2738    private static final String _FINDER_COLUMN_MESSAGEID_MESSAGEID_2 = "mbMessageFlag.messageId = ?";
2739    private static final String _FINDER_COLUMN_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
2740    private static final String _FINDER_COLUMN_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
2741    private static final String _FINDER_COLUMN_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
2742    private static final String _FINDER_COLUMN_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
2743    private static final String _FINDER_COLUMN_U_T_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
2744    private static final String _FINDER_COLUMN_U_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
2745    private static final String _FINDER_COLUMN_U_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
2746    private static final String _FINDER_COLUMN_U_M_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
2747    private static final String _FINDER_COLUMN_U_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
2748    private static final String _FINDER_COLUMN_U_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
2749    private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessageFlag.";
2750    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessageFlag exists with the primary key ";
2751    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessageFlag exists with the key {";
2752    private static Log _log = LogFactoryUtil.getLog(MBMessageFlagPersistenceImpl.class);
2753}