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