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