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