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