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