001    /**
002     * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.messageboards.NoSuchMessageFlagException;
043    import com.liferay.portlet.messageboards.model.MBMessageFlag;
044    import com.liferay.portlet.messageboards.model.impl.MBMessageFlagImpl;
045    import com.liferay.portlet.messageboards.model.impl.MBMessageFlagModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the message boards message flag service.
055     *
056     * <p>
057     * Never modify or reference this class directly. Always use {@link MBMessageFlagUtil} to access the message boards message flag persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see MBMessageFlagPersistence
066     * @see MBMessageFlagUtil
067     * @generated
068     */
069    public class MBMessageFlagPersistenceImpl extends BasePersistenceImpl<MBMessageFlag>
070            implements MBMessageFlagPersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageFlagImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
075                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
076                            FINDER_CLASS_NAME_LIST, "findByUserId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
084                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
085                            FINDER_CLASS_NAME_LIST, "countByUserId",
086                            new String[] { Long.class.getName() });
087            public static final FinderPath FINDER_PATH_FIND_BY_THREADID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
088                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
089                            FINDER_CLASS_NAME_LIST, "findByThreadId",
090                            new String[] {
091                                    Long.class.getName(),
092                                    
093                            "java.lang.Integer", "java.lang.Integer",
094                                    "com.liferay.portal.kernel.util.OrderByComparator"
095                            });
096            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
097                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
098                            FINDER_CLASS_NAME_LIST, "countByThreadId",
099                            new String[] { Long.class.getName() });
100            public static final FinderPath FINDER_PATH_FIND_BY_MESSAGEID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
101                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
102                            FINDER_CLASS_NAME_LIST, "findByMessageId",
103                            new String[] {
104                                    Long.class.getName(),
105                                    
106                            "java.lang.Integer", "java.lang.Integer",
107                                    "com.liferay.portal.kernel.util.OrderByComparator"
108                            });
109            public static final FinderPath FINDER_PATH_COUNT_BY_MESSAGEID = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
110                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
111                            FINDER_CLASS_NAME_LIST, "countByMessageId",
112                            new String[] { Long.class.getName() });
113            public static final FinderPath FINDER_PATH_FIND_BY_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
114                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
115                            FINDER_CLASS_NAME_LIST, "findByT_F",
116                            new String[] {
117                                    Long.class.getName(), Integer.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_COUNT_BY_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
123                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
124                            FINDER_CLASS_NAME_LIST, "countByT_F",
125                            new String[] { Long.class.getName(), Integer.class.getName() });
126            public static final FinderPath FINDER_PATH_FIND_BY_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
127                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
128                            FINDER_CLASS_NAME_LIST, "findByM_F",
129                            new String[] {
130                                    Long.class.getName(), Integer.class.getName(),
131                                    
132                            "java.lang.Integer", "java.lang.Integer",
133                                    "com.liferay.portal.kernel.util.OrderByComparator"
134                            });
135            public static final FinderPath FINDER_PATH_COUNT_BY_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
136                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
137                            FINDER_CLASS_NAME_LIST, "countByM_F",
138                            new String[] { Long.class.getName(), Integer.class.getName() });
139            public static final FinderPath FINDER_PATH_FIND_BY_U_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
140                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
141                            FINDER_CLASS_NAME_LIST, "findByU_T_F",
142                            new String[] {
143                                    Long.class.getName(), Long.class.getName(),
144                                    Integer.class.getName(),
145                                    
146                            "java.lang.Integer", "java.lang.Integer",
147                                    "com.liferay.portal.kernel.util.OrderByComparator"
148                            });
149            public static final FinderPath FINDER_PATH_COUNT_BY_U_T_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
150                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
151                            FINDER_CLASS_NAME_LIST, "countByU_T_F",
152                            new String[] {
153                                    Long.class.getName(), Long.class.getName(),
154                                    Integer.class.getName()
155                            });
156            public static final FinderPath FINDER_PATH_FETCH_BY_U_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
157                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
158                            FINDER_CLASS_NAME_ENTITY, "fetchByU_M_F",
159                            new String[] {
160                                    Long.class.getName(), Long.class.getName(),
161                                    Integer.class.getName()
162                            });
163            public static final FinderPath FINDER_PATH_COUNT_BY_U_M_F = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
164                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
165                            FINDER_CLASS_NAME_LIST, "countByU_M_F",
166                            new String[] {
167                                    Long.class.getName(), Long.class.getName(),
168                                    Integer.class.getName()
169                            });
170            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
171                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
172                            FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
173            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
174                            MBMessageFlagModelImpl.FINDER_CACHE_ENABLED,
175                            FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
176    
177            /**
178             * Caches the message boards message flag in the entity cache if it is enabled.
179             *
180             * @param mbMessageFlag the message boards message flag to cache
181             */
182            public void cacheResult(MBMessageFlag mbMessageFlag) {
183                    EntityCacheUtil.putResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
184                            MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
185                            mbMessageFlag);
186    
187                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
188                            new Object[] {
189                                    new Long(mbMessageFlag.getUserId()),
190                                    new Long(mbMessageFlag.getMessageId()),
191                                    new Integer(mbMessageFlag.getFlag())
192                            }, mbMessageFlag);
193            }
194    
195            /**
196             * Caches the message boards message flags in the entity cache if it is enabled.
197             *
198             * @param mbMessageFlags the message boards message flags to cache
199             */
200            public void cacheResult(List<MBMessageFlag> mbMessageFlags) {
201                    for (MBMessageFlag mbMessageFlag : mbMessageFlags) {
202                            if (EntityCacheUtil.getResult(
203                                                    MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
204                                                    MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
205                                                    this) == null) {
206                                    cacheResult(mbMessageFlag);
207                            }
208                    }
209            }
210    
211            /**
212             * Clears the cache for all message boards message flags.
213             *
214             * <p>
215             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
216             * </p>
217             */
218            public void clearCache() {
219                    CacheRegistryUtil.clear(MBMessageFlagImpl.class.getName());
220                    EntityCacheUtil.clearCache(MBMessageFlagImpl.class.getName());
221                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
222                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
223            }
224    
225            /**
226             * Clears the cache for the message boards message flag.
227             *
228             * <p>
229             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
230             * </p>
231             */
232            public void clearCache(MBMessageFlag mbMessageFlag) {
233                    EntityCacheUtil.removeResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
234                            MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey());
235    
236                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
237                            new Object[] {
238                                    new Long(mbMessageFlag.getUserId()),
239                                    new Long(mbMessageFlag.getMessageId()),
240                                    new Integer(mbMessageFlag.getFlag())
241                            });
242            }
243    
244            /**
245             * Creates a new message boards message flag with the primary key. Does not add the message boards message flag to the database.
246             *
247             * @param messageFlagId the primary key for the new message boards message flag
248             * @return the new message boards message flag
249             */
250            public MBMessageFlag create(long messageFlagId) {
251                    MBMessageFlag mbMessageFlag = new MBMessageFlagImpl();
252    
253                    mbMessageFlag.setNew(true);
254                    mbMessageFlag.setPrimaryKey(messageFlagId);
255    
256                    return mbMessageFlag;
257            }
258    
259            /**
260             * Removes the message boards message flag with the primary key from the database. Also notifies the appropriate model listeners.
261             *
262             * @param primaryKey the primary key of the message boards message flag to remove
263             * @return the message boards message flag that was removed
264             * @throws com.liferay.portal.NoSuchModelException if a message boards message flag with the primary key could not be found
265             * @throws SystemException if a system exception occurred
266             */
267            public MBMessageFlag remove(Serializable primaryKey)
268                    throws NoSuchModelException, SystemException {
269                    return remove(((Long)primaryKey).longValue());
270            }
271    
272            /**
273             * Removes the message boards message flag with the primary key from the database. Also notifies the appropriate model listeners.
274             *
275             * @param messageFlagId the primary key of the message boards message flag to remove
276             * @return the message boards message flag that was removed
277             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
278             * @throws SystemException if a system exception occurred
279             */
280            public MBMessageFlag remove(long messageFlagId)
281                    throws NoSuchMessageFlagException, SystemException {
282                    Session session = null;
283    
284                    try {
285                            session = openSession();
286    
287                            MBMessageFlag mbMessageFlag = (MBMessageFlag)session.get(MBMessageFlagImpl.class,
288                                            new Long(messageFlagId));
289    
290                            if (mbMessageFlag == null) {
291                                    if (_log.isWarnEnabled()) {
292                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageFlagId);
293                                    }
294    
295                                    throw new NoSuchMessageFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
296                                            messageFlagId);
297                            }
298    
299                            return remove(mbMessageFlag);
300                    }
301                    catch (NoSuchMessageFlagException nsee) {
302                            throw nsee;
303                    }
304                    catch (Exception e) {
305                            throw processException(e);
306                    }
307                    finally {
308                            closeSession(session);
309                    }
310            }
311    
312            protected MBMessageFlag removeImpl(MBMessageFlag mbMessageFlag)
313                    throws SystemException {
314                    mbMessageFlag = toUnwrappedModel(mbMessageFlag);
315    
316                    Session session = null;
317    
318                    try {
319                            session = openSession();
320    
321                            if (mbMessageFlag.isCachedModel() || BatchSessionUtil.isEnabled()) {
322                                    Object staleObject = session.get(MBMessageFlagImpl.class,
323                                                    mbMessageFlag.getPrimaryKeyObj());
324    
325                                    if (staleObject != null) {
326                                            session.evict(staleObject);
327                                    }
328                            }
329    
330                            session.delete(mbMessageFlag);
331    
332                            session.flush();
333                    }
334                    catch (Exception e) {
335                            throw processException(e);
336                    }
337                    finally {
338                            closeSession(session);
339                    }
340    
341                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
342    
343                    MBMessageFlagModelImpl mbMessageFlagModelImpl = (MBMessageFlagModelImpl)mbMessageFlag;
344    
345                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
346                            new Object[] {
347                                    new Long(mbMessageFlagModelImpl.getOriginalUserId()),
348                                    new Long(mbMessageFlagModelImpl.getOriginalMessageId()),
349                                    new Integer(mbMessageFlagModelImpl.getOriginalFlag())
350                            });
351    
352                    EntityCacheUtil.removeResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
353                            MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey());
354    
355                    return mbMessageFlag;
356            }
357    
358            public MBMessageFlag updateImpl(
359                    com.liferay.portlet.messageboards.model.MBMessageFlag mbMessageFlag,
360                    boolean merge) throws SystemException {
361                    mbMessageFlag = toUnwrappedModel(mbMessageFlag);
362    
363                    boolean isNew = mbMessageFlag.isNew();
364    
365                    MBMessageFlagModelImpl mbMessageFlagModelImpl = (MBMessageFlagModelImpl)mbMessageFlag;
366    
367                    Session session = null;
368    
369                    try {
370                            session = openSession();
371    
372                            BatchSessionUtil.update(session, mbMessageFlag, merge);
373    
374                            mbMessageFlag.setNew(false);
375                    }
376                    catch (Exception e) {
377                            throw processException(e);
378                    }
379                    finally {
380                            closeSession(session);
381                    }
382    
383                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
384    
385                    EntityCacheUtil.putResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
386                            MBMessageFlagImpl.class, mbMessageFlag.getPrimaryKey(),
387                            mbMessageFlag);
388    
389                    if (!isNew &&
390                                    ((mbMessageFlag.getUserId() != mbMessageFlagModelImpl.getOriginalUserId()) ||
391                                    (mbMessageFlag.getMessageId() != mbMessageFlagModelImpl.getOriginalMessageId()) ||
392                                    (mbMessageFlag.getFlag() != mbMessageFlagModelImpl.getOriginalFlag()))) {
393                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_M_F,
394                                    new Object[] {
395                                            new Long(mbMessageFlagModelImpl.getOriginalUserId()),
396                                            new Long(mbMessageFlagModelImpl.getOriginalMessageId()),
397                                            new Integer(mbMessageFlagModelImpl.getOriginalFlag())
398                                    });
399                    }
400    
401                    if (isNew ||
402                                    ((mbMessageFlag.getUserId() != mbMessageFlagModelImpl.getOriginalUserId()) ||
403                                    (mbMessageFlag.getMessageId() != mbMessageFlagModelImpl.getOriginalMessageId()) ||
404                                    (mbMessageFlag.getFlag() != mbMessageFlagModelImpl.getOriginalFlag()))) {
405                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
406                                    new Object[] {
407                                            new Long(mbMessageFlag.getUserId()),
408                                            new Long(mbMessageFlag.getMessageId()),
409                                            new Integer(mbMessageFlag.getFlag())
410                                    }, mbMessageFlag);
411                    }
412    
413                    return mbMessageFlag;
414            }
415    
416            protected MBMessageFlag toUnwrappedModel(MBMessageFlag mbMessageFlag) {
417                    if (mbMessageFlag instanceof MBMessageFlagImpl) {
418                            return mbMessageFlag;
419                    }
420    
421                    MBMessageFlagImpl mbMessageFlagImpl = new MBMessageFlagImpl();
422    
423                    mbMessageFlagImpl.setNew(mbMessageFlag.isNew());
424                    mbMessageFlagImpl.setPrimaryKey(mbMessageFlag.getPrimaryKey());
425    
426                    mbMessageFlagImpl.setMessageFlagId(mbMessageFlag.getMessageFlagId());
427                    mbMessageFlagImpl.setUserId(mbMessageFlag.getUserId());
428                    mbMessageFlagImpl.setModifiedDate(mbMessageFlag.getModifiedDate());
429                    mbMessageFlagImpl.setThreadId(mbMessageFlag.getThreadId());
430                    mbMessageFlagImpl.setMessageId(mbMessageFlag.getMessageId());
431                    mbMessageFlagImpl.setFlag(mbMessageFlag.getFlag());
432    
433                    return mbMessageFlagImpl;
434            }
435    
436            /**
437             * Finds the message boards message flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
438             *
439             * @param primaryKey the primary key of the message boards message flag to find
440             * @return the message boards message flag
441             * @throws com.liferay.portal.NoSuchModelException if a message boards message flag with the primary key could not be found
442             * @throws SystemException if a system exception occurred
443             */
444            public MBMessageFlag findByPrimaryKey(Serializable primaryKey)
445                    throws NoSuchModelException, SystemException {
446                    return findByPrimaryKey(((Long)primaryKey).longValue());
447            }
448    
449            /**
450             * Finds the message boards message flag with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageFlagException} if it could not be found.
451             *
452             * @param messageFlagId the primary key of the message boards message flag to find
453             * @return the message boards message flag
454             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
455             * @throws SystemException if a system exception occurred
456             */
457            public MBMessageFlag findByPrimaryKey(long messageFlagId)
458                    throws NoSuchMessageFlagException, SystemException {
459                    MBMessageFlag mbMessageFlag = fetchByPrimaryKey(messageFlagId);
460    
461                    if (mbMessageFlag == null) {
462                            if (_log.isWarnEnabled()) {
463                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + messageFlagId);
464                            }
465    
466                            throw new NoSuchMessageFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
467                                    messageFlagId);
468                    }
469    
470                    return mbMessageFlag;
471            }
472    
473            /**
474             * Finds the message boards message flag with the primary key or returns <code>null</code> if it could not be found.
475             *
476             * @param primaryKey the primary key of the message boards message flag to find
477             * @return the message boards message flag, or <code>null</code> if a message boards message flag with the primary key could not be found
478             * @throws SystemException if a system exception occurred
479             */
480            public MBMessageFlag fetchByPrimaryKey(Serializable primaryKey)
481                    throws SystemException {
482                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
483            }
484    
485            /**
486             * Finds the message boards message flag with the primary key or returns <code>null</code> if it could not be found.
487             *
488             * @param messageFlagId the primary key of the message boards message flag to find
489             * @return the message boards message flag, or <code>null</code> if a message boards message flag with the primary key could not be found
490             * @throws SystemException if a system exception occurred
491             */
492            public MBMessageFlag fetchByPrimaryKey(long messageFlagId)
493                    throws SystemException {
494                    MBMessageFlag mbMessageFlag = (MBMessageFlag)EntityCacheUtil.getResult(MBMessageFlagModelImpl.ENTITY_CACHE_ENABLED,
495                                    MBMessageFlagImpl.class, messageFlagId, this);
496    
497                    if (mbMessageFlag == null) {
498                            Session session = null;
499    
500                            try {
501                                    session = openSession();
502    
503                                    mbMessageFlag = (MBMessageFlag)session.get(MBMessageFlagImpl.class,
504                                                    new Long(messageFlagId));
505                            }
506                            catch (Exception e) {
507                                    throw processException(e);
508                            }
509                            finally {
510                                    if (mbMessageFlag != null) {
511                                            cacheResult(mbMessageFlag);
512                                    }
513    
514                                    closeSession(session);
515                            }
516                    }
517    
518                    return mbMessageFlag;
519            }
520    
521            /**
522             * Finds all the message boards message flags where userId = &#63;.
523             *
524             * @param userId the user id to search with
525             * @return the matching message boards message flags
526             * @throws SystemException if a system exception occurred
527             */
528            public List<MBMessageFlag> findByUserId(long userId)
529                    throws SystemException {
530                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
531            }
532    
533            /**
534             * Finds a range of all the message boards message flags where userId = &#63;.
535             *
536             * <p>
537             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
538             * </p>
539             *
540             * @param userId the user id to search with
541             * @param start the lower bound of the range of message boards message flags to return
542             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
543             * @return the range of matching message boards message flags
544             * @throws SystemException if a system exception occurred
545             */
546            public List<MBMessageFlag> findByUserId(long userId, int start, int end)
547                    throws SystemException {
548                    return findByUserId(userId, start, end, null);
549            }
550    
551            /**
552             * Finds an ordered range of all the message boards message flags where userId = &#63;.
553             *
554             * <p>
555             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
556             * </p>
557             *
558             * @param userId the user id to search with
559             * @param start the lower bound of the range of message boards message flags to return
560             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
561             * @param orderByComparator the comparator to order the results by
562             * @return the ordered range of matching message boards message flags
563             * @throws SystemException if a system exception occurred
564             */
565            public List<MBMessageFlag> findByUserId(long userId, int start, int end,
566                    OrderByComparator orderByComparator) throws SystemException {
567                    Object[] finderArgs = new Object[] {
568                                    userId,
569                                    
570                                    String.valueOf(start), String.valueOf(end),
571                                    String.valueOf(orderByComparator)
572                            };
573    
574                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
575                                    finderArgs, this);
576    
577                    if (list == null) {
578                            Session session = null;
579    
580                            try {
581                                    session = openSession();
582    
583                                    StringBundler query = null;
584    
585                                    if (orderByComparator != null) {
586                                            query = new StringBundler(3 +
587                                                            (orderByComparator.getOrderByFields().length * 3));
588                                    }
589                                    else {
590                                            query = new StringBundler(2);
591                                    }
592    
593                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
594    
595                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
596    
597                                    if (orderByComparator != null) {
598                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
599                                                    orderByComparator);
600                                    }
601    
602                                    String sql = query.toString();
603    
604                                    Query q = session.createQuery(sql);
605    
606                                    QueryPos qPos = QueryPos.getInstance(q);
607    
608                                    qPos.add(userId);
609    
610                                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
611                                                    start, end);
612                            }
613                            catch (Exception e) {
614                                    throw processException(e);
615                            }
616                            finally {
617                                    if (list == null) {
618                                            list = new ArrayList<MBMessageFlag>();
619                                    }
620    
621                                    cacheResult(list);
622    
623                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
624                                            finderArgs, list);
625    
626                                    closeSession(session);
627                            }
628                    }
629    
630                    return list;
631            }
632    
633            /**
634             * Finds the first message boards message flag in the ordered set where userId = &#63;.
635             *
636             * <p>
637             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
638             * </p>
639             *
640             * @param userId the user id to search with
641             * @param orderByComparator the comparator to order the set by
642             * @return the first matching message boards message flag
643             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
644             * @throws SystemException if a system exception occurred
645             */
646            public MBMessageFlag findByUserId_First(long userId,
647                    OrderByComparator orderByComparator)
648                    throws NoSuchMessageFlagException, SystemException {
649                    List<MBMessageFlag> list = findByUserId(userId, 0, 1, orderByComparator);
650    
651                    if (list.isEmpty()) {
652                            StringBundler msg = new StringBundler(4);
653    
654                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
655    
656                            msg.append("userId=");
657                            msg.append(userId);
658    
659                            msg.append(StringPool.CLOSE_CURLY_BRACE);
660    
661                            throw new NoSuchMessageFlagException(msg.toString());
662                    }
663                    else {
664                            return list.get(0);
665                    }
666            }
667    
668            /**
669             * Finds the last message boards message flag in the ordered set where userId = &#63;.
670             *
671             * <p>
672             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
673             * </p>
674             *
675             * @param userId the user id to search with
676             * @param orderByComparator the comparator to order the set by
677             * @return the last matching message boards message flag
678             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
679             * @throws SystemException if a system exception occurred
680             */
681            public MBMessageFlag findByUserId_Last(long userId,
682                    OrderByComparator orderByComparator)
683                    throws NoSuchMessageFlagException, SystemException {
684                    int count = countByUserId(userId);
685    
686                    List<MBMessageFlag> list = findByUserId(userId, count - 1, count,
687                                    orderByComparator);
688    
689                    if (list.isEmpty()) {
690                            StringBundler msg = new StringBundler(4);
691    
692                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
693    
694                            msg.append("userId=");
695                            msg.append(userId);
696    
697                            msg.append(StringPool.CLOSE_CURLY_BRACE);
698    
699                            throw new NoSuchMessageFlagException(msg.toString());
700                    }
701                    else {
702                            return list.get(0);
703                    }
704            }
705    
706            /**
707             * Finds the message boards message flags before and after the current message boards message flag in the ordered set where userId = &#63;.
708             *
709             * <p>
710             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
711             * </p>
712             *
713             * @param messageFlagId the primary key of the current message boards message flag
714             * @param userId the user id to search with
715             * @param orderByComparator the comparator to order the set by
716             * @return the previous, current, and next message boards message flag
717             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
718             * @throws SystemException if a system exception occurred
719             */
720            public MBMessageFlag[] findByUserId_PrevAndNext(long messageFlagId,
721                    long userId, OrderByComparator orderByComparator)
722                    throws NoSuchMessageFlagException, SystemException {
723                    MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
724    
725                    Session session = null;
726    
727                    try {
728                            session = openSession();
729    
730                            MBMessageFlag[] array = new MBMessageFlagImpl[3];
731    
732                            array[0] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
733                                            orderByComparator, true);
734    
735                            array[1] = mbMessageFlag;
736    
737                            array[2] = getByUserId_PrevAndNext(session, mbMessageFlag, userId,
738                                            orderByComparator, false);
739    
740                            return array;
741                    }
742                    catch (Exception e) {
743                            throw processException(e);
744                    }
745                    finally {
746                            closeSession(session);
747                    }
748            }
749    
750            protected MBMessageFlag getByUserId_PrevAndNext(Session session,
751                    MBMessageFlag mbMessageFlag, long userId,
752                    OrderByComparator orderByComparator, boolean previous) {
753                    StringBundler query = null;
754    
755                    if (orderByComparator != null) {
756                            query = new StringBundler(6 +
757                                            (orderByComparator.getOrderByFields().length * 6));
758                    }
759                    else {
760                            query = new StringBundler(3);
761                    }
762    
763                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
764    
765                    query.append(_FINDER_COLUMN_USERID_USERID_2);
766    
767                    if (orderByComparator != null) {
768                            String[] orderByFields = orderByComparator.getOrderByFields();
769    
770                            if (orderByFields.length > 0) {
771                                    query.append(WHERE_AND);
772                            }
773    
774                            for (int i = 0; i < orderByFields.length; i++) {
775                                    query.append(_ORDER_BY_ENTITY_ALIAS);
776                                    query.append(orderByFields[i]);
777    
778                                    if ((i + 1) < orderByFields.length) {
779                                            if (orderByComparator.isAscending() ^ previous) {
780                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
781                                            }
782                                            else {
783                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
784                                            }
785                                    }
786                                    else {
787                                            if (orderByComparator.isAscending() ^ previous) {
788                                                    query.append(WHERE_GREATER_THAN);
789                                            }
790                                            else {
791                                                    query.append(WHERE_LESSER_THAN);
792                                            }
793                                    }
794                            }
795    
796                            query.append(ORDER_BY_CLAUSE);
797    
798                            for (int i = 0; i < orderByFields.length; i++) {
799                                    query.append(_ORDER_BY_ENTITY_ALIAS);
800                                    query.append(orderByFields[i]);
801    
802                                    if ((i + 1) < orderByFields.length) {
803                                            if (orderByComparator.isAscending() ^ previous) {
804                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
805                                            }
806                                            else {
807                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
808                                            }
809                                    }
810                                    else {
811                                            if (orderByComparator.isAscending() ^ previous) {
812                                                    query.append(ORDER_BY_ASC);
813                                            }
814                                            else {
815                                                    query.append(ORDER_BY_DESC);
816                                            }
817                                    }
818                            }
819                    }
820    
821                    String sql = query.toString();
822    
823                    Query q = session.createQuery(sql);
824    
825                    q.setFirstResult(0);
826                    q.setMaxResults(2);
827    
828                    QueryPos qPos = QueryPos.getInstance(q);
829    
830                    qPos.add(userId);
831    
832                    if (orderByComparator != null) {
833                            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
834    
835                            for (Object value : values) {
836                                    qPos.add(value);
837                            }
838                    }
839    
840                    List<MBMessageFlag> list = q.list();
841    
842                    if (list.size() == 2) {
843                            return list.get(1);
844                    }
845                    else {
846                            return null;
847                    }
848            }
849    
850            /**
851             * Finds all the message boards message flags where threadId = &#63;.
852             *
853             * @param threadId the thread id to search with
854             * @return the matching message boards message flags
855             * @throws SystemException if a system exception occurred
856             */
857            public List<MBMessageFlag> findByThreadId(long threadId)
858                    throws SystemException {
859                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
860                            null);
861            }
862    
863            /**
864             * Finds a range of all the message boards message flags where threadId = &#63;.
865             *
866             * <p>
867             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
868             * </p>
869             *
870             * @param threadId the thread id to search with
871             * @param start the lower bound of the range of message boards message flags to return
872             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
873             * @return the range of matching message boards message flags
874             * @throws SystemException if a system exception occurred
875             */
876            public List<MBMessageFlag> findByThreadId(long threadId, int start, int end)
877                    throws SystemException {
878                    return findByThreadId(threadId, start, end, null);
879            }
880    
881            /**
882             * Finds an ordered range of all the message boards message flags where threadId = &#63;.
883             *
884             * <p>
885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
886             * </p>
887             *
888             * @param threadId the thread id to search with
889             * @param start the lower bound of the range of message boards message flags to return
890             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
891             * @param orderByComparator the comparator to order the results by
892             * @return the ordered range of matching message boards message flags
893             * @throws SystemException if a system exception occurred
894             */
895            public List<MBMessageFlag> findByThreadId(long threadId, int start,
896                    int end, OrderByComparator orderByComparator) throws SystemException {
897                    Object[] finderArgs = new Object[] {
898                                    threadId,
899                                    
900                                    String.valueOf(start), String.valueOf(end),
901                                    String.valueOf(orderByComparator)
902                            };
903    
904                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_THREADID,
905                                    finderArgs, this);
906    
907                    if (list == null) {
908                            Session session = null;
909    
910                            try {
911                                    session = openSession();
912    
913                                    StringBundler query = null;
914    
915                                    if (orderByComparator != null) {
916                                            query = new StringBundler(3 +
917                                                            (orderByComparator.getOrderByFields().length * 3));
918                                    }
919                                    else {
920                                            query = new StringBundler(2);
921                                    }
922    
923                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
924    
925                                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
926    
927                                    if (orderByComparator != null) {
928                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
929                                                    orderByComparator);
930                                    }
931    
932                                    String sql = query.toString();
933    
934                                    Query q = session.createQuery(sql);
935    
936                                    QueryPos qPos = QueryPos.getInstance(q);
937    
938                                    qPos.add(threadId);
939    
940                                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
941                                                    start, end);
942                            }
943                            catch (Exception e) {
944                                    throw processException(e);
945                            }
946                            finally {
947                                    if (list == null) {
948                                            list = new ArrayList<MBMessageFlag>();
949                                    }
950    
951                                    cacheResult(list);
952    
953                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_THREADID,
954                                            finderArgs, list);
955    
956                                    closeSession(session);
957                            }
958                    }
959    
960                    return list;
961            }
962    
963            /**
964             * Finds the first message boards message flag in the ordered set where threadId = &#63;.
965             *
966             * <p>
967             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
968             * </p>
969             *
970             * @param threadId the thread id to search with
971             * @param orderByComparator the comparator to order the set by
972             * @return the first matching message boards message flag
973             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
974             * @throws SystemException if a system exception occurred
975             */
976            public MBMessageFlag findByThreadId_First(long threadId,
977                    OrderByComparator orderByComparator)
978                    throws NoSuchMessageFlagException, SystemException {
979                    List<MBMessageFlag> list = findByThreadId(threadId, 0, 1,
980                                    orderByComparator);
981    
982                    if (list.isEmpty()) {
983                            StringBundler msg = new StringBundler(4);
984    
985                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
986    
987                            msg.append("threadId=");
988                            msg.append(threadId);
989    
990                            msg.append(StringPool.CLOSE_CURLY_BRACE);
991    
992                            throw new NoSuchMessageFlagException(msg.toString());
993                    }
994                    else {
995                            return list.get(0);
996                    }
997            }
998    
999            /**
1000             * Finds the last message boards message flag in the ordered set where threadId = &#63;.
1001             *
1002             * <p>
1003             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1004             * </p>
1005             *
1006             * @param threadId the thread id to search with
1007             * @param orderByComparator the comparator to order the set by
1008             * @return the last matching message boards message flag
1009             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
1010             * @throws SystemException if a system exception occurred
1011             */
1012            public MBMessageFlag findByThreadId_Last(long threadId,
1013                    OrderByComparator orderByComparator)
1014                    throws NoSuchMessageFlagException, SystemException {
1015                    int count = countByThreadId(threadId);
1016    
1017                    List<MBMessageFlag> list = findByThreadId(threadId, count - 1, count,
1018                                    orderByComparator);
1019    
1020                    if (list.isEmpty()) {
1021                            StringBundler msg = new StringBundler(4);
1022    
1023                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1024    
1025                            msg.append("threadId=");
1026                            msg.append(threadId);
1027    
1028                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1029    
1030                            throw new NoSuchMessageFlagException(msg.toString());
1031                    }
1032                    else {
1033                            return list.get(0);
1034                    }
1035            }
1036    
1037            /**
1038             * Finds the message boards message flags before and after the current message boards message flag in the ordered set where threadId = &#63;.
1039             *
1040             * <p>
1041             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1042             * </p>
1043             *
1044             * @param messageFlagId the primary key of the current message boards message flag
1045             * @param threadId the thread id to search with
1046             * @param orderByComparator the comparator to order the set by
1047             * @return the previous, current, and next message boards message flag
1048             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
1049             * @throws SystemException if a system exception occurred
1050             */
1051            public MBMessageFlag[] findByThreadId_PrevAndNext(long messageFlagId,
1052                    long threadId, OrderByComparator orderByComparator)
1053                    throws NoSuchMessageFlagException, SystemException {
1054                    MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1055    
1056                    Session session = null;
1057    
1058                    try {
1059                            session = openSession();
1060    
1061                            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1062    
1063                            array[0] = getByThreadId_PrevAndNext(session, mbMessageFlag,
1064                                            threadId, orderByComparator, true);
1065    
1066                            array[1] = mbMessageFlag;
1067    
1068                            array[2] = getByThreadId_PrevAndNext(session, mbMessageFlag,
1069                                            threadId, orderByComparator, false);
1070    
1071                            return array;
1072                    }
1073                    catch (Exception e) {
1074                            throw processException(e);
1075                    }
1076                    finally {
1077                            closeSession(session);
1078                    }
1079            }
1080    
1081            protected MBMessageFlag getByThreadId_PrevAndNext(Session session,
1082                    MBMessageFlag mbMessageFlag, long threadId,
1083                    OrderByComparator orderByComparator, boolean previous) {
1084                    StringBundler query = null;
1085    
1086                    if (orderByComparator != null) {
1087                            query = new StringBundler(6 +
1088                                            (orderByComparator.getOrderByFields().length * 6));
1089                    }
1090                    else {
1091                            query = new StringBundler(3);
1092                    }
1093    
1094                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1095    
1096                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1097    
1098                    if (orderByComparator != null) {
1099                            String[] orderByFields = orderByComparator.getOrderByFields();
1100    
1101                            if (orderByFields.length > 0) {
1102                                    query.append(WHERE_AND);
1103                            }
1104    
1105                            for (int i = 0; i < orderByFields.length; i++) {
1106                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1107                                    query.append(orderByFields[i]);
1108    
1109                                    if ((i + 1) < orderByFields.length) {
1110                                            if (orderByComparator.isAscending() ^ previous) {
1111                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1112                                            }
1113                                            else {
1114                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1115                                            }
1116                                    }
1117                                    else {
1118                                            if (orderByComparator.isAscending() ^ previous) {
1119                                                    query.append(WHERE_GREATER_THAN);
1120                                            }
1121                                            else {
1122                                                    query.append(WHERE_LESSER_THAN);
1123                                            }
1124                                    }
1125                            }
1126    
1127                            query.append(ORDER_BY_CLAUSE);
1128    
1129                            for (int i = 0; i < orderByFields.length; i++) {
1130                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1131                                    query.append(orderByFields[i]);
1132    
1133                                    if ((i + 1) < orderByFields.length) {
1134                                            if (orderByComparator.isAscending() ^ previous) {
1135                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1136                                            }
1137                                            else {
1138                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1139                                            }
1140                                    }
1141                                    else {
1142                                            if (orderByComparator.isAscending() ^ previous) {
1143                                                    query.append(ORDER_BY_ASC);
1144                                            }
1145                                            else {
1146                                                    query.append(ORDER_BY_DESC);
1147                                            }
1148                                    }
1149                            }
1150                    }
1151    
1152                    String sql = query.toString();
1153    
1154                    Query q = session.createQuery(sql);
1155    
1156                    q.setFirstResult(0);
1157                    q.setMaxResults(2);
1158    
1159                    QueryPos qPos = QueryPos.getInstance(q);
1160    
1161                    qPos.add(threadId);
1162    
1163                    if (orderByComparator != null) {
1164                            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1165    
1166                            for (Object value : values) {
1167                                    qPos.add(value);
1168                            }
1169                    }
1170    
1171                    List<MBMessageFlag> list = q.list();
1172    
1173                    if (list.size() == 2) {
1174                            return list.get(1);
1175                    }
1176                    else {
1177                            return null;
1178                    }
1179            }
1180    
1181            /**
1182             * Finds all the message boards message flags where messageId = &#63;.
1183             *
1184             * @param messageId the message id to search with
1185             * @return the matching message boards message flags
1186             * @throws SystemException if a system exception occurred
1187             */
1188            public List<MBMessageFlag> findByMessageId(long messageId)
1189                    throws SystemException {
1190                    return findByMessageId(messageId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1191                            null);
1192            }
1193    
1194            /**
1195             * Finds a range of all the message boards message flags where messageId = &#63;.
1196             *
1197             * <p>
1198             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1199             * </p>
1200             *
1201             * @param messageId the message id to search with
1202             * @param start the lower bound of the range of message boards message flags to return
1203             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
1204             * @return the range of matching message boards message flags
1205             * @throws SystemException if a system exception occurred
1206             */
1207            public List<MBMessageFlag> findByMessageId(long messageId, int start,
1208                    int end) throws SystemException {
1209                    return findByMessageId(messageId, start, end, null);
1210            }
1211    
1212            /**
1213             * Finds an ordered range of all the message boards message flags where messageId = &#63;.
1214             *
1215             * <p>
1216             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1217             * </p>
1218             *
1219             * @param messageId the message id to search with
1220             * @param start the lower bound of the range of message boards message flags to return
1221             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
1222             * @param orderByComparator the comparator to order the results by
1223             * @return the ordered range of matching message boards message flags
1224             * @throws SystemException if a system exception occurred
1225             */
1226            public List<MBMessageFlag> findByMessageId(long messageId, int start,
1227                    int end, OrderByComparator orderByComparator) throws SystemException {
1228                    Object[] finderArgs = new Object[] {
1229                                    messageId,
1230                                    
1231                                    String.valueOf(start), String.valueOf(end),
1232                                    String.valueOf(orderByComparator)
1233                            };
1234    
1235                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_MESSAGEID,
1236                                    finderArgs, this);
1237    
1238                    if (list == null) {
1239                            Session session = null;
1240    
1241                            try {
1242                                    session = openSession();
1243    
1244                                    StringBundler query = null;
1245    
1246                                    if (orderByComparator != null) {
1247                                            query = new StringBundler(3 +
1248                                                            (orderByComparator.getOrderByFields().length * 3));
1249                                    }
1250                                    else {
1251                                            query = new StringBundler(2);
1252                                    }
1253    
1254                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1255    
1256                                    query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1257    
1258                                    if (orderByComparator != null) {
1259                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1260                                                    orderByComparator);
1261                                    }
1262    
1263                                    String sql = query.toString();
1264    
1265                                    Query q = session.createQuery(sql);
1266    
1267                                    QueryPos qPos = QueryPos.getInstance(q);
1268    
1269                                    qPos.add(messageId);
1270    
1271                                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1272                                                    start, end);
1273                            }
1274                            catch (Exception e) {
1275                                    throw processException(e);
1276                            }
1277                            finally {
1278                                    if (list == null) {
1279                                            list = new ArrayList<MBMessageFlag>();
1280                                    }
1281    
1282                                    cacheResult(list);
1283    
1284                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_MESSAGEID,
1285                                            finderArgs, list);
1286    
1287                                    closeSession(session);
1288                            }
1289                    }
1290    
1291                    return list;
1292            }
1293    
1294            /**
1295             * Finds the first message boards message flag in the ordered set where messageId = &#63;.
1296             *
1297             * <p>
1298             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1299             * </p>
1300             *
1301             * @param messageId the message id to search with
1302             * @param orderByComparator the comparator to order the set by
1303             * @return the first matching message boards message flag
1304             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
1305             * @throws SystemException if a system exception occurred
1306             */
1307            public MBMessageFlag findByMessageId_First(long messageId,
1308                    OrderByComparator orderByComparator)
1309                    throws NoSuchMessageFlagException, SystemException {
1310                    List<MBMessageFlag> list = findByMessageId(messageId, 0, 1,
1311                                    orderByComparator);
1312    
1313                    if (list.isEmpty()) {
1314                            StringBundler msg = new StringBundler(4);
1315    
1316                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1317    
1318                            msg.append("messageId=");
1319                            msg.append(messageId);
1320    
1321                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1322    
1323                            throw new NoSuchMessageFlagException(msg.toString());
1324                    }
1325                    else {
1326                            return list.get(0);
1327                    }
1328            }
1329    
1330            /**
1331             * Finds the last message boards message flag in the ordered set where messageId = &#63;.
1332             *
1333             * <p>
1334             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1335             * </p>
1336             *
1337             * @param messageId the message id to search with
1338             * @param orderByComparator the comparator to order the set by
1339             * @return the last matching message boards message flag
1340             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
1341             * @throws SystemException if a system exception occurred
1342             */
1343            public MBMessageFlag findByMessageId_Last(long messageId,
1344                    OrderByComparator orderByComparator)
1345                    throws NoSuchMessageFlagException, SystemException {
1346                    int count = countByMessageId(messageId);
1347    
1348                    List<MBMessageFlag> list = findByMessageId(messageId, count - 1, count,
1349                                    orderByComparator);
1350    
1351                    if (list.isEmpty()) {
1352                            StringBundler msg = new StringBundler(4);
1353    
1354                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1355    
1356                            msg.append("messageId=");
1357                            msg.append(messageId);
1358    
1359                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1360    
1361                            throw new NoSuchMessageFlagException(msg.toString());
1362                    }
1363                    else {
1364                            return list.get(0);
1365                    }
1366            }
1367    
1368            /**
1369             * Finds the message boards message flags before and after the current message boards message flag in the ordered set where messageId = &#63;.
1370             *
1371             * <p>
1372             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1373             * </p>
1374             *
1375             * @param messageFlagId the primary key of the current message boards message flag
1376             * @param messageId the message id to search with
1377             * @param orderByComparator the comparator to order the set by
1378             * @return the previous, current, and next message boards message flag
1379             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
1380             * @throws SystemException if a system exception occurred
1381             */
1382            public MBMessageFlag[] findByMessageId_PrevAndNext(long messageFlagId,
1383                    long messageId, OrderByComparator orderByComparator)
1384                    throws NoSuchMessageFlagException, SystemException {
1385                    MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1386    
1387                    Session session = null;
1388    
1389                    try {
1390                            session = openSession();
1391    
1392                            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1393    
1394                            array[0] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1395                                            messageId, orderByComparator, true);
1396    
1397                            array[1] = mbMessageFlag;
1398    
1399                            array[2] = getByMessageId_PrevAndNext(session, mbMessageFlag,
1400                                            messageId, orderByComparator, false);
1401    
1402                            return array;
1403                    }
1404                    catch (Exception e) {
1405                            throw processException(e);
1406                    }
1407                    finally {
1408                            closeSession(session);
1409                    }
1410            }
1411    
1412            protected MBMessageFlag getByMessageId_PrevAndNext(Session session,
1413                    MBMessageFlag mbMessageFlag, long messageId,
1414                    OrderByComparator orderByComparator, boolean previous) {
1415                    StringBundler query = null;
1416    
1417                    if (orderByComparator != null) {
1418                            query = new StringBundler(6 +
1419                                            (orderByComparator.getOrderByFields().length * 6));
1420                    }
1421                    else {
1422                            query = new StringBundler(3);
1423                    }
1424    
1425                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1426    
1427                    query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
1428    
1429                    if (orderByComparator != null) {
1430                            String[] orderByFields = orderByComparator.getOrderByFields();
1431    
1432                            if (orderByFields.length > 0) {
1433                                    query.append(WHERE_AND);
1434                            }
1435    
1436                            for (int i = 0; i < orderByFields.length; i++) {
1437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1438                                    query.append(orderByFields[i]);
1439    
1440                                    if ((i + 1) < orderByFields.length) {
1441                                            if (orderByComparator.isAscending() ^ previous) {
1442                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1443                                            }
1444                                            else {
1445                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1446                                            }
1447                                    }
1448                                    else {
1449                                            if (orderByComparator.isAscending() ^ previous) {
1450                                                    query.append(WHERE_GREATER_THAN);
1451                                            }
1452                                            else {
1453                                                    query.append(WHERE_LESSER_THAN);
1454                                            }
1455                                    }
1456                            }
1457    
1458                            query.append(ORDER_BY_CLAUSE);
1459    
1460                            for (int i = 0; i < orderByFields.length; i++) {
1461                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1462                                    query.append(orderByFields[i]);
1463    
1464                                    if ((i + 1) < orderByFields.length) {
1465                                            if (orderByComparator.isAscending() ^ previous) {
1466                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1467                                            }
1468                                            else {
1469                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1470                                            }
1471                                    }
1472                                    else {
1473                                            if (orderByComparator.isAscending() ^ previous) {
1474                                                    query.append(ORDER_BY_ASC);
1475                                            }
1476                                            else {
1477                                                    query.append(ORDER_BY_DESC);
1478                                            }
1479                                    }
1480                            }
1481                    }
1482    
1483                    String sql = query.toString();
1484    
1485                    Query q = session.createQuery(sql);
1486    
1487                    q.setFirstResult(0);
1488                    q.setMaxResults(2);
1489    
1490                    QueryPos qPos = QueryPos.getInstance(q);
1491    
1492                    qPos.add(messageId);
1493    
1494                    if (orderByComparator != null) {
1495                            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1496    
1497                            for (Object value : values) {
1498                                    qPos.add(value);
1499                            }
1500                    }
1501    
1502                    List<MBMessageFlag> list = q.list();
1503    
1504                    if (list.size() == 2) {
1505                            return list.get(1);
1506                    }
1507                    else {
1508                            return null;
1509                    }
1510            }
1511    
1512            /**
1513             * Finds all the message boards message flags where threadId = &#63; and flag = &#63;.
1514             *
1515             * @param threadId the thread id to search with
1516             * @param flag the flag to search with
1517             * @return the matching message boards message flags
1518             * @throws SystemException if a system exception occurred
1519             */
1520            public List<MBMessageFlag> findByT_F(long threadId, int flag)
1521                    throws SystemException {
1522                    return findByT_F(threadId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1523                            null);
1524            }
1525    
1526            /**
1527             * Finds a range of all the message boards message flags where threadId = &#63; and flag = &#63;.
1528             *
1529             * <p>
1530             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1531             * </p>
1532             *
1533             * @param threadId the thread id to search with
1534             * @param flag the flag to search with
1535             * @param start the lower bound of the range of message boards message flags to return
1536             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
1537             * @return the range of matching message boards message flags
1538             * @throws SystemException if a system exception occurred
1539             */
1540            public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1541                    int end) throws SystemException {
1542                    return findByT_F(threadId, flag, start, end, null);
1543            }
1544    
1545            /**
1546             * Finds an ordered range of all the message boards message flags where threadId = &#63; and flag = &#63;.
1547             *
1548             * <p>
1549             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1550             * </p>
1551             *
1552             * @param threadId the thread id to search with
1553             * @param flag the flag to search with
1554             * @param start the lower bound of the range of message boards message flags to return
1555             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
1556             * @param orderByComparator the comparator to order the results by
1557             * @return the ordered range of matching message boards message flags
1558             * @throws SystemException if a system exception occurred
1559             */
1560            public List<MBMessageFlag> findByT_F(long threadId, int flag, int start,
1561                    int end, OrderByComparator orderByComparator) throws SystemException {
1562                    Object[] finderArgs = new Object[] {
1563                                    threadId, flag,
1564                                    
1565                                    String.valueOf(start), String.valueOf(end),
1566                                    String.valueOf(orderByComparator)
1567                            };
1568    
1569                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_F,
1570                                    finderArgs, this);
1571    
1572                    if (list == null) {
1573                            Session session = null;
1574    
1575                            try {
1576                                    session = openSession();
1577    
1578                                    StringBundler query = null;
1579    
1580                                    if (orderByComparator != null) {
1581                                            query = new StringBundler(4 +
1582                                                            (orderByComparator.getOrderByFields().length * 3));
1583                                    }
1584                                    else {
1585                                            query = new StringBundler(3);
1586                                    }
1587    
1588                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1589    
1590                                    query.append(_FINDER_COLUMN_T_F_THREADID_2);
1591    
1592                                    query.append(_FINDER_COLUMN_T_F_FLAG_2);
1593    
1594                                    if (orderByComparator != null) {
1595                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1596                                                    orderByComparator);
1597                                    }
1598    
1599                                    String sql = query.toString();
1600    
1601                                    Query q = session.createQuery(sql);
1602    
1603                                    QueryPos qPos = QueryPos.getInstance(q);
1604    
1605                                    qPos.add(threadId);
1606    
1607                                    qPos.add(flag);
1608    
1609                                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1610                                                    start, end);
1611                            }
1612                            catch (Exception e) {
1613                                    throw processException(e);
1614                            }
1615                            finally {
1616                                    if (list == null) {
1617                                            list = new ArrayList<MBMessageFlag>();
1618                                    }
1619    
1620                                    cacheResult(list);
1621    
1622                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_F, finderArgs,
1623                                            list);
1624    
1625                                    closeSession(session);
1626                            }
1627                    }
1628    
1629                    return list;
1630            }
1631    
1632            /**
1633             * Finds the first message boards message flag in the ordered set where threadId = &#63; and flag = &#63;.
1634             *
1635             * <p>
1636             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1637             * </p>
1638             *
1639             * @param threadId the thread id to search with
1640             * @param flag the flag to search with
1641             * @param orderByComparator the comparator to order the set by
1642             * @return the first matching message boards message flag
1643             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
1644             * @throws SystemException if a system exception occurred
1645             */
1646            public MBMessageFlag findByT_F_First(long threadId, int flag,
1647                    OrderByComparator orderByComparator)
1648                    throws NoSuchMessageFlagException, SystemException {
1649                    List<MBMessageFlag> list = findByT_F(threadId, flag, 0, 1,
1650                                    orderByComparator);
1651    
1652                    if (list.isEmpty()) {
1653                            StringBundler msg = new StringBundler(6);
1654    
1655                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1656    
1657                            msg.append("threadId=");
1658                            msg.append(threadId);
1659    
1660                            msg.append(", flag=");
1661                            msg.append(flag);
1662    
1663                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1664    
1665                            throw new NoSuchMessageFlagException(msg.toString());
1666                    }
1667                    else {
1668                            return list.get(0);
1669                    }
1670            }
1671    
1672            /**
1673             * Finds the last message boards message flag in the ordered set where threadId = &#63; and flag = &#63;.
1674             *
1675             * <p>
1676             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1677             * </p>
1678             *
1679             * @param threadId the thread id to search with
1680             * @param flag the flag to search with
1681             * @param orderByComparator the comparator to order the set by
1682             * @return the last matching message boards message flag
1683             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
1684             * @throws SystemException if a system exception occurred
1685             */
1686            public MBMessageFlag findByT_F_Last(long threadId, int flag,
1687                    OrderByComparator orderByComparator)
1688                    throws NoSuchMessageFlagException, SystemException {
1689                    int count = countByT_F(threadId, flag);
1690    
1691                    List<MBMessageFlag> list = findByT_F(threadId, flag, count - 1, count,
1692                                    orderByComparator);
1693    
1694                    if (list.isEmpty()) {
1695                            StringBundler msg = new StringBundler(6);
1696    
1697                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1698    
1699                            msg.append("threadId=");
1700                            msg.append(threadId);
1701    
1702                            msg.append(", flag=");
1703                            msg.append(flag);
1704    
1705                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1706    
1707                            throw new NoSuchMessageFlagException(msg.toString());
1708                    }
1709                    else {
1710                            return list.get(0);
1711                    }
1712            }
1713    
1714            /**
1715             * Finds the message boards message flags before and after the current message boards message flag in the ordered set where threadId = &#63; and flag = &#63;.
1716             *
1717             * <p>
1718             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1719             * </p>
1720             *
1721             * @param messageFlagId the primary key of the current message boards message flag
1722             * @param threadId the thread id to search with
1723             * @param flag the flag to search with
1724             * @param orderByComparator the comparator to order the set by
1725             * @return the previous, current, and next message boards message flag
1726             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
1727             * @throws SystemException if a system exception occurred
1728             */
1729            public MBMessageFlag[] findByT_F_PrevAndNext(long messageFlagId,
1730                    long threadId, int flag, OrderByComparator orderByComparator)
1731                    throws NoSuchMessageFlagException, SystemException {
1732                    MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
1733    
1734                    Session session = null;
1735    
1736                    try {
1737                            session = openSession();
1738    
1739                            MBMessageFlag[] array = new MBMessageFlagImpl[3];
1740    
1741                            array[0] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1742                                            flag, orderByComparator, true);
1743    
1744                            array[1] = mbMessageFlag;
1745    
1746                            array[2] = getByT_F_PrevAndNext(session, mbMessageFlag, threadId,
1747                                            flag, orderByComparator, false);
1748    
1749                            return array;
1750                    }
1751                    catch (Exception e) {
1752                            throw processException(e);
1753                    }
1754                    finally {
1755                            closeSession(session);
1756                    }
1757            }
1758    
1759            protected MBMessageFlag getByT_F_PrevAndNext(Session session,
1760                    MBMessageFlag mbMessageFlag, long threadId, int flag,
1761                    OrderByComparator orderByComparator, boolean previous) {
1762                    StringBundler query = null;
1763    
1764                    if (orderByComparator != null) {
1765                            query = new StringBundler(6 +
1766                                            (orderByComparator.getOrderByFields().length * 6));
1767                    }
1768                    else {
1769                            query = new StringBundler(3);
1770                    }
1771    
1772                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1773    
1774                    query.append(_FINDER_COLUMN_T_F_THREADID_2);
1775    
1776                    query.append(_FINDER_COLUMN_T_F_FLAG_2);
1777    
1778                    if (orderByComparator != null) {
1779                            String[] orderByFields = orderByComparator.getOrderByFields();
1780    
1781                            if (orderByFields.length > 0) {
1782                                    query.append(WHERE_AND);
1783                            }
1784    
1785                            for (int i = 0; i < orderByFields.length; i++) {
1786                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1787                                    query.append(orderByFields[i]);
1788    
1789                                    if ((i + 1) < orderByFields.length) {
1790                                            if (orderByComparator.isAscending() ^ previous) {
1791                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1792                                            }
1793                                            else {
1794                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1795                                            }
1796                                    }
1797                                    else {
1798                                            if (orderByComparator.isAscending() ^ previous) {
1799                                                    query.append(WHERE_GREATER_THAN);
1800                                            }
1801                                            else {
1802                                                    query.append(WHERE_LESSER_THAN);
1803                                            }
1804                                    }
1805                            }
1806    
1807                            query.append(ORDER_BY_CLAUSE);
1808    
1809                            for (int i = 0; i < orderByFields.length; i++) {
1810                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1811                                    query.append(orderByFields[i]);
1812    
1813                                    if ((i + 1) < orderByFields.length) {
1814                                            if (orderByComparator.isAscending() ^ previous) {
1815                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1816                                            }
1817                                            else {
1818                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1819                                            }
1820                                    }
1821                                    else {
1822                                            if (orderByComparator.isAscending() ^ previous) {
1823                                                    query.append(ORDER_BY_ASC);
1824                                            }
1825                                            else {
1826                                                    query.append(ORDER_BY_DESC);
1827                                            }
1828                                    }
1829                            }
1830                    }
1831    
1832                    String sql = query.toString();
1833    
1834                    Query q = session.createQuery(sql);
1835    
1836                    q.setFirstResult(0);
1837                    q.setMaxResults(2);
1838    
1839                    QueryPos qPos = QueryPos.getInstance(q);
1840    
1841                    qPos.add(threadId);
1842    
1843                    qPos.add(flag);
1844    
1845                    if (orderByComparator != null) {
1846                            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
1847    
1848                            for (Object value : values) {
1849                                    qPos.add(value);
1850                            }
1851                    }
1852    
1853                    List<MBMessageFlag> list = q.list();
1854    
1855                    if (list.size() == 2) {
1856                            return list.get(1);
1857                    }
1858                    else {
1859                            return null;
1860                    }
1861            }
1862    
1863            /**
1864             * Finds all the message boards message flags where messageId = &#63; and flag = &#63;.
1865             *
1866             * @param messageId the message id to search with
1867             * @param flag the flag to search with
1868             * @return the matching message boards message flags
1869             * @throws SystemException if a system exception occurred
1870             */
1871            public List<MBMessageFlag> findByM_F(long messageId, int flag)
1872                    throws SystemException {
1873                    return findByM_F(messageId, flag, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1874                            null);
1875            }
1876    
1877            /**
1878             * Finds a range of all the message boards message flags where messageId = &#63; and flag = &#63;.
1879             *
1880             * <p>
1881             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1882             * </p>
1883             *
1884             * @param messageId the message id to search with
1885             * @param flag the flag to search with
1886             * @param start the lower bound of the range of message boards message flags to return
1887             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
1888             * @return the range of matching message boards message flags
1889             * @throws SystemException if a system exception occurred
1890             */
1891            public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1892                    int end) throws SystemException {
1893                    return findByM_F(messageId, flag, start, end, null);
1894            }
1895    
1896            /**
1897             * Finds an ordered range of all the message boards message flags where messageId = &#63; and flag = &#63;.
1898             *
1899             * <p>
1900             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1901             * </p>
1902             *
1903             * @param messageId the message id to search with
1904             * @param flag the flag to search with
1905             * @param start the lower bound of the range of message boards message flags to return
1906             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
1907             * @param orderByComparator the comparator to order the results by
1908             * @return the ordered range of matching message boards message flags
1909             * @throws SystemException if a system exception occurred
1910             */
1911            public List<MBMessageFlag> findByM_F(long messageId, int flag, int start,
1912                    int end, OrderByComparator orderByComparator) throws SystemException {
1913                    Object[] finderArgs = new Object[] {
1914                                    messageId, flag,
1915                                    
1916                                    String.valueOf(start), String.valueOf(end),
1917                                    String.valueOf(orderByComparator)
1918                            };
1919    
1920                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_M_F,
1921                                    finderArgs, this);
1922    
1923                    if (list == null) {
1924                            Session session = null;
1925    
1926                            try {
1927                                    session = openSession();
1928    
1929                                    StringBundler query = null;
1930    
1931                                    if (orderByComparator != null) {
1932                                            query = new StringBundler(4 +
1933                                                            (orderByComparator.getOrderByFields().length * 3));
1934                                    }
1935                                    else {
1936                                            query = new StringBundler(3);
1937                                    }
1938    
1939                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
1940    
1941                                    query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
1942    
1943                                    query.append(_FINDER_COLUMN_M_F_FLAG_2);
1944    
1945                                    if (orderByComparator != null) {
1946                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1947                                                    orderByComparator);
1948                                    }
1949    
1950                                    String sql = query.toString();
1951    
1952                                    Query q = session.createQuery(sql);
1953    
1954                                    QueryPos qPos = QueryPos.getInstance(q);
1955    
1956                                    qPos.add(messageId);
1957    
1958                                    qPos.add(flag);
1959    
1960                                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
1961                                                    start, end);
1962                            }
1963                            catch (Exception e) {
1964                                    throw processException(e);
1965                            }
1966                            finally {
1967                                    if (list == null) {
1968                                            list = new ArrayList<MBMessageFlag>();
1969                                    }
1970    
1971                                    cacheResult(list);
1972    
1973                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_M_F, finderArgs,
1974                                            list);
1975    
1976                                    closeSession(session);
1977                            }
1978                    }
1979    
1980                    return list;
1981            }
1982    
1983            /**
1984             * Finds the first message boards message flag in the ordered set where messageId = &#63; and flag = &#63;.
1985             *
1986             * <p>
1987             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1988             * </p>
1989             *
1990             * @param messageId the message id to search with
1991             * @param flag the flag to search with
1992             * @param orderByComparator the comparator to order the set by
1993             * @return the first matching message boards message flag
1994             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
1995             * @throws SystemException if a system exception occurred
1996             */
1997            public MBMessageFlag findByM_F_First(long messageId, int flag,
1998                    OrderByComparator orderByComparator)
1999                    throws NoSuchMessageFlagException, SystemException {
2000                    List<MBMessageFlag> list = findByM_F(messageId, flag, 0, 1,
2001                                    orderByComparator);
2002    
2003                    if (list.isEmpty()) {
2004                            StringBundler msg = new StringBundler(6);
2005    
2006                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2007    
2008                            msg.append("messageId=");
2009                            msg.append(messageId);
2010    
2011                            msg.append(", flag=");
2012                            msg.append(flag);
2013    
2014                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2015    
2016                            throw new NoSuchMessageFlagException(msg.toString());
2017                    }
2018                    else {
2019                            return list.get(0);
2020                    }
2021            }
2022    
2023            /**
2024             * Finds the last message boards message flag in the ordered set where messageId = &#63; and flag = &#63;.
2025             *
2026             * <p>
2027             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2028             * </p>
2029             *
2030             * @param messageId the message id to search with
2031             * @param flag the flag to search with
2032             * @param orderByComparator the comparator to order the set by
2033             * @return the last matching message boards message flag
2034             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
2035             * @throws SystemException if a system exception occurred
2036             */
2037            public MBMessageFlag findByM_F_Last(long messageId, int flag,
2038                    OrderByComparator orderByComparator)
2039                    throws NoSuchMessageFlagException, SystemException {
2040                    int count = countByM_F(messageId, flag);
2041    
2042                    List<MBMessageFlag> list = findByM_F(messageId, flag, count - 1, count,
2043                                    orderByComparator);
2044    
2045                    if (list.isEmpty()) {
2046                            StringBundler msg = new StringBundler(6);
2047    
2048                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2049    
2050                            msg.append("messageId=");
2051                            msg.append(messageId);
2052    
2053                            msg.append(", flag=");
2054                            msg.append(flag);
2055    
2056                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2057    
2058                            throw new NoSuchMessageFlagException(msg.toString());
2059                    }
2060                    else {
2061                            return list.get(0);
2062                    }
2063            }
2064    
2065            /**
2066             * Finds the message boards message flags before and after the current message boards message flag in the ordered set where messageId = &#63; and flag = &#63;.
2067             *
2068             * <p>
2069             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2070             * </p>
2071             *
2072             * @param messageFlagId the primary key of the current message boards message flag
2073             * @param messageId the message id to search with
2074             * @param flag the flag to search with
2075             * @param orderByComparator the comparator to order the set by
2076             * @return the previous, current, and next message boards message flag
2077             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
2078             * @throws SystemException if a system exception occurred
2079             */
2080            public MBMessageFlag[] findByM_F_PrevAndNext(long messageFlagId,
2081                    long messageId, int flag, OrderByComparator orderByComparator)
2082                    throws NoSuchMessageFlagException, SystemException {
2083                    MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
2084    
2085                    Session session = null;
2086    
2087                    try {
2088                            session = openSession();
2089    
2090                            MBMessageFlag[] array = new MBMessageFlagImpl[3];
2091    
2092                            array[0] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
2093                                            flag, orderByComparator, true);
2094    
2095                            array[1] = mbMessageFlag;
2096    
2097                            array[2] = getByM_F_PrevAndNext(session, mbMessageFlag, messageId,
2098                                            flag, orderByComparator, false);
2099    
2100                            return array;
2101                    }
2102                    catch (Exception e) {
2103                            throw processException(e);
2104                    }
2105                    finally {
2106                            closeSession(session);
2107                    }
2108            }
2109    
2110            protected MBMessageFlag getByM_F_PrevAndNext(Session session,
2111                    MBMessageFlag mbMessageFlag, long messageId, int flag,
2112                    OrderByComparator orderByComparator, boolean previous) {
2113                    StringBundler query = null;
2114    
2115                    if (orderByComparator != null) {
2116                            query = new StringBundler(6 +
2117                                            (orderByComparator.getOrderByFields().length * 6));
2118                    }
2119                    else {
2120                            query = new StringBundler(3);
2121                    }
2122    
2123                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2124    
2125                    query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
2126    
2127                    query.append(_FINDER_COLUMN_M_F_FLAG_2);
2128    
2129                    if (orderByComparator != null) {
2130                            String[] orderByFields = orderByComparator.getOrderByFields();
2131    
2132                            if (orderByFields.length > 0) {
2133                                    query.append(WHERE_AND);
2134                            }
2135    
2136                            for (int i = 0; i < orderByFields.length; i++) {
2137                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2138                                    query.append(orderByFields[i]);
2139    
2140                                    if ((i + 1) < orderByFields.length) {
2141                                            if (orderByComparator.isAscending() ^ previous) {
2142                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2143                                            }
2144                                            else {
2145                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2146                                            }
2147                                    }
2148                                    else {
2149                                            if (orderByComparator.isAscending() ^ previous) {
2150                                                    query.append(WHERE_GREATER_THAN);
2151                                            }
2152                                            else {
2153                                                    query.append(WHERE_LESSER_THAN);
2154                                            }
2155                                    }
2156                            }
2157    
2158                            query.append(ORDER_BY_CLAUSE);
2159    
2160                            for (int i = 0; i < orderByFields.length; i++) {
2161                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2162                                    query.append(orderByFields[i]);
2163    
2164                                    if ((i + 1) < orderByFields.length) {
2165                                            if (orderByComparator.isAscending() ^ previous) {
2166                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2167                                            }
2168                                            else {
2169                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2170                                            }
2171                                    }
2172                                    else {
2173                                            if (orderByComparator.isAscending() ^ previous) {
2174                                                    query.append(ORDER_BY_ASC);
2175                                            }
2176                                            else {
2177                                                    query.append(ORDER_BY_DESC);
2178                                            }
2179                                    }
2180                            }
2181                    }
2182    
2183                    String sql = query.toString();
2184    
2185                    Query q = session.createQuery(sql);
2186    
2187                    q.setFirstResult(0);
2188                    q.setMaxResults(2);
2189    
2190                    QueryPos qPos = QueryPos.getInstance(q);
2191    
2192                    qPos.add(messageId);
2193    
2194                    qPos.add(flag);
2195    
2196                    if (orderByComparator != null) {
2197                            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2198    
2199                            for (Object value : values) {
2200                                    qPos.add(value);
2201                            }
2202                    }
2203    
2204                    List<MBMessageFlag> list = q.list();
2205    
2206                    if (list.size() == 2) {
2207                            return list.get(1);
2208                    }
2209                    else {
2210                            return null;
2211                    }
2212            }
2213    
2214            /**
2215             * Finds all the message boards message flags where userId = &#63; and threadId = &#63; and flag = &#63;.
2216             *
2217             * @param userId the user id to search with
2218             * @param threadId the thread id to search with
2219             * @param flag the flag to search with
2220             * @return the matching message boards message flags
2221             * @throws SystemException if a system exception occurred
2222             */
2223            public List<MBMessageFlag> findByU_T_F(long userId, long threadId, int flag)
2224                    throws SystemException {
2225                    return findByU_T_F(userId, threadId, flag, QueryUtil.ALL_POS,
2226                            QueryUtil.ALL_POS, null);
2227            }
2228    
2229            /**
2230             * Finds a range of all the message boards message flags where userId = &#63; and threadId = &#63; and flag = &#63;.
2231             *
2232             * <p>
2233             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2234             * </p>
2235             *
2236             * @param userId the user id to search with
2237             * @param threadId the thread id to search with
2238             * @param flag the flag to search with
2239             * @param start the lower bound of the range of message boards message flags to return
2240             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
2241             * @return the range of matching message boards message flags
2242             * @throws SystemException if a system exception occurred
2243             */
2244            public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
2245                    int flag, int start, int end) throws SystemException {
2246                    return findByU_T_F(userId, threadId, flag, start, end, null);
2247            }
2248    
2249            /**
2250             * Finds an ordered range of all the message boards message flags where userId = &#63; and threadId = &#63; and flag = &#63;.
2251             *
2252             * <p>
2253             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2254             * </p>
2255             *
2256             * @param userId the user id to search with
2257             * @param threadId the thread id to search with
2258             * @param flag the flag to search with
2259             * @param start the lower bound of the range of message boards message flags to return
2260             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
2261             * @param orderByComparator the comparator to order the results by
2262             * @return the ordered range of matching message boards message flags
2263             * @throws SystemException if a system exception occurred
2264             */
2265            public List<MBMessageFlag> findByU_T_F(long userId, long threadId,
2266                    int flag, int start, int end, OrderByComparator orderByComparator)
2267                    throws SystemException {
2268                    Object[] finderArgs = new Object[] {
2269                                    userId, threadId, flag,
2270                                    
2271                                    String.valueOf(start), String.valueOf(end),
2272                                    String.valueOf(orderByComparator)
2273                            };
2274    
2275                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_U_T_F,
2276                                    finderArgs, this);
2277    
2278                    if (list == null) {
2279                            Session session = null;
2280    
2281                            try {
2282                                    session = openSession();
2283    
2284                                    StringBundler query = null;
2285    
2286                                    if (orderByComparator != null) {
2287                                            query = new StringBundler(5 +
2288                                                            (orderByComparator.getOrderByFields().length * 3));
2289                                    }
2290                                    else {
2291                                            query = new StringBundler(4);
2292                                    }
2293    
2294                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2295    
2296                                    query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2297    
2298                                    query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2299    
2300                                    query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2301    
2302                                    if (orderByComparator != null) {
2303                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2304                                                    orderByComparator);
2305                                    }
2306    
2307                                    String sql = query.toString();
2308    
2309                                    Query q = session.createQuery(sql);
2310    
2311                                    QueryPos qPos = QueryPos.getInstance(q);
2312    
2313                                    qPos.add(userId);
2314    
2315                                    qPos.add(threadId);
2316    
2317                                    qPos.add(flag);
2318    
2319                                    list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2320                                                    start, end);
2321                            }
2322                            catch (Exception e) {
2323                                    throw processException(e);
2324                            }
2325                            finally {
2326                                    if (list == null) {
2327                                            list = new ArrayList<MBMessageFlag>();
2328                                    }
2329    
2330                                    cacheResult(list);
2331    
2332                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_U_T_F,
2333                                            finderArgs, list);
2334    
2335                                    closeSession(session);
2336                            }
2337                    }
2338    
2339                    return list;
2340            }
2341    
2342            /**
2343             * Finds the first message boards message flag in the ordered set where userId = &#63; and threadId = &#63; and flag = &#63;.
2344             *
2345             * <p>
2346             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2347             * </p>
2348             *
2349             * @param userId the user id to search with
2350             * @param threadId the thread id to search with
2351             * @param flag the flag to search with
2352             * @param orderByComparator the comparator to order the set by
2353             * @return the first matching message boards message flag
2354             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
2355             * @throws SystemException if a system exception occurred
2356             */
2357            public MBMessageFlag findByU_T_F_First(long userId, long threadId,
2358                    int flag, OrderByComparator orderByComparator)
2359                    throws NoSuchMessageFlagException, SystemException {
2360                    List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag, 0, 1,
2361                                    orderByComparator);
2362    
2363                    if (list.isEmpty()) {
2364                            StringBundler msg = new StringBundler(8);
2365    
2366                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2367    
2368                            msg.append("userId=");
2369                            msg.append(userId);
2370    
2371                            msg.append(", threadId=");
2372                            msg.append(threadId);
2373    
2374                            msg.append(", flag=");
2375                            msg.append(flag);
2376    
2377                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2378    
2379                            throw new NoSuchMessageFlagException(msg.toString());
2380                    }
2381                    else {
2382                            return list.get(0);
2383                    }
2384            }
2385    
2386            /**
2387             * Finds the last message boards message flag in the ordered set where userId = &#63; and threadId = &#63; and flag = &#63;.
2388             *
2389             * <p>
2390             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2391             * </p>
2392             *
2393             * @param userId the user id to search with
2394             * @param threadId the thread id to search with
2395             * @param flag the flag to search with
2396             * @param orderByComparator the comparator to order the set by
2397             * @return the last matching message boards message flag
2398             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
2399             * @throws SystemException if a system exception occurred
2400             */
2401            public MBMessageFlag findByU_T_F_Last(long userId, long threadId, int flag,
2402                    OrderByComparator orderByComparator)
2403                    throws NoSuchMessageFlagException, SystemException {
2404                    int count = countByU_T_F(userId, threadId, flag);
2405    
2406                    List<MBMessageFlag> list = findByU_T_F(userId, threadId, flag,
2407                                    count - 1, count, orderByComparator);
2408    
2409                    if (list.isEmpty()) {
2410                            StringBundler msg = new StringBundler(8);
2411    
2412                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2413    
2414                            msg.append("userId=");
2415                            msg.append(userId);
2416    
2417                            msg.append(", threadId=");
2418                            msg.append(threadId);
2419    
2420                            msg.append(", flag=");
2421                            msg.append(flag);
2422    
2423                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2424    
2425                            throw new NoSuchMessageFlagException(msg.toString());
2426                    }
2427                    else {
2428                            return list.get(0);
2429                    }
2430            }
2431    
2432            /**
2433             * Finds the message boards message flags before and after the current message boards message flag in the ordered set where userId = &#63; and threadId = &#63; and flag = &#63;.
2434             *
2435             * <p>
2436             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2437             * </p>
2438             *
2439             * @param messageFlagId the primary key of the current message boards message flag
2440             * @param userId the user id to search with
2441             * @param threadId the thread id to search with
2442             * @param flag the flag to search with
2443             * @param orderByComparator the comparator to order the set by
2444             * @return the previous, current, and next message boards message flag
2445             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a message boards message flag with the primary key could not be found
2446             * @throws SystemException if a system exception occurred
2447             */
2448            public MBMessageFlag[] findByU_T_F_PrevAndNext(long messageFlagId,
2449                    long userId, long threadId, int flag,
2450                    OrderByComparator orderByComparator)
2451                    throws NoSuchMessageFlagException, SystemException {
2452                    MBMessageFlag mbMessageFlag = findByPrimaryKey(messageFlagId);
2453    
2454                    Session session = null;
2455    
2456                    try {
2457                            session = openSession();
2458    
2459                            MBMessageFlag[] array = new MBMessageFlagImpl[3];
2460    
2461                            array[0] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
2462                                            threadId, flag, orderByComparator, true);
2463    
2464                            array[1] = mbMessageFlag;
2465    
2466                            array[2] = getByU_T_F_PrevAndNext(session, mbMessageFlag, userId,
2467                                            threadId, flag, orderByComparator, false);
2468    
2469                            return array;
2470                    }
2471                    catch (Exception e) {
2472                            throw processException(e);
2473                    }
2474                    finally {
2475                            closeSession(session);
2476                    }
2477            }
2478    
2479            protected MBMessageFlag getByU_T_F_PrevAndNext(Session session,
2480                    MBMessageFlag mbMessageFlag, long userId, long threadId, int flag,
2481                    OrderByComparator orderByComparator, boolean previous) {
2482                    StringBundler query = null;
2483    
2484                    if (orderByComparator != null) {
2485                            query = new StringBundler(6 +
2486                                            (orderByComparator.getOrderByFields().length * 6));
2487                    }
2488                    else {
2489                            query = new StringBundler(3);
2490                    }
2491    
2492                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2493    
2494                    query.append(_FINDER_COLUMN_U_T_F_USERID_2);
2495    
2496                    query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
2497    
2498                    query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
2499    
2500                    if (orderByComparator != null) {
2501                            String[] orderByFields = orderByComparator.getOrderByFields();
2502    
2503                            if (orderByFields.length > 0) {
2504                                    query.append(WHERE_AND);
2505                            }
2506    
2507                            for (int i = 0; i < orderByFields.length; i++) {
2508                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2509                                    query.append(orderByFields[i]);
2510    
2511                                    if ((i + 1) < orderByFields.length) {
2512                                            if (orderByComparator.isAscending() ^ previous) {
2513                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2514                                            }
2515                                            else {
2516                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2517                                            }
2518                                    }
2519                                    else {
2520                                            if (orderByComparator.isAscending() ^ previous) {
2521                                                    query.append(WHERE_GREATER_THAN);
2522                                            }
2523                                            else {
2524                                                    query.append(WHERE_LESSER_THAN);
2525                                            }
2526                                    }
2527                            }
2528    
2529                            query.append(ORDER_BY_CLAUSE);
2530    
2531                            for (int i = 0; i < orderByFields.length; i++) {
2532                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2533                                    query.append(orderByFields[i]);
2534    
2535                                    if ((i + 1) < orderByFields.length) {
2536                                            if (orderByComparator.isAscending() ^ previous) {
2537                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2538                                            }
2539                                            else {
2540                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2541                                            }
2542                                    }
2543                                    else {
2544                                            if (orderByComparator.isAscending() ^ previous) {
2545                                                    query.append(ORDER_BY_ASC);
2546                                            }
2547                                            else {
2548                                                    query.append(ORDER_BY_DESC);
2549                                            }
2550                                    }
2551                            }
2552                    }
2553    
2554                    String sql = query.toString();
2555    
2556                    Query q = session.createQuery(sql);
2557    
2558                    q.setFirstResult(0);
2559                    q.setMaxResults(2);
2560    
2561                    QueryPos qPos = QueryPos.getInstance(q);
2562    
2563                    qPos.add(userId);
2564    
2565                    qPos.add(threadId);
2566    
2567                    qPos.add(flag);
2568    
2569                    if (orderByComparator != null) {
2570                            Object[] values = orderByComparator.getOrderByValues(mbMessageFlag);
2571    
2572                            for (Object value : values) {
2573                                    qPos.add(value);
2574                            }
2575                    }
2576    
2577                    List<MBMessageFlag> list = q.list();
2578    
2579                    if (list.size() == 2) {
2580                            return list.get(1);
2581                    }
2582                    else {
2583                            return null;
2584                    }
2585            }
2586    
2587            /**
2588             * Finds the message boards message flag where userId = &#63; and messageId = &#63; and flag = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageFlagException} if it could not be found.
2589             *
2590             * @param userId the user id to search with
2591             * @param messageId the message id to search with
2592             * @param flag the flag to search with
2593             * @return the matching message boards message flag
2594             * @throws com.liferay.portlet.messageboards.NoSuchMessageFlagException if a matching message boards message flag could not be found
2595             * @throws SystemException if a system exception occurred
2596             */
2597            public MBMessageFlag findByU_M_F(long userId, long messageId, int flag)
2598                    throws NoSuchMessageFlagException, SystemException {
2599                    MBMessageFlag mbMessageFlag = fetchByU_M_F(userId, messageId, flag);
2600    
2601                    if (mbMessageFlag == null) {
2602                            StringBundler msg = new StringBundler(8);
2603    
2604                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2605    
2606                            msg.append("userId=");
2607                            msg.append(userId);
2608    
2609                            msg.append(", messageId=");
2610                            msg.append(messageId);
2611    
2612                            msg.append(", flag=");
2613                            msg.append(flag);
2614    
2615                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2616    
2617                            if (_log.isWarnEnabled()) {
2618                                    _log.warn(msg.toString());
2619                            }
2620    
2621                            throw new NoSuchMessageFlagException(msg.toString());
2622                    }
2623    
2624                    return mbMessageFlag;
2625            }
2626    
2627            /**
2628             * Finds the message boards message flag where userId = &#63; and messageId = &#63; and flag = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
2629             *
2630             * @param userId the user id to search with
2631             * @param messageId the message id to search with
2632             * @param flag the flag to search with
2633             * @return the matching message boards message flag, or <code>null</code> if a matching message boards message flag could not be found
2634             * @throws SystemException if a system exception occurred
2635             */
2636            public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag)
2637                    throws SystemException {
2638                    return fetchByU_M_F(userId, messageId, flag, true);
2639            }
2640    
2641            /**
2642             * Finds the message boards message flag where userId = &#63; and messageId = &#63; and flag = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
2643             *
2644             * @param userId the user id to search with
2645             * @param messageId the message id to search with
2646             * @param flag the flag to search with
2647             * @return the matching message boards message flag, or <code>null</code> if a matching message boards message flag could not be found
2648             * @throws SystemException if a system exception occurred
2649             */
2650            public MBMessageFlag fetchByU_M_F(long userId, long messageId, int flag,
2651                    boolean retrieveFromCache) throws SystemException {
2652                    Object[] finderArgs = new Object[] { userId, messageId, flag };
2653    
2654                    Object result = null;
2655    
2656                    if (retrieveFromCache) {
2657                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_M_F,
2658                                            finderArgs, this);
2659                    }
2660    
2661                    if (result == null) {
2662                            Session session = null;
2663    
2664                            try {
2665                                    session = openSession();
2666    
2667                                    StringBundler query = new StringBundler(4);
2668    
2669                                    query.append(_SQL_SELECT_MBMESSAGEFLAG_WHERE);
2670    
2671                                    query.append(_FINDER_COLUMN_U_M_F_USERID_2);
2672    
2673                                    query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
2674    
2675                                    query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
2676    
2677                                    String sql = query.toString();
2678    
2679                                    Query q = session.createQuery(sql);
2680    
2681                                    QueryPos qPos = QueryPos.getInstance(q);
2682    
2683                                    qPos.add(userId);
2684    
2685                                    qPos.add(messageId);
2686    
2687                                    qPos.add(flag);
2688    
2689                                    List<MBMessageFlag> list = q.list();
2690    
2691                                    result = list;
2692    
2693                                    MBMessageFlag mbMessageFlag = null;
2694    
2695                                    if (list.isEmpty()) {
2696                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2697                                                    finderArgs, list);
2698                                    }
2699                                    else {
2700                                            mbMessageFlag = list.get(0);
2701    
2702                                            cacheResult(mbMessageFlag);
2703    
2704                                            if ((mbMessageFlag.getUserId() != userId) ||
2705                                                            (mbMessageFlag.getMessageId() != messageId) ||
2706                                                            (mbMessageFlag.getFlag() != flag)) {
2707                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2708                                                            finderArgs, mbMessageFlag);
2709                                            }
2710                                    }
2711    
2712                                    return mbMessageFlag;
2713                            }
2714                            catch (Exception e) {
2715                                    throw processException(e);
2716                            }
2717                            finally {
2718                                    if (result == null) {
2719                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_M_F,
2720                                                    finderArgs, new ArrayList<MBMessageFlag>());
2721                                    }
2722    
2723                                    closeSession(session);
2724                            }
2725                    }
2726                    else {
2727                            if (result instanceof List<?>) {
2728                                    return null;
2729                            }
2730                            else {
2731                                    return (MBMessageFlag)result;
2732                            }
2733                    }
2734            }
2735    
2736            /**
2737             * Finds all the message boards message flags.
2738             *
2739             * @return the message boards message flags
2740             * @throws SystemException if a system exception occurred
2741             */
2742            public List<MBMessageFlag> findAll() throws SystemException {
2743                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2744            }
2745    
2746            /**
2747             * Finds a range of all the message boards message flags.
2748             *
2749             * <p>
2750             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2751             * </p>
2752             *
2753             * @param start the lower bound of the range of message boards message flags to return
2754             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
2755             * @return the range of message boards message flags
2756             * @throws SystemException if a system exception occurred
2757             */
2758            public List<MBMessageFlag> findAll(int start, int end)
2759                    throws SystemException {
2760                    return findAll(start, end, null);
2761            }
2762    
2763            /**
2764             * Finds an ordered range of all the message boards message flags.
2765             *
2766             * <p>
2767             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
2768             * </p>
2769             *
2770             * @param start the lower bound of the range of message boards message flags to return
2771             * @param end the upper bound of the range of message boards message flags to return (not inclusive)
2772             * @param orderByComparator the comparator to order the results by
2773             * @return the ordered range of message boards message flags
2774             * @throws SystemException if a system exception occurred
2775             */
2776            public List<MBMessageFlag> findAll(int start, int end,
2777                    OrderByComparator orderByComparator) throws SystemException {
2778                    Object[] finderArgs = new Object[] {
2779                                    String.valueOf(start), String.valueOf(end),
2780                                    String.valueOf(orderByComparator)
2781                            };
2782    
2783                    List<MBMessageFlag> list = (List<MBMessageFlag>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2784                                    finderArgs, this);
2785    
2786                    if (list == null) {
2787                            Session session = null;
2788    
2789                            try {
2790                                    session = openSession();
2791    
2792                                    StringBundler query = null;
2793                                    String sql = null;
2794    
2795                                    if (orderByComparator != null) {
2796                                            query = new StringBundler(2 +
2797                                                            (orderByComparator.getOrderByFields().length * 3));
2798    
2799                                            query.append(_SQL_SELECT_MBMESSAGEFLAG);
2800    
2801                                            appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2802                                                    orderByComparator);
2803    
2804                                            sql = query.toString();
2805                                    }
2806                                    else {
2807                                            sql = _SQL_SELECT_MBMESSAGEFLAG;
2808                                    }
2809    
2810                                    Query q = session.createQuery(sql);
2811    
2812                                    if (orderByComparator == null) {
2813                                            list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2814                                                            start, end, false);
2815    
2816                                            Collections.sort(list);
2817                                    }
2818                                    else {
2819                                            list = (List<MBMessageFlag>)QueryUtil.list(q, getDialect(),
2820                                                            start, end);
2821                                    }
2822                            }
2823                            catch (Exception e) {
2824                                    throw processException(e);
2825                            }
2826                            finally {
2827                                    if (list == null) {
2828                                            list = new ArrayList<MBMessageFlag>();
2829                                    }
2830    
2831                                    cacheResult(list);
2832    
2833                                    FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2834    
2835                                    closeSession(session);
2836                            }
2837                    }
2838    
2839                    return list;
2840            }
2841    
2842            /**
2843             * Removes all the message boards message flags where userId = &#63; from the database.
2844             *
2845             * @param userId the user id to search with
2846             * @throws SystemException if a system exception occurred
2847             */
2848            public void removeByUserId(long userId) throws SystemException {
2849                    for (MBMessageFlag mbMessageFlag : findByUserId(userId)) {
2850                            remove(mbMessageFlag);
2851                    }
2852            }
2853    
2854            /**
2855             * Removes all the message boards message flags where threadId = &#63; from the database.
2856             *
2857             * @param threadId the thread id to search with
2858             * @throws SystemException if a system exception occurred
2859             */
2860            public void removeByThreadId(long threadId) throws SystemException {
2861                    for (MBMessageFlag mbMessageFlag : findByThreadId(threadId)) {
2862                            remove(mbMessageFlag);
2863                    }
2864            }
2865    
2866            /**
2867             * Removes all the message boards message flags where messageId = &#63; from the database.
2868             *
2869             * @param messageId the message id to search with
2870             * @throws SystemException if a system exception occurred
2871             */
2872            public void removeByMessageId(long messageId) throws SystemException {
2873                    for (MBMessageFlag mbMessageFlag : findByMessageId(messageId)) {
2874                            remove(mbMessageFlag);
2875                    }
2876            }
2877    
2878            /**
2879             * Removes all the message boards message flags where threadId = &#63; and flag = &#63; from the database.
2880             *
2881             * @param threadId the thread id to search with
2882             * @param flag the flag to search with
2883             * @throws SystemException if a system exception occurred
2884             */
2885            public void removeByT_F(long threadId, int flag) throws SystemException {
2886                    for (MBMessageFlag mbMessageFlag : findByT_F(threadId, flag)) {
2887                            remove(mbMessageFlag);
2888                    }
2889            }
2890    
2891            /**
2892             * Removes all the message boards message flags where messageId = &#63; and flag = &#63; from the database.
2893             *
2894             * @param messageId the message id to search with
2895             * @param flag the flag to search with
2896             * @throws SystemException if a system exception occurred
2897             */
2898            public void removeByM_F(long messageId, int flag) throws SystemException {
2899                    for (MBMessageFlag mbMessageFlag : findByM_F(messageId, flag)) {
2900                            remove(mbMessageFlag);
2901                    }
2902            }
2903    
2904            /**
2905             * Removes all the message boards message flags where userId = &#63; and threadId = &#63; and flag = &#63; from the database.
2906             *
2907             * @param userId the user id to search with
2908             * @param threadId the thread id to search with
2909             * @param flag the flag to search with
2910             * @throws SystemException if a system exception occurred
2911             */
2912            public void removeByU_T_F(long userId, long threadId, int flag)
2913                    throws SystemException {
2914                    for (MBMessageFlag mbMessageFlag : findByU_T_F(userId, threadId, flag)) {
2915                            remove(mbMessageFlag);
2916                    }
2917            }
2918    
2919            /**
2920             * Removes the message boards message flag where userId = &#63; and messageId = &#63; and flag = &#63; from the database.
2921             *
2922             * @param userId the user id to search with
2923             * @param messageId the message id to search with
2924             * @param flag the flag to search with
2925             * @throws SystemException if a system exception occurred
2926             */
2927            public void removeByU_M_F(long userId, long messageId, int flag)
2928                    throws NoSuchMessageFlagException, SystemException {
2929                    MBMessageFlag mbMessageFlag = findByU_M_F(userId, messageId, flag);
2930    
2931                    remove(mbMessageFlag);
2932            }
2933    
2934            /**
2935             * Removes all the message boards message flags from the database.
2936             *
2937             * @throws SystemException if a system exception occurred
2938             */
2939            public void removeAll() throws SystemException {
2940                    for (MBMessageFlag mbMessageFlag : findAll()) {
2941                            remove(mbMessageFlag);
2942                    }
2943            }
2944    
2945            /**
2946             * Counts all the message boards message flags where userId = &#63;.
2947             *
2948             * @param userId the user id to search with
2949             * @return the number of matching message boards message flags
2950             * @throws SystemException if a system exception occurred
2951             */
2952            public int countByUserId(long userId) throws SystemException {
2953                    Object[] finderArgs = new Object[] { userId };
2954    
2955                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2956                                    finderArgs, this);
2957    
2958                    if (count == null) {
2959                            Session session = null;
2960    
2961                            try {
2962                                    session = openSession();
2963    
2964                                    StringBundler query = new StringBundler(2);
2965    
2966                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
2967    
2968                                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2969    
2970                                    String sql = query.toString();
2971    
2972                                    Query q = session.createQuery(sql);
2973    
2974                                    QueryPos qPos = QueryPos.getInstance(q);
2975    
2976                                    qPos.add(userId);
2977    
2978                                    count = (Long)q.uniqueResult();
2979                            }
2980                            catch (Exception e) {
2981                                    throw processException(e);
2982                            }
2983                            finally {
2984                                    if (count == null) {
2985                                            count = Long.valueOf(0);
2986                                    }
2987    
2988                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2989                                            finderArgs, count);
2990    
2991                                    closeSession(session);
2992                            }
2993                    }
2994    
2995                    return count.intValue();
2996            }
2997    
2998            /**
2999             * Counts all the message boards message flags where threadId = &#63;.
3000             *
3001             * @param threadId the thread id to search with
3002             * @return the number of matching message boards message flags
3003             * @throws SystemException if a system exception occurred
3004             */
3005            public int countByThreadId(long threadId) throws SystemException {
3006                    Object[] finderArgs = new Object[] { threadId };
3007    
3008                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
3009                                    finderArgs, this);
3010    
3011                    if (count == null) {
3012                            Session session = null;
3013    
3014                            try {
3015                                    session = openSession();
3016    
3017                                    StringBundler query = new StringBundler(2);
3018    
3019                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3020    
3021                                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3022    
3023                                    String sql = query.toString();
3024    
3025                                    Query q = session.createQuery(sql);
3026    
3027                                    QueryPos qPos = QueryPos.getInstance(q);
3028    
3029                                    qPos.add(threadId);
3030    
3031                                    count = (Long)q.uniqueResult();
3032                            }
3033                            catch (Exception e) {
3034                                    throw processException(e);
3035                            }
3036                            finally {
3037                                    if (count == null) {
3038                                            count = Long.valueOf(0);
3039                                    }
3040    
3041                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
3042                                            finderArgs, count);
3043    
3044                                    closeSession(session);
3045                            }
3046                    }
3047    
3048                    return count.intValue();
3049            }
3050    
3051            /**
3052             * Counts all the message boards message flags where messageId = &#63;.
3053             *
3054             * @param messageId the message id to search with
3055             * @return the number of matching message boards message flags
3056             * @throws SystemException if a system exception occurred
3057             */
3058            public int countByMessageId(long messageId) throws SystemException {
3059                    Object[] finderArgs = new Object[] { messageId };
3060    
3061                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_MESSAGEID,
3062                                    finderArgs, this);
3063    
3064                    if (count == null) {
3065                            Session session = null;
3066    
3067                            try {
3068                                    session = openSession();
3069    
3070                                    StringBundler query = new StringBundler(2);
3071    
3072                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3073    
3074                                    query.append(_FINDER_COLUMN_MESSAGEID_MESSAGEID_2);
3075    
3076                                    String sql = query.toString();
3077    
3078                                    Query q = session.createQuery(sql);
3079    
3080                                    QueryPos qPos = QueryPos.getInstance(q);
3081    
3082                                    qPos.add(messageId);
3083    
3084                                    count = (Long)q.uniqueResult();
3085                            }
3086                            catch (Exception e) {
3087                                    throw processException(e);
3088                            }
3089                            finally {
3090                                    if (count == null) {
3091                                            count = Long.valueOf(0);
3092                                    }
3093    
3094                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_MESSAGEID,
3095                                            finderArgs, count);
3096    
3097                                    closeSession(session);
3098                            }
3099                    }
3100    
3101                    return count.intValue();
3102            }
3103    
3104            /**
3105             * Counts all the message boards message flags where threadId = &#63; and flag = &#63;.
3106             *
3107             * @param threadId the thread id to search with
3108             * @param flag the flag to search with
3109             * @return the number of matching message boards message flags
3110             * @throws SystemException if a system exception occurred
3111             */
3112            public int countByT_F(long threadId, int flag) throws SystemException {
3113                    Object[] finderArgs = new Object[] { threadId, flag };
3114    
3115                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_F,
3116                                    finderArgs, this);
3117    
3118                    if (count == null) {
3119                            Session session = null;
3120    
3121                            try {
3122                                    session = openSession();
3123    
3124                                    StringBundler query = new StringBundler(3);
3125    
3126                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3127    
3128                                    query.append(_FINDER_COLUMN_T_F_THREADID_2);
3129    
3130                                    query.append(_FINDER_COLUMN_T_F_FLAG_2);
3131    
3132                                    String sql = query.toString();
3133    
3134                                    Query q = session.createQuery(sql);
3135    
3136                                    QueryPos qPos = QueryPos.getInstance(q);
3137    
3138                                    qPos.add(threadId);
3139    
3140                                    qPos.add(flag);
3141    
3142                                    count = (Long)q.uniqueResult();
3143                            }
3144                            catch (Exception e) {
3145                                    throw processException(e);
3146                            }
3147                            finally {
3148                                    if (count == null) {
3149                                            count = Long.valueOf(0);
3150                                    }
3151    
3152                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_F, finderArgs,
3153                                            count);
3154    
3155                                    closeSession(session);
3156                            }
3157                    }
3158    
3159                    return count.intValue();
3160            }
3161    
3162            /**
3163             * Counts all the message boards message flags where messageId = &#63; and flag = &#63;.
3164             *
3165             * @param messageId the message id to search with
3166             * @param flag the flag to search with
3167             * @return the number of matching message boards message flags
3168             * @throws SystemException if a system exception occurred
3169             */
3170            public int countByM_F(long messageId, int flag) throws SystemException {
3171                    Object[] finderArgs = new Object[] { messageId, flag };
3172    
3173                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_M_F,
3174                                    finderArgs, this);
3175    
3176                    if (count == null) {
3177                            Session session = null;
3178    
3179                            try {
3180                                    session = openSession();
3181    
3182                                    StringBundler query = new StringBundler(3);
3183    
3184                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3185    
3186                                    query.append(_FINDER_COLUMN_M_F_MESSAGEID_2);
3187    
3188                                    query.append(_FINDER_COLUMN_M_F_FLAG_2);
3189    
3190                                    String sql = query.toString();
3191    
3192                                    Query q = session.createQuery(sql);
3193    
3194                                    QueryPos qPos = QueryPos.getInstance(q);
3195    
3196                                    qPos.add(messageId);
3197    
3198                                    qPos.add(flag);
3199    
3200                                    count = (Long)q.uniqueResult();
3201                            }
3202                            catch (Exception e) {
3203                                    throw processException(e);
3204                            }
3205                            finally {
3206                                    if (count == null) {
3207                                            count = Long.valueOf(0);
3208                                    }
3209    
3210                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_M_F, finderArgs,
3211                                            count);
3212    
3213                                    closeSession(session);
3214                            }
3215                    }
3216    
3217                    return count.intValue();
3218            }
3219    
3220            /**
3221             * Counts all the message boards message flags where userId = &#63; and threadId = &#63; and flag = &#63;.
3222             *
3223             * @param userId the user id to search with
3224             * @param threadId the thread id to search with
3225             * @param flag the flag to search with
3226             * @return the number of matching message boards message flags
3227             * @throws SystemException if a system exception occurred
3228             */
3229            public int countByU_T_F(long userId, long threadId, int flag)
3230                    throws SystemException {
3231                    Object[] finderArgs = new Object[] { userId, threadId, flag };
3232    
3233                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T_F,
3234                                    finderArgs, this);
3235    
3236                    if (count == null) {
3237                            Session session = null;
3238    
3239                            try {
3240                                    session = openSession();
3241    
3242                                    StringBundler query = new StringBundler(4);
3243    
3244                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3245    
3246                                    query.append(_FINDER_COLUMN_U_T_F_USERID_2);
3247    
3248                                    query.append(_FINDER_COLUMN_U_T_F_THREADID_2);
3249    
3250                                    query.append(_FINDER_COLUMN_U_T_F_FLAG_2);
3251    
3252                                    String sql = query.toString();
3253    
3254                                    Query q = session.createQuery(sql);
3255    
3256                                    QueryPos qPos = QueryPos.getInstance(q);
3257    
3258                                    qPos.add(userId);
3259    
3260                                    qPos.add(threadId);
3261    
3262                                    qPos.add(flag);
3263    
3264                                    count = (Long)q.uniqueResult();
3265                            }
3266                            catch (Exception e) {
3267                                    throw processException(e);
3268                            }
3269                            finally {
3270                                    if (count == null) {
3271                                            count = Long.valueOf(0);
3272                                    }
3273    
3274                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T_F,
3275                                            finderArgs, count);
3276    
3277                                    closeSession(session);
3278                            }
3279                    }
3280    
3281                    return count.intValue();
3282            }
3283    
3284            /**
3285             * Counts all the message boards message flags where userId = &#63; and messageId = &#63; and flag = &#63;.
3286             *
3287             * @param userId the user id to search with
3288             * @param messageId the message id to search with
3289             * @param flag the flag to search with
3290             * @return the number of matching message boards message flags
3291             * @throws SystemException if a system exception occurred
3292             */
3293            public int countByU_M_F(long userId, long messageId, int flag)
3294                    throws SystemException {
3295                    Object[] finderArgs = new Object[] { userId, messageId, flag };
3296    
3297                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_M_F,
3298                                    finderArgs, this);
3299    
3300                    if (count == null) {
3301                            Session session = null;
3302    
3303                            try {
3304                                    session = openSession();
3305    
3306                                    StringBundler query = new StringBundler(4);
3307    
3308                                    query.append(_SQL_COUNT_MBMESSAGEFLAG_WHERE);
3309    
3310                                    query.append(_FINDER_COLUMN_U_M_F_USERID_2);
3311    
3312                                    query.append(_FINDER_COLUMN_U_M_F_MESSAGEID_2);
3313    
3314                                    query.append(_FINDER_COLUMN_U_M_F_FLAG_2);
3315    
3316                                    String sql = query.toString();
3317    
3318                                    Query q = session.createQuery(sql);
3319    
3320                                    QueryPos qPos = QueryPos.getInstance(q);
3321    
3322                                    qPos.add(userId);
3323    
3324                                    qPos.add(messageId);
3325    
3326                                    qPos.add(flag);
3327    
3328                                    count = (Long)q.uniqueResult();
3329                            }
3330                            catch (Exception e) {
3331                                    throw processException(e);
3332                            }
3333                            finally {
3334                                    if (count == null) {
3335                                            count = Long.valueOf(0);
3336                                    }
3337    
3338                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_M_F,
3339                                            finderArgs, count);
3340    
3341                                    closeSession(session);
3342                            }
3343                    }
3344    
3345                    return count.intValue();
3346            }
3347    
3348            /**
3349             * Counts all the message boards message flags.
3350             *
3351             * @return the number of message boards message flags
3352             * @throws SystemException if a system exception occurred
3353             */
3354            public int countAll() throws SystemException {
3355                    Object[] finderArgs = new Object[0];
3356    
3357                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3358                                    finderArgs, this);
3359    
3360                    if (count == null) {
3361                            Session session = null;
3362    
3363                            try {
3364                                    session = openSession();
3365    
3366                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGEFLAG);
3367    
3368                                    count = (Long)q.uniqueResult();
3369                            }
3370                            catch (Exception e) {
3371                                    throw processException(e);
3372                            }
3373                            finally {
3374                                    if (count == null) {
3375                                            count = Long.valueOf(0);
3376                                    }
3377    
3378                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3379                                            count);
3380    
3381                                    closeSession(session);
3382                            }
3383                    }
3384    
3385                    return count.intValue();
3386            }
3387    
3388            /**
3389             * Initializes the message boards message flag persistence.
3390             */
3391            public void afterPropertiesSet() {
3392                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3393                                            com.liferay.portal.util.PropsUtil.get(
3394                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessageFlag")));
3395    
3396                    if (listenerClassNames.length > 0) {
3397                            try {
3398                                    List<ModelListener<MBMessageFlag>> listenersList = new ArrayList<ModelListener<MBMessageFlag>>();
3399    
3400                                    for (String listenerClassName : listenerClassNames) {
3401                                            listenersList.add((ModelListener<MBMessageFlag>)InstanceFactory.newInstance(
3402                                                            listenerClassName));
3403                                    }
3404    
3405                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3406                            }
3407                            catch (Exception e) {
3408                                    _log.error(e);
3409                            }
3410                    }
3411            }
3412    
3413            @BeanReference(type = MBBanPersistence.class)
3414            protected MBBanPersistence mbBanPersistence;
3415            @BeanReference(type = MBCategoryPersistence.class)
3416            protected MBCategoryPersistence mbCategoryPersistence;
3417            @BeanReference(type = MBDiscussionPersistence.class)
3418            protected MBDiscussionPersistence mbDiscussionPersistence;
3419            @BeanReference(type = MBMailingListPersistence.class)
3420            protected MBMailingListPersistence mbMailingListPersistence;
3421            @BeanReference(type = MBMessagePersistence.class)
3422            protected MBMessagePersistence mbMessagePersistence;
3423            @BeanReference(type = MBMessageFlagPersistence.class)
3424            protected MBMessageFlagPersistence mbMessageFlagPersistence;
3425            @BeanReference(type = MBStatsUserPersistence.class)
3426            protected MBStatsUserPersistence mbStatsUserPersistence;
3427            @BeanReference(type = MBThreadPersistence.class)
3428            protected MBThreadPersistence mbThreadPersistence;
3429            @BeanReference(type = ResourcePersistence.class)
3430            protected ResourcePersistence resourcePersistence;
3431            @BeanReference(type = UserPersistence.class)
3432            protected UserPersistence userPersistence;
3433            private static final String _SQL_SELECT_MBMESSAGEFLAG = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag";
3434            private static final String _SQL_SELECT_MBMESSAGEFLAG_WHERE = "SELECT mbMessageFlag FROM MBMessageFlag mbMessageFlag WHERE ";
3435            private static final String _SQL_COUNT_MBMESSAGEFLAG = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag";
3436            private static final String _SQL_COUNT_MBMESSAGEFLAG_WHERE = "SELECT COUNT(mbMessageFlag) FROM MBMessageFlag mbMessageFlag WHERE ";
3437            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessageFlag.userId = ?";
3438            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessageFlag.threadId = ?";
3439            private static final String _FINDER_COLUMN_MESSAGEID_MESSAGEID_2 = "mbMessageFlag.messageId = ?";
3440            private static final String _FINDER_COLUMN_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
3441            private static final String _FINDER_COLUMN_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
3442            private static final String _FINDER_COLUMN_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
3443            private static final String _FINDER_COLUMN_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
3444            private static final String _FINDER_COLUMN_U_T_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
3445            private static final String _FINDER_COLUMN_U_T_F_THREADID_2 = "mbMessageFlag.threadId = ? AND ";
3446            private static final String _FINDER_COLUMN_U_T_F_FLAG_2 = "mbMessageFlag.flag = ?";
3447            private static final String _FINDER_COLUMN_U_M_F_USERID_2 = "mbMessageFlag.userId = ? AND ";
3448            private static final String _FINDER_COLUMN_U_M_F_MESSAGEID_2 = "mbMessageFlag.messageId = ? AND ";
3449            private static final String _FINDER_COLUMN_U_M_F_FLAG_2 = "mbMessageFlag.flag = ?";
3450            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessageFlag.";
3451            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessageFlag exists with the primary key ";
3452            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessageFlag exists with the key {";
3453            private static Log _log = LogFactoryUtil.getLog(MBMessageFlagPersistenceImpl.class);
3454    }