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