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