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