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.messageboards.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.dao.DynamicQuery;
27  import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28  import com.liferay.portal.kernel.util.GetterUtil;
29  import com.liferay.portal.kernel.util.OrderByComparator;
30  import com.liferay.portal.kernel.util.StringMaker;
31  import com.liferay.portal.kernel.util.StringPool;
32  import com.liferay.portal.kernel.util.Validator;
33  import com.liferay.portal.model.ModelListener;
34  import com.liferay.portal.service.persistence.BasePersistence;
35  import com.liferay.portal.spring.hibernate.FinderCache;
36  import com.liferay.portal.spring.hibernate.HibernateUtil;
37  import com.liferay.portal.util.PropsUtil;
38  
39  import com.liferay.portlet.messageboards.NoSuchStatsUserException;
40  import com.liferay.portlet.messageboards.model.MBStatsUser;
41  import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
42  import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
43  
44  import com.liferay.util.dao.hibernate.QueryUtil;
45  
46  import org.apache.commons.logging.Log;
47  import org.apache.commons.logging.LogFactory;
48  
49  import org.hibernate.Query;
50  import org.hibernate.Session;
51  
52  import java.util.Collections;
53  import java.util.Iterator;
54  import java.util.List;
55  
56  /**
57   * <a href="MBStatsUserPersistenceImpl.java.html"><b><i>View Source</i></b></a>
58   *
59   * @author Brian Wing Shun Chan
60   *
61   */
62  public class MBStatsUserPersistenceImpl extends BasePersistence
63      implements MBStatsUserPersistence {
64      public MBStatsUser create(long statsUserId) {
65          MBStatsUser mbStatsUser = new MBStatsUserImpl();
66  
67          mbStatsUser.setNew(true);
68          mbStatsUser.setPrimaryKey(statsUserId);
69  
70          return mbStatsUser;
71      }
72  
73      public MBStatsUser remove(long statsUserId)
74          throws NoSuchStatsUserException, SystemException {
75          Session session = null;
76  
77          try {
78              session = openSession();
79  
80              MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
81                      new Long(statsUserId));
82  
83              if (mbStatsUser == null) {
84                  if (_log.isWarnEnabled()) {
85                      _log.warn("No MBStatsUser exists with the primary key " +
86                          statsUserId);
87                  }
88  
89                  throw new NoSuchStatsUserException(
90                      "No MBStatsUser exists with the primary key " +
91                      statsUserId);
92              }
93  
94              return remove(mbStatsUser);
95          }
96          catch (NoSuchStatsUserException nsee) {
97              throw nsee;
98          }
99          catch (Exception e) {
100             throw HibernateUtil.processException(e);
101         }
102         finally {
103             closeSession(session);
104         }
105     }
106 
107     public MBStatsUser remove(MBStatsUser mbStatsUser)
108         throws SystemException {
109         ModelListener listener = _getListener();
110 
111         if (listener != null) {
112             listener.onBeforeRemove(mbStatsUser);
113         }
114 
115         mbStatsUser = removeImpl(mbStatsUser);
116 
117         if (listener != null) {
118             listener.onAfterRemove(mbStatsUser);
119         }
120 
121         return mbStatsUser;
122     }
123 
124     protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
125         throws SystemException {
126         Session session = null;
127 
128         try {
129             session = openSession();
130 
131             session.delete(mbStatsUser);
132 
133             session.flush();
134 
135             return mbStatsUser;
136         }
137         catch (Exception e) {
138             throw HibernateUtil.processException(e);
139         }
140         finally {
141             closeSession(session);
142 
143             FinderCache.clearCache(MBStatsUser.class.getName());
144         }
145     }
146 
147     public MBStatsUser update(MBStatsUser mbStatsUser)
148         throws SystemException {
149         return update(mbStatsUser, false);
150     }
151 
152     public MBStatsUser update(MBStatsUser mbStatsUser, boolean merge)
153         throws SystemException {
154         ModelListener listener = _getListener();
155 
156         boolean isNew = mbStatsUser.isNew();
157 
158         if (listener != null) {
159             if (isNew) {
160                 listener.onBeforeCreate(mbStatsUser);
161             }
162             else {
163                 listener.onBeforeUpdate(mbStatsUser);
164             }
165         }
166 
167         mbStatsUser = updateImpl(mbStatsUser, merge);
168 
169         if (listener != null) {
170             if (isNew) {
171                 listener.onAfterCreate(mbStatsUser);
172             }
173             else {
174                 listener.onAfterUpdate(mbStatsUser);
175             }
176         }
177 
178         return mbStatsUser;
179     }
180 
181     public MBStatsUser updateImpl(
182         com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
183         boolean merge) throws SystemException {
184         Session session = null;
185 
186         try {
187             session = openSession();
188 
189             if (merge) {
190                 session.merge(mbStatsUser);
191             }
192             else {
193                 if (mbStatsUser.isNew()) {
194                     session.save(mbStatsUser);
195                 }
196             }
197 
198             session.flush();
199 
200             mbStatsUser.setNew(false);
201 
202             return mbStatsUser;
203         }
204         catch (Exception e) {
205             throw HibernateUtil.processException(e);
206         }
207         finally {
208             closeSession(session);
209 
210             FinderCache.clearCache(MBStatsUser.class.getName());
211         }
212     }
213 
214     public MBStatsUser findByPrimaryKey(long statsUserId)
215         throws NoSuchStatsUserException, SystemException {
216         MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
217 
218         if (mbStatsUser == null) {
219             if (_log.isWarnEnabled()) {
220                 _log.warn("No MBStatsUser exists with the primary key " +
221                     statsUserId);
222             }
223 
224             throw new NoSuchStatsUserException(
225                 "No MBStatsUser exists with the primary key " + statsUserId);
226         }
227 
228         return mbStatsUser;
229     }
230 
231     public MBStatsUser fetchByPrimaryKey(long statsUserId)
232         throws SystemException {
233         Session session = null;
234 
235         try {
236             session = openSession();
237 
238             return (MBStatsUser)session.get(MBStatsUserImpl.class,
239                 new Long(statsUserId));
240         }
241         catch (Exception e) {
242             throw HibernateUtil.processException(e);
243         }
244         finally {
245             closeSession(session);
246         }
247     }
248 
249     public List findByGroupId(long groupId) throws SystemException {
250         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
251         String finderClassName = MBStatsUser.class.getName();
252         String finderMethodName = "findByGroupId";
253         String[] finderParams = new String[] { Long.class.getName() };
254         Object[] finderArgs = new Object[] { new Long(groupId) };
255 
256         Object result = null;
257 
258         if (finderClassNameCacheEnabled) {
259             result = FinderCache.getResult(finderClassName, finderMethodName,
260                     finderParams, finderArgs, getSessionFactory());
261         }
262 
263         if (result == null) {
264             Session session = null;
265 
266             try {
267                 session = openSession();
268 
269                 StringMaker query = new StringMaker();
270 
271                 query.append(
272                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
273 
274                 query.append("groupId = ?");
275 
276                 query.append(" ");
277 
278                 query.append("ORDER BY ");
279 
280                 query.append("messageCount DESC");
281 
282                 Query q = session.createQuery(query.toString());
283 
284                 int queryPos = 0;
285 
286                 q.setLong(queryPos++, groupId);
287 
288                 List list = q.list();
289 
290                 FinderCache.putResult(finderClassNameCacheEnabled,
291                     finderClassName, finderMethodName, finderParams,
292                     finderArgs, list);
293 
294                 return list;
295             }
296             catch (Exception e) {
297                 throw HibernateUtil.processException(e);
298             }
299             finally {
300                 closeSession(session);
301             }
302         }
303         else {
304             return (List)result;
305         }
306     }
307 
308     public List findByGroupId(long groupId, int begin, int end)
309         throws SystemException {
310         return findByGroupId(groupId, begin, end, null);
311     }
312 
313     public List findByGroupId(long groupId, int begin, int end,
314         OrderByComparator obc) throws SystemException {
315         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
316         String finderClassName = MBStatsUser.class.getName();
317         String finderMethodName = "findByGroupId";
318         String[] finderParams = new String[] {
319                 Long.class.getName(),
320                 
321                 "java.lang.Integer", "java.lang.Integer",
322                 "com.liferay.portal.kernel.util.OrderByComparator"
323             };
324         Object[] finderArgs = new Object[] {
325                 new Long(groupId),
326                 
327                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
328             };
329 
330         Object result = null;
331 
332         if (finderClassNameCacheEnabled) {
333             result = FinderCache.getResult(finderClassName, finderMethodName,
334                     finderParams, finderArgs, getSessionFactory());
335         }
336 
337         if (result == null) {
338             Session session = null;
339 
340             try {
341                 session = openSession();
342 
343                 StringMaker query = new StringMaker();
344 
345                 query.append(
346                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
347 
348                 query.append("groupId = ?");
349 
350                 query.append(" ");
351 
352                 if (obc != null) {
353                     query.append("ORDER BY ");
354                     query.append(obc.getOrderBy());
355                 }
356 
357                 else {
358                     query.append("ORDER BY ");
359 
360                     query.append("messageCount DESC");
361                 }
362 
363                 Query q = session.createQuery(query.toString());
364 
365                 int queryPos = 0;
366 
367                 q.setLong(queryPos++, groupId);
368 
369                 List list = QueryUtil.list(q, getDialect(), begin, end);
370 
371                 FinderCache.putResult(finderClassNameCacheEnabled,
372                     finderClassName, finderMethodName, finderParams,
373                     finderArgs, list);
374 
375                 return list;
376             }
377             catch (Exception e) {
378                 throw HibernateUtil.processException(e);
379             }
380             finally {
381                 closeSession(session);
382             }
383         }
384         else {
385             return (List)result;
386         }
387     }
388 
389     public MBStatsUser findByGroupId_First(long groupId, OrderByComparator obc)
390         throws NoSuchStatsUserException, SystemException {
391         List list = findByGroupId(groupId, 0, 1, obc);
392 
393         if (list.size() == 0) {
394             StringMaker msg = new StringMaker();
395 
396             msg.append("No MBStatsUser exists with the key {");
397 
398             msg.append("groupId=" + groupId);
399 
400             msg.append(StringPool.CLOSE_CURLY_BRACE);
401 
402             throw new NoSuchStatsUserException(msg.toString());
403         }
404         else {
405             return (MBStatsUser)list.get(0);
406         }
407     }
408 
409     public MBStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
410         throws NoSuchStatsUserException, SystemException {
411         int count = countByGroupId(groupId);
412 
413         List list = findByGroupId(groupId, count - 1, count, obc);
414 
415         if (list.size() == 0) {
416             StringMaker msg = new StringMaker();
417 
418             msg.append("No MBStatsUser exists with the key {");
419 
420             msg.append("groupId=" + groupId);
421 
422             msg.append(StringPool.CLOSE_CURLY_BRACE);
423 
424             throw new NoSuchStatsUserException(msg.toString());
425         }
426         else {
427             return (MBStatsUser)list.get(0);
428         }
429     }
430 
431     public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
432         long groupId, OrderByComparator obc)
433         throws NoSuchStatsUserException, SystemException {
434         MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
435 
436         int count = countByGroupId(groupId);
437 
438         Session session = null;
439 
440         try {
441             session = openSession();
442 
443             StringMaker query = new StringMaker();
444 
445             query.append(
446                 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
447 
448             query.append("groupId = ?");
449 
450             query.append(" ");
451 
452             if (obc != null) {
453                 query.append("ORDER BY ");
454                 query.append(obc.getOrderBy());
455             }
456 
457             else {
458                 query.append("ORDER BY ");
459 
460                 query.append("messageCount DESC");
461             }
462 
463             Query q = session.createQuery(query.toString());
464 
465             int queryPos = 0;
466 
467             q.setLong(queryPos++, groupId);
468 
469             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
470                     mbStatsUser);
471 
472             MBStatsUser[] array = new MBStatsUserImpl[3];
473 
474             array[0] = (MBStatsUser)objArray[0];
475             array[1] = (MBStatsUser)objArray[1];
476             array[2] = (MBStatsUser)objArray[2];
477 
478             return array;
479         }
480         catch (Exception e) {
481             throw HibernateUtil.processException(e);
482         }
483         finally {
484             closeSession(session);
485         }
486     }
487 
488     public List findByUserId(long userId) throws SystemException {
489         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
490         String finderClassName = MBStatsUser.class.getName();
491         String finderMethodName = "findByUserId";
492         String[] finderParams = new String[] { Long.class.getName() };
493         Object[] finderArgs = new Object[] { new Long(userId) };
494 
495         Object result = null;
496 
497         if (finderClassNameCacheEnabled) {
498             result = FinderCache.getResult(finderClassName, finderMethodName,
499                     finderParams, finderArgs, getSessionFactory());
500         }
501 
502         if (result == null) {
503             Session session = null;
504 
505             try {
506                 session = openSession();
507 
508                 StringMaker query = new StringMaker();
509 
510                 query.append(
511                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
512 
513                 query.append("userId = ?");
514 
515                 query.append(" ");
516 
517                 query.append("ORDER BY ");
518 
519                 query.append("messageCount DESC");
520 
521                 Query q = session.createQuery(query.toString());
522 
523                 int queryPos = 0;
524 
525                 q.setLong(queryPos++, userId);
526 
527                 List list = q.list();
528 
529                 FinderCache.putResult(finderClassNameCacheEnabled,
530                     finderClassName, finderMethodName, finderParams,
531                     finderArgs, list);
532 
533                 return list;
534             }
535             catch (Exception e) {
536                 throw HibernateUtil.processException(e);
537             }
538             finally {
539                 closeSession(session);
540             }
541         }
542         else {
543             return (List)result;
544         }
545     }
546 
547     public List findByUserId(long userId, int begin, int end)
548         throws SystemException {
549         return findByUserId(userId, begin, end, null);
550     }
551 
552     public List findByUserId(long userId, int begin, int end,
553         OrderByComparator obc) throws SystemException {
554         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
555         String finderClassName = MBStatsUser.class.getName();
556         String finderMethodName = "findByUserId";
557         String[] finderParams = new String[] {
558                 Long.class.getName(),
559                 
560                 "java.lang.Integer", "java.lang.Integer",
561                 "com.liferay.portal.kernel.util.OrderByComparator"
562             };
563         Object[] finderArgs = new Object[] {
564                 new Long(userId),
565                 
566                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
567             };
568 
569         Object result = null;
570 
571         if (finderClassNameCacheEnabled) {
572             result = FinderCache.getResult(finderClassName, finderMethodName,
573                     finderParams, finderArgs, getSessionFactory());
574         }
575 
576         if (result == null) {
577             Session session = null;
578 
579             try {
580                 session = openSession();
581 
582                 StringMaker query = new StringMaker();
583 
584                 query.append(
585                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
586 
587                 query.append("userId = ?");
588 
589                 query.append(" ");
590 
591                 if (obc != null) {
592                     query.append("ORDER BY ");
593                     query.append(obc.getOrderBy());
594                 }
595 
596                 else {
597                     query.append("ORDER BY ");
598 
599                     query.append("messageCount DESC");
600                 }
601 
602                 Query q = session.createQuery(query.toString());
603 
604                 int queryPos = 0;
605 
606                 q.setLong(queryPos++, userId);
607 
608                 List list = QueryUtil.list(q, getDialect(), begin, end);
609 
610                 FinderCache.putResult(finderClassNameCacheEnabled,
611                     finderClassName, finderMethodName, finderParams,
612                     finderArgs, list);
613 
614                 return list;
615             }
616             catch (Exception e) {
617                 throw HibernateUtil.processException(e);
618             }
619             finally {
620                 closeSession(session);
621             }
622         }
623         else {
624             return (List)result;
625         }
626     }
627 
628     public MBStatsUser findByUserId_First(long userId, OrderByComparator obc)
629         throws NoSuchStatsUserException, SystemException {
630         List list = findByUserId(userId, 0, 1, obc);
631 
632         if (list.size() == 0) {
633             StringMaker msg = new StringMaker();
634 
635             msg.append("No MBStatsUser exists with the key {");
636 
637             msg.append("userId=" + userId);
638 
639             msg.append(StringPool.CLOSE_CURLY_BRACE);
640 
641             throw new NoSuchStatsUserException(msg.toString());
642         }
643         else {
644             return (MBStatsUser)list.get(0);
645         }
646     }
647 
648     public MBStatsUser findByUserId_Last(long userId, OrderByComparator obc)
649         throws NoSuchStatsUserException, SystemException {
650         int count = countByUserId(userId);
651 
652         List list = findByUserId(userId, count - 1, count, obc);
653 
654         if (list.size() == 0) {
655             StringMaker msg = new StringMaker();
656 
657             msg.append("No MBStatsUser exists with the key {");
658 
659             msg.append("userId=" + userId);
660 
661             msg.append(StringPool.CLOSE_CURLY_BRACE);
662 
663             throw new NoSuchStatsUserException(msg.toString());
664         }
665         else {
666             return (MBStatsUser)list.get(0);
667         }
668     }
669 
670     public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
671         long userId, OrderByComparator obc)
672         throws NoSuchStatsUserException, SystemException {
673         MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
674 
675         int count = countByUserId(userId);
676 
677         Session session = null;
678 
679         try {
680             session = openSession();
681 
682             StringMaker query = new StringMaker();
683 
684             query.append(
685                 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
686 
687             query.append("userId = ?");
688 
689             query.append(" ");
690 
691             if (obc != null) {
692                 query.append("ORDER BY ");
693                 query.append(obc.getOrderBy());
694             }
695 
696             else {
697                 query.append("ORDER BY ");
698 
699                 query.append("messageCount DESC");
700             }
701 
702             Query q = session.createQuery(query.toString());
703 
704             int queryPos = 0;
705 
706             q.setLong(queryPos++, userId);
707 
708             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
709                     mbStatsUser);
710 
711             MBStatsUser[] array = new MBStatsUserImpl[3];
712 
713             array[0] = (MBStatsUser)objArray[0];
714             array[1] = (MBStatsUser)objArray[1];
715             array[2] = (MBStatsUser)objArray[2];
716 
717             return array;
718         }
719         catch (Exception e) {
720             throw HibernateUtil.processException(e);
721         }
722         finally {
723             closeSession(session);
724         }
725     }
726 
727     public MBStatsUser findByG_U(long groupId, long userId)
728         throws NoSuchStatsUserException, SystemException {
729         MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
730 
731         if (mbStatsUser == null) {
732             StringMaker msg = new StringMaker();
733 
734             msg.append("No MBStatsUser exists with the key {");
735 
736             msg.append("groupId=" + groupId);
737 
738             msg.append(", ");
739             msg.append("userId=" + userId);
740 
741             msg.append(StringPool.CLOSE_CURLY_BRACE);
742 
743             if (_log.isWarnEnabled()) {
744                 _log.warn(msg.toString());
745             }
746 
747             throw new NoSuchStatsUserException(msg.toString());
748         }
749 
750         return mbStatsUser;
751     }
752 
753     public MBStatsUser fetchByG_U(long groupId, long userId)
754         throws SystemException {
755         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
756         String finderClassName = MBStatsUser.class.getName();
757         String finderMethodName = "fetchByG_U";
758         String[] finderParams = new String[] {
759                 Long.class.getName(), Long.class.getName()
760             };
761         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
762 
763         Object result = null;
764 
765         if (finderClassNameCacheEnabled) {
766             result = FinderCache.getResult(finderClassName, finderMethodName,
767                     finderParams, finderArgs, getSessionFactory());
768         }
769 
770         if (result == null) {
771             Session session = null;
772 
773             try {
774                 session = openSession();
775 
776                 StringMaker query = new StringMaker();
777 
778                 query.append(
779                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
780 
781                 query.append("groupId = ?");
782 
783                 query.append(" AND ");
784 
785                 query.append("userId = ?");
786 
787                 query.append(" ");
788 
789                 query.append("ORDER BY ");
790 
791                 query.append("messageCount DESC");
792 
793                 Query q = session.createQuery(query.toString());
794 
795                 int queryPos = 0;
796 
797                 q.setLong(queryPos++, groupId);
798 
799                 q.setLong(queryPos++, userId);
800 
801                 List list = q.list();
802 
803                 FinderCache.putResult(finderClassNameCacheEnabled,
804                     finderClassName, finderMethodName, finderParams,
805                     finderArgs, list);
806 
807                 if (list.size() == 0) {
808                     return null;
809                 }
810                 else {
811                     return (MBStatsUser)list.get(0);
812                 }
813             }
814             catch (Exception e) {
815                 throw HibernateUtil.processException(e);
816             }
817             finally {
818                 closeSession(session);
819             }
820         }
821         else {
822             List list = (List)result;
823 
824             if (list.size() == 0) {
825                 return null;
826             }
827             else {
828                 return (MBStatsUser)list.get(0);
829             }
830         }
831     }
832 
833     public List findByG_M(long groupId, int messageCount)
834         throws SystemException {
835         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
836         String finderClassName = MBStatsUser.class.getName();
837         String finderMethodName = "findByG_M";
838         String[] finderParams = new String[] {
839                 Long.class.getName(), Integer.class.getName()
840             };
841         Object[] finderArgs = new Object[] {
842                 new Long(groupId), new Integer(messageCount)
843             };
844 
845         Object result = null;
846 
847         if (finderClassNameCacheEnabled) {
848             result = FinderCache.getResult(finderClassName, finderMethodName,
849                     finderParams, finderArgs, getSessionFactory());
850         }
851 
852         if (result == null) {
853             Session session = null;
854 
855             try {
856                 session = openSession();
857 
858                 StringMaker query = new StringMaker();
859 
860                 query.append(
861                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
862 
863                 query.append("groupId = ?");
864 
865                 query.append(" AND ");
866 
867                 query.append("messageCount != ?");
868 
869                 query.append(" ");
870 
871                 query.append("ORDER BY ");
872 
873                 query.append("messageCount DESC");
874 
875                 Query q = session.createQuery(query.toString());
876 
877                 int queryPos = 0;
878 
879                 q.setLong(queryPos++, groupId);
880 
881                 q.setInteger(queryPos++, messageCount);
882 
883                 List list = q.list();
884 
885                 FinderCache.putResult(finderClassNameCacheEnabled,
886                     finderClassName, finderMethodName, finderParams,
887                     finderArgs, list);
888 
889                 return list;
890             }
891             catch (Exception e) {
892                 throw HibernateUtil.processException(e);
893             }
894             finally {
895                 closeSession(session);
896             }
897         }
898         else {
899             return (List)result;
900         }
901     }
902 
903     public List findByG_M(long groupId, int messageCount, int begin, int end)
904         throws SystemException {
905         return findByG_M(groupId, messageCount, begin, end, null);
906     }
907 
908     public List findByG_M(long groupId, int messageCount, int begin, int end,
909         OrderByComparator obc) throws SystemException {
910         boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
911         String finderClassName = MBStatsUser.class.getName();
912         String finderMethodName = "findByG_M";
913         String[] finderParams = new String[] {
914                 Long.class.getName(), Integer.class.getName(),
915                 
916                 "java.lang.Integer", "java.lang.Integer",
917                 "com.liferay.portal.kernel.util.OrderByComparator"
918             };
919         Object[] finderArgs = new Object[] {
920                 new Long(groupId), new Integer(messageCount),
921                 
922                 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
923             };
924 
925         Object result = null;
926 
927         if (finderClassNameCacheEnabled) {
928             result = FinderCache.getResult(finderClassName, finderMethodName,
929                     finderParams, finderArgs, getSessionFactory());
930         }
931 
932         if (result == null) {
933             Session session = null;
934 
935             try {
936                 session = openSession();
937 
938                 StringMaker query = new StringMaker();
939 
940                 query.append(
941                     "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
942 
943                 query.append("groupId = ?");
944 
945                 query.append(" AND ");
946 
947                 query.append("messageCount != ?");
948 
949                 query.append(" ");
950 
951                 if (obc != null) {
952                     query.append("ORDER BY ");
953                     query.append(obc.getOrderBy());
954                 }
955 
956                 else {
957                     query.append("ORDER BY ");
958 
959                     query.append("messageCount DESC");
960                 }
961 
962                 Query q = session.createQuery(query.toString());
963 
964                 int queryPos = 0;
965 
966                 q.setLong(queryPos++, groupId);
967 
968                 q.setInteger(queryPos++, messageCount);
969 
970                 List list = QueryUtil.list(q, getDialect(), begin, end);
971 
972                 FinderCache.putResult(finderClassNameCacheEnabled,
973                     finderClassName, finderMethodName, finderParams,
974                     finderArgs, list);
975 
976                 return list;
977             }
978             catch (Exception e) {
979                 throw HibernateUtil.processException(e);
980             }
981             finally {
982                 closeSession(session);
983             }
984         }
985         else {
986             return (List)result;
987         }
988     }
989 
990     public MBStatsUser findByG_M_First(long groupId, int messageCount,
991         OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
992         List list = findByG_M(groupId, messageCount, 0, 1, obc);
993 
994         if (list.size() == 0) {
995             StringMaker msg = new StringMaker();
996 
997             msg.append("No MBStatsUser exists with the key {");
998 
999             msg.append("groupId=" + groupId);
1000
1001            msg.append(", ");
1002            msg.append("messageCount=" + messageCount);
1003
1004            msg.append(StringPool.CLOSE_CURLY_BRACE);
1005
1006            throw new NoSuchStatsUserException(msg.toString());
1007        }
1008        else {
1009            return (MBStatsUser)list.get(0);
1010        }
1011    }
1012
1013    public MBStatsUser findByG_M_Last(long groupId, int messageCount,
1014        OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1015        int count = countByG_M(groupId, messageCount);
1016
1017        List list = findByG_M(groupId, messageCount, count - 1, count, obc);
1018
1019        if (list.size() == 0) {
1020            StringMaker msg = new StringMaker();
1021
1022            msg.append("No MBStatsUser exists with the key {");
1023
1024            msg.append("groupId=" + groupId);
1025
1026            msg.append(", ");
1027            msg.append("messageCount=" + messageCount);
1028
1029            msg.append(StringPool.CLOSE_CURLY_BRACE);
1030
1031            throw new NoSuchStatsUserException(msg.toString());
1032        }
1033        else {
1034            return (MBStatsUser)list.get(0);
1035        }
1036    }
1037
1038    public MBStatsUser[] findByG_M_PrevAndNext(long statsUserId, long groupId,
1039        int messageCount, OrderByComparator obc)
1040        throws NoSuchStatsUserException, SystemException {
1041        MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1042
1043        int count = countByG_M(groupId, messageCount);
1044
1045        Session session = null;
1046
1047        try {
1048            session = openSession();
1049
1050            StringMaker query = new StringMaker();
1051
1052            query.append(
1053                "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1054
1055            query.append("groupId = ?");
1056
1057            query.append(" AND ");
1058
1059            query.append("messageCount != ?");
1060
1061            query.append(" ");
1062
1063            if (obc != null) {
1064                query.append("ORDER BY ");
1065                query.append(obc.getOrderBy());
1066            }
1067
1068            else {
1069                query.append("ORDER BY ");
1070
1071                query.append("messageCount DESC");
1072            }
1073
1074            Query q = session.createQuery(query.toString());
1075
1076            int queryPos = 0;
1077
1078            q.setLong(queryPos++, groupId);
1079
1080            q.setInteger(queryPos++, messageCount);
1081
1082            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1083                    mbStatsUser);
1084
1085            MBStatsUser[] array = new MBStatsUserImpl[3];
1086
1087            array[0] = (MBStatsUser)objArray[0];
1088            array[1] = (MBStatsUser)objArray[1];
1089            array[2] = (MBStatsUser)objArray[2];
1090
1091            return array;
1092        }
1093        catch (Exception e) {
1094            throw HibernateUtil.processException(e);
1095        }
1096        finally {
1097            closeSession(session);
1098        }
1099    }
1100
1101    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1102        throws SystemException {
1103        Session session = null;
1104
1105        try {
1106            session = openSession();
1107
1108            DynamicQuery query = queryInitializer.initialize(session);
1109
1110            return query.list();
1111        }
1112        catch (Exception e) {
1113            throw HibernateUtil.processException(e);
1114        }
1115        finally {
1116            closeSession(session);
1117        }
1118    }
1119
1120    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1121        int begin, int end) throws SystemException {
1122        Session session = null;
1123
1124        try {
1125            session = openSession();
1126
1127            DynamicQuery query = queryInitializer.initialize(session);
1128
1129            query.setLimit(begin, end);
1130
1131            return query.list();
1132        }
1133        catch (Exception e) {
1134            throw HibernateUtil.processException(e);
1135        }
1136        finally {
1137            closeSession(session);
1138        }
1139    }
1140
1141    public List findAll() throws SystemException {
1142        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1143    }
1144
1145    public List findAll(int begin, int end) throws SystemException {
1146        return findAll(begin, end, null);
1147    }
1148
1149    public List findAll(int begin, int end, OrderByComparator obc)
1150        throws SystemException {
1151        boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1152        String finderClassName = MBStatsUser.class.getName();
1153        String finderMethodName = "findAll";
1154        String[] finderParams = new String[] {
1155                "java.lang.Integer", "java.lang.Integer",
1156                "com.liferay.portal.kernel.util.OrderByComparator"
1157            };
1158        Object[] finderArgs = new Object[] {
1159                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1160            };
1161
1162        Object result = null;
1163
1164        if (finderClassNameCacheEnabled) {
1165            result = FinderCache.getResult(finderClassName, finderMethodName,
1166                    finderParams, finderArgs, getSessionFactory());
1167        }
1168
1169        if (result == null) {
1170            Session session = null;
1171
1172            try {
1173                session = openSession();
1174
1175                StringMaker query = new StringMaker();
1176
1177                query.append(
1178                    "FROM com.liferay.portlet.messageboards.model.MBStatsUser ");
1179
1180                if (obc != null) {
1181                    query.append("ORDER BY ");
1182                    query.append(obc.getOrderBy());
1183                }
1184
1185                else {
1186                    query.append("ORDER BY ");
1187
1188                    query.append("messageCount DESC");
1189                }
1190
1191                Query q = session.createQuery(query.toString());
1192
1193                List list = QueryUtil.list(q, getDialect(), begin, end);
1194
1195                if (obc == null) {
1196                    Collections.sort(list);
1197                }
1198
1199                FinderCache.putResult(finderClassNameCacheEnabled,
1200                    finderClassName, finderMethodName, finderParams,
1201                    finderArgs, list);
1202
1203                return list;
1204            }
1205            catch (Exception e) {
1206                throw HibernateUtil.processException(e);
1207            }
1208            finally {
1209                closeSession(session);
1210            }
1211        }
1212        else {
1213            return (List)result;
1214        }
1215    }
1216
1217    public void removeByGroupId(long groupId) throws SystemException {
1218        Iterator itr = findByGroupId(groupId).iterator();
1219
1220        while (itr.hasNext()) {
1221            MBStatsUser mbStatsUser = (MBStatsUser)itr.next();
1222
1223            remove(mbStatsUser);
1224        }
1225    }
1226
1227    public void removeByUserId(long userId) throws SystemException {
1228        Iterator itr = findByUserId(userId).iterator();
1229
1230        while (itr.hasNext()) {
1231            MBStatsUser mbStatsUser = (MBStatsUser)itr.next();
1232
1233            remove(mbStatsUser);
1234        }
1235    }
1236
1237    public void removeByG_U(long groupId, long userId)
1238        throws NoSuchStatsUserException, SystemException {
1239        MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1240
1241        remove(mbStatsUser);
1242    }
1243
1244    public void removeByG_M(long groupId, int messageCount)
1245        throws SystemException {
1246        Iterator itr = findByG_M(groupId, messageCount).iterator();
1247
1248        while (itr.hasNext()) {
1249            MBStatsUser mbStatsUser = (MBStatsUser)itr.next();
1250
1251            remove(mbStatsUser);
1252        }
1253    }
1254
1255    public void removeAll() throws SystemException {
1256        Iterator itr = findAll().iterator();
1257
1258        while (itr.hasNext()) {
1259            remove((MBStatsUser)itr.next());
1260        }
1261    }
1262
1263    public int countByGroupId(long groupId) throws SystemException {
1264        boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1265        String finderClassName = MBStatsUser.class.getName();
1266        String finderMethodName = "countByGroupId";
1267        String[] finderParams = new String[] { Long.class.getName() };
1268        Object[] finderArgs = new Object[] { new Long(groupId) };
1269
1270        Object result = null;
1271
1272        if (finderClassNameCacheEnabled) {
1273            result = FinderCache.getResult(finderClassName, finderMethodName,
1274                    finderParams, finderArgs, getSessionFactory());
1275        }
1276
1277        if (result == null) {
1278            Session session = null;
1279
1280            try {
1281                session = openSession();
1282
1283                StringMaker query = new StringMaker();
1284
1285                query.append("SELECT COUNT(*) ");
1286                query.append(
1287                    "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1288
1289                query.append("groupId = ?");
1290
1291                query.append(" ");
1292
1293                Query q = session.createQuery(query.toString());
1294
1295                int queryPos = 0;
1296
1297                q.setLong(queryPos++, groupId);
1298
1299                Long count = null;
1300
1301                Iterator itr = q.list().iterator();
1302
1303                if (itr.hasNext()) {
1304                    count = (Long)itr.next();
1305                }
1306
1307                if (count == null) {
1308                    count = new Long(0);
1309                }
1310
1311                FinderCache.putResult(finderClassNameCacheEnabled,
1312                    finderClassName, finderMethodName, finderParams,
1313                    finderArgs, count);
1314
1315                return count.intValue();
1316            }
1317            catch (Exception e) {
1318                throw HibernateUtil.processException(e);
1319            }
1320            finally {
1321                closeSession(session);
1322            }
1323        }
1324        else {
1325            return ((Long)result).intValue();
1326        }
1327    }
1328
1329    public int countByUserId(long userId) throws SystemException {
1330        boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1331        String finderClassName = MBStatsUser.class.getName();
1332        String finderMethodName = "countByUserId";
1333        String[] finderParams = new String[] { Long.class.getName() };
1334        Object[] finderArgs = new Object[] { new Long(userId) };
1335
1336        Object result = null;
1337
1338        if (finderClassNameCacheEnabled) {
1339            result = FinderCache.getResult(finderClassName, finderMethodName,
1340                    finderParams, finderArgs, getSessionFactory());
1341        }
1342
1343        if (result == null) {
1344            Session session = null;
1345
1346            try {
1347                session = openSession();
1348
1349                StringMaker query = new StringMaker();
1350
1351                query.append("SELECT COUNT(*) ");
1352                query.append(
1353                    "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1354
1355                query.append("userId = ?");
1356
1357                query.append(" ");
1358
1359                Query q = session.createQuery(query.toString());
1360
1361                int queryPos = 0;
1362
1363                q.setLong(queryPos++, userId);
1364
1365                Long count = null;
1366
1367                Iterator itr = q.list().iterator();
1368
1369                if (itr.hasNext()) {
1370                    count = (Long)itr.next();
1371                }
1372
1373                if (count == null) {
1374                    count = new Long(0);
1375                }
1376
1377                FinderCache.putResult(finderClassNameCacheEnabled,
1378                    finderClassName, finderMethodName, finderParams,
1379                    finderArgs, count);
1380
1381                return count.intValue();
1382            }
1383            catch (Exception e) {
1384                throw HibernateUtil.processException(e);
1385            }
1386            finally {
1387                closeSession(session);
1388            }
1389        }
1390        else {
1391            return ((Long)result).intValue();
1392        }
1393    }
1394
1395    public int countByG_U(long groupId, long userId) throws SystemException {
1396        boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1397        String finderClassName = MBStatsUser.class.getName();
1398        String finderMethodName = "countByG_U";
1399        String[] finderParams = new String[] {
1400                Long.class.getName(), Long.class.getName()
1401            };
1402        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1403
1404        Object result = null;
1405
1406        if (finderClassNameCacheEnabled) {
1407            result = FinderCache.getResult(finderClassName, finderMethodName,
1408                    finderParams, finderArgs, getSessionFactory());
1409        }
1410
1411        if (result == null) {
1412            Session session = null;
1413
1414            try {
1415                session = openSession();
1416
1417                StringMaker query = new StringMaker();
1418
1419                query.append("SELECT COUNT(*) ");
1420                query.append(
1421                    "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1422
1423                query.append("groupId = ?");
1424
1425                query.append(" AND ");
1426
1427                query.append("userId = ?");
1428
1429                query.append(" ");
1430
1431                Query q = session.createQuery(query.toString());
1432
1433                int queryPos = 0;
1434
1435                q.setLong(queryPos++, groupId);
1436
1437                q.setLong(queryPos++, userId);
1438
1439                Long count = null;
1440
1441                Iterator itr = q.list().iterator();
1442
1443                if (itr.hasNext()) {
1444                    count = (Long)itr.next();
1445                }
1446
1447                if (count == null) {
1448                    count = new Long(0);
1449                }
1450
1451                FinderCache.putResult(finderClassNameCacheEnabled,
1452                    finderClassName, finderMethodName, finderParams,
1453                    finderArgs, count);
1454
1455                return count.intValue();
1456            }
1457            catch (Exception e) {
1458                throw HibernateUtil.processException(e);
1459            }
1460            finally {
1461                closeSession(session);
1462            }
1463        }
1464        else {
1465            return ((Long)result).intValue();
1466        }
1467    }
1468
1469    public int countByG_M(long groupId, int messageCount)
1470        throws SystemException {
1471        boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1472        String finderClassName = MBStatsUser.class.getName();
1473        String finderMethodName = "countByG_M";
1474        String[] finderParams = new String[] {
1475                Long.class.getName(), Integer.class.getName()
1476            };
1477        Object[] finderArgs = new Object[] {
1478                new Long(groupId), new Integer(messageCount)
1479            };
1480
1481        Object result = null;
1482
1483        if (finderClassNameCacheEnabled) {
1484            result = FinderCache.getResult(finderClassName, finderMethodName,
1485                    finderParams, finderArgs, getSessionFactory());
1486        }
1487
1488        if (result == null) {
1489            Session session = null;
1490
1491            try {
1492                session = openSession();
1493
1494                StringMaker query = new StringMaker();
1495
1496                query.append("SELECT COUNT(*) ");
1497                query.append(
1498                    "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1499
1500                query.append("groupId = ?");
1501
1502                query.append(" AND ");
1503
1504                query.append("messageCount != ?");
1505
1506                query.append(" ");
1507
1508                Query q = session.createQuery(query.toString());
1509
1510                int queryPos = 0;
1511
1512                q.setLong(queryPos++, groupId);
1513
1514                q.setInteger(queryPos++, messageCount);
1515
1516                Long count = null;
1517
1518                Iterator itr = q.list().iterator();
1519
1520                if (itr.hasNext()) {
1521                    count = (Long)itr.next();
1522                }
1523
1524                if (count == null) {
1525                    count = new Long(0);
1526                }
1527
1528                FinderCache.putResult(finderClassNameCacheEnabled,
1529                    finderClassName, finderMethodName, finderParams,
1530                    finderArgs, count);
1531
1532                return count.intValue();
1533            }
1534            catch (Exception e) {
1535                throw HibernateUtil.processException(e);
1536            }
1537            finally {
1538                closeSession(session);
1539            }
1540        }
1541        else {
1542            return ((Long)result).intValue();
1543        }
1544    }
1545
1546    public int countAll() throws SystemException {
1547        boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1548        String finderClassName = MBStatsUser.class.getName();
1549        String finderMethodName = "countAll";
1550        String[] finderParams = new String[] {  };
1551        Object[] finderArgs = new Object[] {  };
1552
1553        Object result = null;
1554
1555        if (finderClassNameCacheEnabled) {
1556            result = FinderCache.getResult(finderClassName, finderMethodName,
1557                    finderParams, finderArgs, getSessionFactory());
1558        }
1559
1560        if (result == null) {
1561            Session session = null;
1562
1563            try {
1564                session = openSession();
1565
1566                Query q = session.createQuery(
1567                        "SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBStatsUser");
1568
1569                Long count = null;
1570
1571                Iterator itr = q.list().iterator();
1572
1573                if (itr.hasNext()) {
1574                    count = (Long)itr.next();
1575                }
1576
1577                if (count == null) {
1578                    count = new Long(0);
1579                }
1580
1581                FinderCache.putResult(finderClassNameCacheEnabled,
1582                    finderClassName, finderMethodName, finderParams,
1583                    finderArgs, count);
1584
1585                return count.intValue();
1586            }
1587            catch (Exception e) {
1588                throw HibernateUtil.processException(e);
1589            }
1590            finally {
1591                closeSession(session);
1592            }
1593        }
1594        else {
1595            return ((Long)result).intValue();
1596        }
1597    }
1598
1599    protected void initDao() {
1600    }
1601
1602    private static ModelListener _getListener() {
1603        if (Validator.isNotNull(_LISTENER)) {
1604            try {
1605                return (ModelListener)Class.forName(_LISTENER).newInstance();
1606            }
1607            catch (Exception e) {
1608                _log.error(e);
1609            }
1610        }
1611
1612        return null;
1613    }
1614
1615    private static final String _LISTENER = GetterUtil.getString(PropsUtil.get(
1616                "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser"));
1617    private static Log _log = LogFactory.getLog(MBStatsUserPersistenceImpl.class);
1618}