001
014
015 package com.liferay.portlet.announcements.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.kernel.util.Validator;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.announcements.NoSuchDeliveryException;
044 import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
045 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryImpl;
046 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
070 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
071 implements AnnouncementsDeliveryPersistence {
072 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
073 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
074 ".List";
075 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
076 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
077 FINDER_CLASS_NAME_LIST, "findByUserId",
078 new String[] {
079 Long.class.getName(),
080
081 "java.lang.Integer", "java.lang.Integer",
082 "com.liferay.portal.kernel.util.OrderByComparator"
083 });
084 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
085 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
086 FINDER_CLASS_NAME_LIST, "countByUserId",
087 new String[] { Long.class.getName() });
088 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
089 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
090 FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
091 new String[] { Long.class.getName(), String.class.getName() });
092 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
093 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
094 FINDER_CLASS_NAME_LIST, "countByU_T",
095 new String[] { Long.class.getName(), String.class.getName() });
096 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
097 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
098 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
100 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
101 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
102
103
108 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
109 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
110 AnnouncementsDeliveryImpl.class,
111 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
112
113 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
114 new Object[] {
115 new Long(announcementsDelivery.getUserId()),
116
117 announcementsDelivery.getType()
118 }, announcementsDelivery);
119 }
120
121
126 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
127 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
128 if (EntityCacheUtil.getResult(
129 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
130 AnnouncementsDeliveryImpl.class,
131 announcementsDelivery.getPrimaryKey(), this) == null) {
132 cacheResult(announcementsDelivery);
133 }
134 }
135 }
136
137
144 public void clearCache() {
145 CacheRegistryUtil.clear(AnnouncementsDeliveryImpl.class.getName());
146 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
149 }
150
151
158 public void clearCache(AnnouncementsDelivery announcementsDelivery) {
159 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
160 AnnouncementsDeliveryImpl.class,
161 announcementsDelivery.getPrimaryKey());
162
163 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
164 new Object[] {
165 new Long(announcementsDelivery.getUserId()),
166
167 announcementsDelivery.getType()
168 });
169 }
170
171
177 public AnnouncementsDelivery create(long deliveryId) {
178 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
179
180 announcementsDelivery.setNew(true);
181 announcementsDelivery.setPrimaryKey(deliveryId);
182
183 return announcementsDelivery;
184 }
185
186
194 public AnnouncementsDelivery remove(Serializable primaryKey)
195 throws NoSuchModelException, SystemException {
196 return remove(((Long)primaryKey).longValue());
197 }
198
199
207 public AnnouncementsDelivery remove(long deliveryId)
208 throws NoSuchDeliveryException, SystemException {
209 Session session = null;
210
211 try {
212 session = openSession();
213
214 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
215 new Long(deliveryId));
216
217 if (announcementsDelivery == null) {
218 if (_log.isWarnEnabled()) {
219 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
220 }
221
222 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
223 deliveryId);
224 }
225
226 return remove(announcementsDelivery);
227 }
228 catch (NoSuchDeliveryException nsee) {
229 throw nsee;
230 }
231 catch (Exception e) {
232 throw processException(e);
233 }
234 finally {
235 closeSession(session);
236 }
237 }
238
239 protected AnnouncementsDelivery removeImpl(
240 AnnouncementsDelivery announcementsDelivery) throws SystemException {
241 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
242
243 Session session = null;
244
245 try {
246 session = openSession();
247
248 BatchSessionUtil.delete(session, announcementsDelivery);
249 }
250 catch (Exception e) {
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256
257 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
258
259 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
260
261 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
262 new Object[] {
263 new Long(announcementsDeliveryModelImpl.getOriginalUserId()),
264
265 announcementsDeliveryModelImpl.getOriginalType()
266 });
267
268 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
269 AnnouncementsDeliveryImpl.class,
270 announcementsDelivery.getPrimaryKey());
271
272 return announcementsDelivery;
273 }
274
275 public AnnouncementsDelivery updateImpl(
276 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery,
277 boolean merge) throws SystemException {
278 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
279
280 boolean isNew = announcementsDelivery.isNew();
281
282 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
283
284 Session session = null;
285
286 try {
287 session = openSession();
288
289 BatchSessionUtil.update(session, announcementsDelivery, merge);
290
291 announcementsDelivery.setNew(false);
292 }
293 catch (Exception e) {
294 throw processException(e);
295 }
296 finally {
297 closeSession(session);
298 }
299
300 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
301
302 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
303 AnnouncementsDeliveryImpl.class,
304 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
305
306 if (!isNew &&
307 ((announcementsDelivery.getUserId() != announcementsDeliveryModelImpl.getOriginalUserId()) ||
308 !Validator.equals(announcementsDelivery.getType(),
309 announcementsDeliveryModelImpl.getOriginalType()))) {
310 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
311 new Object[] {
312 new Long(announcementsDeliveryModelImpl.getOriginalUserId()),
313
314 announcementsDeliveryModelImpl.getOriginalType()
315 });
316 }
317
318 if (isNew ||
319 ((announcementsDelivery.getUserId() != announcementsDeliveryModelImpl.getOriginalUserId()) ||
320 !Validator.equals(announcementsDelivery.getType(),
321 announcementsDeliveryModelImpl.getOriginalType()))) {
322 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
323 new Object[] {
324 new Long(announcementsDelivery.getUserId()),
325
326 announcementsDelivery.getType()
327 }, announcementsDelivery);
328 }
329
330 return announcementsDelivery;
331 }
332
333 protected AnnouncementsDelivery toUnwrappedModel(
334 AnnouncementsDelivery announcementsDelivery) {
335 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
336 return announcementsDelivery;
337 }
338
339 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
340
341 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
342 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
343
344 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
345 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
346 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
347 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
348 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
349 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
350 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
351
352 return announcementsDeliveryImpl;
353 }
354
355
363 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
364 throws NoSuchModelException, SystemException {
365 return findByPrimaryKey(((Long)primaryKey).longValue());
366 }
367
368
376 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
377 throws NoSuchDeliveryException, SystemException {
378 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
379
380 if (announcementsDelivery == null) {
381 if (_log.isWarnEnabled()) {
382 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
383 }
384
385 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
386 deliveryId);
387 }
388
389 return announcementsDelivery;
390 }
391
392
399 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
400 throws SystemException {
401 return fetchByPrimaryKey(((Long)primaryKey).longValue());
402 }
403
404
411 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
412 throws SystemException {
413 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
414 AnnouncementsDeliveryImpl.class, deliveryId, this);
415
416 if (announcementsDelivery == null) {
417 Session session = null;
418
419 try {
420 session = openSession();
421
422 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
423 new Long(deliveryId));
424 }
425 catch (Exception e) {
426 throw processException(e);
427 }
428 finally {
429 if (announcementsDelivery != null) {
430 cacheResult(announcementsDelivery);
431 }
432
433 closeSession(session);
434 }
435 }
436
437 return announcementsDelivery;
438 }
439
440
447 public List<AnnouncementsDelivery> findByUserId(long userId)
448 throws SystemException {
449 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
450 }
451
452
465 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
466 int end) throws SystemException {
467 return findByUserId(userId, start, end, null);
468 }
469
470
484 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
485 int end, OrderByComparator orderByComparator) throws SystemException {
486 Object[] finderArgs = new Object[] {
487 userId,
488
489 String.valueOf(start), String.valueOf(end),
490 String.valueOf(orderByComparator)
491 };
492
493 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
494 finderArgs, this);
495
496 if (list == null) {
497 Session session = null;
498
499 try {
500 session = openSession();
501
502 StringBundler query = null;
503
504 if (orderByComparator != null) {
505 query = new StringBundler(3 +
506 (orderByComparator.getOrderByFields().length * 3));
507 }
508 else {
509 query = new StringBundler(2);
510 }
511
512 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
513
514 query.append(_FINDER_COLUMN_USERID_USERID_2);
515
516 if (orderByComparator != null) {
517 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
518 orderByComparator);
519 }
520
521 String sql = query.toString();
522
523 Query q = session.createQuery(sql);
524
525 QueryPos qPos = QueryPos.getInstance(q);
526
527 qPos.add(userId);
528
529 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
530 getDialect(), start, end);
531 }
532 catch (Exception e) {
533 throw processException(e);
534 }
535 finally {
536 if (list == null) {
537 list = new ArrayList<AnnouncementsDelivery>();
538 }
539
540 cacheResult(list);
541
542 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
543 finderArgs, list);
544
545 closeSession(session);
546 }
547 }
548
549 return list;
550 }
551
552
565 public AnnouncementsDelivery findByUserId_First(long userId,
566 OrderByComparator orderByComparator)
567 throws NoSuchDeliveryException, SystemException {
568 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
569 orderByComparator);
570
571 if (list.isEmpty()) {
572 StringBundler msg = new StringBundler(4);
573
574 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
575
576 msg.append("userId=");
577 msg.append(userId);
578
579 msg.append(StringPool.CLOSE_CURLY_BRACE);
580
581 throw new NoSuchDeliveryException(msg.toString());
582 }
583 else {
584 return list.get(0);
585 }
586 }
587
588
601 public AnnouncementsDelivery findByUserId_Last(long userId,
602 OrderByComparator orderByComparator)
603 throws NoSuchDeliveryException, SystemException {
604 int count = countByUserId(userId);
605
606 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
607 count, orderByComparator);
608
609 if (list.isEmpty()) {
610 StringBundler msg = new StringBundler(4);
611
612 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
613
614 msg.append("userId=");
615 msg.append(userId);
616
617 msg.append(StringPool.CLOSE_CURLY_BRACE);
618
619 throw new NoSuchDeliveryException(msg.toString());
620 }
621 else {
622 return list.get(0);
623 }
624 }
625
626
640 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
641 long userId, OrderByComparator orderByComparator)
642 throws NoSuchDeliveryException, SystemException {
643 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
644
645 Session session = null;
646
647 try {
648 session = openSession();
649
650 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
651
652 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
653 userId, orderByComparator, true);
654
655 array[1] = announcementsDelivery;
656
657 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
658 userId, orderByComparator, false);
659
660 return array;
661 }
662 catch (Exception e) {
663 throw processException(e);
664 }
665 finally {
666 closeSession(session);
667 }
668 }
669
670 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
671 AnnouncementsDelivery announcementsDelivery, long userId,
672 OrderByComparator orderByComparator, boolean previous) {
673 StringBundler query = null;
674
675 if (orderByComparator != null) {
676 query = new StringBundler(6 +
677 (orderByComparator.getOrderByFields().length * 6));
678 }
679 else {
680 query = new StringBundler(3);
681 }
682
683 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
684
685 query.append(_FINDER_COLUMN_USERID_USERID_2);
686
687 if (orderByComparator != null) {
688 String[] orderByFields = orderByComparator.getOrderByFields();
689
690 if (orderByFields.length > 0) {
691 query.append(WHERE_AND);
692 }
693
694 for (int i = 0; i < orderByFields.length; i++) {
695 query.append(_ORDER_BY_ENTITY_ALIAS);
696 query.append(orderByFields[i]);
697
698 if ((i + 1) < orderByFields.length) {
699 if (orderByComparator.isAscending() ^ previous) {
700 query.append(WHERE_GREATER_THAN_HAS_NEXT);
701 }
702 else {
703 query.append(WHERE_LESSER_THAN_HAS_NEXT);
704 }
705 }
706 else {
707 if (orderByComparator.isAscending() ^ previous) {
708 query.append(WHERE_GREATER_THAN);
709 }
710 else {
711 query.append(WHERE_LESSER_THAN);
712 }
713 }
714 }
715
716 query.append(ORDER_BY_CLAUSE);
717
718 for (int i = 0; i < orderByFields.length; i++) {
719 query.append(_ORDER_BY_ENTITY_ALIAS);
720 query.append(orderByFields[i]);
721
722 if ((i + 1) < orderByFields.length) {
723 if (orderByComparator.isAscending() ^ previous) {
724 query.append(ORDER_BY_ASC_HAS_NEXT);
725 }
726 else {
727 query.append(ORDER_BY_DESC_HAS_NEXT);
728 }
729 }
730 else {
731 if (orderByComparator.isAscending() ^ previous) {
732 query.append(ORDER_BY_ASC);
733 }
734 else {
735 query.append(ORDER_BY_DESC);
736 }
737 }
738 }
739 }
740
741 String sql = query.toString();
742
743 Query q = session.createQuery(sql);
744
745 q.setFirstResult(0);
746 q.setMaxResults(2);
747
748 QueryPos qPos = QueryPos.getInstance(q);
749
750 qPos.add(userId);
751
752 if (orderByComparator != null) {
753 Object[] values = orderByComparator.getOrderByValues(announcementsDelivery);
754
755 for (Object value : values) {
756 qPos.add(value);
757 }
758 }
759
760 List<AnnouncementsDelivery> list = q.list();
761
762 if (list.size() == 2) {
763 return list.get(1);
764 }
765 else {
766 return null;
767 }
768 }
769
770
779 public AnnouncementsDelivery findByU_T(long userId, String type)
780 throws NoSuchDeliveryException, SystemException {
781 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
782
783 if (announcementsDelivery == null) {
784 StringBundler msg = new StringBundler(6);
785
786 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
787
788 msg.append("userId=");
789 msg.append(userId);
790
791 msg.append(", type=");
792 msg.append(type);
793
794 msg.append(StringPool.CLOSE_CURLY_BRACE);
795
796 if (_log.isWarnEnabled()) {
797 _log.warn(msg.toString());
798 }
799
800 throw new NoSuchDeliveryException(msg.toString());
801 }
802
803 return announcementsDelivery;
804 }
805
806
814 public AnnouncementsDelivery fetchByU_T(long userId, String type)
815 throws SystemException {
816 return fetchByU_T(userId, type, true);
817 }
818
819
827 public AnnouncementsDelivery fetchByU_T(long userId, String type,
828 boolean retrieveFromCache) throws SystemException {
829 Object[] finderArgs = new Object[] { userId, type };
830
831 Object result = null;
832
833 if (retrieveFromCache) {
834 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
835 finderArgs, this);
836 }
837
838 if (result == null) {
839 Session session = null;
840
841 try {
842 session = openSession();
843
844 StringBundler query = new StringBundler(3);
845
846 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
847
848 query.append(_FINDER_COLUMN_U_T_USERID_2);
849
850 if (type == null) {
851 query.append(_FINDER_COLUMN_U_T_TYPE_1);
852 }
853 else {
854 if (type.equals(StringPool.BLANK)) {
855 query.append(_FINDER_COLUMN_U_T_TYPE_3);
856 }
857 else {
858 query.append(_FINDER_COLUMN_U_T_TYPE_2);
859 }
860 }
861
862 String sql = query.toString();
863
864 Query q = session.createQuery(sql);
865
866 QueryPos qPos = QueryPos.getInstance(q);
867
868 qPos.add(userId);
869
870 if (type != null) {
871 qPos.add(type);
872 }
873
874 List<AnnouncementsDelivery> list = q.list();
875
876 result = list;
877
878 AnnouncementsDelivery announcementsDelivery = null;
879
880 if (list.isEmpty()) {
881 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
882 finderArgs, list);
883 }
884 else {
885 announcementsDelivery = list.get(0);
886
887 cacheResult(announcementsDelivery);
888
889 if ((announcementsDelivery.getUserId() != userId) ||
890 (announcementsDelivery.getType() == null) ||
891 !announcementsDelivery.getType().equals(type)) {
892 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
893 finderArgs, announcementsDelivery);
894 }
895 }
896
897 return announcementsDelivery;
898 }
899 catch (Exception e) {
900 throw processException(e);
901 }
902 finally {
903 if (result == null) {
904 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
905 finderArgs, new ArrayList<AnnouncementsDelivery>());
906 }
907
908 closeSession(session);
909 }
910 }
911 else {
912 if (result instanceof List<?>) {
913 return null;
914 }
915 else {
916 return (AnnouncementsDelivery)result;
917 }
918 }
919 }
920
921
927 public List<AnnouncementsDelivery> findAll() throws SystemException {
928 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
929 }
930
931
943 public List<AnnouncementsDelivery> findAll(int start, int end)
944 throws SystemException {
945 return findAll(start, end, null);
946 }
947
948
961 public List<AnnouncementsDelivery> findAll(int start, int end,
962 OrderByComparator orderByComparator) throws SystemException {
963 Object[] finderArgs = new Object[] {
964 String.valueOf(start), String.valueOf(end),
965 String.valueOf(orderByComparator)
966 };
967
968 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
969 finderArgs, this);
970
971 if (list == null) {
972 Session session = null;
973
974 try {
975 session = openSession();
976
977 StringBundler query = null;
978 String sql = null;
979
980 if (orderByComparator != null) {
981 query = new StringBundler(2 +
982 (orderByComparator.getOrderByFields().length * 3));
983
984 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
985
986 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
987 orderByComparator);
988
989 sql = query.toString();
990 }
991 else {
992 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
993 }
994
995 Query q = session.createQuery(sql);
996
997 if (orderByComparator == null) {
998 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
999 getDialect(), start, end, false);
1000
1001 Collections.sort(list);
1002 }
1003 else {
1004 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1005 getDialect(), start, end);
1006 }
1007 }
1008 catch (Exception e) {
1009 throw processException(e);
1010 }
1011 finally {
1012 if (list == null) {
1013 list = new ArrayList<AnnouncementsDelivery>();
1014 }
1015
1016 cacheResult(list);
1017
1018 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1019
1020 closeSession(session);
1021 }
1022 }
1023
1024 return list;
1025 }
1026
1027
1033 public void removeByUserId(long userId) throws SystemException {
1034 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1035 remove(announcementsDelivery);
1036 }
1037 }
1038
1039
1046 public void removeByU_T(long userId, String type)
1047 throws NoSuchDeliveryException, SystemException {
1048 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1049
1050 remove(announcementsDelivery);
1051 }
1052
1053
1058 public void removeAll() throws SystemException {
1059 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1060 remove(announcementsDelivery);
1061 }
1062 }
1063
1064
1071 public int countByUserId(long userId) throws SystemException {
1072 Object[] finderArgs = new Object[] { userId };
1073
1074 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1075 finderArgs, this);
1076
1077 if (count == null) {
1078 Session session = null;
1079
1080 try {
1081 session = openSession();
1082
1083 StringBundler query = new StringBundler(2);
1084
1085 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1086
1087 query.append(_FINDER_COLUMN_USERID_USERID_2);
1088
1089 String sql = query.toString();
1090
1091 Query q = session.createQuery(sql);
1092
1093 QueryPos qPos = QueryPos.getInstance(q);
1094
1095 qPos.add(userId);
1096
1097 count = (Long)q.uniqueResult();
1098 }
1099 catch (Exception e) {
1100 throw processException(e);
1101 }
1102 finally {
1103 if (count == null) {
1104 count = Long.valueOf(0);
1105 }
1106
1107 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1108 finderArgs, count);
1109
1110 closeSession(session);
1111 }
1112 }
1113
1114 return count.intValue();
1115 }
1116
1117
1125 public int countByU_T(long userId, String type) throws SystemException {
1126 Object[] finderArgs = new Object[] { userId, type };
1127
1128 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1129 finderArgs, this);
1130
1131 if (count == null) {
1132 Session session = null;
1133
1134 try {
1135 session = openSession();
1136
1137 StringBundler query = new StringBundler(3);
1138
1139 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1140
1141 query.append(_FINDER_COLUMN_U_T_USERID_2);
1142
1143 if (type == null) {
1144 query.append(_FINDER_COLUMN_U_T_TYPE_1);
1145 }
1146 else {
1147 if (type.equals(StringPool.BLANK)) {
1148 query.append(_FINDER_COLUMN_U_T_TYPE_3);
1149 }
1150 else {
1151 query.append(_FINDER_COLUMN_U_T_TYPE_2);
1152 }
1153 }
1154
1155 String sql = query.toString();
1156
1157 Query q = session.createQuery(sql);
1158
1159 QueryPos qPos = QueryPos.getInstance(q);
1160
1161 qPos.add(userId);
1162
1163 if (type != null) {
1164 qPos.add(type);
1165 }
1166
1167 count = (Long)q.uniqueResult();
1168 }
1169 catch (Exception e) {
1170 throw processException(e);
1171 }
1172 finally {
1173 if (count == null) {
1174 count = Long.valueOf(0);
1175 }
1176
1177 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1178 count);
1179
1180 closeSession(session);
1181 }
1182 }
1183
1184 return count.intValue();
1185 }
1186
1187
1193 public int countAll() throws SystemException {
1194 Object[] finderArgs = new Object[0];
1195
1196 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1197 finderArgs, this);
1198
1199 if (count == null) {
1200 Session session = null;
1201
1202 try {
1203 session = openSession();
1204
1205 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1206
1207 count = (Long)q.uniqueResult();
1208 }
1209 catch (Exception e) {
1210 throw processException(e);
1211 }
1212 finally {
1213 if (count == null) {
1214 count = Long.valueOf(0);
1215 }
1216
1217 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1218 count);
1219
1220 closeSession(session);
1221 }
1222 }
1223
1224 return count.intValue();
1225 }
1226
1227
1230 public void afterPropertiesSet() {
1231 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1232 com.liferay.portal.util.PropsUtil.get(
1233 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1234
1235 if (listenerClassNames.length > 0) {
1236 try {
1237 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1238
1239 for (String listenerClassName : listenerClassNames) {
1240 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1241 listenerClassName));
1242 }
1243
1244 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1245 }
1246 catch (Exception e) {
1247 _log.error(e);
1248 }
1249 }
1250 }
1251
1252 public void destroy() {
1253 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1254 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1255 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1256 }
1257
1258 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1259 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1260 @BeanReference(type = AnnouncementsEntryPersistence.class)
1261 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1262 @BeanReference(type = AnnouncementsFlagPersistence.class)
1263 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1264 @BeanReference(type = ResourcePersistence.class)
1265 protected ResourcePersistence resourcePersistence;
1266 @BeanReference(type = UserPersistence.class)
1267 protected UserPersistence userPersistence;
1268 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1269 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1270 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1271 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1272 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1273 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1274 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1275 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1276 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1277 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1278 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1279 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1280 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1281 }