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