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