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 clearUniqueFindersCache(
216 AnnouncementsDelivery announcementsDelivery) {
217 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
218 new Object[] {
219 Long.valueOf(announcementsDelivery.getUserId()),
220
221 announcementsDelivery.getType()
222 });
223 }
224
225
231 public AnnouncementsDelivery create(long deliveryId) {
232 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
233
234 announcementsDelivery.setNew(true);
235 announcementsDelivery.setPrimaryKey(deliveryId);
236
237 return announcementsDelivery;
238 }
239
240
248 public AnnouncementsDelivery remove(long deliveryId)
249 throws NoSuchDeliveryException, SystemException {
250 return remove(Long.valueOf(deliveryId));
251 }
252
253
261 @Override
262 public AnnouncementsDelivery remove(Serializable primaryKey)
263 throws NoSuchDeliveryException, SystemException {
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
270 primaryKey);
271
272 if (announcementsDelivery == null) {
273 if (_log.isWarnEnabled()) {
274 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
275 }
276
277 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
278 primaryKey);
279 }
280
281 return remove(announcementsDelivery);
282 }
283 catch (NoSuchDeliveryException nsee) {
284 throw nsee;
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292 }
293
294 @Override
295 protected AnnouncementsDelivery removeImpl(
296 AnnouncementsDelivery announcementsDelivery) throws SystemException {
297 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
298
299 Session session = null;
300
301 try {
302 session = openSession();
303
304 BatchSessionUtil.delete(session, announcementsDelivery);
305 }
306 catch (Exception e) {
307 throw processException(e);
308 }
309 finally {
310 closeSession(session);
311 }
312
313 clearCache(announcementsDelivery);
314
315 return announcementsDelivery;
316 }
317
318 @Override
319 public AnnouncementsDelivery updateImpl(
320 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery,
321 boolean merge) throws SystemException {
322 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
323
324 boolean isNew = announcementsDelivery.isNew();
325
326 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
327
328 Session session = null;
329
330 try {
331 session = openSession();
332
333 BatchSessionUtil.update(session, announcementsDelivery, merge);
334
335 announcementsDelivery.setNew(false);
336 }
337 catch (Exception e) {
338 throw processException(e);
339 }
340 finally {
341 closeSession(session);
342 }
343
344 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
345
346 if (isNew || !AnnouncementsDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
347 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
348 }
349 else {
350 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
351 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
352 Object[] args = new Object[] {
353 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId())
354 };
355
356 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
357 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
358 args);
359
360 args = new Object[] {
361 Long.valueOf(announcementsDeliveryModelImpl.getUserId())
362 };
363
364 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
365 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
366 args);
367 }
368 }
369
370 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
371 AnnouncementsDeliveryImpl.class,
372 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
373
374 if (isNew) {
375 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
376 new Object[] {
377 Long.valueOf(announcementsDelivery.getUserId()),
378
379 announcementsDelivery.getType()
380 }, announcementsDelivery);
381 }
382 else {
383 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
384 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
385 Object[] args = new Object[] {
386 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId()),
387
388 announcementsDeliveryModelImpl.getOriginalType()
389 };
390
391 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
392 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
393
394 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
395 new Object[] {
396 Long.valueOf(announcementsDelivery.getUserId()),
397
398 announcementsDelivery.getType()
399 }, announcementsDelivery);
400 }
401 }
402
403 return announcementsDelivery;
404 }
405
406 protected AnnouncementsDelivery toUnwrappedModel(
407 AnnouncementsDelivery announcementsDelivery) {
408 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
409 return announcementsDelivery;
410 }
411
412 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
413
414 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
415 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
416
417 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
418 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
419 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
420 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
421 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
422 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
423 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
424
425 return announcementsDeliveryImpl;
426 }
427
428
436 @Override
437 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
438 throws NoSuchModelException, SystemException {
439 return findByPrimaryKey(((Long)primaryKey).longValue());
440 }
441
442
450 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
451 throws NoSuchDeliveryException, SystemException {
452 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
453
454 if (announcementsDelivery == null) {
455 if (_log.isWarnEnabled()) {
456 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
457 }
458
459 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
460 deliveryId);
461 }
462
463 return announcementsDelivery;
464 }
465
466
473 @Override
474 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
475 throws SystemException {
476 return fetchByPrimaryKey(((Long)primaryKey).longValue());
477 }
478
479
486 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
487 throws SystemException {
488 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
489 AnnouncementsDeliveryImpl.class, deliveryId);
490
491 if (announcementsDelivery == _nullAnnouncementsDelivery) {
492 return null;
493 }
494
495 if (announcementsDelivery == null) {
496 Session session = null;
497
498 boolean hasException = false;
499
500 try {
501 session = openSession();
502
503 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
504 Long.valueOf(deliveryId));
505 }
506 catch (Exception e) {
507 hasException = true;
508
509 throw processException(e);
510 }
511 finally {
512 if (announcementsDelivery != null) {
513 cacheResult(announcementsDelivery);
514 }
515 else if (!hasException) {
516 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
517 AnnouncementsDeliveryImpl.class, deliveryId,
518 _nullAnnouncementsDelivery);
519 }
520
521 closeSession(session);
522 }
523 }
524
525 return announcementsDelivery;
526 }
527
528
535 public List<AnnouncementsDelivery> findByUserId(long userId)
536 throws SystemException {
537 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
538 }
539
540
553 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
554 int end) throws SystemException {
555 return findByUserId(userId, start, end, null);
556 }
557
558
572 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
573 int end, OrderByComparator orderByComparator) throws SystemException {
574 FinderPath finderPath = null;
575 Object[] finderArgs = null;
576
577 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
578 (orderByComparator == null)) {
579 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
580 finderArgs = new Object[] { userId };
581 }
582 else {
583 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
584 finderArgs = new Object[] { userId, start, end, orderByComparator };
585 }
586
587 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
588 finderArgs, this);
589
590 if ((list != null) && !list.isEmpty()) {
591 for (AnnouncementsDelivery announcementsDelivery : list) {
592 if ((userId != announcementsDelivery.getUserId())) {
593 list = null;
594
595 break;
596 }
597 }
598 }
599
600 if (list == null) {
601 StringBundler query = null;
602
603 if (orderByComparator != null) {
604 query = new StringBundler(3 +
605 (orderByComparator.getOrderByFields().length * 3));
606 }
607 else {
608 query = new StringBundler(2);
609 }
610
611 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
612
613 query.append(_FINDER_COLUMN_USERID_USERID_2);
614
615 if (orderByComparator != null) {
616 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
617 orderByComparator);
618 }
619
620 String sql = query.toString();
621
622 Session session = null;
623
624 try {
625 session = openSession();
626
627 Query q = session.createQuery(sql);
628
629 QueryPos qPos = QueryPos.getInstance(q);
630
631 qPos.add(userId);
632
633 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
634 getDialect(), start, end);
635 }
636 catch (Exception e) {
637 throw processException(e);
638 }
639 finally {
640 if (list == null) {
641 FinderCacheUtil.removeResult(finderPath, finderArgs);
642 }
643 else {
644 cacheResult(list);
645
646 FinderCacheUtil.putResult(finderPath, finderArgs, list);
647 }
648
649 closeSession(session);
650 }
651 }
652
653 return list;
654 }
655
656
669 public AnnouncementsDelivery findByUserId_First(long userId,
670 OrderByComparator orderByComparator)
671 throws NoSuchDeliveryException, SystemException {
672 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
673 orderByComparator);
674
675 if (list.isEmpty()) {
676 StringBundler msg = new StringBundler(4);
677
678 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
679
680 msg.append("userId=");
681 msg.append(userId);
682
683 msg.append(StringPool.CLOSE_CURLY_BRACE);
684
685 throw new NoSuchDeliveryException(msg.toString());
686 }
687 else {
688 return list.get(0);
689 }
690 }
691
692
705 public AnnouncementsDelivery findByUserId_Last(long userId,
706 OrderByComparator orderByComparator)
707 throws NoSuchDeliveryException, SystemException {
708 int count = countByUserId(userId);
709
710 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
711 count, orderByComparator);
712
713 if (list.isEmpty()) {
714 StringBundler msg = new StringBundler(4);
715
716 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
717
718 msg.append("userId=");
719 msg.append(userId);
720
721 msg.append(StringPool.CLOSE_CURLY_BRACE);
722
723 throw new NoSuchDeliveryException(msg.toString());
724 }
725 else {
726 return list.get(0);
727 }
728 }
729
730
744 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
745 long userId, OrderByComparator orderByComparator)
746 throws NoSuchDeliveryException, SystemException {
747 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
748
749 Session session = null;
750
751 try {
752 session = openSession();
753
754 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
755
756 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
757 userId, orderByComparator, true);
758
759 array[1] = announcementsDelivery;
760
761 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
762 userId, orderByComparator, false);
763
764 return array;
765 }
766 catch (Exception e) {
767 throw processException(e);
768 }
769 finally {
770 closeSession(session);
771 }
772 }
773
774 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
775 AnnouncementsDelivery announcementsDelivery, long userId,
776 OrderByComparator orderByComparator, boolean previous) {
777 StringBundler query = null;
778
779 if (orderByComparator != null) {
780 query = new StringBundler(6 +
781 (orderByComparator.getOrderByFields().length * 6));
782 }
783 else {
784 query = new StringBundler(3);
785 }
786
787 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
788
789 query.append(_FINDER_COLUMN_USERID_USERID_2);
790
791 if (orderByComparator != null) {
792 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
793
794 if (orderByConditionFields.length > 0) {
795 query.append(WHERE_AND);
796 }
797
798 for (int i = 0; i < orderByConditionFields.length; i++) {
799 query.append(_ORDER_BY_ENTITY_ALIAS);
800 query.append(orderByConditionFields[i]);
801
802 if ((i + 1) < orderByConditionFields.length) {
803 if (orderByComparator.isAscending() ^ previous) {
804 query.append(WHERE_GREATER_THAN_HAS_NEXT);
805 }
806 else {
807 query.append(WHERE_LESSER_THAN_HAS_NEXT);
808 }
809 }
810 else {
811 if (orderByComparator.isAscending() ^ previous) {
812 query.append(WHERE_GREATER_THAN);
813 }
814 else {
815 query.append(WHERE_LESSER_THAN);
816 }
817 }
818 }
819
820 query.append(ORDER_BY_CLAUSE);
821
822 String[] orderByFields = orderByComparator.getOrderByFields();
823
824 for (int i = 0; i < orderByFields.length; i++) {
825 query.append(_ORDER_BY_ENTITY_ALIAS);
826 query.append(orderByFields[i]);
827
828 if ((i + 1) < orderByFields.length) {
829 if (orderByComparator.isAscending() ^ previous) {
830 query.append(ORDER_BY_ASC_HAS_NEXT);
831 }
832 else {
833 query.append(ORDER_BY_DESC_HAS_NEXT);
834 }
835 }
836 else {
837 if (orderByComparator.isAscending() ^ previous) {
838 query.append(ORDER_BY_ASC);
839 }
840 else {
841 query.append(ORDER_BY_DESC);
842 }
843 }
844 }
845 }
846
847 String sql = query.toString();
848
849 Query q = session.createQuery(sql);
850
851 q.setFirstResult(0);
852 q.setMaxResults(2);
853
854 QueryPos qPos = QueryPos.getInstance(q);
855
856 qPos.add(userId);
857
858 if (orderByComparator != null) {
859 Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
860
861 for (Object value : values) {
862 qPos.add(value);
863 }
864 }
865
866 List<AnnouncementsDelivery> list = q.list();
867
868 if (list.size() == 2) {
869 return list.get(1);
870 }
871 else {
872 return null;
873 }
874 }
875
876
885 public AnnouncementsDelivery findByU_T(long userId, String type)
886 throws NoSuchDeliveryException, SystemException {
887 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
888
889 if (announcementsDelivery == null) {
890 StringBundler msg = new StringBundler(6);
891
892 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
893
894 msg.append("userId=");
895 msg.append(userId);
896
897 msg.append(", type=");
898 msg.append(type);
899
900 msg.append(StringPool.CLOSE_CURLY_BRACE);
901
902 if (_log.isWarnEnabled()) {
903 _log.warn(msg.toString());
904 }
905
906 throw new NoSuchDeliveryException(msg.toString());
907 }
908
909 return announcementsDelivery;
910 }
911
912
920 public AnnouncementsDelivery fetchByU_T(long userId, String type)
921 throws SystemException {
922 return fetchByU_T(userId, type, true);
923 }
924
925
934 public AnnouncementsDelivery fetchByU_T(long userId, String type,
935 boolean retrieveFromCache) throws SystemException {
936 Object[] finderArgs = new Object[] { userId, type };
937
938 Object result = null;
939
940 if (retrieveFromCache) {
941 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
942 finderArgs, this);
943 }
944
945 if (result instanceof AnnouncementsDelivery) {
946 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)result;
947
948 if ((userId != announcementsDelivery.getUserId()) ||
949 !Validator.equals(type, announcementsDelivery.getType())) {
950 result = null;
951 }
952 }
953
954 if (result == null) {
955 StringBundler query = new StringBundler(3);
956
957 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
958
959 query.append(_FINDER_COLUMN_U_T_USERID_2);
960
961 if (type == null) {
962 query.append(_FINDER_COLUMN_U_T_TYPE_1);
963 }
964 else {
965 if (type.equals(StringPool.BLANK)) {
966 query.append(_FINDER_COLUMN_U_T_TYPE_3);
967 }
968 else {
969 query.append(_FINDER_COLUMN_U_T_TYPE_2);
970 }
971 }
972
973 String sql = query.toString();
974
975 Session session = null;
976
977 try {
978 session = openSession();
979
980 Query q = session.createQuery(sql);
981
982 QueryPos qPos = QueryPos.getInstance(q);
983
984 qPos.add(userId);
985
986 if (type != null) {
987 qPos.add(type);
988 }
989
990 List<AnnouncementsDelivery> list = q.list();
991
992 result = list;
993
994 AnnouncementsDelivery announcementsDelivery = null;
995
996 if (list.isEmpty()) {
997 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
998 finderArgs, list);
999 }
1000 else {
1001 announcementsDelivery = list.get(0);
1002
1003 cacheResult(announcementsDelivery);
1004
1005 if ((announcementsDelivery.getUserId() != userId) ||
1006 (announcementsDelivery.getType() == null) ||
1007 !announcementsDelivery.getType().equals(type)) {
1008 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
1009 finderArgs, announcementsDelivery);
1010 }
1011 }
1012
1013 return announcementsDelivery;
1014 }
1015 catch (Exception e) {
1016 throw processException(e);
1017 }
1018 finally {
1019 if (result == null) {
1020 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1021 finderArgs);
1022 }
1023
1024 closeSession(session);
1025 }
1026 }
1027 else {
1028 if (result instanceof List<?>) {
1029 return null;
1030 }
1031 else {
1032 return (AnnouncementsDelivery)result;
1033 }
1034 }
1035 }
1036
1037
1043 public List<AnnouncementsDelivery> findAll() throws SystemException {
1044 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1045 }
1046
1047
1059 public List<AnnouncementsDelivery> findAll(int start, int end)
1060 throws SystemException {
1061 return findAll(start, end, null);
1062 }
1063
1064
1077 public List<AnnouncementsDelivery> findAll(int start, int end,
1078 OrderByComparator orderByComparator) throws SystemException {
1079 FinderPath finderPath = null;
1080 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1081
1082 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1083 (orderByComparator == null)) {
1084 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1085 finderArgs = FINDER_ARGS_EMPTY;
1086 }
1087 else {
1088 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1089 finderArgs = new Object[] { start, end, orderByComparator };
1090 }
1091
1092 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1093 finderArgs, this);
1094
1095 if (list == null) {
1096 StringBundler query = null;
1097 String sql = null;
1098
1099 if (orderByComparator != null) {
1100 query = new StringBundler(2 +
1101 (orderByComparator.getOrderByFields().length * 3));
1102
1103 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1104
1105 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1106 orderByComparator);
1107
1108 sql = query.toString();
1109 }
1110 else {
1111 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1112 }
1113
1114 Session session = null;
1115
1116 try {
1117 session = openSession();
1118
1119 Query q = session.createQuery(sql);
1120
1121 if (orderByComparator == null) {
1122 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1123 getDialect(), start, end, false);
1124
1125 Collections.sort(list);
1126 }
1127 else {
1128 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1129 getDialect(), start, end);
1130 }
1131 }
1132 catch (Exception e) {
1133 throw processException(e);
1134 }
1135 finally {
1136 if (list == null) {
1137 FinderCacheUtil.removeResult(finderPath, finderArgs);
1138 }
1139 else {
1140 cacheResult(list);
1141
1142 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1143 }
1144
1145 closeSession(session);
1146 }
1147 }
1148
1149 return list;
1150 }
1151
1152
1158 public void removeByUserId(long userId) throws SystemException {
1159 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1160 remove(announcementsDelivery);
1161 }
1162 }
1163
1164
1171 public void removeByU_T(long userId, String type)
1172 throws NoSuchDeliveryException, SystemException {
1173 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1174
1175 remove(announcementsDelivery);
1176 }
1177
1178
1183 public void removeAll() throws SystemException {
1184 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1185 remove(announcementsDelivery);
1186 }
1187 }
1188
1189
1196 public int countByUserId(long userId) throws SystemException {
1197 Object[] finderArgs = new Object[] { userId };
1198
1199 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1200 finderArgs, this);
1201
1202 if (count == null) {
1203 StringBundler query = new StringBundler(2);
1204
1205 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1206
1207 query.append(_FINDER_COLUMN_USERID_USERID_2);
1208
1209 String sql = query.toString();
1210
1211 Session session = null;
1212
1213 try {
1214 session = openSession();
1215
1216 Query q = session.createQuery(sql);
1217
1218 QueryPos qPos = QueryPos.getInstance(q);
1219
1220 qPos.add(userId);
1221
1222 count = (Long)q.uniqueResult();
1223 }
1224 catch (Exception e) {
1225 throw processException(e);
1226 }
1227 finally {
1228 if (count == null) {
1229 count = Long.valueOf(0);
1230 }
1231
1232 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1233 finderArgs, count);
1234
1235 closeSession(session);
1236 }
1237 }
1238
1239 return count.intValue();
1240 }
1241
1242
1250 public int countByU_T(long userId, String type) throws SystemException {
1251 Object[] finderArgs = new Object[] { userId, type };
1252
1253 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1254 finderArgs, this);
1255
1256 if (count == null) {
1257 StringBundler query = new StringBundler(3);
1258
1259 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1260
1261 query.append(_FINDER_COLUMN_U_T_USERID_2);
1262
1263 if (type == null) {
1264 query.append(_FINDER_COLUMN_U_T_TYPE_1);
1265 }
1266 else {
1267 if (type.equals(StringPool.BLANK)) {
1268 query.append(_FINDER_COLUMN_U_T_TYPE_3);
1269 }
1270 else {
1271 query.append(_FINDER_COLUMN_U_T_TYPE_2);
1272 }
1273 }
1274
1275 String sql = query.toString();
1276
1277 Session session = null;
1278
1279 try {
1280 session = openSession();
1281
1282 Query q = session.createQuery(sql);
1283
1284 QueryPos qPos = QueryPos.getInstance(q);
1285
1286 qPos.add(userId);
1287
1288 if (type != null) {
1289 qPos.add(type);
1290 }
1291
1292 count = (Long)q.uniqueResult();
1293 }
1294 catch (Exception e) {
1295 throw processException(e);
1296 }
1297 finally {
1298 if (count == null) {
1299 count = Long.valueOf(0);
1300 }
1301
1302 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1303 count);
1304
1305 closeSession(session);
1306 }
1307 }
1308
1309 return count.intValue();
1310 }
1311
1312
1318 public int countAll() throws SystemException {
1319 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1320 FINDER_ARGS_EMPTY, this);
1321
1322 if (count == null) {
1323 Session session = null;
1324
1325 try {
1326 session = openSession();
1327
1328 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1329
1330 count = (Long)q.uniqueResult();
1331 }
1332 catch (Exception e) {
1333 throw processException(e);
1334 }
1335 finally {
1336 if (count == null) {
1337 count = Long.valueOf(0);
1338 }
1339
1340 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1341 FINDER_ARGS_EMPTY, count);
1342
1343 closeSession(session);
1344 }
1345 }
1346
1347 return count.intValue();
1348 }
1349
1350
1353 public void afterPropertiesSet() {
1354 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1355 com.liferay.portal.util.PropsUtil.get(
1356 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1357
1358 if (listenerClassNames.length > 0) {
1359 try {
1360 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1361
1362 for (String listenerClassName : listenerClassNames) {
1363 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1364 listenerClassName));
1365 }
1366
1367 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1368 }
1369 catch (Exception e) {
1370 _log.error(e);
1371 }
1372 }
1373 }
1374
1375 public void destroy() {
1376 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1377 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1378 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1379 }
1380
1381 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1382 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1383 @BeanReference(type = AnnouncementsEntryPersistence.class)
1384 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1385 @BeanReference(type = AnnouncementsFlagPersistence.class)
1386 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1387 @BeanReference(type = ResourcePersistence.class)
1388 protected ResourcePersistence resourcePersistence;
1389 @BeanReference(type = UserPersistence.class)
1390 protected UserPersistence userPersistence;
1391 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1392 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1393 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1394 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1395 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1396 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1397 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1398 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1399 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1400 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1401 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1402 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1403 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1404 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1405 private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1406 @Override
1407 public Object clone() {
1408 return this;
1409 }
1410
1411 @Override
1412 public CacheModel<AnnouncementsDelivery> toCacheModel() {
1413 return _nullAnnouncementsDeliveryCacheModel;
1414 }
1415 };
1416
1417 private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1418 new CacheModel<AnnouncementsDelivery>() {
1419 public AnnouncementsDelivery toEntityModel() {
1420 return _nullAnnouncementsDelivery;
1421 }
1422 };
1423 }