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