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