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