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