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