001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchUserNotificationEventException;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
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.StringUtil;
036 import com.liferay.portal.kernel.util.UnmodifiableList;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.ModelListener;
041 import com.liferay.portal.model.UserNotificationEvent;
042 import com.liferay.portal.model.impl.UserNotificationEventImpl;
043 import com.liferay.portal.model.impl.UserNotificationEventModelImpl;
044 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
045
046 import java.io.Serializable;
047
048 import java.util.ArrayList;
049 import java.util.Collections;
050 import java.util.List;
051
052
064 public class UserNotificationEventPersistenceImpl extends BasePersistenceImpl<UserNotificationEvent>
065 implements UserNotificationEventPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = UserNotificationEventImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
077 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
078 UserNotificationEventImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
081 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
082 UserNotificationEventImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
085 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
088 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
089 UserNotificationEventImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
091 new String[] {
092 String.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
098 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
099 UserNotificationEventImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
101 new String[] { String.class.getName() },
102 UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
103 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
105 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
107 new String[] { String.class.getName() });
108
109
116 public List<UserNotificationEvent> findByUuid(String uuid)
117 throws SystemException {
118 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<UserNotificationEvent> findByUuid(String uuid, int start,
135 int end) throws SystemException {
136 return findByUuid(uuid, start, end, null);
137 }
138
139
153 public List<UserNotificationEvent> findByUuid(String uuid, int start,
154 int end, OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid, start, end, orderByComparator };
168 }
169
170 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (UserNotificationEvent userNotificationEvent : list) {
175 if (!Validator.equals(uuid, userNotificationEvent.getUuid())) {
176 list = null;
177
178 break;
179 }
180 }
181 }
182
183 if (list == null) {
184 StringBundler query = null;
185
186 if (orderByComparator != null) {
187 query = new StringBundler(3 +
188 (orderByComparator.getOrderByFields().length * 3));
189 }
190 else {
191 query = new StringBundler(3);
192 }
193
194 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
195
196 if (uuid == null) {
197 query.append(_FINDER_COLUMN_UUID_UUID_1);
198 }
199 else {
200 if (uuid.equals(StringPool.BLANK)) {
201 query.append(_FINDER_COLUMN_UUID_UUID_3);
202 }
203 else {
204 query.append(_FINDER_COLUMN_UUID_UUID_2);
205 }
206 }
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 if (uuid != null) {
229 qPos.add(uuid);
230 }
231
232 if (!pagination) {
233 list = (List<UserNotificationEvent>)QueryUtil.list(q,
234 getDialect(), start, end, false);
235
236 Collections.sort(list);
237
238 list = new UnmodifiableList<UserNotificationEvent>(list);
239 }
240 else {
241 list = (List<UserNotificationEvent>)QueryUtil.list(q,
242 getDialect(), start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
271 public UserNotificationEvent findByUuid_First(String uuid,
272 OrderByComparator orderByComparator)
273 throws NoSuchUserNotificationEventException, SystemException {
274 UserNotificationEvent userNotificationEvent = fetchByUuid_First(uuid,
275 orderByComparator);
276
277 if (userNotificationEvent != null) {
278 return userNotificationEvent;
279 }
280
281 StringBundler msg = new StringBundler(4);
282
283 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
284
285 msg.append("uuid=");
286 msg.append(uuid);
287
288 msg.append(StringPool.CLOSE_CURLY_BRACE);
289
290 throw new NoSuchUserNotificationEventException(msg.toString());
291 }
292
293
301 public UserNotificationEvent fetchByUuid_First(String uuid,
302 OrderByComparator orderByComparator) throws SystemException {
303 List<UserNotificationEvent> list = findByUuid(uuid, 0, 1,
304 orderByComparator);
305
306 if (!list.isEmpty()) {
307 return list.get(0);
308 }
309
310 return null;
311 }
312
313
322 public UserNotificationEvent findByUuid_Last(String uuid,
323 OrderByComparator orderByComparator)
324 throws NoSuchUserNotificationEventException, SystemException {
325 UserNotificationEvent userNotificationEvent = fetchByUuid_Last(uuid,
326 orderByComparator);
327
328 if (userNotificationEvent != null) {
329 return userNotificationEvent;
330 }
331
332 StringBundler msg = new StringBundler(4);
333
334 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
335
336 msg.append("uuid=");
337 msg.append(uuid);
338
339 msg.append(StringPool.CLOSE_CURLY_BRACE);
340
341 throw new NoSuchUserNotificationEventException(msg.toString());
342 }
343
344
352 public UserNotificationEvent fetchByUuid_Last(String uuid,
353 OrderByComparator orderByComparator) throws SystemException {
354 int count = countByUuid(uuid);
355
356 List<UserNotificationEvent> list = findByUuid(uuid, count - 1, count,
357 orderByComparator);
358
359 if (!list.isEmpty()) {
360 return list.get(0);
361 }
362
363 return null;
364 }
365
366
376 public UserNotificationEvent[] findByUuid_PrevAndNext(
377 long userNotificationEventId, String uuid,
378 OrderByComparator orderByComparator)
379 throws NoSuchUserNotificationEventException, SystemException {
380 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
381
382 Session session = null;
383
384 try {
385 session = openSession();
386
387 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
388
389 array[0] = getByUuid_PrevAndNext(session, userNotificationEvent,
390 uuid, orderByComparator, true);
391
392 array[1] = userNotificationEvent;
393
394 array[2] = getByUuid_PrevAndNext(session, userNotificationEvent,
395 uuid, orderByComparator, false);
396
397 return array;
398 }
399 catch (Exception e) {
400 throw processException(e);
401 }
402 finally {
403 closeSession(session);
404 }
405 }
406
407 protected UserNotificationEvent getByUuid_PrevAndNext(Session session,
408 UserNotificationEvent userNotificationEvent, String uuid,
409 OrderByComparator orderByComparator, boolean previous) {
410 StringBundler query = null;
411
412 if (orderByComparator != null) {
413 query = new StringBundler(6 +
414 (orderByComparator.getOrderByFields().length * 6));
415 }
416 else {
417 query = new StringBundler(3);
418 }
419
420 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
421
422 if (uuid == null) {
423 query.append(_FINDER_COLUMN_UUID_UUID_1);
424 }
425 else {
426 if (uuid.equals(StringPool.BLANK)) {
427 query.append(_FINDER_COLUMN_UUID_UUID_3);
428 }
429 else {
430 query.append(_FINDER_COLUMN_UUID_UUID_2);
431 }
432 }
433
434 if (orderByComparator != null) {
435 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
436
437 if (orderByConditionFields.length > 0) {
438 query.append(WHERE_AND);
439 }
440
441 for (int i = 0; i < orderByConditionFields.length; i++) {
442 query.append(_ORDER_BY_ENTITY_ALIAS);
443 query.append(orderByConditionFields[i]);
444
445 if ((i + 1) < orderByConditionFields.length) {
446 if (orderByComparator.isAscending() ^ previous) {
447 query.append(WHERE_GREATER_THAN_HAS_NEXT);
448 }
449 else {
450 query.append(WHERE_LESSER_THAN_HAS_NEXT);
451 }
452 }
453 else {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN);
459 }
460 }
461 }
462
463 query.append(ORDER_BY_CLAUSE);
464
465 String[] orderByFields = orderByComparator.getOrderByFields();
466
467 for (int i = 0; i < orderByFields.length; i++) {
468 query.append(_ORDER_BY_ENTITY_ALIAS);
469 query.append(orderByFields[i]);
470
471 if ((i + 1) < orderByFields.length) {
472 if (orderByComparator.isAscending() ^ previous) {
473 query.append(ORDER_BY_ASC_HAS_NEXT);
474 }
475 else {
476 query.append(ORDER_BY_DESC_HAS_NEXT);
477 }
478 }
479 else {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC);
482 }
483 else {
484 query.append(ORDER_BY_DESC);
485 }
486 }
487 }
488 }
489 else {
490 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 q.setFirstResult(0);
498 q.setMaxResults(2);
499
500 QueryPos qPos = QueryPos.getInstance(q);
501
502 if (uuid != null) {
503 qPos.add(uuid);
504 }
505
506 if (orderByComparator != null) {
507 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
508
509 for (Object value : values) {
510 qPos.add(value);
511 }
512 }
513
514 List<UserNotificationEvent> list = q.list();
515
516 if (list.size() == 2) {
517 return list.get(1);
518 }
519 else {
520 return null;
521 }
522 }
523
524
530 public void removeByUuid(String uuid) throws SystemException {
531 for (UserNotificationEvent userNotificationEvent : findByUuid(uuid,
532 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
533 remove(userNotificationEvent);
534 }
535 }
536
537
544 public int countByUuid(String uuid) throws SystemException {
545 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
546
547 Object[] finderArgs = new Object[] { uuid };
548
549 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
550 this);
551
552 if (count == null) {
553 StringBundler query = new StringBundler(2);
554
555 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
556
557 if (uuid == null) {
558 query.append(_FINDER_COLUMN_UUID_UUID_1);
559 }
560 else {
561 if (uuid.equals(StringPool.BLANK)) {
562 query.append(_FINDER_COLUMN_UUID_UUID_3);
563 }
564 else {
565 query.append(_FINDER_COLUMN_UUID_UUID_2);
566 }
567 }
568
569 String sql = query.toString();
570
571 Session session = null;
572
573 try {
574 session = openSession();
575
576 Query q = session.createQuery(sql);
577
578 QueryPos qPos = QueryPos.getInstance(q);
579
580 if (uuid != null) {
581 qPos.add(uuid);
582 }
583
584 count = (Long)q.uniqueResult();
585
586 FinderCacheUtil.putResult(finderPath, finderArgs, count);
587 }
588 catch (Exception e) {
589 FinderCacheUtil.removeResult(finderPath, finderArgs);
590
591 throw processException(e);
592 }
593 finally {
594 closeSession(session);
595 }
596 }
597
598 return count.intValue();
599 }
600
601 private static final String _FINDER_COLUMN_UUID_UUID_1 = "userNotificationEvent.uuid IS NULL";
602 private static final String _FINDER_COLUMN_UUID_UUID_2 = "userNotificationEvent.uuid = ?";
603 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = ?)";
604 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
605 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
606 UserNotificationEventImpl.class,
607 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
608 new String[] {
609 String.class.getName(), Long.class.getName(),
610
611 Integer.class.getName(), Integer.class.getName(),
612 OrderByComparator.class.getName()
613 });
614 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
615 new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
616 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
617 UserNotificationEventImpl.class,
618 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
619 new String[] { String.class.getName(), Long.class.getName() },
620 UserNotificationEventModelImpl.UUID_COLUMN_BITMASK |
621 UserNotificationEventModelImpl.COMPANYID_COLUMN_BITMASK |
622 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
623 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
624 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
625 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
626 new String[] { String.class.getName(), Long.class.getName() });
627
628
636 public List<UserNotificationEvent> findByUuid_C(String uuid, long companyId)
637 throws SystemException {
638 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
639 QueryUtil.ALL_POS, null);
640 }
641
642
656 public List<UserNotificationEvent> findByUuid_C(String uuid,
657 long companyId, int start, int end) throws SystemException {
658 return findByUuid_C(uuid, companyId, start, end, null);
659 }
660
661
676 public List<UserNotificationEvent> findByUuid_C(String uuid,
677 long companyId, int start, int end, OrderByComparator orderByComparator)
678 throws SystemException {
679 boolean pagination = true;
680 FinderPath finderPath = null;
681 Object[] finderArgs = null;
682
683 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
684 (orderByComparator == null)) {
685 pagination = false;
686 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
687 finderArgs = new Object[] { uuid, companyId };
688 }
689 else {
690 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
691 finderArgs = new Object[] {
692 uuid, companyId,
693
694 start, end, orderByComparator
695 };
696 }
697
698 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
699 finderArgs, this);
700
701 if ((list != null) && !list.isEmpty()) {
702 for (UserNotificationEvent userNotificationEvent : list) {
703 if (!Validator.equals(uuid, userNotificationEvent.getUuid()) ||
704 (companyId != userNotificationEvent.getCompanyId())) {
705 list = null;
706
707 break;
708 }
709 }
710 }
711
712 if (list == null) {
713 StringBundler query = null;
714
715 if (orderByComparator != null) {
716 query = new StringBundler(4 +
717 (orderByComparator.getOrderByFields().length * 3));
718 }
719 else {
720 query = new StringBundler(4);
721 }
722
723 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
724
725 if (uuid == null) {
726 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
727 }
728 else {
729 if (uuid.equals(StringPool.BLANK)) {
730 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
731 }
732 else {
733 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
734 }
735 }
736
737 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
738
739 if (orderByComparator != null) {
740 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
741 orderByComparator);
742 }
743 else
744 if (pagination) {
745 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
746 }
747
748 String sql = query.toString();
749
750 Session session = null;
751
752 try {
753 session = openSession();
754
755 Query q = session.createQuery(sql);
756
757 QueryPos qPos = QueryPos.getInstance(q);
758
759 if (uuid != null) {
760 qPos.add(uuid);
761 }
762
763 qPos.add(companyId);
764
765 if (!pagination) {
766 list = (List<UserNotificationEvent>)QueryUtil.list(q,
767 getDialect(), start, end, false);
768
769 Collections.sort(list);
770
771 list = new UnmodifiableList<UserNotificationEvent>(list);
772 }
773 else {
774 list = (List<UserNotificationEvent>)QueryUtil.list(q,
775 getDialect(), start, end);
776 }
777
778 cacheResult(list);
779
780 FinderCacheUtil.putResult(finderPath, finderArgs, list);
781 }
782 catch (Exception e) {
783 FinderCacheUtil.removeResult(finderPath, finderArgs);
784
785 throw processException(e);
786 }
787 finally {
788 closeSession(session);
789 }
790 }
791
792 return list;
793 }
794
795
805 public UserNotificationEvent findByUuid_C_First(String uuid,
806 long companyId, OrderByComparator orderByComparator)
807 throws NoSuchUserNotificationEventException, SystemException {
808 UserNotificationEvent userNotificationEvent = fetchByUuid_C_First(uuid,
809 companyId, orderByComparator);
810
811 if (userNotificationEvent != null) {
812 return userNotificationEvent;
813 }
814
815 StringBundler msg = new StringBundler(6);
816
817 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
818
819 msg.append("uuid=");
820 msg.append(uuid);
821
822 msg.append(", companyId=");
823 msg.append(companyId);
824
825 msg.append(StringPool.CLOSE_CURLY_BRACE);
826
827 throw new NoSuchUserNotificationEventException(msg.toString());
828 }
829
830
839 public UserNotificationEvent fetchByUuid_C_First(String uuid,
840 long companyId, OrderByComparator orderByComparator)
841 throws SystemException {
842 List<UserNotificationEvent> list = findByUuid_C(uuid, companyId, 0, 1,
843 orderByComparator);
844
845 if (!list.isEmpty()) {
846 return list.get(0);
847 }
848
849 return null;
850 }
851
852
862 public UserNotificationEvent findByUuid_C_Last(String uuid, long companyId,
863 OrderByComparator orderByComparator)
864 throws NoSuchUserNotificationEventException, SystemException {
865 UserNotificationEvent userNotificationEvent = fetchByUuid_C_Last(uuid,
866 companyId, orderByComparator);
867
868 if (userNotificationEvent != null) {
869 return userNotificationEvent;
870 }
871
872 StringBundler msg = new StringBundler(6);
873
874 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
875
876 msg.append("uuid=");
877 msg.append(uuid);
878
879 msg.append(", companyId=");
880 msg.append(companyId);
881
882 msg.append(StringPool.CLOSE_CURLY_BRACE);
883
884 throw new NoSuchUserNotificationEventException(msg.toString());
885 }
886
887
896 public UserNotificationEvent fetchByUuid_C_Last(String uuid,
897 long companyId, OrderByComparator orderByComparator)
898 throws SystemException {
899 int count = countByUuid_C(uuid, companyId);
900
901 List<UserNotificationEvent> list = findByUuid_C(uuid, companyId,
902 count - 1, count, orderByComparator);
903
904 if (!list.isEmpty()) {
905 return list.get(0);
906 }
907
908 return null;
909 }
910
911
922 public UserNotificationEvent[] findByUuid_C_PrevAndNext(
923 long userNotificationEventId, String uuid, long companyId,
924 OrderByComparator orderByComparator)
925 throws NoSuchUserNotificationEventException, SystemException {
926 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
927
928 Session session = null;
929
930 try {
931 session = openSession();
932
933 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
934
935 array[0] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
936 uuid, companyId, orderByComparator, true);
937
938 array[1] = userNotificationEvent;
939
940 array[2] = getByUuid_C_PrevAndNext(session, userNotificationEvent,
941 uuid, companyId, orderByComparator, false);
942
943 return array;
944 }
945 catch (Exception e) {
946 throw processException(e);
947 }
948 finally {
949 closeSession(session);
950 }
951 }
952
953 protected UserNotificationEvent getByUuid_C_PrevAndNext(Session session,
954 UserNotificationEvent userNotificationEvent, String uuid,
955 long companyId, OrderByComparator orderByComparator, boolean previous) {
956 StringBundler query = null;
957
958 if (orderByComparator != null) {
959 query = new StringBundler(6 +
960 (orderByComparator.getOrderByFields().length * 6));
961 }
962 else {
963 query = new StringBundler(3);
964 }
965
966 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
967
968 if (uuid == null) {
969 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
970 }
971 else {
972 if (uuid.equals(StringPool.BLANK)) {
973 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
974 }
975 else {
976 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
977 }
978 }
979
980 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
981
982 if (orderByComparator != null) {
983 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
984
985 if (orderByConditionFields.length > 0) {
986 query.append(WHERE_AND);
987 }
988
989 for (int i = 0; i < orderByConditionFields.length; i++) {
990 query.append(_ORDER_BY_ENTITY_ALIAS);
991 query.append(orderByConditionFields[i]);
992
993 if ((i + 1) < orderByConditionFields.length) {
994 if (orderByComparator.isAscending() ^ previous) {
995 query.append(WHERE_GREATER_THAN_HAS_NEXT);
996 }
997 else {
998 query.append(WHERE_LESSER_THAN_HAS_NEXT);
999 }
1000 }
1001 else {
1002 if (orderByComparator.isAscending() ^ previous) {
1003 query.append(WHERE_GREATER_THAN);
1004 }
1005 else {
1006 query.append(WHERE_LESSER_THAN);
1007 }
1008 }
1009 }
1010
1011 query.append(ORDER_BY_CLAUSE);
1012
1013 String[] orderByFields = orderByComparator.getOrderByFields();
1014
1015 for (int i = 0; i < orderByFields.length; i++) {
1016 query.append(_ORDER_BY_ENTITY_ALIAS);
1017 query.append(orderByFields[i]);
1018
1019 if ((i + 1) < orderByFields.length) {
1020 if (orderByComparator.isAscending() ^ previous) {
1021 query.append(ORDER_BY_ASC_HAS_NEXT);
1022 }
1023 else {
1024 query.append(ORDER_BY_DESC_HAS_NEXT);
1025 }
1026 }
1027 else {
1028 if (orderByComparator.isAscending() ^ previous) {
1029 query.append(ORDER_BY_ASC);
1030 }
1031 else {
1032 query.append(ORDER_BY_DESC);
1033 }
1034 }
1035 }
1036 }
1037 else {
1038 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1039 }
1040
1041 String sql = query.toString();
1042
1043 Query q = session.createQuery(sql);
1044
1045 q.setFirstResult(0);
1046 q.setMaxResults(2);
1047
1048 QueryPos qPos = QueryPos.getInstance(q);
1049
1050 if (uuid != null) {
1051 qPos.add(uuid);
1052 }
1053
1054 qPos.add(companyId);
1055
1056 if (orderByComparator != null) {
1057 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1058
1059 for (Object value : values) {
1060 qPos.add(value);
1061 }
1062 }
1063
1064 List<UserNotificationEvent> list = q.list();
1065
1066 if (list.size() == 2) {
1067 return list.get(1);
1068 }
1069 else {
1070 return null;
1071 }
1072 }
1073
1074
1081 public void removeByUuid_C(String uuid, long companyId)
1082 throws SystemException {
1083 for (UserNotificationEvent userNotificationEvent : findByUuid_C(uuid,
1084 companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1085 remove(userNotificationEvent);
1086 }
1087 }
1088
1089
1097 public int countByUuid_C(String uuid, long companyId)
1098 throws SystemException {
1099 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1100
1101 Object[] finderArgs = new Object[] { uuid, companyId };
1102
1103 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1104 this);
1105
1106 if (count == null) {
1107 StringBundler query = new StringBundler(3);
1108
1109 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1110
1111 if (uuid == null) {
1112 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1113 }
1114 else {
1115 if (uuid.equals(StringPool.BLANK)) {
1116 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1117 }
1118 else {
1119 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1120 }
1121 }
1122
1123 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1124
1125 String sql = query.toString();
1126
1127 Session session = null;
1128
1129 try {
1130 session = openSession();
1131
1132 Query q = session.createQuery(sql);
1133
1134 QueryPos qPos = QueryPos.getInstance(q);
1135
1136 if (uuid != null) {
1137 qPos.add(uuid);
1138 }
1139
1140 qPos.add(companyId);
1141
1142 count = (Long)q.uniqueResult();
1143
1144 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1145 }
1146 catch (Exception e) {
1147 FinderCacheUtil.removeResult(finderPath, finderArgs);
1148
1149 throw processException(e);
1150 }
1151 finally {
1152 closeSession(session);
1153 }
1154 }
1155
1156 return count.intValue();
1157 }
1158
1159 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "userNotificationEvent.uuid IS NULL AND ";
1160 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "userNotificationEvent.uuid = ? AND ";
1161 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(userNotificationEvent.uuid IS NULL OR userNotificationEvent.uuid = ?) AND ";
1162 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "userNotificationEvent.companyId = ?";
1163 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1164 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1165 UserNotificationEventImpl.class,
1166 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1167 new String[] {
1168 Long.class.getName(),
1169
1170 Integer.class.getName(), Integer.class.getName(),
1171 OrderByComparator.class.getName()
1172 });
1173 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1174 new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1175 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1176 UserNotificationEventImpl.class,
1177 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1178 new String[] { Long.class.getName() },
1179 UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1180 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1181 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1182 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1183 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1184 new String[] { Long.class.getName() });
1185
1186
1193 public List<UserNotificationEvent> findByUserId(long userId)
1194 throws SystemException {
1195 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1196 }
1197
1198
1211 public List<UserNotificationEvent> findByUserId(long userId, int start,
1212 int end) throws SystemException {
1213 return findByUserId(userId, start, end, null);
1214 }
1215
1216
1230 public List<UserNotificationEvent> findByUserId(long userId, int start,
1231 int end, OrderByComparator orderByComparator) throws SystemException {
1232 boolean pagination = true;
1233 FinderPath finderPath = null;
1234 Object[] finderArgs = null;
1235
1236 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1237 (orderByComparator == null)) {
1238 pagination = false;
1239 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
1240 finderArgs = new Object[] { userId };
1241 }
1242 else {
1243 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
1244 finderArgs = new Object[] { userId, start, end, orderByComparator };
1245 }
1246
1247 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1248 finderArgs, this);
1249
1250 if ((list != null) && !list.isEmpty()) {
1251 for (UserNotificationEvent userNotificationEvent : list) {
1252 if ((userId != userNotificationEvent.getUserId())) {
1253 list = null;
1254
1255 break;
1256 }
1257 }
1258 }
1259
1260 if (list == null) {
1261 StringBundler query = null;
1262
1263 if (orderByComparator != null) {
1264 query = new StringBundler(3 +
1265 (orderByComparator.getOrderByFields().length * 3));
1266 }
1267 else {
1268 query = new StringBundler(3);
1269 }
1270
1271 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1272
1273 query.append(_FINDER_COLUMN_USERID_USERID_2);
1274
1275 if (orderByComparator != null) {
1276 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1277 orderByComparator);
1278 }
1279 else
1280 if (pagination) {
1281 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1282 }
1283
1284 String sql = query.toString();
1285
1286 Session session = null;
1287
1288 try {
1289 session = openSession();
1290
1291 Query q = session.createQuery(sql);
1292
1293 QueryPos qPos = QueryPos.getInstance(q);
1294
1295 qPos.add(userId);
1296
1297 if (!pagination) {
1298 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1299 getDialect(), start, end, false);
1300
1301 Collections.sort(list);
1302
1303 list = new UnmodifiableList<UserNotificationEvent>(list);
1304 }
1305 else {
1306 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1307 getDialect(), start, end);
1308 }
1309
1310 cacheResult(list);
1311
1312 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1313 }
1314 catch (Exception e) {
1315 FinderCacheUtil.removeResult(finderPath, finderArgs);
1316
1317 throw processException(e);
1318 }
1319 finally {
1320 closeSession(session);
1321 }
1322 }
1323
1324 return list;
1325 }
1326
1327
1336 public UserNotificationEvent findByUserId_First(long userId,
1337 OrderByComparator orderByComparator)
1338 throws NoSuchUserNotificationEventException, SystemException {
1339 UserNotificationEvent userNotificationEvent = fetchByUserId_First(userId,
1340 orderByComparator);
1341
1342 if (userNotificationEvent != null) {
1343 return userNotificationEvent;
1344 }
1345
1346 StringBundler msg = new StringBundler(4);
1347
1348 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1349
1350 msg.append("userId=");
1351 msg.append(userId);
1352
1353 msg.append(StringPool.CLOSE_CURLY_BRACE);
1354
1355 throw new NoSuchUserNotificationEventException(msg.toString());
1356 }
1357
1358
1366 public UserNotificationEvent fetchByUserId_First(long userId,
1367 OrderByComparator orderByComparator) throws SystemException {
1368 List<UserNotificationEvent> list = findByUserId(userId, 0, 1,
1369 orderByComparator);
1370
1371 if (!list.isEmpty()) {
1372 return list.get(0);
1373 }
1374
1375 return null;
1376 }
1377
1378
1387 public UserNotificationEvent findByUserId_Last(long userId,
1388 OrderByComparator orderByComparator)
1389 throws NoSuchUserNotificationEventException, SystemException {
1390 UserNotificationEvent userNotificationEvent = fetchByUserId_Last(userId,
1391 orderByComparator);
1392
1393 if (userNotificationEvent != null) {
1394 return userNotificationEvent;
1395 }
1396
1397 StringBundler msg = new StringBundler(4);
1398
1399 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1400
1401 msg.append("userId=");
1402 msg.append(userId);
1403
1404 msg.append(StringPool.CLOSE_CURLY_BRACE);
1405
1406 throw new NoSuchUserNotificationEventException(msg.toString());
1407 }
1408
1409
1417 public UserNotificationEvent fetchByUserId_Last(long userId,
1418 OrderByComparator orderByComparator) throws SystemException {
1419 int count = countByUserId(userId);
1420
1421 List<UserNotificationEvent> list = findByUserId(userId, count - 1,
1422 count, orderByComparator);
1423
1424 if (!list.isEmpty()) {
1425 return list.get(0);
1426 }
1427
1428 return null;
1429 }
1430
1431
1441 public UserNotificationEvent[] findByUserId_PrevAndNext(
1442 long userNotificationEventId, long userId,
1443 OrderByComparator orderByComparator)
1444 throws NoSuchUserNotificationEventException, SystemException {
1445 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1446
1447 Session session = null;
1448
1449 try {
1450 session = openSession();
1451
1452 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1453
1454 array[0] = getByUserId_PrevAndNext(session, userNotificationEvent,
1455 userId, orderByComparator, true);
1456
1457 array[1] = userNotificationEvent;
1458
1459 array[2] = getByUserId_PrevAndNext(session, userNotificationEvent,
1460 userId, orderByComparator, false);
1461
1462 return array;
1463 }
1464 catch (Exception e) {
1465 throw processException(e);
1466 }
1467 finally {
1468 closeSession(session);
1469 }
1470 }
1471
1472 protected UserNotificationEvent getByUserId_PrevAndNext(Session session,
1473 UserNotificationEvent userNotificationEvent, long userId,
1474 OrderByComparator orderByComparator, boolean previous) {
1475 StringBundler query = null;
1476
1477 if (orderByComparator != null) {
1478 query = new StringBundler(6 +
1479 (orderByComparator.getOrderByFields().length * 6));
1480 }
1481 else {
1482 query = new StringBundler(3);
1483 }
1484
1485 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1486
1487 query.append(_FINDER_COLUMN_USERID_USERID_2);
1488
1489 if (orderByComparator != null) {
1490 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1491
1492 if (orderByConditionFields.length > 0) {
1493 query.append(WHERE_AND);
1494 }
1495
1496 for (int i = 0; i < orderByConditionFields.length; i++) {
1497 query.append(_ORDER_BY_ENTITY_ALIAS);
1498 query.append(orderByConditionFields[i]);
1499
1500 if ((i + 1) < orderByConditionFields.length) {
1501 if (orderByComparator.isAscending() ^ previous) {
1502 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1503 }
1504 else {
1505 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1506 }
1507 }
1508 else {
1509 if (orderByComparator.isAscending() ^ previous) {
1510 query.append(WHERE_GREATER_THAN);
1511 }
1512 else {
1513 query.append(WHERE_LESSER_THAN);
1514 }
1515 }
1516 }
1517
1518 query.append(ORDER_BY_CLAUSE);
1519
1520 String[] orderByFields = orderByComparator.getOrderByFields();
1521
1522 for (int i = 0; i < orderByFields.length; i++) {
1523 query.append(_ORDER_BY_ENTITY_ALIAS);
1524 query.append(orderByFields[i]);
1525
1526 if ((i + 1) < orderByFields.length) {
1527 if (orderByComparator.isAscending() ^ previous) {
1528 query.append(ORDER_BY_ASC_HAS_NEXT);
1529 }
1530 else {
1531 query.append(ORDER_BY_DESC_HAS_NEXT);
1532 }
1533 }
1534 else {
1535 if (orderByComparator.isAscending() ^ previous) {
1536 query.append(ORDER_BY_ASC);
1537 }
1538 else {
1539 query.append(ORDER_BY_DESC);
1540 }
1541 }
1542 }
1543 }
1544 else {
1545 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1546 }
1547
1548 String sql = query.toString();
1549
1550 Query q = session.createQuery(sql);
1551
1552 q.setFirstResult(0);
1553 q.setMaxResults(2);
1554
1555 QueryPos qPos = QueryPos.getInstance(q);
1556
1557 qPos.add(userId);
1558
1559 if (orderByComparator != null) {
1560 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
1561
1562 for (Object value : values) {
1563 qPos.add(value);
1564 }
1565 }
1566
1567 List<UserNotificationEvent> list = q.list();
1568
1569 if (list.size() == 2) {
1570 return list.get(1);
1571 }
1572 else {
1573 return null;
1574 }
1575 }
1576
1577
1583 public void removeByUserId(long userId) throws SystemException {
1584 for (UserNotificationEvent userNotificationEvent : findByUserId(
1585 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1586 remove(userNotificationEvent);
1587 }
1588 }
1589
1590
1597 public int countByUserId(long userId) throws SystemException {
1598 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
1599
1600 Object[] finderArgs = new Object[] { userId };
1601
1602 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1603 this);
1604
1605 if (count == null) {
1606 StringBundler query = new StringBundler(2);
1607
1608 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
1609
1610 query.append(_FINDER_COLUMN_USERID_USERID_2);
1611
1612 String sql = query.toString();
1613
1614 Session session = null;
1615
1616 try {
1617 session = openSession();
1618
1619 Query q = session.createQuery(sql);
1620
1621 QueryPos qPos = QueryPos.getInstance(q);
1622
1623 qPos.add(userId);
1624
1625 count = (Long)q.uniqueResult();
1626
1627 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1628 }
1629 catch (Exception e) {
1630 FinderCacheUtil.removeResult(finderPath, finderArgs);
1631
1632 throw processException(e);
1633 }
1634 finally {
1635 closeSession(session);
1636 }
1637 }
1638
1639 return count.intValue();
1640 }
1641
1642 private static final String _FINDER_COLUMN_USERID_USERID_2 = "userNotificationEvent.userId = ?";
1643 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1644 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1645 UserNotificationEventImpl.class,
1646 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_A",
1647 new String[] {
1648 Long.class.getName(), Boolean.class.getName(),
1649
1650 Integer.class.getName(), Integer.class.getName(),
1651 OrderByComparator.class.getName()
1652 });
1653 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1654 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED,
1655 UserNotificationEventImpl.class,
1656 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_A",
1657 new String[] { Long.class.getName(), Boolean.class.getName() },
1658 UserNotificationEventModelImpl.USERID_COLUMN_BITMASK |
1659 UserNotificationEventModelImpl.ARCHIVED_COLUMN_BITMASK |
1660 UserNotificationEventModelImpl.TIMESTAMP_COLUMN_BITMASK);
1661 public static final FinderPath FINDER_PATH_COUNT_BY_U_A = new FinderPath(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
1662 UserNotificationEventModelImpl.FINDER_CACHE_ENABLED, Long.class,
1663 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_A",
1664 new String[] { Long.class.getName(), Boolean.class.getName() });
1665
1666
1674 public List<UserNotificationEvent> findByU_A(long userId, boolean archived)
1675 throws SystemException {
1676 return findByU_A(userId, archived, QueryUtil.ALL_POS,
1677 QueryUtil.ALL_POS, null);
1678 }
1679
1680
1694 public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1695 int start, int end) throws SystemException {
1696 return findByU_A(userId, archived, start, end, null);
1697 }
1698
1699
1714 public List<UserNotificationEvent> findByU_A(long userId, boolean archived,
1715 int start, int end, OrderByComparator orderByComparator)
1716 throws SystemException {
1717 boolean pagination = true;
1718 FinderPath finderPath = null;
1719 Object[] finderArgs = null;
1720
1721 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1722 (orderByComparator == null)) {
1723 pagination = false;
1724 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A;
1725 finderArgs = new Object[] { userId, archived };
1726 }
1727 else {
1728 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_A;
1729 finderArgs = new Object[] {
1730 userId, archived,
1731
1732 start, end, orderByComparator
1733 };
1734 }
1735
1736 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
1737 finderArgs, this);
1738
1739 if ((list != null) && !list.isEmpty()) {
1740 for (UserNotificationEvent userNotificationEvent : list) {
1741 if ((userId != userNotificationEvent.getUserId()) ||
1742 (archived != userNotificationEvent.getArchived())) {
1743 list = null;
1744
1745 break;
1746 }
1747 }
1748 }
1749
1750 if (list == null) {
1751 StringBundler query = null;
1752
1753 if (orderByComparator != null) {
1754 query = new StringBundler(4 +
1755 (orderByComparator.getOrderByFields().length * 3));
1756 }
1757 else {
1758 query = new StringBundler(4);
1759 }
1760
1761 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1762
1763 query.append(_FINDER_COLUMN_U_A_USERID_2);
1764
1765 query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
1766
1767 if (orderByComparator != null) {
1768 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1769 orderByComparator);
1770 }
1771 else
1772 if (pagination) {
1773 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
1774 }
1775
1776 String sql = query.toString();
1777
1778 Session session = null;
1779
1780 try {
1781 session = openSession();
1782
1783 Query q = session.createQuery(sql);
1784
1785 QueryPos qPos = QueryPos.getInstance(q);
1786
1787 qPos.add(userId);
1788
1789 qPos.add(archived);
1790
1791 if (!pagination) {
1792 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1793 getDialect(), start, end, false);
1794
1795 Collections.sort(list);
1796
1797 list = new UnmodifiableList<UserNotificationEvent>(list);
1798 }
1799 else {
1800 list = (List<UserNotificationEvent>)QueryUtil.list(q,
1801 getDialect(), start, end);
1802 }
1803
1804 cacheResult(list);
1805
1806 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1807 }
1808 catch (Exception e) {
1809 FinderCacheUtil.removeResult(finderPath, finderArgs);
1810
1811 throw processException(e);
1812 }
1813 finally {
1814 closeSession(session);
1815 }
1816 }
1817
1818 return list;
1819 }
1820
1821
1831 public UserNotificationEvent findByU_A_First(long userId, boolean archived,
1832 OrderByComparator orderByComparator)
1833 throws NoSuchUserNotificationEventException, SystemException {
1834 UserNotificationEvent userNotificationEvent = fetchByU_A_First(userId,
1835 archived, orderByComparator);
1836
1837 if (userNotificationEvent != null) {
1838 return userNotificationEvent;
1839 }
1840
1841 StringBundler msg = new StringBundler(6);
1842
1843 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1844
1845 msg.append("userId=");
1846 msg.append(userId);
1847
1848 msg.append(", archived=");
1849 msg.append(archived);
1850
1851 msg.append(StringPool.CLOSE_CURLY_BRACE);
1852
1853 throw new NoSuchUserNotificationEventException(msg.toString());
1854 }
1855
1856
1865 public UserNotificationEvent fetchByU_A_First(long userId,
1866 boolean archived, OrderByComparator orderByComparator)
1867 throws SystemException {
1868 List<UserNotificationEvent> list = findByU_A(userId, archived, 0, 1,
1869 orderByComparator);
1870
1871 if (!list.isEmpty()) {
1872 return list.get(0);
1873 }
1874
1875 return null;
1876 }
1877
1878
1888 public UserNotificationEvent findByU_A_Last(long userId, boolean archived,
1889 OrderByComparator orderByComparator)
1890 throws NoSuchUserNotificationEventException, SystemException {
1891 UserNotificationEvent userNotificationEvent = fetchByU_A_Last(userId,
1892 archived, orderByComparator);
1893
1894 if (userNotificationEvent != null) {
1895 return userNotificationEvent;
1896 }
1897
1898 StringBundler msg = new StringBundler(6);
1899
1900 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1901
1902 msg.append("userId=");
1903 msg.append(userId);
1904
1905 msg.append(", archived=");
1906 msg.append(archived);
1907
1908 msg.append(StringPool.CLOSE_CURLY_BRACE);
1909
1910 throw new NoSuchUserNotificationEventException(msg.toString());
1911 }
1912
1913
1922 public UserNotificationEvent fetchByU_A_Last(long userId, boolean archived,
1923 OrderByComparator orderByComparator) throws SystemException {
1924 int count = countByU_A(userId, archived);
1925
1926 List<UserNotificationEvent> list = findByU_A(userId, archived,
1927 count - 1, count, orderByComparator);
1928
1929 if (!list.isEmpty()) {
1930 return list.get(0);
1931 }
1932
1933 return null;
1934 }
1935
1936
1947 public UserNotificationEvent[] findByU_A_PrevAndNext(
1948 long userNotificationEventId, long userId, boolean archived,
1949 OrderByComparator orderByComparator)
1950 throws NoSuchUserNotificationEventException, SystemException {
1951 UserNotificationEvent userNotificationEvent = findByPrimaryKey(userNotificationEventId);
1952
1953 Session session = null;
1954
1955 try {
1956 session = openSession();
1957
1958 UserNotificationEvent[] array = new UserNotificationEventImpl[3];
1959
1960 array[0] = getByU_A_PrevAndNext(session, userNotificationEvent,
1961 userId, archived, orderByComparator, true);
1962
1963 array[1] = userNotificationEvent;
1964
1965 array[2] = getByU_A_PrevAndNext(session, userNotificationEvent,
1966 userId, archived, orderByComparator, false);
1967
1968 return array;
1969 }
1970 catch (Exception e) {
1971 throw processException(e);
1972 }
1973 finally {
1974 closeSession(session);
1975 }
1976 }
1977
1978 protected UserNotificationEvent getByU_A_PrevAndNext(Session session,
1979 UserNotificationEvent userNotificationEvent, long userId,
1980 boolean archived, OrderByComparator orderByComparator, boolean previous) {
1981 StringBundler query = null;
1982
1983 if (orderByComparator != null) {
1984 query = new StringBundler(6 +
1985 (orderByComparator.getOrderByFields().length * 6));
1986 }
1987 else {
1988 query = new StringBundler(3);
1989 }
1990
1991 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT_WHERE);
1992
1993 query.append(_FINDER_COLUMN_U_A_USERID_2);
1994
1995 query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
1996
1997 if (orderByComparator != null) {
1998 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1999
2000 if (orderByConditionFields.length > 0) {
2001 query.append(WHERE_AND);
2002 }
2003
2004 for (int i = 0; i < orderByConditionFields.length; i++) {
2005 query.append(_ORDER_BY_ENTITY_ALIAS);
2006 query.append(orderByConditionFields[i]);
2007
2008 if ((i + 1) < orderByConditionFields.length) {
2009 if (orderByComparator.isAscending() ^ previous) {
2010 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2011 }
2012 else {
2013 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2014 }
2015 }
2016 else {
2017 if (orderByComparator.isAscending() ^ previous) {
2018 query.append(WHERE_GREATER_THAN);
2019 }
2020 else {
2021 query.append(WHERE_LESSER_THAN);
2022 }
2023 }
2024 }
2025
2026 query.append(ORDER_BY_CLAUSE);
2027
2028 String[] orderByFields = orderByComparator.getOrderByFields();
2029
2030 for (int i = 0; i < orderByFields.length; i++) {
2031 query.append(_ORDER_BY_ENTITY_ALIAS);
2032 query.append(orderByFields[i]);
2033
2034 if ((i + 1) < orderByFields.length) {
2035 if (orderByComparator.isAscending() ^ previous) {
2036 query.append(ORDER_BY_ASC_HAS_NEXT);
2037 }
2038 else {
2039 query.append(ORDER_BY_DESC_HAS_NEXT);
2040 }
2041 }
2042 else {
2043 if (orderByComparator.isAscending() ^ previous) {
2044 query.append(ORDER_BY_ASC);
2045 }
2046 else {
2047 query.append(ORDER_BY_DESC);
2048 }
2049 }
2050 }
2051 }
2052 else {
2053 query.append(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2054 }
2055
2056 String sql = query.toString();
2057
2058 Query q = session.createQuery(sql);
2059
2060 q.setFirstResult(0);
2061 q.setMaxResults(2);
2062
2063 QueryPos qPos = QueryPos.getInstance(q);
2064
2065 qPos.add(userId);
2066
2067 qPos.add(archived);
2068
2069 if (orderByComparator != null) {
2070 Object[] values = orderByComparator.getOrderByConditionValues(userNotificationEvent);
2071
2072 for (Object value : values) {
2073 qPos.add(value);
2074 }
2075 }
2076
2077 List<UserNotificationEvent> list = q.list();
2078
2079 if (list.size() == 2) {
2080 return list.get(1);
2081 }
2082 else {
2083 return null;
2084 }
2085 }
2086
2087
2094 public void removeByU_A(long userId, boolean archived)
2095 throws SystemException {
2096 for (UserNotificationEvent userNotificationEvent : findByU_A(userId,
2097 archived, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2098 remove(userNotificationEvent);
2099 }
2100 }
2101
2102
2110 public int countByU_A(long userId, boolean archived)
2111 throws SystemException {
2112 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_A;
2113
2114 Object[] finderArgs = new Object[] { userId, archived };
2115
2116 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2117 this);
2118
2119 if (count == null) {
2120 StringBundler query = new StringBundler(3);
2121
2122 query.append(_SQL_COUNT_USERNOTIFICATIONEVENT_WHERE);
2123
2124 query.append(_FINDER_COLUMN_U_A_USERID_2);
2125
2126 query.append(_FINDER_COLUMN_U_A_ARCHIVED_2);
2127
2128 String sql = query.toString();
2129
2130 Session session = null;
2131
2132 try {
2133 session = openSession();
2134
2135 Query q = session.createQuery(sql);
2136
2137 QueryPos qPos = QueryPos.getInstance(q);
2138
2139 qPos.add(userId);
2140
2141 qPos.add(archived);
2142
2143 count = (Long)q.uniqueResult();
2144
2145 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2146 }
2147 catch (Exception e) {
2148 FinderCacheUtil.removeResult(finderPath, finderArgs);
2149
2150 throw processException(e);
2151 }
2152 finally {
2153 closeSession(session);
2154 }
2155 }
2156
2157 return count.intValue();
2158 }
2159
2160 private static final String _FINDER_COLUMN_U_A_USERID_2 = "userNotificationEvent.userId = ? AND ";
2161 private static final String _FINDER_COLUMN_U_A_ARCHIVED_2 = "userNotificationEvent.archived = ?";
2162
2163
2168 public void cacheResult(UserNotificationEvent userNotificationEvent) {
2169 EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2170 UserNotificationEventImpl.class,
2171 userNotificationEvent.getPrimaryKey(), userNotificationEvent);
2172
2173 userNotificationEvent.resetOriginalValues();
2174 }
2175
2176
2181 public void cacheResult(List<UserNotificationEvent> userNotificationEvents) {
2182 for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
2183 if (EntityCacheUtil.getResult(
2184 UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2185 UserNotificationEventImpl.class,
2186 userNotificationEvent.getPrimaryKey()) == null) {
2187 cacheResult(userNotificationEvent);
2188 }
2189 else {
2190 userNotificationEvent.resetOriginalValues();
2191 }
2192 }
2193 }
2194
2195
2202 @Override
2203 public void clearCache() {
2204 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
2205 CacheRegistryUtil.clear(UserNotificationEventImpl.class.getName());
2206 }
2207
2208 EntityCacheUtil.clearCache(UserNotificationEventImpl.class.getName());
2209
2210 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
2211 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2212 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2213 }
2214
2215
2222 @Override
2223 public void clearCache(UserNotificationEvent userNotificationEvent) {
2224 EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2225 UserNotificationEventImpl.class,
2226 userNotificationEvent.getPrimaryKey());
2227
2228 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2229 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2230 }
2231
2232 @Override
2233 public void clearCache(List<UserNotificationEvent> userNotificationEvents) {
2234 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2235 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2236
2237 for (UserNotificationEvent userNotificationEvent : userNotificationEvents) {
2238 EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2239 UserNotificationEventImpl.class,
2240 userNotificationEvent.getPrimaryKey());
2241 }
2242 }
2243
2244
2250 public UserNotificationEvent create(long userNotificationEventId) {
2251 UserNotificationEvent userNotificationEvent = new UserNotificationEventImpl();
2252
2253 userNotificationEvent.setNew(true);
2254 userNotificationEvent.setPrimaryKey(userNotificationEventId);
2255
2256 String uuid = PortalUUIDUtil.generate();
2257
2258 userNotificationEvent.setUuid(uuid);
2259
2260 return userNotificationEvent;
2261 }
2262
2263
2271 public UserNotificationEvent remove(long userNotificationEventId)
2272 throws NoSuchUserNotificationEventException, SystemException {
2273 return remove(Long.valueOf(userNotificationEventId));
2274 }
2275
2276
2284 @Override
2285 public UserNotificationEvent remove(Serializable primaryKey)
2286 throws NoSuchUserNotificationEventException, SystemException {
2287 Session session = null;
2288
2289 try {
2290 session = openSession();
2291
2292 UserNotificationEvent userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2293 primaryKey);
2294
2295 if (userNotificationEvent == null) {
2296 if (_log.isWarnEnabled()) {
2297 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2298 }
2299
2300 throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2301 primaryKey);
2302 }
2303
2304 return remove(userNotificationEvent);
2305 }
2306 catch (NoSuchUserNotificationEventException nsee) {
2307 throw nsee;
2308 }
2309 catch (Exception e) {
2310 throw processException(e);
2311 }
2312 finally {
2313 closeSession(session);
2314 }
2315 }
2316
2317 @Override
2318 protected UserNotificationEvent removeImpl(
2319 UserNotificationEvent userNotificationEvent) throws SystemException {
2320 userNotificationEvent = toUnwrappedModel(userNotificationEvent);
2321
2322 Session session = null;
2323
2324 try {
2325 session = openSession();
2326
2327 if (!session.contains(userNotificationEvent)) {
2328 userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2329 userNotificationEvent.getPrimaryKeyObj());
2330 }
2331
2332 if (userNotificationEvent != null) {
2333 session.delete(userNotificationEvent);
2334 }
2335 }
2336 catch (Exception e) {
2337 throw processException(e);
2338 }
2339 finally {
2340 closeSession(session);
2341 }
2342
2343 if (userNotificationEvent != null) {
2344 clearCache(userNotificationEvent);
2345 }
2346
2347 return userNotificationEvent;
2348 }
2349
2350 @Override
2351 public UserNotificationEvent updateImpl(
2352 com.liferay.portal.model.UserNotificationEvent userNotificationEvent)
2353 throws SystemException {
2354 userNotificationEvent = toUnwrappedModel(userNotificationEvent);
2355
2356 boolean isNew = userNotificationEvent.isNew();
2357
2358 UserNotificationEventModelImpl userNotificationEventModelImpl = (UserNotificationEventModelImpl)userNotificationEvent;
2359
2360 if (Validator.isNull(userNotificationEvent.getUuid())) {
2361 String uuid = PortalUUIDUtil.generate();
2362
2363 userNotificationEvent.setUuid(uuid);
2364 }
2365
2366 Session session = null;
2367
2368 try {
2369 session = openSession();
2370
2371 if (userNotificationEvent.isNew()) {
2372 session.save(userNotificationEvent);
2373
2374 userNotificationEvent.setNew(false);
2375 }
2376 else {
2377 session.merge(userNotificationEvent);
2378 }
2379 }
2380 catch (Exception e) {
2381 throw processException(e);
2382 }
2383 finally {
2384 closeSession(session);
2385 }
2386
2387 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2388
2389 if (isNew || !UserNotificationEventModelImpl.COLUMN_BITMASK_ENABLED) {
2390 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2391 }
2392
2393 else {
2394 if ((userNotificationEventModelImpl.getColumnBitmask() &
2395 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
2396 Object[] args = new Object[] {
2397 userNotificationEventModelImpl.getOriginalUuid()
2398 };
2399
2400 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2401 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2402 args);
2403
2404 args = new Object[] { userNotificationEventModelImpl.getUuid() };
2405
2406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
2407 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
2408 args);
2409 }
2410
2411 if ((userNotificationEventModelImpl.getColumnBitmask() &
2412 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
2413 Object[] args = new Object[] {
2414 userNotificationEventModelImpl.getOriginalUuid(),
2415 Long.valueOf(userNotificationEventModelImpl.getOriginalCompanyId())
2416 };
2417
2418 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2419 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2420 args);
2421
2422 args = new Object[] {
2423 userNotificationEventModelImpl.getUuid(),
2424 Long.valueOf(userNotificationEventModelImpl.getCompanyId())
2425 };
2426
2427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
2428 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
2429 args);
2430 }
2431
2432 if ((userNotificationEventModelImpl.getColumnBitmask() &
2433 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
2434 Object[] args = new Object[] {
2435 Long.valueOf(userNotificationEventModelImpl.getOriginalUserId())
2436 };
2437
2438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2439 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2440 args);
2441
2442 args = new Object[] {
2443 Long.valueOf(userNotificationEventModelImpl.getUserId())
2444 };
2445
2446 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
2447 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
2448 args);
2449 }
2450
2451 if ((userNotificationEventModelImpl.getColumnBitmask() &
2452 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A.getColumnBitmask()) != 0) {
2453 Object[] args = new Object[] {
2454 Long.valueOf(userNotificationEventModelImpl.getOriginalUserId()),
2455 Boolean.valueOf(userNotificationEventModelImpl.getOriginalArchived())
2456 };
2457
2458 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_A, args);
2459 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_A,
2460 args);
2461
2462 args = new Object[] {
2463 Long.valueOf(userNotificationEventModelImpl.getUserId()),
2464 Boolean.valueOf(userNotificationEventModelImpl.getArchived())
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 }
2472
2473 EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2474 UserNotificationEventImpl.class,
2475 userNotificationEvent.getPrimaryKey(), userNotificationEvent);
2476
2477 return userNotificationEvent;
2478 }
2479
2480 protected UserNotificationEvent toUnwrappedModel(
2481 UserNotificationEvent userNotificationEvent) {
2482 if (userNotificationEvent instanceof UserNotificationEventImpl) {
2483 return userNotificationEvent;
2484 }
2485
2486 UserNotificationEventImpl userNotificationEventImpl = new UserNotificationEventImpl();
2487
2488 userNotificationEventImpl.setNew(userNotificationEvent.isNew());
2489 userNotificationEventImpl.setPrimaryKey(userNotificationEvent.getPrimaryKey());
2490
2491 userNotificationEventImpl.setUuid(userNotificationEvent.getUuid());
2492 userNotificationEventImpl.setUserNotificationEventId(userNotificationEvent.getUserNotificationEventId());
2493 userNotificationEventImpl.setCompanyId(userNotificationEvent.getCompanyId());
2494 userNotificationEventImpl.setUserId(userNotificationEvent.getUserId());
2495 userNotificationEventImpl.setType(userNotificationEvent.getType());
2496 userNotificationEventImpl.setTimestamp(userNotificationEvent.getTimestamp());
2497 userNotificationEventImpl.setDeliverBy(userNotificationEvent.getDeliverBy());
2498 userNotificationEventImpl.setPayload(userNotificationEvent.getPayload());
2499 userNotificationEventImpl.setArchived(userNotificationEvent.isArchived());
2500
2501 return userNotificationEventImpl;
2502 }
2503
2504
2512 @Override
2513 public UserNotificationEvent findByPrimaryKey(Serializable primaryKey)
2514 throws NoSuchModelException, SystemException {
2515 return findByPrimaryKey(((Long)primaryKey).longValue());
2516 }
2517
2518
2526 public UserNotificationEvent findByPrimaryKey(long userNotificationEventId)
2527 throws NoSuchUserNotificationEventException, SystemException {
2528 UserNotificationEvent userNotificationEvent = fetchByPrimaryKey(userNotificationEventId);
2529
2530 if (userNotificationEvent == null) {
2531 if (_log.isWarnEnabled()) {
2532 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2533 userNotificationEventId);
2534 }
2535
2536 throw new NoSuchUserNotificationEventException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2537 userNotificationEventId);
2538 }
2539
2540 return userNotificationEvent;
2541 }
2542
2543
2550 @Override
2551 public UserNotificationEvent fetchByPrimaryKey(Serializable primaryKey)
2552 throws SystemException {
2553 return fetchByPrimaryKey(((Long)primaryKey).longValue());
2554 }
2555
2556
2563 public UserNotificationEvent fetchByPrimaryKey(long userNotificationEventId)
2564 throws SystemException {
2565 UserNotificationEvent userNotificationEvent = (UserNotificationEvent)EntityCacheUtil.getResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2566 UserNotificationEventImpl.class, userNotificationEventId);
2567
2568 if (userNotificationEvent == _nullUserNotificationEvent) {
2569 return null;
2570 }
2571
2572 if (userNotificationEvent == null) {
2573 Session session = null;
2574
2575 try {
2576 session = openSession();
2577
2578 userNotificationEvent = (UserNotificationEvent)session.get(UserNotificationEventImpl.class,
2579 Long.valueOf(userNotificationEventId));
2580
2581 if (userNotificationEvent != null) {
2582 cacheResult(userNotificationEvent);
2583 }
2584 else {
2585 EntityCacheUtil.putResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2586 UserNotificationEventImpl.class,
2587 userNotificationEventId, _nullUserNotificationEvent);
2588 }
2589 }
2590 catch (Exception e) {
2591 EntityCacheUtil.removeResult(UserNotificationEventModelImpl.ENTITY_CACHE_ENABLED,
2592 UserNotificationEventImpl.class, userNotificationEventId);
2593
2594 throw processException(e);
2595 }
2596 finally {
2597 closeSession(session);
2598 }
2599 }
2600
2601 return userNotificationEvent;
2602 }
2603
2604
2610 public List<UserNotificationEvent> findAll() throws SystemException {
2611 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2612 }
2613
2614
2626 public List<UserNotificationEvent> findAll(int start, int end)
2627 throws SystemException {
2628 return findAll(start, end, null);
2629 }
2630
2631
2644 public List<UserNotificationEvent> findAll(int start, int end,
2645 OrderByComparator orderByComparator) throws SystemException {
2646 boolean pagination = true;
2647 FinderPath finderPath = null;
2648 Object[] finderArgs = null;
2649
2650 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2651 (orderByComparator == null)) {
2652 pagination = false;
2653 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2654 finderArgs = FINDER_ARGS_EMPTY;
2655 }
2656 else {
2657 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2658 finderArgs = new Object[] { start, end, orderByComparator };
2659 }
2660
2661 List<UserNotificationEvent> list = (List<UserNotificationEvent>)FinderCacheUtil.getResult(finderPath,
2662 finderArgs, this);
2663
2664 if (list == null) {
2665 StringBundler query = null;
2666 String sql = null;
2667
2668 if (orderByComparator != null) {
2669 query = new StringBundler(2 +
2670 (orderByComparator.getOrderByFields().length * 3));
2671
2672 query.append(_SQL_SELECT_USERNOTIFICATIONEVENT);
2673
2674 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2675 orderByComparator);
2676
2677 sql = query.toString();
2678 }
2679 else {
2680 sql = _SQL_SELECT_USERNOTIFICATIONEVENT;
2681
2682 if (pagination) {
2683 sql = sql.concat(UserNotificationEventModelImpl.ORDER_BY_JPQL);
2684 }
2685 }
2686
2687 Session session = null;
2688
2689 try {
2690 session = openSession();
2691
2692 Query q = session.createQuery(sql);
2693
2694 if (!pagination) {
2695 list = (List<UserNotificationEvent>)QueryUtil.list(q,
2696 getDialect(), start, end, false);
2697
2698 Collections.sort(list);
2699
2700 list = new UnmodifiableList<UserNotificationEvent>(list);
2701 }
2702 else {
2703 list = (List<UserNotificationEvent>)QueryUtil.list(q,
2704 getDialect(), start, end);
2705 }
2706
2707 cacheResult(list);
2708
2709 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2710 }
2711 catch (Exception e) {
2712 FinderCacheUtil.removeResult(finderPath, finderArgs);
2713
2714 throw processException(e);
2715 }
2716 finally {
2717 closeSession(session);
2718 }
2719 }
2720
2721 return list;
2722 }
2723
2724
2729 public void removeAll() throws SystemException {
2730 for (UserNotificationEvent userNotificationEvent : findAll()) {
2731 remove(userNotificationEvent);
2732 }
2733 }
2734
2735
2741 public int countAll() throws SystemException {
2742 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2743 FINDER_ARGS_EMPTY, this);
2744
2745 if (count == null) {
2746 Session session = null;
2747
2748 try {
2749 session = openSession();
2750
2751 Query q = session.createQuery(_SQL_COUNT_USERNOTIFICATIONEVENT);
2752
2753 count = (Long)q.uniqueResult();
2754
2755 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2756 FINDER_ARGS_EMPTY, count);
2757 }
2758 catch (Exception e) {
2759 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2760 FINDER_ARGS_EMPTY);
2761
2762 throw processException(e);
2763 }
2764 finally {
2765 closeSession(session);
2766 }
2767 }
2768
2769 return count.intValue();
2770 }
2771
2772
2775 public void afterPropertiesSet() {
2776 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2777 com.liferay.portal.util.PropsUtil.get(
2778 "value.object.listener.com.liferay.portal.model.UserNotificationEvent")));
2779
2780 if (listenerClassNames.length > 0) {
2781 try {
2782 List<ModelListener<UserNotificationEvent>> listenersList = new ArrayList<ModelListener<UserNotificationEvent>>();
2783
2784 for (String listenerClassName : listenerClassNames) {
2785 listenersList.add((ModelListener<UserNotificationEvent>)InstanceFactory.newInstance(
2786 listenerClassName));
2787 }
2788
2789 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2790 }
2791 catch (Exception e) {
2792 _log.error(e);
2793 }
2794 }
2795 }
2796
2797 public void destroy() {
2798 EntityCacheUtil.removeCache(UserNotificationEventImpl.class.getName());
2799 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2800 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2801 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2802 }
2803
2804 private static final String _SQL_SELECT_USERNOTIFICATIONEVENT = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent";
2805 private static final String _SQL_SELECT_USERNOTIFICATIONEVENT_WHERE = "SELECT userNotificationEvent FROM UserNotificationEvent userNotificationEvent WHERE ";
2806 private static final String _SQL_COUNT_USERNOTIFICATIONEVENT = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent";
2807 private static final String _SQL_COUNT_USERNOTIFICATIONEVENT_WHERE = "SELECT COUNT(userNotificationEvent) FROM UserNotificationEvent userNotificationEvent WHERE ";
2808 private static final String _ORDER_BY_ENTITY_ALIAS = "userNotificationEvent.";
2809 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No UserNotificationEvent exists with the primary key ";
2810 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No UserNotificationEvent exists with the key {";
2811 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2812 private static Log _log = LogFactoryUtil.getLog(UserNotificationEventPersistenceImpl.class);
2813 private static UserNotificationEvent _nullUserNotificationEvent = new UserNotificationEventImpl() {
2814 @Override
2815 public Object clone() {
2816 return this;
2817 }
2818
2819 @Override
2820 public CacheModel<UserNotificationEvent> toCacheModel() {
2821 return _nullUserNotificationEventCacheModel;
2822 }
2823 };
2824
2825 private static CacheModel<UserNotificationEvent> _nullUserNotificationEventCacheModel =
2826 new CacheModel<UserNotificationEvent>() {
2827 public UserNotificationEvent toEntityModel() {
2828 return _nullUserNotificationEvent;
2829 }
2830 };
2831 }