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