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