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