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.blogs.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCache;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCache;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.OrderByComparator;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.kernel.util.Validator;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
036    
037    import com.liferay.portlet.blogs.NoSuchStatsUserException;
038    import com.liferay.portlet.blogs.model.BlogsStatsUser;
039    import com.liferay.portlet.blogs.model.impl.BlogsStatsUserImpl;
040    import com.liferay.portlet.blogs.model.impl.BlogsStatsUserModelImpl;
041    import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence;
042    
043    import java.io.Serializable;
044    
045    import java.sql.Timestamp;
046    
047    import java.util.Collections;
048    import java.util.Date;
049    import java.util.HashMap;
050    import java.util.HashSet;
051    import java.util.Iterator;
052    import java.util.List;
053    import java.util.Map;
054    import java.util.Set;
055    
056    /**
057     * The persistence implementation for the blogs stats user service.
058     *
059     * <p>
060     * Caching information and settings can be found in <code>portal.properties</code>
061     * </p>
062     *
063     * @author Brian Wing Shun Chan
064     * @see BlogsStatsUserPersistence
065     * @see com.liferay.portlet.blogs.service.persistence.BlogsStatsUserUtil
066     * @generated
067     */
068    @ProviderType
069    public class BlogsStatsUserPersistenceImpl extends BasePersistenceImpl<BlogsStatsUser>
070            implements BlogsStatsUserPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * Never modify or reference this class directly. Always use {@link BlogsStatsUserUtil} to access the blogs stats user persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = BlogsStatsUserImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
082                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
083                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
084                            "findAll", new String[0]);
085            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
086                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
087                            BlogsStatsUserImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
090                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
093                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
094                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
095                            "findByGroupId",
096                            new String[] {
097                                    Long.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
103                    new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
104                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
105                            BlogsStatsUserImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
107                            new String[] { Long.class.getName() },
108                            BlogsStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
109                            BlogsStatsUserModelImpl.ENTRYCOUNT_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
111                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
113                            new String[] { Long.class.getName() });
114    
115            /**
116             * Returns all the blogs stats users where groupId = &#63;.
117             *
118             * @param groupId the group ID
119             * @return the matching blogs stats users
120             */
121            @Override
122            public List<BlogsStatsUser> findByGroupId(long groupId) {
123                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124            }
125    
126            /**
127             * Returns a range of all the blogs stats users where groupId = &#63;.
128             *
129             * <p>
130             * 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 BlogsStatsUserModelImpl}. 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.
131             * </p>
132             *
133             * @param groupId the group ID
134             * @param start the lower bound of the range of blogs stats users
135             * @param end the upper bound of the range of blogs stats users (not inclusive)
136             * @return the range of matching blogs stats users
137             */
138            @Override
139            public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end) {
140                    return findByGroupId(groupId, start, end, null);
141            }
142    
143            /**
144             * Returns an ordered range of all the blogs stats users where groupId = &#63;.
145             *
146             * <p>
147             * 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 BlogsStatsUserModelImpl}. 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.
148             * </p>
149             *
150             * @param groupId the group ID
151             * @param start the lower bound of the range of blogs stats users
152             * @param end the upper bound of the range of blogs stats users (not inclusive)
153             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
154             * @return the ordered range of matching blogs stats users
155             */
156            @Override
157            public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end,
158                    OrderByComparator<BlogsStatsUser> orderByComparator) {
159                    return findByGroupId(groupId, start, end, orderByComparator, true);
160            }
161    
162            /**
163             * Returns an ordered range of all the blogs stats users where groupId = &#63;.
164             *
165             * <p>
166             * 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 BlogsStatsUserModelImpl}. 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.
167             * </p>
168             *
169             * @param groupId the group ID
170             * @param start the lower bound of the range of blogs stats users
171             * @param end the upper bound of the range of blogs stats users (not inclusive)
172             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
173             * @param retrieveFromCache whether to retrieve from the finder cache
174             * @return the ordered range of matching blogs stats users
175             */
176            @Override
177            public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end,
178                    OrderByComparator<BlogsStatsUser> orderByComparator,
179                    boolean retrieveFromCache) {
180                    boolean pagination = true;
181                    FinderPath finderPath = null;
182                    Object[] finderArgs = null;
183    
184                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
185                                    (orderByComparator == null)) {
186                            pagination = false;
187                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
188                            finderArgs = new Object[] { groupId };
189                    }
190                    else {
191                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
192                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
193                    }
194    
195                    List<BlogsStatsUser> list = null;
196    
197                    if (retrieveFromCache) {
198                            list = (List<BlogsStatsUser>)finderCache.getResult(finderPath,
199                                            finderArgs, this);
200    
201                            if ((list != null) && !list.isEmpty()) {
202                                    for (BlogsStatsUser blogsStatsUser : list) {
203                                            if ((groupId != blogsStatsUser.getGroupId())) {
204                                                    list = null;
205    
206                                                    break;
207                                            }
208                                    }
209                            }
210                    }
211    
212                    if (list == null) {
213                            StringBundler query = null;
214    
215                            if (orderByComparator != null) {
216                                    query = new StringBundler(3 +
217                                                    (orderByComparator.getOrderByFields().length * 3));
218                            }
219                            else {
220                                    query = new StringBundler(3);
221                            }
222    
223                            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
224    
225                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
226    
227                            if (orderByComparator != null) {
228                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
229                                            orderByComparator);
230                            }
231                            else
232                             if (pagination) {
233                                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
234                            }
235    
236                            String sql = query.toString();
237    
238                            Session session = null;
239    
240                            try {
241                                    session = openSession();
242    
243                                    Query q = session.createQuery(sql);
244    
245                                    QueryPos qPos = QueryPos.getInstance(q);
246    
247                                    qPos.add(groupId);
248    
249                                    if (!pagination) {
250                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
251                                                            getDialect(), start, end, false);
252    
253                                            Collections.sort(list);
254    
255                                            list = Collections.unmodifiableList(list);
256                                    }
257                                    else {
258                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
259                                                            getDialect(), start, end);
260                                    }
261    
262                                    cacheResult(list);
263    
264                                    finderCache.putResult(finderPath, finderArgs, list);
265                            }
266                            catch (Exception e) {
267                                    finderCache.removeResult(finderPath, finderArgs);
268    
269                                    throw processException(e);
270                            }
271                            finally {
272                                    closeSession(session);
273                            }
274                    }
275    
276                    return list;
277            }
278    
279            /**
280             * Returns the first blogs stats user in the ordered set where groupId = &#63;.
281             *
282             * @param groupId the group ID
283             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
284             * @return the first matching blogs stats user
285             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
286             */
287            @Override
288            public BlogsStatsUser findByGroupId_First(long groupId,
289                    OrderByComparator<BlogsStatsUser> orderByComparator)
290                    throws NoSuchStatsUserException {
291                    BlogsStatsUser blogsStatsUser = fetchByGroupId_First(groupId,
292                                    orderByComparator);
293    
294                    if (blogsStatsUser != null) {
295                            return blogsStatsUser;
296                    }
297    
298                    StringBundler msg = new StringBundler(4);
299    
300                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
301    
302                    msg.append("groupId=");
303                    msg.append(groupId);
304    
305                    msg.append(StringPool.CLOSE_CURLY_BRACE);
306    
307                    throw new NoSuchStatsUserException(msg.toString());
308            }
309    
310            /**
311             * Returns the first blogs stats user in the ordered set where groupId = &#63;.
312             *
313             * @param groupId the group ID
314             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
315             * @return the first matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
316             */
317            @Override
318            public BlogsStatsUser fetchByGroupId_First(long groupId,
319                    OrderByComparator<BlogsStatsUser> orderByComparator) {
320                    List<BlogsStatsUser> list = findByGroupId(groupId, 0, 1,
321                                    orderByComparator);
322    
323                    if (!list.isEmpty()) {
324                            return list.get(0);
325                    }
326    
327                    return null;
328            }
329    
330            /**
331             * Returns the last blogs stats user in the ordered set where groupId = &#63;.
332             *
333             * @param groupId the group ID
334             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
335             * @return the last matching blogs stats user
336             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
337             */
338            @Override
339            public BlogsStatsUser findByGroupId_Last(long groupId,
340                    OrderByComparator<BlogsStatsUser> orderByComparator)
341                    throws NoSuchStatsUserException {
342                    BlogsStatsUser blogsStatsUser = fetchByGroupId_Last(groupId,
343                                    orderByComparator);
344    
345                    if (blogsStatsUser != null) {
346                            return blogsStatsUser;
347                    }
348    
349                    StringBundler msg = new StringBundler(4);
350    
351                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
352    
353                    msg.append("groupId=");
354                    msg.append(groupId);
355    
356                    msg.append(StringPool.CLOSE_CURLY_BRACE);
357    
358                    throw new NoSuchStatsUserException(msg.toString());
359            }
360    
361            /**
362             * Returns the last blogs stats user in the ordered set where groupId = &#63;.
363             *
364             * @param groupId the group ID
365             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
366             * @return the last matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
367             */
368            @Override
369            public BlogsStatsUser fetchByGroupId_Last(long groupId,
370                    OrderByComparator<BlogsStatsUser> orderByComparator) {
371                    int count = countByGroupId(groupId);
372    
373                    if (count == 0) {
374                            return null;
375                    }
376    
377                    List<BlogsStatsUser> list = findByGroupId(groupId, count - 1, count,
378                                    orderByComparator);
379    
380                    if (!list.isEmpty()) {
381                            return list.get(0);
382                    }
383    
384                    return null;
385            }
386    
387            /**
388             * Returns the blogs stats users before and after the current blogs stats user in the ordered set where groupId = &#63;.
389             *
390             * @param statsUserId the primary key of the current blogs stats user
391             * @param groupId the group ID
392             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
393             * @return the previous, current, and next blogs stats user
394             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
395             */
396            @Override
397            public BlogsStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
398                    long groupId, OrderByComparator<BlogsStatsUser> orderByComparator)
399                    throws NoSuchStatsUserException {
400                    BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
401    
402                    Session session = null;
403    
404                    try {
405                            session = openSession();
406    
407                            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
408    
409                            array[0] = getByGroupId_PrevAndNext(session, blogsStatsUser,
410                                            groupId, orderByComparator, true);
411    
412                            array[1] = blogsStatsUser;
413    
414                            array[2] = getByGroupId_PrevAndNext(session, blogsStatsUser,
415                                            groupId, orderByComparator, false);
416    
417                            return array;
418                    }
419                    catch (Exception e) {
420                            throw processException(e);
421                    }
422                    finally {
423                            closeSession(session);
424                    }
425            }
426    
427            protected BlogsStatsUser getByGroupId_PrevAndNext(Session session,
428                    BlogsStatsUser blogsStatsUser, long groupId,
429                    OrderByComparator<BlogsStatsUser> orderByComparator, boolean previous) {
430                    StringBundler query = null;
431    
432                    if (orderByComparator != null) {
433                            query = new StringBundler(6 +
434                                            (orderByComparator.getOrderByFields().length * 6));
435                    }
436                    else {
437                            query = new StringBundler(3);
438                    }
439    
440                    query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
441    
442                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
443    
444                    if (orderByComparator != null) {
445                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446    
447                            if (orderByConditionFields.length > 0) {
448                                    query.append(WHERE_AND);
449                            }
450    
451                            for (int i = 0; i < orderByConditionFields.length; i++) {
452                                    query.append(_ORDER_BY_ENTITY_ALIAS);
453                                    query.append(orderByConditionFields[i]);
454    
455                                    if ((i + 1) < orderByConditionFields.length) {
456                                            if (orderByComparator.isAscending() ^ previous) {
457                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
458                                            }
459                                            else {
460                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
461                                            }
462                                    }
463                                    else {
464                                            if (orderByComparator.isAscending() ^ previous) {
465                                                    query.append(WHERE_GREATER_THAN);
466                                            }
467                                            else {
468                                                    query.append(WHERE_LESSER_THAN);
469                                            }
470                                    }
471                            }
472    
473                            query.append(ORDER_BY_CLAUSE);
474    
475                            String[] orderByFields = orderByComparator.getOrderByFields();
476    
477                            for (int i = 0; i < orderByFields.length; i++) {
478                                    query.append(_ORDER_BY_ENTITY_ALIAS);
479                                    query.append(orderByFields[i]);
480    
481                                    if ((i + 1) < orderByFields.length) {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
484                                            }
485                                            else {
486                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
487                                            }
488                                    }
489                                    else {
490                                            if (orderByComparator.isAscending() ^ previous) {
491                                                    query.append(ORDER_BY_ASC);
492                                            }
493                                            else {
494                                                    query.append(ORDER_BY_DESC);
495                                            }
496                                    }
497                            }
498                    }
499                    else {
500                            query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
501                    }
502    
503                    String sql = query.toString();
504    
505                    Query q = session.createQuery(sql);
506    
507                    q.setFirstResult(0);
508                    q.setMaxResults(2);
509    
510                    QueryPos qPos = QueryPos.getInstance(q);
511    
512                    qPos.add(groupId);
513    
514                    if (orderByComparator != null) {
515                            Object[] values = orderByComparator.getOrderByConditionValues(blogsStatsUser);
516    
517                            for (Object value : values) {
518                                    qPos.add(value);
519                            }
520                    }
521    
522                    List<BlogsStatsUser> list = q.list();
523    
524                    if (list.size() == 2) {
525                            return list.get(1);
526                    }
527                    else {
528                            return null;
529                    }
530            }
531    
532            /**
533             * Removes all the blogs stats users where groupId = &#63; from the database.
534             *
535             * @param groupId the group ID
536             */
537            @Override
538            public void removeByGroupId(long groupId) {
539                    for (BlogsStatsUser blogsStatsUser : findByGroupId(groupId,
540                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
541                            remove(blogsStatsUser);
542                    }
543            }
544    
545            /**
546             * Returns the number of blogs stats users where groupId = &#63;.
547             *
548             * @param groupId the group ID
549             * @return the number of matching blogs stats users
550             */
551            @Override
552            public int countByGroupId(long groupId) {
553                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
554    
555                    Object[] finderArgs = new Object[] { groupId };
556    
557                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
558    
559                    if (count == null) {
560                            StringBundler query = new StringBundler(2);
561    
562                            query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
563    
564                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
565    
566                            String sql = query.toString();
567    
568                            Session session = null;
569    
570                            try {
571                                    session = openSession();
572    
573                                    Query q = session.createQuery(sql);
574    
575                                    QueryPos qPos = QueryPos.getInstance(q);
576    
577                                    qPos.add(groupId);
578    
579                                    count = (Long)q.uniqueResult();
580    
581                                    finderCache.putResult(finderPath, finderArgs, count);
582                            }
583                            catch (Exception e) {
584                                    finderCache.removeResult(finderPath, finderArgs);
585    
586                                    throw processException(e);
587                            }
588                            finally {
589                                    closeSession(session);
590                            }
591                    }
592    
593                    return count.intValue();
594            }
595    
596            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "blogsStatsUser.groupId = ?";
597            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
598                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
599                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
600                            "findByUserId",
601                            new String[] {
602                                    Long.class.getName(),
603                                    
604                            Integer.class.getName(), Integer.class.getName(),
605                                    OrderByComparator.class.getName()
606                            });
607            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
608                    new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
609                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
610                            BlogsStatsUserImpl.class,
611                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
612                            new String[] { Long.class.getName() },
613                            BlogsStatsUserModelImpl.USERID_COLUMN_BITMASK |
614                            BlogsStatsUserModelImpl.ENTRYCOUNT_COLUMN_BITMASK);
615            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
616                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
617                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
618                            new String[] { Long.class.getName() });
619    
620            /**
621             * Returns all the blogs stats users where userId = &#63;.
622             *
623             * @param userId the user ID
624             * @return the matching blogs stats users
625             */
626            @Override
627            public List<BlogsStatsUser> findByUserId(long userId) {
628                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
629            }
630    
631            /**
632             * Returns a range of all the blogs stats users where userId = &#63;.
633             *
634             * <p>
635             * 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 BlogsStatsUserModelImpl}. 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.
636             * </p>
637             *
638             * @param userId the user ID
639             * @param start the lower bound of the range of blogs stats users
640             * @param end the upper bound of the range of blogs stats users (not inclusive)
641             * @return the range of matching blogs stats users
642             */
643            @Override
644            public List<BlogsStatsUser> findByUserId(long userId, int start, int end) {
645                    return findByUserId(userId, start, end, null);
646            }
647    
648            /**
649             * Returns an ordered range of all the blogs stats users where userId = &#63;.
650             *
651             * <p>
652             * 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 BlogsStatsUserModelImpl}. 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.
653             * </p>
654             *
655             * @param userId the user ID
656             * @param start the lower bound of the range of blogs stats users
657             * @param end the upper bound of the range of blogs stats users (not inclusive)
658             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
659             * @return the ordered range of matching blogs stats users
660             */
661            @Override
662            public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
663                    OrderByComparator<BlogsStatsUser> orderByComparator) {
664                    return findByUserId(userId, start, end, orderByComparator, true);
665            }
666    
667            /**
668             * Returns an ordered range of all the blogs stats users where userId = &#63;.
669             *
670             * <p>
671             * 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 BlogsStatsUserModelImpl}. 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.
672             * </p>
673             *
674             * @param userId the user ID
675             * @param start the lower bound of the range of blogs stats users
676             * @param end the upper bound of the range of blogs stats users (not inclusive)
677             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
678             * @param retrieveFromCache whether to retrieve from the finder cache
679             * @return the ordered range of matching blogs stats users
680             */
681            @Override
682            public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
683                    OrderByComparator<BlogsStatsUser> orderByComparator,
684                    boolean retrieveFromCache) {
685                    boolean pagination = true;
686                    FinderPath finderPath = null;
687                    Object[] finderArgs = null;
688    
689                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
690                                    (orderByComparator == null)) {
691                            pagination = false;
692                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
693                            finderArgs = new Object[] { userId };
694                    }
695                    else {
696                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
697                            finderArgs = new Object[] { userId, start, end, orderByComparator };
698                    }
699    
700                    List<BlogsStatsUser> list = null;
701    
702                    if (retrieveFromCache) {
703                            list = (List<BlogsStatsUser>)finderCache.getResult(finderPath,
704                                            finderArgs, this);
705    
706                            if ((list != null) && !list.isEmpty()) {
707                                    for (BlogsStatsUser blogsStatsUser : list) {
708                                            if ((userId != blogsStatsUser.getUserId())) {
709                                                    list = null;
710    
711                                                    break;
712                                            }
713                                    }
714                            }
715                    }
716    
717                    if (list == null) {
718                            StringBundler query = null;
719    
720                            if (orderByComparator != null) {
721                                    query = new StringBundler(3 +
722                                                    (orderByComparator.getOrderByFields().length * 3));
723                            }
724                            else {
725                                    query = new StringBundler(3);
726                            }
727    
728                            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
729    
730                            query.append(_FINDER_COLUMN_USERID_USERID_2);
731    
732                            if (orderByComparator != null) {
733                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
734                                            orderByComparator);
735                            }
736                            else
737                             if (pagination) {
738                                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
739                            }
740    
741                            String sql = query.toString();
742    
743                            Session session = null;
744    
745                            try {
746                                    session = openSession();
747    
748                                    Query q = session.createQuery(sql);
749    
750                                    QueryPos qPos = QueryPos.getInstance(q);
751    
752                                    qPos.add(userId);
753    
754                                    if (!pagination) {
755                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
756                                                            getDialect(), start, end, false);
757    
758                                            Collections.sort(list);
759    
760                                            list = Collections.unmodifiableList(list);
761                                    }
762                                    else {
763                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
764                                                            getDialect(), start, end);
765                                    }
766    
767                                    cacheResult(list);
768    
769                                    finderCache.putResult(finderPath, finderArgs, list);
770                            }
771                            catch (Exception e) {
772                                    finderCache.removeResult(finderPath, finderArgs);
773    
774                                    throw processException(e);
775                            }
776                            finally {
777                                    closeSession(session);
778                            }
779                    }
780    
781                    return list;
782            }
783    
784            /**
785             * Returns the first blogs stats user in the ordered set where userId = &#63;.
786             *
787             * @param userId the user ID
788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
789             * @return the first matching blogs stats user
790             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
791             */
792            @Override
793            public BlogsStatsUser findByUserId_First(long userId,
794                    OrderByComparator<BlogsStatsUser> orderByComparator)
795                    throws NoSuchStatsUserException {
796                    BlogsStatsUser blogsStatsUser = fetchByUserId_First(userId,
797                                    orderByComparator);
798    
799                    if (blogsStatsUser != null) {
800                            return blogsStatsUser;
801                    }
802    
803                    StringBundler msg = new StringBundler(4);
804    
805                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
806    
807                    msg.append("userId=");
808                    msg.append(userId);
809    
810                    msg.append(StringPool.CLOSE_CURLY_BRACE);
811    
812                    throw new NoSuchStatsUserException(msg.toString());
813            }
814    
815            /**
816             * Returns the first blogs stats user in the ordered set where userId = &#63;.
817             *
818             * @param userId the user ID
819             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
820             * @return the first matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
821             */
822            @Override
823            public BlogsStatsUser fetchByUserId_First(long userId,
824                    OrderByComparator<BlogsStatsUser> orderByComparator) {
825                    List<BlogsStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
826    
827                    if (!list.isEmpty()) {
828                            return list.get(0);
829                    }
830    
831                    return null;
832            }
833    
834            /**
835             * Returns the last blogs stats user in the ordered set where userId = &#63;.
836             *
837             * @param userId the user ID
838             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
839             * @return the last matching blogs stats user
840             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
841             */
842            @Override
843            public BlogsStatsUser findByUserId_Last(long userId,
844                    OrderByComparator<BlogsStatsUser> orderByComparator)
845                    throws NoSuchStatsUserException {
846                    BlogsStatsUser blogsStatsUser = fetchByUserId_Last(userId,
847                                    orderByComparator);
848    
849                    if (blogsStatsUser != null) {
850                            return blogsStatsUser;
851                    }
852    
853                    StringBundler msg = new StringBundler(4);
854    
855                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
856    
857                    msg.append("userId=");
858                    msg.append(userId);
859    
860                    msg.append(StringPool.CLOSE_CURLY_BRACE);
861    
862                    throw new NoSuchStatsUserException(msg.toString());
863            }
864    
865            /**
866             * Returns the last blogs stats user in the ordered set where userId = &#63;.
867             *
868             * @param userId the user ID
869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
870             * @return the last matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
871             */
872            @Override
873            public BlogsStatsUser fetchByUserId_Last(long userId,
874                    OrderByComparator<BlogsStatsUser> orderByComparator) {
875                    int count = countByUserId(userId);
876    
877                    if (count == 0) {
878                            return null;
879                    }
880    
881                    List<BlogsStatsUser> list = findByUserId(userId, count - 1, count,
882                                    orderByComparator);
883    
884                    if (!list.isEmpty()) {
885                            return list.get(0);
886                    }
887    
888                    return null;
889            }
890    
891            /**
892             * Returns the blogs stats users before and after the current blogs stats user in the ordered set where userId = &#63;.
893             *
894             * @param statsUserId the primary key of the current blogs stats user
895             * @param userId the user ID
896             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
897             * @return the previous, current, and next blogs stats user
898             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
899             */
900            @Override
901            public BlogsStatsUser[] findByUserId_PrevAndNext(long statsUserId,
902                    long userId, OrderByComparator<BlogsStatsUser> orderByComparator)
903                    throws NoSuchStatsUserException {
904                    BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
905    
906                    Session session = null;
907    
908                    try {
909                            session = openSession();
910    
911                            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
912    
913                            array[0] = getByUserId_PrevAndNext(session, blogsStatsUser, userId,
914                                            orderByComparator, true);
915    
916                            array[1] = blogsStatsUser;
917    
918                            array[2] = getByUserId_PrevAndNext(session, blogsStatsUser, userId,
919                                            orderByComparator, false);
920    
921                            return array;
922                    }
923                    catch (Exception e) {
924                            throw processException(e);
925                    }
926                    finally {
927                            closeSession(session);
928                    }
929            }
930    
931            protected BlogsStatsUser getByUserId_PrevAndNext(Session session,
932                    BlogsStatsUser blogsStatsUser, long userId,
933                    OrderByComparator<BlogsStatsUser> orderByComparator, boolean previous) {
934                    StringBundler query = null;
935    
936                    if (orderByComparator != null) {
937                            query = new StringBundler(6 +
938                                            (orderByComparator.getOrderByFields().length * 6));
939                    }
940                    else {
941                            query = new StringBundler(3);
942                    }
943    
944                    query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
945    
946                    query.append(_FINDER_COLUMN_USERID_USERID_2);
947    
948                    if (orderByComparator != null) {
949                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
950    
951                            if (orderByConditionFields.length > 0) {
952                                    query.append(WHERE_AND);
953                            }
954    
955                            for (int i = 0; i < orderByConditionFields.length; i++) {
956                                    query.append(_ORDER_BY_ENTITY_ALIAS);
957                                    query.append(orderByConditionFields[i]);
958    
959                                    if ((i + 1) < orderByConditionFields.length) {
960                                            if (orderByComparator.isAscending() ^ previous) {
961                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
962                                            }
963                                            else {
964                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
965                                            }
966                                    }
967                                    else {
968                                            if (orderByComparator.isAscending() ^ previous) {
969                                                    query.append(WHERE_GREATER_THAN);
970                                            }
971                                            else {
972                                                    query.append(WHERE_LESSER_THAN);
973                                            }
974                                    }
975                            }
976    
977                            query.append(ORDER_BY_CLAUSE);
978    
979                            String[] orderByFields = orderByComparator.getOrderByFields();
980    
981                            for (int i = 0; i < orderByFields.length; i++) {
982                                    query.append(_ORDER_BY_ENTITY_ALIAS);
983                                    query.append(orderByFields[i]);
984    
985                                    if ((i + 1) < orderByFields.length) {
986                                            if (orderByComparator.isAscending() ^ previous) {
987                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
988                                            }
989                                            else {
990                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
991                                            }
992                                    }
993                                    else {
994                                            if (orderByComparator.isAscending() ^ previous) {
995                                                    query.append(ORDER_BY_ASC);
996                                            }
997                                            else {
998                                                    query.append(ORDER_BY_DESC);
999                                            }
1000                                    }
1001                            }
1002                    }
1003                    else {
1004                            query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1005                    }
1006    
1007                    String sql = query.toString();
1008    
1009                    Query q = session.createQuery(sql);
1010    
1011                    q.setFirstResult(0);
1012                    q.setMaxResults(2);
1013    
1014                    QueryPos qPos = QueryPos.getInstance(q);
1015    
1016                    qPos.add(userId);
1017    
1018                    if (orderByComparator != null) {
1019                            Object[] values = orderByComparator.getOrderByConditionValues(blogsStatsUser);
1020    
1021                            for (Object value : values) {
1022                                    qPos.add(value);
1023                            }
1024                    }
1025    
1026                    List<BlogsStatsUser> list = q.list();
1027    
1028                    if (list.size() == 2) {
1029                            return list.get(1);
1030                    }
1031                    else {
1032                            return null;
1033                    }
1034            }
1035    
1036            /**
1037             * Removes all the blogs stats users where userId = &#63; from the database.
1038             *
1039             * @param userId the user ID
1040             */
1041            @Override
1042            public void removeByUserId(long userId) {
1043                    for (BlogsStatsUser blogsStatsUser : findByUserId(userId,
1044                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1045                            remove(blogsStatsUser);
1046                    }
1047            }
1048    
1049            /**
1050             * Returns the number of blogs stats users where userId = &#63;.
1051             *
1052             * @param userId the user ID
1053             * @return the number of matching blogs stats users
1054             */
1055            @Override
1056            public int countByUserId(long userId) {
1057                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1058    
1059                    Object[] finderArgs = new Object[] { userId };
1060    
1061                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1062    
1063                    if (count == null) {
1064                            StringBundler query = new StringBundler(2);
1065    
1066                            query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1067    
1068                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1069    
1070                            String sql = query.toString();
1071    
1072                            Session session = null;
1073    
1074                            try {
1075                                    session = openSession();
1076    
1077                                    Query q = session.createQuery(sql);
1078    
1079                                    QueryPos qPos = QueryPos.getInstance(q);
1080    
1081                                    qPos.add(userId);
1082    
1083                                    count = (Long)q.uniqueResult();
1084    
1085                                    finderCache.putResult(finderPath, finderArgs, count);
1086                            }
1087                            catch (Exception e) {
1088                                    finderCache.removeResult(finderPath, finderArgs);
1089    
1090                                    throw processException(e);
1091                            }
1092                            finally {
1093                                    closeSession(session);
1094                            }
1095                    }
1096    
1097                    return count.intValue();
1098            }
1099    
1100            private static final String _FINDER_COLUMN_USERID_USERID_2 = "blogsStatsUser.userId = ?";
1101            public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1102                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
1103                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
1104                            new String[] { Long.class.getName(), Long.class.getName() },
1105                            BlogsStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
1106                            BlogsStatsUserModelImpl.USERID_COLUMN_BITMASK);
1107            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1108                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1109                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
1110                            new String[] { Long.class.getName(), Long.class.getName() });
1111    
1112            /**
1113             * Returns the blogs stats user where groupId = &#63; and userId = &#63; or throws a {@link NoSuchStatsUserException} if it could not be found.
1114             *
1115             * @param groupId the group ID
1116             * @param userId the user ID
1117             * @return the matching blogs stats user
1118             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
1119             */
1120            @Override
1121            public BlogsStatsUser findByG_U(long groupId, long userId)
1122                    throws NoSuchStatsUserException {
1123                    BlogsStatsUser blogsStatsUser = fetchByG_U(groupId, userId);
1124    
1125                    if (blogsStatsUser == null) {
1126                            StringBundler msg = new StringBundler(6);
1127    
1128                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1129    
1130                            msg.append("groupId=");
1131                            msg.append(groupId);
1132    
1133                            msg.append(", userId=");
1134                            msg.append(userId);
1135    
1136                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1137    
1138                            if (_log.isWarnEnabled()) {
1139                                    _log.warn(msg.toString());
1140                            }
1141    
1142                            throw new NoSuchStatsUserException(msg.toString());
1143                    }
1144    
1145                    return blogsStatsUser;
1146            }
1147    
1148            /**
1149             * Returns the blogs stats user where groupId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1150             *
1151             * @param groupId the group ID
1152             * @param userId the user ID
1153             * @return the matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
1154             */
1155            @Override
1156            public BlogsStatsUser fetchByG_U(long groupId, long userId) {
1157                    return fetchByG_U(groupId, userId, true);
1158            }
1159    
1160            /**
1161             * Returns the blogs stats user where groupId = &#63; and userId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1162             *
1163             * @param groupId the group ID
1164             * @param userId the user ID
1165             * @param retrieveFromCache whether to retrieve from the finder cache
1166             * @return the matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
1167             */
1168            @Override
1169            public BlogsStatsUser fetchByG_U(long groupId, long userId,
1170                    boolean retrieveFromCache) {
1171                    Object[] finderArgs = new Object[] { groupId, userId };
1172    
1173                    Object result = null;
1174    
1175                    if (retrieveFromCache) {
1176                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_U,
1177                                            finderArgs, this);
1178                    }
1179    
1180                    if (result instanceof BlogsStatsUser) {
1181                            BlogsStatsUser blogsStatsUser = (BlogsStatsUser)result;
1182    
1183                            if ((groupId != blogsStatsUser.getGroupId()) ||
1184                                            (userId != blogsStatsUser.getUserId())) {
1185                                    result = null;
1186                            }
1187                    }
1188    
1189                    if (result == null) {
1190                            StringBundler query = new StringBundler(4);
1191    
1192                            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1193    
1194                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1195    
1196                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1197    
1198                            String sql = query.toString();
1199    
1200                            Session session = null;
1201    
1202                            try {
1203                                    session = openSession();
1204    
1205                                    Query q = session.createQuery(sql);
1206    
1207                                    QueryPos qPos = QueryPos.getInstance(q);
1208    
1209                                    qPos.add(groupId);
1210    
1211                                    qPos.add(userId);
1212    
1213                                    List<BlogsStatsUser> list = q.list();
1214    
1215                                    if (list.isEmpty()) {
1216                                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_U, finderArgs,
1217                                                    list);
1218                                    }
1219                                    else {
1220                                            BlogsStatsUser blogsStatsUser = list.get(0);
1221    
1222                                            result = blogsStatsUser;
1223    
1224                                            cacheResult(blogsStatsUser);
1225    
1226                                            if ((blogsStatsUser.getGroupId() != groupId) ||
1227                                                            (blogsStatsUser.getUserId() != userId)) {
1228                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_U,
1229                                                            finderArgs, blogsStatsUser);
1230                                            }
1231                                    }
1232                            }
1233                            catch (Exception e) {
1234                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_U, finderArgs);
1235    
1236                                    throw processException(e);
1237                            }
1238                            finally {
1239                                    closeSession(session);
1240                            }
1241                    }
1242    
1243                    if (result instanceof List<?>) {
1244                            return null;
1245                    }
1246                    else {
1247                            return (BlogsStatsUser)result;
1248                    }
1249            }
1250    
1251            /**
1252             * Removes the blogs stats user where groupId = &#63; and userId = &#63; from the database.
1253             *
1254             * @param groupId the group ID
1255             * @param userId the user ID
1256             * @return the blogs stats user that was removed
1257             */
1258            @Override
1259            public BlogsStatsUser removeByG_U(long groupId, long userId)
1260                    throws NoSuchStatsUserException {
1261                    BlogsStatsUser blogsStatsUser = findByG_U(groupId, userId);
1262    
1263                    return remove(blogsStatsUser);
1264            }
1265    
1266            /**
1267             * Returns the number of blogs stats users where groupId = &#63; and userId = &#63;.
1268             *
1269             * @param groupId the group ID
1270             * @param userId the user ID
1271             * @return the number of matching blogs stats users
1272             */
1273            @Override
1274            public int countByG_U(long groupId, long userId) {
1275                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
1276    
1277                    Object[] finderArgs = new Object[] { groupId, userId };
1278    
1279                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1280    
1281                    if (count == null) {
1282                            StringBundler query = new StringBundler(3);
1283    
1284                            query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1285    
1286                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1287    
1288                            query.append(_FINDER_COLUMN_G_U_USERID_2);
1289    
1290                            String sql = query.toString();
1291    
1292                            Session session = null;
1293    
1294                            try {
1295                                    session = openSession();
1296    
1297                                    Query q = session.createQuery(sql);
1298    
1299                                    QueryPos qPos = QueryPos.getInstance(q);
1300    
1301                                    qPos.add(groupId);
1302    
1303                                    qPos.add(userId);
1304    
1305                                    count = (Long)q.uniqueResult();
1306    
1307                                    finderCache.putResult(finderPath, finderArgs, count);
1308                            }
1309                            catch (Exception e) {
1310                                    finderCache.removeResult(finderPath, finderArgs);
1311    
1312                                    throw processException(e);
1313                            }
1314                            finally {
1315                                    closeSession(session);
1316                            }
1317                    }
1318    
1319                    return count.intValue();
1320            }
1321    
1322            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "blogsStatsUser.groupId = ? AND ";
1323            private static final String _FINDER_COLUMN_G_U_USERID_2 = "blogsStatsUser.userId = ?";
1324            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTE = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1325                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
1326                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1327                            "findByG_NotE",
1328                            new String[] {
1329                                    Long.class.getName(), Integer.class.getName(),
1330                                    
1331                            Integer.class.getName(), Integer.class.getName(),
1332                                    OrderByComparator.class.getName()
1333                            });
1334            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTE = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1335                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1336                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotE",
1337                            new String[] { Long.class.getName(), Integer.class.getName() });
1338    
1339            /**
1340             * Returns all the blogs stats users where groupId = &#63; and entryCount &ne; &#63;.
1341             *
1342             * @param groupId the group ID
1343             * @param entryCount the entry count
1344             * @return the matching blogs stats users
1345             */
1346            @Override
1347            public List<BlogsStatsUser> findByG_NotE(long groupId, int entryCount) {
1348                    return findByG_NotE(groupId, entryCount, QueryUtil.ALL_POS,
1349                            QueryUtil.ALL_POS, null);
1350            }
1351    
1352            /**
1353             * Returns a range of all the blogs stats users where groupId = &#63; and entryCount &ne; &#63;.
1354             *
1355             * <p>
1356             * 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 BlogsStatsUserModelImpl}. 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.
1357             * </p>
1358             *
1359             * @param groupId the group ID
1360             * @param entryCount the entry count
1361             * @param start the lower bound of the range of blogs stats users
1362             * @param end the upper bound of the range of blogs stats users (not inclusive)
1363             * @return the range of matching blogs stats users
1364             */
1365            @Override
1366            public List<BlogsStatsUser> findByG_NotE(long groupId, int entryCount,
1367                    int start, int end) {
1368                    return findByG_NotE(groupId, entryCount, start, end, null);
1369            }
1370    
1371            /**
1372             * Returns an ordered range of all the blogs stats users where groupId = &#63; and entryCount &ne; &#63;.
1373             *
1374             * <p>
1375             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BlogsStatsUserModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1376             * </p>
1377             *
1378             * @param groupId the group ID
1379             * @param entryCount the entry count
1380             * @param start the lower bound of the range of blogs stats users
1381             * @param end the upper bound of the range of blogs stats users (not inclusive)
1382             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1383             * @return the ordered range of matching blogs stats users
1384             */
1385            @Override
1386            public List<BlogsStatsUser> findByG_NotE(long groupId, int entryCount,
1387                    int start, int end, OrderByComparator<BlogsStatsUser> orderByComparator) {
1388                    return findByG_NotE(groupId, entryCount, start, end, orderByComparator,
1389                            true);
1390            }
1391    
1392            /**
1393             * Returns an ordered range of all the blogs stats users where groupId = &#63; and entryCount &ne; &#63;.
1394             *
1395             * <p>
1396             * 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 BlogsStatsUserModelImpl}. 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.
1397             * </p>
1398             *
1399             * @param groupId the group ID
1400             * @param entryCount the entry count
1401             * @param start the lower bound of the range of blogs stats users
1402             * @param end the upper bound of the range of blogs stats users (not inclusive)
1403             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1404             * @param retrieveFromCache whether to retrieve from the finder cache
1405             * @return the ordered range of matching blogs stats users
1406             */
1407            @Override
1408            public List<BlogsStatsUser> findByG_NotE(long groupId, int entryCount,
1409                    int start, int end,
1410                    OrderByComparator<BlogsStatsUser> orderByComparator,
1411                    boolean retrieveFromCache) {
1412                    boolean pagination = true;
1413                    FinderPath finderPath = null;
1414                    Object[] finderArgs = null;
1415    
1416                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTE;
1417                    finderArgs = new Object[] {
1418                                    groupId, entryCount,
1419                                    
1420                                    start, end, orderByComparator
1421                            };
1422    
1423                    List<BlogsStatsUser> list = null;
1424    
1425                    if (retrieveFromCache) {
1426                            list = (List<BlogsStatsUser>)finderCache.getResult(finderPath,
1427                                            finderArgs, this);
1428    
1429                            if ((list != null) && !list.isEmpty()) {
1430                                    for (BlogsStatsUser blogsStatsUser : list) {
1431                                            if ((groupId != blogsStatsUser.getGroupId()) ||
1432                                                            (entryCount == blogsStatsUser.getEntryCount())) {
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(4 +
1446                                                    (orderByComparator.getOrderByFields().length * 3));
1447                            }
1448                            else {
1449                                    query = new StringBundler(4);
1450                            }
1451    
1452                            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1453    
1454                            query.append(_FINDER_COLUMN_G_NOTE_GROUPID_2);
1455    
1456                            query.append(_FINDER_COLUMN_G_NOTE_ENTRYCOUNT_2);
1457    
1458                            if (orderByComparator != null) {
1459                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1460                                            orderByComparator);
1461                            }
1462                            else
1463                             if (pagination) {
1464                                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1465                            }
1466    
1467                            String sql = query.toString();
1468    
1469                            Session session = null;
1470    
1471                            try {
1472                                    session = openSession();
1473    
1474                                    Query q = session.createQuery(sql);
1475    
1476                                    QueryPos qPos = QueryPos.getInstance(q);
1477    
1478                                    qPos.add(groupId);
1479    
1480                                    qPos.add(entryCount);
1481    
1482                                    if (!pagination) {
1483                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
1484                                                            getDialect(), start, end, false);
1485    
1486                                            Collections.sort(list);
1487    
1488                                            list = Collections.unmodifiableList(list);
1489                                    }
1490                                    else {
1491                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
1492                                                            getDialect(), start, end);
1493                                    }
1494    
1495                                    cacheResult(list);
1496    
1497                                    finderCache.putResult(finderPath, finderArgs, list);
1498                            }
1499                            catch (Exception e) {
1500                                    finderCache.removeResult(finderPath, finderArgs);
1501    
1502                                    throw processException(e);
1503                            }
1504                            finally {
1505                                    closeSession(session);
1506                            }
1507                    }
1508    
1509                    return list;
1510            }
1511    
1512            /**
1513             * Returns the first blogs stats user in the ordered set where groupId = &#63; and entryCount &ne; &#63;.
1514             *
1515             * @param groupId the group ID
1516             * @param entryCount the entry count
1517             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1518             * @return the first matching blogs stats user
1519             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
1520             */
1521            @Override
1522            public BlogsStatsUser findByG_NotE_First(long groupId, int entryCount,
1523                    OrderByComparator<BlogsStatsUser> orderByComparator)
1524                    throws NoSuchStatsUserException {
1525                    BlogsStatsUser blogsStatsUser = fetchByG_NotE_First(groupId,
1526                                    entryCount, orderByComparator);
1527    
1528                    if (blogsStatsUser != null) {
1529                            return blogsStatsUser;
1530                    }
1531    
1532                    StringBundler msg = new StringBundler(6);
1533    
1534                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1535    
1536                    msg.append("groupId=");
1537                    msg.append(groupId);
1538    
1539                    msg.append(", entryCount=");
1540                    msg.append(entryCount);
1541    
1542                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1543    
1544                    throw new NoSuchStatsUserException(msg.toString());
1545            }
1546    
1547            /**
1548             * Returns the first blogs stats user in the ordered set where groupId = &#63; and entryCount &ne; &#63;.
1549             *
1550             * @param groupId the group ID
1551             * @param entryCount the entry count
1552             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1553             * @return the first matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
1554             */
1555            @Override
1556            public BlogsStatsUser fetchByG_NotE_First(long groupId, int entryCount,
1557                    OrderByComparator<BlogsStatsUser> orderByComparator) {
1558                    List<BlogsStatsUser> list = findByG_NotE(groupId, entryCount, 0, 1,
1559                                    orderByComparator);
1560    
1561                    if (!list.isEmpty()) {
1562                            return list.get(0);
1563                    }
1564    
1565                    return null;
1566            }
1567    
1568            /**
1569             * Returns the last blogs stats user in the ordered set where groupId = &#63; and entryCount &ne; &#63;.
1570             *
1571             * @param groupId the group ID
1572             * @param entryCount the entry count
1573             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1574             * @return the last matching blogs stats user
1575             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
1576             */
1577            @Override
1578            public BlogsStatsUser findByG_NotE_Last(long groupId, int entryCount,
1579                    OrderByComparator<BlogsStatsUser> orderByComparator)
1580                    throws NoSuchStatsUserException {
1581                    BlogsStatsUser blogsStatsUser = fetchByG_NotE_Last(groupId, entryCount,
1582                                    orderByComparator);
1583    
1584                    if (blogsStatsUser != null) {
1585                            return blogsStatsUser;
1586                    }
1587    
1588                    StringBundler msg = new StringBundler(6);
1589    
1590                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1591    
1592                    msg.append("groupId=");
1593                    msg.append(groupId);
1594    
1595                    msg.append(", entryCount=");
1596                    msg.append(entryCount);
1597    
1598                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1599    
1600                    throw new NoSuchStatsUserException(msg.toString());
1601            }
1602    
1603            /**
1604             * Returns the last blogs stats user in the ordered set where groupId = &#63; and entryCount &ne; &#63;.
1605             *
1606             * @param groupId the group ID
1607             * @param entryCount the entry count
1608             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1609             * @return the last matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
1610             */
1611            @Override
1612            public BlogsStatsUser fetchByG_NotE_Last(long groupId, int entryCount,
1613                    OrderByComparator<BlogsStatsUser> orderByComparator) {
1614                    int count = countByG_NotE(groupId, entryCount);
1615    
1616                    if (count == 0) {
1617                            return null;
1618                    }
1619    
1620                    List<BlogsStatsUser> list = findByG_NotE(groupId, entryCount,
1621                                    count - 1, count, orderByComparator);
1622    
1623                    if (!list.isEmpty()) {
1624                            return list.get(0);
1625                    }
1626    
1627                    return null;
1628            }
1629    
1630            /**
1631             * Returns the blogs stats users before and after the current blogs stats user in the ordered set where groupId = &#63; and entryCount &ne; &#63;.
1632             *
1633             * @param statsUserId the primary key of the current blogs stats user
1634             * @param groupId the group ID
1635             * @param entryCount the entry count
1636             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1637             * @return the previous, current, and next blogs stats user
1638             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
1639             */
1640            @Override
1641            public BlogsStatsUser[] findByG_NotE_PrevAndNext(long statsUserId,
1642                    long groupId, int entryCount,
1643                    OrderByComparator<BlogsStatsUser> orderByComparator)
1644                    throws NoSuchStatsUserException {
1645                    BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1646    
1647                    Session session = null;
1648    
1649                    try {
1650                            session = openSession();
1651    
1652                            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1653    
1654                            array[0] = getByG_NotE_PrevAndNext(session, blogsStatsUser,
1655                                            groupId, entryCount, orderByComparator, true);
1656    
1657                            array[1] = blogsStatsUser;
1658    
1659                            array[2] = getByG_NotE_PrevAndNext(session, blogsStatsUser,
1660                                            groupId, entryCount, orderByComparator, false);
1661    
1662                            return array;
1663                    }
1664                    catch (Exception e) {
1665                            throw processException(e);
1666                    }
1667                    finally {
1668                            closeSession(session);
1669                    }
1670            }
1671    
1672            protected BlogsStatsUser getByG_NotE_PrevAndNext(Session session,
1673                    BlogsStatsUser blogsStatsUser, long groupId, int entryCount,
1674                    OrderByComparator<BlogsStatsUser> orderByComparator, boolean previous) {
1675                    StringBundler query = null;
1676    
1677                    if (orderByComparator != null) {
1678                            query = new StringBundler(6 +
1679                                            (orderByComparator.getOrderByFields().length * 6));
1680                    }
1681                    else {
1682                            query = new StringBundler(3);
1683                    }
1684    
1685                    query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1686    
1687                    query.append(_FINDER_COLUMN_G_NOTE_GROUPID_2);
1688    
1689                    query.append(_FINDER_COLUMN_G_NOTE_ENTRYCOUNT_2);
1690    
1691                    if (orderByComparator != null) {
1692                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1693    
1694                            if (orderByConditionFields.length > 0) {
1695                                    query.append(WHERE_AND);
1696                            }
1697    
1698                            for (int i = 0; i < orderByConditionFields.length; i++) {
1699                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1700                                    query.append(orderByConditionFields[i]);
1701    
1702                                    if ((i + 1) < orderByConditionFields.length) {
1703                                            if (orderByComparator.isAscending() ^ previous) {
1704                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1705                                            }
1706                                            else {
1707                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1708                                            }
1709                                    }
1710                                    else {
1711                                            if (orderByComparator.isAscending() ^ previous) {
1712                                                    query.append(WHERE_GREATER_THAN);
1713                                            }
1714                                            else {
1715                                                    query.append(WHERE_LESSER_THAN);
1716                                            }
1717                                    }
1718                            }
1719    
1720                            query.append(ORDER_BY_CLAUSE);
1721    
1722                            String[] orderByFields = orderByComparator.getOrderByFields();
1723    
1724                            for (int i = 0; i < orderByFields.length; i++) {
1725                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1726                                    query.append(orderByFields[i]);
1727    
1728                                    if ((i + 1) < orderByFields.length) {
1729                                            if (orderByComparator.isAscending() ^ previous) {
1730                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1731                                            }
1732                                            else {
1733                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1734                                            }
1735                                    }
1736                                    else {
1737                                            if (orderByComparator.isAscending() ^ previous) {
1738                                                    query.append(ORDER_BY_ASC);
1739                                            }
1740                                            else {
1741                                                    query.append(ORDER_BY_DESC);
1742                                            }
1743                                    }
1744                            }
1745                    }
1746                    else {
1747                            query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1748                    }
1749    
1750                    String sql = query.toString();
1751    
1752                    Query q = session.createQuery(sql);
1753    
1754                    q.setFirstResult(0);
1755                    q.setMaxResults(2);
1756    
1757                    QueryPos qPos = QueryPos.getInstance(q);
1758    
1759                    qPos.add(groupId);
1760    
1761                    qPos.add(entryCount);
1762    
1763                    if (orderByComparator != null) {
1764                            Object[] values = orderByComparator.getOrderByConditionValues(blogsStatsUser);
1765    
1766                            for (Object value : values) {
1767                                    qPos.add(value);
1768                            }
1769                    }
1770    
1771                    List<BlogsStatsUser> list = q.list();
1772    
1773                    if (list.size() == 2) {
1774                            return list.get(1);
1775                    }
1776                    else {
1777                            return null;
1778                    }
1779            }
1780    
1781            /**
1782             * Removes all the blogs stats users where groupId = &#63; and entryCount &ne; &#63; from the database.
1783             *
1784             * @param groupId the group ID
1785             * @param entryCount the entry count
1786             */
1787            @Override
1788            public void removeByG_NotE(long groupId, int entryCount) {
1789                    for (BlogsStatsUser blogsStatsUser : findByG_NotE(groupId, entryCount,
1790                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1791                            remove(blogsStatsUser);
1792                    }
1793            }
1794    
1795            /**
1796             * Returns the number of blogs stats users where groupId = &#63; and entryCount &ne; &#63;.
1797             *
1798             * @param groupId the group ID
1799             * @param entryCount the entry count
1800             * @return the number of matching blogs stats users
1801             */
1802            @Override
1803            public int countByG_NotE(long groupId, int entryCount) {
1804                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTE;
1805    
1806                    Object[] finderArgs = new Object[] { groupId, entryCount };
1807    
1808                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1809    
1810                    if (count == null) {
1811                            StringBundler query = new StringBundler(3);
1812    
1813                            query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1814    
1815                            query.append(_FINDER_COLUMN_G_NOTE_GROUPID_2);
1816    
1817                            query.append(_FINDER_COLUMN_G_NOTE_ENTRYCOUNT_2);
1818    
1819                            String sql = query.toString();
1820    
1821                            Session session = null;
1822    
1823                            try {
1824                                    session = openSession();
1825    
1826                                    Query q = session.createQuery(sql);
1827    
1828                                    QueryPos qPos = QueryPos.getInstance(q);
1829    
1830                                    qPos.add(groupId);
1831    
1832                                    qPos.add(entryCount);
1833    
1834                                    count = (Long)q.uniqueResult();
1835    
1836                                    finderCache.putResult(finderPath, finderArgs, count);
1837                            }
1838                            catch (Exception e) {
1839                                    finderCache.removeResult(finderPath, finderArgs);
1840    
1841                                    throw processException(e);
1842                            }
1843                            finally {
1844                                    closeSession(session);
1845                            }
1846                    }
1847    
1848                    return count.intValue();
1849            }
1850    
1851            private static final String _FINDER_COLUMN_G_NOTE_GROUPID_2 = "blogsStatsUser.groupId = ? AND ";
1852            private static final String _FINDER_COLUMN_G_NOTE_ENTRYCOUNT_2 = "blogsStatsUser.entryCount != ?";
1853            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTE = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1854                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
1855                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1856                            "findByC_NotE",
1857                            new String[] {
1858                                    Long.class.getName(), Integer.class.getName(),
1859                                    
1860                            Integer.class.getName(), Integer.class.getName(),
1861                                    OrderByComparator.class.getName()
1862                            });
1863            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTE = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1864                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1865                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_NotE",
1866                            new String[] { Long.class.getName(), Integer.class.getName() });
1867    
1868            /**
1869             * Returns all the blogs stats users where companyId = &#63; and entryCount &ne; &#63;.
1870             *
1871             * @param companyId the company ID
1872             * @param entryCount the entry count
1873             * @return the matching blogs stats users
1874             */
1875            @Override
1876            public List<BlogsStatsUser> findByC_NotE(long companyId, int entryCount) {
1877                    return findByC_NotE(companyId, entryCount, QueryUtil.ALL_POS,
1878                            QueryUtil.ALL_POS, null);
1879            }
1880    
1881            /**
1882             * Returns a range of all the blogs stats users where companyId = &#63; and entryCount &ne; &#63;.
1883             *
1884             * <p>
1885             * 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 BlogsStatsUserModelImpl}. 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.
1886             * </p>
1887             *
1888             * @param companyId the company ID
1889             * @param entryCount the entry count
1890             * @param start the lower bound of the range of blogs stats users
1891             * @param end the upper bound of the range of blogs stats users (not inclusive)
1892             * @return the range of matching blogs stats users
1893             */
1894            @Override
1895            public List<BlogsStatsUser> findByC_NotE(long companyId, int entryCount,
1896                    int start, int end) {
1897                    return findByC_NotE(companyId, entryCount, start, end, null);
1898            }
1899    
1900            /**
1901             * Returns an ordered range of all the blogs stats users where companyId = &#63; and entryCount &ne; &#63;.
1902             *
1903             * <p>
1904             * 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 BlogsStatsUserModelImpl}. 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.
1905             * </p>
1906             *
1907             * @param companyId the company ID
1908             * @param entryCount the entry count
1909             * @param start the lower bound of the range of blogs stats users
1910             * @param end the upper bound of the range of blogs stats users (not inclusive)
1911             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1912             * @return the ordered range of matching blogs stats users
1913             */
1914            @Override
1915            public List<BlogsStatsUser> findByC_NotE(long companyId, int entryCount,
1916                    int start, int end, OrderByComparator<BlogsStatsUser> orderByComparator) {
1917                    return findByC_NotE(companyId, entryCount, start, end,
1918                            orderByComparator, true);
1919            }
1920    
1921            /**
1922             * Returns an ordered range of all the blogs stats users where companyId = &#63; and entryCount &ne; &#63;.
1923             *
1924             * <p>
1925             * 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 BlogsStatsUserModelImpl}. 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.
1926             * </p>
1927             *
1928             * @param companyId the company ID
1929             * @param entryCount the entry count
1930             * @param start the lower bound of the range of blogs stats users
1931             * @param end the upper bound of the range of blogs stats users (not inclusive)
1932             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1933             * @param retrieveFromCache whether to retrieve from the finder cache
1934             * @return the ordered range of matching blogs stats users
1935             */
1936            @Override
1937            public List<BlogsStatsUser> findByC_NotE(long companyId, int entryCount,
1938                    int start, int end,
1939                    OrderByComparator<BlogsStatsUser> orderByComparator,
1940                    boolean retrieveFromCache) {
1941                    boolean pagination = true;
1942                    FinderPath finderPath = null;
1943                    Object[] finderArgs = null;
1944    
1945                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_NOTE;
1946                    finderArgs = new Object[] {
1947                                    companyId, entryCount,
1948                                    
1949                                    start, end, orderByComparator
1950                            };
1951    
1952                    List<BlogsStatsUser> list = null;
1953    
1954                    if (retrieveFromCache) {
1955                            list = (List<BlogsStatsUser>)finderCache.getResult(finderPath,
1956                                            finderArgs, this);
1957    
1958                            if ((list != null) && !list.isEmpty()) {
1959                                    for (BlogsStatsUser blogsStatsUser : list) {
1960                                            if ((companyId != blogsStatsUser.getCompanyId()) ||
1961                                                            (entryCount == blogsStatsUser.getEntryCount())) {
1962                                                    list = null;
1963    
1964                                                    break;
1965                                            }
1966                                    }
1967                            }
1968                    }
1969    
1970                    if (list == null) {
1971                            StringBundler query = null;
1972    
1973                            if (orderByComparator != null) {
1974                                    query = new StringBundler(4 +
1975                                                    (orderByComparator.getOrderByFields().length * 3));
1976                            }
1977                            else {
1978                                    query = new StringBundler(4);
1979                            }
1980    
1981                            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1982    
1983                            query.append(_FINDER_COLUMN_C_NOTE_COMPANYID_2);
1984    
1985                            query.append(_FINDER_COLUMN_C_NOTE_ENTRYCOUNT_2);
1986    
1987                            if (orderByComparator != null) {
1988                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1989                                            orderByComparator);
1990                            }
1991                            else
1992                             if (pagination) {
1993                                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1994                            }
1995    
1996                            String sql = query.toString();
1997    
1998                            Session session = null;
1999    
2000                            try {
2001                                    session = openSession();
2002    
2003                                    Query q = session.createQuery(sql);
2004    
2005                                    QueryPos qPos = QueryPos.getInstance(q);
2006    
2007                                    qPos.add(companyId);
2008    
2009                                    qPos.add(entryCount);
2010    
2011                                    if (!pagination) {
2012                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
2013                                                            getDialect(), start, end, false);
2014    
2015                                            Collections.sort(list);
2016    
2017                                            list = Collections.unmodifiableList(list);
2018                                    }
2019                                    else {
2020                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
2021                                                            getDialect(), start, end);
2022                                    }
2023    
2024                                    cacheResult(list);
2025    
2026                                    finderCache.putResult(finderPath, finderArgs, list);
2027                            }
2028                            catch (Exception e) {
2029                                    finderCache.removeResult(finderPath, finderArgs);
2030    
2031                                    throw processException(e);
2032                            }
2033                            finally {
2034                                    closeSession(session);
2035                            }
2036                    }
2037    
2038                    return list;
2039            }
2040    
2041            /**
2042             * Returns the first blogs stats user in the ordered set where companyId = &#63; and entryCount &ne; &#63;.
2043             *
2044             * @param companyId the company ID
2045             * @param entryCount the entry count
2046             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2047             * @return the first matching blogs stats user
2048             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
2049             */
2050            @Override
2051            public BlogsStatsUser findByC_NotE_First(long companyId, int entryCount,
2052                    OrderByComparator<BlogsStatsUser> orderByComparator)
2053                    throws NoSuchStatsUserException {
2054                    BlogsStatsUser blogsStatsUser = fetchByC_NotE_First(companyId,
2055                                    entryCount, orderByComparator);
2056    
2057                    if (blogsStatsUser != null) {
2058                            return blogsStatsUser;
2059                    }
2060    
2061                    StringBundler msg = new StringBundler(6);
2062    
2063                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2064    
2065                    msg.append("companyId=");
2066                    msg.append(companyId);
2067    
2068                    msg.append(", entryCount=");
2069                    msg.append(entryCount);
2070    
2071                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2072    
2073                    throw new NoSuchStatsUserException(msg.toString());
2074            }
2075    
2076            /**
2077             * Returns the first blogs stats user in the ordered set where companyId = &#63; and entryCount &ne; &#63;.
2078             *
2079             * @param companyId the company ID
2080             * @param entryCount the entry count
2081             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2082             * @return the first matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
2083             */
2084            @Override
2085            public BlogsStatsUser fetchByC_NotE_First(long companyId, int entryCount,
2086                    OrderByComparator<BlogsStatsUser> orderByComparator) {
2087                    List<BlogsStatsUser> list = findByC_NotE(companyId, entryCount, 0, 1,
2088                                    orderByComparator);
2089    
2090                    if (!list.isEmpty()) {
2091                            return list.get(0);
2092                    }
2093    
2094                    return null;
2095            }
2096    
2097            /**
2098             * Returns the last blogs stats user in the ordered set where companyId = &#63; and entryCount &ne; &#63;.
2099             *
2100             * @param companyId the company ID
2101             * @param entryCount the entry count
2102             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2103             * @return the last matching blogs stats user
2104             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
2105             */
2106            @Override
2107            public BlogsStatsUser findByC_NotE_Last(long companyId, int entryCount,
2108                    OrderByComparator<BlogsStatsUser> orderByComparator)
2109                    throws NoSuchStatsUserException {
2110                    BlogsStatsUser blogsStatsUser = fetchByC_NotE_Last(companyId,
2111                                    entryCount, orderByComparator);
2112    
2113                    if (blogsStatsUser != null) {
2114                            return blogsStatsUser;
2115                    }
2116    
2117                    StringBundler msg = new StringBundler(6);
2118    
2119                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2120    
2121                    msg.append("companyId=");
2122                    msg.append(companyId);
2123    
2124                    msg.append(", entryCount=");
2125                    msg.append(entryCount);
2126    
2127                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2128    
2129                    throw new NoSuchStatsUserException(msg.toString());
2130            }
2131    
2132            /**
2133             * Returns the last blogs stats user in the ordered set where companyId = &#63; and entryCount &ne; &#63;.
2134             *
2135             * @param companyId the company ID
2136             * @param entryCount the entry count
2137             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2138             * @return the last matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
2139             */
2140            @Override
2141            public BlogsStatsUser fetchByC_NotE_Last(long companyId, int entryCount,
2142                    OrderByComparator<BlogsStatsUser> orderByComparator) {
2143                    int count = countByC_NotE(companyId, entryCount);
2144    
2145                    if (count == 0) {
2146                            return null;
2147                    }
2148    
2149                    List<BlogsStatsUser> list = findByC_NotE(companyId, entryCount,
2150                                    count - 1, count, orderByComparator);
2151    
2152                    if (!list.isEmpty()) {
2153                            return list.get(0);
2154                    }
2155    
2156                    return null;
2157            }
2158    
2159            /**
2160             * Returns the blogs stats users before and after the current blogs stats user in the ordered set where companyId = &#63; and entryCount &ne; &#63;.
2161             *
2162             * @param statsUserId the primary key of the current blogs stats user
2163             * @param companyId the company ID
2164             * @param entryCount the entry count
2165             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2166             * @return the previous, current, and next blogs stats user
2167             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
2168             */
2169            @Override
2170            public BlogsStatsUser[] findByC_NotE_PrevAndNext(long statsUserId,
2171                    long companyId, int entryCount,
2172                    OrderByComparator<BlogsStatsUser> orderByComparator)
2173                    throws NoSuchStatsUserException {
2174                    BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
2175    
2176                    Session session = null;
2177    
2178                    try {
2179                            session = openSession();
2180    
2181                            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
2182    
2183                            array[0] = getByC_NotE_PrevAndNext(session, blogsStatsUser,
2184                                            companyId, entryCount, orderByComparator, true);
2185    
2186                            array[1] = blogsStatsUser;
2187    
2188                            array[2] = getByC_NotE_PrevAndNext(session, blogsStatsUser,
2189                                            companyId, entryCount, orderByComparator, false);
2190    
2191                            return array;
2192                    }
2193                    catch (Exception e) {
2194                            throw processException(e);
2195                    }
2196                    finally {
2197                            closeSession(session);
2198                    }
2199            }
2200    
2201            protected BlogsStatsUser getByC_NotE_PrevAndNext(Session session,
2202                    BlogsStatsUser blogsStatsUser, long companyId, int entryCount,
2203                    OrderByComparator<BlogsStatsUser> orderByComparator, boolean previous) {
2204                    StringBundler query = null;
2205    
2206                    if (orderByComparator != null) {
2207                            query = new StringBundler(6 +
2208                                            (orderByComparator.getOrderByFields().length * 6));
2209                    }
2210                    else {
2211                            query = new StringBundler(3);
2212                    }
2213    
2214                    query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
2215    
2216                    query.append(_FINDER_COLUMN_C_NOTE_COMPANYID_2);
2217    
2218                    query.append(_FINDER_COLUMN_C_NOTE_ENTRYCOUNT_2);
2219    
2220                    if (orderByComparator != null) {
2221                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2222    
2223                            if (orderByConditionFields.length > 0) {
2224                                    query.append(WHERE_AND);
2225                            }
2226    
2227                            for (int i = 0; i < orderByConditionFields.length; i++) {
2228                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2229                                    query.append(orderByConditionFields[i]);
2230    
2231                                    if ((i + 1) < orderByConditionFields.length) {
2232                                            if (orderByComparator.isAscending() ^ previous) {
2233                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2234                                            }
2235                                            else {
2236                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2237                                            }
2238                                    }
2239                                    else {
2240                                            if (orderByComparator.isAscending() ^ previous) {
2241                                                    query.append(WHERE_GREATER_THAN);
2242                                            }
2243                                            else {
2244                                                    query.append(WHERE_LESSER_THAN);
2245                                            }
2246                                    }
2247                            }
2248    
2249                            query.append(ORDER_BY_CLAUSE);
2250    
2251                            String[] orderByFields = orderByComparator.getOrderByFields();
2252    
2253                            for (int i = 0; i < orderByFields.length; i++) {
2254                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2255                                    query.append(orderByFields[i]);
2256    
2257                                    if ((i + 1) < orderByFields.length) {
2258                                            if (orderByComparator.isAscending() ^ previous) {
2259                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2260                                            }
2261                                            else {
2262                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2263                                            }
2264                                    }
2265                                    else {
2266                                            if (orderByComparator.isAscending() ^ previous) {
2267                                                    query.append(ORDER_BY_ASC);
2268                                            }
2269                                            else {
2270                                                    query.append(ORDER_BY_DESC);
2271                                            }
2272                                    }
2273                            }
2274                    }
2275                    else {
2276                            query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
2277                    }
2278    
2279                    String sql = query.toString();
2280    
2281                    Query q = session.createQuery(sql);
2282    
2283                    q.setFirstResult(0);
2284                    q.setMaxResults(2);
2285    
2286                    QueryPos qPos = QueryPos.getInstance(q);
2287    
2288                    qPos.add(companyId);
2289    
2290                    qPos.add(entryCount);
2291    
2292                    if (orderByComparator != null) {
2293                            Object[] values = orderByComparator.getOrderByConditionValues(blogsStatsUser);
2294    
2295                            for (Object value : values) {
2296                                    qPos.add(value);
2297                            }
2298                    }
2299    
2300                    List<BlogsStatsUser> list = q.list();
2301    
2302                    if (list.size() == 2) {
2303                            return list.get(1);
2304                    }
2305                    else {
2306                            return null;
2307                    }
2308            }
2309    
2310            /**
2311             * Removes all the blogs stats users where companyId = &#63; and entryCount &ne; &#63; from the database.
2312             *
2313             * @param companyId the company ID
2314             * @param entryCount the entry count
2315             */
2316            @Override
2317            public void removeByC_NotE(long companyId, int entryCount) {
2318                    for (BlogsStatsUser blogsStatsUser : findByC_NotE(companyId,
2319                                    entryCount, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2320                            remove(blogsStatsUser);
2321                    }
2322            }
2323    
2324            /**
2325             * Returns the number of blogs stats users where companyId = &#63; and entryCount &ne; &#63;.
2326             *
2327             * @param companyId the company ID
2328             * @param entryCount the entry count
2329             * @return the number of matching blogs stats users
2330             */
2331            @Override
2332            public int countByC_NotE(long companyId, int entryCount) {
2333                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_NOTE;
2334    
2335                    Object[] finderArgs = new Object[] { companyId, entryCount };
2336    
2337                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2338    
2339                    if (count == null) {
2340                            StringBundler query = new StringBundler(3);
2341    
2342                            query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
2343    
2344                            query.append(_FINDER_COLUMN_C_NOTE_COMPANYID_2);
2345    
2346                            query.append(_FINDER_COLUMN_C_NOTE_ENTRYCOUNT_2);
2347    
2348                            String sql = query.toString();
2349    
2350                            Session session = null;
2351    
2352                            try {
2353                                    session = openSession();
2354    
2355                                    Query q = session.createQuery(sql);
2356    
2357                                    QueryPos qPos = QueryPos.getInstance(q);
2358    
2359                                    qPos.add(companyId);
2360    
2361                                    qPos.add(entryCount);
2362    
2363                                    count = (Long)q.uniqueResult();
2364    
2365                                    finderCache.putResult(finderPath, finderArgs, count);
2366                            }
2367                            catch (Exception e) {
2368                                    finderCache.removeResult(finderPath, finderArgs);
2369    
2370                                    throw processException(e);
2371                            }
2372                            finally {
2373                                    closeSession(session);
2374                            }
2375                    }
2376    
2377                    return count.intValue();
2378            }
2379    
2380            private static final String _FINDER_COLUMN_C_NOTE_COMPANYID_2 = "blogsStatsUser.companyId = ? AND ";
2381            private static final String _FINDER_COLUMN_C_NOTE_ENTRYCOUNT_2 = "blogsStatsUser.entryCount != ?";
2382            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_L = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2383                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
2384                            BlogsStatsUserImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
2385                            "findByU_L",
2386                            new String[] {
2387                                    Long.class.getName(), Date.class.getName(),
2388                                    
2389                            Integer.class.getName(), Integer.class.getName(),
2390                                    OrderByComparator.class.getName()
2391                            });
2392            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_L = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2393                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
2394                            BlogsStatsUserImpl.class,
2395                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_L",
2396                            new String[] { Long.class.getName(), Date.class.getName() },
2397                            BlogsStatsUserModelImpl.USERID_COLUMN_BITMASK |
2398                            BlogsStatsUserModelImpl.LASTPOSTDATE_COLUMN_BITMASK |
2399                            BlogsStatsUserModelImpl.ENTRYCOUNT_COLUMN_BITMASK);
2400            public static final FinderPath FINDER_PATH_COUNT_BY_U_L = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2401                            BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
2402                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_L",
2403                            new String[] { Long.class.getName(), Date.class.getName() });
2404    
2405            /**
2406             * Returns all the blogs stats users where userId = &#63; and lastPostDate = &#63;.
2407             *
2408             * @param userId the user ID
2409             * @param lastPostDate the last post date
2410             * @return the matching blogs stats users
2411             */
2412            @Override
2413            public List<BlogsStatsUser> findByU_L(long userId, Date lastPostDate) {
2414                    return findByU_L(userId, lastPostDate, QueryUtil.ALL_POS,
2415                            QueryUtil.ALL_POS, null);
2416            }
2417    
2418            /**
2419             * Returns a range of all the blogs stats users where userId = &#63; and lastPostDate = &#63;.
2420             *
2421             * <p>
2422             * 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 BlogsStatsUserModelImpl}. 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.
2423             * </p>
2424             *
2425             * @param userId the user ID
2426             * @param lastPostDate the last post date
2427             * @param start the lower bound of the range of blogs stats users
2428             * @param end the upper bound of the range of blogs stats users (not inclusive)
2429             * @return the range of matching blogs stats users
2430             */
2431            @Override
2432            public List<BlogsStatsUser> findByU_L(long userId, Date lastPostDate,
2433                    int start, int end) {
2434                    return findByU_L(userId, lastPostDate, start, end, null);
2435            }
2436    
2437            /**
2438             * Returns an ordered range of all the blogs stats users where userId = &#63; and lastPostDate = &#63;.
2439             *
2440             * <p>
2441             * 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 BlogsStatsUserModelImpl}. 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.
2442             * </p>
2443             *
2444             * @param userId the user ID
2445             * @param lastPostDate the last post date
2446             * @param start the lower bound of the range of blogs stats users
2447             * @param end the upper bound of the range of blogs stats users (not inclusive)
2448             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2449             * @return the ordered range of matching blogs stats users
2450             */
2451            @Override
2452            public List<BlogsStatsUser> findByU_L(long userId, Date lastPostDate,
2453                    int start, int end, OrderByComparator<BlogsStatsUser> orderByComparator) {
2454                    return findByU_L(userId, lastPostDate, start, end, orderByComparator,
2455                            true);
2456            }
2457    
2458            /**
2459             * Returns an ordered range of all the blogs stats users where userId = &#63; and lastPostDate = &#63;.
2460             *
2461             * <p>
2462             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link BlogsStatsUserModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2463             * </p>
2464             *
2465             * @param userId the user ID
2466             * @param lastPostDate the last post date
2467             * @param start the lower bound of the range of blogs stats users
2468             * @param end the upper bound of the range of blogs stats users (not inclusive)
2469             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2470             * @param retrieveFromCache whether to retrieve from the finder cache
2471             * @return the ordered range of matching blogs stats users
2472             */
2473            @Override
2474            public List<BlogsStatsUser> findByU_L(long userId, Date lastPostDate,
2475                    int start, int end,
2476                    OrderByComparator<BlogsStatsUser> orderByComparator,
2477                    boolean retrieveFromCache) {
2478                    boolean pagination = true;
2479                    FinderPath finderPath = null;
2480                    Object[] finderArgs = null;
2481    
2482                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2483                                    (orderByComparator == null)) {
2484                            pagination = false;
2485                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_L;
2486                            finderArgs = new Object[] { userId, lastPostDate };
2487                    }
2488                    else {
2489                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_L;
2490                            finderArgs = new Object[] {
2491                                            userId, lastPostDate,
2492                                            
2493                                            start, end, orderByComparator
2494                                    };
2495                    }
2496    
2497                    List<BlogsStatsUser> list = null;
2498    
2499                    if (retrieveFromCache) {
2500                            list = (List<BlogsStatsUser>)finderCache.getResult(finderPath,
2501                                            finderArgs, this);
2502    
2503                            if ((list != null) && !list.isEmpty()) {
2504                                    for (BlogsStatsUser blogsStatsUser : list) {
2505                                            if ((userId != blogsStatsUser.getUserId()) ||
2506                                                            !Validator.equals(lastPostDate,
2507                                                                    blogsStatsUser.getLastPostDate())) {
2508                                                    list = null;
2509    
2510                                                    break;
2511                                            }
2512                                    }
2513                            }
2514                    }
2515    
2516                    if (list == null) {
2517                            StringBundler query = null;
2518    
2519                            if (orderByComparator != null) {
2520                                    query = new StringBundler(4 +
2521                                                    (orderByComparator.getOrderByFields().length * 3));
2522                            }
2523                            else {
2524                                    query = new StringBundler(4);
2525                            }
2526    
2527                            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
2528    
2529                            query.append(_FINDER_COLUMN_U_L_USERID_2);
2530    
2531                            boolean bindLastPostDate = false;
2532    
2533                            if (lastPostDate == null) {
2534                                    query.append(_FINDER_COLUMN_U_L_LASTPOSTDATE_1);
2535                            }
2536                            else {
2537                                    bindLastPostDate = true;
2538    
2539                                    query.append(_FINDER_COLUMN_U_L_LASTPOSTDATE_2);
2540                            }
2541    
2542                            if (orderByComparator != null) {
2543                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2544                                            orderByComparator);
2545                            }
2546                            else
2547                             if (pagination) {
2548                                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
2549                            }
2550    
2551                            String sql = query.toString();
2552    
2553                            Session session = null;
2554    
2555                            try {
2556                                    session = openSession();
2557    
2558                                    Query q = session.createQuery(sql);
2559    
2560                                    QueryPos qPos = QueryPos.getInstance(q);
2561    
2562                                    qPos.add(userId);
2563    
2564                                    if (bindLastPostDate) {
2565                                            qPos.add(new Timestamp(lastPostDate.getTime()));
2566                                    }
2567    
2568                                    if (!pagination) {
2569                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
2570                                                            getDialect(), start, end, false);
2571    
2572                                            Collections.sort(list);
2573    
2574                                            list = Collections.unmodifiableList(list);
2575                                    }
2576                                    else {
2577                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
2578                                                            getDialect(), start, end);
2579                                    }
2580    
2581                                    cacheResult(list);
2582    
2583                                    finderCache.putResult(finderPath, finderArgs, list);
2584                            }
2585                            catch (Exception e) {
2586                                    finderCache.removeResult(finderPath, finderArgs);
2587    
2588                                    throw processException(e);
2589                            }
2590                            finally {
2591                                    closeSession(session);
2592                            }
2593                    }
2594    
2595                    return list;
2596            }
2597    
2598            /**
2599             * Returns the first blogs stats user in the ordered set where userId = &#63; and lastPostDate = &#63;.
2600             *
2601             * @param userId the user ID
2602             * @param lastPostDate the last post date
2603             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2604             * @return the first matching blogs stats user
2605             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
2606             */
2607            @Override
2608            public BlogsStatsUser findByU_L_First(long userId, Date lastPostDate,
2609                    OrderByComparator<BlogsStatsUser> orderByComparator)
2610                    throws NoSuchStatsUserException {
2611                    BlogsStatsUser blogsStatsUser = fetchByU_L_First(userId, lastPostDate,
2612                                    orderByComparator);
2613    
2614                    if (blogsStatsUser != null) {
2615                            return blogsStatsUser;
2616                    }
2617    
2618                    StringBundler msg = new StringBundler(6);
2619    
2620                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2621    
2622                    msg.append("userId=");
2623                    msg.append(userId);
2624    
2625                    msg.append(", lastPostDate=");
2626                    msg.append(lastPostDate);
2627    
2628                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2629    
2630                    throw new NoSuchStatsUserException(msg.toString());
2631            }
2632    
2633            /**
2634             * Returns the first blogs stats user in the ordered set where userId = &#63; and lastPostDate = &#63;.
2635             *
2636             * @param userId the user ID
2637             * @param lastPostDate the last post date
2638             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2639             * @return the first matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
2640             */
2641            @Override
2642            public BlogsStatsUser fetchByU_L_First(long userId, Date lastPostDate,
2643                    OrderByComparator<BlogsStatsUser> orderByComparator) {
2644                    List<BlogsStatsUser> list = findByU_L(userId, lastPostDate, 0, 1,
2645                                    orderByComparator);
2646    
2647                    if (!list.isEmpty()) {
2648                            return list.get(0);
2649                    }
2650    
2651                    return null;
2652            }
2653    
2654            /**
2655             * Returns the last blogs stats user in the ordered set where userId = &#63; and lastPostDate = &#63;.
2656             *
2657             * @param userId the user ID
2658             * @param lastPostDate the last post date
2659             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2660             * @return the last matching blogs stats user
2661             * @throws NoSuchStatsUserException if a matching blogs stats user could not be found
2662             */
2663            @Override
2664            public BlogsStatsUser findByU_L_Last(long userId, Date lastPostDate,
2665                    OrderByComparator<BlogsStatsUser> orderByComparator)
2666                    throws NoSuchStatsUserException {
2667                    BlogsStatsUser blogsStatsUser = fetchByU_L_Last(userId, lastPostDate,
2668                                    orderByComparator);
2669    
2670                    if (blogsStatsUser != null) {
2671                            return blogsStatsUser;
2672                    }
2673    
2674                    StringBundler msg = new StringBundler(6);
2675    
2676                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2677    
2678                    msg.append("userId=");
2679                    msg.append(userId);
2680    
2681                    msg.append(", lastPostDate=");
2682                    msg.append(lastPostDate);
2683    
2684                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2685    
2686                    throw new NoSuchStatsUserException(msg.toString());
2687            }
2688    
2689            /**
2690             * Returns the last blogs stats user in the ordered set where userId = &#63; and lastPostDate = &#63;.
2691             *
2692             * @param userId the user ID
2693             * @param lastPostDate the last post date
2694             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2695             * @return the last matching blogs stats user, or <code>null</code> if a matching blogs stats user could not be found
2696             */
2697            @Override
2698            public BlogsStatsUser fetchByU_L_Last(long userId, Date lastPostDate,
2699                    OrderByComparator<BlogsStatsUser> orderByComparator) {
2700                    int count = countByU_L(userId, lastPostDate);
2701    
2702                    if (count == 0) {
2703                            return null;
2704                    }
2705    
2706                    List<BlogsStatsUser> list = findByU_L(userId, lastPostDate, count - 1,
2707                                    count, orderByComparator);
2708    
2709                    if (!list.isEmpty()) {
2710                            return list.get(0);
2711                    }
2712    
2713                    return null;
2714            }
2715    
2716            /**
2717             * Returns the blogs stats users before and after the current blogs stats user in the ordered set where userId = &#63; and lastPostDate = &#63;.
2718             *
2719             * @param statsUserId the primary key of the current blogs stats user
2720             * @param userId the user ID
2721             * @param lastPostDate the last post date
2722             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2723             * @return the previous, current, and next blogs stats user
2724             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
2725             */
2726            @Override
2727            public BlogsStatsUser[] findByU_L_PrevAndNext(long statsUserId,
2728                    long userId, Date lastPostDate,
2729                    OrderByComparator<BlogsStatsUser> orderByComparator)
2730                    throws NoSuchStatsUserException {
2731                    BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
2732    
2733                    Session session = null;
2734    
2735                    try {
2736                            session = openSession();
2737    
2738                            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
2739    
2740                            array[0] = getByU_L_PrevAndNext(session, blogsStatsUser, userId,
2741                                            lastPostDate, orderByComparator, true);
2742    
2743                            array[1] = blogsStatsUser;
2744    
2745                            array[2] = getByU_L_PrevAndNext(session, blogsStatsUser, userId,
2746                                            lastPostDate, orderByComparator, false);
2747    
2748                            return array;
2749                    }
2750                    catch (Exception e) {
2751                            throw processException(e);
2752                    }
2753                    finally {
2754                            closeSession(session);
2755                    }
2756            }
2757    
2758            protected BlogsStatsUser getByU_L_PrevAndNext(Session session,
2759                    BlogsStatsUser blogsStatsUser, long userId, Date lastPostDate,
2760                    OrderByComparator<BlogsStatsUser> orderByComparator, boolean previous) {
2761                    StringBundler query = null;
2762    
2763                    if (orderByComparator != null) {
2764                            query = new StringBundler(6 +
2765                                            (orderByComparator.getOrderByFields().length * 6));
2766                    }
2767                    else {
2768                            query = new StringBundler(3);
2769                    }
2770    
2771                    query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
2772    
2773                    query.append(_FINDER_COLUMN_U_L_USERID_2);
2774    
2775                    boolean bindLastPostDate = false;
2776    
2777                    if (lastPostDate == null) {
2778                            query.append(_FINDER_COLUMN_U_L_LASTPOSTDATE_1);
2779                    }
2780                    else {
2781                            bindLastPostDate = true;
2782    
2783                            query.append(_FINDER_COLUMN_U_L_LASTPOSTDATE_2);
2784                    }
2785    
2786                    if (orderByComparator != null) {
2787                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2788    
2789                            if (orderByConditionFields.length > 0) {
2790                                    query.append(WHERE_AND);
2791                            }
2792    
2793                            for (int i = 0; i < orderByConditionFields.length; i++) {
2794                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2795                                    query.append(orderByConditionFields[i]);
2796    
2797                                    if ((i + 1) < orderByConditionFields.length) {
2798                                            if (orderByComparator.isAscending() ^ previous) {
2799                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2800                                            }
2801                                            else {
2802                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2803                                            }
2804                                    }
2805                                    else {
2806                                            if (orderByComparator.isAscending() ^ previous) {
2807                                                    query.append(WHERE_GREATER_THAN);
2808                                            }
2809                                            else {
2810                                                    query.append(WHERE_LESSER_THAN);
2811                                            }
2812                                    }
2813                            }
2814    
2815                            query.append(ORDER_BY_CLAUSE);
2816    
2817                            String[] orderByFields = orderByComparator.getOrderByFields();
2818    
2819                            for (int i = 0; i < orderByFields.length; i++) {
2820                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2821                                    query.append(orderByFields[i]);
2822    
2823                                    if ((i + 1) < orderByFields.length) {
2824                                            if (orderByComparator.isAscending() ^ previous) {
2825                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2826                                            }
2827                                            else {
2828                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2829                                            }
2830                                    }
2831                                    else {
2832                                            if (orderByComparator.isAscending() ^ previous) {
2833                                                    query.append(ORDER_BY_ASC);
2834                                            }
2835                                            else {
2836                                                    query.append(ORDER_BY_DESC);
2837                                            }
2838                                    }
2839                            }
2840                    }
2841                    else {
2842                            query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
2843                    }
2844    
2845                    String sql = query.toString();
2846    
2847                    Query q = session.createQuery(sql);
2848    
2849                    q.setFirstResult(0);
2850                    q.setMaxResults(2);
2851    
2852                    QueryPos qPos = QueryPos.getInstance(q);
2853    
2854                    qPos.add(userId);
2855    
2856                    if (bindLastPostDate) {
2857                            qPos.add(new Timestamp(lastPostDate.getTime()));
2858                    }
2859    
2860                    if (orderByComparator != null) {
2861                            Object[] values = orderByComparator.getOrderByConditionValues(blogsStatsUser);
2862    
2863                            for (Object value : values) {
2864                                    qPos.add(value);
2865                            }
2866                    }
2867    
2868                    List<BlogsStatsUser> list = q.list();
2869    
2870                    if (list.size() == 2) {
2871                            return list.get(1);
2872                    }
2873                    else {
2874                            return null;
2875                    }
2876            }
2877    
2878            /**
2879             * Removes all the blogs stats users where userId = &#63; and lastPostDate = &#63; from the database.
2880             *
2881             * @param userId the user ID
2882             * @param lastPostDate the last post date
2883             */
2884            @Override
2885            public void removeByU_L(long userId, Date lastPostDate) {
2886                    for (BlogsStatsUser blogsStatsUser : findByU_L(userId, lastPostDate,
2887                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2888                            remove(blogsStatsUser);
2889                    }
2890            }
2891    
2892            /**
2893             * Returns the number of blogs stats users where userId = &#63; and lastPostDate = &#63;.
2894             *
2895             * @param userId the user ID
2896             * @param lastPostDate the last post date
2897             * @return the number of matching blogs stats users
2898             */
2899            @Override
2900            public int countByU_L(long userId, Date lastPostDate) {
2901                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_L;
2902    
2903                    Object[] finderArgs = new Object[] { userId, lastPostDate };
2904    
2905                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2906    
2907                    if (count == null) {
2908                            StringBundler query = new StringBundler(3);
2909    
2910                            query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
2911    
2912                            query.append(_FINDER_COLUMN_U_L_USERID_2);
2913    
2914                            boolean bindLastPostDate = false;
2915    
2916                            if (lastPostDate == null) {
2917                                    query.append(_FINDER_COLUMN_U_L_LASTPOSTDATE_1);
2918                            }
2919                            else {
2920                                    bindLastPostDate = true;
2921    
2922                                    query.append(_FINDER_COLUMN_U_L_LASTPOSTDATE_2);
2923                            }
2924    
2925                            String sql = query.toString();
2926    
2927                            Session session = null;
2928    
2929                            try {
2930                                    session = openSession();
2931    
2932                                    Query q = session.createQuery(sql);
2933    
2934                                    QueryPos qPos = QueryPos.getInstance(q);
2935    
2936                                    qPos.add(userId);
2937    
2938                                    if (bindLastPostDate) {
2939                                            qPos.add(new Timestamp(lastPostDate.getTime()));
2940                                    }
2941    
2942                                    count = (Long)q.uniqueResult();
2943    
2944                                    finderCache.putResult(finderPath, finderArgs, count);
2945                            }
2946                            catch (Exception e) {
2947                                    finderCache.removeResult(finderPath, finderArgs);
2948    
2949                                    throw processException(e);
2950                            }
2951                            finally {
2952                                    closeSession(session);
2953                            }
2954                    }
2955    
2956                    return count.intValue();
2957            }
2958    
2959            private static final String _FINDER_COLUMN_U_L_USERID_2 = "blogsStatsUser.userId = ? AND ";
2960            private static final String _FINDER_COLUMN_U_L_LASTPOSTDATE_1 = "blogsStatsUser.lastPostDate IS NULL";
2961            private static final String _FINDER_COLUMN_U_L_LASTPOSTDATE_2 = "blogsStatsUser.lastPostDate = ?";
2962    
2963            public BlogsStatsUserPersistenceImpl() {
2964                    setModelClass(BlogsStatsUser.class);
2965            }
2966    
2967            /**
2968             * Caches the blogs stats user in the entity cache if it is enabled.
2969             *
2970             * @param blogsStatsUser the blogs stats user
2971             */
2972            @Override
2973            public void cacheResult(BlogsStatsUser blogsStatsUser) {
2974                    entityCache.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2975                            BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
2976                            blogsStatsUser);
2977    
2978                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_U,
2979                            new Object[] { blogsStatsUser.getGroupId(), blogsStatsUser.getUserId() },
2980                            blogsStatsUser);
2981    
2982                    blogsStatsUser.resetOriginalValues();
2983            }
2984    
2985            /**
2986             * Caches the blogs stats users in the entity cache if it is enabled.
2987             *
2988             * @param blogsStatsUsers the blogs stats users
2989             */
2990            @Override
2991            public void cacheResult(List<BlogsStatsUser> blogsStatsUsers) {
2992                    for (BlogsStatsUser blogsStatsUser : blogsStatsUsers) {
2993                            if (entityCache.getResult(
2994                                                    BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2995                                                    BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey()) == null) {
2996                                    cacheResult(blogsStatsUser);
2997                            }
2998                            else {
2999                                    blogsStatsUser.resetOriginalValues();
3000                            }
3001                    }
3002            }
3003    
3004            /**
3005             * Clears the cache for all blogs stats users.
3006             *
3007             * <p>
3008             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3009             * </p>
3010             */
3011            @Override
3012            public void clearCache() {
3013                    entityCache.clearCache(BlogsStatsUserImpl.class);
3014    
3015                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
3016                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3017                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3018            }
3019    
3020            /**
3021             * Clears the cache for the blogs stats user.
3022             *
3023             * <p>
3024             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
3025             * </p>
3026             */
3027            @Override
3028            public void clearCache(BlogsStatsUser blogsStatsUser) {
3029                    entityCache.removeResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3030                            BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey());
3031    
3032                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3033                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3034    
3035                    clearUniqueFindersCache((BlogsStatsUserModelImpl)blogsStatsUser);
3036            }
3037    
3038            @Override
3039            public void clearCache(List<BlogsStatsUser> blogsStatsUsers) {
3040                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3041                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3042    
3043                    for (BlogsStatsUser blogsStatsUser : blogsStatsUsers) {
3044                            entityCache.removeResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3045                                    BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey());
3046    
3047                            clearUniqueFindersCache((BlogsStatsUserModelImpl)blogsStatsUser);
3048                    }
3049            }
3050    
3051            protected void cacheUniqueFindersCache(
3052                    BlogsStatsUserModelImpl blogsStatsUserModelImpl, boolean isNew) {
3053                    if (isNew) {
3054                            Object[] args = new Object[] {
3055                                            blogsStatsUserModelImpl.getGroupId(),
3056                                            blogsStatsUserModelImpl.getUserId()
3057                                    };
3058    
3059                            finderCache.putResult(FINDER_PATH_COUNT_BY_G_U, args,
3060                                    Long.valueOf(1));
3061                            finderCache.putResult(FINDER_PATH_FETCH_BY_G_U, args,
3062                                    blogsStatsUserModelImpl);
3063                    }
3064                    else {
3065                            if ((blogsStatsUserModelImpl.getColumnBitmask() &
3066                                            FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
3067                                    Object[] args = new Object[] {
3068                                                    blogsStatsUserModelImpl.getGroupId(),
3069                                                    blogsStatsUserModelImpl.getUserId()
3070                                            };
3071    
3072                                    finderCache.putResult(FINDER_PATH_COUNT_BY_G_U, args,
3073                                            Long.valueOf(1));
3074                                    finderCache.putResult(FINDER_PATH_FETCH_BY_G_U, args,
3075                                            blogsStatsUserModelImpl);
3076                            }
3077                    }
3078            }
3079    
3080            protected void clearUniqueFindersCache(
3081                    BlogsStatsUserModelImpl blogsStatsUserModelImpl) {
3082                    Object[] args = new Object[] {
3083                                    blogsStatsUserModelImpl.getGroupId(),
3084                                    blogsStatsUserModelImpl.getUserId()
3085                            };
3086    
3087                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
3088                    finderCache.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
3089    
3090                    if ((blogsStatsUserModelImpl.getColumnBitmask() &
3091                                    FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
3092                            args = new Object[] {
3093                                            blogsStatsUserModelImpl.getOriginalGroupId(),
3094                                            blogsStatsUserModelImpl.getOriginalUserId()
3095                                    };
3096    
3097                            finderCache.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
3098                            finderCache.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
3099                    }
3100            }
3101    
3102            /**
3103             * Creates a new blogs stats user with the primary key. Does not add the blogs stats user to the database.
3104             *
3105             * @param statsUserId the primary key for the new blogs stats user
3106             * @return the new blogs stats user
3107             */
3108            @Override
3109            public BlogsStatsUser create(long statsUserId) {
3110                    BlogsStatsUser blogsStatsUser = new BlogsStatsUserImpl();
3111    
3112                    blogsStatsUser.setNew(true);
3113                    blogsStatsUser.setPrimaryKey(statsUserId);
3114    
3115                    return blogsStatsUser;
3116            }
3117    
3118            /**
3119             * Removes the blogs stats user with the primary key from the database. Also notifies the appropriate model listeners.
3120             *
3121             * @param statsUserId the primary key of the blogs stats user
3122             * @return the blogs stats user that was removed
3123             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
3124             */
3125            @Override
3126            public BlogsStatsUser remove(long statsUserId)
3127                    throws NoSuchStatsUserException {
3128                    return remove((Serializable)statsUserId);
3129            }
3130    
3131            /**
3132             * Removes the blogs stats user with the primary key from the database. Also notifies the appropriate model listeners.
3133             *
3134             * @param primaryKey the primary key of the blogs stats user
3135             * @return the blogs stats user that was removed
3136             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
3137             */
3138            @Override
3139            public BlogsStatsUser remove(Serializable primaryKey)
3140                    throws NoSuchStatsUserException {
3141                    Session session = null;
3142    
3143                    try {
3144                            session = openSession();
3145    
3146                            BlogsStatsUser blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
3147                                            primaryKey);
3148    
3149                            if (blogsStatsUser == null) {
3150                                    if (_log.isWarnEnabled()) {
3151                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3152                                    }
3153    
3154                                    throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3155                                            primaryKey);
3156                            }
3157    
3158                            return remove(blogsStatsUser);
3159                    }
3160                    catch (NoSuchStatsUserException nsee) {
3161                            throw nsee;
3162                    }
3163                    catch (Exception e) {
3164                            throw processException(e);
3165                    }
3166                    finally {
3167                            closeSession(session);
3168                    }
3169            }
3170    
3171            @Override
3172            protected BlogsStatsUser removeImpl(BlogsStatsUser blogsStatsUser) {
3173                    blogsStatsUser = toUnwrappedModel(blogsStatsUser);
3174    
3175                    Session session = null;
3176    
3177                    try {
3178                            session = openSession();
3179    
3180                            if (!session.contains(blogsStatsUser)) {
3181                                    blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
3182                                                    blogsStatsUser.getPrimaryKeyObj());
3183                            }
3184    
3185                            if (blogsStatsUser != null) {
3186                                    session.delete(blogsStatsUser);
3187                            }
3188                    }
3189                    catch (Exception e) {
3190                            throw processException(e);
3191                    }
3192                    finally {
3193                            closeSession(session);
3194                    }
3195    
3196                    if (blogsStatsUser != null) {
3197                            clearCache(blogsStatsUser);
3198                    }
3199    
3200                    return blogsStatsUser;
3201            }
3202    
3203            @Override
3204            public BlogsStatsUser updateImpl(BlogsStatsUser blogsStatsUser) {
3205                    blogsStatsUser = toUnwrappedModel(blogsStatsUser);
3206    
3207                    boolean isNew = blogsStatsUser.isNew();
3208    
3209                    BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
3210    
3211                    Session session = null;
3212    
3213                    try {
3214                            session = openSession();
3215    
3216                            if (blogsStatsUser.isNew()) {
3217                                    session.save(blogsStatsUser);
3218    
3219                                    blogsStatsUser.setNew(false);
3220                            }
3221                            else {
3222                                    blogsStatsUser = (BlogsStatsUser)session.merge(blogsStatsUser);
3223                            }
3224                    }
3225                    catch (Exception e) {
3226                            throw processException(e);
3227                    }
3228                    finally {
3229                            closeSession(session);
3230                    }
3231    
3232                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3233    
3234                    if (isNew || !BlogsStatsUserModelImpl.COLUMN_BITMASK_ENABLED) {
3235                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3236                    }
3237    
3238                    else {
3239                            if ((blogsStatsUserModelImpl.getColumnBitmask() &
3240                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3241                                    Object[] args = new Object[] {
3242                                                    blogsStatsUserModelImpl.getOriginalGroupId()
3243                                            };
3244    
3245                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3246                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3247                                            args);
3248    
3249                                    args = new Object[] { blogsStatsUserModelImpl.getGroupId() };
3250    
3251                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3252                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3253                                            args);
3254                            }
3255    
3256                            if ((blogsStatsUserModelImpl.getColumnBitmask() &
3257                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
3258                                    Object[] args = new Object[] {
3259                                                    blogsStatsUserModelImpl.getOriginalUserId()
3260                                            };
3261    
3262                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3263                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3264                                            args);
3265    
3266                                    args = new Object[] { blogsStatsUserModelImpl.getUserId() };
3267    
3268                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3269                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3270                                            args);
3271                            }
3272    
3273                            if ((blogsStatsUserModelImpl.getColumnBitmask() &
3274                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_L.getColumnBitmask()) != 0) {
3275                                    Object[] args = new Object[] {
3276                                                    blogsStatsUserModelImpl.getOriginalUserId(),
3277                                                    blogsStatsUserModelImpl.getOriginalLastPostDate()
3278                                            };
3279    
3280                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L, args);
3281                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_L,
3282                                            args);
3283    
3284                                    args = new Object[] {
3285                                                    blogsStatsUserModelImpl.getUserId(),
3286                                                    blogsStatsUserModelImpl.getLastPostDate()
3287                                            };
3288    
3289                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_U_L, args);
3290                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_L,
3291                                            args);
3292                            }
3293                    }
3294    
3295                    entityCache.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3296                            BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
3297                            blogsStatsUser, false);
3298    
3299                    clearUniqueFindersCache(blogsStatsUserModelImpl);
3300                    cacheUniqueFindersCache(blogsStatsUserModelImpl, isNew);
3301    
3302                    blogsStatsUser.resetOriginalValues();
3303    
3304                    return blogsStatsUser;
3305            }
3306    
3307            protected BlogsStatsUser toUnwrappedModel(BlogsStatsUser blogsStatsUser) {
3308                    if (blogsStatsUser instanceof BlogsStatsUserImpl) {
3309                            return blogsStatsUser;
3310                    }
3311    
3312                    BlogsStatsUserImpl blogsStatsUserImpl = new BlogsStatsUserImpl();
3313    
3314                    blogsStatsUserImpl.setNew(blogsStatsUser.isNew());
3315                    blogsStatsUserImpl.setPrimaryKey(blogsStatsUser.getPrimaryKey());
3316    
3317                    blogsStatsUserImpl.setStatsUserId(blogsStatsUser.getStatsUserId());
3318                    blogsStatsUserImpl.setGroupId(blogsStatsUser.getGroupId());
3319                    blogsStatsUserImpl.setCompanyId(blogsStatsUser.getCompanyId());
3320                    blogsStatsUserImpl.setUserId(blogsStatsUser.getUserId());
3321                    blogsStatsUserImpl.setEntryCount(blogsStatsUser.getEntryCount());
3322                    blogsStatsUserImpl.setLastPostDate(blogsStatsUser.getLastPostDate());
3323                    blogsStatsUserImpl.setRatingsTotalEntries(blogsStatsUser.getRatingsTotalEntries());
3324                    blogsStatsUserImpl.setRatingsTotalScore(blogsStatsUser.getRatingsTotalScore());
3325                    blogsStatsUserImpl.setRatingsAverageScore(blogsStatsUser.getRatingsAverageScore());
3326    
3327                    return blogsStatsUserImpl;
3328            }
3329    
3330            /**
3331             * Returns the blogs stats user with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3332             *
3333             * @param primaryKey the primary key of the blogs stats user
3334             * @return the blogs stats user
3335             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
3336             */
3337            @Override
3338            public BlogsStatsUser findByPrimaryKey(Serializable primaryKey)
3339                    throws NoSuchStatsUserException {
3340                    BlogsStatsUser blogsStatsUser = fetchByPrimaryKey(primaryKey);
3341    
3342                    if (blogsStatsUser == null) {
3343                            if (_log.isWarnEnabled()) {
3344                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3345                            }
3346    
3347                            throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3348                                    primaryKey);
3349                    }
3350    
3351                    return blogsStatsUser;
3352            }
3353    
3354            /**
3355             * Returns the blogs stats user with the primary key or throws a {@link NoSuchStatsUserException} if it could not be found.
3356             *
3357             * @param statsUserId the primary key of the blogs stats user
3358             * @return the blogs stats user
3359             * @throws NoSuchStatsUserException if a blogs stats user with the primary key could not be found
3360             */
3361            @Override
3362            public BlogsStatsUser findByPrimaryKey(long statsUserId)
3363                    throws NoSuchStatsUserException {
3364                    return findByPrimaryKey((Serializable)statsUserId);
3365            }
3366    
3367            /**
3368             * Returns the blogs stats user with the primary key or returns <code>null</code> if it could not be found.
3369             *
3370             * @param primaryKey the primary key of the blogs stats user
3371             * @return the blogs stats user, or <code>null</code> if a blogs stats user with the primary key could not be found
3372             */
3373            @Override
3374            public BlogsStatsUser fetchByPrimaryKey(Serializable primaryKey) {
3375                    BlogsStatsUser blogsStatsUser = (BlogsStatsUser)entityCache.getResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3376                                    BlogsStatsUserImpl.class, primaryKey);
3377    
3378                    if (blogsStatsUser == _nullBlogsStatsUser) {
3379                            return null;
3380                    }
3381    
3382                    if (blogsStatsUser == null) {
3383                            Session session = null;
3384    
3385                            try {
3386                                    session = openSession();
3387    
3388                                    blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
3389                                                    primaryKey);
3390    
3391                                    if (blogsStatsUser != null) {
3392                                            cacheResult(blogsStatsUser);
3393                                    }
3394                                    else {
3395                                            entityCache.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3396                                                    BlogsStatsUserImpl.class, primaryKey,
3397                                                    _nullBlogsStatsUser);
3398                                    }
3399                            }
3400                            catch (Exception e) {
3401                                    entityCache.removeResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3402                                            BlogsStatsUserImpl.class, primaryKey);
3403    
3404                                    throw processException(e);
3405                            }
3406                            finally {
3407                                    closeSession(session);
3408                            }
3409                    }
3410    
3411                    return blogsStatsUser;
3412            }
3413    
3414            /**
3415             * Returns the blogs stats user with the primary key or returns <code>null</code> if it could not be found.
3416             *
3417             * @param statsUserId the primary key of the blogs stats user
3418             * @return the blogs stats user, or <code>null</code> if a blogs stats user with the primary key could not be found
3419             */
3420            @Override
3421            public BlogsStatsUser fetchByPrimaryKey(long statsUserId) {
3422                    return fetchByPrimaryKey((Serializable)statsUserId);
3423            }
3424    
3425            @Override
3426            public Map<Serializable, BlogsStatsUser> fetchByPrimaryKeys(
3427                    Set<Serializable> primaryKeys) {
3428                    if (primaryKeys.isEmpty()) {
3429                            return Collections.emptyMap();
3430                    }
3431    
3432                    Map<Serializable, BlogsStatsUser> map = new HashMap<Serializable, BlogsStatsUser>();
3433    
3434                    if (primaryKeys.size() == 1) {
3435                            Iterator<Serializable> iterator = primaryKeys.iterator();
3436    
3437                            Serializable primaryKey = iterator.next();
3438    
3439                            BlogsStatsUser blogsStatsUser = fetchByPrimaryKey(primaryKey);
3440    
3441                            if (blogsStatsUser != null) {
3442                                    map.put(primaryKey, blogsStatsUser);
3443                            }
3444    
3445                            return map;
3446                    }
3447    
3448                    Set<Serializable> uncachedPrimaryKeys = null;
3449    
3450                    for (Serializable primaryKey : primaryKeys) {
3451                            BlogsStatsUser blogsStatsUser = (BlogsStatsUser)entityCache.getResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3452                                            BlogsStatsUserImpl.class, primaryKey);
3453    
3454                            if (blogsStatsUser == null) {
3455                                    if (uncachedPrimaryKeys == null) {
3456                                            uncachedPrimaryKeys = new HashSet<Serializable>();
3457                                    }
3458    
3459                                    uncachedPrimaryKeys.add(primaryKey);
3460                            }
3461                            else {
3462                                    map.put(primaryKey, blogsStatsUser);
3463                            }
3464                    }
3465    
3466                    if (uncachedPrimaryKeys == null) {
3467                            return map;
3468                    }
3469    
3470                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
3471                                    1);
3472    
3473                    query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE_PKS_IN);
3474    
3475                    for (Serializable primaryKey : uncachedPrimaryKeys) {
3476                            query.append(String.valueOf(primaryKey));
3477    
3478                            query.append(StringPool.COMMA);
3479                    }
3480    
3481                    query.setIndex(query.index() - 1);
3482    
3483                    query.append(StringPool.CLOSE_PARENTHESIS);
3484    
3485                    String sql = query.toString();
3486    
3487                    Session session = null;
3488    
3489                    try {
3490                            session = openSession();
3491    
3492                            Query q = session.createQuery(sql);
3493    
3494                            for (BlogsStatsUser blogsStatsUser : (List<BlogsStatsUser>)q.list()) {
3495                                    map.put(blogsStatsUser.getPrimaryKeyObj(), blogsStatsUser);
3496    
3497                                    cacheResult(blogsStatsUser);
3498    
3499                                    uncachedPrimaryKeys.remove(blogsStatsUser.getPrimaryKeyObj());
3500                            }
3501    
3502                            for (Serializable primaryKey : uncachedPrimaryKeys) {
3503                                    entityCache.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
3504                                            BlogsStatsUserImpl.class, primaryKey, _nullBlogsStatsUser);
3505                            }
3506                    }
3507                    catch (Exception e) {
3508                            throw processException(e);
3509                    }
3510                    finally {
3511                            closeSession(session);
3512                    }
3513    
3514                    return map;
3515            }
3516    
3517            /**
3518             * Returns all the blogs stats users.
3519             *
3520             * @return the blogs stats users
3521             */
3522            @Override
3523            public List<BlogsStatsUser> findAll() {
3524                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3525            }
3526    
3527            /**
3528             * Returns a range of all the blogs stats users.
3529             *
3530             * <p>
3531             * 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 BlogsStatsUserModelImpl}. 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.
3532             * </p>
3533             *
3534             * @param start the lower bound of the range of blogs stats users
3535             * @param end the upper bound of the range of blogs stats users (not inclusive)
3536             * @return the range of blogs stats users
3537             */
3538            @Override
3539            public List<BlogsStatsUser> findAll(int start, int end) {
3540                    return findAll(start, end, null);
3541            }
3542    
3543            /**
3544             * Returns an ordered range of all the blogs stats users.
3545             *
3546             * <p>
3547             * 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 BlogsStatsUserModelImpl}. 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.
3548             * </p>
3549             *
3550             * @param start the lower bound of the range of blogs stats users
3551             * @param end the upper bound of the range of blogs stats users (not inclusive)
3552             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3553             * @return the ordered range of blogs stats users
3554             */
3555            @Override
3556            public List<BlogsStatsUser> findAll(int start, int end,
3557                    OrderByComparator<BlogsStatsUser> orderByComparator) {
3558                    return findAll(start, end, orderByComparator, true);
3559            }
3560    
3561            /**
3562             * Returns an ordered range of all the blogs stats users.
3563             *
3564             * <p>
3565             * 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 BlogsStatsUserModelImpl}. 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.
3566             * </p>
3567             *
3568             * @param start the lower bound of the range of blogs stats users
3569             * @param end the upper bound of the range of blogs stats users (not inclusive)
3570             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3571             * @param retrieveFromCache whether to retrieve from the finder cache
3572             * @return the ordered range of blogs stats users
3573             */
3574            @Override
3575            public List<BlogsStatsUser> findAll(int start, int end,
3576                    OrderByComparator<BlogsStatsUser> orderByComparator,
3577                    boolean retrieveFromCache) {
3578                    boolean pagination = true;
3579                    FinderPath finderPath = null;
3580                    Object[] finderArgs = null;
3581    
3582                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3583                                    (orderByComparator == null)) {
3584                            pagination = false;
3585                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3586                            finderArgs = FINDER_ARGS_EMPTY;
3587                    }
3588                    else {
3589                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3590                            finderArgs = new Object[] { start, end, orderByComparator };
3591                    }
3592    
3593                    List<BlogsStatsUser> list = null;
3594    
3595                    if (retrieveFromCache) {
3596                            list = (List<BlogsStatsUser>)finderCache.getResult(finderPath,
3597                                            finderArgs, this);
3598                    }
3599    
3600                    if (list == null) {
3601                            StringBundler query = null;
3602                            String sql = null;
3603    
3604                            if (orderByComparator != null) {
3605                                    query = new StringBundler(2 +
3606                                                    (orderByComparator.getOrderByFields().length * 3));
3607    
3608                                    query.append(_SQL_SELECT_BLOGSSTATSUSER);
3609    
3610                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3611                                            orderByComparator);
3612    
3613                                    sql = query.toString();
3614                            }
3615                            else {
3616                                    sql = _SQL_SELECT_BLOGSSTATSUSER;
3617    
3618                                    if (pagination) {
3619                                            sql = sql.concat(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
3620                                    }
3621                            }
3622    
3623                            Session session = null;
3624    
3625                            try {
3626                                    session = openSession();
3627    
3628                                    Query q = session.createQuery(sql);
3629    
3630                                    if (!pagination) {
3631                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
3632                                                            getDialect(), start, end, false);
3633    
3634                                            Collections.sort(list);
3635    
3636                                            list = Collections.unmodifiableList(list);
3637                                    }
3638                                    else {
3639                                            list = (List<BlogsStatsUser>)QueryUtil.list(q,
3640                                                            getDialect(), start, end);
3641                                    }
3642    
3643                                    cacheResult(list);
3644    
3645                                    finderCache.putResult(finderPath, finderArgs, list);
3646                            }
3647                            catch (Exception e) {
3648                                    finderCache.removeResult(finderPath, finderArgs);
3649    
3650                                    throw processException(e);
3651                            }
3652                            finally {
3653                                    closeSession(session);
3654                            }
3655                    }
3656    
3657                    return list;
3658            }
3659    
3660            /**
3661             * Removes all the blogs stats users from the database.
3662             *
3663             */
3664            @Override
3665            public void removeAll() {
3666                    for (BlogsStatsUser blogsStatsUser : findAll()) {
3667                            remove(blogsStatsUser);
3668                    }
3669            }
3670    
3671            /**
3672             * Returns the number of blogs stats users.
3673             *
3674             * @return the number of blogs stats users
3675             */
3676            @Override
3677            public int countAll() {
3678                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3679                                    FINDER_ARGS_EMPTY, this);
3680    
3681                    if (count == null) {
3682                            Session session = null;
3683    
3684                            try {
3685                                    session = openSession();
3686    
3687                                    Query q = session.createQuery(_SQL_COUNT_BLOGSSTATSUSER);
3688    
3689                                    count = (Long)q.uniqueResult();
3690    
3691                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3692                                            count);
3693                            }
3694                            catch (Exception e) {
3695                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3696                                            FINDER_ARGS_EMPTY);
3697    
3698                                    throw processException(e);
3699                            }
3700                            finally {
3701                                    closeSession(session);
3702                            }
3703                    }
3704    
3705                    return count.intValue();
3706            }
3707    
3708            @Override
3709            protected Map<String, Integer> getTableColumnsMap() {
3710                    return BlogsStatsUserModelImpl.TABLE_COLUMNS_MAP;
3711            }
3712    
3713            /**
3714             * Initializes the blogs stats user persistence.
3715             */
3716            public void afterPropertiesSet() {
3717            }
3718    
3719            public void destroy() {
3720                    entityCache.removeCache(BlogsStatsUserImpl.class.getName());
3721                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3722                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3723                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3724            }
3725    
3726            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3727            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3728            private static final String _SQL_SELECT_BLOGSSTATSUSER = "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser";
3729            private static final String _SQL_SELECT_BLOGSSTATSUSER_WHERE_PKS_IN = "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE statsUserId IN (";
3730            private static final String _SQL_SELECT_BLOGSSTATSUSER_WHERE = "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ";
3731            private static final String _SQL_COUNT_BLOGSSTATSUSER = "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser";
3732            private static final String _SQL_COUNT_BLOGSSTATSUSER_WHERE = "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser WHERE ";
3733            private static final String _ORDER_BY_ENTITY_ALIAS = "blogsStatsUser.";
3734            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BlogsStatsUser exists with the primary key ";
3735            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BlogsStatsUser exists with the key {";
3736            private static final Log _log = LogFactoryUtil.getLog(BlogsStatsUserPersistenceImpl.class);
3737            private static final BlogsStatsUser _nullBlogsStatsUser = new BlogsStatsUserImpl() {
3738                            @Override
3739                            public Object clone() {
3740                                    return this;
3741                            }
3742    
3743                            @Override
3744                            public CacheModel<BlogsStatsUser> toCacheModel() {
3745                                    return _nullBlogsStatsUserCacheModel;
3746                            }
3747                    };
3748    
3749            private static final CacheModel<BlogsStatsUser> _nullBlogsStatsUserCacheModel =
3750                    new CacheModel<BlogsStatsUser>() {
3751                            @Override
3752                            public BlogsStatsUser toEntityModel() {
3753                                    return _nullBlogsStatsUser;
3754                            }
3755                    };
3756    }