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