1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portlet.blogs.service.persistence;
16  
17  import com.liferay.portal.NoSuchModelException;
18  import com.liferay.portal.kernel.annotation.BeanReference;
19  import com.liferay.portal.kernel.cache.CacheRegistry;
20  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
21  import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23  import com.liferay.portal.kernel.dao.orm.FinderPath;
24  import com.liferay.portal.kernel.dao.orm.Query;
25  import com.liferay.portal.kernel.dao.orm.QueryPos;
26  import com.liferay.portal.kernel.dao.orm.QueryUtil;
27  import com.liferay.portal.kernel.dao.orm.Session;
28  import com.liferay.portal.kernel.exception.SystemException;
29  import com.liferay.portal.kernel.log.Log;
30  import com.liferay.portal.kernel.log.LogFactoryUtil;
31  import com.liferay.portal.kernel.util.GetterUtil;
32  import com.liferay.portal.kernel.util.OrderByComparator;
33  import com.liferay.portal.kernel.util.StringBundler;
34  import com.liferay.portal.kernel.util.StringPool;
35  import com.liferay.portal.kernel.util.StringUtil;
36  import com.liferay.portal.model.ModelListener;
37  import com.liferay.portal.service.persistence.BatchSessionUtil;
38  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
39  
40  import com.liferay.portlet.blogs.NoSuchStatsUserException;
41  import com.liferay.portlet.blogs.model.BlogsStatsUser;
42  import com.liferay.portlet.blogs.model.impl.BlogsStatsUserImpl;
43  import com.liferay.portlet.blogs.model.impl.BlogsStatsUserModelImpl;
44  
45  import java.io.Serializable;
46  
47  import java.util.ArrayList;
48  import java.util.Collections;
49  import java.util.List;
50  
51  /**
52   * <a href="BlogsStatsUserPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * <p>
55   * ServiceBuilder generated this class. Modifications in this class will be
56   * overwritten the next time is generated.
57   * </p>
58   *
59   * @author    Brian Wing Shun Chan
60   * @see       BlogsStatsUserPersistence
61   * @see       BlogsStatsUserUtil
62   * @generated
63   */
64  public class BlogsStatsUserPersistenceImpl extends BasePersistenceImpl<BlogsStatsUser>
65      implements BlogsStatsUserPersistence {
66      public static final String FINDER_CLASS_NAME_ENTITY = BlogsStatsUserImpl.class.getName();
67      public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
68          ".List";
69      public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
70              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
71              FINDER_CLASS_NAME_LIST, "findByGroupId",
72              new String[] { Long.class.getName() });
73      public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
74              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
75              FINDER_CLASS_NAME_LIST, "findByGroupId",
76              new String[] {
77                  Long.class.getName(),
78                  
79              "java.lang.Integer", "java.lang.Integer",
80                  "com.liferay.portal.kernel.util.OrderByComparator"
81              });
82      public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
83              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
84              FINDER_CLASS_NAME_LIST, "countByGroupId",
85              new String[] { Long.class.getName() });
86      public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
87              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
88              FINDER_CLASS_NAME_LIST, "findByUserId",
89              new String[] { Long.class.getName() });
90      public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
91              BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
92              FINDER_CLASS_NAME_LIST, "findByUserId",
93              new String[] {
94                  Long.class.getName(),
95                  
96              "java.lang.Integer", "java.lang.Integer",
97                  "com.liferay.portal.kernel.util.OrderByComparator"
98              });
99      public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
100             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
101             FINDER_CLASS_NAME_LIST, "countByUserId",
102             new String[] { Long.class.getName() });
103     public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
104             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
105             FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
106             new String[] { Long.class.getName(), Long.class.getName() });
107     public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
108             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
109             FINDER_CLASS_NAME_LIST, "countByG_U",
110             new String[] { Long.class.getName(), Long.class.getName() });
111     public static final FinderPath FINDER_PATH_FIND_BY_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
112             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
113             FINDER_CLASS_NAME_LIST, "findByG_E",
114             new String[] { Long.class.getName(), Integer.class.getName() });
115     public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
116             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
117             FINDER_CLASS_NAME_LIST, "findByG_E",
118             new String[] {
119                 Long.class.getName(), Integer.class.getName(),
120                 
121             "java.lang.Integer", "java.lang.Integer",
122                 "com.liferay.portal.kernel.util.OrderByComparator"
123             });
124     public static final FinderPath FINDER_PATH_COUNT_BY_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
125             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
126             FINDER_CLASS_NAME_LIST, "countByG_E",
127             new String[] { Long.class.getName(), Integer.class.getName() });
128     public static final FinderPath FINDER_PATH_FIND_BY_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
129             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
130             FINDER_CLASS_NAME_LIST, "findByC_E",
131             new String[] { Long.class.getName(), Integer.class.getName() });
132     public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
133             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
134             FINDER_CLASS_NAME_LIST, "findByC_E",
135             new String[] {
136                 Long.class.getName(), Integer.class.getName(),
137                 
138             "java.lang.Integer", "java.lang.Integer",
139                 "com.liferay.portal.kernel.util.OrderByComparator"
140             });
141     public static final FinderPath FINDER_PATH_COUNT_BY_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
142             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
143             FINDER_CLASS_NAME_LIST, "countByC_E",
144             new String[] { Long.class.getName(), Integer.class.getName() });
145     public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
146             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
147             FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
148     public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
149             BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
150             FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
151 
152     public void cacheResult(BlogsStatsUser blogsStatsUser) {
153         EntityCacheUtil.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
154             BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
155             blogsStatsUser);
156 
157         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
158             new Object[] {
159                 new Long(blogsStatsUser.getGroupId()),
160                 new Long(blogsStatsUser.getUserId())
161             }, blogsStatsUser);
162     }
163 
164     public void cacheResult(List<BlogsStatsUser> blogsStatsUsers) {
165         for (BlogsStatsUser blogsStatsUser : blogsStatsUsers) {
166             if (EntityCacheUtil.getResult(
167                         BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
168                         BlogsStatsUserImpl.class,
169                         blogsStatsUser.getPrimaryKey(), this) == null) {
170                 cacheResult(blogsStatsUser);
171             }
172         }
173     }
174 
175     public void clearCache() {
176         CacheRegistry.clear(BlogsStatsUserImpl.class.getName());
177         EntityCacheUtil.clearCache(BlogsStatsUserImpl.class.getName());
178         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
179         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
180     }
181 
182     public BlogsStatsUser create(long statsUserId) {
183         BlogsStatsUser blogsStatsUser = new BlogsStatsUserImpl();
184 
185         blogsStatsUser.setNew(true);
186         blogsStatsUser.setPrimaryKey(statsUserId);
187 
188         return blogsStatsUser;
189     }
190 
191     public BlogsStatsUser remove(Serializable primaryKey)
192         throws NoSuchModelException, SystemException {
193         return remove(((Long)primaryKey).longValue());
194     }
195 
196     public BlogsStatsUser remove(long statsUserId)
197         throws NoSuchStatsUserException, SystemException {
198         Session session = null;
199 
200         try {
201             session = openSession();
202 
203             BlogsStatsUser blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
204                     new Long(statsUserId));
205 
206             if (blogsStatsUser == null) {
207                 if (_log.isWarnEnabled()) {
208                     _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
209                 }
210 
211                 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
212                     statsUserId);
213             }
214 
215             return remove(blogsStatsUser);
216         }
217         catch (NoSuchStatsUserException nsee) {
218             throw nsee;
219         }
220         catch (Exception e) {
221             throw processException(e);
222         }
223         finally {
224             closeSession(session);
225         }
226     }
227 
228     public BlogsStatsUser remove(BlogsStatsUser blogsStatsUser)
229         throws SystemException {
230         for (ModelListener<BlogsStatsUser> listener : listeners) {
231             listener.onBeforeRemove(blogsStatsUser);
232         }
233 
234         blogsStatsUser = removeImpl(blogsStatsUser);
235 
236         for (ModelListener<BlogsStatsUser> listener : listeners) {
237             listener.onAfterRemove(blogsStatsUser);
238         }
239 
240         return blogsStatsUser;
241     }
242 
243     protected BlogsStatsUser removeImpl(BlogsStatsUser blogsStatsUser)
244         throws SystemException {
245         blogsStatsUser = toUnwrappedModel(blogsStatsUser);
246 
247         Session session = null;
248 
249         try {
250             session = openSession();
251 
252             if (blogsStatsUser.isCachedModel() || BatchSessionUtil.isEnabled()) {
253                 Object staleObject = session.get(BlogsStatsUserImpl.class,
254                         blogsStatsUser.getPrimaryKeyObj());
255 
256                 if (staleObject != null) {
257                     session.evict(staleObject);
258                 }
259             }
260 
261             session.delete(blogsStatsUser);
262 
263             session.flush();
264         }
265         catch (Exception e) {
266             throw processException(e);
267         }
268         finally {
269             closeSession(session);
270         }
271 
272         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273 
274         BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
275 
276         FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
277             new Object[] {
278                 new Long(blogsStatsUserModelImpl.getOriginalGroupId()),
279                 new Long(blogsStatsUserModelImpl.getOriginalUserId())
280             });
281 
282         EntityCacheUtil.removeResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
283             BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey());
284 
285         return blogsStatsUser;
286     }
287 
288     public BlogsStatsUser updateImpl(
289         com.liferay.portlet.blogs.model.BlogsStatsUser blogsStatsUser,
290         boolean merge) throws SystemException {
291         blogsStatsUser = toUnwrappedModel(blogsStatsUser);
292 
293         boolean isNew = blogsStatsUser.isNew();
294 
295         BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
296 
297         Session session = null;
298 
299         try {
300             session = openSession();
301 
302             BatchSessionUtil.update(session, blogsStatsUser, merge);
303 
304             blogsStatsUser.setNew(false);
305         }
306         catch (Exception e) {
307             throw processException(e);
308         }
309         finally {
310             closeSession(session);
311         }
312 
313         FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
314 
315         EntityCacheUtil.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
316             BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
317             blogsStatsUser);
318 
319         if (!isNew &&
320                 ((blogsStatsUser.getGroupId() != blogsStatsUserModelImpl.getOriginalGroupId()) ||
321                 (blogsStatsUser.getUserId() != blogsStatsUserModelImpl.getOriginalUserId()))) {
322             FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
323                 new Object[] {
324                     new Long(blogsStatsUserModelImpl.getOriginalGroupId()),
325                     new Long(blogsStatsUserModelImpl.getOriginalUserId())
326                 });
327         }
328 
329         if (isNew ||
330                 ((blogsStatsUser.getGroupId() != blogsStatsUserModelImpl.getOriginalGroupId()) ||
331                 (blogsStatsUser.getUserId() != blogsStatsUserModelImpl.getOriginalUserId()))) {
332             FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
333                 new Object[] {
334                     new Long(blogsStatsUser.getGroupId()),
335                     new Long(blogsStatsUser.getUserId())
336                 }, blogsStatsUser);
337         }
338 
339         return blogsStatsUser;
340     }
341 
342     protected BlogsStatsUser toUnwrappedModel(BlogsStatsUser blogsStatsUser) {
343         if (blogsStatsUser instanceof BlogsStatsUserImpl) {
344             return blogsStatsUser;
345         }
346 
347         BlogsStatsUserImpl blogsStatsUserImpl = new BlogsStatsUserImpl();
348 
349         blogsStatsUserImpl.setNew(blogsStatsUser.isNew());
350         blogsStatsUserImpl.setPrimaryKey(blogsStatsUser.getPrimaryKey());
351 
352         blogsStatsUserImpl.setStatsUserId(blogsStatsUser.getStatsUserId());
353         blogsStatsUserImpl.setGroupId(blogsStatsUser.getGroupId());
354         blogsStatsUserImpl.setCompanyId(blogsStatsUser.getCompanyId());
355         blogsStatsUserImpl.setUserId(blogsStatsUser.getUserId());
356         blogsStatsUserImpl.setEntryCount(blogsStatsUser.getEntryCount());
357         blogsStatsUserImpl.setLastPostDate(blogsStatsUser.getLastPostDate());
358         blogsStatsUserImpl.setRatingsTotalEntries(blogsStatsUser.getRatingsTotalEntries());
359         blogsStatsUserImpl.setRatingsTotalScore(blogsStatsUser.getRatingsTotalScore());
360         blogsStatsUserImpl.setRatingsAverageScore(blogsStatsUser.getRatingsAverageScore());
361 
362         return blogsStatsUserImpl;
363     }
364 
365     public BlogsStatsUser findByPrimaryKey(Serializable primaryKey)
366         throws NoSuchModelException, SystemException {
367         return findByPrimaryKey(((Long)primaryKey).longValue());
368     }
369 
370     public BlogsStatsUser findByPrimaryKey(long statsUserId)
371         throws NoSuchStatsUserException, SystemException {
372         BlogsStatsUser blogsStatsUser = fetchByPrimaryKey(statsUserId);
373 
374         if (blogsStatsUser == null) {
375             if (_log.isWarnEnabled()) {
376                 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
377             }
378 
379             throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
380                 statsUserId);
381         }
382 
383         return blogsStatsUser;
384     }
385 
386     public BlogsStatsUser fetchByPrimaryKey(Serializable primaryKey)
387         throws SystemException {
388         return fetchByPrimaryKey(((Long)primaryKey).longValue());
389     }
390 
391     public BlogsStatsUser fetchByPrimaryKey(long statsUserId)
392         throws SystemException {
393         BlogsStatsUser blogsStatsUser = (BlogsStatsUser)EntityCacheUtil.getResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
394                 BlogsStatsUserImpl.class, statsUserId, this);
395 
396         if (blogsStatsUser == null) {
397             Session session = null;
398 
399             try {
400                 session = openSession();
401 
402                 blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
403                         new Long(statsUserId));
404             }
405             catch (Exception e) {
406                 throw processException(e);
407             }
408             finally {
409                 if (blogsStatsUser != null) {
410                     cacheResult(blogsStatsUser);
411                 }
412 
413                 closeSession(session);
414             }
415         }
416 
417         return blogsStatsUser;
418     }
419 
420     public List<BlogsStatsUser> findByGroupId(long groupId)
421         throws SystemException {
422         Object[] finderArgs = new Object[] { new Long(groupId) };
423 
424         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
425                 finderArgs, this);
426 
427         if (list == null) {
428             Session session = null;
429 
430             try {
431                 session = openSession();
432 
433                 StringBundler query = new StringBundler(3);
434 
435                 query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
436 
437                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
438 
439                 query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
440 
441                 String sql = query.toString();
442 
443                 Query q = session.createQuery(sql);
444 
445                 QueryPos qPos = QueryPos.getInstance(q);
446 
447                 qPos.add(groupId);
448 
449                 list = q.list();
450             }
451             catch (Exception e) {
452                 throw processException(e);
453             }
454             finally {
455                 if (list == null) {
456                     list = new ArrayList<BlogsStatsUser>();
457                 }
458 
459                 cacheResult(list);
460 
461                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
462                     finderArgs, list);
463 
464                 closeSession(session);
465             }
466         }
467 
468         return list;
469     }
470 
471     public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end)
472         throws SystemException {
473         return findByGroupId(groupId, start, end, null);
474     }
475 
476     public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end,
477         OrderByComparator obc) throws SystemException {
478         Object[] finderArgs = new Object[] {
479                 new Long(groupId),
480                 
481                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
482             };
483 
484         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
485                 finderArgs, this);
486 
487         if (list == null) {
488             Session session = null;
489 
490             try {
491                 session = openSession();
492 
493                 StringBundler query = null;
494 
495                 if (obc != null) {
496                     query = new StringBundler(3 +
497                             (obc.getOrderByFields().length * 3));
498                 }
499                 else {
500                     query = new StringBundler(3);
501                 }
502 
503                 query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
504 
505                 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
506 
507                 if (obc != null) {
508                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
509                 }
510 
511                 else {
512                     query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
513                 }
514 
515                 String sql = query.toString();
516 
517                 Query q = session.createQuery(sql);
518 
519                 QueryPos qPos = QueryPos.getInstance(q);
520 
521                 qPos.add(groupId);
522 
523                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
524                         start, end);
525             }
526             catch (Exception e) {
527                 throw processException(e);
528             }
529             finally {
530                 if (list == null) {
531                     list = new ArrayList<BlogsStatsUser>();
532                 }
533 
534                 cacheResult(list);
535 
536                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
537                     finderArgs, list);
538 
539                 closeSession(session);
540             }
541         }
542 
543         return list;
544     }
545 
546     public BlogsStatsUser findByGroupId_First(long groupId,
547         OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
548         List<BlogsStatsUser> list = findByGroupId(groupId, 0, 1, obc);
549 
550         if (list.isEmpty()) {
551             StringBundler msg = new StringBundler(4);
552 
553             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
554 
555             msg.append("groupId=");
556             msg.append(groupId);
557 
558             msg.append(StringPool.CLOSE_CURLY_BRACE);
559 
560             throw new NoSuchStatsUserException(msg.toString());
561         }
562         else {
563             return list.get(0);
564         }
565     }
566 
567     public BlogsStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
568         throws NoSuchStatsUserException, SystemException {
569         int count = countByGroupId(groupId);
570 
571         List<BlogsStatsUser> list = findByGroupId(groupId, count - 1, count, obc);
572 
573         if (list.isEmpty()) {
574             StringBundler msg = new StringBundler(4);
575 
576             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
577 
578             msg.append("groupId=");
579             msg.append(groupId);
580 
581             msg.append(StringPool.CLOSE_CURLY_BRACE);
582 
583             throw new NoSuchStatsUserException(msg.toString());
584         }
585         else {
586             return list.get(0);
587         }
588     }
589 
590     public BlogsStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
591         long groupId, OrderByComparator obc)
592         throws NoSuchStatsUserException, SystemException {
593         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
594 
595         int count = countByGroupId(groupId);
596 
597         Session session = null;
598 
599         try {
600             session = openSession();
601 
602             StringBundler query = null;
603 
604             if (obc != null) {
605                 query = new StringBundler(3 +
606                         (obc.getOrderByFields().length * 3));
607             }
608             else {
609                 query = new StringBundler(3);
610             }
611 
612             query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
613 
614             query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
615 
616             if (obc != null) {
617                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
618             }
619 
620             else {
621                 query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
622             }
623 
624             String sql = query.toString();
625 
626             Query q = session.createQuery(sql);
627 
628             QueryPos qPos = QueryPos.getInstance(q);
629 
630             qPos.add(groupId);
631 
632             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
633                     blogsStatsUser);
634 
635             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
636 
637             array[0] = (BlogsStatsUser)objArray[0];
638             array[1] = (BlogsStatsUser)objArray[1];
639             array[2] = (BlogsStatsUser)objArray[2];
640 
641             return array;
642         }
643         catch (Exception e) {
644             throw processException(e);
645         }
646         finally {
647             closeSession(session);
648         }
649     }
650 
651     public List<BlogsStatsUser> findByUserId(long userId)
652         throws SystemException {
653         Object[] finderArgs = new Object[] { new Long(userId) };
654 
655         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
656                 finderArgs, this);
657 
658         if (list == null) {
659             Session session = null;
660 
661             try {
662                 session = openSession();
663 
664                 StringBundler query = new StringBundler(3);
665 
666                 query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
667 
668                 query.append(_FINDER_COLUMN_USERID_USERID_2);
669 
670                 query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
671 
672                 String sql = query.toString();
673 
674                 Query q = session.createQuery(sql);
675 
676                 QueryPos qPos = QueryPos.getInstance(q);
677 
678                 qPos.add(userId);
679 
680                 list = q.list();
681             }
682             catch (Exception e) {
683                 throw processException(e);
684             }
685             finally {
686                 if (list == null) {
687                     list = new ArrayList<BlogsStatsUser>();
688                 }
689 
690                 cacheResult(list);
691 
692                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
693                     finderArgs, list);
694 
695                 closeSession(session);
696             }
697         }
698 
699         return list;
700     }
701 
702     public List<BlogsStatsUser> findByUserId(long userId, int start, int end)
703         throws SystemException {
704         return findByUserId(userId, start, end, null);
705     }
706 
707     public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
708         OrderByComparator obc) throws SystemException {
709         Object[] finderArgs = new Object[] {
710                 new Long(userId),
711                 
712                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
713             };
714 
715         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
716                 finderArgs, this);
717 
718         if (list == null) {
719             Session session = null;
720 
721             try {
722                 session = openSession();
723 
724                 StringBundler query = null;
725 
726                 if (obc != null) {
727                     query = new StringBundler(3 +
728                             (obc.getOrderByFields().length * 3));
729                 }
730                 else {
731                     query = new StringBundler(3);
732                 }
733 
734                 query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
735 
736                 query.append(_FINDER_COLUMN_USERID_USERID_2);
737 
738                 if (obc != null) {
739                     appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
740                 }
741 
742                 else {
743                     query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
744                 }
745 
746                 String sql = query.toString();
747 
748                 Query q = session.createQuery(sql);
749 
750                 QueryPos qPos = QueryPos.getInstance(q);
751 
752                 qPos.add(userId);
753 
754                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
755                         start, end);
756             }
757             catch (Exception e) {
758                 throw processException(e);
759             }
760             finally {
761                 if (list == null) {
762                     list = new ArrayList<BlogsStatsUser>();
763                 }
764 
765                 cacheResult(list);
766 
767                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
768                     finderArgs, list);
769 
770                 closeSession(session);
771             }
772         }
773 
774         return list;
775     }
776 
777     public BlogsStatsUser findByUserId_First(long userId, OrderByComparator obc)
778         throws NoSuchStatsUserException, SystemException {
779         List<BlogsStatsUser> list = findByUserId(userId, 0, 1, obc);
780 
781         if (list.isEmpty()) {
782             StringBundler msg = new StringBundler(4);
783 
784             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
785 
786             msg.append("userId=");
787             msg.append(userId);
788 
789             msg.append(StringPool.CLOSE_CURLY_BRACE);
790 
791             throw new NoSuchStatsUserException(msg.toString());
792         }
793         else {
794             return list.get(0);
795         }
796     }
797 
798     public BlogsStatsUser findByUserId_Last(long userId, OrderByComparator obc)
799         throws NoSuchStatsUserException, SystemException {
800         int count = countByUserId(userId);
801 
802         List<BlogsStatsUser> list = findByUserId(userId, count - 1, count, obc);
803 
804         if (list.isEmpty()) {
805             StringBundler msg = new StringBundler(4);
806 
807             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
808 
809             msg.append("userId=");
810             msg.append(userId);
811 
812             msg.append(StringPool.CLOSE_CURLY_BRACE);
813 
814             throw new NoSuchStatsUserException(msg.toString());
815         }
816         else {
817             return list.get(0);
818         }
819     }
820 
821     public BlogsStatsUser[] findByUserId_PrevAndNext(long statsUserId,
822         long userId, OrderByComparator obc)
823         throws NoSuchStatsUserException, SystemException {
824         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
825 
826         int count = countByUserId(userId);
827 
828         Session session = null;
829 
830         try {
831             session = openSession();
832 
833             StringBundler query = null;
834 
835             if (obc != null) {
836                 query = new StringBundler(3 +
837                         (obc.getOrderByFields().length * 3));
838             }
839             else {
840                 query = new StringBundler(3);
841             }
842 
843             query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
844 
845             query.append(_FINDER_COLUMN_USERID_USERID_2);
846 
847             if (obc != null) {
848                 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
849             }
850 
851             else {
852                 query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
853             }
854 
855             String sql = query.toString();
856 
857             Query q = session.createQuery(sql);
858 
859             QueryPos qPos = QueryPos.getInstance(q);
860 
861             qPos.add(userId);
862 
863             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
864                     blogsStatsUser);
865 
866             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
867 
868             array[0] = (BlogsStatsUser)objArray[0];
869             array[1] = (BlogsStatsUser)objArray[1];
870             array[2] = (BlogsStatsUser)objArray[2];
871 
872             return array;
873         }
874         catch (Exception e) {
875             throw processException(e);
876         }
877         finally {
878             closeSession(session);
879         }
880     }
881 
882     public BlogsStatsUser findByG_U(long groupId, long userId)
883         throws NoSuchStatsUserException, SystemException {
884         BlogsStatsUser blogsStatsUser = fetchByG_U(groupId, userId);
885 
886         if (blogsStatsUser == null) {
887             StringBundler msg = new StringBundler(6);
888 
889             msg.append(_NO_SUCH_ENTITY_WITH_KEY);
890 
891             msg.append("groupId=");
892             msg.append(groupId);
893 
894             msg.append(", userId=");
895             msg.append(userId);
896 
897             msg.append(StringPool.CLOSE_CURLY_BRACE);
898 
899             if (_log.isWarnEnabled()) {
900                 _log.warn(msg.toString());
901             }
902 
903             throw new NoSuchStatsUserException(msg.toString());
904         }
905 
906         return blogsStatsUser;
907     }
908 
909     public BlogsStatsUser fetchByG_U(long groupId, long userId)
910         throws SystemException {
911         return fetchByG_U(groupId, userId, true);
912     }
913 
914     public BlogsStatsUser fetchByG_U(long groupId, long userId,
915         boolean retrieveFromCache) throws SystemException {
916         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
917 
918         Object result = null;
919 
920         if (retrieveFromCache) {
921             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
922                     finderArgs, this);
923         }
924 
925         if (result == null) {
926             Session session = null;
927 
928             try {
929                 session = openSession();
930 
931                 StringBundler query = new StringBundler(4);
932 
933                 query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
934 
935                 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
936 
937                 query.append(_FINDER_COLUMN_G_U_USERID_2);
938 
939                 query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
940 
941                 String sql = query.toString();
942 
943                 Query q = session.createQuery(sql);
944 
945                 QueryPos qPos = QueryPos.getInstance(q);
946 
947                 qPos.add(groupId);
948 
949                 qPos.add(userId);
950 
951                 List<BlogsStatsUser> list = q.list();
952 
953                 result = list;
954 
955                 BlogsStatsUser blogsStatsUser = null;
956 
957                 if (list.isEmpty()) {
958                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
959                         finderArgs, list);
960                 }
961                 else {
962                     blogsStatsUser = list.get(0);
963 
964                     cacheResult(blogsStatsUser);
965 
966                     if ((blogsStatsUser.getGroupId() != groupId) ||
967                             (blogsStatsUser.getUserId() != userId)) {
968                         FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
969                             finderArgs, blogsStatsUser);
970                     }
971                 }
972 
973                 return blogsStatsUser;
974             }
975             catch (Exception e) {
976                 throw processException(e);
977             }
978             finally {
979                 if (result == null) {
980                     FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
981                         finderArgs, new ArrayList<BlogsStatsUser>());
982                 }
983 
984                 closeSession(session);
985             }
986         }
987         else {
988             if (result instanceof List<?>) {
989                 return null;
990             }
991             else {
992                 return (BlogsStatsUser)result;
993             }
994         }
995     }
996 
997     public List<BlogsStatsUser> findByG_E(long groupId, int entryCount)
998         throws SystemException {
999         Object[] finderArgs = new Object[] {
1000                new Long(groupId), new Integer(entryCount)
1001            };
1002
1003        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_E,
1004                finderArgs, this);
1005
1006        if (list == null) {
1007            Session session = null;
1008
1009            try {
1010                session = openSession();
1011
1012                StringBundler query = new StringBundler(4);
1013
1014                query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1015
1016                query.append(_FINDER_COLUMN_G_E_GROUPID_2);
1017
1018                query.append(_FINDER_COLUMN_G_E_ENTRYCOUNT_2);
1019
1020                query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1021
1022                String sql = query.toString();
1023
1024                Query q = session.createQuery(sql);
1025
1026                QueryPos qPos = QueryPos.getInstance(q);
1027
1028                qPos.add(groupId);
1029
1030                qPos.add(entryCount);
1031
1032                list = q.list();
1033            }
1034            catch (Exception e) {
1035                throw processException(e);
1036            }
1037            finally {
1038                if (list == null) {
1039                    list = new ArrayList<BlogsStatsUser>();
1040                }
1041
1042                cacheResult(list);
1043
1044                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_E, finderArgs,
1045                    list);
1046
1047                closeSession(session);
1048            }
1049        }
1050
1051        return list;
1052    }
1053
1054    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1055        int start, int end) throws SystemException {
1056        return findByG_E(groupId, entryCount, start, end, null);
1057    }
1058
1059    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1060        int start, int end, OrderByComparator obc) throws SystemException {
1061        Object[] finderArgs = new Object[] {
1062                new Long(groupId), new Integer(entryCount),
1063                
1064                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1065            };
1066
1067        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_E,
1068                finderArgs, this);
1069
1070        if (list == null) {
1071            Session session = null;
1072
1073            try {
1074                session = openSession();
1075
1076                StringBundler query = null;
1077
1078                if (obc != null) {
1079                    query = new StringBundler(4 +
1080                            (obc.getOrderByFields().length * 3));
1081                }
1082                else {
1083                    query = new StringBundler(4);
1084                }
1085
1086                query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1087
1088                query.append(_FINDER_COLUMN_G_E_GROUPID_2);
1089
1090                query.append(_FINDER_COLUMN_G_E_ENTRYCOUNT_2);
1091
1092                if (obc != null) {
1093                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1094                }
1095
1096                else {
1097                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1098                }
1099
1100                String sql = query.toString();
1101
1102                Query q = session.createQuery(sql);
1103
1104                QueryPos qPos = QueryPos.getInstance(q);
1105
1106                qPos.add(groupId);
1107
1108                qPos.add(entryCount);
1109
1110                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1111                        start, end);
1112            }
1113            catch (Exception e) {
1114                throw processException(e);
1115            }
1116            finally {
1117                if (list == null) {
1118                    list = new ArrayList<BlogsStatsUser>();
1119                }
1120
1121                cacheResult(list);
1122
1123                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_E,
1124                    finderArgs, list);
1125
1126                closeSession(session);
1127            }
1128        }
1129
1130        return list;
1131    }
1132
1133    public BlogsStatsUser findByG_E_First(long groupId, int entryCount,
1134        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1135        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, 0, 1, obc);
1136
1137        if (list.isEmpty()) {
1138            StringBundler msg = new StringBundler(6);
1139
1140            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1141
1142            msg.append("groupId=");
1143            msg.append(groupId);
1144
1145            msg.append(", entryCount=");
1146            msg.append(entryCount);
1147
1148            msg.append(StringPool.CLOSE_CURLY_BRACE);
1149
1150            throw new NoSuchStatsUserException(msg.toString());
1151        }
1152        else {
1153            return list.get(0);
1154        }
1155    }
1156
1157    public BlogsStatsUser findByG_E_Last(long groupId, int entryCount,
1158        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1159        int count = countByG_E(groupId, entryCount);
1160
1161        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, count - 1,
1162                count, obc);
1163
1164        if (list.isEmpty()) {
1165            StringBundler msg = new StringBundler(6);
1166
1167            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1168
1169            msg.append("groupId=");
1170            msg.append(groupId);
1171
1172            msg.append(", entryCount=");
1173            msg.append(entryCount);
1174
1175            msg.append(StringPool.CLOSE_CURLY_BRACE);
1176
1177            throw new NoSuchStatsUserException(msg.toString());
1178        }
1179        else {
1180            return list.get(0);
1181        }
1182    }
1183
1184    public BlogsStatsUser[] findByG_E_PrevAndNext(long statsUserId,
1185        long groupId, int entryCount, OrderByComparator obc)
1186        throws NoSuchStatsUserException, SystemException {
1187        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1188
1189        int count = countByG_E(groupId, entryCount);
1190
1191        Session session = null;
1192
1193        try {
1194            session = openSession();
1195
1196            StringBundler query = null;
1197
1198            if (obc != null) {
1199                query = new StringBundler(4 +
1200                        (obc.getOrderByFields().length * 3));
1201            }
1202            else {
1203                query = new StringBundler(4);
1204            }
1205
1206            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1207
1208            query.append(_FINDER_COLUMN_G_E_GROUPID_2);
1209
1210            query.append(_FINDER_COLUMN_G_E_ENTRYCOUNT_2);
1211
1212            if (obc != null) {
1213                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1214            }
1215
1216            else {
1217                query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1218            }
1219
1220            String sql = query.toString();
1221
1222            Query q = session.createQuery(sql);
1223
1224            QueryPos qPos = QueryPos.getInstance(q);
1225
1226            qPos.add(groupId);
1227
1228            qPos.add(entryCount);
1229
1230            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1231                    blogsStatsUser);
1232
1233            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1234
1235            array[0] = (BlogsStatsUser)objArray[0];
1236            array[1] = (BlogsStatsUser)objArray[1];
1237            array[2] = (BlogsStatsUser)objArray[2];
1238
1239            return array;
1240        }
1241        catch (Exception e) {
1242            throw processException(e);
1243        }
1244        finally {
1245            closeSession(session);
1246        }
1247    }
1248
1249    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount)
1250        throws SystemException {
1251        Object[] finderArgs = new Object[] {
1252                new Long(companyId), new Integer(entryCount)
1253            };
1254
1255        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_E,
1256                finderArgs, this);
1257
1258        if (list == null) {
1259            Session session = null;
1260
1261            try {
1262                session = openSession();
1263
1264                StringBundler query = new StringBundler(4);
1265
1266                query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1267
1268                query.append(_FINDER_COLUMN_C_E_COMPANYID_2);
1269
1270                query.append(_FINDER_COLUMN_C_E_ENTRYCOUNT_2);
1271
1272                query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1273
1274                String sql = query.toString();
1275
1276                Query q = session.createQuery(sql);
1277
1278                QueryPos qPos = QueryPos.getInstance(q);
1279
1280                qPos.add(companyId);
1281
1282                qPos.add(entryCount);
1283
1284                list = q.list();
1285            }
1286            catch (Exception e) {
1287                throw processException(e);
1288            }
1289            finally {
1290                if (list == null) {
1291                    list = new ArrayList<BlogsStatsUser>();
1292                }
1293
1294                cacheResult(list);
1295
1296                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_E, finderArgs,
1297                    list);
1298
1299                closeSession(session);
1300            }
1301        }
1302
1303        return list;
1304    }
1305
1306    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1307        int start, int end) throws SystemException {
1308        return findByC_E(companyId, entryCount, start, end, null);
1309    }
1310
1311    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1312        int start, int end, OrderByComparator obc) throws SystemException {
1313        Object[] finderArgs = new Object[] {
1314                new Long(companyId), new Integer(entryCount),
1315                
1316                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1317            };
1318
1319        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_E,
1320                finderArgs, this);
1321
1322        if (list == null) {
1323            Session session = null;
1324
1325            try {
1326                session = openSession();
1327
1328                StringBundler query = null;
1329
1330                if (obc != null) {
1331                    query = new StringBundler(4 +
1332                            (obc.getOrderByFields().length * 3));
1333                }
1334                else {
1335                    query = new StringBundler(4);
1336                }
1337
1338                query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1339
1340                query.append(_FINDER_COLUMN_C_E_COMPANYID_2);
1341
1342                query.append(_FINDER_COLUMN_C_E_ENTRYCOUNT_2);
1343
1344                if (obc != null) {
1345                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1346                }
1347
1348                else {
1349                    query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1350                }
1351
1352                String sql = query.toString();
1353
1354                Query q = session.createQuery(sql);
1355
1356                QueryPos qPos = QueryPos.getInstance(q);
1357
1358                qPos.add(companyId);
1359
1360                qPos.add(entryCount);
1361
1362                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1363                        start, end);
1364            }
1365            catch (Exception e) {
1366                throw processException(e);
1367            }
1368            finally {
1369                if (list == null) {
1370                    list = new ArrayList<BlogsStatsUser>();
1371                }
1372
1373                cacheResult(list);
1374
1375                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_E,
1376                    finderArgs, list);
1377
1378                closeSession(session);
1379            }
1380        }
1381
1382        return list;
1383    }
1384
1385    public BlogsStatsUser findByC_E_First(long companyId, int entryCount,
1386        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1387        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, 0, 1, obc);
1388
1389        if (list.isEmpty()) {
1390            StringBundler msg = new StringBundler(6);
1391
1392            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1393
1394            msg.append("companyId=");
1395            msg.append(companyId);
1396
1397            msg.append(", entryCount=");
1398            msg.append(entryCount);
1399
1400            msg.append(StringPool.CLOSE_CURLY_BRACE);
1401
1402            throw new NoSuchStatsUserException(msg.toString());
1403        }
1404        else {
1405            return list.get(0);
1406        }
1407    }
1408
1409    public BlogsStatsUser findByC_E_Last(long companyId, int entryCount,
1410        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1411        int count = countByC_E(companyId, entryCount);
1412
1413        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, count - 1,
1414                count, obc);
1415
1416        if (list.isEmpty()) {
1417            StringBundler msg = new StringBundler(6);
1418
1419            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1420
1421            msg.append("companyId=");
1422            msg.append(companyId);
1423
1424            msg.append(", entryCount=");
1425            msg.append(entryCount);
1426
1427            msg.append(StringPool.CLOSE_CURLY_BRACE);
1428
1429            throw new NoSuchStatsUserException(msg.toString());
1430        }
1431        else {
1432            return list.get(0);
1433        }
1434    }
1435
1436    public BlogsStatsUser[] findByC_E_PrevAndNext(long statsUserId,
1437        long companyId, int entryCount, OrderByComparator obc)
1438        throws NoSuchStatsUserException, SystemException {
1439        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1440
1441        int count = countByC_E(companyId, entryCount);
1442
1443        Session session = null;
1444
1445        try {
1446            session = openSession();
1447
1448            StringBundler query = null;
1449
1450            if (obc != null) {
1451                query = new StringBundler(4 +
1452                        (obc.getOrderByFields().length * 3));
1453            }
1454            else {
1455                query = new StringBundler(4);
1456            }
1457
1458            query.append(_SQL_SELECT_BLOGSSTATSUSER_WHERE);
1459
1460            query.append(_FINDER_COLUMN_C_E_COMPANYID_2);
1461
1462            query.append(_FINDER_COLUMN_C_E_ENTRYCOUNT_2);
1463
1464            if (obc != null) {
1465                appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1466            }
1467
1468            else {
1469                query.append(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1470            }
1471
1472            String sql = query.toString();
1473
1474            Query q = session.createQuery(sql);
1475
1476            QueryPos qPos = QueryPos.getInstance(q);
1477
1478            qPos.add(companyId);
1479
1480            qPos.add(entryCount);
1481
1482            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1483                    blogsStatsUser);
1484
1485            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1486
1487            array[0] = (BlogsStatsUser)objArray[0];
1488            array[1] = (BlogsStatsUser)objArray[1];
1489            array[2] = (BlogsStatsUser)objArray[2];
1490
1491            return array;
1492        }
1493        catch (Exception e) {
1494            throw processException(e);
1495        }
1496        finally {
1497            closeSession(session);
1498        }
1499    }
1500
1501    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1502        throws SystemException {
1503        Session session = null;
1504
1505        try {
1506            session = openSession();
1507
1508            dynamicQuery.compile(session);
1509
1510            return dynamicQuery.list();
1511        }
1512        catch (Exception e) {
1513            throw processException(e);
1514        }
1515        finally {
1516            closeSession(session);
1517        }
1518    }
1519
1520    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1521        int start, int end) throws SystemException {
1522        Session session = null;
1523
1524        try {
1525            session = openSession();
1526
1527            dynamicQuery.setLimit(start, end);
1528
1529            dynamicQuery.compile(session);
1530
1531            return dynamicQuery.list();
1532        }
1533        catch (Exception e) {
1534            throw processException(e);
1535        }
1536        finally {
1537            closeSession(session);
1538        }
1539    }
1540
1541    public List<BlogsStatsUser> findAll() throws SystemException {
1542        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1543    }
1544
1545    public List<BlogsStatsUser> findAll(int start, int end)
1546        throws SystemException {
1547        return findAll(start, end, null);
1548    }
1549
1550    public List<BlogsStatsUser> findAll(int start, int end,
1551        OrderByComparator obc) throws SystemException {
1552        Object[] finderArgs = new Object[] {
1553                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1554            };
1555
1556        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1557                finderArgs, this);
1558
1559        if (list == null) {
1560            Session session = null;
1561
1562            try {
1563                session = openSession();
1564
1565                StringBundler query = null;
1566                String sql = null;
1567
1568                if (obc != null) {
1569                    query = new StringBundler(2 +
1570                            (obc.getOrderByFields().length * 3));
1571
1572                    query.append(_SQL_SELECT_BLOGSSTATSUSER);
1573
1574                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
1575
1576                    sql = query.toString();
1577                }
1578
1579                else {
1580                    sql = _SQL_SELECT_BLOGSSTATSUSER.concat(BlogsStatsUserModelImpl.ORDER_BY_JPQL);
1581                }
1582
1583                Query q = session.createQuery(sql);
1584
1585                if (obc == null) {
1586                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1587                            getDialect(), start, end, false);
1588
1589                    Collections.sort(list);
1590                }
1591                else {
1592                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1593                            getDialect(), start, end);
1594                }
1595            }
1596            catch (Exception e) {
1597                throw processException(e);
1598            }
1599            finally {
1600                if (list == null) {
1601                    list = new ArrayList<BlogsStatsUser>();
1602                }
1603
1604                cacheResult(list);
1605
1606                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1607
1608                closeSession(session);
1609            }
1610        }
1611
1612        return list;
1613    }
1614
1615    public void removeByGroupId(long groupId) throws SystemException {
1616        for (BlogsStatsUser blogsStatsUser : findByGroupId(groupId)) {
1617            remove(blogsStatsUser);
1618        }
1619    }
1620
1621    public void removeByUserId(long userId) throws SystemException {
1622        for (BlogsStatsUser blogsStatsUser : findByUserId(userId)) {
1623            remove(blogsStatsUser);
1624        }
1625    }
1626
1627    public void removeByG_U(long groupId, long userId)
1628        throws NoSuchStatsUserException, SystemException {
1629        BlogsStatsUser blogsStatsUser = findByG_U(groupId, userId);
1630
1631        remove(blogsStatsUser);
1632    }
1633
1634    public void removeByG_E(long groupId, int entryCount)
1635        throws SystemException {
1636        for (BlogsStatsUser blogsStatsUser : findByG_E(groupId, entryCount)) {
1637            remove(blogsStatsUser);
1638        }
1639    }
1640
1641    public void removeByC_E(long companyId, int entryCount)
1642        throws SystemException {
1643        for (BlogsStatsUser blogsStatsUser : findByC_E(companyId, entryCount)) {
1644            remove(blogsStatsUser);
1645        }
1646    }
1647
1648    public void removeAll() throws SystemException {
1649        for (BlogsStatsUser blogsStatsUser : findAll()) {
1650            remove(blogsStatsUser);
1651        }
1652    }
1653
1654    public int countByGroupId(long groupId) throws SystemException {
1655        Object[] finderArgs = new Object[] { new Long(groupId) };
1656
1657        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1658                finderArgs, this);
1659
1660        if (count == null) {
1661            Session session = null;
1662
1663            try {
1664                session = openSession();
1665
1666                StringBundler query = new StringBundler(2);
1667
1668                query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1669
1670                query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1671
1672                String sql = query.toString();
1673
1674                Query q = session.createQuery(sql);
1675
1676                QueryPos qPos = QueryPos.getInstance(q);
1677
1678                qPos.add(groupId);
1679
1680                count = (Long)q.uniqueResult();
1681            }
1682            catch (Exception e) {
1683                throw processException(e);
1684            }
1685            finally {
1686                if (count == null) {
1687                    count = Long.valueOf(0);
1688                }
1689
1690                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1691                    finderArgs, count);
1692
1693                closeSession(session);
1694            }
1695        }
1696
1697        return count.intValue();
1698    }
1699
1700    public int countByUserId(long userId) throws SystemException {
1701        Object[] finderArgs = new Object[] { new Long(userId) };
1702
1703        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1704                finderArgs, this);
1705
1706        if (count == null) {
1707            Session session = null;
1708
1709            try {
1710                session = openSession();
1711
1712                StringBundler query = new StringBundler(2);
1713
1714                query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1715
1716                query.append(_FINDER_COLUMN_USERID_USERID_2);
1717
1718                String sql = query.toString();
1719
1720                Query q = session.createQuery(sql);
1721
1722                QueryPos qPos = QueryPos.getInstance(q);
1723
1724                qPos.add(userId);
1725
1726                count = (Long)q.uniqueResult();
1727            }
1728            catch (Exception e) {
1729                throw processException(e);
1730            }
1731            finally {
1732                if (count == null) {
1733                    count = Long.valueOf(0);
1734                }
1735
1736                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1737                    finderArgs, count);
1738
1739                closeSession(session);
1740            }
1741        }
1742
1743        return count.intValue();
1744    }
1745
1746    public int countByG_U(long groupId, long userId) throws SystemException {
1747        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1748
1749        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1750                finderArgs, this);
1751
1752        if (count == null) {
1753            Session session = null;
1754
1755            try {
1756                session = openSession();
1757
1758                StringBundler query = new StringBundler(3);
1759
1760                query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1761
1762                query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1763
1764                query.append(_FINDER_COLUMN_G_U_USERID_2);
1765
1766                String sql = query.toString();
1767
1768                Query q = session.createQuery(sql);
1769
1770                QueryPos qPos = QueryPos.getInstance(q);
1771
1772                qPos.add(groupId);
1773
1774                qPos.add(userId);
1775
1776                count = (Long)q.uniqueResult();
1777            }
1778            catch (Exception e) {
1779                throw processException(e);
1780            }
1781            finally {
1782                if (count == null) {
1783                    count = Long.valueOf(0);
1784                }
1785
1786                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1787                    count);
1788
1789                closeSession(session);
1790            }
1791        }
1792
1793        return count.intValue();
1794    }
1795
1796    public int countByG_E(long groupId, int entryCount)
1797        throws SystemException {
1798        Object[] finderArgs = new Object[] {
1799                new Long(groupId), new Integer(entryCount)
1800            };
1801
1802        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_E,
1803                finderArgs, this);
1804
1805        if (count == null) {
1806            Session session = null;
1807
1808            try {
1809                session = openSession();
1810
1811                StringBundler query = new StringBundler(3);
1812
1813                query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1814
1815                query.append(_FINDER_COLUMN_G_E_GROUPID_2);
1816
1817                query.append(_FINDER_COLUMN_G_E_ENTRYCOUNT_2);
1818
1819                String sql = query.toString();
1820
1821                Query q = session.createQuery(sql);
1822
1823                QueryPos qPos = QueryPos.getInstance(q);
1824
1825                qPos.add(groupId);
1826
1827                qPos.add(entryCount);
1828
1829                count = (Long)q.uniqueResult();
1830            }
1831            catch (Exception e) {
1832                throw processException(e);
1833            }
1834            finally {
1835                if (count == null) {
1836                    count = Long.valueOf(0);
1837                }
1838
1839                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_E, finderArgs,
1840                    count);
1841
1842                closeSession(session);
1843            }
1844        }
1845
1846        return count.intValue();
1847    }
1848
1849    public int countByC_E(long companyId, int entryCount)
1850        throws SystemException {
1851        Object[] finderArgs = new Object[] {
1852                new Long(companyId), new Integer(entryCount)
1853            };
1854
1855        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_E,
1856                finderArgs, this);
1857
1858        if (count == null) {
1859            Session session = null;
1860
1861            try {
1862                session = openSession();
1863
1864                StringBundler query = new StringBundler(3);
1865
1866                query.append(_SQL_COUNT_BLOGSSTATSUSER_WHERE);
1867
1868                query.append(_FINDER_COLUMN_C_E_COMPANYID_2);
1869
1870                query.append(_FINDER_COLUMN_C_E_ENTRYCOUNT_2);
1871
1872                String sql = query.toString();
1873
1874                Query q = session.createQuery(sql);
1875
1876                QueryPos qPos = QueryPos.getInstance(q);
1877
1878                qPos.add(companyId);
1879
1880                qPos.add(entryCount);
1881
1882                count = (Long)q.uniqueResult();
1883            }
1884            catch (Exception e) {
1885                throw processException(e);
1886            }
1887            finally {
1888                if (count == null) {
1889                    count = Long.valueOf(0);
1890                }
1891
1892                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_E, finderArgs,
1893                    count);
1894
1895                closeSession(session);
1896            }
1897        }
1898
1899        return count.intValue();
1900    }
1901
1902    public int countAll() throws SystemException {
1903        Object[] finderArgs = new Object[0];
1904
1905        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1906                finderArgs, this);
1907
1908        if (count == null) {
1909            Session session = null;
1910
1911            try {
1912                session = openSession();
1913
1914                Query q = session.createQuery(_SQL_COUNT_BLOGSSTATSUSER);
1915
1916                count = (Long)q.uniqueResult();
1917            }
1918            catch (Exception e) {
1919                throw processException(e);
1920            }
1921            finally {
1922                if (count == null) {
1923                    count = Long.valueOf(0);
1924                }
1925
1926                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1927                    count);
1928
1929                closeSession(session);
1930            }
1931        }
1932
1933        return count.intValue();
1934    }
1935
1936    public void afterPropertiesSet() {
1937        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1938                    com.liferay.portal.util.PropsUtil.get(
1939                        "value.object.listener.com.liferay.portlet.blogs.model.BlogsStatsUser")));
1940
1941        if (listenerClassNames.length > 0) {
1942            try {
1943                List<ModelListener<BlogsStatsUser>> listenersList = new ArrayList<ModelListener<BlogsStatsUser>>();
1944
1945                for (String listenerClassName : listenerClassNames) {
1946                    listenersList.add((ModelListener<BlogsStatsUser>)Class.forName(
1947                            listenerClassName).newInstance());
1948                }
1949
1950                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1951            }
1952            catch (Exception e) {
1953                _log.error(e);
1954            }
1955        }
1956    }
1957
1958    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence")
1959    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1960    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence")
1961    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
1962    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence")
1963    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
1964    @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1965    protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1966    @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1967    protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1968    private static final String _SQL_SELECT_BLOGSSTATSUSER = "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser";
1969    private static final String _SQL_SELECT_BLOGSSTATSUSER_WHERE = "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ";
1970    private static final String _SQL_COUNT_BLOGSSTATSUSER = "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser";
1971    private static final String _SQL_COUNT_BLOGSSTATSUSER_WHERE = "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser WHERE ";
1972    private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "blogsStatsUser.groupId = ?";
1973    private static final String _FINDER_COLUMN_USERID_USERID_2 = "blogsStatsUser.userId = ?";
1974    private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "blogsStatsUser.groupId = ? AND ";
1975    private static final String _FINDER_COLUMN_G_U_USERID_2 = "blogsStatsUser.userId = ?";
1976    private static final String _FINDER_COLUMN_G_E_GROUPID_2 = "blogsStatsUser.groupId = ? AND ";
1977    private static final String _FINDER_COLUMN_G_E_ENTRYCOUNT_2 = "blogsStatsUser.entryCount != ?";
1978    private static final String _FINDER_COLUMN_C_E_COMPANYID_2 = "blogsStatsUser.companyId = ? AND ";
1979    private static final String _FINDER_COLUMN_C_E_ENTRYCOUNT_2 = "blogsStatsUser.entryCount != ?";
1980    private static final String _ORDER_BY_ENTITY_ALIAS = "blogsStatsUser.";
1981    private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No BlogsStatsUser exists with the primary key ";
1982    private static final String _NO_SUCH_ENTITY_WITH_KEY = "No BlogsStatsUser exists with the key {";
1983    private static Log _log = LogFactoryUtil.getLog(BlogsStatsUserPersistenceImpl.class);
1984}