001
014
015 package com.liferay.portlet.announcements.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
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.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.OrderByComparator;
029 import com.liferay.portal.kernel.util.SetUtil;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.kernel.util.Validator;
033 import com.liferay.portal.model.CacheModel;
034 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
035
036 import com.liferay.portlet.announcements.NoSuchDeliveryException;
037 import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
038 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryImpl;
039 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryModelImpl;
040 import com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence;
041
042 import java.io.Serializable;
043
044 import java.util.Collections;
045 import java.util.HashMap;
046 import java.util.HashSet;
047 import java.util.Iterator;
048 import java.util.List;
049 import java.util.Map;
050 import java.util.Set;
051
052
064 @ProviderType
065 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
066 implements AnnouncementsDeliveryPersistence {
067
072 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List1";
075 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List2";
077 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
078 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
079 AnnouncementsDeliveryImpl.class,
080 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
082 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
083 AnnouncementsDeliveryImpl.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
086 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
089 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
090 AnnouncementsDeliveryImpl.class,
091 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
092 new String[] {
093 Long.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
099 new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
100 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
101 AnnouncementsDeliveryImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
103 new String[] { Long.class.getName() },
104 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
106 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
108 new String[] { Long.class.getName() });
109
110
116 @Override
117 public List<AnnouncementsDelivery> findByUserId(long userId) {
118 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
133 @Override
134 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
135 int end) {
136 return findByUserId(userId, start, end, null);
137 }
138
139
152 @Override
153 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
154 int end, OrderByComparator<AnnouncementsDelivery> orderByComparator) {
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_USERID;
163 finderArgs = new Object[] { userId };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
167 finderArgs = new Object[] { userId, start, end, orderByComparator };
168 }
169
170 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (AnnouncementsDelivery announcementsDelivery : list) {
175 if ((userId != announcementsDelivery.getUserId())) {
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_ANNOUNCEMENTSDELIVERY_WHERE);
195
196 query.append(_FINDER_COLUMN_USERID_USERID_2);
197
198 if (orderByComparator != null) {
199 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
200 orderByComparator);
201 }
202 else
203 if (pagination) {
204 query.append(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
205 }
206
207 String sql = query.toString();
208
209 Session session = null;
210
211 try {
212 session = openSession();
213
214 Query q = session.createQuery(sql);
215
216 QueryPos qPos = QueryPos.getInstance(q);
217
218 qPos.add(userId);
219
220 if (!pagination) {
221 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
222 getDialect(), start, end, false);
223
224 Collections.sort(list);
225
226 list = Collections.unmodifiableList(list);
227 }
228 else {
229 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
230 getDialect(), start, end);
231 }
232
233 cacheResult(list);
234
235 FinderCacheUtil.putResult(finderPath, finderArgs, list);
236 }
237 catch (Exception e) {
238 FinderCacheUtil.removeResult(finderPath, finderArgs);
239
240 throw processException(e);
241 }
242 finally {
243 closeSession(session);
244 }
245 }
246
247 return list;
248 }
249
250
258 @Override
259 public AnnouncementsDelivery findByUserId_First(long userId,
260 OrderByComparator<AnnouncementsDelivery> orderByComparator)
261 throws NoSuchDeliveryException {
262 AnnouncementsDelivery announcementsDelivery = fetchByUserId_First(userId,
263 orderByComparator);
264
265 if (announcementsDelivery != null) {
266 return announcementsDelivery;
267 }
268
269 StringBundler msg = new StringBundler(4);
270
271 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
272
273 msg.append("userId=");
274 msg.append(userId);
275
276 msg.append(StringPool.CLOSE_CURLY_BRACE);
277
278 throw new NoSuchDeliveryException(msg.toString());
279 }
280
281
288 @Override
289 public AnnouncementsDelivery fetchByUserId_First(long userId,
290 OrderByComparator<AnnouncementsDelivery> orderByComparator) {
291 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
292 orderByComparator);
293
294 if (!list.isEmpty()) {
295 return list.get(0);
296 }
297
298 return null;
299 }
300
301
309 @Override
310 public AnnouncementsDelivery findByUserId_Last(long userId,
311 OrderByComparator<AnnouncementsDelivery> orderByComparator)
312 throws NoSuchDeliveryException {
313 AnnouncementsDelivery announcementsDelivery = fetchByUserId_Last(userId,
314 orderByComparator);
315
316 if (announcementsDelivery != null) {
317 return announcementsDelivery;
318 }
319
320 StringBundler msg = new StringBundler(4);
321
322 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
323
324 msg.append("userId=");
325 msg.append(userId);
326
327 msg.append(StringPool.CLOSE_CURLY_BRACE);
328
329 throw new NoSuchDeliveryException(msg.toString());
330 }
331
332
339 @Override
340 public AnnouncementsDelivery fetchByUserId_Last(long userId,
341 OrderByComparator<AnnouncementsDelivery> orderByComparator) {
342 int count = countByUserId(userId);
343
344 if (count == 0) {
345 return null;
346 }
347
348 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
349 count, orderByComparator);
350
351 if (!list.isEmpty()) {
352 return list.get(0);
353 }
354
355 return null;
356 }
357
358
367 @Override
368 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
369 long userId, OrderByComparator<AnnouncementsDelivery> orderByComparator)
370 throws NoSuchDeliveryException {
371 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
379
380 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
381 userId, orderByComparator, true);
382
383 array[1] = announcementsDelivery;
384
385 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
386 userId, orderByComparator, false);
387
388 return array;
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396 }
397
398 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
399 AnnouncementsDelivery announcementsDelivery, long userId,
400 OrderByComparator<AnnouncementsDelivery> orderByComparator,
401 boolean previous) {
402 StringBundler query = null;
403
404 if (orderByComparator != null) {
405 query = new StringBundler(6 +
406 (orderByComparator.getOrderByFields().length * 6));
407 }
408 else {
409 query = new StringBundler(3);
410 }
411
412 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
413
414 query.append(_FINDER_COLUMN_USERID_USERID_2);
415
416 if (orderByComparator != null) {
417 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
418
419 if (orderByConditionFields.length > 0) {
420 query.append(WHERE_AND);
421 }
422
423 for (int i = 0; i < orderByConditionFields.length; i++) {
424 query.append(_ORDER_BY_ENTITY_ALIAS);
425 query.append(orderByConditionFields[i]);
426
427 if ((i + 1) < orderByConditionFields.length) {
428 if (orderByComparator.isAscending() ^ previous) {
429 query.append(WHERE_GREATER_THAN_HAS_NEXT);
430 }
431 else {
432 query.append(WHERE_LESSER_THAN_HAS_NEXT);
433 }
434 }
435 else {
436 if (orderByComparator.isAscending() ^ previous) {
437 query.append(WHERE_GREATER_THAN);
438 }
439 else {
440 query.append(WHERE_LESSER_THAN);
441 }
442 }
443 }
444
445 query.append(ORDER_BY_CLAUSE);
446
447 String[] orderByFields = orderByComparator.getOrderByFields();
448
449 for (int i = 0; i < orderByFields.length; i++) {
450 query.append(_ORDER_BY_ENTITY_ALIAS);
451 query.append(orderByFields[i]);
452
453 if ((i + 1) < orderByFields.length) {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(ORDER_BY_ASC_HAS_NEXT);
456 }
457 else {
458 query.append(ORDER_BY_DESC_HAS_NEXT);
459 }
460 }
461 else {
462 if (orderByComparator.isAscending() ^ previous) {
463 query.append(ORDER_BY_ASC);
464 }
465 else {
466 query.append(ORDER_BY_DESC);
467 }
468 }
469 }
470 }
471 else {
472 query.append(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
473 }
474
475 String sql = query.toString();
476
477 Query q = session.createQuery(sql);
478
479 q.setFirstResult(0);
480 q.setMaxResults(2);
481
482 QueryPos qPos = QueryPos.getInstance(q);
483
484 qPos.add(userId);
485
486 if (orderByComparator != null) {
487 Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
488
489 for (Object value : values) {
490 qPos.add(value);
491 }
492 }
493
494 List<AnnouncementsDelivery> list = q.list();
495
496 if (list.size() == 2) {
497 return list.get(1);
498 }
499 else {
500 return null;
501 }
502 }
503
504
509 @Override
510 public void removeByUserId(long userId) {
511 for (AnnouncementsDelivery announcementsDelivery : findByUserId(
512 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
513 remove(announcementsDelivery);
514 }
515 }
516
517
523 @Override
524 public int countByUserId(long userId) {
525 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
526
527 Object[] finderArgs = new Object[] { userId };
528
529 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
530 this);
531
532 if (count == null) {
533 StringBundler query = new StringBundler(2);
534
535 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
536
537 query.append(_FINDER_COLUMN_USERID_USERID_2);
538
539 String sql = query.toString();
540
541 Session session = null;
542
543 try {
544 session = openSession();
545
546 Query q = session.createQuery(sql);
547
548 QueryPos qPos = QueryPos.getInstance(q);
549
550 qPos.add(userId);
551
552 count = (Long)q.uniqueResult();
553
554 FinderCacheUtil.putResult(finderPath, finderArgs, count);
555 }
556 catch (Exception e) {
557 FinderCacheUtil.removeResult(finderPath, finderArgs);
558
559 throw processException(e);
560 }
561 finally {
562 closeSession(session);
563 }
564 }
565
566 return count.intValue();
567 }
568
569 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
570 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
571 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
572 AnnouncementsDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
573 "fetchByU_T",
574 new String[] { Long.class.getName(), String.class.getName() },
575 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK |
576 AnnouncementsDeliveryModelImpl.TYPE_COLUMN_BITMASK);
577 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
578 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
579 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
580 new String[] { Long.class.getName(), String.class.getName() });
581
582
590 @Override
591 public AnnouncementsDelivery findByU_T(long userId, String type)
592 throws NoSuchDeliveryException {
593 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
594
595 if (announcementsDelivery == null) {
596 StringBundler msg = new StringBundler(6);
597
598 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
599
600 msg.append("userId=");
601 msg.append(userId);
602
603 msg.append(", type=");
604 msg.append(type);
605
606 msg.append(StringPool.CLOSE_CURLY_BRACE);
607
608 if (_log.isWarnEnabled()) {
609 _log.warn(msg.toString());
610 }
611
612 throw new NoSuchDeliveryException(msg.toString());
613 }
614
615 return announcementsDelivery;
616 }
617
618
625 @Override
626 public AnnouncementsDelivery fetchByU_T(long userId, String type) {
627 return fetchByU_T(userId, type, true);
628 }
629
630
638 @Override
639 public AnnouncementsDelivery fetchByU_T(long userId, String type,
640 boolean retrieveFromCache) {
641 Object[] finderArgs = new Object[] { userId, type };
642
643 Object result = null;
644
645 if (retrieveFromCache) {
646 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
647 finderArgs, this);
648 }
649
650 if (result instanceof AnnouncementsDelivery) {
651 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)result;
652
653 if ((userId != announcementsDelivery.getUserId()) ||
654 !Validator.equals(type, announcementsDelivery.getType())) {
655 result = null;
656 }
657 }
658
659 if (result == null) {
660 StringBundler query = new StringBundler(4);
661
662 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
663
664 query.append(_FINDER_COLUMN_U_T_USERID_2);
665
666 boolean bindType = false;
667
668 if (type == null) {
669 query.append(_FINDER_COLUMN_U_T_TYPE_1);
670 }
671 else if (type.equals(StringPool.BLANK)) {
672 query.append(_FINDER_COLUMN_U_T_TYPE_3);
673 }
674 else {
675 bindType = true;
676
677 query.append(_FINDER_COLUMN_U_T_TYPE_2);
678 }
679
680 String sql = query.toString();
681
682 Session session = null;
683
684 try {
685 session = openSession();
686
687 Query q = session.createQuery(sql);
688
689 QueryPos qPos = QueryPos.getInstance(q);
690
691 qPos.add(userId);
692
693 if (bindType) {
694 qPos.add(type);
695 }
696
697 List<AnnouncementsDelivery> list = q.list();
698
699 if (list.isEmpty()) {
700 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
701 finderArgs, list);
702 }
703 else {
704 AnnouncementsDelivery announcementsDelivery = list.get(0);
705
706 result = announcementsDelivery;
707
708 cacheResult(announcementsDelivery);
709
710 if ((announcementsDelivery.getUserId() != userId) ||
711 (announcementsDelivery.getType() == null) ||
712 !announcementsDelivery.getType().equals(type)) {
713 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
714 finderArgs, announcementsDelivery);
715 }
716 }
717 }
718 catch (Exception e) {
719 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
720 finderArgs);
721
722 throw processException(e);
723 }
724 finally {
725 closeSession(session);
726 }
727 }
728
729 if (result instanceof List<?>) {
730 return null;
731 }
732 else {
733 return (AnnouncementsDelivery)result;
734 }
735 }
736
737
744 @Override
745 public AnnouncementsDelivery removeByU_T(long userId, String type)
746 throws NoSuchDeliveryException {
747 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
748
749 return remove(announcementsDelivery);
750 }
751
752
759 @Override
760 public int countByU_T(long userId, String type) {
761 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
762
763 Object[] finderArgs = new Object[] { userId, type };
764
765 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
766 this);
767
768 if (count == null) {
769 StringBundler query = new StringBundler(3);
770
771 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
772
773 query.append(_FINDER_COLUMN_U_T_USERID_2);
774
775 boolean bindType = false;
776
777 if (type == null) {
778 query.append(_FINDER_COLUMN_U_T_TYPE_1);
779 }
780 else if (type.equals(StringPool.BLANK)) {
781 query.append(_FINDER_COLUMN_U_T_TYPE_3);
782 }
783 else {
784 bindType = true;
785
786 query.append(_FINDER_COLUMN_U_T_TYPE_2);
787 }
788
789 String sql = query.toString();
790
791 Session session = null;
792
793 try {
794 session = openSession();
795
796 Query q = session.createQuery(sql);
797
798 QueryPos qPos = QueryPos.getInstance(q);
799
800 qPos.add(userId);
801
802 if (bindType) {
803 qPos.add(type);
804 }
805
806 count = (Long)q.uniqueResult();
807
808 FinderCacheUtil.putResult(finderPath, finderArgs, count);
809 }
810 catch (Exception e) {
811 FinderCacheUtil.removeResult(finderPath, finderArgs);
812
813 throw processException(e);
814 }
815 finally {
816 closeSession(session);
817 }
818 }
819
820 return count.intValue();
821 }
822
823 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
824 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
825 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
826 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = '')";
827
828 public AnnouncementsDeliveryPersistenceImpl() {
829 setModelClass(AnnouncementsDelivery.class);
830 }
831
832
837 @Override
838 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
839 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
840 AnnouncementsDeliveryImpl.class,
841 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
842
843 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
844 new Object[] {
845 announcementsDelivery.getUserId(),
846 announcementsDelivery.getType()
847 }, announcementsDelivery);
848
849 announcementsDelivery.resetOriginalValues();
850 }
851
852
857 @Override
858 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
859 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
860 if (EntityCacheUtil.getResult(
861 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
862 AnnouncementsDeliveryImpl.class,
863 announcementsDelivery.getPrimaryKey()) == null) {
864 cacheResult(announcementsDelivery);
865 }
866 else {
867 announcementsDelivery.resetOriginalValues();
868 }
869 }
870 }
871
872
879 @Override
880 public void clearCache() {
881 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class);
882
883 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
884 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
885 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
886 }
887
888
895 @Override
896 public void clearCache(AnnouncementsDelivery announcementsDelivery) {
897 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
898 AnnouncementsDeliveryImpl.class,
899 announcementsDelivery.getPrimaryKey());
900
901 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
902 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
903
904 clearUniqueFindersCache(announcementsDelivery);
905 }
906
907 @Override
908 public void clearCache(List<AnnouncementsDelivery> announcementsDeliveries) {
909 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
910 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
911
912 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
913 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
914 AnnouncementsDeliveryImpl.class,
915 announcementsDelivery.getPrimaryKey());
916
917 clearUniqueFindersCache(announcementsDelivery);
918 }
919 }
920
921 protected void cacheUniqueFindersCache(
922 AnnouncementsDelivery announcementsDelivery) {
923 if (announcementsDelivery.isNew()) {
924 Object[] args = new Object[] {
925 announcementsDelivery.getUserId(),
926 announcementsDelivery.getType()
927 };
928
929 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
930 Long.valueOf(1));
931 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
932 announcementsDelivery);
933 }
934 else {
935 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
936
937 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
938 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
939 Object[] args = new Object[] {
940 announcementsDelivery.getUserId(),
941 announcementsDelivery.getType()
942 };
943
944 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
945 Long.valueOf(1));
946 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
947 announcementsDelivery);
948 }
949 }
950 }
951
952 protected void clearUniqueFindersCache(
953 AnnouncementsDelivery announcementsDelivery) {
954 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
955
956 Object[] args = new Object[] {
957 announcementsDelivery.getUserId(),
958 announcementsDelivery.getType()
959 };
960
961 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
962 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
963
964 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
965 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
966 args = new Object[] {
967 announcementsDeliveryModelImpl.getOriginalUserId(),
968 announcementsDeliveryModelImpl.getOriginalType()
969 };
970
971 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
972 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
973 }
974 }
975
976
982 @Override
983 public AnnouncementsDelivery create(long deliveryId) {
984 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
985
986 announcementsDelivery.setNew(true);
987 announcementsDelivery.setPrimaryKey(deliveryId);
988
989 return announcementsDelivery;
990 }
991
992
999 @Override
1000 public AnnouncementsDelivery remove(long deliveryId)
1001 throws NoSuchDeliveryException {
1002 return remove((Serializable)deliveryId);
1003 }
1004
1005
1012 @Override
1013 public AnnouncementsDelivery remove(Serializable primaryKey)
1014 throws NoSuchDeliveryException {
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1021 primaryKey);
1022
1023 if (announcementsDelivery == null) {
1024 if (_log.isWarnEnabled()) {
1025 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1026 }
1027
1028 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1029 primaryKey);
1030 }
1031
1032 return remove(announcementsDelivery);
1033 }
1034 catch (NoSuchDeliveryException nsee) {
1035 throw nsee;
1036 }
1037 catch (Exception e) {
1038 throw processException(e);
1039 }
1040 finally {
1041 closeSession(session);
1042 }
1043 }
1044
1045 @Override
1046 protected AnnouncementsDelivery removeImpl(
1047 AnnouncementsDelivery announcementsDelivery) {
1048 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
1049
1050 Session session = null;
1051
1052 try {
1053 session = openSession();
1054
1055 if (!session.contains(announcementsDelivery)) {
1056 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1057 announcementsDelivery.getPrimaryKeyObj());
1058 }
1059
1060 if (announcementsDelivery != null) {
1061 session.delete(announcementsDelivery);
1062 }
1063 }
1064 catch (Exception e) {
1065 throw processException(e);
1066 }
1067 finally {
1068 closeSession(session);
1069 }
1070
1071 if (announcementsDelivery != null) {
1072 clearCache(announcementsDelivery);
1073 }
1074
1075 return announcementsDelivery;
1076 }
1077
1078 @Override
1079 public AnnouncementsDelivery updateImpl(
1080 AnnouncementsDelivery announcementsDelivery) {
1081 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
1082
1083 boolean isNew = announcementsDelivery.isNew();
1084
1085 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
1086
1087 Session session = null;
1088
1089 try {
1090 session = openSession();
1091
1092 if (announcementsDelivery.isNew()) {
1093 session.save(announcementsDelivery);
1094
1095 announcementsDelivery.setNew(false);
1096 }
1097 else {
1098 session.merge(announcementsDelivery);
1099 }
1100 }
1101 catch (Exception e) {
1102 throw processException(e);
1103 }
1104 finally {
1105 closeSession(session);
1106 }
1107
1108 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1109
1110 if (isNew || !AnnouncementsDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
1111 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1112 }
1113
1114 else {
1115 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
1116 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1117 Object[] args = new Object[] {
1118 announcementsDeliveryModelImpl.getOriginalUserId()
1119 };
1120
1121 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1122 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1123 args);
1124
1125 args = new Object[] { announcementsDeliveryModelImpl.getUserId() };
1126
1127 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1128 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1129 args);
1130 }
1131 }
1132
1133 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1134 AnnouncementsDeliveryImpl.class,
1135 announcementsDelivery.getPrimaryKey(), announcementsDelivery, false);
1136
1137 clearUniqueFindersCache(announcementsDelivery);
1138 cacheUniqueFindersCache(announcementsDelivery);
1139
1140 announcementsDelivery.resetOriginalValues();
1141
1142 return announcementsDelivery;
1143 }
1144
1145 protected AnnouncementsDelivery toUnwrappedModel(
1146 AnnouncementsDelivery announcementsDelivery) {
1147 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
1148 return announcementsDelivery;
1149 }
1150
1151 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
1152
1153 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
1154 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
1155
1156 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
1157 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
1158 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
1159 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
1160 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
1161 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
1162 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
1163
1164 return announcementsDeliveryImpl;
1165 }
1166
1167
1174 @Override
1175 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
1176 throws NoSuchDeliveryException {
1177 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(primaryKey);
1178
1179 if (announcementsDelivery == null) {
1180 if (_log.isWarnEnabled()) {
1181 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1182 }
1183
1184 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1185 primaryKey);
1186 }
1187
1188 return announcementsDelivery;
1189 }
1190
1191
1198 @Override
1199 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
1200 throws NoSuchDeliveryException {
1201 return findByPrimaryKey((Serializable)deliveryId);
1202 }
1203
1204
1210 @Override
1211 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey) {
1212 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1213 AnnouncementsDeliveryImpl.class, primaryKey);
1214
1215 if (announcementsDelivery == _nullAnnouncementsDelivery) {
1216 return null;
1217 }
1218
1219 if (announcementsDelivery == null) {
1220 Session session = null;
1221
1222 try {
1223 session = openSession();
1224
1225 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1226 primaryKey);
1227
1228 if (announcementsDelivery != null) {
1229 cacheResult(announcementsDelivery);
1230 }
1231 else {
1232 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1233 AnnouncementsDeliveryImpl.class, primaryKey,
1234 _nullAnnouncementsDelivery);
1235 }
1236 }
1237 catch (Exception e) {
1238 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1239 AnnouncementsDeliveryImpl.class, primaryKey);
1240
1241 throw processException(e);
1242 }
1243 finally {
1244 closeSession(session);
1245 }
1246 }
1247
1248 return announcementsDelivery;
1249 }
1250
1251
1257 @Override
1258 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId) {
1259 return fetchByPrimaryKey((Serializable)deliveryId);
1260 }
1261
1262 @Override
1263 public Map<Serializable, AnnouncementsDelivery> fetchByPrimaryKeys(
1264 Set<Serializable> primaryKeys) {
1265 if (primaryKeys.isEmpty()) {
1266 return Collections.emptyMap();
1267 }
1268
1269 Map<Serializable, AnnouncementsDelivery> map = new HashMap<Serializable, AnnouncementsDelivery>();
1270
1271 if (primaryKeys.size() == 1) {
1272 Iterator<Serializable> iterator = primaryKeys.iterator();
1273
1274 Serializable primaryKey = iterator.next();
1275
1276 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(primaryKey);
1277
1278 if (announcementsDelivery != null) {
1279 map.put(primaryKey, announcementsDelivery);
1280 }
1281
1282 return map;
1283 }
1284
1285 Set<Serializable> uncachedPrimaryKeys = null;
1286
1287 for (Serializable primaryKey : primaryKeys) {
1288 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1289 AnnouncementsDeliveryImpl.class, primaryKey);
1290
1291 if (announcementsDelivery == null) {
1292 if (uncachedPrimaryKeys == null) {
1293 uncachedPrimaryKeys = new HashSet<Serializable>();
1294 }
1295
1296 uncachedPrimaryKeys.add(primaryKey);
1297 }
1298 else {
1299 map.put(primaryKey, announcementsDelivery);
1300 }
1301 }
1302
1303 if (uncachedPrimaryKeys == null) {
1304 return map;
1305 }
1306
1307 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
1308 1);
1309
1310 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE_PKS_IN);
1311
1312 for (Serializable primaryKey : uncachedPrimaryKeys) {
1313 query.append(String.valueOf(primaryKey));
1314
1315 query.append(StringPool.COMMA);
1316 }
1317
1318 query.setIndex(query.index() - 1);
1319
1320 query.append(StringPool.CLOSE_PARENTHESIS);
1321
1322 String sql = query.toString();
1323
1324 Session session = null;
1325
1326 try {
1327 session = openSession();
1328
1329 Query q = session.createQuery(sql);
1330
1331 for (AnnouncementsDelivery announcementsDelivery : (List<AnnouncementsDelivery>)q.list()) {
1332 map.put(announcementsDelivery.getPrimaryKeyObj(),
1333 announcementsDelivery);
1334
1335 cacheResult(announcementsDelivery);
1336
1337 uncachedPrimaryKeys.remove(announcementsDelivery.getPrimaryKeyObj());
1338 }
1339
1340 for (Serializable primaryKey : uncachedPrimaryKeys) {
1341 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1342 AnnouncementsDeliveryImpl.class, primaryKey,
1343 _nullAnnouncementsDelivery);
1344 }
1345 }
1346 catch (Exception e) {
1347 throw processException(e);
1348 }
1349 finally {
1350 closeSession(session);
1351 }
1352
1353 return map;
1354 }
1355
1356
1361 @Override
1362 public List<AnnouncementsDelivery> findAll() {
1363 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1364 }
1365
1366
1377 @Override
1378 public List<AnnouncementsDelivery> findAll(int start, int end) {
1379 return findAll(start, end, null);
1380 }
1381
1382
1394 @Override
1395 public List<AnnouncementsDelivery> findAll(int start, int end,
1396 OrderByComparator<AnnouncementsDelivery> orderByComparator) {
1397 boolean pagination = true;
1398 FinderPath finderPath = null;
1399 Object[] finderArgs = null;
1400
1401 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1402 (orderByComparator == null)) {
1403 pagination = false;
1404 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1405 finderArgs = FINDER_ARGS_EMPTY;
1406 }
1407 else {
1408 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1409 finderArgs = new Object[] { start, end, orderByComparator };
1410 }
1411
1412 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1413 finderArgs, this);
1414
1415 if (list == null) {
1416 StringBundler query = null;
1417 String sql = null;
1418
1419 if (orderByComparator != null) {
1420 query = new StringBundler(2 +
1421 (orderByComparator.getOrderByFields().length * 3));
1422
1423 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1424
1425 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1426 orderByComparator);
1427
1428 sql = query.toString();
1429 }
1430 else {
1431 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1432
1433 if (pagination) {
1434 sql = sql.concat(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
1435 }
1436 }
1437
1438 Session session = null;
1439
1440 try {
1441 session = openSession();
1442
1443 Query q = session.createQuery(sql);
1444
1445 if (!pagination) {
1446 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1447 getDialect(), start, end, false);
1448
1449 Collections.sort(list);
1450
1451 list = Collections.unmodifiableList(list);
1452 }
1453 else {
1454 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1455 getDialect(), start, end);
1456 }
1457
1458 cacheResult(list);
1459
1460 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1461 }
1462 catch (Exception e) {
1463 FinderCacheUtil.removeResult(finderPath, finderArgs);
1464
1465 throw processException(e);
1466 }
1467 finally {
1468 closeSession(session);
1469 }
1470 }
1471
1472 return list;
1473 }
1474
1475
1479 @Override
1480 public void removeAll() {
1481 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1482 remove(announcementsDelivery);
1483 }
1484 }
1485
1486
1491 @Override
1492 public int countAll() {
1493 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1494 FINDER_ARGS_EMPTY, this);
1495
1496 if (count == null) {
1497 Session session = null;
1498
1499 try {
1500 session = openSession();
1501
1502 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1503
1504 count = (Long)q.uniqueResult();
1505
1506 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1507 FINDER_ARGS_EMPTY, count);
1508 }
1509 catch (Exception e) {
1510 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1511 FINDER_ARGS_EMPTY);
1512
1513 throw processException(e);
1514 }
1515 finally {
1516 closeSession(session);
1517 }
1518 }
1519
1520 return count.intValue();
1521 }
1522
1523 @Override
1524 protected Set<String> getBadColumnNames() {
1525 return _badColumnNames;
1526 }
1527
1528
1531 public void afterPropertiesSet() {
1532 }
1533
1534 public void destroy() {
1535 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1536 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1537 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1538 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1539 }
1540
1541 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1542 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE_PKS_IN = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE deliveryId IN (";
1543 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1544 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1545 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1546 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1547 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1548 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1549 private static final Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1550 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
1551 "type"
1552 });
1553 private static final AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1554 @Override
1555 public Object clone() {
1556 return this;
1557 }
1558
1559 @Override
1560 public CacheModel<AnnouncementsDelivery> toCacheModel() {
1561 return _nullAnnouncementsDeliveryCacheModel;
1562 }
1563 };
1564
1565 private static final CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1566 new CacheModel<AnnouncementsDelivery>() {
1567 @Override
1568 public AnnouncementsDelivery toEntityModel() {
1569 return _nullAnnouncementsDelivery;
1570 }
1571 };
1572 }