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