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 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
386 else {
387 if ((mbStatsUserModelImpl.getColumnBitmask() &
388 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
389 Object[] args = new Object[] {
390 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId())
391 };
392
393 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
394 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
395 args);
396
397 args = new Object[] {
398 Long.valueOf(mbStatsUserModelImpl.getGroupId())
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
406 if ((mbStatsUserModelImpl.getColumnBitmask() &
407 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
408 Object[] args = new Object[] {
409 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
410 };
411
412 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
413 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
414 args);
415
416 args = new Object[] {
417 Long.valueOf(mbStatsUserModelImpl.getUserId())
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
425 if ((mbStatsUserModelImpl.getColumnBitmask() &
426 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM.getColumnBitmask()) != 0) {
427 Object[] args = new Object[] {
428 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
429 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId()),
430 Integer.valueOf(mbStatsUserModelImpl.getOriginalMessageCount())
431 };
432
433 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
434 args);
435 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM,
436 args);
437
438 args = new Object[] {
439 Long.valueOf(mbStatsUserModelImpl.getGroupId()),
440 Long.valueOf(mbStatsUserModelImpl.getUserId()),
441 Integer.valueOf(mbStatsUserModelImpl.getMessageCount())
442 };
443
444 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
445 args);
446 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM,
447 args);
448 }
449 }
450
451 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
452 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
453
454 if (isNew) {
455 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
456 new Object[] {
457 Long.valueOf(mbStatsUser.getGroupId()),
458 Long.valueOf(mbStatsUser.getUserId())
459 }, mbStatsUser);
460 }
461 else {
462 if ((mbStatsUserModelImpl.getColumnBitmask() &
463 FINDER_PATH_FETCH_BY_G_U.getColumnBitmask()) != 0) {
464 Object[] args = new Object[] {
465 Long.valueOf(mbStatsUserModelImpl.getOriginalGroupId()),
466 Long.valueOf(mbStatsUserModelImpl.getOriginalUserId())
467 };
468
469 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
470 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U, args);
471
472 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
473 new Object[] {
474 Long.valueOf(mbStatsUser.getGroupId()),
475 Long.valueOf(mbStatsUser.getUserId())
476 }, mbStatsUser);
477 }
478 }
479
480 return mbStatsUser;
481 }
482
483 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
484 if (mbStatsUser instanceof MBStatsUserImpl) {
485 return mbStatsUser;
486 }
487
488 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
489
490 mbStatsUserImpl.setNew(mbStatsUser.isNew());
491 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
492
493 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
494 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
495 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
496 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
497 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
498
499 return mbStatsUserImpl;
500 }
501
502
510 @Override
511 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
512 throws NoSuchModelException, SystemException {
513 return findByPrimaryKey(((Long)primaryKey).longValue());
514 }
515
516
524 public MBStatsUser findByPrimaryKey(long statsUserId)
525 throws NoSuchStatsUserException, SystemException {
526 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
527
528 if (mbStatsUser == null) {
529 if (_log.isWarnEnabled()) {
530 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
531 }
532
533 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
534 statsUserId);
535 }
536
537 return mbStatsUser;
538 }
539
540
547 @Override
548 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
549 throws SystemException {
550 return fetchByPrimaryKey(((Long)primaryKey).longValue());
551 }
552
553
560 public MBStatsUser fetchByPrimaryKey(long statsUserId)
561 throws SystemException {
562 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
563 MBStatsUserImpl.class, statsUserId);
564
565 if (mbStatsUser == _nullMBStatsUser) {
566 return null;
567 }
568
569 if (mbStatsUser == null) {
570 Session session = null;
571
572 boolean hasException = false;
573
574 try {
575 session = openSession();
576
577 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
578 Long.valueOf(statsUserId));
579 }
580 catch (Exception e) {
581 hasException = true;
582
583 throw processException(e);
584 }
585 finally {
586 if (mbStatsUser != null) {
587 cacheResult(mbStatsUser);
588 }
589 else if (!hasException) {
590 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
591 MBStatsUserImpl.class, statsUserId, _nullMBStatsUser);
592 }
593
594 closeSession(session);
595 }
596 }
597
598 return mbStatsUser;
599 }
600
601
608 public List<MBStatsUser> findByGroupId(long groupId)
609 throws SystemException {
610 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
611 }
612
613
626 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
627 throws SystemException {
628 return findByGroupId(groupId, start, end, null);
629 }
630
631
645 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
646 OrderByComparator orderByComparator) throws SystemException {
647 FinderPath finderPath = null;
648 Object[] finderArgs = null;
649
650 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
651 (orderByComparator == null)) {
652 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
653 finderArgs = new Object[] { groupId };
654 }
655 else {
656 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
657 finderArgs = new Object[] { groupId, start, end, orderByComparator };
658 }
659
660 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
661 finderArgs, this);
662
663 if (list == null) {
664 StringBundler query = null;
665
666 if (orderByComparator != null) {
667 query = new StringBundler(3 +
668 (orderByComparator.getOrderByFields().length * 3));
669 }
670 else {
671 query = new StringBundler(3);
672 }
673
674 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
675
676 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
677
678 if (orderByComparator != null) {
679 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
680 orderByComparator);
681 }
682
683 else {
684 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
685 }
686
687 String sql = query.toString();
688
689 Session session = null;
690
691 try {
692 session = openSession();
693
694 Query q = session.createQuery(sql);
695
696 QueryPos qPos = QueryPos.getInstance(q);
697
698 qPos.add(groupId);
699
700 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
701 start, end);
702 }
703 catch (Exception e) {
704 throw processException(e);
705 }
706 finally {
707 if (list == null) {
708 FinderCacheUtil.removeResult(finderPath, finderArgs);
709 }
710 else {
711 cacheResult(list);
712
713 FinderCacheUtil.putResult(finderPath, finderArgs, list);
714 }
715
716 closeSession(session);
717 }
718 }
719
720 return list;
721 }
722
723
736 public MBStatsUser findByGroupId_First(long groupId,
737 OrderByComparator orderByComparator)
738 throws NoSuchStatsUserException, SystemException {
739 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
740
741 if (list.isEmpty()) {
742 StringBundler msg = new StringBundler(4);
743
744 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
745
746 msg.append("groupId=");
747 msg.append(groupId);
748
749 msg.append(StringPool.CLOSE_CURLY_BRACE);
750
751 throw new NoSuchStatsUserException(msg.toString());
752 }
753 else {
754 return list.get(0);
755 }
756 }
757
758
771 public MBStatsUser findByGroupId_Last(long groupId,
772 OrderByComparator orderByComparator)
773 throws NoSuchStatsUserException, SystemException {
774 int count = countByGroupId(groupId);
775
776 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
777 orderByComparator);
778
779 if (list.isEmpty()) {
780 StringBundler msg = new StringBundler(4);
781
782 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
783
784 msg.append("groupId=");
785 msg.append(groupId);
786
787 msg.append(StringPool.CLOSE_CURLY_BRACE);
788
789 throw new NoSuchStatsUserException(msg.toString());
790 }
791 else {
792 return list.get(0);
793 }
794 }
795
796
810 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
811 long groupId, OrderByComparator orderByComparator)
812 throws NoSuchStatsUserException, SystemException {
813 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
814
815 Session session = null;
816
817 try {
818 session = openSession();
819
820 MBStatsUser[] array = new MBStatsUserImpl[3];
821
822 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
823 orderByComparator, true);
824
825 array[1] = mbStatsUser;
826
827 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
828 orderByComparator, false);
829
830 return array;
831 }
832 catch (Exception e) {
833 throw processException(e);
834 }
835 finally {
836 closeSession(session);
837 }
838 }
839
840 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
841 MBStatsUser mbStatsUser, long groupId,
842 OrderByComparator orderByComparator, boolean previous) {
843 StringBundler query = null;
844
845 if (orderByComparator != null) {
846 query = new StringBundler(6 +
847 (orderByComparator.getOrderByFields().length * 6));
848 }
849 else {
850 query = new StringBundler(3);
851 }
852
853 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
854
855 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
856
857 if (orderByComparator != null) {
858 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
859
860 if (orderByConditionFields.length > 0) {
861 query.append(WHERE_AND);
862 }
863
864 for (int i = 0; i < orderByConditionFields.length; i++) {
865 query.append(_ORDER_BY_ENTITY_ALIAS);
866 query.append(orderByConditionFields[i]);
867
868 if ((i + 1) < orderByConditionFields.length) {
869 if (orderByComparator.isAscending() ^ previous) {
870 query.append(WHERE_GREATER_THAN_HAS_NEXT);
871 }
872 else {
873 query.append(WHERE_LESSER_THAN_HAS_NEXT);
874 }
875 }
876 else {
877 if (orderByComparator.isAscending() ^ previous) {
878 query.append(WHERE_GREATER_THAN);
879 }
880 else {
881 query.append(WHERE_LESSER_THAN);
882 }
883 }
884 }
885
886 query.append(ORDER_BY_CLAUSE);
887
888 String[] orderByFields = orderByComparator.getOrderByFields();
889
890 for (int i = 0; i < orderByFields.length; i++) {
891 query.append(_ORDER_BY_ENTITY_ALIAS);
892 query.append(orderByFields[i]);
893
894 if ((i + 1) < orderByFields.length) {
895 if (orderByComparator.isAscending() ^ previous) {
896 query.append(ORDER_BY_ASC_HAS_NEXT);
897 }
898 else {
899 query.append(ORDER_BY_DESC_HAS_NEXT);
900 }
901 }
902 else {
903 if (orderByComparator.isAscending() ^ previous) {
904 query.append(ORDER_BY_ASC);
905 }
906 else {
907 query.append(ORDER_BY_DESC);
908 }
909 }
910 }
911 }
912
913 else {
914 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
915 }
916
917 String sql = query.toString();
918
919 Query q = session.createQuery(sql);
920
921 q.setFirstResult(0);
922 q.setMaxResults(2);
923
924 QueryPos qPos = QueryPos.getInstance(q);
925
926 qPos.add(groupId);
927
928 if (orderByComparator != null) {
929 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
930
931 for (Object value : values) {
932 qPos.add(value);
933 }
934 }
935
936 List<MBStatsUser> list = q.list();
937
938 if (list.size() == 2) {
939 return list.get(1);
940 }
941 else {
942 return null;
943 }
944 }
945
946
953 public List<MBStatsUser> findByUserId(long userId)
954 throws SystemException {
955 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
956 }
957
958
971 public List<MBStatsUser> findByUserId(long userId, int start, int end)
972 throws SystemException {
973 return findByUserId(userId, start, end, null);
974 }
975
976
990 public List<MBStatsUser> findByUserId(long userId, int start, int end,
991 OrderByComparator orderByComparator) throws SystemException {
992 FinderPath finderPath = null;
993 Object[] finderArgs = null;
994
995 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
996 (orderByComparator == null)) {
997 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
998 finderArgs = new Object[] { userId };
999 }
1000 else {
1001 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1002 finderArgs = new Object[] { userId, start, end, orderByComparator };
1003 }
1004
1005 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1006 finderArgs, this);
1007
1008 if (list == null) {
1009 StringBundler query = null;
1010
1011 if (orderByComparator != null) {
1012 query = new StringBundler(3 +
1013 (orderByComparator.getOrderByFields().length * 3));
1014 }
1015 else {
1016 query = new StringBundler(3);
1017 }
1018
1019 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1020
1021 query.append(_FINDER_COLUMN_USERID_USERID_2);
1022
1023 if (orderByComparator != null) {
1024 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1025 orderByComparator);
1026 }
1027
1028 else {
1029 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1030 }
1031
1032 String sql = query.toString();
1033
1034 Session session = null;
1035
1036 try {
1037 session = openSession();
1038
1039 Query q = session.createQuery(sql);
1040
1041 QueryPos qPos = QueryPos.getInstance(q);
1042
1043 qPos.add(userId);
1044
1045 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1046 start, end);
1047 }
1048 catch (Exception e) {
1049 throw processException(e);
1050 }
1051 finally {
1052 if (list == null) {
1053 FinderCacheUtil.removeResult(finderPath, finderArgs);
1054 }
1055 else {
1056 cacheResult(list);
1057
1058 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1059 }
1060
1061 closeSession(session);
1062 }
1063 }
1064
1065 return list;
1066 }
1067
1068
1081 public MBStatsUser findByUserId_First(long userId,
1082 OrderByComparator orderByComparator)
1083 throws NoSuchStatsUserException, SystemException {
1084 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
1085
1086 if (list.isEmpty()) {
1087 StringBundler msg = new StringBundler(4);
1088
1089 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1090
1091 msg.append("userId=");
1092 msg.append(userId);
1093
1094 msg.append(StringPool.CLOSE_CURLY_BRACE);
1095
1096 throw new NoSuchStatsUserException(msg.toString());
1097 }
1098 else {
1099 return list.get(0);
1100 }
1101 }
1102
1103
1116 public MBStatsUser findByUserId_Last(long userId,
1117 OrderByComparator orderByComparator)
1118 throws NoSuchStatsUserException, SystemException {
1119 int count = countByUserId(userId);
1120
1121 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
1122 orderByComparator);
1123
1124 if (list.isEmpty()) {
1125 StringBundler msg = new StringBundler(4);
1126
1127 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1128
1129 msg.append("userId=");
1130 msg.append(userId);
1131
1132 msg.append(StringPool.CLOSE_CURLY_BRACE);
1133
1134 throw new NoSuchStatsUserException(msg.toString());
1135 }
1136 else {
1137 return list.get(0);
1138 }
1139 }
1140
1141
1155 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
1156 long userId, OrderByComparator orderByComparator)
1157 throws NoSuchStatsUserException, SystemException {
1158 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1159
1160 Session session = null;
1161
1162 try {
1163 session = openSession();
1164
1165 MBStatsUser[] array = new MBStatsUserImpl[3];
1166
1167 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1168 orderByComparator, true);
1169
1170 array[1] = mbStatsUser;
1171
1172 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
1173 orderByComparator, false);
1174
1175 return array;
1176 }
1177 catch (Exception e) {
1178 throw processException(e);
1179 }
1180 finally {
1181 closeSession(session);
1182 }
1183 }
1184
1185 protected MBStatsUser getByUserId_PrevAndNext(Session session,
1186 MBStatsUser mbStatsUser, long userId,
1187 OrderByComparator orderByComparator, boolean previous) {
1188 StringBundler query = null;
1189
1190 if (orderByComparator != null) {
1191 query = new StringBundler(6 +
1192 (orderByComparator.getOrderByFields().length * 6));
1193 }
1194 else {
1195 query = new StringBundler(3);
1196 }
1197
1198 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1199
1200 query.append(_FINDER_COLUMN_USERID_USERID_2);
1201
1202 if (orderByComparator != null) {
1203 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1204
1205 if (orderByConditionFields.length > 0) {
1206 query.append(WHERE_AND);
1207 }
1208
1209 for (int i = 0; i < orderByConditionFields.length; i++) {
1210 query.append(_ORDER_BY_ENTITY_ALIAS);
1211 query.append(orderByConditionFields[i]);
1212
1213 if ((i + 1) < orderByConditionFields.length) {
1214 if (orderByComparator.isAscending() ^ previous) {
1215 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1216 }
1217 else {
1218 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1219 }
1220 }
1221 else {
1222 if (orderByComparator.isAscending() ^ previous) {
1223 query.append(WHERE_GREATER_THAN);
1224 }
1225 else {
1226 query.append(WHERE_LESSER_THAN);
1227 }
1228 }
1229 }
1230
1231 query.append(ORDER_BY_CLAUSE);
1232
1233 String[] orderByFields = orderByComparator.getOrderByFields();
1234
1235 for (int i = 0; i < orderByFields.length; i++) {
1236 query.append(_ORDER_BY_ENTITY_ALIAS);
1237 query.append(orderByFields[i]);
1238
1239 if ((i + 1) < orderByFields.length) {
1240 if (orderByComparator.isAscending() ^ previous) {
1241 query.append(ORDER_BY_ASC_HAS_NEXT);
1242 }
1243 else {
1244 query.append(ORDER_BY_DESC_HAS_NEXT);
1245 }
1246 }
1247 else {
1248 if (orderByComparator.isAscending() ^ previous) {
1249 query.append(ORDER_BY_ASC);
1250 }
1251 else {
1252 query.append(ORDER_BY_DESC);
1253 }
1254 }
1255 }
1256 }
1257
1258 else {
1259 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1260 }
1261
1262 String sql = query.toString();
1263
1264 Query q = session.createQuery(sql);
1265
1266 q.setFirstResult(0);
1267 q.setMaxResults(2);
1268
1269 QueryPos qPos = QueryPos.getInstance(q);
1270
1271 qPos.add(userId);
1272
1273 if (orderByComparator != null) {
1274 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1275
1276 for (Object value : values) {
1277 qPos.add(value);
1278 }
1279 }
1280
1281 List<MBStatsUser> list = q.list();
1282
1283 if (list.size() == 2) {
1284 return list.get(1);
1285 }
1286 else {
1287 return null;
1288 }
1289 }
1290
1291
1300 public MBStatsUser findByG_U(long groupId, long userId)
1301 throws NoSuchStatsUserException, SystemException {
1302 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
1303
1304 if (mbStatsUser == null) {
1305 StringBundler msg = new StringBundler(6);
1306
1307 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1308
1309 msg.append("groupId=");
1310 msg.append(groupId);
1311
1312 msg.append(", userId=");
1313 msg.append(userId);
1314
1315 msg.append(StringPool.CLOSE_CURLY_BRACE);
1316
1317 if (_log.isWarnEnabled()) {
1318 _log.warn(msg.toString());
1319 }
1320
1321 throw new NoSuchStatsUserException(msg.toString());
1322 }
1323
1324 return mbStatsUser;
1325 }
1326
1327
1335 public MBStatsUser fetchByG_U(long groupId, long userId)
1336 throws SystemException {
1337 return fetchByG_U(groupId, userId, true);
1338 }
1339
1340
1349 public MBStatsUser fetchByG_U(long groupId, long userId,
1350 boolean retrieveFromCache) throws SystemException {
1351 Object[] finderArgs = new Object[] { groupId, userId };
1352
1353 Object result = null;
1354
1355 if (retrieveFromCache) {
1356 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
1357 finderArgs, this);
1358 }
1359
1360 if (result == null) {
1361 StringBundler query = new StringBundler(4);
1362
1363 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1364
1365 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1366
1367 query.append(_FINDER_COLUMN_G_U_USERID_2);
1368
1369 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1370
1371 String sql = query.toString();
1372
1373 Session session = null;
1374
1375 try {
1376 session = openSession();
1377
1378 Query q = session.createQuery(sql);
1379
1380 QueryPos qPos = QueryPos.getInstance(q);
1381
1382 qPos.add(groupId);
1383
1384 qPos.add(userId);
1385
1386 List<MBStatsUser> list = q.list();
1387
1388 result = list;
1389
1390 MBStatsUser mbStatsUser = null;
1391
1392 if (list.isEmpty()) {
1393 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1394 finderArgs, list);
1395 }
1396 else {
1397 mbStatsUser = list.get(0);
1398
1399 cacheResult(mbStatsUser);
1400
1401 if ((mbStatsUser.getGroupId() != groupId) ||
1402 (mbStatsUser.getUserId() != userId)) {
1403 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1404 finderArgs, mbStatsUser);
1405 }
1406 }
1407
1408 return mbStatsUser;
1409 }
1410 catch (Exception e) {
1411 throw processException(e);
1412 }
1413 finally {
1414 if (result == null) {
1415 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
1416 finderArgs);
1417 }
1418
1419 closeSession(session);
1420 }
1421 }
1422 else {
1423 if (result instanceof List<?>) {
1424 return null;
1425 }
1426 else {
1427 return (MBStatsUser)result;
1428 }
1429 }
1430 }
1431
1432
1441 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1442 int messageCount) throws SystemException {
1443 return findByG_NotU_NotM(groupId, userId, messageCount,
1444 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1445 }
1446
1447
1462 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1463 int messageCount, int start, int end) throws SystemException {
1464 return findByG_NotU_NotM(groupId, userId, messageCount, start, end, null);
1465 }
1466
1467
1483 public List<MBStatsUser> findByG_NotU_NotM(long groupId, long userId,
1484 int messageCount, int start, int end,
1485 OrderByComparator orderByComparator) throws SystemException {
1486 FinderPath finderPath = null;
1487 Object[] finderArgs = null;
1488
1489 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1490 (orderByComparator == null)) {
1491 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_NOTU_NOTM;
1492 finderArgs = new Object[] { groupId, userId, messageCount };
1493 }
1494 else {
1495 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_NOTU_NOTM;
1496 finderArgs = new Object[] {
1497 groupId, userId, messageCount,
1498
1499 start, end, orderByComparator
1500 };
1501 }
1502
1503 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1504 finderArgs, this);
1505
1506 if (list == null) {
1507 StringBundler query = null;
1508
1509 if (orderByComparator != null) {
1510 query = new StringBundler(5 +
1511 (orderByComparator.getOrderByFields().length * 3));
1512 }
1513 else {
1514 query = new StringBundler(5);
1515 }
1516
1517 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1518
1519 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1520
1521 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1522
1523 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1524
1525 if (orderByComparator != null) {
1526 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1527 orderByComparator);
1528 }
1529
1530 else {
1531 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1532 }
1533
1534 String sql = query.toString();
1535
1536 Session session = null;
1537
1538 try {
1539 session = openSession();
1540
1541 Query q = session.createQuery(sql);
1542
1543 QueryPos qPos = QueryPos.getInstance(q);
1544
1545 qPos.add(groupId);
1546
1547 qPos.add(userId);
1548
1549 qPos.add(messageCount);
1550
1551 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1552 start, end);
1553 }
1554 catch (Exception e) {
1555 throw processException(e);
1556 }
1557 finally {
1558 if (list == null) {
1559 FinderCacheUtil.removeResult(finderPath, finderArgs);
1560 }
1561 else {
1562 cacheResult(list);
1563
1564 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1565 }
1566
1567 closeSession(session);
1568 }
1569 }
1570
1571 return list;
1572 }
1573
1574
1589 public MBStatsUser findByG_NotU_NotM_First(long groupId, long userId,
1590 int messageCount, OrderByComparator orderByComparator)
1591 throws NoSuchStatsUserException, SystemException {
1592 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1593 messageCount, 0, 1, orderByComparator);
1594
1595 if (list.isEmpty()) {
1596 StringBundler msg = new StringBundler(8);
1597
1598 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1599
1600 msg.append("groupId=");
1601 msg.append(groupId);
1602
1603 msg.append(", userId=");
1604 msg.append(userId);
1605
1606 msg.append(", messageCount=");
1607 msg.append(messageCount);
1608
1609 msg.append(StringPool.CLOSE_CURLY_BRACE);
1610
1611 throw new NoSuchStatsUserException(msg.toString());
1612 }
1613 else {
1614 return list.get(0);
1615 }
1616 }
1617
1618
1633 public MBStatsUser findByG_NotU_NotM_Last(long groupId, long userId,
1634 int messageCount, OrderByComparator orderByComparator)
1635 throws NoSuchStatsUserException, SystemException {
1636 int count = countByG_NotU_NotM(groupId, userId, messageCount);
1637
1638 List<MBStatsUser> list = findByG_NotU_NotM(groupId, userId,
1639 messageCount, count - 1, count, orderByComparator);
1640
1641 if (list.isEmpty()) {
1642 StringBundler msg = new StringBundler(8);
1643
1644 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1645
1646 msg.append("groupId=");
1647 msg.append(groupId);
1648
1649 msg.append(", userId=");
1650 msg.append(userId);
1651
1652 msg.append(", messageCount=");
1653 msg.append(messageCount);
1654
1655 msg.append(StringPool.CLOSE_CURLY_BRACE);
1656
1657 throw new NoSuchStatsUserException(msg.toString());
1658 }
1659 else {
1660 return list.get(0);
1661 }
1662 }
1663
1664
1680 public MBStatsUser[] findByG_NotU_NotM_PrevAndNext(long statsUserId,
1681 long groupId, long userId, int messageCount,
1682 OrderByComparator orderByComparator)
1683 throws NoSuchStatsUserException, SystemException {
1684 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1685
1686 Session session = null;
1687
1688 try {
1689 session = openSession();
1690
1691 MBStatsUser[] array = new MBStatsUserImpl[3];
1692
1693 array[0] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1694 groupId, userId, messageCount, orderByComparator, true);
1695
1696 array[1] = mbStatsUser;
1697
1698 array[2] = getByG_NotU_NotM_PrevAndNext(session, mbStatsUser,
1699 groupId, userId, messageCount, orderByComparator, false);
1700
1701 return array;
1702 }
1703 catch (Exception e) {
1704 throw processException(e);
1705 }
1706 finally {
1707 closeSession(session);
1708 }
1709 }
1710
1711 protected MBStatsUser getByG_NotU_NotM_PrevAndNext(Session session,
1712 MBStatsUser mbStatsUser, long groupId, long userId, int messageCount,
1713 OrderByComparator orderByComparator, boolean previous) {
1714 StringBundler query = null;
1715
1716 if (orderByComparator != null) {
1717 query = new StringBundler(6 +
1718 (orderByComparator.getOrderByFields().length * 6));
1719 }
1720 else {
1721 query = new StringBundler(3);
1722 }
1723
1724 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1725
1726 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
1727
1728 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
1729
1730 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
1731
1732 if (orderByComparator != null) {
1733 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1734
1735 if (orderByConditionFields.length > 0) {
1736 query.append(WHERE_AND);
1737 }
1738
1739 for (int i = 0; i < orderByConditionFields.length; i++) {
1740 query.append(_ORDER_BY_ENTITY_ALIAS);
1741 query.append(orderByConditionFields[i]);
1742
1743 if ((i + 1) < orderByConditionFields.length) {
1744 if (orderByComparator.isAscending() ^ previous) {
1745 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1746 }
1747 else {
1748 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1749 }
1750 }
1751 else {
1752 if (orderByComparator.isAscending() ^ previous) {
1753 query.append(WHERE_GREATER_THAN);
1754 }
1755 else {
1756 query.append(WHERE_LESSER_THAN);
1757 }
1758 }
1759 }
1760
1761 query.append(ORDER_BY_CLAUSE);
1762
1763 String[] orderByFields = orderByComparator.getOrderByFields();
1764
1765 for (int i = 0; i < orderByFields.length; i++) {
1766 query.append(_ORDER_BY_ENTITY_ALIAS);
1767 query.append(orderByFields[i]);
1768
1769 if ((i + 1) < orderByFields.length) {
1770 if (orderByComparator.isAscending() ^ previous) {
1771 query.append(ORDER_BY_ASC_HAS_NEXT);
1772 }
1773 else {
1774 query.append(ORDER_BY_DESC_HAS_NEXT);
1775 }
1776 }
1777 else {
1778 if (orderByComparator.isAscending() ^ previous) {
1779 query.append(ORDER_BY_ASC);
1780 }
1781 else {
1782 query.append(ORDER_BY_DESC);
1783 }
1784 }
1785 }
1786 }
1787
1788 else {
1789 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1790 }
1791
1792 String sql = query.toString();
1793
1794 Query q = session.createQuery(sql);
1795
1796 q.setFirstResult(0);
1797 q.setMaxResults(2);
1798
1799 QueryPos qPos = QueryPos.getInstance(q);
1800
1801 qPos.add(groupId);
1802
1803 qPos.add(userId);
1804
1805 qPos.add(messageCount);
1806
1807 if (orderByComparator != null) {
1808 Object[] values = orderByComparator.getOrderByConditionValues(mbStatsUser);
1809
1810 for (Object value : values) {
1811 qPos.add(value);
1812 }
1813 }
1814
1815 List<MBStatsUser> list = q.list();
1816
1817 if (list.size() == 2) {
1818 return list.get(1);
1819 }
1820 else {
1821 return null;
1822 }
1823 }
1824
1825
1831 public List<MBStatsUser> findAll() throws SystemException {
1832 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1833 }
1834
1835
1847 public List<MBStatsUser> findAll(int start, int end)
1848 throws SystemException {
1849 return findAll(start, end, null);
1850 }
1851
1852
1865 public List<MBStatsUser> findAll(int start, int end,
1866 OrderByComparator orderByComparator) throws SystemException {
1867 FinderPath finderPath = null;
1868 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1869
1870 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1871 (orderByComparator == null)) {
1872 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1873 finderArgs = FINDER_ARGS_EMPTY;
1874 }
1875 else {
1876 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1877 finderArgs = new Object[] { start, end, orderByComparator };
1878 }
1879
1880 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(finderPath,
1881 finderArgs, this);
1882
1883 if (list == null) {
1884 StringBundler query = null;
1885 String sql = null;
1886
1887 if (orderByComparator != null) {
1888 query = new StringBundler(2 +
1889 (orderByComparator.getOrderByFields().length * 3));
1890
1891 query.append(_SQL_SELECT_MBSTATSUSER);
1892
1893 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1894 orderByComparator);
1895
1896 sql = query.toString();
1897 }
1898 else {
1899 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1900 }
1901
1902 Session session = null;
1903
1904 try {
1905 session = openSession();
1906
1907 Query q = session.createQuery(sql);
1908
1909 if (orderByComparator == null) {
1910 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1911 start, end, false);
1912
1913 Collections.sort(list);
1914 }
1915 else {
1916 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1917 start, end);
1918 }
1919 }
1920 catch (Exception e) {
1921 throw processException(e);
1922 }
1923 finally {
1924 if (list == null) {
1925 FinderCacheUtil.removeResult(finderPath, finderArgs);
1926 }
1927 else {
1928 cacheResult(list);
1929
1930 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1931 }
1932
1933 closeSession(session);
1934 }
1935 }
1936
1937 return list;
1938 }
1939
1940
1946 public void removeByGroupId(long groupId) throws SystemException {
1947 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1948 remove(mbStatsUser);
1949 }
1950 }
1951
1952
1958 public void removeByUserId(long userId) throws SystemException {
1959 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1960 remove(mbStatsUser);
1961 }
1962 }
1963
1964
1971 public void removeByG_U(long groupId, long userId)
1972 throws NoSuchStatsUserException, SystemException {
1973 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1974
1975 remove(mbStatsUser);
1976 }
1977
1978
1986 public void removeByG_NotU_NotM(long groupId, long userId, int messageCount)
1987 throws SystemException {
1988 for (MBStatsUser mbStatsUser : findByG_NotU_NotM(groupId, userId,
1989 messageCount)) {
1990 remove(mbStatsUser);
1991 }
1992 }
1993
1994
1999 public void removeAll() throws SystemException {
2000 for (MBStatsUser mbStatsUser : findAll()) {
2001 remove(mbStatsUser);
2002 }
2003 }
2004
2005
2012 public int countByGroupId(long groupId) throws SystemException {
2013 Object[] finderArgs = new Object[] { groupId };
2014
2015 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2016 finderArgs, this);
2017
2018 if (count == null) {
2019 StringBundler query = new StringBundler(2);
2020
2021 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2022
2023 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2024
2025 String sql = query.toString();
2026
2027 Session session = null;
2028
2029 try {
2030 session = openSession();
2031
2032 Query q = session.createQuery(sql);
2033
2034 QueryPos qPos = QueryPos.getInstance(q);
2035
2036 qPos.add(groupId);
2037
2038 count = (Long)q.uniqueResult();
2039 }
2040 catch (Exception e) {
2041 throw processException(e);
2042 }
2043 finally {
2044 if (count == null) {
2045 count = Long.valueOf(0);
2046 }
2047
2048 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2049 finderArgs, count);
2050
2051 closeSession(session);
2052 }
2053 }
2054
2055 return count.intValue();
2056 }
2057
2058
2065 public int countByUserId(long userId) throws SystemException {
2066 Object[] finderArgs = new Object[] { userId };
2067
2068 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
2069 finderArgs, this);
2070
2071 if (count == null) {
2072 StringBundler query = new StringBundler(2);
2073
2074 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2075
2076 query.append(_FINDER_COLUMN_USERID_USERID_2);
2077
2078 String sql = query.toString();
2079
2080 Session session = null;
2081
2082 try {
2083 session = openSession();
2084
2085 Query q = session.createQuery(sql);
2086
2087 QueryPos qPos = QueryPos.getInstance(q);
2088
2089 qPos.add(userId);
2090
2091 count = (Long)q.uniqueResult();
2092 }
2093 catch (Exception e) {
2094 throw processException(e);
2095 }
2096 finally {
2097 if (count == null) {
2098 count = Long.valueOf(0);
2099 }
2100
2101 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
2102 finderArgs, count);
2103
2104 closeSession(session);
2105 }
2106 }
2107
2108 return count.intValue();
2109 }
2110
2111
2119 public int countByG_U(long groupId, long userId) throws SystemException {
2120 Object[] finderArgs = new Object[] { groupId, userId };
2121
2122 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
2123 finderArgs, this);
2124
2125 if (count == null) {
2126 StringBundler query = new StringBundler(3);
2127
2128 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2129
2130 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
2131
2132 query.append(_FINDER_COLUMN_G_U_USERID_2);
2133
2134 String sql = query.toString();
2135
2136 Session session = null;
2137
2138 try {
2139 session = openSession();
2140
2141 Query q = session.createQuery(sql);
2142
2143 QueryPos qPos = QueryPos.getInstance(q);
2144
2145 qPos.add(groupId);
2146
2147 qPos.add(userId);
2148
2149 count = (Long)q.uniqueResult();
2150 }
2151 catch (Exception e) {
2152 throw processException(e);
2153 }
2154 finally {
2155 if (count == null) {
2156 count = Long.valueOf(0);
2157 }
2158
2159 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
2160 count);
2161
2162 closeSession(session);
2163 }
2164 }
2165
2166 return count.intValue();
2167 }
2168
2169
2178 public int countByG_NotU_NotM(long groupId, long userId, int messageCount)
2179 throws SystemException {
2180 Object[] finderArgs = new Object[] { groupId, userId, messageCount };
2181
2182 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
2183 finderArgs, this);
2184
2185 if (count == null) {
2186 StringBundler query = new StringBundler(4);
2187
2188 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
2189
2190 query.append(_FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2);
2191
2192 query.append(_FINDER_COLUMN_G_NOTU_NOTM_USERID_2);
2193
2194 query.append(_FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2);
2195
2196 String sql = query.toString();
2197
2198 Session session = null;
2199
2200 try {
2201 session = openSession();
2202
2203 Query q = session.createQuery(sql);
2204
2205 QueryPos qPos = QueryPos.getInstance(q);
2206
2207 qPos.add(groupId);
2208
2209 qPos.add(userId);
2210
2211 qPos.add(messageCount);
2212
2213 count = (Long)q.uniqueResult();
2214 }
2215 catch (Exception e) {
2216 throw processException(e);
2217 }
2218 finally {
2219 if (count == null) {
2220 count = Long.valueOf(0);
2221 }
2222
2223 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTU_NOTM,
2224 finderArgs, count);
2225
2226 closeSession(session);
2227 }
2228 }
2229
2230 return count.intValue();
2231 }
2232
2233
2239 public int countAll() throws SystemException {
2240 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2241 FINDER_ARGS_EMPTY, this);
2242
2243 if (count == null) {
2244 Session session = null;
2245
2246 try {
2247 session = openSession();
2248
2249 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
2250
2251 count = (Long)q.uniqueResult();
2252 }
2253 catch (Exception e) {
2254 throw processException(e);
2255 }
2256 finally {
2257 if (count == null) {
2258 count = Long.valueOf(0);
2259 }
2260
2261 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2262 FINDER_ARGS_EMPTY, count);
2263
2264 closeSession(session);
2265 }
2266 }
2267
2268 return count.intValue();
2269 }
2270
2271
2274 public void afterPropertiesSet() {
2275 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2276 com.liferay.portal.util.PropsUtil.get(
2277 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
2278
2279 if (listenerClassNames.length > 0) {
2280 try {
2281 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
2282
2283 for (String listenerClassName : listenerClassNames) {
2284 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
2285 listenerClassName));
2286 }
2287
2288 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2289 }
2290 catch (Exception e) {
2291 _log.error(e);
2292 }
2293 }
2294 }
2295
2296 public void destroy() {
2297 EntityCacheUtil.removeCache(MBStatsUserImpl.class.getName());
2298 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2299 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2300 }
2301
2302 @BeanReference(type = MBBanPersistence.class)
2303 protected MBBanPersistence mbBanPersistence;
2304 @BeanReference(type = MBCategoryPersistence.class)
2305 protected MBCategoryPersistence mbCategoryPersistence;
2306 @BeanReference(type = MBDiscussionPersistence.class)
2307 protected MBDiscussionPersistence mbDiscussionPersistence;
2308 @BeanReference(type = MBMailingListPersistence.class)
2309 protected MBMailingListPersistence mbMailingListPersistence;
2310 @BeanReference(type = MBMessagePersistence.class)
2311 protected MBMessagePersistence mbMessagePersistence;
2312 @BeanReference(type = MBStatsUserPersistence.class)
2313 protected MBStatsUserPersistence mbStatsUserPersistence;
2314 @BeanReference(type = MBThreadPersistence.class)
2315 protected MBThreadPersistence mbThreadPersistence;
2316 @BeanReference(type = MBThreadFlagPersistence.class)
2317 protected MBThreadFlagPersistence mbThreadFlagPersistence;
2318 @BeanReference(type = GroupPersistence.class)
2319 protected GroupPersistence groupPersistence;
2320 @BeanReference(type = ResourcePersistence.class)
2321 protected ResourcePersistence resourcePersistence;
2322 @BeanReference(type = UserPersistence.class)
2323 protected UserPersistence userPersistence;
2324 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
2325 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
2326 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
2327 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
2328 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
2329 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
2330 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2331 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
2332 private static final String _FINDER_COLUMN_G_NOTU_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
2333 private static final String _FINDER_COLUMN_G_NOTU_NOTM_USERID_2 = "mbStatsUser.userId != ? AND ";
2334 private static final String _FINDER_COLUMN_G_NOTU_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
2335 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
2336 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
2337 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
2338 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2339 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
2340 private static MBStatsUser _nullMBStatsUser = new MBStatsUserImpl() {
2341 @Override
2342 public Object clone() {
2343 return this;
2344 }
2345
2346 @Override
2347 public CacheModel<MBStatsUser> toCacheModel() {
2348 return _nullMBStatsUserCacheModel;
2349 }
2350 };
2351
2352 private static CacheModel<MBStatsUser> _nullMBStatsUserCacheModel = new CacheModel<MBStatsUser>() {
2353 public MBStatsUser toEntityModel() {
2354 return _nullMBStatsUser;
2355 }
2356 };
2357 }