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