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