001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038
039 import com.liferay.portlet.messageboards.NoSuchStatsUserException;
040 import com.liferay.portlet.messageboards.model.MBStatsUser;
041 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
042 import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class MBStatsUserPersistenceImpl extends BasePersistenceImpl<MBStatsUser>
063 implements MBStatsUserPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = MBStatsUserImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
075 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
078 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
081 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
084 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
086 new String[] {
087 Long.class.getName(),
088
089 Integer.class.getName(), Integer.class.getName(),
090 OrderByComparator.class.getName()
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
093 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
094 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
096 new String[] { Long.class.getName() },
097 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
098 MBStatsUserModelImpl.MESSAGECOUNT_COLUMN_BITMASK);
099 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
100 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
102 new String[] { Long.class.getName() });
103
104
111 public List<MBStatsUser> findByGroupId(long groupId)
112 throws SystemException {
113 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
114 }
115
116
129 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
130 throws SystemException {
131 return findByGroupId(groupId, start, end, null);
132 }
133
134
148 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
149 OrderByComparator orderByComparator) throws SystemException {
150 boolean pagination = true;
151 FinderPath finderPath = null;
152 Object[] finderArgs = null;
153
154 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
155 (orderByComparator == null)) {
156 pagination = false;
157 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
158 finderArgs = new Object[] { groupId };
159 }
160 else {
161 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
162 finderArgs = new Object[] { groupId, start, end, orderByComparator };
163 }
164
165 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
166 finderArgs, this);
167
168 if ((list != null) && !list.isEmpty()) {
169 for (MBStatsUser mbStatsUser : list) {
170 if ((groupId != mbStatsUser.getGroupId())) {
171 list = null;
172
173 break;
174 }
175 }
176 }
177
178 if (list == null) {
179 StringBundler query = null;
180
181 if (orderByComparator != null) {
182 query = new StringBundler(3 +
183 (orderByComparator.getOrderByFields().length * 3));
184 }
185 else {
186 query = new StringBundler(3);
187 }
188
189 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
190
191 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
192
193 if (orderByComparator != null) {
194 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
195 orderByComparator);
196 }
197 else
198 if (pagination) {
199 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
200 }
201
202 String sql = query.toString();
203
204 Session session = null;
205
206 try {
207 session = openSession();
208
209 Query q = session.createQuery(sql);
210
211 QueryPos qPos = QueryPos.getInstance(q);
212
213 qPos.add(groupId);
214
215 if (!pagination) {
216 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
217 start, end, false);
218
219 Collections.sort(list);
220
221 list = new UnmodifiableList<MBStatsUser>(list);
222 }
223 else {
224 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
225 start, end);
226 }
227
228 cacheResult(list);
229
230 FinderCacheUtil.putResult(finderPath, finderArgs, list);
231 }
232 catch (Exception e) {
233 FinderCacheUtil.removeResult(finderPath, finderArgs);
234
235 throw processException(e);
236 }
237 finally {
238 closeSession(session);
239 }
240 }
241
242 return list;
243 }
244
245
254 public MBStatsUser findByGroupId_First(long groupId,
255 OrderByComparator orderByComparator)
256 throws NoSuchStatsUserException, SystemException {
257 MBStatsUser mbStatsUser = fetchByGroupId_First(groupId,
258 orderByComparator);
259
260 if (mbStatsUser != null) {
261 return mbStatsUser;
262 }
263
264 StringBundler msg = new StringBundler(4);
265
266 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
267
268 msg.append("groupId=");
269 msg.append(groupId);
270
271 msg.append(StringPool.CLOSE_CURLY_BRACE);
272
273 throw new NoSuchStatsUserException(msg.toString());
274 }
275
276
284 public MBStatsUser fetchByGroupId_First(long groupId,
285 OrderByComparator orderByComparator) throws SystemException {
286 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
287
288 if (!list.isEmpty()) {
289 return list.get(0);
290 }
291
292 return null;
293 }
294
295
304 public MBStatsUser findByGroupId_Last(long groupId,
305 OrderByComparator orderByComparator)
306 throws NoSuchStatsUserException, SystemException {
307 MBStatsUser mbStatsUser = fetchByGroupId_Last(groupId, orderByComparator);
308
309 if (mbStatsUser != null) {
310 return mbStatsUser;
311 }
312
313 StringBundler msg = new StringBundler(4);
314
315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
316
317 msg.append("groupId=");
318 msg.append(groupId);
319
320 msg.append(StringPool.CLOSE_CURLY_BRACE);
321
322 throw new NoSuchStatsUserException(msg.toString());
323 }
324
325
333 public MBStatsUser fetchByGroupId_Last(long groupId,
334 OrderByComparator orderByComparator) throws SystemException {
335 int count = countByGroupId(groupId);
336
337 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
338 orderByComparator);
339
340 if (!list.isEmpty()) {
341 return list.get(0);
342 }
343
344 return null;
345 }
346
347
357 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
358 long groupId, OrderByComparator orderByComparator)
359 throws NoSuchStatsUserException, SystemException {
360 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
361
362 Session session = null;
363
364 try {
365 session = openSession();
366
367 MBStatsUser[] array = new MBStatsUserImpl[3];
368
369 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
370 orderByComparator, true);
371
372 array[1] = mbStatsUser;
373
374 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
375 orderByComparator, false);
376
377 return array;
378 }
379 catch (Exception e) {
380 throw processException(e);
381 }
382 finally {
383 closeSession(session);
384 }
385 }
386
387 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
388 MBStatsUser mbStatsUser, long groupId,
389 OrderByComparator orderByComparator, boolean previous) {
390 StringBundler query = null;
391
392 if (orderByComparator != null) {
393 query = new StringBundler(6 +
394 (orderByComparator.getOrderByFields().length * 6));
395 }
396 else {
397 query = new StringBundler(3);
398 }
399
400 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
401
402 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
403
404 if (orderByComparator != null) {
405 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
406
407 if (orderByConditionFields.length > 0) {
408 query.append(WHERE_AND);
409 }
410
411 for (int i = 0; i < orderByConditionFields.length; i++) {
412 query.append(_ORDER_BY_ENTITY_ALIAS);
413 query.append(orderByConditionFields[i]);
414
415 if ((i + 1) < orderByConditionFields.length) {
416 if (orderByComparator.isAscending() ^ previous) {
417 query.append(WHERE_GREATER_THAN_HAS_NEXT);
418 }
419 else {
420 query.append(WHERE_LESSER_THAN_HAS_NEXT);
421 }
422 }
423 else {
424 if (orderByComparator.isAscending() ^ previous) {
425 query.append(WHERE_GREATER_THAN);
426 }
427 else {
428 query.append(WHERE_LESSER_THAN);
429 }
430 }
431 }
432
433 query.append(ORDER_BY_CLAUSE);
434
435 String[] orderByFields = orderByComparator.getOrderByFields();
436
437 for (int i = 0; i < orderByFields.length; i++) {
438 query.append(_ORDER_BY_ENTITY_ALIAS);
439 query.append(orderByFields[i]);
440
441 if ((i + 1) < orderByFields.length) {
442 if (orderByComparator.isAscending() ^ previous) {
443 query.append(ORDER_BY_ASC_HAS_NEXT);
444 }
445 else {
446 query.append(ORDER_BY_DESC_HAS_NEXT);
447 }
448 }
449 else {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(ORDER_BY_ASC);
452 }
453 else {
454 query.append(ORDER_BY_DESC);
455 }
456 }
457 }
458 }
459 else {
460 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
461 }
462
463 String sql = query.toString();
464
465 Query q = session.createQuery(sql);
466
467 q.setFirstResult(0);
468 q.setMaxResults(2);
469
470 QueryPos qPos = QueryPos.getInstance(q);
471
472 qPos.add(groupId);
473
474 if (orderByComparator != null) {
475 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
476
477 for (Object value : values) {
478 qPos.add(value);
479 }
480 }
481
482 List<MBStatsUser> list = q.list();
483
484 if (list.size() == 2) {
485 return list.get(1);
486 }
487 else {
488 return null;
489 }
490 }
491
492
498 public void removeByGroupId(long groupId) throws SystemException {
499 for (MBStatsUser mbStatsUser : findByGroupId(groupId,
500 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
501 remove(mbStatsUser);
502 }
503 }
504
505
512 public int countByGroupId(long groupId) throws SystemException {
513 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
514
515 Object[] finderArgs = new Object[] { groupId };
516
517 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
518 this);
519
520 if (count == null) {
521 StringBundler query = new StringBundler(2);
522
523 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
524
525 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
526
527 String sql = query.toString();
528
529 Session session = null;
530
531 try {
532 session = openSession();
533
534 Query q = session.createQuery(sql);
535
536 QueryPos qPos = QueryPos.getInstance(q);
537
538 qPos.add(groupId);
539
540 count = (Long)q.uniqueResult();
541
542 FinderCacheUtil.putResult(finderPath, finderArgs, count);
543 }
544 catch (Exception e) {
545 FinderCacheUtil.removeResult(finderPath, finderArgs);
546
547 throw processException(e);
548 }
549 finally {
550 closeSession(session);
551 }
552 }
553
554 return count.intValue();
555 }
556
557 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
558 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
559 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
560 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
561 new String[] {
562 Long.class.getName(),
563
564 Integer.class.getName(), Integer.class.getName(),
565 OrderByComparator.class.getName()
566 });
567 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
568 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
569 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
570 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
571 new String[] { Long.class.getName() },
572 MBStatsUserModelImpl.USERID_COLUMN_BITMASK |
573 MBStatsUserModelImpl.MESSAGECOUNT_COLUMN_BITMASK);
574 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
575 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
576 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
577 new String[] { Long.class.getName() });
578
579
586 public List<MBStatsUser> findByUserId(long userId)
587 throws SystemException {
588 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
589 }
590
591
604 public List<MBStatsUser> findByUserId(long userId, int start, int end)
605 throws SystemException {
606 return findByUserId(userId, start, end, null);
607 }
608
609
623 public List<MBStatsUser> findByUserId(long userId, int start, int end,
624 OrderByComparator orderByComparator) throws SystemException {
625 boolean pagination = true;
626 FinderPath finderPath = null;
627 Object[] finderArgs = null;
628
629 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
630 (orderByComparator == null)) {
631 pagination = false;
632 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
633 finderArgs = new Object[] { userId };
634 }
635 else {
636 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
637 finderArgs = new Object[] { userId, start, end, orderByComparator };
638 }
639
640 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
641 finderArgs, this);
642
643 if ((list != null) && !list.isEmpty()) {
644 for (MBStatsUser mbStatsUser : list) {
645 if ((userId != mbStatsUser.getUserId())) {
646 list = null;
647
648 break;
649 }
650 }
651 }
652
653 if (list == null) {
654 StringBundler query = null;
655
656 if (orderByComparator != null) {
657 query = new StringBundler(3 +
658 (orderByComparator.getOrderByFields().length * 3));
659 }
660 else {
661 query = new StringBundler(3);
662 }
663
664 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
665
666 query.append(_FINDER_COLUMN_USERID_USERID_2);
667
668 if (orderByComparator != null) {
669 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
670 orderByComparator);
671 }
672 else
673 if (pagination) {
674 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
675 }
676
677 String sql = query.toString();
678
679 Session session = null;
680
681 try {
682 session = openSession();
683
684 Query q = session.createQuery(sql);
685
686 QueryPos qPos = QueryPos.getInstance(q);
687
688 qPos.add(userId);
689
690 if (!pagination) {
691 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
692 start, end, false);
693
694 Collections.sort(list);
695
696 list = new UnmodifiableList<MBStatsUser>(list);
697 }
698 else {
699 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
700 start, end);
701 }
702
703 cacheResult(list);
704
705 FinderCacheUtil.putResult(finderPath, finderArgs, list);
706 }
707 catch (Exception e) {
708 FinderCacheUtil.removeResult(finderPath, finderArgs);
709
710 throw processException(e);
711 }
712 finally {
713 closeSession(session);
714 }
715 }
716
717 return list;
718 }
719
720
729 public MBStatsUser findByUserId_First(long userId,
730 OrderByComparator orderByComparator)
731 throws NoSuchStatsUserException, SystemException {
732 MBStatsUser mbStatsUser = fetchByUserId_First(userId, orderByComparator);
733
734 if (mbStatsUser != null) {
735 return mbStatsUser;
736 }
737
738 StringBundler msg = new StringBundler(4);
739
740 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
741
742 msg.append("userId=");
743 msg.append(userId);
744
745 msg.append(StringPool.CLOSE_CURLY_BRACE);
746
747 throw new NoSuchStatsUserException(msg.toString());
748 }
749
750
758 public MBStatsUser fetchByUserId_First(long userId,
759 OrderByComparator orderByComparator) throws SystemException {
760 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
761
762 if (!list.isEmpty()) {
763 return list.get(0);
764 }
765
766 return null;
767 }
768
769
778 public MBStatsUser findByUserId_Last(long userId,
779 OrderByComparator orderByComparator)
780 throws NoSuchStatsUserException, SystemException {
781 MBStatsUser mbStatsUser = fetchByUserId_Last(userId, orderByComparator);
782
783 if (mbStatsUser != null) {
784 return mbStatsUser;
785 }
786
787 StringBundler msg = new StringBundler(4);
788
789 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
790
791 msg.append("userId=");
792 msg.append(userId);
793
794 msg.append(StringPool.CLOSE_CURLY_BRACE);
795
796 throw new NoSuchStatsUserException(msg.toString());
797 }
798
799
807 public MBStatsUser fetchByUserId_Last(long userId,
808 OrderByComparator orderByComparator) throws SystemException {
809 int count = countByUserId(userId);
810
811 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
812 orderByComparator);
813
814 if (!list.isEmpty()) {
815 return list.get(0);
816 }
817
818 return null;
819 }
820
821
831 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
832 long userId, OrderByComparator orderByComparator)
833 throws NoSuchStatsUserException, SystemException {
834 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
835
836 Session session = null;
837
838 try {
839 session = openSession();
840
841 MBStatsUser[] array = new MBStatsUserImpl[3];
842
843 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
844 orderByComparator, true);
845
846 array[1] = mbStatsUser;
847
848 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
849 orderByComparator, false);
850
851 return array;
852 }
853 catch (Exception e) {
854 throw processException(e);
855 }
856 finally {
857 closeSession(session);
858 }
859 }
860
861 protected MBStatsUser getByUserId_PrevAndNext(Session session,
862 MBStatsUser mbStatsUser, long userId,
863 OrderByComparator orderByComparator, boolean previous) {
864 StringBundler query = null;
865
866 if (orderByComparator != null) {
867 query = new StringBundler(6 +
868 (orderByComparator.getOrderByFields().length * 6));
869 }
870 else {
871 query = new StringBundler(3);
872 }
873
874 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
875
876 query.append(_FINDER_COLUMN_USERID_USERID_2);
877
878 if (orderByComparator != null) {
879 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
880
881 if (orderByConditionFields.length > 0) {
882 query.append(WHERE_AND);
883 }
884
885 for (int i = 0; i < orderByConditionFields.length; i++) {
886 query.append(_ORDER_BY_ENTITY_ALIAS);
887 query.append(orderByConditionFields[i]);
888
889 if ((i + 1) < orderByConditionFields.length) {
890 if (orderByComparator.isAscending() ^ previous) {
891 query.append(WHERE_GREATER_THAN_HAS_NEXT);
892 }
893 else {
894 query.append(WHERE_LESSER_THAN_HAS_NEXT);
895 }
896 }
897 else {
898 if (orderByComparator.isAscending() ^ previous) {
899 query.append(WHERE_GREATER_THAN);
900 }
901 else {
902 query.append(WHERE_LESSER_THAN);
903 }
904 }
905 }
906
907 query.append(ORDER_BY_CLAUSE);
908
909 String[] orderByFields = orderByComparator.getOrderByFields();
910
911 for (int i = 0; i < orderByFields.length; i++) {
912 query.append(_ORDER_BY_ENTITY_ALIAS);
913 query.append(orderByFields[i]);
914
915 if ((i + 1) < orderByFields.length) {
916 if (orderByComparator.isAscending() ^ previous) {
917 query.append(ORDER_BY_ASC_HAS_NEXT);
918 }
919 else {
920 query.append(ORDER_BY_DESC_HAS_NEXT);
921 }
922 }
923 else {
924 if (orderByComparator.isAscending() ^ previous) {
925 query.append(ORDER_BY_ASC);
926 }
927 else {
928 query.append(ORDER_BY_DESC);
929 }
930 }
931 }
932 }
933 else {
934 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
935 }
936
937 String sql = query.toString();
938
939 Query q = session.createQuery(sql);
940
941 q.setFirstResult(0);
942 q.setMaxResults(2);
943
944 QueryPos qPos = QueryPos.getInstance(q);
945
946 qPos.add(userId);
947
948 if (orderByComparator != null) {
949 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
950
951 for (Object value : values) {
952 qPos.add(value);
953 }
954 }
955
956 List<MBStatsUser> list = q.list();
957
958 if (list.size() == 2) {
959 return list.get(1);
960 }
961 else {
962 return null;
963 }
964 }
965
966
972 public void removeByUserId(long userId) throws SystemException {
973 for (MBStatsUser mbStatsUser : findByUserId(userId, QueryUtil.ALL_POS,
974 QueryUtil.ALL_POS, null)) {
975 remove(mbStatsUser);
976 }
977 }
978
979
986 public int countByUserId(long userId) throws SystemException {
987 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
988
989 Object[] finderArgs = new Object[] { userId };
990
991 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
992 this);
993
994 if (count == null) {
995 StringBundler query = new StringBundler(2);
996
997 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
998
999 query.append(_FINDER_COLUMN_USERID_USERID_2);
1000
1001 String sql = query.toString();
1002
1003 Session session = null;
1004
1005 try {
1006 session = openSession();
1007
1008 Query q = session.createQuery(sql);
1009
1010 QueryPos qPos = QueryPos.getInstance(q);
1011
1012 qPos.add(userId);
1013
1014 count = (Long)q.uniqueResult();
1015
1016 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1017 }
1018 catch (Exception e) {
1019 FinderCacheUtil.removeResult(finderPath, finderArgs);
1020
1021 throw processException(e);
1022 }
1023 finally {
1024 closeSession(session);
1025 }
1026 }
1027
1028 return count.intValue();
1029 }
1030
1031 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
1032 public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1033 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
1034 FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
1035 new String[] { Long.class.getName(), Long.class.getName() },
1036 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
1037 MBStatsUserModelImpl.USERID_COLUMN_BITMASK);
1038 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1039 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1040 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
1041 new String[] { Long.class.getName(), Long.class.getName() });
1042
1043
1052 public MBStatsUser findByG_U(long groupId, long userId)
1053 throws NoSuchStatsUserException, SystemException {
1054 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1055
1056 if (mbStatsUser == null) {
1057 StringBundler msg = new StringBundler(6);
1058
1059 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1060
1061 msg.append("groupId=");
1062 msg.append(groupId);
1063
1064 msg.append(", userId=");
1065 msg.append(userId);
1066
1067 msg.append(StringPool.CLOSE_CURLY_BRACE);
1068
1069 if (_log.isWarnEnabled()) {
1070 _log.warn(msg.toString());
1071 }
1072
1073 throw new NoSuchStatsUserException(msg.toString());
1074 }
1075
1076 return mbStatsUser;
1077 }
1078
1079
1087 public MBStatsUser fetchByG_U(long groupId, long userId)
1088 throws SystemException {
1089 return fetchByG_U(groupId, userId, true);
1090 }
1091
1092
1101 public MBStatsUser fetchByG_U(long groupId, long userId,
1102 boolean retrieveFromCache) throws SystemException {
1103 Object[] finderArgs = new Object[] { groupId, userId };
1104
1105 Object result = null;
1106
1107 if (retrieveFromCache) {
1108 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1109 finderArgs, this);
1110 }
1111
1112 if (result instanceof MBStatsUser) {
1113 MBStatsUser mbStatsUser = (MBStatsUser)result;
1114
1115 if ((groupId != mbStatsUser.getGroupId()) ||
1116 (userId != mbStatsUser.getUserId())) {
1117 result = null;
1118 }
1119 }
1120
1121 if (result == null) {
1122 StringBundler query = new StringBundler(4);
1123
1124 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1125
1126 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1127
1128 query.append(_FINDER_COLUMN_G_U_USERID_2);
1129
1130 String sql = query.toString();
1131
1132 Session session = null;
1133
1134 try {
1135 session = openSession();
1136
1137 Query q = session.createQuery(sql);
1138
1139 QueryPos qPos = QueryPos.getInstance(q);
1140
1141 qPos.add(groupId);
1142
1143 qPos.add(userId);
1144
1145 List<MBStatsUser> list = q.list();
1146
1147 if (list.isEmpty()) {
1148 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1149 finderArgs, list);
1150 }
1151 else {
1152 MBStatsUser mbStatsUser = list.get(0);
1153
1154 result = mbStatsUser;
1155
1156 cacheResult(mbStatsUser);
1157
1158 if ((mbStatsUser.getGroupId() != groupId) ||
1159 (mbStatsUser.getUserId() != userId)) {
1160 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1161 finderArgs, mbStatsUser);
1162 }
1163 }
1164 }
1165 catch (Exception e) {
1166 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1167 finderArgs);
1168
1169 throw processException(e);
1170 }
1171 finally {
1172 closeSession(session);
1173 }
1174 }
1175
1176 if (result instanceof List<?>) {
1177 return null;
1178 }
1179 else {
1180 return (MBStatsUser)result;
1181 }
1182 }
1183
1184
1192 public MBStatsUser removeByG_U(long groupId, long userId)
1193 throws NoSuchStatsUserException, SystemException {
1194 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1195
1196 return remove(mbStatsUser);
1197 }
1198
1199
1207 public int countByG_U(long groupId, long userId) throws SystemException {
1208 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
1209
1210 Object[] finderArgs = new Object[] { groupId, userId };
1211
1212 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1213 this);
1214
1215 if (count == null) {
1216 StringBundler query = new StringBundler(3);
1217
1218 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1219
1220 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1221
1222 query.append(_FINDER_COLUMN_G_U_USERID_2);
1223
1224 String sql = query.toString();
1225
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 Query q = session.createQuery(sql);
1232
1233 QueryPos qPos = QueryPos.getInstance(q);
1234
1235 qPos.add(groupId);
1236
1237 qPos.add(userId);
1238
1239 count = (Long)q.uniqueResult();
1240
1241 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1242 }
1243 catch (Exception e) {
1244 FinderCacheUtil.removeResult(finderPath, finderArgs);
1245
1246 throw processException(e);
1247 }
1248 finally {
1249 closeSession(session);
1250 }
1251 }
1252
1253 return count.intValue();
1254 }
1255
1256 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
1257 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
1258 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM =
1259 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1260 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
1261 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotU_NotM",
1262 new String[] {
1263 Long.class.getName(), Long.class.getName(),
1264 Integer.class.getName(),
1265
1266 Integer.class.getName(), Integer.class.getName(),
1267 OrderByComparator.class.getName()
1268 });
1269 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM =
1270 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1271 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
1272 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotU_NotM",
1273 new String[] {
1274 Long.class.getName(), Long.class.getName(),
1275 Integer.class.getName()
1276 });
1277
1278
1287 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1288 int messageCount) throws SystemException {
1289 return findByG_NotU_NotM(groupId, userId, messageCount,
1290 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1291 }
1292
1293
1308 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1309 int messageCount, int start, int end) throws SystemException {
1310 return findByG_NotU_NotM(groupId, userId, messageCount, start, end, null);
1311 }
1312
1313
1329 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1330 int messageCount, int start, int end,
1331 OrderByComparator orderByComparator) throws SystemException {
1332 boolean pagination = true;
1333 FinderPath finderPath = null;
1334 Object[] finderArgs = null;
1335
1336 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM;
1337 finderArgs = new Object[] {
1338 groupId, userId, messageCount,
1339
1340 start, end, orderByComparator
1341 };
1342
1343 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1344 finderArgs, this);
1345
1346 if ((list != null) && !list.isEmpty()) {
1347 for (MBStatsUser mbStatsUser : list) {
1348 if ((groupId != mbStatsUser.getGroupId()) ||
1349 (userId != mbStatsUser.getUserId()) ||
1350 (messageCount != mbStatsUser.getMessageCount())) {
1351 list = null;
1352
1353 break;
1354 }
1355 }
1356 }
1357
1358 if (list == null) {
1359 StringBundler query = null;
1360
1361 if (orderByComparator != null) {
1362 query = new StringBundler(5 +
1363 (orderByComparator.getOrderByFields().length * 3));
1364 }
1365 else {
1366 query = new StringBundler(5);
1367 }
1368
1369 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1370
1371 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1372
1373 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1374
1375 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1376
1377 if (orderByComparator != null) {
1378 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1379 orderByComparator);
1380 }
1381 else
1382 if (pagination) {
1383 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1384 }
1385
1386 String sql = query.toString();
1387
1388 Session session = null;
1389
1390 try {
1391 session = openSession();
1392
1393 Query q = session.createQuery(sql);
1394
1395 QueryPos qPos = QueryPos.getInstance(q);
1396
1397 qPos.add(groupId);
1398
1399 qPos.add(userId);
1400
1401 qPos.add(messageCount);
1402
1403 if (!pagination) {
1404 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1405 start, end, false);
1406
1407 Collections.sort(list);
1408
1409 list = new UnmodifiableList<MBStatsUser>(list);
1410 }
1411 else {
1412 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1413 start, end);
1414 }
1415
1416 cacheResult(list);
1417
1418 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1419 }
1420 catch (Exception e) {
1421 FinderCacheUtil.removeResult(finderPath, finderArgs);
1422
1423 throw processException(e);
1424 }
1425 finally {
1426 closeSession(session);
1427 }
1428 }
1429
1430 return list;
1431 }
1432
1433
1444 public MBStatsUser findByG_NotU_NotM_First(long groupId, long userId,
1445 int messageCount, OrderByComparator orderByComparator)
1446 throws NoSuchStatsUserException, SystemException {
1447 MBStatsUser mbStatsUser = fetchByG_NotU_NotM_First(groupId, userId,
1448 messageCount, orderByComparator);
1449
1450 if (mbStatsUser != null) {
1451 return mbStatsUser;
1452 }
1453
1454 StringBundler msg = new StringBundler(8);
1455
1456 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1457
1458 msg.append("groupId=");
1459 msg.append(groupId);
1460
1461 msg.append(", userId=");
1462 msg.append(userId);
1463
1464 msg.append(", messageCount=");
1465 msg.append(messageCount);
1466
1467 msg.append(StringPool.CLOSE_CURLY_BRACE);
1468
1469 throw new NoSuchStatsUserException(msg.toString());
1470 }
1471
1472
1482 public MBStatsUser fetchByG_NotU_NotM_First(long groupId, long userId,
1483 int messageCount, OrderByComparator orderByComparator)
1484 throws SystemException {
1485 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1486 messageCount, 0, 1, orderByComparator);
1487
1488 if (!list.isEmpty()) {
1489 return list.get(0);
1490 }
1491
1492 return null;
1493 }
1494
1495
1506 public MBStatsUser findByG_NotU_NotM_Last(long groupId, long userId,
1507 int messageCount, OrderByComparator orderByComparator)
1508 throws NoSuchStatsUserException, SystemException {
1509 MBStatsUser mbStatsUser = fetchByG_NotU_NotM_Last(groupId, userId,
1510 messageCount, orderByComparator);
1511
1512 if (mbStatsUser != null) {
1513 return mbStatsUser;
1514 }
1515
1516 StringBundler msg = new StringBundler(8);
1517
1518 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1519
1520 msg.append("groupId=");
1521 msg.append(groupId);
1522
1523 msg.append(", userId=");
1524 msg.append(userId);
1525
1526 msg.append(", messageCount=");
1527 msg.append(messageCount);
1528
1529 msg.append(StringPool.CLOSE_CURLY_BRACE);
1530
1531 throw new NoSuchStatsUserException(msg.toString());
1532 }
1533
1534
1544 public MBStatsUser fetchByG_NotU_NotM_Last(long groupId, long userId,
1545 int messageCount, OrderByComparator orderByComparator)
1546 throws SystemException {
1547 int count = countByG_NotU_NotM(groupId, userId, messageCount);
1548
1549 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1550 messageCount, count - 1, count, orderByComparator);
1551
1552 if (!list.isEmpty()) {
1553 return list.get(0);
1554 }
1555
1556 return null;
1557 }
1558
1559
1571 public MBStatsUser[] findByG_NotU_NotM_PrevAndNext(long statsUserId,
1572 long groupId, long userId, int messageCount,
1573 OrderByComparator orderByComparator)
1574 throws NoSuchStatsUserException, SystemException {
1575 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1576
1577 Session session = null;
1578
1579 try {
1580 session = openSession();
1581
1582 MBStatsUser[] array = new MBStatsUserImpl[3];
1583
1584 array[0] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1585 groupId, userId, messageCount, orderByComparator, true);
1586
1587 array[1] = mbStatsUser;
1588
1589 array[2] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1590 groupId, userId, messageCount, orderByComparator, false);
1591
1592 return array;
1593 }
1594 catch (Exception e) {
1595 throw processException(e);
1596 }
1597 finally {
1598 closeSession(session);
1599 }
1600 }
1601
1602 protected MBStatsUser getByG_NotU_NotM_PrevAndNext(Session session,
1603 MBStatsUser mbStatsUser, long groupId, long userId, int messageCount,
1604 OrderByComparator orderByComparator, boolean previous) {
1605 StringBundler query = null;
1606
1607 if (orderByComparator != null) {
1608 query = new StringBundler(6 +
1609 (orderByComparator.getOrderByFields().length * 6));
1610 }
1611 else {
1612 query = new StringBundler(3);
1613 }
1614
1615 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1616
1617 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1618
1619 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1620
1621 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1622
1623 if (orderByComparator != null) {
1624 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1625
1626 if (orderByConditionFields.length > 0) {
1627 query.append(WHERE_AND);
1628 }
1629
1630 for (int i = 0; i < orderByConditionFields.length; i++) {
1631 query.append(_ORDER_BY_ENTITY_ALIAS);
1632 query.append(orderByConditionFields[i]);
1633
1634 if ((i + 1) < orderByConditionFields.length) {
1635 if (orderByComparator.isAscending() ^ previous) {
1636 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1637 }
1638 else {
1639 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1640 }
1641 }
1642 else {
1643 if (orderByComparator.isAscending() ^ previous) {
1644 query.append(WHERE_GREATER_THAN);
1645 }
1646 else {
1647 query.append(WHERE_LESSER_THAN);
1648 }
1649 }
1650 }
1651
1652 query.append(ORDER_BY_CLAUSE);
1653
1654 String[] orderByFields = orderByComparator.getOrderByFields();
1655
1656 for (int i = 0; i < orderByFields.length; i++) {
1657 query.append(_ORDER_BY_ENTITY_ALIAS);
1658 query.append(orderByFields[i]);
1659
1660 if ((i + 1) < orderByFields.length) {
1661 if (orderByComparator.isAscending() ^ previous) {
1662 query.append(ORDER_BY_ASC_HAS_NEXT);
1663 }
1664 else {
1665 query.append(ORDER_BY_DESC_HAS_NEXT);
1666 }
1667 }
1668 else {
1669 if (orderByComparator.isAscending() ^ previous) {
1670 query.append(ORDER_BY_ASC);
1671 }
1672 else {
1673 query.append(ORDER_BY_DESC);
1674 }
1675 }
1676 }
1677 }
1678 else {
1679 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1680 }
1681
1682 String sql = query.toString();
1683
1684 Query q = session.createQuery(sql);
1685
1686 q.setFirstResult(0);
1687 q.setMaxResults(2);
1688
1689 QueryPos qPos = QueryPos.getInstance(q);
1690
1691 qPos.add(groupId);
1692
1693 qPos.add(userId);
1694
1695 qPos.add(messageCount);
1696
1697 if (orderByComparator != null) {
1698 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1699
1700 for (Object value : values) {
1701 qPos.add(value);
1702 }
1703 }
1704
1705 List<MBStatsUser> list = q.list();
1706
1707 if (list.size() == 2) {
1708 return list.get(1);
1709 }
1710 else {
1711 return null;
1712 }
1713 }
1714
1715
1723 public void removeByG_NotU_NotM(long groupId, long userId, int messageCount)
1724 throws SystemException {
1725 for (MBStatsUser mbStatsUser : findByG_NotU_NotM(groupId, userId,
1726 messageCount, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1727 remove(mbStatsUser);
1728 }
1729 }
1730
1731
1740 public int countByG_NotU_NotM(long groupId, long userId, int messageCount)
1741 throws SystemException {
1742 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM;
1743
1744 Object[] finderArgs = new Object[] { groupId, userId, messageCount };
1745
1746 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1747 this);
1748
1749 if (count == null) {
1750 StringBundler query = new StringBundler(4);
1751
1752 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1753
1754 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1755
1756 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1757
1758 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1759
1760 String sql = query.toString();
1761
1762 Session session = null;
1763
1764 try {
1765 session = openSession();
1766
1767 Query q = session.createQuery(sql);
1768
1769 QueryPos qPos = QueryPos.getInstance(q);
1770
1771 qPos.add(groupId);
1772
1773 qPos.add(userId);
1774
1775 qPos.add(messageCount);
1776
1777 count = (Long)q.uniqueResult();
1778
1779 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1780 }
1781 catch (Exception e) {
1782 FinderCacheUtil.removeResult(finderPath, finderArgs);
1783
1784 throw processException(e);
1785 }
1786 finally {
1787 closeSession(session);
1788 }
1789 }
1790
1791 return count.intValue();
1792 }
1793
1794 private static final String _FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
1795 private static final String _FINDER_COLUMN_G_NOTU_NOTM_USERID_2 = "mbStatsUser.userId != ? AND ";
1796 private static final String _FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
1797
1798
1803 public void cacheResult(MBStatsUser mbStatsUser) {
1804 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1805 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
1806
1807 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1808 new Object[] { mbStatsUser.getGroupId(), mbStatsUser.getUserId() },
1809 mbStatsUser);
1810
1811 mbStatsUser.resetOriginalValues();
1812 }
1813
1814
1819 public void cacheResult(List<MBStatsUser> mbStatsUsers) {
1820 for (MBStatsUser mbStatsUser : mbStatsUsers) {
1821 if (EntityCacheUtil.getResult(
1822 MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1823 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey()) == null) {
1824 cacheResult(mbStatsUser);
1825 }
1826 else {
1827 mbStatsUser.resetOriginalValues();
1828 }
1829 }
1830 }
1831
1832
1839 @Override
1840 public void clearCache() {
1841 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1842 CacheRegistryUtil.clear(MBStatsUserImpl.class.getName());
1843 }
1844
1845 EntityCacheUtil.clearCache(MBStatsUserImpl.class.getName());
1846
1847 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1848 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1849 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1850 }
1851
1852
1859 @Override
1860 public void clearCache(MBStatsUser mbStatsUser) {
1861 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1862 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
1863
1864 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1865 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1866
1867 clearUniqueFindersCache(mbStatsUser);
1868 }
1869
1870 @Override
1871 public void clearCache(List<MBStatsUser> mbStatsUsers) {
1872 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1873 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1874
1875 for (MBStatsUser mbStatsUser : mbStatsUsers) {
1876 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
1877 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
1878
1879 clearUniqueFindersCache(mbStatsUser);
1880 }
1881 }
1882
1883 protected void cacheUniqueFindersCache(MBStatsUser mbStatsUser) {
1884 if (mbStatsUser.isNew()) {
1885 Object[] args = new Object[] {
1886 mbStatsUser.getGroupId(), mbStatsUser.getUserId()
1887 };
1888
1889 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, args,
1890 Long.valueOf(1));
1891 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U, args,
1892 mbStatsUser);
1893 }
1894 else {
1895 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
1896
1897 if ((mbStatsUserModelImpl.getColumnBitmask() &
1898 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
1899 Object[] args = new Object[] {
1900 mbStatsUser.getGroupId(), mbStatsUser.getUserId()
1901 };
1902
1903 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, args,
1904 Long.valueOf(1));
1905 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U, args,
1906 mbStatsUser);
1907 }
1908 }
1909 }
1910
1911 protected void clearUniqueFindersCache(MBStatsUser mbStatsUser) {
1912 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
1913
1914 Object[] args = new Object[] {
1915 mbStatsUser.getGroupId(), mbStatsUser.getUserId()
1916 };
1917
1918 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1919 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
1920
1921 if ((mbStatsUserModelImpl.getColumnBitmask() &
1922 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
1923 args = new Object[] {
1924 mbStatsUserModelImpl.getOriginalGroupId(),
1925 mbStatsUserModelImpl.getOriginalUserId()
1926 };
1927
1928 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
1929 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
1930 }
1931 }
1932
1933
1939 public MBStatsUser create(long statsUserId) {
1940 MBStatsUser mbStatsUser = new MBStatsUserImpl();
1941
1942 mbStatsUser.setNew(true);
1943 mbStatsUser.setPrimaryKey(statsUserId);
1944
1945 return mbStatsUser;
1946 }
1947
1948
1956 public MBStatsUser remove(long statsUserId)
1957 throws NoSuchStatsUserException, SystemException {
1958 return remove((Serializable)statsUserId);
1959 }
1960
1961
1969 @Override
1970 public MBStatsUser remove(Serializable primaryKey)
1971 throws NoSuchStatsUserException, SystemException {
1972 Session session = null;
1973
1974 try {
1975 session = openSession();
1976
1977 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
1978 primaryKey);
1979
1980 if (mbStatsUser == null) {
1981 if (_log.isWarnEnabled()) {
1982 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1983 }
1984
1985 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1986 primaryKey);
1987 }
1988
1989 return remove(mbStatsUser);
1990 }
1991 catch (NoSuchStatsUserException nsee) {
1992 throw nsee;
1993 }
1994 catch (Exception e) {
1995 throw processException(e);
1996 }
1997 finally {
1998 closeSession(session);
1999 }
2000 }
2001
2002 @Override
2003 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
2004 throws SystemException {
2005 mbStatsUser = toUnwrappedModel(mbStatsUser);
2006
2007 Session session = null;
2008
2009 try {
2010 session = openSession();
2011
2012 if (!session.contains(mbStatsUser)) {
2013 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
2014 mbStatsUser.getPrimaryKeyObj());
2015 }
2016
2017 if (mbStatsUser != null) {
2018 session.delete(mbStatsUser);
2019 }
2020 }
2021 catch (Exception e) {
2022 throw processException(e);
2023 }
2024 finally {
2025 closeSession(session);
2026 }
2027
2028 if (mbStatsUser != null) {
2029 clearCache(mbStatsUser);
2030 }
2031
2032 return mbStatsUser;
2033 }
2034
2035 @Override
2036 public MBStatsUser updateImpl(
2037 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser)
2038 throws SystemException {
2039 mbStatsUser = toUnwrappedModel(mbStatsUser);
2040
2041 boolean isNew = mbStatsUser.isNew();
2042
2043 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
2044
2045 Session session = null;
2046
2047 try {
2048 session = openSession();
2049
2050 if (mbStatsUser.isNew()) {
2051 session.save(mbStatsUser);
2052
2053 mbStatsUser.setNew(false);
2054 }
2055 else {
2056 session.merge(mbStatsUser);
2057 }
2058 }
2059 catch (Exception e) {
2060 throw processException(e);
2061 }
2062 finally {
2063 closeSession(session);
2064 }
2065
2066 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2067
2068 if (isNew || !MBStatsUserModelImpl.COLUMN_BITMASK_ENABLED) {
2069 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2070 }
2071
2072 else {
2073 if ((mbStatsUserModelImpl.getColumnBitmask() &
2074 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
2075 Object[] args = new Object[] {
2076 mbStatsUserModelImpl.getOriginalGroupId()
2077 };
2078
2079 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2080 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2081 args);
2082
2083 args = new Object[] { mbStatsUserModelImpl.getGroupId() };
2084
2085 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
2086 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
2087 args);
2088 }
2089
2090 if ((mbStatsUserModelImpl.getColumnBitmask() &
2091 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2092 Object[] args = new Object[] {
2093 mbStatsUserModelImpl.getOriginalUserId()
2094 };
2095
2096 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2097 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2098 args);
2099
2100 args = new Object[] { mbStatsUserModelImpl.getUserId() };
2101
2102 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2103 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2104 args);
2105 }
2106 }
2107
2108 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2109 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
2110
2111 clearUniqueFindersCache(mbStatsUser);
2112 cacheUniqueFindersCache(mbStatsUser);
2113
2114 return mbStatsUser;
2115 }
2116
2117 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
2118 if (mbStatsUser instanceof MBStatsUserImpl) {
2119 return mbStatsUser;
2120 }
2121
2122 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
2123
2124 mbStatsUserImpl.setNew(mbStatsUser.isNew());
2125 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
2126
2127 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
2128 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
2129 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
2130 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
2131 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
2132
2133 return mbStatsUserImpl;
2134 }
2135
2136
2144 @Override
2145 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
2146 throws NoSuchStatsUserException, SystemException {
2147 MBStatsUser mbStatsUser = fetchByPrimaryKey(primaryKey);
2148
2149 if (mbStatsUser == null) {
2150 if (_log.isWarnEnabled()) {
2151 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2152 }
2153
2154 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2155 primaryKey);
2156 }
2157
2158 return mbStatsUser;
2159 }
2160
2161
2169 public MBStatsUser findByPrimaryKey(long statsUserId)
2170 throws NoSuchStatsUserException, SystemException {
2171 return findByPrimaryKey((Serializable)statsUserId);
2172 }
2173
2174
2181 @Override
2182 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
2183 throws SystemException {
2184 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2185 MBStatsUserImpl.class, primaryKey);
2186
2187 if (mbStatsUser == _nullMBStatsUser) {
2188 return null;
2189 }
2190
2191 if (mbStatsUser == null) {
2192 Session session = null;
2193
2194 try {
2195 session = openSession();
2196
2197 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
2198 primaryKey);
2199
2200 if (mbStatsUser != null) {
2201 cacheResult(mbStatsUser);
2202 }
2203 else {
2204 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2205 MBStatsUserImpl.class, primaryKey, _nullMBStatsUser);
2206 }
2207 }
2208 catch (Exception e) {
2209 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
2210 MBStatsUserImpl.class, primaryKey);
2211
2212 throw processException(e);
2213 }
2214 finally {
2215 closeSession(session);
2216 }
2217 }
2218
2219 return mbStatsUser;
2220 }
2221
2222
2229 public MBStatsUser fetchByPrimaryKey(long statsUserId)
2230 throws SystemException {
2231 return fetchByPrimaryKey((Serializable)statsUserId);
2232 }
2233
2234
2240 public List<MBStatsUser> findAll() throws SystemException {
2241 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2242 }
2243
2244
2256 public List<MBStatsUser> findAll(int start, int end)
2257 throws SystemException {
2258 return findAll(start, end, null);
2259 }
2260
2261
2274 public List<MBStatsUser> findAll(int start, int end,
2275 OrderByComparator orderByComparator) throws SystemException {
2276 boolean pagination = true;
2277 FinderPath finderPath = null;
2278 Object[] finderArgs = null;
2279
2280 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2281 (orderByComparator == null)) {
2282 pagination = false;
2283 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2284 finderArgs = FINDER_ARGS_EMPTY;
2285 }
2286 else {
2287 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2288 finderArgs = new Object[] { start, end, orderByComparator };
2289 }
2290
2291 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
2292 finderArgs, this);
2293
2294 if (list == null) {
2295 StringBundler query = null;
2296 String sql = null;
2297
2298 if (orderByComparator != null) {
2299 query = new StringBundler(2 +
2300 (orderByComparator.getOrderByFields().length * 3));
2301
2302 query.append(_SQL_SELECT_MBSTATSUSER);
2303
2304 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2305 orderByComparator);
2306
2307 sql = query.toString();
2308 }
2309 else {
2310 sql = _SQL_SELECT_MBSTATSUSER;
2311
2312 if (pagination) {
2313 sql = sql.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
2314 }
2315 }
2316
2317 Session session = null;
2318
2319 try {
2320 session = openSession();
2321
2322 Query q = session.createQuery(sql);
2323
2324 if (!pagination) {
2325 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
2326 start, end, false);
2327
2328 Collections.sort(list);
2329
2330 list = new UnmodifiableList<MBStatsUser>(list);
2331 }
2332 else {
2333 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
2334 start, end);
2335 }
2336
2337 cacheResult(list);
2338
2339 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2340 }
2341 catch (Exception e) {
2342 FinderCacheUtil.removeResult(finderPath, finderArgs);
2343
2344 throw processException(e);
2345 }
2346 finally {
2347 closeSession(session);
2348 }
2349 }
2350
2351 return list;
2352 }
2353
2354
2359 public void removeAll() throws SystemException {
2360 for (MBStatsUser mbStatsUser : findAll()) {
2361 remove(mbStatsUser);
2362 }
2363 }
2364
2365
2371 public int countAll() throws SystemException {
2372 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2373 FINDER_ARGS_EMPTY, this);
2374
2375 if (count == null) {
2376 Session session = null;
2377
2378 try {
2379 session = openSession();
2380
2381 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2382
2383 count = (Long)q.uniqueResult();
2384
2385 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2386 FINDER_ARGS_EMPTY, count);
2387 }
2388 catch (Exception e) {
2389 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2390 FINDER_ARGS_EMPTY);
2391
2392 throw processException(e);
2393 }
2394 finally {
2395 closeSession(session);
2396 }
2397 }
2398
2399 return count.intValue();
2400 }
2401
2402
2405 public void afterPropertiesSet() {
2406 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2407 com.liferay.portal.util.PropsUtil.get(
2408 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2409
2410 if (listenerClassNames.length > 0) {
2411 try {
2412 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2413
2414 for (String listenerClassName : listenerClassNames) {
2415 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2416 listenerClassName));
2417 }
2418
2419 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2420 }
2421 catch (Exception e) {
2422 _log.error(e);
2423 }
2424 }
2425 }
2426
2427 public void destroy() {
2428 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2429 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2430 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2431 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2432 }
2433
2434 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2435 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2436 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2437 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2438 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2439 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2440 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2441 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2442 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2443 private static MBStatsUser _nullMBStatsUser = new MBStatsUserImpl() {
2444 @Override
2445 public Object clone() {
2446 return this;
2447 }
2448
2449 @Override
2450 public CacheModel<MBStatsUser> toCacheModel() {
2451 return _nullMBStatsUserCacheModel;
2452 }
2453 };
2454
2455 private static CacheModel<MBStatsUser> _nullMBStatsUserCacheModel = new CacheModel<MBStatsUser>() {
2456 public MBStatsUser toEntityModel() {
2457 return _nullMBStatsUser;
2458 }
2459 };
2460 }