001
014
015 package com.liferay.portlet.announcements.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.CacheModel;
038 import com.liferay.portal.model.ModelListener;
039 import com.liferay.portal.service.persistence.BatchSessionUtil;
040 import com.liferay.portal.service.persistence.ResourcePersistence;
041 import com.liferay.portal.service.persistence.UserPersistence;
042 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
043
044 import com.liferay.portlet.announcements.NoSuchDeliveryException;
045 import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
046 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryImpl;
047 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryModelImpl;
048
049 import java.io.Serializable;
050
051 import java.util.ArrayList;
052 import java.util.Collections;
053 import java.util.List;
054
055
067 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
068 implements AnnouncementsDeliveryPersistence {
069
074 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076 ".List1";
077 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List2";
079 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
080 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
081 AnnouncementsDeliveryImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
083 new String[] {
084 Long.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
090 new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
091 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
092 AnnouncementsDeliveryImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
094 new String[] { Long.class.getName() },
095 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK);
096 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
097 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
099 new String[] { Long.class.getName() });
100 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
101 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
102 AnnouncementsDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
103 "fetchByU_T",
104 new String[] { Long.class.getName(), String.class.getName() },
105 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK |
106 AnnouncementsDeliveryModelImpl.TYPE_COLUMN_BITMASK);
107 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
108 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
109 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
110 new String[] { Long.class.getName(), String.class.getName() });
111 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
112 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
113 AnnouncementsDeliveryImpl.class,
114 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
115 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
116 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
117 AnnouncementsDeliveryImpl.class,
118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
119 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
120 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
122
123
128 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
129 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
130 AnnouncementsDeliveryImpl.class,
131 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
132
133 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
134 new Object[] {
135 Long.valueOf(announcementsDelivery.getUserId()),
136
137 announcementsDelivery.getType()
138 }, announcementsDelivery);
139
140 announcementsDelivery.resetOriginalValues();
141 }
142
143
148 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
149 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
150 if (EntityCacheUtil.getResult(
151 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
152 AnnouncementsDeliveryImpl.class,
153 announcementsDelivery.getPrimaryKey()) == null) {
154 cacheResult(announcementsDelivery);
155 }
156 else {
157 announcementsDelivery.resetOriginalValues();
158 }
159 }
160 }
161
162
169 @Override
170 public void clearCache() {
171 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
172 CacheRegistryUtil.clear(AnnouncementsDeliveryImpl.class.getName());
173 }
174
175 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
176
177 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
179 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
180 }
181
182
189 @Override
190 public void clearCache(AnnouncementsDelivery announcementsDelivery) {
191 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
192 AnnouncementsDeliveryImpl.class,
193 announcementsDelivery.getPrimaryKey());
194
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
196 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
197
198 clearUniqueFindersCache(announcementsDelivery);
199 }
200
201 @Override
202 public void clearCache(List<AnnouncementsDelivery> announcementsDeliveries) {
203 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
204 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
205
206 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
207 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
208 AnnouncementsDeliveryImpl.class,
209 announcementsDelivery.getPrimaryKey());
210
211 clearUniqueFindersCache(announcementsDelivery);
212 }
213 }
214
215 protected void cacheUniqueFindersCache(
216 AnnouncementsDelivery announcementsDelivery) {
217 if (announcementsDelivery.isNew()) {
218 Object[] args = new Object[] {
219 Long.valueOf(announcementsDelivery.getUserId()),
220
221 announcementsDelivery.getType()
222 };
223
224 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
225 Long.valueOf(1));
226 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
227 announcementsDelivery);
228 }
229 else {
230 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
231
232 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
233 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
234 Object[] args = new Object[] {
235 Long.valueOf(announcementsDelivery.getUserId()),
236
237 announcementsDelivery.getType()
238 };
239
240 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, args,
241 Long.valueOf(1));
242 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T, args,
243 announcementsDelivery);
244 }
245 }
246 }
247
248 protected void clearUniqueFindersCache(
249 AnnouncementsDelivery announcementsDelivery) {
250 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
251
252 Object[] args = new Object[] {
253 Long.valueOf(announcementsDelivery.getUserId()),
254
255 announcementsDelivery.getType()
256 };
257
258 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
259 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
260
261 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
262 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
263 args = new Object[] {
264 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId()),
265
266 announcementsDeliveryModelImpl.getOriginalType()
267 };
268
269 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
270 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
271 }
272 }
273
274
280 public AnnouncementsDelivery create(long deliveryId) {
281 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
282
283 announcementsDelivery.setNew(true);
284 announcementsDelivery.setPrimaryKey(deliveryId);
285
286 return announcementsDelivery;
287 }
288
289
297 public AnnouncementsDelivery remove(long deliveryId)
298 throws NoSuchDeliveryException, SystemException {
299 return remove(Long.valueOf(deliveryId));
300 }
301
302
310 @Override
311 public AnnouncementsDelivery remove(Serializable primaryKey)
312 throws NoSuchDeliveryException, SystemException {
313 Session session = null;
314
315 try {
316 session = openSession();
317
318 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
319 primaryKey);
320
321 if (announcementsDelivery == null) {
322 if (_log.isWarnEnabled()) {
323 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
324 }
325
326 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
327 primaryKey);
328 }
329
330 return remove(announcementsDelivery);
331 }
332 catch (NoSuchDeliveryException nsee) {
333 throw nsee;
334 }
335 catch (Exception e) {
336 throw processException(e);
337 }
338 finally {
339 closeSession(session);
340 }
341 }
342
343 @Override
344 protected AnnouncementsDelivery removeImpl(
345 AnnouncementsDelivery announcementsDelivery) throws SystemException {
346 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
347
348 Session session = null;
349
350 try {
351 session = openSession();
352
353 BatchSessionUtil.delete(session, announcementsDelivery);
354 }
355 catch (Exception e) {
356 throw processException(e);
357 }
358 finally {
359 closeSession(session);
360 }
361
362 clearCache(announcementsDelivery);
363
364 return announcementsDelivery;
365 }
366
367 @Override
368 public AnnouncementsDelivery updateImpl(
369 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery,
370 boolean merge) throws SystemException {
371 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
372
373 boolean isNew = announcementsDelivery.isNew();
374
375 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
376
377 Session session = null;
378
379 try {
380 session = openSession();
381
382 BatchSessionUtil.update(session, announcementsDelivery, merge);
383
384 announcementsDelivery.setNew(false);
385 }
386 catch (Exception e) {
387 throw processException(e);
388 }
389 finally {
390 closeSession(session);
391 }
392
393 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
394
395 if (isNew || !AnnouncementsDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
396 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
397 }
398
399 else {
400 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
401 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
402 Object[] args = new Object[] {
403 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId())
404 };
405
406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
407 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
408 args);
409
410 args = new Object[] {
411 Long.valueOf(announcementsDeliveryModelImpl.getUserId())
412 };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
415 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
416 args);
417 }
418 }
419
420 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
421 AnnouncementsDeliveryImpl.class,
422 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
423
424 clearUniqueFindersCache(announcementsDelivery);
425 cacheUniqueFindersCache(announcementsDelivery);
426
427 return announcementsDelivery;
428 }
429
430 protected AnnouncementsDelivery toUnwrappedModel(
431 AnnouncementsDelivery announcementsDelivery) {
432 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
433 return announcementsDelivery;
434 }
435
436 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
437
438 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
439 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
440
441 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
442 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
443 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
444 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
445 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
446 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
447 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
448
449 return announcementsDeliveryImpl;
450 }
451
452
460 @Override
461 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
462 throws NoSuchModelException, SystemException {
463 return findByPrimaryKey(((Long)primaryKey).longValue());
464 }
465
466
474 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
475 throws NoSuchDeliveryException, SystemException {
476 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
477
478 if (announcementsDelivery == null) {
479 if (_log.isWarnEnabled()) {
480 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
481 }
482
483 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
484 deliveryId);
485 }
486
487 return announcementsDelivery;
488 }
489
490
497 @Override
498 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
499 throws SystemException {
500 return fetchByPrimaryKey(((Long)primaryKey).longValue());
501 }
502
503
510 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
511 throws SystemException {
512 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
513 AnnouncementsDeliveryImpl.class, deliveryId);
514
515 if (announcementsDelivery == _nullAnnouncementsDelivery) {
516 return null;
517 }
518
519 if (announcementsDelivery == null) {
520 Session session = null;
521
522 boolean hasException = false;
523
524 try {
525 session = openSession();
526
527 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
528 Long.valueOf(deliveryId));
529 }
530 catch (Exception e) {
531 hasException = true;
532
533 throw processException(e);
534 }
535 finally {
536 if (announcementsDelivery != null) {
537 cacheResult(announcementsDelivery);
538 }
539 else if (!hasException) {
540 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
541 AnnouncementsDeliveryImpl.class, deliveryId,
542 _nullAnnouncementsDelivery);
543 }
544
545 closeSession(session);
546 }
547 }
548
549 return announcementsDelivery;
550 }
551
552
559 public List<AnnouncementsDelivery> findByUserId(long userId)
560 throws SystemException {
561 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
562 }
563
564
577 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
578 int end) throws SystemException {
579 return findByUserId(userId, start, end, null);
580 }
581
582
596 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
597 int end, OrderByComparator orderByComparator) throws SystemException {
598 FinderPath finderPath = null;
599 Object[] finderArgs = null;
600
601 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
602 (orderByComparator == null)) {
603 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
604 finderArgs = new Object[] { userId };
605 }
606 else {
607 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
608 finderArgs = new Object[] { userId, start, end, orderByComparator };
609 }
610
611 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
612 finderArgs, this);
613
614 if ((list != null) && !list.isEmpty()) {
615 for (AnnouncementsDelivery announcementsDelivery : list) {
616 if ((userId != announcementsDelivery.getUserId())) {
617 list = null;
618
619 break;
620 }
621 }
622 }
623
624 if (list == null) {
625 StringBundler query = null;
626
627 if (orderByComparator != null) {
628 query = new StringBundler(3 +
629 (orderByComparator.getOrderByFields().length * 3));
630 }
631 else {
632 query = new StringBundler(2);
633 }
634
635 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
636
637 query.append(_FINDER_COLUMN_USERID_USERID_2);
638
639 if (orderByComparator != null) {
640 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
641 orderByComparator);
642 }
643
644 String sql = query.toString();
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 Query q = session.createQuery(sql);
652
653 QueryPos qPos = QueryPos.getInstance(q);
654
655 qPos.add(userId);
656
657 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
658 getDialect(), start, end);
659 }
660 catch (Exception e) {
661 throw processException(e);
662 }
663 finally {
664 if (list == null) {
665 FinderCacheUtil.removeResult(finderPath, finderArgs);
666 }
667 else {
668 cacheResult(list);
669
670 FinderCacheUtil.putResult(finderPath, finderArgs, list);
671 }
672
673 closeSession(session);
674 }
675 }
676
677 return list;
678 }
679
680
689 public AnnouncementsDelivery findByUserId_First(long userId,
690 OrderByComparator orderByComparator)
691 throws NoSuchDeliveryException, SystemException {
692 AnnouncementsDelivery announcementsDelivery = fetchByUserId_First(userId,
693 orderByComparator);
694
695 if (announcementsDelivery != null) {
696 return announcementsDelivery;
697 }
698
699 StringBundler msg = new StringBundler(4);
700
701 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
702
703 msg.append("userId=");
704 msg.append(userId);
705
706 msg.append(StringPool.CLOSE_CURLY_BRACE);
707
708 throw new NoSuchDeliveryException(msg.toString());
709 }
710
711
719 public AnnouncementsDelivery fetchByUserId_First(long userId,
720 OrderByComparator orderByComparator) throws SystemException {
721 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
722 orderByComparator);
723
724 if (!list.isEmpty()) {
725 return list.get(0);
726 }
727
728 return null;
729 }
730
731
740 public AnnouncementsDelivery findByUserId_Last(long userId,
741 OrderByComparator orderByComparator)
742 throws NoSuchDeliveryException, SystemException {
743 AnnouncementsDelivery announcementsDelivery = fetchByUserId_Last(userId,
744 orderByComparator);
745
746 if (announcementsDelivery != null) {
747 return announcementsDelivery;
748 }
749
750 StringBundler msg = new StringBundler(4);
751
752 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
753
754 msg.append("userId=");
755 msg.append(userId);
756
757 msg.append(StringPool.CLOSE_CURLY_BRACE);
758
759 throw new NoSuchDeliveryException(msg.toString());
760 }
761
762
770 public AnnouncementsDelivery fetchByUserId_Last(long userId,
771 OrderByComparator orderByComparator) throws SystemException {
772 int count = countByUserId(userId);
773
774 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
775 count, orderByComparator);
776
777 if (!list.isEmpty()) {
778 return list.get(0);
779 }
780
781 return null;
782 }
783
784
794 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
795 long userId, OrderByComparator orderByComparator)
796 throws NoSuchDeliveryException, SystemException {
797 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
798
799 Session session = null;
800
801 try {
802 session = openSession();
803
804 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
805
806 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
807 userId, orderByComparator, true);
808
809 array[1] = announcementsDelivery;
810
811 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
812 userId, orderByComparator, false);
813
814 return array;
815 }
816 catch (Exception e) {
817 throw processException(e);
818 }
819 finally {
820 closeSession(session);
821 }
822 }
823
824 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
825 AnnouncementsDelivery announcementsDelivery, long userId,
826 OrderByComparator orderByComparator, boolean previous) {
827 StringBundler query = null;
828
829 if (orderByComparator != null) {
830 query = new StringBundler(6 +
831 (orderByComparator.getOrderByFields().length * 6));
832 }
833 else {
834 query = new StringBundler(3);
835 }
836
837 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
838
839 query.append(_FINDER_COLUMN_USERID_USERID_2);
840
841 if (orderByComparator != null) {
842 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
843
844 if (orderByConditionFields.length > 0) {
845 query.append(WHERE_AND);
846 }
847
848 for (int i = 0; i < orderByConditionFields.length; i++) {
849 query.append(_ORDER_BY_ENTITY_ALIAS);
850 query.append(orderByConditionFields[i]);
851
852 if ((i + 1) < orderByConditionFields.length) {
853 if (orderByComparator.isAscending() ^ previous) {
854 query.append(WHERE_GREATER_THAN_HAS_NEXT);
855 }
856 else {
857 query.append(WHERE_LESSER_THAN_HAS_NEXT);
858 }
859 }
860 else {
861 if (orderByComparator.isAscending() ^ previous) {
862 query.append(WHERE_GREATER_THAN);
863 }
864 else {
865 query.append(WHERE_LESSER_THAN);
866 }
867 }
868 }
869
870 query.append(ORDER_BY_CLAUSE);
871
872 String[] orderByFields = orderByComparator.getOrderByFields();
873
874 for (int i = 0; i < orderByFields.length; i++) {
875 query.append(_ORDER_BY_ENTITY_ALIAS);
876 query.append(orderByFields[i]);
877
878 if ((i + 1) < orderByFields.length) {
879 if (orderByComparator.isAscending() ^ previous) {
880 query.append(ORDER_BY_ASC_HAS_NEXT);
881 }
882 else {
883 query.append(ORDER_BY_DESC_HAS_NEXT);
884 }
885 }
886 else {
887 if (orderByComparator.isAscending() ^ previous) {
888 query.append(ORDER_BY_ASC);
889 }
890 else {
891 query.append(ORDER_BY_DESC);
892 }
893 }
894 }
895 }
896
897 String sql = query.toString();
898
899 Query q = session.createQuery(sql);
900
901 q.setFirstResult(0);
902 q.setMaxResults(2);
903
904 QueryPos qPos = QueryPos.getInstance(q);
905
906 qPos.add(userId);
907
908 if (orderByComparator != null) {
909 Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
910
911 for (Object value : values) {
912 qPos.add(value);
913 }
914 }
915
916 List<AnnouncementsDelivery> list = q.list();
917
918 if (list.size() == 2) {
919 return list.get(1);
920 }
921 else {
922 return null;
923 }
924 }
925
926
935 public AnnouncementsDelivery findByU_T(long userId, String type)
936 throws NoSuchDeliveryException, SystemException {
937 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
938
939 if (announcementsDelivery == null) {
940 StringBundler msg = new StringBundler(6);
941
942 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
943
944 msg.append("userId=");
945 msg.append(userId);
946
947 msg.append(", type=");
948 msg.append(type);
949
950 msg.append(StringPool.CLOSE_CURLY_BRACE);
951
952 if (_log.isWarnEnabled()) {
953 _log.warn(msg.toString());
954 }
955
956 throw new NoSuchDeliveryException(msg.toString());
957 }
958
959 return announcementsDelivery;
960 }
961
962
970 public AnnouncementsDelivery fetchByU_T(long userId, String type)
971 throws SystemException {
972 return fetchByU_T(userId, type, true);
973 }
974
975
984 public AnnouncementsDelivery fetchByU_T(long userId, String type,
985 boolean retrieveFromCache) throws SystemException {
986 Object[] finderArgs = new Object[] { userId, type };
987
988 Object result = null;
989
990 if (retrieveFromCache) {
991 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
992 finderArgs, this);
993 }
994
995 if (result instanceof AnnouncementsDelivery) {
996 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)result;
997
998 if ((userId != announcementsDelivery.getUserId()) ||
999 !Validator.equals(type, announcementsDelivery.getType())) {
1000 result = null;
1001 }
1002 }
1003
1004 if (result == null) {
1005 StringBundler query = new StringBundler(3);
1006
1007 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
1008
1009 query.append(_FINDER_COLUMN_U_T_USERID_2);
1010
1011 if (type == null) {
1012 query.append(_FINDER_COLUMN_U_T_TYPE_1);
1013 }
1014 else {
1015 if (type.equals(StringPool.BLANK)) {
1016 query.append(_FINDER_COLUMN_U_T_TYPE_3);
1017 }
1018 else {
1019 query.append(_FINDER_COLUMN_U_T_TYPE_2);
1020 }
1021 }
1022
1023 String sql = query.toString();
1024
1025 Session session = null;
1026
1027 try {
1028 session = openSession();
1029
1030 Query q = session.createQuery(sql);
1031
1032 QueryPos qPos = QueryPos.getInstance(q);
1033
1034 qPos.add(userId);
1035
1036 if (type != null) {
1037 qPos.add(type);
1038 }
1039
1040 List<AnnouncementsDelivery> list = q.list();
1041
1042 result = list;
1043
1044 AnnouncementsDelivery announcementsDelivery = null;
1045
1046 if (list.isEmpty()) {
1047 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1048 finderArgs, list);
1049 }
1050 else {
1051 announcementsDelivery = list.get(0);
1052
1053 cacheResult(announcementsDelivery);
1054
1055 if ((announcementsDelivery.getUserId() != userId) ||
1056 (announcementsDelivery.getType() == null) ||
1057 !announcementsDelivery.getType().equals(type)) {
1058 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1059 finderArgs, announcementsDelivery);
1060 }
1061 }
1062
1063 return announcementsDelivery;
1064 }
1065 catch (Exception e) {
1066 throw processException(e);
1067 }
1068 finally {
1069 if (result == null) {
1070 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1071 finderArgs);
1072 }
1073
1074 closeSession(session);
1075 }
1076 }
1077 else {
1078 if (result instanceof List<?>) {
1079 return null;
1080 }
1081 else {
1082 return (AnnouncementsDelivery)result;
1083 }
1084 }
1085 }
1086
1087
1093 public List<AnnouncementsDelivery> findAll() throws SystemException {
1094 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1095 }
1096
1097
1109 public List<AnnouncementsDelivery> findAll(int start, int end)
1110 throws SystemException {
1111 return findAll(start, end, null);
1112 }
1113
1114
1127 public List<AnnouncementsDelivery> findAll(int start, int end,
1128 OrderByComparator orderByComparator) throws SystemException {
1129 FinderPath finderPath = null;
1130 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1131
1132 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1133 (orderByComparator == null)) {
1134 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1135 finderArgs = FINDER_ARGS_EMPTY;
1136 }
1137 else {
1138 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1139 finderArgs = new Object[] { start, end, orderByComparator };
1140 }
1141
1142 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1143 finderArgs, this);
1144
1145 if (list == null) {
1146 StringBundler query = null;
1147 String sql = null;
1148
1149 if (orderByComparator != null) {
1150 query = new StringBundler(2 +
1151 (orderByComparator.getOrderByFields().length * 3));
1152
1153 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1154
1155 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1156 orderByComparator);
1157
1158 sql = query.toString();
1159 }
1160 else {
1161 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1162 }
1163
1164 Session session = null;
1165
1166 try {
1167 session = openSession();
1168
1169 Query q = session.createQuery(sql);
1170
1171 if (orderByComparator == null) {
1172 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1173 getDialect(), start, end, false);
1174
1175 Collections.sort(list);
1176 }
1177 else {
1178 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1179 getDialect(), start, end);
1180 }
1181 }
1182 catch (Exception e) {
1183 throw processException(e);
1184 }
1185 finally {
1186 if (list == null) {
1187 FinderCacheUtil.removeResult(finderPath, finderArgs);
1188 }
1189 else {
1190 cacheResult(list);
1191
1192 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1193 }
1194
1195 closeSession(session);
1196 }
1197 }
1198
1199 return list;
1200 }
1201
1202
1208 public void removeByUserId(long userId) throws SystemException {
1209 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1210 remove(announcementsDelivery);
1211 }
1212 }
1213
1214
1222 public AnnouncementsDelivery removeByU_T(long userId, String type)
1223 throws NoSuchDeliveryException, SystemException {
1224 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1225
1226 return remove(announcementsDelivery);
1227 }
1228
1229
1234 public void removeAll() throws SystemException {
1235 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1236 remove(announcementsDelivery);
1237 }
1238 }
1239
1240
1247 public int countByUserId(long userId) throws SystemException {
1248 Object[] finderArgs = new Object[] { userId };
1249
1250 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1251 finderArgs, this);
1252
1253 if (count == null) {
1254 StringBundler query = new StringBundler(2);
1255
1256 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1257
1258 query.append(_FINDER_COLUMN_USERID_USERID_2);
1259
1260 String sql = query.toString();
1261
1262 Session session = null;
1263
1264 try {
1265 session = openSession();
1266
1267 Query q = session.createQuery(sql);
1268
1269 QueryPos qPos = QueryPos.getInstance(q);
1270
1271 qPos.add(userId);
1272
1273 count = (Long)q.uniqueResult();
1274 }
1275 catch (Exception e) {
1276 throw processException(e);
1277 }
1278 finally {
1279 if (count == null) {
1280 count = Long.valueOf(0);
1281 }
1282
1283 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1284 finderArgs, count);
1285
1286 closeSession(session);
1287 }
1288 }
1289
1290 return count.intValue();
1291 }
1292
1293
1301 public int countByU_T(long userId, String type) throws SystemException {
1302 Object[] finderArgs = new Object[] { userId, type };
1303
1304 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1305 finderArgs, this);
1306
1307 if (count == null) {
1308 StringBundler query = new StringBundler(3);
1309
1310 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1311
1312 query.append(_FINDER_COLUMN_U_T_USERID_2);
1313
1314 if (type == null) {
1315 query.append(_FINDER_COLUMN_U_T_TYPE_1);
1316 }
1317 else {
1318 if (type.equals(StringPool.BLANK)) {
1319 query.append(_FINDER_COLUMN_U_T_TYPE_3);
1320 }
1321 else {
1322 query.append(_FINDER_COLUMN_U_T_TYPE_2);
1323 }
1324 }
1325
1326 String sql = query.toString();
1327
1328 Session session = null;
1329
1330 try {
1331 session = openSession();
1332
1333 Query q = session.createQuery(sql);
1334
1335 QueryPos qPos = QueryPos.getInstance(q);
1336
1337 qPos.add(userId);
1338
1339 if (type != null) {
1340 qPos.add(type);
1341 }
1342
1343 count = (Long)q.uniqueResult();
1344 }
1345 catch (Exception e) {
1346 throw processException(e);
1347 }
1348 finally {
1349 if (count == null) {
1350 count = Long.valueOf(0);
1351 }
1352
1353 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1354 count);
1355
1356 closeSession(session);
1357 }
1358 }
1359
1360 return count.intValue();
1361 }
1362
1363
1369 public int countAll() throws SystemException {
1370 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1371 FINDER_ARGS_EMPTY, this);
1372
1373 if (count == null) {
1374 Session session = null;
1375
1376 try {
1377 session = openSession();
1378
1379 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1380
1381 count = (Long)q.uniqueResult();
1382 }
1383 catch (Exception e) {
1384 throw processException(e);
1385 }
1386 finally {
1387 if (count == null) {
1388 count = Long.valueOf(0);
1389 }
1390
1391 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1392 FINDER_ARGS_EMPTY, count);
1393
1394 closeSession(session);
1395 }
1396 }
1397
1398 return count.intValue();
1399 }
1400
1401
1404 public void afterPropertiesSet() {
1405 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1406 com.liferay.portal.util.PropsUtil.get(
1407 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1408
1409 if (listenerClassNames.length > 0) {
1410 try {
1411 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1412
1413 for (String listenerClassName : listenerClassNames) {
1414 Class<?> clazz = getClass();
1415
1416 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1417 clazz.getClassLoader(), listenerClassName));
1418 }
1419
1420 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1421 }
1422 catch (Exception e) {
1423 _log.error(e);
1424 }
1425 }
1426 }
1427
1428 public void destroy() {
1429 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1430 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1431 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1432 }
1433
1434 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1435 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1436 @BeanReference(type = AnnouncementsEntryPersistence.class)
1437 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1438 @BeanReference(type = AnnouncementsFlagPersistence.class)
1439 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1440 @BeanReference(type = ResourcePersistence.class)
1441 protected ResourcePersistence resourcePersistence;
1442 @BeanReference(type = UserPersistence.class)
1443 protected UserPersistence userPersistence;
1444 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1445 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1446 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1447 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1448 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1449 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1450 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1451 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1452 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1453 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1454 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1455 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1456 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1457 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1458 private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1459 @Override
1460 public Object clone() {
1461 return this;
1462 }
1463
1464 @Override
1465 public CacheModel<AnnouncementsDelivery> toCacheModel() {
1466 return _nullAnnouncementsDeliveryCacheModel;
1467 }
1468 };
1469
1470 private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1471 new CacheModel<AnnouncementsDelivery>() {
1472 public AnnouncementsDelivery toEntityModel() {
1473 return _nullAnnouncementsDelivery;
1474 }
1475 };
1476 }