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