001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.BatchSessionUtil;
038 import com.liferay.portal.service.persistence.ResourcePersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.messageboards.NoSuchStatsUserException;
043 import com.liferay.portlet.messageboards.model.MBStatsUser;
044 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
045 import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
069 public class MBStatsUserPersistenceImpl extends BasePersistenceImpl<MBStatsUser>
070 implements MBStatsUserPersistence {
071 public static final String FINDER_CLASS_NAME_ENTITY = MBStatsUserImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073 ".List";
074 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
075 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076 "findByGroupId",
077 new String[] {
078 Long.class.getName(),
079
080 "java.lang.Integer", "java.lang.Integer",
081 "com.liferay.portal.kernel.util.OrderByComparator"
082 });
083 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
084 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085 "countByGroupId", new String[] { Long.class.getName() });
086 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
087 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088 "findByUserId",
089 new String[] {
090 Long.class.getName(),
091
092 "java.lang.Integer", "java.lang.Integer",
093 "com.liferay.portal.kernel.util.OrderByComparator"
094 });
095 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
096 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097 "countByUserId", new String[] { Long.class.getName() });
098 public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
099 MBStatsUserModelImpl.FINDER_CACHE_ENABLED,
100 FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
101 new String[] { Long.class.getName(), Long.class.getName() });
102 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
103 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "countByG_U",
105 new String[] { Long.class.getName(), Long.class.getName() });
106 public static final FinderPath FINDER_PATH_FIND_BY_G_NOTM = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
107 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
108 "findByG_NotM",
109 new String[] {
110 Long.class.getName(), Integer.class.getName(),
111
112 "java.lang.Integer", "java.lang.Integer",
113 "com.liferay.portal.kernel.util.OrderByComparator"
114 });
115 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTM = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
116 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
117 "countByG_NotM",
118 new String[] { Long.class.getName(), Integer.class.getName() });
119 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
120 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
121 "findAll", new String[0]);
122 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
123 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
124 "countAll", new String[0]);
125
126
131 public void cacheResult(MBStatsUser mbStatsUser) {
132 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
133 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
134
135 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
136 new Object[] {
137 new Long(mbStatsUser.getGroupId()),
138 new Long(mbStatsUser.getUserId())
139 }, mbStatsUser);
140 }
141
142
147 public void cacheResult(List<MBStatsUser> mbStatsUsers) {
148 for (MBStatsUser mbStatsUser : mbStatsUsers) {
149 if (EntityCacheUtil.getResult(
150 MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
151 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), this) == null) {
152 cacheResult(mbStatsUser);
153 }
154 }
155 }
156
157
164 public void clearCache() {
165 CacheRegistryUtil.clear(MBStatsUserImpl.class.getName());
166 EntityCacheUtil.clearCache(MBStatsUserImpl.class.getName());
167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
168 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
169 }
170
171
178 public void clearCache(MBStatsUser mbStatsUser) {
179 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
180 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
181
182 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
183 new Object[] {
184 new Long(mbStatsUser.getGroupId()),
185 new Long(mbStatsUser.getUserId())
186 });
187 }
188
189
195 public MBStatsUser create(long statsUserId) {
196 MBStatsUser mbStatsUser = new MBStatsUserImpl();
197
198 mbStatsUser.setNew(true);
199 mbStatsUser.setPrimaryKey(statsUserId);
200
201 return mbStatsUser;
202 }
203
204
212 public MBStatsUser remove(Serializable primaryKey)
213 throws NoSuchModelException, SystemException {
214 return remove(((Long)primaryKey).longValue());
215 }
216
217
225 public MBStatsUser remove(long statsUserId)
226 throws NoSuchStatsUserException, SystemException {
227 Session session = null;
228
229 try {
230 session = openSession();
231
232 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
233 new Long(statsUserId));
234
235 if (mbStatsUser == null) {
236 if (_log.isWarnEnabled()) {
237 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
238 }
239
240 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
241 statsUserId);
242 }
243
244 return remove(mbStatsUser);
245 }
246 catch (NoSuchStatsUserException nsee) {
247 throw nsee;
248 }
249 catch (Exception e) {
250 throw processException(e);
251 }
252 finally {
253 closeSession(session);
254 }
255 }
256
257 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
258 throws SystemException {
259 mbStatsUser = toUnwrappedModel(mbStatsUser);
260
261 Session session = null;
262
263 try {
264 session = openSession();
265
266 BatchSessionUtil.delete(session, mbStatsUser);
267 }
268 catch (Exception e) {
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274
275 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
276
277 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
278
279 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
280 new Object[] {
281 new Long(mbStatsUserModelImpl.getGroupId()),
282 new Long(mbStatsUserModelImpl.getUserId())
283 });
284
285 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
286 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
287
288 return mbStatsUser;
289 }
290
291 public MBStatsUser updateImpl(
292 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
293 boolean merge) throws SystemException {
294 mbStatsUser = toUnwrappedModel(mbStatsUser);
295
296 boolean isNew = mbStatsUser.isNew();
297
298 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
299
300 Session session = null;
301
302 try {
303 session = openSession();
304
305 BatchSessionUtil.update(session, mbStatsUser, merge);
306
307 mbStatsUser.setNew(false);
308 }
309 catch (Exception e) {
310 throw processException(e);
311 }
312 finally {
313 closeSession(session);
314 }
315
316 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
317
318 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
319 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
320
321 if (!isNew &&
322 ((mbStatsUser.getGroupId() != mbStatsUserModelImpl.getOriginalGroupId()) ||
323 (mbStatsUser.getUserId() != mbStatsUserModelImpl.getOriginalUserId()))) {
324 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
325 new Object[] {
326 new Long(mbStatsUserModelImpl.getOriginalGroupId()),
327 new Long(mbStatsUserModelImpl.getOriginalUserId())
328 });
329 }
330
331 if (isNew ||
332 ((mbStatsUser.getGroupId() != mbStatsUserModelImpl.getOriginalGroupId()) ||
333 (mbStatsUser.getUserId() != mbStatsUserModelImpl.getOriginalUserId()))) {
334 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
335 new Object[] {
336 new Long(mbStatsUser.getGroupId()),
337 new Long(mbStatsUser.getUserId())
338 }, mbStatsUser);
339 }
340
341 return mbStatsUser;
342 }
343
344 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
345 if (mbStatsUser instanceof MBStatsUserImpl) {
346 return mbStatsUser;
347 }
348
349 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
350
351 mbStatsUserImpl.setNew(mbStatsUser.isNew());
352 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
353
354 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
355 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
356 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
357 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
358 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
359
360 return mbStatsUserImpl;
361 }
362
363
371 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
372 throws NoSuchModelException, SystemException {
373 return findByPrimaryKey(((Long)primaryKey).longValue());
374 }
375
376
384 public MBStatsUser findByPrimaryKey(long statsUserId)
385 throws NoSuchStatsUserException, SystemException {
386 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
387
388 if (mbStatsUser == null) {
389 if (_log.isWarnEnabled()) {
390 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
391 }
392
393 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
394 statsUserId);
395 }
396
397 return mbStatsUser;
398 }
399
400
407 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
408 throws SystemException {
409 return fetchByPrimaryKey(((Long)primaryKey).longValue());
410 }
411
412
419 public MBStatsUser fetchByPrimaryKey(long statsUserId)
420 throws SystemException {
421 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
422 MBStatsUserImpl.class, statsUserId, this);
423
424 if (mbStatsUser == null) {
425 Session session = null;
426
427 try {
428 session = openSession();
429
430 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
431 new Long(statsUserId));
432 }
433 catch (Exception e) {
434 throw processException(e);
435 }
436 finally {
437 if (mbStatsUser != null) {
438 cacheResult(mbStatsUser);
439 }
440
441 closeSession(session);
442 }
443 }
444
445 return mbStatsUser;
446 }
447
448
455 public List<MBStatsUser> findByGroupId(long groupId)
456 throws SystemException {
457 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
458 }
459
460
473 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
474 throws SystemException {
475 return findByGroupId(groupId, start, end, null);
476 }
477
478
492 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
493 OrderByComparator orderByComparator) throws SystemException {
494 Object[] finderArgs = new Object[] {
495 groupId,
496
497 String.valueOf(start), String.valueOf(end),
498 String.valueOf(orderByComparator)
499 };
500
501 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
502 finderArgs, this);
503
504 if (list == null) {
505 StringBundler query = null;
506
507 if (orderByComparator != null) {
508 query = new StringBundler(3 +
509 (orderByComparator.getOrderByFields().length * 3));
510 }
511 else {
512 query = new StringBundler(3);
513 }
514
515 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
516
517 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
518
519 if (orderByComparator != null) {
520 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
521 orderByComparator);
522 }
523
524 else {
525 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
526 }
527
528 String sql = query.toString();
529
530 Session session = null;
531
532 try {
533 session = openSession();
534
535 Query q = session.createQuery(sql);
536
537 QueryPos qPos = QueryPos.getInstance(q);
538
539 qPos.add(groupId);
540
541 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
542 start, end);
543 }
544 catch (Exception e) {
545 throw processException(e);
546 }
547 finally {
548 if (list == null) {
549 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
550 finderArgs);
551 }
552 else {
553 cacheResult(list);
554
555 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
556 finderArgs, list);
557 }
558
559 closeSession(session);
560 }
561 }
562
563 return list;
564 }
565
566
579 public MBStatsUser findByGroupId_First(long groupId,
580 OrderByComparator orderByComparator)
581 throws NoSuchStatsUserException, SystemException {
582 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
583
584 if (list.isEmpty()) {
585 StringBundler msg = new StringBundler(4);
586
587 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
588
589 msg.append("groupId=");
590 msg.append(groupId);
591
592 msg.append(StringPool.CLOSE_CURLY_BRACE);
593
594 throw new NoSuchStatsUserException(msg.toString());
595 }
596 else {
597 return list.get(0);
598 }
599 }
600
601
614 public MBStatsUser findByGroupId_Last(long groupId,
615 OrderByComparator orderByComparator)
616 throws NoSuchStatsUserException, SystemException {
617 int count = countByGroupId(groupId);
618
619 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
620 orderByComparator);
621
622 if (list.isEmpty()) {
623 StringBundler msg = new StringBundler(4);
624
625 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
626
627 msg.append("groupId=");
628 msg.append(groupId);
629
630 msg.append(StringPool.CLOSE_CURLY_BRACE);
631
632 throw new NoSuchStatsUserException(msg.toString());
633 }
634 else {
635 return list.get(0);
636 }
637 }
638
639
653 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
654 long groupId, OrderByComparator orderByComparator)
655 throws NoSuchStatsUserException, SystemException {
656 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
657
658 Session session = null;
659
660 try {
661 session = openSession();
662
663 MBStatsUser[] array = new MBStatsUserImpl[3];
664
665 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
666 orderByComparator, true);
667
668 array[1] = mbStatsUser;
669
670 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
671 orderByComparator, false);
672
673 return array;
674 }
675 catch (Exception e) {
676 throw processException(e);
677 }
678 finally {
679 closeSession(session);
680 }
681 }
682
683 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
684 MBStatsUser mbStatsUser, long groupId,
685 OrderByComparator orderByComparator, boolean previous) {
686 StringBundler query = null;
687
688 if (orderByComparator != null) {
689 query = new StringBundler(6 +
690 (orderByComparator.getOrderByFields().length * 6));
691 }
692 else {
693 query = new StringBundler(3);
694 }
695
696 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
697
698 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
699
700 if (orderByComparator != null) {
701 String[] orderByFields = orderByComparator.getOrderByFields();
702
703 if (orderByFields.length > 0) {
704 query.append(WHERE_AND);
705 }
706
707 for (int i = 0; i < orderByFields.length; i++) {
708 query.append(_ORDER_BY_ENTITY_ALIAS);
709 query.append(orderByFields[i]);
710
711 if ((i + 1) < orderByFields.length) {
712 if (orderByComparator.isAscending() ^ previous) {
713 query.append(WHERE_GREATER_THAN_HAS_NEXT);
714 }
715 else {
716 query.append(WHERE_LESSER_THAN_HAS_NEXT);
717 }
718 }
719 else {
720 if (orderByComparator.isAscending() ^ previous) {
721 query.append(WHERE_GREATER_THAN);
722 }
723 else {
724 query.append(WHERE_LESSER_THAN);
725 }
726 }
727 }
728
729 query.append(ORDER_BY_CLAUSE);
730
731 for (int i = 0; i < orderByFields.length; i++) {
732 query.append(_ORDER_BY_ENTITY_ALIAS);
733 query.append(orderByFields[i]);
734
735 if ((i + 1) < orderByFields.length) {
736 if (orderByComparator.isAscending() ^ previous) {
737 query.append(ORDER_BY_ASC_HAS_NEXT);
738 }
739 else {
740 query.append(ORDER_BY_DESC_HAS_NEXT);
741 }
742 }
743 else {
744 if (orderByComparator.isAscending() ^ previous) {
745 query.append(ORDER_BY_ASC);
746 }
747 else {
748 query.append(ORDER_BY_DESC);
749 }
750 }
751 }
752 }
753
754 else {
755 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
756 }
757
758 String sql = query.toString();
759
760 Query q = session.createQuery(sql);
761
762 q.setFirstResult(0);
763 q.setMaxResults(2);
764
765 QueryPos qPos = QueryPos.getInstance(q);
766
767 qPos.add(groupId);
768
769 if (orderByComparator != null) {
770 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
771
772 for (Object value : values) {
773 qPos.add(value);
774 }
775 }
776
777 List<MBStatsUser> list = q.list();
778
779 if (list.size() == 2) {
780 return list.get(1);
781 }
782 else {
783 return null;
784 }
785 }
786
787
794 public List<MBStatsUser> findByUserId(long userId)
795 throws SystemException {
796 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
797 }
798
799
812 public List<MBStatsUser> findByUserId(long userId, int start, int end)
813 throws SystemException {
814 return findByUserId(userId, start, end, null);
815 }
816
817
831 public List<MBStatsUser> findByUserId(long userId, int start, int end,
832 OrderByComparator orderByComparator) throws SystemException {
833 Object[] finderArgs = new Object[] {
834 userId,
835
836 String.valueOf(start), String.valueOf(end),
837 String.valueOf(orderByComparator)
838 };
839
840 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
841 finderArgs, this);
842
843 if (list == null) {
844 StringBundler query = null;
845
846 if (orderByComparator != null) {
847 query = new StringBundler(3 +
848 (orderByComparator.getOrderByFields().length * 3));
849 }
850 else {
851 query = new StringBundler(3);
852 }
853
854 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
855
856 query.append(_FINDER_COLUMN_USERID_USERID_2);
857
858 if (orderByComparator != null) {
859 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
860 orderByComparator);
861 }
862
863 else {
864 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
865 }
866
867 String sql = query.toString();
868
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 Query q = session.createQuery(sql);
875
876 QueryPos qPos = QueryPos.getInstance(q);
877
878 qPos.add(userId);
879
880 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
881 start, end);
882 }
883 catch (Exception e) {
884 throw processException(e);
885 }
886 finally {
887 if (list == null) {
888 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
889 finderArgs);
890 }
891 else {
892 cacheResult(list);
893
894 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
895 finderArgs, list);
896 }
897
898 closeSession(session);
899 }
900 }
901
902 return list;
903 }
904
905
918 public MBStatsUser findByUserId_First(long userId,
919 OrderByComparator orderByComparator)
920 throws NoSuchStatsUserException, SystemException {
921 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
922
923 if (list.isEmpty()) {
924 StringBundler msg = new StringBundler(4);
925
926 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
927
928 msg.append("userId=");
929 msg.append(userId);
930
931 msg.append(StringPool.CLOSE_CURLY_BRACE);
932
933 throw new NoSuchStatsUserException(msg.toString());
934 }
935 else {
936 return list.get(0);
937 }
938 }
939
940
953 public MBStatsUser findByUserId_Last(long userId,
954 OrderByComparator orderByComparator)
955 throws NoSuchStatsUserException, SystemException {
956 int count = countByUserId(userId);
957
958 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
959 orderByComparator);
960
961 if (list.isEmpty()) {
962 StringBundler msg = new StringBundler(4);
963
964 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
965
966 msg.append("userId=");
967 msg.append(userId);
968
969 msg.append(StringPool.CLOSE_CURLY_BRACE);
970
971 throw new NoSuchStatsUserException(msg.toString());
972 }
973 else {
974 return list.get(0);
975 }
976 }
977
978
992 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
993 long userId, OrderByComparator orderByComparator)
994 throws NoSuchStatsUserException, SystemException {
995 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
996
997 Session session = null;
998
999 try {
1000 session = openSession();
1001
1002 MBStatsUser[] array = new MBStatsUserImpl[3];
1003
1004 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1005 orderByComparator, true);
1006
1007 array[1] = mbStatsUser;
1008
1009 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1010 orderByComparator, false);
1011
1012 return array;
1013 }
1014 catch (Exception e) {
1015 throw processException(e);
1016 }
1017 finally {
1018 closeSession(session);
1019 }
1020 }
1021
1022 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1023 MBStatsUser mbStatsUser, long userId,
1024 OrderByComparator orderByComparator, boolean previous) {
1025 StringBundler query = null;
1026
1027 if (orderByComparator != null) {
1028 query = new StringBundler(6 +
1029 (orderByComparator.getOrderByFields().length * 6));
1030 }
1031 else {
1032 query = new StringBundler(3);
1033 }
1034
1035 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1036
1037 query.append(_FINDER_COLUMN_USERID_USERID_2);
1038
1039 if (orderByComparator != null) {
1040 String[] orderByFields = orderByComparator.getOrderByFields();
1041
1042 if (orderByFields.length > 0) {
1043 query.append(WHERE_AND);
1044 }
1045
1046 for (int i = 0; i < orderByFields.length; i++) {
1047 query.append(_ORDER_BY_ENTITY_ALIAS);
1048 query.append(orderByFields[i]);
1049
1050 if ((i + 1) < orderByFields.length) {
1051 if (orderByComparator.isAscending() ^ previous) {
1052 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1053 }
1054 else {
1055 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1056 }
1057 }
1058 else {
1059 if (orderByComparator.isAscending() ^ previous) {
1060 query.append(WHERE_GREATER_THAN);
1061 }
1062 else {
1063 query.append(WHERE_LESSER_THAN);
1064 }
1065 }
1066 }
1067
1068 query.append(ORDER_BY_CLAUSE);
1069
1070 for (int i = 0; i < orderByFields.length; i++) {
1071 query.append(_ORDER_BY_ENTITY_ALIAS);
1072 query.append(orderByFields[i]);
1073
1074 if ((i + 1) < orderByFields.length) {
1075 if (orderByComparator.isAscending() ^ previous) {
1076 query.append(ORDER_BY_ASC_HAS_NEXT);
1077 }
1078 else {
1079 query.append(ORDER_BY_DESC_HAS_NEXT);
1080 }
1081 }
1082 else {
1083 if (orderByComparator.isAscending() ^ previous) {
1084 query.append(ORDER_BY_ASC);
1085 }
1086 else {
1087 query.append(ORDER_BY_DESC);
1088 }
1089 }
1090 }
1091 }
1092
1093 else {
1094 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1095 }
1096
1097 String sql = query.toString();
1098
1099 Query q = session.createQuery(sql);
1100
1101 q.setFirstResult(0);
1102 q.setMaxResults(2);
1103
1104 QueryPos qPos = QueryPos.getInstance(q);
1105
1106 qPos.add(userId);
1107
1108 if (orderByComparator != null) {
1109 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1110
1111 for (Object value : values) {
1112 qPos.add(value);
1113 }
1114 }
1115
1116 List<MBStatsUser> list = q.list();
1117
1118 if (list.size() == 2) {
1119 return list.get(1);
1120 }
1121 else {
1122 return null;
1123 }
1124 }
1125
1126
1135 public MBStatsUser findByG_U(long groupId, long userId)
1136 throws NoSuchStatsUserException, SystemException {
1137 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1138
1139 if (mbStatsUser == null) {
1140 StringBundler msg = new StringBundler(6);
1141
1142 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1143
1144 msg.append("groupId=");
1145 msg.append(groupId);
1146
1147 msg.append(", userId=");
1148 msg.append(userId);
1149
1150 msg.append(StringPool.CLOSE_CURLY_BRACE);
1151
1152 if (_log.isWarnEnabled()) {
1153 _log.warn(msg.toString());
1154 }
1155
1156 throw new NoSuchStatsUserException(msg.toString());
1157 }
1158
1159 return mbStatsUser;
1160 }
1161
1162
1170 public MBStatsUser fetchByG_U(long groupId, long userId)
1171 throws SystemException {
1172 return fetchByG_U(groupId, userId, true);
1173 }
1174
1175
1183 public MBStatsUser fetchByG_U(long groupId, long userId,
1184 boolean retrieveFromCache) throws SystemException {
1185 Object[] finderArgs = new Object[] { groupId, userId };
1186
1187 Object result = null;
1188
1189 if (retrieveFromCache) {
1190 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1191 finderArgs, this);
1192 }
1193
1194 if (result == null) {
1195 StringBundler query = new StringBundler(4);
1196
1197 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1198
1199 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1200
1201 query.append(_FINDER_COLUMN_G_U_USERID_2);
1202
1203 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1204
1205 String sql = query.toString();
1206
1207 Session session = null;
1208
1209 try {
1210 session = openSession();
1211
1212 Query q = session.createQuery(sql);
1213
1214 QueryPos qPos = QueryPos.getInstance(q);
1215
1216 qPos.add(groupId);
1217
1218 qPos.add(userId);
1219
1220 List<MBStatsUser> list = q.list();
1221
1222 result = list;
1223
1224 MBStatsUser mbStatsUser = null;
1225
1226 if (list.isEmpty()) {
1227 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1228 finderArgs, list);
1229 }
1230 else {
1231 mbStatsUser = list.get(0);
1232
1233 cacheResult(mbStatsUser);
1234
1235 if ((mbStatsUser.getGroupId() != groupId) ||
1236 (mbStatsUser.getUserId() != userId)) {
1237 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1238 finderArgs, mbStatsUser);
1239 }
1240 }
1241
1242 return mbStatsUser;
1243 }
1244 catch (Exception e) {
1245 throw processException(e);
1246 }
1247 finally {
1248 if (result == null) {
1249 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1250 finderArgs);
1251 }
1252
1253 closeSession(session);
1254 }
1255 }
1256 else {
1257 if (result instanceof List<?>) {
1258 return null;
1259 }
1260 else {
1261 return (MBStatsUser)result;
1262 }
1263 }
1264 }
1265
1266
1274 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount)
1275 throws SystemException {
1276 return findByG_NotM(groupId, messageCount, QueryUtil.ALL_POS,
1277 QueryUtil.ALL_POS, null);
1278 }
1279
1280
1294 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1295 int start, int end) throws SystemException {
1296 return findByG_NotM(groupId, messageCount, start, end, null);
1297 }
1298
1299
1314 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1315 int start, int end, OrderByComparator orderByComparator)
1316 throws SystemException {
1317 Object[] finderArgs = new Object[] {
1318 groupId, messageCount,
1319
1320 String.valueOf(start), String.valueOf(end),
1321 String.valueOf(orderByComparator)
1322 };
1323
1324 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTM,
1325 finderArgs, this);
1326
1327 if (list == null) {
1328 StringBundler query = null;
1329
1330 if (orderByComparator != null) {
1331 query = new StringBundler(4 +
1332 (orderByComparator.getOrderByFields().length * 3));
1333 }
1334 else {
1335 query = new StringBundler(4);
1336 }
1337
1338 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1339
1340 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1341
1342 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1343
1344 if (orderByComparator != null) {
1345 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1346 orderByComparator);
1347 }
1348
1349 else {
1350 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1351 }
1352
1353 String sql = query.toString();
1354
1355 Session session = null;
1356
1357 try {
1358 session = openSession();
1359
1360 Query q = session.createQuery(sql);
1361
1362 QueryPos qPos = QueryPos.getInstance(q);
1363
1364 qPos.add(groupId);
1365
1366 qPos.add(messageCount);
1367
1368 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1369 start, end);
1370 }
1371 catch (Exception e) {
1372 throw processException(e);
1373 }
1374 finally {
1375 if (list == null) {
1376 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_NOTM,
1377 finderArgs);
1378 }
1379 else {
1380 cacheResult(list);
1381
1382 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTM,
1383 finderArgs, list);
1384 }
1385
1386 closeSession(session);
1387 }
1388 }
1389
1390 return list;
1391 }
1392
1393
1407 public MBStatsUser findByG_NotM_First(long groupId, int messageCount,
1408 OrderByComparator orderByComparator)
1409 throws NoSuchStatsUserException, SystemException {
1410 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, 0, 1,
1411 orderByComparator);
1412
1413 if (list.isEmpty()) {
1414 StringBundler msg = new StringBundler(6);
1415
1416 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1417
1418 msg.append("groupId=");
1419 msg.append(groupId);
1420
1421 msg.append(", messageCount=");
1422 msg.append(messageCount);
1423
1424 msg.append(StringPool.CLOSE_CURLY_BRACE);
1425
1426 throw new NoSuchStatsUserException(msg.toString());
1427 }
1428 else {
1429 return list.get(0);
1430 }
1431 }
1432
1433
1447 public MBStatsUser findByG_NotM_Last(long groupId, int messageCount,
1448 OrderByComparator orderByComparator)
1449 throws NoSuchStatsUserException, SystemException {
1450 int count = countByG_NotM(groupId, messageCount);
1451
1452 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, count - 1,
1453 count, orderByComparator);
1454
1455 if (list.isEmpty()) {
1456 StringBundler msg = new StringBundler(6);
1457
1458 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1459
1460 msg.append("groupId=");
1461 msg.append(groupId);
1462
1463 msg.append(", messageCount=");
1464 msg.append(messageCount);
1465
1466 msg.append(StringPool.CLOSE_CURLY_BRACE);
1467
1468 throw new NoSuchStatsUserException(msg.toString());
1469 }
1470 else {
1471 return list.get(0);
1472 }
1473 }
1474
1475
1490 public MBStatsUser[] findByG_NotM_PrevAndNext(long statsUserId,
1491 long groupId, int messageCount, OrderByComparator orderByComparator)
1492 throws NoSuchStatsUserException, SystemException {
1493 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1494
1495 Session session = null;
1496
1497 try {
1498 session = openSession();
1499
1500 MBStatsUser[] array = new MBStatsUserImpl[3];
1501
1502 array[0] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1503 messageCount, orderByComparator, true);
1504
1505 array[1] = mbStatsUser;
1506
1507 array[2] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1508 messageCount, orderByComparator, false);
1509
1510 return array;
1511 }
1512 catch (Exception e) {
1513 throw processException(e);
1514 }
1515 finally {
1516 closeSession(session);
1517 }
1518 }
1519
1520 protected MBStatsUser getByG_NotM_PrevAndNext(Session session,
1521 MBStatsUser mbStatsUser, long groupId, int messageCount,
1522 OrderByComparator orderByComparator, boolean previous) {
1523 StringBundler query = null;
1524
1525 if (orderByComparator != null) {
1526 query = new StringBundler(6 +
1527 (orderByComparator.getOrderByFields().length * 6));
1528 }
1529 else {
1530 query = new StringBundler(3);
1531 }
1532
1533 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1534
1535 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1536
1537 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1538
1539 if (orderByComparator != null) {
1540 String[] orderByFields = orderByComparator.getOrderByFields();
1541
1542 if (orderByFields.length > 0) {
1543 query.append(WHERE_AND);
1544 }
1545
1546 for (int i = 0; i < orderByFields.length; i++) {
1547 query.append(_ORDER_BY_ENTITY_ALIAS);
1548 query.append(orderByFields[i]);
1549
1550 if ((i + 1) < orderByFields.length) {
1551 if (orderByComparator.isAscending() ^ previous) {
1552 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1553 }
1554 else {
1555 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1556 }
1557 }
1558 else {
1559 if (orderByComparator.isAscending() ^ previous) {
1560 query.append(WHERE_GREATER_THAN);
1561 }
1562 else {
1563 query.append(WHERE_LESSER_THAN);
1564 }
1565 }
1566 }
1567
1568 query.append(ORDER_BY_CLAUSE);
1569
1570 for (int i = 0; i < orderByFields.length; i++) {
1571 query.append(_ORDER_BY_ENTITY_ALIAS);
1572 query.append(orderByFields[i]);
1573
1574 if ((i + 1) < orderByFields.length) {
1575 if (orderByComparator.isAscending() ^ previous) {
1576 query.append(ORDER_BY_ASC_HAS_NEXT);
1577 }
1578 else {
1579 query.append(ORDER_BY_DESC_HAS_NEXT);
1580 }
1581 }
1582 else {
1583 if (orderByComparator.isAscending() ^ previous) {
1584 query.append(ORDER_BY_ASC);
1585 }
1586 else {
1587 query.append(ORDER_BY_DESC);
1588 }
1589 }
1590 }
1591 }
1592
1593 else {
1594 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1595 }
1596
1597 String sql = query.toString();
1598
1599 Query q = session.createQuery(sql);
1600
1601 q.setFirstResult(0);
1602 q.setMaxResults(2);
1603
1604 QueryPos qPos = QueryPos.getInstance(q);
1605
1606 qPos.add(groupId);
1607
1608 qPos.add(messageCount);
1609
1610 if (orderByComparator != null) {
1611 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1612
1613 for (Object value : values) {
1614 qPos.add(value);
1615 }
1616 }
1617
1618 List<MBStatsUser> list = q.list();
1619
1620 if (list.size() == 2) {
1621 return list.get(1);
1622 }
1623 else {
1624 return null;
1625 }
1626 }
1627
1628
1634 public List<MBStatsUser> findAll() throws SystemException {
1635 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1636 }
1637
1638
1650 public List<MBStatsUser> findAll(int start, int end)
1651 throws SystemException {
1652 return findAll(start, end, null);
1653 }
1654
1655
1668 public List<MBStatsUser> findAll(int start, int end,
1669 OrderByComparator orderByComparator) throws SystemException {
1670 Object[] finderArgs = new Object[] {
1671 String.valueOf(start), String.valueOf(end),
1672 String.valueOf(orderByComparator)
1673 };
1674
1675 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1676 finderArgs, this);
1677
1678 if (list == null) {
1679 StringBundler query = null;
1680 String sql = null;
1681
1682 if (orderByComparator != null) {
1683 query = new StringBundler(2 +
1684 (orderByComparator.getOrderByFields().length * 3));
1685
1686 query.append(_SQL_SELECT_MBSTATSUSER);
1687
1688 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1689 orderByComparator);
1690
1691 sql = query.toString();
1692 }
1693 else {
1694 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1695 }
1696
1697 Session session = null;
1698
1699 try {
1700 session = openSession();
1701
1702 Query q = session.createQuery(sql);
1703
1704 if (orderByComparator == null) {
1705 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1706 start, end, false);
1707
1708 Collections.sort(list);
1709 }
1710 else {
1711 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1712 start, end);
1713 }
1714 }
1715 catch (Exception e) {
1716 throw processException(e);
1717 }
1718 finally {
1719 if (list == null) {
1720 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1721 finderArgs);
1722 }
1723 else {
1724 cacheResult(list);
1725
1726 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1727 list);
1728 }
1729
1730 closeSession(session);
1731 }
1732 }
1733
1734 return list;
1735 }
1736
1737
1743 public void removeByGroupId(long groupId) throws SystemException {
1744 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1745 remove(mbStatsUser);
1746 }
1747 }
1748
1749
1755 public void removeByUserId(long userId) throws SystemException {
1756 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1757 remove(mbStatsUser);
1758 }
1759 }
1760
1761
1768 public void removeByG_U(long groupId, long userId)
1769 throws NoSuchStatsUserException, SystemException {
1770 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1771
1772 remove(mbStatsUser);
1773 }
1774
1775
1782 public void removeByG_NotM(long groupId, int messageCount)
1783 throws SystemException {
1784 for (MBStatsUser mbStatsUser : findByG_NotM(groupId, messageCount)) {
1785 remove(mbStatsUser);
1786 }
1787 }
1788
1789
1794 public void removeAll() throws SystemException {
1795 for (MBStatsUser mbStatsUser : findAll()) {
1796 remove(mbStatsUser);
1797 }
1798 }
1799
1800
1807 public int countByGroupId(long groupId) throws SystemException {
1808 Object[] finderArgs = new Object[] { groupId };
1809
1810 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1811 finderArgs, this);
1812
1813 if (count == null) {
1814 StringBundler query = new StringBundler(2);
1815
1816 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1817
1818 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1819
1820 String sql = query.toString();
1821
1822 Session session = null;
1823
1824 try {
1825 session = openSession();
1826
1827 Query q = session.createQuery(sql);
1828
1829 QueryPos qPos = QueryPos.getInstance(q);
1830
1831 qPos.add(groupId);
1832
1833 count = (Long)q.uniqueResult();
1834 }
1835 catch (Exception e) {
1836 throw processException(e);
1837 }
1838 finally {
1839 if (count == null) {
1840 count = Long.valueOf(0);
1841 }
1842
1843 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1844 finderArgs, count);
1845
1846 closeSession(session);
1847 }
1848 }
1849
1850 return count.intValue();
1851 }
1852
1853
1860 public int countByUserId(long userId) throws SystemException {
1861 Object[] finderArgs = new Object[] { userId };
1862
1863 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1864 finderArgs, this);
1865
1866 if (count == null) {
1867 StringBundler query = new StringBundler(2);
1868
1869 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1870
1871 query.append(_FINDER_COLUMN_USERID_USERID_2);
1872
1873 String sql = query.toString();
1874
1875 Session session = null;
1876
1877 try {
1878 session = openSession();
1879
1880 Query q = session.createQuery(sql);
1881
1882 QueryPos qPos = QueryPos.getInstance(q);
1883
1884 qPos.add(userId);
1885
1886 count = (Long)q.uniqueResult();
1887 }
1888 catch (Exception e) {
1889 throw processException(e);
1890 }
1891 finally {
1892 if (count == null) {
1893 count = Long.valueOf(0);
1894 }
1895
1896 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1897 finderArgs, count);
1898
1899 closeSession(session);
1900 }
1901 }
1902
1903 return count.intValue();
1904 }
1905
1906
1914 public int countByG_U(long groupId, long userId) throws SystemException {
1915 Object[] finderArgs = new Object[] { groupId, userId };
1916
1917 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1918 finderArgs, this);
1919
1920 if (count == null) {
1921 StringBundler query = new StringBundler(3);
1922
1923 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1924
1925 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1926
1927 query.append(_FINDER_COLUMN_G_U_USERID_2);
1928
1929 String sql = query.toString();
1930
1931 Session session = null;
1932
1933 try {
1934 session = openSession();
1935
1936 Query q = session.createQuery(sql);
1937
1938 QueryPos qPos = QueryPos.getInstance(q);
1939
1940 qPos.add(groupId);
1941
1942 qPos.add(userId);
1943
1944 count = (Long)q.uniqueResult();
1945 }
1946 catch (Exception e) {
1947 throw processException(e);
1948 }
1949 finally {
1950 if (count == null) {
1951 count = Long.valueOf(0);
1952 }
1953
1954 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1955 count);
1956
1957 closeSession(session);
1958 }
1959 }
1960
1961 return count.intValue();
1962 }
1963
1964
1972 public int countByG_NotM(long groupId, int messageCount)
1973 throws SystemException {
1974 Object[] finderArgs = new Object[] { groupId, messageCount };
1975
1976 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTM,
1977 finderArgs, this);
1978
1979 if (count == null) {
1980 StringBundler query = new StringBundler(3);
1981
1982 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1983
1984 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1985
1986 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1987
1988 String sql = query.toString();
1989
1990 Session session = null;
1991
1992 try {
1993 session = openSession();
1994
1995 Query q = session.createQuery(sql);
1996
1997 QueryPos qPos = QueryPos.getInstance(q);
1998
1999 qPos.add(groupId);
2000
2001 qPos.add(messageCount);
2002
2003 count = (Long)q.uniqueResult();
2004 }
2005 catch (Exception e) {
2006 throw processException(e);
2007 }
2008 finally {
2009 if (count == null) {
2010 count = Long.valueOf(0);
2011 }
2012
2013 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTM,
2014 finderArgs, count);
2015
2016 closeSession(session);
2017 }
2018 }
2019
2020 return count.intValue();
2021 }
2022
2023
2029 public int countAll() throws SystemException {
2030 Object[] finderArgs = new Object[0];
2031
2032 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2033 finderArgs, this);
2034
2035 if (count == null) {
2036 Session session = null;
2037
2038 try {
2039 session = openSession();
2040
2041 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2042
2043 count = (Long)q.uniqueResult();
2044 }
2045 catch (Exception e) {
2046 throw processException(e);
2047 }
2048 finally {
2049 if (count == null) {
2050 count = Long.valueOf(0);
2051 }
2052
2053 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2054 count);
2055
2056 closeSession(session);
2057 }
2058 }
2059
2060 return count.intValue();
2061 }
2062
2063
2066 public void afterPropertiesSet() {
2067 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2068 com.liferay.portal.util.PropsUtil.get(
2069 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2070
2071 if (listenerClassNames.length > 0) {
2072 try {
2073 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2074
2075 for (String listenerClassName : listenerClassNames) {
2076 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2077 listenerClassName));
2078 }
2079
2080 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2081 }
2082 catch (Exception e) {
2083 _log.error(e);
2084 }
2085 }
2086 }
2087
2088 public void destroy() {
2089 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2090 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2091 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2092 }
2093
2094 @BeanReference(type = MBBanPersistence.class)
2095 protected MBBanPersistence mbBanPersistence;
2096 @BeanReference(type = MBCategoryPersistence.class)
2097 protected MBCategoryPersistence mbCategoryPersistence;
2098 @BeanReference(type = MBDiscussionPersistence.class)
2099 protected MBDiscussionPersistence mbDiscussionPersistence;
2100 @BeanReference(type = MBMailingListPersistence.class)
2101 protected MBMailingListPersistence mbMailingListPersistence;
2102 @BeanReference(type = MBMessagePersistence.class)
2103 protected MBMessagePersistence mbMessagePersistence;
2104 @BeanReference(type = MBMessageFlagPersistence.class)
2105 protected MBMessageFlagPersistence mbMessageFlagPersistence;
2106 @BeanReference(type = MBStatsUserPersistence.class)
2107 protected MBStatsUserPersistence mbStatsUserPersistence;
2108 @BeanReference(type = MBThreadPersistence.class)
2109 protected MBThreadPersistence mbThreadPersistence;
2110 @BeanReference(type = ResourcePersistence.class)
2111 protected ResourcePersistence resourcePersistence;
2112 @BeanReference(type = UserPersistence.class)
2113 protected UserPersistence userPersistence;
2114 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2115 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2116 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2117 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2118 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2119 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2120 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2121 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2122 private static final String _FINDER_COLUMN_G_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2123 private static final String _FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2124 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2125 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2126 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2127 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2128 }