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