001
014
015 package com.liferay.portlet.announcements.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
039
040 import com.liferay.portlet.announcements.NoSuchDeliveryException;
041 import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
042 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryImpl;
043 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryModelImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
064 implements AnnouncementsDeliveryPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
071 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072 ".List1";
073 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074 ".List2";
075 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
076 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
077 AnnouncementsDeliveryImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
080 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
081 AnnouncementsDeliveryImpl.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
084 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
086 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
087 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
088 AnnouncementsDeliveryImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
090 new String[] {
091 Long.class.getName(),
092
093 Integer.class.getName(), Integer.class.getName(),
094 OrderByComparator.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
097 new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
098 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
099 AnnouncementsDeliveryImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
101 new String[] { Long.class.getName() },
102 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK);
103 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
104 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
106 new String[] { Long.class.getName() });
107
108
115 public List<AnnouncementsDelivery> findByUserId(long userId)
116 throws SystemException {
117 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
118 }
119
120
133 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
134 int end) throws SystemException {
135 return findByUserId(userId, start, end, null);
136 }
137
138
152 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
153 int end, OrderByComparator orderByComparator) throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
162 finderArgs = new Object[] { userId };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
166 finderArgs = new Object[] { userId, start, end, orderByComparator };
167 }
168
169 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
170 finderArgs, this);
171
172 if ((list != null) && !list.isEmpty()) {
173 for (AnnouncementsDelivery announcementsDelivery : list) {
174 if ((userId != announcementsDelivery.getUserId())) {
175 list = null;
176
177 break;
178 }
179 }
180 }
181
182 if (list == null) {
183 StringBundler query = null;
184
185 if (orderByComparator != null) {
186 query = new StringBundler(3 +
187 (orderByComparator.getOrderByFields().length * 3));
188 }
189 else {
190 query = new StringBundler(3);
191 }
192
193 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
194
195 query.append(_FINDER_COLUMN_USERID_USERID_2);
196
197 if (orderByComparator != null) {
198 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
199 orderByComparator);
200 }
201 else
202 if (pagination) {
203 query.append(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
204 }
205
206 String sql = query.toString();
207
208 Session session = null;
209
210 try {
211 session = openSession();
212
213 Query q = session.createQuery(sql);
214
215 QueryPos qPos = QueryPos.getInstance(q);
216
217 qPos.add(userId);
218
219 if (!pagination) {
220 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
221 getDialect(), start, end, false);
222
223 Collections.sort(list);
224
225 list = new UnmodifiableList<AnnouncementsDelivery>(list);
226 }
227 else {
228 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
229 getDialect(), start, end);
230 }
231
232 cacheResult(list);
233
234 FinderCacheUtil.putResult(finderPath, finderArgs, list);
235 }
236 catch (Exception e) {
237 FinderCacheUtil.removeResult(finderPath, finderArgs);
238
239 throw processException(e);
240 }
241 finally {
242 closeSession(session);
243 }
244 }
245
246 return list;
247 }
248
249
258 public AnnouncementsDelivery findByUserId_First(long userId,
259 OrderByComparator orderByComparator)
260 throws NoSuchDeliveryException, SystemException {
261 AnnouncementsDelivery announcementsDelivery = fetchByUserId_First(userId,
262 orderByComparator);
263
264 if (announcementsDelivery != null) {
265 return announcementsDelivery;
266 }
267
268 StringBundler msg = new StringBundler(4);
269
270 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
271
272 msg.append("userId=");
273 msg.append(userId);
274
275 msg.append(StringPool.CLOSE_CURLY_BRACE);
276
277 throw new NoSuchDeliveryException(msg.toString());
278 }
279
280
288 public AnnouncementsDelivery fetchByUserId_First(long userId,
289 OrderByComparator orderByComparator) throws SystemException {
290 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
291 orderByComparator);
292
293 if (!list.isEmpty()) {
294 return list.get(0);
295 }
296
297 return null;
298 }
299
300
309 public AnnouncementsDelivery findByUserId_Last(long userId,
310 OrderByComparator orderByComparator)
311 throws NoSuchDeliveryException, SystemException {
312 AnnouncementsDelivery announcementsDelivery = fetchByUserId_Last(userId,
313 orderByComparator);
314
315 if (announcementsDelivery != null) {
316 return announcementsDelivery;
317 }
318
319 StringBundler msg = new StringBundler(4);
320
321 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322
323 msg.append("userId=");
324 msg.append(userId);
325
326 msg.append(StringPool.CLOSE_CURLY_BRACE);
327
328 throw new NoSuchDeliveryException(msg.toString());
329 }
330
331
339 public AnnouncementsDelivery fetchByUserId_Last(long userId,
340 OrderByComparator orderByComparator) throws SystemException {
341 int count = countByUserId(userId);
342
343 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
344 count, orderByComparator);
345
346 if (!list.isEmpty()) {
347 return list.get(0);
348 }
349
350 return null;
351 }
352
353
363 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
364 long userId, OrderByComparator orderByComparator)
365 throws NoSuchDeliveryException, SystemException {
366 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
367
368 Session session = null;
369
370 try {
371 session = openSession();
372
373 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
374
375 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
376 userId, orderByComparator, true);
377
378 array[1] = announcementsDelivery;
379
380 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
381 userId, orderByComparator, false);
382
383 return array;
384 }
385 catch (Exception e) {
386 throw processException(e);
387 }
388 finally {
389 closeSession(session);
390 }
391 }
392
393 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
394 AnnouncementsDelivery announcementsDelivery, long userId,
395 OrderByComparator orderByComparator, boolean previous) {
396 StringBundler query = null;
397
398 if (orderByComparator != null) {
399 query = new StringBundler(6 +
400 (orderByComparator.getOrderByFields().length * 6));
401 }
402 else {
403 query = new StringBundler(3);
404 }
405
406 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
407
408 query.append(_FINDER_COLUMN_USERID_USERID_2);
409
410 if (orderByComparator != null) {
411 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
412
413 if (orderByConditionFields.length > 0) {
414 query.append(WHERE_AND);
415 }
416
417 for (int i = 0; i < orderByConditionFields.length; i++) {
418 query.append(_ORDER_BY_ENTITY_ALIAS);
419 query.append(orderByConditionFields[i]);
420
421 if ((i + 1) < orderByConditionFields.length) {
422 if (orderByComparator.isAscending() ^ previous) {
423 query.append(WHERE_GREATER_THAN_HAS_NEXT);
424 }
425 else {
426 query.append(WHERE_LESSER_THAN_HAS_NEXT);
427 }
428 }
429 else {
430 if (orderByComparator.isAscending() ^ previous) {
431 query.append(WHERE_GREATER_THAN);
432 }
433 else {
434 query.append(WHERE_LESSER_THAN);
435 }
436 }
437 }
438
439 query.append(ORDER_BY_CLAUSE);
440
441 String[] orderByFields = orderByComparator.getOrderByFields();
442
443 for (int i = 0; i < orderByFields.length; i++) {
444 query.append(_ORDER_BY_ENTITY_ALIAS);
445 query.append(orderByFields[i]);
446
447 if ((i + 1) < orderByFields.length) {
448 if (orderByComparator.isAscending() ^ previous) {
449 query.append(ORDER_BY_ASC_HAS_NEXT);
450 }
451 else {
452 query.append(ORDER_BY_DESC_HAS_NEXT);
453 }
454 }
455 else {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(ORDER_BY_ASC);
458 }
459 else {
460 query.append(ORDER_BY_DESC);
461 }
462 }
463 }
464 }
465 else {
466 query.append(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
467 }
468
469 String sql = query.toString();
470
471 Query q = session.createQuery(sql);
472
473 q.setFirstResult(0);
474 q.setMaxResults(2);
475
476 QueryPos qPos = QueryPos.getInstance(q);
477
478 qPos.add(userId);
479
480 if (orderByComparator != null) {
481 Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
482
483 for (Object value : values) {
484 qPos.add(value);
485 }
486 }
487
488 List<AnnouncementsDelivery> list = q.list();
489
490 if (list.size() == 2) {
491 return list.get(1);
492 }
493 else {
494 return null;
495 }
496 }
497
498
504 public void removeByUserId(long userId) throws SystemException {
505 for (AnnouncementsDelivery announcementsDelivery : findByUserId(
506 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
507 remove(announcementsDelivery);
508 }
509 }
510
511
518 public int countByUserId(long userId) throws SystemException {
519 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
520
521 Object[] finderArgs = new Object[] { userId };
522
523 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
524 this);
525
526 if (count == null) {
527 StringBundler query = new StringBundler(2);
528
529 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
530
531 query.append(_FINDER_COLUMN_USERID_USERID_2);
532
533 String sql = query.toString();
534
535 Session session = null;
536
537 try {
538 session = openSession();
539
540 Query q = session.createQuery(sql);
541
542 QueryPos qPos = QueryPos.getInstance(q);
543
544 qPos.add(userId);
545
546 count = (Long)q.uniqueResult();
547
548 FinderCacheUtil.putResult(finderPath, finderArgs, count);
549 }
550 catch (Exception e) {
551 FinderCacheUtil.removeResult(finderPath, finderArgs);
552
553 throw processException(e);
554 }
555 finally {
556 closeSession(session);
557 }
558 }
559
560 return count.intValue();
561 }
562
563 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
564 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
565 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
566 AnnouncementsDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
567 "fetchByU_T",
568 new String[] { Long.class.getName(), String.class.getName() },
569 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK |
570 AnnouncementsDeliveryModelImpl.TYPE_COLUMN_BITMASK);
571 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
572 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
573 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
574 new String[] { Long.class.getName(), String.class.getName() });
575
576
585 public AnnouncementsDelivery findByU_T(long userId, String type)
586 throws NoSuchDeliveryException, SystemException {
587 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
588
589 if (announcementsDelivery == null) {
590 StringBundler msg = new StringBundler(6);
591
592 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
593
594 msg.append("userId=");
595 msg.append(userId);
596
597 msg.append(", type=");
598 msg.append(type);
599
600 msg.append(StringPool.CLOSE_CURLY_BRACE);
601
602 if (_log.isWarnEnabled()) {
603 _log.warn(msg.toString());
604 }
605
606 throw new NoSuchDeliveryException(msg.toString());
607 }
608
609 return announcementsDelivery;
610 }
611
612
620 public AnnouncementsDelivery fetchByU_T(long userId, String type)
621 throws SystemException {
622 return fetchByU_T(userId, type, true);
623 }
624
625
634 public AnnouncementsDelivery fetchByU_T(long userId, String type,
635 boolean retrieveFromCache) throws SystemException {
636 Object[] finderArgs = new Object[] { userId, type };
637
638 Object result = null;
639
640 if (retrieveFromCache) {
641 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
642 finderArgs, this);
643 }
644
645 if (result instanceof AnnouncementsDelivery) {
646 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)result;
647
648 if ((userId != announcementsDelivery.getUserId()) ||
649 !Validator.equals(type, announcementsDelivery.getType())) {
650 result = null;
651 }
652 }
653
654 if (result == null) {
655 StringBundler query = new StringBundler(4);
656
657 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
658
659 query.append(_FINDER_COLUMN_U_T_USERID_2);
660
661 boolean bindType = false;
662
663 if (type == null) {
664 query.append(_FINDER_COLUMN_U_T_TYPE_1);
665 }
666 else if (type.equals(StringPool.BLANK)) {
667 query.append(_FINDER_COLUMN_U_T_TYPE_3);
668 }
669 else {
670 bindType = true;
671
672 query.append(_FINDER_COLUMN_U_T_TYPE_2);
673 }
674
675 String sql = query.toString();
676
677 Session session = null;
678
679 try {
680 session = openSession();
681
682 Query q = session.createQuery(sql);
683
684 QueryPos qPos = QueryPos.getInstance(q);
685
686 qPos.add(userId);
687
688 if (bindType) {
689 qPos.add(type);
690 }
691
692 List<AnnouncementsDelivery> list = q.list();
693
694 if (list.isEmpty()) {
695 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
696 finderArgs, list);
697 }
698 else {
699 AnnouncementsDelivery announcementsDelivery = list.get(0);
700
701 result = announcementsDelivery;
702
703 cacheResult(announcementsDelivery);
704
705 if ((announcementsDelivery.getUserId() != userId) ||
706 (announcementsDelivery.getType() == null) ||
707 !announcementsDelivery.getType().equals(type)) {
708 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
709 finderArgs, announcementsDelivery);
710 }
711 }
712 }
713 catch (Exception e) {
714 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
715 finderArgs);
716
717 throw processException(e);
718 }
719 finally {
720 closeSession(session);
721 }
722 }
723
724 if (result instanceof List<?>) {
725 return null;
726 }
727 else {
728 return (AnnouncementsDelivery)result;
729 }
730 }
731
732
740 public AnnouncementsDelivery removeByU_T(long userId, String type)
741 throws NoSuchDeliveryException, SystemException {
742 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
743
744 return remove(announcementsDelivery);
745 }
746
747
755 public int countByU_T(long userId, String type) throws SystemException {
756 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
757
758 Object[] finderArgs = new Object[] { userId, type };
759
760 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
761 this);
762
763 if (count == null) {
764 StringBundler query = new StringBundler(3);
765
766 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
767
768 query.append(_FINDER_COLUMN_U_T_USERID_2);
769
770 boolean bindType = false;
771
772 if (type == null) {
773 query.append(_FINDER_COLUMN_U_T_TYPE_1);
774 }
775 else if (type.equals(StringPool.BLANK)) {
776 query.append(_FINDER_COLUMN_U_T_TYPE_3);
777 }
778 else {
779 bindType = true;
780
781 query.append(_FINDER_COLUMN_U_T_TYPE_2);
782 }
783
784 String sql = query.toString();
785
786 Session session = null;
787
788 try {
789 session = openSession();
790
791 Query q = session.createQuery(sql);
792
793 QueryPos qPos = QueryPos.getInstance(q);
794
795 qPos.add(userId);
796
797 if (bindType) {
798 qPos.add(type);
799 }
800
801 count = (Long)q.uniqueResult();
802
803 FinderCacheUtil.putResult(finderPath, finderArgs, count);
804 }
805 catch (Exception e) {
806 FinderCacheUtil.removeResult(finderPath, finderArgs);
807
808 throw processException(e);
809 }
810 finally {
811 closeSession(session);
812 }
813 }
814
815 return count.intValue();
816 }
817
818 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
819 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
820 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
821 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = '')";
822
823
828 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
829 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
830 AnnouncementsDeliveryImpl.class,
831 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
832
833 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
834 new Object[] {
835 announcementsDelivery.getUserId(),
836 announcementsDelivery.getType()
837 }, announcementsDelivery);
838
839 announcementsDelivery.resetOriginalValues();
840 }
841
842
847 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
848 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
849 if (EntityCacheUtil.getResult(
850 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
851 AnnouncementsDeliveryImpl.class,
852 announcementsDelivery.getPrimaryKey()) == null) {
853 cacheResult(announcementsDelivery);
854 }
855 else {
856 announcementsDelivery.resetOriginalValues();
857 }
858 }
859 }
860
861
868 @Override
869 public void clearCache() {
870 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
871 CacheRegistryUtil.clear(AnnouncementsDeliveryImpl.class.getName());
872 }
873
874 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
875
876 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
877 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
878 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
879 }
880
881
888 @Override
889 public void clearCache(AnnouncementsDelivery announcementsDelivery) {
890 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
891 AnnouncementsDeliveryImpl.class,
892 announcementsDelivery.getPrimaryKey());
893
894 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
895 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
896
897 clearUniqueFindersCache(announcementsDelivery);
898 }
899
900 @Override
901 public void clearCache(List<AnnouncementsDelivery> announcementsDeliveries) {
902 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
903 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
904
905 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
906 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
907 AnnouncementsDeliveryImpl.class,
908 announcementsDelivery.getPrimaryKey());
909
910 clearUniqueFindersCache(announcementsDelivery);
911 }
912 }
913
914 protected void cacheUniqueFindersCache(
915 AnnouncementsDelivery announcementsDelivery) {
916 if (announcementsDelivery.isNew()) {
917 Object[] args = new Object[] {
918 announcementsDelivery.getUserId(),
919 announcementsDelivery.getType()
920 };
921
922 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
923 Long.valueOf(1));
924 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
925 announcementsDelivery);
926 }
927 else {
928 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
929
930 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
931 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
932 Object[] args = new Object[] {
933 announcementsDelivery.getUserId(),
934 announcementsDelivery.getType()
935 };
936
937 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
938 Long.valueOf(1));
939 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
940 announcementsDelivery);
941 }
942 }
943 }
944
945 protected void clearUniqueFindersCache(
946 AnnouncementsDelivery announcementsDelivery) {
947 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
948
949 Object[] args = new Object[] {
950 announcementsDelivery.getUserId(),
951 announcementsDelivery.getType()
952 };
953
954 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
955 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
956
957 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
958 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
959 args = new Object[] {
960 announcementsDeliveryModelImpl.getOriginalUserId(),
961 announcementsDeliveryModelImpl.getOriginalType()
962 };
963
964 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
965 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
966 }
967 }
968
969
975 public AnnouncementsDelivery create(long deliveryId) {
976 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
977
978 announcementsDelivery.setNew(true);
979 announcementsDelivery.setPrimaryKey(deliveryId);
980
981 return announcementsDelivery;
982 }
983
984
992 public AnnouncementsDelivery remove(long deliveryId)
993 throws NoSuchDeliveryException, SystemException {
994 return remove((Serializable)deliveryId);
995 }
996
997
1005 @Override
1006 public AnnouncementsDelivery remove(Serializable primaryKey)
1007 throws NoSuchDeliveryException, SystemException {
1008 Session session = null;
1009
1010 try {
1011 session = openSession();
1012
1013 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1014 primaryKey);
1015
1016 if (announcementsDelivery == null) {
1017 if (_log.isWarnEnabled()) {
1018 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1019 }
1020
1021 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1022 primaryKey);
1023 }
1024
1025 return remove(announcementsDelivery);
1026 }
1027 catch (NoSuchDeliveryException nsee) {
1028 throw nsee;
1029 }
1030 catch (Exception e) {
1031 throw processException(e);
1032 }
1033 finally {
1034 closeSession(session);
1035 }
1036 }
1037
1038 @Override
1039 protected AnnouncementsDelivery removeImpl(
1040 AnnouncementsDelivery announcementsDelivery) throws SystemException {
1041 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
1042
1043 Session session = null;
1044
1045 try {
1046 session = openSession();
1047
1048 if (!session.contains(announcementsDelivery)) {
1049 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1050 announcementsDelivery.getPrimaryKeyObj());
1051 }
1052
1053 if (announcementsDelivery != null) {
1054 session.delete(announcementsDelivery);
1055 }
1056 }
1057 catch (Exception e) {
1058 throw processException(e);
1059 }
1060 finally {
1061 closeSession(session);
1062 }
1063
1064 if (announcementsDelivery != null) {
1065 clearCache(announcementsDelivery);
1066 }
1067
1068 return announcementsDelivery;
1069 }
1070
1071 @Override
1072 public AnnouncementsDelivery updateImpl(
1073 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery)
1074 throws SystemException {
1075 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
1076
1077 boolean isNew = announcementsDelivery.isNew();
1078
1079 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
1080
1081 Session session = null;
1082
1083 try {
1084 session = openSession();
1085
1086 if (announcementsDelivery.isNew()) {
1087 session.save(announcementsDelivery);
1088
1089 announcementsDelivery.setNew(false);
1090 }
1091 else {
1092 session.merge(announcementsDelivery);
1093 }
1094 }
1095 catch (Exception e) {
1096 throw processException(e);
1097 }
1098 finally {
1099 closeSession(session);
1100 }
1101
1102 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1103
1104 if (isNew || !AnnouncementsDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
1105 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1106 }
1107
1108 else {
1109 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
1110 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
1111 Object[] args = new Object[] {
1112 announcementsDeliveryModelImpl.getOriginalUserId()
1113 };
1114
1115 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1116 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1117 args);
1118
1119 args = new Object[] { announcementsDeliveryModelImpl.getUserId() };
1120
1121 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1122 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1123 args);
1124 }
1125 }
1126
1127 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1128 AnnouncementsDeliveryImpl.class,
1129 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
1130
1131 clearUniqueFindersCache(announcementsDelivery);
1132 cacheUniqueFindersCache(announcementsDelivery);
1133
1134 return announcementsDelivery;
1135 }
1136
1137 protected AnnouncementsDelivery toUnwrappedModel(
1138 AnnouncementsDelivery announcementsDelivery) {
1139 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
1140 return announcementsDelivery;
1141 }
1142
1143 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
1144
1145 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
1146 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
1147
1148 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
1149 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
1150 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
1151 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
1152 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
1153 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
1154 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
1155
1156 return announcementsDeliveryImpl;
1157 }
1158
1159
1167 @Override
1168 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
1169 throws NoSuchDeliveryException, SystemException {
1170 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(primaryKey);
1171
1172 if (announcementsDelivery == null) {
1173 if (_log.isWarnEnabled()) {
1174 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1175 }
1176
1177 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1178 primaryKey);
1179 }
1180
1181 return announcementsDelivery;
1182 }
1183
1184
1192 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
1193 throws NoSuchDeliveryException, SystemException {
1194 return findByPrimaryKey((Serializable)deliveryId);
1195 }
1196
1197
1204 @Override
1205 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
1206 throws SystemException {
1207 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1208 AnnouncementsDeliveryImpl.class, primaryKey);
1209
1210 if (announcementsDelivery == _nullAnnouncementsDelivery) {
1211 return null;
1212 }
1213
1214 if (announcementsDelivery == null) {
1215 Session session = null;
1216
1217 try {
1218 session = openSession();
1219
1220 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1221 primaryKey);
1222
1223 if (announcementsDelivery != null) {
1224 cacheResult(announcementsDelivery);
1225 }
1226 else {
1227 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1228 AnnouncementsDeliveryImpl.class, primaryKey,
1229 _nullAnnouncementsDelivery);
1230 }
1231 }
1232 catch (Exception e) {
1233 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1234 AnnouncementsDeliveryImpl.class, primaryKey);
1235
1236 throw processException(e);
1237 }
1238 finally {
1239 closeSession(session);
1240 }
1241 }
1242
1243 return announcementsDelivery;
1244 }
1245
1246
1253 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
1254 throws SystemException {
1255 return fetchByPrimaryKey((Serializable)deliveryId);
1256 }
1257
1258
1264 public List<AnnouncementsDelivery> findAll() throws SystemException {
1265 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1266 }
1267
1268
1280 public List<AnnouncementsDelivery> findAll(int start, int end)
1281 throws SystemException {
1282 return findAll(start, end, null);
1283 }
1284
1285
1298 public List<AnnouncementsDelivery> findAll(int start, int end,
1299 OrderByComparator orderByComparator) throws SystemException {
1300 boolean pagination = true;
1301 FinderPath finderPath = null;
1302 Object[] finderArgs = null;
1303
1304 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1305 (orderByComparator == null)) {
1306 pagination = false;
1307 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1308 finderArgs = FINDER_ARGS_EMPTY;
1309 }
1310 else {
1311 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1312 finderArgs = new Object[] { start, end, orderByComparator };
1313 }
1314
1315 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1316 finderArgs, this);
1317
1318 if (list == null) {
1319 StringBundler query = null;
1320 String sql = null;
1321
1322 if (orderByComparator != null) {
1323 query = new StringBundler(2 +
1324 (orderByComparator.getOrderByFields().length * 3));
1325
1326 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1327
1328 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1329 orderByComparator);
1330
1331 sql = query.toString();
1332 }
1333 else {
1334 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1335
1336 if (pagination) {
1337 sql = sql.concat(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
1338 }
1339 }
1340
1341 Session session = null;
1342
1343 try {
1344 session = openSession();
1345
1346 Query q = session.createQuery(sql);
1347
1348 if (!pagination) {
1349 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1350 getDialect(), start, end, false);
1351
1352 Collections.sort(list);
1353
1354 list = new UnmodifiableList<AnnouncementsDelivery>(list);
1355 }
1356 else {
1357 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1358 getDialect(), start, end);
1359 }
1360
1361 cacheResult(list);
1362
1363 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1364 }
1365 catch (Exception e) {
1366 FinderCacheUtil.removeResult(finderPath, finderArgs);
1367
1368 throw processException(e);
1369 }
1370 finally {
1371 closeSession(session);
1372 }
1373 }
1374
1375 return list;
1376 }
1377
1378
1383 public void removeAll() throws SystemException {
1384 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1385 remove(announcementsDelivery);
1386 }
1387 }
1388
1389
1395 public int countAll() throws SystemException {
1396 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1397 FINDER_ARGS_EMPTY, this);
1398
1399 if (count == null) {
1400 Session session = null;
1401
1402 try {
1403 session = openSession();
1404
1405 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1406
1407 count = (Long)q.uniqueResult();
1408
1409 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1410 FINDER_ARGS_EMPTY, count);
1411 }
1412 catch (Exception e) {
1413 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1414 FINDER_ARGS_EMPTY);
1415
1416 throw processException(e);
1417 }
1418 finally {
1419 closeSession(session);
1420 }
1421 }
1422
1423 return count.intValue();
1424 }
1425
1426
1429 public void afterPropertiesSet() {
1430 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1431 com.liferay.portal.util.PropsUtil.get(
1432 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1433
1434 if (listenerClassNames.length > 0) {
1435 try {
1436 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1437
1438 for (String listenerClassName : listenerClassNames) {
1439 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1440 listenerClassName));
1441 }
1442
1443 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1444 }
1445 catch (Exception e) {
1446 _log.error(e);
1447 }
1448 }
1449 }
1450
1451 public void destroy() {
1452 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1453 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1454 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1455 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1456 }
1457
1458 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1459 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1460 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1461 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1462 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1463 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1464 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1465 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1466 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1467 private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1468 @Override
1469 public Object clone() {
1470 return this;
1471 }
1472
1473 @Override
1474 public CacheModel<AnnouncementsDelivery> toCacheModel() {
1475 return _nullAnnouncementsDeliveryCacheModel;
1476 }
1477 };
1478
1479 private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1480 new CacheModel<AnnouncementsDelivery>() {
1481 public AnnouncementsDelivery toEntityModel() {
1482 return _nullAnnouncementsDelivery;
1483 }
1484 };
1485 }