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