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.model.CacheModel;
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
066 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
067 implements AnnouncementsDeliveryPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
079 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
080 AnnouncementsDeliveryImpl.class,
081 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
089 new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
090 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
091 AnnouncementsDeliveryImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
093 new String[] { Long.class.getName() },
094 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK);
095 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
096 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
098 new String[] { Long.class.getName() });
099 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
100 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
101 AnnouncementsDeliveryImpl.class, FINDER_CLASS_NAME_ENTITY,
102 "fetchByU_T",
103 new String[] { Long.class.getName(), String.class.getName() },
104 AnnouncementsDeliveryModelImpl.USERID_COLUMN_BITMASK |
105 AnnouncementsDeliveryModelImpl.TYPE_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
107 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_T",
109 new String[] { Long.class.getName(), String.class.getName() });
110 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
111 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
112 AnnouncementsDeliveryImpl.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
114 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
115 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
116 AnnouncementsDeliveryImpl.class,
117 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
118 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
119 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED, Long.class,
120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
121
122
127 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
128 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
129 AnnouncementsDeliveryImpl.class,
130 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
131
132 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
133 new Object[] {
134 Long.valueOf(announcementsDelivery.getUserId()),
135
136 announcementsDelivery.getType()
137 }, announcementsDelivery);
138
139 announcementsDelivery.resetOriginalValues();
140 }
141
142
147 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
148 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
149 if (EntityCacheUtil.getResult(
150 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
151 AnnouncementsDeliveryImpl.class,
152 announcementsDelivery.getPrimaryKey()) == null) {
153 cacheResult(announcementsDelivery);
154 }
155 else {
156 announcementsDelivery.resetOriginalValues();
157 }
158 }
159 }
160
161
168 @Override
169 public void clearCache() {
170 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
171 CacheRegistryUtil.clear(AnnouncementsDeliveryImpl.class.getName());
172 }
173
174 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
175
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
177 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
178 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
179 }
180
181
188 @Override
189 public void clearCache(AnnouncementsDelivery announcementsDelivery) {
190 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
191 AnnouncementsDeliveryImpl.class,
192 announcementsDelivery.getPrimaryKey());
193
194 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
195 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
196
197 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
198 new Object[] {
199 Long.valueOf(announcementsDelivery.getUserId()),
200
201 announcementsDelivery.getType()
202 });
203 }
204
205
211 public AnnouncementsDelivery create(long deliveryId) {
212 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
213
214 announcementsDelivery.setNew(true);
215 announcementsDelivery.setPrimaryKey(deliveryId);
216
217 return announcementsDelivery;
218 }
219
220
228 @Override
229 public AnnouncementsDelivery remove(Serializable primaryKey)
230 throws NoSuchModelException, SystemException {
231 return remove(((Long)primaryKey).longValue());
232 }
233
234
242 public AnnouncementsDelivery remove(long deliveryId)
243 throws NoSuchDeliveryException, SystemException {
244 Session session = null;
245
246 try {
247 session = openSession();
248
249 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
250 Long.valueOf(deliveryId));
251
252 if (announcementsDelivery == null) {
253 if (_log.isWarnEnabled()) {
254 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
255 }
256
257 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
258 deliveryId);
259 }
260
261 return announcementsDeliveryPersistence.remove(announcementsDelivery);
262 }
263 catch (NoSuchDeliveryException nsee) {
264 throw nsee;
265 }
266 catch (Exception e) {
267 throw processException(e);
268 }
269 finally {
270 closeSession(session);
271 }
272 }
273
274
281 @Override
282 public AnnouncementsDelivery remove(
283 AnnouncementsDelivery announcementsDelivery) throws SystemException {
284 return super.remove(announcementsDelivery);
285 }
286
287 @Override
288 protected AnnouncementsDelivery removeImpl(
289 AnnouncementsDelivery announcementsDelivery) throws SystemException {
290 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
291
292 Session session = null;
293
294 try {
295 session = openSession();
296
297 BatchSessionUtil.delete(session, announcementsDelivery);
298 }
299 catch (Exception e) {
300 throw processException(e);
301 }
302 finally {
303 closeSession(session);
304 }
305
306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
307 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
308
309 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
310
311 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
312 new Object[] {
313 Long.valueOf(announcementsDeliveryModelImpl.getUserId()),
314
315 announcementsDeliveryModelImpl.getType()
316 });
317
318 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
319 AnnouncementsDeliveryImpl.class,
320 announcementsDelivery.getPrimaryKey());
321
322 return announcementsDelivery;
323 }
324
325 @Override
326 public AnnouncementsDelivery updateImpl(
327 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery,
328 boolean merge) throws SystemException {
329 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
330
331 boolean isNew = announcementsDelivery.isNew();
332
333 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
334
335 Session session = null;
336
337 try {
338 session = openSession();
339
340 BatchSessionUtil.update(session, announcementsDelivery, merge);
341
342 announcementsDelivery.setNew(false);
343 }
344 catch (Exception e) {
345 throw processException(e);
346 }
347 finally {
348 closeSession(session);
349 }
350
351 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
352
353 if (isNew || !AnnouncementsDeliveryModelImpl.COLUMN_BITMASK_ENABLED) {
354 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
355 }
356
357 else {
358 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
359 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
360 Object[] args = new Object[] {
361 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId())
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 args = new Object[] {
369 Long.valueOf(announcementsDeliveryModelImpl.getUserId())
370 };
371
372 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
373 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
374 args);
375 }
376 }
377
378 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
379 AnnouncementsDeliveryImpl.class,
380 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
381
382 if (isNew) {
383 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
384 new Object[] {
385 Long.valueOf(announcementsDelivery.getUserId()),
386
387 announcementsDelivery.getType()
388 }, announcementsDelivery);
389 }
390 else {
391 if ((announcementsDeliveryModelImpl.getColumnBitmask() &
392 FINDER_PATH_FETCH_BY_U_T.getColumnBitmask()) != 0) {
393 Object[] args = new Object[] {
394 Long.valueOf(announcementsDeliveryModelImpl.getOriginalUserId()),
395
396 announcementsDeliveryModelImpl.getOriginalType()
397 };
398
399 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_T, args);
400 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T, args);
401
402 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
403 new Object[] {
404 Long.valueOf(announcementsDelivery.getUserId()),
405
406 announcementsDelivery.getType()
407 }, announcementsDelivery);
408 }
409 }
410
411 return announcementsDelivery;
412 }
413
414 protected AnnouncementsDelivery toUnwrappedModel(
415 AnnouncementsDelivery announcementsDelivery) {
416 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
417 return announcementsDelivery;
418 }
419
420 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
421
422 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
423 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
424
425 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
426 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
427 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
428 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
429 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
430 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
431 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
432
433 return announcementsDeliveryImpl;
434 }
435
436
444 @Override
445 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
446 throws NoSuchModelException, SystemException {
447 return findByPrimaryKey(((Long)primaryKey).longValue());
448 }
449
450
458 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
459 throws NoSuchDeliveryException, SystemException {
460 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
461
462 if (announcementsDelivery == null) {
463 if (_log.isWarnEnabled()) {
464 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
465 }
466
467 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
468 deliveryId);
469 }
470
471 return announcementsDelivery;
472 }
473
474
481 @Override
482 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
483 throws SystemException {
484 return fetchByPrimaryKey(((Long)primaryKey).longValue());
485 }
486
487
494 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
495 throws SystemException {
496 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
497 AnnouncementsDeliveryImpl.class, deliveryId);
498
499 if (announcementsDelivery == _nullAnnouncementsDelivery) {
500 return null;
501 }
502
503 if (announcementsDelivery == null) {
504 Session session = null;
505
506 boolean hasException = false;
507
508 try {
509 session = openSession();
510
511 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
512 Long.valueOf(deliveryId));
513 }
514 catch (Exception e) {
515 hasException = true;
516
517 throw processException(e);
518 }
519 finally {
520 if (announcementsDelivery != null) {
521 cacheResult(announcementsDelivery);
522 }
523 else if (!hasException) {
524 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
525 AnnouncementsDeliveryImpl.class, deliveryId,
526 _nullAnnouncementsDelivery);
527 }
528
529 closeSession(session);
530 }
531 }
532
533 return announcementsDelivery;
534 }
535
536
543 public List<AnnouncementsDelivery> findByUserId(long userId)
544 throws SystemException {
545 return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
546 }
547
548
561 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
562 int end) throws SystemException {
563 return findByUserId(userId, start, end, null);
564 }
565
566
580 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
581 int end, OrderByComparator orderByComparator) throws SystemException {
582 FinderPath finderPath = null;
583 Object[] finderArgs = null;
584
585 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
586 (orderByComparator == null)) {
587 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
588 finderArgs = new Object[] { userId };
589 }
590 else {
591 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
592 finderArgs = new Object[] { userId, start, end, orderByComparator };
593 }
594
595 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
596 finderArgs, this);
597
598 if (list == null) {
599 StringBundler query = null;
600
601 if (orderByComparator != null) {
602 query = new StringBundler(3 +
603 (orderByComparator.getOrderByFields().length * 3));
604 }
605 else {
606 query = new StringBundler(2);
607 }
608
609 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
610
611 query.append(_FINDER_COLUMN_USERID_USERID_2);
612
613 if (orderByComparator != null) {
614 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
615 orderByComparator);
616 }
617
618 String sql = query.toString();
619
620 Session session = null;
621
622 try {
623 session = openSession();
624
625 Query q = session.createQuery(sql);
626
627 QueryPos qPos = QueryPos.getInstance(q);
628
629 qPos.add(userId);
630
631 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
632 getDialect(), start, end);
633 }
634 catch (Exception e) {
635 throw processException(e);
636 }
637 finally {
638 if (list == null) {
639 FinderCacheUtil.removeResult(finderPath, finderArgs);
640 }
641 else {
642 cacheResult(list);
643
644 FinderCacheUtil.putResult(finderPath, finderArgs, list);
645 }
646
647 closeSession(session);
648 }
649 }
650
651 return list;
652 }
653
654
667 public AnnouncementsDelivery findByUserId_First(long userId,
668 OrderByComparator orderByComparator)
669 throws NoSuchDeliveryException, SystemException {
670 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1,
671 orderByComparator);
672
673 if (list.isEmpty()) {
674 StringBundler msg = new StringBundler(4);
675
676 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
677
678 msg.append("userId=");
679 msg.append(userId);
680
681 msg.append(StringPool.CLOSE_CURLY_BRACE);
682
683 throw new NoSuchDeliveryException(msg.toString());
684 }
685 else {
686 return list.get(0);
687 }
688 }
689
690
703 public AnnouncementsDelivery findByUserId_Last(long userId,
704 OrderByComparator orderByComparator)
705 throws NoSuchDeliveryException, SystemException {
706 int count = countByUserId(userId);
707
708 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
709 count, orderByComparator);
710
711 if (list.isEmpty()) {
712 StringBundler msg = new StringBundler(4);
713
714 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
715
716 msg.append("userId=");
717 msg.append(userId);
718
719 msg.append(StringPool.CLOSE_CURLY_BRACE);
720
721 throw new NoSuchDeliveryException(msg.toString());
722 }
723 else {
724 return list.get(0);
725 }
726 }
727
728
742 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
743 long userId, OrderByComparator orderByComparator)
744 throws NoSuchDeliveryException, SystemException {
745 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
746
747 Session session = null;
748
749 try {
750 session = openSession();
751
752 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
753
754 array[0] = getByUserId_PrevAndNext(session, announcementsDelivery,
755 userId, orderByComparator, true);
756
757 array[1] = announcementsDelivery;
758
759 array[2] = getByUserId_PrevAndNext(session, announcementsDelivery,
760 userId, orderByComparator, false);
761
762 return array;
763 }
764 catch (Exception e) {
765 throw processException(e);
766 }
767 finally {
768 closeSession(session);
769 }
770 }
771
772 protected AnnouncementsDelivery getByUserId_PrevAndNext(Session session,
773 AnnouncementsDelivery announcementsDelivery, long userId,
774 OrderByComparator orderByComparator, boolean previous) {
775 StringBundler query = null;
776
777 if (orderByComparator != null) {
778 query = new StringBundler(6 +
779 (orderByComparator.getOrderByFields().length * 6));
780 }
781 else {
782 query = new StringBundler(3);
783 }
784
785 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
786
787 query.append(_FINDER_COLUMN_USERID_USERID_2);
788
789 if (orderByComparator != null) {
790 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
791
792 if (orderByConditionFields.length > 0) {
793 query.append(WHERE_AND);
794 }
795
796 for (int i = 0; i < orderByConditionFields.length; i++) {
797 query.append(_ORDER_BY_ENTITY_ALIAS);
798 query.append(orderByConditionFields[i]);
799
800 if ((i + 1) < orderByConditionFields.length) {
801 if (orderByComparator.isAscending() ^ previous) {
802 query.append(WHERE_GREATER_THAN_HAS_NEXT);
803 }
804 else {
805 query.append(WHERE_LESSER_THAN_HAS_NEXT);
806 }
807 }
808 else {
809 if (orderByComparator.isAscending() ^ previous) {
810 query.append(WHERE_GREATER_THAN);
811 }
812 else {
813 query.append(WHERE_LESSER_THAN);
814 }
815 }
816 }
817
818 query.append(ORDER_BY_CLAUSE);
819
820 String[] orderByFields = orderByComparator.getOrderByFields();
821
822 for (int i = 0; i < orderByFields.length; i++) {
823 query.append(_ORDER_BY_ENTITY_ALIAS);
824 query.append(orderByFields[i]);
825
826 if ((i + 1) < orderByFields.length) {
827 if (orderByComparator.isAscending() ^ previous) {
828 query.append(ORDER_BY_ASC_HAS_NEXT);
829 }
830 else {
831 query.append(ORDER_BY_DESC_HAS_NEXT);
832 }
833 }
834 else {
835 if (orderByComparator.isAscending() ^ previous) {
836 query.append(ORDER_BY_ASC);
837 }
838 else {
839 query.append(ORDER_BY_DESC);
840 }
841 }
842 }
843 }
844
845 String sql = query.toString();
846
847 Query q = session.createQuery(sql);
848
849 q.setFirstResult(0);
850 q.setMaxResults(2);
851
852 QueryPos qPos = QueryPos.getInstance(q);
853
854 qPos.add(userId);
855
856 if (orderByComparator != null) {
857 Object[] values = orderByComparator.getOrderByConditionValues(announcementsDelivery);
858
859 for (Object value : values) {
860 qPos.add(value);
861 }
862 }
863
864 List<AnnouncementsDelivery> list = q.list();
865
866 if (list.size() == 2) {
867 return list.get(1);
868 }
869 else {
870 return null;
871 }
872 }
873
874
883 public AnnouncementsDelivery findByU_T(long userId, String type)
884 throws NoSuchDeliveryException, SystemException {
885 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
886
887 if (announcementsDelivery == null) {
888 StringBundler msg = new StringBundler(6);
889
890 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
891
892 msg.append("userId=");
893 msg.append(userId);
894
895 msg.append(", type=");
896 msg.append(type);
897
898 msg.append(StringPool.CLOSE_CURLY_BRACE);
899
900 if (_log.isWarnEnabled()) {
901 _log.warn(msg.toString());
902 }
903
904 throw new NoSuchDeliveryException(msg.toString());
905 }
906
907 return announcementsDelivery;
908 }
909
910
918 public AnnouncementsDelivery fetchByU_T(long userId, String type)
919 throws SystemException {
920 return fetchByU_T(userId, type, true);
921 }
922
923
932 public AnnouncementsDelivery fetchByU_T(long userId, String type,
933 boolean retrieveFromCache) throws SystemException {
934 Object[] finderArgs = new Object[] { userId, type };
935
936 Object result = null;
937
938 if (retrieveFromCache) {
939 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
940 finderArgs, this);
941 }
942
943 if (result == null) {
944 StringBundler query = new StringBundler(3);
945
946 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
947
948 query.append(_FINDER_COLUMN_U_T_USERID_2);
949
950 if (type == null) {
951 query.append(_FINDER_COLUMN_U_T_TYPE_1);
952 }
953 else {
954 if (type.equals(StringPool.BLANK)) {
955 query.append(_FINDER_COLUMN_U_T_TYPE_3);
956 }
957 else {
958 query.append(_FINDER_COLUMN_U_T_TYPE_2);
959 }
960 }
961
962 String sql = query.toString();
963
964 Session session = null;
965
966 try {
967 session = openSession();
968
969 Query q = session.createQuery(sql);
970
971 QueryPos qPos = QueryPos.getInstance(q);
972
973 qPos.add(userId);
974
975 if (type != null) {
976 qPos.add(type);
977 }
978
979 List<AnnouncementsDelivery> list = q.list();
980
981 result = list;
982
983 AnnouncementsDelivery announcementsDelivery = null;
984
985 if (list.isEmpty()) {
986 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
987 finderArgs, list);
988 }
989 else {
990 announcementsDelivery = list.get(0);
991
992 cacheResult(announcementsDelivery);
993
994 if ((announcementsDelivery.getUserId() != userId) ||
995 (announcementsDelivery.getType() == null) ||
996 !announcementsDelivery.getType().equals(type)) {
997 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
998 finderArgs, announcementsDelivery);
999 }
1000 }
1001
1002 return announcementsDelivery;
1003 }
1004 catch (Exception e) {
1005 throw processException(e);
1006 }
1007 finally {
1008 if (result == null) {
1009 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
1010 finderArgs);
1011 }
1012
1013 closeSession(session);
1014 }
1015 }
1016 else {
1017 if (result instanceof List<?>) {
1018 return null;
1019 }
1020 else {
1021 return (AnnouncementsDelivery)result;
1022 }
1023 }
1024 }
1025
1026
1032 public List<AnnouncementsDelivery> findAll() throws SystemException {
1033 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1034 }
1035
1036
1048 public List<AnnouncementsDelivery> findAll(int start, int end)
1049 throws SystemException {
1050 return findAll(start, end, null);
1051 }
1052
1053
1066 public List<AnnouncementsDelivery> findAll(int start, int end,
1067 OrderByComparator orderByComparator) throws SystemException {
1068 FinderPath finderPath = null;
1069 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1070
1071 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1072 (orderByComparator == null)) {
1073 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1074 finderArgs = FINDER_ARGS_EMPTY;
1075 }
1076 else {
1077 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1078 finderArgs = new Object[] { start, end, orderByComparator };
1079 }
1080
1081 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(finderPath,
1082 finderArgs, this);
1083
1084 if (list == null) {
1085 StringBundler query = null;
1086 String sql = null;
1087
1088 if (orderByComparator != null) {
1089 query = new StringBundler(2 +
1090 (orderByComparator.getOrderByFields().length * 3));
1091
1092 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
1093
1094 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1095 orderByComparator);
1096
1097 sql = query.toString();
1098 }
1099 else {
1100 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
1101 }
1102
1103 Session session = null;
1104
1105 try {
1106 session = openSession();
1107
1108 Query q = session.createQuery(sql);
1109
1110 if (orderByComparator == null) {
1111 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1112 getDialect(), start, end, false);
1113
1114 Collections.sort(list);
1115 }
1116 else {
1117 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
1118 getDialect(), start, end);
1119 }
1120 }
1121 catch (Exception e) {
1122 throw processException(e);
1123 }
1124 finally {
1125 if (list == null) {
1126 FinderCacheUtil.removeResult(finderPath, finderArgs);
1127 }
1128 else {
1129 cacheResult(list);
1130
1131 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1132 }
1133
1134 closeSession(session);
1135 }
1136 }
1137
1138 return list;
1139 }
1140
1141
1147 public void removeByUserId(long userId) throws SystemException {
1148 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
1149 announcementsDeliveryPersistence.remove(announcementsDelivery);
1150 }
1151 }
1152
1153
1160 public void removeByU_T(long userId, String type)
1161 throws NoSuchDeliveryException, SystemException {
1162 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
1163
1164 announcementsDeliveryPersistence.remove(announcementsDelivery);
1165 }
1166
1167
1172 public void removeAll() throws SystemException {
1173 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
1174 announcementsDeliveryPersistence.remove(announcementsDelivery);
1175 }
1176 }
1177
1178
1185 public int countByUserId(long userId) throws SystemException {
1186 Object[] finderArgs = new Object[] { userId };
1187
1188 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1189 finderArgs, this);
1190
1191 if (count == null) {
1192 StringBundler query = new StringBundler(2);
1193
1194 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1195
1196 query.append(_FINDER_COLUMN_USERID_USERID_2);
1197
1198 String sql = query.toString();
1199
1200 Session session = null;
1201
1202 try {
1203 session = openSession();
1204
1205 Query q = session.createQuery(sql);
1206
1207 QueryPos qPos = QueryPos.getInstance(q);
1208
1209 qPos.add(userId);
1210
1211 count = (Long)q.uniqueResult();
1212 }
1213 catch (Exception e) {
1214 throw processException(e);
1215 }
1216 finally {
1217 if (count == null) {
1218 count = Long.valueOf(0);
1219 }
1220
1221 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1222 finderArgs, count);
1223
1224 closeSession(session);
1225 }
1226 }
1227
1228 return count.intValue();
1229 }
1230
1231
1239 public int countByU_T(long userId, String type) throws SystemException {
1240 Object[] finderArgs = new Object[] { userId, type };
1241
1242 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
1243 finderArgs, this);
1244
1245 if (count == null) {
1246 StringBundler query = new StringBundler(3);
1247
1248 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
1249
1250 query.append(_FINDER_COLUMN_U_T_USERID_2);
1251
1252 if (type == null) {
1253 query.append(_FINDER_COLUMN_U_T_TYPE_1);
1254 }
1255 else {
1256 if (type.equals(StringPool.BLANK)) {
1257 query.append(_FINDER_COLUMN_U_T_TYPE_3);
1258 }
1259 else {
1260 query.append(_FINDER_COLUMN_U_T_TYPE_2);
1261 }
1262 }
1263
1264 String sql = query.toString();
1265
1266 Session session = null;
1267
1268 try {
1269 session = openSession();
1270
1271 Query q = session.createQuery(sql);
1272
1273 QueryPos qPos = QueryPos.getInstance(q);
1274
1275 qPos.add(userId);
1276
1277 if (type != null) {
1278 qPos.add(type);
1279 }
1280
1281 count = (Long)q.uniqueResult();
1282 }
1283 catch (Exception e) {
1284 throw processException(e);
1285 }
1286 finally {
1287 if (count == null) {
1288 count = Long.valueOf(0);
1289 }
1290
1291 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
1292 count);
1293
1294 closeSession(session);
1295 }
1296 }
1297
1298 return count.intValue();
1299 }
1300
1301
1307 public int countAll() throws SystemException {
1308 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1309 FINDER_ARGS_EMPTY, this);
1310
1311 if (count == null) {
1312 Session session = null;
1313
1314 try {
1315 session = openSession();
1316
1317 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
1318
1319 count = (Long)q.uniqueResult();
1320 }
1321 catch (Exception e) {
1322 throw processException(e);
1323 }
1324 finally {
1325 if (count == null) {
1326 count = Long.valueOf(0);
1327 }
1328
1329 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1330 FINDER_ARGS_EMPTY, count);
1331
1332 closeSession(session);
1333 }
1334 }
1335
1336 return count.intValue();
1337 }
1338
1339
1342 public void afterPropertiesSet() {
1343 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1344 com.liferay.portal.util.PropsUtil.get(
1345 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1346
1347 if (listenerClassNames.length > 0) {
1348 try {
1349 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1350
1351 for (String listenerClassName : listenerClassNames) {
1352 listenersList.add((ModelListener<AnnouncementsDelivery>)InstanceFactory.newInstance(
1353 listenerClassName));
1354 }
1355
1356 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1357 }
1358 catch (Exception e) {
1359 _log.error(e);
1360 }
1361 }
1362 }
1363
1364 public void destroy() {
1365 EntityCacheUtil.removeCache(AnnouncementsDeliveryImpl.class.getName());
1366 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1367 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1368 }
1369
1370 @BeanReference(type = AnnouncementsDeliveryPersistence.class)
1371 protected AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1372 @BeanReference(type = AnnouncementsEntryPersistence.class)
1373 protected AnnouncementsEntryPersistence announcementsEntryPersistence;
1374 @BeanReference(type = AnnouncementsFlagPersistence.class)
1375 protected AnnouncementsFlagPersistence announcementsFlagPersistence;
1376 @BeanReference(type = ResourcePersistence.class)
1377 protected ResourcePersistence resourcePersistence;
1378 @BeanReference(type = UserPersistence.class)
1379 protected UserPersistence userPersistence;
1380 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1381 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1382 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1383 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1384 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1385 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1386 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1387 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1388 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1389 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1390 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1391 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1392 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1393 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1394 private static AnnouncementsDelivery _nullAnnouncementsDelivery = new AnnouncementsDeliveryImpl() {
1395 @Override
1396 public Object clone() {
1397 return this;
1398 }
1399
1400 @Override
1401 public CacheModel<AnnouncementsDelivery> toCacheModel() {
1402 return _nullAnnouncementsDeliveryCacheModel;
1403 }
1404 };
1405
1406 private static CacheModel<AnnouncementsDelivery> _nullAnnouncementsDeliveryCacheModel =
1407 new CacheModel<AnnouncementsDelivery>() {
1408 public AnnouncementsDelivery toEntityModel() {
1409 return _nullAnnouncementsDelivery;
1410 }
1411 };
1412 }