001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.Session;
025    import com.liferay.portal.kernel.exception.SystemException;
026    import com.liferay.portal.kernel.log.Log;
027    import com.liferay.portal.kernel.log.LogFactoryUtil;
028    import com.liferay.portal.kernel.util.GetterUtil;
029    import com.liferay.portal.kernel.util.InstanceFactory;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.StringUtil;
034    import com.liferay.portal.kernel.util.UnmodifiableList;
035    import com.liferay.portal.model.CacheModel;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038    
039    import com.liferay.portlet.messageboards.NoSuchThreadFlagException;
040    import com.liferay.portlet.messageboards.model.MBThreadFlag;
041    import com.liferay.portlet.messageboards.model.impl.MBThreadFlagImpl;
042    import com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl;
043    
044    import java.io.Serializable;
045    
046    import java.util.ArrayList;
047    import java.util.Collections;
048    import java.util.List;
049    
050    /**
051     * The persistence implementation for the message boards thread flag service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see MBThreadFlagPersistence
059     * @see MBThreadFlagUtil
060     * @generated
061     */
062    public class MBThreadFlagPersistenceImpl extends BasePersistenceImpl<MBThreadFlag>
063            implements MBThreadFlagPersistence {
064            /*
065             * NOTE FOR DEVELOPERS:
066             *
067             * Never modify or reference this class directly. Always use {@link MBThreadFlagUtil} to access the message boards thread flag persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
068             */
069            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadFlagImpl.class.getName();
070            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071                    ".List1";
072            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073                    ".List2";
074            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
075                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
076                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
078                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
081                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
082                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
084                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
085                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
086                            new String[] {
087                                    Long.class.getName(),
088                                    
089                            Integer.class.getName(), Integer.class.getName(),
090                                    OrderByComparator.class.getName()
091                            });
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
093                    new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
094                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
096                            new String[] { Long.class.getName() },
097                            MBThreadFlagModelImpl.USERID_COLUMN_BITMASK);
098            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
099                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
100                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
101                            new String[] { Long.class.getName() });
102    
103            /**
104             * Returns all the message boards thread flags where userId = &#63;.
105             *
106             * @param userId the user ID
107             * @return the matching message boards thread flags
108             * @throws SystemException if a system exception occurred
109             */
110            public List<MBThreadFlag> findByUserId(long userId)
111                    throws SystemException {
112                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
113            }
114    
115            /**
116             * Returns a range of all the message boards thread flags where userId = &#63;.
117             *
118             * <p>
119             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
120             * </p>
121             *
122             * @param userId the user ID
123             * @param start the lower bound of the range of message boards thread flags
124             * @param end the upper bound of the range of message boards thread flags (not inclusive)
125             * @return the range of matching message boards thread flags
126             * @throws SystemException if a system exception occurred
127             */
128            public List<MBThreadFlag> findByUserId(long userId, int start, int end)
129                    throws SystemException {
130                    return findByUserId(userId, start, end, null);
131            }
132    
133            /**
134             * Returns an ordered range of all the message boards thread flags where userId = &#63;.
135             *
136             * <p>
137             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
138             * </p>
139             *
140             * @param userId the user ID
141             * @param start the lower bound of the range of message boards thread flags
142             * @param end the upper bound of the range of message boards thread flags (not inclusive)
143             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
144             * @return the ordered range of matching message boards thread flags
145             * @throws SystemException if a system exception occurred
146             */
147            public List<MBThreadFlag> findByUserId(long userId, int start, int end,
148                    OrderByComparator orderByComparator) throws SystemException {
149                    boolean pagination = true;
150                    FinderPath finderPath = null;
151                    Object[] finderArgs = null;
152    
153                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
154                                    (orderByComparator == null)) {
155                            pagination = false;
156                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
157                            finderArgs = new Object[] { userId };
158                    }
159                    else {
160                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
161                            finderArgs = new Object[] { userId, start, end, orderByComparator };
162                    }
163    
164                    List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
165                                    finderArgs, this);
166    
167                    if ((list != null) && !list.isEmpty()) {
168                            for (MBThreadFlag mbThreadFlag : list) {
169                                    if ((userId != mbThreadFlag.getUserId())) {
170                                            list = null;
171    
172                                            break;
173                                    }
174                            }
175                    }
176    
177                    if (list == null) {
178                            StringBundler query = null;
179    
180                            if (orderByComparator != null) {
181                                    query = new StringBundler(3 +
182                                                    (orderByComparator.getOrderByFields().length * 3));
183                            }
184                            else {
185                                    query = new StringBundler(3);
186                            }
187    
188                            query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
189    
190                            query.append(_FINDER_COLUMN_USERID_USERID_2);
191    
192                            if (orderByComparator != null) {
193                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
194                                            orderByComparator);
195                            }
196                            else
197                             if (pagination) {
198                                    query.append(MBThreadFlagModelImpl.ORDER_BY_JPQL);
199                            }
200    
201                            String sql = query.toString();
202    
203                            Session session = null;
204    
205                            try {
206                                    session = openSession();
207    
208                                    Query q = session.createQuery(sql);
209    
210                                    QueryPos qPos = QueryPos.getInstance(q);
211    
212                                    qPos.add(userId);
213    
214                                    if (!pagination) {
215                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
216                                                            start, end, false);
217    
218                                            Collections.sort(list);
219    
220                                            list = new UnmodifiableList<MBThreadFlag>(list);
221                                    }
222                                    else {
223                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
224                                                            start, end);
225                                    }
226    
227                                    cacheResult(list);
228    
229                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
230                            }
231                            catch (Exception e) {
232                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
233    
234                                    throw processException(e);
235                            }
236                            finally {
237                                    closeSession(session);
238                            }
239                    }
240    
241                    return list;
242            }
243    
244            /**
245             * Returns the first message boards thread flag in the ordered set where userId = &#63;.
246             *
247             * @param userId the user ID
248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
249             * @return the first matching message boards thread flag
250             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
251             * @throws SystemException if a system exception occurred
252             */
253            public MBThreadFlag findByUserId_First(long userId,
254                    OrderByComparator orderByComparator)
255                    throws NoSuchThreadFlagException, SystemException {
256                    MBThreadFlag mbThreadFlag = fetchByUserId_First(userId,
257                                    orderByComparator);
258    
259                    if (mbThreadFlag != null) {
260                            return mbThreadFlag;
261                    }
262    
263                    StringBundler msg = new StringBundler(4);
264    
265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
266    
267                    msg.append("userId=");
268                    msg.append(userId);
269    
270                    msg.append(StringPool.CLOSE_CURLY_BRACE);
271    
272                    throw new NoSuchThreadFlagException(msg.toString());
273            }
274    
275            /**
276             * Returns the first message boards thread flag in the ordered set where userId = &#63;.
277             *
278             * @param userId the user ID
279             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
280             * @return the first matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
281             * @throws SystemException if a system exception occurred
282             */
283            public MBThreadFlag fetchByUserId_First(long userId,
284                    OrderByComparator orderByComparator) throws SystemException {
285                    List<MBThreadFlag> list = findByUserId(userId, 0, 1, orderByComparator);
286    
287                    if (!list.isEmpty()) {
288                            return list.get(0);
289                    }
290    
291                    return null;
292            }
293    
294            /**
295             * Returns the last message boards thread flag in the ordered set where userId = &#63;.
296             *
297             * @param userId the user ID
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the last matching message boards thread flag
300             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
301             * @throws SystemException if a system exception occurred
302             */
303            public MBThreadFlag findByUserId_Last(long userId,
304                    OrderByComparator orderByComparator)
305                    throws NoSuchThreadFlagException, SystemException {
306                    MBThreadFlag mbThreadFlag = fetchByUserId_Last(userId, orderByComparator);
307    
308                    if (mbThreadFlag != null) {
309                            return mbThreadFlag;
310                    }
311    
312                    StringBundler msg = new StringBundler(4);
313    
314                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
315    
316                    msg.append("userId=");
317                    msg.append(userId);
318    
319                    msg.append(StringPool.CLOSE_CURLY_BRACE);
320    
321                    throw new NoSuchThreadFlagException(msg.toString());
322            }
323    
324            /**
325             * Returns the last message boards thread flag in the ordered set where userId = &#63;.
326             *
327             * @param userId the user ID
328             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
329             * @return the last matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
330             * @throws SystemException if a system exception occurred
331             */
332            public MBThreadFlag fetchByUserId_Last(long userId,
333                    OrderByComparator orderByComparator) throws SystemException {
334                    int count = countByUserId(userId);
335    
336                    List<MBThreadFlag> list = findByUserId(userId, count - 1, count,
337                                    orderByComparator);
338    
339                    if (!list.isEmpty()) {
340                            return list.get(0);
341                    }
342    
343                    return null;
344            }
345    
346            /**
347             * Returns the message boards thread flags before and after the current message boards thread flag in the ordered set where userId = &#63;.
348             *
349             * @param threadFlagId the primary key of the current message boards thread flag
350             * @param userId the user ID
351             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
352             * @return the previous, current, and next message boards thread flag
353             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
354             * @throws SystemException if a system exception occurred
355             */
356            public MBThreadFlag[] findByUserId_PrevAndNext(long threadFlagId,
357                    long userId, OrderByComparator orderByComparator)
358                    throws NoSuchThreadFlagException, SystemException {
359                    MBThreadFlag mbThreadFlag = findByPrimaryKey(threadFlagId);
360    
361                    Session session = null;
362    
363                    try {
364                            session = openSession();
365    
366                            MBThreadFlag[] array = new MBThreadFlagImpl[3];
367    
368                            array[0] = getByUserId_PrevAndNext(session, mbThreadFlag, userId,
369                                            orderByComparator, true);
370    
371                            array[1] = mbThreadFlag;
372    
373                            array[2] = getByUserId_PrevAndNext(session, mbThreadFlag, userId,
374                                            orderByComparator, false);
375    
376                            return array;
377                    }
378                    catch (Exception e) {
379                            throw processException(e);
380                    }
381                    finally {
382                            closeSession(session);
383                    }
384            }
385    
386            protected MBThreadFlag getByUserId_PrevAndNext(Session session,
387                    MBThreadFlag mbThreadFlag, long userId,
388                    OrderByComparator orderByComparator, boolean previous) {
389                    StringBundler query = null;
390    
391                    if (orderByComparator != null) {
392                            query = new StringBundler(6 +
393                                            (orderByComparator.getOrderByFields().length * 6));
394                    }
395                    else {
396                            query = new StringBundler(3);
397                    }
398    
399                    query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
400    
401                    query.append(_FINDER_COLUMN_USERID_USERID_2);
402    
403                    if (orderByComparator != null) {
404                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
405    
406                            if (orderByConditionFields.length > 0) {
407                                    query.append(WHERE_AND);
408                            }
409    
410                            for (int i = 0; i < orderByConditionFields.length; i++) {
411                                    query.append(_ORDER_BY_ENTITY_ALIAS);
412                                    query.append(orderByConditionFields[i]);
413    
414                                    if ((i + 1) < orderByConditionFields.length) {
415                                            if (orderByComparator.isAscending() ^ previous) {
416                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
417                                            }
418                                            else {
419                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
420                                            }
421                                    }
422                                    else {
423                                            if (orderByComparator.isAscending() ^ previous) {
424                                                    query.append(WHERE_GREATER_THAN);
425                                            }
426                                            else {
427                                                    query.append(WHERE_LESSER_THAN);
428                                            }
429                                    }
430                            }
431    
432                            query.append(ORDER_BY_CLAUSE);
433    
434                            String[] orderByFields = orderByComparator.getOrderByFields();
435    
436                            for (int i = 0; i < orderByFields.length; i++) {
437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
438                                    query.append(orderByFields[i]);
439    
440                                    if ((i + 1) < orderByFields.length) {
441                                            if (orderByComparator.isAscending() ^ previous) {
442                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
443                                            }
444                                            else {
445                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
446                                            }
447                                    }
448                                    else {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(ORDER_BY_ASC);
451                                            }
452                                            else {
453                                                    query.append(ORDER_BY_DESC);
454                                            }
455                                    }
456                            }
457                    }
458                    else {
459                            query.append(MBThreadFlagModelImpl.ORDER_BY_JPQL);
460                    }
461    
462                    String sql = query.toString();
463    
464                    Query q = session.createQuery(sql);
465    
466                    q.setFirstResult(0);
467                    q.setMaxResults(2);
468    
469                    QueryPos qPos = QueryPos.getInstance(q);
470    
471                    qPos.add(userId);
472    
473                    if (orderByComparator != null) {
474                            Object[] values = orderByComparator.getOrderByConditionValues(mbThreadFlag);
475    
476                            for (Object value : values) {
477                                    qPos.add(value);
478                            }
479                    }
480    
481                    List<MBThreadFlag> list = q.list();
482    
483                    if (list.size() == 2) {
484                            return list.get(1);
485                    }
486                    else {
487                            return null;
488                    }
489            }
490    
491            /**
492             * Removes all the message boards thread flags where userId = &#63; from the database.
493             *
494             * @param userId the user ID
495             * @throws SystemException if a system exception occurred
496             */
497            public void removeByUserId(long userId) throws SystemException {
498                    for (MBThreadFlag mbThreadFlag : findByUserId(userId,
499                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
500                            remove(mbThreadFlag);
501                    }
502            }
503    
504            /**
505             * Returns the number of message boards thread flags where userId = &#63;.
506             *
507             * @param userId the user ID
508             * @return the number of matching message boards thread flags
509             * @throws SystemException if a system exception occurred
510             */
511            public int countByUserId(long userId) throws SystemException {
512                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
513    
514                    Object[] finderArgs = new Object[] { userId };
515    
516                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
517                                    this);
518    
519                    if (count == null) {
520                            StringBundler query = new StringBundler(2);
521    
522                            query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
523    
524                            query.append(_FINDER_COLUMN_USERID_USERID_2);
525    
526                            String sql = query.toString();
527    
528                            Session session = null;
529    
530                            try {
531                                    session = openSession();
532    
533                                    Query q = session.createQuery(sql);
534    
535                                    QueryPos qPos = QueryPos.getInstance(q);
536    
537                                    qPos.add(userId);
538    
539                                    count = (Long)q.uniqueResult();
540    
541                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
542                            }
543                            catch (Exception e) {
544                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
545    
546                                    throw processException(e);
547                            }
548                            finally {
549                                    closeSession(session);
550                            }
551                    }
552    
553                    return count.intValue();
554            }
555    
556            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbThreadFlag.userId = ?";
557            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
558                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
559                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
560                            new String[] {
561                                    Long.class.getName(),
562                                    
563                            Integer.class.getName(), Integer.class.getName(),
564                                    OrderByComparator.class.getName()
565                            });
566            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
567                    new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
568                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
569                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
570                            new String[] { Long.class.getName() },
571                            MBThreadFlagModelImpl.THREADID_COLUMN_BITMASK);
572            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
573                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
574                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
575                            new String[] { Long.class.getName() });
576    
577            /**
578             * Returns all the message boards thread flags where threadId = &#63;.
579             *
580             * @param threadId the thread ID
581             * @return the matching message boards thread flags
582             * @throws SystemException if a system exception occurred
583             */
584            public List<MBThreadFlag> findByThreadId(long threadId)
585                    throws SystemException {
586                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
587                            null);
588            }
589    
590            /**
591             * Returns a range of all the message boards thread flags where threadId = &#63;.
592             *
593             * <p>
594             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
595             * </p>
596             *
597             * @param threadId the thread ID
598             * @param start the lower bound of the range of message boards thread flags
599             * @param end the upper bound of the range of message boards thread flags (not inclusive)
600             * @return the range of matching message boards thread flags
601             * @throws SystemException if a system exception occurred
602             */
603            public List<MBThreadFlag> findByThreadId(long threadId, int start, int end)
604                    throws SystemException {
605                    return findByThreadId(threadId, start, end, null);
606            }
607    
608            /**
609             * Returns an ordered range of all the message boards thread flags where threadId = &#63;.
610             *
611             * <p>
612             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
613             * </p>
614             *
615             * @param threadId the thread ID
616             * @param start the lower bound of the range of message boards thread flags
617             * @param end the upper bound of the range of message boards thread flags (not inclusive)
618             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
619             * @return the ordered range of matching message boards thread flags
620             * @throws SystemException if a system exception occurred
621             */
622            public List<MBThreadFlag> findByThreadId(long threadId, int start, int end,
623                    OrderByComparator orderByComparator) throws SystemException {
624                    boolean pagination = true;
625                    FinderPath finderPath = null;
626                    Object[] finderArgs = null;
627    
628                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
629                                    (orderByComparator == null)) {
630                            pagination = false;
631                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
632                            finderArgs = new Object[] { threadId };
633                    }
634                    else {
635                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
636                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
637                    }
638    
639                    List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
640                                    finderArgs, this);
641    
642                    if ((list != null) && !list.isEmpty()) {
643                            for (MBThreadFlag mbThreadFlag : list) {
644                                    if ((threadId != mbThreadFlag.getThreadId())) {
645                                            list = null;
646    
647                                            break;
648                                    }
649                            }
650                    }
651    
652                    if (list == null) {
653                            StringBundler query = null;
654    
655                            if (orderByComparator != null) {
656                                    query = new StringBundler(3 +
657                                                    (orderByComparator.getOrderByFields().length * 3));
658                            }
659                            else {
660                                    query = new StringBundler(3);
661                            }
662    
663                            query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
664    
665                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
666    
667                            if (orderByComparator != null) {
668                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
669                                            orderByComparator);
670                            }
671                            else
672                             if (pagination) {
673                                    query.append(MBThreadFlagModelImpl.ORDER_BY_JPQL);
674                            }
675    
676                            String sql = query.toString();
677    
678                            Session session = null;
679    
680                            try {
681                                    session = openSession();
682    
683                                    Query q = session.createQuery(sql);
684    
685                                    QueryPos qPos = QueryPos.getInstance(q);
686    
687                                    qPos.add(threadId);
688    
689                                    if (!pagination) {
690                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
691                                                            start, end, false);
692    
693                                            Collections.sort(list);
694    
695                                            list = new UnmodifiableList<MBThreadFlag>(list);
696                                    }
697                                    else {
698                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
699                                                            start, end);
700                                    }
701    
702                                    cacheResult(list);
703    
704                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
705                            }
706                            catch (Exception e) {
707                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
708    
709                                    throw processException(e);
710                            }
711                            finally {
712                                    closeSession(session);
713                            }
714                    }
715    
716                    return list;
717            }
718    
719            /**
720             * Returns the first message boards thread flag in the ordered set where threadId = &#63;.
721             *
722             * @param threadId the thread ID
723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
724             * @return the first matching message boards thread flag
725             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
726             * @throws SystemException if a system exception occurred
727             */
728            public MBThreadFlag findByThreadId_First(long threadId,
729                    OrderByComparator orderByComparator)
730                    throws NoSuchThreadFlagException, SystemException {
731                    MBThreadFlag mbThreadFlag = fetchByThreadId_First(threadId,
732                                    orderByComparator);
733    
734                    if (mbThreadFlag != null) {
735                            return mbThreadFlag;
736                    }
737    
738                    StringBundler msg = new StringBundler(4);
739    
740                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
741    
742                    msg.append("threadId=");
743                    msg.append(threadId);
744    
745                    msg.append(StringPool.CLOSE_CURLY_BRACE);
746    
747                    throw new NoSuchThreadFlagException(msg.toString());
748            }
749    
750            /**
751             * Returns the first message boards thread flag in the ordered set where threadId = &#63;.
752             *
753             * @param threadId the thread ID
754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
755             * @return the first matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
756             * @throws SystemException if a system exception occurred
757             */
758            public MBThreadFlag fetchByThreadId_First(long threadId,
759                    OrderByComparator orderByComparator) throws SystemException {
760                    List<MBThreadFlag> list = findByThreadId(threadId, 0, 1,
761                                    orderByComparator);
762    
763                    if (!list.isEmpty()) {
764                            return list.get(0);
765                    }
766    
767                    return null;
768            }
769    
770            /**
771             * Returns the last message boards thread flag in the ordered set where threadId = &#63;.
772             *
773             * @param threadId the thread ID
774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
775             * @return the last matching message boards thread flag
776             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
777             * @throws SystemException if a system exception occurred
778             */
779            public MBThreadFlag findByThreadId_Last(long threadId,
780                    OrderByComparator orderByComparator)
781                    throws NoSuchThreadFlagException, SystemException {
782                    MBThreadFlag mbThreadFlag = fetchByThreadId_Last(threadId,
783                                    orderByComparator);
784    
785                    if (mbThreadFlag != null) {
786                            return mbThreadFlag;
787                    }
788    
789                    StringBundler msg = new StringBundler(4);
790    
791                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
792    
793                    msg.append("threadId=");
794                    msg.append(threadId);
795    
796                    msg.append(StringPool.CLOSE_CURLY_BRACE);
797    
798                    throw new NoSuchThreadFlagException(msg.toString());
799            }
800    
801            /**
802             * Returns the last message boards thread flag in the ordered set where threadId = &#63;.
803             *
804             * @param threadId the thread ID
805             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
806             * @return the last matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
807             * @throws SystemException if a system exception occurred
808             */
809            public MBThreadFlag fetchByThreadId_Last(long threadId,
810                    OrderByComparator orderByComparator) throws SystemException {
811                    int count = countByThreadId(threadId);
812    
813                    List<MBThreadFlag> list = findByThreadId(threadId, count - 1, count,
814                                    orderByComparator);
815    
816                    if (!list.isEmpty()) {
817                            return list.get(0);
818                    }
819    
820                    return null;
821            }
822    
823            /**
824             * Returns the message boards thread flags before and after the current message boards thread flag in the ordered set where threadId = &#63;.
825             *
826             * @param threadFlagId the primary key of the current message boards thread flag
827             * @param threadId the thread ID
828             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
829             * @return the previous, current, and next message boards thread flag
830             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
831             * @throws SystemException if a system exception occurred
832             */
833            public MBThreadFlag[] findByThreadId_PrevAndNext(long threadFlagId,
834                    long threadId, OrderByComparator orderByComparator)
835                    throws NoSuchThreadFlagException, SystemException {
836                    MBThreadFlag mbThreadFlag = findByPrimaryKey(threadFlagId);
837    
838                    Session session = null;
839    
840                    try {
841                            session = openSession();
842    
843                            MBThreadFlag[] array = new MBThreadFlagImpl[3];
844    
845                            array[0] = getByThreadId_PrevAndNext(session, mbThreadFlag,
846                                            threadId, orderByComparator, true);
847    
848                            array[1] = mbThreadFlag;
849    
850                            array[2] = getByThreadId_PrevAndNext(session, mbThreadFlag,
851                                            threadId, orderByComparator, false);
852    
853                            return array;
854                    }
855                    catch (Exception e) {
856                            throw processException(e);
857                    }
858                    finally {
859                            closeSession(session);
860                    }
861            }
862    
863            protected MBThreadFlag getByThreadId_PrevAndNext(Session session,
864                    MBThreadFlag mbThreadFlag, long threadId,
865                    OrderByComparator orderByComparator, boolean previous) {
866                    StringBundler query = null;
867    
868                    if (orderByComparator != null) {
869                            query = new StringBundler(6 +
870                                            (orderByComparator.getOrderByFields().length * 6));
871                    }
872                    else {
873                            query = new StringBundler(3);
874                    }
875    
876                    query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
877    
878                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
879    
880                    if (orderByComparator != null) {
881                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
882    
883                            if (orderByConditionFields.length > 0) {
884                                    query.append(WHERE_AND);
885                            }
886    
887                            for (int i = 0; i < orderByConditionFields.length; i++) {
888                                    query.append(_ORDER_BY_ENTITY_ALIAS);
889                                    query.append(orderByConditionFields[i]);
890    
891                                    if ((i + 1) < orderByConditionFields.length) {
892                                            if (orderByComparator.isAscending() ^ previous) {
893                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
894                                            }
895                                            else {
896                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
897                                            }
898                                    }
899                                    else {
900                                            if (orderByComparator.isAscending() ^ previous) {
901                                                    query.append(WHERE_GREATER_THAN);
902                                            }
903                                            else {
904                                                    query.append(WHERE_LESSER_THAN);
905                                            }
906                                    }
907                            }
908    
909                            query.append(ORDER_BY_CLAUSE);
910    
911                            String[] orderByFields = orderByComparator.getOrderByFields();
912    
913                            for (int i = 0; i < orderByFields.length; i++) {
914                                    query.append(_ORDER_BY_ENTITY_ALIAS);
915                                    query.append(orderByFields[i]);
916    
917                                    if ((i + 1) < orderByFields.length) {
918                                            if (orderByComparator.isAscending() ^ previous) {
919                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
920                                            }
921                                            else {
922                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
923                                            }
924                                    }
925                                    else {
926                                            if (orderByComparator.isAscending() ^ previous) {
927                                                    query.append(ORDER_BY_ASC);
928                                            }
929                                            else {
930                                                    query.append(ORDER_BY_DESC);
931                                            }
932                                    }
933                            }
934                    }
935                    else {
936                            query.append(MBThreadFlagModelImpl.ORDER_BY_JPQL);
937                    }
938    
939                    String sql = query.toString();
940    
941                    Query q = session.createQuery(sql);
942    
943                    q.setFirstResult(0);
944                    q.setMaxResults(2);
945    
946                    QueryPos qPos = QueryPos.getInstance(q);
947    
948                    qPos.add(threadId);
949    
950                    if (orderByComparator != null) {
951                            Object[] values = orderByComparator.getOrderByConditionValues(mbThreadFlag);
952    
953                            for (Object value : values) {
954                                    qPos.add(value);
955                            }
956                    }
957    
958                    List<MBThreadFlag> list = q.list();
959    
960                    if (list.size() == 2) {
961                            return list.get(1);
962                    }
963                    else {
964                            return null;
965                    }
966            }
967    
968            /**
969             * Removes all the message boards thread flags where threadId = &#63; from the database.
970             *
971             * @param threadId the thread ID
972             * @throws SystemException if a system exception occurred
973             */
974            public void removeByThreadId(long threadId) throws SystemException {
975                    for (MBThreadFlag mbThreadFlag : findByThreadId(threadId,
976                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
977                            remove(mbThreadFlag);
978                    }
979            }
980    
981            /**
982             * Returns the number of message boards thread flags where threadId = &#63;.
983             *
984             * @param threadId the thread ID
985             * @return the number of matching message boards thread flags
986             * @throws SystemException if a system exception occurred
987             */
988            public int countByThreadId(long threadId) throws SystemException {
989                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
990    
991                    Object[] finderArgs = new Object[] { threadId };
992    
993                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
994                                    this);
995    
996                    if (count == null) {
997                            StringBundler query = new StringBundler(2);
998    
999                            query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1000    
1001                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1002    
1003                            String sql = query.toString();
1004    
1005                            Session session = null;
1006    
1007                            try {
1008                                    session = openSession();
1009    
1010                                    Query q = session.createQuery(sql);
1011    
1012                                    QueryPos qPos = QueryPos.getInstance(q);
1013    
1014                                    qPos.add(threadId);
1015    
1016                                    count = (Long)q.uniqueResult();
1017    
1018                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1019                            }
1020                            catch (Exception e) {
1021                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1022    
1023                                    throw processException(e);
1024                            }
1025                            finally {
1026                                    closeSession(session);
1027                            }
1028                    }
1029    
1030                    return count.intValue();
1031            }
1032    
1033            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbThreadFlag.threadId = ?";
1034            public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1035                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
1036                            FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
1037                            new String[] { Long.class.getName(), Long.class.getName() },
1038                            MBThreadFlagModelImpl.USERID_COLUMN_BITMASK |
1039                            MBThreadFlagModelImpl.THREADID_COLUMN_BITMASK);
1040            public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1041                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
1042                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
1043                            new String[] { Long.class.getName(), Long.class.getName() });
1044    
1045            /**
1046             * Returns the message boards thread flag where userId = &#63; and threadId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadFlagException} if it could not be found.
1047             *
1048             * @param userId the user ID
1049             * @param threadId the thread ID
1050             * @return the matching message boards thread flag
1051             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
1052             * @throws SystemException if a system exception occurred
1053             */
1054            public MBThreadFlag findByU_T(long userId, long threadId)
1055                    throws NoSuchThreadFlagException, SystemException {
1056                    MBThreadFlag mbThreadFlag = fetchByU_T(userId, threadId);
1057    
1058                    if (mbThreadFlag == null) {
1059                            StringBundler msg = new StringBundler(6);
1060    
1061                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1062    
1063                            msg.append("userId=");
1064                            msg.append(userId);
1065    
1066                            msg.append(", threadId=");
1067                            msg.append(threadId);
1068    
1069                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1070    
1071                            if (_log.isWarnEnabled()) {
1072                                    _log.warn(msg.toString());
1073                            }
1074    
1075                            throw new NoSuchThreadFlagException(msg.toString());
1076                    }
1077    
1078                    return mbThreadFlag;
1079            }
1080    
1081            /**
1082             * Returns the message boards thread flag where userId = &#63; and threadId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1083             *
1084             * @param userId the user ID
1085             * @param threadId the thread ID
1086             * @return the matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
1087             * @throws SystemException if a system exception occurred
1088             */
1089            public MBThreadFlag fetchByU_T(long userId, long threadId)
1090                    throws SystemException {
1091                    return fetchByU_T(userId, threadId, true);
1092            }
1093    
1094            /**
1095             * Returns the message boards thread flag where userId = &#63; and threadId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1096             *
1097             * @param userId the user ID
1098             * @param threadId the thread ID
1099             * @param retrieveFromCache whether to use the finder cache
1100             * @return the matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public MBThreadFlag fetchByU_T(long userId, long threadId,
1104                    boolean retrieveFromCache) throws SystemException {
1105                    Object[] finderArgs = new Object[] { userId, threadId };
1106    
1107                    Object result = null;
1108    
1109                    if (retrieveFromCache) {
1110                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
1111                                            finderArgs, this);
1112                    }
1113    
1114                    if (result instanceof MBThreadFlag) {
1115                            MBThreadFlag mbThreadFlag = (MBThreadFlag)result;
1116    
1117                            if ((userId != mbThreadFlag.getUserId()) ||
1118                                            (threadId != mbThreadFlag.getThreadId())) {
1119                                    result = null;
1120                            }
1121                    }
1122    
1123                    if (result == null) {
1124                            StringBundler query = new StringBundler(4);
1125    
1126                            query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
1127    
1128                            query.append(_FINDER_COLUMN_U_T_USERID_2);
1129    
1130                            query.append(_FINDER_COLUMN_U_T_THREADID_2);
1131    
1132                            String sql = query.toString();
1133    
1134                            Session session = null;
1135    
1136                            try {
1137                                    session = openSession();
1138    
1139                                    Query q = session.createQuery(sql);
1140    
1141                                    QueryPos qPos = QueryPos.getInstance(q);
1142    
1143                                    qPos.add(userId);
1144    
1145                                    qPos.add(threadId);
1146    
1147                                    List<MBThreadFlag> list = q.list();
1148    
1149                                    if (list.isEmpty()) {
1150                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1151                                                    finderArgs, list);
1152                                    }
1153                                    else {
1154                                            MBThreadFlag mbThreadFlag = list.get(0);
1155    
1156                                            result = mbThreadFlag;
1157    
1158                                            cacheResult(mbThreadFlag);
1159    
1160                                            if ((mbThreadFlag.getUserId() != userId) ||
1161                                                            (mbThreadFlag.getThreadId() != threadId)) {
1162                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1163                                                            finderArgs, mbThreadFlag);
1164                                            }
1165                                    }
1166                            }
1167                            catch (Exception e) {
1168                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1169                                            finderArgs);
1170    
1171                                    throw processException(e);
1172                            }
1173                            finally {
1174                                    closeSession(session);
1175                            }
1176                    }
1177    
1178                    if (result instanceof List<?>) {
1179                            return null;
1180                    }
1181                    else {
1182                            return (MBThreadFlag)result;
1183                    }
1184            }
1185    
1186            /**
1187             * Removes the message boards thread flag where userId = &#63; and threadId = &#63; from the database.
1188             *
1189             * @param userId the user ID
1190             * @param threadId the thread ID
1191             * @return the message boards thread flag that was removed
1192             * @throws SystemException if a system exception occurred
1193             */
1194            public MBThreadFlag removeByU_T(long userId, long threadId)
1195                    throws NoSuchThreadFlagException, SystemException {
1196                    MBThreadFlag mbThreadFlag = findByU_T(userId, threadId);
1197    
1198                    return remove(mbThreadFlag);
1199            }
1200    
1201            /**
1202             * Returns the number of message boards thread flags where userId = &#63; and threadId = &#63;.
1203             *
1204             * @param userId the user ID
1205             * @param threadId the thread ID
1206             * @return the number of matching message boards thread flags
1207             * @throws SystemException if a system exception occurred
1208             */
1209            public int countByU_T(long userId, long threadId) throws SystemException {
1210                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
1211    
1212                    Object[] finderArgs = new Object[] { userId, threadId };
1213    
1214                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1215                                    this);
1216    
1217                    if (count == null) {
1218                            StringBundler query = new StringBundler(3);
1219    
1220                            query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1221    
1222                            query.append(_FINDER_COLUMN_U_T_USERID_2);
1223    
1224                            query.append(_FINDER_COLUMN_U_T_THREADID_2);
1225    
1226                            String sql = query.toString();
1227    
1228                            Session session = null;
1229    
1230                            try {
1231                                    session = openSession();
1232    
1233                                    Query q = session.createQuery(sql);
1234    
1235                                    QueryPos qPos = QueryPos.getInstance(q);
1236    
1237                                    qPos.add(userId);
1238    
1239                                    qPos.add(threadId);
1240    
1241                                    count = (Long)q.uniqueResult();
1242    
1243                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1244                            }
1245                            catch (Exception e) {
1246                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1247    
1248                                    throw processException(e);
1249                            }
1250                            finally {
1251                                    closeSession(session);
1252                            }
1253                    }
1254    
1255                    return count.intValue();
1256            }
1257    
1258            private static final String _FINDER_COLUMN_U_T_USERID_2 = "mbThreadFlag.userId = ? AND ";
1259            private static final String _FINDER_COLUMN_U_T_THREADID_2 = "mbThreadFlag.threadId = ?";
1260    
1261            /**
1262             * Caches the message boards thread flag in the entity cache if it is enabled.
1263             *
1264             * @param mbThreadFlag the message boards thread flag
1265             */
1266            public void cacheResult(MBThreadFlag mbThreadFlag) {
1267                    EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1268                            MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey(), mbThreadFlag);
1269    
1270                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1271                            new Object[] { mbThreadFlag.getUserId(), mbThreadFlag.getThreadId() },
1272                            mbThreadFlag);
1273    
1274                    mbThreadFlag.resetOriginalValues();
1275            }
1276    
1277            /**
1278             * Caches the message boards thread flags in the entity cache if it is enabled.
1279             *
1280             * @param mbThreadFlags the message boards thread flags
1281             */
1282            public void cacheResult(List<MBThreadFlag> mbThreadFlags) {
1283                    for (MBThreadFlag mbThreadFlag : mbThreadFlags) {
1284                            if (EntityCacheUtil.getResult(
1285                                                    MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1286                                                    MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey()) == null) {
1287                                    cacheResult(mbThreadFlag);
1288                            }
1289                            else {
1290                                    mbThreadFlag.resetOriginalValues();
1291                            }
1292                    }
1293            }
1294    
1295            /**
1296             * Clears the cache for all message boards thread flags.
1297             *
1298             * <p>
1299             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1300             * </p>
1301             */
1302            @Override
1303            public void clearCache() {
1304                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1305                            CacheRegistryUtil.clear(MBThreadFlagImpl.class.getName());
1306                    }
1307    
1308                    EntityCacheUtil.clearCache(MBThreadFlagImpl.class.getName());
1309    
1310                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1311                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1312                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1313            }
1314    
1315            /**
1316             * Clears the cache for the message boards thread flag.
1317             *
1318             * <p>
1319             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
1320             * </p>
1321             */
1322            @Override
1323            public void clearCache(MBThreadFlag mbThreadFlag) {
1324                    EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1325                            MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey());
1326    
1327                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1328                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1329    
1330                    clearUniqueFindersCache(mbThreadFlag);
1331            }
1332    
1333            @Override
1334            public void clearCache(List<MBThreadFlag> mbThreadFlags) {
1335                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1336                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1337    
1338                    for (MBThreadFlag mbThreadFlag : mbThreadFlags) {
1339                            EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1340                                    MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey());
1341    
1342                            clearUniqueFindersCache(mbThreadFlag);
1343                    }
1344            }
1345    
1346            protected void cacheUniqueFindersCache(MBThreadFlag mbThreadFlag) {
1347                    if (mbThreadFlag.isNew()) {
1348                            Object[] args = new Object[] {
1349                                            mbThreadFlag.getUserId(), mbThreadFlag.getThreadId()
1350                                    };
1351    
1352                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1353                                    Long.valueOf(1));
1354                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1355                                    mbThreadFlag);
1356                    }
1357                    else {
1358                            MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
1359    
1360                            if ((mbThreadFlagModelImpl.getColumnBitmask() &
1361                                            FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1362                                    Object[] args = new Object[] {
1363                                                    mbThreadFlag.getUserId(), mbThreadFlag.getThreadId()
1364                                            };
1365    
1366                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
1367                                            Long.valueOf(1));
1368                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
1369                                            mbThreadFlag);
1370                            }
1371                    }
1372            }
1373    
1374            protected void clearUniqueFindersCache(MBThreadFlag mbThreadFlag) {
1375                    MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
1376    
1377                    Object[] args = new Object[] {
1378                                    mbThreadFlag.getUserId(), mbThreadFlag.getThreadId()
1379                            };
1380    
1381                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1382                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1383    
1384                    if ((mbThreadFlagModelImpl.getColumnBitmask() &
1385                                    FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
1386                            args = new Object[] {
1387                                            mbThreadFlagModelImpl.getOriginalUserId(),
1388                                            mbThreadFlagModelImpl.getOriginalThreadId()
1389                                    };
1390    
1391                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
1392                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
1393                    }
1394            }
1395    
1396            /**
1397             * Creates a new message boards thread flag with the primary key. Does not add the message boards thread flag to the database.
1398             *
1399             * @param threadFlagId the primary key for the new message boards thread flag
1400             * @return the new message boards thread flag
1401             */
1402            public MBThreadFlag create(long threadFlagId) {
1403                    MBThreadFlag mbThreadFlag = new MBThreadFlagImpl();
1404    
1405                    mbThreadFlag.setNew(true);
1406                    mbThreadFlag.setPrimaryKey(threadFlagId);
1407    
1408                    return mbThreadFlag;
1409            }
1410    
1411            /**
1412             * Removes the message boards thread flag with the primary key from the database. Also notifies the appropriate model listeners.
1413             *
1414             * @param threadFlagId the primary key of the message boards thread flag
1415             * @return the message boards thread flag that was removed
1416             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
1417             * @throws SystemException if a system exception occurred
1418             */
1419            public MBThreadFlag remove(long threadFlagId)
1420                    throws NoSuchThreadFlagException, SystemException {
1421                    return remove((Serializable)threadFlagId);
1422            }
1423    
1424            /**
1425             * Removes the message boards thread flag with the primary key from the database. Also notifies the appropriate model listeners.
1426             *
1427             * @param primaryKey the primary key of the message boards thread flag
1428             * @return the message boards thread flag that was removed
1429             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
1430             * @throws SystemException if a system exception occurred
1431             */
1432            @Override
1433            public MBThreadFlag remove(Serializable primaryKey)
1434                    throws NoSuchThreadFlagException, SystemException {
1435                    Session session = null;
1436    
1437                    try {
1438                            session = openSession();
1439    
1440                            MBThreadFlag mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
1441                                            primaryKey);
1442    
1443                            if (mbThreadFlag == null) {
1444                                    if (_log.isWarnEnabled()) {
1445                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1446                                    }
1447    
1448                                    throw new NoSuchThreadFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1449                                            primaryKey);
1450                            }
1451    
1452                            return remove(mbThreadFlag);
1453                    }
1454                    catch (NoSuchThreadFlagException nsee) {
1455                            throw nsee;
1456                    }
1457                    catch (Exception e) {
1458                            throw processException(e);
1459                    }
1460                    finally {
1461                            closeSession(session);
1462                    }
1463            }
1464    
1465            @Override
1466            protected MBThreadFlag removeImpl(MBThreadFlag mbThreadFlag)
1467                    throws SystemException {
1468                    mbThreadFlag = toUnwrappedModel(mbThreadFlag);
1469    
1470                    Session session = null;
1471    
1472                    try {
1473                            session = openSession();
1474    
1475                            if (!session.contains(mbThreadFlag)) {
1476                                    mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
1477                                                    mbThreadFlag.getPrimaryKeyObj());
1478                            }
1479    
1480                            if (mbThreadFlag != null) {
1481                                    session.delete(mbThreadFlag);
1482                            }
1483                    }
1484                    catch (Exception e) {
1485                            throw processException(e);
1486                    }
1487                    finally {
1488                            closeSession(session);
1489                    }
1490    
1491                    if (mbThreadFlag != null) {
1492                            clearCache(mbThreadFlag);
1493                    }
1494    
1495                    return mbThreadFlag;
1496            }
1497    
1498            @Override
1499            public MBThreadFlag updateImpl(
1500                    com.liferay.portlet.messageboards.model.MBThreadFlag mbThreadFlag)
1501                    throws SystemException {
1502                    mbThreadFlag = toUnwrappedModel(mbThreadFlag);
1503    
1504                    boolean isNew = mbThreadFlag.isNew();
1505    
1506                    MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
1507    
1508                    Session session = null;
1509    
1510                    try {
1511                            session = openSession();
1512    
1513                            if (mbThreadFlag.isNew()) {
1514                                    session.save(mbThreadFlag);
1515    
1516                                    mbThreadFlag.setNew(false);
1517                            }
1518                            else {
1519                                    session.merge(mbThreadFlag);
1520                            }
1521                    }
1522                    catch (Exception e) {
1523                            throw processException(e);
1524                    }
1525                    finally {
1526                            closeSession(session);
1527                    }
1528    
1529                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1530    
1531                    if (isNew || !MBThreadFlagModelImpl.COLUMN_BITMASK_ENABLED) {
1532                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1533                    }
1534    
1535                    else {
1536                            if ((mbThreadFlagModelImpl.getColumnBitmask() &
1537                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1538                                    Object[] args = new Object[] {
1539                                                    mbThreadFlagModelImpl.getOriginalUserId()
1540                                            };
1541    
1542                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1543                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1544                                            args);
1545    
1546                                    args = new Object[] { mbThreadFlagModelImpl.getUserId() };
1547    
1548                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1549                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1550                                            args);
1551                            }
1552    
1553                            if ((mbThreadFlagModelImpl.getColumnBitmask() &
1554                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
1555                                    Object[] args = new Object[] {
1556                                                    mbThreadFlagModelImpl.getOriginalThreadId()
1557                                            };
1558    
1559                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1560                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1561                                            args);
1562    
1563                                    args = new Object[] { mbThreadFlagModelImpl.getThreadId() };
1564    
1565                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
1566                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
1567                                            args);
1568                            }
1569                    }
1570    
1571                    EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1572                            MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey(), mbThreadFlag);
1573    
1574                    clearUniqueFindersCache(mbThreadFlag);
1575                    cacheUniqueFindersCache(mbThreadFlag);
1576    
1577                    return mbThreadFlag;
1578            }
1579    
1580            protected MBThreadFlag toUnwrappedModel(MBThreadFlag mbThreadFlag) {
1581                    if (mbThreadFlag instanceof MBThreadFlagImpl) {
1582                            return mbThreadFlag;
1583                    }
1584    
1585                    MBThreadFlagImpl mbThreadFlagImpl = new MBThreadFlagImpl();
1586    
1587                    mbThreadFlagImpl.setNew(mbThreadFlag.isNew());
1588                    mbThreadFlagImpl.setPrimaryKey(mbThreadFlag.getPrimaryKey());
1589    
1590                    mbThreadFlagImpl.setThreadFlagId(mbThreadFlag.getThreadFlagId());
1591                    mbThreadFlagImpl.setUserId(mbThreadFlag.getUserId());
1592                    mbThreadFlagImpl.setModifiedDate(mbThreadFlag.getModifiedDate());
1593                    mbThreadFlagImpl.setThreadId(mbThreadFlag.getThreadId());
1594    
1595                    return mbThreadFlagImpl;
1596            }
1597    
1598            /**
1599             * Returns the message boards thread flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
1600             *
1601             * @param primaryKey the primary key of the message boards thread flag
1602             * @return the message boards thread flag
1603             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
1604             * @throws SystemException if a system exception occurred
1605             */
1606            @Override
1607            public MBThreadFlag findByPrimaryKey(Serializable primaryKey)
1608                    throws NoSuchThreadFlagException, SystemException {
1609                    MBThreadFlag mbThreadFlag = fetchByPrimaryKey(primaryKey);
1610    
1611                    if (mbThreadFlag == null) {
1612                            if (_log.isWarnEnabled()) {
1613                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1614                            }
1615    
1616                            throw new NoSuchThreadFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1617                                    primaryKey);
1618                    }
1619    
1620                    return mbThreadFlag;
1621            }
1622    
1623            /**
1624             * Returns the message boards thread flag with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadFlagException} if it could not be found.
1625             *
1626             * @param threadFlagId the primary key of the message boards thread flag
1627             * @return the message boards thread flag
1628             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
1629             * @throws SystemException if a system exception occurred
1630             */
1631            public MBThreadFlag findByPrimaryKey(long threadFlagId)
1632                    throws NoSuchThreadFlagException, SystemException {
1633                    return findByPrimaryKey((Serializable)threadFlagId);
1634            }
1635    
1636            /**
1637             * Returns the message boards thread flag with the primary key or returns <code>null</code> if it could not be found.
1638             *
1639             * @param primaryKey the primary key of the message boards thread flag
1640             * @return the message boards thread flag, or <code>null</code> if a message boards thread flag with the primary key could not be found
1641             * @throws SystemException if a system exception occurred
1642             */
1643            @Override
1644            public MBThreadFlag fetchByPrimaryKey(Serializable primaryKey)
1645                    throws SystemException {
1646                    MBThreadFlag mbThreadFlag = (MBThreadFlag)EntityCacheUtil.getResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1647                                    MBThreadFlagImpl.class, primaryKey);
1648    
1649                    if (mbThreadFlag == _nullMBThreadFlag) {
1650                            return null;
1651                    }
1652    
1653                    if (mbThreadFlag == null) {
1654                            Session session = null;
1655    
1656                            try {
1657                                    session = openSession();
1658    
1659                                    mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
1660                                                    primaryKey);
1661    
1662                                    if (mbThreadFlag != null) {
1663                                            cacheResult(mbThreadFlag);
1664                                    }
1665                                    else {
1666                                            EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1667                                                    MBThreadFlagImpl.class, primaryKey, _nullMBThreadFlag);
1668                                    }
1669                            }
1670                            catch (Exception e) {
1671                                    EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
1672                                            MBThreadFlagImpl.class, primaryKey);
1673    
1674                                    throw processException(e);
1675                            }
1676                            finally {
1677                                    closeSession(session);
1678                            }
1679                    }
1680    
1681                    return mbThreadFlag;
1682            }
1683    
1684            /**
1685             * Returns the message boards thread flag with the primary key or returns <code>null</code> if it could not be found.
1686             *
1687             * @param threadFlagId the primary key of the message boards thread flag
1688             * @return the message boards thread flag, or <code>null</code> if a message boards thread flag with the primary key could not be found
1689             * @throws SystemException if a system exception occurred
1690             */
1691            public MBThreadFlag fetchByPrimaryKey(long threadFlagId)
1692                    throws SystemException {
1693                    return fetchByPrimaryKey((Serializable)threadFlagId);
1694            }
1695    
1696            /**
1697             * Returns all the message boards thread flags.
1698             *
1699             * @return the message boards thread flags
1700             * @throws SystemException if a system exception occurred
1701             */
1702            public List<MBThreadFlag> findAll() throws SystemException {
1703                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1704            }
1705    
1706            /**
1707             * Returns a range of all the message boards thread flags.
1708             *
1709             * <p>
1710             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1711             * </p>
1712             *
1713             * @param start the lower bound of the range of message boards thread flags
1714             * @param end the upper bound of the range of message boards thread flags (not inclusive)
1715             * @return the range of message boards thread flags
1716             * @throws SystemException if a system exception occurred
1717             */
1718            public List<MBThreadFlag> findAll(int start, int end)
1719                    throws SystemException {
1720                    return findAll(start, end, null);
1721            }
1722    
1723            /**
1724             * Returns an ordered range of all the message boards thread flags.
1725             *
1726             * <p>
1727             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1728             * </p>
1729             *
1730             * @param start the lower bound of the range of message boards thread flags
1731             * @param end the upper bound of the range of message boards thread flags (not inclusive)
1732             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1733             * @return the ordered range of message boards thread flags
1734             * @throws SystemException if a system exception occurred
1735             */
1736            public List<MBThreadFlag> findAll(int start, int end,
1737                    OrderByComparator orderByComparator) throws SystemException {
1738                    boolean pagination = true;
1739                    FinderPath finderPath = null;
1740                    Object[] finderArgs = null;
1741    
1742                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1743                                    (orderByComparator == null)) {
1744                            pagination = false;
1745                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1746                            finderArgs = FINDER_ARGS_EMPTY;
1747                    }
1748                    else {
1749                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1750                            finderArgs = new Object[] { start, end, orderByComparator };
1751                    }
1752    
1753                    List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
1754                                    finderArgs, this);
1755    
1756                    if (list == null) {
1757                            StringBundler query = null;
1758                            String sql = null;
1759    
1760                            if (orderByComparator != null) {
1761                                    query = new StringBundler(2 +
1762                                                    (orderByComparator.getOrderByFields().length * 3));
1763    
1764                                    query.append(_SQL_SELECT_MBTHREADFLAG);
1765    
1766                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1767                                            orderByComparator);
1768    
1769                                    sql = query.toString();
1770                            }
1771                            else {
1772                                    sql = _SQL_SELECT_MBTHREADFLAG;
1773    
1774                                    if (pagination) {
1775                                            sql = sql.concat(MBThreadFlagModelImpl.ORDER_BY_JPQL);
1776                                    }
1777                            }
1778    
1779                            Session session = null;
1780    
1781                            try {
1782                                    session = openSession();
1783    
1784                                    Query q = session.createQuery(sql);
1785    
1786                                    if (!pagination) {
1787                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1788                                                            start, end, false);
1789    
1790                                            Collections.sort(list);
1791    
1792                                            list = new UnmodifiableList<MBThreadFlag>(list);
1793                                    }
1794                                    else {
1795                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1796                                                            start, end);
1797                                    }
1798    
1799                                    cacheResult(list);
1800    
1801                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1802                            }
1803                            catch (Exception e) {
1804                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1805    
1806                                    throw processException(e);
1807                            }
1808                            finally {
1809                                    closeSession(session);
1810                            }
1811                    }
1812    
1813                    return list;
1814            }
1815    
1816            /**
1817             * Removes all the message boards thread flags from the database.
1818             *
1819             * @throws SystemException if a system exception occurred
1820             */
1821            public void removeAll() throws SystemException {
1822                    for (MBThreadFlag mbThreadFlag : findAll()) {
1823                            remove(mbThreadFlag);
1824                    }
1825            }
1826    
1827            /**
1828             * Returns the number of message boards thread flags.
1829             *
1830             * @return the number of message boards thread flags
1831             * @throws SystemException if a system exception occurred
1832             */
1833            public int countAll() throws SystemException {
1834                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1835                                    FINDER_ARGS_EMPTY, this);
1836    
1837                    if (count == null) {
1838                            Session session = null;
1839    
1840                            try {
1841                                    session = openSession();
1842    
1843                                    Query q = session.createQuery(_SQL_COUNT_MBTHREADFLAG);
1844    
1845                                    count = (Long)q.uniqueResult();
1846    
1847                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1848                                            FINDER_ARGS_EMPTY, count);
1849                            }
1850                            catch (Exception e) {
1851                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1852                                            FINDER_ARGS_EMPTY);
1853    
1854                                    throw processException(e);
1855                            }
1856                            finally {
1857                                    closeSession(session);
1858                            }
1859                    }
1860    
1861                    return count.intValue();
1862            }
1863    
1864            /**
1865             * Initializes the message boards thread flag persistence.
1866             */
1867            public void afterPropertiesSet() {
1868                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1869                                            com.liferay.portal.util.PropsUtil.get(
1870                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBThreadFlag")));
1871    
1872                    if (listenerClassNames.length > 0) {
1873                            try {
1874                                    List<ModelListener<MBThreadFlag>> listenersList = new ArrayList<ModelListener<MBThreadFlag>>();
1875    
1876                                    for (String listenerClassName : listenerClassNames) {
1877                                            listenersList.add((ModelListener<MBThreadFlag>)InstanceFactory.newInstance(
1878                                                            listenerClassName));
1879                                    }
1880    
1881                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1882                            }
1883                            catch (Exception e) {
1884                                    _log.error(e);
1885                            }
1886                    }
1887            }
1888    
1889            public void destroy() {
1890                    EntityCacheUtil.removeCache(MBThreadFlagImpl.class.getName());
1891                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1892                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1893                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1894            }
1895    
1896            private static final String _SQL_SELECT_MBTHREADFLAG = "SELECT mbThreadFlag FROM MBThreadFlag mbThreadFlag";
1897            private static final String _SQL_SELECT_MBTHREADFLAG_WHERE = "SELECT mbThreadFlag FROM MBThreadFlag mbThreadFlag WHERE ";
1898            private static final String _SQL_COUNT_MBTHREADFLAG = "SELECT COUNT(mbThreadFlag) FROM MBThreadFlag mbThreadFlag";
1899            private static final String _SQL_COUNT_MBTHREADFLAG_WHERE = "SELECT COUNT(mbThreadFlag) FROM MBThreadFlag mbThreadFlag WHERE ";
1900            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThreadFlag.";
1901            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThreadFlag exists with the primary key ";
1902            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThreadFlag exists with the key {";
1903            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1904            private static Log _log = LogFactoryUtil.getLog(MBThreadFlagPersistenceImpl.class);
1905            private static MBThreadFlag _nullMBThreadFlag = new MBThreadFlagImpl() {
1906                            @Override
1907                            public Object clone() {
1908                                    return this;
1909                            }
1910    
1911                            @Override
1912                            public CacheModel<MBThreadFlag> toCacheModel() {
1913                                    return _nullMBThreadFlagCacheModel;
1914                            }
1915                    };
1916    
1917            private static CacheModel<MBThreadFlag> _nullMBThreadFlagCacheModel = new CacheModel<MBThreadFlag>() {
1918                            public MBThreadFlag toEntityModel() {
1919                                    return _nullMBThreadFlag;
1920                            }
1921                    };
1922    }