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