001
014
015 package com.liferay.portlet.announcements.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.GetterUtil;
030 import com.liferay.portal.kernel.util.InstanceFactory;
031 import com.liferay.portal.kernel.util.OrderByComparator;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.UnmodifiableList;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.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
052
064 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
065 implements AnnouncementsDeliveryPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
077 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
078 AnnouncementsDeliveryImpl.class,
079 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
081 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
082 AnnouncementsDeliveryImpl.class,
083 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
085 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
088 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
089 AnnouncementsDeliveryImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
091 new String[] {
092 Long.class.getName(),
093
094 Integer.class.getName(), Integer.class.getName(),
095 OrderByComparator.class.getName()
096 });
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
098 new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
099 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
100 AnnouncementsDeliveryImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
102 new String[] { Long.class.getName() },
103 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK);
104 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
105 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
106 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
107 new String[] { Long.class.getName() });
108
109
116 public List<AnnouncementsDelivery> findByUserId(long userId)
117 throws SystemException {
118 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
135 int end) throws SystemException {
136 return findByUserId(userId, start, end, null);
137 }
138
139
153 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
154 int end, OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_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 = new UnmodifiableList<AnnouncementsDelivery>(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
259 public AnnouncementsDelivery findByUserId_First(long userId,
260 OrderByComparator orderByComparator)
261 throws NoSuchDeliveryException, SystemException {
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
289 public AnnouncementsDelivery fetchByUserId_First(long userId,
290 OrderByComparator orderByComparator) throws SystemException {
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
310 public AnnouncementsDelivery findByUserId_Last(long userId,
311 OrderByComparator orderByComparator)
312 throws NoSuchDeliveryException, SystemException {
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
340 public AnnouncementsDelivery fetchByUserId_Last(long userId,
341 OrderByComparator orderByComparator) throws SystemException {
342 int count = countByUserId(userId);
343
344 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
345 count, orderByComparator);
346
347 if (!list.isEmpty()) {
348 return list.get(0);
349 }
350
351 return null;
352 }
353
354
364 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
365 long userId, OrderByComparator orderByComparator)
366 throws NoSuchDeliveryException, SystemException {
367 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
368
369 Session session = null;
370
371 try {
372 session = openSession();
373
374 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
375
376 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
377 userId, orderByComparator, true);
378
379 array[1] = announcementsDelivery;
380
381 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
382 userId, orderByComparator, false);
383
384 return array;
385 }
386 catch (Exception e) {
387 throw processException(e);
388 }
389 finally {
390 closeSession(session);
391 }
392 }
393
394 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
395 AnnouncementsDelivery announcementsDelivery, long userId,
396 OrderByComparator orderByComparator, boolean previous) {
397 StringBundler query = null;
398
399 if (orderByComparator != null) {
400 query = new StringBundler(6 +
401 (orderByComparator.getOrderByFields().length * 6));
402 }
403 else {
404 query = new StringBundler(3);
405 }
406
407 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
408
409 query.append(_FINDER_COLUMN_USERID_USERID_2);
410
411 if (orderByComparator != null) {
412 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
413
414 if (orderByConditionFields.length > 0) {
415 query.append(WHERE_AND);
416 }
417
418 for (int i = 0; i < orderByConditionFields.length; i++) {
419 query.append(_ORDER_BY_ENTITY_ALIAS);
420 query.append(orderByConditionFields[i]);
421
422 if ((i + 1) < orderByConditionFields.length) {
423 if (orderByComparator.isAscending() ^ previous) {
424 query.append(WHERE_GREATER_THAN_HAS_NEXT);
425 }
426 else {
427 query.append(WHERE_LESSER_THAN_HAS_NEXT);
428 }
429 }
430 else {
431 if (orderByComparator.isAscending() ^ previous) {
432 query.append(WHERE_GREATER_THAN);
433 }
434 else {
435 query.append(WHERE_LESSER_THAN);
436 }
437 }
438 }
439
440 query.append(ORDER_BY_CLAUSE);
441
442 String[] orderByFields = orderByComparator.getOrderByFields();
443
444 for (int i = 0; i < orderByFields.length; i++) {
445 query.append(_ORDER_BY_ENTITY_ALIAS);
446 query.append(orderByFields[i]);
447
448 if ((i + 1) < orderByFields.length) {
449 if (orderByComparator.isAscending() ^ previous) {
450 query.append(ORDER_BY_ASC_HAS_NEXT);
451 }
452 else {
453 query.append(ORDER_BY_DESC_HAS_NEXT);
454 }
455 }
456 else {
457 if (orderByComparator.isAscending() ^ previous) {
458 query.append(ORDER_BY_ASC);
459 }
460 else {
461 query.append(ORDER_BY_DESC);
462 }
463 }
464 }
465 }
466 else {
467 query.append(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
468 }
469
470 String sql = query.toString();
471
472 Query q = session.createQuery(sql);
473
474 q.setFirstResult(0);
475 q.setMaxResults(2);
476
477 QueryPos qPos = QueryPos.getInstance(q);
478
479 qPos.add(userId);
480
481 if (orderByComparator != null) {
482 Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
483
484 for (Object value : values) {
485 qPos.add(value);
486 }
487 }
488
489 List<AnnouncementsDelivery> list = q.list();
490
491 if (list.size() == 2) {
492 return list.get(1);
493 }
494 else {
495 return null;
496 }
497 }
498
499
505 public void removeByUserId(long userId) throws SystemException {
506 for (AnnouncementsDelivery announcementsDelivery : findByUserId(
507 userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
508 remove(announcementsDelivery);
509 }
510 }
511
512
519 public int countByUserId(long userId) throws SystemException {
520 FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
521
522 Object[] finderArgs = new Object[] { userId };
523
524 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
525 this);
526
527 if (count == null) {
528 StringBundler query = new StringBundler(2);
529
530 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
531
532 query.append(_FINDER_COLUMN_USERID_USERID_2);
533
534 String sql = query.toString();
535
536 Session session = null;
537
538 try {
539 session = openSession();
540
541 Query q = session.createQuery(sql);
542
543 QueryPos qPos = QueryPos.getInstance(q);
544
545 qPos.add(userId);
546
547 count = (Long)q.uniqueResult();
548
549 FinderCacheUtil.putResult(finderPath, finderArgs, count);
550 }
551 catch (Exception e) {
552 FinderCacheUtil.removeResult(finderPath, finderArgs);
553
554 throw processException(e);
555 }
556 finally {
557 closeSession(session);
558 }
559 }
560
561 return count.intValue();
562 }
563
564 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
565 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
566 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
567 AnnouncementsDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
568 "fetchByU_T",
569 new String[] { Long.class.getName(), String.class.getName() },
570 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK |
571 AnnouncementsDeliveryModelImpl.TYPE_COLUMN_BITMASK);
572 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
573 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
574 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
575 new String[] { Long.class.getName(), String.class.getName() });
576
577
586 public AnnouncementsDelivery findByU_T(long userId, String type)
587 throws NoSuchDeliveryException, SystemException {
588 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
589
590 if (announcementsDelivery == null) {
591 StringBundler msg = new StringBundler(6);
592
593 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
594
595 msg.append("userId=");
596 msg.append(userId);
597
598 msg.append(", type=");
599 msg.append(type);
600
601 msg.append(StringPool.CLOSE_CURLY_BRACE);
602
603 if (_log.isWarnEnabled()) {
604 _log.warn(msg.toString());
605 }
606
607 throw new NoSuchDeliveryException(msg.toString());
608 }
609
610 return announcementsDelivery;
611 }
612
613
621 public AnnouncementsDelivery fetchByU_T(long userId, String type)
622 throws SystemException {
623 return fetchByU_T(userId, type, true);
624 }
625
626
635 public AnnouncementsDelivery fetchByU_T(long userId, String type,
636 boolean retrieveFromCache) throws SystemException {
637 Object[] finderArgs = new Object[] { userId, type };
638
639 Object result = null;
640
641 if (retrieveFromCache) {
642 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
643 finderArgs, this);
644 }
645
646 if (result instanceof AnnouncementsDelivery) {
647 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)result;
648
649 if ((userId != announcementsDelivery.getUserId()) ||
650 !Validator.equals(type, announcementsDelivery.getType())) {
651 result = null;
652 }
653 }
654
655 if (result == null) {
656 StringBundler query = new StringBundler(4);
657
658 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
659
660 query.append(_FINDER_COLUMN_U_T_USERID_2);
661
662 if (type == null) {
663 query.append(_FINDER_COLUMN_U_T_TYPE_1);
664 }
665 else {
666 if (type.equals(StringPool.BLANK)) {
667 query.append(_FINDER_COLUMN_U_T_TYPE_3);
668 }
669 else {
670 query.append(_FINDER_COLUMN_U_T_TYPE_2);
671 }
672 }
673
674 String sql = query.toString();
675
676 Session session = null;
677
678 try {
679 session = openSession();
680
681 Query q = session.createQuery(sql);
682
683 QueryPos qPos = QueryPos.getInstance(q);
684
685 qPos.add(userId);
686
687 if (type != null) {
688 qPos.add(type);
689 }
690
691 List<AnnouncementsDelivery> list = q.list();
692
693 if (list.isEmpty()) {
694 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
695 finderArgs, list);
696 }
697 else {
698 AnnouncementsDelivery announcementsDelivery = list.get(0);
699
700 result = announcementsDelivery;
701
702 cacheResult(announcementsDelivery);
703
704 if ((announcementsDelivery.getUserId() != userId) ||
705 (announcementsDelivery.getType() == null) ||
706 !announcementsDelivery.getType().equals(type)) {
707 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
708 finderArgs, announcementsDelivery);
709 }
710 }
711 }
712 catch (Exception e) {
713 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
714 finderArgs);
715
716 throw processException(e);
717 }
718 finally {
719 closeSession(session);
720 }
721 }
722
723 if (result instanceof List<?>) {
724 return null;
725 }
726 else {
727 return (AnnouncementsDelivery)result;
728 }
729 }
730
731
739 public AnnouncementsDelivery removeByU_T(long userId, String type)
740 throws NoSuchDeliveryException, SystemException {
741 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
742
743 return remove(announcementsDelivery);
744 }
745
746
754 public int countByU_T(long userId, String type) throws SystemException {
755 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_T;
756
757 Object[] finderArgs = new Object[] { userId, type };
758
759 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
760 this);
761
762 if (count == null) {
763 StringBundler query = new StringBundler(3);
764
765 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
766
767 query.append(_FINDER_COLUMN_U_T_USERID_2);
768
769 if (type == null) {
770 query.append(_FINDER_COLUMN_U_T_TYPE_1);
771 }
772 else {
773 if (type.equals(StringPool.BLANK)) {
774 query.append(_FINDER_COLUMN_U_T_TYPE_3);
775 }
776 else {
777 query.append(_FINDER_COLUMN_U_T_TYPE_2);
778 }
779 }
780
781 String sql = query.toString();
782
783 Session session = null;
784
785 try {
786 session = openSession();
787
788 Query q = session.createQuery(sql);
789
790 QueryPos qPos = QueryPos.getInstance(q);
791
792 qPos.add(userId);
793
794 if (type != null) {
795 qPos.add(type);
796 }
797
798 count = (Long)q.uniqueResult();
799
800 FinderCacheUtil.putResult(finderPath, finderArgs, count);
801 }
802 catch (Exception e) {
803 FinderCacheUtil.removeResult(finderPath, finderArgs);
804
805 throw processException(e);
806 }
807 finally {
808 closeSession(session);
809 }
810 }
811
812 return count.intValue();
813 }
814
815 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
816 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
817 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
818 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
819
820
825 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
826 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
827 AnnouncementsDeliveryImpl.class,
828 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
829
830 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
831 new Object[] {
832 Long.valueOf(announcementsDelivery.getUserId()),
833
834 announcementsDelivery.getType()
835 }, announcementsDelivery);
836
837 announcementsDelivery.resetOriginalValues();
838 }
839
840
845 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
846 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
847 if (EntityCacheUtil.getResult(
848 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
849 AnnouncementsDeliveryImpl.class,
850 announcementsDelivery.getPrimaryKey()) == null) {
851 cacheResult(announcementsDelivery);
852 }
853 else {
854 announcementsDelivery.resetOriginalValues();
855 }
856 }
857 }
858
859
866 @Override
867 public void clearCache() {
868 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
869 CacheRegistryUtil.clear(AnnouncementsDeliveryImpl.class.getName());
870 }
871
872 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
873
874 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
875 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
876 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
877 }
878
879
886 @Override
887 public void clearCache(AnnouncementsDelivery announcementsDelivery) {
888 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
889 AnnouncementsDeliveryImpl.class,
890 announcementsDelivery.getPrimaryKey());
891
892 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
893 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
894
895 clearUniqueFindersCache(announcementsDelivery);
896 }
897
898 @Override
899 public void clearCache(List<AnnouncementsDelivery> announcementsDeliveries) {
900 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
901 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
902
903 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
904 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
905 AnnouncementsDeliveryImpl.class,
906 announcementsDelivery.getPrimaryKey());
907
908 clearUniqueFindersCache(announcementsDelivery);
909 }
910 }
911
912 protected void cacheUniqueFindersCache(
913 AnnouncementsDelivery announcementsDelivery) {
914 if (announcementsDelivery.isNew()) {
915 Object[] args = new Object[] {
916 Long.valueOf(announcementsDelivery.getUserId()),
917
918 announcementsDelivery.getType()
919 };
920
921 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
922 Long.valueOf(1));
923 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
924 announcementsDelivery);
925 }
926 else {
927 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
928
929 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
930 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
931 Object[] args = new Object[] {
932 Long.valueOf(announcementsDelivery.getUserId()),
933
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 Long.valueOf(announcementsDelivery.getUserId()),
951
952 announcementsDelivery.getType()
953 };
954
955 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
956 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
957
958 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
959 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
960 args = new Object[] {
961 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId()),
962
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(Long.valueOf(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 Long.valueOf(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[] {
1122 Long.valueOf(announcementsDeliveryModelImpl.getUserId())
1123 };
1124
1125 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
1126 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
1127 args);
1128 }
1129 }
1130
1131 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1132 AnnouncementsDeliveryImpl.class,
1133 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
1134
1135 clearUniqueFindersCache(announcementsDelivery);
1136 cacheUniqueFindersCache(announcementsDelivery);
1137
1138 return announcementsDelivery;
1139 }
1140
1141 protected AnnouncementsDelivery toUnwrappedModel(
1142 AnnouncementsDelivery announcementsDelivery) {
1143 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
1144 return announcementsDelivery;
1145 }
1146
1147 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
1148
1149 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
1150 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
1151
1152 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
1153 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
1154 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
1155 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
1156 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
1157 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
1158 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
1159
1160 return announcementsDeliveryImpl;
1161 }
1162
1163
1171 @Override
1172 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
1173 throws NoSuchModelException, SystemException {
1174 return findByPrimaryKey(((Long)primaryKey).longValue());
1175 }
1176
1177
1185 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
1186 throws NoSuchDeliveryException, SystemException {
1187 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
1188
1189 if (announcementsDelivery == null) {
1190 if (_log.isWarnEnabled()) {
1191 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
1192 }
1193
1194 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1195 deliveryId);
1196 }
1197
1198 return announcementsDelivery;
1199 }
1200
1201
1208 @Override
1209 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
1210 throws SystemException {
1211 return fetchByPrimaryKey(((Long)primaryKey).longValue());
1212 }
1213
1214
1221 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
1222 throws SystemException {
1223 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1224 AnnouncementsDeliveryImpl.class, deliveryId);
1225
1226 if (announcementsDelivery == _nullAnnouncementsDelivery) {
1227 return null;
1228 }
1229
1230 if (announcementsDelivery == null) {
1231 Session session = null;
1232
1233 try {
1234 session = openSession();
1235
1236 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
1237 Long.valueOf(deliveryId));
1238
1239 if (announcementsDelivery != null) {
1240 cacheResult(announcementsDelivery);
1241 }
1242 else {
1243 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1244 AnnouncementsDeliveryImpl.class, deliveryId,
1245 _nullAnnouncementsDelivery);
1246 }
1247 }
1248 catch (Exception e) {
1249 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
1250 AnnouncementsDeliveryImpl.class, deliveryId);
1251
1252 throw processException(e);
1253 }
1254 finally {
1255 closeSession(session);
1256 }
1257 }
1258
1259 return announcementsDelivery;
1260 }
1261
1262
1268 public List<AnnouncementsDelivery> findAll() throws SystemException {
1269 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1270 }
1271
1272
1284 public List<AnnouncementsDelivery> findAll(int start, int end)
1285 throws SystemException {
1286 return findAll(start, end, null);
1287 }
1288
1289
1302 public List<AnnouncementsDelivery> findAll(int start, int end,
1303 OrderByComparator orderByComparator) throws SystemException {
1304 boolean pagination = true;
1305 FinderPath finderPath = null;
1306 Object[] finderArgs = null;
1307
1308 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1309 (orderByComparator == null)) {
1310 pagination = false;
1311 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1312 finderArgs = FINDER_ARGS_EMPTY;
1313 }
1314 else {
1315 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1316 finderArgs = new Object[] { start, end, orderByComparator };
1317 }
1318
1319 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1320 finderArgs, this);
1321
1322 if (list == null) {
1323 StringBundler query = null;
1324 String sql = null;
1325
1326 if (orderByComparator != null) {
1327 query = new StringBundler(2 +
1328 (orderByComparator.getOrderByFields().length * 3));
1329
1330 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1331
1332 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1333 orderByComparator);
1334
1335 sql = query.toString();
1336 }
1337 else {
1338 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1339
1340 if (pagination) {
1341 sql = sql.concat(AnnouncementsDeliveryModelImpl.ORDER_BY_JPQL);
1342 }
1343 }
1344
1345 Session session = null;
1346
1347 try {
1348 session = openSession();
1349
1350 Query q = session.createQuery(sql);
1351
1352 if (!pagination) {
1353 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1354 getDialect(), start, end, false);
1355
1356 Collections.sort(list);
1357
1358 list = new UnmodifiableList<AnnouncementsDelivery>(list);
1359 }
1360 else {
1361 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1362 getDialect(), start, end);
1363 }
1364
1365 cacheResult(list);
1366
1367 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1368 }
1369 catch (Exception e) {
1370 FinderCacheUtil.removeResult(finderPath, finderArgs);
1371
1372 throw processException(e);
1373 }
1374 finally {
1375 closeSession(session);
1376 }
1377 }
1378
1379 return list;
1380 }
1381
1382
1387 public void removeAll() throws SystemException {
1388 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1389 remove(announcementsDelivery);
1390 }
1391 }
1392
1393
1399 public int countAll() throws SystemException {
1400 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1401 FINDER_ARGS_EMPTY, this);
1402
1403 if (count == null) {
1404 Session session = null;
1405
1406 try {
1407 session = openSession();
1408
1409 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1410
1411 count = (Long)q.uniqueResult();
1412
1413 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1414 FINDER_ARGS_EMPTY, count);
1415 }
1416 catch (Exception e) {
1417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
1418 FINDER_ARGS_EMPTY);
1419
1420 throw processException(e);
1421 }
1422 finally {
1423 closeSession(session);
1424 }
1425 }
1426
1427 return count.intValue();
1428 }
1429
1430
1433 public void afterPropertiesSet() {
1434 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1435 com.liferay.portal.util.PropsUtil.get(
1436 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1437
1438 if (listenerClassNames.length > 0) {
1439 try {
1440 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1441
1442 for (String listenerClassName : listenerClassNames) {
1443 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1444 listenerClassName));
1445 }
1446
1447 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1448 }
1449 catch (Exception e) {
1450 _log.error(e);
1451 }
1452 }
1453 }
1454
1455 public void destroy() {
1456 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1457 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1458 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1459 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1460 }
1461
1462 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1463 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1464 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1465 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1466 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1467 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1468 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1469 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1470 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1471 private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1472 @Override
1473 public Object clone() {
1474 return this;
1475 }
1476
1477 @Override
1478 public CacheModel<AnnouncementsDelivery> toCacheModel() {
1479 return _nullAnnouncementsDeliveryCacheModel;
1480 }
1481 };
1482
1483 private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1484 new CacheModel<AnnouncementsDelivery>() {
1485 public AnnouncementsDelivery toEntityModel() {
1486 return _nullAnnouncementsDelivery;
1487 }
1488 };
1489 }