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