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.GroupPersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.messageboards.NoSuchStatsUserException;
043 import com.liferay.portlet.messageboards.model.MBStatsUser;
044 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
045 import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
065 public class MBStatsUserPersistenceImpl extends BasePersistenceImpl<MBStatsUser>
066 implements MBStatsUserPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = MBStatsUserImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
078 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
080 new String[] {
081 Long.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
087 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
088 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
090 new String[] { Long.class.getName() },
091 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK);
092 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
093 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
095 new String[] { Long.class.getName() });
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
097 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
099 new String[] {
100 Long.class.getName(),
101
102 "java.lang.Integer", "java.lang.Integer",
103 "com.liferay.portal.kernel.util.OrderByComparator"
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
106 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
107 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
109 new String[] { Long.class.getName() },
110 MBStatsUserModelImpl.USERID_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
112 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
114 new String[] { Long.class.getName() });
115 public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
116 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
117 FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
118 new String[] { Long.class.getName(), Long.class.getName() },
119 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
120 MBStatsUserModelImpl.USERID_COLUMN_BITMASK);
121 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
122 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
123 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
124 new String[] { Long.class.getName(), Long.class.getName() });
125 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM =
126 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
127 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
128 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_NotU_NotM",
129 new String[] {
130 Long.class.getName(), Long.class.getName(),
131 Integer.class.getName(),
132
133 "java.lang.Integer", "java.lang.Integer",
134 "com.liferay.portal.kernel.util.OrderByComparator"
135 });
136 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM =
137 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
138 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
139 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_NotU_NotM",
140 new String[] {
141 Long.class.getName(), Long.class.getName(),
142 Integer.class.getName()
143 });
144 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
145 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
146 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
147 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
148 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
149 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
150 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
151 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
152 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
153
154
159 public void cacheResult(MBStatsUser mbStatsUser) {
160 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
161 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
162
163 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
164 new Object[] {
165 Long.valueOf(mbStatsUser.getGroupId()),
166 Long.valueOf(mbStatsUser.getUserId())
167 }, mbStatsUser);
168
169 mbStatsUser.resetOriginalValues();
170 }
171
172
177 public void cacheResult(List<MBStatsUser> mbStatsUsers) {
178 for (MBStatsUser mbStatsUser : mbStatsUsers) {
179 if (EntityCacheUtil.getResult(
180 MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
181 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey()) == null) {
182 cacheResult(mbStatsUser);
183 }
184 else {
185 mbStatsUser.resetOriginalValues();
186 }
187 }
188 }
189
190
197 @Override
198 public void clearCache() {
199 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
200 CacheRegistryUtil.clear(MBStatsUserImpl.class.getName());
201 }
202
203 EntityCacheUtil.clearCache(MBStatsUserImpl.class.getName());
204
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
208 }
209
210
217 @Override
218 public void clearCache(MBStatsUser mbStatsUser) {
219 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
220 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
221
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
223 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
224
225 clearUniqueFindersCache(mbStatsUser);
226 }
227
228 @Override
229 public void clearCache(List<MBStatsUser> mbStatsUsers) {
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
231 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
232
233 for (MBStatsUser mbStatsUser : mbStatsUsers) {
234 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
235 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
236
237 clearUniqueFindersCache(mbStatsUser);
238 }
239 }
240
241 protected void clearUniqueFindersCache(MBStatsUser mbStatsUser) {
242 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
243 new Object[] {
244 Long.valueOf(mbStatsUser.getGroupId()),
245 Long.valueOf(mbStatsUser.getUserId())
246 });
247 }
248
249
255 public MBStatsUser create(long statsUserId) {
256 MBStatsUser mbStatsUser = new MBStatsUserImpl();
257
258 mbStatsUser.setNew(true);
259 mbStatsUser.setPrimaryKey(statsUserId);
260
261 return mbStatsUser;
262 }
263
264
272 public MBStatsUser remove(long statsUserId)
273 throws NoSuchStatsUserException, SystemException {
274 return remove(Long.valueOf(statsUserId));
275 }
276
277
285 @Override
286 public MBStatsUser remove(Serializable primaryKey)
287 throws NoSuchStatsUserException, SystemException {
288 Session session = null;
289
290 try {
291 session = openSession();
292
293 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
294 primaryKey);
295
296 if (mbStatsUser == null) {
297 if (_log.isWarnEnabled()) {
298 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
299 }
300
301 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
302 primaryKey);
303 }
304
305 return remove(mbStatsUser);
306 }
307 catch (NoSuchStatsUserException nsee) {
308 throw nsee;
309 }
310 catch (Exception e) {
311 throw processException(e);
312 }
313 finally {
314 closeSession(session);
315 }
316 }
317
318 @Override
319 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
320 throws SystemException {
321 mbStatsUser = toUnwrappedModel(mbStatsUser);
322
323 Session session = null;
324
325 try {
326 session = openSession();
327
328 if (mbStatsUser.isCachedModel()) {
329 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
330 mbStatsUser.getPrimaryKeyObj());
331 }
332
333 session.delete(mbStatsUser);
334 }
335 catch (Exception e) {
336 throw processException(e);
337 }
338 finally {
339 closeSession(session);
340 }
341
342 clearCache(mbStatsUser);
343
344 return mbStatsUser;
345 }
346
347 @Override
348 public MBStatsUser updateImpl(
349 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser)
350 throws SystemException {
351 mbStatsUser = toUnwrappedModel(mbStatsUser);
352
353 boolean isNew = mbStatsUser.isNew();
354
355 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
356
357 Session session = null;
358
359 try {
360 session = openSession();
361
362 if (mbStatsUser.isNew()) {
363 session.save(mbStatsUser);
364
365 mbStatsUser.setNew(false);
366 }
367 else {
368 session.merge(mbStatsUser);
369 }
370 }
371 catch (Exception e) {
372 throw processException(e);
373 }
374 finally {
375 closeSession(session);
376 }
377
378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
379
380 if (isNew || !MBStatsUserModelImpl.COLUMN_BITMASK_ENABLED) {
381 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
382 }
383
384 else {
385 if ((mbStatsUserModelImpl.getColumnBitmask() &
386 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
387 Object[] args = new Object[] {
388 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId())
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 args = new Object[] {
396 Long.valueOf(mbStatsUserModelImpl.getGroupId())
397 };
398
399 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
400 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
401 args);
402 }
403
404 if ((mbStatsUserModelImpl.getColumnBitmask() &
405 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
406 Object[] args = new Object[] {
407 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
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 args = new Object[] {
415 Long.valueOf(mbStatsUserModelImpl.getUserId())
416 };
417
418 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
419 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
420 args);
421 }
422 }
423
424 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
425 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
426
427 if (isNew) {
428 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
429 new Object[] {
430 Long.valueOf(mbStatsUser.getGroupId()),
431 Long.valueOf(mbStatsUser.getUserId())
432 }, mbStatsUser);
433 }
434 else {
435 if ((mbStatsUserModelImpl.getColumnBitmask() &
436 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
437 Object[] args = new Object[] {
438 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
439 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
440 };
441
442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
443
444 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
445
446 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
447 new Object[] {
448 Long.valueOf(mbStatsUser.getGroupId()),
449 Long.valueOf(mbStatsUser.getUserId())
450 }, mbStatsUser);
451 }
452 }
453
454 return mbStatsUser;
455 }
456
457 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
458 if (mbStatsUser instanceof MBStatsUserImpl) {
459 return mbStatsUser;
460 }
461
462 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
463
464 mbStatsUserImpl.setNew(mbStatsUser.isNew());
465 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
466
467 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
468 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
469 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
470 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
471 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
472
473 return mbStatsUserImpl;
474 }
475
476
484 @Override
485 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
486 throws NoSuchModelException, SystemException {
487 return findByPrimaryKey(((Long)primaryKey).longValue());
488 }
489
490
498 public MBStatsUser findByPrimaryKey(long statsUserId)
499 throws NoSuchStatsUserException, SystemException {
500 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
501
502 if (mbStatsUser == null) {
503 if (_log.isWarnEnabled()) {
504 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
505 }
506
507 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
508 statsUserId);
509 }
510
511 return mbStatsUser;
512 }
513
514
521 @Override
522 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
523 throws SystemException {
524 return fetchByPrimaryKey(((Long)primaryKey).longValue());
525 }
526
527
534 public MBStatsUser fetchByPrimaryKey(long statsUserId)
535 throws SystemException {
536 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
537 MBStatsUserImpl.class, statsUserId);
538
539 if (mbStatsUser == _nullMBStatsUser) {
540 return null;
541 }
542
543 if (mbStatsUser == null) {
544 Session session = null;
545
546 boolean hasException = false;
547
548 try {
549 session = openSession();
550
551 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
552 Long.valueOf(statsUserId));
553 }
554 catch (Exception e) {
555 hasException = true;
556
557 throw processException(e);
558 }
559 finally {
560 if (mbStatsUser != null) {
561 cacheResult(mbStatsUser);
562 }
563 else if (!hasException) {
564 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
565 MBStatsUserImpl.class, statsUserId, _nullMBStatsUser);
566 }
567
568 closeSession(session);
569 }
570 }
571
572 return mbStatsUser;
573 }
574
575
582 public List<MBStatsUser> findByGroupId(long groupId)
583 throws SystemException {
584 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
585 }
586
587
600 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
601 throws SystemException {
602 return findByGroupId(groupId, start, end, null);
603 }
604
605
619 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
620 OrderByComparator orderByComparator) throws SystemException {
621 FinderPath finderPath = null;
622 Object[] finderArgs = null;
623
624 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
625 (orderByComparator == null)) {
626 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
627 finderArgs = new Object[] { groupId };
628 }
629 else {
630 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
631 finderArgs = new Object[] { groupId, start, end, orderByComparator };
632 }
633
634 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
635 finderArgs, this);
636
637 if ((list != null) && !list.isEmpty()) {
638 for (MBStatsUser mbStatsUser : list) {
639 if ((groupId != mbStatsUser.getGroupId())) {
640 list = null;
641
642 break;
643 }
644 }
645 }
646
647 if (list == null) {
648 StringBundler query = null;
649
650 if (orderByComparator != null) {
651 query = new StringBundler(3 +
652 (orderByComparator.getOrderByFields().length * 3));
653 }
654 else {
655 query = new StringBundler(3);
656 }
657
658 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
659
660 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
661
662 if (orderByComparator != null) {
663 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
664 orderByComparator);
665 }
666
667 else {
668 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
669 }
670
671 String sql = query.toString();
672
673 Session session = null;
674
675 try {
676 session = openSession();
677
678 Query q = session.createQuery(sql);
679
680 QueryPos qPos = QueryPos.getInstance(q);
681
682 qPos.add(groupId);
683
684 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
685 start, end);
686 }
687 catch (Exception e) {
688 throw processException(e);
689 }
690 finally {
691 if (list == null) {
692 FinderCacheUtil.removeResult(finderPath, finderArgs);
693 }
694 else {
695 cacheResult(list);
696
697 FinderCacheUtil.putResult(finderPath, finderArgs, list);
698 }
699
700 closeSession(session);
701 }
702 }
703
704 return list;
705 }
706
707
716 public MBStatsUser findByGroupId_First(long groupId,
717 OrderByComparator orderByComparator)
718 throws NoSuchStatsUserException, SystemException {
719 MBStatsUser mbStatsUser = fetchByGroupId_First(groupId,
720 orderByComparator);
721
722 if (mbStatsUser != null) {
723 return mbStatsUser;
724 }
725
726 StringBundler msg = new StringBundler(4);
727
728 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
729
730 msg.append("groupId=");
731 msg.append(groupId);
732
733 msg.append(StringPool.CLOSE_CURLY_BRACE);
734
735 throw new NoSuchStatsUserException(msg.toString());
736 }
737
738
746 public MBStatsUser fetchByGroupId_First(long groupId,
747 OrderByComparator orderByComparator) throws SystemException {
748 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
749
750 if (!list.isEmpty()) {
751 return list.get(0);
752 }
753
754 return null;
755 }
756
757
766 public MBStatsUser findByGroupId_Last(long groupId,
767 OrderByComparator orderByComparator)
768 throws NoSuchStatsUserException, SystemException {
769 MBStatsUser mbStatsUser = fetchByGroupId_Last(groupId, orderByComparator);
770
771 if (mbStatsUser != null) {
772 return mbStatsUser;
773 }
774
775 StringBundler msg = new StringBundler(4);
776
777 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
778
779 msg.append("groupId=");
780 msg.append(groupId);
781
782 msg.append(StringPool.CLOSE_CURLY_BRACE);
783
784 throw new NoSuchStatsUserException(msg.toString());
785 }
786
787
795 public MBStatsUser fetchByGroupId_Last(long groupId,
796 OrderByComparator orderByComparator) throws SystemException {
797 int count = countByGroupId(groupId);
798
799 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
800 orderByComparator);
801
802 if (!list.isEmpty()) {
803 return list.get(0);
804 }
805
806 return null;
807 }
808
809
819 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
820 long groupId, OrderByComparator orderByComparator)
821 throws NoSuchStatsUserException, SystemException {
822 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
823
824 Session session = null;
825
826 try {
827 session = openSession();
828
829 MBStatsUser[] array = new MBStatsUserImpl[3];
830
831 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
832 orderByComparator, true);
833
834 array[1] = mbStatsUser;
835
836 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
837 orderByComparator, false);
838
839 return array;
840 }
841 catch (Exception e) {
842 throw processException(e);
843 }
844 finally {
845 closeSession(session);
846 }
847 }
848
849 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
850 MBStatsUser mbStatsUser, long groupId,
851 OrderByComparator orderByComparator, boolean previous) {
852 StringBundler query = null;
853
854 if (orderByComparator != null) {
855 query = new StringBundler(6 +
856 (orderByComparator.getOrderByFields().length * 6));
857 }
858 else {
859 query = new StringBundler(3);
860 }
861
862 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
863
864 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
865
866 if (orderByComparator != null) {
867 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
868
869 if (orderByConditionFields.length > 0) {
870 query.append(WHERE_AND);
871 }
872
873 for (int i = 0; i < orderByConditionFields.length; i++) {
874 query.append(_ORDER_BY_ENTITY_ALIAS);
875 query.append(orderByConditionFields[i]);
876
877 if ((i + 1) < orderByConditionFields.length) {
878 if (orderByComparator.isAscending() ^ previous) {
879 query.append(WHERE_GREATER_THAN_HAS_NEXT);
880 }
881 else {
882 query.append(WHERE_LESSER_THAN_HAS_NEXT);
883 }
884 }
885 else {
886 if (orderByComparator.isAscending() ^ previous) {
887 query.append(WHERE_GREATER_THAN);
888 }
889 else {
890 query.append(WHERE_LESSER_THAN);
891 }
892 }
893 }
894
895 query.append(ORDER_BY_CLAUSE);
896
897 String[] orderByFields = orderByComparator.getOrderByFields();
898
899 for (int i = 0; i < orderByFields.length; i++) {
900 query.append(_ORDER_BY_ENTITY_ALIAS);
901 query.append(orderByFields[i]);
902
903 if ((i + 1) < orderByFields.length) {
904 if (orderByComparator.isAscending() ^ previous) {
905 query.append(ORDER_BY_ASC_HAS_NEXT);
906 }
907 else {
908 query.append(ORDER_BY_DESC_HAS_NEXT);
909 }
910 }
911 else {
912 if (orderByComparator.isAscending() ^ previous) {
913 query.append(ORDER_BY_ASC);
914 }
915 else {
916 query.append(ORDER_BY_DESC);
917 }
918 }
919 }
920 }
921
922 else {
923 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
924 }
925
926 String sql = query.toString();
927
928 Query q = session.createQuery(sql);
929
930 q.setFirstResult(0);
931 q.setMaxResults(2);
932
933 QueryPos qPos = QueryPos.getInstance(q);
934
935 qPos.add(groupId);
936
937 if (orderByComparator != null) {
938 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
939
940 for (Object value : values) {
941 qPos.add(value);
942 }
943 }
944
945 List<MBStatsUser> list = q.list();
946
947 if (list.size() == 2) {
948 return list.get(1);
949 }
950 else {
951 return null;
952 }
953 }
954
955
962 public List<MBStatsUser> findByUserId(long userId)
963 throws SystemException {
964 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
965 }
966
967
980 public List<MBStatsUser> findByUserId(long userId, int start, int end)
981 throws SystemException {
982 return findByUserId(userId, start, end, null);
983 }
984
985
999 public List<MBStatsUser> findByUserId(long userId, int start, int end,
1000 OrderByComparator orderByComparator) throws SystemException {
1001 FinderPath finderPath = null;
1002 Object[] finderArgs = null;
1003
1004 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1005 (orderByComparator == null)) {
1006 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1007 finderArgs = new Object[] { userId };
1008 }
1009 else {
1010 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1011 finderArgs = new Object[] { userId, start, end, orderByComparator };
1012 }
1013
1014 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1015 finderArgs, this);
1016
1017 if ((list != null) && !list.isEmpty()) {
1018 for (MBStatsUser mbStatsUser : list) {
1019 if ((userId != mbStatsUser.getUserId())) {
1020 list = null;
1021
1022 break;
1023 }
1024 }
1025 }
1026
1027 if (list == null) {
1028 StringBundler query = null;
1029
1030 if (orderByComparator != null) {
1031 query = new StringBundler(3 +
1032 (orderByComparator.getOrderByFields().length * 3));
1033 }
1034 else {
1035 query = new StringBundler(3);
1036 }
1037
1038 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1039
1040 query.append(_FINDER_COLUMN_USERID_USERID_2);
1041
1042 if (orderByComparator != null) {
1043 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1044 orderByComparator);
1045 }
1046
1047 else {
1048 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1049 }
1050
1051 String sql = query.toString();
1052
1053 Session session = null;
1054
1055 try {
1056 session = openSession();
1057
1058 Query q = session.createQuery(sql);
1059
1060 QueryPos qPos = QueryPos.getInstance(q);
1061
1062 qPos.add(userId);
1063
1064 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1065 start, end);
1066 }
1067 catch (Exception e) {
1068 throw processException(e);
1069 }
1070 finally {
1071 if (list == null) {
1072 FinderCacheUtil.removeResult(finderPath, finderArgs);
1073 }
1074 else {
1075 cacheResult(list);
1076
1077 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1078 }
1079
1080 closeSession(session);
1081 }
1082 }
1083
1084 return list;
1085 }
1086
1087
1096 public MBStatsUser findByUserId_First(long userId,
1097 OrderByComparator orderByComparator)
1098 throws NoSuchStatsUserException, SystemException {
1099 MBStatsUser mbStatsUser = fetchByUserId_First(userId, orderByComparator);
1100
1101 if (mbStatsUser != null) {
1102 return mbStatsUser;
1103 }
1104
1105 StringBundler msg = new StringBundler(4);
1106
1107 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1108
1109 msg.append("userId=");
1110 msg.append(userId);
1111
1112 msg.append(StringPool.CLOSE_CURLY_BRACE);
1113
1114 throw new NoSuchStatsUserException(msg.toString());
1115 }
1116
1117
1125 public MBStatsUser fetchByUserId_First(long userId,
1126 OrderByComparator orderByComparator) throws SystemException {
1127 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
1128
1129 if (!list.isEmpty()) {
1130 return list.get(0);
1131 }
1132
1133 return null;
1134 }
1135
1136
1145 public MBStatsUser findByUserId_Last(long userId,
1146 OrderByComparator orderByComparator)
1147 throws NoSuchStatsUserException, SystemException {
1148 MBStatsUser mbStatsUser = fetchByUserId_Last(userId, orderByComparator);
1149
1150 if (mbStatsUser != null) {
1151 return mbStatsUser;
1152 }
1153
1154 StringBundler msg = new StringBundler(4);
1155
1156 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1157
1158 msg.append("userId=");
1159 msg.append(userId);
1160
1161 msg.append(StringPool.CLOSE_CURLY_BRACE);
1162
1163 throw new NoSuchStatsUserException(msg.toString());
1164 }
1165
1166
1174 public MBStatsUser fetchByUserId_Last(long userId,
1175 OrderByComparator orderByComparator) throws SystemException {
1176 int count = countByUserId(userId);
1177
1178 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
1179 orderByComparator);
1180
1181 if (!list.isEmpty()) {
1182 return list.get(0);
1183 }
1184
1185 return null;
1186 }
1187
1188
1198 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
1199 long userId, OrderByComparator orderByComparator)
1200 throws NoSuchStatsUserException, SystemException {
1201 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1202
1203 Session session = null;
1204
1205 try {
1206 session = openSession();
1207
1208 MBStatsUser[] array = new MBStatsUserImpl[3];
1209
1210 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1211 orderByComparator, true);
1212
1213 array[1] = mbStatsUser;
1214
1215 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1216 orderByComparator, false);
1217
1218 return array;
1219 }
1220 catch (Exception e) {
1221 throw processException(e);
1222 }
1223 finally {
1224 closeSession(session);
1225 }
1226 }
1227
1228 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1229 MBStatsUser mbStatsUser, long userId,
1230 OrderByComparator orderByComparator, boolean previous) {
1231 StringBundler query = null;
1232
1233 if (orderByComparator != null) {
1234 query = new StringBundler(6 +
1235 (orderByComparator.getOrderByFields().length * 6));
1236 }
1237 else {
1238 query = new StringBundler(3);
1239 }
1240
1241 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1242
1243 query.append(_FINDER_COLUMN_USERID_USERID_2);
1244
1245 if (orderByComparator != null) {
1246 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1247
1248 if (orderByConditionFields.length > 0) {
1249 query.append(WHERE_AND);
1250 }
1251
1252 for (int i = 0; i < orderByConditionFields.length; i++) {
1253 query.append(_ORDER_BY_ENTITY_ALIAS);
1254 query.append(orderByConditionFields[i]);
1255
1256 if ((i + 1) < orderByConditionFields.length) {
1257 if (orderByComparator.isAscending() ^ previous) {
1258 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1259 }
1260 else {
1261 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1262 }
1263 }
1264 else {
1265 if (orderByComparator.isAscending() ^ previous) {
1266 query.append(WHERE_GREATER_THAN);
1267 }
1268 else {
1269 query.append(WHERE_LESSER_THAN);
1270 }
1271 }
1272 }
1273
1274 query.append(ORDER_BY_CLAUSE);
1275
1276 String[] orderByFields = orderByComparator.getOrderByFields();
1277
1278 for (int i = 0; i < orderByFields.length; i++) {
1279 query.append(_ORDER_BY_ENTITY_ALIAS);
1280 query.append(orderByFields[i]);
1281
1282 if ((i + 1) < orderByFields.length) {
1283 if (orderByComparator.isAscending() ^ previous) {
1284 query.append(ORDER_BY_ASC_HAS_NEXT);
1285 }
1286 else {
1287 query.append(ORDER_BY_DESC_HAS_NEXT);
1288 }
1289 }
1290 else {
1291 if (orderByComparator.isAscending() ^ previous) {
1292 query.append(ORDER_BY_ASC);
1293 }
1294 else {
1295 query.append(ORDER_BY_DESC);
1296 }
1297 }
1298 }
1299 }
1300
1301 else {
1302 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1303 }
1304
1305 String sql = query.toString();
1306
1307 Query q = session.createQuery(sql);
1308
1309 q.setFirstResult(0);
1310 q.setMaxResults(2);
1311
1312 QueryPos qPos = QueryPos.getInstance(q);
1313
1314 qPos.add(userId);
1315
1316 if (orderByComparator != null) {
1317 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1318
1319 for (Object value : values) {
1320 qPos.add(value);
1321 }
1322 }
1323
1324 List<MBStatsUser> list = q.list();
1325
1326 if (list.size() == 2) {
1327 return list.get(1);
1328 }
1329 else {
1330 return null;
1331 }
1332 }
1333
1334
1343 public MBStatsUser findByG_U(long groupId, long userId)
1344 throws NoSuchStatsUserException, SystemException {
1345 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1346
1347 if (mbStatsUser == null) {
1348 StringBundler msg = new StringBundler(6);
1349
1350 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1351
1352 msg.append("groupId=");
1353 msg.append(groupId);
1354
1355 msg.append(", userId=");
1356 msg.append(userId);
1357
1358 msg.append(StringPool.CLOSE_CURLY_BRACE);
1359
1360 if (_log.isWarnEnabled()) {
1361 _log.warn(msg.toString());
1362 }
1363
1364 throw new NoSuchStatsUserException(msg.toString());
1365 }
1366
1367 return mbStatsUser;
1368 }
1369
1370
1378 public MBStatsUser fetchByG_U(long groupId, long userId)
1379 throws SystemException {
1380 return fetchByG_U(groupId, userId, true);
1381 }
1382
1383
1392 public MBStatsUser fetchByG_U(long groupId, long userId,
1393 boolean retrieveFromCache) throws SystemException {
1394 Object[] finderArgs = new Object[] { groupId, userId };
1395
1396 Object result = null;
1397
1398 if (retrieveFromCache) {
1399 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1400 finderArgs, this);
1401 }
1402
1403 if (result instanceof MBStatsUser) {
1404 MBStatsUser mbStatsUser = (MBStatsUser)result;
1405
1406 if ((groupId != mbStatsUser.getGroupId()) ||
1407 (userId != mbStatsUser.getUserId())) {
1408 result = null;
1409 }
1410 }
1411
1412 if (result == null) {
1413 StringBundler query = new StringBundler(4);
1414
1415 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1416
1417 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1418
1419 query.append(_FINDER_COLUMN_G_U_USERID_2);
1420
1421 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1422
1423 String sql = query.toString();
1424
1425 Session session = null;
1426
1427 try {
1428 session = openSession();
1429
1430 Query q = session.createQuery(sql);
1431
1432 QueryPos qPos = QueryPos.getInstance(q);
1433
1434 qPos.add(groupId);
1435
1436 qPos.add(userId);
1437
1438 List<MBStatsUser> list = q.list();
1439
1440 result = list;
1441
1442 MBStatsUser mbStatsUser = null;
1443
1444 if (list.isEmpty()) {
1445 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1446 finderArgs, list);
1447 }
1448 else {
1449 mbStatsUser = list.get(0);
1450
1451 cacheResult(mbStatsUser);
1452
1453 if ((mbStatsUser.getGroupId() != groupId) ||
1454 (mbStatsUser.getUserId() != userId)) {
1455 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1456 finderArgs, mbStatsUser);
1457 }
1458 }
1459
1460 return mbStatsUser;
1461 }
1462 catch (Exception e) {
1463 throw processException(e);
1464 }
1465 finally {
1466 if (result == null) {
1467 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1468 finderArgs);
1469 }
1470
1471 closeSession(session);
1472 }
1473 }
1474 else {
1475 if (result instanceof List<?>) {
1476 return null;
1477 }
1478 else {
1479 return (MBStatsUser)result;
1480 }
1481 }
1482 }
1483
1484
1493 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1494 int messageCount) throws SystemException {
1495 return findByG_NotU_NotM(groupId, userId, messageCount,
1496 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1497 }
1498
1499
1514 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1515 int messageCount, int start, int end) throws SystemException {
1516 return findByG_NotU_NotM(groupId, userId, messageCount, start, end, null);
1517 }
1518
1519
1535 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1536 int messageCount, int start, int end,
1537 OrderByComparator orderByComparator) throws SystemException {
1538 FinderPath finderPath = null;
1539 Object[] finderArgs = null;
1540
1541 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM;
1542 finderArgs = new Object[] {
1543 groupId, userId, messageCount,
1544
1545 start, end, orderByComparator
1546 };
1547
1548 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1549 finderArgs, this);
1550
1551 if ((list != null) && !list.isEmpty()) {
1552 for (MBStatsUser mbStatsUser : list) {
1553 if ((groupId != mbStatsUser.getGroupId()) ||
1554 (userId != mbStatsUser.getUserId()) ||
1555 (messageCount != mbStatsUser.getMessageCount())) {
1556 list = null;
1557
1558 break;
1559 }
1560 }
1561 }
1562
1563 if (list == null) {
1564 StringBundler query = null;
1565
1566 if (orderByComparator != null) {
1567 query = new StringBundler(5 +
1568 (orderByComparator.getOrderByFields().length * 3));
1569 }
1570 else {
1571 query = new StringBundler(5);
1572 }
1573
1574 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1575
1576 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1577
1578 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1579
1580 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1581
1582 if (orderByComparator != null) {
1583 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1584 orderByComparator);
1585 }
1586
1587 else {
1588 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1589 }
1590
1591 String sql = query.toString();
1592
1593 Session session = null;
1594
1595 try {
1596 session = openSession();
1597
1598 Query q = session.createQuery(sql);
1599
1600 QueryPos qPos = QueryPos.getInstance(q);
1601
1602 qPos.add(groupId);
1603
1604 qPos.add(userId);
1605
1606 qPos.add(messageCount);
1607
1608 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1609 start, end);
1610 }
1611 catch (Exception e) {
1612 throw processException(e);
1613 }
1614 finally {
1615 if (list == null) {
1616 FinderCacheUtil.removeResult(finderPath, finderArgs);
1617 }
1618 else {
1619 cacheResult(list);
1620
1621 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1622 }
1623
1624 closeSession(session);
1625 }
1626 }
1627
1628 return list;
1629 }
1630
1631
1642 public MBStatsUser findByG_NotU_NotM_First(long groupId, long userId,
1643 int messageCount, OrderByComparator orderByComparator)
1644 throws NoSuchStatsUserException, SystemException {
1645 MBStatsUser mbStatsUser = fetchByG_NotU_NotM_First(groupId, userId,
1646 messageCount, orderByComparator);
1647
1648 if (mbStatsUser != null) {
1649 return mbStatsUser;
1650 }
1651
1652 StringBundler msg = new StringBundler(8);
1653
1654 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1655
1656 msg.append("groupId=");
1657 msg.append(groupId);
1658
1659 msg.append(", userId=");
1660 msg.append(userId);
1661
1662 msg.append(", messageCount=");
1663 msg.append(messageCount);
1664
1665 msg.append(StringPool.CLOSE_CURLY_BRACE);
1666
1667 throw new NoSuchStatsUserException(msg.toString());
1668 }
1669
1670
1680 public MBStatsUser fetchByG_NotU_NotM_First(long groupId, long userId,
1681 int messageCount, OrderByComparator orderByComparator)
1682 throws SystemException {
1683 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1684 messageCount, 0, 1, orderByComparator);
1685
1686 if (!list.isEmpty()) {
1687 return list.get(0);
1688 }
1689
1690 return null;
1691 }
1692
1693
1704 public MBStatsUser findByG_NotU_NotM_Last(long groupId, long userId,
1705 int messageCount, OrderByComparator orderByComparator)
1706 throws NoSuchStatsUserException, SystemException {
1707 MBStatsUser mbStatsUser = fetchByG_NotU_NotM_Last(groupId, userId,
1708 messageCount, orderByComparator);
1709
1710 if (mbStatsUser != null) {
1711 return mbStatsUser;
1712 }
1713
1714 StringBundler msg = new StringBundler(8);
1715
1716 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1717
1718 msg.append("groupId=");
1719 msg.append(groupId);
1720
1721 msg.append(", userId=");
1722 msg.append(userId);
1723
1724 msg.append(", messageCount=");
1725 msg.append(messageCount);
1726
1727 msg.append(StringPool.CLOSE_CURLY_BRACE);
1728
1729 throw new NoSuchStatsUserException(msg.toString());
1730 }
1731
1732
1742 public MBStatsUser fetchByG_NotU_NotM_Last(long groupId, long userId,
1743 int messageCount, OrderByComparator orderByComparator)
1744 throws SystemException {
1745 int count = countByG_NotU_NotM(groupId, userId, messageCount);
1746
1747 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1748 messageCount, count - 1, count, orderByComparator);
1749
1750 if (!list.isEmpty()) {
1751 return list.get(0);
1752 }
1753
1754 return null;
1755 }
1756
1757
1769 public MBStatsUser[] findByG_NotU_NotM_PrevAndNext(long statsUserId,
1770 long groupId, long userId, int messageCount,
1771 OrderByComparator orderByComparator)
1772 throws NoSuchStatsUserException, SystemException {
1773 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1774
1775 Session session = null;
1776
1777 try {
1778 session = openSession();
1779
1780 MBStatsUser[] array = new MBStatsUserImpl[3];
1781
1782 array[0] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1783 groupId, userId, messageCount, orderByComparator, true);
1784
1785 array[1] = mbStatsUser;
1786
1787 array[2] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1788 groupId, userId, messageCount, orderByComparator, false);
1789
1790 return array;
1791 }
1792 catch (Exception e) {
1793 throw processException(e);
1794 }
1795 finally {
1796 closeSession(session);
1797 }
1798 }
1799
1800 protected MBStatsUser getByG_NotU_NotM_PrevAndNext(Session session,
1801 MBStatsUser mbStatsUser, long groupId, long userId, int messageCount,
1802 OrderByComparator orderByComparator, boolean previous) {
1803 StringBundler query = null;
1804
1805 if (orderByComparator != null) {
1806 query = new StringBundler(6 +
1807 (orderByComparator.getOrderByFields().length * 6));
1808 }
1809 else {
1810 query = new StringBundler(3);
1811 }
1812
1813 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1814
1815 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1816
1817 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1818
1819 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1820
1821 if (orderByComparator != null) {
1822 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1823
1824 if (orderByConditionFields.length > 0) {
1825 query.append(WHERE_AND);
1826 }
1827
1828 for (int i = 0; i < orderByConditionFields.length; i++) {
1829 query.append(_ORDER_BY_ENTITY_ALIAS);
1830 query.append(orderByConditionFields[i]);
1831
1832 if ((i + 1) < orderByConditionFields.length) {
1833 if (orderByComparator.isAscending() ^ previous) {
1834 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1835 }
1836 else {
1837 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1838 }
1839 }
1840 else {
1841 if (orderByComparator.isAscending() ^ previous) {
1842 query.append(WHERE_GREATER_THAN);
1843 }
1844 else {
1845 query.append(WHERE_LESSER_THAN);
1846 }
1847 }
1848 }
1849
1850 query.append(ORDER_BY_CLAUSE);
1851
1852 String[] orderByFields = orderByComparator.getOrderByFields();
1853
1854 for (int i = 0; i < orderByFields.length; i++) {
1855 query.append(_ORDER_BY_ENTITY_ALIAS);
1856 query.append(orderByFields[i]);
1857
1858 if ((i + 1) < orderByFields.length) {
1859 if (orderByComparator.isAscending() ^ previous) {
1860 query.append(ORDER_BY_ASC_HAS_NEXT);
1861 }
1862 else {
1863 query.append(ORDER_BY_DESC_HAS_NEXT);
1864 }
1865 }
1866 else {
1867 if (orderByComparator.isAscending() ^ previous) {
1868 query.append(ORDER_BY_ASC);
1869 }
1870 else {
1871 query.append(ORDER_BY_DESC);
1872 }
1873 }
1874 }
1875 }
1876
1877 else {
1878 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1879 }
1880
1881 String sql = query.toString();
1882
1883 Query q = session.createQuery(sql);
1884
1885 q.setFirstResult(0);
1886 q.setMaxResults(2);
1887
1888 QueryPos qPos = QueryPos.getInstance(q);
1889
1890 qPos.add(groupId);
1891
1892 qPos.add(userId);
1893
1894 qPos.add(messageCount);
1895
1896 if (orderByComparator != null) {
1897 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1898
1899 for (Object value : values) {
1900 qPos.add(value);
1901 }
1902 }
1903
1904 List<MBStatsUser> list = q.list();
1905
1906 if (list.size() == 2) {
1907 return list.get(1);
1908 }
1909 else {
1910 return null;
1911 }
1912 }
1913
1914
1920 public List<MBStatsUser> findAll() throws SystemException {
1921 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1922 }
1923
1924
1936 public List<MBStatsUser> findAll(int start, int end)
1937 throws SystemException {
1938 return findAll(start, end, null);
1939 }
1940
1941
1954 public List<MBStatsUser> findAll(int start, int end,
1955 OrderByComparator orderByComparator) throws SystemException {
1956 FinderPath finderPath = null;
1957 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1958
1959 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1960 (orderByComparator == null)) {
1961 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1962 finderArgs = FINDER_ARGS_EMPTY;
1963 }
1964 else {
1965 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1966 finderArgs = new Object[] { start, end, orderByComparator };
1967 }
1968
1969 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1970 finderArgs, this);
1971
1972 if (list == null) {
1973 StringBundler query = null;
1974 String sql = null;
1975
1976 if (orderByComparator != null) {
1977 query = new StringBundler(2 +
1978 (orderByComparator.getOrderByFields().length * 3));
1979
1980 query.append(_SQL_SELECT_MBSTATSUSER);
1981
1982 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1983 orderByComparator);
1984
1985 sql = query.toString();
1986 }
1987 else {
1988 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1989 }
1990
1991 Session session = null;
1992
1993 try {
1994 session = openSession();
1995
1996 Query q = session.createQuery(sql);
1997
1998 if (orderByComparator == null) {
1999 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
2000 start, end, false);
2001
2002 Collections.sort(list);
2003 }
2004 else {
2005 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
2006 start, end);
2007 }
2008 }
2009 catch (Exception e) {
2010 throw processException(e);
2011 }
2012 finally {
2013 if (list == null) {
2014 FinderCacheUtil.removeResult(finderPath, finderArgs);
2015 }
2016 else {
2017 cacheResult(list);
2018
2019 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2020 }
2021
2022 closeSession(session);
2023 }
2024 }
2025
2026 return list;
2027 }
2028
2029
2035 public void removeByGroupId(long groupId) throws SystemException {
2036 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
2037 remove(mbStatsUser);
2038 }
2039 }
2040
2041
2047 public void removeByUserId(long userId) throws SystemException {
2048 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
2049 remove(mbStatsUser);
2050 }
2051 }
2052
2053
2061 public MBStatsUser removeByG_U(long groupId, long userId)
2062 throws NoSuchStatsUserException, SystemException {
2063 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
2064
2065 return remove(mbStatsUser);
2066 }
2067
2068
2076 public void removeByG_NotU_NotM(long groupId, long userId, int messageCount)
2077 throws SystemException {
2078 for (MBStatsUser mbStatsUser : findByG_NotU_NotM(groupId, userId,
2079 messageCount)) {
2080 remove(mbStatsUser);
2081 }
2082 }
2083
2084
2089 public void removeAll() throws SystemException {
2090 for (MBStatsUser mbStatsUser : findAll()) {
2091 remove(mbStatsUser);
2092 }
2093 }
2094
2095
2102 public int countByGroupId(long groupId) throws SystemException {
2103 Object[] finderArgs = new Object[] { groupId };
2104
2105 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2106 finderArgs, this);
2107
2108 if (count == null) {
2109 StringBundler query = new StringBundler(2);
2110
2111 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2112
2113 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2114
2115 String sql = query.toString();
2116
2117 Session session = null;
2118
2119 try {
2120 session = openSession();
2121
2122 Query q = session.createQuery(sql);
2123
2124 QueryPos qPos = QueryPos.getInstance(q);
2125
2126 qPos.add(groupId);
2127
2128 count = (Long)q.uniqueResult();
2129 }
2130 catch (Exception e) {
2131 throw processException(e);
2132 }
2133 finally {
2134 if (count == null) {
2135 count = Long.valueOf(0);
2136 }
2137
2138 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2139 finderArgs, count);
2140
2141 closeSession(session);
2142 }
2143 }
2144
2145 return count.intValue();
2146 }
2147
2148
2155 public int countByUserId(long userId) throws SystemException {
2156 Object[] finderArgs = new Object[] { userId };
2157
2158 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2159 finderArgs, this);
2160
2161 if (count == null) {
2162 StringBundler query = new StringBundler(2);
2163
2164 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2165
2166 query.append(_FINDER_COLUMN_USERID_USERID_2);
2167
2168 String sql = query.toString();
2169
2170 Session session = null;
2171
2172 try {
2173 session = openSession();
2174
2175 Query q = session.createQuery(sql);
2176
2177 QueryPos qPos = QueryPos.getInstance(q);
2178
2179 qPos.add(userId);
2180
2181 count = (Long)q.uniqueResult();
2182 }
2183 catch (Exception e) {
2184 throw processException(e);
2185 }
2186 finally {
2187 if (count == null) {
2188 count = Long.valueOf(0);
2189 }
2190
2191 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2192 finderArgs, count);
2193
2194 closeSession(session);
2195 }
2196 }
2197
2198 return count.intValue();
2199 }
2200
2201
2209 public int countByG_U(long groupId, long userId) throws SystemException {
2210 Object[] finderArgs = new Object[] { groupId, userId };
2211
2212 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2213 finderArgs, this);
2214
2215 if (count == null) {
2216 StringBundler query = new StringBundler(3);
2217
2218 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2219
2220 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2221
2222 query.append(_FINDER_COLUMN_G_U_USERID_2);
2223
2224 String sql = query.toString();
2225
2226 Session session = null;
2227
2228 try {
2229 session = openSession();
2230
2231 Query q = session.createQuery(sql);
2232
2233 QueryPos qPos = QueryPos.getInstance(q);
2234
2235 qPos.add(groupId);
2236
2237 qPos.add(userId);
2238
2239 count = (Long)q.uniqueResult();
2240 }
2241 catch (Exception e) {
2242 throw processException(e);
2243 }
2244 finally {
2245 if (count == null) {
2246 count = Long.valueOf(0);
2247 }
2248
2249 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2250 count);
2251
2252 closeSession(session);
2253 }
2254 }
2255
2256 return count.intValue();
2257 }
2258
2259
2268 public int countByG_NotU_NotM(long groupId, long userId, int messageCount)
2269 throws SystemException {
2270 Object[] finderArgs = new Object[] { groupId, userId, messageCount };
2271
2272 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM,
2273 finderArgs, this);
2274
2275 if (count == null) {
2276 StringBundler query = new StringBundler(4);
2277
2278 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2279
2280 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
2281
2282 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
2283
2284 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
2285
2286 String sql = query.toString();
2287
2288 Session session = null;
2289
2290 try {
2291 session = openSession();
2292
2293 Query q = session.createQuery(sql);
2294
2295 QueryPos qPos = QueryPos.getInstance(q);
2296
2297 qPos.add(groupId);
2298
2299 qPos.add(userId);
2300
2301 qPos.add(messageCount);
2302
2303 count = (Long)q.uniqueResult();
2304 }
2305 catch (Exception e) {
2306 throw processException(e);
2307 }
2308 finally {
2309 if (count == null) {
2310 count = Long.valueOf(0);
2311 }
2312
2313 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_NOTU_NOTM,
2314 finderArgs, count);
2315
2316 closeSession(session);
2317 }
2318 }
2319
2320 return count.intValue();
2321 }
2322
2323
2329 public int countAll() throws SystemException {
2330 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2331 FINDER_ARGS_EMPTY, this);
2332
2333 if (count == null) {
2334 Session session = null;
2335
2336 try {
2337 session = openSession();
2338
2339 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2340
2341 count = (Long)q.uniqueResult();
2342 }
2343 catch (Exception e) {
2344 throw processException(e);
2345 }
2346 finally {
2347 if (count == null) {
2348 count = Long.valueOf(0);
2349 }
2350
2351 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2352 FINDER_ARGS_EMPTY, count);
2353
2354 closeSession(session);
2355 }
2356 }
2357
2358 return count.intValue();
2359 }
2360
2361
2364 public void afterPropertiesSet() {
2365 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2366 com.liferay.portal.util.PropsUtil.get(
2367 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2368
2369 if (listenerClassNames.length > 0) {
2370 try {
2371 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2372
2373 for (String listenerClassName : listenerClassNames) {
2374 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2375 listenerClassName));
2376 }
2377
2378 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2379 }
2380 catch (Exception e) {
2381 _log.error(e);
2382 }
2383 }
2384 }
2385
2386 public void destroy() {
2387 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2388 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2389 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2390 }
2391
2392 @BeanReference(type = MBBanPersistence.class)
2393 protected MBBanPersistence mbBanPersistence;
2394 @BeanReference(type = MBCategoryPersistence.class)
2395 protected MBCategoryPersistence mbCategoryPersistence;
2396 @BeanReference(type = MBDiscussionPersistence.class)
2397 protected MBDiscussionPersistence mbDiscussionPersistence;
2398 @BeanReference(type = MBMailingListPersistence.class)
2399 protected MBMailingListPersistence mbMailingListPersistence;
2400 @BeanReference(type = MBMessagePersistence.class)
2401 protected MBMessagePersistence mbMessagePersistence;
2402 @BeanReference(type = MBStatsUserPersistence.class)
2403 protected MBStatsUserPersistence mbStatsUserPersistence;
2404 @BeanReference(type = MBThreadPersistence.class)
2405 protected MBThreadPersistence mbThreadPersistence;
2406 @BeanReference(type = MBThreadFlagPersistence.class)
2407 protected MBThreadFlagPersistence mbThreadFlagPersistence;
2408 @BeanReference(type = GroupPersistence.class)
2409 protected GroupPersistence groupPersistence;
2410 @BeanReference(type = UserPersistence.class)
2411 protected UserPersistence userPersistence;
2412 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2413 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2414 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2415 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2416 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2417 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2418 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2419 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2420 private static final String _FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2421 private static final String _FINDER_COLUMN_G_NOTU_NOTM_USERID_2 = "mbStatsUser.userId != ? AND ";
2422 private static final String _FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2423 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2424 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2425 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2426 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2427 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2428 private static MBStatsUser _nullMBStatsUser = new MBStatsUserImpl() {
2429 @Override
2430 public Object clone() {
2431 return this;
2432 }
2433
2434 @Override
2435 public CacheModel<MBStatsUser> toCacheModel() {
2436 return _nullMBStatsUserCacheModel;
2437 }
2438 };
2439
2440 private static CacheModel<MBStatsUser> _nullMBStatsUserCacheModel = new CacheModel<MBStatsUser>() {
2441 public MBStatsUser toEntityModel() {
2442 return _nullMBStatsUser;
2443 }
2444 };
2445 }