001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchUserNotificationEventException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.UserNotificationEvent;
041 import com.liferay.portal.model.impl.UserNotificationEventImpl;
042 import com.liferay.portal.model.impl.UserNotificationEventModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class UserNotificationEventPersistenceImpl extends BasePersistenceImpl<UserNotificationEvent>
064 implements UserNotificationEventPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationEventImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
076 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
077 UserNotificationEventImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
080 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
081 UserNotificationEventImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
084 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
087 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
088 UserNotificationEventImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090 new String[] {
091 String.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
097 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
098 UserNotificationEventImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
100 new String[] { String.class.getName() },
101 UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
102 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
104 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
106 new String[] { String.class.getName() });
107
108
115 public List<UserNotificationEvent> findByUuid(String uuid)
116 throws SystemException {
117 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 public List<UserNotificationEvent> findByUuid(String uuid, int start,
134 int end) throws SystemException {
135 return findByUuid(uuid, start, end, null);
136 }
137
138
152 public List<UserNotificationEvent> findByUuid(String uuid, int start,
153 int end, OrderByComparator orderByComparator) throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162 finderArgs = new Object[] { uuid };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166 finderArgs = new Object[] { uuid, start, end, orderByComparator };
167 }
168
169 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (UserNotificationEvent userNotificationEvent : list) {
174 if (!Validator.equals(uuid, userNotificationEvent.getUuid())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
194
195 boolean bindUuid = false;
196
197 if (uuid == null) {
198 query.append(_FINDER_COLUMN_UUID_UUID_1);
199 }
200 else if (uuid.equals(StringPool.BLANK)) {
201 query.append(_FINDER_COLUMN_UUID_UUID_3);
202 }
203 else {
204 bindUuid = true;
205
206 query.append(_FINDER_COLUMN_UUID_UUID_2);
207 }
208
209 if (orderByComparator != null) {
210 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
211 orderByComparator);
212 }
213 else
214 if (pagination) {
215 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
216 }
217
218 String sql = query.toString();
219
220 Session session = null;
221
222 try {
223 session = openSession();
224
225 Query q = session.createQuery(sql);
226
227 QueryPos qPos = QueryPos.getInstance(q);
228
229 if (bindUuid) {
230 qPos.add(uuid);
231 }
232
233 if (!pagination) {
234 list = (List<UserNotificationEvent>)QueryUtil.list(q,
235 getDialect(), start, end, false);
236
237 Collections.sort(list);
238
239 list = new UnmodifiableList<UserNotificationEvent>(list);
240 }
241 else {
242 list = (List<UserNotificationEvent>)QueryUtil.list(q,
243 getDialect(), start, end);
244 }
245
246 cacheResult(list);
247
248 FinderCacheUtil.putResult(finderPath, finderArgs, list);
249 }
250 catch (Exception e) {
251 FinderCacheUtil.removeResult(finderPath, finderArgs);
252
253 throw processException(e);
254 }
255 finally {
256 closeSession(session);
257 }
258 }
259
260 return list;
261 }
262
263
272 public UserNotificationEvent findByUuid_First(String uuid,
273 OrderByComparator orderByComparator)
274 throws NoSuchUserNotificationEventException, SystemException {
275 UserNotificationEvent userNotificationEvent = fetchByUuid_First(uuid,
276 orderByComparator);
277
278 if (userNotificationEvent != null) {
279 return userNotificationEvent;
280 }
281
282 StringBundler msg = new StringBundler(4);
283
284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285
286 msg.append("uuid=");
287 msg.append(uuid);
288
289 msg.append(StringPool.CLOSE_CURLY_BRACE);
290
291 throw new NoSuchUserNotificationEventException(msg.toString());
292 }
293
294
302 public UserNotificationEvent fetchByUuid_First(String uuid,
303 OrderByComparator orderByComparator) throws SystemException {
304 List<UserNotificationEvent> list = findByUuid(uuid, 0, 1,
305 orderByComparator);
306
307 if (!list.isEmpty()) {
308 return list.get(0);
309 }
310
311 return null;
312 }
313
314
323 public UserNotificationEvent findByUuid_Last(String uuid,
324 OrderByComparator orderByComparator)
325 throws NoSuchUserNotificationEventException, SystemException {
326 UserNotificationEvent userNotificationEvent = fetchByUuid_Last(uuid,
327 orderByComparator);
328
329 if (userNotificationEvent != null) {
330 return userNotificationEvent;
331 }
332
333 StringBundler msg = new StringBundler(4);
334
335 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336
337 msg.append("uuid=");
338 msg.append(uuid);
339
340 msg.append(StringPool.CLOSE_CURLY_BRACE);
341
342 throw new NoSuchUserNotificationEventException(msg.toString());
343 }
344
345
353 public UserNotificationEvent fetchByUuid_Last(String uuid,
354 OrderByComparator orderByComparator) throws SystemException {
355 int count = countByUuid(uuid);
356
357 List<UserNotificationEvent> list = findByUuid(uuid, count - 1, count,
358 orderByComparator);
359
360 if (!list.isEmpty()) {
361 return list.get(0);
362 }
363
364 return null;
365 }
366
367
377 public UserNotificationEvent[] findByUuid_PrevAndNext(
378 long userNotificationEventId, String uuid,
379 OrderByComparator orderByComparator)
380 throws NoSuchUserNotificationEventException, SystemException {
381 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
382
383 Session session = null;
384
385 try {
386 session = openSession();
387
388 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
389
390 array[0] = getByUuid_PrevAndNext(session, userNotificationEvent,
391 uuid, orderByComparator, true);
392
393 array[1] = userNotificationEvent;
394
395 array[2] = getByUuid_PrevAndNext(session, userNotificationEvent,
396 uuid, orderByComparator, false);
397
398 return array;
399 }
400 catch (Exception e) {
401 throw processException(e);
402 }
403 finally {
404 closeSession(session);
405 }
406 }
407
408 protected UserNotificationEvent getByUuid_PrevAndNext(Session session,
409 UserNotificationEvent userNotificationEvent, String uuid,
410 OrderByComparator orderByComparator, boolean previous) {
411 StringBundler query = null;
412
413 if (orderByComparator != null) {
414 query = new StringBundler(6 +
415 (orderByComparator.getOrderByFields().length * 6));
416 }
417 else {
418 query = new StringBundler(3);
419 }
420
421 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
422
423 boolean bindUuid = false;
424
425 if (uuid == null) {
426 query.append(_FINDER_COLUMN_UUID_UUID_1);
427 }
428 else if (uuid.equals(StringPool.BLANK)) {
429 query.append(_FINDER_COLUMN_UUID_UUID_3);
430 }
431 else {
432 bindUuid = true;
433
434 query.append(_FINDER_COLUMN_UUID_UUID_2);
435 }
436
437 if (orderByComparator != null) {
438 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
439
440 if (orderByConditionFields.length > 0) {
441 query.append(WHERE_AND);
442 }
443
444 for (int i = 0; i < orderByConditionFields.length; i++) {
445 query.append(_ORDER_BY_ENTITY_ALIAS);
446 query.append(orderByConditionFields[i]);
447
448 if ((i + 1) < orderByConditionFields.length) {
449 if (orderByComparator.isAscending() ^ previous) {
450 query.append(WHERE_GREATER_THAN_HAS_NEXT);
451 }
452 else {
453 query.append(WHERE_LESSER_THAN_HAS_NEXT);
454 }
455 }
456 else {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(WHERE_GREATER_THAN);
459 }
460 else {
461 query.append(WHERE_LESSER_THAN);
462 }
463 }
464 }
465
466 query.append(ORDER_BY_CLAUSE);
467
468 String[] orderByFields = orderByComparator.getOrderByFields();
469
470 for (int i = 0; i < orderByFields.length; i++) {
471 query.append(_ORDER_BY_ENTITY_ALIAS);
472 query.append(orderByFields[i]);
473
474 if ((i + 1) < orderByFields.length) {
475 if (orderByComparator.isAscending() ^ previous) {
476 query.append(ORDER_BY_ASC_HAS_NEXT);
477 }
478 else {
479 query.append(ORDER_BY_DESC_HAS_NEXT);
480 }
481 }
482 else {
483 if (orderByComparator.isAscending() ^ previous) {
484 query.append(ORDER_BY_ASC);
485 }
486 else {
487 query.append(ORDER_BY_DESC);
488 }
489 }
490 }
491 }
492 else {
493 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
494 }
495
496 String sql = query.toString();
497
498 Query q = session.createQuery(sql);
499
500 q.setFirstResult(0);
501 q.setMaxResults(2);
502
503 QueryPos qPos = QueryPos.getInstance(q);
504
505 if (bindUuid) {
506 qPos.add(uuid);
507 }
508
509 if (orderByComparator != null) {
510 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
511
512 for (Object value : values) {
513 qPos.add(value);
514 }
515 }
516
517 List<UserNotificationEvent> list = q.list();
518
519 if (list.size() == 2) {
520 return list.get(1);
521 }
522 else {
523 return null;
524 }
525 }
526
527
533 public void removeByUuid(String uuid) throws SystemException {
534 for (UserNotificationEvent userNotificationEvent : findByUuid(uuid,
535 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
536 remove(userNotificationEvent);
537 }
538 }
539
540
547 public int countByUuid(String uuid) throws SystemException {
548 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
549
550 Object[] finderArgs = new Object[] { uuid };
551
552 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
553 this);
554
555 if (count == null) {
556 StringBundler query = new StringBundler(2);
557
558 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
559
560 boolean bindUuid = false;
561
562 if (uuid == null) {
563 query.append(_FINDER_COLUMN_UUID_UUID_1);
564 }
565 else if (uuid.equals(StringPool.BLANK)) {
566 query.append(_FINDER_COLUMN_UUID_UUID_3);
567 }
568 else {
569 bindUuid = true;
570
571 query.append(_FINDER_COLUMN_UUID_UUID_2);
572 }
573
574 String sql = query.toString();
575
576 Session session = null;
577
578 try {
579 session = openSession();
580
581 Query q = session.createQuery(sql);
582
583 QueryPos qPos = QueryPos.getInstance(q);
584
585 if (bindUuid) {
586 qPos.add(uuid);
587 }
588
589 count = (Long)q.uniqueResult();
590
591 FinderCacheUtil.putResult(finderPath, finderArgs, count);
592 }
593 catch (Exception e) {
594 FinderCacheUtil.removeResult(finderPath, finderArgs);
595
596 throw processException(e);
597 }
598 finally {
599 closeSession(session);
600 }
601 }
602
603 return count.intValue();
604 }
605
606 private static final String _FINDER_COLUMN_UUID_UUID_1 = "userNotificationEvent.uuid IS NULL";
607 private static final String _FINDER_COLUMN_UUID_UUID_2 = "userNotificationEvent.uuid = ?";
608 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = '')";
609 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
610 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
611 UserNotificationEventImpl.class,
612 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
613 new String[] {
614 String.class.getName(), Long.class.getName(),
615
616 Integer.class.getName(), Integer.class.getName(),
617 OrderByComparator.class.getName()
618 });
619 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
620 new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
621 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
622 UserNotificationEventImpl.class,
623 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
624 new String[] { String.class.getName(), Long.class.getName() },
625 UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
626 UserNotificationEventModelImpl.COMPANYID_COLUMN_BITMASK |
627 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
628 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
629 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
630 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
631 new String[] { String.class.getName(), Long.class.getName() });
632
633
641 public List<UserNotificationEvent> findByUuid_C(String uuid, long companyId)
642 throws SystemException {
643 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
644 QueryUtil.ALL_POS, null);
645 }
646
647
661 public List<UserNotificationEvent> findByUuid_C(String uuid,
662 long companyId, int start, int end) throws SystemException {
663 return findByUuid_C(uuid, companyId, start, end, null);
664 }
665
666
681 public List<UserNotificationEvent> findByUuid_C(String uuid,
682 long companyId, int start, int end, OrderByComparator orderByComparator)
683 throws SystemException {
684 boolean pagination = true;
685 FinderPath finderPath = null;
686 Object[] finderArgs = null;
687
688 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
689 (orderByComparator == null)) {
690 pagination = false;
691 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
692 finderArgs = new Object[] { uuid, companyId };
693 }
694 else {
695 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
696 finderArgs = new Object[] {
697 uuid, companyId,
698
699 start, end, orderByComparator
700 };
701 }
702
703 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
704 finderArgs, this);
705
706 if ((list != null) && !list.isEmpty()) {
707 for (UserNotificationEvent userNotificationEvent : list) {
708 if (!Validator.equals(uuid, userNotificationEvent.getUuid()) ||
709 (companyId != userNotificationEvent.getCompanyId())) {
710 list = null;
711
712 break;
713 }
714 }
715 }
716
717 if (list == null) {
718 StringBundler query = null;
719
720 if (orderByComparator != null) {
721 query = new StringBundler(4 +
722 (orderByComparator.getOrderByFields().length * 3));
723 }
724 else {
725 query = new StringBundler(4);
726 }
727
728 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
729
730 boolean bindUuid = false;
731
732 if (uuid == null) {
733 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
734 }
735 else if (uuid.equals(StringPool.BLANK)) {
736 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
737 }
738 else {
739 bindUuid = true;
740
741 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
742 }
743
744 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
745
746 if (orderByComparator != null) {
747 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
748 orderByComparator);
749 }
750 else
751 if (pagination) {
752 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
753 }
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 if (bindUuid) {
767 qPos.add(uuid);
768 }
769
770 qPos.add(companyId);
771
772 if (!pagination) {
773 list = (List<UserNotificationEvent>)QueryUtil.list(q,
774 getDialect(), start, end, false);
775
776 Collections.sort(list);
777
778 list = new UnmodifiableList<UserNotificationEvent>(list);
779 }
780 else {
781 list = (List<UserNotificationEvent>)QueryUtil.list(q,
782 getDialect(), start, end);
783 }
784
785 cacheResult(list);
786
787 FinderCacheUtil.putResult(finderPath, finderArgs, list);
788 }
789 catch (Exception e) {
790 FinderCacheUtil.removeResult(finderPath, finderArgs);
791
792 throw processException(e);
793 }
794 finally {
795 closeSession(session);
796 }
797 }
798
799 return list;
800 }
801
802
812 public UserNotificationEvent findByUuid_C_First(String uuid,
813 long companyId, OrderByComparator orderByComparator)
814 throws NoSuchUserNotificationEventException, SystemException {
815 UserNotificationEvent userNotificationEvent = fetchByUuid_C_First(uuid,
816 companyId, orderByComparator);
817
818 if (userNotificationEvent != null) {
819 return userNotificationEvent;
820 }
821
822 StringBundler msg = new StringBundler(6);
823
824 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
825
826 msg.append("uuid=");
827 msg.append(uuid);
828
829 msg.append(", companyId=");
830 msg.append(companyId);
831
832 msg.append(StringPool.CLOSE_CURLY_BRACE);
833
834 throw new NoSuchUserNotificationEventException(msg.toString());
835 }
836
837
846 public UserNotificationEvent fetchByUuid_C_First(String uuid,
847 long companyId, OrderByComparator orderByComparator)
848 throws SystemException {
849 List<UserNotificationEvent> list = findByUuid_C(uuid, companyId, 0, 1,
850 orderByComparator);
851
852 if (!list.isEmpty()) {
853 return list.get(0);
854 }
855
856 return null;
857 }
858
859
869 public UserNotificationEvent findByUuid_C_Last(String uuid, long companyId,
870 OrderByComparator orderByComparator)
871 throws NoSuchUserNotificationEventException, SystemException {
872 UserNotificationEvent userNotificationEvent = fetchByUuid_C_Last(uuid,
873 companyId, orderByComparator);
874
875 if (userNotificationEvent != null) {
876 return userNotificationEvent;
877 }
878
879 StringBundler msg = new StringBundler(6);
880
881 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
882
883 msg.append("uuid=");
884 msg.append(uuid);
885
886 msg.append(", companyId=");
887 msg.append(companyId);
888
889 msg.append(StringPool.CLOSE_CURLY_BRACE);
890
891 throw new NoSuchUserNotificationEventException(msg.toString());
892 }
893
894
903 public UserNotificationEvent fetchByUuid_C_Last(String uuid,
904 long companyId, OrderByComparator orderByComparator)
905 throws SystemException {
906 int count = countByUuid_C(uuid, companyId);
907
908 List<UserNotificationEvent> list = findByUuid_C(uuid, companyId,
909 count - 1, count, orderByComparator);
910
911 if (!list.isEmpty()) {
912 return list.get(0);
913 }
914
915 return null;
916 }
917
918
929 public UserNotificationEvent[] findByUuid_C_PrevAndNext(
930 long userNotificationEventId, String uuid, long companyId,
931 OrderByComparator orderByComparator)
932 throws NoSuchUserNotificationEventException, SystemException {
933 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
934
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
941
942 array[0] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
943 uuid, companyId, orderByComparator, true);
944
945 array[1] = userNotificationEvent;
946
947 array[2] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
948 uuid, companyId, orderByComparator, false);
949
950 return array;
951 }
952 catch (Exception e) {
953 throw processException(e);
954 }
955 finally {
956 closeSession(session);
957 }
958 }
959
960 protected UserNotificationEvent getByUuid_C_PrevAndNext(Session session,
961 UserNotificationEvent userNotificationEvent, String uuid,
962 long companyId, OrderByComparator orderByComparator, boolean previous) {
963 StringBundler query = null;
964
965 if (orderByComparator != null) {
966 query = new StringBundler(6 +
967 (orderByComparator.getOrderByFields().length * 6));
968 }
969 else {
970 query = new StringBundler(3);
971 }
972
973 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
974
975 boolean bindUuid = false;
976
977 if (uuid == null) {
978 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
979 }
980 else if (uuid.equals(StringPool.BLANK)) {
981 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
982 }
983 else {
984 bindUuid = true;
985
986 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
987 }
988
989 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
990
991 if (orderByComparator != null) {
992 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
993
994 if (orderByConditionFields.length > 0) {
995 query.append(WHERE_AND);
996 }
997
998 for (int i = 0; i < orderByConditionFields.length; i++) {
999 query.append(_ORDER_BY_ENTITY_ALIAS);
1000 query.append(orderByConditionFields[i]);
1001
1002 if ((i + 1) < orderByConditionFields.length) {
1003 if (orderByComparator.isAscending() ^ previous) {
1004 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1005 }
1006 else {
1007 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1008 }
1009 }
1010 else {
1011 if (orderByComparator.isAscending() ^ previous) {
1012 query.append(WHERE_GREATER_THAN);
1013 }
1014 else {
1015 query.append(WHERE_LESSER_THAN);
1016 }
1017 }
1018 }
1019
1020 query.append(ORDER_BY_CLAUSE);
1021
1022 String[] orderByFields = orderByComparator.getOrderByFields();
1023
1024 for (int i = 0; i < orderByFields.length; i++) {
1025 query.append(_ORDER_BY_ENTITY_ALIAS);
1026 query.append(orderByFields[i]);
1027
1028 if ((i + 1) < orderByFields.length) {
1029 if (orderByComparator.isAscending() ^ previous) {
1030 query.append(ORDER_BY_ASC_HAS_NEXT);
1031 }
1032 else {
1033 query.append(ORDER_BY_DESC_HAS_NEXT);
1034 }
1035 }
1036 else {
1037 if (orderByComparator.isAscending() ^ previous) {
1038 query.append(ORDER_BY_ASC);
1039 }
1040 else {
1041 query.append(ORDER_BY_DESC);
1042 }
1043 }
1044 }
1045 }
1046 else {
1047 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1048 }
1049
1050 String sql = query.toString();
1051
1052 Query q = session.createQuery(sql);
1053
1054 q.setFirstResult(0);
1055 q.setMaxResults(2);
1056
1057 QueryPos qPos = QueryPos.getInstance(q);
1058
1059 if (bindUuid) {
1060 qPos.add(uuid);
1061 }
1062
1063 qPos.add(companyId);
1064
1065 if (orderByComparator != null) {
1066 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1067
1068 for (Object value : values) {
1069 qPos.add(value);
1070 }
1071 }
1072
1073 List<UserNotificationEvent> list = q.list();
1074
1075 if (list.size() == 2) {
1076 return list.get(1);
1077 }
1078 else {
1079 return null;
1080 }
1081 }
1082
1083
1090 public void removeByUuid_C(String uuid, long companyId)
1091 throws SystemException {
1092 for (UserNotificationEvent userNotificationEvent : findByUuid_C(uuid,
1093 companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1094 remove(userNotificationEvent);
1095 }
1096 }
1097
1098
1106 public int countByUuid_C(String uuid, long companyId)
1107 throws SystemException {
1108 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1109
1110 Object[] finderArgs = new Object[] { uuid, companyId };
1111
1112 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1113 this);
1114
1115 if (count == null) {
1116 StringBundler query = new StringBundler(3);
1117
1118 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1119
1120 boolean bindUuid = false;
1121
1122 if (uuid == null) {
1123 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1124 }
1125 else if (uuid.equals(StringPool.BLANK)) {
1126 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1127 }
1128 else {
1129 bindUuid = true;
1130
1131 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1132 }
1133
1134 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1135
1136 String sql = query.toString();
1137
1138 Session session = null;
1139
1140 try {
1141 session = openSession();
1142
1143 Query q = session.createQuery(sql);
1144
1145 QueryPos qPos = QueryPos.getInstance(q);
1146
1147 if (bindUuid) {
1148 qPos.add(uuid);
1149 }
1150
1151 qPos.add(companyId);
1152
1153 count = (Long)q.uniqueResult();
1154
1155 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1156 }
1157 catch (Exception e) {
1158 FinderCacheUtil.removeResult(finderPath, finderArgs);
1159
1160 throw processException(e);
1161 }
1162 finally {
1163 closeSession(session);
1164 }
1165 }
1166
1167 return count.intValue();
1168 }
1169
1170 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "userNotificationEvent.uuid IS NULL AND ";
1171 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "userNotificationEvent.uuid = ? AND ";
1172 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = '') AND ";
1173 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "userNotificationEvent.companyId = ?";
1174 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1175 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1176 UserNotificationEventImpl.class,
1177 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1178 new String[] {
1179 Long.class.getName(),
1180
1181 Integer.class.getName(), Integer.class.getName(),
1182 OrderByComparator.class.getName()
1183 });
1184 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1185 new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1186 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1187 UserNotificationEventImpl.class,
1188 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1189 new String[] { Long.class.getName() },
1190 UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1191 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1192 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1193 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1194 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1195 new String[] { Long.class.getName() });
1196
1197
1204 public List<UserNotificationEvent> findByUserId(long userId)
1205 throws SystemException {
1206 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1207 }
1208
1209
1222 public List<UserNotificationEvent> findByUserId(long userId, int start,
1223 int end) throws SystemException {
1224 return findByUserId(userId, start, end, null);
1225 }
1226
1227
1241 public List<UserNotificationEvent> findByUserId(long userId, int start,
1242 int end, OrderByComparator orderByComparator) throws SystemException {
1243 boolean pagination = true;
1244 FinderPath finderPath = null;
1245 Object[] finderArgs = null;
1246
1247 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1248 (orderByComparator == null)) {
1249 pagination = false;
1250 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1251 finderArgs = new Object[] { userId };
1252 }
1253 else {
1254 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1255 finderArgs = new Object[] { userId, start, end, orderByComparator };
1256 }
1257
1258 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1259 finderArgs, this);
1260
1261 if ((list != null) && !list.isEmpty()) {
1262 for (UserNotificationEvent userNotificationEvent : list) {
1263 if ((userId != userNotificationEvent.getUserId())) {
1264 list = null;
1265
1266 break;
1267 }
1268 }
1269 }
1270
1271 if (list == null) {
1272 StringBundler query = null;
1273
1274 if (orderByComparator != null) {
1275 query = new StringBundler(3 +
1276 (orderByComparator.getOrderByFields().length * 3));
1277 }
1278 else {
1279 query = new StringBundler(3);
1280 }
1281
1282 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1283
1284 query.append(_FINDER_COLUMN_USERID_USERID_2);
1285
1286 if (orderByComparator != null) {
1287 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1288 orderByComparator);
1289 }
1290 else
1291 if (pagination) {
1292 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1293 }
1294
1295 String sql = query.toString();
1296
1297 Session session = null;
1298
1299 try {
1300 session = openSession();
1301
1302 Query q = session.createQuery(sql);
1303
1304 QueryPos qPos = QueryPos.getInstance(q);
1305
1306 qPos.add(userId);
1307
1308 if (!pagination) {
1309 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1310 getDialect(), start, end, false);
1311
1312 Collections.sort(list);
1313
1314 list = new UnmodifiableList<UserNotificationEvent>(list);
1315 }
1316 else {
1317 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1318 getDialect(), start, end);
1319 }
1320
1321 cacheResult(list);
1322
1323 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1324 }
1325 catch (Exception e) {
1326 FinderCacheUtil.removeResult(finderPath, finderArgs);
1327
1328 throw processException(e);
1329 }
1330 finally {
1331 closeSession(session);
1332 }
1333 }
1334
1335 return list;
1336 }
1337
1338
1347 public UserNotificationEvent findByUserId_First(long userId,
1348 OrderByComparator orderByComparator)
1349 throws NoSuchUserNotificationEventException, SystemException {
1350 UserNotificationEvent userNotificationEvent = fetchByUserId_First(userId,
1351 orderByComparator);
1352
1353 if (userNotificationEvent != null) {
1354 return userNotificationEvent;
1355 }
1356
1357 StringBundler msg = new StringBundler(4);
1358
1359 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1360
1361 msg.append("userId=");
1362 msg.append(userId);
1363
1364 msg.append(StringPool.CLOSE_CURLY_BRACE);
1365
1366 throw new NoSuchUserNotificationEventException(msg.toString());
1367 }
1368
1369
1377 public UserNotificationEvent fetchByUserId_First(long userId,
1378 OrderByComparator orderByComparator) throws SystemException {
1379 List<UserNotificationEvent> list = findByUserId(userId, 0, 1,
1380 orderByComparator);
1381
1382 if (!list.isEmpty()) {
1383 return list.get(0);
1384 }
1385
1386 return null;
1387 }
1388
1389
1398 public UserNotificationEvent findByUserId_Last(long userId,
1399 OrderByComparator orderByComparator)
1400 throws NoSuchUserNotificationEventException, SystemException {
1401 UserNotificationEvent userNotificationEvent = fetchByUserId_Last(userId,
1402 orderByComparator);
1403
1404 if (userNotificationEvent != null) {
1405 return userNotificationEvent;
1406 }
1407
1408 StringBundler msg = new StringBundler(4);
1409
1410 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1411
1412 msg.append("userId=");
1413 msg.append(userId);
1414
1415 msg.append(StringPool.CLOSE_CURLY_BRACE);
1416
1417 throw new NoSuchUserNotificationEventException(msg.toString());
1418 }
1419
1420
1428 public UserNotificationEvent fetchByUserId_Last(long userId,
1429 OrderByComparator orderByComparator) throws SystemException {
1430 int count = countByUserId(userId);
1431
1432 List<UserNotificationEvent> list = findByUserId(userId, count - 1,
1433 count, orderByComparator);
1434
1435 if (!list.isEmpty()) {
1436 return list.get(0);
1437 }
1438
1439 return null;
1440 }
1441
1442
1452 public UserNotificationEvent[] findByUserId_PrevAndNext(
1453 long userNotificationEventId, long userId,
1454 OrderByComparator orderByComparator)
1455 throws NoSuchUserNotificationEventException, SystemException {
1456 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1457
1458 Session session = null;
1459
1460 try {
1461 session = openSession();
1462
1463 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1464
1465 array[0] = getByUserId_PrevAndNext(session, userNotificationEvent,
1466 userId, orderByComparator, true);
1467
1468 array[1] = userNotificationEvent;
1469
1470 array[2] = getByUserId_PrevAndNext(session, userNotificationEvent,
1471 userId, orderByComparator, false);
1472
1473 return array;
1474 }
1475 catch (Exception e) {
1476 throw processException(e);
1477 }
1478 finally {
1479 closeSession(session);
1480 }
1481 }
1482
1483 protected UserNotificationEvent getByUserId_PrevAndNext(Session session,
1484 UserNotificationEvent userNotificationEvent, long userId,
1485 OrderByComparator orderByComparator, boolean previous) {
1486 StringBundler query = null;
1487
1488 if (orderByComparator != null) {
1489 query = new StringBundler(6 +
1490 (orderByComparator.getOrderByFields().length * 6));
1491 }
1492 else {
1493 query = new StringBundler(3);
1494 }
1495
1496 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1497
1498 query.append(_FINDER_COLUMN_USERID_USERID_2);
1499
1500 if (orderByComparator != null) {
1501 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1502
1503 if (orderByConditionFields.length > 0) {
1504 query.append(WHERE_AND);
1505 }
1506
1507 for (int i = 0; i < orderByConditionFields.length; i++) {
1508 query.append(_ORDER_BY_ENTITY_ALIAS);
1509 query.append(orderByConditionFields[i]);
1510
1511 if ((i + 1) < orderByConditionFields.length) {
1512 if (orderByComparator.isAscending() ^ previous) {
1513 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1514 }
1515 else {
1516 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1517 }
1518 }
1519 else {
1520 if (orderByComparator.isAscending() ^ previous) {
1521 query.append(WHERE_GREATER_THAN);
1522 }
1523 else {
1524 query.append(WHERE_LESSER_THAN);
1525 }
1526 }
1527 }
1528
1529 query.append(ORDER_BY_CLAUSE);
1530
1531 String[] orderByFields = orderByComparator.getOrderByFields();
1532
1533 for (int i = 0; i < orderByFields.length; i++) {
1534 query.append(_ORDER_BY_ENTITY_ALIAS);
1535 query.append(orderByFields[i]);
1536
1537 if ((i + 1) < orderByFields.length) {
1538 if (orderByComparator.isAscending() ^ previous) {
1539 query.append(ORDER_BY_ASC_HAS_NEXT);
1540 }
1541 else {
1542 query.append(ORDER_BY_DESC_HAS_NEXT);
1543 }
1544 }
1545 else {
1546 if (orderByComparator.isAscending() ^ previous) {
1547 query.append(ORDER_BY_ASC);
1548 }
1549 else {
1550 query.append(ORDER_BY_DESC);
1551 }
1552 }
1553 }
1554 }
1555 else {
1556 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1557 }
1558
1559 String sql = query.toString();
1560
1561 Query q = session.createQuery(sql);
1562
1563 q.setFirstResult(0);
1564 q.setMaxResults(2);
1565
1566 QueryPos qPos = QueryPos.getInstance(q);
1567
1568 qPos.add(userId);
1569
1570 if (orderByComparator != null) {
1571 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1572
1573 for (Object value : values) {
1574 qPos.add(value);
1575 }
1576 }
1577
1578 List<UserNotificationEvent> list = q.list();
1579
1580 if (list.size() == 2) {
1581 return list.get(1);
1582 }
1583 else {
1584 return null;
1585 }
1586 }
1587
1588
1594 public void removeByUserId(long userId) throws SystemException {
1595 for (UserNotificationEvent userNotificationEvent : findByUserId(
1596 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1597 remove(userNotificationEvent);
1598 }
1599 }
1600
1601
1608 public int countByUserId(long userId) throws SystemException {
1609 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1610
1611 Object[] finderArgs = new Object[] { userId };
1612
1613 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1614 this);
1615
1616 if (count == null) {
1617 StringBundler query = new StringBundler(2);
1618
1619 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1620
1621 query.append(_FINDER_COLUMN_USERID_USERID_2);
1622
1623 String sql = query.toString();
1624
1625 Session session = null;
1626
1627 try {
1628 session = openSession();
1629
1630 Query q = session.createQuery(sql);
1631
1632 QueryPos qPos = QueryPos.getInstance(q);
1633
1634 qPos.add(userId);
1635
1636 count = (Long)q.uniqueResult();
1637
1638 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1639 }
1640 catch (Exception e) {
1641 FinderCacheUtil.removeResult(finderPath, finderArgs);
1642
1643 throw processException(e);
1644 }
1645 finally {
1646 closeSession(session);
1647 }
1648 }
1649
1650 return count.intValue();
1651 }
1652
1653 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationEvent.userId = ?";
1654 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1655 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1656 UserNotificationEventImpl.class,
1657 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_A",
1658 new String[] {
1659 Long.class.getName(), Boolean.class.getName(),
1660
1661 Integer.class.getName(), Integer.class.getName(),
1662 OrderByComparator.class.getName()
1663 });
1664 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1665 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1666 UserNotificationEventImpl.class,
1667 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_A",
1668 new String[] { Long.class.getName(), Boolean.class.getName() },
1669 UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1670 UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
1671 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1672 public static final FinderPath FINDER_PATH_COUNT_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1673 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1674 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_A",
1675 new String[] { Long.class.getName(), Boolean.class.getName() });
1676
1677
1685 public List<UserNotificationEvent> findByU_A(long userId, boolean archived)
1686 throws SystemException {
1687 return findByU_A(userId, archived, QueryUtil.ALL_POS,
1688 QueryUtil.ALL_POS, null);
1689 }
1690
1691
1705 public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1706 int start, int end) throws SystemException {
1707 return findByU_A(userId, archived, start, end, null);
1708 }
1709
1710
1725 public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1726 int start, int end, OrderByComparator orderByComparator)
1727 throws SystemException {
1728 boolean pagination = true;
1729 FinderPath finderPath = null;
1730 Object[] finderArgs = null;
1731
1732 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1733 (orderByComparator == null)) {
1734 pagination = false;
1735 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A;
1736 finderArgs = new Object[] { userId, archived };
1737 }
1738 else {
1739 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A;
1740 finderArgs = new Object[] {
1741 userId, archived,
1742
1743 start, end, orderByComparator
1744 };
1745 }
1746
1747 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1748 finderArgs, this);
1749
1750 if ((list != null) && !list.isEmpty()) {
1751 for (UserNotificationEvent userNotificationEvent : list) {
1752 if ((userId != userNotificationEvent.getUserId()) ||
1753 (archived != userNotificationEvent.getArchived())) {
1754 list = null;
1755
1756 break;
1757 }
1758 }
1759 }
1760
1761 if (list == null) {
1762 StringBundler query = null;
1763
1764 if (orderByComparator != null) {
1765 query = new StringBundler(4 +
1766 (orderByComparator.getOrderByFields().length * 3));
1767 }
1768 else {
1769 query = new StringBundler(4);
1770 }
1771
1772 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1773
1774 query.append(_FINDER_COLUMN_U_A_USERID_2);
1775
1776 query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
1777
1778 if (orderByComparator != null) {
1779 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1780 orderByComparator);
1781 }
1782 else
1783 if (pagination) {
1784 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1785 }
1786
1787 String sql = query.toString();
1788
1789 Session session = null;
1790
1791 try {
1792 session = openSession();
1793
1794 Query q = session.createQuery(sql);
1795
1796 QueryPos qPos = QueryPos.getInstance(q);
1797
1798 qPos.add(userId);
1799
1800 qPos.add(archived);
1801
1802 if (!pagination) {
1803 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1804 getDialect(), start, end, false);
1805
1806 Collections.sort(list);
1807
1808 list = new UnmodifiableList<UserNotificationEvent>(list);
1809 }
1810 else {
1811 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1812 getDialect(), start, end);
1813 }
1814
1815 cacheResult(list);
1816
1817 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1818 }
1819 catch (Exception e) {
1820 FinderCacheUtil.removeResult(finderPath, finderArgs);
1821
1822 throw processException(e);
1823 }
1824 finally {
1825 closeSession(session);
1826 }
1827 }
1828
1829 return list;
1830 }
1831
1832
1842 public UserNotificationEvent findByU_A_First(long userId, boolean archived,
1843 OrderByComparator orderByComparator)
1844 throws NoSuchUserNotificationEventException, SystemException {
1845 UserNotificationEvent userNotificationEvent = fetchByU_A_First(userId,
1846 archived, orderByComparator);
1847
1848 if (userNotificationEvent != null) {
1849 return userNotificationEvent;
1850 }
1851
1852 StringBundler msg = new StringBundler(6);
1853
1854 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1855
1856 msg.append("userId=");
1857 msg.append(userId);
1858
1859 msg.append(", archived=");
1860 msg.append(archived);
1861
1862 msg.append(StringPool.CLOSE_CURLY_BRACE);
1863
1864 throw new NoSuchUserNotificationEventException(msg.toString());
1865 }
1866
1867
1876 public UserNotificationEvent fetchByU_A_First(long userId,
1877 boolean archived, OrderByComparator orderByComparator)
1878 throws SystemException {
1879 List<UserNotificationEvent> list = findByU_A(userId, archived, 0, 1,
1880 orderByComparator);
1881
1882 if (!list.isEmpty()) {
1883 return list.get(0);
1884 }
1885
1886 return null;
1887 }
1888
1889
1899 public UserNotificationEvent findByU_A_Last(long userId, boolean archived,
1900 OrderByComparator orderByComparator)
1901 throws NoSuchUserNotificationEventException, SystemException {
1902 UserNotificationEvent userNotificationEvent = fetchByU_A_Last(userId,
1903 archived, orderByComparator);
1904
1905 if (userNotificationEvent != null) {
1906 return userNotificationEvent;
1907 }
1908
1909 StringBundler msg = new StringBundler(6);
1910
1911 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1912
1913 msg.append("userId=");
1914 msg.append(userId);
1915
1916 msg.append(", archived=");
1917 msg.append(archived);
1918
1919 msg.append(StringPool.CLOSE_CURLY_BRACE);
1920
1921 throw new NoSuchUserNotificationEventException(msg.toString());
1922 }
1923
1924
1933 public UserNotificationEvent fetchByU_A_Last(long userId, boolean archived,
1934 OrderByComparator orderByComparator) throws SystemException {
1935 int count = countByU_A(userId, archived);
1936
1937 List<UserNotificationEvent> list = findByU_A(userId, archived,
1938 count - 1, count, orderByComparator);
1939
1940 if (!list.isEmpty()) {
1941 return list.get(0);
1942 }
1943
1944 return null;
1945 }
1946
1947
1958 public UserNotificationEvent[] findByU_A_PrevAndNext(
1959 long userNotificationEventId, long userId, boolean archived,
1960 OrderByComparator orderByComparator)
1961 throws NoSuchUserNotificationEventException, SystemException {
1962 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1963
1964 Session session = null;
1965
1966 try {
1967 session = openSession();
1968
1969 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1970
1971 array[0] = getByU_A_PrevAndNext(session, userNotificationEvent,
1972 userId, archived, orderByComparator, true);
1973
1974 array[1] = userNotificationEvent;
1975
1976 array[2] = getByU_A_PrevAndNext(session, userNotificationEvent,
1977 userId, archived, orderByComparator, false);
1978
1979 return array;
1980 }
1981 catch (Exception e) {
1982 throw processException(e);
1983 }
1984 finally {
1985 closeSession(session);
1986 }
1987 }
1988
1989 protected UserNotificationEvent getByU_A_PrevAndNext(Session session,
1990 UserNotificationEvent userNotificationEvent, long userId,
1991 boolean archived, OrderByComparator orderByComparator, boolean previous) {
1992 StringBundler query = null;
1993
1994 if (orderByComparator != null) {
1995 query = new StringBundler(6 +
1996 (orderByComparator.getOrderByFields().length * 6));
1997 }
1998 else {
1999 query = new StringBundler(3);
2000 }
2001
2002 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
2003
2004 query.append(_FINDER_COLUMN_U_A_USERID_2);
2005
2006 query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
2007
2008 if (orderByComparator != null) {
2009 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2010
2011 if (orderByConditionFields.length > 0) {
2012 query.append(WHERE_AND);
2013 }
2014
2015 for (int i = 0; i < orderByConditionFields.length; i++) {
2016 query.append(_ORDER_BY_ENTITY_ALIAS);
2017 query.append(orderByConditionFields[i]);
2018
2019 if ((i + 1) < orderByConditionFields.length) {
2020 if (orderByComparator.isAscending() ^ previous) {
2021 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2022 }
2023 else {
2024 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2025 }
2026 }
2027 else {
2028 if (orderByComparator.isAscending() ^ previous) {
2029 query.append(WHERE_GREATER_THAN);
2030 }
2031 else {
2032 query.append(WHERE_LESSER_THAN);
2033 }
2034 }
2035 }
2036
2037 query.append(ORDER_BY_CLAUSE);
2038
2039 String[] orderByFields = orderByComparator.getOrderByFields();
2040
2041 for (int i = 0; i < orderByFields.length; i++) {
2042 query.append(_ORDER_BY_ENTITY_ALIAS);
2043 query.append(orderByFields[i]);
2044
2045 if ((i + 1) < orderByFields.length) {
2046 if (orderByComparator.isAscending() ^ previous) {
2047 query.append(ORDER_BY_ASC_HAS_NEXT);
2048 }
2049 else {
2050 query.append(ORDER_BY_DESC_HAS_NEXT);
2051 }
2052 }
2053 else {
2054 if (orderByComparator.isAscending() ^ previous) {
2055 query.append(ORDER_BY_ASC);
2056 }
2057 else {
2058 query.append(ORDER_BY_DESC);
2059 }
2060 }
2061 }
2062 }
2063 else {
2064 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2065 }
2066
2067 String sql = query.toString();
2068
2069 Query q = session.createQuery(sql);
2070
2071 q.setFirstResult(0);
2072 q.setMaxResults(2);
2073
2074 QueryPos qPos = QueryPos.getInstance(q);
2075
2076 qPos.add(userId);
2077
2078 qPos.add(archived);
2079
2080 if (orderByComparator != null) {
2081 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
2082
2083 for (Object value : values) {
2084 qPos.add(value);
2085 }
2086 }
2087
2088 List<UserNotificationEvent> list = q.list();
2089
2090 if (list.size() == 2) {
2091 return list.get(1);
2092 }
2093 else {
2094 return null;
2095 }
2096 }
2097
2098
2105 public void removeByU_A(long userId, boolean archived)
2106 throws SystemException {
2107 for (UserNotificationEvent userNotificationEvent : findByU_A(userId,
2108 archived, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2109 remove(userNotificationEvent);
2110 }
2111 }
2112
2113
2121 public int countByU_A(long userId, boolean archived)
2122 throws SystemException {
2123 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_A;
2124
2125 Object[] finderArgs = new Object[] { userId, archived };
2126
2127 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2128 this);
2129
2130 if (count == null) {
2131 StringBundler query = new StringBundler(3);
2132
2133 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2134
2135 query.append(_FINDER_COLUMN_U_A_USERID_2);
2136
2137 query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
2138
2139 String sql = query.toString();
2140
2141 Session session = null;
2142
2143 try {
2144 session = openSession();
2145
2146 Query q = session.createQuery(sql);
2147
2148 QueryPos qPos = QueryPos.getInstance(q);
2149
2150 qPos.add(userId);
2151
2152 qPos.add(archived);
2153
2154 count = (Long)q.uniqueResult();
2155
2156 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2157 }
2158 catch (Exception e) {
2159 FinderCacheUtil.removeResult(finderPath, finderArgs);
2160
2161 throw processException(e);
2162 }
2163 finally {
2164 closeSession(session);
2165 }
2166 }
2167
2168 return count.intValue();
2169 }
2170
2171 private static final String _FINDER_COLUMN_U_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
2172 private static final String _FINDER_COLUMN_U_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
2173
2174
2179 public void cacheResult(UserNotificationEvent userNotificationEvent) {
2180 EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2181 UserNotificationEventImpl.class,
2182 userNotificationEvent.getPrimaryKey(), userNotificationEvent);
2183
2184 userNotificationEvent.resetOriginalValues();
2185 }
2186
2187
2192 public void cacheResult(List<UserNotificationEvent> userNotificationEvents) {
2193 for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
2194 if (EntityCacheUtil.getResult(
2195 UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2196 UserNotificationEventImpl.class,
2197 userNotificationEvent.getPrimaryKey()) == null) {
2198 cacheResult(userNotificationEvent);
2199 }
2200 else {
2201 userNotificationEvent.resetOriginalValues();
2202 }
2203 }
2204 }
2205
2206
2213 @Override
2214 public void clearCache() {
2215 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2216 CacheRegistryUtil.clear(UserNotificationEventImpl.class.getName());
2217 }
2218
2219 EntityCacheUtil.clearCache(UserNotificationEventImpl.class.getName());
2220
2221 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2223 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2224 }
2225
2226
2233 @Override
2234 public void clearCache(UserNotificationEvent userNotificationEvent) {
2235 EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2236 UserNotificationEventImpl.class,
2237 userNotificationEvent.getPrimaryKey());
2238
2239 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2240 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2241 }
2242
2243 @Override
2244 public void clearCache(List<UserNotificationEvent> userNotificationEvents) {
2245 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2246 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2247
2248 for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
2249 EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2250 UserNotificationEventImpl.class,
2251 userNotificationEvent.getPrimaryKey());
2252 }
2253 }
2254
2255
2261 public UserNotificationEvent create(long userNotificationEventId) {
2262 UserNotificationEvent userNotificationEvent = new UserNotificationEventImpl();
2263
2264 userNotificationEvent.setNew(true);
2265 userNotificationEvent.setPrimaryKey(userNotificationEventId);
2266
2267 String uuid = PortalUUIDUtil.generate();
2268
2269 userNotificationEvent.setUuid(uuid);
2270
2271 return userNotificationEvent;
2272 }
2273
2274
2282 public UserNotificationEvent remove(long userNotificationEventId)
2283 throws NoSuchUserNotificationEventException, SystemException {
2284 return remove((Serializable)userNotificationEventId);
2285 }
2286
2287
2295 @Override
2296 public UserNotificationEvent remove(Serializable primaryKey)
2297 throws NoSuchUserNotificationEventException, SystemException {
2298 Session session = null;
2299
2300 try {
2301 session = openSession();
2302
2303 UserNotificationEvent userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2304 primaryKey);
2305
2306 if (userNotificationEvent == null) {
2307 if (_log.isWarnEnabled()) {
2308 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2309 }
2310
2311 throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2312 primaryKey);
2313 }
2314
2315 return remove(userNotificationEvent);
2316 }
2317 catch (NoSuchUserNotificationEventException nsee) {
2318 throw nsee;
2319 }
2320 catch (Exception e) {
2321 throw processException(e);
2322 }
2323 finally {
2324 closeSession(session);
2325 }
2326 }
2327
2328 @Override
2329 protected UserNotificationEvent removeImpl(
2330 UserNotificationEvent userNotificationEvent) throws SystemException {
2331 userNotificationEvent = toUnwrappedModel(userNotificationEvent);
2332
2333 Session session = null;
2334
2335 try {
2336 session = openSession();
2337
2338 if (!session.contains(userNotificationEvent)) {
2339 userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2340 userNotificationEvent.getPrimaryKeyObj());
2341 }
2342
2343 if (userNotificationEvent != null) {
2344 session.delete(userNotificationEvent);
2345 }
2346 }
2347 catch (Exception e) {
2348 throw processException(e);
2349 }
2350 finally {
2351 closeSession(session);
2352 }
2353
2354 if (userNotificationEvent != null) {
2355 clearCache(userNotificationEvent);
2356 }
2357
2358 return userNotificationEvent;
2359 }
2360
2361 @Override
2362 public UserNotificationEvent updateImpl(
2363 com.liferay.portal.model.UserNotificationEvent userNotificationEvent)
2364 throws SystemException {
2365 userNotificationEvent = toUnwrappedModel(userNotificationEvent);
2366
2367 boolean isNew = userNotificationEvent.isNew();
2368
2369 UserNotificationEventModelImpl userNotificationEventModelImpl = (UserNotificationEventModelImpl)userNotificationEvent;
2370
2371 if (Validator.isNull(userNotificationEvent.getUuid())) {
2372 String uuid = PortalUUIDUtil.generate();
2373
2374 userNotificationEvent.setUuid(uuid);
2375 }
2376
2377 Session session = null;
2378
2379 try {
2380 session = openSession();
2381
2382 if (userNotificationEvent.isNew()) {
2383 session.save(userNotificationEvent);
2384
2385 userNotificationEvent.setNew(false);
2386 }
2387 else {
2388 session.merge(userNotificationEvent);
2389 }
2390 }
2391 catch (Exception e) {
2392 throw processException(e);
2393 }
2394 finally {
2395 closeSession(session);
2396 }
2397
2398 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2399
2400 if (isNew || !UserNotificationEventModelImpl.COLUMN_BITMASK_ENABLED) {
2401 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2402 }
2403
2404 else {
2405 if ((userNotificationEventModelImpl.getColumnBitmask() &
2406 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2407 Object[] args = new Object[] {
2408 userNotificationEventModelImpl.getOriginalUuid()
2409 };
2410
2411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2412 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2413 args);
2414
2415 args = new Object[] { userNotificationEventModelImpl.getUuid() };
2416
2417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2418 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2419 args);
2420 }
2421
2422 if ((userNotificationEventModelImpl.getColumnBitmask() &
2423 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2424 Object[] args = new Object[] {
2425 userNotificationEventModelImpl.getOriginalUuid(),
2426 userNotificationEventModelImpl.getOriginalCompanyId()
2427 };
2428
2429 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2430 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2431 args);
2432
2433 args = new Object[] {
2434 userNotificationEventModelImpl.getUuid(),
2435 userNotificationEventModelImpl.getCompanyId()
2436 };
2437
2438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2439 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2440 args);
2441 }
2442
2443 if ((userNotificationEventModelImpl.getColumnBitmask() &
2444 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2445 Object[] args = new Object[] {
2446 userNotificationEventModelImpl.getOriginalUserId()
2447 };
2448
2449 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2450 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2451 args);
2452
2453 args = new Object[] { userNotificationEventModelImpl.getUserId() };
2454
2455 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2456 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2457 args);
2458 }
2459
2460 if ((userNotificationEventModelImpl.getColumnBitmask() &
2461 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A.getColumnBitmask()) != 0) {
2462 Object[] args = new Object[] {
2463 userNotificationEventModelImpl.getOriginalUserId(),
2464 userNotificationEventModelImpl.getOriginalArchived()
2465 };
2466
2467 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
2468 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
2469 args);
2470
2471 args = new Object[] {
2472 userNotificationEventModelImpl.getUserId(),
2473 userNotificationEventModelImpl.getArchived()
2474 };
2475
2476 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
2477 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
2478 args);
2479 }
2480 }
2481
2482 EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2483 UserNotificationEventImpl.class,
2484 userNotificationEvent.getPrimaryKey(), userNotificationEvent);
2485
2486 return userNotificationEvent;
2487 }
2488
2489 protected UserNotificationEvent toUnwrappedModel(
2490 UserNotificationEvent userNotificationEvent) {
2491 if (userNotificationEvent instanceof UserNotificationEventImpl) {
2492 return userNotificationEvent;
2493 }
2494
2495 UserNotificationEventImpl userNotificationEventImpl = new UserNotificationEventImpl();
2496
2497 userNotificationEventImpl.setNew(userNotificationEvent.isNew());
2498 userNotificationEventImpl.setPrimaryKey(userNotificationEvent.getPrimaryKey());
2499
2500 userNotificationEventImpl.setUuid(userNotificationEvent.getUuid());
2501 userNotificationEventImpl.setUserNotificationEventId(userNotificationEvent.getUserNotificationEventId());
2502 userNotificationEventImpl.setCompanyId(userNotificationEvent.getCompanyId());
2503 userNotificationEventImpl.setUserId(userNotificationEvent.getUserId());
2504 userNotificationEventImpl.setType(userNotificationEvent.getType());
2505 userNotificationEventImpl.setTimestamp(userNotificationEvent.getTimestamp());
2506 userNotificationEventImpl.setDeliverBy(userNotificationEvent.getDeliverBy());
2507 userNotificationEventImpl.setPayload(userNotificationEvent.getPayload());
2508 userNotificationEventImpl.setArchived(userNotificationEvent.isArchived());
2509
2510 return userNotificationEventImpl;
2511 }
2512
2513
2521 @Override
2522 public UserNotificationEvent findByPrimaryKey(Serializable primaryKey)
2523 throws NoSuchUserNotificationEventException, SystemException {
2524 UserNotificationEvent userNotificationEvent = fetchByPrimaryKey(primaryKey);
2525
2526 if (userNotificationEvent == null) {
2527 if (_log.isWarnEnabled()) {
2528 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2529 }
2530
2531 throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2532 primaryKey);
2533 }
2534
2535 return userNotificationEvent;
2536 }
2537
2538
2546 public UserNotificationEvent findByPrimaryKey(long userNotificationEventId)
2547 throws NoSuchUserNotificationEventException, SystemException {
2548 return findByPrimaryKey((Serializable)userNotificationEventId);
2549 }
2550
2551
2558 @Override
2559 public UserNotificationEvent fetchByPrimaryKey(Serializable primaryKey)
2560 throws SystemException {
2561 UserNotificationEvent userNotificationEvent = (UserNotificationEvent)EntityCacheUtil.getResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2562 UserNotificationEventImpl.class, primaryKey);
2563
2564 if (userNotificationEvent == _nullUserNotificationEvent) {
2565 return null;
2566 }
2567
2568 if (userNotificationEvent == null) {
2569 Session session = null;
2570
2571 try {
2572 session = openSession();
2573
2574 userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2575 primaryKey);
2576
2577 if (userNotificationEvent != null) {
2578 cacheResult(userNotificationEvent);
2579 }
2580 else {
2581 EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2582 UserNotificationEventImpl.class, primaryKey,
2583 _nullUserNotificationEvent);
2584 }
2585 }
2586 catch (Exception e) {
2587 EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2588 UserNotificationEventImpl.class, primaryKey);
2589
2590 throw processException(e);
2591 }
2592 finally {
2593 closeSession(session);
2594 }
2595 }
2596
2597 return userNotificationEvent;
2598 }
2599
2600
2607 public UserNotificationEvent fetchByPrimaryKey(long userNotificationEventId)
2608 throws SystemException {
2609 return fetchByPrimaryKey((Serializable)userNotificationEventId);
2610 }
2611
2612
2618 public List<UserNotificationEvent> findAll() throws SystemException {
2619 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2620 }
2621
2622
2634 public List<UserNotificationEvent> findAll(int start, int end)
2635 throws SystemException {
2636 return findAll(start, end, null);
2637 }
2638
2639
2652 public List<UserNotificationEvent> findAll(int start, int end,
2653 OrderByComparator orderByComparator) throws SystemException {
2654 boolean pagination = true;
2655 FinderPath finderPath = null;
2656 Object[] finderArgs = null;
2657
2658 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2659 (orderByComparator == null)) {
2660 pagination = false;
2661 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2662 finderArgs = FINDER_ARGS_EMPTY;
2663 }
2664 else {
2665 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2666 finderArgs = new Object[] { start, end, orderByComparator };
2667 }
2668
2669 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
2670 finderArgs, this);
2671
2672 if (list == null) {
2673 StringBundler query = null;
2674 String sql = null;
2675
2676 if (orderByComparator != null) {
2677 query = new StringBundler(2 +
2678 (orderByComparator.getOrderByFields().length * 3));
2679
2680 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT);
2681
2682 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2683 orderByComparator);
2684
2685 sql = query.toString();
2686 }
2687 else {
2688 sql = _SQL_SELECT_USERNOTIFICATIONEVENT;
2689
2690 if (pagination) {
2691 sql = sql.concat(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2692 }
2693 }
2694
2695 Session session = null;
2696
2697 try {
2698 session = openSession();
2699
2700 Query q = session.createQuery(sql);
2701
2702 if (!pagination) {
2703 list = (List<UserNotificationEvent>)QueryUtil.list(q,
2704 getDialect(), start, end, false);
2705
2706 Collections.sort(list);
2707
2708 list = new UnmodifiableList<UserNotificationEvent>(list);
2709 }
2710 else {
2711 list = (List<UserNotificationEvent>)QueryUtil.list(q,
2712 getDialect(), start, end);
2713 }
2714
2715 cacheResult(list);
2716
2717 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2718 }
2719 catch (Exception e) {
2720 FinderCacheUtil.removeResult(finderPath, finderArgs);
2721
2722 throw processException(e);
2723 }
2724 finally {
2725 closeSession(session);
2726 }
2727 }
2728
2729 return list;
2730 }
2731
2732
2737 public void removeAll() throws SystemException {
2738 for (UserNotificationEvent userNotificationEvent : findAll()) {
2739 remove(userNotificationEvent);
2740 }
2741 }
2742
2743
2749 public int countAll() throws SystemException {
2750 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2751 FINDER_ARGS_EMPTY, this);
2752
2753 if (count == null) {
2754 Session session = null;
2755
2756 try {
2757 session = openSession();
2758
2759 Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONEVENT);
2760
2761 count = (Long)q.uniqueResult();
2762
2763 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2764 FINDER_ARGS_EMPTY, count);
2765 }
2766 catch (Exception e) {
2767 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2768 FINDER_ARGS_EMPTY);
2769
2770 throw processException(e);
2771 }
2772 finally {
2773 closeSession(session);
2774 }
2775 }
2776
2777 return count.intValue();
2778 }
2779
2780
2783 public void afterPropertiesSet() {
2784 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2785 com.liferay.portal.util.PropsUtil.get(
2786 "value.object.listener.com.liferay.portal.model.UserNotificationEvent")));
2787
2788 if (listenerClassNames.length > 0) {
2789 try {
2790 List<ModelListener<UserNotificationEvent>> listenersList = new ArrayList<ModelListener<UserNotificationEvent>>();
2791
2792 for (String listenerClassName : listenerClassNames) {
2793 listenersList.add((ModelListener<UserNotificationEvent>)InstanceFactory.newInstance(
2794 listenerClassName));
2795 }
2796
2797 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2798 }
2799 catch (Exception e) {
2800 _log.error(e);
2801 }
2802 }
2803 }
2804
2805 public void destroy() {
2806 EntityCacheUtil.removeCache(UserNotificationEventImpl.class.getName());
2807 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2808 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2809 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2810 }
2811
2812 private static final String _SQL_SELECT_USERNOTIFICATIONEVENT = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent";
2813 private static final String _SQL_SELECT_USERNOTIFICATIONEVENT_WHERE = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent WHERE ";
2814 private static final String _SQL_COUNT_USERNOTIFICATIONEVENT = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent";
2815 private static final String _SQL_COUNT_USERNOTIFICATIONEVENT_WHERE = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent WHERE ";
2816 private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationEvent.";
2817 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationEvent exists with the primary key ";
2818 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationEvent exists with the key {";
2819 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2820 private static Log _log = LogFactoryUtil.getLog(UserNotificationEventPersistenceImpl.class);
2821 private static UserNotificationEvent _nullUserNotificationEvent = new UserNotificationEventImpl() {
2822 @Override
2823 public Object clone() {
2824 return this;
2825 }
2826
2827 @Override
2828 public CacheModel<UserNotificationEvent> toCacheModel() {
2829 return _nullUserNotificationEventCacheModel;
2830 }
2831 };
2832
2833 private static CacheModel<UserNotificationEvent> _nullUserNotificationEventCacheModel =
2834 new CacheModel<UserNotificationEvent>() {
2835 public UserNotificationEvent toEntityModel() {
2836 return _nullUserNotificationEvent;
2837 }
2838 };
2839 }