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.getOriginalGroupId()),
282 new Long(mbStatsUserModelImpl.getOriginalUserId())
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 Session session = null;
506
507 try {
508 session = openSession();
509
510 StringBundler query = null;
511
512 if (orderByComparator != null) {
513 query = new StringBundler(3 +
514 (orderByComparator.getOrderByFields().length * 3));
515 }
516 else {
517 query = new StringBundler(3);
518 }
519
520 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
521
522 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
523
524 if (orderByComparator != null) {
525 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
526 orderByComparator);
527 }
528
529 else {
530 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
531 }
532
533 String sql = query.toString();
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 list = new ArrayList<MBStatsUser>();
550 }
551
552 cacheResult(list);
553
554 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
555 finderArgs, list);
556
557 closeSession(session);
558 }
559 }
560
561 return list;
562 }
563
564
577 public MBStatsUser findByGroupId_First(long groupId,
578 OrderByComparator orderByComparator)
579 throws NoSuchStatsUserException, SystemException {
580 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
581
582 if (list.isEmpty()) {
583 StringBundler msg = new StringBundler(4);
584
585 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
586
587 msg.append("groupId=");
588 msg.append(groupId);
589
590 msg.append(StringPool.CLOSE_CURLY_BRACE);
591
592 throw new NoSuchStatsUserException(msg.toString());
593 }
594 else {
595 return list.get(0);
596 }
597 }
598
599
612 public MBStatsUser findByGroupId_Last(long groupId,
613 OrderByComparator orderByComparator)
614 throws NoSuchStatsUserException, SystemException {
615 int count = countByGroupId(groupId);
616
617 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
618 orderByComparator);
619
620 if (list.isEmpty()) {
621 StringBundler msg = new StringBundler(4);
622
623 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
624
625 msg.append("groupId=");
626 msg.append(groupId);
627
628 msg.append(StringPool.CLOSE_CURLY_BRACE);
629
630 throw new NoSuchStatsUserException(msg.toString());
631 }
632 else {
633 return list.get(0);
634 }
635 }
636
637
651 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
652 long groupId, OrderByComparator orderByComparator)
653 throws NoSuchStatsUserException, SystemException {
654 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
655
656 Session session = null;
657
658 try {
659 session = openSession();
660
661 MBStatsUser[] array = new MBStatsUserImpl[3];
662
663 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
664 orderByComparator, true);
665
666 array[1] = mbStatsUser;
667
668 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
669 orderByComparator, false);
670
671 return array;
672 }
673 catch (Exception e) {
674 throw processException(e);
675 }
676 finally {
677 closeSession(session);
678 }
679 }
680
681 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
682 MBStatsUser mbStatsUser, long groupId,
683 OrderByComparator orderByComparator, boolean previous) {
684 StringBundler query = null;
685
686 if (orderByComparator != null) {
687 query = new StringBundler(6 +
688 (orderByComparator.getOrderByFields().length * 6));
689 }
690 else {
691 query = new StringBundler(3);
692 }
693
694 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
695
696 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
697
698 if (orderByComparator != null) {
699 String[] orderByFields = orderByComparator.getOrderByFields();
700
701 if (orderByFields.length > 0) {
702 query.append(WHERE_AND);
703 }
704
705 for (int i = 0; i < orderByFields.length; i++) {
706 query.append(_ORDER_BY_ENTITY_ALIAS);
707 query.append(orderByFields[i]);
708
709 if ((i + 1) < orderByFields.length) {
710 if (orderByComparator.isAscending() ^ previous) {
711 query.append(WHERE_GREATER_THAN_HAS_NEXT);
712 }
713 else {
714 query.append(WHERE_LESSER_THAN_HAS_NEXT);
715 }
716 }
717 else {
718 if (orderByComparator.isAscending() ^ previous) {
719 query.append(WHERE_GREATER_THAN);
720 }
721 else {
722 query.append(WHERE_LESSER_THAN);
723 }
724 }
725 }
726
727 query.append(ORDER_BY_CLAUSE);
728
729 for (int i = 0; i < orderByFields.length; i++) {
730 query.append(_ORDER_BY_ENTITY_ALIAS);
731 query.append(orderByFields[i]);
732
733 if ((i + 1) < orderByFields.length) {
734 if (orderByComparator.isAscending() ^ previous) {
735 query.append(ORDER_BY_ASC_HAS_NEXT);
736 }
737 else {
738 query.append(ORDER_BY_DESC_HAS_NEXT);
739 }
740 }
741 else {
742 if (orderByComparator.isAscending() ^ previous) {
743 query.append(ORDER_BY_ASC);
744 }
745 else {
746 query.append(ORDER_BY_DESC);
747 }
748 }
749 }
750 }
751
752 else {
753 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
754 }
755
756 String sql = query.toString();
757
758 Query q = session.createQuery(sql);
759
760 q.setFirstResult(0);
761 q.setMaxResults(2);
762
763 QueryPos qPos = QueryPos.getInstance(q);
764
765 qPos.add(groupId);
766
767 if (orderByComparator != null) {
768 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
769
770 for (Object value : values) {
771 qPos.add(value);
772 }
773 }
774
775 List<MBStatsUser> list = q.list();
776
777 if (list.size() == 2) {
778 return list.get(1);
779 }
780 else {
781 return null;
782 }
783 }
784
785
792 public List<MBStatsUser> findByUserId(long userId)
793 throws SystemException {
794 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
795 }
796
797
810 public List<MBStatsUser> findByUserId(long userId, int start, int end)
811 throws SystemException {
812 return findByUserId(userId, start, end, null);
813 }
814
815
829 public List<MBStatsUser> findByUserId(long userId, int start, int end,
830 OrderByComparator orderByComparator) throws SystemException {
831 Object[] finderArgs = new Object[] {
832 userId,
833
834 String.valueOf(start), String.valueOf(end),
835 String.valueOf(orderByComparator)
836 };
837
838 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
839 finderArgs, this);
840
841 if (list == null) {
842 Session session = null;
843
844 try {
845 session = openSession();
846
847 StringBundler query = null;
848
849 if (orderByComparator != null) {
850 query = new StringBundler(3 +
851 (orderByComparator.getOrderByFields().length * 3));
852 }
853 else {
854 query = new StringBundler(3);
855 }
856
857 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
858
859 query.append(_FINDER_COLUMN_USERID_USERID_2);
860
861 if (orderByComparator != null) {
862 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
863 orderByComparator);
864 }
865
866 else {
867 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
868 }
869
870 String sql = query.toString();
871
872 Query q = session.createQuery(sql);
873
874 QueryPos qPos = QueryPos.getInstance(q);
875
876 qPos.add(userId);
877
878 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
879 start, end);
880 }
881 catch (Exception e) {
882 throw processException(e);
883 }
884 finally {
885 if (list == null) {
886 list = new ArrayList<MBStatsUser>();
887 }
888
889 cacheResult(list);
890
891 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
892 finderArgs, list);
893
894 closeSession(session);
895 }
896 }
897
898 return list;
899 }
900
901
914 public MBStatsUser findByUserId_First(long userId,
915 OrderByComparator orderByComparator)
916 throws NoSuchStatsUserException, SystemException {
917 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
918
919 if (list.isEmpty()) {
920 StringBundler msg = new StringBundler(4);
921
922 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
923
924 msg.append("userId=");
925 msg.append(userId);
926
927 msg.append(StringPool.CLOSE_CURLY_BRACE);
928
929 throw new NoSuchStatsUserException(msg.toString());
930 }
931 else {
932 return list.get(0);
933 }
934 }
935
936
949 public MBStatsUser findByUserId_Last(long userId,
950 OrderByComparator orderByComparator)
951 throws NoSuchStatsUserException, SystemException {
952 int count = countByUserId(userId);
953
954 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
955 orderByComparator);
956
957 if (list.isEmpty()) {
958 StringBundler msg = new StringBundler(4);
959
960 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
961
962 msg.append("userId=");
963 msg.append(userId);
964
965 msg.append(StringPool.CLOSE_CURLY_BRACE);
966
967 throw new NoSuchStatsUserException(msg.toString());
968 }
969 else {
970 return list.get(0);
971 }
972 }
973
974
988 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
989 long userId, OrderByComparator orderByComparator)
990 throws NoSuchStatsUserException, SystemException {
991 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
992
993 Session session = null;
994
995 try {
996 session = openSession();
997
998 MBStatsUser[] array = new MBStatsUserImpl[3];
999
1000 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1001 orderByComparator, true);
1002
1003 array[1] = mbStatsUser;
1004
1005 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1006 orderByComparator, false);
1007
1008 return array;
1009 }
1010 catch (Exception e) {
1011 throw processException(e);
1012 }
1013 finally {
1014 closeSession(session);
1015 }
1016 }
1017
1018 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1019 MBStatsUser mbStatsUser, long userId,
1020 OrderByComparator orderByComparator, boolean previous) {
1021 StringBundler query = null;
1022
1023 if (orderByComparator != null) {
1024 query = new StringBundler(6 +
1025 (orderByComparator.getOrderByFields().length * 6));
1026 }
1027 else {
1028 query = new StringBundler(3);
1029 }
1030
1031 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1032
1033 query.append(_FINDER_COLUMN_USERID_USERID_2);
1034
1035 if (orderByComparator != null) {
1036 String[] orderByFields = orderByComparator.getOrderByFields();
1037
1038 if (orderByFields.length > 0) {
1039 query.append(WHERE_AND);
1040 }
1041
1042 for (int i = 0; i < orderByFields.length; i++) {
1043 query.append(_ORDER_BY_ENTITY_ALIAS);
1044 query.append(orderByFields[i]);
1045
1046 if ((i + 1) < orderByFields.length) {
1047 if (orderByComparator.isAscending() ^ previous) {
1048 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1049 }
1050 else {
1051 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1052 }
1053 }
1054 else {
1055 if (orderByComparator.isAscending() ^ previous) {
1056 query.append(WHERE_GREATER_THAN);
1057 }
1058 else {
1059 query.append(WHERE_LESSER_THAN);
1060 }
1061 }
1062 }
1063
1064 query.append(ORDER_BY_CLAUSE);
1065
1066 for (int i = 0; i < orderByFields.length; i++) {
1067 query.append(_ORDER_BY_ENTITY_ALIAS);
1068 query.append(orderByFields[i]);
1069
1070 if ((i + 1) < orderByFields.length) {
1071 if (orderByComparator.isAscending() ^ previous) {
1072 query.append(ORDER_BY_ASC_HAS_NEXT);
1073 }
1074 else {
1075 query.append(ORDER_BY_DESC_HAS_NEXT);
1076 }
1077 }
1078 else {
1079 if (orderByComparator.isAscending() ^ previous) {
1080 query.append(ORDER_BY_ASC);
1081 }
1082 else {
1083 query.append(ORDER_BY_DESC);
1084 }
1085 }
1086 }
1087 }
1088
1089 else {
1090 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1091 }
1092
1093 String sql = query.toString();
1094
1095 Query q = session.createQuery(sql);
1096
1097 q.setFirstResult(0);
1098 q.setMaxResults(2);
1099
1100 QueryPos qPos = QueryPos.getInstance(q);
1101
1102 qPos.add(userId);
1103
1104 if (orderByComparator != null) {
1105 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1106
1107 for (Object value : values) {
1108 qPos.add(value);
1109 }
1110 }
1111
1112 List<MBStatsUser> list = q.list();
1113
1114 if (list.size() == 2) {
1115 return list.get(1);
1116 }
1117 else {
1118 return null;
1119 }
1120 }
1121
1122
1131 public MBStatsUser findByG_U(long groupId, long userId)
1132 throws NoSuchStatsUserException, SystemException {
1133 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1134
1135 if (mbStatsUser == null) {
1136 StringBundler msg = new StringBundler(6);
1137
1138 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139
1140 msg.append("groupId=");
1141 msg.append(groupId);
1142
1143 msg.append(", userId=");
1144 msg.append(userId);
1145
1146 msg.append(StringPool.CLOSE_CURLY_BRACE);
1147
1148 if (_log.isWarnEnabled()) {
1149 _log.warn(msg.toString());
1150 }
1151
1152 throw new NoSuchStatsUserException(msg.toString());
1153 }
1154
1155 return mbStatsUser;
1156 }
1157
1158
1166 public MBStatsUser fetchByG_U(long groupId, long userId)
1167 throws SystemException {
1168 return fetchByG_U(groupId, userId, true);
1169 }
1170
1171
1179 public MBStatsUser fetchByG_U(long groupId, long userId,
1180 boolean retrieveFromCache) throws SystemException {
1181 Object[] finderArgs = new Object[] { groupId, userId };
1182
1183 Object result = null;
1184
1185 if (retrieveFromCache) {
1186 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1187 finderArgs, this);
1188 }
1189
1190 if (result == null) {
1191 Session session = null;
1192
1193 try {
1194 session = openSession();
1195
1196 StringBundler query = new StringBundler(4);
1197
1198 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1199
1200 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1201
1202 query.append(_FINDER_COLUMN_G_U_USERID_2);
1203
1204 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1205
1206 String sql = query.toString();
1207
1208 Query q = session.createQuery(sql);
1209
1210 QueryPos qPos = QueryPos.getInstance(q);
1211
1212 qPos.add(groupId);
1213
1214 qPos.add(userId);
1215
1216 List<MBStatsUser> list = q.list();
1217
1218 result = list;
1219
1220 MBStatsUser mbStatsUser = null;
1221
1222 if (list.isEmpty()) {
1223 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1224 finderArgs, list);
1225 }
1226 else {
1227 mbStatsUser = list.get(0);
1228
1229 cacheResult(mbStatsUser);
1230
1231 if ((mbStatsUser.getGroupId() != groupId) ||
1232 (mbStatsUser.getUserId() != userId)) {
1233 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1234 finderArgs, mbStatsUser);
1235 }
1236 }
1237
1238 return mbStatsUser;
1239 }
1240 catch (Exception e) {
1241 throw processException(e);
1242 }
1243 finally {
1244 if (result == null) {
1245 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1246 finderArgs, new ArrayList<MBStatsUser>());
1247 }
1248
1249 closeSession(session);
1250 }
1251 }
1252 else {
1253 if (result instanceof List<?>) {
1254 return null;
1255 }
1256 else {
1257 return (MBStatsUser)result;
1258 }
1259 }
1260 }
1261
1262
1270 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount)
1271 throws SystemException {
1272 return findByG_NotM(groupId, messageCount, QueryUtil.ALL_POS,
1273 QueryUtil.ALL_POS, null);
1274 }
1275
1276
1290 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1291 int start, int end) throws SystemException {
1292 return findByG_NotM(groupId, messageCount, start, end, null);
1293 }
1294
1295
1310 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1311 int start, int end, OrderByComparator orderByComparator)
1312 throws SystemException {
1313 Object[] finderArgs = new Object[] {
1314 groupId, messageCount,
1315
1316 String.valueOf(start), String.valueOf(end),
1317 String.valueOf(orderByComparator)
1318 };
1319
1320 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTM,
1321 finderArgs, this);
1322
1323 if (list == null) {
1324 Session session = null;
1325
1326 try {
1327 session = openSession();
1328
1329 StringBundler query = null;
1330
1331 if (orderByComparator != null) {
1332 query = new StringBundler(4 +
1333 (orderByComparator.getOrderByFields().length * 3));
1334 }
1335 else {
1336 query = new StringBundler(4);
1337 }
1338
1339 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1340
1341 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1342
1343 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1344
1345 if (orderByComparator != null) {
1346 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1347 orderByComparator);
1348 }
1349
1350 else {
1351 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1352 }
1353
1354 String sql = query.toString();
1355
1356 Query q = session.createQuery(sql);
1357
1358 QueryPos qPos = QueryPos.getInstance(q);
1359
1360 qPos.add(groupId);
1361
1362 qPos.add(messageCount);
1363
1364 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1365 start, end);
1366 }
1367 catch (Exception e) {
1368 throw processException(e);
1369 }
1370 finally {
1371 if (list == null) {
1372 list = new ArrayList<MBStatsUser>();
1373 }
1374
1375 cacheResult(list);
1376
1377 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTM,
1378 finderArgs, list);
1379
1380 closeSession(session);
1381 }
1382 }
1383
1384 return list;
1385 }
1386
1387
1401 public MBStatsUser findByG_NotM_First(long groupId, int messageCount,
1402 OrderByComparator orderByComparator)
1403 throws NoSuchStatsUserException, SystemException {
1404 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, 0, 1,
1405 orderByComparator);
1406
1407 if (list.isEmpty()) {
1408 StringBundler msg = new StringBundler(6);
1409
1410 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1411
1412 msg.append("groupId=");
1413 msg.append(groupId);
1414
1415 msg.append(", messageCount=");
1416 msg.append(messageCount);
1417
1418 msg.append(StringPool.CLOSE_CURLY_BRACE);
1419
1420 throw new NoSuchStatsUserException(msg.toString());
1421 }
1422 else {
1423 return list.get(0);
1424 }
1425 }
1426
1427
1441 public MBStatsUser findByG_NotM_Last(long groupId, int messageCount,
1442 OrderByComparator orderByComparator)
1443 throws NoSuchStatsUserException, SystemException {
1444 int count = countByG_NotM(groupId, messageCount);
1445
1446 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, count - 1,
1447 count, orderByComparator);
1448
1449 if (list.isEmpty()) {
1450 StringBundler msg = new StringBundler(6);
1451
1452 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1453
1454 msg.append("groupId=");
1455 msg.append(groupId);
1456
1457 msg.append(", messageCount=");
1458 msg.append(messageCount);
1459
1460 msg.append(StringPool.CLOSE_CURLY_BRACE);
1461
1462 throw new NoSuchStatsUserException(msg.toString());
1463 }
1464 else {
1465 return list.get(0);
1466 }
1467 }
1468
1469
1484 public MBStatsUser[] findByG_NotM_PrevAndNext(long statsUserId,
1485 long groupId, int messageCount, OrderByComparator orderByComparator)
1486 throws NoSuchStatsUserException, SystemException {
1487 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1488
1489 Session session = null;
1490
1491 try {
1492 session = openSession();
1493
1494 MBStatsUser[] array = new MBStatsUserImpl[3];
1495
1496 array[0] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1497 messageCount, orderByComparator, true);
1498
1499 array[1] = mbStatsUser;
1500
1501 array[2] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1502 messageCount, orderByComparator, false);
1503
1504 return array;
1505 }
1506 catch (Exception e) {
1507 throw processException(e);
1508 }
1509 finally {
1510 closeSession(session);
1511 }
1512 }
1513
1514 protected MBStatsUser getByG_NotM_PrevAndNext(Session session,
1515 MBStatsUser mbStatsUser, long groupId, int messageCount,
1516 OrderByComparator orderByComparator, boolean previous) {
1517 StringBundler query = null;
1518
1519 if (orderByComparator != null) {
1520 query = new StringBundler(6 +
1521 (orderByComparator.getOrderByFields().length * 6));
1522 }
1523 else {
1524 query = new StringBundler(3);
1525 }
1526
1527 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1528
1529 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1530
1531 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1532
1533 if (orderByComparator != null) {
1534 String[] orderByFields = orderByComparator.getOrderByFields();
1535
1536 if (orderByFields.length > 0) {
1537 query.append(WHERE_AND);
1538 }
1539
1540 for (int i = 0; i < orderByFields.length; i++) {
1541 query.append(_ORDER_BY_ENTITY_ALIAS);
1542 query.append(orderByFields[i]);
1543
1544 if ((i + 1) < orderByFields.length) {
1545 if (orderByComparator.isAscending() ^ previous) {
1546 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1547 }
1548 else {
1549 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1550 }
1551 }
1552 else {
1553 if (orderByComparator.isAscending() ^ previous) {
1554 query.append(WHERE_GREATER_THAN);
1555 }
1556 else {
1557 query.append(WHERE_LESSER_THAN);
1558 }
1559 }
1560 }
1561
1562 query.append(ORDER_BY_CLAUSE);
1563
1564 for (int i = 0; i < orderByFields.length; i++) {
1565 query.append(_ORDER_BY_ENTITY_ALIAS);
1566 query.append(orderByFields[i]);
1567
1568 if ((i + 1) < orderByFields.length) {
1569 if (orderByComparator.isAscending() ^ previous) {
1570 query.append(ORDER_BY_ASC_HAS_NEXT);
1571 }
1572 else {
1573 query.append(ORDER_BY_DESC_HAS_NEXT);
1574 }
1575 }
1576 else {
1577 if (orderByComparator.isAscending() ^ previous) {
1578 query.append(ORDER_BY_ASC);
1579 }
1580 else {
1581 query.append(ORDER_BY_DESC);
1582 }
1583 }
1584 }
1585 }
1586
1587 else {
1588 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1589 }
1590
1591 String sql = query.toString();
1592
1593 Query q = session.createQuery(sql);
1594
1595 q.setFirstResult(0);
1596 q.setMaxResults(2);
1597
1598 QueryPos qPos = QueryPos.getInstance(q);
1599
1600 qPos.add(groupId);
1601
1602 qPos.add(messageCount);
1603
1604 if (orderByComparator != null) {
1605 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1606
1607 for (Object value : values) {
1608 qPos.add(value);
1609 }
1610 }
1611
1612 List<MBStatsUser> list = q.list();
1613
1614 if (list.size() == 2) {
1615 return list.get(1);
1616 }
1617 else {
1618 return null;
1619 }
1620 }
1621
1622
1628 public List<MBStatsUser> findAll() throws SystemException {
1629 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1630 }
1631
1632
1644 public List<MBStatsUser> findAll(int start, int end)
1645 throws SystemException {
1646 return findAll(start, end, null);
1647 }
1648
1649
1662 public List<MBStatsUser> findAll(int start, int end,
1663 OrderByComparator orderByComparator) throws SystemException {
1664 Object[] finderArgs = new Object[] {
1665 String.valueOf(start), String.valueOf(end),
1666 String.valueOf(orderByComparator)
1667 };
1668
1669 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1670 finderArgs, this);
1671
1672 if (list == null) {
1673 Session session = null;
1674
1675 try {
1676 session = openSession();
1677
1678 StringBundler query = null;
1679 String sql = null;
1680
1681 if (orderByComparator != null) {
1682 query = new StringBundler(2 +
1683 (orderByComparator.getOrderByFields().length * 3));
1684
1685 query.append(_SQL_SELECT_MBSTATSUSER);
1686
1687 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1688 orderByComparator);
1689
1690 sql = query.toString();
1691 }
1692 else {
1693 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1694 }
1695
1696 Query q = session.createQuery(sql);
1697
1698 if (orderByComparator == null) {
1699 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1700 start, end, false);
1701
1702 Collections.sort(list);
1703 }
1704 else {
1705 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1706 start, end);
1707 }
1708 }
1709 catch (Exception e) {
1710 throw processException(e);
1711 }
1712 finally {
1713 if (list == null) {
1714 list = new ArrayList<MBStatsUser>();
1715 }
1716
1717 cacheResult(list);
1718
1719 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1720
1721 closeSession(session);
1722 }
1723 }
1724
1725 return list;
1726 }
1727
1728
1734 public void removeByGroupId(long groupId) throws SystemException {
1735 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1736 remove(mbStatsUser);
1737 }
1738 }
1739
1740
1746 public void removeByUserId(long userId) throws SystemException {
1747 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1748 remove(mbStatsUser);
1749 }
1750 }
1751
1752
1759 public void removeByG_U(long groupId, long userId)
1760 throws NoSuchStatsUserException, SystemException {
1761 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1762
1763 remove(mbStatsUser);
1764 }
1765
1766
1773 public void removeByG_NotM(long groupId, int messageCount)
1774 throws SystemException {
1775 for (MBStatsUser mbStatsUser : findByG_NotM(groupId, messageCount)) {
1776 remove(mbStatsUser);
1777 }
1778 }
1779
1780
1785 public void removeAll() throws SystemException {
1786 for (MBStatsUser mbStatsUser : findAll()) {
1787 remove(mbStatsUser);
1788 }
1789 }
1790
1791
1798 public int countByGroupId(long groupId) throws SystemException {
1799 Object[] finderArgs = new Object[] { groupId };
1800
1801 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1802 finderArgs, this);
1803
1804 if (count == null) {
1805 Session session = null;
1806
1807 try {
1808 session = openSession();
1809
1810 StringBundler query = new StringBundler(2);
1811
1812 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1813
1814 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1815
1816 String sql = query.toString();
1817
1818 Query q = session.createQuery(sql);
1819
1820 QueryPos qPos = QueryPos.getInstance(q);
1821
1822 qPos.add(groupId);
1823
1824 count = (Long)q.uniqueResult();
1825 }
1826 catch (Exception e) {
1827 throw processException(e);
1828 }
1829 finally {
1830 if (count == null) {
1831 count = Long.valueOf(0);
1832 }
1833
1834 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1835 finderArgs, count);
1836
1837 closeSession(session);
1838 }
1839 }
1840
1841 return count.intValue();
1842 }
1843
1844
1851 public int countByUserId(long userId) throws SystemException {
1852 Object[] finderArgs = new Object[] { userId };
1853
1854 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1855 finderArgs, this);
1856
1857 if (count == null) {
1858 Session session = null;
1859
1860 try {
1861 session = openSession();
1862
1863 StringBundler query = new StringBundler(2);
1864
1865 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1866
1867 query.append(_FINDER_COLUMN_USERID_USERID_2);
1868
1869 String sql = query.toString();
1870
1871 Query q = session.createQuery(sql);
1872
1873 QueryPos qPos = QueryPos.getInstance(q);
1874
1875 qPos.add(userId);
1876
1877 count = (Long)q.uniqueResult();
1878 }
1879 catch (Exception e) {
1880 throw processException(e);
1881 }
1882 finally {
1883 if (count == null) {
1884 count = Long.valueOf(0);
1885 }
1886
1887 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1888 finderArgs, count);
1889
1890 closeSession(session);
1891 }
1892 }
1893
1894 return count.intValue();
1895 }
1896
1897
1905 public int countByG_U(long groupId, long userId) throws SystemException {
1906 Object[] finderArgs = new Object[] { groupId, userId };
1907
1908 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1909 finderArgs, this);
1910
1911 if (count == null) {
1912 Session session = null;
1913
1914 try {
1915 session = openSession();
1916
1917 StringBundler query = new StringBundler(3);
1918
1919 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1920
1921 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1922
1923 query.append(_FINDER_COLUMN_G_U_USERID_2);
1924
1925 String sql = query.toString();
1926
1927 Query q = session.createQuery(sql);
1928
1929 QueryPos qPos = QueryPos.getInstance(q);
1930
1931 qPos.add(groupId);
1932
1933 qPos.add(userId);
1934
1935 count = (Long)q.uniqueResult();
1936 }
1937 catch (Exception e) {
1938 throw processException(e);
1939 }
1940 finally {
1941 if (count == null) {
1942 count = Long.valueOf(0);
1943 }
1944
1945 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1946 count);
1947
1948 closeSession(session);
1949 }
1950 }
1951
1952 return count.intValue();
1953 }
1954
1955
1963 public int countByG_NotM(long groupId, int messageCount)
1964 throws SystemException {
1965 Object[] finderArgs = new Object[] { groupId, messageCount };
1966
1967 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTM,
1968 finderArgs, this);
1969
1970 if (count == null) {
1971 Session session = null;
1972
1973 try {
1974 session = openSession();
1975
1976 StringBundler query = new StringBundler(3);
1977
1978 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1979
1980 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1981
1982 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1983
1984 String sql = query.toString();
1985
1986 Query q = session.createQuery(sql);
1987
1988 QueryPos qPos = QueryPos.getInstance(q);
1989
1990 qPos.add(groupId);
1991
1992 qPos.add(messageCount);
1993
1994 count = (Long)q.uniqueResult();
1995 }
1996 catch (Exception e) {
1997 throw processException(e);
1998 }
1999 finally {
2000 if (count == null) {
2001 count = Long.valueOf(0);
2002 }
2003
2004 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTM,
2005 finderArgs, count);
2006
2007 closeSession(session);
2008 }
2009 }
2010
2011 return count.intValue();
2012 }
2013
2014
2020 public int countAll() throws SystemException {
2021 Object[] finderArgs = new Object[0];
2022
2023 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2024 finderArgs, this);
2025
2026 if (count == null) {
2027 Session session = null;
2028
2029 try {
2030 session = openSession();
2031
2032 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2033
2034 count = (Long)q.uniqueResult();
2035 }
2036 catch (Exception e) {
2037 throw processException(e);
2038 }
2039 finally {
2040 if (count == null) {
2041 count = Long.valueOf(0);
2042 }
2043
2044 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2045 count);
2046
2047 closeSession(session);
2048 }
2049 }
2050
2051 return count.intValue();
2052 }
2053
2054
2057 public void afterPropertiesSet() {
2058 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2059 com.liferay.portal.util.PropsUtil.get(
2060 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2061
2062 if (listenerClassNames.length > 0) {
2063 try {
2064 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2065
2066 for (String listenerClassName : listenerClassNames) {
2067 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2068 listenerClassName));
2069 }
2070
2071 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2072 }
2073 catch (Exception e) {
2074 _log.error(e);
2075 }
2076 }
2077 }
2078
2079 public void destroy() {
2080 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2081 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2082 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2083 }
2084
2085 @BeanReference(type = MBBanPersistence.class)
2086 protected MBBanPersistence mbBanPersistence;
2087 @BeanReference(type = MBCategoryPersistence.class)
2088 protected MBCategoryPersistence mbCategoryPersistence;
2089 @BeanReference(type = MBDiscussionPersistence.class)
2090 protected MBDiscussionPersistence mbDiscussionPersistence;
2091 @BeanReference(type = MBMailingListPersistence.class)
2092 protected MBMailingListPersistence mbMailingListPersistence;
2093 @BeanReference(type = MBMessagePersistence.class)
2094 protected MBMessagePersistence mbMessagePersistence;
2095 @BeanReference(type = MBMessageFlagPersistence.class)
2096 protected MBMessageFlagPersistence mbMessageFlagPersistence;
2097 @BeanReference(type = MBStatsUserPersistence.class)
2098 protected MBStatsUserPersistence mbStatsUserPersistence;
2099 @BeanReference(type = MBThreadPersistence.class)
2100 protected MBThreadPersistence mbThreadPersistence;
2101 @BeanReference(type = ResourcePersistence.class)
2102 protected ResourcePersistence resourcePersistence;
2103 @BeanReference(type = UserPersistence.class)
2104 protected UserPersistence userPersistence;
2105 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2106 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2107 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2108 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2109 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2110 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2111 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2112 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2113 private static final String _FINDER_COLUMN_G_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2114 private static final String _FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2115 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2116 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2117 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2118 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2119 }