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