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