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