001
014
015 package com.liferay.portlet.messageboards.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCache;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCache;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.Validator;
035 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.service.ServiceContext;
038 import com.liferay.portal.service.ServiceContextThreadLocal;
039 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
040
041 import com.liferay.portlet.messageboards.NoSuchMailingListException;
042 import com.liferay.portlet.messageboards.model.MBMailingList;
043 import com.liferay.portlet.messageboards.model.impl.MBMailingListImpl;
044 import com.liferay.portlet.messageboards.model.impl.MBMailingListModelImpl;
045 import com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence;
046
047 import java.io.Serializable;
048
049 import java.util.Collections;
050 import java.util.Date;
051 import java.util.HashMap;
052 import java.util.HashSet;
053 import java.util.Iterator;
054 import java.util.List;
055 import java.util.Map;
056 import java.util.Set;
057
058
070 @ProviderType
071 public class MBMailingListPersistenceImpl extends BasePersistenceImpl<MBMailingList>
072 implements MBMailingListPersistence {
073
078 public static final String FINDER_CLASS_NAME_ENTITY = MBMailingListImpl.class.getName();
079 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List1";
081 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List2";
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
084 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
085 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
086 "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
088 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
089 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
090 "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
092 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
095 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
096 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
097 "findByUuid",
098 new String[] {
099 String.class.getName(),
100
101 Integer.class.getName(), Integer.class.getName(),
102 OrderByComparator.class.getName()
103 });
104 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
105 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
106 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
107 "findByUuid", new String[] { String.class.getName() },
108 MBMailingListModelImpl.UUID_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
110 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112 new String[] { String.class.getName() });
113
114
120 @Override
121 public List<MBMailingList> findByUuid(String uuid) {
122 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
137 @Override
138 public List<MBMailingList> findByUuid(String uuid, int start, int end) {
139 return findByUuid(uuid, start, end, null);
140 }
141
142
155 @Override
156 public List<MBMailingList> findByUuid(String uuid, int start, int end,
157 OrderByComparator<MBMailingList> orderByComparator) {
158 return findByUuid(uuid, start, end, orderByComparator, true);
159 }
160
161
175 @Override
176 public List<MBMailingList> findByUuid(String uuid, int start, int end,
177 OrderByComparator<MBMailingList> orderByComparator,
178 boolean retrieveFromCache) {
179 boolean pagination = true;
180 FinderPath finderPath = null;
181 Object[] finderArgs = null;
182
183 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
184 (orderByComparator == null)) {
185 pagination = false;
186 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
187 finderArgs = new Object[] { uuid };
188 }
189 else {
190 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
191 finderArgs = new Object[] { uuid, start, end, orderByComparator };
192 }
193
194 List<MBMailingList> list = null;
195
196 if (retrieveFromCache) {
197 list = (List<MBMailingList>)finderCache.getResult(finderPath,
198 finderArgs, this);
199
200 if ((list != null) && !list.isEmpty()) {
201 for (MBMailingList mbMailingList : list) {
202 if (!Validator.equals(uuid, mbMailingList.getUuid())) {
203 list = null;
204
205 break;
206 }
207 }
208 }
209 }
210
211 if (list == null) {
212 StringBundler query = null;
213
214 if (orderByComparator != null) {
215 query = new StringBundler(3 +
216 (orderByComparator.getOrderByFields().length * 3));
217 }
218 else {
219 query = new StringBundler(3);
220 }
221
222 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
223
224 boolean bindUuid = false;
225
226 if (uuid == null) {
227 query.append(_FINDER_COLUMN_UUID_UUID_1);
228 }
229 else if (uuid.equals(StringPool.BLANK)) {
230 query.append(_FINDER_COLUMN_UUID_UUID_3);
231 }
232 else {
233 bindUuid = true;
234
235 query.append(_FINDER_COLUMN_UUID_UUID_2);
236 }
237
238 if (orderByComparator != null) {
239 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
240 orderByComparator);
241 }
242 else
243 if (pagination) {
244 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
245 }
246
247 String sql = query.toString();
248
249 Session session = null;
250
251 try {
252 session = openSession();
253
254 Query q = session.createQuery(sql);
255
256 QueryPos qPos = QueryPos.getInstance(q);
257
258 if (bindUuid) {
259 qPos.add(uuid);
260 }
261
262 if (!pagination) {
263 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
264 start, end, false);
265
266 Collections.sort(list);
267
268 list = Collections.unmodifiableList(list);
269 }
270 else {
271 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
272 start, end);
273 }
274
275 cacheResult(list);
276
277 finderCache.putResult(finderPath, finderArgs, list);
278 }
279 catch (Exception e) {
280 finderCache.removeResult(finderPath, finderArgs);
281
282 throw processException(e);
283 }
284 finally {
285 closeSession(session);
286 }
287 }
288
289 return list;
290 }
291
292
300 @Override
301 public MBMailingList findByUuid_First(String uuid,
302 OrderByComparator<MBMailingList> orderByComparator)
303 throws NoSuchMailingListException {
304 MBMailingList mbMailingList = fetchByUuid_First(uuid, orderByComparator);
305
306 if (mbMailingList != null) {
307 return mbMailingList;
308 }
309
310 StringBundler msg = new StringBundler(4);
311
312 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
313
314 msg.append("uuid=");
315 msg.append(uuid);
316
317 msg.append(StringPool.CLOSE_CURLY_BRACE);
318
319 throw new NoSuchMailingListException(msg.toString());
320 }
321
322
329 @Override
330 public MBMailingList fetchByUuid_First(String uuid,
331 OrderByComparator<MBMailingList> orderByComparator) {
332 List<MBMailingList> list = findByUuid(uuid, 0, 1, orderByComparator);
333
334 if (!list.isEmpty()) {
335 return list.get(0);
336 }
337
338 return null;
339 }
340
341
349 @Override
350 public MBMailingList findByUuid_Last(String uuid,
351 OrderByComparator<MBMailingList> orderByComparator)
352 throws NoSuchMailingListException {
353 MBMailingList mbMailingList = fetchByUuid_Last(uuid, orderByComparator);
354
355 if (mbMailingList != null) {
356 return mbMailingList;
357 }
358
359 StringBundler msg = new StringBundler(4);
360
361 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
362
363 msg.append("uuid=");
364 msg.append(uuid);
365
366 msg.append(StringPool.CLOSE_CURLY_BRACE);
367
368 throw new NoSuchMailingListException(msg.toString());
369 }
370
371
378 @Override
379 public MBMailingList fetchByUuid_Last(String uuid,
380 OrderByComparator<MBMailingList> orderByComparator) {
381 int count = countByUuid(uuid);
382
383 if (count == 0) {
384 return null;
385 }
386
387 List<MBMailingList> list = findByUuid(uuid, count - 1, count,
388 orderByComparator);
389
390 if (!list.isEmpty()) {
391 return list.get(0);
392 }
393
394 return null;
395 }
396
397
406 @Override
407 public MBMailingList[] findByUuid_PrevAndNext(long mailingListId,
408 String uuid, OrderByComparator<MBMailingList> orderByComparator)
409 throws NoSuchMailingListException {
410 MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
411
412 Session session = null;
413
414 try {
415 session = openSession();
416
417 MBMailingList[] array = new MBMailingListImpl[3];
418
419 array[0] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
420 orderByComparator, true);
421
422 array[1] = mbMailingList;
423
424 array[2] = getByUuid_PrevAndNext(session, mbMailingList, uuid,
425 orderByComparator, false);
426
427 return array;
428 }
429 catch (Exception e) {
430 throw processException(e);
431 }
432 finally {
433 closeSession(session);
434 }
435 }
436
437 protected MBMailingList getByUuid_PrevAndNext(Session session,
438 MBMailingList mbMailingList, String uuid,
439 OrderByComparator<MBMailingList> orderByComparator, boolean previous) {
440 StringBundler query = null;
441
442 if (orderByComparator != null) {
443 query = new StringBundler(6 +
444 (orderByComparator.getOrderByFields().length * 6));
445 }
446 else {
447 query = new StringBundler(3);
448 }
449
450 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
451
452 boolean bindUuid = false;
453
454 if (uuid == null) {
455 query.append(_FINDER_COLUMN_UUID_UUID_1);
456 }
457 else if (uuid.equals(StringPool.BLANK)) {
458 query.append(_FINDER_COLUMN_UUID_UUID_3);
459 }
460 else {
461 bindUuid = true;
462
463 query.append(_FINDER_COLUMN_UUID_UUID_2);
464 }
465
466 if (orderByComparator != null) {
467 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
468
469 if (orderByConditionFields.length > 0) {
470 query.append(WHERE_AND);
471 }
472
473 for (int i = 0; i < orderByConditionFields.length; i++) {
474 query.append(_ORDER_BY_ENTITY_ALIAS);
475 query.append(orderByConditionFields[i]);
476
477 if ((i + 1) < orderByConditionFields.length) {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(WHERE_GREATER_THAN_HAS_NEXT);
480 }
481 else {
482 query.append(WHERE_LESSER_THAN_HAS_NEXT);
483 }
484 }
485 else {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(WHERE_GREATER_THAN);
488 }
489 else {
490 query.append(WHERE_LESSER_THAN);
491 }
492 }
493 }
494
495 query.append(ORDER_BY_CLAUSE);
496
497 String[] orderByFields = orderByComparator.getOrderByFields();
498
499 for (int i = 0; i < orderByFields.length; i++) {
500 query.append(_ORDER_BY_ENTITY_ALIAS);
501 query.append(orderByFields[i]);
502
503 if ((i + 1) < orderByFields.length) {
504 if (orderByComparator.isAscending() ^ previous) {
505 query.append(ORDER_BY_ASC_HAS_NEXT);
506 }
507 else {
508 query.append(ORDER_BY_DESC_HAS_NEXT);
509 }
510 }
511 else {
512 if (orderByComparator.isAscending() ^ previous) {
513 query.append(ORDER_BY_ASC);
514 }
515 else {
516 query.append(ORDER_BY_DESC);
517 }
518 }
519 }
520 }
521 else {
522 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
523 }
524
525 String sql = query.toString();
526
527 Query q = session.createQuery(sql);
528
529 q.setFirstResult(0);
530 q.setMaxResults(2);
531
532 QueryPos qPos = QueryPos.getInstance(q);
533
534 if (bindUuid) {
535 qPos.add(uuid);
536 }
537
538 if (orderByComparator != null) {
539 Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
540
541 for (Object value : values) {
542 qPos.add(value);
543 }
544 }
545
546 List<MBMailingList> list = q.list();
547
548 if (list.size() == 2) {
549 return list.get(1);
550 }
551 else {
552 return null;
553 }
554 }
555
556
561 @Override
562 public void removeByUuid(String uuid) {
563 for (MBMailingList mbMailingList : findByUuid(uuid, QueryUtil.ALL_POS,
564 QueryUtil.ALL_POS, null)) {
565 remove(mbMailingList);
566 }
567 }
568
569
575 @Override
576 public int countByUuid(String uuid) {
577 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
578
579 Object[] finderArgs = new Object[] { uuid };
580
581 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
582
583 if (count == null) {
584 StringBundler query = new StringBundler(2);
585
586 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
587
588 boolean bindUuid = false;
589
590 if (uuid == null) {
591 query.append(_FINDER_COLUMN_UUID_UUID_1);
592 }
593 else if (uuid.equals(StringPool.BLANK)) {
594 query.append(_FINDER_COLUMN_UUID_UUID_3);
595 }
596 else {
597 bindUuid = true;
598
599 query.append(_FINDER_COLUMN_UUID_UUID_2);
600 }
601
602 String sql = query.toString();
603
604 Session session = null;
605
606 try {
607 session = openSession();
608
609 Query q = session.createQuery(sql);
610
611 QueryPos qPos = QueryPos.getInstance(q);
612
613 if (bindUuid) {
614 qPos.add(uuid);
615 }
616
617 count = (Long)q.uniqueResult();
618
619 finderCache.putResult(finderPath, finderArgs, count);
620 }
621 catch (Exception e) {
622 finderCache.removeResult(finderPath, finderArgs);
623
624 throw processException(e);
625 }
626 finally {
627 closeSession(session);
628 }
629 }
630
631 return count.intValue();
632 }
633
634 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMailingList.uuid IS NULL";
635 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMailingList.uuid = ?";
636 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = '')";
637 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
638 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
639 MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
640 new String[] { String.class.getName(), Long.class.getName() },
641 MBMailingListModelImpl.UUID_COLUMN_BITMASK |
642 MBMailingListModelImpl.GROUPID_COLUMN_BITMASK);
643 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
644 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
645 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
646 new String[] { String.class.getName(), Long.class.getName() });
647
648
656 @Override
657 public MBMailingList findByUUID_G(String uuid, long groupId)
658 throws NoSuchMailingListException {
659 MBMailingList mbMailingList = fetchByUUID_G(uuid, groupId);
660
661 if (mbMailingList == null) {
662 StringBundler msg = new StringBundler(6);
663
664 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
665
666 msg.append("uuid=");
667 msg.append(uuid);
668
669 msg.append(", groupId=");
670 msg.append(groupId);
671
672 msg.append(StringPool.CLOSE_CURLY_BRACE);
673
674 if (_log.isWarnEnabled()) {
675 _log.warn(msg.toString());
676 }
677
678 throw new NoSuchMailingListException(msg.toString());
679 }
680
681 return mbMailingList;
682 }
683
684
691 @Override
692 public MBMailingList fetchByUUID_G(String uuid, long groupId) {
693 return fetchByUUID_G(uuid, groupId, true);
694 }
695
696
704 @Override
705 public MBMailingList fetchByUUID_G(String uuid, long groupId,
706 boolean retrieveFromCache) {
707 Object[] finderArgs = new Object[] { uuid, groupId };
708
709 Object result = null;
710
711 if (retrieveFromCache) {
712 result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
713 finderArgs, this);
714 }
715
716 if (result instanceof MBMailingList) {
717 MBMailingList mbMailingList = (MBMailingList)result;
718
719 if (!Validator.equals(uuid, mbMailingList.getUuid()) ||
720 (groupId != mbMailingList.getGroupId())) {
721 result = null;
722 }
723 }
724
725 if (result == null) {
726 StringBundler query = new StringBundler(4);
727
728 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
729
730 boolean bindUuid = false;
731
732 if (uuid == null) {
733 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
734 }
735 else if (uuid.equals(StringPool.BLANK)) {
736 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
737 }
738 else {
739 bindUuid = true;
740
741 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
742 }
743
744 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
745
746 String sql = query.toString();
747
748 Session session = null;
749
750 try {
751 session = openSession();
752
753 Query q = session.createQuery(sql);
754
755 QueryPos qPos = QueryPos.getInstance(q);
756
757 if (bindUuid) {
758 qPos.add(uuid);
759 }
760
761 qPos.add(groupId);
762
763 List<MBMailingList> list = q.list();
764
765 if (list.isEmpty()) {
766 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
767 finderArgs, list);
768 }
769 else {
770 MBMailingList mbMailingList = list.get(0);
771
772 result = mbMailingList;
773
774 cacheResult(mbMailingList);
775
776 if ((mbMailingList.getUuid() == null) ||
777 !mbMailingList.getUuid().equals(uuid) ||
778 (mbMailingList.getGroupId() != groupId)) {
779 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
780 finderArgs, mbMailingList);
781 }
782 }
783 }
784 catch (Exception e) {
785 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
786
787 throw processException(e);
788 }
789 finally {
790 closeSession(session);
791 }
792 }
793
794 if (result instanceof List<?>) {
795 return null;
796 }
797 else {
798 return (MBMailingList)result;
799 }
800 }
801
802
809 @Override
810 public MBMailingList removeByUUID_G(String uuid, long groupId)
811 throws NoSuchMailingListException {
812 MBMailingList mbMailingList = findByUUID_G(uuid, groupId);
813
814 return remove(mbMailingList);
815 }
816
817
824 @Override
825 public int countByUUID_G(String uuid, long groupId) {
826 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
827
828 Object[] finderArgs = new Object[] { uuid, groupId };
829
830 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
831
832 if (count == null) {
833 StringBundler query = new StringBundler(3);
834
835 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
836
837 boolean bindUuid = false;
838
839 if (uuid == null) {
840 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
841 }
842 else if (uuid.equals(StringPool.BLANK)) {
843 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
844 }
845 else {
846 bindUuid = true;
847
848 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
849 }
850
851 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
852
853 String sql = query.toString();
854
855 Session session = null;
856
857 try {
858 session = openSession();
859
860 Query q = session.createQuery(sql);
861
862 QueryPos qPos = QueryPos.getInstance(q);
863
864 if (bindUuid) {
865 qPos.add(uuid);
866 }
867
868 qPos.add(groupId);
869
870 count = (Long)q.uniqueResult();
871
872 finderCache.putResult(finderPath, finderArgs, count);
873 }
874 catch (Exception e) {
875 finderCache.removeResult(finderPath, finderArgs);
876
877 throw processException(e);
878 }
879 finally {
880 closeSession(session);
881 }
882 }
883
884 return count.intValue();
885 }
886
887 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMailingList.uuid IS NULL AND ";
888 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMailingList.uuid = ? AND ";
889 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = '') AND ";
890 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMailingList.groupId = ?";
891 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
892 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
893 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
894 "findByUuid_C",
895 new String[] {
896 String.class.getName(), Long.class.getName(),
897
898 Integer.class.getName(), Integer.class.getName(),
899 OrderByComparator.class.getName()
900 });
901 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
902 new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
903 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
904 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
905 "findByUuid_C",
906 new String[] { String.class.getName(), Long.class.getName() },
907 MBMailingListModelImpl.UUID_COLUMN_BITMASK |
908 MBMailingListModelImpl.COMPANYID_COLUMN_BITMASK);
909 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
910 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
911 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
912 new String[] { String.class.getName(), Long.class.getName() });
913
914
921 @Override
922 public List<MBMailingList> findByUuid_C(String uuid, long companyId) {
923 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
924 QueryUtil.ALL_POS, null);
925 }
926
927
940 @Override
941 public List<MBMailingList> findByUuid_C(String uuid, long companyId,
942 int start, int end) {
943 return findByUuid_C(uuid, companyId, start, end, null);
944 }
945
946
960 @Override
961 public List<MBMailingList> findByUuid_C(String uuid, long companyId,
962 int start, int end, OrderByComparator<MBMailingList> orderByComparator) {
963 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
964 }
965
966
981 @Override
982 public List<MBMailingList> findByUuid_C(String uuid, long companyId,
983 int start, int end, OrderByComparator<MBMailingList> orderByComparator,
984 boolean retrieveFromCache) {
985 boolean pagination = true;
986 FinderPath finderPath = null;
987 Object[] finderArgs = null;
988
989 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
990 (orderByComparator == null)) {
991 pagination = false;
992 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
993 finderArgs = new Object[] { uuid, companyId };
994 }
995 else {
996 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
997 finderArgs = new Object[] {
998 uuid, companyId,
999
1000 start, end, orderByComparator
1001 };
1002 }
1003
1004 List<MBMailingList> list = null;
1005
1006 if (retrieveFromCache) {
1007 list = (List<MBMailingList>)finderCache.getResult(finderPath,
1008 finderArgs, this);
1009
1010 if ((list != null) && !list.isEmpty()) {
1011 for (MBMailingList mbMailingList : list) {
1012 if (!Validator.equals(uuid, mbMailingList.getUuid()) ||
1013 (companyId != mbMailingList.getCompanyId())) {
1014 list = null;
1015
1016 break;
1017 }
1018 }
1019 }
1020 }
1021
1022 if (list == null) {
1023 StringBundler query = null;
1024
1025 if (orderByComparator != null) {
1026 query = new StringBundler(4 +
1027 (orderByComparator.getOrderByFields().length * 3));
1028 }
1029 else {
1030 query = new StringBundler(4);
1031 }
1032
1033 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1034
1035 boolean bindUuid = false;
1036
1037 if (uuid == null) {
1038 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1039 }
1040 else if (uuid.equals(StringPool.BLANK)) {
1041 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1042 }
1043 else {
1044 bindUuid = true;
1045
1046 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1047 }
1048
1049 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1050
1051 if (orderByComparator != null) {
1052 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1053 orderByComparator);
1054 }
1055 else
1056 if (pagination) {
1057 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1058 }
1059
1060 String sql = query.toString();
1061
1062 Session session = null;
1063
1064 try {
1065 session = openSession();
1066
1067 Query q = session.createQuery(sql);
1068
1069 QueryPos qPos = QueryPos.getInstance(q);
1070
1071 if (bindUuid) {
1072 qPos.add(uuid);
1073 }
1074
1075 qPos.add(companyId);
1076
1077 if (!pagination) {
1078 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1079 start, end, false);
1080
1081 Collections.sort(list);
1082
1083 list = Collections.unmodifiableList(list);
1084 }
1085 else {
1086 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1087 start, end);
1088 }
1089
1090 cacheResult(list);
1091
1092 finderCache.putResult(finderPath, finderArgs, list);
1093 }
1094 catch (Exception e) {
1095 finderCache.removeResult(finderPath, finderArgs);
1096
1097 throw processException(e);
1098 }
1099 finally {
1100 closeSession(session);
1101 }
1102 }
1103
1104 return list;
1105 }
1106
1107
1116 @Override
1117 public MBMailingList findByUuid_C_First(String uuid, long companyId,
1118 OrderByComparator<MBMailingList> orderByComparator)
1119 throws NoSuchMailingListException {
1120 MBMailingList mbMailingList = fetchByUuid_C_First(uuid, companyId,
1121 orderByComparator);
1122
1123 if (mbMailingList != null) {
1124 return mbMailingList;
1125 }
1126
1127 StringBundler msg = new StringBundler(6);
1128
1129 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1130
1131 msg.append("uuid=");
1132 msg.append(uuid);
1133
1134 msg.append(", companyId=");
1135 msg.append(companyId);
1136
1137 msg.append(StringPool.CLOSE_CURLY_BRACE);
1138
1139 throw new NoSuchMailingListException(msg.toString());
1140 }
1141
1142
1150 @Override
1151 public MBMailingList fetchByUuid_C_First(String uuid, long companyId,
1152 OrderByComparator<MBMailingList> orderByComparator) {
1153 List<MBMailingList> list = findByUuid_C(uuid, companyId, 0, 1,
1154 orderByComparator);
1155
1156 if (!list.isEmpty()) {
1157 return list.get(0);
1158 }
1159
1160 return null;
1161 }
1162
1163
1172 @Override
1173 public MBMailingList findByUuid_C_Last(String uuid, long companyId,
1174 OrderByComparator<MBMailingList> orderByComparator)
1175 throws NoSuchMailingListException {
1176 MBMailingList mbMailingList = fetchByUuid_C_Last(uuid, companyId,
1177 orderByComparator);
1178
1179 if (mbMailingList != null) {
1180 return mbMailingList;
1181 }
1182
1183 StringBundler msg = new StringBundler(6);
1184
1185 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1186
1187 msg.append("uuid=");
1188 msg.append(uuid);
1189
1190 msg.append(", companyId=");
1191 msg.append(companyId);
1192
1193 msg.append(StringPool.CLOSE_CURLY_BRACE);
1194
1195 throw new NoSuchMailingListException(msg.toString());
1196 }
1197
1198
1206 @Override
1207 public MBMailingList fetchByUuid_C_Last(String uuid, long companyId,
1208 OrderByComparator<MBMailingList> orderByComparator) {
1209 int count = countByUuid_C(uuid, companyId);
1210
1211 if (count == 0) {
1212 return null;
1213 }
1214
1215 List<MBMailingList> list = findByUuid_C(uuid, companyId, count - 1,
1216 count, orderByComparator);
1217
1218 if (!list.isEmpty()) {
1219 return list.get(0);
1220 }
1221
1222 return null;
1223 }
1224
1225
1235 @Override
1236 public MBMailingList[] findByUuid_C_PrevAndNext(long mailingListId,
1237 String uuid, long companyId,
1238 OrderByComparator<MBMailingList> orderByComparator)
1239 throws NoSuchMailingListException {
1240 MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1241
1242 Session session = null;
1243
1244 try {
1245 session = openSession();
1246
1247 MBMailingList[] array = new MBMailingListImpl[3];
1248
1249 array[0] = getByUuid_C_PrevAndNext(session, mbMailingList, uuid,
1250 companyId, orderByComparator, true);
1251
1252 array[1] = mbMailingList;
1253
1254 array[2] = getByUuid_C_PrevAndNext(session, mbMailingList, uuid,
1255 companyId, orderByComparator, false);
1256
1257 return array;
1258 }
1259 catch (Exception e) {
1260 throw processException(e);
1261 }
1262 finally {
1263 closeSession(session);
1264 }
1265 }
1266
1267 protected MBMailingList getByUuid_C_PrevAndNext(Session session,
1268 MBMailingList mbMailingList, String uuid, long companyId,
1269 OrderByComparator<MBMailingList> orderByComparator, boolean previous) {
1270 StringBundler query = null;
1271
1272 if (orderByComparator != null) {
1273 query = new StringBundler(6 +
1274 (orderByComparator.getOrderByFields().length * 6));
1275 }
1276 else {
1277 query = new StringBundler(3);
1278 }
1279
1280 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1281
1282 boolean bindUuid = false;
1283
1284 if (uuid == null) {
1285 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1286 }
1287 else if (uuid.equals(StringPool.BLANK)) {
1288 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1289 }
1290 else {
1291 bindUuid = true;
1292
1293 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1294 }
1295
1296 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1297
1298 if (orderByComparator != null) {
1299 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1300
1301 if (orderByConditionFields.length > 0) {
1302 query.append(WHERE_AND);
1303 }
1304
1305 for (int i = 0; i < orderByConditionFields.length; i++) {
1306 query.append(_ORDER_BY_ENTITY_ALIAS);
1307 query.append(orderByConditionFields[i]);
1308
1309 if ((i + 1) < orderByConditionFields.length) {
1310 if (orderByComparator.isAscending() ^ previous) {
1311 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1312 }
1313 else {
1314 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1315 }
1316 }
1317 else {
1318 if (orderByComparator.isAscending() ^ previous) {
1319 query.append(WHERE_GREATER_THAN);
1320 }
1321 else {
1322 query.append(WHERE_LESSER_THAN);
1323 }
1324 }
1325 }
1326
1327 query.append(ORDER_BY_CLAUSE);
1328
1329 String[] orderByFields = orderByComparator.getOrderByFields();
1330
1331 for (int i = 0; i < orderByFields.length; i++) {
1332 query.append(_ORDER_BY_ENTITY_ALIAS);
1333 query.append(orderByFields[i]);
1334
1335 if ((i + 1) < orderByFields.length) {
1336 if (orderByComparator.isAscending() ^ previous) {
1337 query.append(ORDER_BY_ASC_HAS_NEXT);
1338 }
1339 else {
1340 query.append(ORDER_BY_DESC_HAS_NEXT);
1341 }
1342 }
1343 else {
1344 if (orderByComparator.isAscending() ^ previous) {
1345 query.append(ORDER_BY_ASC);
1346 }
1347 else {
1348 query.append(ORDER_BY_DESC);
1349 }
1350 }
1351 }
1352 }
1353 else {
1354 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1355 }
1356
1357 String sql = query.toString();
1358
1359 Query q = session.createQuery(sql);
1360
1361 q.setFirstResult(0);
1362 q.setMaxResults(2);
1363
1364 QueryPos qPos = QueryPos.getInstance(q);
1365
1366 if (bindUuid) {
1367 qPos.add(uuid);
1368 }
1369
1370 qPos.add(companyId);
1371
1372 if (orderByComparator != null) {
1373 Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1374
1375 for (Object value : values) {
1376 qPos.add(value);
1377 }
1378 }
1379
1380 List<MBMailingList> list = q.list();
1381
1382 if (list.size() == 2) {
1383 return list.get(1);
1384 }
1385 else {
1386 return null;
1387 }
1388 }
1389
1390
1396 @Override
1397 public void removeByUuid_C(String uuid, long companyId) {
1398 for (MBMailingList mbMailingList : findByUuid_C(uuid, companyId,
1399 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1400 remove(mbMailingList);
1401 }
1402 }
1403
1404
1411 @Override
1412 public int countByUuid_C(String uuid, long companyId) {
1413 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1414
1415 Object[] finderArgs = new Object[] { uuid, companyId };
1416
1417 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1418
1419 if (count == null) {
1420 StringBundler query = new StringBundler(3);
1421
1422 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1423
1424 boolean bindUuid = false;
1425
1426 if (uuid == null) {
1427 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1428 }
1429 else if (uuid.equals(StringPool.BLANK)) {
1430 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1431 }
1432 else {
1433 bindUuid = true;
1434
1435 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1436 }
1437
1438 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1439
1440 String sql = query.toString();
1441
1442 Session session = null;
1443
1444 try {
1445 session = openSession();
1446
1447 Query q = session.createQuery(sql);
1448
1449 QueryPos qPos = QueryPos.getInstance(q);
1450
1451 if (bindUuid) {
1452 qPos.add(uuid);
1453 }
1454
1455 qPos.add(companyId);
1456
1457 count = (Long)q.uniqueResult();
1458
1459 finderCache.putResult(finderPath, finderArgs, count);
1460 }
1461 catch (Exception e) {
1462 finderCache.removeResult(finderPath, finderArgs);
1463
1464 throw processException(e);
1465 }
1466 finally {
1467 closeSession(session);
1468 }
1469 }
1470
1471 return count.intValue();
1472 }
1473
1474 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMailingList.uuid IS NULL AND ";
1475 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMailingList.uuid = ? AND ";
1476 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMailingList.uuid IS NULL OR mbMailingList.uuid = '') AND ";
1477 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMailingList.companyId = ?";
1478 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1479 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1480 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
1481 "findByActive",
1482 new String[] {
1483 Boolean.class.getName(),
1484
1485 Integer.class.getName(), Integer.class.getName(),
1486 OrderByComparator.class.getName()
1487 });
1488 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE =
1489 new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1490 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1491 MBMailingListImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
1492 "findByActive", new String[] { Boolean.class.getName() },
1493 MBMailingListModelImpl.ACTIVE_COLUMN_BITMASK);
1494 public static final FinderPath FINDER_PATH_COUNT_BY_ACTIVE = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1495 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
1496 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByActive",
1497 new String[] { Boolean.class.getName() });
1498
1499
1505 @Override
1506 public List<MBMailingList> findByActive(boolean active) {
1507 return findByActive(active, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1508 }
1509
1510
1522 @Override
1523 public List<MBMailingList> findByActive(boolean active, int start, int end) {
1524 return findByActive(active, start, end, null);
1525 }
1526
1527
1540 @Override
1541 public List<MBMailingList> findByActive(boolean active, int start, int end,
1542 OrderByComparator<MBMailingList> orderByComparator) {
1543 return findByActive(active, start, end, orderByComparator, true);
1544 }
1545
1546
1560 @Override
1561 public List<MBMailingList> findByActive(boolean active, int start, int end,
1562 OrderByComparator<MBMailingList> orderByComparator,
1563 boolean retrieveFromCache) {
1564 boolean pagination = true;
1565 FinderPath finderPath = null;
1566 Object[] finderArgs = null;
1567
1568 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1569 (orderByComparator == null)) {
1570 pagination = false;
1571 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE;
1572 finderArgs = new Object[] { active };
1573 }
1574 else {
1575 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_ACTIVE;
1576 finderArgs = new Object[] { active, start, end, orderByComparator };
1577 }
1578
1579 List<MBMailingList> list = null;
1580
1581 if (retrieveFromCache) {
1582 list = (List<MBMailingList>)finderCache.getResult(finderPath,
1583 finderArgs, this);
1584
1585 if ((list != null) && !list.isEmpty()) {
1586 for (MBMailingList mbMailingList : list) {
1587 if ((active != mbMailingList.getActive())) {
1588 list = null;
1589
1590 break;
1591 }
1592 }
1593 }
1594 }
1595
1596 if (list == null) {
1597 StringBundler query = null;
1598
1599 if (orderByComparator != null) {
1600 query = new StringBundler(3 +
1601 (orderByComparator.getOrderByFields().length * 3));
1602 }
1603 else {
1604 query = new StringBundler(3);
1605 }
1606
1607 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1608
1609 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1610
1611 if (orderByComparator != null) {
1612 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1613 orderByComparator);
1614 }
1615 else
1616 if (pagination) {
1617 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1618 }
1619
1620 String sql = query.toString();
1621
1622 Session session = null;
1623
1624 try {
1625 session = openSession();
1626
1627 Query q = session.createQuery(sql);
1628
1629 QueryPos qPos = QueryPos.getInstance(q);
1630
1631 qPos.add(active);
1632
1633 if (!pagination) {
1634 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1635 start, end, false);
1636
1637 Collections.sort(list);
1638
1639 list = Collections.unmodifiableList(list);
1640 }
1641 else {
1642 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
1643 start, end);
1644 }
1645
1646 cacheResult(list);
1647
1648 finderCache.putResult(finderPath, finderArgs, list);
1649 }
1650 catch (Exception e) {
1651 finderCache.removeResult(finderPath, finderArgs);
1652
1653 throw processException(e);
1654 }
1655 finally {
1656 closeSession(session);
1657 }
1658 }
1659
1660 return list;
1661 }
1662
1663
1671 @Override
1672 public MBMailingList findByActive_First(boolean active,
1673 OrderByComparator<MBMailingList> orderByComparator)
1674 throws NoSuchMailingListException {
1675 MBMailingList mbMailingList = fetchByActive_First(active,
1676 orderByComparator);
1677
1678 if (mbMailingList != null) {
1679 return mbMailingList;
1680 }
1681
1682 StringBundler msg = new StringBundler(4);
1683
1684 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1685
1686 msg.append("active=");
1687 msg.append(active);
1688
1689 msg.append(StringPool.CLOSE_CURLY_BRACE);
1690
1691 throw new NoSuchMailingListException(msg.toString());
1692 }
1693
1694
1701 @Override
1702 public MBMailingList fetchByActive_First(boolean active,
1703 OrderByComparator<MBMailingList> orderByComparator) {
1704 List<MBMailingList> list = findByActive(active, 0, 1, orderByComparator);
1705
1706 if (!list.isEmpty()) {
1707 return list.get(0);
1708 }
1709
1710 return null;
1711 }
1712
1713
1721 @Override
1722 public MBMailingList findByActive_Last(boolean active,
1723 OrderByComparator<MBMailingList> orderByComparator)
1724 throws NoSuchMailingListException {
1725 MBMailingList mbMailingList = fetchByActive_Last(active,
1726 orderByComparator);
1727
1728 if (mbMailingList != null) {
1729 return mbMailingList;
1730 }
1731
1732 StringBundler msg = new StringBundler(4);
1733
1734 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1735
1736 msg.append("active=");
1737 msg.append(active);
1738
1739 msg.append(StringPool.CLOSE_CURLY_BRACE);
1740
1741 throw new NoSuchMailingListException(msg.toString());
1742 }
1743
1744
1751 @Override
1752 public MBMailingList fetchByActive_Last(boolean active,
1753 OrderByComparator<MBMailingList> orderByComparator) {
1754 int count = countByActive(active);
1755
1756 if (count == 0) {
1757 return null;
1758 }
1759
1760 List<MBMailingList> list = findByActive(active, count - 1, count,
1761 orderByComparator);
1762
1763 if (!list.isEmpty()) {
1764 return list.get(0);
1765 }
1766
1767 return null;
1768 }
1769
1770
1779 @Override
1780 public MBMailingList[] findByActive_PrevAndNext(long mailingListId,
1781 boolean active, OrderByComparator<MBMailingList> orderByComparator)
1782 throws NoSuchMailingListException {
1783 MBMailingList mbMailingList = findByPrimaryKey(mailingListId);
1784
1785 Session session = null;
1786
1787 try {
1788 session = openSession();
1789
1790 MBMailingList[] array = new MBMailingListImpl[3];
1791
1792 array[0] = getByActive_PrevAndNext(session, mbMailingList, active,
1793 orderByComparator, true);
1794
1795 array[1] = mbMailingList;
1796
1797 array[2] = getByActive_PrevAndNext(session, mbMailingList, active,
1798 orderByComparator, false);
1799
1800 return array;
1801 }
1802 catch (Exception e) {
1803 throw processException(e);
1804 }
1805 finally {
1806 closeSession(session);
1807 }
1808 }
1809
1810 protected MBMailingList getByActive_PrevAndNext(Session session,
1811 MBMailingList mbMailingList, boolean active,
1812 OrderByComparator<MBMailingList> orderByComparator, boolean previous) {
1813 StringBundler query = null;
1814
1815 if (orderByComparator != null) {
1816 query = new StringBundler(6 +
1817 (orderByComparator.getOrderByFields().length * 6));
1818 }
1819 else {
1820 query = new StringBundler(3);
1821 }
1822
1823 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
1824
1825 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1826
1827 if (orderByComparator != null) {
1828 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1829
1830 if (orderByConditionFields.length > 0) {
1831 query.append(WHERE_AND);
1832 }
1833
1834 for (int i = 0; i < orderByConditionFields.length; i++) {
1835 query.append(_ORDER_BY_ENTITY_ALIAS);
1836 query.append(orderByConditionFields[i]);
1837
1838 if ((i + 1) < orderByConditionFields.length) {
1839 if (orderByComparator.isAscending() ^ previous) {
1840 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1841 }
1842 else {
1843 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1844 }
1845 }
1846 else {
1847 if (orderByComparator.isAscending() ^ previous) {
1848 query.append(WHERE_GREATER_THAN);
1849 }
1850 else {
1851 query.append(WHERE_LESSER_THAN);
1852 }
1853 }
1854 }
1855
1856 query.append(ORDER_BY_CLAUSE);
1857
1858 String[] orderByFields = orderByComparator.getOrderByFields();
1859
1860 for (int i = 0; i < orderByFields.length; i++) {
1861 query.append(_ORDER_BY_ENTITY_ALIAS);
1862 query.append(orderByFields[i]);
1863
1864 if ((i + 1) < orderByFields.length) {
1865 if (orderByComparator.isAscending() ^ previous) {
1866 query.append(ORDER_BY_ASC_HAS_NEXT);
1867 }
1868 else {
1869 query.append(ORDER_BY_DESC_HAS_NEXT);
1870 }
1871 }
1872 else {
1873 if (orderByComparator.isAscending() ^ previous) {
1874 query.append(ORDER_BY_ASC);
1875 }
1876 else {
1877 query.append(ORDER_BY_DESC);
1878 }
1879 }
1880 }
1881 }
1882 else {
1883 query.append(MBMailingListModelImpl.ORDER_BY_JPQL);
1884 }
1885
1886 String sql = query.toString();
1887
1888 Query q = session.createQuery(sql);
1889
1890 q.setFirstResult(0);
1891 q.setMaxResults(2);
1892
1893 QueryPos qPos = QueryPos.getInstance(q);
1894
1895 qPos.add(active);
1896
1897 if (orderByComparator != null) {
1898 Object[] values = orderByComparator.getOrderByConditionValues(mbMailingList);
1899
1900 for (Object value : values) {
1901 qPos.add(value);
1902 }
1903 }
1904
1905 List<MBMailingList> list = q.list();
1906
1907 if (list.size() == 2) {
1908 return list.get(1);
1909 }
1910 else {
1911 return null;
1912 }
1913 }
1914
1915
1920 @Override
1921 public void removeByActive(boolean active) {
1922 for (MBMailingList mbMailingList : findByActive(active,
1923 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1924 remove(mbMailingList);
1925 }
1926 }
1927
1928
1934 @Override
1935 public int countByActive(boolean active) {
1936 FinderPath finderPath = FINDER_PATH_COUNT_BY_ACTIVE;
1937
1938 Object[] finderArgs = new Object[] { active };
1939
1940 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1941
1942 if (count == null) {
1943 StringBundler query = new StringBundler(2);
1944
1945 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
1946
1947 query.append(_FINDER_COLUMN_ACTIVE_ACTIVE_2);
1948
1949 String sql = query.toString();
1950
1951 Session session = null;
1952
1953 try {
1954 session = openSession();
1955
1956 Query q = session.createQuery(sql);
1957
1958 QueryPos qPos = QueryPos.getInstance(q);
1959
1960 qPos.add(active);
1961
1962 count = (Long)q.uniqueResult();
1963
1964 finderCache.putResult(finderPath, finderArgs, count);
1965 }
1966 catch (Exception e) {
1967 finderCache.removeResult(finderPath, finderArgs);
1968
1969 throw processException(e);
1970 }
1971 finally {
1972 closeSession(session);
1973 }
1974 }
1975
1976 return count.intValue();
1977 }
1978
1979 private static final String _FINDER_COLUMN_ACTIVE_ACTIVE_2 = "mbMailingList.active = ?";
1980 public static final FinderPath FINDER_PATH_FETCH_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1981 MBMailingListModelImpl.FINDER_CACHE_ENABLED,
1982 MBMailingListImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByG_C",
1983 new String[] { Long.class.getName(), Long.class.getName() },
1984 MBMailingListModelImpl.GROUPID_COLUMN_BITMASK |
1985 MBMailingListModelImpl.CATEGORYID_COLUMN_BITMASK);
1986 public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
1987 MBMailingListModelImpl.FINDER_CACHE_ENABLED, Long.class,
1988 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
1989 new String[] { Long.class.getName(), Long.class.getName() });
1990
1991
1999 @Override
2000 public MBMailingList findByG_C(long groupId, long categoryId)
2001 throws NoSuchMailingListException {
2002 MBMailingList mbMailingList = fetchByG_C(groupId, categoryId);
2003
2004 if (mbMailingList == null) {
2005 StringBundler msg = new StringBundler(6);
2006
2007 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2008
2009 msg.append("groupId=");
2010 msg.append(groupId);
2011
2012 msg.append(", categoryId=");
2013 msg.append(categoryId);
2014
2015 msg.append(StringPool.CLOSE_CURLY_BRACE);
2016
2017 if (_log.isWarnEnabled()) {
2018 _log.warn(msg.toString());
2019 }
2020
2021 throw new NoSuchMailingListException(msg.toString());
2022 }
2023
2024 return mbMailingList;
2025 }
2026
2027
2034 @Override
2035 public MBMailingList fetchByG_C(long groupId, long categoryId) {
2036 return fetchByG_C(groupId, categoryId, true);
2037 }
2038
2039
2047 @Override
2048 public MBMailingList fetchByG_C(long groupId, long categoryId,
2049 boolean retrieveFromCache) {
2050 Object[] finderArgs = new Object[] { groupId, categoryId };
2051
2052 Object result = null;
2053
2054 if (retrieveFromCache) {
2055 result = finderCache.getResult(FINDER_PATH_FETCH_BY_G_C,
2056 finderArgs, this);
2057 }
2058
2059 if (result instanceof MBMailingList) {
2060 MBMailingList mbMailingList = (MBMailingList)result;
2061
2062 if ((groupId != mbMailingList.getGroupId()) ||
2063 (categoryId != mbMailingList.getCategoryId())) {
2064 result = null;
2065 }
2066 }
2067
2068 if (result == null) {
2069 StringBundler query = new StringBundler(4);
2070
2071 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE);
2072
2073 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2074
2075 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2076
2077 String sql = query.toString();
2078
2079 Session session = null;
2080
2081 try {
2082 session = openSession();
2083
2084 Query q = session.createQuery(sql);
2085
2086 QueryPos qPos = QueryPos.getInstance(q);
2087
2088 qPos.add(groupId);
2089
2090 qPos.add(categoryId);
2091
2092 List<MBMailingList> list = q.list();
2093
2094 if (list.isEmpty()) {
2095 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C, finderArgs,
2096 list);
2097 }
2098 else {
2099 MBMailingList mbMailingList = list.get(0);
2100
2101 result = mbMailingList;
2102
2103 cacheResult(mbMailingList);
2104
2105 if ((mbMailingList.getGroupId() != groupId) ||
2106 (mbMailingList.getCategoryId() != categoryId)) {
2107 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C,
2108 finderArgs, mbMailingList);
2109 }
2110 }
2111 }
2112 catch (Exception e) {
2113 finderCache.removeResult(FINDER_PATH_FETCH_BY_G_C, finderArgs);
2114
2115 throw processException(e);
2116 }
2117 finally {
2118 closeSession(session);
2119 }
2120 }
2121
2122 if (result instanceof List<?>) {
2123 return null;
2124 }
2125 else {
2126 return (MBMailingList)result;
2127 }
2128 }
2129
2130
2137 @Override
2138 public MBMailingList removeByG_C(long groupId, long categoryId)
2139 throws NoSuchMailingListException {
2140 MBMailingList mbMailingList = findByG_C(groupId, categoryId);
2141
2142 return remove(mbMailingList);
2143 }
2144
2145
2152 @Override
2153 public int countByG_C(long groupId, long categoryId) {
2154 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
2155
2156 Object[] finderArgs = new Object[] { groupId, categoryId };
2157
2158 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2159
2160 if (count == null) {
2161 StringBundler query = new StringBundler(3);
2162
2163 query.append(_SQL_COUNT_MBMAILINGLIST_WHERE);
2164
2165 query.append(_FINDER_COLUMN_G_C_GROUPID_2);
2166
2167 query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
2168
2169 String sql = query.toString();
2170
2171 Session session = null;
2172
2173 try {
2174 session = openSession();
2175
2176 Query q = session.createQuery(sql);
2177
2178 QueryPos qPos = QueryPos.getInstance(q);
2179
2180 qPos.add(groupId);
2181
2182 qPos.add(categoryId);
2183
2184 count = (Long)q.uniqueResult();
2185
2186 finderCache.putResult(finderPath, finderArgs, count);
2187 }
2188 catch (Exception e) {
2189 finderCache.removeResult(finderPath, finderArgs);
2190
2191 throw processException(e);
2192 }
2193 finally {
2194 closeSession(session);
2195 }
2196 }
2197
2198 return count.intValue();
2199 }
2200
2201 private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMailingList.groupId = ? AND ";
2202 private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMailingList.categoryId = ?";
2203
2204 public MBMailingListPersistenceImpl() {
2205 setModelClass(MBMailingList.class);
2206 }
2207
2208
2213 @Override
2214 public void cacheResult(MBMailingList mbMailingList) {
2215 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2216 MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
2217 mbMailingList);
2218
2219 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
2220 new Object[] { mbMailingList.getUuid(), mbMailingList.getGroupId() },
2221 mbMailingList);
2222
2223 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C,
2224 new Object[] {
2225 mbMailingList.getGroupId(), mbMailingList.getCategoryId()
2226 }, mbMailingList);
2227
2228 mbMailingList.resetOriginalValues();
2229 }
2230
2231
2236 @Override
2237 public void cacheResult(List<MBMailingList> mbMailingLists) {
2238 for (MBMailingList mbMailingList : mbMailingLists) {
2239 if (entityCache.getResult(
2240 MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2241 MBMailingListImpl.class, mbMailingList.getPrimaryKey()) == null) {
2242 cacheResult(mbMailingList);
2243 }
2244 else {
2245 mbMailingList.resetOriginalValues();
2246 }
2247 }
2248 }
2249
2250
2257 @Override
2258 public void clearCache() {
2259 entityCache.clearCache(MBMailingListImpl.class);
2260
2261 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
2262 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2263 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2264 }
2265
2266
2273 @Override
2274 public void clearCache(MBMailingList mbMailingList) {
2275 entityCache.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2276 MBMailingListImpl.class, mbMailingList.getPrimaryKey());
2277
2278 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2279 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2280
2281 clearUniqueFindersCache((MBMailingListModelImpl)mbMailingList);
2282 }
2283
2284 @Override
2285 public void clearCache(List<MBMailingList> mbMailingLists) {
2286 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2287 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2288
2289 for (MBMailingList mbMailingList : mbMailingLists) {
2290 entityCache.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2291 MBMailingListImpl.class, mbMailingList.getPrimaryKey());
2292
2293 clearUniqueFindersCache((MBMailingListModelImpl)mbMailingList);
2294 }
2295 }
2296
2297 protected void cacheUniqueFindersCache(
2298 MBMailingListModelImpl mbMailingListModelImpl, boolean isNew) {
2299 if (isNew) {
2300 Object[] args = new Object[] {
2301 mbMailingListModelImpl.getUuid(),
2302 mbMailingListModelImpl.getGroupId()
2303 };
2304
2305 finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2306 Long.valueOf(1));
2307 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2308 mbMailingListModelImpl);
2309
2310 args = new Object[] {
2311 mbMailingListModelImpl.getGroupId(),
2312 mbMailingListModelImpl.getCategoryId()
2313 };
2314
2315 finderCache.putResult(FINDER_PATH_COUNT_BY_G_C, args,
2316 Long.valueOf(1));
2317 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C, args,
2318 mbMailingListModelImpl);
2319 }
2320 else {
2321 if ((mbMailingListModelImpl.getColumnBitmask() &
2322 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2323 Object[] args = new Object[] {
2324 mbMailingListModelImpl.getUuid(),
2325 mbMailingListModelImpl.getGroupId()
2326 };
2327
2328 finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
2329 Long.valueOf(1));
2330 finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
2331 mbMailingListModelImpl);
2332 }
2333
2334 if ((mbMailingListModelImpl.getColumnBitmask() &
2335 FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
2336 Object[] args = new Object[] {
2337 mbMailingListModelImpl.getGroupId(),
2338 mbMailingListModelImpl.getCategoryId()
2339 };
2340
2341 finderCache.putResult(FINDER_PATH_COUNT_BY_G_C, args,
2342 Long.valueOf(1));
2343 finderCache.putResult(FINDER_PATH_FETCH_BY_G_C, args,
2344 mbMailingListModelImpl);
2345 }
2346 }
2347 }
2348
2349 protected void clearUniqueFindersCache(
2350 MBMailingListModelImpl mbMailingListModelImpl) {
2351 Object[] args = new Object[] {
2352 mbMailingListModelImpl.getUuid(),
2353 mbMailingListModelImpl.getGroupId()
2354 };
2355
2356 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2357 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2358
2359 if ((mbMailingListModelImpl.getColumnBitmask() &
2360 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
2361 args = new Object[] {
2362 mbMailingListModelImpl.getOriginalUuid(),
2363 mbMailingListModelImpl.getOriginalGroupId()
2364 };
2365
2366 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
2367 finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
2368 }
2369
2370 args = new Object[] {
2371 mbMailingListModelImpl.getGroupId(),
2372 mbMailingListModelImpl.getCategoryId()
2373 };
2374
2375 finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2376 finderCache.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
2377
2378 if ((mbMailingListModelImpl.getColumnBitmask() &
2379 FINDER_PATH_FETCH_BY_G_C.getColumnBitmask()) != 0) {
2380 args = new Object[] {
2381 mbMailingListModelImpl.getOriginalGroupId(),
2382 mbMailingListModelImpl.getOriginalCategoryId()
2383 };
2384
2385 finderCache.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
2386 finderCache.removeResult(FINDER_PATH_FETCH_BY_G_C, args);
2387 }
2388 }
2389
2390
2396 @Override
2397 public MBMailingList create(long mailingListId) {
2398 MBMailingList mbMailingList = new MBMailingListImpl();
2399
2400 mbMailingList.setNew(true);
2401 mbMailingList.setPrimaryKey(mailingListId);
2402
2403 String uuid = PortalUUIDUtil.generate();
2404
2405 mbMailingList.setUuid(uuid);
2406
2407 return mbMailingList;
2408 }
2409
2410
2417 @Override
2418 public MBMailingList remove(long mailingListId)
2419 throws NoSuchMailingListException {
2420 return remove((Serializable)mailingListId);
2421 }
2422
2423
2430 @Override
2431 public MBMailingList remove(Serializable primaryKey)
2432 throws NoSuchMailingListException {
2433 Session session = null;
2434
2435 try {
2436 session = openSession();
2437
2438 MBMailingList mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2439 primaryKey);
2440
2441 if (mbMailingList == null) {
2442 if (_log.isWarnEnabled()) {
2443 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2444 }
2445
2446 throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2447 primaryKey);
2448 }
2449
2450 return remove(mbMailingList);
2451 }
2452 catch (NoSuchMailingListException nsee) {
2453 throw nsee;
2454 }
2455 catch (Exception e) {
2456 throw processException(e);
2457 }
2458 finally {
2459 closeSession(session);
2460 }
2461 }
2462
2463 @Override
2464 protected MBMailingList removeImpl(MBMailingList mbMailingList) {
2465 mbMailingList = toUnwrappedModel(mbMailingList);
2466
2467 Session session = null;
2468
2469 try {
2470 session = openSession();
2471
2472 if (!session.contains(mbMailingList)) {
2473 mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2474 mbMailingList.getPrimaryKeyObj());
2475 }
2476
2477 if (mbMailingList != null) {
2478 session.delete(mbMailingList);
2479 }
2480 }
2481 catch (Exception e) {
2482 throw processException(e);
2483 }
2484 finally {
2485 closeSession(session);
2486 }
2487
2488 if (mbMailingList != null) {
2489 clearCache(mbMailingList);
2490 }
2491
2492 return mbMailingList;
2493 }
2494
2495 @Override
2496 public MBMailingList updateImpl(MBMailingList mbMailingList) {
2497 mbMailingList = toUnwrappedModel(mbMailingList);
2498
2499 boolean isNew = mbMailingList.isNew();
2500
2501 MBMailingListModelImpl mbMailingListModelImpl = (MBMailingListModelImpl)mbMailingList;
2502
2503 if (Validator.isNull(mbMailingList.getUuid())) {
2504 String uuid = PortalUUIDUtil.generate();
2505
2506 mbMailingList.setUuid(uuid);
2507 }
2508
2509 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
2510
2511 Date now = new Date();
2512
2513 if (isNew && (mbMailingList.getCreateDate() == null)) {
2514 if (serviceContext == null) {
2515 mbMailingList.setCreateDate(now);
2516 }
2517 else {
2518 mbMailingList.setCreateDate(serviceContext.getCreateDate(now));
2519 }
2520 }
2521
2522 if (!mbMailingListModelImpl.hasSetModifiedDate()) {
2523 if (serviceContext == null) {
2524 mbMailingList.setModifiedDate(now);
2525 }
2526 else {
2527 mbMailingList.setModifiedDate(serviceContext.getModifiedDate(
2528 now));
2529 }
2530 }
2531
2532 Session session = null;
2533
2534 try {
2535 session = openSession();
2536
2537 if (mbMailingList.isNew()) {
2538 session.save(mbMailingList);
2539
2540 mbMailingList.setNew(false);
2541 }
2542 else {
2543 mbMailingList = (MBMailingList)session.merge(mbMailingList);
2544 }
2545 }
2546 catch (Exception e) {
2547 throw processException(e);
2548 }
2549 finally {
2550 closeSession(session);
2551 }
2552
2553 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2554
2555 if (isNew || !MBMailingListModelImpl.COLUMN_BITMASK_ENABLED) {
2556 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2557 }
2558
2559 else {
2560 if ((mbMailingListModelImpl.getColumnBitmask() &
2561 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2562 Object[] args = new Object[] {
2563 mbMailingListModelImpl.getOriginalUuid()
2564 };
2565
2566 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2567 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2568 args);
2569
2570 args = new Object[] { mbMailingListModelImpl.getUuid() };
2571
2572 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2573 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2574 args);
2575 }
2576
2577 if ((mbMailingListModelImpl.getColumnBitmask() &
2578 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2579 Object[] args = new Object[] {
2580 mbMailingListModelImpl.getOriginalUuid(),
2581 mbMailingListModelImpl.getOriginalCompanyId()
2582 };
2583
2584 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2585 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2586 args);
2587
2588 args = new Object[] {
2589 mbMailingListModelImpl.getUuid(),
2590 mbMailingListModelImpl.getCompanyId()
2591 };
2592
2593 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2594 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2595 args);
2596 }
2597
2598 if ((mbMailingListModelImpl.getColumnBitmask() &
2599 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE.getColumnBitmask()) != 0) {
2600 Object[] args = new Object[] {
2601 mbMailingListModelImpl.getOriginalActive()
2602 };
2603
2604 finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2605 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2606 args);
2607
2608 args = new Object[] { mbMailingListModelImpl.getActive() };
2609
2610 finderCache.removeResult(FINDER_PATH_COUNT_BY_ACTIVE, args);
2611 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_ACTIVE,
2612 args);
2613 }
2614 }
2615
2616 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2617 MBMailingListImpl.class, mbMailingList.getPrimaryKey(),
2618 mbMailingList, false);
2619
2620 clearUniqueFindersCache(mbMailingListModelImpl);
2621 cacheUniqueFindersCache(mbMailingListModelImpl, isNew);
2622
2623 mbMailingList.resetOriginalValues();
2624
2625 return mbMailingList;
2626 }
2627
2628 protected MBMailingList toUnwrappedModel(MBMailingList mbMailingList) {
2629 if (mbMailingList instanceof MBMailingListImpl) {
2630 return mbMailingList;
2631 }
2632
2633 MBMailingListImpl mbMailingListImpl = new MBMailingListImpl();
2634
2635 mbMailingListImpl.setNew(mbMailingList.isNew());
2636 mbMailingListImpl.setPrimaryKey(mbMailingList.getPrimaryKey());
2637
2638 mbMailingListImpl.setUuid(mbMailingList.getUuid());
2639 mbMailingListImpl.setMailingListId(mbMailingList.getMailingListId());
2640 mbMailingListImpl.setGroupId(mbMailingList.getGroupId());
2641 mbMailingListImpl.setCompanyId(mbMailingList.getCompanyId());
2642 mbMailingListImpl.setUserId(mbMailingList.getUserId());
2643 mbMailingListImpl.setUserName(mbMailingList.getUserName());
2644 mbMailingListImpl.setCreateDate(mbMailingList.getCreateDate());
2645 mbMailingListImpl.setModifiedDate(mbMailingList.getModifiedDate());
2646 mbMailingListImpl.setCategoryId(mbMailingList.getCategoryId());
2647 mbMailingListImpl.setEmailAddress(mbMailingList.getEmailAddress());
2648 mbMailingListImpl.setInProtocol(mbMailingList.getInProtocol());
2649 mbMailingListImpl.setInServerName(mbMailingList.getInServerName());
2650 mbMailingListImpl.setInServerPort(mbMailingList.getInServerPort());
2651 mbMailingListImpl.setInUseSSL(mbMailingList.isInUseSSL());
2652 mbMailingListImpl.setInUserName(mbMailingList.getInUserName());
2653 mbMailingListImpl.setInPassword(mbMailingList.getInPassword());
2654 mbMailingListImpl.setInReadInterval(mbMailingList.getInReadInterval());
2655 mbMailingListImpl.setOutEmailAddress(mbMailingList.getOutEmailAddress());
2656 mbMailingListImpl.setOutCustom(mbMailingList.isOutCustom());
2657 mbMailingListImpl.setOutServerName(mbMailingList.getOutServerName());
2658 mbMailingListImpl.setOutServerPort(mbMailingList.getOutServerPort());
2659 mbMailingListImpl.setOutUseSSL(mbMailingList.isOutUseSSL());
2660 mbMailingListImpl.setOutUserName(mbMailingList.getOutUserName());
2661 mbMailingListImpl.setOutPassword(mbMailingList.getOutPassword());
2662 mbMailingListImpl.setAllowAnonymous(mbMailingList.isAllowAnonymous());
2663 mbMailingListImpl.setActive(mbMailingList.isActive());
2664
2665 return mbMailingListImpl;
2666 }
2667
2668
2675 @Override
2676 public MBMailingList findByPrimaryKey(Serializable primaryKey)
2677 throws NoSuchMailingListException {
2678 MBMailingList mbMailingList = fetchByPrimaryKey(primaryKey);
2679
2680 if (mbMailingList == null) {
2681 if (_log.isWarnEnabled()) {
2682 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2683 }
2684
2685 throw new NoSuchMailingListException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2686 primaryKey);
2687 }
2688
2689 return mbMailingList;
2690 }
2691
2692
2699 @Override
2700 public MBMailingList findByPrimaryKey(long mailingListId)
2701 throws NoSuchMailingListException {
2702 return findByPrimaryKey((Serializable)mailingListId);
2703 }
2704
2705
2711 @Override
2712 public MBMailingList fetchByPrimaryKey(Serializable primaryKey) {
2713 MBMailingList mbMailingList = (MBMailingList)entityCache.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2714 MBMailingListImpl.class, primaryKey);
2715
2716 if (mbMailingList == _nullMBMailingList) {
2717 return null;
2718 }
2719
2720 if (mbMailingList == null) {
2721 Session session = null;
2722
2723 try {
2724 session = openSession();
2725
2726 mbMailingList = (MBMailingList)session.get(MBMailingListImpl.class,
2727 primaryKey);
2728
2729 if (mbMailingList != null) {
2730 cacheResult(mbMailingList);
2731 }
2732 else {
2733 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2734 MBMailingListImpl.class, primaryKey, _nullMBMailingList);
2735 }
2736 }
2737 catch (Exception e) {
2738 entityCache.removeResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2739 MBMailingListImpl.class, primaryKey);
2740
2741 throw processException(e);
2742 }
2743 finally {
2744 closeSession(session);
2745 }
2746 }
2747
2748 return mbMailingList;
2749 }
2750
2751
2757 @Override
2758 public MBMailingList fetchByPrimaryKey(long mailingListId) {
2759 return fetchByPrimaryKey((Serializable)mailingListId);
2760 }
2761
2762 @Override
2763 public Map<Serializable, MBMailingList> fetchByPrimaryKeys(
2764 Set<Serializable> primaryKeys) {
2765 if (primaryKeys.isEmpty()) {
2766 return Collections.emptyMap();
2767 }
2768
2769 Map<Serializable, MBMailingList> map = new HashMap<Serializable, MBMailingList>();
2770
2771 if (primaryKeys.size() == 1) {
2772 Iterator<Serializable> iterator = primaryKeys.iterator();
2773
2774 Serializable primaryKey = iterator.next();
2775
2776 MBMailingList mbMailingList = fetchByPrimaryKey(primaryKey);
2777
2778 if (mbMailingList != null) {
2779 map.put(primaryKey, mbMailingList);
2780 }
2781
2782 return map;
2783 }
2784
2785 Set<Serializable> uncachedPrimaryKeys = null;
2786
2787 for (Serializable primaryKey : primaryKeys) {
2788 MBMailingList mbMailingList = (MBMailingList)entityCache.getResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2789 MBMailingListImpl.class, primaryKey);
2790
2791 if (mbMailingList == null) {
2792 if (uncachedPrimaryKeys == null) {
2793 uncachedPrimaryKeys = new HashSet<Serializable>();
2794 }
2795
2796 uncachedPrimaryKeys.add(primaryKey);
2797 }
2798 else {
2799 map.put(primaryKey, mbMailingList);
2800 }
2801 }
2802
2803 if (uncachedPrimaryKeys == null) {
2804 return map;
2805 }
2806
2807 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2808 1);
2809
2810 query.append(_SQL_SELECT_MBMAILINGLIST_WHERE_PKS_IN);
2811
2812 for (Serializable primaryKey : uncachedPrimaryKeys) {
2813 query.append(String.valueOf(primaryKey));
2814
2815 query.append(StringPool.COMMA);
2816 }
2817
2818 query.setIndex(query.index() - 1);
2819
2820 query.append(StringPool.CLOSE_PARENTHESIS);
2821
2822 String sql = query.toString();
2823
2824 Session session = null;
2825
2826 try {
2827 session = openSession();
2828
2829 Query q = session.createQuery(sql);
2830
2831 for (MBMailingList mbMailingList : (List<MBMailingList>)q.list()) {
2832 map.put(mbMailingList.getPrimaryKeyObj(), mbMailingList);
2833
2834 cacheResult(mbMailingList);
2835
2836 uncachedPrimaryKeys.remove(mbMailingList.getPrimaryKeyObj());
2837 }
2838
2839 for (Serializable primaryKey : uncachedPrimaryKeys) {
2840 entityCache.putResult(MBMailingListModelImpl.ENTITY_CACHE_ENABLED,
2841 MBMailingListImpl.class, primaryKey, _nullMBMailingList);
2842 }
2843 }
2844 catch (Exception e) {
2845 throw processException(e);
2846 }
2847 finally {
2848 closeSession(session);
2849 }
2850
2851 return map;
2852 }
2853
2854
2859 @Override
2860 public List<MBMailingList> findAll() {
2861 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2862 }
2863
2864
2875 @Override
2876 public List<MBMailingList> findAll(int start, int end) {
2877 return findAll(start, end, null);
2878 }
2879
2880
2892 @Override
2893 public List<MBMailingList> findAll(int start, int end,
2894 OrderByComparator<MBMailingList> orderByComparator) {
2895 return findAll(start, end, orderByComparator, true);
2896 }
2897
2898
2911 @Override
2912 public List<MBMailingList> findAll(int start, int end,
2913 OrderByComparator<MBMailingList> orderByComparator,
2914 boolean retrieveFromCache) {
2915 boolean pagination = true;
2916 FinderPath finderPath = null;
2917 Object[] finderArgs = null;
2918
2919 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2920 (orderByComparator == null)) {
2921 pagination = false;
2922 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2923 finderArgs = FINDER_ARGS_EMPTY;
2924 }
2925 else {
2926 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2927 finderArgs = new Object[] { start, end, orderByComparator };
2928 }
2929
2930 List<MBMailingList> list = null;
2931
2932 if (retrieveFromCache) {
2933 list = (List<MBMailingList>)finderCache.getResult(finderPath,
2934 finderArgs, this);
2935 }
2936
2937 if (list == null) {
2938 StringBundler query = null;
2939 String sql = null;
2940
2941 if (orderByComparator != null) {
2942 query = new StringBundler(2 +
2943 (orderByComparator.getOrderByFields().length * 3));
2944
2945 query.append(_SQL_SELECT_MBMAILINGLIST);
2946
2947 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2948 orderByComparator);
2949
2950 sql = query.toString();
2951 }
2952 else {
2953 sql = _SQL_SELECT_MBMAILINGLIST;
2954
2955 if (pagination) {
2956 sql = sql.concat(MBMailingListModelImpl.ORDER_BY_JPQL);
2957 }
2958 }
2959
2960 Session session = null;
2961
2962 try {
2963 session = openSession();
2964
2965 Query q = session.createQuery(sql);
2966
2967 if (!pagination) {
2968 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
2969 start, end, false);
2970
2971 Collections.sort(list);
2972
2973 list = Collections.unmodifiableList(list);
2974 }
2975 else {
2976 list = (List<MBMailingList>)QueryUtil.list(q, getDialect(),
2977 start, end);
2978 }
2979
2980 cacheResult(list);
2981
2982 finderCache.putResult(finderPath, finderArgs, list);
2983 }
2984 catch (Exception e) {
2985 finderCache.removeResult(finderPath, finderArgs);
2986
2987 throw processException(e);
2988 }
2989 finally {
2990 closeSession(session);
2991 }
2992 }
2993
2994 return list;
2995 }
2996
2997
3001 @Override
3002 public void removeAll() {
3003 for (MBMailingList mbMailingList : findAll()) {
3004 remove(mbMailingList);
3005 }
3006 }
3007
3008
3013 @Override
3014 public int countAll() {
3015 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
3016 FINDER_ARGS_EMPTY, this);
3017
3018 if (count == null) {
3019 Session session = null;
3020
3021 try {
3022 session = openSession();
3023
3024 Query q = session.createQuery(_SQL_COUNT_MBMAILINGLIST);
3025
3026 count = (Long)q.uniqueResult();
3027
3028 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
3029 count);
3030 }
3031 catch (Exception e) {
3032 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
3033 FINDER_ARGS_EMPTY);
3034
3035 throw processException(e);
3036 }
3037 finally {
3038 closeSession(session);
3039 }
3040 }
3041
3042 return count.intValue();
3043 }
3044
3045 @Override
3046 public Set<String> getBadColumnNames() {
3047 return _badColumnNames;
3048 }
3049
3050 @Override
3051 protected Map<String, Integer> getTableColumnsMap() {
3052 return MBMailingListModelImpl.TABLE_COLUMNS_MAP;
3053 }
3054
3055
3058 public void afterPropertiesSet() {
3059 }
3060
3061 public void destroy() {
3062 entityCache.removeCache(MBMailingListImpl.class.getName());
3063 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
3064 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3065 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3066 }
3067
3068 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
3069 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
3070 private static final String _SQL_SELECT_MBMAILINGLIST = "SELECT mbMailingList FROM MBMailingList mbMailingList";
3071 private static final String _SQL_SELECT_MBMAILINGLIST_WHERE_PKS_IN = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE mailingListId IN (";
3072 private static final String _SQL_SELECT_MBMAILINGLIST_WHERE = "SELECT mbMailingList FROM MBMailingList mbMailingList WHERE ";
3073 private static final String _SQL_COUNT_MBMAILINGLIST = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList";
3074 private static final String _SQL_COUNT_MBMAILINGLIST_WHERE = "SELECT COUNT(mbMailingList) FROM MBMailingList mbMailingList WHERE ";
3075 private static final String _ORDER_BY_ENTITY_ALIAS = "mbMailingList.";
3076 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMailingList exists with the primary key ";
3077 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMailingList exists with the key {";
3078 private static final Log _log = LogFactoryUtil.getLog(MBMailingListPersistenceImpl.class);
3079 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3080 "uuid", "active"
3081 });
3082 private static final MBMailingList _nullMBMailingList = new MBMailingListImpl() {
3083 @Override
3084 public Object clone() {
3085 return this;
3086 }
3087
3088 @Override
3089 public CacheModel<MBMailingList> toCacheModel() {
3090 return _nullMBMailingListCacheModel;
3091 }
3092 };
3093
3094 private static final CacheModel<MBMailingList> _nullMBMailingListCacheModel = new CacheModel<MBMailingList>() {
3095 @Override
3096 public MBMailingList toEntityModel() {
3097 return _nullMBMailingList;
3098 }
3099 };
3100 }