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