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