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