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