001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.GroupPersistence;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.messageboards.NoSuchStatsUserException;
045 import com.liferay.portlet.messageboards.model.MBStatsUser;
046 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
047 import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
067 public class MBStatsUserPersistenceImpl extends BasePersistenceImpl<MBStatsUser>
068 implements MBStatsUserPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = MBStatsUserImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
080 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
089 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
090 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
092 new String[] { Long.class.getName() },
093 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK);
094 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
095 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
097 new String[] { Long.class.getName() });
098 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
099 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
100 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
101 new String[] {
102 Long.class.getName(),
103
104 "java.lang.Integer", "java.lang.Integer",
105 "com.liferay.portal.kernel.util.OrderByComparator"
106 });
107 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
108 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
109 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
110 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
111 new String[] { Long.class.getName() },
112 MBStatsUserModelImpl.USERID_COLUMN_BITMASK);
113 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
114 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
115 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
116 new String[] { Long.class.getName() });
117 public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
118 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
119 FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
120 new String[] { Long.class.getName(), Long.class.getName() },
121 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
122 MBStatsUserModelImpl.USERID_COLUMN_BITMASK);
123 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
124 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
125 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
126 new String[] { Long.class.getName(), Long.class.getName() });
127 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM =
128 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
129 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
130 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotU_NotM",
131 new String[] {
132 Long.class.getName(), Long.class.getName(),
133 Integer.class.getName(),
134
135 "java.lang.Integer", "java.lang.Integer",
136 "com.liferay.portal.kernel.util.OrderByComparator"
137 });
138 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM =
139 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
140 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
141 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotU_NotM",
142 new String[] {
143 Long.class.getName(), Long.class.getName(),
144 Integer.class.getName()
145 });
146 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
147 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
148 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
149 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
150 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
151 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
152 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
153 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
154 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
155
156
161 public void cacheResult(MBStatsUser mbStatsUser) {
162 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
163 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
164
165 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
166 new Object[] {
167 Long.valueOf(mbStatsUser.getGroupId()),
168 Long.valueOf(mbStatsUser.getUserId())
169 }, mbStatsUser);
170
171 mbStatsUser.resetOriginalValues();
172 }
173
174
179 public void cacheResult(List<MBStatsUser> mbStatsUsers) {
180 for (MBStatsUser mbStatsUser : mbStatsUsers) {
181 if (EntityCacheUtil.getResult(
182 MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
183 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey()) == null) {
184 cacheResult(mbStatsUser);
185 }
186 else {
187 mbStatsUser.resetOriginalValues();
188 }
189 }
190 }
191
192
199 @Override
200 public void clearCache() {
201 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
202 CacheRegistryUtil.clear(MBStatsUserImpl.class.getName());
203 }
204
205 EntityCacheUtil.clearCache(MBStatsUserImpl.class.getName());
206
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
208 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
209 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
210 }
211
212
219 @Override
220 public void clearCache(MBStatsUser mbStatsUser) {
221 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
222 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
223
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
225 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
226
227 clearUniqueFindersCache(mbStatsUser);
228 }
229
230 @Override
231 public void clearCache(List<MBStatsUser> mbStatsUsers) {
232 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
233 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
234
235 for (MBStatsUser mbStatsUser : mbStatsUsers) {
236 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
237 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
238
239 clearUniqueFindersCache(mbStatsUser);
240 }
241 }
242
243 protected void clearUniqueFindersCache(MBStatsUser mbStatsUser) {
244 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
245 new Object[] {
246 Long.valueOf(mbStatsUser.getGroupId()),
247 Long.valueOf(mbStatsUser.getUserId())
248 });
249 }
250
251
257 public MBStatsUser create(long statsUserId) {
258 MBStatsUser mbStatsUser = new MBStatsUserImpl();
259
260 mbStatsUser.setNew(true);
261 mbStatsUser.setPrimaryKey(statsUserId);
262
263 return mbStatsUser;
264 }
265
266
274 public MBStatsUser remove(long statsUserId)
275 throws NoSuchStatsUserException, SystemException {
276 return remove(Long.valueOf(statsUserId));
277 }
278
279
287 @Override
288 public MBStatsUser remove(Serializable primaryKey)
289 throws NoSuchStatsUserException, SystemException {
290 Session session = null;
291
292 try {
293 session = openSession();
294
295 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
296 primaryKey);
297
298 if (mbStatsUser == null) {
299 if (_log.isWarnEnabled()) {
300 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
301 }
302
303 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
304 primaryKey);
305 }
306
307 return remove(mbStatsUser);
308 }
309 catch (NoSuchStatsUserException nsee) {
310 throw nsee;
311 }
312 catch (Exception e) {
313 throw processException(e);
314 }
315 finally {
316 closeSession(session);
317 }
318 }
319
320 @Override
321 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
322 throws SystemException {
323 mbStatsUser = toUnwrappedModel(mbStatsUser);
324
325 Session session = null;
326
327 try {
328 session = openSession();
329
330 BatchSessionUtil.delete(session, mbStatsUser);
331 }
332 catch (Exception e) {
333 throw processException(e);
334 }
335 finally {
336 closeSession(session);
337 }
338
339 clearCache(mbStatsUser);
340
341 return mbStatsUser;
342 }
343
344 @Override
345 public MBStatsUser updateImpl(
346 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
347 boolean merge) throws SystemException {
348 mbStatsUser = toUnwrappedModel(mbStatsUser);
349
350 boolean isNew = mbStatsUser.isNew();
351
352 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
353
354 Session session = null;
355
356 try {
357 session = openSession();
358
359 BatchSessionUtil.update(session, mbStatsUser, merge);
360
361 mbStatsUser.setNew(false);
362 }
363 catch (Exception e) {
364 throw processException(e);
365 }
366 finally {
367 closeSession(session);
368 }
369
370 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
371
372 if (isNew || !MBStatsUserModelImpl.COLUMN_BITMASK_ENABLED) {
373 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
374 }
375
376 else {
377 if ((mbStatsUserModelImpl.getColumnBitmask() &
378 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
379 Object[] args = new Object[] {
380 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId())
381 };
382
383 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
384 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
385 args);
386
387 args = new Object[] {
388 Long.valueOf(mbStatsUserModelImpl.getGroupId())
389 };
390
391 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
392 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
393 args);
394 }
395
396 if ((mbStatsUserModelImpl.getColumnBitmask() &
397 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
398 Object[] args = new Object[] {
399 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
400 };
401
402 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
403 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
404 args);
405
406 args = new Object[] {
407 Long.valueOf(mbStatsUserModelImpl.getUserId())
408 };
409
410 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
411 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
412 args);
413 }
414 }
415
416 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
417 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
418
419 if (isNew) {
420 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
421 new Object[] {
422 Long.valueOf(mbStatsUser.getGroupId()),
423 Long.valueOf(mbStatsUser.getUserId())
424 }, mbStatsUser);
425 }
426 else {
427 if ((mbStatsUserModelImpl.getColumnBitmask() &
428 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
429 Object[] args = new Object[] {
430 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
431 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
432 };
433
434 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
435
436 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
437
438 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
439 new Object[] {
440 Long.valueOf(mbStatsUser.getGroupId()),
441 Long.valueOf(mbStatsUser.getUserId())
442 }, mbStatsUser);
443 }
444 }
445
446 return mbStatsUser;
447 }
448
449 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
450 if (mbStatsUser instanceof MBStatsUserImpl) {
451 return mbStatsUser;
452 }
453
454 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
455
456 mbStatsUserImpl.setNew(mbStatsUser.isNew());
457 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
458
459 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
460 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
461 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
462 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
463 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
464
465 return mbStatsUserImpl;
466 }
467
468
476 @Override
477 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
478 throws NoSuchModelException, SystemException {
479 return findByPrimaryKey(((Long)primaryKey).longValue());
480 }
481
482
490 public MBStatsUser findByPrimaryKey(long statsUserId)
491 throws NoSuchStatsUserException, SystemException {
492 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
493
494 if (mbStatsUser == null) {
495 if (_log.isWarnEnabled()) {
496 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
497 }
498
499 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
500 statsUserId);
501 }
502
503 return mbStatsUser;
504 }
505
506
513 @Override
514 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
515 throws SystemException {
516 return fetchByPrimaryKey(((Long)primaryKey).longValue());
517 }
518
519
526 public MBStatsUser fetchByPrimaryKey(long statsUserId)
527 throws SystemException {
528 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
529 MBStatsUserImpl.class, statsUserId);
530
531 if (mbStatsUser == _nullMBStatsUser) {
532 return null;
533 }
534
535 if (mbStatsUser == null) {
536 Session session = null;
537
538 boolean hasException = false;
539
540 try {
541 session = openSession();
542
543 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
544 Long.valueOf(statsUserId));
545 }
546 catch (Exception e) {
547 hasException = true;
548
549 throw processException(e);
550 }
551 finally {
552 if (mbStatsUser != null) {
553 cacheResult(mbStatsUser);
554 }
555 else if (!hasException) {
556 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
557 MBStatsUserImpl.class, statsUserId, _nullMBStatsUser);
558 }
559
560 closeSession(session);
561 }
562 }
563
564 return mbStatsUser;
565 }
566
567
574 public List<MBStatsUser> findByGroupId(long groupId)
575 throws SystemException {
576 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
577 }
578
579
592 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
593 throws SystemException {
594 return findByGroupId(groupId, start, end, null);
595 }
596
597
611 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
612 OrderByComparator orderByComparator) throws SystemException {
613 FinderPath finderPath = null;
614 Object[] finderArgs = null;
615
616 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
617 (orderByComparator == null)) {
618 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
619 finderArgs = new Object[] { groupId };
620 }
621 else {
622 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
623 finderArgs = new Object[] { groupId, start, end, orderByComparator };
624 }
625
626 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
627 finderArgs, this);
628
629 if ((list != null) && !list.isEmpty()) {
630 for (MBStatsUser mbStatsUser : list) {
631 if ((groupId != mbStatsUser.getGroupId())) {
632 list = null;
633
634 break;
635 }
636 }
637 }
638
639 if (list == null) {
640 StringBundler query = null;
641
642 if (orderByComparator != null) {
643 query = new StringBundler(3 +
644 (orderByComparator.getOrderByFields().length * 3));
645 }
646 else {
647 query = new StringBundler(3);
648 }
649
650 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
651
652 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
653
654 if (orderByComparator != null) {
655 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
656 orderByComparator);
657 }
658
659 else {
660 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
661 }
662
663 String sql = query.toString();
664
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 Query q = session.createQuery(sql);
671
672 QueryPos qPos = QueryPos.getInstance(q);
673
674 qPos.add(groupId);
675
676 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
677 start, end);
678 }
679 catch (Exception e) {
680 throw processException(e);
681 }
682 finally {
683 if (list == null) {
684 FinderCacheUtil.removeResult(finderPath, finderArgs);
685 }
686 else {
687 cacheResult(list);
688
689 FinderCacheUtil.putResult(finderPath, finderArgs, list);
690 }
691
692 closeSession(session);
693 }
694 }
695
696 return list;
697 }
698
699
708 public MBStatsUser findByGroupId_First(long groupId,
709 OrderByComparator orderByComparator)
710 throws NoSuchStatsUserException, SystemException {
711 MBStatsUser mbStatsUser = fetchByGroupId_First(groupId,
712 orderByComparator);
713
714 if (mbStatsUser != null) {
715 return mbStatsUser;
716 }
717
718 StringBundler msg = new StringBundler(4);
719
720 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
721
722 msg.append("groupId=");
723 msg.append(groupId);
724
725 msg.append(StringPool.CLOSE_CURLY_BRACE);
726
727 throw new NoSuchStatsUserException(msg.toString());
728 }
729
730
738 public MBStatsUser fetchByGroupId_First(long groupId,
739 OrderByComparator orderByComparator) throws SystemException {
740 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
741
742 if (!list.isEmpty()) {
743 return list.get(0);
744 }
745
746 return null;
747 }
748
749
758 public MBStatsUser findByGroupId_Last(long groupId,
759 OrderByComparator orderByComparator)
760 throws NoSuchStatsUserException, SystemException {
761 MBStatsUser mbStatsUser = fetchByGroupId_Last(groupId, orderByComparator);
762
763 if (mbStatsUser != null) {
764 return mbStatsUser;
765 }
766
767 StringBundler msg = new StringBundler(4);
768
769 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
770
771 msg.append("groupId=");
772 msg.append(groupId);
773
774 msg.append(StringPool.CLOSE_CURLY_BRACE);
775
776 throw new NoSuchStatsUserException(msg.toString());
777 }
778
779
787 public MBStatsUser fetchByGroupId_Last(long groupId,
788 OrderByComparator orderByComparator) throws SystemException {
789 int count = countByGroupId(groupId);
790
791 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
792 orderByComparator);
793
794 if (!list.isEmpty()) {
795 return list.get(0);
796 }
797
798 return null;
799 }
800
801
811 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
812 long groupId, OrderByComparator orderByComparator)
813 throws NoSuchStatsUserException, SystemException {
814 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
815
816 Session session = null;
817
818 try {
819 session = openSession();
820
821 MBStatsUser[] array = new MBStatsUserImpl[3];
822
823 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
824 orderByComparator, true);
825
826 array[1] = mbStatsUser;
827
828 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
829 orderByComparator, false);
830
831 return array;
832 }
833 catch (Exception e) {
834 throw processException(e);
835 }
836 finally {
837 closeSession(session);
838 }
839 }
840
841 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
842 MBStatsUser mbStatsUser, long groupId,
843 OrderByComparator orderByComparator, boolean previous) {
844 StringBundler query = null;
845
846 if (orderByComparator != null) {
847 query = new StringBundler(6 +
848 (orderByComparator.getOrderByFields().length * 6));
849 }
850 else {
851 query = new StringBundler(3);
852 }
853
854 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
855
856 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
857
858 if (orderByComparator != null) {
859 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
860
861 if (orderByConditionFields.length > 0) {
862 query.append(WHERE_AND);
863 }
864
865 for (int i = 0; i < orderByConditionFields.length; i++) {
866 query.append(_ORDER_BY_ENTITY_ALIAS);
867 query.append(orderByConditionFields[i]);
868
869 if ((i + 1) < orderByConditionFields.length) {
870 if (orderByComparator.isAscending() ^ previous) {
871 query.append(WHERE_GREATER_THAN_HAS_NEXT);
872 }
873 else {
874 query.append(WHERE_LESSER_THAN_HAS_NEXT);
875 }
876 }
877 else {
878 if (orderByComparator.isAscending() ^ previous) {
879 query.append(WHERE_GREATER_THAN);
880 }
881 else {
882 query.append(WHERE_LESSER_THAN);
883 }
884 }
885 }
886
887 query.append(ORDER_BY_CLAUSE);
888
889 String[] orderByFields = orderByComparator.getOrderByFields();
890
891 for (int i = 0; i < orderByFields.length; i++) {
892 query.append(_ORDER_BY_ENTITY_ALIAS);
893 query.append(orderByFields[i]);
894
895 if ((i + 1) < orderByFields.length) {
896 if (orderByComparator.isAscending() ^ previous) {
897 query.append(ORDER_BY_ASC_HAS_NEXT);
898 }
899 else {
900 query.append(ORDER_BY_DESC_HAS_NEXT);
901 }
902 }
903 else {
904 if (orderByComparator.isAscending() ^ previous) {
905 query.append(ORDER_BY_ASC);
906 }
907 else {
908 query.append(ORDER_BY_DESC);
909 }
910 }
911 }
912 }
913
914 else {
915 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
916 }
917
918 String sql = query.toString();
919
920 Query q = session.createQuery(sql);
921
922 q.setFirstResult(0);
923 q.setMaxResults(2);
924
925 QueryPos qPos = QueryPos.getInstance(q);
926
927 qPos.add(groupId);
928
929 if (orderByComparator != null) {
930 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
931
932 for (Object value : values) {
933 qPos.add(value);
934 }
935 }
936
937 List<MBStatsUser> list = q.list();
938
939 if (list.size() == 2) {
940 return list.get(1);
941 }
942 else {
943 return null;
944 }
945 }
946
947
954 public List<MBStatsUser> findByUserId(long userId)
955 throws SystemException {
956 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
957 }
958
959
972 public List<MBStatsUser> findByUserId(long userId, int start, int end)
973 throws SystemException {
974 return findByUserId(userId, start, end, null);
975 }
976
977
991 public List<MBStatsUser> findByUserId(long userId, int start, int end,
992 OrderByComparator orderByComparator) throws SystemException {
993 FinderPath finderPath = null;
994 Object[] finderArgs = null;
995
996 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
997 (orderByComparator == null)) {
998 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
999 finderArgs = new Object[] { userId };
1000 }
1001 else {
1002 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1003 finderArgs = new Object[] { userId, start, end, orderByComparator };
1004 }
1005
1006 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1007 finderArgs, this);
1008
1009 if ((list != null) && !list.isEmpty()) {
1010 for (MBStatsUser mbStatsUser : list) {
1011 if ((userId != mbStatsUser.getUserId())) {
1012 list = null;
1013
1014 break;
1015 }
1016 }
1017 }
1018
1019 if (list == null) {
1020 StringBundler query = null;
1021
1022 if (orderByComparator != null) {
1023 query = new StringBundler(3 +
1024 (orderByComparator.getOrderByFields().length * 3));
1025 }
1026 else {
1027 query = new StringBundler(3);
1028 }
1029
1030 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1031
1032 query.append(_FINDER_COLUMN_USERID_USERID_2);
1033
1034 if (orderByComparator != null) {
1035 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1036 orderByComparator);
1037 }
1038
1039 else {
1040 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1041 }
1042
1043 String sql = query.toString();
1044
1045 Session session = null;
1046
1047 try {
1048 session = openSession();
1049
1050 Query q = session.createQuery(sql);
1051
1052 QueryPos qPos = QueryPos.getInstance(q);
1053
1054 qPos.add(userId);
1055
1056 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1057 start, end);
1058 }
1059 catch (Exception e) {
1060 throw processException(e);
1061 }
1062 finally {
1063 if (list == null) {
1064 FinderCacheUtil.removeResult(finderPath, finderArgs);
1065 }
1066 else {
1067 cacheResult(list);
1068
1069 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1070 }
1071
1072 closeSession(session);
1073 }
1074 }
1075
1076 return list;
1077 }
1078
1079
1088 public MBStatsUser findByUserId_First(long userId,
1089 OrderByComparator orderByComparator)
1090 throws NoSuchStatsUserException, SystemException {
1091 MBStatsUser mbStatsUser = fetchByUserId_First(userId, orderByComparator);
1092
1093 if (mbStatsUser != null) {
1094 return mbStatsUser;
1095 }
1096
1097 StringBundler msg = new StringBundler(4);
1098
1099 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1100
1101 msg.append("userId=");
1102 msg.append(userId);
1103
1104 msg.append(StringPool.CLOSE_CURLY_BRACE);
1105
1106 throw new NoSuchStatsUserException(msg.toString());
1107 }
1108
1109
1117 public MBStatsUser fetchByUserId_First(long userId,
1118 OrderByComparator orderByComparator) throws SystemException {
1119 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
1120
1121 if (!list.isEmpty()) {
1122 return list.get(0);
1123 }
1124
1125 return null;
1126 }
1127
1128
1137 public MBStatsUser findByUserId_Last(long userId,
1138 OrderByComparator orderByComparator)
1139 throws NoSuchStatsUserException, SystemException {
1140 MBStatsUser mbStatsUser = fetchByUserId_Last(userId, orderByComparator);
1141
1142 if (mbStatsUser != null) {
1143 return mbStatsUser;
1144 }
1145
1146 StringBundler msg = new StringBundler(4);
1147
1148 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1149
1150 msg.append("userId=");
1151 msg.append(userId);
1152
1153 msg.append(StringPool.CLOSE_CURLY_BRACE);
1154
1155 throw new NoSuchStatsUserException(msg.toString());
1156 }
1157
1158
1166 public MBStatsUser fetchByUserId_Last(long userId,
1167 OrderByComparator orderByComparator) throws SystemException {
1168 int count = countByUserId(userId);
1169
1170 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
1171 orderByComparator);
1172
1173 if (!list.isEmpty()) {
1174 return list.get(0);
1175 }
1176
1177 return null;
1178 }
1179
1180
1190 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
1191 long userId, OrderByComparator orderByComparator)
1192 throws NoSuchStatsUserException, SystemException {
1193 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1194
1195 Session session = null;
1196
1197 try {
1198 session = openSession();
1199
1200 MBStatsUser[] array = new MBStatsUserImpl[3];
1201
1202 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1203 orderByComparator, true);
1204
1205 array[1] = mbStatsUser;
1206
1207 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1208 orderByComparator, false);
1209
1210 return array;
1211 }
1212 catch (Exception e) {
1213 throw processException(e);
1214 }
1215 finally {
1216 closeSession(session);
1217 }
1218 }
1219
1220 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1221 MBStatsUser mbStatsUser, long userId,
1222 OrderByComparator orderByComparator, boolean previous) {
1223 StringBundler query = null;
1224
1225 if (orderByComparator != null) {
1226 query = new StringBundler(6 +
1227 (orderByComparator.getOrderByFields().length * 6));
1228 }
1229 else {
1230 query = new StringBundler(3);
1231 }
1232
1233 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1234
1235 query.append(_FINDER_COLUMN_USERID_USERID_2);
1236
1237 if (orderByComparator != null) {
1238 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1239
1240 if (orderByConditionFields.length > 0) {
1241 query.append(WHERE_AND);
1242 }
1243
1244 for (int i = 0; i < orderByConditionFields.length; i++) {
1245 query.append(_ORDER_BY_ENTITY_ALIAS);
1246 query.append(orderByConditionFields[i]);
1247
1248 if ((i + 1) < orderByConditionFields.length) {
1249 if (orderByComparator.isAscending() ^ previous) {
1250 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1251 }
1252 else {
1253 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1254 }
1255 }
1256 else {
1257 if (orderByComparator.isAscending() ^ previous) {
1258 query.append(WHERE_GREATER_THAN);
1259 }
1260 else {
1261 query.append(WHERE_LESSER_THAN);
1262 }
1263 }
1264 }
1265
1266 query.append(ORDER_BY_CLAUSE);
1267
1268 String[] orderByFields = orderByComparator.getOrderByFields();
1269
1270 for (int i = 0; i < orderByFields.length; i++) {
1271 query.append(_ORDER_BY_ENTITY_ALIAS);
1272 query.append(orderByFields[i]);
1273
1274 if ((i + 1) < orderByFields.length) {
1275 if (orderByComparator.isAscending() ^ previous) {
1276 query.append(ORDER_BY_ASC_HAS_NEXT);
1277 }
1278 else {
1279 query.append(ORDER_BY_DESC_HAS_NEXT);
1280 }
1281 }
1282 else {
1283 if (orderByComparator.isAscending() ^ previous) {
1284 query.append(ORDER_BY_ASC);
1285 }
1286 else {
1287 query.append(ORDER_BY_DESC);
1288 }
1289 }
1290 }
1291 }
1292
1293 else {
1294 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1295 }
1296
1297 String sql = query.toString();
1298
1299 Query q = session.createQuery(sql);
1300
1301 q.setFirstResult(0);
1302 q.setMaxResults(2);
1303
1304 QueryPos qPos = QueryPos.getInstance(q);
1305
1306 qPos.add(userId);
1307
1308 if (orderByComparator != null) {
1309 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1310
1311 for (Object value : values) {
1312 qPos.add(value);
1313 }
1314 }
1315
1316 List<MBStatsUser> list = q.list();
1317
1318 if (list.size() == 2) {
1319 return list.get(1);
1320 }
1321 else {
1322 return null;
1323 }
1324 }
1325
1326
1335 public MBStatsUser findByG_U(long groupId, long userId)
1336 throws NoSuchStatsUserException, SystemException {
1337 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1338
1339 if (mbStatsUser == null) {
1340 StringBundler msg = new StringBundler(6);
1341
1342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1343
1344 msg.append("groupId=");
1345 msg.append(groupId);
1346
1347 msg.append(", userId=");
1348 msg.append(userId);
1349
1350 msg.append(StringPool.CLOSE_CURLY_BRACE);
1351
1352 if (_log.isWarnEnabled()) {
1353 _log.warn(msg.toString());
1354 }
1355
1356 throw new NoSuchStatsUserException(msg.toString());
1357 }
1358
1359 return mbStatsUser;
1360 }
1361
1362
1370 public MBStatsUser fetchByG_U(long groupId, long userId)
1371 throws SystemException {
1372 return fetchByG_U(groupId, userId, true);
1373 }
1374
1375
1384 public MBStatsUser fetchByG_U(long groupId, long userId,
1385 boolean retrieveFromCache) throws SystemException {
1386 Object[] finderArgs = new Object[] { groupId, userId };
1387
1388 Object result = null;
1389
1390 if (retrieveFromCache) {
1391 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1392 finderArgs, this);
1393 }
1394
1395 if (result instanceof MBStatsUser) {
1396 MBStatsUser mbStatsUser = (MBStatsUser)result;
1397
1398 if ((groupId != mbStatsUser.getGroupId()) ||
1399 (userId != mbStatsUser.getUserId())) {
1400 result = null;
1401 }
1402 }
1403
1404 if (result == null) {
1405 StringBundler query = new StringBundler(4);
1406
1407 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1408
1409 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1410
1411 query.append(_FINDER_COLUMN_G_U_USERID_2);
1412
1413 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1414
1415 String sql = query.toString();
1416
1417 Session session = null;
1418
1419 try {
1420 session = openSession();
1421
1422 Query q = session.createQuery(sql);
1423
1424 QueryPos qPos = QueryPos.getInstance(q);
1425
1426 qPos.add(groupId);
1427
1428 qPos.add(userId);
1429
1430 List<MBStatsUser> list = q.list();
1431
1432 result = list;
1433
1434 MBStatsUser mbStatsUser = null;
1435
1436 if (list.isEmpty()) {
1437 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1438 finderArgs, list);
1439 }
1440 else {
1441 mbStatsUser = list.get(0);
1442
1443 cacheResult(mbStatsUser);
1444
1445 if ((mbStatsUser.getGroupId() != groupId) ||
1446 (mbStatsUser.getUserId() != userId)) {
1447 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1448 finderArgs, mbStatsUser);
1449 }
1450 }
1451
1452 return mbStatsUser;
1453 }
1454 catch (Exception e) {
1455 throw processException(e);
1456 }
1457 finally {
1458 if (result == null) {
1459 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1460 finderArgs);
1461 }
1462
1463 closeSession(session);
1464 }
1465 }
1466 else {
1467 if (result instanceof List<?>) {
1468 return null;
1469 }
1470 else {
1471 return (MBStatsUser)result;
1472 }
1473 }
1474 }
1475
1476
1485 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1486 int messageCount) throws SystemException {
1487 return findByG_NotU_NotM(groupId, userId, messageCount,
1488 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1489 }
1490
1491
1506 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1507 int messageCount, int start, int end) throws SystemException {
1508 return findByG_NotU_NotM(groupId, userId, messageCount, start, end, null);
1509 }
1510
1511
1527 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1528 int messageCount, int start, int end,
1529 OrderByComparator orderByComparator) throws SystemException {
1530 FinderPath finderPath = null;
1531 Object[] finderArgs = null;
1532
1533 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM;
1534 finderArgs = new Object[] {
1535 groupId, userId, messageCount,
1536
1537 start, end, orderByComparator
1538 };
1539
1540 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1541 finderArgs, this);
1542
1543 if ((list != null) && !list.isEmpty()) {
1544 for (MBStatsUser mbStatsUser : list) {
1545 if ((groupId != mbStatsUser.getGroupId()) ||
1546 (userId != mbStatsUser.getUserId()) ||
1547 (messageCount != mbStatsUser.getMessageCount())) {
1548 list = null;
1549
1550 break;
1551 }
1552 }
1553 }
1554
1555 if (list == null) {
1556 StringBundler query = null;
1557
1558 if (orderByComparator != null) {
1559 query = new StringBundler(5 +
1560 (orderByComparator.getOrderByFields().length * 3));
1561 }
1562 else {
1563 query = new StringBundler(5);
1564 }
1565
1566 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1567
1568 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1569
1570 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1571
1572 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1573
1574 if (orderByComparator != null) {
1575 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1576 orderByComparator);
1577 }
1578
1579 else {
1580 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1581 }
1582
1583 String sql = query.toString();
1584
1585 Session session = null;
1586
1587 try {
1588 session = openSession();
1589
1590 Query q = session.createQuery(sql);
1591
1592 QueryPos qPos = QueryPos.getInstance(q);
1593
1594 qPos.add(groupId);
1595
1596 qPos.add(userId);
1597
1598 qPos.add(messageCount);
1599
1600 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1601 start, end);
1602 }
1603 catch (Exception e) {
1604 throw processException(e);
1605 }
1606 finally {
1607 if (list == null) {
1608 FinderCacheUtil.removeResult(finderPath, finderArgs);
1609 }
1610 else {
1611 cacheResult(list);
1612
1613 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1614 }
1615
1616 closeSession(session);
1617 }
1618 }
1619
1620 return list;
1621 }
1622
1623
1634 public MBStatsUser findByG_NotU_NotM_First(long groupId, long userId,
1635 int messageCount, OrderByComparator orderByComparator)
1636 throws NoSuchStatsUserException, SystemException {
1637 MBStatsUser mbStatsUser = fetchByG_NotU_NotM_First(groupId, userId,
1638 messageCount, orderByComparator);
1639
1640 if (mbStatsUser != null) {
1641 return mbStatsUser;
1642 }
1643
1644 StringBundler msg = new StringBundler(8);
1645
1646 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1647
1648 msg.append("groupId=");
1649 msg.append(groupId);
1650
1651 msg.append(", userId=");
1652 msg.append(userId);
1653
1654 msg.append(", messageCount=");
1655 msg.append(messageCount);
1656
1657 msg.append(StringPool.CLOSE_CURLY_BRACE);
1658
1659 throw new NoSuchStatsUserException(msg.toString());
1660 }
1661
1662
1672 public MBStatsUser fetchByG_NotU_NotM_First(long groupId, long userId,
1673 int messageCount, OrderByComparator orderByComparator)
1674 throws SystemException {
1675 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1676 messageCount, 0, 1, orderByComparator);
1677
1678 if (!list.isEmpty()) {
1679 return list.get(0);
1680 }
1681
1682 return null;
1683 }
1684
1685
1696 public MBStatsUser findByG_NotU_NotM_Last(long groupId, long userId,
1697 int messageCount, OrderByComparator orderByComparator)
1698 throws NoSuchStatsUserException, SystemException {
1699 MBStatsUser mbStatsUser = fetchByG_NotU_NotM_Last(groupId, userId,
1700 messageCount, orderByComparator);
1701
1702 if (mbStatsUser != null) {
1703 return mbStatsUser;
1704 }
1705
1706 StringBundler msg = new StringBundler(8);
1707
1708 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1709
1710 msg.append("groupId=");
1711 msg.append(groupId);
1712
1713 msg.append(", userId=");
1714 msg.append(userId);
1715
1716 msg.append(", messageCount=");
1717 msg.append(messageCount);
1718
1719 msg.append(StringPool.CLOSE_CURLY_BRACE);
1720
1721 throw new NoSuchStatsUserException(msg.toString());
1722 }
1723
1724
1734 public MBStatsUser fetchByG_NotU_NotM_Last(long groupId, long userId,
1735 int messageCount, OrderByComparator orderByComparator)
1736 throws SystemException {
1737 int count = countByG_NotU_NotM(groupId, userId, messageCount);
1738
1739 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1740 messageCount, count - 1, count, orderByComparator);
1741
1742 if (!list.isEmpty()) {
1743 return list.get(0);
1744 }
1745
1746 return null;
1747 }
1748
1749
1761 public MBStatsUser[] findByG_NotU_NotM_PrevAndNext(long statsUserId,
1762 long groupId, long userId, int messageCount,
1763 OrderByComparator orderByComparator)
1764 throws NoSuchStatsUserException, SystemException {
1765 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1766
1767 Session session = null;
1768
1769 try {
1770 session = openSession();
1771
1772 MBStatsUser[] array = new MBStatsUserImpl[3];
1773
1774 array[0] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1775 groupId, userId, messageCount, orderByComparator, true);
1776
1777 array[1] = mbStatsUser;
1778
1779 array[2] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1780 groupId, userId, messageCount, orderByComparator, false);
1781
1782 return array;
1783 }
1784 catch (Exception e) {
1785 throw processException(e);
1786 }
1787 finally {
1788 closeSession(session);
1789 }
1790 }
1791
1792 protected MBStatsUser getByG_NotU_NotM_PrevAndNext(Session session,
1793 MBStatsUser mbStatsUser, long groupId, long userId, int messageCount,
1794 OrderByComparator orderByComparator, boolean previous) {
1795 StringBundler query = null;
1796
1797 if (orderByComparator != null) {
1798 query = new StringBundler(6 +
1799 (orderByComparator.getOrderByFields().length * 6));
1800 }
1801 else {
1802 query = new StringBundler(3);
1803 }
1804
1805 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1806
1807 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1808
1809 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1810
1811 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1812
1813 if (orderByComparator != null) {
1814 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1815
1816 if (orderByConditionFields.length > 0) {
1817 query.append(WHERE_AND);
1818 }
1819
1820 for (int i = 0; i < orderByConditionFields.length; i++) {
1821 query.append(_ORDER_BY_ENTITY_ALIAS);
1822 query.append(orderByConditionFields[i]);
1823
1824 if ((i + 1) < orderByConditionFields.length) {
1825 if (orderByComparator.isAscending() ^ previous) {
1826 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1827 }
1828 else {
1829 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1830 }
1831 }
1832 else {
1833 if (orderByComparator.isAscending() ^ previous) {
1834 query.append(WHERE_GREATER_THAN);
1835 }
1836 else {
1837 query.append(WHERE_LESSER_THAN);
1838 }
1839 }
1840 }
1841
1842 query.append(ORDER_BY_CLAUSE);
1843
1844 String[] orderByFields = orderByComparator.getOrderByFields();
1845
1846 for (int i = 0; i < orderByFields.length; i++) {
1847 query.append(_ORDER_BY_ENTITY_ALIAS);
1848 query.append(orderByFields[i]);
1849
1850 if ((i + 1) < orderByFields.length) {
1851 if (orderByComparator.isAscending() ^ previous) {
1852 query.append(ORDER_BY_ASC_HAS_NEXT);
1853 }
1854 else {
1855 query.append(ORDER_BY_DESC_HAS_NEXT);
1856 }
1857 }
1858 else {
1859 if (orderByComparator.isAscending() ^ previous) {
1860 query.append(ORDER_BY_ASC);
1861 }
1862 else {
1863 query.append(ORDER_BY_DESC);
1864 }
1865 }
1866 }
1867 }
1868
1869 else {
1870 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1871 }
1872
1873 String sql = query.toString();
1874
1875 Query q = session.createQuery(sql);
1876
1877 q.setFirstResult(0);
1878 q.setMaxResults(2);
1879
1880 QueryPos qPos = QueryPos.getInstance(q);
1881
1882 qPos.add(groupId);
1883
1884 qPos.add(userId);
1885
1886 qPos.add(messageCount);
1887
1888 if (orderByComparator != null) {
1889 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1890
1891 for (Object value : values) {
1892 qPos.add(value);
1893 }
1894 }
1895
1896 List<MBStatsUser> list = q.list();
1897
1898 if (list.size() == 2) {
1899 return list.get(1);
1900 }
1901 else {
1902 return null;
1903 }
1904 }
1905
1906
1912 public List<MBStatsUser> findAll() throws SystemException {
1913 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1914 }
1915
1916
1928 public List<MBStatsUser> findAll(int start, int end)
1929 throws SystemException {
1930 return findAll(start, end, null);
1931 }
1932
1933
1946 public List<MBStatsUser> findAll(int start, int end,
1947 OrderByComparator orderByComparator) throws SystemException {
1948 FinderPath finderPath = null;
1949 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1950
1951 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1952 (orderByComparator == null)) {
1953 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1954 finderArgs = FINDER_ARGS_EMPTY;
1955 }
1956 else {
1957 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1958 finderArgs = new Object[] { start, end, orderByComparator };
1959 }
1960
1961 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1962 finderArgs, this);
1963
1964 if (list == null) {
1965 StringBundler query = null;
1966 String sql = null;
1967
1968 if (orderByComparator != null) {
1969 query = new StringBundler(2 +
1970 (orderByComparator.getOrderByFields().length * 3));
1971
1972 query.append(_SQL_SELECT_MBSTATSUSER);
1973
1974 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1975 orderByComparator);
1976
1977 sql = query.toString();
1978 }
1979 else {
1980 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1981 }
1982
1983 Session session = null;
1984
1985 try {
1986 session = openSession();
1987
1988 Query q = session.createQuery(sql);
1989
1990 if (orderByComparator == null) {
1991 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1992 start, end, false);
1993
1994 Collections.sort(list);
1995 }
1996 else {
1997 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1998 start, end);
1999 }
2000 }
2001 catch (Exception e) {
2002 throw processException(e);
2003 }
2004 finally {
2005 if (list == null) {
2006 FinderCacheUtil.removeResult(finderPath, finderArgs);
2007 }
2008 else {
2009 cacheResult(list);
2010
2011 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2012 }
2013
2014 closeSession(session);
2015 }
2016 }
2017
2018 return list;
2019 }
2020
2021
2027 public void removeByGroupId(long groupId) throws SystemException {
2028 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
2029 remove(mbStatsUser);
2030 }
2031 }
2032
2033
2039 public void removeByUserId(long userId) throws SystemException {
2040 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
2041 remove(mbStatsUser);
2042 }
2043 }
2044
2045
2053 public MBStatsUser removeByG_U(long groupId, long userId)
2054 throws NoSuchStatsUserException, SystemException {
2055 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
2056
2057 return remove(mbStatsUser);
2058 }
2059
2060
2068 public void removeByG_NotU_NotM(long groupId, long userId, int messageCount)
2069 throws SystemException {
2070 for (MBStatsUser mbStatsUser : findByG_NotU_NotM(groupId, userId,
2071 messageCount)) {
2072 remove(mbStatsUser);
2073 }
2074 }
2075
2076
2081 public void removeAll() throws SystemException {
2082 for (MBStatsUser mbStatsUser : findAll()) {
2083 remove(mbStatsUser);
2084 }
2085 }
2086
2087
2094 public int countByGroupId(long groupId) throws SystemException {
2095 Object[] finderArgs = new Object[] { groupId };
2096
2097 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2098 finderArgs, this);
2099
2100 if (count == null) {
2101 StringBundler query = new StringBundler(2);
2102
2103 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2104
2105 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2106
2107 String sql = query.toString();
2108
2109 Session session = null;
2110
2111 try {
2112 session = openSession();
2113
2114 Query q = session.createQuery(sql);
2115
2116 QueryPos qPos = QueryPos.getInstance(q);
2117
2118 qPos.add(groupId);
2119
2120 count = (Long)q.uniqueResult();
2121 }
2122 catch (Exception e) {
2123 throw processException(e);
2124 }
2125 finally {
2126 if (count == null) {
2127 count = Long.valueOf(0);
2128 }
2129
2130 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2131 finderArgs, count);
2132
2133 closeSession(session);
2134 }
2135 }
2136
2137 return count.intValue();
2138 }
2139
2140
2147 public int countByUserId(long userId) throws SystemException {
2148 Object[] finderArgs = new Object[] { userId };
2149
2150 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2151 finderArgs, this);
2152
2153 if (count == null) {
2154 StringBundler query = new StringBundler(2);
2155
2156 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2157
2158 query.append(_FINDER_COLUMN_USERID_USERID_2);
2159
2160 String sql = query.toString();
2161
2162 Session session = null;
2163
2164 try {
2165 session = openSession();
2166
2167 Query q = session.createQuery(sql);
2168
2169 QueryPos qPos = QueryPos.getInstance(q);
2170
2171 qPos.add(userId);
2172
2173 count = (Long)q.uniqueResult();
2174 }
2175 catch (Exception e) {
2176 throw processException(e);
2177 }
2178 finally {
2179 if (count == null) {
2180 count = Long.valueOf(0);
2181 }
2182
2183 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2184 finderArgs, count);
2185
2186 closeSession(session);
2187 }
2188 }
2189
2190 return count.intValue();
2191 }
2192
2193
2201 public int countByG_U(long groupId, long userId) throws SystemException {
2202 Object[] finderArgs = new Object[] { groupId, userId };
2203
2204 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2205 finderArgs, this);
2206
2207 if (count == null) {
2208 StringBundler query = new StringBundler(3);
2209
2210 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2211
2212 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2213
2214 query.append(_FINDER_COLUMN_G_U_USERID_2);
2215
2216 String sql = query.toString();
2217
2218 Session session = null;
2219
2220 try {
2221 session = openSession();
2222
2223 Query q = session.createQuery(sql);
2224
2225 QueryPos qPos = QueryPos.getInstance(q);
2226
2227 qPos.add(groupId);
2228
2229 qPos.add(userId);
2230
2231 count = (Long)q.uniqueResult();
2232 }
2233 catch (Exception e) {
2234 throw processException(e);
2235 }
2236 finally {
2237 if (count == null) {
2238 count = Long.valueOf(0);
2239 }
2240
2241 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2242 count);
2243
2244 closeSession(session);
2245 }
2246 }
2247
2248 return count.intValue();
2249 }
2250
2251
2260 public int countByG_NotU_NotM(long groupId, long userId, int messageCount)
2261 throws SystemException {
2262 Object[] finderArgs = new Object[] { groupId, userId, messageCount };
2263
2264 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM,
2265 finderArgs, this);
2266
2267 if (count == null) {
2268 StringBundler query = new StringBundler(4);
2269
2270 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2271
2272 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
2273
2274 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
2275
2276 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
2277
2278 String sql = query.toString();
2279
2280 Session session = null;
2281
2282 try {
2283 session = openSession();
2284
2285 Query q = session.createQuery(sql);
2286
2287 QueryPos qPos = QueryPos.getInstance(q);
2288
2289 qPos.add(groupId);
2290
2291 qPos.add(userId);
2292
2293 qPos.add(messageCount);
2294
2295 count = (Long)q.uniqueResult();
2296 }
2297 catch (Exception e) {
2298 throw processException(e);
2299 }
2300 finally {
2301 if (count == null) {
2302 count = Long.valueOf(0);
2303 }
2304
2305 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM,
2306 finderArgs, count);
2307
2308 closeSession(session);
2309 }
2310 }
2311
2312 return count.intValue();
2313 }
2314
2315
2321 public int countAll() throws SystemException {
2322 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2323 FINDER_ARGS_EMPTY, this);
2324
2325 if (count == null) {
2326 Session session = null;
2327
2328 try {
2329 session = openSession();
2330
2331 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2332
2333 count = (Long)q.uniqueResult();
2334 }
2335 catch (Exception e) {
2336 throw processException(e);
2337 }
2338 finally {
2339 if (count == null) {
2340 count = Long.valueOf(0);
2341 }
2342
2343 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2344 FINDER_ARGS_EMPTY, count);
2345
2346 closeSession(session);
2347 }
2348 }
2349
2350 return count.intValue();
2351 }
2352
2353
2356 public void afterPropertiesSet() {
2357 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2358 com.liferay.portal.util.PropsUtil.get(
2359 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2360
2361 if (listenerClassNames.length > 0) {
2362 try {
2363 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2364
2365 for (String listenerClassName : listenerClassNames) {
2366 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2367 listenerClassName));
2368 }
2369
2370 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2371 }
2372 catch (Exception e) {
2373 _log.error(e);
2374 }
2375 }
2376 }
2377
2378 public void destroy() {
2379 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2380 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2381 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2382 }
2383
2384 @BeanReference(type = MBBanPersistence.class)
2385 protected MBBanPersistence mbBanPersistence;
2386 @BeanReference(type = MBCategoryPersistence.class)
2387 protected MBCategoryPersistence mbCategoryPersistence;
2388 @BeanReference(type = MBDiscussionPersistence.class)
2389 protected MBDiscussionPersistence mbDiscussionPersistence;
2390 @BeanReference(type = MBMailingListPersistence.class)
2391 protected MBMailingListPersistence mbMailingListPersistence;
2392 @BeanReference(type = MBMessagePersistence.class)
2393 protected MBMessagePersistence mbMessagePersistence;
2394 @BeanReference(type = MBStatsUserPersistence.class)
2395 protected MBStatsUserPersistence mbStatsUserPersistence;
2396 @BeanReference(type = MBThreadPersistence.class)
2397 protected MBThreadPersistence mbThreadPersistence;
2398 @BeanReference(type = MBThreadFlagPersistence.class)
2399 protected MBThreadFlagPersistence mbThreadFlagPersistence;
2400 @BeanReference(type = GroupPersistence.class)
2401 protected GroupPersistence groupPersistence;
2402 @BeanReference(type = ResourcePersistence.class)
2403 protected ResourcePersistence resourcePersistence;
2404 @BeanReference(type = UserPersistence.class)
2405 protected UserPersistence userPersistence;
2406 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2407 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2408 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2409 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2410 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2411 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2412 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2413 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2414 private static final String _FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2415 private static final String _FINDER_COLUMN_G_NOTU_NOTM_USERID_2 = "mbStatsUser.userId != ? AND ";
2416 private static final String _FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2417 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2418 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2419 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2420 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2421 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2422 private static MBStatsUser _nullMBStatsUser = new MBStatsUserImpl() {
2423 @Override
2424 public Object clone() {
2425 return this;
2426 }
2427
2428 @Override
2429 public CacheModel<MBStatsUser> toCacheModel() {
2430 return _nullMBStatsUserCacheModel;
2431 }
2432 };
2433
2434 private static CacheModel<MBStatsUser> _nullMBStatsUserCacheModel = new CacheModel<MBStatsUser>() {
2435 public MBStatsUser toEntityModel() {
2436 return _nullMBStatsUser;
2437 }
2438 };
2439 }