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 if (mbStatsUser.isCachedModel() || BatchSessionUtil.isEnabled()) {
267 Object staleObject = session.get(MBStatsUserImpl.class,
268 mbStatsUser.getPrimaryKeyObj());
269
270 if (staleObject != null) {
271 session.evict(staleObject);
272 }
273 }
274
275 session.delete(mbStatsUser);
276
277 session.flush();
278 }
279 catch (Exception e) {
280 throw processException(e);
281 }
282 finally {
283 closeSession(session);
284 }
285
286 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
287
288 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
289
290 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
291 new Object[] {
292 new Long(mbStatsUserModelImpl.getOriginalGroupId()),
293 new Long(mbStatsUserModelImpl.getOriginalUserId())
294 });
295
296 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
297 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
298
299 return mbStatsUser;
300 }
301
302 public MBStatsUser updateImpl(
303 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
304 boolean merge) throws SystemException {
305 mbStatsUser = toUnwrappedModel(mbStatsUser);
306
307 boolean isNew = mbStatsUser.isNew();
308
309 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
310
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 BatchSessionUtil.update(session, mbStatsUser, merge);
317
318 mbStatsUser.setNew(false);
319 }
320 catch (Exception e) {
321 throw processException(e);
322 }
323 finally {
324 closeSession(session);
325 }
326
327 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
328
329 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
330 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
331
332 if (!isNew &&
333 ((mbStatsUser.getGroupId() != mbStatsUserModelImpl.getOriginalGroupId()) ||
334 (mbStatsUser.getUserId() != mbStatsUserModelImpl.getOriginalUserId()))) {
335 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
336 new Object[] {
337 new Long(mbStatsUserModelImpl.getOriginalGroupId()),
338 new Long(mbStatsUserModelImpl.getOriginalUserId())
339 });
340 }
341
342 if (isNew ||
343 ((mbStatsUser.getGroupId() != mbStatsUserModelImpl.getOriginalGroupId()) ||
344 (mbStatsUser.getUserId() != mbStatsUserModelImpl.getOriginalUserId()))) {
345 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
346 new Object[] {
347 new Long(mbStatsUser.getGroupId()),
348 new Long(mbStatsUser.getUserId())
349 }, mbStatsUser);
350 }
351
352 return mbStatsUser;
353 }
354
355 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
356 if (mbStatsUser instanceof MBStatsUserImpl) {
357 return mbStatsUser;
358 }
359
360 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
361
362 mbStatsUserImpl.setNew(mbStatsUser.isNew());
363 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
364
365 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
366 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
367 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
368 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
369 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
370
371 return mbStatsUserImpl;
372 }
373
374
382 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
383 throws NoSuchModelException, SystemException {
384 return findByPrimaryKey(((Long)primaryKey).longValue());
385 }
386
387
395 public MBStatsUser findByPrimaryKey(long statsUserId)
396 throws NoSuchStatsUserException, SystemException {
397 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
398
399 if (mbStatsUser == null) {
400 if (_log.isWarnEnabled()) {
401 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
402 }
403
404 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
405 statsUserId);
406 }
407
408 return mbStatsUser;
409 }
410
411
418 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
419 throws SystemException {
420 return fetchByPrimaryKey(((Long)primaryKey).longValue());
421 }
422
423
430 public MBStatsUser fetchByPrimaryKey(long statsUserId)
431 throws SystemException {
432 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
433 MBStatsUserImpl.class, statsUserId, this);
434
435 if (mbStatsUser == null) {
436 Session session = null;
437
438 try {
439 session = openSession();
440
441 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
442 new Long(statsUserId));
443 }
444 catch (Exception e) {
445 throw processException(e);
446 }
447 finally {
448 if (mbStatsUser != null) {
449 cacheResult(mbStatsUser);
450 }
451
452 closeSession(session);
453 }
454 }
455
456 return mbStatsUser;
457 }
458
459
466 public List<MBStatsUser> findByGroupId(long groupId)
467 throws SystemException {
468 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
469 }
470
471
484 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
485 throws SystemException {
486 return findByGroupId(groupId, start, end, null);
487 }
488
489
503 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
504 OrderByComparator orderByComparator) throws SystemException {
505 Object[] finderArgs = new Object[] {
506 groupId,
507
508 String.valueOf(start), String.valueOf(end),
509 String.valueOf(orderByComparator)
510 };
511
512 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
513 finderArgs, this);
514
515 if (list == null) {
516 Session session = null;
517
518 try {
519 session = openSession();
520
521 StringBundler query = null;
522
523 if (orderByComparator != null) {
524 query = new StringBundler(3 +
525 (orderByComparator.getOrderByFields().length * 3));
526 }
527 else {
528 query = new StringBundler(3);
529 }
530
531 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
532
533 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
534
535 if (orderByComparator != null) {
536 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
537 orderByComparator);
538 }
539
540 else {
541 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
542 }
543
544 String sql = query.toString();
545
546 Query q = session.createQuery(sql);
547
548 QueryPos qPos = QueryPos.getInstance(q);
549
550 qPos.add(groupId);
551
552 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
553 start, end);
554 }
555 catch (Exception e) {
556 throw processException(e);
557 }
558 finally {
559 if (list == null) {
560 list = new ArrayList<MBStatsUser>();
561 }
562
563 cacheResult(list);
564
565 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
566 finderArgs, list);
567
568 closeSession(session);
569 }
570 }
571
572 return list;
573 }
574
575
588 public MBStatsUser findByGroupId_First(long groupId,
589 OrderByComparator orderByComparator)
590 throws NoSuchStatsUserException, SystemException {
591 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
592
593 if (list.isEmpty()) {
594 StringBundler msg = new StringBundler(4);
595
596 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
597
598 msg.append("groupId=");
599 msg.append(groupId);
600
601 msg.append(StringPool.CLOSE_CURLY_BRACE);
602
603 throw new NoSuchStatsUserException(msg.toString());
604 }
605 else {
606 return list.get(0);
607 }
608 }
609
610
623 public MBStatsUser findByGroupId_Last(long groupId,
624 OrderByComparator orderByComparator)
625 throws NoSuchStatsUserException, SystemException {
626 int count = countByGroupId(groupId);
627
628 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
629 orderByComparator);
630
631 if (list.isEmpty()) {
632 StringBundler msg = new StringBundler(4);
633
634 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
635
636 msg.append("groupId=");
637 msg.append(groupId);
638
639 msg.append(StringPool.CLOSE_CURLY_BRACE);
640
641 throw new NoSuchStatsUserException(msg.toString());
642 }
643 else {
644 return list.get(0);
645 }
646 }
647
648
662 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
663 long groupId, OrderByComparator orderByComparator)
664 throws NoSuchStatsUserException, SystemException {
665 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
666
667 Session session = null;
668
669 try {
670 session = openSession();
671
672 MBStatsUser[] array = new MBStatsUserImpl[3];
673
674 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
675 orderByComparator, true);
676
677 array[1] = mbStatsUser;
678
679 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
680 orderByComparator, false);
681
682 return array;
683 }
684 catch (Exception e) {
685 throw processException(e);
686 }
687 finally {
688 closeSession(session);
689 }
690 }
691
692 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
693 MBStatsUser mbStatsUser, long groupId,
694 OrderByComparator orderByComparator, boolean previous) {
695 StringBundler query = null;
696
697 if (orderByComparator != null) {
698 query = new StringBundler(6 +
699 (orderByComparator.getOrderByFields().length * 6));
700 }
701 else {
702 query = new StringBundler(3);
703 }
704
705 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
706
707 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
708
709 if (orderByComparator != null) {
710 String[] orderByFields = orderByComparator.getOrderByFields();
711
712 if (orderByFields.length > 0) {
713 query.append(WHERE_AND);
714 }
715
716 for (int i = 0; i < orderByFields.length; i++) {
717 query.append(_ORDER_BY_ENTITY_ALIAS);
718 query.append(orderByFields[i]);
719
720 if ((i + 1) < orderByFields.length) {
721 if (orderByComparator.isAscending() ^ previous) {
722 query.append(WHERE_GREATER_THAN_HAS_NEXT);
723 }
724 else {
725 query.append(WHERE_LESSER_THAN_HAS_NEXT);
726 }
727 }
728 else {
729 if (orderByComparator.isAscending() ^ previous) {
730 query.append(WHERE_GREATER_THAN);
731 }
732 else {
733 query.append(WHERE_LESSER_THAN);
734 }
735 }
736 }
737
738 query.append(ORDER_BY_CLAUSE);
739
740 for (int i = 0; i < orderByFields.length; i++) {
741 query.append(_ORDER_BY_ENTITY_ALIAS);
742 query.append(orderByFields[i]);
743
744 if ((i + 1) < orderByFields.length) {
745 if (orderByComparator.isAscending() ^ previous) {
746 query.append(ORDER_BY_ASC_HAS_NEXT);
747 }
748 else {
749 query.append(ORDER_BY_DESC_HAS_NEXT);
750 }
751 }
752 else {
753 if (orderByComparator.isAscending() ^ previous) {
754 query.append(ORDER_BY_ASC);
755 }
756 else {
757 query.append(ORDER_BY_DESC);
758 }
759 }
760 }
761 }
762
763 else {
764 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
765 }
766
767 String sql = query.toString();
768
769 Query q = session.createQuery(sql);
770
771 q.setFirstResult(0);
772 q.setMaxResults(2);
773
774 QueryPos qPos = QueryPos.getInstance(q);
775
776 qPos.add(groupId);
777
778 if (orderByComparator != null) {
779 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
780
781 for (Object value : values) {
782 qPos.add(value);
783 }
784 }
785
786 List<MBStatsUser> list = q.list();
787
788 if (list.size() == 2) {
789 return list.get(1);
790 }
791 else {
792 return null;
793 }
794 }
795
796
803 public List<MBStatsUser> findByUserId(long userId)
804 throws SystemException {
805 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
806 }
807
808
821 public List<MBStatsUser> findByUserId(long userId, int start, int end)
822 throws SystemException {
823 return findByUserId(userId, start, end, null);
824 }
825
826
840 public List<MBStatsUser> findByUserId(long userId, int start, int end,
841 OrderByComparator orderByComparator) throws SystemException {
842 Object[] finderArgs = new Object[] {
843 userId,
844
845 String.valueOf(start), String.valueOf(end),
846 String.valueOf(orderByComparator)
847 };
848
849 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
850 finderArgs, this);
851
852 if (list == null) {
853 Session session = null;
854
855 try {
856 session = openSession();
857
858 StringBundler query = null;
859
860 if (orderByComparator != null) {
861 query = new StringBundler(3 +
862 (orderByComparator.getOrderByFields().length * 3));
863 }
864 else {
865 query = new StringBundler(3);
866 }
867
868 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
869
870 query.append(_FINDER_COLUMN_USERID_USERID_2);
871
872 if (orderByComparator != null) {
873 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
874 orderByComparator);
875 }
876
877 else {
878 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
879 }
880
881 String sql = query.toString();
882
883 Query q = session.createQuery(sql);
884
885 QueryPos qPos = QueryPos.getInstance(q);
886
887 qPos.add(userId);
888
889 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
890 start, end);
891 }
892 catch (Exception e) {
893 throw processException(e);
894 }
895 finally {
896 if (list == null) {
897 list = new ArrayList<MBStatsUser>();
898 }
899
900 cacheResult(list);
901
902 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
903 finderArgs, list);
904
905 closeSession(session);
906 }
907 }
908
909 return list;
910 }
911
912
925 public MBStatsUser findByUserId_First(long userId,
926 OrderByComparator orderByComparator)
927 throws NoSuchStatsUserException, SystemException {
928 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
929
930 if (list.isEmpty()) {
931 StringBundler msg = new StringBundler(4);
932
933 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
934
935 msg.append("userId=");
936 msg.append(userId);
937
938 msg.append(StringPool.CLOSE_CURLY_BRACE);
939
940 throw new NoSuchStatsUserException(msg.toString());
941 }
942 else {
943 return list.get(0);
944 }
945 }
946
947
960 public MBStatsUser findByUserId_Last(long userId,
961 OrderByComparator orderByComparator)
962 throws NoSuchStatsUserException, SystemException {
963 int count = countByUserId(userId);
964
965 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
966 orderByComparator);
967
968 if (list.isEmpty()) {
969 StringBundler msg = new StringBundler(4);
970
971 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
972
973 msg.append("userId=");
974 msg.append(userId);
975
976 msg.append(StringPool.CLOSE_CURLY_BRACE);
977
978 throw new NoSuchStatsUserException(msg.toString());
979 }
980 else {
981 return list.get(0);
982 }
983 }
984
985
999 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
1000 long userId, OrderByComparator orderByComparator)
1001 throws NoSuchStatsUserException, SystemException {
1002 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1003
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 MBStatsUser[] array = new MBStatsUserImpl[3];
1010
1011 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1012 orderByComparator, true);
1013
1014 array[1] = mbStatsUser;
1015
1016 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1017 orderByComparator, false);
1018
1019 return array;
1020 }
1021 catch (Exception e) {
1022 throw processException(e);
1023 }
1024 finally {
1025 closeSession(session);
1026 }
1027 }
1028
1029 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1030 MBStatsUser mbStatsUser, long userId,
1031 OrderByComparator orderByComparator, boolean previous) {
1032 StringBundler query = null;
1033
1034 if (orderByComparator != null) {
1035 query = new StringBundler(6 +
1036 (orderByComparator.getOrderByFields().length * 6));
1037 }
1038 else {
1039 query = new StringBundler(3);
1040 }
1041
1042 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1043
1044 query.append(_FINDER_COLUMN_USERID_USERID_2);
1045
1046 if (orderByComparator != null) {
1047 String[] orderByFields = orderByComparator.getOrderByFields();
1048
1049 if (orderByFields.length > 0) {
1050 query.append(WHERE_AND);
1051 }
1052
1053 for (int i = 0; i < orderByFields.length; i++) {
1054 query.append(_ORDER_BY_ENTITY_ALIAS);
1055 query.append(orderByFields[i]);
1056
1057 if ((i + 1) < orderByFields.length) {
1058 if (orderByComparator.isAscending() ^ previous) {
1059 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1060 }
1061 else {
1062 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1063 }
1064 }
1065 else {
1066 if (orderByComparator.isAscending() ^ previous) {
1067 query.append(WHERE_GREATER_THAN);
1068 }
1069 else {
1070 query.append(WHERE_LESSER_THAN);
1071 }
1072 }
1073 }
1074
1075 query.append(ORDER_BY_CLAUSE);
1076
1077 for (int i = 0; i < orderByFields.length; i++) {
1078 query.append(_ORDER_BY_ENTITY_ALIAS);
1079 query.append(orderByFields[i]);
1080
1081 if ((i + 1) < orderByFields.length) {
1082 if (orderByComparator.isAscending() ^ previous) {
1083 query.append(ORDER_BY_ASC_HAS_NEXT);
1084 }
1085 else {
1086 query.append(ORDER_BY_DESC_HAS_NEXT);
1087 }
1088 }
1089 else {
1090 if (orderByComparator.isAscending() ^ previous) {
1091 query.append(ORDER_BY_ASC);
1092 }
1093 else {
1094 query.append(ORDER_BY_DESC);
1095 }
1096 }
1097 }
1098 }
1099
1100 else {
1101 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1102 }
1103
1104 String sql = query.toString();
1105
1106 Query q = session.createQuery(sql);
1107
1108 q.setFirstResult(0);
1109 q.setMaxResults(2);
1110
1111 QueryPos qPos = QueryPos.getInstance(q);
1112
1113 qPos.add(userId);
1114
1115 if (orderByComparator != null) {
1116 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1117
1118 for (Object value : values) {
1119 qPos.add(value);
1120 }
1121 }
1122
1123 List<MBStatsUser> list = q.list();
1124
1125 if (list.size() == 2) {
1126 return list.get(1);
1127 }
1128 else {
1129 return null;
1130 }
1131 }
1132
1133
1142 public MBStatsUser findByG_U(long groupId, long userId)
1143 throws NoSuchStatsUserException, SystemException {
1144 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1145
1146 if (mbStatsUser == null) {
1147 StringBundler msg = new StringBundler(6);
1148
1149 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1150
1151 msg.append("groupId=");
1152 msg.append(groupId);
1153
1154 msg.append(", userId=");
1155 msg.append(userId);
1156
1157 msg.append(StringPool.CLOSE_CURLY_BRACE);
1158
1159 if (_log.isWarnEnabled()) {
1160 _log.warn(msg.toString());
1161 }
1162
1163 throw new NoSuchStatsUserException(msg.toString());
1164 }
1165
1166 return mbStatsUser;
1167 }
1168
1169
1177 public MBStatsUser fetchByG_U(long groupId, long userId)
1178 throws SystemException {
1179 return fetchByG_U(groupId, userId, true);
1180 }
1181
1182
1190 public MBStatsUser fetchByG_U(long groupId, long userId,
1191 boolean retrieveFromCache) throws SystemException {
1192 Object[] finderArgs = new Object[] { groupId, userId };
1193
1194 Object result = null;
1195
1196 if (retrieveFromCache) {
1197 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1198 finderArgs, this);
1199 }
1200
1201 if (result == null) {
1202 Session session = null;
1203
1204 try {
1205 session = openSession();
1206
1207 StringBundler query = new StringBundler(4);
1208
1209 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1210
1211 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1212
1213 query.append(_FINDER_COLUMN_G_U_USERID_2);
1214
1215 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1216
1217 String sql = query.toString();
1218
1219 Query q = session.createQuery(sql);
1220
1221 QueryPos qPos = QueryPos.getInstance(q);
1222
1223 qPos.add(groupId);
1224
1225 qPos.add(userId);
1226
1227 List<MBStatsUser> list = q.list();
1228
1229 result = list;
1230
1231 MBStatsUser mbStatsUser = null;
1232
1233 if (list.isEmpty()) {
1234 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1235 finderArgs, list);
1236 }
1237 else {
1238 mbStatsUser = list.get(0);
1239
1240 cacheResult(mbStatsUser);
1241
1242 if ((mbStatsUser.getGroupId() != groupId) ||
1243 (mbStatsUser.getUserId() != userId)) {
1244 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1245 finderArgs, mbStatsUser);
1246 }
1247 }
1248
1249 return mbStatsUser;
1250 }
1251 catch (Exception e) {
1252 throw processException(e);
1253 }
1254 finally {
1255 if (result == null) {
1256 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1257 finderArgs, new ArrayList<MBStatsUser>());
1258 }
1259
1260 closeSession(session);
1261 }
1262 }
1263 else {
1264 if (result instanceof List<?>) {
1265 return null;
1266 }
1267 else {
1268 return (MBStatsUser)result;
1269 }
1270 }
1271 }
1272
1273
1281 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount)
1282 throws SystemException {
1283 return findByG_NotM(groupId, messageCount, QueryUtil.ALL_POS,
1284 QueryUtil.ALL_POS, null);
1285 }
1286
1287
1301 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1302 int start, int end) throws SystemException {
1303 return findByG_NotM(groupId, messageCount, start, end, null);
1304 }
1305
1306
1321 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1322 int start, int end, OrderByComparator orderByComparator)
1323 throws SystemException {
1324 Object[] finderArgs = new Object[] {
1325 groupId, messageCount,
1326
1327 String.valueOf(start), String.valueOf(end),
1328 String.valueOf(orderByComparator)
1329 };
1330
1331 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTM,
1332 finderArgs, this);
1333
1334 if (list == null) {
1335 Session session = null;
1336
1337 try {
1338 session = openSession();
1339
1340 StringBundler query = null;
1341
1342 if (orderByComparator != null) {
1343 query = new StringBundler(4 +
1344 (orderByComparator.getOrderByFields().length * 3));
1345 }
1346 else {
1347 query = new StringBundler(4);
1348 }
1349
1350 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1351
1352 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1353
1354 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1355
1356 if (orderByComparator != null) {
1357 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1358 orderByComparator);
1359 }
1360
1361 else {
1362 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1363 }
1364
1365 String sql = query.toString();
1366
1367 Query q = session.createQuery(sql);
1368
1369 QueryPos qPos = QueryPos.getInstance(q);
1370
1371 qPos.add(groupId);
1372
1373 qPos.add(messageCount);
1374
1375 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1376 start, end);
1377 }
1378 catch (Exception e) {
1379 throw processException(e);
1380 }
1381 finally {
1382 if (list == null) {
1383 list = new ArrayList<MBStatsUser>();
1384 }
1385
1386 cacheResult(list);
1387
1388 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTM,
1389 finderArgs, list);
1390
1391 closeSession(session);
1392 }
1393 }
1394
1395 return list;
1396 }
1397
1398
1412 public MBStatsUser findByG_NotM_First(long groupId, int messageCount,
1413 OrderByComparator orderByComparator)
1414 throws NoSuchStatsUserException, SystemException {
1415 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, 0, 1,
1416 orderByComparator);
1417
1418 if (list.isEmpty()) {
1419 StringBundler msg = new StringBundler(6);
1420
1421 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1422
1423 msg.append("groupId=");
1424 msg.append(groupId);
1425
1426 msg.append(", messageCount=");
1427 msg.append(messageCount);
1428
1429 msg.append(StringPool.CLOSE_CURLY_BRACE);
1430
1431 throw new NoSuchStatsUserException(msg.toString());
1432 }
1433 else {
1434 return list.get(0);
1435 }
1436 }
1437
1438
1452 public MBStatsUser findByG_NotM_Last(long groupId, int messageCount,
1453 OrderByComparator orderByComparator)
1454 throws NoSuchStatsUserException, SystemException {
1455 int count = countByG_NotM(groupId, messageCount);
1456
1457 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, count - 1,
1458 count, orderByComparator);
1459
1460 if (list.isEmpty()) {
1461 StringBundler msg = new StringBundler(6);
1462
1463 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1464
1465 msg.append("groupId=");
1466 msg.append(groupId);
1467
1468 msg.append(", messageCount=");
1469 msg.append(messageCount);
1470
1471 msg.append(StringPool.CLOSE_CURLY_BRACE);
1472
1473 throw new NoSuchStatsUserException(msg.toString());
1474 }
1475 else {
1476 return list.get(0);
1477 }
1478 }
1479
1480
1495 public MBStatsUser[] findByG_NotM_PrevAndNext(long statsUserId,
1496 long groupId, int messageCount, OrderByComparator orderByComparator)
1497 throws NoSuchStatsUserException, SystemException {
1498 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1499
1500 Session session = null;
1501
1502 try {
1503 session = openSession();
1504
1505 MBStatsUser[] array = new MBStatsUserImpl[3];
1506
1507 array[0] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1508 messageCount, orderByComparator, true);
1509
1510 array[1] = mbStatsUser;
1511
1512 array[2] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1513 messageCount, orderByComparator, false);
1514
1515 return array;
1516 }
1517 catch (Exception e) {
1518 throw processException(e);
1519 }
1520 finally {
1521 closeSession(session);
1522 }
1523 }
1524
1525 protected MBStatsUser getByG_NotM_PrevAndNext(Session session,
1526 MBStatsUser mbStatsUser, long groupId, int messageCount,
1527 OrderByComparator orderByComparator, boolean previous) {
1528 StringBundler query = null;
1529
1530 if (orderByComparator != null) {
1531 query = new StringBundler(6 +
1532 (orderByComparator.getOrderByFields().length * 6));
1533 }
1534 else {
1535 query = new StringBundler(3);
1536 }
1537
1538 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1539
1540 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1541
1542 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1543
1544 if (orderByComparator != null) {
1545 String[] orderByFields = orderByComparator.getOrderByFields();
1546
1547 if (orderByFields.length > 0) {
1548 query.append(WHERE_AND);
1549 }
1550
1551 for (int i = 0; i < orderByFields.length; i++) {
1552 query.append(_ORDER_BY_ENTITY_ALIAS);
1553 query.append(orderByFields[i]);
1554
1555 if ((i + 1) < orderByFields.length) {
1556 if (orderByComparator.isAscending() ^ previous) {
1557 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1558 }
1559 else {
1560 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1561 }
1562 }
1563 else {
1564 if (orderByComparator.isAscending() ^ previous) {
1565 query.append(WHERE_GREATER_THAN);
1566 }
1567 else {
1568 query.append(WHERE_LESSER_THAN);
1569 }
1570 }
1571 }
1572
1573 query.append(ORDER_BY_CLAUSE);
1574
1575 for (int i = 0; i < orderByFields.length; i++) {
1576 query.append(_ORDER_BY_ENTITY_ALIAS);
1577 query.append(orderByFields[i]);
1578
1579 if ((i + 1) < orderByFields.length) {
1580 if (orderByComparator.isAscending() ^ previous) {
1581 query.append(ORDER_BY_ASC_HAS_NEXT);
1582 }
1583 else {
1584 query.append(ORDER_BY_DESC_HAS_NEXT);
1585 }
1586 }
1587 else {
1588 if (orderByComparator.isAscending() ^ previous) {
1589 query.append(ORDER_BY_ASC);
1590 }
1591 else {
1592 query.append(ORDER_BY_DESC);
1593 }
1594 }
1595 }
1596 }
1597
1598 else {
1599 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1600 }
1601
1602 String sql = query.toString();
1603
1604 Query q = session.createQuery(sql);
1605
1606 q.setFirstResult(0);
1607 q.setMaxResults(2);
1608
1609 QueryPos qPos = QueryPos.getInstance(q);
1610
1611 qPos.add(groupId);
1612
1613 qPos.add(messageCount);
1614
1615 if (orderByComparator != null) {
1616 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1617
1618 for (Object value : values) {
1619 qPos.add(value);
1620 }
1621 }
1622
1623 List<MBStatsUser> list = q.list();
1624
1625 if (list.size() == 2) {
1626 return list.get(1);
1627 }
1628 else {
1629 return null;
1630 }
1631 }
1632
1633
1639 public List<MBStatsUser> findAll() throws SystemException {
1640 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1641 }
1642
1643
1655 public List<MBStatsUser> findAll(int start, int end)
1656 throws SystemException {
1657 return findAll(start, end, null);
1658 }
1659
1660
1673 public List<MBStatsUser> findAll(int start, int end,
1674 OrderByComparator orderByComparator) throws SystemException {
1675 Object[] finderArgs = new Object[] {
1676 String.valueOf(start), String.valueOf(end),
1677 String.valueOf(orderByComparator)
1678 };
1679
1680 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1681 finderArgs, this);
1682
1683 if (list == null) {
1684 Session session = null;
1685
1686 try {
1687 session = openSession();
1688
1689 StringBundler query = null;
1690 String sql = null;
1691
1692 if (orderByComparator != null) {
1693 query = new StringBundler(2 +
1694 (orderByComparator.getOrderByFields().length * 3));
1695
1696 query.append(_SQL_SELECT_MBSTATSUSER);
1697
1698 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1699 orderByComparator);
1700
1701 sql = query.toString();
1702 }
1703 else {
1704 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1705 }
1706
1707 Query q = session.createQuery(sql);
1708
1709 if (orderByComparator == null) {
1710 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1711 start, end, false);
1712
1713 Collections.sort(list);
1714 }
1715 else {
1716 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1717 start, end);
1718 }
1719 }
1720 catch (Exception e) {
1721 throw processException(e);
1722 }
1723 finally {
1724 if (list == null) {
1725 list = new ArrayList<MBStatsUser>();
1726 }
1727
1728 cacheResult(list);
1729
1730 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1731
1732 closeSession(session);
1733 }
1734 }
1735
1736 return list;
1737 }
1738
1739
1745 public void removeByGroupId(long groupId) throws SystemException {
1746 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1747 remove(mbStatsUser);
1748 }
1749 }
1750
1751
1757 public void removeByUserId(long userId) throws SystemException {
1758 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1759 remove(mbStatsUser);
1760 }
1761 }
1762
1763
1770 public void removeByG_U(long groupId, long userId)
1771 throws NoSuchStatsUserException, SystemException {
1772 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1773
1774 remove(mbStatsUser);
1775 }
1776
1777
1784 public void removeByG_NotM(long groupId, int messageCount)
1785 throws SystemException {
1786 for (MBStatsUser mbStatsUser : findByG_NotM(groupId, messageCount)) {
1787 remove(mbStatsUser);
1788 }
1789 }
1790
1791
1796 public void removeAll() throws SystemException {
1797 for (MBStatsUser mbStatsUser : findAll()) {
1798 remove(mbStatsUser);
1799 }
1800 }
1801
1802
1809 public int countByGroupId(long groupId) throws SystemException {
1810 Object[] finderArgs = new Object[] { groupId };
1811
1812 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1813 finderArgs, this);
1814
1815 if (count == null) {
1816 Session session = null;
1817
1818 try {
1819 session = openSession();
1820
1821 StringBundler query = new StringBundler(2);
1822
1823 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1824
1825 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1826
1827 String sql = query.toString();
1828
1829 Query q = session.createQuery(sql);
1830
1831 QueryPos qPos = QueryPos.getInstance(q);
1832
1833 qPos.add(groupId);
1834
1835 count = (Long)q.uniqueResult();
1836 }
1837 catch (Exception e) {
1838 throw processException(e);
1839 }
1840 finally {
1841 if (count == null) {
1842 count = Long.valueOf(0);
1843 }
1844
1845 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1846 finderArgs, count);
1847
1848 closeSession(session);
1849 }
1850 }
1851
1852 return count.intValue();
1853 }
1854
1855
1862 public int countByUserId(long userId) throws SystemException {
1863 Object[] finderArgs = new Object[] { userId };
1864
1865 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1866 finderArgs, this);
1867
1868 if (count == null) {
1869 Session session = null;
1870
1871 try {
1872 session = openSession();
1873
1874 StringBundler query = new StringBundler(2);
1875
1876 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1877
1878 query.append(_FINDER_COLUMN_USERID_USERID_2);
1879
1880 String sql = query.toString();
1881
1882 Query q = session.createQuery(sql);
1883
1884 QueryPos qPos = QueryPos.getInstance(q);
1885
1886 qPos.add(userId);
1887
1888 count = (Long)q.uniqueResult();
1889 }
1890 catch (Exception e) {
1891 throw processException(e);
1892 }
1893 finally {
1894 if (count == null) {
1895 count = Long.valueOf(0);
1896 }
1897
1898 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1899 finderArgs, count);
1900
1901 closeSession(session);
1902 }
1903 }
1904
1905 return count.intValue();
1906 }
1907
1908
1916 public int countByG_U(long groupId, long userId) throws SystemException {
1917 Object[] finderArgs = new Object[] { groupId, userId };
1918
1919 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1920 finderArgs, this);
1921
1922 if (count == null) {
1923 Session session = null;
1924
1925 try {
1926 session = openSession();
1927
1928 StringBundler query = new StringBundler(3);
1929
1930 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1931
1932 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1933
1934 query.append(_FINDER_COLUMN_G_U_USERID_2);
1935
1936 String sql = query.toString();
1937
1938 Query q = session.createQuery(sql);
1939
1940 QueryPos qPos = QueryPos.getInstance(q);
1941
1942 qPos.add(groupId);
1943
1944 qPos.add(userId);
1945
1946 count = (Long)q.uniqueResult();
1947 }
1948 catch (Exception e) {
1949 throw processException(e);
1950 }
1951 finally {
1952 if (count == null) {
1953 count = Long.valueOf(0);
1954 }
1955
1956 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1957 count);
1958
1959 closeSession(session);
1960 }
1961 }
1962
1963 return count.intValue();
1964 }
1965
1966
1974 public int countByG_NotM(long groupId, int messageCount)
1975 throws SystemException {
1976 Object[] finderArgs = new Object[] { groupId, messageCount };
1977
1978 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTM,
1979 finderArgs, this);
1980
1981 if (count == null) {
1982 Session session = null;
1983
1984 try {
1985 session = openSession();
1986
1987 StringBundler query = new StringBundler(3);
1988
1989 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1990
1991 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1992
1993 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1994
1995 String sql = query.toString();
1996
1997 Query q = session.createQuery(sql);
1998
1999 QueryPos qPos = QueryPos.getInstance(q);
2000
2001 qPos.add(groupId);
2002
2003 qPos.add(messageCount);
2004
2005 count = (Long)q.uniqueResult();
2006 }
2007 catch (Exception e) {
2008 throw processException(e);
2009 }
2010 finally {
2011 if (count == null) {
2012 count = Long.valueOf(0);
2013 }
2014
2015 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTM,
2016 finderArgs, count);
2017
2018 closeSession(session);
2019 }
2020 }
2021
2022 return count.intValue();
2023 }
2024
2025
2031 public int countAll() throws SystemException {
2032 Object[] finderArgs = new Object[0];
2033
2034 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2035 finderArgs, this);
2036
2037 if (count == null) {
2038 Session session = null;
2039
2040 try {
2041 session = openSession();
2042
2043 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2044
2045 count = (Long)q.uniqueResult();
2046 }
2047 catch (Exception e) {
2048 throw processException(e);
2049 }
2050 finally {
2051 if (count == null) {
2052 count = Long.valueOf(0);
2053 }
2054
2055 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2056 count);
2057
2058 closeSession(session);
2059 }
2060 }
2061
2062 return count.intValue();
2063 }
2064
2065
2068 public void afterPropertiesSet() {
2069 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2070 com.liferay.portal.util.PropsUtil.get(
2071 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2072
2073 if (listenerClassNames.length > 0) {
2074 try {
2075 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2076
2077 for (String listenerClassName : listenerClassNames) {
2078 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2079 listenerClassName));
2080 }
2081
2082 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2083 }
2084 catch (Exception e) {
2085 _log.error(e);
2086 }
2087 }
2088 }
2089
2090 @BeanReference(type = MBBanPersistence.class)
2091 protected MBBanPersistence mbBanPersistence;
2092 @BeanReference(type = MBCategoryPersistence.class)
2093 protected MBCategoryPersistence mbCategoryPersistence;
2094 @BeanReference(type = MBDiscussionPersistence.class)
2095 protected MBDiscussionPersistence mbDiscussionPersistence;
2096 @BeanReference(type = MBMailingListPersistence.class)
2097 protected MBMailingListPersistence mbMailingListPersistence;
2098 @BeanReference(type = MBMessagePersistence.class)
2099 protected MBMessagePersistence mbMessagePersistence;
2100 @BeanReference(type = MBMessageFlagPersistence.class)
2101 protected MBMessageFlagPersistence mbMessageFlagPersistence;
2102 @BeanReference(type = MBStatsUserPersistence.class)
2103 protected MBStatsUserPersistence mbStatsUserPersistence;
2104 @BeanReference(type = MBThreadPersistence.class)
2105 protected MBThreadPersistence mbThreadPersistence;
2106 @BeanReference(type = ResourcePersistence.class)
2107 protected ResourcePersistence resourcePersistence;
2108 @BeanReference(type = UserPersistence.class)
2109 protected UserPersistence userPersistence;
2110 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2111 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2112 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2113 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2114 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2115 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2116 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2117 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2118 private static final String _FINDER_COLUMN_G_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2119 private static final String _FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2120 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2121 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2122 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2123 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2124 }