1   /**
2    * Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.annotation.BeanReference;
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.log.Log;
34  import com.liferay.portal.kernel.log.LogFactoryUtil;
35  import com.liferay.portal.kernel.util.GetterUtil;
36  import com.liferay.portal.kernel.util.OrderByComparator;
37  import com.liferay.portal.kernel.util.StringPool;
38  import com.liferay.portal.kernel.util.StringUtil;
39  import com.liferay.portal.model.ModelListener;
40  import com.liferay.portal.service.persistence.BatchSessionUtil;
41  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
42  
43  import com.liferay.portlet.journal.NoSuchArticleResourceException;
44  import com.liferay.portlet.journal.model.JournalArticleResource;
45  import com.liferay.portlet.journal.model.impl.JournalArticleResourceImpl;
46  import com.liferay.portlet.journal.model.impl.JournalArticleResourceModelImpl;
47  
48  import java.util.ArrayList;
49  import java.util.Collections;
50  import java.util.Iterator;
51  import java.util.List;
52  
53  /**
54   * <a href="JournalArticleResourcePersistenceImpl.java.html"><b><i>View Source</i></b></a>
55   *
56   * @author Brian Wing Shun Chan
57   *
58   */
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         for (ModelListener listener : listeners) {
109             listener.onBeforeRemove(journalArticleResource);
110         }
111 
112         journalArticleResource = removeImpl(journalArticleResource);
113 
114         for (ModelListener listener : listeners) {
115             listener.onAfterRemove(journalArticleResource);
116         }
117 
118         return journalArticleResource;
119     }
120 
121     protected JournalArticleResource removeImpl(
122         JournalArticleResource journalArticleResource)
123         throws SystemException {
124         Session session = null;
125 
126         try {
127             session = openSession();
128 
129             if (BatchSessionUtil.isEnabled()) {
130                 Object staleObject = session.get(JournalArticleResourceImpl.class,
131                         journalArticleResource.getPrimaryKeyObj());
132 
133                 if (staleObject != null) {
134                     session.evict(staleObject);
135                 }
136             }
137 
138             session.delete(journalArticleResource);
139 
140             session.flush();
141 
142             return journalArticleResource;
143         }
144         catch (Exception e) {
145             throw processException(e);
146         }
147         finally {
148             closeSession(session);
149 
150             FinderCacheUtil.clearCache(JournalArticleResource.class.getName());
151         }
152     }
153 
154     /**
155      * @deprecated Use <code>update(JournalArticleResource journalArticleResource, boolean merge)</code>.
156      */
157     public JournalArticleResource update(
158         JournalArticleResource journalArticleResource)
159         throws SystemException {
160         if (_log.isWarnEnabled()) {
161             _log.warn(
162                 "Using the deprecated update(JournalArticleResource journalArticleResource) method. Use update(JournalArticleResource journalArticleResource, boolean merge) instead.");
163         }
164 
165         return update(journalArticleResource, false);
166     }
167 
168     /**
169      * Add, update, or merge, the entity. This method also calls the model
170      * listeners to trigger the proper events associated with adding, deleting,
171      * or updating an entity.
172      *
173      * @param        journalArticleResource the entity to add, update, or merge
174      * @param        merge boolean value for whether to merge the entity. The
175      *                default value is false. Setting merge to true is more
176      *                expensive and should only be true when journalArticleResource is
177      *                transient. See LEP-5473 for a detailed discussion of this
178      *                method.
179      * @return        true if the portlet can be displayed via Ajax
180      */
181     public JournalArticleResource update(
182         JournalArticleResource journalArticleResource, boolean merge)
183         throws SystemException {
184         boolean isNew = journalArticleResource.isNew();
185 
186         for (ModelListener listener : listeners) {
187             if (isNew) {
188                 listener.onBeforeCreate(journalArticleResource);
189             }
190             else {
191                 listener.onBeforeUpdate(journalArticleResource);
192             }
193         }
194 
195         journalArticleResource = updateImpl(journalArticleResource, merge);
196 
197         for (ModelListener listener : listeners) {
198             if (isNew) {
199                 listener.onAfterCreate(journalArticleResource);
200             }
201             else {
202                 listener.onAfterUpdate(journalArticleResource);
203             }
204         }
205 
206         return journalArticleResource;
207     }
208 
209     public JournalArticleResource updateImpl(
210         com.liferay.portlet.journal.model.JournalArticleResource journalArticleResource,
211         boolean merge) throws SystemException {
212         Session session = null;
213 
214         try {
215             session = openSession();
216 
217             BatchSessionUtil.update(session, journalArticleResource, merge);
218 
219             journalArticleResource.setNew(false);
220 
221             return journalArticleResource;
222         }
223         catch (Exception e) {
224             throw processException(e);
225         }
226         finally {
227             closeSession(session);
228 
229             FinderCacheUtil.clearCache(JournalArticleResource.class.getName());
230         }
231     }
232 
233     public JournalArticleResource findByPrimaryKey(long resourcePrimKey)
234         throws NoSuchArticleResourceException, SystemException {
235         JournalArticleResource journalArticleResource = fetchByPrimaryKey(resourcePrimKey);
236 
237         if (journalArticleResource == null) {
238             if (_log.isWarnEnabled()) {
239                 _log.warn(
240                     "No JournalArticleResource exists with the primary key " +
241                     resourcePrimKey);
242             }
243 
244             throw new NoSuchArticleResourceException(
245                 "No JournalArticleResource exists with the primary key " +
246                 resourcePrimKey);
247         }
248 
249         return journalArticleResource;
250     }
251 
252     public JournalArticleResource fetchByPrimaryKey(long resourcePrimKey)
253         throws SystemException {
254         Session session = null;
255 
256         try {
257             session = openSession();
258 
259             return (JournalArticleResource)session.get(JournalArticleResourceImpl.class,
260                 new Long(resourcePrimKey));
261         }
262         catch (Exception e) {
263             throw processException(e);
264         }
265         finally {
266             closeSession(session);
267         }
268     }
269 
270     public List<JournalArticleResource> findByGroupId(long groupId)
271         throws SystemException {
272         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
273         String finderClassName = JournalArticleResource.class.getName();
274         String finderMethodName = "findByGroupId";
275         String[] finderParams = new String[] { Long.class.getName() };
276         Object[] finderArgs = new Object[] { new Long(groupId) };
277 
278         Object result = null;
279 
280         if (finderClassNameCacheEnabled) {
281             result = FinderCacheUtil.getResult(finderClassName,
282                     finderMethodName, finderParams, finderArgs, this);
283         }
284 
285         if (result == null) {
286             Session session = null;
287 
288             try {
289                 session = openSession();
290 
291                 StringBuilder query = new StringBuilder();
292 
293                 query.append(
294                     "FROM com.liferay.portlet.journal.model.JournalArticleResource WHERE ");
295 
296                 query.append("groupId = ?");
297 
298                 query.append(" ");
299 
300                 Query q = session.createQuery(query.toString());
301 
302                 QueryPos qPos = QueryPos.getInstance(q);
303 
304                 qPos.add(groupId);
305 
306                 List<JournalArticleResource> list = q.list();
307 
308                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
309                     finderClassName, finderMethodName, finderParams,
310                     finderArgs, list);
311 
312                 return list;
313             }
314             catch (Exception e) {
315                 throw processException(e);
316             }
317             finally {
318                 closeSession(session);
319             }
320         }
321         else {
322             return (List<JournalArticleResource>)result;
323         }
324     }
325 
326     public List<JournalArticleResource> findByGroupId(long groupId, int start,
327         int end) throws SystemException {
328         return findByGroupId(groupId, start, end, null);
329     }
330 
331     public List<JournalArticleResource> findByGroupId(long groupId, int start,
332         int end, OrderByComparator obc) throws SystemException {
333         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
334         String finderClassName = JournalArticleResource.class.getName();
335         String finderMethodName = "findByGroupId";
336         String[] finderParams = new String[] {
337                 Long.class.getName(),
338                 
339                 "java.lang.Integer", "java.lang.Integer",
340                 "com.liferay.portal.kernel.util.OrderByComparator"
341             };
342         Object[] finderArgs = new Object[] {
343                 new Long(groupId),
344                 
345                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
346             };
347 
348         Object result = null;
349 
350         if (finderClassNameCacheEnabled) {
351             result = FinderCacheUtil.getResult(finderClassName,
352                     finderMethodName, finderParams, finderArgs, this);
353         }
354 
355         if (result == null) {
356             Session session = null;
357 
358             try {
359                 session = openSession();
360 
361                 StringBuilder query = new StringBuilder();
362 
363                 query.append(
364                     "FROM com.liferay.portlet.journal.model.JournalArticleResource WHERE ");
365 
366                 query.append("groupId = ?");
367 
368                 query.append(" ");
369 
370                 if (obc != null) {
371                     query.append("ORDER BY ");
372                     query.append(obc.getOrderBy());
373                 }
374 
375                 Query q = session.createQuery(query.toString());
376 
377                 QueryPos qPos = QueryPos.getInstance(q);
378 
379                 qPos.add(groupId);
380 
381                 List<JournalArticleResource> list = (List<JournalArticleResource>)QueryUtil.list(q,
382                         getDialect(), start, end);
383 
384                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
385                     finderClassName, finderMethodName, finderParams,
386                     finderArgs, list);
387 
388                 return list;
389             }
390             catch (Exception e) {
391                 throw processException(e);
392             }
393             finally {
394                 closeSession(session);
395             }
396         }
397         else {
398             return (List<JournalArticleResource>)result;
399         }
400     }
401 
402     public JournalArticleResource findByGroupId_First(long groupId,
403         OrderByComparator obc)
404         throws NoSuchArticleResourceException, SystemException {
405         List<JournalArticleResource> list = findByGroupId(groupId, 0, 1, obc);
406 
407         if (list.size() == 0) {
408             StringBuilder msg = new StringBuilder();
409 
410             msg.append("No JournalArticleResource exists with the key {");
411 
412             msg.append("groupId=" + groupId);
413 
414             msg.append(StringPool.CLOSE_CURLY_BRACE);
415 
416             throw new NoSuchArticleResourceException(msg.toString());
417         }
418         else {
419             return list.get(0);
420         }
421     }
422 
423     public JournalArticleResource findByGroupId_Last(long groupId,
424         OrderByComparator obc)
425         throws NoSuchArticleResourceException, SystemException {
426         int count = countByGroupId(groupId);
427 
428         List<JournalArticleResource> list = findByGroupId(groupId, count - 1,
429                 count, obc);
430 
431         if (list.size() == 0) {
432             StringBuilder msg = new StringBuilder();
433 
434             msg.append("No JournalArticleResource exists with the key {");
435 
436             msg.append("groupId=" + groupId);
437 
438             msg.append(StringPool.CLOSE_CURLY_BRACE);
439 
440             throw new NoSuchArticleResourceException(msg.toString());
441         }
442         else {
443             return list.get(0);
444         }
445     }
446 
447     public JournalArticleResource[] findByGroupId_PrevAndNext(
448         long resourcePrimKey, long groupId, OrderByComparator obc)
449         throws NoSuchArticleResourceException, SystemException {
450         JournalArticleResource journalArticleResource = findByPrimaryKey(resourcePrimKey);
451 
452         int count = countByGroupId(groupId);
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.journal.model.JournalArticleResource WHERE ");
463 
464             query.append("groupId = ?");
465 
466             query.append(" ");
467 
468             if (obc != null) {
469                 query.append("ORDER BY ");
470                 query.append(obc.getOrderBy());
471             }
472 
473             Query q = session.createQuery(query.toString());
474 
475             QueryPos qPos = QueryPos.getInstance(q);
476 
477             qPos.add(groupId);
478 
479             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
480                     journalArticleResource);
481 
482             JournalArticleResource[] array = new JournalArticleResourceImpl[3];
483 
484             array[0] = (JournalArticleResource)objArray[0];
485             array[1] = (JournalArticleResource)objArray[1];
486             array[2] = (JournalArticleResource)objArray[2];
487 
488             return array;
489         }
490         catch (Exception e) {
491             throw processException(e);
492         }
493         finally {
494             closeSession(session);
495         }
496     }
497 
498     public JournalArticleResource findByG_A(long groupId, String articleId)
499         throws NoSuchArticleResourceException, SystemException {
500         JournalArticleResource journalArticleResource = fetchByG_A(groupId,
501                 articleId);
502 
503         if (journalArticleResource == null) {
504             StringBuilder msg = new StringBuilder();
505 
506             msg.append("No JournalArticleResource exists with the key {");
507 
508             msg.append("groupId=" + groupId);
509 
510             msg.append(", ");
511             msg.append("articleId=" + articleId);
512 
513             msg.append(StringPool.CLOSE_CURLY_BRACE);
514 
515             if (_log.isWarnEnabled()) {
516                 _log.warn(msg.toString());
517             }
518 
519             throw new NoSuchArticleResourceException(msg.toString());
520         }
521 
522         return journalArticleResource;
523     }
524 
525     public JournalArticleResource fetchByG_A(long groupId, String articleId)
526         throws SystemException {
527         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
528         String finderClassName = JournalArticleResource.class.getName();
529         String finderMethodName = "fetchByG_A";
530         String[] finderParams = new String[] {
531                 Long.class.getName(), String.class.getName()
532             };
533         Object[] finderArgs = new Object[] { new Long(groupId), articleId };
534 
535         Object result = null;
536 
537         if (finderClassNameCacheEnabled) {
538             result = FinderCacheUtil.getResult(finderClassName,
539                     finderMethodName, finderParams, finderArgs, this);
540         }
541 
542         if (result == null) {
543             Session session = null;
544 
545             try {
546                 session = openSession();
547 
548                 StringBuilder query = new StringBuilder();
549 
550                 query.append(
551                     "FROM com.liferay.portlet.journal.model.JournalArticleResource WHERE ");
552 
553                 query.append("groupId = ?");
554 
555                 query.append(" AND ");
556 
557                 if (articleId == null) {
558                     query.append("articleId IS NULL");
559                 }
560                 else {
561                     query.append("articleId = ?");
562                 }
563 
564                 query.append(" ");
565 
566                 Query q = session.createQuery(query.toString());
567 
568                 QueryPos qPos = QueryPos.getInstance(q);
569 
570                 qPos.add(groupId);
571 
572                 if (articleId != null) {
573                     qPos.add(articleId);
574                 }
575 
576                 List<JournalArticleResource> list = q.list();
577 
578                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
579                     finderClassName, finderMethodName, finderParams,
580                     finderArgs, list);
581 
582                 if (list.size() == 0) {
583                     return null;
584                 }
585                 else {
586                     return list.get(0);
587                 }
588             }
589             catch (Exception e) {
590                 throw processException(e);
591             }
592             finally {
593                 closeSession(session);
594             }
595         }
596         else {
597             List<JournalArticleResource> list = (List<JournalArticleResource>)result;
598 
599             if (list.size() == 0) {
600                 return null;
601             }
602             else {
603                 return list.get(0);
604             }
605         }
606     }
607 
608     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
609         throws SystemException {
610         Session session = null;
611 
612         try {
613             session = openSession();
614 
615             dynamicQuery.compile(session);
616 
617             return dynamicQuery.list();
618         }
619         catch (Exception e) {
620             throw processException(e);
621         }
622         finally {
623             closeSession(session);
624         }
625     }
626 
627     public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
628         int start, int end) throws SystemException {
629         Session session = null;
630 
631         try {
632             session = openSession();
633 
634             dynamicQuery.setLimit(start, end);
635 
636             dynamicQuery.compile(session);
637 
638             return dynamicQuery.list();
639         }
640         catch (Exception e) {
641             throw processException(e);
642         }
643         finally {
644             closeSession(session);
645         }
646     }
647 
648     public List<JournalArticleResource> findAll() throws SystemException {
649         return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
650     }
651 
652     public List<JournalArticleResource> findAll(int start, int end)
653         throws SystemException {
654         return findAll(start, end, null);
655     }
656 
657     public List<JournalArticleResource> findAll(int start, int end,
658         OrderByComparator obc) throws SystemException {
659         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
660         String finderClassName = JournalArticleResource.class.getName();
661         String finderMethodName = "findAll";
662         String[] finderParams = new String[] {
663                 "java.lang.Integer", "java.lang.Integer",
664                 "com.liferay.portal.kernel.util.OrderByComparator"
665             };
666         Object[] finderArgs = new Object[] {
667                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
668             };
669 
670         Object result = null;
671 
672         if (finderClassNameCacheEnabled) {
673             result = FinderCacheUtil.getResult(finderClassName,
674                     finderMethodName, finderParams, finderArgs, this);
675         }
676 
677         if (result == null) {
678             Session session = null;
679 
680             try {
681                 session = openSession();
682 
683                 StringBuilder query = new StringBuilder();
684 
685                 query.append(
686                     "FROM com.liferay.portlet.journal.model.JournalArticleResource ");
687 
688                 if (obc != null) {
689                     query.append("ORDER BY ");
690                     query.append(obc.getOrderBy());
691                 }
692 
693                 Query q = session.createQuery(query.toString());
694 
695                 List<JournalArticleResource> list = null;
696 
697                 if (obc == null) {
698                     list = (List<JournalArticleResource>)QueryUtil.list(q,
699                             getDialect(), start, end, false);
700 
701                     Collections.sort(list);
702                 }
703                 else {
704                     list = (List<JournalArticleResource>)QueryUtil.list(q,
705                             getDialect(), start, end);
706                 }
707 
708                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
709                     finderClassName, finderMethodName, finderParams,
710                     finderArgs, list);
711 
712                 return list;
713             }
714             catch (Exception e) {
715                 throw processException(e);
716             }
717             finally {
718                 closeSession(session);
719             }
720         }
721         else {
722             return (List<JournalArticleResource>)result;
723         }
724     }
725 
726     public void removeByGroupId(long groupId) throws SystemException {
727         for (JournalArticleResource journalArticleResource : findByGroupId(
728                 groupId)) {
729             remove(journalArticleResource);
730         }
731     }
732 
733     public void removeByG_A(long groupId, String articleId)
734         throws NoSuchArticleResourceException, SystemException {
735         JournalArticleResource journalArticleResource = findByG_A(groupId,
736                 articleId);
737 
738         remove(journalArticleResource);
739     }
740 
741     public void removeAll() throws SystemException {
742         for (JournalArticleResource journalArticleResource : findAll()) {
743             remove(journalArticleResource);
744         }
745     }
746 
747     public int countByGroupId(long groupId) throws SystemException {
748         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
749         String finderClassName = JournalArticleResource.class.getName();
750         String finderMethodName = "countByGroupId";
751         String[] finderParams = new String[] { Long.class.getName() };
752         Object[] finderArgs = new Object[] { new Long(groupId) };
753 
754         Object result = null;
755 
756         if (finderClassNameCacheEnabled) {
757             result = FinderCacheUtil.getResult(finderClassName,
758                     finderMethodName, finderParams, finderArgs, this);
759         }
760 
761         if (result == null) {
762             Session session = null;
763 
764             try {
765                 session = openSession();
766 
767                 StringBuilder query = new StringBuilder();
768 
769                 query.append("SELECT COUNT(*) ");
770                 query.append(
771                     "FROM com.liferay.portlet.journal.model.JournalArticleResource WHERE ");
772 
773                 query.append("groupId = ?");
774 
775                 query.append(" ");
776 
777                 Query q = session.createQuery(query.toString());
778 
779                 QueryPos qPos = QueryPos.getInstance(q);
780 
781                 qPos.add(groupId);
782 
783                 Long count = null;
784 
785                 Iterator<Long> itr = q.list().iterator();
786 
787                 if (itr.hasNext()) {
788                     count = itr.next();
789                 }
790 
791                 if (count == null) {
792                     count = new Long(0);
793                 }
794 
795                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
796                     finderClassName, finderMethodName, finderParams,
797                     finderArgs, count);
798 
799                 return count.intValue();
800             }
801             catch (Exception e) {
802                 throw processException(e);
803             }
804             finally {
805                 closeSession(session);
806             }
807         }
808         else {
809             return ((Long)result).intValue();
810         }
811     }
812 
813     public int countByG_A(long groupId, String articleId)
814         throws SystemException {
815         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
816         String finderClassName = JournalArticleResource.class.getName();
817         String finderMethodName = "countByG_A";
818         String[] finderParams = new String[] {
819                 Long.class.getName(), String.class.getName()
820             };
821         Object[] finderArgs = new Object[] { new Long(groupId), articleId };
822 
823         Object result = null;
824 
825         if (finderClassNameCacheEnabled) {
826             result = FinderCacheUtil.getResult(finderClassName,
827                     finderMethodName, finderParams, finderArgs, this);
828         }
829 
830         if (result == null) {
831             Session session = null;
832 
833             try {
834                 session = openSession();
835 
836                 StringBuilder query = new StringBuilder();
837 
838                 query.append("SELECT COUNT(*) ");
839                 query.append(
840                     "FROM com.liferay.portlet.journal.model.JournalArticleResource WHERE ");
841 
842                 query.append("groupId = ?");
843 
844                 query.append(" AND ");
845 
846                 if (articleId == null) {
847                     query.append("articleId IS NULL");
848                 }
849                 else {
850                     query.append("articleId = ?");
851                 }
852 
853                 query.append(" ");
854 
855                 Query q = session.createQuery(query.toString());
856 
857                 QueryPos qPos = QueryPos.getInstance(q);
858 
859                 qPos.add(groupId);
860 
861                 if (articleId != null) {
862                     qPos.add(articleId);
863                 }
864 
865                 Long count = null;
866 
867                 Iterator<Long> itr = q.list().iterator();
868 
869                 if (itr.hasNext()) {
870                     count = itr.next();
871                 }
872 
873                 if (count == null) {
874                     count = new Long(0);
875                 }
876 
877                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
878                     finderClassName, finderMethodName, finderParams,
879                     finderArgs, count);
880 
881                 return count.intValue();
882             }
883             catch (Exception e) {
884                 throw processException(e);
885             }
886             finally {
887                 closeSession(session);
888             }
889         }
890         else {
891             return ((Long)result).intValue();
892         }
893     }
894 
895     public int countAll() throws SystemException {
896         boolean finderClassNameCacheEnabled = JournalArticleResourceModelImpl.CACHE_ENABLED;
897         String finderClassName = JournalArticleResource.class.getName();
898         String finderMethodName = "countAll";
899         String[] finderParams = new String[] {  };
900         Object[] finderArgs = new Object[] {  };
901 
902         Object result = null;
903 
904         if (finderClassNameCacheEnabled) {
905             result = FinderCacheUtil.getResult(finderClassName,
906                     finderMethodName, finderParams, finderArgs, this);
907         }
908 
909         if (result == null) {
910             Session session = null;
911 
912             try {
913                 session = openSession();
914 
915                 Query q = session.createQuery(
916                         "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalArticleResource");
917 
918                 Long count = null;
919 
920                 Iterator<Long> itr = q.list().iterator();
921 
922                 if (itr.hasNext()) {
923                     count = itr.next();
924                 }
925 
926                 if (count == null) {
927                     count = new Long(0);
928                 }
929 
930                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
931                     finderClassName, finderMethodName, finderParams,
932                     finderArgs, count);
933 
934                 return count.intValue();
935             }
936             catch (Exception e) {
937                 throw processException(e);
938             }
939             finally {
940                 closeSession(session);
941             }
942         }
943         else {
944             return ((Long)result).intValue();
945         }
946     }
947 
948     public void afterPropertiesSet() {
949         String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
950                     com.liferay.portal.util.PropsUtil.get(
951                         "value.object.listener.com.liferay.portlet.journal.model.JournalArticleResource")));
952 
953         if (listenerClassNames.length > 0) {
954             try {
955                 List<ModelListener> listenersList = new ArrayList<ModelListener>();
956 
957                 for (String listenerClassName : listenerClassNames) {
958                     listenersList.add((ModelListener)Class.forName(
959                             listenerClassName).newInstance());
960                 }
961 
962                 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
963             }
964             catch (Exception e) {
965                 _log.error(e);
966             }
967         }
968     }
969 
970     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticlePersistence.impl")
971     protected com.liferay.portlet.journal.service.persistence.JournalArticlePersistence journalArticlePersistence;
972     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleImagePersistence.impl")
973     protected com.liferay.portlet.journal.service.persistence.JournalArticleImagePersistence journalArticleImagePersistence;
974     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence.impl")
975     protected com.liferay.portlet.journal.service.persistence.JournalArticleResourcePersistence journalArticleResourcePersistence;
976     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence.impl")
977     protected com.liferay.portlet.journal.service.persistence.JournalContentSearchPersistence journalContentSearchPersistence;
978     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalFeedPersistence.impl")
979     protected com.liferay.portlet.journal.service.persistence.JournalFeedPersistence journalFeedPersistence;
980     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalStructurePersistence.impl")
981     protected com.liferay.portlet.journal.service.persistence.JournalStructurePersistence journalStructurePersistence;
982     @BeanReference(name = "com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence.impl")
983     protected com.liferay.portlet.journal.service.persistence.JournalTemplatePersistence journalTemplatePersistence;
984     private static Log _log = LogFactoryUtil.getLog(JournalArticleResourcePersistenceImpl.class);
985 }