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.getUserId()),
264
265 announcementsDeliveryModelImpl.getType()
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 StringBundler query = null;
498
499 if (orderByComparator != null) {
500 query = new StringBundler(3 +
501 (orderByComparator.getOrderByFields().length * 3));
502 }
503 else {
504 query = new StringBundler(2);
505 }
506
507 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
508
509 query.append(_FINDER_COLUMN_USERID_USERID_2);
510
511 if (orderByComparator != null) {
512 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
513 orderByComparator);
514 }
515
516 String sql = query.toString();
517
518 Session session = null;
519
520 try {
521 session = openSession();
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 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
538 finderArgs);
539 }
540 else {
541 cacheResult(list);
542
543 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
544 finderArgs, list);
545 }
546
547 closeSession(session);
548 }
549 }
550
551 return list;
552 }
553
554
567 public AnnouncementsDelivery findByUserId_First(long userId,
568 OrderByComparator orderByComparator)
569 throws NoSuchDeliveryException, SystemException {
570 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
571 orderByComparator);
572
573 if (list.isEmpty()) {
574 StringBundler msg = new StringBundler(4);
575
576 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
577
578 msg.append("userId=");
579 msg.append(userId);
580
581 msg.append(StringPool.CLOSE_CURLY_BRACE);
582
583 throw new NoSuchDeliveryException(msg.toString());
584 }
585 else {
586 return list.get(0);
587 }
588 }
589
590
603 public AnnouncementsDelivery findByUserId_Last(long userId,
604 OrderByComparator orderByComparator)
605 throws NoSuchDeliveryException, SystemException {
606 int count = countByUserId(userId);
607
608 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
609 count, orderByComparator);
610
611 if (list.isEmpty()) {
612 StringBundler msg = new StringBundler(4);
613
614 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
615
616 msg.append("userId=");
617 msg.append(userId);
618
619 msg.append(StringPool.CLOSE_CURLY_BRACE);
620
621 throw new NoSuchDeliveryException(msg.toString());
622 }
623 else {
624 return list.get(0);
625 }
626 }
627
628
642 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
643 long userId, OrderByComparator orderByComparator)
644 throws NoSuchDeliveryException, SystemException {
645 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
646
647 Session session = null;
648
649 try {
650 session = openSession();
651
652 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
653
654 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
655 userId, orderByComparator, true);
656
657 array[1] = announcementsDelivery;
658
659 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
660 userId, orderByComparator, false);
661
662 return array;
663 }
664 catch (Exception e) {
665 throw processException(e);
666 }
667 finally {
668 closeSession(session);
669 }
670 }
671
672 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
673 AnnouncementsDelivery announcementsDelivery, long userId,
674 OrderByComparator orderByComparator, boolean previous) {
675 StringBundler query = null;
676
677 if (orderByComparator != null) {
678 query = new StringBundler(6 +
679 (orderByComparator.getOrderByFields().length * 6));
680 }
681 else {
682 query = new StringBundler(3);
683 }
684
685 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
686
687 query.append(_FINDER_COLUMN_USERID_USERID_2);
688
689 if (orderByComparator != null) {
690 String[] orderByFields = orderByComparator.getOrderByFields();
691
692 if (orderByFields.length > 0) {
693 query.append(WHERE_AND);
694 }
695
696 for (int i = 0; i < orderByFields.length; i++) {
697 query.append(_ORDER_BY_ENTITY_ALIAS);
698 query.append(orderByFields[i]);
699
700 if ((i + 1) < orderByFields.length) {
701 if (orderByComparator.isAscending() ^ previous) {
702 query.append(WHERE_GREATER_THAN_HAS_NEXT);
703 }
704 else {
705 query.append(WHERE_LESSER_THAN_HAS_NEXT);
706 }
707 }
708 else {
709 if (orderByComparator.isAscending() ^ previous) {
710 query.append(WHERE_GREATER_THAN);
711 }
712 else {
713 query.append(WHERE_LESSER_THAN);
714 }
715 }
716 }
717
718 query.append(ORDER_BY_CLAUSE);
719
720 for (int i = 0; i < orderByFields.length; i++) {
721 query.append(_ORDER_BY_ENTITY_ALIAS);
722 query.append(orderByFields[i]);
723
724 if ((i + 1) < orderByFields.length) {
725 if (orderByComparator.isAscending() ^ previous) {
726 query.append(ORDER_BY_ASC_HAS_NEXT);
727 }
728 else {
729 query.append(ORDER_BY_DESC_HAS_NEXT);
730 }
731 }
732 else {
733 if (orderByComparator.isAscending() ^ previous) {
734 query.append(ORDER_BY_ASC);
735 }
736 else {
737 query.append(ORDER_BY_DESC);
738 }
739 }
740 }
741 }
742
743 String sql = query.toString();
744
745 Query q = session.createQuery(sql);
746
747 q.setFirstResult(0);
748 q.setMaxResults(2);
749
750 QueryPos qPos = QueryPos.getInstance(q);
751
752 qPos.add(userId);
753
754 if (orderByComparator != null) {
755 Object[] values = orderByComparator.getOrderByValues(announcementsDelivery);
756
757 for (Object value : values) {
758 qPos.add(value);
759 }
760 }
761
762 List<AnnouncementsDelivery> list = q.list();
763
764 if (list.size() == 2) {
765 return list.get(1);
766 }
767 else {
768 return null;
769 }
770 }
771
772
781 public AnnouncementsDelivery findByU_T(long userId, String type)
782 throws NoSuchDeliveryException, SystemException {
783 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
784
785 if (announcementsDelivery == null) {
786 StringBundler msg = new StringBundler(6);
787
788 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
789
790 msg.append("userId=");
791 msg.append(userId);
792
793 msg.append(", type=");
794 msg.append(type);
795
796 msg.append(StringPool.CLOSE_CURLY_BRACE);
797
798 if (_log.isWarnEnabled()) {
799 _log.warn(msg.toString());
800 }
801
802 throw new NoSuchDeliveryException(msg.toString());
803 }
804
805 return announcementsDelivery;
806 }
807
808
816 public AnnouncementsDelivery fetchByU_T(long userId, String type)
817 throws SystemException {
818 return fetchByU_T(userId, type, true);
819 }
820
821
829 public AnnouncementsDelivery fetchByU_T(long userId, String type,
830 boolean retrieveFromCache) throws SystemException {
831 Object[] finderArgs = new Object[] { userId, type };
832
833 Object result = null;
834
835 if (retrieveFromCache) {
836 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
837 finderArgs, this);
838 }
839
840 if (result == null) {
841 StringBundler query = new StringBundler(3);
842
843 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
844
845 query.append(_FINDER_COLUMN_U_T_USERID_2);
846
847 if (type == null) {
848 query.append(_FINDER_COLUMN_U_T_TYPE_1);
849 }
850 else {
851 if (type.equals(StringPool.BLANK)) {
852 query.append(_FINDER_COLUMN_U_T_TYPE_3);
853 }
854 else {
855 query.append(_FINDER_COLUMN_U_T_TYPE_2);
856 }
857 }
858
859 String sql = query.toString();
860
861 Session session = null;
862
863 try {
864 session = openSession();
865
866 Query q = session.createQuery(sql);
867
868 QueryPos qPos = QueryPos.getInstance(q);
869
870 qPos.add(userId);
871
872 if (type != null) {
873 qPos.add(type);
874 }
875
876 List<AnnouncementsDelivery> list = q.list();
877
878 result = list;
879
880 AnnouncementsDelivery announcementsDelivery = null;
881
882 if (list.isEmpty()) {
883 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
884 finderArgs, list);
885 }
886 else {
887 announcementsDelivery = list.get(0);
888
889 cacheResult(announcementsDelivery);
890
891 if ((announcementsDelivery.getUserId() != userId) ||
892 (announcementsDelivery.getType() == null) ||
893 !announcementsDelivery.getType().equals(type)) {
894 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
895 finderArgs, announcementsDelivery);
896 }
897 }
898
899 return announcementsDelivery;
900 }
901 catch (Exception e) {
902 throw processException(e);
903 }
904 finally {
905 if (result == null) {
906 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
907 finderArgs);
908 }
909
910 closeSession(session);
911 }
912 }
913 else {
914 if (result instanceof List<?>) {
915 return null;
916 }
917 else {
918 return (AnnouncementsDelivery)result;
919 }
920 }
921 }
922
923
929 public List<AnnouncementsDelivery> findAll() throws SystemException {
930 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
931 }
932
933
945 public List<AnnouncementsDelivery> findAll(int start, int end)
946 throws SystemException {
947 return findAll(start, end, null);
948 }
949
950
963 public List<AnnouncementsDelivery> findAll(int start, int end,
964 OrderByComparator orderByComparator) throws SystemException {
965 Object[] finderArgs = new Object[] {
966 String.valueOf(start), String.valueOf(end),
967 String.valueOf(orderByComparator)
968 };
969
970 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
971 finderArgs, this);
972
973 if (list == null) {
974 StringBundler query = null;
975 String sql = null;
976
977 if (orderByComparator != null) {
978 query = new StringBundler(2 +
979 (orderByComparator.getOrderByFields().length * 3));
980
981 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
982
983 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
984 orderByComparator);
985
986 sql = query.toString();
987 }
988 else {
989 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
990 }
991
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 Query q = session.createQuery(sql);
998
999 if (orderByComparator == null) {
1000 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1001 getDialect(), start, end, false);
1002
1003 Collections.sort(list);
1004 }
1005 else {
1006 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1007 getDialect(), start, end);
1008 }
1009 }
1010 catch (Exception e) {
1011 throw processException(e);
1012 }
1013 finally {
1014 if (list == null) {
1015 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1016 finderArgs);
1017 }
1018 else {
1019 cacheResult(list);
1020
1021 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1022 list);
1023 }
1024
1025 closeSession(session);
1026 }
1027 }
1028
1029 return list;
1030 }
1031
1032
1038 public void removeByUserId(long userId) throws SystemException {
1039 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1040 remove(announcementsDelivery);
1041 }
1042 }
1043
1044
1051 public void removeByU_T(long userId, String type)
1052 throws NoSuchDeliveryException, SystemException {
1053 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1054
1055 remove(announcementsDelivery);
1056 }
1057
1058
1063 public void removeAll() throws SystemException {
1064 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1065 remove(announcementsDelivery);
1066 }
1067 }
1068
1069
1076 public int countByUserId(long userId) throws SystemException {
1077 Object[] finderArgs = new Object[] { userId };
1078
1079 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1080 finderArgs, this);
1081
1082 if (count == null) {
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 Session session = null;
1092
1093 try {
1094 session = openSession();
1095
1096 Query q = session.createQuery(sql);
1097
1098 QueryPos qPos = QueryPos.getInstance(q);
1099
1100 qPos.add(userId);
1101
1102 count = (Long)q.uniqueResult();
1103 }
1104 catch (Exception e) {
1105 throw processException(e);
1106 }
1107 finally {
1108 if (count == null) {
1109 count = Long.valueOf(0);
1110 }
1111
1112 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1113 finderArgs, count);
1114
1115 closeSession(session);
1116 }
1117 }
1118
1119 return count.intValue();
1120 }
1121
1122
1130 public int countByU_T(long userId, String type) throws SystemException {
1131 Object[] finderArgs = new Object[] { userId, type };
1132
1133 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1134 finderArgs, this);
1135
1136 if (count == null) {
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 Session session = null;
1158
1159 try {
1160 session = openSession();
1161
1162 Query q = session.createQuery(sql);
1163
1164 QueryPos qPos = QueryPos.getInstance(q);
1165
1166 qPos.add(userId);
1167
1168 if (type != null) {
1169 qPos.add(type);
1170 }
1171
1172 count = (Long)q.uniqueResult();
1173 }
1174 catch (Exception e) {
1175 throw processException(e);
1176 }
1177 finally {
1178 if (count == null) {
1179 count = Long.valueOf(0);
1180 }
1181
1182 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1183 count);
1184
1185 closeSession(session);
1186 }
1187 }
1188
1189 return count.intValue();
1190 }
1191
1192
1198 public int countAll() throws SystemException {
1199 Object[] finderArgs = new Object[0];
1200
1201 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1202 finderArgs, this);
1203
1204 if (count == null) {
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1211
1212 count = (Long)q.uniqueResult();
1213 }
1214 catch (Exception e) {
1215 throw processException(e);
1216 }
1217 finally {
1218 if (count == null) {
1219 count = Long.valueOf(0);
1220 }
1221
1222 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1223 count);
1224
1225 closeSession(session);
1226 }
1227 }
1228
1229 return count.intValue();
1230 }
1231
1232
1235 public void afterPropertiesSet() {
1236 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1237 com.liferay.portal.util.PropsUtil.get(
1238 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1239
1240 if (listenerClassNames.length > 0) {
1241 try {
1242 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1243
1244 for (String listenerClassName : listenerClassNames) {
1245 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1246 listenerClassName));
1247 }
1248
1249 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1250 }
1251 catch (Exception e) {
1252 _log.error(e);
1253 }
1254 }
1255 }
1256
1257 public void destroy() {
1258 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1259 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1260 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1261 }
1262
1263 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1264 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1265 @BeanReference(type = AnnouncementsEntryPersistence.class)
1266 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1267 @BeanReference(type = AnnouncementsFlagPersistence.class)
1268 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1269 @BeanReference(type = ResourcePersistence.class)
1270 protected ResourcePersistence resourcePersistence;
1271 @BeanReference(type = UserPersistence.class)
1272 protected UserPersistence userPersistence;
1273 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1274 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1275 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1276 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1277 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1278 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1279 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1280 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1281 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1282 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1283 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1284 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1285 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1286 }