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