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