001    /**
002     * Copyright (c) 2000-2012 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;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.CacheModel;
037    import com.liferay.portal.model.ModelListener;
038    import com.liferay.portal.service.persistence.BatchSessionUtil;
039    import com.liferay.portal.service.persistence.ResourcePersistence;
040    import com.liferay.portal.service.persistence.UserPersistence;
041    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042    
043    import com.liferay.portlet.messageboards.NoSuchThreadFlagException;
044    import com.liferay.portlet.messageboards.model.MBThreadFlag;
045    import com.liferay.portlet.messageboards.model.impl.MBThreadFlagImpl;
046    import com.liferay.portlet.messageboards.model.impl.MBThreadFlagModelImpl;
047    
048    import java.io.Serializable;
049    
050    import java.util.ArrayList;
051    import java.util.Collections;
052    import java.util.List;
053    
054    /**
055     * The persistence implementation for the message boards thread flag service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see MBThreadFlagPersistence
063     * @see MBThreadFlagUtil
064     * @generated
065     */
066    public class MBThreadFlagPersistenceImpl extends BasePersistenceImpl<MBThreadFlag>
067            implements MBThreadFlagPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * 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.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = MBThreadFlagImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
079                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
081                            new String[] {
082                                    Long.class.getName(),
083                                    
084                            "java.lang.Integer", "java.lang.Integer",
085                                    "com.liferay.portal.kernel.util.OrderByComparator"
086                            });
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
088                    new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
089                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
091                            new String[] { Long.class.getName() },
092                            MBThreadFlagModelImpl.USERID_COLUMN_BITMASK);
093            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
094                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
095                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
096                            new String[] { Long.class.getName() });
097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
098                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
100                            new String[] {
101                                    Long.class.getName(),
102                                    
103                            "java.lang.Integer", "java.lang.Integer",
104                                    "com.liferay.portal.kernel.util.OrderByComparator"
105                            });
106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
107                    new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
108                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
110                            new String[] { Long.class.getName() },
111                            MBThreadFlagModelImpl.THREADID_COLUMN_BITMASK);
112            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
113                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
114                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
115                            new String[] { Long.class.getName() });
116            public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
117                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
118                            FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
119                            new String[] { Long.class.getName(), Long.class.getName() },
120                            MBThreadFlagModelImpl.USERID_COLUMN_BITMASK |
121                            MBThreadFlagModelImpl.THREADID_COLUMN_BITMASK);
122            public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
123                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
124                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
125                            new String[] { Long.class.getName(), Long.class.getName() });
126            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
127                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
128                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
129            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
130                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, MBThreadFlagImpl.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
132            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
133                            MBThreadFlagModelImpl.FINDER_CACHE_ENABLED, Long.class,
134                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
135    
136            /**
137             * Caches the message boards thread flag in the entity cache if it is enabled.
138             *
139             * @param mbThreadFlag the message boards thread flag
140             */
141            public void cacheResult(MBThreadFlag mbThreadFlag) {
142                    EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
143                            MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey(), mbThreadFlag);
144    
145                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
146                            new Object[] {
147                                    Long.valueOf(mbThreadFlag.getUserId()),
148                                    Long.valueOf(mbThreadFlag.getThreadId())
149                            }, mbThreadFlag);
150    
151                    mbThreadFlag.resetOriginalValues();
152            }
153    
154            /**
155             * Caches the message boards thread flags in the entity cache if it is enabled.
156             *
157             * @param mbThreadFlags the message boards thread flags
158             */
159            public void cacheResult(List<MBThreadFlag> mbThreadFlags) {
160                    for (MBThreadFlag mbThreadFlag : mbThreadFlags) {
161                            if (EntityCacheUtil.getResult(
162                                                    MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
163                                                    MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey()) == null) {
164                                    cacheResult(mbThreadFlag);
165                            }
166                            else {
167                                    mbThreadFlag.resetOriginalValues();
168                            }
169                    }
170            }
171    
172            /**
173             * Clears the cache for all message boards thread flags.
174             *
175             * <p>
176             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
177             * </p>
178             */
179            @Override
180            public void clearCache() {
181                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
182                            CacheRegistryUtil.clear(MBThreadFlagImpl.class.getName());
183                    }
184    
185                    EntityCacheUtil.clearCache(MBThreadFlagImpl.class.getName());
186    
187                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
188                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
189                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
190            }
191    
192            /**
193             * Clears the cache for the message boards thread flag.
194             *
195             * <p>
196             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
197             * </p>
198             */
199            @Override
200            public void clearCache(MBThreadFlag mbThreadFlag) {
201                    EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
202                            MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey());
203    
204                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
205                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
206    
207                    clearUniqueFindersCache(mbThreadFlag);
208            }
209    
210            @Override
211            public void clearCache(List<MBThreadFlag> mbThreadFlags) {
212                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
213                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
214    
215                    for (MBThreadFlag mbThreadFlag : mbThreadFlags) {
216                            EntityCacheUtil.removeResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
217                                    MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey());
218    
219                            clearUniqueFindersCache(mbThreadFlag);
220                    }
221            }
222    
223            protected void clearUniqueFindersCache(MBThreadFlag mbThreadFlag) {
224                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
225                            new Object[] {
226                                    Long.valueOf(mbThreadFlag.getUserId()),
227                                    Long.valueOf(mbThreadFlag.getThreadId())
228                            });
229            }
230    
231            /**
232             * Creates a new message boards thread flag with the primary key. Does not add the message boards thread flag to the database.
233             *
234             * @param threadFlagId the primary key for the new message boards thread flag
235             * @return the new message boards thread flag
236             */
237            public MBThreadFlag create(long threadFlagId) {
238                    MBThreadFlag mbThreadFlag = new MBThreadFlagImpl();
239    
240                    mbThreadFlag.setNew(true);
241                    mbThreadFlag.setPrimaryKey(threadFlagId);
242    
243                    return mbThreadFlag;
244            }
245    
246            /**
247             * Removes the message boards thread flag with the primary key from the database. Also notifies the appropriate model listeners.
248             *
249             * @param threadFlagId the primary key of the message boards thread flag
250             * @return the message boards thread flag that was removed
251             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
252             * @throws SystemException if a system exception occurred
253             */
254            public MBThreadFlag remove(long threadFlagId)
255                    throws NoSuchThreadFlagException, SystemException {
256                    return remove(Long.valueOf(threadFlagId));
257            }
258    
259            /**
260             * Removes the message boards thread flag with the primary key from the database. Also notifies the appropriate model listeners.
261             *
262             * @param primaryKey the primary key of the message boards thread flag
263             * @return the message boards thread flag that was removed
264             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
265             * @throws SystemException if a system exception occurred
266             */
267            @Override
268            public MBThreadFlag remove(Serializable primaryKey)
269                    throws NoSuchThreadFlagException, SystemException {
270                    Session session = null;
271    
272                    try {
273                            session = openSession();
274    
275                            MBThreadFlag mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
276                                            primaryKey);
277    
278                            if (mbThreadFlag == null) {
279                                    if (_log.isWarnEnabled()) {
280                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
281                                    }
282    
283                                    throw new NoSuchThreadFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
284                                            primaryKey);
285                            }
286    
287                            return remove(mbThreadFlag);
288                    }
289                    catch (NoSuchThreadFlagException nsee) {
290                            throw nsee;
291                    }
292                    catch (Exception e) {
293                            throw processException(e);
294                    }
295                    finally {
296                            closeSession(session);
297                    }
298            }
299    
300            @Override
301            protected MBThreadFlag removeImpl(MBThreadFlag mbThreadFlag)
302                    throws SystemException {
303                    mbThreadFlag = toUnwrappedModel(mbThreadFlag);
304    
305                    Session session = null;
306    
307                    try {
308                            session = openSession();
309    
310                            BatchSessionUtil.delete(session, mbThreadFlag);
311                    }
312                    catch (Exception e) {
313                            throw processException(e);
314                    }
315                    finally {
316                            closeSession(session);
317                    }
318    
319                    clearCache(mbThreadFlag);
320    
321                    return mbThreadFlag;
322            }
323    
324            @Override
325            public MBThreadFlag updateImpl(
326                    com.liferay.portlet.messageboards.model.MBThreadFlag mbThreadFlag,
327                    boolean merge) throws SystemException {
328                    mbThreadFlag = toUnwrappedModel(mbThreadFlag);
329    
330                    boolean isNew = mbThreadFlag.isNew();
331    
332                    MBThreadFlagModelImpl mbThreadFlagModelImpl = (MBThreadFlagModelImpl)mbThreadFlag;
333    
334                    Session session = null;
335    
336                    try {
337                            session = openSession();
338    
339                            BatchSessionUtil.update(session, mbThreadFlag, merge);
340    
341                            mbThreadFlag.setNew(false);
342                    }
343                    catch (Exception e) {
344                            throw processException(e);
345                    }
346                    finally {
347                            closeSession(session);
348                    }
349    
350                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
351    
352                    if (isNew || !MBThreadFlagModelImpl.COLUMN_BITMASK_ENABLED) {
353                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
354                    }
355                    else {
356                            if ((mbThreadFlagModelImpl.getColumnBitmask() &
357                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
358                                    Object[] args = new Object[] {
359                                                    Long.valueOf(mbThreadFlagModelImpl.getOriginalUserId())
360                                            };
361    
362                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
363                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
364                                            args);
365    
366                                    args = new Object[] {
367                                                    Long.valueOf(mbThreadFlagModelImpl.getUserId())
368                                            };
369    
370                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
371                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
372                                            args);
373                            }
374    
375                            if ((mbThreadFlagModelImpl.getColumnBitmask() &
376                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
377                                    Object[] args = new Object[] {
378                                                    Long.valueOf(mbThreadFlagModelImpl.getOriginalThreadId())
379                                            };
380    
381                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
382                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
383                                            args);
384    
385                                    args = new Object[] {
386                                                    Long.valueOf(mbThreadFlagModelImpl.getThreadId())
387                                            };
388    
389                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
390                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
391                                            args);
392                            }
393                    }
394    
395                    EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
396                            MBThreadFlagImpl.class, mbThreadFlag.getPrimaryKey(), mbThreadFlag);
397    
398                    if (isNew) {
399                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
400                                    new Object[] {
401                                            Long.valueOf(mbThreadFlag.getUserId()),
402                                            Long.valueOf(mbThreadFlag.getThreadId())
403                                    }, mbThreadFlag);
404                    }
405                    else {
406                            if ((mbThreadFlagModelImpl.getColumnBitmask() &
407                                            FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
408                                    Object[] args = new Object[] {
409                                                    Long.valueOf(mbThreadFlagModelImpl.getOriginalUserId()),
410                                                    Long.valueOf(mbThreadFlagModelImpl.getOriginalThreadId())
411                                            };
412    
413                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
414                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
415    
416                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
417                                            new Object[] {
418                                                    Long.valueOf(mbThreadFlag.getUserId()),
419                                                    Long.valueOf(mbThreadFlag.getThreadId())
420                                            }, mbThreadFlag);
421                            }
422                    }
423    
424                    return mbThreadFlag;
425            }
426    
427            protected MBThreadFlag toUnwrappedModel(MBThreadFlag mbThreadFlag) {
428                    if (mbThreadFlag instanceof MBThreadFlagImpl) {
429                            return mbThreadFlag;
430                    }
431    
432                    MBThreadFlagImpl mbThreadFlagImpl = new MBThreadFlagImpl();
433    
434                    mbThreadFlagImpl.setNew(mbThreadFlag.isNew());
435                    mbThreadFlagImpl.setPrimaryKey(mbThreadFlag.getPrimaryKey());
436    
437                    mbThreadFlagImpl.setThreadFlagId(mbThreadFlag.getThreadFlagId());
438                    mbThreadFlagImpl.setUserId(mbThreadFlag.getUserId());
439                    mbThreadFlagImpl.setModifiedDate(mbThreadFlag.getModifiedDate());
440                    mbThreadFlagImpl.setThreadId(mbThreadFlag.getThreadId());
441    
442                    return mbThreadFlagImpl;
443            }
444    
445            /**
446             * Returns the message boards thread flag with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
447             *
448             * @param primaryKey the primary key of the message boards thread flag
449             * @return the message boards thread flag
450             * @throws com.liferay.portal.NoSuchModelException if a message boards thread flag with the primary key could not be found
451             * @throws SystemException if a system exception occurred
452             */
453            @Override
454            public MBThreadFlag findByPrimaryKey(Serializable primaryKey)
455                    throws NoSuchModelException, SystemException {
456                    return findByPrimaryKey(((Long)primaryKey).longValue());
457            }
458    
459            /**
460             * Returns the message boards thread flag with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadFlagException} if it could not be found.
461             *
462             * @param threadFlagId the primary key of the message boards thread flag
463             * @return the message boards thread flag
464             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
465             * @throws SystemException if a system exception occurred
466             */
467            public MBThreadFlag findByPrimaryKey(long threadFlagId)
468                    throws NoSuchThreadFlagException, SystemException {
469                    MBThreadFlag mbThreadFlag = fetchByPrimaryKey(threadFlagId);
470    
471                    if (mbThreadFlag == null) {
472                            if (_log.isWarnEnabled()) {
473                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + threadFlagId);
474                            }
475    
476                            throw new NoSuchThreadFlagException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
477                                    threadFlagId);
478                    }
479    
480                    return mbThreadFlag;
481            }
482    
483            /**
484             * Returns the message boards thread flag with the primary key or returns <code>null</code> if it could not be found.
485             *
486             * @param primaryKey the primary key of the message boards thread flag
487             * @return the message boards thread flag, or <code>null</code> if a message boards thread flag with the primary key could not be found
488             * @throws SystemException if a system exception occurred
489             */
490            @Override
491            public MBThreadFlag fetchByPrimaryKey(Serializable primaryKey)
492                    throws SystemException {
493                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
494            }
495    
496            /**
497             * Returns the message boards thread flag with the primary key or returns <code>null</code> if it could not be found.
498             *
499             * @param threadFlagId the primary key of the message boards thread flag
500             * @return the message boards thread flag, or <code>null</code> if a message boards thread flag with the primary key could not be found
501             * @throws SystemException if a system exception occurred
502             */
503            public MBThreadFlag fetchByPrimaryKey(long threadFlagId)
504                    throws SystemException {
505                    MBThreadFlag mbThreadFlag = (MBThreadFlag)EntityCacheUtil.getResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
506                                    MBThreadFlagImpl.class, threadFlagId);
507    
508                    if (mbThreadFlag == _nullMBThreadFlag) {
509                            return null;
510                    }
511    
512                    if (mbThreadFlag == null) {
513                            Session session = null;
514    
515                            boolean hasException = false;
516    
517                            try {
518                                    session = openSession();
519    
520                                    mbThreadFlag = (MBThreadFlag)session.get(MBThreadFlagImpl.class,
521                                                    Long.valueOf(threadFlagId));
522                            }
523                            catch (Exception e) {
524                                    hasException = true;
525    
526                                    throw processException(e);
527                            }
528                            finally {
529                                    if (mbThreadFlag != null) {
530                                            cacheResult(mbThreadFlag);
531                                    }
532                                    else if (!hasException) {
533                                            EntityCacheUtil.putResult(MBThreadFlagModelImpl.ENTITY_CACHE_ENABLED,
534                                                    MBThreadFlagImpl.class, threadFlagId, _nullMBThreadFlag);
535                                    }
536    
537                                    closeSession(session);
538                            }
539                    }
540    
541                    return mbThreadFlag;
542            }
543    
544            /**
545             * Returns all the message boards thread flags where userId = &#63;.
546             *
547             * @param userId the user ID
548             * @return the matching message boards thread flags
549             * @throws SystemException if a system exception occurred
550             */
551            public List<MBThreadFlag> findByUserId(long userId)
552                    throws SystemException {
553                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
554            }
555    
556            /**
557             * Returns a range of all the message boards thread flags where userId = &#63;.
558             *
559             * <p>
560             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
561             * </p>
562             *
563             * @param userId the user ID
564             * @param start the lower bound of the range of message boards thread flags
565             * @param end the upper bound of the range of message boards thread flags (not inclusive)
566             * @return the range of matching message boards thread flags
567             * @throws SystemException if a system exception occurred
568             */
569            public List<MBThreadFlag> findByUserId(long userId, int start, int end)
570                    throws SystemException {
571                    return findByUserId(userId, start, end, null);
572            }
573    
574            /**
575             * Returns an ordered range of all the message boards thread flags where userId = &#63;.
576             *
577             * <p>
578             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
579             * </p>
580             *
581             * @param userId the user ID
582             * @param start the lower bound of the range of message boards thread flags
583             * @param end the upper bound of the range of message boards thread flags (not inclusive)
584             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
585             * @return the ordered range of matching message boards thread flags
586             * @throws SystemException if a system exception occurred
587             */
588            public List<MBThreadFlag> findByUserId(long userId, int start, int end,
589                    OrderByComparator orderByComparator) throws SystemException {
590                    FinderPath finderPath = null;
591                    Object[] finderArgs = null;
592    
593                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
594                                    (orderByComparator == null)) {
595                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
596                            finderArgs = new Object[] { userId };
597                    }
598                    else {
599                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
600                            finderArgs = new Object[] { userId, start, end, orderByComparator };
601                    }
602    
603                    List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
604                                    finderArgs, this);
605    
606                    if ((list != null) && !list.isEmpty()) {
607                            for (MBThreadFlag mbThreadFlag : list) {
608                                    if ((userId != mbThreadFlag.getUserId())) {
609                                            list = null;
610    
611                                            break;
612                                    }
613                            }
614                    }
615    
616                    if (list == null) {
617                            StringBundler query = null;
618    
619                            if (orderByComparator != null) {
620                                    query = new StringBundler(3 +
621                                                    (orderByComparator.getOrderByFields().length * 3));
622                            }
623                            else {
624                                    query = new StringBundler(2);
625                            }
626    
627                            query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
628    
629                            query.append(_FINDER_COLUMN_USERID_USERID_2);
630    
631                            if (orderByComparator != null) {
632                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
633                                            orderByComparator);
634                            }
635    
636                            String sql = query.toString();
637    
638                            Session session = null;
639    
640                            try {
641                                    session = openSession();
642    
643                                    Query q = session.createQuery(sql);
644    
645                                    QueryPos qPos = QueryPos.getInstance(q);
646    
647                                    qPos.add(userId);
648    
649                                    list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
650                                                    start, end);
651                            }
652                            catch (Exception e) {
653                                    throw processException(e);
654                            }
655                            finally {
656                                    if (list == null) {
657                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
658                                    }
659                                    else {
660                                            cacheResult(list);
661    
662                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
663                                    }
664    
665                                    closeSession(session);
666                            }
667                    }
668    
669                    return list;
670            }
671    
672            /**
673             * Returns the first message boards thread flag in the ordered set where userId = &#63;.
674             *
675             * <p>
676             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
677             * </p>
678             *
679             * @param userId the user ID
680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
681             * @return the first matching message boards thread flag
682             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
683             * @throws SystemException if a system exception occurred
684             */
685            public MBThreadFlag findByUserId_First(long userId,
686                    OrderByComparator orderByComparator)
687                    throws NoSuchThreadFlagException, SystemException {
688                    List<MBThreadFlag> list = findByUserId(userId, 0, 1, orderByComparator);
689    
690                    if (list.isEmpty()) {
691                            StringBundler msg = new StringBundler(4);
692    
693                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
694    
695                            msg.append("userId=");
696                            msg.append(userId);
697    
698                            msg.append(StringPool.CLOSE_CURLY_BRACE);
699    
700                            throw new NoSuchThreadFlagException(msg.toString());
701                    }
702                    else {
703                            return list.get(0);
704                    }
705            }
706    
707            /**
708             * Returns the last message boards thread flag in the ordered set where userId = &#63;.
709             *
710             * <p>
711             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
712             * </p>
713             *
714             * @param userId the user ID
715             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
716             * @return the last matching message boards thread flag
717             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
718             * @throws SystemException if a system exception occurred
719             */
720            public MBThreadFlag findByUserId_Last(long userId,
721                    OrderByComparator orderByComparator)
722                    throws NoSuchThreadFlagException, SystemException {
723                    int count = countByUserId(userId);
724    
725                    List<MBThreadFlag> list = findByUserId(userId, count - 1, count,
726                                    orderByComparator);
727    
728                    if (list.isEmpty()) {
729                            StringBundler msg = new StringBundler(4);
730    
731                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
732    
733                            msg.append("userId=");
734                            msg.append(userId);
735    
736                            msg.append(StringPool.CLOSE_CURLY_BRACE);
737    
738                            throw new NoSuchThreadFlagException(msg.toString());
739                    }
740                    else {
741                            return list.get(0);
742                    }
743            }
744    
745            /**
746             * Returns the message boards thread flags before and after the current message boards thread flag in the ordered set where userId = &#63;.
747             *
748             * <p>
749             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
750             * </p>
751             *
752             * @param threadFlagId the primary key of the current message boards thread flag
753             * @param userId the user ID
754             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
755             * @return the previous, current, and next message boards thread flag
756             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
757             * @throws SystemException if a system exception occurred
758             */
759            public MBThreadFlag[] findByUserId_PrevAndNext(long threadFlagId,
760                    long userId, OrderByComparator orderByComparator)
761                    throws NoSuchThreadFlagException, SystemException {
762                    MBThreadFlag mbThreadFlag = findByPrimaryKey(threadFlagId);
763    
764                    Session session = null;
765    
766                    try {
767                            session = openSession();
768    
769                            MBThreadFlag[] array = new MBThreadFlagImpl[3];
770    
771                            array[0] = getByUserId_PrevAndNext(session, mbThreadFlag, userId,
772                                            orderByComparator, true);
773    
774                            array[1] = mbThreadFlag;
775    
776                            array[2] = getByUserId_PrevAndNext(session, mbThreadFlag, userId,
777                                            orderByComparator, false);
778    
779                            return array;
780                    }
781                    catch (Exception e) {
782                            throw processException(e);
783                    }
784                    finally {
785                            closeSession(session);
786                    }
787            }
788    
789            protected MBThreadFlag getByUserId_PrevAndNext(Session session,
790                    MBThreadFlag mbThreadFlag, long userId,
791                    OrderByComparator orderByComparator, boolean previous) {
792                    StringBundler query = null;
793    
794                    if (orderByComparator != null) {
795                            query = new StringBundler(6 +
796                                            (orderByComparator.getOrderByFields().length * 6));
797                    }
798                    else {
799                            query = new StringBundler(3);
800                    }
801    
802                    query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
803    
804                    query.append(_FINDER_COLUMN_USERID_USERID_2);
805    
806                    if (orderByComparator != null) {
807                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
808    
809                            if (orderByConditionFields.length > 0) {
810                                    query.append(WHERE_AND);
811                            }
812    
813                            for (int i = 0; i < orderByConditionFields.length; i++) {
814                                    query.append(_ORDER_BY_ENTITY_ALIAS);
815                                    query.append(orderByConditionFields[i]);
816    
817                                    if ((i + 1) < orderByConditionFields.length) {
818                                            if (orderByComparator.isAscending() ^ previous) {
819                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
820                                            }
821                                            else {
822                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
823                                            }
824                                    }
825                                    else {
826                                            if (orderByComparator.isAscending() ^ previous) {
827                                                    query.append(WHERE_GREATER_THAN);
828                                            }
829                                            else {
830                                                    query.append(WHERE_LESSER_THAN);
831                                            }
832                                    }
833                            }
834    
835                            query.append(ORDER_BY_CLAUSE);
836    
837                            String[] orderByFields = orderByComparator.getOrderByFields();
838    
839                            for (int i = 0; i < orderByFields.length; i++) {
840                                    query.append(_ORDER_BY_ENTITY_ALIAS);
841                                    query.append(orderByFields[i]);
842    
843                                    if ((i + 1) < orderByFields.length) {
844                                            if (orderByComparator.isAscending() ^ previous) {
845                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
846                                            }
847                                            else {
848                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
849                                            }
850                                    }
851                                    else {
852                                            if (orderByComparator.isAscending() ^ previous) {
853                                                    query.append(ORDER_BY_ASC);
854                                            }
855                                            else {
856                                                    query.append(ORDER_BY_DESC);
857                                            }
858                                    }
859                            }
860                    }
861    
862                    String sql = query.toString();
863    
864                    Query q = session.createQuery(sql);
865    
866                    q.setFirstResult(0);
867                    q.setMaxResults(2);
868    
869                    QueryPos qPos = QueryPos.getInstance(q);
870    
871                    qPos.add(userId);
872    
873                    if (orderByComparator != null) {
874                            Object[] values = orderByComparator.getOrderByConditionValues(mbThreadFlag);
875    
876                            for (Object value : values) {
877                                    qPos.add(value);
878                            }
879                    }
880    
881                    List<MBThreadFlag> list = q.list();
882    
883                    if (list.size() == 2) {
884                            return list.get(1);
885                    }
886                    else {
887                            return null;
888                    }
889            }
890    
891            /**
892             * Returns all the message boards thread flags where threadId = &#63;.
893             *
894             * @param threadId the thread ID
895             * @return the matching message boards thread flags
896             * @throws SystemException if a system exception occurred
897             */
898            public List<MBThreadFlag> findByThreadId(long threadId)
899                    throws SystemException {
900                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
901                            null);
902            }
903    
904            /**
905             * Returns a range of all the message boards thread flags where threadId = &#63;.
906             *
907             * <p>
908             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
909             * </p>
910             *
911             * @param threadId the thread ID
912             * @param start the lower bound of the range of message boards thread flags
913             * @param end the upper bound of the range of message boards thread flags (not inclusive)
914             * @return the range of matching message boards thread flags
915             * @throws SystemException if a system exception occurred
916             */
917            public List<MBThreadFlag> findByThreadId(long threadId, int start, int end)
918                    throws SystemException {
919                    return findByThreadId(threadId, start, end, null);
920            }
921    
922            /**
923             * Returns an ordered range of all the message boards thread flags where threadId = &#63;.
924             *
925             * <p>
926             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
927             * </p>
928             *
929             * @param threadId the thread ID
930             * @param start the lower bound of the range of message boards thread flags
931             * @param end the upper bound of the range of message boards thread flags (not inclusive)
932             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
933             * @return the ordered range of matching message boards thread flags
934             * @throws SystemException if a system exception occurred
935             */
936            public List<MBThreadFlag> findByThreadId(long threadId, int start, int end,
937                    OrderByComparator orderByComparator) throws SystemException {
938                    FinderPath finderPath = null;
939                    Object[] finderArgs = null;
940    
941                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
942                                    (orderByComparator == null)) {
943                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
944                            finderArgs = new Object[] { threadId };
945                    }
946                    else {
947                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
948                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
949                    }
950    
951                    List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
952                                    finderArgs, this);
953    
954                    if ((list != null) && !list.isEmpty()) {
955                            for (MBThreadFlag mbThreadFlag : list) {
956                                    if ((threadId != mbThreadFlag.getThreadId())) {
957                                            list = null;
958    
959                                            break;
960                                    }
961                            }
962                    }
963    
964                    if (list == null) {
965                            StringBundler query = null;
966    
967                            if (orderByComparator != null) {
968                                    query = new StringBundler(3 +
969                                                    (orderByComparator.getOrderByFields().length * 3));
970                            }
971                            else {
972                                    query = new StringBundler(2);
973                            }
974    
975                            query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
976    
977                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
978    
979                            if (orderByComparator != null) {
980                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
981                                            orderByComparator);
982                            }
983    
984                            String sql = query.toString();
985    
986                            Session session = null;
987    
988                            try {
989                                    session = openSession();
990    
991                                    Query q = session.createQuery(sql);
992    
993                                    QueryPos qPos = QueryPos.getInstance(q);
994    
995                                    qPos.add(threadId);
996    
997                                    list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
998                                                    start, end);
999                            }
1000                            catch (Exception e) {
1001                                    throw processException(e);
1002                            }
1003                            finally {
1004                                    if (list == null) {
1005                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1006                                    }
1007                                    else {
1008                                            cacheResult(list);
1009    
1010                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1011                                    }
1012    
1013                                    closeSession(session);
1014                            }
1015                    }
1016    
1017                    return list;
1018            }
1019    
1020            /**
1021             * Returns the first message boards thread flag in the ordered set where threadId = &#63;.
1022             *
1023             * <p>
1024             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1025             * </p>
1026             *
1027             * @param threadId the thread ID
1028             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1029             * @return the first matching message boards thread flag
1030             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
1031             * @throws SystemException if a system exception occurred
1032             */
1033            public MBThreadFlag findByThreadId_First(long threadId,
1034                    OrderByComparator orderByComparator)
1035                    throws NoSuchThreadFlagException, SystemException {
1036                    List<MBThreadFlag> list = findByThreadId(threadId, 0, 1,
1037                                    orderByComparator);
1038    
1039                    if (list.isEmpty()) {
1040                            StringBundler msg = new StringBundler(4);
1041    
1042                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1043    
1044                            msg.append("threadId=");
1045                            msg.append(threadId);
1046    
1047                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1048    
1049                            throw new NoSuchThreadFlagException(msg.toString());
1050                    }
1051                    else {
1052                            return list.get(0);
1053                    }
1054            }
1055    
1056            /**
1057             * Returns the last message boards thread flag in the ordered set where threadId = &#63;.
1058             *
1059             * <p>
1060             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1061             * </p>
1062             *
1063             * @param threadId the thread ID
1064             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1065             * @return the last matching message boards thread flag
1066             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
1067             * @throws SystemException if a system exception occurred
1068             */
1069            public MBThreadFlag findByThreadId_Last(long threadId,
1070                    OrderByComparator orderByComparator)
1071                    throws NoSuchThreadFlagException, SystemException {
1072                    int count = countByThreadId(threadId);
1073    
1074                    List<MBThreadFlag> list = findByThreadId(threadId, count - 1, count,
1075                                    orderByComparator);
1076    
1077                    if (list.isEmpty()) {
1078                            StringBundler msg = new StringBundler(4);
1079    
1080                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1081    
1082                            msg.append("threadId=");
1083                            msg.append(threadId);
1084    
1085                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1086    
1087                            throw new NoSuchThreadFlagException(msg.toString());
1088                    }
1089                    else {
1090                            return list.get(0);
1091                    }
1092            }
1093    
1094            /**
1095             * Returns the message boards thread flags before and after the current message boards thread flag in the ordered set where threadId = &#63;.
1096             *
1097             * <p>
1098             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1099             * </p>
1100             *
1101             * @param threadFlagId the primary key of the current message boards thread flag
1102             * @param threadId the thread ID
1103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1104             * @return the previous, current, and next message boards thread flag
1105             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a message boards thread flag with the primary key could not be found
1106             * @throws SystemException if a system exception occurred
1107             */
1108            public MBThreadFlag[] findByThreadId_PrevAndNext(long threadFlagId,
1109                    long threadId, OrderByComparator orderByComparator)
1110                    throws NoSuchThreadFlagException, SystemException {
1111                    MBThreadFlag mbThreadFlag = findByPrimaryKey(threadFlagId);
1112    
1113                    Session session = null;
1114    
1115                    try {
1116                            session = openSession();
1117    
1118                            MBThreadFlag[] array = new MBThreadFlagImpl[3];
1119    
1120                            array[0] = getByThreadId_PrevAndNext(session, mbThreadFlag,
1121                                            threadId, orderByComparator, true);
1122    
1123                            array[1] = mbThreadFlag;
1124    
1125                            array[2] = getByThreadId_PrevAndNext(session, mbThreadFlag,
1126                                            threadId, orderByComparator, false);
1127    
1128                            return array;
1129                    }
1130                    catch (Exception e) {
1131                            throw processException(e);
1132                    }
1133                    finally {
1134                            closeSession(session);
1135                    }
1136            }
1137    
1138            protected MBThreadFlag getByThreadId_PrevAndNext(Session session,
1139                    MBThreadFlag mbThreadFlag, long threadId,
1140                    OrderByComparator orderByComparator, boolean previous) {
1141                    StringBundler query = null;
1142    
1143                    if (orderByComparator != null) {
1144                            query = new StringBundler(6 +
1145                                            (orderByComparator.getOrderByFields().length * 6));
1146                    }
1147                    else {
1148                            query = new StringBundler(3);
1149                    }
1150    
1151                    query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
1152    
1153                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1154    
1155                    if (orderByComparator != null) {
1156                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1157    
1158                            if (orderByConditionFields.length > 0) {
1159                                    query.append(WHERE_AND);
1160                            }
1161    
1162                            for (int i = 0; i < orderByConditionFields.length; i++) {
1163                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1164                                    query.append(orderByConditionFields[i]);
1165    
1166                                    if ((i + 1) < orderByConditionFields.length) {
1167                                            if (orderByComparator.isAscending() ^ previous) {
1168                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1169                                            }
1170                                            else {
1171                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1172                                            }
1173                                    }
1174                                    else {
1175                                            if (orderByComparator.isAscending() ^ previous) {
1176                                                    query.append(WHERE_GREATER_THAN);
1177                                            }
1178                                            else {
1179                                                    query.append(WHERE_LESSER_THAN);
1180                                            }
1181                                    }
1182                            }
1183    
1184                            query.append(ORDER_BY_CLAUSE);
1185    
1186                            String[] orderByFields = orderByComparator.getOrderByFields();
1187    
1188                            for (int i = 0; i < orderByFields.length; i++) {
1189                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1190                                    query.append(orderByFields[i]);
1191    
1192                                    if ((i + 1) < orderByFields.length) {
1193                                            if (orderByComparator.isAscending() ^ previous) {
1194                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1195                                            }
1196                                            else {
1197                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1198                                            }
1199                                    }
1200                                    else {
1201                                            if (orderByComparator.isAscending() ^ previous) {
1202                                                    query.append(ORDER_BY_ASC);
1203                                            }
1204                                            else {
1205                                                    query.append(ORDER_BY_DESC);
1206                                            }
1207                                    }
1208                            }
1209                    }
1210    
1211                    String sql = query.toString();
1212    
1213                    Query q = session.createQuery(sql);
1214    
1215                    q.setFirstResult(0);
1216                    q.setMaxResults(2);
1217    
1218                    QueryPos qPos = QueryPos.getInstance(q);
1219    
1220                    qPos.add(threadId);
1221    
1222                    if (orderByComparator != null) {
1223                            Object[] values = orderByComparator.getOrderByConditionValues(mbThreadFlag);
1224    
1225                            for (Object value : values) {
1226                                    qPos.add(value);
1227                            }
1228                    }
1229    
1230                    List<MBThreadFlag> list = q.list();
1231    
1232                    if (list.size() == 2) {
1233                            return list.get(1);
1234                    }
1235                    else {
1236                            return null;
1237                    }
1238            }
1239    
1240            /**
1241             * Returns the message boards thread flag where userId = &#63; and threadId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchThreadFlagException} if it could not be found.
1242             *
1243             * @param userId the user ID
1244             * @param threadId the thread ID
1245             * @return the matching message boards thread flag
1246             * @throws com.liferay.portlet.messageboards.NoSuchThreadFlagException if a matching message boards thread flag could not be found
1247             * @throws SystemException if a system exception occurred
1248             */
1249            public MBThreadFlag findByU_T(long userId, long threadId)
1250                    throws NoSuchThreadFlagException, SystemException {
1251                    MBThreadFlag mbThreadFlag = fetchByU_T(userId, threadId);
1252    
1253                    if (mbThreadFlag == null) {
1254                            StringBundler msg = new StringBundler(6);
1255    
1256                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1257    
1258                            msg.append("userId=");
1259                            msg.append(userId);
1260    
1261                            msg.append(", threadId=");
1262                            msg.append(threadId);
1263    
1264                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1265    
1266                            if (_log.isWarnEnabled()) {
1267                                    _log.warn(msg.toString());
1268                            }
1269    
1270                            throw new NoSuchThreadFlagException(msg.toString());
1271                    }
1272    
1273                    return mbThreadFlag;
1274            }
1275    
1276            /**
1277             * 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.
1278             *
1279             * @param userId the user ID
1280             * @param threadId the thread ID
1281             * @return the matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
1282             * @throws SystemException if a system exception occurred
1283             */
1284            public MBThreadFlag fetchByU_T(long userId, long threadId)
1285                    throws SystemException {
1286                    return fetchByU_T(userId, threadId, true);
1287            }
1288    
1289            /**
1290             * 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.
1291             *
1292             * @param userId the user ID
1293             * @param threadId the thread ID
1294             * @param retrieveFromCache whether to use the finder cache
1295             * @return the matching message boards thread flag, or <code>null</code> if a matching message boards thread flag could not be found
1296             * @throws SystemException if a system exception occurred
1297             */
1298            public MBThreadFlag fetchByU_T(long userId, long threadId,
1299                    boolean retrieveFromCache) throws SystemException {
1300                    Object[] finderArgs = new Object[] { userId, threadId };
1301    
1302                    Object result = null;
1303    
1304                    if (retrieveFromCache) {
1305                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
1306                                            finderArgs, this);
1307                    }
1308    
1309                    if (result instanceof MBThreadFlag) {
1310                            MBThreadFlag mbThreadFlag = (MBThreadFlag)result;
1311    
1312                            if ((userId != mbThreadFlag.getUserId()) ||
1313                                            (threadId != mbThreadFlag.getThreadId())) {
1314                                    result = null;
1315                            }
1316                    }
1317    
1318                    if (result == null) {
1319                            StringBundler query = new StringBundler(3);
1320    
1321                            query.append(_SQL_SELECT_MBTHREADFLAG_WHERE);
1322    
1323                            query.append(_FINDER_COLUMN_U_T_USERID_2);
1324    
1325                            query.append(_FINDER_COLUMN_U_T_THREADID_2);
1326    
1327                            String sql = query.toString();
1328    
1329                            Session session = null;
1330    
1331                            try {
1332                                    session = openSession();
1333    
1334                                    Query q = session.createQuery(sql);
1335    
1336                                    QueryPos qPos = QueryPos.getInstance(q);
1337    
1338                                    qPos.add(userId);
1339    
1340                                    qPos.add(threadId);
1341    
1342                                    List<MBThreadFlag> list = q.list();
1343    
1344                                    result = list;
1345    
1346                                    MBThreadFlag mbThreadFlag = null;
1347    
1348                                    if (list.isEmpty()) {
1349                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1350                                                    finderArgs, list);
1351                                    }
1352                                    else {
1353                                            mbThreadFlag = list.get(0);
1354    
1355                                            cacheResult(mbThreadFlag);
1356    
1357                                            if ((mbThreadFlag.getUserId() != userId) ||
1358                                                            (mbThreadFlag.getThreadId() != threadId)) {
1359                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1360                                                            finderArgs, mbThreadFlag);
1361                                            }
1362                                    }
1363    
1364                                    return mbThreadFlag;
1365                            }
1366                            catch (Exception e) {
1367                                    throw processException(e);
1368                            }
1369                            finally {
1370                                    if (result == null) {
1371                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1372                                                    finderArgs);
1373                                    }
1374    
1375                                    closeSession(session);
1376                            }
1377                    }
1378                    else {
1379                            if (result instanceof List<?>) {
1380                                    return null;
1381                            }
1382                            else {
1383                                    return (MBThreadFlag)result;
1384                            }
1385                    }
1386            }
1387    
1388            /**
1389             * Returns all the message boards thread flags.
1390             *
1391             * @return the message boards thread flags
1392             * @throws SystemException if a system exception occurred
1393             */
1394            public List<MBThreadFlag> findAll() throws SystemException {
1395                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1396            }
1397    
1398            /**
1399             * Returns a range of all the message boards thread flags.
1400             *
1401             * <p>
1402             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1403             * </p>
1404             *
1405             * @param start the lower bound of the range of message boards thread flags
1406             * @param end the upper bound of the range of message boards thread flags (not inclusive)
1407             * @return the range of message boards thread flags
1408             * @throws SystemException if a system exception occurred
1409             */
1410            public List<MBThreadFlag> findAll(int start, int end)
1411                    throws SystemException {
1412                    return findAll(start, end, null);
1413            }
1414    
1415            /**
1416             * Returns an ordered range of all the message boards thread flags.
1417             *
1418             * <p>
1419             * 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 com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1420             * </p>
1421             *
1422             * @param start the lower bound of the range of message boards thread flags
1423             * @param end the upper bound of the range of message boards thread flags (not inclusive)
1424             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1425             * @return the ordered range of message boards thread flags
1426             * @throws SystemException if a system exception occurred
1427             */
1428            public List<MBThreadFlag> findAll(int start, int end,
1429                    OrderByComparator orderByComparator) throws SystemException {
1430                    FinderPath finderPath = null;
1431                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1432    
1433                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1434                                    (orderByComparator == null)) {
1435                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1436                            finderArgs = FINDER_ARGS_EMPTY;
1437                    }
1438                    else {
1439                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1440                            finderArgs = new Object[] { start, end, orderByComparator };
1441                    }
1442    
1443                    List<MBThreadFlag> list = (List<MBThreadFlag>)FinderCacheUtil.getResult(finderPath,
1444                                    finderArgs, this);
1445    
1446                    if (list == null) {
1447                            StringBundler query = null;
1448                            String sql = null;
1449    
1450                            if (orderByComparator != null) {
1451                                    query = new StringBundler(2 +
1452                                                    (orderByComparator.getOrderByFields().length * 3));
1453    
1454                                    query.append(_SQL_SELECT_MBTHREADFLAG);
1455    
1456                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1457                                            orderByComparator);
1458    
1459                                    sql = query.toString();
1460                            }
1461                            else {
1462                                    sql = _SQL_SELECT_MBTHREADFLAG;
1463                            }
1464    
1465                            Session session = null;
1466    
1467                            try {
1468                                    session = openSession();
1469    
1470                                    Query q = session.createQuery(sql);
1471    
1472                                    if (orderByComparator == null) {
1473                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1474                                                            start, end, false);
1475    
1476                                            Collections.sort(list);
1477                                    }
1478                                    else {
1479                                            list = (List<MBThreadFlag>)QueryUtil.list(q, getDialect(),
1480                                                            start, end);
1481                                    }
1482                            }
1483                            catch (Exception e) {
1484                                    throw processException(e);
1485                            }
1486                            finally {
1487                                    if (list == null) {
1488                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1489                                    }
1490                                    else {
1491                                            cacheResult(list);
1492    
1493                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1494                                    }
1495    
1496                                    closeSession(session);
1497                            }
1498                    }
1499    
1500                    return list;
1501            }
1502    
1503            /**
1504             * Removes all the message boards thread flags where userId = &#63; from the database.
1505             *
1506             * @param userId the user ID
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public void removeByUserId(long userId) throws SystemException {
1510                    for (MBThreadFlag mbThreadFlag : findByUserId(userId)) {
1511                            remove(mbThreadFlag);
1512                    }
1513            }
1514    
1515            /**
1516             * Removes all the message boards thread flags where threadId = &#63; from the database.
1517             *
1518             * @param threadId the thread ID
1519             * @throws SystemException if a system exception occurred
1520             */
1521            public void removeByThreadId(long threadId) throws SystemException {
1522                    for (MBThreadFlag mbThreadFlag : findByThreadId(threadId)) {
1523                            remove(mbThreadFlag);
1524                    }
1525            }
1526    
1527            /**
1528             * Removes the message boards thread flag where userId = &#63; and threadId = &#63; from the database.
1529             *
1530             * @param userId the user ID
1531             * @param threadId the thread ID
1532             * @throws SystemException if a system exception occurred
1533             */
1534            public void removeByU_T(long userId, long threadId)
1535                    throws NoSuchThreadFlagException, SystemException {
1536                    MBThreadFlag mbThreadFlag = findByU_T(userId, threadId);
1537    
1538                    remove(mbThreadFlag);
1539            }
1540    
1541            /**
1542             * Removes all the message boards thread flags from the database.
1543             *
1544             * @throws SystemException if a system exception occurred
1545             */
1546            public void removeAll() throws SystemException {
1547                    for (MBThreadFlag mbThreadFlag : findAll()) {
1548                            remove(mbThreadFlag);
1549                    }
1550            }
1551    
1552            /**
1553             * Returns the number of message boards thread flags where userId = &#63;.
1554             *
1555             * @param userId the user ID
1556             * @return the number of matching message boards thread flags
1557             * @throws SystemException if a system exception occurred
1558             */
1559            public int countByUserId(long userId) throws SystemException {
1560                    Object[] finderArgs = new Object[] { userId };
1561    
1562                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1563                                    finderArgs, this);
1564    
1565                    if (count == null) {
1566                            StringBundler query = new StringBundler(2);
1567    
1568                            query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1569    
1570                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1571    
1572                            String sql = query.toString();
1573    
1574                            Session session = null;
1575    
1576                            try {
1577                                    session = openSession();
1578    
1579                                    Query q = session.createQuery(sql);
1580    
1581                                    QueryPos qPos = QueryPos.getInstance(q);
1582    
1583                                    qPos.add(userId);
1584    
1585                                    count = (Long)q.uniqueResult();
1586                            }
1587                            catch (Exception e) {
1588                                    throw processException(e);
1589                            }
1590                            finally {
1591                                    if (count == null) {
1592                                            count = Long.valueOf(0);
1593                                    }
1594    
1595                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1596                                            finderArgs, count);
1597    
1598                                    closeSession(session);
1599                            }
1600                    }
1601    
1602                    return count.intValue();
1603            }
1604    
1605            /**
1606             * Returns the number of message boards thread flags where threadId = &#63;.
1607             *
1608             * @param threadId the thread ID
1609             * @return the number of matching message boards thread flags
1610             * @throws SystemException if a system exception occurred
1611             */
1612            public int countByThreadId(long threadId) throws SystemException {
1613                    Object[] finderArgs = new Object[] { threadId };
1614    
1615                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_THREADID,
1616                                    finderArgs, this);
1617    
1618                    if (count == null) {
1619                            StringBundler query = new StringBundler(2);
1620    
1621                            query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1622    
1623                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
1624    
1625                            String sql = query.toString();
1626    
1627                            Session session = null;
1628    
1629                            try {
1630                                    session = openSession();
1631    
1632                                    Query q = session.createQuery(sql);
1633    
1634                                    QueryPos qPos = QueryPos.getInstance(q);
1635    
1636                                    qPos.add(threadId);
1637    
1638                                    count = (Long)q.uniqueResult();
1639                            }
1640                            catch (Exception e) {
1641                                    throw processException(e);
1642                            }
1643                            finally {
1644                                    if (count == null) {
1645                                            count = Long.valueOf(0);
1646                                    }
1647    
1648                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_THREADID,
1649                                            finderArgs, count);
1650    
1651                                    closeSession(session);
1652                            }
1653                    }
1654    
1655                    return count.intValue();
1656            }
1657    
1658            /**
1659             * Returns the number of message boards thread flags where userId = &#63; and threadId = &#63;.
1660             *
1661             * @param userId the user ID
1662             * @param threadId the thread ID
1663             * @return the number of matching message boards thread flags
1664             * @throws SystemException if a system exception occurred
1665             */
1666            public int countByU_T(long userId, long threadId) throws SystemException {
1667                    Object[] finderArgs = new Object[] { userId, threadId };
1668    
1669                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1670                                    finderArgs, this);
1671    
1672                    if (count == null) {
1673                            StringBundler query = new StringBundler(3);
1674    
1675                            query.append(_SQL_COUNT_MBTHREADFLAG_WHERE);
1676    
1677                            query.append(_FINDER_COLUMN_U_T_USERID_2);
1678    
1679                            query.append(_FINDER_COLUMN_U_T_THREADID_2);
1680    
1681                            String sql = query.toString();
1682    
1683                            Session session = null;
1684    
1685                            try {
1686                                    session = openSession();
1687    
1688                                    Query q = session.createQuery(sql);
1689    
1690                                    QueryPos qPos = QueryPos.getInstance(q);
1691    
1692                                    qPos.add(userId);
1693    
1694                                    qPos.add(threadId);
1695    
1696                                    count = (Long)q.uniqueResult();
1697                            }
1698                            catch (Exception e) {
1699                                    throw processException(e);
1700                            }
1701                            finally {
1702                                    if (count == null) {
1703                                            count = Long.valueOf(0);
1704                                    }
1705    
1706                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1707                                            count);
1708    
1709                                    closeSession(session);
1710                            }
1711                    }
1712    
1713                    return count.intValue();
1714            }
1715    
1716            /**
1717             * Returns the number of message boards thread flags.
1718             *
1719             * @return the number of message boards thread flags
1720             * @throws SystemException if a system exception occurred
1721             */
1722            public int countAll() throws SystemException {
1723                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1724                                    FINDER_ARGS_EMPTY, this);
1725    
1726                    if (count == null) {
1727                            Session session = null;
1728    
1729                            try {
1730                                    session = openSession();
1731    
1732                                    Query q = session.createQuery(_SQL_COUNT_MBTHREADFLAG);
1733    
1734                                    count = (Long)q.uniqueResult();
1735                            }
1736                            catch (Exception e) {
1737                                    throw processException(e);
1738                            }
1739                            finally {
1740                                    if (count == null) {
1741                                            count = Long.valueOf(0);
1742                                    }
1743    
1744                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1745                                            FINDER_ARGS_EMPTY, count);
1746    
1747                                    closeSession(session);
1748                            }
1749                    }
1750    
1751                    return count.intValue();
1752            }
1753    
1754            /**
1755             * Initializes the message boards thread flag persistence.
1756             */
1757            public void afterPropertiesSet() {
1758                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1759                                            com.liferay.portal.util.PropsUtil.get(
1760                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBThreadFlag")));
1761    
1762                    if (listenerClassNames.length > 0) {
1763                            try {
1764                                    List<ModelListener<MBThreadFlag>> listenersList = new ArrayList<ModelListener<MBThreadFlag>>();
1765    
1766                                    for (String listenerClassName : listenerClassNames) {
1767                                            listenersList.add((ModelListener<MBThreadFlag>)InstanceFactory.newInstance(
1768                                                            listenerClassName));
1769                                    }
1770    
1771                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1772                            }
1773                            catch (Exception e) {
1774                                    _log.error(e);
1775                            }
1776                    }
1777            }
1778    
1779            public void destroy() {
1780                    EntityCacheUtil.removeCache(MBThreadFlagImpl.class.getName());
1781                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1782                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1783            }
1784    
1785            @BeanReference(type = MBBanPersistence.class)
1786            protected MBBanPersistence mbBanPersistence;
1787            @BeanReference(type = MBCategoryPersistence.class)
1788            protected MBCategoryPersistence mbCategoryPersistence;
1789            @BeanReference(type = MBDiscussionPersistence.class)
1790            protected MBDiscussionPersistence mbDiscussionPersistence;
1791            @BeanReference(type = MBMailingListPersistence.class)
1792            protected MBMailingListPersistence mbMailingListPersistence;
1793            @BeanReference(type = MBMessagePersistence.class)
1794            protected MBMessagePersistence mbMessagePersistence;
1795            @BeanReference(type = MBStatsUserPersistence.class)
1796            protected MBStatsUserPersistence mbStatsUserPersistence;
1797            @BeanReference(type = MBThreadPersistence.class)
1798            protected MBThreadPersistence mbThreadPersistence;
1799            @BeanReference(type = MBThreadFlagPersistence.class)
1800            protected MBThreadFlagPersistence mbThreadFlagPersistence;
1801            @BeanReference(type = ResourcePersistence.class)
1802            protected ResourcePersistence resourcePersistence;
1803            @BeanReference(type = UserPersistence.class)
1804            protected UserPersistence userPersistence;
1805            private static final String _SQL_SELECT_MBTHREADFLAG = "SELECT mbThreadFlag FROM MBThreadFlag mbThreadFlag";
1806            private static final String _SQL_SELECT_MBTHREADFLAG_WHERE = "SELECT mbThreadFlag FROM MBThreadFlag mbThreadFlag WHERE ";
1807            private static final String _SQL_COUNT_MBTHREADFLAG = "SELECT COUNT(mbThreadFlag) FROM MBThreadFlag mbThreadFlag";
1808            private static final String _SQL_COUNT_MBTHREADFLAG_WHERE = "SELECT COUNT(mbThreadFlag) FROM MBThreadFlag mbThreadFlag WHERE ";
1809            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbThreadFlag.userId = ?";
1810            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbThreadFlag.threadId = ?";
1811            private static final String _FINDER_COLUMN_U_T_USERID_2 = "mbThreadFlag.userId = ? AND ";
1812            private static final String _FINDER_COLUMN_U_T_THREADID_2 = "mbThreadFlag.threadId = ?";
1813            private static final String _ORDER_BY_ENTITY_ALIAS = "mbThreadFlag.";
1814            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBThreadFlag exists with the primary key ";
1815            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBThreadFlag exists with the key {";
1816            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1817            private static Log _log = LogFactoryUtil.getLog(MBThreadFlagPersistenceImpl.class);
1818            private static MBThreadFlag _nullMBThreadFlag = new MBThreadFlagImpl() {
1819                            @Override
1820                            public Object clone() {
1821                                    return this;
1822                            }
1823    
1824                            @Override
1825                            public CacheModel<MBThreadFlag> toCacheModel() {
1826                                    return _nullMBThreadFlagCacheModel;
1827                            }
1828                    };
1829    
1830            private static CacheModel<MBThreadFlag> _nullMBThreadFlagCacheModel = new CacheModel<MBThreadFlag>() {
1831                            public MBThreadFlag toEntityModel() {
1832                                    return _nullMBThreadFlag;
1833                            }
1834                    };
1835    }