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