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