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_WITHOUT_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_WITH_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 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
238 new Object[] {
239 Long.valueOf(mbStatsUser.getGroupId()),
240 Long.valueOf(mbStatsUser.getUserId())
241 });
242 }
243
244
250 public MBStatsUser create(long statsUserId) {
251 MBStatsUser mbStatsUser = new MBStatsUserImpl();
252
253 mbStatsUser.setNew(true);
254 mbStatsUser.setPrimaryKey(statsUserId);
255
256 return mbStatsUser;
257 }
258
259
267 @Override
268 public MBStatsUser remove(Serializable primaryKey)
269 throws NoSuchModelException, SystemException {
270 return remove(((Long)primaryKey).longValue());
271 }
272
273
281 public MBStatsUser remove(long statsUserId)
282 throws NoSuchStatsUserException, SystemException {
283 Session session = null;
284
285 try {
286 session = openSession();
287
288 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
289 Long.valueOf(statsUserId));
290
291 if (mbStatsUser == null) {
292 if (_log.isWarnEnabled()) {
293 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
294 }
295
296 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
297 statsUserId);
298 }
299
300 return mbStatsUserPersistence.remove(mbStatsUser);
301 }
302 catch (NoSuchStatsUserException nsee) {
303 throw nsee;
304 }
305 catch (Exception e) {
306 throw processException(e);
307 }
308 finally {
309 closeSession(session);
310 }
311 }
312
313
320 @Override
321 public MBStatsUser remove(MBStatsUser mbStatsUser)
322 throws SystemException {
323 return super.remove(mbStatsUser);
324 }
325
326 @Override
327 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
328 throws SystemException {
329 mbStatsUser = toUnwrappedModel(mbStatsUser);
330
331 Session session = null;
332
333 try {
334 session = openSession();
335
336 BatchSessionUtil.delete(session, mbStatsUser);
337 }
338 catch (Exception e) {
339 throw processException(e);
340 }
341 finally {
342 closeSession(session);
343 }
344
345 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
346 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
347
348 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
349
350 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
351 new Object[] {
352 Long.valueOf(mbStatsUserModelImpl.getGroupId()),
353 Long.valueOf(mbStatsUserModelImpl.getUserId())
354 });
355
356 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
357 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
358
359 return mbStatsUser;
360 }
361
362 @Override
363 public MBStatsUser updateImpl(
364 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
365 boolean merge) throws SystemException {
366 mbStatsUser = toUnwrappedModel(mbStatsUser);
367
368 boolean isNew = mbStatsUser.isNew();
369
370 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
371
372 Session session = null;
373
374 try {
375 session = openSession();
376
377 BatchSessionUtil.update(session, mbStatsUser, merge);
378
379 mbStatsUser.setNew(false);
380 }
381 catch (Exception e) {
382 throw processException(e);
383 }
384 finally {
385 closeSession(session);
386 }
387
388 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
389
390 if (isNew || !MBStatsUserModelImpl.COLUMN_BITMASK_ENABLED) {
391 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
392 }
393
394 else {
395 if ((mbStatsUserModelImpl.getColumnBitmask() &
396 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
397 Object[] args = new Object[] {
398 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId())
399 };
400
401 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
402 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
403 args);
404
405 args = new Object[] {
406 Long.valueOf(mbStatsUserModelImpl.getGroupId())
407 };
408
409 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
410 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
411 args);
412 }
413
414 if ((mbStatsUserModelImpl.getColumnBitmask() &
415 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
416 Object[] args = new Object[] {
417 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
418 };
419
420 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
421 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
422 args);
423
424 args = new Object[] {
425 Long.valueOf(mbStatsUserModelImpl.getUserId())
426 };
427
428 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
429 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
430 args);
431 }
432
433 if ((mbStatsUserModelImpl.getColumnBitmask() &
434 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM.getColumnBitmask()) != 0) {
435 Object[] args = new Object[] {
436 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
437 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId()),
438 Integer.valueOf(mbStatsUserModelImpl.getOriginalMessageCount())
439 };
440
441 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
442 args);
443 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM,
444 args);
445
446 args = new Object[] {
447 Long.valueOf(mbStatsUserModelImpl.getGroupId()),
448 Long.valueOf(mbStatsUserModelImpl.getUserId()),
449 Integer.valueOf(mbStatsUserModelImpl.getMessageCount())
450 };
451
452 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
453 args);
454 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM,
455 args);
456 }
457 }
458
459 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
460 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
461
462 if (isNew) {
463 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
464 new Object[] {
465 Long.valueOf(mbStatsUser.getGroupId()),
466 Long.valueOf(mbStatsUser.getUserId())
467 }, mbStatsUser);
468 }
469 else {
470 if ((mbStatsUserModelImpl.getColumnBitmask() &
471 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
472 Object[] args = new Object[] {
473 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
474 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
475 };
476
477 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
478 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
479
480 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
481 new Object[] {
482 Long.valueOf(mbStatsUser.getGroupId()),
483 Long.valueOf(mbStatsUser.getUserId())
484 }, mbStatsUser);
485 }
486 }
487
488 return mbStatsUser;
489 }
490
491 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
492 if (mbStatsUser instanceof MBStatsUserImpl) {
493 return mbStatsUser;
494 }
495
496 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
497
498 mbStatsUserImpl.setNew(mbStatsUser.isNew());
499 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
500
501 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
502 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
503 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
504 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
505 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
506
507 return mbStatsUserImpl;
508 }
509
510
518 @Override
519 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
520 throws NoSuchModelException, SystemException {
521 return findByPrimaryKey(((Long)primaryKey).longValue());
522 }
523
524
532 public MBStatsUser findByPrimaryKey(long statsUserId)
533 throws NoSuchStatsUserException, SystemException {
534 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
535
536 if (mbStatsUser == null) {
537 if (_log.isWarnEnabled()) {
538 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
539 }
540
541 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
542 statsUserId);
543 }
544
545 return mbStatsUser;
546 }
547
548
555 @Override
556 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
557 throws SystemException {
558 return fetchByPrimaryKey(((Long)primaryKey).longValue());
559 }
560
561
568 public MBStatsUser fetchByPrimaryKey(long statsUserId)
569 throws SystemException {
570 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
571 MBStatsUserImpl.class, statsUserId);
572
573 if (mbStatsUser == _nullMBStatsUser) {
574 return null;
575 }
576
577 if (mbStatsUser == null) {
578 Session session = null;
579
580 boolean hasException = false;
581
582 try {
583 session = openSession();
584
585 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
586 Long.valueOf(statsUserId));
587 }
588 catch (Exception e) {
589 hasException = true;
590
591 throw processException(e);
592 }
593 finally {
594 if (mbStatsUser != null) {
595 cacheResult(mbStatsUser);
596 }
597 else if (!hasException) {
598 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
599 MBStatsUserImpl.class, statsUserId, _nullMBStatsUser);
600 }
601
602 closeSession(session);
603 }
604 }
605
606 return mbStatsUser;
607 }
608
609
616 public List<MBStatsUser> findByGroupId(long groupId)
617 throws SystemException {
618 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
619 }
620
621
634 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
635 throws SystemException {
636 return findByGroupId(groupId, start, end, null);
637 }
638
639
653 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
654 OrderByComparator orderByComparator) throws SystemException {
655 FinderPath finderPath = null;
656 Object[] finderArgs = null;
657
658 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
659 (orderByComparator == null)) {
660 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
661 finderArgs = new Object[] { groupId };
662 }
663 else {
664 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
665 finderArgs = new Object[] { groupId, start, end, orderByComparator };
666 }
667
668 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
669 finderArgs, this);
670
671 if (list == null) {
672 StringBundler query = null;
673
674 if (orderByComparator != null) {
675 query = new StringBundler(3 +
676 (orderByComparator.getOrderByFields().length * 3));
677 }
678 else {
679 query = new StringBundler(3);
680 }
681
682 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
683
684 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
685
686 if (orderByComparator != null) {
687 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
688 orderByComparator);
689 }
690
691 else {
692 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
693 }
694
695 String sql = query.toString();
696
697 Session session = null;
698
699 try {
700 session = openSession();
701
702 Query q = session.createQuery(sql);
703
704 QueryPos qPos = QueryPos.getInstance(q);
705
706 qPos.add(groupId);
707
708 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
709 start, end);
710 }
711 catch (Exception e) {
712 throw processException(e);
713 }
714 finally {
715 if (list == null) {
716 FinderCacheUtil.removeResult(finderPath, finderArgs);
717 }
718 else {
719 cacheResult(list);
720
721 FinderCacheUtil.putResult(finderPath, finderArgs, list);
722 }
723
724 closeSession(session);
725 }
726 }
727
728 return list;
729 }
730
731
744 public MBStatsUser findByGroupId_First(long groupId,
745 OrderByComparator orderByComparator)
746 throws NoSuchStatsUserException, SystemException {
747 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
748
749 if (list.isEmpty()) {
750 StringBundler msg = new StringBundler(4);
751
752 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
753
754 msg.append("groupId=");
755 msg.append(groupId);
756
757 msg.append(StringPool.CLOSE_CURLY_BRACE);
758
759 throw new NoSuchStatsUserException(msg.toString());
760 }
761 else {
762 return list.get(0);
763 }
764 }
765
766
779 public MBStatsUser findByGroupId_Last(long groupId,
780 OrderByComparator orderByComparator)
781 throws NoSuchStatsUserException, SystemException {
782 int count = countByGroupId(groupId);
783
784 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
785 orderByComparator);
786
787 if (list.isEmpty()) {
788 StringBundler msg = new StringBundler(4);
789
790 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
791
792 msg.append("groupId=");
793 msg.append(groupId);
794
795 msg.append(StringPool.CLOSE_CURLY_BRACE);
796
797 throw new NoSuchStatsUserException(msg.toString());
798 }
799 else {
800 return list.get(0);
801 }
802 }
803
804
818 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
819 long groupId, OrderByComparator orderByComparator)
820 throws NoSuchStatsUserException, SystemException {
821 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
822
823 Session session = null;
824
825 try {
826 session = openSession();
827
828 MBStatsUser[] array = new MBStatsUserImpl[3];
829
830 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
831 orderByComparator, true);
832
833 array[1] = mbStatsUser;
834
835 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
836 orderByComparator, false);
837
838 return array;
839 }
840 catch (Exception e) {
841 throw processException(e);
842 }
843 finally {
844 closeSession(session);
845 }
846 }
847
848 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
849 MBStatsUser mbStatsUser, long groupId,
850 OrderByComparator orderByComparator, boolean previous) {
851 StringBundler query = null;
852
853 if (orderByComparator != null) {
854 query = new StringBundler(6 +
855 (orderByComparator.getOrderByFields().length * 6));
856 }
857 else {
858 query = new StringBundler(3);
859 }
860
861 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
862
863 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
864
865 if (orderByComparator != null) {
866 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
867
868 if (orderByConditionFields.length > 0) {
869 query.append(WHERE_AND);
870 }
871
872 for (int i = 0; i < orderByConditionFields.length; i++) {
873 query.append(_ORDER_BY_ENTITY_ALIAS);
874 query.append(orderByConditionFields[i]);
875
876 if ((i + 1) < orderByConditionFields.length) {
877 if (orderByComparator.isAscending() ^ previous) {
878 query.append(WHERE_GREATER_THAN_HAS_NEXT);
879 }
880 else {
881 query.append(WHERE_LESSER_THAN_HAS_NEXT);
882 }
883 }
884 else {
885 if (orderByComparator.isAscending() ^ previous) {
886 query.append(WHERE_GREATER_THAN);
887 }
888 else {
889 query.append(WHERE_LESSER_THAN);
890 }
891 }
892 }
893
894 query.append(ORDER_BY_CLAUSE);
895
896 String[] orderByFields = orderByComparator.getOrderByFields();
897
898 for (int i = 0; i < orderByFields.length; i++) {
899 query.append(_ORDER_BY_ENTITY_ALIAS);
900 query.append(orderByFields[i]);
901
902 if ((i + 1) < orderByFields.length) {
903 if (orderByComparator.isAscending() ^ previous) {
904 query.append(ORDER_BY_ASC_HAS_NEXT);
905 }
906 else {
907 query.append(ORDER_BY_DESC_HAS_NEXT);
908 }
909 }
910 else {
911 if (orderByComparator.isAscending() ^ previous) {
912 query.append(ORDER_BY_ASC);
913 }
914 else {
915 query.append(ORDER_BY_DESC);
916 }
917 }
918 }
919 }
920
921 else {
922 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
923 }
924
925 String sql = query.toString();
926
927 Query q = session.createQuery(sql);
928
929 q.setFirstResult(0);
930 q.setMaxResults(2);
931
932 QueryPos qPos = QueryPos.getInstance(q);
933
934 qPos.add(groupId);
935
936 if (orderByComparator != null) {
937 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
938
939 for (Object value : values) {
940 qPos.add(value);
941 }
942 }
943
944 List<MBStatsUser> list = q.list();
945
946 if (list.size() == 2) {
947 return list.get(1);
948 }
949 else {
950 return null;
951 }
952 }
953
954
961 public List<MBStatsUser> findByUserId(long userId)
962 throws SystemException {
963 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
964 }
965
966
979 public List<MBStatsUser> findByUserId(long userId, int start, int end)
980 throws SystemException {
981 return findByUserId(userId, start, end, null);
982 }
983
984
998 public List<MBStatsUser> findByUserId(long userId, int start, int end,
999 OrderByComparator orderByComparator) throws SystemException {
1000 FinderPath finderPath = null;
1001 Object[] finderArgs = null;
1002
1003 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1004 (orderByComparator == null)) {
1005 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1006 finderArgs = new Object[] { userId };
1007 }
1008 else {
1009 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1010 finderArgs = new Object[] { userId, start, end, orderByComparator };
1011 }
1012
1013 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1014 finderArgs, this);
1015
1016 if (list == null) {
1017 StringBundler query = null;
1018
1019 if (orderByComparator != null) {
1020 query = new StringBundler(3 +
1021 (orderByComparator.getOrderByFields().length * 3));
1022 }
1023 else {
1024 query = new StringBundler(3);
1025 }
1026
1027 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1028
1029 query.append(_FINDER_COLUMN_USERID_USERID_2);
1030
1031 if (orderByComparator != null) {
1032 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1033 orderByComparator);
1034 }
1035
1036 else {
1037 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1038 }
1039
1040 String sql = query.toString();
1041
1042 Session session = null;
1043
1044 try {
1045 session = openSession();
1046
1047 Query q = session.createQuery(sql);
1048
1049 QueryPos qPos = QueryPos.getInstance(q);
1050
1051 qPos.add(userId);
1052
1053 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1054 start, end);
1055 }
1056 catch (Exception e) {
1057 throw processException(e);
1058 }
1059 finally {
1060 if (list == null) {
1061 FinderCacheUtil.removeResult(finderPath, finderArgs);
1062 }
1063 else {
1064 cacheResult(list);
1065
1066 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1067 }
1068
1069 closeSession(session);
1070 }
1071 }
1072
1073 return list;
1074 }
1075
1076
1089 public MBStatsUser findByUserId_First(long userId,
1090 OrderByComparator orderByComparator)
1091 throws NoSuchStatsUserException, SystemException {
1092 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
1093
1094 if (list.isEmpty()) {
1095 StringBundler msg = new StringBundler(4);
1096
1097 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1098
1099 msg.append("userId=");
1100 msg.append(userId);
1101
1102 msg.append(StringPool.CLOSE_CURLY_BRACE);
1103
1104 throw new NoSuchStatsUserException(msg.toString());
1105 }
1106 else {
1107 return list.get(0);
1108 }
1109 }
1110
1111
1124 public MBStatsUser findByUserId_Last(long userId,
1125 OrderByComparator orderByComparator)
1126 throws NoSuchStatsUserException, SystemException {
1127 int count = countByUserId(userId);
1128
1129 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
1130 orderByComparator);
1131
1132 if (list.isEmpty()) {
1133 StringBundler msg = new StringBundler(4);
1134
1135 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1136
1137 msg.append("userId=");
1138 msg.append(userId);
1139
1140 msg.append(StringPool.CLOSE_CURLY_BRACE);
1141
1142 throw new NoSuchStatsUserException(msg.toString());
1143 }
1144 else {
1145 return list.get(0);
1146 }
1147 }
1148
1149
1163 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
1164 long userId, OrderByComparator orderByComparator)
1165 throws NoSuchStatsUserException, SystemException {
1166 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1167
1168 Session session = null;
1169
1170 try {
1171 session = openSession();
1172
1173 MBStatsUser[] array = new MBStatsUserImpl[3];
1174
1175 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1176 orderByComparator, true);
1177
1178 array[1] = mbStatsUser;
1179
1180 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1181 orderByComparator, false);
1182
1183 return array;
1184 }
1185 catch (Exception e) {
1186 throw processException(e);
1187 }
1188 finally {
1189 closeSession(session);
1190 }
1191 }
1192
1193 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1194 MBStatsUser mbStatsUser, long userId,
1195 OrderByComparator orderByComparator, boolean previous) {
1196 StringBundler query = null;
1197
1198 if (orderByComparator != null) {
1199 query = new StringBundler(6 +
1200 (orderByComparator.getOrderByFields().length * 6));
1201 }
1202 else {
1203 query = new StringBundler(3);
1204 }
1205
1206 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1207
1208 query.append(_FINDER_COLUMN_USERID_USERID_2);
1209
1210 if (orderByComparator != null) {
1211 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1212
1213 if (orderByConditionFields.length > 0) {
1214 query.append(WHERE_AND);
1215 }
1216
1217 for (int i = 0; i < orderByConditionFields.length; i++) {
1218 query.append(_ORDER_BY_ENTITY_ALIAS);
1219 query.append(orderByConditionFields[i]);
1220
1221 if ((i + 1) < orderByConditionFields.length) {
1222 if (orderByComparator.isAscending() ^ previous) {
1223 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1224 }
1225 else {
1226 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1227 }
1228 }
1229 else {
1230 if (orderByComparator.isAscending() ^ previous) {
1231 query.append(WHERE_GREATER_THAN);
1232 }
1233 else {
1234 query.append(WHERE_LESSER_THAN);
1235 }
1236 }
1237 }
1238
1239 query.append(ORDER_BY_CLAUSE);
1240
1241 String[] orderByFields = orderByComparator.getOrderByFields();
1242
1243 for (int i = 0; i < orderByFields.length; i++) {
1244 query.append(_ORDER_BY_ENTITY_ALIAS);
1245 query.append(orderByFields[i]);
1246
1247 if ((i + 1) < orderByFields.length) {
1248 if (orderByComparator.isAscending() ^ previous) {
1249 query.append(ORDER_BY_ASC_HAS_NEXT);
1250 }
1251 else {
1252 query.append(ORDER_BY_DESC_HAS_NEXT);
1253 }
1254 }
1255 else {
1256 if (orderByComparator.isAscending() ^ previous) {
1257 query.append(ORDER_BY_ASC);
1258 }
1259 else {
1260 query.append(ORDER_BY_DESC);
1261 }
1262 }
1263 }
1264 }
1265
1266 else {
1267 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1268 }
1269
1270 String sql = query.toString();
1271
1272 Query q = session.createQuery(sql);
1273
1274 q.setFirstResult(0);
1275 q.setMaxResults(2);
1276
1277 QueryPos qPos = QueryPos.getInstance(q);
1278
1279 qPos.add(userId);
1280
1281 if (orderByComparator != null) {
1282 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1283
1284 for (Object value : values) {
1285 qPos.add(value);
1286 }
1287 }
1288
1289 List<MBStatsUser> list = q.list();
1290
1291 if (list.size() == 2) {
1292 return list.get(1);
1293 }
1294 else {
1295 return null;
1296 }
1297 }
1298
1299
1308 public MBStatsUser findByG_U(long groupId, long userId)
1309 throws NoSuchStatsUserException, SystemException {
1310 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1311
1312 if (mbStatsUser == null) {
1313 StringBundler msg = new StringBundler(6);
1314
1315 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1316
1317 msg.append("groupId=");
1318 msg.append(groupId);
1319
1320 msg.append(", userId=");
1321 msg.append(userId);
1322
1323 msg.append(StringPool.CLOSE_CURLY_BRACE);
1324
1325 if (_log.isWarnEnabled()) {
1326 _log.warn(msg.toString());
1327 }
1328
1329 throw new NoSuchStatsUserException(msg.toString());
1330 }
1331
1332 return mbStatsUser;
1333 }
1334
1335
1343 public MBStatsUser fetchByG_U(long groupId, long userId)
1344 throws SystemException {
1345 return fetchByG_U(groupId, userId, true);
1346 }
1347
1348
1357 public MBStatsUser fetchByG_U(long groupId, long userId,
1358 boolean retrieveFromCache) throws SystemException {
1359 Object[] finderArgs = new Object[] { groupId, userId };
1360
1361 Object result = null;
1362
1363 if (retrieveFromCache) {
1364 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1365 finderArgs, this);
1366 }
1367
1368 if (result == null) {
1369 StringBundler query = new StringBundler(4);
1370
1371 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1372
1373 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1374
1375 query.append(_FINDER_COLUMN_G_U_USERID_2);
1376
1377 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1378
1379 String sql = query.toString();
1380
1381 Session session = null;
1382
1383 try {
1384 session = openSession();
1385
1386 Query q = session.createQuery(sql);
1387
1388 QueryPos qPos = QueryPos.getInstance(q);
1389
1390 qPos.add(groupId);
1391
1392 qPos.add(userId);
1393
1394 List<MBStatsUser> list = q.list();
1395
1396 result = list;
1397
1398 MBStatsUser mbStatsUser = null;
1399
1400 if (list.isEmpty()) {
1401 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1402 finderArgs, list);
1403 }
1404 else {
1405 mbStatsUser = list.get(0);
1406
1407 cacheResult(mbStatsUser);
1408
1409 if ((mbStatsUser.getGroupId() != groupId) ||
1410 (mbStatsUser.getUserId() != userId)) {
1411 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1412 finderArgs, mbStatsUser);
1413 }
1414 }
1415
1416 return mbStatsUser;
1417 }
1418 catch (Exception e) {
1419 throw processException(e);
1420 }
1421 finally {
1422 if (result == null) {
1423 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1424 finderArgs);
1425 }
1426
1427 closeSession(session);
1428 }
1429 }
1430 else {
1431 if (result instanceof List<?>) {
1432 return null;
1433 }
1434 else {
1435 return (MBStatsUser)result;
1436 }
1437 }
1438 }
1439
1440
1449 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1450 int messageCount) throws SystemException {
1451 return findByG_NotU_NotM(groupId, userId, messageCount,
1452 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1453 }
1454
1455
1470 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1471 int messageCount, int start, int end) throws SystemException {
1472 return findByG_NotU_NotM(groupId, userId, messageCount, start, end, null);
1473 }
1474
1475
1491 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1492 int messageCount, int start, int end,
1493 OrderByComparator orderByComparator) throws SystemException {
1494 FinderPath finderPath = null;
1495 Object[] finderArgs = null;
1496
1497 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1498 (orderByComparator == null)) {
1499 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM;
1500 finderArgs = new Object[] { groupId, userId, messageCount };
1501 }
1502 else {
1503 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM;
1504 finderArgs = new Object[] {
1505 groupId, userId, messageCount,
1506
1507 start, end, orderByComparator
1508 };
1509 }
1510
1511 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1512 finderArgs, this);
1513
1514 if (list == null) {
1515 StringBundler query = null;
1516
1517 if (orderByComparator != null) {
1518 query = new StringBundler(5 +
1519 (orderByComparator.getOrderByFields().length * 3));
1520 }
1521 else {
1522 query = new StringBundler(5);
1523 }
1524
1525 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1526
1527 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1528
1529 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1530
1531 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1532
1533 if (orderByComparator != null) {
1534 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1535 orderByComparator);
1536 }
1537
1538 else {
1539 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1540 }
1541
1542 String sql = query.toString();
1543
1544 Session session = null;
1545
1546 try {
1547 session = openSession();
1548
1549 Query q = session.createQuery(sql);
1550
1551 QueryPos qPos = QueryPos.getInstance(q);
1552
1553 qPos.add(groupId);
1554
1555 qPos.add(userId);
1556
1557 qPos.add(messageCount);
1558
1559 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1560 start, end);
1561 }
1562 catch (Exception e) {
1563 throw processException(e);
1564 }
1565 finally {
1566 if (list == null) {
1567 FinderCacheUtil.removeResult(finderPath, finderArgs);
1568 }
1569 else {
1570 cacheResult(list);
1571
1572 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1573 }
1574
1575 closeSession(session);
1576 }
1577 }
1578
1579 return list;
1580 }
1581
1582
1597 public MBStatsUser findByG_NotU_NotM_First(long groupId, long userId,
1598 int messageCount, OrderByComparator orderByComparator)
1599 throws NoSuchStatsUserException, SystemException {
1600 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1601 messageCount, 0, 1, orderByComparator);
1602
1603 if (list.isEmpty()) {
1604 StringBundler msg = new StringBundler(8);
1605
1606 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1607
1608 msg.append("groupId=");
1609 msg.append(groupId);
1610
1611 msg.append(", userId=");
1612 msg.append(userId);
1613
1614 msg.append(", messageCount=");
1615 msg.append(messageCount);
1616
1617 msg.append(StringPool.CLOSE_CURLY_BRACE);
1618
1619 throw new NoSuchStatsUserException(msg.toString());
1620 }
1621 else {
1622 return list.get(0);
1623 }
1624 }
1625
1626
1641 public MBStatsUser findByG_NotU_NotM_Last(long groupId, long userId,
1642 int messageCount, OrderByComparator orderByComparator)
1643 throws NoSuchStatsUserException, SystemException {
1644 int count = countByG_NotU_NotM(groupId, userId, messageCount);
1645
1646 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1647 messageCount, count - 1, count, orderByComparator);
1648
1649 if (list.isEmpty()) {
1650 StringBundler msg = new StringBundler(8);
1651
1652 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1653
1654 msg.append("groupId=");
1655 msg.append(groupId);
1656
1657 msg.append(", userId=");
1658 msg.append(userId);
1659
1660 msg.append(", messageCount=");
1661 msg.append(messageCount);
1662
1663 msg.append(StringPool.CLOSE_CURLY_BRACE);
1664
1665 throw new NoSuchStatsUserException(msg.toString());
1666 }
1667 else {
1668 return list.get(0);
1669 }
1670 }
1671
1672
1688 public MBStatsUser[] findByG_NotU_NotM_PrevAndNext(long statsUserId,
1689 long groupId, long userId, int messageCount,
1690 OrderByComparator orderByComparator)
1691 throws NoSuchStatsUserException, SystemException {
1692 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1693
1694 Session session = null;
1695
1696 try {
1697 session = openSession();
1698
1699 MBStatsUser[] array = new MBStatsUserImpl[3];
1700
1701 array[0] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1702 groupId, userId, messageCount, orderByComparator, true);
1703
1704 array[1] = mbStatsUser;
1705
1706 array[2] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1707 groupId, userId, messageCount, orderByComparator, false);
1708
1709 return array;
1710 }
1711 catch (Exception e) {
1712 throw processException(e);
1713 }
1714 finally {
1715 closeSession(session);
1716 }
1717 }
1718
1719 protected MBStatsUser getByG_NotU_NotM_PrevAndNext(Session session,
1720 MBStatsUser mbStatsUser, long groupId, long userId, int messageCount,
1721 OrderByComparator orderByComparator, boolean previous) {
1722 StringBundler query = null;
1723
1724 if (orderByComparator != null) {
1725 query = new StringBundler(6 +
1726 (orderByComparator.getOrderByFields().length * 6));
1727 }
1728 else {
1729 query = new StringBundler(3);
1730 }
1731
1732 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1733
1734 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1735
1736 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1737
1738 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1739
1740 if (orderByComparator != null) {
1741 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1742
1743 if (orderByConditionFields.length > 0) {
1744 query.append(WHERE_AND);
1745 }
1746
1747 for (int i = 0; i < orderByConditionFields.length; i++) {
1748 query.append(_ORDER_BY_ENTITY_ALIAS);
1749 query.append(orderByConditionFields[i]);
1750
1751 if ((i + 1) < orderByConditionFields.length) {
1752 if (orderByComparator.isAscending() ^ previous) {
1753 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1754 }
1755 else {
1756 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1757 }
1758 }
1759 else {
1760 if (orderByComparator.isAscending() ^ previous) {
1761 query.append(WHERE_GREATER_THAN);
1762 }
1763 else {
1764 query.append(WHERE_LESSER_THAN);
1765 }
1766 }
1767 }
1768
1769 query.append(ORDER_BY_CLAUSE);
1770
1771 String[] orderByFields = orderByComparator.getOrderByFields();
1772
1773 for (int i = 0; i < orderByFields.length; i++) {
1774 query.append(_ORDER_BY_ENTITY_ALIAS);
1775 query.append(orderByFields[i]);
1776
1777 if ((i + 1) < orderByFields.length) {
1778 if (orderByComparator.isAscending() ^ previous) {
1779 query.append(ORDER_BY_ASC_HAS_NEXT);
1780 }
1781 else {
1782 query.append(ORDER_BY_DESC_HAS_NEXT);
1783 }
1784 }
1785 else {
1786 if (orderByComparator.isAscending() ^ previous) {
1787 query.append(ORDER_BY_ASC);
1788 }
1789 else {
1790 query.append(ORDER_BY_DESC);
1791 }
1792 }
1793 }
1794 }
1795
1796 else {
1797 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1798 }
1799
1800 String sql = query.toString();
1801
1802 Query q = session.createQuery(sql);
1803
1804 q.setFirstResult(0);
1805 q.setMaxResults(2);
1806
1807 QueryPos qPos = QueryPos.getInstance(q);
1808
1809 qPos.add(groupId);
1810
1811 qPos.add(userId);
1812
1813 qPos.add(messageCount);
1814
1815 if (orderByComparator != null) {
1816 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1817
1818 for (Object value : values) {
1819 qPos.add(value);
1820 }
1821 }
1822
1823 List<MBStatsUser> list = q.list();
1824
1825 if (list.size() == 2) {
1826 return list.get(1);
1827 }
1828 else {
1829 return null;
1830 }
1831 }
1832
1833
1839 public List<MBStatsUser> findAll() throws SystemException {
1840 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1841 }
1842
1843
1855 public List<MBStatsUser> findAll(int start, int end)
1856 throws SystemException {
1857 return findAll(start, end, null);
1858 }
1859
1860
1873 public List<MBStatsUser> findAll(int start, int end,
1874 OrderByComparator orderByComparator) throws SystemException {
1875 FinderPath finderPath = null;
1876 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1877
1878 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1879 (orderByComparator == null)) {
1880 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1881 finderArgs = FINDER_ARGS_EMPTY;
1882 }
1883 else {
1884 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1885 finderArgs = new Object[] { start, end, orderByComparator };
1886 }
1887
1888 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1889 finderArgs, this);
1890
1891 if (list == null) {
1892 StringBundler query = null;
1893 String sql = null;
1894
1895 if (orderByComparator != null) {
1896 query = new StringBundler(2 +
1897 (orderByComparator.getOrderByFields().length * 3));
1898
1899 query.append(_SQL_SELECT_MBSTATSUSER);
1900
1901 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1902 orderByComparator);
1903
1904 sql = query.toString();
1905 }
1906 else {
1907 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1908 }
1909
1910 Session session = null;
1911
1912 try {
1913 session = openSession();
1914
1915 Query q = session.createQuery(sql);
1916
1917 if (orderByComparator == null) {
1918 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1919 start, end, false);
1920
1921 Collections.sort(list);
1922 }
1923 else {
1924 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1925 start, end);
1926 }
1927 }
1928 catch (Exception e) {
1929 throw processException(e);
1930 }
1931 finally {
1932 if (list == null) {
1933 FinderCacheUtil.removeResult(finderPath, finderArgs);
1934 }
1935 else {
1936 cacheResult(list);
1937
1938 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1939 }
1940
1941 closeSession(session);
1942 }
1943 }
1944
1945 return list;
1946 }
1947
1948
1954 public void removeByGroupId(long groupId) throws SystemException {
1955 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1956 mbStatsUserPersistence.remove(mbStatsUser);
1957 }
1958 }
1959
1960
1966 public void removeByUserId(long userId) throws SystemException {
1967 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1968 mbStatsUserPersistence.remove(mbStatsUser);
1969 }
1970 }
1971
1972
1979 public void removeByG_U(long groupId, long userId)
1980 throws NoSuchStatsUserException, SystemException {
1981 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1982
1983 mbStatsUserPersistence.remove(mbStatsUser);
1984 }
1985
1986
1994 public void removeByG_NotU_NotM(long groupId, long userId, int messageCount)
1995 throws SystemException {
1996 for (MBStatsUser mbStatsUser : findByG_NotU_NotM(groupId, userId,
1997 messageCount)) {
1998 mbStatsUserPersistence.remove(mbStatsUser);
1999 }
2000 }
2001
2002
2007 public void removeAll() throws SystemException {
2008 for (MBStatsUser mbStatsUser : findAll()) {
2009 mbStatsUserPersistence.remove(mbStatsUser);
2010 }
2011 }
2012
2013
2020 public int countByGroupId(long groupId) throws SystemException {
2021 Object[] finderArgs = new Object[] { groupId };
2022
2023 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2024 finderArgs, this);
2025
2026 if (count == null) {
2027 StringBundler query = new StringBundler(2);
2028
2029 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2030
2031 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2032
2033 String sql = query.toString();
2034
2035 Session session = null;
2036
2037 try {
2038 session = openSession();
2039
2040 Query q = session.createQuery(sql);
2041
2042 QueryPos qPos = QueryPos.getInstance(q);
2043
2044 qPos.add(groupId);
2045
2046 count = (Long)q.uniqueResult();
2047 }
2048 catch (Exception e) {
2049 throw processException(e);
2050 }
2051 finally {
2052 if (count == null) {
2053 count = Long.valueOf(0);
2054 }
2055
2056 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2057 finderArgs, count);
2058
2059 closeSession(session);
2060 }
2061 }
2062
2063 return count.intValue();
2064 }
2065
2066
2073 public int countByUserId(long userId) throws SystemException {
2074 Object[] finderArgs = new Object[] { userId };
2075
2076 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2077 finderArgs, this);
2078
2079 if (count == null) {
2080 StringBundler query = new StringBundler(2);
2081
2082 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2083
2084 query.append(_FINDER_COLUMN_USERID_USERID_2);
2085
2086 String sql = query.toString();
2087
2088 Session session = null;
2089
2090 try {
2091 session = openSession();
2092
2093 Query q = session.createQuery(sql);
2094
2095 QueryPos qPos = QueryPos.getInstance(q);
2096
2097 qPos.add(userId);
2098
2099 count = (Long)q.uniqueResult();
2100 }
2101 catch (Exception e) {
2102 throw processException(e);
2103 }
2104 finally {
2105 if (count == null) {
2106 count = Long.valueOf(0);
2107 }
2108
2109 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2110 finderArgs, count);
2111
2112 closeSession(session);
2113 }
2114 }
2115
2116 return count.intValue();
2117 }
2118
2119
2127 public int countByG_U(long groupId, long userId) throws SystemException {
2128 Object[] finderArgs = new Object[] { groupId, userId };
2129
2130 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2131 finderArgs, this);
2132
2133 if (count == null) {
2134 StringBundler query = new StringBundler(3);
2135
2136 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2137
2138 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2139
2140 query.append(_FINDER_COLUMN_G_U_USERID_2);
2141
2142 String sql = query.toString();
2143
2144 Session session = null;
2145
2146 try {
2147 session = openSession();
2148
2149 Query q = session.createQuery(sql);
2150
2151 QueryPos qPos = QueryPos.getInstance(q);
2152
2153 qPos.add(groupId);
2154
2155 qPos.add(userId);
2156
2157 count = (Long)q.uniqueResult();
2158 }
2159 catch (Exception e) {
2160 throw processException(e);
2161 }
2162 finally {
2163 if (count == null) {
2164 count = Long.valueOf(0);
2165 }
2166
2167 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2168 count);
2169
2170 closeSession(session);
2171 }
2172 }
2173
2174 return count.intValue();
2175 }
2176
2177
2186 public int countByG_NotU_NotM(long groupId, long userId, int messageCount)
2187 throws SystemException {
2188 Object[] finderArgs = new Object[] { groupId, userId, messageCount };
2189
2190 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
2191 finderArgs, this);
2192
2193 if (count == null) {
2194 StringBundler query = new StringBundler(4);
2195
2196 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2197
2198 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
2199
2200 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
2201
2202 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
2203
2204 String sql = query.toString();
2205
2206 Session session = null;
2207
2208 try {
2209 session = openSession();
2210
2211 Query q = session.createQuery(sql);
2212
2213 QueryPos qPos = QueryPos.getInstance(q);
2214
2215 qPos.add(groupId);
2216
2217 qPos.add(userId);
2218
2219 qPos.add(messageCount);
2220
2221 count = (Long)q.uniqueResult();
2222 }
2223 catch (Exception e) {
2224 throw processException(e);
2225 }
2226 finally {
2227 if (count == null) {
2228 count = Long.valueOf(0);
2229 }
2230
2231 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
2232 finderArgs, count);
2233
2234 closeSession(session);
2235 }
2236 }
2237
2238 return count.intValue();
2239 }
2240
2241
2247 public int countAll() throws SystemException {
2248 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2249 FINDER_ARGS_EMPTY, this);
2250
2251 if (count == null) {
2252 Session session = null;
2253
2254 try {
2255 session = openSession();
2256
2257 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2258
2259 count = (Long)q.uniqueResult();
2260 }
2261 catch (Exception e) {
2262 throw processException(e);
2263 }
2264 finally {
2265 if (count == null) {
2266 count = Long.valueOf(0);
2267 }
2268
2269 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2270 FINDER_ARGS_EMPTY, count);
2271
2272 closeSession(session);
2273 }
2274 }
2275
2276 return count.intValue();
2277 }
2278
2279
2282 public void afterPropertiesSet() {
2283 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2284 com.liferay.portal.util.PropsUtil.get(
2285 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2286
2287 if (listenerClassNames.length > 0) {
2288 try {
2289 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2290
2291 for (String listenerClassName : listenerClassNames) {
2292 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2293 listenerClassName));
2294 }
2295
2296 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2297 }
2298 catch (Exception e) {
2299 _log.error(e);
2300 }
2301 }
2302 }
2303
2304 public void destroy() {
2305 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2306 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2307 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2308 }
2309
2310 @BeanReference(type = MBBanPersistence.class)
2311 protected MBBanPersistence mbBanPersistence;
2312 @BeanReference(type = MBCategoryPersistence.class)
2313 protected MBCategoryPersistence mbCategoryPersistence;
2314 @BeanReference(type = MBDiscussionPersistence.class)
2315 protected MBDiscussionPersistence mbDiscussionPersistence;
2316 @BeanReference(type = MBMailingListPersistence.class)
2317 protected MBMailingListPersistence mbMailingListPersistence;
2318 @BeanReference(type = MBMessagePersistence.class)
2319 protected MBMessagePersistence mbMessagePersistence;
2320 @BeanReference(type = MBStatsUserPersistence.class)
2321 protected MBStatsUserPersistence mbStatsUserPersistence;
2322 @BeanReference(type = MBThreadPersistence.class)
2323 protected MBThreadPersistence mbThreadPersistence;
2324 @BeanReference(type = MBThreadFlagPersistence.class)
2325 protected MBThreadFlagPersistence mbThreadFlagPersistence;
2326 @BeanReference(type = GroupPersistence.class)
2327 protected GroupPersistence groupPersistence;
2328 @BeanReference(type = ResourcePersistence.class)
2329 protected ResourcePersistence resourcePersistence;
2330 @BeanReference(type = UserPersistence.class)
2331 protected UserPersistence userPersistence;
2332 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2333 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2334 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2335 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2336 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2337 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2338 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2339 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2340 private static final String _FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2341 private static final String _FINDER_COLUMN_G_NOTU_NOTM_USERID_2 = "mbStatsUser.userId != ? AND ";
2342 private static final String _FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2343 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2344 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2345 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2346 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2347 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2348 private static MBStatsUser _nullMBStatsUser = new MBStatsUserImpl() {
2349 @Override
2350 public Object clone() {
2351 return this;
2352 }
2353
2354 @Override
2355 public CacheModel<MBStatsUser> toCacheModel() {
2356 return _nullMBStatsUserCacheModel;
2357 }
2358 };
2359
2360 private static CacheModel<MBStatsUser> _nullMBStatsUserCacheModel = new CacheModel<MBStatsUser>() {
2361 public MBStatsUser toEntityModel() {
2362 return _nullMBStatsUser;
2363 }
2364 };
2365 }