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