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