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