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