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