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 if (announcementsDelivery.isCachedModel() ||
249 BatchSessionUtil.isEnabled()) {
250 Object staleObject = session.get(AnnouncementsDeliveryImpl.class,
251 announcementsDelivery.getPrimaryKeyObj());
252
253 if (staleObject != null) {
254 session.evict(staleObject);
255 }
256 }
257
258 session.delete(announcementsDelivery);
259
260 session.flush();
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 closeSession(session);
267 }
268
269 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
270
271 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
272
273 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
274 new Object[] {
275 new Long(announcementsDeliveryModelImpl.getOriginalUserId()),
276
277 announcementsDeliveryModelImpl.getOriginalType()
278 });
279
280 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
281 AnnouncementsDeliveryImpl.class,
282 announcementsDelivery.getPrimaryKey());
283
284 return announcementsDelivery;
285 }
286
287 public AnnouncementsDelivery updateImpl(
288 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery,
289 boolean merge) throws SystemException {
290 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
291
292 boolean isNew = announcementsDelivery.isNew();
293
294 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
295
296 Session session = null;
297
298 try {
299 session = openSession();
300
301 BatchSessionUtil.update(session, announcementsDelivery, merge);
302
303 announcementsDelivery.setNew(false);
304 }
305 catch (Exception e) {
306 throw processException(e);
307 }
308 finally {
309 closeSession(session);
310 }
311
312 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
313
314 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
315 AnnouncementsDeliveryImpl.class,
316 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
317
318 if (!isNew &&
319 ((announcementsDelivery.getUserId() != announcementsDeliveryModelImpl.getOriginalUserId()) ||
320 !Validator.equals(announcementsDelivery.getType(),
321 announcementsDeliveryModelImpl.getOriginalType()))) {
322 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
323 new Object[] {
324 new Long(announcementsDeliveryModelImpl.getOriginalUserId()),
325
326 announcementsDeliveryModelImpl.getOriginalType()
327 });
328 }
329
330 if (isNew ||
331 ((announcementsDelivery.getUserId() != announcementsDeliveryModelImpl.getOriginalUserId()) ||
332 !Validator.equals(announcementsDelivery.getType(),
333 announcementsDeliveryModelImpl.getOriginalType()))) {
334 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
335 new Object[] {
336 new Long(announcementsDelivery.getUserId()),
337
338 announcementsDelivery.getType()
339 }, announcementsDelivery);
340 }
341
342 return announcementsDelivery;
343 }
344
345 protected AnnouncementsDelivery toUnwrappedModel(
346 AnnouncementsDelivery announcementsDelivery) {
347 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
348 return announcementsDelivery;
349 }
350
351 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
352
353 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
354 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
355
356 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
357 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
358 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
359 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
360 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
361 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
362 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
363
364 return announcementsDeliveryImpl;
365 }
366
367
375 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
376 throws NoSuchModelException, SystemException {
377 return findByPrimaryKey(((Long)primaryKey).longValue());
378 }
379
380
388 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
389 throws NoSuchDeliveryException, SystemException {
390 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
391
392 if (announcementsDelivery == null) {
393 if (_log.isWarnEnabled()) {
394 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
395 }
396
397 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
398 deliveryId);
399 }
400
401 return announcementsDelivery;
402 }
403
404
411 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
412 throws SystemException {
413 return fetchByPrimaryKey(((Long)primaryKey).longValue());
414 }
415
416
423 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
424 throws SystemException {
425 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
426 AnnouncementsDeliveryImpl.class, deliveryId, this);
427
428 if (announcementsDelivery == null) {
429 Session session = null;
430
431 try {
432 session = openSession();
433
434 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
435 new Long(deliveryId));
436 }
437 catch (Exception e) {
438 throw processException(e);
439 }
440 finally {
441 if (announcementsDelivery != null) {
442 cacheResult(announcementsDelivery);
443 }
444
445 closeSession(session);
446 }
447 }
448
449 return announcementsDelivery;
450 }
451
452
459 public List<AnnouncementsDelivery> findByUserId(long userId)
460 throws SystemException {
461 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
462 }
463
464
477 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
478 int end) throws SystemException {
479 return findByUserId(userId, start, end, null);
480 }
481
482
496 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
497 int end, OrderByComparator orderByComparator) throws SystemException {
498 Object[] finderArgs = new Object[] {
499 userId,
500
501 String.valueOf(start), String.valueOf(end),
502 String.valueOf(orderByComparator)
503 };
504
505 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
506 finderArgs, this);
507
508 if (list == null) {
509 Session session = null;
510
511 try {
512 session = openSession();
513
514 StringBundler query = null;
515
516 if (orderByComparator != null) {
517 query = new StringBundler(3 +
518 (orderByComparator.getOrderByFields().length * 3));
519 }
520 else {
521 query = new StringBundler(2);
522 }
523
524 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
525
526 query.append(_FINDER_COLUMN_USERID_USERID_2);
527
528 if (orderByComparator != null) {
529 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
530 orderByComparator);
531 }
532
533 String sql = query.toString();
534
535 Query q = session.createQuery(sql);
536
537 QueryPos qPos = QueryPos.getInstance(q);
538
539 qPos.add(userId);
540
541 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
542 getDialect(), start, end);
543 }
544 catch (Exception e) {
545 throw processException(e);
546 }
547 finally {
548 if (list == null) {
549 list = new ArrayList<AnnouncementsDelivery>();
550 }
551
552 cacheResult(list);
553
554 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
555 finderArgs, list);
556
557 closeSession(session);
558 }
559 }
560
561 return list;
562 }
563
564
577 public AnnouncementsDelivery findByUserId_First(long userId,
578 OrderByComparator orderByComparator)
579 throws NoSuchDeliveryException, SystemException {
580 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
581 orderByComparator);
582
583 if (list.isEmpty()) {
584 StringBundler msg = new StringBundler(4);
585
586 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
587
588 msg.append("userId=");
589 msg.append(userId);
590
591 msg.append(StringPool.CLOSE_CURLY_BRACE);
592
593 throw new NoSuchDeliveryException(msg.toString());
594 }
595 else {
596 return list.get(0);
597 }
598 }
599
600
613 public AnnouncementsDelivery findByUserId_Last(long userId,
614 OrderByComparator orderByComparator)
615 throws NoSuchDeliveryException, SystemException {
616 int count = countByUserId(userId);
617
618 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
619 count, orderByComparator);
620
621 if (list.isEmpty()) {
622 StringBundler msg = new StringBundler(4);
623
624 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
625
626 msg.append("userId=");
627 msg.append(userId);
628
629 msg.append(StringPool.CLOSE_CURLY_BRACE);
630
631 throw new NoSuchDeliveryException(msg.toString());
632 }
633 else {
634 return list.get(0);
635 }
636 }
637
638
652 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
653 long userId, OrderByComparator orderByComparator)
654 throws NoSuchDeliveryException, SystemException {
655 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
656
657 Session session = null;
658
659 try {
660 session = openSession();
661
662 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
663
664 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
665 userId, orderByComparator, true);
666
667 array[1] = announcementsDelivery;
668
669 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
670 userId, orderByComparator, false);
671
672 return array;
673 }
674 catch (Exception e) {
675 throw processException(e);
676 }
677 finally {
678 closeSession(session);
679 }
680 }
681
682 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
683 AnnouncementsDelivery announcementsDelivery, long userId,
684 OrderByComparator orderByComparator, boolean previous) {
685 StringBundler query = null;
686
687 if (orderByComparator != null) {
688 query = new StringBundler(6 +
689 (orderByComparator.getOrderByFields().length * 6));
690 }
691 else {
692 query = new StringBundler(3);
693 }
694
695 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
696
697 query.append(_FINDER_COLUMN_USERID_USERID_2);
698
699 if (orderByComparator != null) {
700 String[] orderByFields = orderByComparator.getOrderByFields();
701
702 if (orderByFields.length > 0) {
703 query.append(WHERE_AND);
704 }
705
706 for (int i = 0; i < orderByFields.length; i++) {
707 query.append(_ORDER_BY_ENTITY_ALIAS);
708 query.append(orderByFields[i]);
709
710 if ((i + 1) < orderByFields.length) {
711 if (orderByComparator.isAscending() ^ previous) {
712 query.append(WHERE_GREATER_THAN_HAS_NEXT);
713 }
714 else {
715 query.append(WHERE_LESSER_THAN_HAS_NEXT);
716 }
717 }
718 else {
719 if (orderByComparator.isAscending() ^ previous) {
720 query.append(WHERE_GREATER_THAN);
721 }
722 else {
723 query.append(WHERE_LESSER_THAN);
724 }
725 }
726 }
727
728 query.append(ORDER_BY_CLAUSE);
729
730 for (int i = 0; i < orderByFields.length; i++) {
731 query.append(_ORDER_BY_ENTITY_ALIAS);
732 query.append(orderByFields[i]);
733
734 if ((i + 1) < orderByFields.length) {
735 if (orderByComparator.isAscending() ^ previous) {
736 query.append(ORDER_BY_ASC_HAS_NEXT);
737 }
738 else {
739 query.append(ORDER_BY_DESC_HAS_NEXT);
740 }
741 }
742 else {
743 if (orderByComparator.isAscending() ^ previous) {
744 query.append(ORDER_BY_ASC);
745 }
746 else {
747 query.append(ORDER_BY_DESC);
748 }
749 }
750 }
751 }
752
753 String sql = query.toString();
754
755 Query q = session.createQuery(sql);
756
757 q.setFirstResult(0);
758 q.setMaxResults(2);
759
760 QueryPos qPos = QueryPos.getInstance(q);
761
762 qPos.add(userId);
763
764 if (orderByComparator != null) {
765 Object[] values = orderByComparator.getOrderByValues(announcementsDelivery);
766
767 for (Object value : values) {
768 qPos.add(value);
769 }
770 }
771
772 List<AnnouncementsDelivery> list = q.list();
773
774 if (list.size() == 2) {
775 return list.get(1);
776 }
777 else {
778 return null;
779 }
780 }
781
782
791 public AnnouncementsDelivery findByU_T(long userId, String type)
792 throws NoSuchDeliveryException, SystemException {
793 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
794
795 if (announcementsDelivery == null) {
796 StringBundler msg = new StringBundler(6);
797
798 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
799
800 msg.append("userId=");
801 msg.append(userId);
802
803 msg.append(", type=");
804 msg.append(type);
805
806 msg.append(StringPool.CLOSE_CURLY_BRACE);
807
808 if (_log.isWarnEnabled()) {
809 _log.warn(msg.toString());
810 }
811
812 throw new NoSuchDeliveryException(msg.toString());
813 }
814
815 return announcementsDelivery;
816 }
817
818
826 public AnnouncementsDelivery fetchByU_T(long userId, String type)
827 throws SystemException {
828 return fetchByU_T(userId, type, true);
829 }
830
831
839 public AnnouncementsDelivery fetchByU_T(long userId, String type,
840 boolean retrieveFromCache) throws SystemException {
841 Object[] finderArgs = new Object[] { userId, type };
842
843 Object result = null;
844
845 if (retrieveFromCache) {
846 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
847 finderArgs, this);
848 }
849
850 if (result == null) {
851 Session session = null;
852
853 try {
854 session = openSession();
855
856 StringBundler query = new StringBundler(3);
857
858 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
859
860 query.append(_FINDER_COLUMN_U_T_USERID_2);
861
862 if (type == null) {
863 query.append(_FINDER_COLUMN_U_T_TYPE_1);
864 }
865 else {
866 if (type.equals(StringPool.BLANK)) {
867 query.append(_FINDER_COLUMN_U_T_TYPE_3);
868 }
869 else {
870 query.append(_FINDER_COLUMN_U_T_TYPE_2);
871 }
872 }
873
874 String sql = query.toString();
875
876 Query q = session.createQuery(sql);
877
878 QueryPos qPos = QueryPos.getInstance(q);
879
880 qPos.add(userId);
881
882 if (type != null) {
883 qPos.add(type);
884 }
885
886 List<AnnouncementsDelivery> list = q.list();
887
888 result = list;
889
890 AnnouncementsDelivery announcementsDelivery = null;
891
892 if (list.isEmpty()) {
893 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
894 finderArgs, list);
895 }
896 else {
897 announcementsDelivery = list.get(0);
898
899 cacheResult(announcementsDelivery);
900
901 if ((announcementsDelivery.getUserId() != userId) ||
902 (announcementsDelivery.getType() == null) ||
903 !announcementsDelivery.getType().equals(type)) {
904 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
905 finderArgs, announcementsDelivery);
906 }
907 }
908
909 return announcementsDelivery;
910 }
911 catch (Exception e) {
912 throw processException(e);
913 }
914 finally {
915 if (result == null) {
916 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
917 finderArgs, new ArrayList<AnnouncementsDelivery>());
918 }
919
920 closeSession(session);
921 }
922 }
923 else {
924 if (result instanceof List<?>) {
925 return null;
926 }
927 else {
928 return (AnnouncementsDelivery)result;
929 }
930 }
931 }
932
933
939 public List<AnnouncementsDelivery> findAll() throws SystemException {
940 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
941 }
942
943
955 public List<AnnouncementsDelivery> findAll(int start, int end)
956 throws SystemException {
957 return findAll(start, end, null);
958 }
959
960
973 public List<AnnouncementsDelivery> findAll(int start, int end,
974 OrderByComparator orderByComparator) throws SystemException {
975 Object[] finderArgs = new Object[] {
976 String.valueOf(start), String.valueOf(end),
977 String.valueOf(orderByComparator)
978 };
979
980 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
981 finderArgs, this);
982
983 if (list == null) {
984 Session session = null;
985
986 try {
987 session = openSession();
988
989 StringBundler query = null;
990 String sql = null;
991
992 if (orderByComparator != null) {
993 query = new StringBundler(2 +
994 (orderByComparator.getOrderByFields().length * 3));
995
996 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
997
998 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
999 orderByComparator);
1000
1001 sql = query.toString();
1002 }
1003 else {
1004 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1005 }
1006
1007 Query q = session.createQuery(sql);
1008
1009 if (orderByComparator == null) {
1010 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1011 getDialect(), start, end, false);
1012
1013 Collections.sort(list);
1014 }
1015 else {
1016 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1017 getDialect(), start, end);
1018 }
1019 }
1020 catch (Exception e) {
1021 throw processException(e);
1022 }
1023 finally {
1024 if (list == null) {
1025 list = new ArrayList<AnnouncementsDelivery>();
1026 }
1027
1028 cacheResult(list);
1029
1030 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1031
1032 closeSession(session);
1033 }
1034 }
1035
1036 return list;
1037 }
1038
1039
1045 public void removeByUserId(long userId) throws SystemException {
1046 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1047 remove(announcementsDelivery);
1048 }
1049 }
1050
1051
1058 public void removeByU_T(long userId, String type)
1059 throws NoSuchDeliveryException, SystemException {
1060 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1061
1062 remove(announcementsDelivery);
1063 }
1064
1065
1070 public void removeAll() throws SystemException {
1071 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1072 remove(announcementsDelivery);
1073 }
1074 }
1075
1076
1083 public int countByUserId(long userId) throws SystemException {
1084 Object[] finderArgs = new Object[] { userId };
1085
1086 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1087 finderArgs, this);
1088
1089 if (count == null) {
1090 Session session = null;
1091
1092 try {
1093 session = openSession();
1094
1095 StringBundler query = new StringBundler(2);
1096
1097 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1098
1099 query.append(_FINDER_COLUMN_USERID_USERID_2);
1100
1101 String sql = query.toString();
1102
1103 Query q = session.createQuery(sql);
1104
1105 QueryPos qPos = QueryPos.getInstance(q);
1106
1107 qPos.add(userId);
1108
1109 count = (Long)q.uniqueResult();
1110 }
1111 catch (Exception e) {
1112 throw processException(e);
1113 }
1114 finally {
1115 if (count == null) {
1116 count = Long.valueOf(0);
1117 }
1118
1119 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1120 finderArgs, count);
1121
1122 closeSession(session);
1123 }
1124 }
1125
1126 return count.intValue();
1127 }
1128
1129
1137 public int countByU_T(long userId, String type) throws SystemException {
1138 Object[] finderArgs = new Object[] { userId, type };
1139
1140 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1141 finderArgs, this);
1142
1143 if (count == null) {
1144 Session session = null;
1145
1146 try {
1147 session = openSession();
1148
1149 StringBundler query = new StringBundler(3);
1150
1151 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1152
1153 query.append(_FINDER_COLUMN_U_T_USERID_2);
1154
1155 if (type == null) {
1156 query.append(_FINDER_COLUMN_U_T_TYPE_1);
1157 }
1158 else {
1159 if (type.equals(StringPool.BLANK)) {
1160 query.append(_FINDER_COLUMN_U_T_TYPE_3);
1161 }
1162 else {
1163 query.append(_FINDER_COLUMN_U_T_TYPE_2);
1164 }
1165 }
1166
1167 String sql = query.toString();
1168
1169 Query q = session.createQuery(sql);
1170
1171 QueryPos qPos = QueryPos.getInstance(q);
1172
1173 qPos.add(userId);
1174
1175 if (type != null) {
1176 qPos.add(type);
1177 }
1178
1179 count = (Long)q.uniqueResult();
1180 }
1181 catch (Exception e) {
1182 throw processException(e);
1183 }
1184 finally {
1185 if (count == null) {
1186 count = Long.valueOf(0);
1187 }
1188
1189 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1190 count);
1191
1192 closeSession(session);
1193 }
1194 }
1195
1196 return count.intValue();
1197 }
1198
1199
1205 public int countAll() throws SystemException {
1206 Object[] finderArgs = new Object[0];
1207
1208 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1209 finderArgs, this);
1210
1211 if (count == null) {
1212 Session session = null;
1213
1214 try {
1215 session = openSession();
1216
1217 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1218
1219 count = (Long)q.uniqueResult();
1220 }
1221 catch (Exception e) {
1222 throw processException(e);
1223 }
1224 finally {
1225 if (count == null) {
1226 count = Long.valueOf(0);
1227 }
1228
1229 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1230 count);
1231
1232 closeSession(session);
1233 }
1234 }
1235
1236 return count.intValue();
1237 }
1238
1239
1242 public void afterPropertiesSet() {
1243 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1244 com.liferay.portal.util.PropsUtil.get(
1245 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1246
1247 if (listenerClassNames.length > 0) {
1248 try {
1249 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1250
1251 for (String listenerClassName : listenerClassNames) {
1252 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1253 listenerClassName));
1254 }
1255
1256 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1257 }
1258 catch (Exception e) {
1259 _log.error(e);
1260 }
1261 }
1262 }
1263
1264 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1265 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1266 @BeanReference(type = AnnouncementsEntryPersistence.class)
1267 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1268 @BeanReference(type = AnnouncementsFlagPersistence.class)
1269 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1270 @BeanReference(type = ResourcePersistence.class)
1271 protected ResourcePersistence resourcePersistence;
1272 @BeanReference(type = UserPersistence.class)
1273 protected UserPersistence userPersistence;
1274 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1275 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1276 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1277 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1278 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1279 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1280 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1281 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1282 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1283 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1284 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1285 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1286 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1287 }