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