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