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