1
14
15 package com.liferay.portlet.announcements.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
22 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
24 import com.liferay.portal.kernel.dao.orm.FinderPath;
25 import com.liferay.portal.kernel.dao.orm.Query;
26 import com.liferay.portal.kernel.dao.orm.QueryPos;
27 import com.liferay.portal.kernel.dao.orm.QueryUtil;
28 import com.liferay.portal.kernel.dao.orm.Session;
29 import com.liferay.portal.kernel.log.Log;
30 import com.liferay.portal.kernel.log.LogFactoryUtil;
31 import com.liferay.portal.kernel.util.GetterUtil;
32 import com.liferay.portal.kernel.util.OrderByComparator;
33 import com.liferay.portal.kernel.util.StringBundler;
34 import com.liferay.portal.kernel.util.StringPool;
35 import com.liferay.portal.kernel.util.StringUtil;
36 import com.liferay.portal.kernel.util.Validator;
37 import com.liferay.portal.model.ModelListener;
38 import com.liferay.portal.service.persistence.BatchSessionUtil;
39 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40
41 import com.liferay.portlet.announcements.NoSuchDeliveryException;
42 import com.liferay.portlet.announcements.model.AnnouncementsDelivery;
43 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryImpl;
44 import com.liferay.portlet.announcements.model.impl.AnnouncementsDeliveryModelImpl;
45
46 import java.io.Serializable;
47
48 import java.util.ArrayList;
49 import java.util.Collections;
50 import java.util.List;
51
52
65 public class AnnouncementsDeliveryPersistenceImpl extends BasePersistenceImpl<AnnouncementsDelivery>
66 implements AnnouncementsDeliveryPersistence {
67 public static final String FINDER_CLASS_NAME_ENTITY = AnnouncementsDeliveryImpl.class.getName();
68 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
69 ".List";
70 public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
71 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
72 FINDER_CLASS_NAME_LIST, "findByUserId",
73 new String[] { Long.class.getName() });
74 public static final FinderPath FINDER_PATH_FIND_BY_OBC_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
75 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
76 FINDER_CLASS_NAME_LIST, "findByUserId",
77 new String[] {
78 Long.class.getName(),
79
80 "java.lang.Integer", "java.lang.Integer",
81 "com.liferay.portal.kernel.util.OrderByComparator"
82 });
83 public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
84 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
85 FINDER_CLASS_NAME_LIST, "countByUserId",
86 new String[] { Long.class.getName() });
87 public static final FinderPath FINDER_PATH_FETCH_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
88 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
89 FINDER_CLASS_NAME_ENTITY, "fetchByU_T",
90 new String[] { Long.class.getName(), String.class.getName() });
91 public static final FinderPath FINDER_PATH_COUNT_BY_U_T = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
92 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
93 FINDER_CLASS_NAME_LIST, "countByU_T",
94 new String[] { Long.class.getName(), String.class.getName() });
95 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
96 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
97 FINDER_CLASS_NAME_LIST, "findAll", new String[0]);
98 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
99 AnnouncementsDeliveryModelImpl.FINDER_CACHE_ENABLED,
100 FINDER_CLASS_NAME_LIST, "countAll", new String[0]);
101
102 public void cacheResult(AnnouncementsDelivery announcementsDelivery) {
103 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
104 AnnouncementsDeliveryImpl.class,
105 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
106
107 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
108 new Object[] {
109 new Long(announcementsDelivery.getUserId()),
110
111 announcementsDelivery.getType()
112 }, announcementsDelivery);
113 }
114
115 public void cacheResult(List<AnnouncementsDelivery> announcementsDeliveries) {
116 for (AnnouncementsDelivery announcementsDelivery : announcementsDeliveries) {
117 if (EntityCacheUtil.getResult(
118 AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
119 AnnouncementsDeliveryImpl.class,
120 announcementsDelivery.getPrimaryKey(), this) == null) {
121 cacheResult(announcementsDelivery);
122 }
123 }
124 }
125
126 public void clearCache() {
127 CacheRegistry.clear(AnnouncementsDeliveryImpl.class.getName());
128 EntityCacheUtil.clearCache(AnnouncementsDeliveryImpl.class.getName());
129 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
130 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
131 }
132
133 public AnnouncementsDelivery create(long deliveryId) {
134 AnnouncementsDelivery announcementsDelivery = new AnnouncementsDeliveryImpl();
135
136 announcementsDelivery.setNew(true);
137 announcementsDelivery.setPrimaryKey(deliveryId);
138
139 return announcementsDelivery;
140 }
141
142 public AnnouncementsDelivery remove(Serializable primaryKey)
143 throws NoSuchModelException, SystemException {
144 return remove(((Long)primaryKey).longValue());
145 }
146
147 public AnnouncementsDelivery remove(long deliveryId)
148 throws NoSuchDeliveryException, SystemException {
149 Session session = null;
150
151 try {
152 session = openSession();
153
154 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
155 new Long(deliveryId));
156
157 if (announcementsDelivery == null) {
158 if (_log.isWarnEnabled()) {
159 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
160 }
161
162 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
163 deliveryId);
164 }
165
166 return remove(announcementsDelivery);
167 }
168 catch (NoSuchDeliveryException nsee) {
169 throw nsee;
170 }
171 catch (Exception e) {
172 throw processException(e);
173 }
174 finally {
175 closeSession(session);
176 }
177 }
178
179 public AnnouncementsDelivery remove(
180 AnnouncementsDelivery announcementsDelivery) throws SystemException {
181 for (ModelListener<AnnouncementsDelivery> listener : listeners) {
182 listener.onBeforeRemove(announcementsDelivery);
183 }
184
185 announcementsDelivery = removeImpl(announcementsDelivery);
186
187 for (ModelListener<AnnouncementsDelivery> listener : listeners) {
188 listener.onAfterRemove(announcementsDelivery);
189 }
190
191 return announcementsDelivery;
192 }
193
194 protected AnnouncementsDelivery removeImpl(
195 AnnouncementsDelivery announcementsDelivery) throws SystemException {
196 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
197
198 Session session = null;
199
200 try {
201 session = openSession();
202
203 if (announcementsDelivery.isCachedModel() ||
204 BatchSessionUtil.isEnabled()) {
205 Object staleObject = session.get(AnnouncementsDeliveryImpl.class,
206 announcementsDelivery.getPrimaryKeyObj());
207
208 if (staleObject != null) {
209 session.evict(staleObject);
210 }
211 }
212
213 session.delete(announcementsDelivery);
214
215 session.flush();
216 }
217 catch (Exception e) {
218 throw processException(e);
219 }
220 finally {
221 closeSession(session);
222 }
223
224 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
225
226 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
227
228 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
229 new Object[] {
230 new Long(announcementsDeliveryModelImpl.getOriginalUserId()),
231
232 announcementsDeliveryModelImpl.getOriginalType()
233 });
234
235 EntityCacheUtil.removeResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
236 AnnouncementsDeliveryImpl.class,
237 announcementsDelivery.getPrimaryKey());
238
239 return announcementsDelivery;
240 }
241
242
245 public AnnouncementsDelivery update(
246 AnnouncementsDelivery announcementsDelivery) throws SystemException {
247 if (_log.isWarnEnabled()) {
248 _log.warn(
249 "Using the deprecated update(AnnouncementsDelivery announcementsDelivery) method. Use update(AnnouncementsDelivery announcementsDelivery, boolean merge) instead.");
250 }
251
252 return update(announcementsDelivery, false);
253 }
254
255 public AnnouncementsDelivery updateImpl(
256 com.liferay.portlet.announcements.model.AnnouncementsDelivery announcementsDelivery,
257 boolean merge) throws SystemException {
258 announcementsDelivery = toUnwrappedModel(announcementsDelivery);
259
260 boolean isNew = announcementsDelivery.isNew();
261
262 AnnouncementsDeliveryModelImpl announcementsDeliveryModelImpl = (AnnouncementsDeliveryModelImpl)announcementsDelivery;
263
264 Session session = null;
265
266 try {
267 session = openSession();
268
269 BatchSessionUtil.update(session, announcementsDelivery, merge);
270
271 announcementsDelivery.setNew(false);
272 }
273 catch (Exception e) {
274 throw processException(e);
275 }
276 finally {
277 closeSession(session);
278 }
279
280 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
281
282 EntityCacheUtil.putResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
283 AnnouncementsDeliveryImpl.class,
284 announcementsDelivery.getPrimaryKey(), announcementsDelivery);
285
286 if (!isNew &&
287 ((announcementsDelivery.getUserId() != announcementsDeliveryModelImpl.getOriginalUserId()) ||
288 !Validator.equals(announcementsDelivery.getType(),
289 announcementsDeliveryModelImpl.getOriginalType()))) {
290 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_T,
291 new Object[] {
292 new Long(announcementsDeliveryModelImpl.getOriginalUserId()),
293
294 announcementsDeliveryModelImpl.getOriginalType()
295 });
296 }
297
298 if (isNew ||
299 ((announcementsDelivery.getUserId() != announcementsDeliveryModelImpl.getOriginalUserId()) ||
300 !Validator.equals(announcementsDelivery.getType(),
301 announcementsDeliveryModelImpl.getOriginalType()))) {
302 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
303 new Object[] {
304 new Long(announcementsDelivery.getUserId()),
305
306 announcementsDelivery.getType()
307 }, announcementsDelivery);
308 }
309
310 return announcementsDelivery;
311 }
312
313 protected AnnouncementsDelivery toUnwrappedModel(
314 AnnouncementsDelivery announcementsDelivery) {
315 if (announcementsDelivery instanceof AnnouncementsDeliveryImpl) {
316 return announcementsDelivery;
317 }
318
319 AnnouncementsDeliveryImpl announcementsDeliveryImpl = new AnnouncementsDeliveryImpl();
320
321 announcementsDeliveryImpl.setNew(announcementsDelivery.isNew());
322 announcementsDeliveryImpl.setPrimaryKey(announcementsDelivery.getPrimaryKey());
323
324 announcementsDeliveryImpl.setDeliveryId(announcementsDelivery.getDeliveryId());
325 announcementsDeliveryImpl.setCompanyId(announcementsDelivery.getCompanyId());
326 announcementsDeliveryImpl.setUserId(announcementsDelivery.getUserId());
327 announcementsDeliveryImpl.setType(announcementsDelivery.getType());
328 announcementsDeliveryImpl.setEmail(announcementsDelivery.isEmail());
329 announcementsDeliveryImpl.setSms(announcementsDelivery.isSms());
330 announcementsDeliveryImpl.setWebsite(announcementsDelivery.isWebsite());
331
332 return announcementsDeliveryImpl;
333 }
334
335 public AnnouncementsDelivery findByPrimaryKey(Serializable primaryKey)
336 throws NoSuchModelException, SystemException {
337 return findByPrimaryKey(((Long)primaryKey).longValue());
338 }
339
340 public AnnouncementsDelivery findByPrimaryKey(long deliveryId)
341 throws NoSuchDeliveryException, SystemException {
342 AnnouncementsDelivery announcementsDelivery = fetchByPrimaryKey(deliveryId);
343
344 if (announcementsDelivery == null) {
345 if (_log.isWarnEnabled()) {
346 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + deliveryId);
347 }
348
349 throw new NoSuchDeliveryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
350 deliveryId);
351 }
352
353 return announcementsDelivery;
354 }
355
356 public AnnouncementsDelivery fetchByPrimaryKey(Serializable primaryKey)
357 throws SystemException {
358 return fetchByPrimaryKey(((Long)primaryKey).longValue());
359 }
360
361 public AnnouncementsDelivery fetchByPrimaryKey(long deliveryId)
362 throws SystemException {
363 AnnouncementsDelivery announcementsDelivery = (AnnouncementsDelivery)EntityCacheUtil.getResult(AnnouncementsDeliveryModelImpl.ENTITY_CACHE_ENABLED,
364 AnnouncementsDeliveryImpl.class, deliveryId, this);
365
366 if (announcementsDelivery == null) {
367 Session session = null;
368
369 try {
370 session = openSession();
371
372 announcementsDelivery = (AnnouncementsDelivery)session.get(AnnouncementsDeliveryImpl.class,
373 new Long(deliveryId));
374 }
375 catch (Exception e) {
376 throw processException(e);
377 }
378 finally {
379 if (announcementsDelivery != null) {
380 cacheResult(announcementsDelivery);
381 }
382
383 closeSession(session);
384 }
385 }
386
387 return announcementsDelivery;
388 }
389
390 public List<AnnouncementsDelivery> findByUserId(long userId)
391 throws SystemException {
392 Object[] finderArgs = new Object[] { new Long(userId) };
393
394 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
395 finderArgs, this);
396
397 if (list == null) {
398 Session session = null;
399
400 try {
401 session = openSession();
402
403 StringBundler query = new StringBundler(2);
404
405 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
406
407 query.append(_FINDER_COLUMN_USERID_USERID_2);
408
409 String sql = query.toString();
410
411 Query q = session.createQuery(sql);
412
413 QueryPos qPos = QueryPos.getInstance(q);
414
415 qPos.add(userId);
416
417 list = q.list();
418 }
419 catch (Exception e) {
420 throw processException(e);
421 }
422 finally {
423 if (list == null) {
424 list = new ArrayList<AnnouncementsDelivery>();
425 }
426
427 cacheResult(list);
428
429 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
430 finderArgs, list);
431
432 closeSession(session);
433 }
434 }
435
436 return list;
437 }
438
439 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
440 int end) throws SystemException {
441 return findByUserId(userId, start, end, null);
442 }
443
444 public List<AnnouncementsDelivery> findByUserId(long userId, int start,
445 int end, OrderByComparator obc) throws SystemException {
446 Object[] finderArgs = new Object[] {
447 new Long(userId),
448
449 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
450 };
451
452 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_USERID,
453 finderArgs, this);
454
455 if (list == null) {
456 Session session = null;
457
458 try {
459 session = openSession();
460
461 StringBundler query = null;
462
463 if (obc != null) {
464 query = new StringBundler(3 +
465 (obc.getOrderByFields().length * 3));
466 }
467 else {
468 query = new StringBundler(2);
469 }
470
471 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
472
473 query.append(_FINDER_COLUMN_USERID_USERID_2);
474
475 if (obc != null) {
476 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
477 }
478
479 String sql = query.toString();
480
481 Query q = session.createQuery(sql);
482
483 QueryPos qPos = QueryPos.getInstance(q);
484
485 qPos.add(userId);
486
487 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
488 getDialect(), start, end);
489 }
490 catch (Exception e) {
491 throw processException(e);
492 }
493 finally {
494 if (list == null) {
495 list = new ArrayList<AnnouncementsDelivery>();
496 }
497
498 cacheResult(list);
499
500 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_USERID,
501 finderArgs, list);
502
503 closeSession(session);
504 }
505 }
506
507 return list;
508 }
509
510 public AnnouncementsDelivery findByUserId_First(long userId,
511 OrderByComparator obc) throws NoSuchDeliveryException, SystemException {
512 List<AnnouncementsDelivery> list = findByUserId(userId, 0, 1, obc);
513
514 if (list.isEmpty()) {
515 StringBundler msg = new StringBundler(4);
516
517 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
518
519 msg.append("userId=");
520 msg.append(userId);
521
522 msg.append(StringPool.CLOSE_CURLY_BRACE);
523
524 throw new NoSuchDeliveryException(msg.toString());
525 }
526 else {
527 return list.get(0);
528 }
529 }
530
531 public AnnouncementsDelivery findByUserId_Last(long userId,
532 OrderByComparator obc) throws NoSuchDeliveryException, SystemException {
533 int count = countByUserId(userId);
534
535 List<AnnouncementsDelivery> list = findByUserId(userId, count - 1,
536 count, obc);
537
538 if (list.isEmpty()) {
539 StringBundler msg = new StringBundler(4);
540
541 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
542
543 msg.append("userId=");
544 msg.append(userId);
545
546 msg.append(StringPool.CLOSE_CURLY_BRACE);
547
548 throw new NoSuchDeliveryException(msg.toString());
549 }
550 else {
551 return list.get(0);
552 }
553 }
554
555 public AnnouncementsDelivery[] findByUserId_PrevAndNext(long deliveryId,
556 long userId, OrderByComparator obc)
557 throws NoSuchDeliveryException, SystemException {
558 AnnouncementsDelivery announcementsDelivery = findByPrimaryKey(deliveryId);
559
560 int count = countByUserId(userId);
561
562 Session session = null;
563
564 try {
565 session = openSession();
566
567 StringBundler query = null;
568
569 if (obc != null) {
570 query = new StringBundler(3 +
571 (obc.getOrderByFields().length * 3));
572 }
573 else {
574 query = new StringBundler(2);
575 }
576
577 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
578
579 query.append(_FINDER_COLUMN_USERID_USERID_2);
580
581 if (obc != null) {
582 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
583 }
584
585 String sql = query.toString();
586
587 Query q = session.createQuery(sql);
588
589 QueryPos qPos = QueryPos.getInstance(q);
590
591 qPos.add(userId);
592
593 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
594 announcementsDelivery);
595
596 AnnouncementsDelivery[] array = new AnnouncementsDeliveryImpl[3];
597
598 array[0] = (AnnouncementsDelivery)objArray[0];
599 array[1] = (AnnouncementsDelivery)objArray[1];
600 array[2] = (AnnouncementsDelivery)objArray[2];
601
602 return array;
603 }
604 catch (Exception e) {
605 throw processException(e);
606 }
607 finally {
608 closeSession(session);
609 }
610 }
611
612 public AnnouncementsDelivery findByU_T(long userId, String type)
613 throws NoSuchDeliveryException, SystemException {
614 AnnouncementsDelivery announcementsDelivery = fetchByU_T(userId, type);
615
616 if (announcementsDelivery == null) {
617 StringBundler msg = new StringBundler(6);
618
619 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
620
621 msg.append("userId=");
622 msg.append(userId);
623
624 msg.append(", type=");
625 msg.append(type);
626
627 msg.append(StringPool.CLOSE_CURLY_BRACE);
628
629 if (_log.isWarnEnabled()) {
630 _log.warn(msg.toString());
631 }
632
633 throw new NoSuchDeliveryException(msg.toString());
634 }
635
636 return announcementsDelivery;
637 }
638
639 public AnnouncementsDelivery fetchByU_T(long userId, String type)
640 throws SystemException {
641 return fetchByU_T(userId, type, true);
642 }
643
644 public AnnouncementsDelivery fetchByU_T(long userId, String type,
645 boolean retrieveFromCache) throws SystemException {
646 Object[] finderArgs = new Object[] { new Long(userId), type };
647
648 Object result = null;
649
650 if (retrieveFromCache) {
651 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_T,
652 finderArgs, this);
653 }
654
655 if (result == null) {
656 Session session = null;
657
658 try {
659 session = openSession();
660
661 StringBundler query = new StringBundler(3);
662
663 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE);
664
665 query.append(_FINDER_COLUMN_U_T_USERID_2);
666
667 if (type == null) {
668 query.append(_FINDER_COLUMN_U_T_TYPE_1);
669 }
670 else {
671 if (type.equals(StringPool.BLANK)) {
672 query.append(_FINDER_COLUMN_U_T_TYPE_3);
673 }
674 else {
675 query.append(_FINDER_COLUMN_U_T_TYPE_2);
676 }
677 }
678
679 String sql = query.toString();
680
681 Query q = session.createQuery(sql);
682
683 QueryPos qPos = QueryPos.getInstance(q);
684
685 qPos.add(userId);
686
687 if (type != null) {
688 qPos.add(type);
689 }
690
691 List<AnnouncementsDelivery> list = q.list();
692
693 result = list;
694
695 AnnouncementsDelivery announcementsDelivery = null;
696
697 if (list.isEmpty()) {
698 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
699 finderArgs, list);
700 }
701 else {
702 announcementsDelivery = list.get(0);
703
704 cacheResult(announcementsDelivery);
705
706 if ((announcementsDelivery.getUserId() != userId) ||
707 (announcementsDelivery.getType() == null) ||
708 !announcementsDelivery.getType().equals(type)) {
709 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
710 finderArgs, announcementsDelivery);
711 }
712 }
713
714 return announcementsDelivery;
715 }
716 catch (Exception e) {
717 throw processException(e);
718 }
719 finally {
720 if (result == null) {
721 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_T,
722 finderArgs, new ArrayList<AnnouncementsDelivery>());
723 }
724
725 closeSession(session);
726 }
727 }
728 else {
729 if (result instanceof List<?>) {
730 return null;
731 }
732 else {
733 return (AnnouncementsDelivery)result;
734 }
735 }
736 }
737
738 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
739 throws SystemException {
740 Session session = null;
741
742 try {
743 session = openSession();
744
745 dynamicQuery.compile(session);
746
747 return dynamicQuery.list();
748 }
749 catch (Exception e) {
750 throw processException(e);
751 }
752 finally {
753 closeSession(session);
754 }
755 }
756
757 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
758 int start, int end) throws SystemException {
759 Session session = null;
760
761 try {
762 session = openSession();
763
764 dynamicQuery.setLimit(start, end);
765
766 dynamicQuery.compile(session);
767
768 return dynamicQuery.list();
769 }
770 catch (Exception e) {
771 throw processException(e);
772 }
773 finally {
774 closeSession(session);
775 }
776 }
777
778 public List<AnnouncementsDelivery> findAll() throws SystemException {
779 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
780 }
781
782 public List<AnnouncementsDelivery> findAll(int start, int end)
783 throws SystemException {
784 return findAll(start, end, null);
785 }
786
787 public List<AnnouncementsDelivery> findAll(int start, int end,
788 OrderByComparator obc) throws SystemException {
789 Object[] finderArgs = new Object[] {
790 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
791 };
792
793 List<AnnouncementsDelivery> list = (List<AnnouncementsDelivery>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
794 finderArgs, this);
795
796 if (list == null) {
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 StringBundler query = null;
803 String sql = null;
804
805 if (obc != null) {
806 query = new StringBundler(2 +
807 (obc.getOrderByFields().length * 3));
808
809 query.append(_SQL_SELECT_ANNOUNCEMENTSDELIVERY);
810
811 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, obc);
812
813 sql = query.toString();
814 }
815
816 sql = _SQL_SELECT_ANNOUNCEMENTSDELIVERY;
817
818 Query q = session.createQuery(sql);
819
820 if (obc == null) {
821 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
822 getDialect(), start, end, false);
823
824 Collections.sort(list);
825 }
826 else {
827 list = (List<AnnouncementsDelivery>)QueryUtil.list(q,
828 getDialect(), start, end);
829 }
830 }
831 catch (Exception e) {
832 throw processException(e);
833 }
834 finally {
835 if (list == null) {
836 list = new ArrayList<AnnouncementsDelivery>();
837 }
838
839 cacheResult(list);
840
841 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
842
843 closeSession(session);
844 }
845 }
846
847 return list;
848 }
849
850 public void removeByUserId(long userId) throws SystemException {
851 for (AnnouncementsDelivery announcementsDelivery : findByUserId(userId)) {
852 remove(announcementsDelivery);
853 }
854 }
855
856 public void removeByU_T(long userId, String type)
857 throws NoSuchDeliveryException, SystemException {
858 AnnouncementsDelivery announcementsDelivery = findByU_T(userId, type);
859
860 remove(announcementsDelivery);
861 }
862
863 public void removeAll() throws SystemException {
864 for (AnnouncementsDelivery announcementsDelivery : findAll()) {
865 remove(announcementsDelivery);
866 }
867 }
868
869 public int countByUserId(long userId) throws SystemException {
870 Object[] finderArgs = new Object[] { new Long(userId) };
871
872 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
873 finderArgs, this);
874
875 if (count == null) {
876 Session session = null;
877
878 try {
879 session = openSession();
880
881 StringBundler query = new StringBundler(2);
882
883 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
884
885 query.append(_FINDER_COLUMN_USERID_USERID_2);
886
887 String sql = query.toString();
888
889 Query q = session.createQuery(sql);
890
891 QueryPos qPos = QueryPos.getInstance(q);
892
893 qPos.add(userId);
894
895 count = (Long)q.uniqueResult();
896 }
897 catch (Exception e) {
898 throw processException(e);
899 }
900 finally {
901 if (count == null) {
902 count = Long.valueOf(0);
903 }
904
905 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
906 finderArgs, count);
907
908 closeSession(session);
909 }
910 }
911
912 return count.intValue();
913 }
914
915 public int countByU_T(long userId, String type) throws SystemException {
916 Object[] finderArgs = new Object[] { new Long(userId), type };
917
918 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_T,
919 finderArgs, this);
920
921 if (count == null) {
922 Session session = null;
923
924 try {
925 session = openSession();
926
927 StringBundler query = new StringBundler(3);
928
929 query.append(_SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE);
930
931 query.append(_FINDER_COLUMN_U_T_USERID_2);
932
933 if (type == null) {
934 query.append(_FINDER_COLUMN_U_T_TYPE_1);
935 }
936 else {
937 if (type.equals(StringPool.BLANK)) {
938 query.append(_FINDER_COLUMN_U_T_TYPE_3);
939 }
940 else {
941 query.append(_FINDER_COLUMN_U_T_TYPE_2);
942 }
943 }
944
945 String sql = query.toString();
946
947 Query q = session.createQuery(sql);
948
949 QueryPos qPos = QueryPos.getInstance(q);
950
951 qPos.add(userId);
952
953 if (type != null) {
954 qPos.add(type);
955 }
956
957 count = (Long)q.uniqueResult();
958 }
959 catch (Exception e) {
960 throw processException(e);
961 }
962 finally {
963 if (count == null) {
964 count = Long.valueOf(0);
965 }
966
967 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_T, finderArgs,
968 count);
969
970 closeSession(session);
971 }
972 }
973
974 return count.intValue();
975 }
976
977 public int countAll() throws SystemException {
978 Object[] finderArgs = new Object[0];
979
980 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
981 finderArgs, this);
982
983 if (count == null) {
984 Session session = null;
985
986 try {
987 session = openSession();
988
989 Query q = session.createQuery(_SQL_COUNT_ANNOUNCEMENTSDELIVERY);
990
991 count = (Long)q.uniqueResult();
992 }
993 catch (Exception e) {
994 throw processException(e);
995 }
996 finally {
997 if (count == null) {
998 count = Long.valueOf(0);
999 }
1000
1001 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1002 count);
1003
1004 closeSession(session);
1005 }
1006 }
1007
1008 return count.intValue();
1009 }
1010
1011 public void afterPropertiesSet() {
1012 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1013 com.liferay.portal.util.PropsUtil.get(
1014 "value.object.listener.com.liferay.portlet.announcements.model.AnnouncementsDelivery")));
1015
1016 if (listenerClassNames.length > 0) {
1017 try {
1018 List<ModelListener<AnnouncementsDelivery>> listenersList = new ArrayList<ModelListener<AnnouncementsDelivery>>();
1019
1020 for (String listenerClassName : listenerClassNames) {
1021 listenersList.add((ModelListener<AnnouncementsDelivery>)Class.forName(
1022 listenerClassName).newInstance());
1023 }
1024
1025 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1026 }
1027 catch (Exception e) {
1028 _log.error(e);
1029 }
1030 }
1031 }
1032
1033 @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence")
1034 protected com.liferay.portlet.announcements.service.persistence.AnnouncementsDeliveryPersistence announcementsDeliveryPersistence;
1035 @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsEntryPersistence")
1036 protected com.liferay.portlet.announcements.service.persistence.AnnouncementsEntryPersistence announcementsEntryPersistence;
1037 @BeanReference(name = "com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence")
1038 protected com.liferay.portlet.announcements.service.persistence.AnnouncementsFlagPersistence announcementsFlagPersistence;
1039 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence")
1040 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
1041 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence")
1042 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1043 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery";
1044 private static final String _SQL_SELECT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT announcementsDelivery FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1045 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery";
1046 private static final String _SQL_COUNT_ANNOUNCEMENTSDELIVERY_WHERE = "SELECT COUNT(announcementsDelivery) FROM AnnouncementsDelivery announcementsDelivery WHERE ";
1047 private static final String _FINDER_COLUMN_USERID_USERID_2 = "announcementsDelivery.userId = ?";
1048 private static final String _FINDER_COLUMN_U_T_USERID_2 = "announcementsDelivery.userId = ? AND ";
1049 private static final String _FINDER_COLUMN_U_T_TYPE_1 = "announcementsDelivery.type IS NULL";
1050 private static final String _FINDER_COLUMN_U_T_TYPE_2 = "announcementsDelivery.type = ?";
1051 private static final String _FINDER_COLUMN_U_T_TYPE_3 = "(announcementsDelivery.type IS NULL OR announcementsDelivery.type = ?)";
1052 private static final String _ORDER_BY_ENTITY_ALIAS = "announcementsDelivery.";
1053 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No AnnouncementsDelivery exists with the primary key ";
1054 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No AnnouncementsDelivery exists with the key {";
1055 private static Log _log = LogFactoryUtil.getLog(AnnouncementsDeliveryPersistenceImpl.class);
1056}