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