1
22
23 package com.liferay.portlet.blogs.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.annotation.BeanReference;
27 import com.liferay.portal.kernel.cache.CacheRegistry;
28 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
29 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
30 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
31 import com.liferay.portal.kernel.dao.orm.FinderPath;
32 import com.liferay.portal.kernel.dao.orm.Query;
33 import com.liferay.portal.kernel.dao.orm.QueryPos;
34 import com.liferay.portal.kernel.dao.orm.QueryUtil;
35 import com.liferay.portal.kernel.dao.orm.Session;
36 import com.liferay.portal.kernel.log.Log;
37 import com.liferay.portal.kernel.log.LogFactoryUtil;
38 import com.liferay.portal.kernel.util.GetterUtil;
39 import com.liferay.portal.kernel.util.OrderByComparator;
40 import com.liferay.portal.kernel.util.StringPool;
41 import com.liferay.portal.kernel.util.StringUtil;
42 import com.liferay.portal.model.ModelListener;
43 import com.liferay.portal.service.persistence.BatchSessionUtil;
44 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
45
46 import com.liferay.portlet.blogs.NoSuchStatsUserException;
47 import com.liferay.portlet.blogs.model.BlogsStatsUser;
48 import com.liferay.portlet.blogs.model.impl.BlogsStatsUserImpl;
49 import com.liferay.portlet.blogs.model.impl.BlogsStatsUserModelImpl;
50
51 import java.util.ArrayList;
52 import java.util.Collections;
53 import java.util.List;
54
55
68 public class BlogsStatsUserPersistenceImpl extends BasePersistenceImpl
69 implements BlogsStatsUserPersistence {
70 public static final String FINDER_CLASS_NAME_ENTITY = BlogsStatsUserImpl.class.getName();
71 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
72 ".List";
73 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
74 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
75 FINDER_CLASS_NAME_LIST, "findByGroupId",
76 new String[] { Long.class.getName() });
77 public static final FinderPath FINDER_PATH_FIND_BY_OBC_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
78 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
79 FINDER_CLASS_NAME_LIST, "findByGroupId",
80 new String[] {
81 Long.class.getName(),
82
83 "java.lang.Integer", "java.lang.Integer",
84 "com.liferay.portal.kernel.util.OrderByComparator"
85 });
86 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
87 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
88 FINDER_CLASS_NAME_LIST, "countByGroupId",
89 new String[] { Long.class.getName() });
90 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
91 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
92 FINDER_CLASS_NAME_LIST, "findByUserId",
93 new String[] { Long.class.getName() });
94 public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
95 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
96 FINDER_CLASS_NAME_LIST, "findByUserId",
97 new String[] {
98 Long.class.getName(),
99
100 "java.lang.Integer", "java.lang.Integer",
101 "com.liferay.portal.kernel.util.OrderByComparator"
102 });
103 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
104 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
105 FINDER_CLASS_NAME_LIST, "countByUserId",
106 new String[] { Long.class.getName() });
107 public static final FinderPath FINDER_PATH_FETCH_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
108 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
109 FINDER_CLASS_NAME_ENTITY, "fetchByG_U",
110 new String[] { Long.class.getName(), Long.class.getName() });
111 public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
112 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
113 FINDER_CLASS_NAME_LIST, "countByG_U",
114 new String[] { Long.class.getName(), Long.class.getName() });
115 public static final FinderPath FINDER_PATH_FIND_BY_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
116 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
117 FINDER_CLASS_NAME_LIST, "findByG_E",
118 new String[] { Long.class.getName(), Integer.class.getName() });
119 public static final FinderPath FINDER_PATH_FIND_BY_OBC_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
120 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
121 FINDER_CLASS_NAME_LIST, "findByG_E",
122 new String[] {
123 Long.class.getName(), Integer.class.getName(),
124
125 "java.lang.Integer", "java.lang.Integer",
126 "com.liferay.portal.kernel.util.OrderByComparator"
127 });
128 public static final FinderPath FINDER_PATH_COUNT_BY_G_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
129 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
130 FINDER_CLASS_NAME_LIST, "countByG_E",
131 new String[] { Long.class.getName(), Integer.class.getName() });
132 public static final FinderPath FINDER_PATH_FIND_BY_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
133 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
134 FINDER_CLASS_NAME_LIST, "findByC_E",
135 new String[] { Long.class.getName(), Integer.class.getName() });
136 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
137 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
138 FINDER_CLASS_NAME_LIST, "findByC_E",
139 new String[] {
140 Long.class.getName(), Integer.class.getName(),
141
142 "java.lang.Integer", "java.lang.Integer",
143 "com.liferay.portal.kernel.util.OrderByComparator"
144 });
145 public static final FinderPath FINDER_PATH_COUNT_BY_C_E = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
146 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
147 FINDER_CLASS_NAME_LIST, "countByC_E",
148 new String[] { Long.class.getName(), Integer.class.getName() });
149 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
150 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
151 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
152 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
153 BlogsStatsUserModelImpl.FINDER_CACHE_ENABLED,
154 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
155
156 public void cacheResult(BlogsStatsUser blogsStatsUser) {
157 EntityCacheUtil.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
158 BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
159 blogsStatsUser);
160
161 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
162 new Object[] {
163 new Long(blogsStatsUser.getGroupId()),
164 new Long(blogsStatsUser.getUserId())
165 }, blogsStatsUser);
166 }
167
168 public void cacheResult(List<BlogsStatsUser> blogsStatsUsers) {
169 for (BlogsStatsUser blogsStatsUser : blogsStatsUsers) {
170 if (EntityCacheUtil.getResult(
171 BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
172 BlogsStatsUserImpl.class,
173 blogsStatsUser.getPrimaryKey(), this) == null) {
174 cacheResult(blogsStatsUser);
175 }
176 }
177 }
178
179 public void clearCache() {
180 CacheRegistry.clear(BlogsStatsUserImpl.class.getName());
181 EntityCacheUtil.clearCache(BlogsStatsUserImpl.class.getName());
182 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
184 }
185
186 public BlogsStatsUser create(long statsUserId) {
187 BlogsStatsUser blogsStatsUser = new BlogsStatsUserImpl();
188
189 blogsStatsUser.setNew(true);
190 blogsStatsUser.setPrimaryKey(statsUserId);
191
192 return blogsStatsUser;
193 }
194
195 public BlogsStatsUser remove(long statsUserId)
196 throws NoSuchStatsUserException, SystemException {
197 Session session = null;
198
199 try {
200 session = openSession();
201
202 BlogsStatsUser blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
203 new Long(statsUserId));
204
205 if (blogsStatsUser == null) {
206 if (_log.isWarnEnabled()) {
207 _log.warn("No BlogsStatsUser exists with the primary key " +
208 statsUserId);
209 }
210
211 throw new NoSuchStatsUserException(
212 "No BlogsStatsUser exists with the primary key " +
213 statsUserId);
214 }
215
216 return remove(blogsStatsUser);
217 }
218 catch (NoSuchStatsUserException nsee) {
219 throw nsee;
220 }
221 catch (Exception e) {
222 throw processException(e);
223 }
224 finally {
225 closeSession(session);
226 }
227 }
228
229 public BlogsStatsUser remove(BlogsStatsUser blogsStatsUser)
230 throws SystemException {
231 for (ModelListener<BlogsStatsUser> listener : listeners) {
232 listener.onBeforeRemove(blogsStatsUser);
233 }
234
235 blogsStatsUser = removeImpl(blogsStatsUser);
236
237 for (ModelListener<BlogsStatsUser> listener : listeners) {
238 listener.onAfterRemove(blogsStatsUser);
239 }
240
241 return blogsStatsUser;
242 }
243
244 protected BlogsStatsUser removeImpl(BlogsStatsUser blogsStatsUser)
245 throws SystemException {
246 Session session = null;
247
248 try {
249 session = openSession();
250
251 if (blogsStatsUser.isCachedModel() || BatchSessionUtil.isEnabled()) {
252 Object staleObject = session.get(BlogsStatsUserImpl.class,
253 blogsStatsUser.getPrimaryKeyObj());
254
255 if (staleObject != null) {
256 session.evict(staleObject);
257 }
258 }
259
260 session.delete(blogsStatsUser);
261
262 session.flush();
263 }
264 catch (Exception e) {
265 throw processException(e);
266 }
267 finally {
268 closeSession(session);
269 }
270
271 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
272
273 BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
274
275 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
276 new Object[] {
277 new Long(blogsStatsUserModelImpl.getOriginalGroupId()),
278 new Long(blogsStatsUserModelImpl.getOriginalUserId())
279 });
280
281 EntityCacheUtil.removeResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
282 BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey());
283
284 return blogsStatsUser;
285 }
286
287
290 public BlogsStatsUser update(BlogsStatsUser blogsStatsUser)
291 throws SystemException {
292 if (_log.isWarnEnabled()) {
293 _log.warn(
294 "Using the deprecated update(BlogsStatsUser blogsStatsUser) method. Use update(BlogsStatsUser blogsStatsUser, boolean merge) instead.");
295 }
296
297 return update(blogsStatsUser, false);
298 }
299
300
312 public BlogsStatsUser update(BlogsStatsUser blogsStatsUser, boolean merge)
313 throws SystemException {
314 boolean isNew = blogsStatsUser.isNew();
315
316 for (ModelListener<BlogsStatsUser> listener : listeners) {
317 if (isNew) {
318 listener.onBeforeCreate(blogsStatsUser);
319 }
320 else {
321 listener.onBeforeUpdate(blogsStatsUser);
322 }
323 }
324
325 blogsStatsUser = updateImpl(blogsStatsUser, merge);
326
327 for (ModelListener<BlogsStatsUser> listener : listeners) {
328 if (isNew) {
329 listener.onAfterCreate(blogsStatsUser);
330 }
331 else {
332 listener.onAfterUpdate(blogsStatsUser);
333 }
334 }
335
336 return blogsStatsUser;
337 }
338
339 public BlogsStatsUser updateImpl(
340 com.liferay.portlet.blogs.model.BlogsStatsUser blogsStatsUser,
341 boolean merge) throws SystemException {
342 boolean isNew = blogsStatsUser.isNew();
343
344 BlogsStatsUserModelImpl blogsStatsUserModelImpl = (BlogsStatsUserModelImpl)blogsStatsUser;
345
346 Session session = null;
347
348 try {
349 session = openSession();
350
351 BatchSessionUtil.update(session, blogsStatsUser, merge);
352
353 blogsStatsUser.setNew(false);
354 }
355 catch (Exception e) {
356 throw processException(e);
357 }
358 finally {
359 closeSession(session);
360 }
361
362 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
363
364 EntityCacheUtil.putResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
365 BlogsStatsUserImpl.class, blogsStatsUser.getPrimaryKey(),
366 blogsStatsUser);
367
368 if (!isNew &&
369 ((blogsStatsUser.getGroupId() != blogsStatsUserModelImpl.getOriginalGroupId()) ||
370 (blogsStatsUser.getUserId() != blogsStatsUserModelImpl.getOriginalUserId()))) {
371 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_U,
372 new Object[] {
373 new Long(blogsStatsUserModelImpl.getOriginalGroupId()),
374 new Long(blogsStatsUserModelImpl.getOriginalUserId())
375 });
376 }
377
378 if (isNew ||
379 ((blogsStatsUser.getGroupId() != blogsStatsUserModelImpl.getOriginalGroupId()) ||
380 (blogsStatsUser.getUserId() != blogsStatsUserModelImpl.getOriginalUserId()))) {
381 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
382 new Object[] {
383 new Long(blogsStatsUser.getGroupId()),
384 new Long(blogsStatsUser.getUserId())
385 }, blogsStatsUser);
386 }
387
388 return blogsStatsUser;
389 }
390
391 public BlogsStatsUser findByPrimaryKey(long statsUserId)
392 throws NoSuchStatsUserException, SystemException {
393 BlogsStatsUser blogsStatsUser = fetchByPrimaryKey(statsUserId);
394
395 if (blogsStatsUser == null) {
396 if (_log.isWarnEnabled()) {
397 _log.warn("No BlogsStatsUser exists with the primary key " +
398 statsUserId);
399 }
400
401 throw new NoSuchStatsUserException(
402 "No BlogsStatsUser exists with the primary key " + statsUserId);
403 }
404
405 return blogsStatsUser;
406 }
407
408 public BlogsStatsUser fetchByPrimaryKey(long statsUserId)
409 throws SystemException {
410 BlogsStatsUser blogsStatsUser = (BlogsStatsUser)EntityCacheUtil.getResult(BlogsStatsUserModelImpl.ENTITY_CACHE_ENABLED,
411 BlogsStatsUserImpl.class, statsUserId, this);
412
413 if (blogsStatsUser == null) {
414 Session session = null;
415
416 try {
417 session = openSession();
418
419 blogsStatsUser = (BlogsStatsUser)session.get(BlogsStatsUserImpl.class,
420 new Long(statsUserId));
421 }
422 catch (Exception e) {
423 throw processException(e);
424 }
425 finally {
426 if (blogsStatsUser != null) {
427 cacheResult(blogsStatsUser);
428 }
429
430 closeSession(session);
431 }
432 }
433
434 return blogsStatsUser;
435 }
436
437 public List<BlogsStatsUser> findByGroupId(long groupId)
438 throws SystemException {
439 Object[] finderArgs = new Object[] { new Long(groupId) };
440
441 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
442 finderArgs, this);
443
444 if (list == null) {
445 Session session = null;
446
447 try {
448 session = openSession();
449
450 StringBuilder query = new StringBuilder();
451
452 query.append(
453 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
454
455 query.append("blogsStatsUser.groupId = ?");
456
457 query.append(" ");
458
459 query.append("ORDER BY ");
460
461 query.append("blogsStatsUser.entryCount DESC");
462
463 Query q = session.createQuery(query.toString());
464
465 QueryPos qPos = QueryPos.getInstance(q);
466
467 qPos.add(groupId);
468
469 list = q.list();
470 }
471 catch (Exception e) {
472 throw processException(e);
473 }
474 finally {
475 if (list == null) {
476 list = new ArrayList<BlogsStatsUser>();
477 }
478
479 cacheResult(list);
480
481 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
482 finderArgs, list);
483
484 closeSession(session);
485 }
486 }
487
488 return list;
489 }
490
491 public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end)
492 throws SystemException {
493 return findByGroupId(groupId, start, end, null);
494 }
495
496 public List<BlogsStatsUser> findByGroupId(long groupId, int start, int end,
497 OrderByComparator obc) throws SystemException {
498 Object[] finderArgs = new Object[] {
499 new Long(groupId),
500
501 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
502 };
503
504 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
505 finderArgs, this);
506
507 if (list == null) {
508 Session session = null;
509
510 try {
511 session = openSession();
512
513 StringBuilder query = new StringBuilder();
514
515 query.append(
516 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
517
518 query.append("blogsStatsUser.groupId = ?");
519
520 query.append(" ");
521
522 if (obc != null) {
523 query.append("ORDER BY ");
524
525 String[] orderByFields = obc.getOrderByFields();
526
527 for (int i = 0; i < orderByFields.length; i++) {
528 query.append("blogsStatsUser.");
529 query.append(orderByFields[i]);
530
531 if (obc.isAscending()) {
532 query.append(" ASC");
533 }
534 else {
535 query.append(" DESC");
536 }
537
538 if ((i + 1) < orderByFields.length) {
539 query.append(", ");
540 }
541 }
542 }
543
544 else {
545 query.append("ORDER BY ");
546
547 query.append("blogsStatsUser.entryCount DESC");
548 }
549
550 Query q = session.createQuery(query.toString());
551
552 QueryPos qPos = QueryPos.getInstance(q);
553
554 qPos.add(groupId);
555
556 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
557 start, end);
558 }
559 catch (Exception e) {
560 throw processException(e);
561 }
562 finally {
563 if (list == null) {
564 list = new ArrayList<BlogsStatsUser>();
565 }
566
567 cacheResult(list);
568
569 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_GROUPID,
570 finderArgs, list);
571
572 closeSession(session);
573 }
574 }
575
576 return list;
577 }
578
579 public BlogsStatsUser findByGroupId_First(long groupId,
580 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
581 List<BlogsStatsUser> list = findByGroupId(groupId, 0, 1, obc);
582
583 if (list.isEmpty()) {
584 StringBuilder msg = new StringBuilder();
585
586 msg.append("No BlogsStatsUser exists with the key {");
587
588 msg.append("groupId=" + groupId);
589
590 msg.append(StringPool.CLOSE_CURLY_BRACE);
591
592 throw new NoSuchStatsUserException(msg.toString());
593 }
594 else {
595 return list.get(0);
596 }
597 }
598
599 public BlogsStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
600 throws NoSuchStatsUserException, SystemException {
601 int count = countByGroupId(groupId);
602
603 List<BlogsStatsUser> list = findByGroupId(groupId, count - 1, count, obc);
604
605 if (list.isEmpty()) {
606 StringBuilder msg = new StringBuilder();
607
608 msg.append("No BlogsStatsUser exists with the key {");
609
610 msg.append("groupId=" + groupId);
611
612 msg.append(StringPool.CLOSE_CURLY_BRACE);
613
614 throw new NoSuchStatsUserException(msg.toString());
615 }
616 else {
617 return list.get(0);
618 }
619 }
620
621 public BlogsStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
622 long groupId, OrderByComparator obc)
623 throws NoSuchStatsUserException, SystemException {
624 BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
625
626 int count = countByGroupId(groupId);
627
628 Session session = null;
629
630 try {
631 session = openSession();
632
633 StringBuilder query = new StringBuilder();
634
635 query.append(
636 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
637
638 query.append("blogsStatsUser.groupId = ?");
639
640 query.append(" ");
641
642 if (obc != null) {
643 query.append("ORDER BY ");
644
645 String[] orderByFields = obc.getOrderByFields();
646
647 for (int i = 0; i < orderByFields.length; i++) {
648 query.append("blogsStatsUser.");
649 query.append(orderByFields[i]);
650
651 if (obc.isAscending()) {
652 query.append(" ASC");
653 }
654 else {
655 query.append(" DESC");
656 }
657
658 if ((i + 1) < orderByFields.length) {
659 query.append(", ");
660 }
661 }
662 }
663
664 else {
665 query.append("ORDER BY ");
666
667 query.append("blogsStatsUser.entryCount DESC");
668 }
669
670 Query q = session.createQuery(query.toString());
671
672 QueryPos qPos = QueryPos.getInstance(q);
673
674 qPos.add(groupId);
675
676 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
677 blogsStatsUser);
678
679 BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
680
681 array[0] = (BlogsStatsUser)objArray[0];
682 array[1] = (BlogsStatsUser)objArray[1];
683 array[2] = (BlogsStatsUser)objArray[2];
684
685 return array;
686 }
687 catch (Exception e) {
688 throw processException(e);
689 }
690 finally {
691 closeSession(session);
692 }
693 }
694
695 public List<BlogsStatsUser> findByUserId(long userId)
696 throws SystemException {
697 Object[] finderArgs = new Object[] { new Long(userId) };
698
699 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
700 finderArgs, this);
701
702 if (list == null) {
703 Session session = null;
704
705 try {
706 session = openSession();
707
708 StringBuilder query = new StringBuilder();
709
710 query.append(
711 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
712
713 query.append("blogsStatsUser.userId = ?");
714
715 query.append(" ");
716
717 query.append("ORDER BY ");
718
719 query.append("blogsStatsUser.entryCount DESC");
720
721 Query q = session.createQuery(query.toString());
722
723 QueryPos qPos = QueryPos.getInstance(q);
724
725 qPos.add(userId);
726
727 list = q.list();
728 }
729 catch (Exception e) {
730 throw processException(e);
731 }
732 finally {
733 if (list == null) {
734 list = new ArrayList<BlogsStatsUser>();
735 }
736
737 cacheResult(list);
738
739 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
740 finderArgs, list);
741
742 closeSession(session);
743 }
744 }
745
746 return list;
747 }
748
749 public List<BlogsStatsUser> findByUserId(long userId, int start, int end)
750 throws SystemException {
751 return findByUserId(userId, start, end, null);
752 }
753
754 public List<BlogsStatsUser> findByUserId(long userId, int start, int end,
755 OrderByComparator obc) throws SystemException {
756 Object[] finderArgs = new Object[] {
757 new Long(userId),
758
759 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
760 };
761
762 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
763 finderArgs, this);
764
765 if (list == null) {
766 Session session = null;
767
768 try {
769 session = openSession();
770
771 StringBuilder query = new StringBuilder();
772
773 query.append(
774 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
775
776 query.append("blogsStatsUser.userId = ?");
777
778 query.append(" ");
779
780 if (obc != null) {
781 query.append("ORDER BY ");
782
783 String[] orderByFields = obc.getOrderByFields();
784
785 for (int i = 0; i < orderByFields.length; i++) {
786 query.append("blogsStatsUser.");
787 query.append(orderByFields[i]);
788
789 if (obc.isAscending()) {
790 query.append(" ASC");
791 }
792 else {
793 query.append(" DESC");
794 }
795
796 if ((i + 1) < orderByFields.length) {
797 query.append(", ");
798 }
799 }
800 }
801
802 else {
803 query.append("ORDER BY ");
804
805 query.append("blogsStatsUser.entryCount DESC");
806 }
807
808 Query q = session.createQuery(query.toString());
809
810 QueryPos qPos = QueryPos.getInstance(q);
811
812 qPos.add(userId);
813
814 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
815 start, end);
816 }
817 catch (Exception e) {
818 throw processException(e);
819 }
820 finally {
821 if (list == null) {
822 list = new ArrayList<BlogsStatsUser>();
823 }
824
825 cacheResult(list);
826
827 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
828 finderArgs, list);
829
830 closeSession(session);
831 }
832 }
833
834 return list;
835 }
836
837 public BlogsStatsUser findByUserId_First(long userId, OrderByComparator obc)
838 throws NoSuchStatsUserException, SystemException {
839 List<BlogsStatsUser> list = findByUserId(userId, 0, 1, obc);
840
841 if (list.isEmpty()) {
842 StringBuilder msg = new StringBuilder();
843
844 msg.append("No BlogsStatsUser exists with the key {");
845
846 msg.append("userId=" + userId);
847
848 msg.append(StringPool.CLOSE_CURLY_BRACE);
849
850 throw new NoSuchStatsUserException(msg.toString());
851 }
852 else {
853 return list.get(0);
854 }
855 }
856
857 public BlogsStatsUser findByUserId_Last(long userId, OrderByComparator obc)
858 throws NoSuchStatsUserException, SystemException {
859 int count = countByUserId(userId);
860
861 List<BlogsStatsUser> list = findByUserId(userId, count - 1, count, obc);
862
863 if (list.isEmpty()) {
864 StringBuilder msg = new StringBuilder();
865
866 msg.append("No BlogsStatsUser exists with the key {");
867
868 msg.append("userId=" + userId);
869
870 msg.append(StringPool.CLOSE_CURLY_BRACE);
871
872 throw new NoSuchStatsUserException(msg.toString());
873 }
874 else {
875 return list.get(0);
876 }
877 }
878
879 public BlogsStatsUser[] findByUserId_PrevAndNext(long statsUserId,
880 long userId, OrderByComparator obc)
881 throws NoSuchStatsUserException, SystemException {
882 BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
883
884 int count = countByUserId(userId);
885
886 Session session = null;
887
888 try {
889 session = openSession();
890
891 StringBuilder query = new StringBuilder();
892
893 query.append(
894 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
895
896 query.append("blogsStatsUser.userId = ?");
897
898 query.append(" ");
899
900 if (obc != null) {
901 query.append("ORDER BY ");
902
903 String[] orderByFields = obc.getOrderByFields();
904
905 for (int i = 0; i < orderByFields.length; i++) {
906 query.append("blogsStatsUser.");
907 query.append(orderByFields[i]);
908
909 if (obc.isAscending()) {
910 query.append(" ASC");
911 }
912 else {
913 query.append(" DESC");
914 }
915
916 if ((i + 1) < orderByFields.length) {
917 query.append(", ");
918 }
919 }
920 }
921
922 else {
923 query.append("ORDER BY ");
924
925 query.append("blogsStatsUser.entryCount DESC");
926 }
927
928 Query q = session.createQuery(query.toString());
929
930 QueryPos qPos = QueryPos.getInstance(q);
931
932 qPos.add(userId);
933
934 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
935 blogsStatsUser);
936
937 BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
938
939 array[0] = (BlogsStatsUser)objArray[0];
940 array[1] = (BlogsStatsUser)objArray[1];
941 array[2] = (BlogsStatsUser)objArray[2];
942
943 return array;
944 }
945 catch (Exception e) {
946 throw processException(e);
947 }
948 finally {
949 closeSession(session);
950 }
951 }
952
953 public BlogsStatsUser findByG_U(long groupId, long userId)
954 throws NoSuchStatsUserException, SystemException {
955 BlogsStatsUser blogsStatsUser = fetchByG_U(groupId, userId);
956
957 if (blogsStatsUser == null) {
958 StringBuilder msg = new StringBuilder();
959
960 msg.append("No BlogsStatsUser exists with the key {");
961
962 msg.append("groupId=" + groupId);
963
964 msg.append(", ");
965 msg.append("userId=" + userId);
966
967 msg.append(StringPool.CLOSE_CURLY_BRACE);
968
969 if (_log.isWarnEnabled()) {
970 _log.warn(msg.toString());
971 }
972
973 throw new NoSuchStatsUserException(msg.toString());
974 }
975
976 return blogsStatsUser;
977 }
978
979 public BlogsStatsUser fetchByG_U(long groupId, long userId)
980 throws SystemException {
981 return fetchByG_U(groupId, userId, true);
982 }
983
984 public BlogsStatsUser fetchByG_U(long groupId, long userId,
985 boolean retrieveFromCache) throws SystemException {
986 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
987
988 Object result = null;
989
990 if (retrieveFromCache) {
991 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_U,
992 finderArgs, this);
993 }
994
995 if (result == null) {
996 Session session = null;
997
998 try {
999 session = openSession();
1000
1001 StringBuilder query = new StringBuilder();
1002
1003 query.append(
1004 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1005
1006 query.append("blogsStatsUser.groupId = ?");
1007
1008 query.append(" AND ");
1009
1010 query.append("blogsStatsUser.userId = ?");
1011
1012 query.append(" ");
1013
1014 query.append("ORDER BY ");
1015
1016 query.append("blogsStatsUser.entryCount DESC");
1017
1018 Query q = session.createQuery(query.toString());
1019
1020 QueryPos qPos = QueryPos.getInstance(q);
1021
1022 qPos.add(groupId);
1023
1024 qPos.add(userId);
1025
1026 List<BlogsStatsUser> list = q.list();
1027
1028 result = list;
1029
1030 BlogsStatsUser blogsStatsUser = null;
1031
1032 if (list.isEmpty()) {
1033 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1034 finderArgs, list);
1035 }
1036 else {
1037 blogsStatsUser = list.get(0);
1038
1039 cacheResult(blogsStatsUser);
1040
1041 if ((blogsStatsUser.getGroupId() != groupId) ||
1042 (blogsStatsUser.getUserId() != userId)) {
1043 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1044 finderArgs, blogsStatsUser);
1045 }
1046 }
1047
1048 return blogsStatsUser;
1049 }
1050 catch (Exception e) {
1051 throw processException(e);
1052 }
1053 finally {
1054 if (result == null) {
1055 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_U,
1056 finderArgs, new ArrayList<BlogsStatsUser>());
1057 }
1058
1059 closeSession(session);
1060 }
1061 }
1062 else {
1063 if (result instanceof List<?>) {
1064 return null;
1065 }
1066 else {
1067 return (BlogsStatsUser)result;
1068 }
1069 }
1070 }
1071
1072 public List<BlogsStatsUser> findByG_E(long groupId, int entryCount)
1073 throws SystemException {
1074 Object[] finderArgs = new Object[] {
1075 new Long(groupId), new Integer(entryCount)
1076 };
1077
1078 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_E,
1079 finderArgs, this);
1080
1081 if (list == null) {
1082 Session session = null;
1083
1084 try {
1085 session = openSession();
1086
1087 StringBuilder query = new StringBuilder();
1088
1089 query.append(
1090 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1091
1092 query.append("blogsStatsUser.groupId = ?");
1093
1094 query.append(" AND ");
1095
1096 query.append("blogsStatsUser.entryCount != ?");
1097
1098 query.append(" ");
1099
1100 query.append("ORDER BY ");
1101
1102 query.append("blogsStatsUser.entryCount DESC");
1103
1104 Query q = session.createQuery(query.toString());
1105
1106 QueryPos qPos = QueryPos.getInstance(q);
1107
1108 qPos.add(groupId);
1109
1110 qPos.add(entryCount);
1111
1112 list = q.list();
1113 }
1114 catch (Exception e) {
1115 throw processException(e);
1116 }
1117 finally {
1118 if (list == null) {
1119 list = new ArrayList<BlogsStatsUser>();
1120 }
1121
1122 cacheResult(list);
1123
1124 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_E, finderArgs,
1125 list);
1126
1127 closeSession(session);
1128 }
1129 }
1130
1131 return list;
1132 }
1133
1134 public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1135 int start, int end) throws SystemException {
1136 return findByG_E(groupId, entryCount, start, end, null);
1137 }
1138
1139 public List<BlogsStatsUser> findByG_E(long groupId, int entryCount,
1140 int start, int end, OrderByComparator obc) throws SystemException {
1141 Object[] finderArgs = new Object[] {
1142 new Long(groupId), new Integer(entryCount),
1143
1144 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1145 };
1146
1147 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_G_E,
1148 finderArgs, this);
1149
1150 if (list == null) {
1151 Session session = null;
1152
1153 try {
1154 session = openSession();
1155
1156 StringBuilder query = new StringBuilder();
1157
1158 query.append(
1159 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1160
1161 query.append("blogsStatsUser.groupId = ?");
1162
1163 query.append(" AND ");
1164
1165 query.append("blogsStatsUser.entryCount != ?");
1166
1167 query.append(" ");
1168
1169 if (obc != null) {
1170 query.append("ORDER BY ");
1171
1172 String[] orderByFields = obc.getOrderByFields();
1173
1174 for (int i = 0; i < orderByFields.length; i++) {
1175 query.append("blogsStatsUser.");
1176 query.append(orderByFields[i]);
1177
1178 if (obc.isAscending()) {
1179 query.append(" ASC");
1180 }
1181 else {
1182 query.append(" DESC");
1183 }
1184
1185 if ((i + 1) < orderByFields.length) {
1186 query.append(", ");
1187 }
1188 }
1189 }
1190
1191 else {
1192 query.append("ORDER BY ");
1193
1194 query.append("blogsStatsUser.entryCount DESC");
1195 }
1196
1197 Query q = session.createQuery(query.toString());
1198
1199 QueryPos qPos = QueryPos.getInstance(q);
1200
1201 qPos.add(groupId);
1202
1203 qPos.add(entryCount);
1204
1205 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1206 start, end);
1207 }
1208 catch (Exception e) {
1209 throw processException(e);
1210 }
1211 finally {
1212 if (list == null) {
1213 list = new ArrayList<BlogsStatsUser>();
1214 }
1215
1216 cacheResult(list);
1217
1218 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_G_E,
1219 finderArgs, list);
1220
1221 closeSession(session);
1222 }
1223 }
1224
1225 return list;
1226 }
1227
1228 public BlogsStatsUser findByG_E_First(long groupId, int entryCount,
1229 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1230 List<BlogsStatsUser> list = findByG_E(groupId, entryCount, 0, 1, obc);
1231
1232 if (list.isEmpty()) {
1233 StringBuilder msg = new StringBuilder();
1234
1235 msg.append("No BlogsStatsUser exists with the key {");
1236
1237 msg.append("groupId=" + groupId);
1238
1239 msg.append(", ");
1240 msg.append("entryCount=" + entryCount);
1241
1242 msg.append(StringPool.CLOSE_CURLY_BRACE);
1243
1244 throw new NoSuchStatsUserException(msg.toString());
1245 }
1246 else {
1247 return list.get(0);
1248 }
1249 }
1250
1251 public BlogsStatsUser findByG_E_Last(long groupId, int entryCount,
1252 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1253 int count = countByG_E(groupId, entryCount);
1254
1255 List<BlogsStatsUser> list = findByG_E(groupId, entryCount, count - 1,
1256 count, obc);
1257
1258 if (list.isEmpty()) {
1259 StringBuilder msg = new StringBuilder();
1260
1261 msg.append("No BlogsStatsUser exists with the key {");
1262
1263 msg.append("groupId=" + groupId);
1264
1265 msg.append(", ");
1266 msg.append("entryCount=" + entryCount);
1267
1268 msg.append(StringPool.CLOSE_CURLY_BRACE);
1269
1270 throw new NoSuchStatsUserException(msg.toString());
1271 }
1272 else {
1273 return list.get(0);
1274 }
1275 }
1276
1277 public BlogsStatsUser[] findByG_E_PrevAndNext(long statsUserId,
1278 long groupId, int entryCount, OrderByComparator obc)
1279 throws NoSuchStatsUserException, SystemException {
1280 BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1281
1282 int count = countByG_E(groupId, entryCount);
1283
1284 Session session = null;
1285
1286 try {
1287 session = openSession();
1288
1289 StringBuilder query = new StringBuilder();
1290
1291 query.append(
1292 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1293
1294 query.append("blogsStatsUser.groupId = ?");
1295
1296 query.append(" AND ");
1297
1298 query.append("blogsStatsUser.entryCount != ?");
1299
1300 query.append(" ");
1301
1302 if (obc != null) {
1303 query.append("ORDER BY ");
1304
1305 String[] orderByFields = obc.getOrderByFields();
1306
1307 for (int i = 0; i < orderByFields.length; i++) {
1308 query.append("blogsStatsUser.");
1309 query.append(orderByFields[i]);
1310
1311 if (obc.isAscending()) {
1312 query.append(" ASC");
1313 }
1314 else {
1315 query.append(" DESC");
1316 }
1317
1318 if ((i + 1) < orderByFields.length) {
1319 query.append(", ");
1320 }
1321 }
1322 }
1323
1324 else {
1325 query.append("ORDER BY ");
1326
1327 query.append("blogsStatsUser.entryCount DESC");
1328 }
1329
1330 Query q = session.createQuery(query.toString());
1331
1332 QueryPos qPos = QueryPos.getInstance(q);
1333
1334 qPos.add(groupId);
1335
1336 qPos.add(entryCount);
1337
1338 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1339 blogsStatsUser);
1340
1341 BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1342
1343 array[0] = (BlogsStatsUser)objArray[0];
1344 array[1] = (BlogsStatsUser)objArray[1];
1345 array[2] = (BlogsStatsUser)objArray[2];
1346
1347 return array;
1348 }
1349 catch (Exception e) {
1350 throw processException(e);
1351 }
1352 finally {
1353 closeSession(session);
1354 }
1355 }
1356
1357 public List<BlogsStatsUser> findByC_E(long companyId, int entryCount)
1358 throws SystemException {
1359 Object[] finderArgs = new Object[] {
1360 new Long(companyId), new Integer(entryCount)
1361 };
1362
1363 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_E,
1364 finderArgs, this);
1365
1366 if (list == null) {
1367 Session session = null;
1368
1369 try {
1370 session = openSession();
1371
1372 StringBuilder query = new StringBuilder();
1373
1374 query.append(
1375 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1376
1377 query.append("blogsStatsUser.companyId = ?");
1378
1379 query.append(" AND ");
1380
1381 query.append("blogsStatsUser.entryCount != ?");
1382
1383 query.append(" ");
1384
1385 query.append("ORDER BY ");
1386
1387 query.append("blogsStatsUser.entryCount DESC");
1388
1389 Query q = session.createQuery(query.toString());
1390
1391 QueryPos qPos = QueryPos.getInstance(q);
1392
1393 qPos.add(companyId);
1394
1395 qPos.add(entryCount);
1396
1397 list = q.list();
1398 }
1399 catch (Exception e) {
1400 throw processException(e);
1401 }
1402 finally {
1403 if (list == null) {
1404 list = new ArrayList<BlogsStatsUser>();
1405 }
1406
1407 cacheResult(list);
1408
1409 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_E, finderArgs,
1410 list);
1411
1412 closeSession(session);
1413 }
1414 }
1415
1416 return list;
1417 }
1418
1419 public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1420 int start, int end) throws SystemException {
1421 return findByC_E(companyId, entryCount, start, end, null);
1422 }
1423
1424 public List<BlogsStatsUser> findByC_E(long companyId, int entryCount,
1425 int start, int end, OrderByComparator obc) throws SystemException {
1426 Object[] finderArgs = new Object[] {
1427 new Long(companyId), new Integer(entryCount),
1428
1429 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1430 };
1431
1432 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_E,
1433 finderArgs, this);
1434
1435 if (list == null) {
1436 Session session = null;
1437
1438 try {
1439 session = openSession();
1440
1441 StringBuilder query = new StringBuilder();
1442
1443 query.append(
1444 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1445
1446 query.append("blogsStatsUser.companyId = ?");
1447
1448 query.append(" AND ");
1449
1450 query.append("blogsStatsUser.entryCount != ?");
1451
1452 query.append(" ");
1453
1454 if (obc != null) {
1455 query.append("ORDER BY ");
1456
1457 String[] orderByFields = obc.getOrderByFields();
1458
1459 for (int i = 0; i < orderByFields.length; i++) {
1460 query.append("blogsStatsUser.");
1461 query.append(orderByFields[i]);
1462
1463 if (obc.isAscending()) {
1464 query.append(" ASC");
1465 }
1466 else {
1467 query.append(" DESC");
1468 }
1469
1470 if ((i + 1) < orderByFields.length) {
1471 query.append(", ");
1472 }
1473 }
1474 }
1475
1476 else {
1477 query.append("ORDER BY ");
1478
1479 query.append("blogsStatsUser.entryCount DESC");
1480 }
1481
1482 Query q = session.createQuery(query.toString());
1483
1484 QueryPos qPos = QueryPos.getInstance(q);
1485
1486 qPos.add(companyId);
1487
1488 qPos.add(entryCount);
1489
1490 list = (List<BlogsStatsUser>)QueryUtil.list(q, getDialect(),
1491 start, end);
1492 }
1493 catch (Exception e) {
1494 throw processException(e);
1495 }
1496 finally {
1497 if (list == null) {
1498 list = new ArrayList<BlogsStatsUser>();
1499 }
1500
1501 cacheResult(list);
1502
1503 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_E,
1504 finderArgs, list);
1505
1506 closeSession(session);
1507 }
1508 }
1509
1510 return list;
1511 }
1512
1513 public BlogsStatsUser findByC_E_First(long companyId, int entryCount,
1514 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1515 List<BlogsStatsUser> list = findByC_E(companyId, entryCount, 0, 1, obc);
1516
1517 if (list.isEmpty()) {
1518 StringBuilder msg = new StringBuilder();
1519
1520 msg.append("No BlogsStatsUser exists with the key {");
1521
1522 msg.append("companyId=" + companyId);
1523
1524 msg.append(", ");
1525 msg.append("entryCount=" + entryCount);
1526
1527 msg.append(StringPool.CLOSE_CURLY_BRACE);
1528
1529 throw new NoSuchStatsUserException(msg.toString());
1530 }
1531 else {
1532 return list.get(0);
1533 }
1534 }
1535
1536 public BlogsStatsUser findByC_E_Last(long companyId, int entryCount,
1537 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1538 int count = countByC_E(companyId, entryCount);
1539
1540 List<BlogsStatsUser> list = findByC_E(companyId, entryCount, count - 1,
1541 count, obc);
1542
1543 if (list.isEmpty()) {
1544 StringBuilder msg = new StringBuilder();
1545
1546 msg.append("No BlogsStatsUser exists with the key {");
1547
1548 msg.append("companyId=" + companyId);
1549
1550 msg.append(", ");
1551 msg.append("entryCount=" + entryCount);
1552
1553 msg.append(StringPool.CLOSE_CURLY_BRACE);
1554
1555 throw new NoSuchStatsUserException(msg.toString());
1556 }
1557 else {
1558 return list.get(0);
1559 }
1560 }
1561
1562 public BlogsStatsUser[] findByC_E_PrevAndNext(long statsUserId,
1563 long companyId, int entryCount, OrderByComparator obc)
1564 throws NoSuchStatsUserException, SystemException {
1565 BlogsStatsUser blogsStatsUser = findByPrimaryKey(statsUserId);
1566
1567 int count = countByC_E(companyId, entryCount);
1568
1569 Session session = null;
1570
1571 try {
1572 session = openSession();
1573
1574 StringBuilder query = new StringBuilder();
1575
1576 query.append(
1577 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser WHERE ");
1578
1579 query.append("blogsStatsUser.companyId = ?");
1580
1581 query.append(" AND ");
1582
1583 query.append("blogsStatsUser.entryCount != ?");
1584
1585 query.append(" ");
1586
1587 if (obc != null) {
1588 query.append("ORDER BY ");
1589
1590 String[] orderByFields = obc.getOrderByFields();
1591
1592 for (int i = 0; i < orderByFields.length; i++) {
1593 query.append("blogsStatsUser.");
1594 query.append(orderByFields[i]);
1595
1596 if (obc.isAscending()) {
1597 query.append(" ASC");
1598 }
1599 else {
1600 query.append(" DESC");
1601 }
1602
1603 if ((i + 1) < orderByFields.length) {
1604 query.append(", ");
1605 }
1606 }
1607 }
1608
1609 else {
1610 query.append("ORDER BY ");
1611
1612 query.append("blogsStatsUser.entryCount DESC");
1613 }
1614
1615 Query q = session.createQuery(query.toString());
1616
1617 QueryPos qPos = QueryPos.getInstance(q);
1618
1619 qPos.add(companyId);
1620
1621 qPos.add(entryCount);
1622
1623 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1624 blogsStatsUser);
1625
1626 BlogsStatsUser[] array = new BlogsStatsUserImpl[3];
1627
1628 array[0] = (BlogsStatsUser)objArray[0];
1629 array[1] = (BlogsStatsUser)objArray[1];
1630 array[2] = (BlogsStatsUser)objArray[2];
1631
1632 return array;
1633 }
1634 catch (Exception e) {
1635 throw processException(e);
1636 }
1637 finally {
1638 closeSession(session);
1639 }
1640 }
1641
1642 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1643 throws SystemException {
1644 Session session = null;
1645
1646 try {
1647 session = openSession();
1648
1649 dynamicQuery.compile(session);
1650
1651 return dynamicQuery.list();
1652 }
1653 catch (Exception e) {
1654 throw processException(e);
1655 }
1656 finally {
1657 closeSession(session);
1658 }
1659 }
1660
1661 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1662 int start, int end) throws SystemException {
1663 Session session = null;
1664
1665 try {
1666 session = openSession();
1667
1668 dynamicQuery.setLimit(start, end);
1669
1670 dynamicQuery.compile(session);
1671
1672 return dynamicQuery.list();
1673 }
1674 catch (Exception e) {
1675 throw processException(e);
1676 }
1677 finally {
1678 closeSession(session);
1679 }
1680 }
1681
1682 public List<BlogsStatsUser> findAll() throws SystemException {
1683 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1684 }
1685
1686 public List<BlogsStatsUser> findAll(int start, int end)
1687 throws SystemException {
1688 return findAll(start, end, null);
1689 }
1690
1691 public List<BlogsStatsUser> findAll(int start, int end,
1692 OrderByComparator obc) throws SystemException {
1693 Object[] finderArgs = new Object[] {
1694 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1695 };
1696
1697 List<BlogsStatsUser> list = (List<BlogsStatsUser>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1698 finderArgs, this);
1699
1700 if (list == null) {
1701 Session session = null;
1702
1703 try {
1704 session = openSession();
1705
1706 StringBuilder query = new StringBuilder();
1707
1708 query.append(
1709 "SELECT blogsStatsUser FROM BlogsStatsUser blogsStatsUser ");
1710
1711 if (obc != null) {
1712 query.append("ORDER BY ");
1713
1714 String[] orderByFields = obc.getOrderByFields();
1715
1716 for (int i = 0; i < orderByFields.length; i++) {
1717 query.append("blogsStatsUser.");
1718 query.append(orderByFields[i]);
1719
1720 if (obc.isAscending()) {
1721 query.append(" ASC");
1722 }
1723 else {
1724 query.append(" DESC");
1725 }
1726
1727 if ((i + 1) < orderByFields.length) {
1728 query.append(", ");
1729 }
1730 }
1731 }
1732
1733 else {
1734 query.append("ORDER BY ");
1735
1736 query.append("blogsStatsUser.entryCount DESC");
1737 }
1738
1739 Query q = session.createQuery(query.toString());
1740
1741 if (obc == null) {
1742 list = (List<BlogsStatsUser>)QueryUtil.list(q,
1743 getDialect(), start, end, false);
1744
1745 Collections.sort(list);
1746 }
1747 else {
1748 list = (List<BlogsStatsUser>)QueryUtil.list(q,
1749 getDialect(), start, end);
1750 }
1751 }
1752 catch (Exception e) {
1753 throw processException(e);
1754 }
1755 finally {
1756 if (list == null) {
1757 list = new ArrayList<BlogsStatsUser>();
1758 }
1759
1760 cacheResult(list);
1761
1762 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1763
1764 closeSession(session);
1765 }
1766 }
1767
1768 return list;
1769 }
1770
1771 public void removeByGroupId(long groupId) throws SystemException {
1772 for (BlogsStatsUser blogsStatsUser : findByGroupId(groupId)) {
1773 remove(blogsStatsUser);
1774 }
1775 }
1776
1777 public void removeByUserId(long userId) throws SystemException {
1778 for (BlogsStatsUser blogsStatsUser : findByUserId(userId)) {
1779 remove(blogsStatsUser);
1780 }
1781 }
1782
1783 public void removeByG_U(long groupId, long userId)
1784 throws NoSuchStatsUserException, SystemException {
1785 BlogsStatsUser blogsStatsUser = findByG_U(groupId, userId);
1786
1787 remove(blogsStatsUser);
1788 }
1789
1790 public void removeByG_E(long groupId, int entryCount)
1791 throws SystemException {
1792 for (BlogsStatsUser blogsStatsUser : findByG_E(groupId, entryCount)) {
1793 remove(blogsStatsUser);
1794 }
1795 }
1796
1797 public void removeByC_E(long companyId, int entryCount)
1798 throws SystemException {
1799 for (BlogsStatsUser blogsStatsUser : findByC_E(companyId, entryCount)) {
1800 remove(blogsStatsUser);
1801 }
1802 }
1803
1804 public void removeAll() throws SystemException {
1805 for (BlogsStatsUser blogsStatsUser : findAll()) {
1806 remove(blogsStatsUser);
1807 }
1808 }
1809
1810 public int countByGroupId(long groupId) throws SystemException {
1811 Object[] finderArgs = new Object[] { new Long(groupId) };
1812
1813 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1814 finderArgs, this);
1815
1816 if (count == null) {
1817 Session session = null;
1818
1819 try {
1820 session = openSession();
1821
1822 StringBuilder query = new StringBuilder();
1823
1824 query.append("SELECT COUNT(blogsStatsUser) ");
1825 query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1826
1827 query.append("blogsStatsUser.groupId = ?");
1828
1829 query.append(" ");
1830
1831 Query q = session.createQuery(query.toString());
1832
1833 QueryPos qPos = QueryPos.getInstance(q);
1834
1835 qPos.add(groupId);
1836
1837 count = (Long)q.uniqueResult();
1838 }
1839 catch (Exception e) {
1840 throw processException(e);
1841 }
1842 finally {
1843 if (count == null) {
1844 count = Long.valueOf(0);
1845 }
1846
1847 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1848 finderArgs, count);
1849
1850 closeSession(session);
1851 }
1852 }
1853
1854 return count.intValue();
1855 }
1856
1857 public int countByUserId(long userId) throws SystemException {
1858 Object[] finderArgs = new Object[] { new Long(userId) };
1859
1860 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1861 finderArgs, this);
1862
1863 if (count == null) {
1864 Session session = null;
1865
1866 try {
1867 session = openSession();
1868
1869 StringBuilder query = new StringBuilder();
1870
1871 query.append("SELECT COUNT(blogsStatsUser) ");
1872 query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1873
1874 query.append("blogsStatsUser.userId = ?");
1875
1876 query.append(" ");
1877
1878 Query q = session.createQuery(query.toString());
1879
1880 QueryPos qPos = QueryPos.getInstance(q);
1881
1882 qPos.add(userId);
1883
1884 count = (Long)q.uniqueResult();
1885 }
1886 catch (Exception e) {
1887 throw processException(e);
1888 }
1889 finally {
1890 if (count == null) {
1891 count = Long.valueOf(0);
1892 }
1893
1894 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1895 finderArgs, count);
1896
1897 closeSession(session);
1898 }
1899 }
1900
1901 return count.intValue();
1902 }
1903
1904 public int countByG_U(long groupId, long userId) throws SystemException {
1905 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1906
1907 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_U,
1908 finderArgs, this);
1909
1910 if (count == null) {
1911 Session session = null;
1912
1913 try {
1914 session = openSession();
1915
1916 StringBuilder query = new StringBuilder();
1917
1918 query.append("SELECT COUNT(blogsStatsUser) ");
1919 query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1920
1921 query.append("blogsStatsUser.groupId = ?");
1922
1923 query.append(" AND ");
1924
1925 query.append("blogsStatsUser.userId = ?");
1926
1927 query.append(" ");
1928
1929 Query q = session.createQuery(query.toString());
1930
1931 QueryPos qPos = QueryPos.getInstance(q);
1932
1933 qPos.add(groupId);
1934
1935 qPos.add(userId);
1936
1937 count = (Long)q.uniqueResult();
1938 }
1939 catch (Exception e) {
1940 throw processException(e);
1941 }
1942 finally {
1943 if (count == null) {
1944 count = Long.valueOf(0);
1945 }
1946
1947 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_U, finderArgs,
1948 count);
1949
1950 closeSession(session);
1951 }
1952 }
1953
1954 return count.intValue();
1955 }
1956
1957 public int countByG_E(long groupId, int entryCount)
1958 throws SystemException {
1959 Object[] finderArgs = new Object[] {
1960 new Long(groupId), new Integer(entryCount)
1961 };
1962
1963 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_E,
1964 finderArgs, this);
1965
1966 if (count == null) {
1967 Session session = null;
1968
1969 try {
1970 session = openSession();
1971
1972 StringBuilder query = new StringBuilder();
1973
1974 query.append("SELECT COUNT(blogsStatsUser) ");
1975 query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
1976
1977 query.append("blogsStatsUser.groupId = ?");
1978
1979 query.append(" AND ");
1980
1981 query.append("blogsStatsUser.entryCount != ?");
1982
1983 query.append(" ");
1984
1985 Query q = session.createQuery(query.toString());
1986
1987 QueryPos qPos = QueryPos.getInstance(q);
1988
1989 qPos.add(groupId);
1990
1991 qPos.add(entryCount);
1992
1993 count = (Long)q.uniqueResult();
1994 }
1995 catch (Exception e) {
1996 throw processException(e);
1997 }
1998 finally {
1999 if (count == null) {
2000 count = Long.valueOf(0);
2001 }
2002
2003 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_E, finderArgs,
2004 count);
2005
2006 closeSession(session);
2007 }
2008 }
2009
2010 return count.intValue();
2011 }
2012
2013 public int countByC_E(long companyId, int entryCount)
2014 throws SystemException {
2015 Object[] finderArgs = new Object[] {
2016 new Long(companyId), new Integer(entryCount)
2017 };
2018
2019 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_E,
2020 finderArgs, this);
2021
2022 if (count == null) {
2023 Session session = null;
2024
2025 try {
2026 session = openSession();
2027
2028 StringBuilder query = new StringBuilder();
2029
2030 query.append("SELECT COUNT(blogsStatsUser) ");
2031 query.append("FROM BlogsStatsUser blogsStatsUser WHERE ");
2032
2033 query.append("blogsStatsUser.companyId = ?");
2034
2035 query.append(" AND ");
2036
2037 query.append("blogsStatsUser.entryCount != ?");
2038
2039 query.append(" ");
2040
2041 Query q = session.createQuery(query.toString());
2042
2043 QueryPos qPos = QueryPos.getInstance(q);
2044
2045 qPos.add(companyId);
2046
2047 qPos.add(entryCount);
2048
2049 count = (Long)q.uniqueResult();
2050 }
2051 catch (Exception e) {
2052 throw processException(e);
2053 }
2054 finally {
2055 if (count == null) {
2056 count = Long.valueOf(0);
2057 }
2058
2059 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_E, finderArgs,
2060 count);
2061
2062 closeSession(session);
2063 }
2064 }
2065
2066 return count.intValue();
2067 }
2068
2069 public int countAll() throws SystemException {
2070 Object[] finderArgs = new Object[0];
2071
2072 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2073 finderArgs, this);
2074
2075 if (count == null) {
2076 Session session = null;
2077
2078 try {
2079 session = openSession();
2080
2081 Query q = session.createQuery(
2082 "SELECT COUNT(blogsStatsUser) FROM BlogsStatsUser blogsStatsUser");
2083
2084 count = (Long)q.uniqueResult();
2085 }
2086 catch (Exception e) {
2087 throw processException(e);
2088 }
2089 finally {
2090 if (count == null) {
2091 count = Long.valueOf(0);
2092 }
2093
2094 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
2095 count);
2096
2097 closeSession(session);
2098 }
2099 }
2100
2101 return count.intValue();
2102 }
2103
2104 public void afterPropertiesSet() {
2105 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2106 com.liferay.portal.util.PropsUtil.get(
2107 "value.object.listener.com.liferay.portlet.blogs.model.BlogsStatsUser")));
2108
2109 if (listenerClassNames.length > 0) {
2110 try {
2111 List<ModelListener<BlogsStatsUser>> listenersList = new ArrayList<ModelListener<BlogsStatsUser>>();
2112
2113 for (String listenerClassName : listenerClassNames) {
2114 listenersList.add((ModelListener<BlogsStatsUser>)Class.forName(
2115 listenerClassName).newInstance());
2116 }
2117
2118 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2119 }
2120 catch (Exception e) {
2121 _log.error(e);
2122 }
2123 }
2124 }
2125
2126 @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
2127 protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
2128 @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence.impl")
2129 protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
2130 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
2131 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2132 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2133 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2134 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2135 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2136 private static Log _log = LogFactoryUtil.getLog(BlogsStatsUserPersistenceImpl.class);
2137}