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