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