001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.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.ModelListener;
037 import com.liferay.portal.service.persistence.BatchSessionUtil;
038 import com.liferay.portal.service.persistence.ResourcePersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.messageboards.NoSuchStatsUserException;
043 import com.liferay.portlet.messageboards.model.MBStatsUser;
044 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
045 import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
046
047 import java.io.Serializable;
048
049 import java.util.ArrayList;
050 import java.util.Collections;
051 import java.util.List;
052
053
059 public class MBStatsUserPersistenceImpl extends BasePersistenceImpl<MBStatsUser>
060 implements MBStatsUserPersistence {
061 public static final String FINDER_CLASS_NAME_ENTITY = MBStatsUserImpl.class.getName();
062 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
063 ".List";
064 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
065 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
066 "findByGroupId",
067 new String[] {
068 Long.class.getName(),
069
070 "java.lang.Integer", "java.lang.Integer",
071 "com.liferay.portal.kernel.util.OrderByComparator"
072 });
073 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
074 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
075 "countByGroupId", new String[] { Long.class.getName() });
076 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
077 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
078 "findByUserId",
079 new String[] {
080 Long.class.getName(),
081
082 "java.lang.Integer", "java.lang.Integer",
083 "com.liferay.portal.kernel.util.OrderByComparator"
084 });
085 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
086 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
087 "countByUserId", new String[] { Long.class.getName() });
088 public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
089 MBStatsUserModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
091 new String[] { Long.class.getName(), Long.class.getName() });
092 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
093 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
094 "countByG_U",
095 new String[] { Long.class.getName(), Long.class.getName() });
096 public static final FinderPath FINDER_PATH_FIND_BY_G_NOTM = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
097 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
098 "findByG_NotM",
099 new String[] {
100 Long.class.getName(), Integer.class.getName(),
101
102 "java.lang.Integer", "java.lang.Integer",
103 "com.liferay.portal.kernel.util.OrderByComparator"
104 });
105 public static final FinderPath FINDER_PATH_COUNT_BY_G_NOTM = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
106 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "countByG_NotM",
108 new String[] { Long.class.getName(), Integer.class.getName() });
109 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
110 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
111 "findAll", new String[0]);
112 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
113 MBStatsUserModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "countAll", new String[0]);
115
116 public void cacheResult(MBStatsUser mbStatsUser) {
117 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
118 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
119
120 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
121 new Object[] {
122 new Long(mbStatsUser.getGroupId()),
123 new Long(mbStatsUser.getUserId())
124 }, mbStatsUser);
125 }
126
127 public void cacheResult(List<MBStatsUser> mbStatsUsers) {
128 for (MBStatsUser mbStatsUser : mbStatsUsers) {
129 if (EntityCacheUtil.getResult(
130 MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
131 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), this) == null) {
132 cacheResult(mbStatsUser);
133 }
134 }
135 }
136
137 public void clearCache() {
138 CacheRegistryUtil.clear(MBStatsUserImpl.class.getName());
139 EntityCacheUtil.clearCache(MBStatsUserImpl.class.getName());
140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
142 }
143
144 public void clearCache(MBStatsUser mbStatsUser) {
145 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
146 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
147
148 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
149 new Object[] {
150 new Long(mbStatsUser.getGroupId()),
151 new Long(mbStatsUser.getUserId())
152 });
153 }
154
155 public MBStatsUser create(long statsUserId) {
156 MBStatsUser mbStatsUser = new MBStatsUserImpl();
157
158 mbStatsUser.setNew(true);
159 mbStatsUser.setPrimaryKey(statsUserId);
160
161 return mbStatsUser;
162 }
163
164 public MBStatsUser remove(Serializable primaryKey)
165 throws NoSuchModelException, SystemException {
166 return remove(((Long)primaryKey).longValue());
167 }
168
169 public MBStatsUser remove(long statsUserId)
170 throws NoSuchStatsUserException, SystemException {
171 Session session = null;
172
173 try {
174 session = openSession();
175
176 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
177 new Long(statsUserId));
178
179 if (mbStatsUser == null) {
180 if (_log.isWarnEnabled()) {
181 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
182 }
183
184 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
185 statsUserId);
186 }
187
188 return remove(mbStatsUser);
189 }
190 catch (NoSuchStatsUserException nsee) {
191 throw nsee;
192 }
193 catch (Exception e) {
194 throw processException(e);
195 }
196 finally {
197 closeSession(session);
198 }
199 }
200
201 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
202 throws SystemException {
203 mbStatsUser = toUnwrappedModel(mbStatsUser);
204
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 if (mbStatsUser.isCachedModel() || BatchSessionUtil.isEnabled()) {
211 Object staleObject = session.get(MBStatsUserImpl.class,
212 mbStatsUser.getPrimaryKeyObj());
213
214 if (staleObject != null) {
215 session.evict(staleObject);
216 }
217 }
218
219 session.delete(mbStatsUser);
220
221 session.flush();
222 }
223 catch (Exception e) {
224 throw processException(e);
225 }
226 finally {
227 closeSession(session);
228 }
229
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
231
232 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
233
234 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
235 new Object[] {
236 new Long(mbStatsUserModelImpl.getOriginalGroupId()),
237 new Long(mbStatsUserModelImpl.getOriginalUserId())
238 });
239
240 EntityCacheUtil.removeResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
241 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey());
242
243 return mbStatsUser;
244 }
245
246 public MBStatsUser updateImpl(
247 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
248 boolean merge) throws SystemException {
249 mbStatsUser = toUnwrappedModel(mbStatsUser);
250
251 boolean isNew = mbStatsUser.isNew();
252
253 MBStatsUserModelImpl mbStatsUserModelImpl = (MBStatsUserModelImpl)mbStatsUser;
254
255 Session session = null;
256
257 try {
258 session = openSession();
259
260 BatchSessionUtil.update(session, mbStatsUser, merge);
261
262 mbStatsUser.setNew(false);
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270
271 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
272
273 EntityCacheUtil.putResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
274 MBStatsUserImpl.class, mbStatsUser.getPrimaryKey(), mbStatsUser);
275
276 if (!isNew &&
277 ((mbStatsUser.getGroupId() != mbStatsUserModelImpl.getOriginalGroupId()) ||
278 (mbStatsUser.getUserId() != mbStatsUserModelImpl.getOriginalUserId()))) {
279 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
280 new Object[] {
281 new Long(mbStatsUserModelImpl.getOriginalGroupId()),
282 new Long(mbStatsUserModelImpl.getOriginalUserId())
283 });
284 }
285
286 if (isNew ||
287 ((mbStatsUser.getGroupId() != mbStatsUserModelImpl.getOriginalGroupId()) ||
288 (mbStatsUser.getUserId() != mbStatsUserModelImpl.getOriginalUserId()))) {
289 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
290 new Object[] {
291 new Long(mbStatsUser.getGroupId()),
292 new Long(mbStatsUser.getUserId())
293 }, mbStatsUser);
294 }
295
296 return mbStatsUser;
297 }
298
299 protected MBStatsUser toUnwrappedModel(MBStatsUser mbStatsUser) {
300 if (mbStatsUser instanceof MBStatsUserImpl) {
301 return mbStatsUser;
302 }
303
304 MBStatsUserImpl mbStatsUserImpl = new MBStatsUserImpl();
305
306 mbStatsUserImpl.setNew(mbStatsUser.isNew());
307 mbStatsUserImpl.setPrimaryKey(mbStatsUser.getPrimaryKey());
308
309 mbStatsUserImpl.setStatsUserId(mbStatsUser.getStatsUserId());
310 mbStatsUserImpl.setGroupId(mbStatsUser.getGroupId());
311 mbStatsUserImpl.setUserId(mbStatsUser.getUserId());
312 mbStatsUserImpl.setMessageCount(mbStatsUser.getMessageCount());
313 mbStatsUserImpl.setLastPostDate(mbStatsUser.getLastPostDate());
314
315 return mbStatsUserImpl;
316 }
317
318 public MBStatsUser findByPrimaryKey(Serializable primaryKey)
319 throws NoSuchModelException, SystemException {
320 return findByPrimaryKey(((Long)primaryKey).longValue());
321 }
322
323 public MBStatsUser findByPrimaryKey(long statsUserId)
324 throws NoSuchStatsUserException, SystemException {
325 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
326
327 if (mbStatsUser == null) {
328 if (_log.isWarnEnabled()) {
329 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsUserId);
330 }
331
332 throw new NoSuchStatsUserException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
333 statsUserId);
334 }
335
336 return mbStatsUser;
337 }
338
339 public MBStatsUser fetchByPrimaryKey(Serializable primaryKey)
340 throws SystemException {
341 return fetchByPrimaryKey(((Long)primaryKey).longValue());
342 }
343
344 public MBStatsUser fetchByPrimaryKey(long statsUserId)
345 throws SystemException {
346 MBStatsUser mbStatsUser = (MBStatsUser)EntityCacheUtil.getResult(MBStatsUserModelImpl.ENTITY_CACHE_ENABLED,
347 MBStatsUserImpl.class, statsUserId, this);
348
349 if (mbStatsUser == null) {
350 Session session = null;
351
352 try {
353 session = openSession();
354
355 mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
356 new Long(statsUserId));
357 }
358 catch (Exception e) {
359 throw processException(e);
360 }
361 finally {
362 if (mbStatsUser != null) {
363 cacheResult(mbStatsUser);
364 }
365
366 closeSession(session);
367 }
368 }
369
370 return mbStatsUser;
371 }
372
373 public List<MBStatsUser> findByGroupId(long groupId)
374 throws SystemException {
375 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
376 }
377
378 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
379 throws SystemException {
380 return findByGroupId(groupId, start, end, null);
381 }
382
383 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
384 OrderByComparator orderByComparator) throws SystemException {
385 Object[] finderArgs = new Object[] {
386 groupId,
387
388 String.valueOf(start), String.valueOf(end),
389 String.valueOf(orderByComparator)
390 };
391
392 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
393 finderArgs, this);
394
395 if (list == null) {
396 Session session = null;
397
398 try {
399 session = openSession();
400
401 StringBundler query = null;
402
403 if (orderByComparator != null) {
404 query = new StringBundler(3 +
405 (orderByComparator.getOrderByFields().length * 3));
406 }
407 else {
408 query = new StringBundler(3);
409 }
410
411 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
412
413 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
414
415 if (orderByComparator != null) {
416 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
417 orderByComparator);
418 }
419
420 else {
421 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
422 }
423
424 String sql = query.toString();
425
426 Query q = session.createQuery(sql);
427
428 QueryPos qPos = QueryPos.getInstance(q);
429
430 qPos.add(groupId);
431
432 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
433 start, end);
434 }
435 catch (Exception e) {
436 throw processException(e);
437 }
438 finally {
439 if (list == null) {
440 list = new ArrayList<MBStatsUser>();
441 }
442
443 cacheResult(list);
444
445 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
446 finderArgs, list);
447
448 closeSession(session);
449 }
450 }
451
452 return list;
453 }
454
455 public MBStatsUser findByGroupId_First(long groupId,
456 OrderByComparator orderByComparator)
457 throws NoSuchStatsUserException, SystemException {
458 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, orderByComparator);
459
460 if (list.isEmpty()) {
461 StringBundler msg = new StringBundler(4);
462
463 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
464
465 msg.append("groupId=");
466 msg.append(groupId);
467
468 msg.append(StringPool.CLOSE_CURLY_BRACE);
469
470 throw new NoSuchStatsUserException(msg.toString());
471 }
472 else {
473 return list.get(0);
474 }
475 }
476
477 public MBStatsUser findByGroupId_Last(long groupId,
478 OrderByComparator orderByComparator)
479 throws NoSuchStatsUserException, SystemException {
480 int count = countByGroupId(groupId);
481
482 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count,
483 orderByComparator);
484
485 if (list.isEmpty()) {
486 StringBundler msg = new StringBundler(4);
487
488 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
489
490 msg.append("groupId=");
491 msg.append(groupId);
492
493 msg.append(StringPool.CLOSE_CURLY_BRACE);
494
495 throw new NoSuchStatsUserException(msg.toString());
496 }
497 else {
498 return list.get(0);
499 }
500 }
501
502 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
503 long groupId, OrderByComparator orderByComparator)
504 throws NoSuchStatsUserException, SystemException {
505 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
506
507 Session session = null;
508
509 try {
510 session = openSession();
511
512 MBStatsUser[] array = new MBStatsUserImpl[3];
513
514 array[0] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
515 orderByComparator, true);
516
517 array[1] = mbStatsUser;
518
519 array[2] = getByGroupId_PrevAndNext(session, mbStatsUser, groupId,
520 orderByComparator, false);
521
522 return array;
523 }
524 catch (Exception e) {
525 throw processException(e);
526 }
527 finally {
528 closeSession(session);
529 }
530 }
531
532 protected MBStatsUser getByGroupId_PrevAndNext(Session session,
533 MBStatsUser mbStatsUser, long groupId,
534 OrderByComparator orderByComparator, boolean previous) {
535 StringBundler query = null;
536
537 if (orderByComparator != null) {
538 query = new StringBundler(6 +
539 (orderByComparator.getOrderByFields().length * 6));
540 }
541 else {
542 query = new StringBundler(3);
543 }
544
545 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
546
547 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
548
549 if (orderByComparator != null) {
550 String[] orderByFields = orderByComparator.getOrderByFields();
551
552 if (orderByFields.length > 0) {
553 query.append(WHERE_AND);
554 }
555
556 for (int i = 0; i < orderByFields.length; i++) {
557 query.append(_ORDER_BY_ENTITY_ALIAS);
558 query.append(orderByFields[i]);
559
560 if ((i + 1) < orderByFields.length) {
561 if (orderByComparator.isAscending() ^ previous) {
562 query.append(WHERE_GREATER_THAN_HAS_NEXT);
563 }
564 else {
565 query.append(WHERE_LESSER_THAN_HAS_NEXT);
566 }
567 }
568 else {
569 if (orderByComparator.isAscending() ^ previous) {
570 query.append(WHERE_GREATER_THAN);
571 }
572 else {
573 query.append(WHERE_LESSER_THAN);
574 }
575 }
576 }
577
578 query.append(ORDER_BY_CLAUSE);
579
580 for (int i = 0; i < orderByFields.length; i++) {
581 query.append(_ORDER_BY_ENTITY_ALIAS);
582 query.append(orderByFields[i]);
583
584 if ((i + 1) < orderByFields.length) {
585 if (orderByComparator.isAscending() ^ previous) {
586 query.append(ORDER_BY_ASC_HAS_NEXT);
587 }
588 else {
589 query.append(ORDER_BY_DESC_HAS_NEXT);
590 }
591 }
592 else {
593 if (orderByComparator.isAscending() ^ previous) {
594 query.append(ORDER_BY_ASC);
595 }
596 else {
597 query.append(ORDER_BY_DESC);
598 }
599 }
600 }
601 }
602
603 else {
604 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
605 }
606
607 String sql = query.toString();
608
609 Query q = session.createQuery(sql);
610
611 q.setFirstResult(0);
612 q.setMaxResults(2);
613
614 QueryPos qPos = QueryPos.getInstance(q);
615
616 qPos.add(groupId);
617
618 if (orderByComparator != null) {
619 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
620
621 for (Object value : values) {
622 qPos.add(value);
623 }
624 }
625
626 List<MBStatsUser> list = q.list();
627
628 if (list.size() == 2) {
629 return list.get(1);
630 }
631 else {
632 return null;
633 }
634 }
635
636 public List<MBStatsUser> findByUserId(long userId)
637 throws SystemException {
638 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
639 }
640
641 public List<MBStatsUser> findByUserId(long userId, int start, int end)
642 throws SystemException {
643 return findByUserId(userId, start, end, null);
644 }
645
646 public List<MBStatsUser> findByUserId(long userId, int start, int end,
647 OrderByComparator orderByComparator) throws SystemException {
648 Object[] finderArgs = new Object[] {
649 userId,
650
651 String.valueOf(start), String.valueOf(end),
652 String.valueOf(orderByComparator)
653 };
654
655 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
656 finderArgs, this);
657
658 if (list == null) {
659 Session session = null;
660
661 try {
662 session = openSession();
663
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_USERID_USERID_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 Query q = session.createQuery(sql);
690
691 QueryPos qPos = QueryPos.getInstance(q);
692
693 qPos.add(userId);
694
695 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
696 start, end);
697 }
698 catch (Exception e) {
699 throw processException(e);
700 }
701 finally {
702 if (list == null) {
703 list = new ArrayList<MBStatsUser>();
704 }
705
706 cacheResult(list);
707
708 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
709 finderArgs, list);
710
711 closeSession(session);
712 }
713 }
714
715 return list;
716 }
717
718 public MBStatsUser findByUserId_First(long userId,
719 OrderByComparator orderByComparator)
720 throws NoSuchStatsUserException, SystemException {
721 List<MBStatsUser> list = findByUserId(userId, 0, 1, orderByComparator);
722
723 if (list.isEmpty()) {
724 StringBundler msg = new StringBundler(4);
725
726 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
727
728 msg.append("userId=");
729 msg.append(userId);
730
731 msg.append(StringPool.CLOSE_CURLY_BRACE);
732
733 throw new NoSuchStatsUserException(msg.toString());
734 }
735 else {
736 return list.get(0);
737 }
738 }
739
740 public MBStatsUser findByUserId_Last(long userId,
741 OrderByComparator orderByComparator)
742 throws NoSuchStatsUserException, SystemException {
743 int count = countByUserId(userId);
744
745 List<MBStatsUser> list = findByUserId(userId, count - 1, count,
746 orderByComparator);
747
748 if (list.isEmpty()) {
749 StringBundler msg = new StringBundler(4);
750
751 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
752
753 msg.append("userId=");
754 msg.append(userId);
755
756 msg.append(StringPool.CLOSE_CURLY_BRACE);
757
758 throw new NoSuchStatsUserException(msg.toString());
759 }
760 else {
761 return list.get(0);
762 }
763 }
764
765 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
766 long userId, OrderByComparator orderByComparator)
767 throws NoSuchStatsUserException, SystemException {
768 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
769
770 Session session = null;
771
772 try {
773 session = openSession();
774
775 MBStatsUser[] array = new MBStatsUserImpl[3];
776
777 array[0] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
778 orderByComparator, true);
779
780 array[1] = mbStatsUser;
781
782 array[2] = getByUserId_PrevAndNext(session, mbStatsUser, userId,
783 orderByComparator, false);
784
785 return array;
786 }
787 catch (Exception e) {
788 throw processException(e);
789 }
790 finally {
791 closeSession(session);
792 }
793 }
794
795 protected MBStatsUser getByUserId_PrevAndNext(Session session,
796 MBStatsUser mbStatsUser, long userId,
797 OrderByComparator orderByComparator, boolean previous) {
798 StringBundler query = null;
799
800 if (orderByComparator != null) {
801 query = new StringBundler(6 +
802 (orderByComparator.getOrderByFields().length * 6));
803 }
804 else {
805 query = new StringBundler(3);
806 }
807
808 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
809
810 query.append(_FINDER_COLUMN_USERID_USERID_2);
811
812 if (orderByComparator != null) {
813 String[] orderByFields = orderByComparator.getOrderByFields();
814
815 if (orderByFields.length > 0) {
816 query.append(WHERE_AND);
817 }
818
819 for (int i = 0; i < orderByFields.length; i++) {
820 query.append(_ORDER_BY_ENTITY_ALIAS);
821 query.append(orderByFields[i]);
822
823 if ((i + 1) < orderByFields.length) {
824 if (orderByComparator.isAscending() ^ previous) {
825 query.append(WHERE_GREATER_THAN_HAS_NEXT);
826 }
827 else {
828 query.append(WHERE_LESSER_THAN_HAS_NEXT);
829 }
830 }
831 else {
832 if (orderByComparator.isAscending() ^ previous) {
833 query.append(WHERE_GREATER_THAN);
834 }
835 else {
836 query.append(WHERE_LESSER_THAN);
837 }
838 }
839 }
840
841 query.append(ORDER_BY_CLAUSE);
842
843 for (int i = 0; i < orderByFields.length; i++) {
844 query.append(_ORDER_BY_ENTITY_ALIAS);
845 query.append(orderByFields[i]);
846
847 if ((i + 1) < orderByFields.length) {
848 if (orderByComparator.isAscending() ^ previous) {
849 query.append(ORDER_BY_ASC_HAS_NEXT);
850 }
851 else {
852 query.append(ORDER_BY_DESC_HAS_NEXT);
853 }
854 }
855 else {
856 if (orderByComparator.isAscending() ^ previous) {
857 query.append(ORDER_BY_ASC);
858 }
859 else {
860 query.append(ORDER_BY_DESC);
861 }
862 }
863 }
864 }
865
866 else {
867 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
868 }
869
870 String sql = query.toString();
871
872 Query q = session.createQuery(sql);
873
874 q.setFirstResult(0);
875 q.setMaxResults(2);
876
877 QueryPos qPos = QueryPos.getInstance(q);
878
879 qPos.add(userId);
880
881 if (orderByComparator != null) {
882 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
883
884 for (Object value : values) {
885 qPos.add(value);
886 }
887 }
888
889 List<MBStatsUser> list = q.list();
890
891 if (list.size() == 2) {
892 return list.get(1);
893 }
894 else {
895 return null;
896 }
897 }
898
899 public MBStatsUser findByG_U(long groupId, long userId)
900 throws NoSuchStatsUserException, SystemException {
901 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
902
903 if (mbStatsUser == null) {
904 StringBundler msg = new StringBundler(6);
905
906 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
907
908 msg.append("groupId=");
909 msg.append(groupId);
910
911 msg.append(", userId=");
912 msg.append(userId);
913
914 msg.append(StringPool.CLOSE_CURLY_BRACE);
915
916 if (_log.isWarnEnabled()) {
917 _log.warn(msg.toString());
918 }
919
920 throw new NoSuchStatsUserException(msg.toString());
921 }
922
923 return mbStatsUser;
924 }
925
926 public MBStatsUser fetchByG_U(long groupId, long userId)
927 throws SystemException {
928 return fetchByG_U(groupId, userId, true);
929 }
930
931 public MBStatsUser fetchByG_U(long groupId, long userId,
932 boolean retrieveFromCache) throws SystemException {
933 Object[] finderArgs = new Object[] { groupId, userId };
934
935 Object result = null;
936
937 if (retrieveFromCache) {
938 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
939 finderArgs, this);
940 }
941
942 if (result == null) {
943 Session session = null;
944
945 try {
946 session = openSession();
947
948 StringBundler query = new StringBundler(4);
949
950 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
951
952 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
953
954 query.append(_FINDER_COLUMN_G_U_USERID_2);
955
956 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
957
958 String sql = query.toString();
959
960 Query q = session.createQuery(sql);
961
962 QueryPos qPos = QueryPos.getInstance(q);
963
964 qPos.add(groupId);
965
966 qPos.add(userId);
967
968 List<MBStatsUser> list = q.list();
969
970 result = list;
971
972 MBStatsUser mbStatsUser = null;
973
974 if (list.isEmpty()) {
975 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
976 finderArgs, list);
977 }
978 else {
979 mbStatsUser = list.get(0);
980
981 cacheResult(mbStatsUser);
982
983 if ((mbStatsUser.getGroupId() != groupId) ||
984 (mbStatsUser.getUserId() != userId)) {
985 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
986 finderArgs, mbStatsUser);
987 }
988 }
989
990 return mbStatsUser;
991 }
992 catch (Exception e) {
993 throw processException(e);
994 }
995 finally {
996 if (result == null) {
997 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
998 finderArgs, new ArrayList<MBStatsUser>());
999 }
1000
1001 closeSession(session);
1002 }
1003 }
1004 else {
1005 if (result instanceof List<?>) {
1006 return null;
1007 }
1008 else {
1009 return (MBStatsUser)result;
1010 }
1011 }
1012 }
1013
1014 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount)
1015 throws SystemException {
1016 return findByG_NotM(groupId, messageCount, QueryUtil.ALL_POS,
1017 QueryUtil.ALL_POS, null);
1018 }
1019
1020 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1021 int start, int end) throws SystemException {
1022 return findByG_NotM(groupId, messageCount, start, end, null);
1023 }
1024
1025 public List<MBStatsUser> findByG_NotM(long groupId, int messageCount,
1026 int start, int end, OrderByComparator orderByComparator)
1027 throws SystemException {
1028 Object[] finderArgs = new Object[] {
1029 groupId, messageCount,
1030
1031 String.valueOf(start), String.valueOf(end),
1032 String.valueOf(orderByComparator)
1033 };
1034
1035 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_NOTM,
1036 finderArgs, this);
1037
1038 if (list == null) {
1039 Session session = null;
1040
1041 try {
1042 session = openSession();
1043
1044 StringBundler query = null;
1045
1046 if (orderByComparator != null) {
1047 query = new StringBundler(4 +
1048 (orderByComparator.getOrderByFields().length * 3));
1049 }
1050 else {
1051 query = new StringBundler(4);
1052 }
1053
1054 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1055
1056 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1057
1058 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1059
1060 if (orderByComparator != null) {
1061 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1062 orderByComparator);
1063 }
1064
1065 else {
1066 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1067 }
1068
1069 String sql = query.toString();
1070
1071 Query q = session.createQuery(sql);
1072
1073 QueryPos qPos = QueryPos.getInstance(q);
1074
1075 qPos.add(groupId);
1076
1077 qPos.add(messageCount);
1078
1079 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1080 start, end);
1081 }
1082 catch (Exception e) {
1083 throw processException(e);
1084 }
1085 finally {
1086 if (list == null) {
1087 list = new ArrayList<MBStatsUser>();
1088 }
1089
1090 cacheResult(list);
1091
1092 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_NOTM,
1093 finderArgs, list);
1094
1095 closeSession(session);
1096 }
1097 }
1098
1099 return list;
1100 }
1101
1102 public MBStatsUser findByG_NotM_First(long groupId, int messageCount,
1103 OrderByComparator orderByComparator)
1104 throws NoSuchStatsUserException, SystemException {
1105 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, 0, 1,
1106 orderByComparator);
1107
1108 if (list.isEmpty()) {
1109 StringBundler msg = new StringBundler(6);
1110
1111 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1112
1113 msg.append("groupId=");
1114 msg.append(groupId);
1115
1116 msg.append(", messageCount=");
1117 msg.append(messageCount);
1118
1119 msg.append(StringPool.CLOSE_CURLY_BRACE);
1120
1121 throw new NoSuchStatsUserException(msg.toString());
1122 }
1123 else {
1124 return list.get(0);
1125 }
1126 }
1127
1128 public MBStatsUser findByG_NotM_Last(long groupId, int messageCount,
1129 OrderByComparator orderByComparator)
1130 throws NoSuchStatsUserException, SystemException {
1131 int count = countByG_NotM(groupId, messageCount);
1132
1133 List<MBStatsUser> list = findByG_NotM(groupId, messageCount, count - 1,
1134 count, orderByComparator);
1135
1136 if (list.isEmpty()) {
1137 StringBundler msg = new StringBundler(6);
1138
1139 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1140
1141 msg.append("groupId=");
1142 msg.append(groupId);
1143
1144 msg.append(", messageCount=");
1145 msg.append(messageCount);
1146
1147 msg.append(StringPool.CLOSE_CURLY_BRACE);
1148
1149 throw new NoSuchStatsUserException(msg.toString());
1150 }
1151 else {
1152 return list.get(0);
1153 }
1154 }
1155
1156 public MBStatsUser[] findByG_NotM_PrevAndNext(long statsUserId,
1157 long groupId, int messageCount, OrderByComparator orderByComparator)
1158 throws NoSuchStatsUserException, SystemException {
1159 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1160
1161 Session session = null;
1162
1163 try {
1164 session = openSession();
1165
1166 MBStatsUser[] array = new MBStatsUserImpl[3];
1167
1168 array[0] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1169 messageCount, orderByComparator, true);
1170
1171 array[1] = mbStatsUser;
1172
1173 array[2] = getByG_NotM_PrevAndNext(session, mbStatsUser, groupId,
1174 messageCount, orderByComparator, false);
1175
1176 return array;
1177 }
1178 catch (Exception e) {
1179 throw processException(e);
1180 }
1181 finally {
1182 closeSession(session);
1183 }
1184 }
1185
1186 protected MBStatsUser getByG_NotM_PrevAndNext(Session session,
1187 MBStatsUser mbStatsUser, long groupId, int messageCount,
1188 OrderByComparator orderByComparator, boolean previous) {
1189 StringBundler query = null;
1190
1191 if (orderByComparator != null) {
1192 query = new StringBundler(6 +
1193 (orderByComparator.getOrderByFields().length * 6));
1194 }
1195 else {
1196 query = new StringBundler(3);
1197 }
1198
1199 query.append(_SQL_SELECT_MBSTATSUSER_WHERE);
1200
1201 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1202
1203 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1204
1205 if (orderByComparator != null) {
1206 String[] orderByFields = orderByComparator.getOrderByFields();
1207
1208 if (orderByFields.length > 0) {
1209 query.append(WHERE_AND);
1210 }
1211
1212 for (int i = 0; i < orderByFields.length; i++) {
1213 query.append(_ORDER_BY_ENTITY_ALIAS);
1214 query.append(orderByFields[i]);
1215
1216 if ((i + 1) < orderByFields.length) {
1217 if (orderByComparator.isAscending() ^ previous) {
1218 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1219 }
1220 else {
1221 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1222 }
1223 }
1224 else {
1225 if (orderByComparator.isAscending() ^ previous) {
1226 query.append(WHERE_GREATER_THAN);
1227 }
1228 else {
1229 query.append(WHERE_LESSER_THAN);
1230 }
1231 }
1232 }
1233
1234 query.append(ORDER_BY_CLAUSE);
1235
1236 for (int i = 0; i < orderByFields.length; i++) {
1237 query.append(_ORDER_BY_ENTITY_ALIAS);
1238 query.append(orderByFields[i]);
1239
1240 if ((i + 1) < orderByFields.length) {
1241 if (orderByComparator.isAscending() ^ previous) {
1242 query.append(ORDER_BY_ASC_HAS_NEXT);
1243 }
1244 else {
1245 query.append(ORDER_BY_DESC_HAS_NEXT);
1246 }
1247 }
1248 else {
1249 if (orderByComparator.isAscending() ^ previous) {
1250 query.append(ORDER_BY_ASC);
1251 }
1252 else {
1253 query.append(ORDER_BY_DESC);
1254 }
1255 }
1256 }
1257 }
1258
1259 else {
1260 query.append(MBStatsUserModelImpl.ORDER_BY_JPQL);
1261 }
1262
1263 String sql = query.toString();
1264
1265 Query q = session.createQuery(sql);
1266
1267 q.setFirstResult(0);
1268 q.setMaxResults(2);
1269
1270 QueryPos qPos = QueryPos.getInstance(q);
1271
1272 qPos.add(groupId);
1273
1274 qPos.add(messageCount);
1275
1276 if (orderByComparator != null) {
1277 Object[] values = orderByComparator.getOrderByValues(mbStatsUser);
1278
1279 for (Object value : values) {
1280 qPos.add(value);
1281 }
1282 }
1283
1284 List<MBStatsUser> list = q.list();
1285
1286 if (list.size() == 2) {
1287 return list.get(1);
1288 }
1289 else {
1290 return null;
1291 }
1292 }
1293
1294 public List<MBStatsUser> findAll() throws SystemException {
1295 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1296 }
1297
1298 public List<MBStatsUser> findAll(int start, int end)
1299 throws SystemException {
1300 return findAll(start, end, null);
1301 }
1302
1303 public List<MBStatsUser> findAll(int start, int end,
1304 OrderByComparator orderByComparator) throws SystemException {
1305 Object[] finderArgs = new Object[] {
1306 String.valueOf(start), String.valueOf(end),
1307 String.valueOf(orderByComparator)
1308 };
1309
1310 List<MBStatsUser> list = (List<MBStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1311 finderArgs, this);
1312
1313 if (list == null) {
1314 Session session = null;
1315
1316 try {
1317 session = openSession();
1318
1319 StringBundler query = null;
1320 String sql = null;
1321
1322 if (orderByComparator != null) {
1323 query = new StringBundler(2 +
1324 (orderByComparator.getOrderByFields().length * 3));
1325
1326 query.append(_SQL_SELECT_MBSTATSUSER);
1327
1328 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1329 orderByComparator);
1330
1331 sql = query.toString();
1332 }
1333 else {
1334 sql = _SQL_SELECT_MBSTATSUSER.concat(MBStatsUserModelImpl.ORDER_BY_JPQL);
1335 }
1336
1337 Query q = session.createQuery(sql);
1338
1339 if (orderByComparator == null) {
1340 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1341 start, end, false);
1342
1343 Collections.sort(list);
1344 }
1345 else {
1346 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1347 start, end);
1348 }
1349 }
1350 catch (Exception e) {
1351 throw processException(e);
1352 }
1353 finally {
1354 if (list == null) {
1355 list = new ArrayList<MBStatsUser>();
1356 }
1357
1358 cacheResult(list);
1359
1360 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1361
1362 closeSession(session);
1363 }
1364 }
1365
1366 return list;
1367 }
1368
1369 public void removeByGroupId(long groupId) throws SystemException {
1370 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1371 remove(mbStatsUser);
1372 }
1373 }
1374
1375 public void removeByUserId(long userId) throws SystemException {
1376 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1377 remove(mbStatsUser);
1378 }
1379 }
1380
1381 public void removeByG_U(long groupId, long userId)
1382 throws NoSuchStatsUserException, SystemException {
1383 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1384
1385 remove(mbStatsUser);
1386 }
1387
1388 public void removeByG_NotM(long groupId, int messageCount)
1389 throws SystemException {
1390 for (MBStatsUser mbStatsUser : findByG_NotM(groupId, messageCount)) {
1391 remove(mbStatsUser);
1392 }
1393 }
1394
1395 public void removeAll() throws SystemException {
1396 for (MBStatsUser mbStatsUser : findAll()) {
1397 remove(mbStatsUser);
1398 }
1399 }
1400
1401 public int countByGroupId(long groupId) throws SystemException {
1402 Object[] finderArgs = new Object[] { groupId };
1403
1404 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1405 finderArgs, this);
1406
1407 if (count == null) {
1408 Session session = null;
1409
1410 try {
1411 session = openSession();
1412
1413 StringBundler query = new StringBundler(2);
1414
1415 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1416
1417 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1418
1419 String sql = query.toString();
1420
1421 Query q = session.createQuery(sql);
1422
1423 QueryPos qPos = QueryPos.getInstance(q);
1424
1425 qPos.add(groupId);
1426
1427 count = (Long)q.uniqueResult();
1428 }
1429 catch (Exception e) {
1430 throw processException(e);
1431 }
1432 finally {
1433 if (count == null) {
1434 count = Long.valueOf(0);
1435 }
1436
1437 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1438 finderArgs, count);
1439
1440 closeSession(session);
1441 }
1442 }
1443
1444 return count.intValue();
1445 }
1446
1447 public int countByUserId(long userId) throws SystemException {
1448 Object[] finderArgs = new Object[] { userId };
1449
1450 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1451 finderArgs, this);
1452
1453 if (count == null) {
1454 Session session = null;
1455
1456 try {
1457 session = openSession();
1458
1459 StringBundler query = new StringBundler(2);
1460
1461 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1462
1463 query.append(_FINDER_COLUMN_USERID_USERID_2);
1464
1465 String sql = query.toString();
1466
1467 Query q = session.createQuery(sql);
1468
1469 QueryPos qPos = QueryPos.getInstance(q);
1470
1471 qPos.add(userId);
1472
1473 count = (Long)q.uniqueResult();
1474 }
1475 catch (Exception e) {
1476 throw processException(e);
1477 }
1478 finally {
1479 if (count == null) {
1480 count = Long.valueOf(0);
1481 }
1482
1483 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1484 finderArgs, count);
1485
1486 closeSession(session);
1487 }
1488 }
1489
1490 return count.intValue();
1491 }
1492
1493 public int countByG_U(long groupId, long userId) throws SystemException {
1494 Object[] finderArgs = new Object[] { groupId, userId };
1495
1496 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1497 finderArgs, this);
1498
1499 if (count == null) {
1500 Session session = null;
1501
1502 try {
1503 session = openSession();
1504
1505 StringBundler query = new StringBundler(3);
1506
1507 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1508
1509 query.append(_FINDER_COLUMN_G_U_GROUPID_2);
1510
1511 query.append(_FINDER_COLUMN_G_U_USERID_2);
1512
1513 String sql = query.toString();
1514
1515 Query q = session.createQuery(sql);
1516
1517 QueryPos qPos = QueryPos.getInstance(q);
1518
1519 qPos.add(groupId);
1520
1521 qPos.add(userId);
1522
1523 count = (Long)q.uniqueResult();
1524 }
1525 catch (Exception e) {
1526 throw processException(e);
1527 }
1528 finally {
1529 if (count == null) {
1530 count = Long.valueOf(0);
1531 }
1532
1533 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1534 count);
1535
1536 closeSession(session);
1537 }
1538 }
1539
1540 return count.intValue();
1541 }
1542
1543 public int countByG_NotM(long groupId, int messageCount)
1544 throws SystemException {
1545 Object[] finderArgs = new Object[] { groupId, messageCount };
1546
1547 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_NOTM,
1548 finderArgs, this);
1549
1550 if (count == null) {
1551 Session session = null;
1552
1553 try {
1554 session = openSession();
1555
1556 StringBundler query = new StringBundler(3);
1557
1558 query.append(_SQL_COUNT_MBSTATSUSER_WHERE);
1559
1560 query.append(_FINDER_COLUMN_G_NOTM_GROUPID_2);
1561
1562 query.append(_FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2);
1563
1564 String sql = query.toString();
1565
1566 Query q = session.createQuery(sql);
1567
1568 QueryPos qPos = QueryPos.getInstance(q);
1569
1570 qPos.add(groupId);
1571
1572 qPos.add(messageCount);
1573
1574 count = (Long)q.uniqueResult();
1575 }
1576 catch (Exception e) {
1577 throw processException(e);
1578 }
1579 finally {
1580 if (count == null) {
1581 count = Long.valueOf(0);
1582 }
1583
1584 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_NOTM,
1585 finderArgs, count);
1586
1587 closeSession(session);
1588 }
1589 }
1590
1591 return count.intValue();
1592 }
1593
1594 public int countAll() throws SystemException {
1595 Object[] finderArgs = new Object[0];
1596
1597 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1598 finderArgs, this);
1599
1600 if (count == null) {
1601 Session session = null;
1602
1603 try {
1604 session = openSession();
1605
1606 Query q = session.createQuery(_SQL_COUNT_MBSTATSUSER);
1607
1608 count = (Long)q.uniqueResult();
1609 }
1610 catch (Exception e) {
1611 throw processException(e);
1612 }
1613 finally {
1614 if (count == null) {
1615 count = Long.valueOf(0);
1616 }
1617
1618 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1619 count);
1620
1621 closeSession(session);
1622 }
1623 }
1624
1625 return count.intValue();
1626 }
1627
1628 public void afterPropertiesSet() {
1629 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1630 com.liferay.portal.util.PropsUtil.get(
1631 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
1632
1633 if (listenerClassNames.length > 0) {
1634 try {
1635 List<ModelListener<MBStatsUser>> listenersList = new ArrayList<ModelListener<MBStatsUser>>();
1636
1637 for (String listenerClassName : listenerClassNames) {
1638 listenersList.add((ModelListener<MBStatsUser>)InstanceFactory.newInstance(
1639 listenerClassName));
1640 }
1641
1642 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1643 }
1644 catch (Exception e) {
1645 _log.error(e);
1646 }
1647 }
1648 }
1649
1650 @BeanReference(type = MBBanPersistence.class)
1651 protected MBBanPersistence mbBanPersistence;
1652 @BeanReference(type = MBCategoryPersistence.class)
1653 protected MBCategoryPersistence mbCategoryPersistence;
1654 @BeanReference(type = MBDiscussionPersistence.class)
1655 protected MBDiscussionPersistence mbDiscussionPersistence;
1656 @BeanReference(type = MBMailingListPersistence.class)
1657 protected MBMailingListPersistence mbMailingListPersistence;
1658 @BeanReference(type = MBMessagePersistence.class)
1659 protected MBMessagePersistence mbMessagePersistence;
1660 @BeanReference(type = MBMessageFlagPersistence.class)
1661 protected MBMessageFlagPersistence mbMessageFlagPersistence;
1662 @BeanReference(type = MBStatsUserPersistence.class)
1663 protected MBStatsUserPersistence mbStatsUserPersistence;
1664 @BeanReference(type = MBThreadPersistence.class)
1665 protected MBThreadPersistence mbThreadPersistence;
1666 @BeanReference(type = ResourcePersistence.class)
1667 protected ResourcePersistence resourcePersistence;
1668 @BeanReference(type = UserPersistence.class)
1669 protected UserPersistence userPersistence;
1670 private static final String _SQL_SELECT_MBSTATSUSER = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser";
1671 private static final String _SQL_SELECT_MBSTATSUSER_WHERE = "SELECT mbStatsUser FROM MBStatsUser mbStatsUser WHERE ";
1672 private static final String _SQL_COUNT_MBSTATSUSER = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser";
1673 private static final String _SQL_COUNT_MBSTATSUSER_WHERE = "SELECT COUNT(mbStatsUser) FROM MBStatsUser mbStatsUser WHERE ";
1674 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbStatsUser.groupId = ?";
1675 private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbStatsUser.userId = ?";
1676 private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
1677 private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbStatsUser.userId = ?";
1678 private static final String _FINDER_COLUMN_G_NOTM_GROUPID_2 = "mbStatsUser.groupId = ? AND ";
1679 private static final String _FINDER_COLUMN_G_NOTM_MESSAGECOUNT_2 = "mbStatsUser.messageCount != ?";
1680 private static final String _ORDER_BY_ENTITY_ALIAS = "mbStatsUser.";
1681 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBStatsUser exists with the primary key ";
1682 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBStatsUser exists with the key {";
1683 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
1684 }