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_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM =
139 new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
140 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
141 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_NotU_NotM",
142 new String[] {
143 Long.class.getName(), Long.class.getName(),
144 Integer.class.getName()
145 },
146 MBStatsUserModelImpl.GROUPID_COLUMN_BITMASK |
147 MBStatsUserModelImpl.USERID_COLUMN_BITMASK |
148 MBStatsUserModelImpl.MESSAGECOUNT_COLUMN_BITMASK);
149 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTU_NOTM = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
150 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
151 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_NotU_NotM",
152 new String[] {
153 Long.class.getName(), Long.class.getName(),
154 Integer.class.getName()
155 });
156 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
157 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
158 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
159 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
160 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, MBStatsUserImpl.class,
161 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
162 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
163 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, Long.class,
164 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
165
166
171 public void cacheResult(MBStatsUser mbStatsUser) {
172 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
173 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
174
175 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
176 new Object[] {
177 Long.valueOf(mbStatsUser.getGroupId()),
178 Long.valueOf(mbStatsUser.getUserId())
179 }, mbStatsUser);
180
181 mbStatsUser.resetOriginalValues();
182 }
183
184
189 public void cacheResult(List<MBStatsUser> mbStatsUsers) {
190 for (MBStatsUser mbStatsUser : mbStatsUsers) {
191 if (EntityCacheUtil.getResult(
192 MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
193 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey()) == null) {
194 cacheResult(mbStatsUser);
195 }
196 else {
197 mbStatsUser.resetOriginalValues();
198 }
199 }
200 }
201
202
209 @Override
210 public void clearCache() {
211 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
212 CacheRegistryUtil.clear(MBStatsUserImpl.class.getName());
213 }
214
215 EntityCacheUtil.clearCache(MBStatsUserImpl.class.getName());
216
217 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
218 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
219 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
220 }
221
222
229 @Override
230 public void clearCache(MBStatsUser mbStatsUser) {
231 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
232 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
233
234 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
235 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
236
237 clearUniqueFindersCache(mbStatsUser);
238 }
239
240 @Override
241 public void clearCache(List<MBStatsUser> mbStatsUsers) {
242 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
243 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
244
245 for (MBStatsUser mbStatsUser : mbStatsUsers) {
246 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
247 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
248
249 clearUniqueFindersCache(mbStatsUser);
250 }
251 }
252
253 protected void clearUniqueFindersCache(MBStatsUser mbStatsUser) {
254 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
255 new Object[] {
256 Long.valueOf(mbStatsUser.getGroupId()),
257 Long.valueOf(mbStatsUser.getUserId())
258 });
259 }
260
261
267 public MBStatsUser create(long statsUserId) {
268 MBStatsUser mbStatsUser = new MBStatsUserImpl();
269
270 mbStatsUser.setNew(true);
271 mbStatsUser.setPrimaryKey(statsUserId);
272
273 return mbStatsUser;
274 }
275
276
284 public MBStatsUser remove(long statsUserId)
285 throws NoSuchStatsUserException, SystemException {
286 return remove(Long.valueOf(statsUserId));
287 }
288
289
297 @Override
298 public MBStatsUser remove(Serializable primaryKey)
299 throws NoSuchStatsUserException, SystemException {
300 Session session = null;
301
302 try {
303 session = openSession();
304
305 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
306 primaryKey);
307
308 if (mbStatsUser == null) {
309 if (_log.isWarnEnabled()) {
310 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
311 }
312
313 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
314 primaryKey);
315 }
316
317 return remove(mbStatsUser);
318 }
319 catch (NoSuchStatsUserException nsee) {
320 throw nsee;
321 }
322 catch (Exception e) {
323 throw processException(e);
324 }
325 finally {
326 closeSession(session);
327 }
328 }
329
330 @Override
331 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
332 throws SystemException {
333 mbStatsUser = toUnwrappedModel(mbStatsUser);
334
335 Session session = null;
336
337 try {
338 session = openSession();
339
340 BatchSessionUtil.delete(session, mbStatsUser);
341 }
342 catch (Exception e) {
343 throw processException(e);
344 }
345 finally {
346 closeSession(session);
347 }
348
349 clearCache(mbStatsUser);
350
351 return mbStatsUser;
352 }
353
354 @Override
355 public MBStatsUser updateImpl(
356 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
357 boolean merge) throws SystemException {
358 mbStatsUser = toUnwrappedModel(mbStatsUser);
359
360 boolean isNew = mbStatsUser.isNew();
361
362 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
363
364 Session session = null;
365
366 try {
367 session = openSession();
368
369 BatchSessionUtil.update(session, mbStatsUser, merge);
370
371 mbStatsUser.setNew(false);
372 }
373 catch (Exception e) {
374 throw processException(e);
375 }
376 finally {
377 closeSession(session);
378 }
379
380 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
381
382 if (isNew || !MBStatsUserModelImpl.COLUMN_BITMASK_ENABLED) {
383 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
384 }
385 else {
386 if ((mbStatsUserModelImpl.getColumnBitmask() &
387 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
388 Object[] args = new Object[] {
389 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId())
390 };
391
392 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
393 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
394 args);
395
396 args = new Object[] {
397 Long.valueOf(mbStatsUserModelImpl.getGroupId())
398 };
399
400 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
401 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
402 args);
403 }
404
405 if ((mbStatsUserModelImpl.getColumnBitmask() &
406 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
407 Object[] args = new Object[] {
408 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
409 };
410
411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
412 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
413 args);
414
415 args = new Object[] {
416 Long.valueOf(mbStatsUserModelImpl.getUserId())
417 };
418
419 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
420 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
421 args);
422 }
423
424 if ((mbStatsUserModelImpl.getColumnBitmask() &
425 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM.getColumnBitmask()) != 0) {
426 Object[] args = new Object[] {
427 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
428 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId()),
429 Integer.valueOf(mbStatsUserModelImpl.getOriginalMessageCount())
430 };
431
432 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
433 args);
434 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM,
435 args);
436
437 args = new Object[] {
438 Long.valueOf(mbStatsUserModelImpl.getGroupId()),
439 Long.valueOf(mbStatsUserModelImpl.getUserId()),
440 Integer.valueOf(mbStatsUserModelImpl.getMessageCount())
441 };
442
443 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
444 args);
445 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM,
446 args);
447 }
448 }
449
450 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
451 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
452
453 if (isNew) {
454 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
455 new Object[] {
456 Long.valueOf(mbStatsUser.getGroupId()),
457 Long.valueOf(mbStatsUser.getUserId())
458 }, mbStatsUser);
459 }
460 else {
461 if ((mbStatsUserModelImpl.getColumnBitmask() &
462 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
463 Object[] args = new Object[] {
464 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
465 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
466 };
467
468 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
469 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
470
471 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
472 new Object[] {
473 Long.valueOf(mbStatsUser.getGroupId()),
474 Long.valueOf(mbStatsUser.getUserId())
475 }, mbStatsUser);
476 }
477 }
478
479 return mbStatsUser;
480 }
481
482 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
483 if (mbStatsUser instanceof MBStatsUserImpl) {
484 return mbStatsUser;
485 }
486
487 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
488
489 mbStatsUserImpl.setNew(mbStatsUser.isNew());
490 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
491
492 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
493 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
494 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
495 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
496 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
497
498 return mbStatsUserImpl;
499 }
500
501
509 @Override
510 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
511 throws NoSuchModelException, SystemException {
512 return findByPrimaryKey(((Long)primaryKey).longValue());
513 }
514
515
523 public MBStatsUser findByPrimaryKey(long statsUserId)
524 throws NoSuchStatsUserException, SystemException {
525 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
526
527 if (mbStatsUser == null) {
528 if (_log.isWarnEnabled()) {
529 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
530 }
531
532 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
533 statsUserId);
534 }
535
536 return mbStatsUser;
537 }
538
539
546 @Override
547 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
548 throws SystemException {
549 return fetchByPrimaryKey(((Long)primaryKey).longValue());
550 }
551
552
559 public MBStatsUser fetchByPrimaryKey(long statsUserId)
560 throws SystemException {
561 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
562 MBStatsUserImpl.class, statsUserId);
563
564 if (mbStatsUser == _nullMBStatsUser) {
565 return null;
566 }
567
568 if (mbStatsUser == null) {
569 Session session = null;
570
571 boolean hasException = false;
572
573 try {
574 session = openSession();
575
576 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
577 Long.valueOf(statsUserId));
578 }
579 catch (Exception e) {
580 hasException = true;
581
582 throw processException(e);
583 }
584 finally {
585 if (mbStatsUser != null) {
586 cacheResult(mbStatsUser);
587 }
588 else if (!hasException) {
589 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
590 MBStatsUserImpl.class, statsUserId, _nullMBStatsUser);
591 }
592
593 closeSession(session);
594 }
595 }
596
597 return mbStatsUser;
598 }
599
600
607 public List<MBStatsUser> findByGroupId(long groupId)
608 throws SystemException {
609 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
610 }
611
612
625 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
626 throws SystemException {
627 return findByGroupId(groupId, start, end, null);
628 }
629
630
644 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
645 OrderByComparator orderByComparator) throws SystemException {
646 FinderPath finderPath = null;
647 Object[] finderArgs = null;
648
649 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
650 (orderByComparator == null)) {
651 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
652 finderArgs = new Object[] { groupId };
653 }
654 else {
655 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
656 finderArgs = new Object[] { groupId, start, end, orderByComparator };
657 }
658
659 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
660 finderArgs, this);
661
662 if ((list != null) && !list.isEmpty()) {
663 for (MBStatsUser mbStatsUser : list) {
664 if ((groupId != mbStatsUser.getGroupId())) {
665 list = null;
666
667 break;
668 }
669 }
670 }
671
672 if (list == null) {
673 StringBundler query = null;
674
675 if (orderByComparator != null) {
676 query = new StringBundler(3 +
677 (orderByComparator.getOrderByFields().length * 3));
678 }
679 else {
680 query = new StringBundler(3);
681 }
682
683 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
684
685 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
686
687 if (orderByComparator != null) {
688 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
689 orderByComparator);
690 }
691
692 else {
693 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
694 }
695
696 String sql = query.toString();
697
698 Session session = null;
699
700 try {
701 session = openSession();
702
703 Query q = session.createQuery(sql);
704
705 QueryPos qPos = QueryPos.getInstance(q);
706
707 qPos.add(groupId);
708
709 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
710 start, end);
711 }
712 catch (Exception e) {
713 throw processException(e);
714 }
715 finally {
716 if (list == null) {
717 FinderCacheUtil.removeResult(finderPath, finderArgs);
718 }
719 else {
720 cacheResult(list);
721
722 FinderCacheUtil.putResult(finderPath, finderArgs, list);
723 }
724
725 closeSession(session);
726 }
727 }
728
729 return list;
730 }
731
732
745 public MBStatsUser findByGroupId_First(long groupId,
746 OrderByComparator orderByComparator)
747 throws NoSuchStatsUserException, SystemException {
748 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
749
750 if (list.isEmpty()) {
751 StringBundler msg = new StringBundler(4);
752
753 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
754
755 msg.append("groupId=");
756 msg.append(groupId);
757
758 msg.append(StringPool.CLOSE_CURLY_BRACE);
759
760 throw new NoSuchStatsUserException(msg.toString());
761 }
762 else {
763 return list.get(0);
764 }
765 }
766
767
780 public MBStatsUser findByGroupId_Last(long groupId,
781 OrderByComparator orderByComparator)
782 throws NoSuchStatsUserException, SystemException {
783 int count = countByGroupId(groupId);
784
785 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
786 orderByComparator);
787
788 if (list.isEmpty()) {
789 StringBundler msg = new StringBundler(4);
790
791 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
792
793 msg.append("groupId=");
794 msg.append(groupId);
795
796 msg.append(StringPool.CLOSE_CURLY_BRACE);
797
798 throw new NoSuchStatsUserException(msg.toString());
799 }
800 else {
801 return list.get(0);
802 }
803 }
804
805
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
1100 public MBStatsUser findByUserId_First(long userId,
1101 OrderByComparator orderByComparator)
1102 throws NoSuchStatsUserException, SystemException {
1103 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
1104
1105 if (list.isEmpty()) {
1106 StringBundler msg = new StringBundler(4);
1107
1108 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1109
1110 msg.append("userId=");
1111 msg.append(userId);
1112
1113 msg.append(StringPool.CLOSE_CURLY_BRACE);
1114
1115 throw new NoSuchStatsUserException(msg.toString());
1116 }
1117 else {
1118 return list.get(0);
1119 }
1120 }
1121
1122
1135 public MBStatsUser findByUserId_Last(long userId,
1136 OrderByComparator orderByComparator)
1137 throws NoSuchStatsUserException, SystemException {
1138 int count = countByUserId(userId);
1139
1140 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
1141 orderByComparator);
1142
1143 if (list.isEmpty()) {
1144 StringBundler msg = new StringBundler(4);
1145
1146 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1147
1148 msg.append("userId=");
1149 msg.append(userId);
1150
1151 msg.append(StringPool.CLOSE_CURLY_BRACE);
1152
1153 throw new NoSuchStatsUserException(msg.toString());
1154 }
1155 else {
1156 return list.get(0);
1157 }
1158 }
1159
1160
1174 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
1175 long userId, OrderByComparator orderByComparator)
1176 throws NoSuchStatsUserException, SystemException {
1177 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1178
1179 Session session = null;
1180
1181 try {
1182 session = openSession();
1183
1184 MBStatsUser[] array = new MBStatsUserImpl[3];
1185
1186 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1187 orderByComparator, true);
1188
1189 array[1] = mbStatsUser;
1190
1191 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1192 orderByComparator, false);
1193
1194 return array;
1195 }
1196 catch (Exception e) {
1197 throw processException(e);
1198 }
1199 finally {
1200 closeSession(session);
1201 }
1202 }
1203
1204 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1205 MBStatsUser mbStatsUser, long userId,
1206 OrderByComparator orderByComparator, boolean previous) {
1207 StringBundler query = null;
1208
1209 if (orderByComparator != null) {
1210 query = new StringBundler(6 +
1211 (orderByComparator.getOrderByFields().length * 6));
1212 }
1213 else {
1214 query = new StringBundler(3);
1215 }
1216
1217 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1218
1219 query.append(_FINDER_COLUMN_USERID_USERID_2);
1220
1221 if (orderByComparator != null) {
1222 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1223
1224 if (orderByConditionFields.length > 0) {
1225 query.append(WHERE_AND);
1226 }
1227
1228 for (int i = 0; i < orderByConditionFields.length; i++) {
1229 query.append(_ORDER_BY_ENTITY_ALIAS);
1230 query.append(orderByConditionFields[i]);
1231
1232 if ((i + 1) < orderByConditionFields.length) {
1233 if (orderByComparator.isAscending() ^ previous) {
1234 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1235 }
1236 else {
1237 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1238 }
1239 }
1240 else {
1241 if (orderByComparator.isAscending() ^ previous) {
1242 query.append(WHERE_GREATER_THAN);
1243 }
1244 else {
1245 query.append(WHERE_LESSER_THAN);
1246 }
1247 }
1248 }
1249
1250 query.append(ORDER_BY_CLAUSE);
1251
1252 String[] orderByFields = orderByComparator.getOrderByFields();
1253
1254 for (int i = 0; i < orderByFields.length; i++) {
1255 query.append(_ORDER_BY_ENTITY_ALIAS);
1256 query.append(orderByFields[i]);
1257
1258 if ((i + 1) < orderByFields.length) {
1259 if (orderByComparator.isAscending() ^ previous) {
1260 query.append(ORDER_BY_ASC_HAS_NEXT);
1261 }
1262 else {
1263 query.append(ORDER_BY_DESC_HAS_NEXT);
1264 }
1265 }
1266 else {
1267 if (orderByComparator.isAscending() ^ previous) {
1268 query.append(ORDER_BY_ASC);
1269 }
1270 else {
1271 query.append(ORDER_BY_DESC);
1272 }
1273 }
1274 }
1275 }
1276
1277 else {
1278 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1279 }
1280
1281 String sql = query.toString();
1282
1283 Query q = session.createQuery(sql);
1284
1285 q.setFirstResult(0);
1286 q.setMaxResults(2);
1287
1288 QueryPos qPos = QueryPos.getInstance(q);
1289
1290 qPos.add(userId);
1291
1292 if (orderByComparator != null) {
1293 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1294
1295 for (Object value : values) {
1296 qPos.add(value);
1297 }
1298 }
1299
1300 List<MBStatsUser> list = q.list();
1301
1302 if (list.size() == 2) {
1303 return list.get(1);
1304 }
1305 else {
1306 return null;
1307 }
1308 }
1309
1310
1319 public MBStatsUser findByG_U(long groupId, long userId)
1320 throws NoSuchStatsUserException, SystemException {
1321 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1322
1323 if (mbStatsUser == null) {
1324 StringBundler msg = new StringBundler(6);
1325
1326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1327
1328 msg.append("groupId=");
1329 msg.append(groupId);
1330
1331 msg.append(", userId=");
1332 msg.append(userId);
1333
1334 msg.append(StringPool.CLOSE_CURLY_BRACE);
1335
1336 if (_log.isWarnEnabled()) {
1337 _log.warn(msg.toString());
1338 }
1339
1340 throw new NoSuchStatsUserException(msg.toString());
1341 }
1342
1343 return mbStatsUser;
1344 }
1345
1346
1354 public MBStatsUser fetchByG_U(long groupId, long userId)
1355 throws SystemException {
1356 return fetchByG_U(groupId, userId, true);
1357 }
1358
1359
1368 public MBStatsUser fetchByG_U(long groupId, long userId,
1369 boolean retrieveFromCache) throws SystemException {
1370 Object[] finderArgs = new Object[] { groupId, userId };
1371
1372 Object result = null;
1373
1374 if (retrieveFromCache) {
1375 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1376 finderArgs, this);
1377 }
1378
1379 if (result instanceof MBStatsUser) {
1380 MBStatsUser mbStatsUser = (MBStatsUser)result;
1381
1382 if ((groupId != mbStatsUser.getGroupId()) ||
1383 (userId != mbStatsUser.getUserId())) {
1384 result = null;
1385 }
1386 }
1387
1388 if (result == null) {
1389 StringBundler query = new StringBundler(4);
1390
1391 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1392
1393 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1394
1395 query.append(_FINDER_COLUMN_G_U_USERID_2);
1396
1397 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1398
1399 String sql = query.toString();
1400
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 Query q = session.createQuery(sql);
1407
1408 QueryPos qPos = QueryPos.getInstance(q);
1409
1410 qPos.add(groupId);
1411
1412 qPos.add(userId);
1413
1414 List<MBStatsUser> list = q.list();
1415
1416 result = list;
1417
1418 MBStatsUser mbStatsUser = null;
1419
1420 if (list.isEmpty()) {
1421 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1422 finderArgs, list);
1423 }
1424 else {
1425 mbStatsUser = list.get(0);
1426
1427 cacheResult(mbStatsUser);
1428
1429 if ((mbStatsUser.getGroupId() != groupId) ||
1430 (mbStatsUser.getUserId() != userId)) {
1431 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1432 finderArgs, mbStatsUser);
1433 }
1434 }
1435
1436 return mbStatsUser;
1437 }
1438 catch (Exception e) {
1439 throw processException(e);
1440 }
1441 finally {
1442 if (result == null) {
1443 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1444 finderArgs);
1445 }
1446
1447 closeSession(session);
1448 }
1449 }
1450 else {
1451 if (result instanceof List<?>) {
1452 return null;
1453 }
1454 else {
1455 return (MBStatsUser)result;
1456 }
1457 }
1458 }
1459
1460
1469 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1470 int messageCount) throws SystemException {
1471 return findByG_NotU_NotM(groupId, userId, messageCount,
1472 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1473 }
1474
1475
1490 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1491 int messageCount, int start, int end) throws SystemException {
1492 return findByG_NotU_NotM(groupId, userId, messageCount, start, end, null);
1493 }
1494
1495
1511 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1512 int messageCount, int start, int end,
1513 OrderByComparator orderByComparator) throws SystemException {
1514 FinderPath finderPath = null;
1515 Object[] finderArgs = null;
1516
1517 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1518 (orderByComparator == null)) {
1519 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM;
1520 finderArgs = new Object[] { groupId, userId, messageCount };
1521 }
1522 else {
1523 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM;
1524 finderArgs = new Object[] {
1525 groupId, userId, messageCount,
1526
1527 start, end, orderByComparator
1528 };
1529 }
1530
1531 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1532 finderArgs, this);
1533
1534 if ((list != null) && !list.isEmpty()) {
1535 for (MBStatsUser mbStatsUser : list) {
1536 if ((groupId != mbStatsUser.getGroupId()) ||
1537 (userId != mbStatsUser.getUserId()) ||
1538 (messageCount != mbStatsUser.getMessageCount())) {
1539 list = null;
1540
1541 break;
1542 }
1543 }
1544 }
1545
1546 if (list == null) {
1547 StringBundler query = null;
1548
1549 if (orderByComparator != null) {
1550 query = new StringBundler(5 +
1551 (orderByComparator.getOrderByFields().length * 3));
1552 }
1553 else {
1554 query = new StringBundler(5);
1555 }
1556
1557 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1558
1559 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1560
1561 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1562
1563 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1564
1565 if (orderByComparator != null) {
1566 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1567 orderByComparator);
1568 }
1569
1570 else {
1571 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1572 }
1573
1574 String sql = query.toString();
1575
1576 Session session = null;
1577
1578 try {
1579 session = openSession();
1580
1581 Query q = session.createQuery(sql);
1582
1583 QueryPos qPos = QueryPos.getInstance(q);
1584
1585 qPos.add(groupId);
1586
1587 qPos.add(userId);
1588
1589 qPos.add(messageCount);
1590
1591 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1592 start, end);
1593 }
1594 catch (Exception e) {
1595 throw processException(e);
1596 }
1597 finally {
1598 if (list == null) {
1599 FinderCacheUtil.removeResult(finderPath, finderArgs);
1600 }
1601 else {
1602 cacheResult(list);
1603
1604 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1605 }
1606
1607 closeSession(session);
1608 }
1609 }
1610
1611 return list;
1612 }
1613
1614
1629 public MBStatsUser findByG_NotU_NotM_First(long groupId, long userId,
1630 int messageCount, OrderByComparator orderByComparator)
1631 throws NoSuchStatsUserException, SystemException {
1632 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1633 messageCount, 0, 1, orderByComparator);
1634
1635 if (list.isEmpty()) {
1636 StringBundler msg = new StringBundler(8);
1637
1638 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1639
1640 msg.append("groupId=");
1641 msg.append(groupId);
1642
1643 msg.append(", userId=");
1644 msg.append(userId);
1645
1646 msg.append(", messageCount=");
1647 msg.append(messageCount);
1648
1649 msg.append(StringPool.CLOSE_CURLY_BRACE);
1650
1651 throw new NoSuchStatsUserException(msg.toString());
1652 }
1653 else {
1654 return list.get(0);
1655 }
1656 }
1657
1658
1673 public MBStatsUser findByG_NotU_NotM_Last(long groupId, long userId,
1674 int messageCount, OrderByComparator orderByComparator)
1675 throws NoSuchStatsUserException, SystemException {
1676 int count = countByG_NotU_NotM(groupId, userId, messageCount);
1677
1678 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1679 messageCount, count - 1, count, orderByComparator);
1680
1681 if (list.isEmpty()) {
1682 StringBundler msg = new StringBundler(8);
1683
1684 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1685
1686 msg.append("groupId=");
1687 msg.append(groupId);
1688
1689 msg.append(", userId=");
1690 msg.append(userId);
1691
1692 msg.append(", messageCount=");
1693 msg.append(messageCount);
1694
1695 msg.append(StringPool.CLOSE_CURLY_BRACE);
1696
1697 throw new NoSuchStatsUserException(msg.toString());
1698 }
1699 else {
1700 return list.get(0);
1701 }
1702 }
1703
1704
1720 public MBStatsUser[] findByG_NotU_NotM_PrevAndNext(long statsUserId,
1721 long groupId, long userId, int messageCount,
1722 OrderByComparator orderByComparator)
1723 throws NoSuchStatsUserException, SystemException {
1724 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1725
1726 Session session = null;
1727
1728 try {
1729 session = openSession();
1730
1731 MBStatsUser[] array = new MBStatsUserImpl[3];
1732
1733 array[0] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1734 groupId, userId, messageCount, orderByComparator, true);
1735
1736 array[1] = mbStatsUser;
1737
1738 array[2] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1739 groupId, userId, messageCount, orderByComparator, false);
1740
1741 return array;
1742 }
1743 catch (Exception e) {
1744 throw processException(e);
1745 }
1746 finally {
1747 closeSession(session);
1748 }
1749 }
1750
1751 protected MBStatsUser getByG_NotU_NotM_PrevAndNext(Session session,
1752 MBStatsUser mbStatsUser, long groupId, long userId, int messageCount,
1753 OrderByComparator orderByComparator, boolean previous) {
1754 StringBundler query = null;
1755
1756 if (orderByComparator != null) {
1757 query = new StringBundler(6 +
1758 (orderByComparator.getOrderByFields().length * 6));
1759 }
1760 else {
1761 query = new StringBundler(3);
1762 }
1763
1764 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1765
1766 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1767
1768 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1769
1770 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1771
1772 if (orderByComparator != null) {
1773 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1774
1775 if (orderByConditionFields.length > 0) {
1776 query.append(WHERE_AND);
1777 }
1778
1779 for (int i = 0; i < orderByConditionFields.length; i++) {
1780 query.append(_ORDER_BY_ENTITY_ALIAS);
1781 query.append(orderByConditionFields[i]);
1782
1783 if ((i + 1) < orderByConditionFields.length) {
1784 if (orderByComparator.isAscending() ^ previous) {
1785 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1786 }
1787 else {
1788 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1789 }
1790 }
1791 else {
1792 if (orderByComparator.isAscending() ^ previous) {
1793 query.append(WHERE_GREATER_THAN);
1794 }
1795 else {
1796 query.append(WHERE_LESSER_THAN);
1797 }
1798 }
1799 }
1800
1801 query.append(ORDER_BY_CLAUSE);
1802
1803 String[] orderByFields = orderByComparator.getOrderByFields();
1804
1805 for (int i = 0; i < orderByFields.length; i++) {
1806 query.append(_ORDER_BY_ENTITY_ALIAS);
1807 query.append(orderByFields[i]);
1808
1809 if ((i + 1) < orderByFields.length) {
1810 if (orderByComparator.isAscending() ^ previous) {
1811 query.append(ORDER_BY_ASC_HAS_NEXT);
1812 }
1813 else {
1814 query.append(ORDER_BY_DESC_HAS_NEXT);
1815 }
1816 }
1817 else {
1818 if (orderByComparator.isAscending() ^ previous) {
1819 query.append(ORDER_BY_ASC);
1820 }
1821 else {
1822 query.append(ORDER_BY_DESC);
1823 }
1824 }
1825 }
1826 }
1827
1828 else {
1829 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1830 }
1831
1832 String sql = query.toString();
1833
1834 Query q = session.createQuery(sql);
1835
1836 q.setFirstResult(0);
1837 q.setMaxResults(2);
1838
1839 QueryPos qPos = QueryPos.getInstance(q);
1840
1841 qPos.add(groupId);
1842
1843 qPos.add(userId);
1844
1845 qPos.add(messageCount);
1846
1847 if (orderByComparator != null) {
1848 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1849
1850 for (Object value : values) {
1851 qPos.add(value);
1852 }
1853 }
1854
1855 List<MBStatsUser> list = q.list();
1856
1857 if (list.size() == 2) {
1858 return list.get(1);
1859 }
1860 else {
1861 return null;
1862 }
1863 }
1864
1865
1871 public List<MBStatsUser> findAll() throws SystemException {
1872 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1873 }
1874
1875
1887 public List<MBStatsUser> findAll(int start, int end)
1888 throws SystemException {
1889 return findAll(start, end, null);
1890 }
1891
1892
1905 public List<MBStatsUser> findAll(int start, int end,
1906 OrderByComparator orderByComparator) throws SystemException {
1907 FinderPath finderPath = null;
1908 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1909
1910 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1911 (orderByComparator == null)) {
1912 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1913 finderArgs = FINDER_ARGS_EMPTY;
1914 }
1915 else {
1916 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1917 finderArgs = new Object[] { start, end, orderByComparator };
1918 }
1919
1920 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1921 finderArgs, this);
1922
1923 if (list == null) {
1924 StringBundler query = null;
1925 String sql = null;
1926
1927 if (orderByComparator != null) {
1928 query = new StringBundler(2 +
1929 (orderByComparator.getOrderByFields().length * 3));
1930
1931 query.append(_SQL_SELECT_MBSTATSUSER);
1932
1933 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1934 orderByComparator);
1935
1936 sql = query.toString();
1937 }
1938 else {
1939 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1940 }
1941
1942 Session session = null;
1943
1944 try {
1945 session = openSession();
1946
1947 Query q = session.createQuery(sql);
1948
1949 if (orderByComparator == null) {
1950 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1951 start, end, false);
1952
1953 Collections.sort(list);
1954 }
1955 else {
1956 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1957 start, end);
1958 }
1959 }
1960 catch (Exception e) {
1961 throw processException(e);
1962 }
1963 finally {
1964 if (list == null) {
1965 FinderCacheUtil.removeResult(finderPath, finderArgs);
1966 }
1967 else {
1968 cacheResult(list);
1969
1970 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1971 }
1972
1973 closeSession(session);
1974 }
1975 }
1976
1977 return list;
1978 }
1979
1980
1986 public void removeByGroupId(long groupId) throws SystemException {
1987 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1988 remove(mbStatsUser);
1989 }
1990 }
1991
1992
1998 public void removeByUserId(long userId) throws SystemException {
1999 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
2000 remove(mbStatsUser);
2001 }
2002 }
2003
2004
2011 public void removeByG_U(long groupId, long userId)
2012 throws NoSuchStatsUserException, SystemException {
2013 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
2014
2015 remove(mbStatsUser);
2016 }
2017
2018
2026 public void removeByG_NotU_NotM(long groupId, long userId, int messageCount)
2027 throws SystemException {
2028 for (MBStatsUser mbStatsUser : findByG_NotU_NotM(groupId, userId,
2029 messageCount)) {
2030 remove(mbStatsUser);
2031 }
2032 }
2033
2034
2039 public void removeAll() throws SystemException {
2040 for (MBStatsUser mbStatsUser : findAll()) {
2041 remove(mbStatsUser);
2042 }
2043 }
2044
2045
2052 public int countByGroupId(long groupId) throws SystemException {
2053 Object[] finderArgs = new Object[] { groupId };
2054
2055 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2056 finderArgs, this);
2057
2058 if (count == null) {
2059 StringBundler query = new StringBundler(2);
2060
2061 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2062
2063 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2064
2065 String sql = query.toString();
2066
2067 Session session = null;
2068
2069 try {
2070 session = openSession();
2071
2072 Query q = session.createQuery(sql);
2073
2074 QueryPos qPos = QueryPos.getInstance(q);
2075
2076 qPos.add(groupId);
2077
2078 count = (Long)q.uniqueResult();
2079 }
2080 catch (Exception e) {
2081 throw processException(e);
2082 }
2083 finally {
2084 if (count == null) {
2085 count = Long.valueOf(0);
2086 }
2087
2088 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2089 finderArgs, count);
2090
2091 closeSession(session);
2092 }
2093 }
2094
2095 return count.intValue();
2096 }
2097
2098
2105 public int countByUserId(long userId) throws SystemException {
2106 Object[] finderArgs = new Object[] { userId };
2107
2108 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2109 finderArgs, this);
2110
2111 if (count == null) {
2112 StringBundler query = new StringBundler(2);
2113
2114 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2115
2116 query.append(_FINDER_COLUMN_USERID_USERID_2);
2117
2118 String sql = query.toString();
2119
2120 Session session = null;
2121
2122 try {
2123 session = openSession();
2124
2125 Query q = session.createQuery(sql);
2126
2127 QueryPos qPos = QueryPos.getInstance(q);
2128
2129 qPos.add(userId);
2130
2131 count = (Long)q.uniqueResult();
2132 }
2133 catch (Exception e) {
2134 throw processException(e);
2135 }
2136 finally {
2137 if (count == null) {
2138 count = Long.valueOf(0);
2139 }
2140
2141 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2142 finderArgs, count);
2143
2144 closeSession(session);
2145 }
2146 }
2147
2148 return count.intValue();
2149 }
2150
2151
2159 public int countByG_U(long groupId, long userId) throws SystemException {
2160 Object[] finderArgs = new Object[] { groupId, userId };
2161
2162 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2163 finderArgs, this);
2164
2165 if (count == null) {
2166 StringBundler query = new StringBundler(3);
2167
2168 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2169
2170 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2171
2172 query.append(_FINDER_COLUMN_G_U_USERID_2);
2173
2174 String sql = query.toString();
2175
2176 Session session = null;
2177
2178 try {
2179 session = openSession();
2180
2181 Query q = session.createQuery(sql);
2182
2183 QueryPos qPos = QueryPos.getInstance(q);
2184
2185 qPos.add(groupId);
2186
2187 qPos.add(userId);
2188
2189 count = (Long)q.uniqueResult();
2190 }
2191 catch (Exception e) {
2192 throw processException(e);
2193 }
2194 finally {
2195 if (count == null) {
2196 count = Long.valueOf(0);
2197 }
2198
2199 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2200 count);
2201
2202 closeSession(session);
2203 }
2204 }
2205
2206 return count.intValue();
2207 }
2208
2209
2218 public int countByG_NotU_NotM(long groupId, long userId, int messageCount)
2219 throws SystemException {
2220 Object[] finderArgs = new Object[] { groupId, userId, messageCount };
2221
2222 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
2223 finderArgs, this);
2224
2225 if (count == null) {
2226 StringBundler query = new StringBundler(4);
2227
2228 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2229
2230 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
2231
2232 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
2233
2234 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
2235
2236 String sql = query.toString();
2237
2238 Session session = null;
2239
2240 try {
2241 session = openSession();
2242
2243 Query q = session.createQuery(sql);
2244
2245 QueryPos qPos = QueryPos.getInstance(q);
2246
2247 qPos.add(groupId);
2248
2249 qPos.add(userId);
2250
2251 qPos.add(messageCount);
2252
2253 count = (Long)q.uniqueResult();
2254 }
2255 catch (Exception e) {
2256 throw processException(e);
2257 }
2258 finally {
2259 if (count == null) {
2260 count = Long.valueOf(0);
2261 }
2262
2263 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
2264 finderArgs, count);
2265
2266 closeSession(session);
2267 }
2268 }
2269
2270 return count.intValue();
2271 }
2272
2273
2279 public int countAll() throws SystemException {
2280 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2281 FINDER_ARGS_EMPTY, this);
2282
2283 if (count == null) {
2284 Session session = null;
2285
2286 try {
2287 session = openSession();
2288
2289 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2290
2291 count = (Long)q.uniqueResult();
2292 }
2293 catch (Exception e) {
2294 throw processException(e);
2295 }
2296 finally {
2297 if (count == null) {
2298 count = Long.valueOf(0);
2299 }
2300
2301 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2302 FINDER_ARGS_EMPTY, count);
2303
2304 closeSession(session);
2305 }
2306 }
2307
2308 return count.intValue();
2309 }
2310
2311
2314 public void afterPropertiesSet() {
2315 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2316 com.liferay.portal.util.PropsUtil.get(
2317 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2318
2319 if (listenerClassNames.length > 0) {
2320 try {
2321 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2322
2323 for (String listenerClassName : listenerClassNames) {
2324 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2325 listenerClassName));
2326 }
2327
2328 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2329 }
2330 catch (Exception e) {
2331 _log.error(e);
2332 }
2333 }
2334 }
2335
2336 public void destroy() {
2337 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2338 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2339 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2340 }
2341
2342 @BeanReference(type = MBBanPersistence.class)
2343 protected MBBanPersistence mbBanPersistence;
2344 @BeanReference(type = MBCategoryPersistence.class)
2345 protected MBCategoryPersistence mbCategoryPersistence;
2346 @BeanReference(type = MBDiscussionPersistence.class)
2347 protected MBDiscussionPersistence mbDiscussionPersistence;
2348 @BeanReference(type = MBMailingListPersistence.class)
2349 protected MBMailingListPersistence mbMailingListPersistence;
2350 @BeanReference(type = MBMessagePersistence.class)
2351 protected MBMessagePersistence mbMessagePersistence;
2352 @BeanReference(type = MBStatsUserPersistence.class)
2353 protected MBStatsUserPersistence mbStatsUserPersistence;
2354 @BeanReference(type = MBThreadPersistence.class)
2355 protected MBThreadPersistence mbThreadPersistence;
2356 @BeanReference(type = MBThreadFlagPersistence.class)
2357 protected MBThreadFlagPersistence mbThreadFlagPersistence;
2358 @BeanReference(type = GroupPersistence.class)
2359 protected GroupPersistence groupPersistence;
2360 @BeanReference(type = ResourcePersistence.class)
2361 protected ResourcePersistence resourcePersistence;
2362 @BeanReference(type = UserPersistence.class)
2363 protected UserPersistence userPersistence;
2364 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2365 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2366 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2367 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2368 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2369 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2370 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2371 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2372 private static final String _FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2373 private static final String _FINDER_COLUMN_G_NOTU_NOTM_USERID_2 = "mbStatsUser.userId != ? AND ";
2374 private static final String _FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2375 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2376 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2377 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2378 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2379 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2380 private static MBStatsUser _nullMBStatsUser = new MBStatsUserImpl() {
2381 @Override
2382 public Object clone() {
2383 return this;
2384 }
2385
2386 @Override
2387 public CacheModel<MBStatsUser> toCacheModel() {
2388 return _nullMBStatsUserCacheModel;
2389 }
2390 };
2391
2392 private static CacheModel<MBStatsUser> _nullMBStatsUserCacheModel = new CacheModel<MBStatsUser>() {
2393 public MBStatsUser toEntityModel() {
2394 return _nullMBStatsUser;
2395 }
2396 };
2397 }