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