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