001
014
015 package com.liferay.portlet.messageboards.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.message.boards.kernel.exception.NoSuchMailingListException;
020 import com.liferay.message.boards.kernel.model.MBMailingList;
021 import com.liferay.message.boards.kernel.service.persistence.MBMailingListPersistence;
022
023 import com.liferay.portal.kernel.bean.BeanReference;
024 import com.liferay.portal.kernel.dao.orm.EntityCache;
025 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026 import com.liferay.portal.kernel.dao.orm.FinderCache;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.Session;
033 import com.liferay.portal.kernel.log.Log;
034 import com.liferay.portal.kernel.log.LogFactoryUtil;
035 import com.liferay.portal.kernel.model.CacheModel;
036 import com.liferay.portal.kernel.service.ServiceContext;
037 import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
038 import com.liferay.portal.kernel.service.persistence.CompanyProvider;
039 import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
040 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
041 import com.liferay.portal.kernel.util.OrderByComparator;
042 import com.liferay.portal.kernel.util.SetUtil;
043 import com.liferay.portal.kernel.util.StringBundler;
044 import com.liferay.portal.kernel.util.StringPool;
045 import com.liferay.portal.kernel.util.Validator;
046 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
047
048 import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
049 import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
050
051 import java.io.Serializable;
052
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.HashMap;
056 import java.util.HashSet;
057 import java.util.Iterator;
058 import java.util.List;
059 import java.util.Map;
060 import java.util.Objects;
061 import java.util.Set;
062
063
075 @ProviderType
076 public class MBMailingListPersistenceImpl extends BasePersistenceImpl<MBMailingList>
077 implements MBMailingListPersistence {
078
083 public static final String FINDER_CLASS_NAME_ENTITY = MBMailingListImpl.class.getName();
084 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085 ".List1";
086 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087 ".List2";
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
089 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
090 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091 "findAll", new String[0]);
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
093 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
094 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
095 "findAll", new String[0]);
096 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
097 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
099 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
100 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
101 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
102 "findByUuid",
103 new String[] {
104 String.class.getName(),
105
106 Integer.class.getName(), Integer.class.getName(),
107 OrderByComparator.class.getName()
108 });
109 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
110 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
111 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
112 "findByUuid", new String[] { String.class.getName() },
113 MBMailingListModelImpl.UUID_COLUMN_BITMASK);
114 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
115 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
117 new String[] { String.class.getName() });
118
119
125 @Override
126 public List<MBMailingList> findByUuid(String uuid) {
127 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
128 }
129
130
142 @Override
143 public List<MBMailingList> findByUuid(String uuid, int start, int end) {
144 return findByUuid(uuid, start, end, null);
145 }
146
147
160 @Override
161 public List<MBMailingList> findByUuid(String uuid, int start, int end,
162 OrderByComparator<MBMailingList> orderByComparator) {
163 return findByUuid(uuid, start, end, orderByComparator, true);
164 }
165
166
180 @Override
181 public List<MBMailingList> findByUuid(String uuid, int start, int end,
182 OrderByComparator<MBMailingList> orderByComparator,
183 boolean retrieveFromCache) {
184 boolean pagination = true;
185 FinderPath finderPath = null;
186 Object[] finderArgs = null;
187
188 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
189 (orderByComparator == null)) {
190 pagination = false;
191 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
192 finderArgs = new Object[] { uuid };
193 }
194 else {
195 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
196 finderArgs = new Object[] { uuid, start, end, orderByComparator };
197 }
198
199 List<MBMailingList> list = null;
200
201 if (retrieveFromCache) {
202 list = (List<MBMailingList>)finderCache.getResult(finderPath,
203 finderArgs, this);
204
205 if ((list != null) && !list.isEmpty()) {
206 for (MBMailingList mbMailingList : list) {
207 if (!Objects.equals(uuid, mbMailingList.getUuid())) {
208 list = null;
209
210 break;
211 }
212 }
213 }
214 }
215
216 if (list == null) {
217 StringBundler query = null;
218
219 if (orderByComparator != null) {
220 query = new StringBundler(3 +
221 (orderByComparator.getOrderByFields().length * 2));
222 }
223 else {
224 query = new StringBundler(3);
225 }
226
227 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
228
229 boolean bindUuid = false;
230
231 if (uuid == null) {
232 query.append(_FINDER_COLUMN_UUID_UUID_1);
233 }
234 else if (uuid.equals(StringPool.BLANK)) {
235 query.append(_FINDER_COLUMN_UUID_UUID_3);
236 }
237 else {
238 bindUuid = true;
239
240 query.append(_FINDER_COLUMN_UUID_UUID_2);
241 }
242
243 if (orderByComparator != null) {
244 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
245 orderByComparator);
246 }
247 else
248 if (pagination) {
249 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
250 }
251
252 String sql = query.toString();
253
254 Session session = null;
255
256 try {
257 session = openSession();
258
259 Query q = session.createQuery(sql);
260
261 QueryPos qPos = QueryPos.getInstance(q);
262
263 if (bindUuid) {
264 qPos.add(uuid);
265 }
266
267 if (!pagination) {
268 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
269 start, end, false);
270
271 Collections.sort(list);
272
273 list = Collections.unmodifiableList(list);
274 }
275 else {
276 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
277 start, end);
278 }
279
280 cacheResult(list);
281
282 finderCache.putResult(finderPath, finderArgs, list);
283 }
284 catch (Exception e) {
285 finderCache.removeResult(finderPath, finderArgs);
286
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292 }
293
294 return list;
295 }
296
297
305 @Override
306 public MBMailingList findByUuid_First(String uuid,
307 OrderByComparator<MBMailingList> orderByComparator)
308 throws NoSuchMailingListException {
309 MBMailingList mbMailingList = fetchByUuid_First(uuid, orderByComparator);
310
311 if (mbMailingList != null) {
312 return mbMailingList;
313 }
314
315 StringBundler msg = new StringBundler(4);
316
317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318
319 msg.append("uuid=");
320 msg.append(uuid);
321
322 msg.append(StringPool.CLOSE_CURLY_BRACE);
323
324 throw new NoSuchMailingListException(msg.toString());
325 }
326
327
334 @Override
335 public MBMailingList fetchByUuid_First(String uuid,
336 OrderByComparator<MBMailingList> orderByComparator) {
337 List<MBMailingList> list = findByUuid(uuid, 0, 1, orderByComparator);
338
339 if (!list.isEmpty()) {
340 return list.get(0);
341 }
342
343 return null;
344 }
345
346
354 @Override
355 public MBMailingList findByUuid_Last(String uuid,
356 OrderByComparator<MBMailingList> orderByComparator)
357 throws NoSuchMailingListException {
358 MBMailingList mbMailingList = fetchByUuid_Last(uuid, orderByComparator);
359
360 if (mbMailingList != null) {
361 return mbMailingList;
362 }
363
364 StringBundler msg = new StringBundler(4);
365
366 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
367
368 msg.append("uuid=");
369 msg.append(uuid);
370
371 msg.append(StringPool.CLOSE_CURLY_BRACE);
372
373 throw new NoSuchMailingListException(msg.toString());
374 }
375
376
383 @Override
384 public MBMailingList fetchByUuid_Last(String uuid,
385 OrderByComparator<MBMailingList> orderByComparator) {
386 int count = countByUuid(uuid);
387
388 if (count == 0) {
389 return null;
390 }
391
392 List<MBMailingList> list = findByUuid(uuid, count - 1, count,
393 orderByComparator);
394
395 if (!list.isEmpty()) {
396 return list.get(0);
397 }
398
399 return null;
400 }
401
402
411 @Override
412 public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
413 String uuid, OrderByComparator<MBMailingList> orderByComparator)
414 throws NoSuchMailingListException {
415 MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
416
417 Session session = null;
418
419 try {
420 session = openSession();
421
422 MBMailingList[] array = new MBMailingListImpl[3];
423
424 array[0] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
425 orderByComparator, true);
426
427 array[1] = mbMailingList;
428
429 array[2] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
430 orderByComparator, false);
431
432 return array;
433 }
434 catch (Exception e) {
435 throw processException(e);
436 }
437 finally {
438 closeSession(session);
439 }
440 }
441
442 protected MBMailingList getByUuid_PrevAndNext(Session session,
443 MBMailingList mbMailingList, String uuid,
444 OrderByComparator<MBMailingList> orderByComparator, boolean previous) {
445 StringBundler query = null;
446
447 if (orderByComparator != null) {
448 query = new StringBundler(4 +
449 (orderByComparator.getOrderByConditionFields().length * 3) +
450 (orderByComparator.getOrderByFields().length * 3));
451 }
452 else {
453 query = new StringBundler(3);
454 }
455
456 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
457
458 boolean bindUuid = false;
459
460 if (uuid == null) {
461 query.append(_FINDER_COLUMN_UUID_UUID_1);
462 }
463 else if (uuid.equals(StringPool.BLANK)) {
464 query.append(_FINDER_COLUMN_UUID_UUID_3);
465 }
466 else {
467 bindUuid = true;
468
469 query.append(_FINDER_COLUMN_UUID_UUID_2);
470 }
471
472 if (orderByComparator != null) {
473 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
474
475 if (orderByConditionFields.length > 0) {
476 query.append(WHERE_AND);
477 }
478
479 for (int i = 0; i < orderByConditionFields.length; i++) {
480 query.append(_ORDER_BY_ENTITY_ALIAS);
481 query.append(orderByConditionFields[i]);
482
483 if ((i + 1) < orderByConditionFields.length) {
484 if (orderByComparator.isAscending() ^ previous) {
485 query.append(WHERE_GREATER_THAN_HAS_NEXT);
486 }
487 else {
488 query.append(WHERE_LESSER_THAN_HAS_NEXT);
489 }
490 }
491 else {
492 if (orderByComparator.isAscending() ^ previous) {
493 query.append(WHERE_GREATER_THAN);
494 }
495 else {
496 query.append(WHERE_LESSER_THAN);
497 }
498 }
499 }
500
501 query.append(ORDER_BY_CLAUSE);
502
503 String[] orderByFields = orderByComparator.getOrderByFields();
504
505 for (int i = 0; i < orderByFields.length; i++) {
506 query.append(_ORDER_BY_ENTITY_ALIAS);
507 query.append(orderByFields[i]);
508
509 if ((i + 1) < orderByFields.length) {
510 if (orderByComparator.isAscending() ^ previous) {
511 query.append(ORDER_BY_ASC_HAS_NEXT);
512 }
513 else {
514 query.append(ORDER_BY_DESC_HAS_NEXT);
515 }
516 }
517 else {
518 if (orderByComparator.isAscending() ^ previous) {
519 query.append(ORDER_BY_ASC);
520 }
521 else {
522 query.append(ORDER_BY_DESC);
523 }
524 }
525 }
526 }
527 else {
528 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
529 }
530
531 String sql = query.toString();
532
533 Query q = session.createQuery(sql);
534
535 q.setFirstResult(0);
536 q.setMaxResults(2);
537
538 QueryPos qPos = QueryPos.getInstance(q);
539
540 if (bindUuid) {
541 qPos.add(uuid);
542 }
543
544 if (orderByComparator != null) {
545 Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
546
547 for (Object value : values) {
548 qPos.add(value);
549 }
550 }
551
552 List<MBMailingList> list = q.list();
553
554 if (list.size() == 2) {
555 return list.get(1);
556 }
557 else {
558 return null;
559 }
560 }
561
562
567 @Override
568 public void removeByUuid(String uuid) {
569 for (MBMailingList mbMailingList : findByUuid(uuid, QueryUtil.ALL_POS,
570 QueryUtil.ALL_POS, null)) {
571 remove(mbMailingList);
572 }
573 }
574
575
581 @Override
582 public int countByUuid(String uuid) {
583 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
584
585 Object[] finderArgs = new Object[] { uuid };
586
587 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
588
589 if (count == null) {
590 StringBundler query = new StringBundler(2);
591
592 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
593
594 boolean bindUuid = false;
595
596 if (uuid == null) {
597 query.append(_FINDER_COLUMN_UUID_UUID_1);
598 }
599 else if (uuid.equals(StringPool.BLANK)) {
600 query.append(_FINDER_COLUMN_UUID_UUID_3);
601 }
602 else {
603 bindUuid = true;
604
605 query.append(_FINDER_COLUMN_UUID_UUID_2);
606 }
607
608 String sql = query.toString();
609
610 Session session = null;
611
612 try {
613 session = openSession();
614
615 Query q = session.createQuery(sql);
616
617 QueryPos qPos = QueryPos.getInstance(q);
618
619 if (bindUuid) {
620 qPos.add(uuid);
621 }
622
623 count = (Long)q.uniqueResult();
624
625 finderCache.putResult(finderPath, finderArgs, count);
626 }
627 catch (Exception e) {
628 finderCache.removeResult(finderPath, finderArgs);
629
630 throw processException(e);
631 }
632 finally {
633 closeSession(session);
634 }
635 }
636
637 return count.intValue();
638 }
639
640 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
641 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
642 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = '')";
643 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
644 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
645 MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
646 new String[] { String.class.getName(), Long.class.getName() },
647 MBMailingListModelImpl.UUID_COLUMN_BITMASK |
648 MBMailingListModelImpl.GROUPID_COLUMN_BITMASK);
649 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
650 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
651 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
652 new String[] { String.class.getName(), Long.class.getName() });
653
654
662 @Override
663 public MBMailingList findByUUID_G(String uuid, long groupId)
664 throws NoSuchMailingListException {
665 MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
666
667 if (mbMailingList == null) {
668 StringBundler msg = new StringBundler(6);
669
670 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
671
672 msg.append("uuid=");
673 msg.append(uuid);
674
675 msg.append(", groupId=");
676 msg.append(groupId);
677
678 msg.append(StringPool.CLOSE_CURLY_BRACE);
679
680 if (_log.isDebugEnabled()) {
681 _log.debug(msg.toString());
682 }
683
684 throw new NoSuchMailingListException(msg.toString());
685 }
686
687 return mbMailingList;
688 }
689
690
697 @Override
698 public MBMailingList fetchByUUID_G(String uuid, long groupId) {
699 return fetchByUUID_G(uuid, groupId, true);
700 }
701
702
710 @Override
711 public MBMailingList fetchByUUID_G(String uuid, long groupId,
712 boolean retrieveFromCache) {
713 Object[] finderArgs = new Object[] { uuid, groupId };
714
715 Object result = null;
716
717 if (retrieveFromCache) {
718 result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
719 finderArgs, this);
720 }
721
722 if (result instanceof MBMailingList) {
723 MBMailingList mbMailingList = (MBMailingList)result;
724
725 if (!Objects.equals(uuid, mbMailingList.getUuid()) ||
726 (groupId != mbMailingList.getGroupId())) {
727 result = null;
728 }
729 }
730
731 if (result == null) {
732 StringBundler query = new StringBundler(4);
733
734 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
735
736 boolean bindUuid = false;
737
738 if (uuid == null) {
739 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
740 }
741 else if (uuid.equals(StringPool.BLANK)) {
742 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
743 }
744 else {
745 bindUuid = true;
746
747 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
748 }
749
750 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
751
752 String sql = query.toString();
753
754 Session session = null;
755
756 try {
757 session = openSession();
758
759 Query q = session.createQuery(sql);
760
761 QueryPos qPos = QueryPos.getInstance(q);
762
763 if (bindUuid) {
764 qPos.add(uuid);
765 }
766
767 qPos.add(groupId);
768
769 List<MBMailingList> list = q.list();
770
771 if (list.isEmpty()) {
772 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
773 finderArgs, list);
774 }
775 else {
776 MBMailingList mbMailingList = list.get(0);
777
778 result = mbMailingList;
779
780 cacheResult(mbMailingList);
781
782 if ((mbMailingList.getUuid() == null) ||
783 !mbMailingList.getUuid().equals(uuid) ||
784 (mbMailingList.getGroupId() != groupId)) {
785 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
786 finderArgs, mbMailingList);
787 }
788 }
789 }
790 catch (Exception e) {
791 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
792
793 throw processException(e);
794 }
795 finally {
796 closeSession(session);
797 }
798 }
799
800 if (result instanceof List<?>) {
801 return null;
802 }
803 else {
804 return (MBMailingList)result;
805 }
806 }
807
808
815 @Override
816 public MBMailingList removeByUUID_G(String uuid, long groupId)
817 throws NoSuchMailingListException {
818 MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
819
820 return remove(mbMailingList);
821 }
822
823
830 @Override
831 public int countByUUID_G(String uuid, long groupId) {
832 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
833
834 Object[] finderArgs = new Object[] { uuid, groupId };
835
836 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
837
838 if (count == null) {
839 StringBundler query = new StringBundler(3);
840
841 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
842
843 boolean bindUuid = false;
844
845 if (uuid == null) {
846 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
847 }
848 else if (uuid.equals(StringPool.BLANK)) {
849 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
850 }
851 else {
852 bindUuid = true;
853
854 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
855 }
856
857 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
858
859 String sql = query.toString();
860
861 Session session = null;
862
863 try {
864 session = openSession();
865
866 Query q = session.createQuery(sql);
867
868 QueryPos qPos = QueryPos.getInstance(q);
869
870 if (bindUuid) {
871 qPos.add(uuid);
872 }
873
874 qPos.add(groupId);
875
876 count = (Long)q.uniqueResult();
877
878 finderCache.putResult(finderPath, finderArgs, count);
879 }
880 catch (Exception e) {
881 finderCache.removeResult(finderPath, finderArgs);
882
883 throw processException(e);
884 }
885 finally {
886 closeSession(session);
887 }
888 }
889
890 return count.intValue();
891 }
892
893 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
894 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
895 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = '') AND ";
896 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
897 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
898 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
899 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
900 "findByUuid_C",
901 new String[] {
902 String.class.getName(), Long.class.getName(),
903
904 Integer.class.getName(), Integer.class.getName(),
905 OrderByComparator.class.getName()
906 });
907 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
908 new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
909 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
910 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
911 "findByUuid_C",
912 new String[] { String.class.getName(), Long.class.getName() },
913 MBMailingListModelImpl.UUID_COLUMN_BITMASK |
914 MBMailingListModelImpl.COMPANYID_COLUMN_BITMASK);
915 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
916 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
917 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
918 new String[] { String.class.getName(), Long.class.getName() });
919
920
927 @Override
928 public List<MBMailingList> findByUuid_C(String uuid, long companyId) {
929 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
930 QueryUtil.ALL_POS, null);
931 }
932
933
946 @Override
947 public List<MBMailingList> findByUuid_C(String uuid, long companyId,
948 int start, int end) {
949 return findByUuid_C(uuid, companyId, start, end, null);
950 }
951
952
966 @Override
967 public List<MBMailingList> findByUuid_C(String uuid, long companyId,
968 int start, int end, OrderByComparator<MBMailingList> orderByComparator) {
969 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
970 }
971
972
987 @Override
988 public List<MBMailingList> findByUuid_C(String uuid, long companyId,
989 int start, int end, OrderByComparator<MBMailingList> orderByComparator,
990 boolean retrieveFromCache) {
991 boolean pagination = true;
992 FinderPath finderPath = null;
993 Object[] finderArgs = null;
994
995 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
996 (orderByComparator == null)) {
997 pagination = false;
998 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
999 finderArgs = new Object[] { uuid, companyId };
1000 }
1001 else {
1002 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1003 finderArgs = new Object[] {
1004 uuid, companyId,
1005
1006 start, end, orderByComparator
1007 };
1008 }
1009
1010 List<MBMailingList> list = null;
1011
1012 if (retrieveFromCache) {
1013 list = (List<MBMailingList>)finderCache.getResult(finderPath,
1014 finderArgs, this);
1015
1016 if ((list != null) && !list.isEmpty()) {
1017 for (MBMailingList mbMailingList : list) {
1018 if (!Objects.equals(uuid, mbMailingList.getUuid()) ||
1019 (companyId != mbMailingList.getCompanyId())) {
1020 list = null;
1021
1022 break;
1023 }
1024 }
1025 }
1026 }
1027
1028 if (list == null) {
1029 StringBundler query = null;
1030
1031 if (orderByComparator != null) {
1032 query = new StringBundler(4 +
1033 (orderByComparator.getOrderByFields().length * 2));
1034 }
1035 else {
1036 query = new StringBundler(4);
1037 }
1038
1039 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1040
1041 boolean bindUuid = false;
1042
1043 if (uuid == null) {
1044 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1045 }
1046 else if (uuid.equals(StringPool.BLANK)) {
1047 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1048 }
1049 else {
1050 bindUuid = true;
1051
1052 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1053 }
1054
1055 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1056
1057 if (orderByComparator != null) {
1058 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1059 orderByComparator);
1060 }
1061 else
1062 if (pagination) {
1063 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1064 }
1065
1066 String sql = query.toString();
1067
1068 Session session = null;
1069
1070 try {
1071 session = openSession();
1072
1073 Query q = session.createQuery(sql);
1074
1075 QueryPos qPos = QueryPos.getInstance(q);
1076
1077 if (bindUuid) {
1078 qPos.add(uuid);
1079 }
1080
1081 qPos.add(companyId);
1082
1083 if (!pagination) {
1084 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1085 start, end, false);
1086
1087 Collections.sort(list);
1088
1089 list = Collections.unmodifiableList(list);
1090 }
1091 else {
1092 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1093 start, end);
1094 }
1095
1096 cacheResult(list);
1097
1098 finderCache.putResult(finderPath, finderArgs, list);
1099 }
1100 catch (Exception e) {
1101 finderCache.removeResult(finderPath, finderArgs);
1102
1103 throw processException(e);
1104 }
1105 finally {
1106 closeSession(session);
1107 }
1108 }
1109
1110 return list;
1111 }
1112
1113
1122 @Override
1123 public MBMailingList findByUuid_C_First(String uuid, long companyId,
1124 OrderByComparator<MBMailingList> orderByComparator)
1125 throws NoSuchMailingListException {
1126 MBMailingList mbMailingList = fetchByUuid_C_First(uuid, companyId,
1127 orderByComparator);
1128
1129 if (mbMailingList != null) {
1130 return mbMailingList;
1131 }
1132
1133 StringBundler msg = new StringBundler(6);
1134
1135 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1136
1137 msg.append("uuid=");
1138 msg.append(uuid);
1139
1140 msg.append(", companyId=");
1141 msg.append(companyId);
1142
1143 msg.append(StringPool.CLOSE_CURLY_BRACE);
1144
1145 throw new NoSuchMailingListException(msg.toString());
1146 }
1147
1148
1156 @Override
1157 public MBMailingList fetchByUuid_C_First(String uuid, long companyId,
1158 OrderByComparator<MBMailingList> orderByComparator) {
1159 List<MBMailingList> list = findByUuid_C(uuid, companyId, 0, 1,
1160 orderByComparator);
1161
1162 if (!list.isEmpty()) {
1163 return list.get(0);
1164 }
1165
1166 return null;
1167 }
1168
1169
1178 @Override
1179 public MBMailingList findByUuid_C_Last(String uuid, long companyId,
1180 OrderByComparator<MBMailingList> orderByComparator)
1181 throws NoSuchMailingListException {
1182 MBMailingList mbMailingList = fetchByUuid_C_Last(uuid, companyId,
1183 orderByComparator);
1184
1185 if (mbMailingList != null) {
1186 return mbMailingList;
1187 }
1188
1189 StringBundler msg = new StringBundler(6);
1190
1191 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1192
1193 msg.append("uuid=");
1194 msg.append(uuid);
1195
1196 msg.append(", companyId=");
1197 msg.append(companyId);
1198
1199 msg.append(StringPool.CLOSE_CURLY_BRACE);
1200
1201 throw new NoSuchMailingListException(msg.toString());
1202 }
1203
1204
1212 @Override
1213 public MBMailingList fetchByUuid_C_Last(String uuid, long companyId,
1214 OrderByComparator<MBMailingList> orderByComparator) {
1215 int count = countByUuid_C(uuid, companyId);
1216
1217 if (count == 0) {
1218 return null;
1219 }
1220
1221 List<MBMailingList> list = findByUuid_C(uuid, companyId, count - 1,
1222 count, orderByComparator);
1223
1224 if (!list.isEmpty()) {
1225 return list.get(0);
1226 }
1227
1228 return null;
1229 }
1230
1231
1241 @Override
1242 public MBMailingList[] findByUuid_C_PrevAndNext(long mailingListId,
1243 String uuid, long companyId,
1244 OrderByComparator<MBMailingList> orderByComparator)
1245 throws NoSuchMailingListException {
1246 MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1247
1248 Session session = null;
1249
1250 try {
1251 session = openSession();
1252
1253 MBMailingList[] array = new MBMailingListImpl[3];
1254
1255 array[0] = getByUuid_C_PrevAndNext(session, mbMailingList, uuid,
1256 companyId, orderByComparator, true);
1257
1258 array[1] = mbMailingList;
1259
1260 array[2] = getByUuid_C_PrevAndNext(session, mbMailingList, uuid,
1261 companyId, orderByComparator, false);
1262
1263 return array;
1264 }
1265 catch (Exception e) {
1266 throw processException(e);
1267 }
1268 finally {
1269 closeSession(session);
1270 }
1271 }
1272
1273 protected MBMailingList getByUuid_C_PrevAndNext(Session session,
1274 MBMailingList mbMailingList, String uuid, long companyId,
1275 OrderByComparator<MBMailingList> orderByComparator, boolean previous) {
1276 StringBundler query = null;
1277
1278 if (orderByComparator != null) {
1279 query = new StringBundler(5 +
1280 (orderByComparator.getOrderByConditionFields().length * 3) +
1281 (orderByComparator.getOrderByFields().length * 3));
1282 }
1283 else {
1284 query = new StringBundler(4);
1285 }
1286
1287 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1288
1289 boolean bindUuid = false;
1290
1291 if (uuid == null) {
1292 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1293 }
1294 else if (uuid.equals(StringPool.BLANK)) {
1295 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1296 }
1297 else {
1298 bindUuid = true;
1299
1300 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1301 }
1302
1303 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1304
1305 if (orderByComparator != null) {
1306 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1307
1308 if (orderByConditionFields.length > 0) {
1309 query.append(WHERE_AND);
1310 }
1311
1312 for (int i = 0; i < orderByConditionFields.length; i++) {
1313 query.append(_ORDER_BY_ENTITY_ALIAS);
1314 query.append(orderByConditionFields[i]);
1315
1316 if ((i + 1) < orderByConditionFields.length) {
1317 if (orderByComparator.isAscending() ^ previous) {
1318 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1319 }
1320 else {
1321 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1322 }
1323 }
1324 else {
1325 if (orderByComparator.isAscending() ^ previous) {
1326 query.append(WHERE_GREATER_THAN);
1327 }
1328 else {
1329 query.append(WHERE_LESSER_THAN);
1330 }
1331 }
1332 }
1333
1334 query.append(ORDER_BY_CLAUSE);
1335
1336 String[] orderByFields = orderByComparator.getOrderByFields();
1337
1338 for (int i = 0; i < orderByFields.length; i++) {
1339 query.append(_ORDER_BY_ENTITY_ALIAS);
1340 query.append(orderByFields[i]);
1341
1342 if ((i + 1) < orderByFields.length) {
1343 if (orderByComparator.isAscending() ^ previous) {
1344 query.append(ORDER_BY_ASC_HAS_NEXT);
1345 }
1346 else {
1347 query.append(ORDER_BY_DESC_HAS_NEXT);
1348 }
1349 }
1350 else {
1351 if (orderByComparator.isAscending() ^ previous) {
1352 query.append(ORDER_BY_ASC);
1353 }
1354 else {
1355 query.append(ORDER_BY_DESC);
1356 }
1357 }
1358 }
1359 }
1360 else {
1361 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1362 }
1363
1364 String sql = query.toString();
1365
1366 Query q = session.createQuery(sql);
1367
1368 q.setFirstResult(0);
1369 q.setMaxResults(2);
1370
1371 QueryPos qPos = QueryPos.getInstance(q);
1372
1373 if (bindUuid) {
1374 qPos.add(uuid);
1375 }
1376
1377 qPos.add(companyId);
1378
1379 if (orderByComparator != null) {
1380 Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1381
1382 for (Object value : values) {
1383 qPos.add(value);
1384 }
1385 }
1386
1387 List<MBMailingList> list = q.list();
1388
1389 if (list.size() == 2) {
1390 return list.get(1);
1391 }
1392 else {
1393 return null;
1394 }
1395 }
1396
1397
1403 @Override
1404 public void removeByUuid_C(String uuid, long companyId) {
1405 for (MBMailingList mbMailingList : findByUuid_C(uuid, companyId,
1406 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1407 remove(mbMailingList);
1408 }
1409 }
1410
1411
1418 @Override
1419 public int countByUuid_C(String uuid, long companyId) {
1420 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1421
1422 Object[] finderArgs = new Object[] { uuid, companyId };
1423
1424 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1425
1426 if (count == null) {
1427 StringBundler query = new StringBundler(3);
1428
1429 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1430
1431 boolean bindUuid = false;
1432
1433 if (uuid == null) {
1434 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1435 }
1436 else if (uuid.equals(StringPool.BLANK)) {
1437 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1438 }
1439 else {
1440 bindUuid = true;
1441
1442 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1443 }
1444
1445 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1446
1447 String sql = query.toString();
1448
1449 Session session = null;
1450
1451 try {
1452 session = openSession();
1453
1454 Query q = session.createQuery(sql);
1455
1456 QueryPos qPos = QueryPos.getInstance(q);
1457
1458 if (bindUuid) {
1459 qPos.add(uuid);
1460 }
1461
1462 qPos.add(companyId);
1463
1464 count = (Long)q.uniqueResult();
1465
1466 finderCache.putResult(finderPath, finderArgs, count);
1467 }
1468 catch (Exception e) {
1469 finderCache.removeResult(finderPath, finderArgs);
1470
1471 throw processException(e);
1472 }
1473 finally {
1474 closeSession(session);
1475 }
1476 }
1477
1478 return count.intValue();
1479 }
1480
1481 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMailingList.uuid IS NULL AND ";
1482 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMailingList.uuid = ? AND ";
1483 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = '') AND ";
1484 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMailingList.companyId = ?";
1485 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1486 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1487 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1488 "findByActive",
1489 new String[] {
1490 Boolean.class.getName(),
1491
1492 Integer.class.getName(), Integer.class.getName(),
1493 OrderByComparator.class.getName()
1494 });
1495 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
1496 new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1497 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1498 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1499 "findByActive", new String[] { Boolean.class.getName() },
1500 MBMailingListModelImpl.ACTIVE_COLUMN_BITMASK);
1501 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1502 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
1503 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
1504 new String[] { Boolean.class.getName() });
1505
1506
1512 @Override
1513 public List<MBMailingList> findByActive(boolean active) {
1514 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1515 }
1516
1517
1529 @Override
1530 public List<MBMailingList> findByActive(boolean active, int start, int end) {
1531 return findByActive(active, start, end, null);
1532 }
1533
1534
1547 @Override
1548 public List<MBMailingList> findByActive(boolean active, int start, int end,
1549 OrderByComparator<MBMailingList> orderByComparator) {
1550 return findByActive(active, start, end, orderByComparator, true);
1551 }
1552
1553
1567 @Override
1568 public List<MBMailingList> findByActive(boolean active, int start, int end,
1569 OrderByComparator<MBMailingList> orderByComparator,
1570 boolean retrieveFromCache) {
1571 boolean pagination = true;
1572 FinderPath finderPath = null;
1573 Object[] finderArgs = null;
1574
1575 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1576 (orderByComparator == null)) {
1577 pagination = false;
1578 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
1579 finderArgs = new Object[] { active };
1580 }
1581 else {
1582 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
1583 finderArgs = new Object[] { active, start, end, orderByComparator };
1584 }
1585
1586 List<MBMailingList> list = null;
1587
1588 if (retrieveFromCache) {
1589 list = (List<MBMailingList>)finderCache.getResult(finderPath,
1590 finderArgs, this);
1591
1592 if ((list != null) && !list.isEmpty()) {
1593 for (MBMailingList mbMailingList : list) {
1594 if ((active != mbMailingList.getActive())) {
1595 list = null;
1596
1597 break;
1598 }
1599 }
1600 }
1601 }
1602
1603 if (list == null) {
1604 StringBundler query = null;
1605
1606 if (orderByComparator != null) {
1607 query = new StringBundler(3 +
1608 (orderByComparator.getOrderByFields().length * 2));
1609 }
1610 else {
1611 query = new StringBundler(3);
1612 }
1613
1614 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1615
1616 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1617
1618 if (orderByComparator != null) {
1619 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1620 orderByComparator);
1621 }
1622 else
1623 if (pagination) {
1624 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1625 }
1626
1627 String sql = query.toString();
1628
1629 Session session = null;
1630
1631 try {
1632 session = openSession();
1633
1634 Query q = session.createQuery(sql);
1635
1636 QueryPos qPos = QueryPos.getInstance(q);
1637
1638 qPos.add(active);
1639
1640 if (!pagination) {
1641 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1642 start, end, false);
1643
1644 Collections.sort(list);
1645
1646 list = Collections.unmodifiableList(list);
1647 }
1648 else {
1649 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1650 start, end);
1651 }
1652
1653 cacheResult(list);
1654
1655 finderCache.putResult(finderPath, finderArgs, list);
1656 }
1657 catch (Exception e) {
1658 finderCache.removeResult(finderPath, finderArgs);
1659
1660 throw processException(e);
1661 }
1662 finally {
1663 closeSession(session);
1664 }
1665 }
1666
1667 return list;
1668 }
1669
1670
1678 @Override
1679 public MBMailingList findByActive_First(boolean active,
1680 OrderByComparator<MBMailingList> orderByComparator)
1681 throws NoSuchMailingListException {
1682 MBMailingList mbMailingList = fetchByActive_First(active,
1683 orderByComparator);
1684
1685 if (mbMailingList != null) {
1686 return mbMailingList;
1687 }
1688
1689 StringBundler msg = new StringBundler(4);
1690
1691 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1692
1693 msg.append("active=");
1694 msg.append(active);
1695
1696 msg.append(StringPool.CLOSE_CURLY_BRACE);
1697
1698 throw new NoSuchMailingListException(msg.toString());
1699 }
1700
1701
1708 @Override
1709 public MBMailingList fetchByActive_First(boolean active,
1710 OrderByComparator<MBMailingList> orderByComparator) {
1711 List<MBMailingList> list = findByActive(active, 0, 1, orderByComparator);
1712
1713 if (!list.isEmpty()) {
1714 return list.get(0);
1715 }
1716
1717 return null;
1718 }
1719
1720
1728 @Override
1729 public MBMailingList findByActive_Last(boolean active,
1730 OrderByComparator<MBMailingList> orderByComparator)
1731 throws NoSuchMailingListException {
1732 MBMailingList mbMailingList = fetchByActive_Last(active,
1733 orderByComparator);
1734
1735 if (mbMailingList != null) {
1736 return mbMailingList;
1737 }
1738
1739 StringBundler msg = new StringBundler(4);
1740
1741 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1742
1743 msg.append("active=");
1744 msg.append(active);
1745
1746 msg.append(StringPool.CLOSE_CURLY_BRACE);
1747
1748 throw new NoSuchMailingListException(msg.toString());
1749 }
1750
1751
1758 @Override
1759 public MBMailingList fetchByActive_Last(boolean active,
1760 OrderByComparator<MBMailingList> orderByComparator) {
1761 int count = countByActive(active);
1762
1763 if (count == 0) {
1764 return null;
1765 }
1766
1767 List<MBMailingList> list = findByActive(active, count - 1, count,
1768 orderByComparator);
1769
1770 if (!list.isEmpty()) {
1771 return list.get(0);
1772 }
1773
1774 return null;
1775 }
1776
1777
1786 @Override
1787 public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1788 boolean active, OrderByComparator<MBMailingList> orderByComparator)
1789 throws NoSuchMailingListException {
1790 MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1791
1792 Session session = null;
1793
1794 try {
1795 session = openSession();
1796
1797 MBMailingList[] array = new MBMailingListImpl[3];
1798
1799 array[0] = getByActive_PrevAndNext(session, mbMailingList, active,
1800 orderByComparator, true);
1801
1802 array[1] = mbMailingList;
1803
1804 array[2] = getByActive_PrevAndNext(session, mbMailingList, active,
1805 orderByComparator, false);
1806
1807 return array;
1808 }
1809 catch (Exception e) {
1810 throw processException(e);
1811 }
1812 finally {
1813 closeSession(session);
1814 }
1815 }
1816
1817 protected MBMailingList getByActive_PrevAndNext(Session session,
1818 MBMailingList mbMailingList, boolean active,
1819 OrderByComparator<MBMailingList> orderByComparator, boolean previous) {
1820 StringBundler query = null;
1821
1822 if (orderByComparator != null) {
1823 query = new StringBundler(4 +
1824 (orderByComparator.getOrderByConditionFields().length * 3) +
1825 (orderByComparator.getOrderByFields().length * 3));
1826 }
1827 else {
1828 query = new StringBundler(3);
1829 }
1830
1831 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1832
1833 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1834
1835 if (orderByComparator != null) {
1836 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1837
1838 if (orderByConditionFields.length > 0) {
1839 query.append(WHERE_AND);
1840 }
1841
1842 for (int i = 0; i < orderByConditionFields.length; i++) {
1843 query.append(_ORDER_BY_ENTITY_ALIAS);
1844 query.append(orderByConditionFields[i]);
1845
1846 if ((i + 1) < orderByConditionFields.length) {
1847 if (orderByComparator.isAscending() ^ previous) {
1848 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1849 }
1850 else {
1851 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1852 }
1853 }
1854 else {
1855 if (orderByComparator.isAscending() ^ previous) {
1856 query.append(WHERE_GREATER_THAN);
1857 }
1858 else {
1859 query.append(WHERE_LESSER_THAN);
1860 }
1861 }
1862 }
1863
1864 query.append(ORDER_BY_CLAUSE);
1865
1866 String[] orderByFields = orderByComparator.getOrderByFields();
1867
1868 for (int i = 0; i < orderByFields.length; i++) {
1869 query.append(_ORDER_BY_ENTITY_ALIAS);
1870 query.append(orderByFields[i]);
1871
1872 if ((i + 1) < orderByFields.length) {
1873 if (orderByComparator.isAscending() ^ previous) {
1874 query.append(ORDER_BY_ASC_HAS_NEXT);
1875 }
1876 else {
1877 query.append(ORDER_BY_DESC_HAS_NEXT);
1878 }
1879 }
1880 else {
1881 if (orderByComparator.isAscending() ^ previous) {
1882 query.append(ORDER_BY_ASC);
1883 }
1884 else {
1885 query.append(ORDER_BY_DESC);
1886 }
1887 }
1888 }
1889 }
1890 else {
1891 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1892 }
1893
1894 String sql = query.toString();
1895
1896 Query q = session.createQuery(sql);
1897
1898 q.setFirstResult(0);
1899 q.setMaxResults(2);
1900
1901 QueryPos qPos = QueryPos.getInstance(q);
1902
1903 qPos.add(active);
1904
1905 if (orderByComparator != null) {
1906 Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1907
1908 for (Object value : values) {
1909 qPos.add(value);
1910 }
1911 }
1912
1913 List<MBMailingList> list = q.list();
1914
1915 if (list.size() == 2) {
1916 return list.get(1);
1917 }
1918 else {
1919 return null;
1920 }
1921 }
1922
1923
1928 @Override
1929 public void removeByActive(boolean active) {
1930 for (MBMailingList mbMailingList : findByActive(active,
1931 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1932 remove(mbMailingList);
1933 }
1934 }
1935
1936
1942 @Override
1943 public int countByActive(boolean active) {
1944 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1945
1946 Object[] finderArgs = new Object[] { active };
1947
1948 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1949
1950 if (count == null) {
1951 StringBundler query = new StringBundler(2);
1952
1953 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1954
1955 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1956
1957 String sql = query.toString();
1958
1959 Session session = null;
1960
1961 try {
1962 session = openSession();
1963
1964 Query q = session.createQuery(sql);
1965
1966 QueryPos qPos = QueryPos.getInstance(q);
1967
1968 qPos.add(active);
1969
1970 count = (Long)q.uniqueResult();
1971
1972 finderCache.putResult(finderPath, finderArgs, count);
1973 }
1974 catch (Exception e) {
1975 finderCache.removeResult(finderPath, finderArgs);
1976
1977 throw processException(e);
1978 }
1979 finally {
1980 closeSession(session);
1981 }
1982 }
1983
1984 return count.intValue();
1985 }
1986
1987 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
1988 public static final FinderPath FINDER_PATH_FETCH_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1989 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1990 MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_C",
1991 new String[] { Long.class.getName(), Long.class.getName() },
1992 MBMailingListModelImpl.GROUPID_COLUMN_BITMASK |
1993 MBMailingListModelImpl.CATEGORYID_COLUMN_BITMASK);
1994 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1995 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
1996 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
1997 new String[] { Long.class.getName(), Long.class.getName() });
1998
1999
2007 @Override
2008 public MBMailingList findByG_C(long groupId, long categoryId)
2009 throws NoSuchMailingListException {
2010 MBMailingList mbMailingList = fetchByG_C(groupId, categoryId);
2011
2012 if (mbMailingList == null) {
2013 StringBundler msg = new StringBundler(6);
2014
2015 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2016
2017 msg.append("groupId=");
2018 msg.append(groupId);
2019
2020 msg.append(", categoryId=");
2021 msg.append(categoryId);
2022
2023 msg.append(StringPool.CLOSE_CURLY_BRACE);
2024
2025 if (_log.isDebugEnabled()) {
2026 _log.debug(msg.toString());
2027 }
2028
2029 throw new NoSuchMailingListException(msg.toString());
2030 }
2031
2032 return mbMailingList;
2033 }
2034
2035
2042 @Override
2043 public MBMailingList fetchByG_C(long groupId, long categoryId) {
2044 return fetchByG_C(groupId, categoryId, true);
2045 }
2046
2047
2055 @Override
2056 public MBMailingList fetchByG_C(long groupId, long categoryId,
2057 boolean retrieveFromCache) {
2058 Object[] finderArgs = new Object[] { groupId, categoryId };
2059
2060 Object result = null;
2061
2062 if (retrieveFromCache) {
2063 result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_C,
2064 finderArgs, this);
2065 }
2066
2067 if (result instanceof MBMailingList) {
2068 MBMailingList mbMailingList = (MBMailingList)result;
2069
2070 if ((groupId != mbMailingList.getGroupId()) ||
2071 (categoryId != mbMailingList.getCategoryId())) {
2072 result = null;
2073 }
2074 }
2075
2076 if (result == null) {
2077 StringBundler query = new StringBundler(4);
2078
2079 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
2080
2081 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2082
2083 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2084
2085 String sql = query.toString();
2086
2087 Session session = null;
2088
2089 try {
2090 session = openSession();
2091
2092 Query q = session.createQuery(sql);
2093
2094 QueryPos qPos = QueryPos.getInstance(q);
2095
2096 qPos.add(groupId);
2097
2098 qPos.add(categoryId);
2099
2100 List<MBMailingList> list = q.list();
2101
2102 if (list.isEmpty()) {
2103 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C, finderArgs,
2104 list);
2105 }
2106 else {
2107 MBMailingList mbMailingList = list.get(0);
2108
2109 result = mbMailingList;
2110
2111 cacheResult(mbMailingList);
2112
2113 if ((mbMailingList.getGroupId() != groupId) ||
2114 (mbMailingList.getCategoryId() != categoryId)) {
2115 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C,
2116 finderArgs, mbMailingList);
2117 }
2118 }
2119 }
2120 catch (Exception e) {
2121 finderCache.removeResult(FINDER_PATH_FETCH_BY_G_C, finderArgs);
2122
2123 throw processException(e);
2124 }
2125 finally {
2126 closeSession(session);
2127 }
2128 }
2129
2130 if (result instanceof List<?>) {
2131 return null;
2132 }
2133 else {
2134 return (MBMailingList)result;
2135 }
2136 }
2137
2138
2145 @Override
2146 public MBMailingList removeByG_C(long groupId, long categoryId)
2147 throws NoSuchMailingListException {
2148 MBMailingList mbMailingList = findByG_C(groupId, categoryId);
2149
2150 return remove(mbMailingList);
2151 }
2152
2153
2160 @Override
2161 public int countByG_C(long groupId, long categoryId) {
2162 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
2163
2164 Object[] finderArgs = new Object[] { groupId, categoryId };
2165
2166 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2167
2168 if (count == null) {
2169 StringBundler query = new StringBundler(3);
2170
2171 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
2172
2173 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2174
2175 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2176
2177 String sql = query.toString();
2178
2179 Session session = null;
2180
2181 try {
2182 session = openSession();
2183
2184 Query q = session.createQuery(sql);
2185
2186 QueryPos qPos = QueryPos.getInstance(q);
2187
2188 qPos.add(groupId);
2189
2190 qPos.add(categoryId);
2191
2192 count = (Long)q.uniqueResult();
2193
2194 finderCache.putResult(finderPath, finderArgs, count);
2195 }
2196 catch (Exception e) {
2197 finderCache.removeResult(finderPath, finderArgs);
2198
2199 throw processException(e);
2200 }
2201 finally {
2202 closeSession(session);
2203 }
2204 }
2205
2206 return count.intValue();
2207 }
2208
2209 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMailingList.groupId = ? AND ";
2210 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMailingList.categoryId = ?";
2211
2212 public MBMailingListPersistenceImpl() {
2213 setModelClass(MBMailingList.class);
2214 }
2215
2216
2221 @Override
2222 public void cacheResult(MBMailingList mbMailingList) {
2223 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2224 MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
2225 mbMailingList);
2226
2227 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2228 new Object[] { mbMailingList.getUuid(), mbMailingList.getGroupId() },
2229 mbMailingList);
2230
2231 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C,
2232 new Object[] {
2233 mbMailingList.getGroupId(), mbMailingList.getCategoryId()
2234 }, mbMailingList);
2235
2236 mbMailingList.resetOriginalValues();
2237 }
2238
2239
2244 @Override
2245 public void cacheResult(List<MBMailingList> mbMailingLists) {
2246 for (MBMailingList mbMailingList : mbMailingLists) {
2247 if (entityCache.getResult(
2248 MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2249 MBMailingListImpl.class, mbMailingList.getPrimaryKey()) == null) {
2250 cacheResult(mbMailingList);
2251 }
2252 else {
2253 mbMailingList.resetOriginalValues();
2254 }
2255 }
2256 }
2257
2258
2265 @Override
2266 public void clearCache() {
2267 entityCache.clearCache(MBMailingListImpl.class);
2268
2269 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2270 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2271 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2272 }
2273
2274
2281 @Override
2282 public void clearCache(MBMailingList mbMailingList) {
2283 entityCache.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2284 MBMailingListImpl.class, mbMailingList.getPrimaryKey());
2285
2286 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2287 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2288
2289 clearUniqueFindersCache((MBMailingListModelImpl)mbMailingList);
2290 }
2291
2292 @Override
2293 public void clearCache(List<MBMailingList> mbMailingLists) {
2294 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2295 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2296
2297 for (MBMailingList mbMailingList : mbMailingLists) {
2298 entityCache.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2299 MBMailingListImpl.class, mbMailingList.getPrimaryKey());
2300
2301 clearUniqueFindersCache((MBMailingListModelImpl)mbMailingList);
2302 }
2303 }
2304
2305 protected void cacheUniqueFindersCache(
2306 MBMailingListModelImpl mbMailingListModelImpl, boolean isNew) {
2307 if (isNew) {
2308 Object[] args = new Object[] {
2309 mbMailingListModelImpl.getUuid(),
2310 mbMailingListModelImpl.getGroupId()
2311 };
2312
2313 finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2314 Long.valueOf(1));
2315 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2316 mbMailingListModelImpl);
2317
2318 args = new Object[] {
2319 mbMailingListModelImpl.getGroupId(),
2320 mbMailingListModelImpl.getCategoryId()
2321 };
2322
2323 finderCache.putResult(FINDER_PATH_COUNT_BY_G_C, args,
2324 Long.valueOf(1));
2325 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C, args,
2326 mbMailingListModelImpl);
2327 }
2328 else {
2329 if ((mbMailingListModelImpl.getColumnBitmask() &
2330 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2331 Object[] args = new Object[] {
2332 mbMailingListModelImpl.getUuid(),
2333 mbMailingListModelImpl.getGroupId()
2334 };
2335
2336 finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2337 Long.valueOf(1));
2338 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2339 mbMailingListModelImpl);
2340 }
2341
2342 if ((mbMailingListModelImpl.getColumnBitmask() &
2343 FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
2344 Object[] args = new Object[] {
2345 mbMailingListModelImpl.getGroupId(),
2346 mbMailingListModelImpl.getCategoryId()
2347 };
2348
2349 finderCache.putResult(FINDER_PATH_COUNT_BY_G_C, args,
2350 Long.valueOf(1));
2351 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C, args,
2352 mbMailingListModelImpl);
2353 }
2354 }
2355 }
2356
2357 protected void clearUniqueFindersCache(
2358 MBMailingListModelImpl mbMailingListModelImpl) {
2359 Object[] args = new Object[] {
2360 mbMailingListModelImpl.getUuid(),
2361 mbMailingListModelImpl.getGroupId()
2362 };
2363
2364 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2365 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2366
2367 if ((mbMailingListModelImpl.getColumnBitmask() &
2368 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2369 args = new Object[] {
2370 mbMailingListModelImpl.getOriginalUuid(),
2371 mbMailingListModelImpl.getOriginalGroupId()
2372 };
2373
2374 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2375 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2376 }
2377
2378 args = new Object[] {
2379 mbMailingListModelImpl.getGroupId(),
2380 mbMailingListModelImpl.getCategoryId()
2381 };
2382
2383 finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2384 finderCache.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
2385
2386 if ((mbMailingListModelImpl.getColumnBitmask() &
2387 FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
2388 args = new Object[] {
2389 mbMailingListModelImpl.getOriginalGroupId(),
2390 mbMailingListModelImpl.getOriginalCategoryId()
2391 };
2392
2393 finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2394 finderCache.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
2395 }
2396 }
2397
2398
2404 @Override
2405 public MBMailingList create(long mailingListId) {
2406 MBMailingList mbMailingList = new MBMailingListImpl();
2407
2408 mbMailingList.setNew(true);
2409 mbMailingList.setPrimaryKey(mailingListId);
2410
2411 String uuid = PortalUUIDUtil.generate();
2412
2413 mbMailingList.setUuid(uuid);
2414
2415 mbMailingList.setCompanyId(companyProvider.getCompanyId());
2416
2417 return mbMailingList;
2418 }
2419
2420
2427 @Override
2428 public MBMailingList remove(long mailingListId)
2429 throws NoSuchMailingListException {
2430 return remove((Serializable)mailingListId);
2431 }
2432
2433
2440 @Override
2441 public MBMailingList remove(Serializable primaryKey)
2442 throws NoSuchMailingListException {
2443 Session session = null;
2444
2445 try {
2446 session = openSession();
2447
2448 MBMailingList mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2449 primaryKey);
2450
2451 if (mbMailingList == null) {
2452 if (_log.isDebugEnabled()) {
2453 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2454 }
2455
2456 throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2457 primaryKey);
2458 }
2459
2460 return remove(mbMailingList);
2461 }
2462 catch (NoSuchMailingListException nsee) {
2463 throw nsee;
2464 }
2465 catch (Exception e) {
2466 throw processException(e);
2467 }
2468 finally {
2469 closeSession(session);
2470 }
2471 }
2472
2473 @Override
2474 protected MBMailingList removeImpl(MBMailingList mbMailingList) {
2475 mbMailingList = toUnwrappedModel(mbMailingList);
2476
2477 Session session = null;
2478
2479 try {
2480 session = openSession();
2481
2482 if (!session.contains(mbMailingList)) {
2483 mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2484 mbMailingList.getPrimaryKeyObj());
2485 }
2486
2487 if (mbMailingList != null) {
2488 session.delete(mbMailingList);
2489 }
2490 }
2491 catch (Exception e) {
2492 throw processException(e);
2493 }
2494 finally {
2495 closeSession(session);
2496 }
2497
2498 if (mbMailingList != null) {
2499 clearCache(mbMailingList);
2500 }
2501
2502 return mbMailingList;
2503 }
2504
2505 @Override
2506 public MBMailingList updateImpl(MBMailingList mbMailingList) {
2507 mbMailingList = toUnwrappedModel(mbMailingList);
2508
2509 boolean isNew = mbMailingList.isNew();
2510
2511 MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
2512
2513 if (Validator.isNull(mbMailingList.getUuid())) {
2514 String uuid = PortalUUIDUtil.generate();
2515
2516 mbMailingList.setUuid(uuid);
2517 }
2518
2519 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2520
2521 Date now = new Date();
2522
2523 if (isNew && (mbMailingList.getCreateDate() == null)) {
2524 if (serviceContext == null) {
2525 mbMailingList.setCreateDate(now);
2526 }
2527 else {
2528 mbMailingList.setCreateDate(serviceContext.getCreateDate(now));
2529 }
2530 }
2531
2532 if (!mbMailingListModelImpl.hasSetModifiedDate()) {
2533 if (serviceContext == null) {
2534 mbMailingList.setModifiedDate(now);
2535 }
2536 else {
2537 mbMailingList.setModifiedDate(serviceContext.getModifiedDate(
2538 now));
2539 }
2540 }
2541
2542 Session session = null;
2543
2544 try {
2545 session = openSession();
2546
2547 if (mbMailingList.isNew()) {
2548 session.save(mbMailingList);
2549
2550 mbMailingList.setNew(false);
2551 }
2552 else {
2553 mbMailingList = (MBMailingList)session.merge(mbMailingList);
2554 }
2555 }
2556 catch (Exception e) {
2557 throw processException(e);
2558 }
2559 finally {
2560 closeSession(session);
2561 }
2562
2563 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2564
2565 if (isNew || !MBMailingListModelImpl.COLUMN_BITMASK_ENABLED) {
2566 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2567 }
2568
2569 else {
2570 if ((mbMailingListModelImpl.getColumnBitmask() &
2571 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2572 Object[] args = new Object[] {
2573 mbMailingListModelImpl.getOriginalUuid()
2574 };
2575
2576 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2577 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2578 args);
2579
2580 args = new Object[] { mbMailingListModelImpl.getUuid() };
2581
2582 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2583 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2584 args);
2585 }
2586
2587 if ((mbMailingListModelImpl.getColumnBitmask() &
2588 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2589 Object[] args = new Object[] {
2590 mbMailingListModelImpl.getOriginalUuid(),
2591 mbMailingListModelImpl.getOriginalCompanyId()
2592 };
2593
2594 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2595 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2596 args);
2597
2598 args = new Object[] {
2599 mbMailingListModelImpl.getUuid(),
2600 mbMailingListModelImpl.getCompanyId()
2601 };
2602
2603 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2604 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2605 args);
2606 }
2607
2608 if ((mbMailingListModelImpl.getColumnBitmask() &
2609 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
2610 Object[] args = new Object[] {
2611 mbMailingListModelImpl.getOriginalActive()
2612 };
2613
2614 finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2615 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2616 args);
2617
2618 args = new Object[] { mbMailingListModelImpl.getActive() };
2619
2620 finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2621 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2622 args);
2623 }
2624 }
2625
2626 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2627 MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
2628 mbMailingList, false);
2629
2630 clearUniqueFindersCache(mbMailingListModelImpl);
2631 cacheUniqueFindersCache(mbMailingListModelImpl, isNew);
2632
2633 mbMailingList.resetOriginalValues();
2634
2635 return mbMailingList;
2636 }
2637
2638 protected MBMailingList toUnwrappedModel(MBMailingList mbMailingList) {
2639 if (mbMailingList instanceof MBMailingListImpl) {
2640 return mbMailingList;
2641 }
2642
2643 MBMailingListImpl mbMailingListImpl = new MBMailingListImpl();
2644
2645 mbMailingListImpl.setNew(mbMailingList.isNew());
2646 mbMailingListImpl.setPrimaryKey(mbMailingList.getPrimaryKey());
2647
2648 mbMailingListImpl.setUuid(mbMailingList.getUuid());
2649 mbMailingListImpl.setMailingListId(mbMailingList.getMailingListId());
2650 mbMailingListImpl.setGroupId(mbMailingList.getGroupId());
2651 mbMailingListImpl.setCompanyId(mbMailingList.getCompanyId());
2652 mbMailingListImpl.setUserId(mbMailingList.getUserId());
2653 mbMailingListImpl.setUserName(mbMailingList.getUserName());
2654 mbMailingListImpl.setCreateDate(mbMailingList.getCreateDate());
2655 mbMailingListImpl.setModifiedDate(mbMailingList.getModifiedDate());
2656 mbMailingListImpl.setCategoryId(mbMailingList.getCategoryId());
2657 mbMailingListImpl.setEmailAddress(mbMailingList.getEmailAddress());
2658 mbMailingListImpl.setInProtocol(mbMailingList.getInProtocol());
2659 mbMailingListImpl.setInServerName(mbMailingList.getInServerName());
2660 mbMailingListImpl.setInServerPort(mbMailingList.getInServerPort());
2661 mbMailingListImpl.setInUseSSL(mbMailingList.isInUseSSL());
2662 mbMailingListImpl.setInUserName(mbMailingList.getInUserName());
2663 mbMailingListImpl.setInPassword(mbMailingList.getInPassword());
2664 mbMailingListImpl.setInReadInterval(mbMailingList.getInReadInterval());
2665 mbMailingListImpl.setOutEmailAddress(mbMailingList.getOutEmailAddress());
2666 mbMailingListImpl.setOutCustom(mbMailingList.isOutCustom());
2667 mbMailingListImpl.setOutServerName(mbMailingList.getOutServerName());
2668 mbMailingListImpl.setOutServerPort(mbMailingList.getOutServerPort());
2669 mbMailingListImpl.setOutUseSSL(mbMailingList.isOutUseSSL());
2670 mbMailingListImpl.setOutUserName(mbMailingList.getOutUserName());
2671 mbMailingListImpl.setOutPassword(mbMailingList.getOutPassword());
2672 mbMailingListImpl.setAllowAnonymous(mbMailingList.isAllowAnonymous());
2673 mbMailingListImpl.setActive(mbMailingList.isActive());
2674
2675 return mbMailingListImpl;
2676 }
2677
2678
2685 @Override
2686 public MBMailingList findByPrimaryKey(Serializable primaryKey)
2687 throws NoSuchMailingListException {
2688 MBMailingList mbMailingList = fetchByPrimaryKey(primaryKey);
2689
2690 if (mbMailingList == null) {
2691 if (_log.isDebugEnabled()) {
2692 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2693 }
2694
2695 throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2696 primaryKey);
2697 }
2698
2699 return mbMailingList;
2700 }
2701
2702
2709 @Override
2710 public MBMailingList findByPrimaryKey(long mailingListId)
2711 throws NoSuchMailingListException {
2712 return findByPrimaryKey((Serializable)mailingListId);
2713 }
2714
2715
2721 @Override
2722 public MBMailingList fetchByPrimaryKey(Serializable primaryKey) {
2723 MBMailingList mbMailingList = (MBMailingList)entityCache.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2724 MBMailingListImpl.class, primaryKey);
2725
2726 if (mbMailingList == _nullMBMailingList) {
2727 return null;
2728 }
2729
2730 if (mbMailingList == null) {
2731 Session session = null;
2732
2733 try {
2734 session = openSession();
2735
2736 mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2737 primaryKey);
2738
2739 if (mbMailingList != null) {
2740 cacheResult(mbMailingList);
2741 }
2742 else {
2743 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2744 MBMailingListImpl.class, primaryKey, _nullMBMailingList);
2745 }
2746 }
2747 catch (Exception e) {
2748 entityCache.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2749 MBMailingListImpl.class, primaryKey);
2750
2751 throw processException(e);
2752 }
2753 finally {
2754 closeSession(session);
2755 }
2756 }
2757
2758 return mbMailingList;
2759 }
2760
2761
2767 @Override
2768 public MBMailingList fetchByPrimaryKey(long mailingListId) {
2769 return fetchByPrimaryKey((Serializable)mailingListId);
2770 }
2771
2772 @Override
2773 public Map<Serializable, MBMailingList> fetchByPrimaryKeys(
2774 Set<Serializable> primaryKeys) {
2775 if (primaryKeys.isEmpty()) {
2776 return Collections.emptyMap();
2777 }
2778
2779 Map<Serializable, MBMailingList> map = new HashMap<Serializable, MBMailingList>();
2780
2781 if (primaryKeys.size() == 1) {
2782 Iterator<Serializable> iterator = primaryKeys.iterator();
2783
2784 Serializable primaryKey = iterator.next();
2785
2786 MBMailingList mbMailingList = fetchByPrimaryKey(primaryKey);
2787
2788 if (mbMailingList != null) {
2789 map.put(primaryKey, mbMailingList);
2790 }
2791
2792 return map;
2793 }
2794
2795 Set<Serializable> uncachedPrimaryKeys = null;
2796
2797 for (Serializable primaryKey : primaryKeys) {
2798 MBMailingList mbMailingList = (MBMailingList)entityCache.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2799 MBMailingListImpl.class, primaryKey);
2800
2801 if (mbMailingList == null) {
2802 if (uncachedPrimaryKeys == null) {
2803 uncachedPrimaryKeys = new HashSet<Serializable>();
2804 }
2805
2806 uncachedPrimaryKeys.add(primaryKey);
2807 }
2808 else {
2809 map.put(primaryKey, mbMailingList);
2810 }
2811 }
2812
2813 if (uncachedPrimaryKeys == null) {
2814 return map;
2815 }
2816
2817 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2818 1);
2819
2820 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE_PKS_IN);
2821
2822 for (Serializable primaryKey : uncachedPrimaryKeys) {
2823 query.append(String.valueOf(primaryKey));
2824
2825 query.append(StringPool.COMMA);
2826 }
2827
2828 query.setIndex(query.index() - 1);
2829
2830 query.append(StringPool.CLOSE_PARENTHESIS);
2831
2832 String sql = query.toString();
2833
2834 Session session = null;
2835
2836 try {
2837 session = openSession();
2838
2839 Query q = session.createQuery(sql);
2840
2841 for (MBMailingList mbMailingList : (List<MBMailingList>)q.list()) {
2842 map.put(mbMailingList.getPrimaryKeyObj(), mbMailingList);
2843
2844 cacheResult(mbMailingList);
2845
2846 uncachedPrimaryKeys.remove(mbMailingList.getPrimaryKeyObj());
2847 }
2848
2849 for (Serializable primaryKey : uncachedPrimaryKeys) {
2850 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2851 MBMailingListImpl.class, primaryKey, _nullMBMailingList);
2852 }
2853 }
2854 catch (Exception e) {
2855 throw processException(e);
2856 }
2857 finally {
2858 closeSession(session);
2859 }
2860
2861 return map;
2862 }
2863
2864
2869 @Override
2870 public List<MBMailingList> findAll() {
2871 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2872 }
2873
2874
2885 @Override
2886 public List<MBMailingList> findAll(int start, int end) {
2887 return findAll(start, end, null);
2888 }
2889
2890
2902 @Override
2903 public List<MBMailingList> findAll(int start, int end,
2904 OrderByComparator<MBMailingList> orderByComparator) {
2905 return findAll(start, end, orderByComparator, true);
2906 }
2907
2908
2921 @Override
2922 public List<MBMailingList> findAll(int start, int end,
2923 OrderByComparator<MBMailingList> orderByComparator,
2924 boolean retrieveFromCache) {
2925 boolean pagination = true;
2926 FinderPath finderPath = null;
2927 Object[] finderArgs = null;
2928
2929 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2930 (orderByComparator == null)) {
2931 pagination = false;
2932 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2933 finderArgs = FINDER_ARGS_EMPTY;
2934 }
2935 else {
2936 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2937 finderArgs = new Object[] { start, end, orderByComparator };
2938 }
2939
2940 List<MBMailingList> list = null;
2941
2942 if (retrieveFromCache) {
2943 list = (List<MBMailingList>)finderCache.getResult(finderPath,
2944 finderArgs, this);
2945 }
2946
2947 if (list == null) {
2948 StringBundler query = null;
2949 String sql = null;
2950
2951 if (orderByComparator != null) {
2952 query = new StringBundler(2 +
2953 (orderByComparator.getOrderByFields().length * 2));
2954
2955 query.append(_SQL_SELECT_MBMAILINGLIST);
2956
2957 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2958 orderByComparator);
2959
2960 sql = query.toString();
2961 }
2962 else {
2963 sql = _SQL_SELECT_MBMAILINGLIST;
2964
2965 if (pagination) {
2966 sql = sql.concat(MBMailingListModelImpl.ORDER_BY_JPQL);
2967 }
2968 }
2969
2970 Session session = null;
2971
2972 try {
2973 session = openSession();
2974
2975 Query q = session.createQuery(sql);
2976
2977 if (!pagination) {
2978 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
2979 start, end, false);
2980
2981 Collections.sort(list);
2982
2983 list = Collections.unmodifiableList(list);
2984 }
2985 else {
2986 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
2987 start, end);
2988 }
2989
2990 cacheResult(list);
2991
2992 finderCache.putResult(finderPath, finderArgs, list);
2993 }
2994 catch (Exception e) {
2995 finderCache.removeResult(finderPath, finderArgs);
2996
2997 throw processException(e);
2998 }
2999 finally {
3000 closeSession(session);
3001 }
3002 }
3003
3004 return list;
3005 }
3006
3007
3011 @Override
3012 public void removeAll() {
3013 for (MBMailingList mbMailingList : findAll()) {
3014 remove(mbMailingList);
3015 }
3016 }
3017
3018
3023 @Override
3024 public int countAll() {
3025 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3026 FINDER_ARGS_EMPTY, this);
3027
3028 if (count == null) {
3029 Session session = null;
3030
3031 try {
3032 session = openSession();
3033
3034 Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
3035
3036 count = (Long)q.uniqueResult();
3037
3038 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3039 count);
3040 }
3041 catch (Exception e) {
3042 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3043 FINDER_ARGS_EMPTY);
3044
3045 throw processException(e);
3046 }
3047 finally {
3048 closeSession(session);
3049 }
3050 }
3051
3052 return count.intValue();
3053 }
3054
3055 @Override
3056 public Set<String> getBadColumnNames() {
3057 return _badColumnNames;
3058 }
3059
3060 @Override
3061 protected Map<String, Integer> getTableColumnsMap() {
3062 return MBMailingListModelImpl.TABLE_COLUMNS_MAP;
3063 }
3064
3065
3068 public void afterPropertiesSet() {
3069 }
3070
3071 public void destroy() {
3072 entityCache.removeCache(MBMailingListImpl.class.getName());
3073 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3074 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3075 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3076 }
3077
3078 @BeanReference(type = CompanyProviderWrapper.class)
3079 protected CompanyProvider companyProvider;
3080 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3081 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3082 private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
3083 private static final String _SQL_SELECT_MBMAILINGLIST_WHERE_PKS_IN = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE mailingListId IN (";
3084 private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
3085 private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
3086 private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
3087 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
3088 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
3089 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
3090 private static final Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
3091 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3092 "uuid", "active"
3093 });
3094 private static final MBMailingList _nullMBMailingList = new MBMailingListImpl() {
3095 @Override
3096 public Object clone() {
3097 return this;
3098 }
3099
3100 @Override
3101 public CacheModel<MBMailingList> toCacheModel() {
3102 return _nullMBMailingListCacheModel;
3103 }
3104 };
3105
3106 private static final CacheModel<MBMailingList> _nullMBMailingListCacheModel = new CacheModel<MBMailingList>() {
3107 @Override
3108 public MBMailingList toEntityModel() {
3109 return _nullMBMailingList;
3110 }
3111 };
3112 }