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