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