001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.exception.NoSuchUserNotificationDeliveryException;
030 import com.liferay.portal.kernel.log.Log;
031 import com.liferay.portal.kernel.log.LogFactoryUtil;
032 import com.liferay.portal.kernel.model.CacheModel;
033 import com.liferay.portal.kernel.model.MVCCModel;
034 import com.liferay.portal.kernel.model.UserNotificationDelivery;
035 import com.liferay.portal.kernel.service.persistence.CompanyProvider;
036 import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
037 import com.liferay.portal.kernel.service.persistence.UserNotificationDeliveryPersistence;
038 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.StringBundler;
041 import com.liferay.portal.kernel.util.StringPool;
042 import com.liferay.portal.model.impl.UserNotificationDeliveryImpl;
043 import com.liferay.portal.model.impl.UserNotificationDeliveryModelImpl;
044
045 import java.io.Serializable;
046
047 import java.util.Collections;
048 import java.util.HashMap;
049 import java.util.HashSet;
050 import java.util.Iterator;
051 import java.util.List;
052 import java.util.Map;
053 import java.util.Objects;
054 import java.util.Set;
055
056
068 @ProviderType
069 public class UserNotificationDeliveryPersistenceImpl extends BasePersistenceImpl<UserNotificationDelivery>
070 implements UserNotificationDeliveryPersistence {
071
076 public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationDeliveryImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List1";
079 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List2";
081 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
082 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
083 UserNotificationDeliveryImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
086 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
087 UserNotificationDeliveryImpl.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
089 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
090 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
092 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
093 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
094 UserNotificationDeliveryImpl.class,
095 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
096 new String[] {
097 Long.class.getName(),
098
099 Integer.class.getName(), Integer.class.getName(),
100 OrderByComparator.class.getName()
101 });
102 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
103 new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
104 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
105 UserNotificationDeliveryImpl.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
107 new String[] { Long.class.getName() },
108 UserNotificationDeliveryModelImpl.USERID_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
110 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
112 new String[] { Long.class.getName() });
113
114
120 @Override
121 public List<UserNotificationDelivery> findByUserId(long userId) {
122 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
123 }
124
125
137 @Override
138 public List<UserNotificationDelivery> findByUserId(long userId, int start,
139 int end) {
140 return findByUserId(userId, start, end, null);
141 }
142
143
156 @Override
157 public List<UserNotificationDelivery> findByUserId(long userId, int start,
158 int end, OrderByComparator<UserNotificationDelivery> orderByComparator) {
159 return findByUserId(userId, start, end, orderByComparator, true);
160 }
161
162
176 @Override
177 public List<UserNotificationDelivery> findByUserId(long userId, int start,
178 int end, OrderByComparator<UserNotificationDelivery> orderByComparator,
179 boolean retrieveFromCache) {
180 boolean pagination = true;
181 FinderPath finderPath = null;
182 Object[] finderArgs = null;
183
184 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
185 (orderByComparator == null)) {
186 pagination = false;
187 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
188 finderArgs = new Object[] { userId };
189 }
190 else {
191 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
192 finderArgs = new Object[] { userId, start, end, orderByComparator };
193 }
194
195 List<UserNotificationDelivery> list = null;
196
197 if (retrieveFromCache) {
198 list = (List<UserNotificationDelivery>)finderCache.getResult(finderPath,
199 finderArgs, this);
200
201 if ((list != null) && !list.isEmpty()) {
202 for (UserNotificationDelivery userNotificationDelivery : list) {
203 if ((userId != userNotificationDelivery.getUserId())) {
204 list = null;
205
206 break;
207 }
208 }
209 }
210 }
211
212 if (list == null) {
213 StringBundler query = null;
214
215 if (orderByComparator != null) {
216 query = new StringBundler(3 +
217 (orderByComparator.getOrderByFields().length * 2));
218 }
219 else {
220 query = new StringBundler(3);
221 }
222
223 query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE);
224
225 query.append(_FINDER_COLUMN_USERID_USERID_2);
226
227 if (orderByComparator != null) {
228 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
229 orderByComparator);
230 }
231 else
232 if (pagination) {
233 query.append(UserNotificationDeliveryModelImpl.ORDER_BY_JPQL);
234 }
235
236 String sql = query.toString();
237
238 Session session = null;
239
240 try {
241 session = openSession();
242
243 Query q = session.createQuery(sql);
244
245 QueryPos qPos = QueryPos.getInstance(q);
246
247 qPos.add(userId);
248
249 if (!pagination) {
250 list = (List<UserNotificationDelivery>)QueryUtil.list(q,
251 getDialect(), start, end, false);
252
253 Collections.sort(list);
254
255 list = Collections.unmodifiableList(list);
256 }
257 else {
258 list = (List<UserNotificationDelivery>)QueryUtil.list(q,
259 getDialect(), start, end);
260 }
261
262 cacheResult(list);
263
264 finderCache.putResult(finderPath, finderArgs, list);
265 }
266 catch (Exception e) {
267 finderCache.removeResult(finderPath, finderArgs);
268
269 throw processException(e);
270 }
271 finally {
272 closeSession(session);
273 }
274 }
275
276 return list;
277 }
278
279
287 @Override
288 public UserNotificationDelivery findByUserId_First(long userId,
289 OrderByComparator<UserNotificationDelivery> orderByComparator)
290 throws NoSuchUserNotificationDeliveryException {
291 UserNotificationDelivery userNotificationDelivery = fetchByUserId_First(userId,
292 orderByComparator);
293
294 if (userNotificationDelivery != null) {
295 return userNotificationDelivery;
296 }
297
298 StringBundler msg = new StringBundler(4);
299
300 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
301
302 msg.append("userId=");
303 msg.append(userId);
304
305 msg.append(StringPool.CLOSE_CURLY_BRACE);
306
307 throw new NoSuchUserNotificationDeliveryException(msg.toString());
308 }
309
310
317 @Override
318 public UserNotificationDelivery fetchByUserId_First(long userId,
319 OrderByComparator<UserNotificationDelivery> orderByComparator) {
320 List<UserNotificationDelivery> list = findByUserId(userId, 0, 1,
321 orderByComparator);
322
323 if (!list.isEmpty()) {
324 return list.get(0);
325 }
326
327 return null;
328 }
329
330
338 @Override
339 public UserNotificationDelivery findByUserId_Last(long userId,
340 OrderByComparator<UserNotificationDelivery> orderByComparator)
341 throws NoSuchUserNotificationDeliveryException {
342 UserNotificationDelivery userNotificationDelivery = fetchByUserId_Last(userId,
343 orderByComparator);
344
345 if (userNotificationDelivery != null) {
346 return userNotificationDelivery;
347 }
348
349 StringBundler msg = new StringBundler(4);
350
351 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
352
353 msg.append("userId=");
354 msg.append(userId);
355
356 msg.append(StringPool.CLOSE_CURLY_BRACE);
357
358 throw new NoSuchUserNotificationDeliveryException(msg.toString());
359 }
360
361
368 @Override
369 public UserNotificationDelivery fetchByUserId_Last(long userId,
370 OrderByComparator<UserNotificationDelivery> orderByComparator) {
371 int count = countByUserId(userId);
372
373 if (count == 0) {
374 return null;
375 }
376
377 List<UserNotificationDelivery> list = findByUserId(userId, count - 1,
378 count, orderByComparator);
379
380 if (!list.isEmpty()) {
381 return list.get(0);
382 }
383
384 return null;
385 }
386
387
396 @Override
397 public UserNotificationDelivery[] findByUserId_PrevAndNext(
398 long userNotificationDeliveryId, long userId,
399 OrderByComparator<UserNotificationDelivery> orderByComparator)
400 throws NoSuchUserNotificationDeliveryException {
401 UserNotificationDelivery userNotificationDelivery = findByPrimaryKey(userNotificationDeliveryId);
402
403 Session session = null;
404
405 try {
406 session = openSession();
407
408 UserNotificationDelivery[] array = new UserNotificationDeliveryImpl[3];
409
410 array[0] = getByUserId_PrevAndNext(session,
411 userNotificationDelivery, userId, orderByComparator, true);
412
413 array[1] = userNotificationDelivery;
414
415 array[2] = getByUserId_PrevAndNext(session,
416 userNotificationDelivery, userId, orderByComparator, false);
417
418 return array;
419 }
420 catch (Exception e) {
421 throw processException(e);
422 }
423 finally {
424 closeSession(session);
425 }
426 }
427
428 protected UserNotificationDelivery getByUserId_PrevAndNext(
429 Session session, UserNotificationDelivery userNotificationDelivery,
430 long userId,
431 OrderByComparator<UserNotificationDelivery> orderByComparator,
432 boolean previous) {
433 StringBundler query = null;
434
435 if (orderByComparator != null) {
436 query = new StringBundler(4 +
437 (orderByComparator.getOrderByConditionFields().length * 3) +
438 (orderByComparator.getOrderByFields().length * 3));
439 }
440 else {
441 query = new StringBundler(3);
442 }
443
444 query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE);
445
446 query.append(_FINDER_COLUMN_USERID_USERID_2);
447
448 if (orderByComparator != null) {
449 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
450
451 if (orderByConditionFields.length > 0) {
452 query.append(WHERE_AND);
453 }
454
455 for (int i = 0; i < orderByConditionFields.length; i++) {
456 query.append(_ORDER_BY_ENTITY_ALIAS);
457 query.append(orderByConditionFields[i]);
458
459 if ((i + 1) < orderByConditionFields.length) {
460 if (orderByComparator.isAscending() ^ previous) {
461 query.append(WHERE_GREATER_THAN_HAS_NEXT);
462 }
463 else {
464 query.append(WHERE_LESSER_THAN_HAS_NEXT);
465 }
466 }
467 else {
468 if (orderByComparator.isAscending() ^ previous) {
469 query.append(WHERE_GREATER_THAN);
470 }
471 else {
472 query.append(WHERE_LESSER_THAN);
473 }
474 }
475 }
476
477 query.append(ORDER_BY_CLAUSE);
478
479 String[] orderByFields = orderByComparator.getOrderByFields();
480
481 for (int i = 0; i < orderByFields.length; i++) {
482 query.append(_ORDER_BY_ENTITY_ALIAS);
483 query.append(orderByFields[i]);
484
485 if ((i + 1) < orderByFields.length) {
486 if (orderByComparator.isAscending() ^ previous) {
487 query.append(ORDER_BY_ASC_HAS_NEXT);
488 }
489 else {
490 query.append(ORDER_BY_DESC_HAS_NEXT);
491 }
492 }
493 else {
494 if (orderByComparator.isAscending() ^ previous) {
495 query.append(ORDER_BY_ASC);
496 }
497 else {
498 query.append(ORDER_BY_DESC);
499 }
500 }
501 }
502 }
503 else {
504 query.append(UserNotificationDeliveryModelImpl.ORDER_BY_JPQL);
505 }
506
507 String sql = query.toString();
508
509 Query q = session.createQuery(sql);
510
511 q.setFirstResult(0);
512 q.setMaxResults(2);
513
514 QueryPos qPos = QueryPos.getInstance(q);
515
516 qPos.add(userId);
517
518 if (orderByComparator != null) {
519 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationDelivery);
520
521 for (Object value : values) {
522 qPos.add(value);
523 }
524 }
525
526 List<UserNotificationDelivery> list = q.list();
527
528 if (list.size() == 2) {
529 return list.get(1);
530 }
531 else {
532 return null;
533 }
534 }
535
536
541 @Override
542 public void removeByUserId(long userId) {
543 for (UserNotificationDelivery userNotificationDelivery : findByUserId(
544 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
545 remove(userNotificationDelivery);
546 }
547 }
548
549
555 @Override
556 public int countByUserId(long userId) {
557 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
558
559 Object[] finderArgs = new Object[] { userId };
560
561 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
562
563 if (count == null) {
564 StringBundler query = new StringBundler(2);
565
566 query.append(_SQL_COUNT_USERNOTIFICATIONDELIVERY_WHERE);
567
568 query.append(_FINDER_COLUMN_USERID_USERID_2);
569
570 String sql = query.toString();
571
572 Session session = null;
573
574 try {
575 session = openSession();
576
577 Query q = session.createQuery(sql);
578
579 QueryPos qPos = QueryPos.getInstance(q);
580
581 qPos.add(userId);
582
583 count = (Long)q.uniqueResult();
584
585 finderCache.putResult(finderPath, finderArgs, count);
586 }
587 catch (Exception e) {
588 finderCache.removeResult(finderPath, finderArgs);
589
590 throw processException(e);
591 }
592 finally {
593 closeSession(session);
594 }
595 }
596
597 return count.intValue();
598 }
599
600 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationDelivery.userId = ?";
601 public static final FinderPath FINDER_PATH_FETCH_BY_U_P_C_N_D = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
602 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED,
603 UserNotificationDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
604 "fetchByU_P_C_N_D",
605 new String[] {
606 Long.class.getName(), String.class.getName(),
607 Long.class.getName(), Integer.class.getName(),
608 Integer.class.getName()
609 },
610 UserNotificationDeliveryModelImpl.USERID_COLUMN_BITMASK |
611 UserNotificationDeliveryModelImpl.PORTLETID_COLUMN_BITMASK |
612 UserNotificationDeliveryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
613 UserNotificationDeliveryModelImpl.NOTIFICATIONTYPE_COLUMN_BITMASK |
614 UserNotificationDeliveryModelImpl.DELIVERYTYPE_COLUMN_BITMASK);
615 public static final FinderPath FINDER_PATH_COUNT_BY_U_P_C_N_D = new FinderPath(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
616 UserNotificationDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
617 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_P_C_N_D",
618 new String[] {
619 Long.class.getName(), String.class.getName(),
620 Long.class.getName(), Integer.class.getName(),
621 Integer.class.getName()
622 });
623
624
635 @Override
636 public UserNotificationDelivery findByU_P_C_N_D(long userId,
637 String portletId, long classNameId, int notificationType,
638 int deliveryType) throws NoSuchUserNotificationDeliveryException {
639 UserNotificationDelivery userNotificationDelivery = fetchByU_P_C_N_D(userId,
640 portletId, classNameId, notificationType, deliveryType);
641
642 if (userNotificationDelivery == null) {
643 StringBundler msg = new StringBundler(12);
644
645 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646
647 msg.append("userId=");
648 msg.append(userId);
649
650 msg.append(", portletId=");
651 msg.append(portletId);
652
653 msg.append(", classNameId=");
654 msg.append(classNameId);
655
656 msg.append(", notificationType=");
657 msg.append(notificationType);
658
659 msg.append(", deliveryType=");
660 msg.append(deliveryType);
661
662 msg.append(StringPool.CLOSE_CURLY_BRACE);
663
664 if (_log.isDebugEnabled()) {
665 _log.debug(msg.toString());
666 }
667
668 throw new NoSuchUserNotificationDeliveryException(msg.toString());
669 }
670
671 return userNotificationDelivery;
672 }
673
674
684 @Override
685 public UserNotificationDelivery fetchByU_P_C_N_D(long userId,
686 String portletId, long classNameId, int notificationType,
687 int deliveryType) {
688 return fetchByU_P_C_N_D(userId, portletId, classNameId,
689 notificationType, deliveryType, true);
690 }
691
692
703 @Override
704 public UserNotificationDelivery fetchByU_P_C_N_D(long userId,
705 String portletId, long classNameId, int notificationType,
706 int deliveryType, boolean retrieveFromCache) {
707 Object[] finderArgs = new Object[] {
708 userId, portletId, classNameId, notificationType, deliveryType
709 };
710
711 Object result = null;
712
713 if (retrieveFromCache) {
714 result = finderCache.getResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
715 finderArgs, this);
716 }
717
718 if (result instanceof UserNotificationDelivery) {
719 UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)result;
720
721 if ((userId != userNotificationDelivery.getUserId()) ||
722 !Objects.equals(portletId,
723 userNotificationDelivery.getPortletId()) ||
724 (classNameId != userNotificationDelivery.getClassNameId()) ||
725 (notificationType != userNotificationDelivery.getNotificationType()) ||
726 (deliveryType != userNotificationDelivery.getDeliveryType())) {
727 result = null;
728 }
729 }
730
731 if (result == null) {
732 StringBundler query = new StringBundler(7);
733
734 query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE);
735
736 query.append(_FINDER_COLUMN_U_P_C_N_D_USERID_2);
737
738 boolean bindPortletId = false;
739
740 if (portletId == null) {
741 query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_1);
742 }
743 else if (portletId.equals(StringPool.BLANK)) {
744 query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_3);
745 }
746 else {
747 bindPortletId = true;
748
749 query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_2);
750 }
751
752 query.append(_FINDER_COLUMN_U_P_C_N_D_CLASSNAMEID_2);
753
754 query.append(_FINDER_COLUMN_U_P_C_N_D_NOTIFICATIONTYPE_2);
755
756 query.append(_FINDER_COLUMN_U_P_C_N_D_DELIVERYTYPE_2);
757
758 String sql = query.toString();
759
760 Session session = null;
761
762 try {
763 session = openSession();
764
765 Query q = session.createQuery(sql);
766
767 QueryPos qPos = QueryPos.getInstance(q);
768
769 qPos.add(userId);
770
771 if (bindPortletId) {
772 qPos.add(portletId);
773 }
774
775 qPos.add(classNameId);
776
777 qPos.add(notificationType);
778
779 qPos.add(deliveryType);
780
781 List<UserNotificationDelivery> list = q.list();
782
783 if (list.isEmpty()) {
784 finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
785 finderArgs, list);
786 }
787 else {
788 UserNotificationDelivery userNotificationDelivery = list.get(0);
789
790 result = userNotificationDelivery;
791
792 cacheResult(userNotificationDelivery);
793
794 if ((userNotificationDelivery.getUserId() != userId) ||
795 (userNotificationDelivery.getPortletId() == null) ||
796 !userNotificationDelivery.getPortletId()
797 .equals(portletId) ||
798 (userNotificationDelivery.getClassNameId() != classNameId) ||
799 (userNotificationDelivery.getNotificationType() != notificationType) ||
800 (userNotificationDelivery.getDeliveryType() != deliveryType)) {
801 finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
802 finderArgs, userNotificationDelivery);
803 }
804 }
805 }
806 catch (Exception e) {
807 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
808 finderArgs);
809
810 throw processException(e);
811 }
812 finally {
813 closeSession(session);
814 }
815 }
816
817 if (result instanceof List<?>) {
818 return null;
819 }
820 else {
821 return (UserNotificationDelivery)result;
822 }
823 }
824
825
835 @Override
836 public UserNotificationDelivery removeByU_P_C_N_D(long userId,
837 String portletId, long classNameId, int notificationType,
838 int deliveryType) throws NoSuchUserNotificationDeliveryException {
839 UserNotificationDelivery userNotificationDelivery = findByU_P_C_N_D(userId,
840 portletId, classNameId, notificationType, deliveryType);
841
842 return remove(userNotificationDelivery);
843 }
844
845
855 @Override
856 public int countByU_P_C_N_D(long userId, String portletId,
857 long classNameId, int notificationType, int deliveryType) {
858 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_P_C_N_D;
859
860 Object[] finderArgs = new Object[] {
861 userId, portletId, classNameId, notificationType, deliveryType
862 };
863
864 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
865
866 if (count == null) {
867 StringBundler query = new StringBundler(6);
868
869 query.append(_SQL_COUNT_USERNOTIFICATIONDELIVERY_WHERE);
870
871 query.append(_FINDER_COLUMN_U_P_C_N_D_USERID_2);
872
873 boolean bindPortletId = false;
874
875 if (portletId == null) {
876 query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_1);
877 }
878 else if (portletId.equals(StringPool.BLANK)) {
879 query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_3);
880 }
881 else {
882 bindPortletId = true;
883
884 query.append(_FINDER_COLUMN_U_P_C_N_D_PORTLETID_2);
885 }
886
887 query.append(_FINDER_COLUMN_U_P_C_N_D_CLASSNAMEID_2);
888
889 query.append(_FINDER_COLUMN_U_P_C_N_D_NOTIFICATIONTYPE_2);
890
891 query.append(_FINDER_COLUMN_U_P_C_N_D_DELIVERYTYPE_2);
892
893 String sql = query.toString();
894
895 Session session = null;
896
897 try {
898 session = openSession();
899
900 Query q = session.createQuery(sql);
901
902 QueryPos qPos = QueryPos.getInstance(q);
903
904 qPos.add(userId);
905
906 if (bindPortletId) {
907 qPos.add(portletId);
908 }
909
910 qPos.add(classNameId);
911
912 qPos.add(notificationType);
913
914 qPos.add(deliveryType);
915
916 count = (Long)q.uniqueResult();
917
918 finderCache.putResult(finderPath, finderArgs, count);
919 }
920 catch (Exception e) {
921 finderCache.removeResult(finderPath, finderArgs);
922
923 throw processException(e);
924 }
925 finally {
926 closeSession(session);
927 }
928 }
929
930 return count.intValue();
931 }
932
933 private static final String _FINDER_COLUMN_U_P_C_N_D_USERID_2 = "userNotificationDelivery.userId = ? AND ";
934 private static final String _FINDER_COLUMN_U_P_C_N_D_PORTLETID_1 = "userNotificationDelivery.portletId IS NULL AND ";
935 private static final String _FINDER_COLUMN_U_P_C_N_D_PORTLETID_2 = "userNotificationDelivery.portletId = ? AND ";
936 private static final String _FINDER_COLUMN_U_P_C_N_D_PORTLETID_3 = "(userNotificationDelivery.portletId IS NULL OR userNotificationDelivery.portletId = '') AND ";
937 private static final String _FINDER_COLUMN_U_P_C_N_D_CLASSNAMEID_2 = "userNotificationDelivery.classNameId = ? AND ";
938 private static final String _FINDER_COLUMN_U_P_C_N_D_NOTIFICATIONTYPE_2 = "userNotificationDelivery.notificationType = ? AND ";
939 private static final String _FINDER_COLUMN_U_P_C_N_D_DELIVERYTYPE_2 = "userNotificationDelivery.deliveryType = ?";
940
941 public UserNotificationDeliveryPersistenceImpl() {
942 setModelClass(UserNotificationDelivery.class);
943 }
944
945
950 @Override
951 public void cacheResult(UserNotificationDelivery userNotificationDelivery) {
952 entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
953 UserNotificationDeliveryImpl.class,
954 userNotificationDelivery.getPrimaryKey(), userNotificationDelivery);
955
956 finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D,
957 new Object[] {
958 userNotificationDelivery.getUserId(),
959 userNotificationDelivery.getPortletId(),
960 userNotificationDelivery.getClassNameId(),
961 userNotificationDelivery.getNotificationType(),
962 userNotificationDelivery.getDeliveryType()
963 }, userNotificationDelivery);
964
965 userNotificationDelivery.resetOriginalValues();
966 }
967
968
973 @Override
974 public void cacheResult(
975 List<UserNotificationDelivery> userNotificationDeliveries) {
976 for (UserNotificationDelivery userNotificationDelivery : userNotificationDeliveries) {
977 if (entityCache.getResult(
978 UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
979 UserNotificationDeliveryImpl.class,
980 userNotificationDelivery.getPrimaryKey()) == null) {
981 cacheResult(userNotificationDelivery);
982 }
983 else {
984 userNotificationDelivery.resetOriginalValues();
985 }
986 }
987 }
988
989
996 @Override
997 public void clearCache() {
998 entityCache.clearCache(UserNotificationDeliveryImpl.class);
999
1000 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1001 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1002 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1003 }
1004
1005
1012 @Override
1013 public void clearCache(UserNotificationDelivery userNotificationDelivery) {
1014 entityCache.removeResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1015 UserNotificationDeliveryImpl.class,
1016 userNotificationDelivery.getPrimaryKey());
1017
1018 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1019 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1020
1021 clearUniqueFindersCache((UserNotificationDeliveryModelImpl)userNotificationDelivery);
1022 }
1023
1024 @Override
1025 public void clearCache(
1026 List<UserNotificationDelivery> userNotificationDeliveries) {
1027 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1028 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1029
1030 for (UserNotificationDelivery userNotificationDelivery : userNotificationDeliveries) {
1031 entityCache.removeResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1032 UserNotificationDeliveryImpl.class,
1033 userNotificationDelivery.getPrimaryKey());
1034
1035 clearUniqueFindersCache((UserNotificationDeliveryModelImpl)userNotificationDelivery);
1036 }
1037 }
1038
1039 protected void cacheUniqueFindersCache(
1040 UserNotificationDeliveryModelImpl userNotificationDeliveryModelImpl,
1041 boolean isNew) {
1042 if (isNew) {
1043 Object[] args = new Object[] {
1044 userNotificationDeliveryModelImpl.getUserId(),
1045 userNotificationDeliveryModelImpl.getPortletId(),
1046 userNotificationDeliveryModelImpl.getClassNameId(),
1047 userNotificationDeliveryModelImpl.getNotificationType(),
1048 userNotificationDeliveryModelImpl.getDeliveryType()
1049 };
1050
1051 finderCache.putResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args,
1052 Long.valueOf(1));
1053 finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args,
1054 userNotificationDeliveryModelImpl);
1055 }
1056 else {
1057 if ((userNotificationDeliveryModelImpl.getColumnBitmask() &
1058 FINDER_PATH_FETCH_BY_U_P_C_N_D.getColumnBitmask()) != 0) {
1059 Object[] args = new Object[] {
1060 userNotificationDeliveryModelImpl.getUserId(),
1061 userNotificationDeliveryModelImpl.getPortletId(),
1062 userNotificationDeliveryModelImpl.getClassNameId(),
1063 userNotificationDeliveryModelImpl.getNotificationType(),
1064 userNotificationDeliveryModelImpl.getDeliveryType()
1065 };
1066
1067 finderCache.putResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args,
1068 Long.valueOf(1));
1069 finderCache.putResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args,
1070 userNotificationDeliveryModelImpl);
1071 }
1072 }
1073 }
1074
1075 protected void clearUniqueFindersCache(
1076 UserNotificationDeliveryModelImpl userNotificationDeliveryModelImpl) {
1077 Object[] args = new Object[] {
1078 userNotificationDeliveryModelImpl.getUserId(),
1079 userNotificationDeliveryModelImpl.getPortletId(),
1080 userNotificationDeliveryModelImpl.getClassNameId(),
1081 userNotificationDeliveryModelImpl.getNotificationType(),
1082 userNotificationDeliveryModelImpl.getDeliveryType()
1083 };
1084
1085 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args);
1086 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args);
1087
1088 if ((userNotificationDeliveryModelImpl.getColumnBitmask() &
1089 FINDER_PATH_FETCH_BY_U_P_C_N_D.getColumnBitmask()) != 0) {
1090 args = new Object[] {
1091 userNotificationDeliveryModelImpl.getOriginalUserId(),
1092 userNotificationDeliveryModelImpl.getOriginalPortletId(),
1093 userNotificationDeliveryModelImpl.getOriginalClassNameId(),
1094 userNotificationDeliveryModelImpl.getOriginalNotificationType(),
1095 userNotificationDeliveryModelImpl.getOriginalDeliveryType()
1096 };
1097
1098 finderCache.removeResult(FINDER_PATH_COUNT_BY_U_P_C_N_D, args);
1099 finderCache.removeResult(FINDER_PATH_FETCH_BY_U_P_C_N_D, args);
1100 }
1101 }
1102
1103
1109 @Override
1110 public UserNotificationDelivery create(long userNotificationDeliveryId) {
1111 UserNotificationDelivery userNotificationDelivery = new UserNotificationDeliveryImpl();
1112
1113 userNotificationDelivery.setNew(true);
1114 userNotificationDelivery.setPrimaryKey(userNotificationDeliveryId);
1115
1116 userNotificationDelivery.setCompanyId(companyProvider.getCompanyId());
1117
1118 return userNotificationDelivery;
1119 }
1120
1121
1128 @Override
1129 public UserNotificationDelivery remove(long userNotificationDeliveryId)
1130 throws NoSuchUserNotificationDeliveryException {
1131 return remove((Serializable)userNotificationDeliveryId);
1132 }
1133
1134
1141 @Override
1142 public UserNotificationDelivery remove(Serializable primaryKey)
1143 throws NoSuchUserNotificationDeliveryException {
1144 Session session = null;
1145
1146 try {
1147 session = openSession();
1148
1149 UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)session.get(UserNotificationDeliveryImpl.class,
1150 primaryKey);
1151
1152 if (userNotificationDelivery == null) {
1153 if (_log.isDebugEnabled()) {
1154 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1155 }
1156
1157 throw new NoSuchUserNotificationDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1158 primaryKey);
1159 }
1160
1161 return remove(userNotificationDelivery);
1162 }
1163 catch (NoSuchUserNotificationDeliveryException nsee) {
1164 throw nsee;
1165 }
1166 catch (Exception e) {
1167 throw processException(e);
1168 }
1169 finally {
1170 closeSession(session);
1171 }
1172 }
1173
1174 @Override
1175 protected UserNotificationDelivery removeImpl(
1176 UserNotificationDelivery userNotificationDelivery) {
1177 userNotificationDelivery = toUnwrappedModel(userNotificationDelivery);
1178
1179 Session session = null;
1180
1181 try {
1182 session = openSession();
1183
1184 if (!session.contains(userNotificationDelivery)) {
1185 userNotificationDelivery = (UserNotificationDelivery)session.get(UserNotificationDeliveryImpl.class,
1186 userNotificationDelivery.getPrimaryKeyObj());
1187 }
1188
1189 if (userNotificationDelivery != null) {
1190 session.delete(userNotificationDelivery);
1191 }
1192 }
1193 catch (Exception e) {
1194 throw processException(e);
1195 }
1196 finally {
1197 closeSession(session);
1198 }
1199
1200 if (userNotificationDelivery != null) {
1201 clearCache(userNotificationDelivery);
1202 }
1203
1204 return userNotificationDelivery;
1205 }
1206
1207 @Override
1208 public UserNotificationDelivery updateImpl(
1209 UserNotificationDelivery userNotificationDelivery) {
1210 userNotificationDelivery = toUnwrappedModel(userNotificationDelivery);
1211
1212 boolean isNew = userNotificationDelivery.isNew();
1213
1214 UserNotificationDeliveryModelImpl userNotificationDeliveryModelImpl = (UserNotificationDeliveryModelImpl)userNotificationDelivery;
1215
1216 Session session = null;
1217
1218 try {
1219 session = openSession();
1220
1221 if (userNotificationDelivery.isNew()) {
1222 session.save(userNotificationDelivery);
1223
1224 userNotificationDelivery.setNew(false);
1225 }
1226 else {
1227 userNotificationDelivery = (UserNotificationDelivery)session.merge(userNotificationDelivery);
1228 }
1229 }
1230 catch (Exception e) {
1231 throw processException(e);
1232 }
1233 finally {
1234 closeSession(session);
1235 }
1236
1237 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1238
1239 if (isNew || !UserNotificationDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
1240 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1241 }
1242
1243 else {
1244 if ((userNotificationDeliveryModelImpl.getColumnBitmask() &
1245 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1246 Object[] args = new Object[] {
1247 userNotificationDeliveryModelImpl.getOriginalUserId()
1248 };
1249
1250 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1251 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1252 args);
1253
1254 args = new Object[] {
1255 userNotificationDeliveryModelImpl.getUserId()
1256 };
1257
1258 finderCache.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1259 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1260 args);
1261 }
1262 }
1263
1264 entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1265 UserNotificationDeliveryImpl.class,
1266 userNotificationDelivery.getPrimaryKey(), userNotificationDelivery,
1267 false);
1268
1269 clearUniqueFindersCache(userNotificationDeliveryModelImpl);
1270 cacheUniqueFindersCache(userNotificationDeliveryModelImpl, isNew);
1271
1272 userNotificationDelivery.resetOriginalValues();
1273
1274 return userNotificationDelivery;
1275 }
1276
1277 protected UserNotificationDelivery toUnwrappedModel(
1278 UserNotificationDelivery userNotificationDelivery) {
1279 if (userNotificationDelivery instanceof UserNotificationDeliveryImpl) {
1280 return userNotificationDelivery;
1281 }
1282
1283 UserNotificationDeliveryImpl userNotificationDeliveryImpl = new UserNotificationDeliveryImpl();
1284
1285 userNotificationDeliveryImpl.setNew(userNotificationDelivery.isNew());
1286 userNotificationDeliveryImpl.setPrimaryKey(userNotificationDelivery.getPrimaryKey());
1287
1288 userNotificationDeliveryImpl.setMvccVersion(userNotificationDelivery.getMvccVersion());
1289 userNotificationDeliveryImpl.setUserNotificationDeliveryId(userNotificationDelivery.getUserNotificationDeliveryId());
1290 userNotificationDeliveryImpl.setCompanyId(userNotificationDelivery.getCompanyId());
1291 userNotificationDeliveryImpl.setUserId(userNotificationDelivery.getUserId());
1292 userNotificationDeliveryImpl.setPortletId(userNotificationDelivery.getPortletId());
1293 userNotificationDeliveryImpl.setClassNameId(userNotificationDelivery.getClassNameId());
1294 userNotificationDeliveryImpl.setNotificationType(userNotificationDelivery.getNotificationType());
1295 userNotificationDeliveryImpl.setDeliveryType(userNotificationDelivery.getDeliveryType());
1296 userNotificationDeliveryImpl.setDeliver(userNotificationDelivery.isDeliver());
1297
1298 return userNotificationDeliveryImpl;
1299 }
1300
1301
1308 @Override
1309 public UserNotificationDelivery findByPrimaryKey(Serializable primaryKey)
1310 throws NoSuchUserNotificationDeliveryException {
1311 UserNotificationDelivery userNotificationDelivery = fetchByPrimaryKey(primaryKey);
1312
1313 if (userNotificationDelivery == null) {
1314 if (_log.isDebugEnabled()) {
1315 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1316 }
1317
1318 throw new NoSuchUserNotificationDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1319 primaryKey);
1320 }
1321
1322 return userNotificationDelivery;
1323 }
1324
1325
1332 @Override
1333 public UserNotificationDelivery findByPrimaryKey(
1334 long userNotificationDeliveryId)
1335 throws NoSuchUserNotificationDeliveryException {
1336 return findByPrimaryKey((Serializable)userNotificationDeliveryId);
1337 }
1338
1339
1345 @Override
1346 public UserNotificationDelivery fetchByPrimaryKey(Serializable primaryKey) {
1347 UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)entityCache.getResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1348 UserNotificationDeliveryImpl.class, primaryKey);
1349
1350 if (userNotificationDelivery == _nullUserNotificationDelivery) {
1351 return null;
1352 }
1353
1354 if (userNotificationDelivery == null) {
1355 Session session = null;
1356
1357 try {
1358 session = openSession();
1359
1360 userNotificationDelivery = (UserNotificationDelivery)session.get(UserNotificationDeliveryImpl.class,
1361 primaryKey);
1362
1363 if (userNotificationDelivery != null) {
1364 cacheResult(userNotificationDelivery);
1365 }
1366 else {
1367 entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1368 UserNotificationDeliveryImpl.class, primaryKey,
1369 _nullUserNotificationDelivery);
1370 }
1371 }
1372 catch (Exception e) {
1373 entityCache.removeResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1374 UserNotificationDeliveryImpl.class, primaryKey);
1375
1376 throw processException(e);
1377 }
1378 finally {
1379 closeSession(session);
1380 }
1381 }
1382
1383 return userNotificationDelivery;
1384 }
1385
1386
1392 @Override
1393 public UserNotificationDelivery fetchByPrimaryKey(
1394 long userNotificationDeliveryId) {
1395 return fetchByPrimaryKey((Serializable)userNotificationDeliveryId);
1396 }
1397
1398 @Override
1399 public Map<Serializable, UserNotificationDelivery> fetchByPrimaryKeys(
1400 Set<Serializable> primaryKeys) {
1401 if (primaryKeys.isEmpty()) {
1402 return Collections.emptyMap();
1403 }
1404
1405 Map<Serializable, UserNotificationDelivery> map = new HashMap<Serializable, UserNotificationDelivery>();
1406
1407 if (primaryKeys.size() == 1) {
1408 Iterator<Serializable> iterator = primaryKeys.iterator();
1409
1410 Serializable primaryKey = iterator.next();
1411
1412 UserNotificationDelivery userNotificationDelivery = fetchByPrimaryKey(primaryKey);
1413
1414 if (userNotificationDelivery != null) {
1415 map.put(primaryKey, userNotificationDelivery);
1416 }
1417
1418 return map;
1419 }
1420
1421 Set<Serializable> uncachedPrimaryKeys = null;
1422
1423 for (Serializable primaryKey : primaryKeys) {
1424 UserNotificationDelivery userNotificationDelivery = (UserNotificationDelivery)entityCache.getResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1425 UserNotificationDeliveryImpl.class, primaryKey);
1426
1427 if (userNotificationDelivery == null) {
1428 if (uncachedPrimaryKeys == null) {
1429 uncachedPrimaryKeys = new HashSet<Serializable>();
1430 }
1431
1432 uncachedPrimaryKeys.add(primaryKey);
1433 }
1434 else {
1435 map.put(primaryKey, userNotificationDelivery);
1436 }
1437 }
1438
1439 if (uncachedPrimaryKeys == null) {
1440 return map;
1441 }
1442
1443 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1444 1);
1445
1446 query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE_PKS_IN);
1447
1448 for (Serializable primaryKey : uncachedPrimaryKeys) {
1449 query.append(String.valueOf(primaryKey));
1450
1451 query.append(StringPool.COMMA);
1452 }
1453
1454 query.setIndex(query.index() - 1);
1455
1456 query.append(StringPool.CLOSE_PARENTHESIS);
1457
1458 String sql = query.toString();
1459
1460 Session session = null;
1461
1462 try {
1463 session = openSession();
1464
1465 Query q = session.createQuery(sql);
1466
1467 for (UserNotificationDelivery userNotificationDelivery : (List<UserNotificationDelivery>)q.list()) {
1468 map.put(userNotificationDelivery.getPrimaryKeyObj(),
1469 userNotificationDelivery);
1470
1471 cacheResult(userNotificationDelivery);
1472
1473 uncachedPrimaryKeys.remove(userNotificationDelivery.getPrimaryKeyObj());
1474 }
1475
1476 for (Serializable primaryKey : uncachedPrimaryKeys) {
1477 entityCache.putResult(UserNotificationDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1478 UserNotificationDeliveryImpl.class, primaryKey,
1479 _nullUserNotificationDelivery);
1480 }
1481 }
1482 catch (Exception e) {
1483 throw processException(e);
1484 }
1485 finally {
1486 closeSession(session);
1487 }
1488
1489 return map;
1490 }
1491
1492
1497 @Override
1498 public List<UserNotificationDelivery> findAll() {
1499 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1500 }
1501
1502
1513 @Override
1514 public List<UserNotificationDelivery> findAll(int start, int end) {
1515 return findAll(start, end, null);
1516 }
1517
1518
1530 @Override
1531 public List<UserNotificationDelivery> findAll(int start, int end,
1532 OrderByComparator<UserNotificationDelivery> orderByComparator) {
1533 return findAll(start, end, orderByComparator, true);
1534 }
1535
1536
1549 @Override
1550 public List<UserNotificationDelivery> findAll(int start, int end,
1551 OrderByComparator<UserNotificationDelivery> orderByComparator,
1552 boolean retrieveFromCache) {
1553 boolean pagination = true;
1554 FinderPath finderPath = null;
1555 Object[] finderArgs = null;
1556
1557 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1558 (orderByComparator == null)) {
1559 pagination = false;
1560 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1561 finderArgs = FINDER_ARGS_EMPTY;
1562 }
1563 else {
1564 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1565 finderArgs = new Object[] { start, end, orderByComparator };
1566 }
1567
1568 List<UserNotificationDelivery> list = null;
1569
1570 if (retrieveFromCache) {
1571 list = (List<UserNotificationDelivery>)finderCache.getResult(finderPath,
1572 finderArgs, this);
1573 }
1574
1575 if (list == null) {
1576 StringBundler query = null;
1577 String sql = null;
1578
1579 if (orderByComparator != null) {
1580 query = new StringBundler(2 +
1581 (orderByComparator.getOrderByFields().length * 2));
1582
1583 query.append(_SQL_SELECT_USERNOTIFICATIONDELIVERY);
1584
1585 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1586 orderByComparator);
1587
1588 sql = query.toString();
1589 }
1590 else {
1591 sql = _SQL_SELECT_USERNOTIFICATIONDELIVERY;
1592
1593 if (pagination) {
1594 sql = sql.concat(UserNotificationDeliveryModelImpl.ORDER_BY_JPQL);
1595 }
1596 }
1597
1598 Session session = null;
1599
1600 try {
1601 session = openSession();
1602
1603 Query q = session.createQuery(sql);
1604
1605 if (!pagination) {
1606 list = (List<UserNotificationDelivery>)QueryUtil.list(q,
1607 getDialect(), start, end, false);
1608
1609 Collections.sort(list);
1610
1611 list = Collections.unmodifiableList(list);
1612 }
1613 else {
1614 list = (List<UserNotificationDelivery>)QueryUtil.list(q,
1615 getDialect(), start, end);
1616 }
1617
1618 cacheResult(list);
1619
1620 finderCache.putResult(finderPath, finderArgs, list);
1621 }
1622 catch (Exception e) {
1623 finderCache.removeResult(finderPath, finderArgs);
1624
1625 throw processException(e);
1626 }
1627 finally {
1628 closeSession(session);
1629 }
1630 }
1631
1632 return list;
1633 }
1634
1635
1639 @Override
1640 public void removeAll() {
1641 for (UserNotificationDelivery userNotificationDelivery : findAll()) {
1642 remove(userNotificationDelivery);
1643 }
1644 }
1645
1646
1651 @Override
1652 public int countAll() {
1653 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
1654 FINDER_ARGS_EMPTY, this);
1655
1656 if (count == null) {
1657 Session session = null;
1658
1659 try {
1660 session = openSession();
1661
1662 Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONDELIVERY);
1663
1664 count = (Long)q.uniqueResult();
1665
1666 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
1667 count);
1668 }
1669 catch (Exception e) {
1670 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
1671 FINDER_ARGS_EMPTY);
1672
1673 throw processException(e);
1674 }
1675 finally {
1676 closeSession(session);
1677 }
1678 }
1679
1680 return count.intValue();
1681 }
1682
1683 @Override
1684 protected Map<String, Integer> getTableColumnsMap() {
1685 return UserNotificationDeliveryModelImpl.TABLE_COLUMNS_MAP;
1686 }
1687
1688
1691 public void afterPropertiesSet() {
1692 }
1693
1694 public void destroy() {
1695 entityCache.removeCache(UserNotificationDeliveryImpl.class.getName());
1696 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
1697 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1698 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1699 }
1700
1701 @BeanReference(type = CompanyProviderWrapper.class)
1702 protected CompanyProvider companyProvider;
1703 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
1704 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
1705 private static final String _SQL_SELECT_USERNOTIFICATIONDELIVERY = "SELECT userNotificationDelivery FROM UserNotificationDelivery userNotificationDelivery";
1706 private static final String _SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE_PKS_IN =
1707 "SELECT userNotificationDelivery FROM UserNotificationDelivery userNotificationDelivery WHERE userNotificationDeliveryId IN (";
1708 private static final String _SQL_SELECT_USERNOTIFICATIONDELIVERY_WHERE = "SELECT userNotificationDelivery FROM UserNotificationDelivery userNotificationDelivery WHERE ";
1709 private static final String _SQL_COUNT_USERNOTIFICATIONDELIVERY = "SELECT COUNT(userNotificationDelivery) FROM UserNotificationDelivery userNotificationDelivery";
1710 private static final String _SQL_COUNT_USERNOTIFICATIONDELIVERY_WHERE = "SELECT COUNT(userNotificationDelivery) FROM UserNotificationDelivery userNotificationDelivery WHERE ";
1711 private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationDelivery.";
1712 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationDelivery exists with the primary key ";
1713 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationDelivery exists with the key {";
1714 private static final Log _log = LogFactoryUtil.getLog(UserNotificationDeliveryPersistenceImpl.class);
1715 private static final UserNotificationDelivery _nullUserNotificationDelivery = new UserNotificationDeliveryImpl() {
1716 @Override
1717 public Object clone() {
1718 return this;
1719 }
1720
1721 @Override
1722 public CacheModel<UserNotificationDelivery> toCacheModel() {
1723 return _nullUserNotificationDeliveryCacheModel;
1724 }
1725 };
1726
1727 private static final CacheModel<UserNotificationDelivery> _nullUserNotificationDeliveryCacheModel =
1728 new NullCacheModel();
1729
1730 private static class NullCacheModel implements CacheModel<UserNotificationDelivery>,
1731 MVCCModel {
1732 @Override
1733 public long getMvccVersion() {
1734 return -1;
1735 }
1736
1737 @Override
1738 public void setMvccVersion(long mvccVersion) {
1739 }
1740
1741 @Override
1742 public UserNotificationDelivery toEntityModel() {
1743 return _nullUserNotificationDelivery;
1744 }
1745 }
1746 }