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