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