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                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
448 
449                 query.append("blogsStatsUser.groupId = ?");
450 
451                 query.append(" ");
452 
453                 query.append("ORDER BY ");
454 
455                 query.append("blogsStatsUser.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                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
511 
512                 query.append("blogsStatsUser.groupId = ?");
513 
514                 query.append(" ");
515 
516                 if (obc != null) {
517                     query.append("ORDER BY ");
518 
519                     String[] orderByFields = obc.getOrderByFields();
520 
521                     for (int i = 0; i < orderByFields.length; i++) {
522                         query.append("blogsStatsUser.");
523                         query.append(orderByFields[i]);
524 
525                         if (obc.isAscending()) {
526                             query.append(" ASC");
527                         }
528                         else {
529                             query.append(" DESC");
530                         }
531 
532                         if ((i + 1) < orderByFields.length) {
533                             query.append(", ");
534                         }
535                     }
536                 }
537 
538                 else {
539                     query.append("ORDER BY ");
540 
541                     query.append("blogsStatsUser.entryCount DESC");
542                 }
543 
544                 Query q = session.createQuery(query.toString());
545 
546                 QueryPos qPos = QueryPos.getInstance(q);
547 
548                 qPos.add(groupId);
549 
550                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
551                         start, end);
552             }
553             catch (Exception e) {
554                 throw processException(e);
555             }
556             finally {
557                 if (list == null) {
558                     list = new ArrayList<BlogsStatsUser>();
559                 }
560 
561                 cacheResult(list);
562 
563                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
564                     finderArgs, list);
565 
566                 closeSession(session);
567             }
568         }
569 
570         return list;
571     }
572 
573     public BlogsStatsUser findByGroupId_First(long groupId,
574         OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
575         List<BlogsStatsUser> list = findByGroupId(groupId, 0, 1, obc);
576 
577         if (list.isEmpty()) {
578             StringBuilder msg = new StringBuilder();
579 
580             msg.append("No BlogsStatsUser exists with the key {");
581 
582             msg.append("groupId=" + groupId);
583 
584             msg.append(StringPool.CLOSE_CURLY_BRACE);
585 
586             throw new NoSuchStatsUserException(msg.toString());
587         }
588         else {
589             return list.get(0);
590         }
591     }
592 
593     public BlogsStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
594         throws NoSuchStatsUserException, SystemException {
595         int count = countByGroupId(groupId);
596 
597         List<BlogsStatsUser> list = findByGroupId(groupId, count - 1, count, obc);
598 
599         if (list.isEmpty()) {
600             StringBuilder msg = new StringBuilder();
601 
602             msg.append("No BlogsStatsUser exists with the key {");
603 
604             msg.append("groupId=" + groupId);
605 
606             msg.append(StringPool.CLOSE_CURLY_BRACE);
607 
608             throw new NoSuchStatsUserException(msg.toString());
609         }
610         else {
611             return list.get(0);
612         }
613     }
614 
615     public BlogsStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
616         long groupId, OrderByComparator obc)
617         throws NoSuchStatsUserException, SystemException {
618         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
619 
620         int count = countByGroupId(groupId);
621 
622         Session session = null;
623 
624         try {
625             session = openSession();
626 
627             StringBuilder query = new StringBuilder();
628 
629             query.append(
630                 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
631 
632             query.append("blogsStatsUser.groupId = ?");
633 
634             query.append(" ");
635 
636             if (obc != null) {
637                 query.append("ORDER BY ");
638 
639                 String[] orderByFields = obc.getOrderByFields();
640 
641                 for (int i = 0; i < orderByFields.length; i++) {
642                     query.append("blogsStatsUser.");
643                     query.append(orderByFields[i]);
644 
645                     if (obc.isAscending()) {
646                         query.append(" ASC");
647                     }
648                     else {
649                         query.append(" DESC");
650                     }
651 
652                     if ((i + 1) < orderByFields.length) {
653                         query.append(", ");
654                     }
655                 }
656             }
657 
658             else {
659                 query.append("ORDER BY ");
660 
661                 query.append("blogsStatsUser.entryCount DESC");
662             }
663 
664             Query q = session.createQuery(query.toString());
665 
666             QueryPos qPos = QueryPos.getInstance(q);
667 
668             qPos.add(groupId);
669 
670             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
671                     blogsStatsUser);
672 
673             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
674 
675             array[0] = (BlogsStatsUser)objArray[0];
676             array[1] = (BlogsStatsUser)objArray[1];
677             array[2] = (BlogsStatsUser)objArray[2];
678 
679             return array;
680         }
681         catch (Exception e) {
682             throw processException(e);
683         }
684         finally {
685             closeSession(session);
686         }
687     }
688 
689     public List<BlogsStatsUser> findByUserId(long userId)
690         throws SystemException {
691         Object[] finderArgs = new Object[] { new Long(userId) };
692 
693         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
694                 finderArgs, this);
695 
696         if (list == null) {
697             Session session = null;
698 
699             try {
700                 session = openSession();
701 
702                 StringBuilder query = new StringBuilder();
703 
704                 query.append(
705                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
706 
707                 query.append("blogsStatsUser.userId = ?");
708 
709                 query.append(" ");
710 
711                 query.append("ORDER BY ");
712 
713                 query.append("blogsStatsUser.entryCount DESC");
714 
715                 Query q = session.createQuery(query.toString());
716 
717                 QueryPos qPos = QueryPos.getInstance(q);
718 
719                 qPos.add(userId);
720 
721                 list = q.list();
722             }
723             catch (Exception e) {
724                 throw processException(e);
725             }
726             finally {
727                 if (list == null) {
728                     list = new ArrayList<BlogsStatsUser>();
729                 }
730 
731                 cacheResult(list);
732 
733                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
734                     finderArgs, list);
735 
736                 closeSession(session);
737             }
738         }
739 
740         return list;
741     }
742 
743     public List<BlogsStatsUser> findByUserId(long userId, int start, int end)
744         throws SystemException {
745         return findByUserId(userId, start, end, null);
746     }
747 
748     public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
749         OrderByComparator obc) throws SystemException {
750         Object[] finderArgs = new Object[] {
751                 new Long(userId),
752                 
753                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
754             };
755 
756         List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
757                 finderArgs, this);
758 
759         if (list == null) {
760             Session session = null;
761 
762             try {
763                 session = openSession();
764 
765                 StringBuilder query = new StringBuilder();
766 
767                 query.append(
768                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
769 
770                 query.append("blogsStatsUser.userId = ?");
771 
772                 query.append(" ");
773 
774                 if (obc != null) {
775                     query.append("ORDER BY ");
776 
777                     String[] orderByFields = obc.getOrderByFields();
778 
779                     for (int i = 0; i < orderByFields.length; i++) {
780                         query.append("blogsStatsUser.");
781                         query.append(orderByFields[i]);
782 
783                         if (obc.isAscending()) {
784                             query.append(" ASC");
785                         }
786                         else {
787                             query.append(" DESC");
788                         }
789 
790                         if ((i + 1) < orderByFields.length) {
791                             query.append(", ");
792                         }
793                     }
794                 }
795 
796                 else {
797                     query.append("ORDER BY ");
798 
799                     query.append("blogsStatsUser.entryCount DESC");
800                 }
801 
802                 Query q = session.createQuery(query.toString());
803 
804                 QueryPos qPos = QueryPos.getInstance(q);
805 
806                 qPos.add(userId);
807 
808                 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
809                         start, end);
810             }
811             catch (Exception e) {
812                 throw processException(e);
813             }
814             finally {
815                 if (list == null) {
816                     list = new ArrayList<BlogsStatsUser>();
817                 }
818 
819                 cacheResult(list);
820 
821                 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
822                     finderArgs, list);
823 
824                 closeSession(session);
825             }
826         }
827 
828         return list;
829     }
830 
831     public BlogsStatsUser findByUserId_First(long userId, OrderByComparator obc)
832         throws NoSuchStatsUserException, SystemException {
833         List<BlogsStatsUser> list = findByUserId(userId, 0, 1, obc);
834 
835         if (list.isEmpty()) {
836             StringBuilder msg = new StringBuilder();
837 
838             msg.append("No BlogsStatsUser exists with the key {");
839 
840             msg.append("userId=" + userId);
841 
842             msg.append(StringPool.CLOSE_CURLY_BRACE);
843 
844             throw new NoSuchStatsUserException(msg.toString());
845         }
846         else {
847             return list.get(0);
848         }
849     }
850 
851     public BlogsStatsUser findByUserId_Last(long userId, OrderByComparator obc)
852         throws NoSuchStatsUserException, SystemException {
853         int count = countByUserId(userId);
854 
855         List<BlogsStatsUser> list = findByUserId(userId, count - 1, count, obc);
856 
857         if (list.isEmpty()) {
858             StringBuilder msg = new StringBuilder();
859 
860             msg.append("No BlogsStatsUser exists with the key {");
861 
862             msg.append("userId=" + userId);
863 
864             msg.append(StringPool.CLOSE_CURLY_BRACE);
865 
866             throw new NoSuchStatsUserException(msg.toString());
867         }
868         else {
869             return list.get(0);
870         }
871     }
872 
873     public BlogsStatsUser[] findByUserId_PrevAndNext(long statsUserId,
874         long userId, OrderByComparator obc)
875         throws NoSuchStatsUserException, SystemException {
876         BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
877 
878         int count = countByUserId(userId);
879 
880         Session session = null;
881 
882         try {
883             session = openSession();
884 
885             StringBuilder query = new StringBuilder();
886 
887             query.append(
888                 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
889 
890             query.append("blogsStatsUser.userId = ?");
891 
892             query.append(" ");
893 
894             if (obc != null) {
895                 query.append("ORDER BY ");
896 
897                 String[] orderByFields = obc.getOrderByFields();
898 
899                 for (int i = 0; i < orderByFields.length; i++) {
900                     query.append("blogsStatsUser.");
901                     query.append(orderByFields[i]);
902 
903                     if (obc.isAscending()) {
904                         query.append(" ASC");
905                     }
906                     else {
907                         query.append(" DESC");
908                     }
909 
910                     if ((i + 1) < orderByFields.length) {
911                         query.append(", ");
912                     }
913                 }
914             }
915 
916             else {
917                 query.append("ORDER BY ");
918 
919                 query.append("blogsStatsUser.entryCount DESC");
920             }
921 
922             Query q = session.createQuery(query.toString());
923 
924             QueryPos qPos = QueryPos.getInstance(q);
925 
926             qPos.add(userId);
927 
928             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
929                     blogsStatsUser);
930 
931             BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
932 
933             array[0] = (BlogsStatsUser)objArray[0];
934             array[1] = (BlogsStatsUser)objArray[1];
935             array[2] = (BlogsStatsUser)objArray[2];
936 
937             return array;
938         }
939         catch (Exception e) {
940             throw processException(e);
941         }
942         finally {
943             closeSession(session);
944         }
945     }
946 
947     public BlogsStatsUser findByG_U(long groupId, long userId)
948         throws NoSuchStatsUserException, SystemException {
949         BlogsStatsUser blogsStatsUser = fetchByG_U(groupId, userId);
950 
951         if (blogsStatsUser == null) {
952             StringBuilder msg = new StringBuilder();
953 
954             msg.append("No BlogsStatsUser exists with the key {");
955 
956             msg.append("groupId=" + groupId);
957 
958             msg.append(", ");
959             msg.append("userId=" + userId);
960 
961             msg.append(StringPool.CLOSE_CURLY_BRACE);
962 
963             if (_log.isWarnEnabled()) {
964                 _log.warn(msg.toString());
965             }
966 
967             throw new NoSuchStatsUserException(msg.toString());
968         }
969 
970         return blogsStatsUser;
971     }
972 
973     public BlogsStatsUser fetchByG_U(long groupId, long userId)
974         throws SystemException {
975         return fetchByG_U(groupId, userId, true);
976     }
977 
978     public BlogsStatsUser fetchByG_U(long groupId, long userId,
979         boolean retrieveFromCache) throws SystemException {
980         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
981 
982         Object result = null;
983 
984         if (retrieveFromCache) {
985             result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
986                     finderArgs, this);
987         }
988 
989         if (result == null) {
990             Session session = null;
991 
992             try {
993                 session = openSession();
994 
995                 StringBuilder query = new StringBuilder();
996 
997                 query.append(
998                     "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
999 
1000                query.append("blogsStatsUser.groupId = ?");
1001
1002                query.append(" AND ");
1003
1004                query.append("blogsStatsUser.userId = ?");
1005
1006                query.append(" ");
1007
1008                query.append("ORDER BY ");
1009
1010                query.append("blogsStatsUser.entryCount DESC");
1011
1012                Query q = session.createQuery(query.toString());
1013
1014                QueryPos qPos = QueryPos.getInstance(q);
1015
1016                qPos.add(groupId);
1017
1018                qPos.add(userId);
1019
1020                List<BlogsStatsUser> list = q.list();
1021
1022                result = list;
1023
1024                BlogsStatsUser blogsStatsUser = null;
1025
1026                if (list.isEmpty()) {
1027                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1028                        finderArgs, list);
1029                }
1030                else {
1031                    blogsStatsUser = list.get(0);
1032
1033                    cacheResult(blogsStatsUser);
1034
1035                    if ((blogsStatsUser.getGroupId() != groupId) ||
1036                            (blogsStatsUser.getUserId() != userId)) {
1037                        FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1038                            finderArgs, blogsStatsUser);
1039                    }
1040                }
1041
1042                return blogsStatsUser;
1043            }
1044            catch (Exception e) {
1045                throw processException(e);
1046            }
1047            finally {
1048                if (result == null) {
1049                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1050                        finderArgs, new ArrayList<BlogsStatsUser>());
1051                }
1052
1053                closeSession(session);
1054            }
1055        }
1056        else {
1057            if (result instanceof List) {
1058                return null;
1059            }
1060            else {
1061                return (BlogsStatsUser)result;
1062            }
1063        }
1064    }
1065
1066    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount)
1067        throws SystemException {
1068        Object[] finderArgs = new Object[] {
1069                new Long(groupId), new Integer(entryCount)
1070            };
1071
1072        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_E,
1073                finderArgs, this);
1074
1075        if (list == null) {
1076            Session session = null;
1077
1078            try {
1079                session = openSession();
1080
1081                StringBuilder query = new StringBuilder();
1082
1083                query.append(
1084                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1085
1086                query.append("blogsStatsUser.groupId = ?");
1087
1088                query.append(" AND ");
1089
1090                query.append("blogsStatsUser.entryCount != ?");
1091
1092                query.append(" ");
1093
1094                query.append("ORDER BY ");
1095
1096                query.append("blogsStatsUser.entryCount DESC");
1097
1098                Query q = session.createQuery(query.toString());
1099
1100                QueryPos qPos = QueryPos.getInstance(q);
1101
1102                qPos.add(groupId);
1103
1104                qPos.add(entryCount);
1105
1106                list = q.list();
1107            }
1108            catch (Exception e) {
1109                throw processException(e);
1110            }
1111            finally {
1112                if (list == null) {
1113                    list = new ArrayList<BlogsStatsUser>();
1114                }
1115
1116                cacheResult(list);
1117
1118                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_E, finderArgs,
1119                    list);
1120
1121                closeSession(session);
1122            }
1123        }
1124
1125        return list;
1126    }
1127
1128    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1129        int start, int end) throws SystemException {
1130        return findByG_E(groupId, entryCount, start, end, null);
1131    }
1132
1133    public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1134        int start, int end, OrderByComparator obc) throws SystemException {
1135        Object[] finderArgs = new Object[] {
1136                new Long(groupId), new Integer(entryCount),
1137                
1138                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1139            };
1140
1141        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_E,
1142                finderArgs, this);
1143
1144        if (list == null) {
1145            Session session = null;
1146
1147            try {
1148                session = openSession();
1149
1150                StringBuilder query = new StringBuilder();
1151
1152                query.append(
1153                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1154
1155                query.append("blogsStatsUser.groupId = ?");
1156
1157                query.append(" AND ");
1158
1159                query.append("blogsStatsUser.entryCount != ?");
1160
1161                query.append(" ");
1162
1163                if (obc != null) {
1164                    query.append("ORDER BY ");
1165
1166                    String[] orderByFields = obc.getOrderByFields();
1167
1168                    for (int i = 0; i < orderByFields.length; i++) {
1169                        query.append("blogsStatsUser.");
1170                        query.append(orderByFields[i]);
1171
1172                        if (obc.isAscending()) {
1173                            query.append(" ASC");
1174                        }
1175                        else {
1176                            query.append(" DESC");
1177                        }
1178
1179                        if ((i + 1) < orderByFields.length) {
1180                            query.append(", ");
1181                        }
1182                    }
1183                }
1184
1185                else {
1186                    query.append("ORDER BY ");
1187
1188                    query.append("blogsStatsUser.entryCount DESC");
1189                }
1190
1191                Query q = session.createQuery(query.toString());
1192
1193                QueryPos qPos = QueryPos.getInstance(q);
1194
1195                qPos.add(groupId);
1196
1197                qPos.add(entryCount);
1198
1199                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1200                        start, end);
1201            }
1202            catch (Exception e) {
1203                throw processException(e);
1204            }
1205            finally {
1206                if (list == null) {
1207                    list = new ArrayList<BlogsStatsUser>();
1208                }
1209
1210                cacheResult(list);
1211
1212                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_E,
1213                    finderArgs, list);
1214
1215                closeSession(session);
1216            }
1217        }
1218
1219        return list;
1220    }
1221
1222    public BlogsStatsUser findByG_E_First(long groupId, int entryCount,
1223        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1224        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, 0, 1, obc);
1225
1226        if (list.isEmpty()) {
1227            StringBuilder msg = new StringBuilder();
1228
1229            msg.append("No BlogsStatsUser exists with the key {");
1230
1231            msg.append("groupId=" + groupId);
1232
1233            msg.append(", ");
1234            msg.append("entryCount=" + entryCount);
1235
1236            msg.append(StringPool.CLOSE_CURLY_BRACE);
1237
1238            throw new NoSuchStatsUserException(msg.toString());
1239        }
1240        else {
1241            return list.get(0);
1242        }
1243    }
1244
1245    public BlogsStatsUser findByG_E_Last(long groupId, int entryCount,
1246        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1247        int count = countByG_E(groupId, entryCount);
1248
1249        List<BlogsStatsUser> list = findByG_E(groupId, entryCount, count - 1,
1250                count, obc);
1251
1252        if (list.isEmpty()) {
1253            StringBuilder msg = new StringBuilder();
1254
1255            msg.append("No BlogsStatsUser exists with the key {");
1256
1257            msg.append("groupId=" + groupId);
1258
1259            msg.append(", ");
1260            msg.append("entryCount=" + entryCount);
1261
1262            msg.append(StringPool.CLOSE_CURLY_BRACE);
1263
1264            throw new NoSuchStatsUserException(msg.toString());
1265        }
1266        else {
1267            return list.get(0);
1268        }
1269    }
1270
1271    public BlogsStatsUser[] findByG_E_PrevAndNext(long statsUserId,
1272        long groupId, int entryCount, OrderByComparator obc)
1273        throws NoSuchStatsUserException, SystemException {
1274        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1275
1276        int count = countByG_E(groupId, entryCount);
1277
1278        Session session = null;
1279
1280        try {
1281            session = openSession();
1282
1283            StringBuilder query = new StringBuilder();
1284
1285            query.append(
1286                "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1287
1288            query.append("blogsStatsUser.groupId = ?");
1289
1290            query.append(" AND ");
1291
1292            query.append("blogsStatsUser.entryCount != ?");
1293
1294            query.append(" ");
1295
1296            if (obc != null) {
1297                query.append("ORDER BY ");
1298
1299                String[] orderByFields = obc.getOrderByFields();
1300
1301                for (int i = 0; i < orderByFields.length; i++) {
1302                    query.append("blogsStatsUser.");
1303                    query.append(orderByFields[i]);
1304
1305                    if (obc.isAscending()) {
1306                        query.append(" ASC");
1307                    }
1308                    else {
1309                        query.append(" DESC");
1310                    }
1311
1312                    if ((i + 1) < orderByFields.length) {
1313                        query.append(", ");
1314                    }
1315                }
1316            }
1317
1318            else {
1319                query.append("ORDER BY ");
1320
1321                query.append("blogsStatsUser.entryCount DESC");
1322            }
1323
1324            Query q = session.createQuery(query.toString());
1325
1326            QueryPos qPos = QueryPos.getInstance(q);
1327
1328            qPos.add(groupId);
1329
1330            qPos.add(entryCount);
1331
1332            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1333                    blogsStatsUser);
1334
1335            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1336
1337            array[0] = (BlogsStatsUser)objArray[0];
1338            array[1] = (BlogsStatsUser)objArray[1];
1339            array[2] = (BlogsStatsUser)objArray[2];
1340
1341            return array;
1342        }
1343        catch (Exception e) {
1344            throw processException(e);
1345        }
1346        finally {
1347            closeSession(session);
1348        }
1349    }
1350
1351    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount)
1352        throws SystemException {
1353        Object[] finderArgs = new Object[] {
1354                new Long(companyId), new Integer(entryCount)
1355            };
1356
1357        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_E,
1358                finderArgs, this);
1359
1360        if (list == null) {
1361            Session session = null;
1362
1363            try {
1364                session = openSession();
1365
1366                StringBuilder query = new StringBuilder();
1367
1368                query.append(
1369                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1370
1371                query.append("blogsStatsUser.companyId = ?");
1372
1373                query.append(" AND ");
1374
1375                query.append("blogsStatsUser.entryCount != ?");
1376
1377                query.append(" ");
1378
1379                query.append("ORDER BY ");
1380
1381                query.append("blogsStatsUser.entryCount DESC");
1382
1383                Query q = session.createQuery(query.toString());
1384
1385                QueryPos qPos = QueryPos.getInstance(q);
1386
1387                qPos.add(companyId);
1388
1389                qPos.add(entryCount);
1390
1391                list = q.list();
1392            }
1393            catch (Exception e) {
1394                throw processException(e);
1395            }
1396            finally {
1397                if (list == null) {
1398                    list = new ArrayList<BlogsStatsUser>();
1399                }
1400
1401                cacheResult(list);
1402
1403                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_E, finderArgs,
1404                    list);
1405
1406                closeSession(session);
1407            }
1408        }
1409
1410        return list;
1411    }
1412
1413    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1414        int start, int end) throws SystemException {
1415        return findByC_E(companyId, entryCount, start, end, null);
1416    }
1417
1418    public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1419        int start, int end, OrderByComparator obc) throws SystemException {
1420        Object[] finderArgs = new Object[] {
1421                new Long(companyId), new Integer(entryCount),
1422                
1423                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1424            };
1425
1426        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_E,
1427                finderArgs, this);
1428
1429        if (list == null) {
1430            Session session = null;
1431
1432            try {
1433                session = openSession();
1434
1435                StringBuilder query = new StringBuilder();
1436
1437                query.append(
1438                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1439
1440                query.append("blogsStatsUser.companyId = ?");
1441
1442                query.append(" AND ");
1443
1444                query.append("blogsStatsUser.entryCount != ?");
1445
1446                query.append(" ");
1447
1448                if (obc != null) {
1449                    query.append("ORDER BY ");
1450
1451                    String[] orderByFields = obc.getOrderByFields();
1452
1453                    for (int i = 0; i < orderByFields.length; i++) {
1454                        query.append("blogsStatsUser.");
1455                        query.append(orderByFields[i]);
1456
1457                        if (obc.isAscending()) {
1458                            query.append(" ASC");
1459                        }
1460                        else {
1461                            query.append(" DESC");
1462                        }
1463
1464                        if ((i + 1) < orderByFields.length) {
1465                            query.append(", ");
1466                        }
1467                    }
1468                }
1469
1470                else {
1471                    query.append("ORDER BY ");
1472
1473                    query.append("blogsStatsUser.entryCount DESC");
1474                }
1475
1476                Query q = session.createQuery(query.toString());
1477
1478                QueryPos qPos = QueryPos.getInstance(q);
1479
1480                qPos.add(companyId);
1481
1482                qPos.add(entryCount);
1483
1484                list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1485                        start, end);
1486            }
1487            catch (Exception e) {
1488                throw processException(e);
1489            }
1490            finally {
1491                if (list == null) {
1492                    list = new ArrayList<BlogsStatsUser>();
1493                }
1494
1495                cacheResult(list);
1496
1497                FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_E,
1498                    finderArgs, list);
1499
1500                closeSession(session);
1501            }
1502        }
1503
1504        return list;
1505    }
1506
1507    public BlogsStatsUser findByC_E_First(long companyId, int entryCount,
1508        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1509        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, 0, 1, obc);
1510
1511        if (list.isEmpty()) {
1512            StringBuilder msg = new StringBuilder();
1513
1514            msg.append("No BlogsStatsUser exists with the key {");
1515
1516            msg.append("companyId=" + companyId);
1517
1518            msg.append(", ");
1519            msg.append("entryCount=" + entryCount);
1520
1521            msg.append(StringPool.CLOSE_CURLY_BRACE);
1522
1523            throw new NoSuchStatsUserException(msg.toString());
1524        }
1525        else {
1526            return list.get(0);
1527        }
1528    }
1529
1530    public BlogsStatsUser findByC_E_Last(long companyId, int entryCount,
1531        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1532        int count = countByC_E(companyId, entryCount);
1533
1534        List<BlogsStatsUser> list = findByC_E(companyId, entryCount, count - 1,
1535                count, obc);
1536
1537        if (list.isEmpty()) {
1538            StringBuilder msg = new StringBuilder();
1539
1540            msg.append("No BlogsStatsUser exists with the key {");
1541
1542            msg.append("companyId=" + companyId);
1543
1544            msg.append(", ");
1545            msg.append("entryCount=" + entryCount);
1546
1547            msg.append(StringPool.CLOSE_CURLY_BRACE);
1548
1549            throw new NoSuchStatsUserException(msg.toString());
1550        }
1551        else {
1552            return list.get(0);
1553        }
1554    }
1555
1556    public BlogsStatsUser[] findByC_E_PrevAndNext(long statsUserId,
1557        long companyId, int entryCount, OrderByComparator obc)
1558        throws NoSuchStatsUserException, SystemException {
1559        BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1560
1561        int count = countByC_E(companyId, entryCount);
1562
1563        Session session = null;
1564
1565        try {
1566            session = openSession();
1567
1568            StringBuilder query = new StringBuilder();
1569
1570            query.append(
1571                "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1572
1573            query.append("blogsStatsUser.companyId = ?");
1574
1575            query.append(" AND ");
1576
1577            query.append("blogsStatsUser.entryCount != ?");
1578
1579            query.append(" ");
1580
1581            if (obc != null) {
1582                query.append("ORDER BY ");
1583
1584                String[] orderByFields = obc.getOrderByFields();
1585
1586                for (int i = 0; i < orderByFields.length; i++) {
1587                    query.append("blogsStatsUser.");
1588                    query.append(orderByFields[i]);
1589
1590                    if (obc.isAscending()) {
1591                        query.append(" ASC");
1592                    }
1593                    else {
1594                        query.append(" DESC");
1595                    }
1596
1597                    if ((i + 1) < orderByFields.length) {
1598                        query.append(", ");
1599                    }
1600                }
1601            }
1602
1603            else {
1604                query.append("ORDER BY ");
1605
1606                query.append("blogsStatsUser.entryCount DESC");
1607            }
1608
1609            Query q = session.createQuery(query.toString());
1610
1611            QueryPos qPos = QueryPos.getInstance(q);
1612
1613            qPos.add(companyId);
1614
1615            qPos.add(entryCount);
1616
1617            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1618                    blogsStatsUser);
1619
1620            BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1621
1622            array[0] = (BlogsStatsUser)objArray[0];
1623            array[1] = (BlogsStatsUser)objArray[1];
1624            array[2] = (BlogsStatsUser)objArray[2];
1625
1626            return array;
1627        }
1628        catch (Exception e) {
1629            throw processException(e);
1630        }
1631        finally {
1632            closeSession(session);
1633        }
1634    }
1635
1636    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1637        throws SystemException {
1638        Session session = null;
1639
1640        try {
1641            session = openSession();
1642
1643            dynamicQuery.compile(session);
1644
1645            return dynamicQuery.list();
1646        }
1647        catch (Exception e) {
1648            throw processException(e);
1649        }
1650        finally {
1651            closeSession(session);
1652        }
1653    }
1654
1655    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1656        int start, int end) throws SystemException {
1657        Session session = null;
1658
1659        try {
1660            session = openSession();
1661
1662            dynamicQuery.setLimit(start, end);
1663
1664            dynamicQuery.compile(session);
1665
1666            return dynamicQuery.list();
1667        }
1668        catch (Exception e) {
1669            throw processException(e);
1670        }
1671        finally {
1672            closeSession(session);
1673        }
1674    }
1675
1676    public List<BlogsStatsUser> findAll() throws SystemException {
1677        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1678    }
1679
1680    public List<BlogsStatsUser> findAll(int start, int end)
1681        throws SystemException {
1682        return findAll(start, end, null);
1683    }
1684
1685    public List<BlogsStatsUser> findAll(int start, int end,
1686        OrderByComparator obc) throws SystemException {
1687        Object[] finderArgs = new Object[] {
1688                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1689            };
1690
1691        List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1692                finderArgs, this);
1693
1694        if (list == null) {
1695            Session session = null;
1696
1697            try {
1698                session = openSession();
1699
1700                StringBuilder query = new StringBuilder();
1701
1702                query.append(
1703                    "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser ");
1704
1705                if (obc != null) {
1706                    query.append("ORDER BY ");
1707
1708                    String[] orderByFields = obc.getOrderByFields();
1709
1710                    for (int i = 0; i < orderByFields.length; i++) {
1711                        query.append("blogsStatsUser.");
1712                        query.append(orderByFields[i]);
1713
1714                        if (obc.isAscending()) {
1715                            query.append(" ASC");
1716                        }
1717                        else {
1718                            query.append(" DESC");
1719                        }
1720
1721                        if ((i + 1) < orderByFields.length) {
1722                            query.append(", ");
1723                        }
1724                    }
1725                }
1726
1727                else {
1728                    query.append("ORDER BY ");
1729
1730                    query.append("blogsStatsUser.entryCount DESC");
1731                }
1732
1733                Query q = session.createQuery(query.toString());
1734
1735                if (obc == null) {
1736                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1737                            getDialect(), start, end, false);
1738
1739                    Collections.sort(list);
1740                }
1741                else {
1742                    list = (List<BlogsStatsUser>)QueryUtil.list(q,
1743                            getDialect(), start, end);
1744                }
1745            }
1746            catch (Exception e) {
1747                throw processException(e);
1748            }
1749            finally {
1750                if (list == null) {
1751                    list = new ArrayList<BlogsStatsUser>();
1752                }
1753
1754                cacheResult(list);
1755
1756                FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1757
1758                closeSession(session);
1759            }
1760        }
1761
1762        return list;
1763    }
1764
1765    public void removeByGroupId(long groupId) throws SystemException {
1766        for (BlogsStatsUser blogsStatsUser : findByGroupId(groupId)) {
1767            remove(blogsStatsUser);
1768        }
1769    }
1770
1771    public void removeByUserId(long userId) throws SystemException {
1772        for (BlogsStatsUser blogsStatsUser : findByUserId(userId)) {
1773            remove(blogsStatsUser);
1774        }
1775    }
1776
1777    public void removeByG_U(long groupId, long userId)
1778        throws NoSuchStatsUserException, SystemException {
1779        BlogsStatsUser blogsStatsUser = findByG_U(groupId, userId);
1780
1781        remove(blogsStatsUser);
1782    }
1783
1784    public void removeByG_E(long groupId, int entryCount)
1785        throws SystemException {
1786        for (BlogsStatsUser blogsStatsUser : findByG_E(groupId, entryCount)) {
1787            remove(blogsStatsUser);
1788        }
1789    }
1790
1791    public void removeByC_E(long companyId, int entryCount)
1792        throws SystemException {
1793        for (BlogsStatsUser blogsStatsUser : findByC_E(companyId, entryCount)) {
1794            remove(blogsStatsUser);
1795        }
1796    }
1797
1798    public void removeAll() throws SystemException {
1799        for (BlogsStatsUser blogsStatsUser : findAll()) {
1800            remove(blogsStatsUser);
1801        }
1802    }
1803
1804    public int countByGroupId(long groupId) throws SystemException {
1805        Object[] finderArgs = new Object[] { new Long(groupId) };
1806
1807        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
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(blogsStatsUser) ");
1819                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1820
1821                query.append("blogsStatsUser.groupId = ?");
1822
1823                query.append(" ");
1824
1825                Query q = session.createQuery(query.toString());
1826
1827                QueryPos qPos = QueryPos.getInstance(q);
1828
1829                qPos.add(groupId);
1830
1831                count = (Long)q.uniqueResult();
1832            }
1833            catch (Exception e) {
1834                throw processException(e);
1835            }
1836            finally {
1837                if (count == null) {
1838                    count = Long.valueOf(0);
1839                }
1840
1841                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1842                    finderArgs, count);
1843
1844                closeSession(session);
1845            }
1846        }
1847
1848        return count.intValue();
1849    }
1850
1851    public int countByUserId(long userId) throws SystemException {
1852        Object[] finderArgs = new Object[] { new Long(userId) };
1853
1854        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1855                finderArgs, this);
1856
1857        if (count == null) {
1858            Session session = null;
1859
1860            try {
1861                session = openSession();
1862
1863                StringBuilder query = new StringBuilder();
1864
1865                query.append("SELECT COUNT(blogsStatsUser) ");
1866                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1867
1868                query.append("blogsStatsUser.userId = ?");
1869
1870                query.append(" ");
1871
1872                Query q = session.createQuery(query.toString());
1873
1874                QueryPos qPos = QueryPos.getInstance(q);
1875
1876                qPos.add(userId);
1877
1878                count = (Long)q.uniqueResult();
1879            }
1880            catch (Exception e) {
1881                throw processException(e);
1882            }
1883            finally {
1884                if (count == null) {
1885                    count = Long.valueOf(0);
1886                }
1887
1888                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1889                    finderArgs, count);
1890
1891                closeSession(session);
1892            }
1893        }
1894
1895        return count.intValue();
1896    }
1897
1898    public int countByG_U(long groupId, long userId) throws SystemException {
1899        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1900
1901        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1902                finderArgs, this);
1903
1904        if (count == null) {
1905            Session session = null;
1906
1907            try {
1908                session = openSession();
1909
1910                StringBuilder query = new StringBuilder();
1911
1912                query.append("SELECT COUNT(blogsStatsUser) ");
1913                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1914
1915                query.append("blogsStatsUser.groupId = ?");
1916
1917                query.append(" AND ");
1918
1919                query.append("blogsStatsUser.userId = ?");
1920
1921                query.append(" ");
1922
1923                Query q = session.createQuery(query.toString());
1924
1925                QueryPos qPos = QueryPos.getInstance(q);
1926
1927                qPos.add(groupId);
1928
1929                qPos.add(userId);
1930
1931                count = (Long)q.uniqueResult();
1932            }
1933            catch (Exception e) {
1934                throw processException(e);
1935            }
1936            finally {
1937                if (count == null) {
1938                    count = Long.valueOf(0);
1939                }
1940
1941                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1942                    count);
1943
1944                closeSession(session);
1945            }
1946        }
1947
1948        return count.intValue();
1949    }
1950
1951    public int countByG_E(long groupId, int entryCount)
1952        throws SystemException {
1953        Object[] finderArgs = new Object[] {
1954                new Long(groupId), new Integer(entryCount)
1955            };
1956
1957        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_E,
1958                finderArgs, this);
1959
1960        if (count == null) {
1961            Session session = null;
1962
1963            try {
1964                session = openSession();
1965
1966                StringBuilder query = new StringBuilder();
1967
1968                query.append("SELECT COUNT(blogsStatsUser) ");
1969                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1970
1971                query.append("blogsStatsUser.groupId = ?");
1972
1973                query.append(" AND ");
1974
1975                query.append("blogsStatsUser.entryCount != ?");
1976
1977                query.append(" ");
1978
1979                Query q = session.createQuery(query.toString());
1980
1981                QueryPos qPos = QueryPos.getInstance(q);
1982
1983                qPos.add(groupId);
1984
1985                qPos.add(entryCount);
1986
1987                count = (Long)q.uniqueResult();
1988            }
1989            catch (Exception e) {
1990                throw processException(e);
1991            }
1992            finally {
1993                if (count == null) {
1994                    count = Long.valueOf(0);
1995                }
1996
1997                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_E, finderArgs,
1998                    count);
1999
2000                closeSession(session);
2001            }
2002        }
2003
2004        return count.intValue();
2005    }
2006
2007    public int countByC_E(long companyId, int entryCount)
2008        throws SystemException {
2009        Object[] finderArgs = new Object[] {
2010                new Long(companyId), new Integer(entryCount)
2011            };
2012
2013        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_E,
2014                finderArgs, this);
2015
2016        if (count == null) {
2017            Session session = null;
2018
2019            try {
2020                session = openSession();
2021
2022                StringBuilder query = new StringBuilder();
2023
2024                query.append("SELECT COUNT(blogsStatsUser) ");
2025                query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
2026
2027                query.append("blogsStatsUser.companyId = ?");
2028
2029                query.append(" AND ");
2030
2031                query.append("blogsStatsUser.entryCount != ?");
2032
2033                query.append(" ");
2034
2035                Query q = session.createQuery(query.toString());
2036
2037                QueryPos qPos = QueryPos.getInstance(q);
2038
2039                qPos.add(companyId);
2040
2041                qPos.add(entryCount);
2042
2043                count = (Long)q.uniqueResult();
2044            }
2045            catch (Exception e) {
2046                throw processException(e);
2047            }
2048            finally {
2049                if (count == null) {
2050                    count = Long.valueOf(0);
2051                }
2052
2053                FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_E, finderArgs,
2054                    count);
2055
2056                closeSession(session);
2057            }
2058        }
2059
2060        return count.intValue();
2061    }
2062
2063    public int countAll() throws SystemException {
2064        Object[] finderArgs = new Object[0];
2065
2066        Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2067                finderArgs, this);
2068
2069        if (count == null) {
2070            Session session = null;
2071
2072            try {
2073                session = openSession();
2074
2075                Query q = session.createQuery(
2076                        "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser");
2077
2078                count = (Long)q.uniqueResult();
2079            }
2080            catch (Exception e) {
2081                throw processException(e);
2082            }
2083            finally {
2084                if (count == null) {
2085                    count = Long.valueOf(0);
2086                }
2087
2088                FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2089                    count);
2090
2091                closeSession(session);
2092            }
2093        }
2094
2095        return count.intValue();
2096    }
2097
2098    public void afterPropertiesSet() {
2099        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2100                    com.liferay.portal.util.PropsUtil.get(
2101                        "value.object.listener.com.liferay.portlet.blogs.model.BlogsStatsUser")));
2102
2103        if (listenerClassNames.length > 0) {
2104            try {
2105                List<ModelListener<BlogsStatsUser>> listenersList = new ArrayList<ModelListener<BlogsStatsUser>>();
2106
2107                for (String listenerClassName : listenerClassNames) {
2108                    listenersList.add((ModelListener<BlogsStatsUser>)Class.forName(
2109                            listenerClassName).newInstance());
2110                }
2111
2112                listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2113            }
2114            catch (Exception e) {
2115                _log.error(e);
2116            }
2117        }
2118    }
2119
2120    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
2121    protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
2122    @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence.impl")
2123    protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
2124    @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
2125    protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2126    private static Log _log = LogFactoryUtil.getLog(BlogsStatsUserPersistenceImpl.class);
2127}