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