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