1   /**
2    * Copyright (c) 2000-2008 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.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.kernel.util.Validator;
38  import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
39  import com.liferay.portal.model.ModelListener;
40  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
41  
42  import com.liferay.portlet.journal.NoSuchArticleException;
43  import com.liferay.portlet.journal.model.JournalArticle;
44  import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
45  import com.liferay.portlet.journal.model.impl.JournalArticleModelImpl;
46  
47  import org.apache.commons.logging.Log;
48  import org.apache.commons.logging.LogFactory;
49  
50  import java.util.ArrayList;
51  import java.util.Collections;
52  import java.util.Iterator;
53  import java.util.List;
54  
55  /**
56   * <a href="JournalArticlePersistenceImpl.java.html"><b><i>View Source</i></b></a>
57   *
58   * @author Brian Wing Shun Chan
59   *
60   */
61  public class JournalArticlePersistenceImpl extends BasePersistenceImpl
62      implements JournalArticlePersistence {
63      public JournalArticle create(long id) {
64          JournalArticle journalArticle = new JournalArticleImpl();
65  
66          journalArticle.setNew(true);
67          journalArticle.setPrimaryKey(id);
68  
69          String uuid = PortalUUIDUtil.generate();
70  
71          journalArticle.setUuid(uuid);
72  
73          return journalArticle;
74      }
75  
76      public JournalArticle remove(long id)
77          throws NoSuchArticleException, SystemException {
78          Session session = null;
79  
80          try {
81              session = openSession();
82  
83              JournalArticle journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
84                      new Long(id));
85  
86              if (journalArticle == null) {
87                  if (_log.isWarnEnabled()) {
88                      _log.warn("No JournalArticle exists with the primary key " +
89                          id);
90                  }
91  
92                  throw new NoSuchArticleException(
93                      "No JournalArticle exists with the primary key " + id);
94              }
95  
96              return remove(journalArticle);
97          }
98          catch (NoSuchArticleException nsee) {
99              throw nsee;
100         }
101         catch (Exception e) {
102             throw processException(e);
103         }
104         finally {
105             closeSession(session);
106         }
107     }
108 
109     public JournalArticle remove(JournalArticle journalArticle)
110         throws SystemException {
111         if (_listeners.length > 0) {
112             for (ModelListener listener : _listeners) {
113                 listener.onBeforeRemove(journalArticle);
114             }
115         }
116 
117         journalArticle = removeImpl(journalArticle);
118 
119         if (_listeners.length > 0) {
120             for (ModelListener listener : _listeners) {
121                 listener.onAfterRemove(journalArticle);
122             }
123         }
124 
125         return journalArticle;
126     }
127 
128     protected JournalArticle removeImpl(JournalArticle journalArticle)
129         throws SystemException {
130         Session session = null;
131 
132         try {
133             session = openSession();
134 
135             session.delete(journalArticle);
136 
137             session.flush();
138 
139             return journalArticle;
140         }
141         catch (Exception e) {
142             throw processException(e);
143         }
144         finally {
145             closeSession(session);
146 
147             FinderCacheUtil.clearCache(JournalArticle.class.getName());
148         }
149     }
150 
151     /**
152      * @deprecated Use <code>update(JournalArticle journalArticle, boolean merge)</code>.
153      */
154     public JournalArticle update(JournalArticle journalArticle)
155         throws SystemException {
156         if (_log.isWarnEnabled()) {
157             _log.warn(
158                 "Using the deprecated update(JournalArticle journalArticle) method. Use update(JournalArticle journalArticle, boolean merge) instead.");
159         }
160 
161         return update(journalArticle, false);
162     }
163 
164     /**
165      * Add, update, or merge, the entity. This method also calls the model
166      * listeners to trigger the proper events associated with adding, deleting,
167      * or updating an entity.
168      *
169      * @param        journalArticle the entity to add, update, or merge
170      * @param        merge boolean value for whether to merge the entity. The
171      *                default value is false. Setting merge to true is more
172      *                expensive and should only be true when journalArticle is
173      *                transient. See LEP-5473 for a detailed discussion of this
174      *                method.
175      * @return        true if the portlet can be displayed via Ajax
176      */
177     public JournalArticle update(JournalArticle journalArticle, boolean merge)
178         throws SystemException {
179         boolean isNew = journalArticle.isNew();
180 
181         if (_listeners.length > 0) {
182             for (ModelListener listener : _listeners) {
183                 if (isNew) {
184                     listener.onBeforeCreate(journalArticle);
185                 }
186                 else {
187                     listener.onBeforeUpdate(journalArticle);
188                 }
189             }
190         }
191 
192         journalArticle = updateImpl(journalArticle, merge);
193 
194         if (_listeners.length > 0) {
195             for (ModelListener listener : _listeners) {
196                 if (isNew) {
197                     listener.onAfterCreate(journalArticle);
198                 }
199                 else {
200                     listener.onAfterUpdate(journalArticle);
201                 }
202             }
203         }
204 
205         return journalArticle;
206     }
207 
208     public JournalArticle updateImpl(
209         com.liferay.portlet.journal.model.JournalArticle journalArticle,
210         boolean merge) throws SystemException {
211         if (Validator.isNull(journalArticle.getUuid())) {
212             String uuid = PortalUUIDUtil.generate();
213 
214             journalArticle.setUuid(uuid);
215         }
216 
217         Session session = null;
218 
219         try {
220             session = openSession();
221 
222             if (merge) {
223                 session.merge(journalArticle);
224             }
225             else {
226                 if (journalArticle.isNew()) {
227                     session.save(journalArticle);
228                 }
229             }
230 
231             session.flush();
232 
233             journalArticle.setNew(false);
234 
235             return journalArticle;
236         }
237         catch (Exception e) {
238             throw processException(e);
239         }
240         finally {
241             closeSession(session);
242 
243             FinderCacheUtil.clearCache(JournalArticle.class.getName());
244         }
245     }
246 
247     public JournalArticle findByPrimaryKey(long id)
248         throws NoSuchArticleException, SystemException {
249         JournalArticle journalArticle = fetchByPrimaryKey(id);
250 
251         if (journalArticle == null) {
252             if (_log.isWarnEnabled()) {
253                 _log.warn("No JournalArticle exists with the primary key " +
254                     id);
255             }
256 
257             throw new NoSuchArticleException(
258                 "No JournalArticle exists with the primary key " + id);
259         }
260 
261         return journalArticle;
262     }
263 
264     public JournalArticle fetchByPrimaryKey(long id) throws SystemException {
265         Session session = null;
266 
267         try {
268             session = openSession();
269 
270             return (JournalArticle)session.get(JournalArticleImpl.class,
271                 new Long(id));
272         }
273         catch (Exception e) {
274             throw processException(e);
275         }
276         finally {
277             closeSession(session);
278         }
279     }
280 
281     public List<JournalArticle> findByUuid(String uuid)
282         throws SystemException {
283         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
284         String finderClassName = JournalArticle.class.getName();
285         String finderMethodName = "findByUuid";
286         String[] finderParams = new String[] { String.class.getName() };
287         Object[] finderArgs = new Object[] { uuid };
288 
289         Object result = null;
290 
291         if (finderClassNameCacheEnabled) {
292             result = FinderCacheUtil.getResult(finderClassName,
293                     finderMethodName, finderParams, finderArgs, this);
294         }
295 
296         if (result == null) {
297             Session session = null;
298 
299             try {
300                 session = openSession();
301 
302                 StringBuilder query = new StringBuilder();
303 
304                 query.append(
305                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
306 
307                 if (uuid == null) {
308                     query.append("uuid_ IS NULL");
309                 }
310                 else {
311                     query.append("uuid_ = ?");
312                 }
313 
314                 query.append(" ");
315 
316                 query.append("ORDER BY ");
317 
318                 query.append("articleId ASC, ");
319                 query.append("version DESC");
320 
321                 Query q = session.createQuery(query.toString());
322 
323                 QueryPos qPos = QueryPos.getInstance(q);
324 
325                 if (uuid != null) {
326                     qPos.add(uuid);
327                 }
328 
329                 List<JournalArticle> list = q.list();
330 
331                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
332                     finderClassName, finderMethodName, finderParams,
333                     finderArgs, list);
334 
335                 return list;
336             }
337             catch (Exception e) {
338                 throw processException(e);
339             }
340             finally {
341                 closeSession(session);
342             }
343         }
344         else {
345             return (List<JournalArticle>)result;
346         }
347     }
348 
349     public List<JournalArticle> findByUuid(String uuid, int start, int end)
350         throws SystemException {
351         return findByUuid(uuid, start, end, null);
352     }
353 
354     public List<JournalArticle> findByUuid(String uuid, int start, int end,
355         OrderByComparator obc) throws SystemException {
356         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
357         String finderClassName = JournalArticle.class.getName();
358         String finderMethodName = "findByUuid";
359         String[] finderParams = new String[] {
360                 String.class.getName(),
361                 
362                 "java.lang.Integer", "java.lang.Integer",
363                 "com.liferay.portal.kernel.util.OrderByComparator"
364             };
365         Object[] finderArgs = new Object[] {
366                 uuid,
367                 
368                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
369             };
370 
371         Object result = null;
372 
373         if (finderClassNameCacheEnabled) {
374             result = FinderCacheUtil.getResult(finderClassName,
375                     finderMethodName, finderParams, finderArgs, this);
376         }
377 
378         if (result == null) {
379             Session session = null;
380 
381             try {
382                 session = openSession();
383 
384                 StringBuilder query = new StringBuilder();
385 
386                 query.append(
387                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
388 
389                 if (uuid == null) {
390                     query.append("uuid_ IS NULL");
391                 }
392                 else {
393                     query.append("uuid_ = ?");
394                 }
395 
396                 query.append(" ");
397 
398                 if (obc != null) {
399                     query.append("ORDER BY ");
400                     query.append(obc.getOrderBy());
401                 }
402 
403                 else {
404                     query.append("ORDER BY ");
405 
406                     query.append("articleId ASC, ");
407                     query.append("version DESC");
408                 }
409 
410                 Query q = session.createQuery(query.toString());
411 
412                 QueryPos qPos = QueryPos.getInstance(q);
413 
414                 if (uuid != null) {
415                     qPos.add(uuid);
416                 }
417 
418                 List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
419                         getDialect(), start, end);
420 
421                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
422                     finderClassName, finderMethodName, finderParams,
423                     finderArgs, list);
424 
425                 return list;
426             }
427             catch (Exception e) {
428                 throw processException(e);
429             }
430             finally {
431                 closeSession(session);
432             }
433         }
434         else {
435             return (List<JournalArticle>)result;
436         }
437     }
438 
439     public JournalArticle findByUuid_First(String uuid, OrderByComparator obc)
440         throws NoSuchArticleException, SystemException {
441         List<JournalArticle> list = findByUuid(uuid, 0, 1, obc);
442 
443         if (list.size() == 0) {
444             StringBuilder msg = new StringBuilder();
445 
446             msg.append("No JournalArticle exists with the key {");
447 
448             msg.append("uuid=" + uuid);
449 
450             msg.append(StringPool.CLOSE_CURLY_BRACE);
451 
452             throw new NoSuchArticleException(msg.toString());
453         }
454         else {
455             return list.get(0);
456         }
457     }
458 
459     public JournalArticle findByUuid_Last(String uuid, OrderByComparator obc)
460         throws NoSuchArticleException, SystemException {
461         int count = countByUuid(uuid);
462 
463         List<JournalArticle> list = findByUuid(uuid, count - 1, count, obc);
464 
465         if (list.size() == 0) {
466             StringBuilder msg = new StringBuilder();
467 
468             msg.append("No JournalArticle exists with the key {");
469 
470             msg.append("uuid=" + uuid);
471 
472             msg.append(StringPool.CLOSE_CURLY_BRACE);
473 
474             throw new NoSuchArticleException(msg.toString());
475         }
476         else {
477             return list.get(0);
478         }
479     }
480 
481     public JournalArticle[] findByUuid_PrevAndNext(long id, String uuid,
482         OrderByComparator obc) throws NoSuchArticleException, SystemException {
483         JournalArticle journalArticle = findByPrimaryKey(id);
484 
485         int count = countByUuid(uuid);
486 
487         Session session = null;
488 
489         try {
490             session = openSession();
491 
492             StringBuilder query = new StringBuilder();
493 
494             query.append(
495                 "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
496 
497             if (uuid == null) {
498                 query.append("uuid_ IS NULL");
499             }
500             else {
501                 query.append("uuid_ = ?");
502             }
503 
504             query.append(" ");
505 
506             if (obc != null) {
507                 query.append("ORDER BY ");
508                 query.append(obc.getOrderBy());
509             }
510 
511             else {
512                 query.append("ORDER BY ");
513 
514                 query.append("articleId ASC, ");
515                 query.append("version DESC");
516             }
517 
518             Query q = session.createQuery(query.toString());
519 
520             QueryPos qPos = QueryPos.getInstance(q);
521 
522             if (uuid != null) {
523                 qPos.add(uuid);
524             }
525 
526             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
527                     journalArticle);
528 
529             JournalArticle[] array = new JournalArticleImpl[3];
530 
531             array[0] = (JournalArticle)objArray[0];
532             array[1] = (JournalArticle)objArray[1];
533             array[2] = (JournalArticle)objArray[2];
534 
535             return array;
536         }
537         catch (Exception e) {
538             throw processException(e);
539         }
540         finally {
541             closeSession(session);
542         }
543     }
544 
545     public JournalArticle findByUUID_G(String uuid, long groupId)
546         throws NoSuchArticleException, SystemException {
547         JournalArticle journalArticle = fetchByUUID_G(uuid, groupId);
548 
549         if (journalArticle == null) {
550             StringBuilder msg = new StringBuilder();
551 
552             msg.append("No JournalArticle exists with the key {");
553 
554             msg.append("uuid=" + uuid);
555 
556             msg.append(", ");
557             msg.append("groupId=" + groupId);
558 
559             msg.append(StringPool.CLOSE_CURLY_BRACE);
560 
561             if (_log.isWarnEnabled()) {
562                 _log.warn(msg.toString());
563             }
564 
565             throw new NoSuchArticleException(msg.toString());
566         }
567 
568         return journalArticle;
569     }
570 
571     public JournalArticle fetchByUUID_G(String uuid, long groupId)
572         throws SystemException {
573         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
574         String finderClassName = JournalArticle.class.getName();
575         String finderMethodName = "fetchByUUID_G";
576         String[] finderParams = new String[] {
577                 String.class.getName(), Long.class.getName()
578             };
579         Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
580 
581         Object result = null;
582 
583         if (finderClassNameCacheEnabled) {
584             result = FinderCacheUtil.getResult(finderClassName,
585                     finderMethodName, finderParams, finderArgs, this);
586         }
587 
588         if (result == null) {
589             Session session = null;
590 
591             try {
592                 session = openSession();
593 
594                 StringBuilder query = new StringBuilder();
595 
596                 query.append(
597                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
598 
599                 if (uuid == null) {
600                     query.append("uuid_ IS NULL");
601                 }
602                 else {
603                     query.append("uuid_ = ?");
604                 }
605 
606                 query.append(" AND ");
607 
608                 query.append("groupId = ?");
609 
610                 query.append(" ");
611 
612                 query.append("ORDER BY ");
613 
614                 query.append("articleId ASC, ");
615                 query.append("version DESC");
616 
617                 Query q = session.createQuery(query.toString());
618 
619                 QueryPos qPos = QueryPos.getInstance(q);
620 
621                 if (uuid != null) {
622                     qPos.add(uuid);
623                 }
624 
625                 qPos.add(groupId);
626 
627                 List<JournalArticle> list = q.list();
628 
629                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
630                     finderClassName, finderMethodName, finderParams,
631                     finderArgs, list);
632 
633                 if (list.size() == 0) {
634                     return null;
635                 }
636                 else {
637                     return list.get(0);
638                 }
639             }
640             catch (Exception e) {
641                 throw processException(e);
642             }
643             finally {
644                 closeSession(session);
645             }
646         }
647         else {
648             List<JournalArticle> list = (List<JournalArticle>)result;
649 
650             if (list.size() == 0) {
651                 return null;
652             }
653             else {
654                 return list.get(0);
655             }
656         }
657     }
658 
659     public List<JournalArticle> findByGroupId(long groupId)
660         throws SystemException {
661         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
662         String finderClassName = JournalArticle.class.getName();
663         String finderMethodName = "findByGroupId";
664         String[] finderParams = new String[] { Long.class.getName() };
665         Object[] finderArgs = new Object[] { new Long(groupId) };
666 
667         Object result = null;
668 
669         if (finderClassNameCacheEnabled) {
670             result = FinderCacheUtil.getResult(finderClassName,
671                     finderMethodName, finderParams, finderArgs, this);
672         }
673 
674         if (result == null) {
675             Session session = null;
676 
677             try {
678                 session = openSession();
679 
680                 StringBuilder query = new StringBuilder();
681 
682                 query.append(
683                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
684 
685                 query.append("groupId = ?");
686 
687                 query.append(" ");
688 
689                 query.append("ORDER BY ");
690 
691                 query.append("articleId ASC, ");
692                 query.append("version DESC");
693 
694                 Query q = session.createQuery(query.toString());
695 
696                 QueryPos qPos = QueryPos.getInstance(q);
697 
698                 qPos.add(groupId);
699 
700                 List<JournalArticle> list = q.list();
701 
702                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
703                     finderClassName, finderMethodName, finderParams,
704                     finderArgs, list);
705 
706                 return list;
707             }
708             catch (Exception e) {
709                 throw processException(e);
710             }
711             finally {
712                 closeSession(session);
713             }
714         }
715         else {
716             return (List<JournalArticle>)result;
717         }
718     }
719 
720     public List<JournalArticle> findByGroupId(long groupId, int start, int end)
721         throws SystemException {
722         return findByGroupId(groupId, start, end, null);
723     }
724 
725     public List<JournalArticle> findByGroupId(long groupId, int start, int end,
726         OrderByComparator obc) throws SystemException {
727         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
728         String finderClassName = JournalArticle.class.getName();
729         String finderMethodName = "findByGroupId";
730         String[] finderParams = new String[] {
731                 Long.class.getName(),
732                 
733                 "java.lang.Integer", "java.lang.Integer",
734                 "com.liferay.portal.kernel.util.OrderByComparator"
735             };
736         Object[] finderArgs = new Object[] {
737                 new Long(groupId),
738                 
739                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
740             };
741 
742         Object result = null;
743 
744         if (finderClassNameCacheEnabled) {
745             result = FinderCacheUtil.getResult(finderClassName,
746                     finderMethodName, finderParams, finderArgs, this);
747         }
748 
749         if (result == null) {
750             Session session = null;
751 
752             try {
753                 session = openSession();
754 
755                 StringBuilder query = new StringBuilder();
756 
757                 query.append(
758                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
759 
760                 query.append("groupId = ?");
761 
762                 query.append(" ");
763 
764                 if (obc != null) {
765                     query.append("ORDER BY ");
766                     query.append(obc.getOrderBy());
767                 }
768 
769                 else {
770                     query.append("ORDER BY ");
771 
772                     query.append("articleId ASC, ");
773                     query.append("version DESC");
774                 }
775 
776                 Query q = session.createQuery(query.toString());
777 
778                 QueryPos qPos = QueryPos.getInstance(q);
779 
780                 qPos.add(groupId);
781 
782                 List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
783                         getDialect(), start, end);
784 
785                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
786                     finderClassName, finderMethodName, finderParams,
787                     finderArgs, list);
788 
789                 return list;
790             }
791             catch (Exception e) {
792                 throw processException(e);
793             }
794             finally {
795                 closeSession(session);
796             }
797         }
798         else {
799             return (List<JournalArticle>)result;
800         }
801     }
802 
803     public JournalArticle findByGroupId_First(long groupId,
804         OrderByComparator obc) throws NoSuchArticleException, SystemException {
805         List<JournalArticle> list = findByGroupId(groupId, 0, 1, obc);
806 
807         if (list.size() == 0) {
808             StringBuilder msg = new StringBuilder();
809 
810             msg.append("No JournalArticle exists with the key {");
811 
812             msg.append("groupId=" + groupId);
813 
814             msg.append(StringPool.CLOSE_CURLY_BRACE);
815 
816             throw new NoSuchArticleException(msg.toString());
817         }
818         else {
819             return list.get(0);
820         }
821     }
822 
823     public JournalArticle findByGroupId_Last(long groupId, OrderByComparator obc)
824         throws NoSuchArticleException, SystemException {
825         int count = countByGroupId(groupId);
826 
827         List<JournalArticle> list = findByGroupId(groupId, count - 1, count, obc);
828 
829         if (list.size() == 0) {
830             StringBuilder msg = new StringBuilder();
831 
832             msg.append("No JournalArticle exists with the key {");
833 
834             msg.append("groupId=" + groupId);
835 
836             msg.append(StringPool.CLOSE_CURLY_BRACE);
837 
838             throw new NoSuchArticleException(msg.toString());
839         }
840         else {
841             return list.get(0);
842         }
843     }
844 
845     public JournalArticle[] findByGroupId_PrevAndNext(long id, long groupId,
846         OrderByComparator obc) throws NoSuchArticleException, SystemException {
847         JournalArticle journalArticle = findByPrimaryKey(id);
848 
849         int count = countByGroupId(groupId);
850 
851         Session session = null;
852 
853         try {
854             session = openSession();
855 
856             StringBuilder query = new StringBuilder();
857 
858             query.append(
859                 "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
860 
861             query.append("groupId = ?");
862 
863             query.append(" ");
864 
865             if (obc != null) {
866                 query.append("ORDER BY ");
867                 query.append(obc.getOrderBy());
868             }
869 
870             else {
871                 query.append("ORDER BY ");
872 
873                 query.append("articleId ASC, ");
874                 query.append("version DESC");
875             }
876 
877             Query q = session.createQuery(query.toString());
878 
879             QueryPos qPos = QueryPos.getInstance(q);
880 
881             qPos.add(groupId);
882 
883             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
884                     journalArticle);
885 
886             JournalArticle[] array = new JournalArticleImpl[3];
887 
888             array[0] = (JournalArticle)objArray[0];
889             array[1] = (JournalArticle)objArray[1];
890             array[2] = (JournalArticle)objArray[2];
891 
892             return array;
893         }
894         catch (Exception e) {
895             throw processException(e);
896         }
897         finally {
898             closeSession(session);
899         }
900     }
901 
902     public List<JournalArticle> findByCompanyId(long companyId)
903         throws SystemException {
904         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
905         String finderClassName = JournalArticle.class.getName();
906         String finderMethodName = "findByCompanyId";
907         String[] finderParams = new String[] { Long.class.getName() };
908         Object[] finderArgs = new Object[] { new Long(companyId) };
909 
910         Object result = null;
911 
912         if (finderClassNameCacheEnabled) {
913             result = FinderCacheUtil.getResult(finderClassName,
914                     finderMethodName, finderParams, finderArgs, this);
915         }
916 
917         if (result == null) {
918             Session session = null;
919 
920             try {
921                 session = openSession();
922 
923                 StringBuilder query = new StringBuilder();
924 
925                 query.append(
926                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
927 
928                 query.append("companyId = ?");
929 
930                 query.append(" ");
931 
932                 query.append("ORDER BY ");
933 
934                 query.append("articleId ASC, ");
935                 query.append("version DESC");
936 
937                 Query q = session.createQuery(query.toString());
938 
939                 QueryPos qPos = QueryPos.getInstance(q);
940 
941                 qPos.add(companyId);
942 
943                 List<JournalArticle> list = q.list();
944 
945                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
946                     finderClassName, finderMethodName, finderParams,
947                     finderArgs, list);
948 
949                 return list;
950             }
951             catch (Exception e) {
952                 throw processException(e);
953             }
954             finally {
955                 closeSession(session);
956             }
957         }
958         else {
959             return (List<JournalArticle>)result;
960         }
961     }
962 
963     public List<JournalArticle> findByCompanyId(long companyId, int start,
964         int end) throws SystemException {
965         return findByCompanyId(companyId, start, end, null);
966     }
967 
968     public List<JournalArticle> findByCompanyId(long companyId, int start,
969         int end, OrderByComparator obc) throws SystemException {
970         boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
971         String finderClassName = JournalArticle.class.getName();
972         String finderMethodName = "findByCompanyId";
973         String[] finderParams = new String[] {
974                 Long.class.getName(),
975                 
976                 "java.lang.Integer", "java.lang.Integer",
977                 "com.liferay.portal.kernel.util.OrderByComparator"
978             };
979         Object[] finderArgs = new Object[] {
980                 new Long(companyId),
981                 
982                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
983             };
984 
985         Object result = null;
986 
987         if (finderClassNameCacheEnabled) {
988             result = FinderCacheUtil.getResult(finderClassName,
989                     finderMethodName, finderParams, finderArgs, this);
990         }
991 
992         if (result == null) {
993             Session session = null;
994 
995             try {
996                 session = openSession();
997 
998                 StringBuilder query = new StringBuilder();
999 
1000                query.append(
1001                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1002
1003                query.append("companyId = ?");
1004
1005                query.append(" ");
1006
1007                if (obc != null) {
1008                    query.append("ORDER BY ");
1009                    query.append(obc.getOrderBy());
1010                }
1011
1012                else {
1013                    query.append("ORDER BY ");
1014
1015                    query.append("articleId ASC, ");
1016                    query.append("version DESC");
1017                }
1018
1019                Query q = session.createQuery(query.toString());
1020
1021                QueryPos qPos = QueryPos.getInstance(q);
1022
1023                qPos.add(companyId);
1024
1025                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
1026                        getDialect(), start, end);
1027
1028                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1029                    finderClassName, finderMethodName, finderParams,
1030                    finderArgs, list);
1031
1032                return list;
1033            }
1034            catch (Exception e) {
1035                throw processException(e);
1036            }
1037            finally {
1038                closeSession(session);
1039            }
1040        }
1041        else {
1042            return (List<JournalArticle>)result;
1043        }
1044    }
1045
1046    public JournalArticle findByCompanyId_First(long companyId,
1047        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1048        List<JournalArticle> list = findByCompanyId(companyId, 0, 1, obc);
1049
1050        if (list.size() == 0) {
1051            StringBuilder msg = new StringBuilder();
1052
1053            msg.append("No JournalArticle exists with the key {");
1054
1055            msg.append("companyId=" + companyId);
1056
1057            msg.append(StringPool.CLOSE_CURLY_BRACE);
1058
1059            throw new NoSuchArticleException(msg.toString());
1060        }
1061        else {
1062            return list.get(0);
1063        }
1064    }
1065
1066    public JournalArticle findByCompanyId_Last(long companyId,
1067        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1068        int count = countByCompanyId(companyId);
1069
1070        List<JournalArticle> list = findByCompanyId(companyId, count - 1,
1071                count, obc);
1072
1073        if (list.size() == 0) {
1074            StringBuilder msg = new StringBuilder();
1075
1076            msg.append("No JournalArticle exists with the key {");
1077
1078            msg.append("companyId=" + companyId);
1079
1080            msg.append(StringPool.CLOSE_CURLY_BRACE);
1081
1082            throw new NoSuchArticleException(msg.toString());
1083        }
1084        else {
1085            return list.get(0);
1086        }
1087    }
1088
1089    public JournalArticle[] findByCompanyId_PrevAndNext(long id,
1090        long companyId, OrderByComparator obc)
1091        throws NoSuchArticleException, SystemException {
1092        JournalArticle journalArticle = findByPrimaryKey(id);
1093
1094        int count = countByCompanyId(companyId);
1095
1096        Session session = null;
1097
1098        try {
1099            session = openSession();
1100
1101            StringBuilder query = new StringBuilder();
1102
1103            query.append(
1104                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1105
1106            query.append("companyId = ?");
1107
1108            query.append(" ");
1109
1110            if (obc != null) {
1111                query.append("ORDER BY ");
1112                query.append(obc.getOrderBy());
1113            }
1114
1115            else {
1116                query.append("ORDER BY ");
1117
1118                query.append("articleId ASC, ");
1119                query.append("version DESC");
1120            }
1121
1122            Query q = session.createQuery(query.toString());
1123
1124            QueryPos qPos = QueryPos.getInstance(q);
1125
1126            qPos.add(companyId);
1127
1128            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1129                    journalArticle);
1130
1131            JournalArticle[] array = new JournalArticleImpl[3];
1132
1133            array[0] = (JournalArticle)objArray[0];
1134            array[1] = (JournalArticle)objArray[1];
1135            array[2] = (JournalArticle)objArray[2];
1136
1137            return array;
1138        }
1139        catch (Exception e) {
1140            throw processException(e);
1141        }
1142        finally {
1143            closeSession(session);
1144        }
1145    }
1146
1147    public List<JournalArticle> findBySmallImageId(long smallImageId)
1148        throws SystemException {
1149        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1150        String finderClassName = JournalArticle.class.getName();
1151        String finderMethodName = "findBySmallImageId";
1152        String[] finderParams = new String[] { Long.class.getName() };
1153        Object[] finderArgs = new Object[] { new Long(smallImageId) };
1154
1155        Object result = null;
1156
1157        if (finderClassNameCacheEnabled) {
1158            result = FinderCacheUtil.getResult(finderClassName,
1159                    finderMethodName, finderParams, finderArgs, this);
1160        }
1161
1162        if (result == null) {
1163            Session session = null;
1164
1165            try {
1166                session = openSession();
1167
1168                StringBuilder query = new StringBuilder();
1169
1170                query.append(
1171                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1172
1173                query.append("smallImageId = ?");
1174
1175                query.append(" ");
1176
1177                query.append("ORDER BY ");
1178
1179                query.append("articleId ASC, ");
1180                query.append("version DESC");
1181
1182                Query q = session.createQuery(query.toString());
1183
1184                QueryPos qPos = QueryPos.getInstance(q);
1185
1186                qPos.add(smallImageId);
1187
1188                List<JournalArticle> list = q.list();
1189
1190                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1191                    finderClassName, finderMethodName, finderParams,
1192                    finderArgs, list);
1193
1194                return list;
1195            }
1196            catch (Exception e) {
1197                throw processException(e);
1198            }
1199            finally {
1200                closeSession(session);
1201            }
1202        }
1203        else {
1204            return (List<JournalArticle>)result;
1205        }
1206    }
1207
1208    public List<JournalArticle> findBySmallImageId(long smallImageId,
1209        int start, int end) throws SystemException {
1210        return findBySmallImageId(smallImageId, start, end, null);
1211    }
1212
1213    public List<JournalArticle> findBySmallImageId(long smallImageId,
1214        int start, int end, OrderByComparator obc) throws SystemException {
1215        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1216        String finderClassName = JournalArticle.class.getName();
1217        String finderMethodName = "findBySmallImageId";
1218        String[] finderParams = new String[] {
1219                Long.class.getName(),
1220                
1221                "java.lang.Integer", "java.lang.Integer",
1222                "com.liferay.portal.kernel.util.OrderByComparator"
1223            };
1224        Object[] finderArgs = new Object[] {
1225                new Long(smallImageId),
1226                
1227                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1228            };
1229
1230        Object result = null;
1231
1232        if (finderClassNameCacheEnabled) {
1233            result = FinderCacheUtil.getResult(finderClassName,
1234                    finderMethodName, finderParams, finderArgs, this);
1235        }
1236
1237        if (result == null) {
1238            Session session = null;
1239
1240            try {
1241                session = openSession();
1242
1243                StringBuilder query = new StringBuilder();
1244
1245                query.append(
1246                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1247
1248                query.append("smallImageId = ?");
1249
1250                query.append(" ");
1251
1252                if (obc != null) {
1253                    query.append("ORDER BY ");
1254                    query.append(obc.getOrderBy());
1255                }
1256
1257                else {
1258                    query.append("ORDER BY ");
1259
1260                    query.append("articleId ASC, ");
1261                    query.append("version DESC");
1262                }
1263
1264                Query q = session.createQuery(query.toString());
1265
1266                QueryPos qPos = QueryPos.getInstance(q);
1267
1268                qPos.add(smallImageId);
1269
1270                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
1271                        getDialect(), start, end);
1272
1273                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1274                    finderClassName, finderMethodName, finderParams,
1275                    finderArgs, list);
1276
1277                return list;
1278            }
1279            catch (Exception e) {
1280                throw processException(e);
1281            }
1282            finally {
1283                closeSession(session);
1284            }
1285        }
1286        else {
1287            return (List<JournalArticle>)result;
1288        }
1289    }
1290
1291    public JournalArticle findBySmallImageId_First(long smallImageId,
1292        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1293        List<JournalArticle> list = findBySmallImageId(smallImageId, 0, 1, obc);
1294
1295        if (list.size() == 0) {
1296            StringBuilder msg = new StringBuilder();
1297
1298            msg.append("No JournalArticle exists with the key {");
1299
1300            msg.append("smallImageId=" + smallImageId);
1301
1302            msg.append(StringPool.CLOSE_CURLY_BRACE);
1303
1304            throw new NoSuchArticleException(msg.toString());
1305        }
1306        else {
1307            return list.get(0);
1308        }
1309    }
1310
1311    public JournalArticle findBySmallImageId_Last(long smallImageId,
1312        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1313        int count = countBySmallImageId(smallImageId);
1314
1315        List<JournalArticle> list = findBySmallImageId(smallImageId, count - 1,
1316                count, obc);
1317
1318        if (list.size() == 0) {
1319            StringBuilder msg = new StringBuilder();
1320
1321            msg.append("No JournalArticle exists with the key {");
1322
1323            msg.append("smallImageId=" + smallImageId);
1324
1325            msg.append(StringPool.CLOSE_CURLY_BRACE);
1326
1327            throw new NoSuchArticleException(msg.toString());
1328        }
1329        else {
1330            return list.get(0);
1331        }
1332    }
1333
1334    public JournalArticle[] findBySmallImageId_PrevAndNext(long id,
1335        long smallImageId, OrderByComparator obc)
1336        throws NoSuchArticleException, SystemException {
1337        JournalArticle journalArticle = findByPrimaryKey(id);
1338
1339        int count = countBySmallImageId(smallImageId);
1340
1341        Session session = null;
1342
1343        try {
1344            session = openSession();
1345
1346            StringBuilder query = new StringBuilder();
1347
1348            query.append(
1349                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1350
1351            query.append("smallImageId = ?");
1352
1353            query.append(" ");
1354
1355            if (obc != null) {
1356                query.append("ORDER BY ");
1357                query.append(obc.getOrderBy());
1358            }
1359
1360            else {
1361                query.append("ORDER BY ");
1362
1363                query.append("articleId ASC, ");
1364                query.append("version DESC");
1365            }
1366
1367            Query q = session.createQuery(query.toString());
1368
1369            QueryPos qPos = QueryPos.getInstance(q);
1370
1371            qPos.add(smallImageId);
1372
1373            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1374                    journalArticle);
1375
1376            JournalArticle[] array = new JournalArticleImpl[3];
1377
1378            array[0] = (JournalArticle)objArray[0];
1379            array[1] = (JournalArticle)objArray[1];
1380            array[2] = (JournalArticle)objArray[2];
1381
1382            return array;
1383        }
1384        catch (Exception e) {
1385            throw processException(e);
1386        }
1387        finally {
1388            closeSession(session);
1389        }
1390    }
1391
1392    public List<JournalArticle> findByG_A(long groupId, String articleId)
1393        throws SystemException {
1394        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1395        String finderClassName = JournalArticle.class.getName();
1396        String finderMethodName = "findByG_A";
1397        String[] finderParams = new String[] {
1398                Long.class.getName(), String.class.getName()
1399            };
1400        Object[] finderArgs = new Object[] { new Long(groupId), articleId };
1401
1402        Object result = null;
1403
1404        if (finderClassNameCacheEnabled) {
1405            result = FinderCacheUtil.getResult(finderClassName,
1406                    finderMethodName, finderParams, finderArgs, this);
1407        }
1408
1409        if (result == null) {
1410            Session session = null;
1411
1412            try {
1413                session = openSession();
1414
1415                StringBuilder query = new StringBuilder();
1416
1417                query.append(
1418                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1419
1420                query.append("groupId = ?");
1421
1422                query.append(" AND ");
1423
1424                if (articleId == null) {
1425                    query.append("articleId IS NULL");
1426                }
1427                else {
1428                    query.append("articleId = ?");
1429                }
1430
1431                query.append(" ");
1432
1433                query.append("ORDER BY ");
1434
1435                query.append("articleId ASC, ");
1436                query.append("version DESC");
1437
1438                Query q = session.createQuery(query.toString());
1439
1440                QueryPos qPos = QueryPos.getInstance(q);
1441
1442                qPos.add(groupId);
1443
1444                if (articleId != null) {
1445                    qPos.add(articleId);
1446                }
1447
1448                List<JournalArticle> list = q.list();
1449
1450                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1451                    finderClassName, finderMethodName, finderParams,
1452                    finderArgs, list);
1453
1454                return list;
1455            }
1456            catch (Exception e) {
1457                throw processException(e);
1458            }
1459            finally {
1460                closeSession(session);
1461            }
1462        }
1463        else {
1464            return (List<JournalArticle>)result;
1465        }
1466    }
1467
1468    public List<JournalArticle> findByG_A(long groupId, String articleId,
1469        int start, int end) throws SystemException {
1470        return findByG_A(groupId, articleId, start, end, null);
1471    }
1472
1473    public List<JournalArticle> findByG_A(long groupId, String articleId,
1474        int start, int end, OrderByComparator obc) throws SystemException {
1475        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1476        String finderClassName = JournalArticle.class.getName();
1477        String finderMethodName = "findByG_A";
1478        String[] finderParams = new String[] {
1479                Long.class.getName(), String.class.getName(),
1480                
1481                "java.lang.Integer", "java.lang.Integer",
1482                "com.liferay.portal.kernel.util.OrderByComparator"
1483            };
1484        Object[] finderArgs = new Object[] {
1485                new Long(groupId),
1486                
1487                articleId,
1488                
1489                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1490            };
1491
1492        Object result = null;
1493
1494        if (finderClassNameCacheEnabled) {
1495            result = FinderCacheUtil.getResult(finderClassName,
1496                    finderMethodName, finderParams, finderArgs, this);
1497        }
1498
1499        if (result == null) {
1500            Session session = null;
1501
1502            try {
1503                session = openSession();
1504
1505                StringBuilder query = new StringBuilder();
1506
1507                query.append(
1508                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1509
1510                query.append("groupId = ?");
1511
1512                query.append(" AND ");
1513
1514                if (articleId == null) {
1515                    query.append("articleId IS NULL");
1516                }
1517                else {
1518                    query.append("articleId = ?");
1519                }
1520
1521                query.append(" ");
1522
1523                if (obc != null) {
1524                    query.append("ORDER BY ");
1525                    query.append(obc.getOrderBy());
1526                }
1527
1528                else {
1529                    query.append("ORDER BY ");
1530
1531                    query.append("articleId ASC, ");
1532                    query.append("version DESC");
1533                }
1534
1535                Query q = session.createQuery(query.toString());
1536
1537                QueryPos qPos = QueryPos.getInstance(q);
1538
1539                qPos.add(groupId);
1540
1541                if (articleId != null) {
1542                    qPos.add(articleId);
1543                }
1544
1545                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
1546                        getDialect(), start, end);
1547
1548                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1549                    finderClassName, finderMethodName, finderParams,
1550                    finderArgs, list);
1551
1552                return list;
1553            }
1554            catch (Exception e) {
1555                throw processException(e);
1556            }
1557            finally {
1558                closeSession(session);
1559            }
1560        }
1561        else {
1562            return (List<JournalArticle>)result;
1563        }
1564    }
1565
1566    public JournalArticle findByG_A_First(long groupId, String articleId,
1567        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1568        List<JournalArticle> list = findByG_A(groupId, articleId, 0, 1, obc);
1569
1570        if (list.size() == 0) {
1571            StringBuilder msg = new StringBuilder();
1572
1573            msg.append("No JournalArticle exists with the key {");
1574
1575            msg.append("groupId=" + groupId);
1576
1577            msg.append(", ");
1578            msg.append("articleId=" + articleId);
1579
1580            msg.append(StringPool.CLOSE_CURLY_BRACE);
1581
1582            throw new NoSuchArticleException(msg.toString());
1583        }
1584        else {
1585            return list.get(0);
1586        }
1587    }
1588
1589    public JournalArticle findByG_A_Last(long groupId, String articleId,
1590        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1591        int count = countByG_A(groupId, articleId);
1592
1593        List<JournalArticle> list = findByG_A(groupId, articleId, count - 1,
1594                count, obc);
1595
1596        if (list.size() == 0) {
1597            StringBuilder msg = new StringBuilder();
1598
1599            msg.append("No JournalArticle exists with the key {");
1600
1601            msg.append("groupId=" + groupId);
1602
1603            msg.append(", ");
1604            msg.append("articleId=" + articleId);
1605
1606            msg.append(StringPool.CLOSE_CURLY_BRACE);
1607
1608            throw new NoSuchArticleException(msg.toString());
1609        }
1610        else {
1611            return list.get(0);
1612        }
1613    }
1614
1615    public JournalArticle[] findByG_A_PrevAndNext(long id, long groupId,
1616        String articleId, OrderByComparator obc)
1617        throws NoSuchArticleException, SystemException {
1618        JournalArticle journalArticle = findByPrimaryKey(id);
1619
1620        int count = countByG_A(groupId, articleId);
1621
1622        Session session = null;
1623
1624        try {
1625            session = openSession();
1626
1627            StringBuilder query = new StringBuilder();
1628
1629            query.append(
1630                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1631
1632            query.append("groupId = ?");
1633
1634            query.append(" AND ");
1635
1636            if (articleId == null) {
1637                query.append("articleId IS NULL");
1638            }
1639            else {
1640                query.append("articleId = ?");
1641            }
1642
1643            query.append(" ");
1644
1645            if (obc != null) {
1646                query.append("ORDER BY ");
1647                query.append(obc.getOrderBy());
1648            }
1649
1650            else {
1651                query.append("ORDER BY ");
1652
1653                query.append("articleId ASC, ");
1654                query.append("version DESC");
1655            }
1656
1657            Query q = session.createQuery(query.toString());
1658
1659            QueryPos qPos = QueryPos.getInstance(q);
1660
1661            qPos.add(groupId);
1662
1663            if (articleId != null) {
1664                qPos.add(articleId);
1665            }
1666
1667            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1668                    journalArticle);
1669
1670            JournalArticle[] array = new JournalArticleImpl[3];
1671
1672            array[0] = (JournalArticle)objArray[0];
1673            array[1] = (JournalArticle)objArray[1];
1674            array[2] = (JournalArticle)objArray[2];
1675
1676            return array;
1677        }
1678        catch (Exception e) {
1679            throw processException(e);
1680        }
1681        finally {
1682            closeSession(session);
1683        }
1684    }
1685
1686    public List<JournalArticle> findByG_S(long groupId, String structureId)
1687        throws SystemException {
1688        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1689        String finderClassName = JournalArticle.class.getName();
1690        String finderMethodName = "findByG_S";
1691        String[] finderParams = new String[] {
1692                Long.class.getName(), String.class.getName()
1693            };
1694        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
1695
1696        Object result = null;
1697
1698        if (finderClassNameCacheEnabled) {
1699            result = FinderCacheUtil.getResult(finderClassName,
1700                    finderMethodName, finderParams, finderArgs, this);
1701        }
1702
1703        if (result == null) {
1704            Session session = null;
1705
1706            try {
1707                session = openSession();
1708
1709                StringBuilder query = new StringBuilder();
1710
1711                query.append(
1712                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1713
1714                query.append("groupId = ?");
1715
1716                query.append(" AND ");
1717
1718                if (structureId == null) {
1719                    query.append("structureId IS NULL");
1720                }
1721                else {
1722                    query.append("structureId = ?");
1723                }
1724
1725                query.append(" ");
1726
1727                query.append("ORDER BY ");
1728
1729                query.append("articleId ASC, ");
1730                query.append("version DESC");
1731
1732                Query q = session.createQuery(query.toString());
1733
1734                QueryPos qPos = QueryPos.getInstance(q);
1735
1736                qPos.add(groupId);
1737
1738                if (structureId != null) {
1739                    qPos.add(structureId);
1740                }
1741
1742                List<JournalArticle> list = q.list();
1743
1744                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1745                    finderClassName, finderMethodName, finderParams,
1746                    finderArgs, list);
1747
1748                return list;
1749            }
1750            catch (Exception e) {
1751                throw processException(e);
1752            }
1753            finally {
1754                closeSession(session);
1755            }
1756        }
1757        else {
1758            return (List<JournalArticle>)result;
1759        }
1760    }
1761
1762    public List<JournalArticle> findByG_S(long groupId, String structureId,
1763        int start, int end) throws SystemException {
1764        return findByG_S(groupId, structureId, start, end, null);
1765    }
1766
1767    public List<JournalArticle> findByG_S(long groupId, String structureId,
1768        int start, int end, OrderByComparator obc) throws SystemException {
1769        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1770        String finderClassName = JournalArticle.class.getName();
1771        String finderMethodName = "findByG_S";
1772        String[] finderParams = new String[] {
1773                Long.class.getName(), String.class.getName(),
1774                
1775                "java.lang.Integer", "java.lang.Integer",
1776                "com.liferay.portal.kernel.util.OrderByComparator"
1777            };
1778        Object[] finderArgs = new Object[] {
1779                new Long(groupId),
1780                
1781                structureId,
1782                
1783                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1784            };
1785
1786        Object result = null;
1787
1788        if (finderClassNameCacheEnabled) {
1789            result = FinderCacheUtil.getResult(finderClassName,
1790                    finderMethodName, finderParams, finderArgs, this);
1791        }
1792
1793        if (result == null) {
1794            Session session = null;
1795
1796            try {
1797                session = openSession();
1798
1799                StringBuilder query = new StringBuilder();
1800
1801                query.append(
1802                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1803
1804                query.append("groupId = ?");
1805
1806                query.append(" AND ");
1807
1808                if (structureId == null) {
1809                    query.append("structureId IS NULL");
1810                }
1811                else {
1812                    query.append("structureId = ?");
1813                }
1814
1815                query.append(" ");
1816
1817                if (obc != null) {
1818                    query.append("ORDER BY ");
1819                    query.append(obc.getOrderBy());
1820                }
1821
1822                else {
1823                    query.append("ORDER BY ");
1824
1825                    query.append("articleId ASC, ");
1826                    query.append("version DESC");
1827                }
1828
1829                Query q = session.createQuery(query.toString());
1830
1831                QueryPos qPos = QueryPos.getInstance(q);
1832
1833                qPos.add(groupId);
1834
1835                if (structureId != null) {
1836                    qPos.add(structureId);
1837                }
1838
1839                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
1840                        getDialect(), start, end);
1841
1842                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1843                    finderClassName, finderMethodName, finderParams,
1844                    finderArgs, list);
1845
1846                return list;
1847            }
1848            catch (Exception e) {
1849                throw processException(e);
1850            }
1851            finally {
1852                closeSession(session);
1853            }
1854        }
1855        else {
1856            return (List<JournalArticle>)result;
1857        }
1858    }
1859
1860    public JournalArticle findByG_S_First(long groupId, String structureId,
1861        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1862        List<JournalArticle> list = findByG_S(groupId, structureId, 0, 1, obc);
1863
1864        if (list.size() == 0) {
1865            StringBuilder msg = new StringBuilder();
1866
1867            msg.append("No JournalArticle exists with the key {");
1868
1869            msg.append("groupId=" + groupId);
1870
1871            msg.append(", ");
1872            msg.append("structureId=" + structureId);
1873
1874            msg.append(StringPool.CLOSE_CURLY_BRACE);
1875
1876            throw new NoSuchArticleException(msg.toString());
1877        }
1878        else {
1879            return list.get(0);
1880        }
1881    }
1882
1883    public JournalArticle findByG_S_Last(long groupId, String structureId,
1884        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1885        int count = countByG_S(groupId, structureId);
1886
1887        List<JournalArticle> list = findByG_S(groupId, structureId, count - 1,
1888                count, obc);
1889
1890        if (list.size() == 0) {
1891            StringBuilder msg = new StringBuilder();
1892
1893            msg.append("No JournalArticle exists with the key {");
1894
1895            msg.append("groupId=" + groupId);
1896
1897            msg.append(", ");
1898            msg.append("structureId=" + structureId);
1899
1900            msg.append(StringPool.CLOSE_CURLY_BRACE);
1901
1902            throw new NoSuchArticleException(msg.toString());
1903        }
1904        else {
1905            return list.get(0);
1906        }
1907    }
1908
1909    public JournalArticle[] findByG_S_PrevAndNext(long id, long groupId,
1910        String structureId, OrderByComparator obc)
1911        throws NoSuchArticleException, SystemException {
1912        JournalArticle journalArticle = findByPrimaryKey(id);
1913
1914        int count = countByG_S(groupId, structureId);
1915
1916        Session session = null;
1917
1918        try {
1919            session = openSession();
1920
1921            StringBuilder query = new StringBuilder();
1922
1923            query.append(
1924                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1925
1926            query.append("groupId = ?");
1927
1928            query.append(" AND ");
1929
1930            if (structureId == null) {
1931                query.append("structureId IS NULL");
1932            }
1933            else {
1934                query.append("structureId = ?");
1935            }
1936
1937            query.append(" ");
1938
1939            if (obc != null) {
1940                query.append("ORDER BY ");
1941                query.append(obc.getOrderBy());
1942            }
1943
1944            else {
1945                query.append("ORDER BY ");
1946
1947                query.append("articleId ASC, ");
1948                query.append("version DESC");
1949            }
1950
1951            Query q = session.createQuery(query.toString());
1952
1953            QueryPos qPos = QueryPos.getInstance(q);
1954
1955            qPos.add(groupId);
1956
1957            if (structureId != null) {
1958                qPos.add(structureId);
1959            }
1960
1961            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1962                    journalArticle);
1963
1964            JournalArticle[] array = new JournalArticleImpl[3];
1965
1966            array[0] = (JournalArticle)objArray[0];
1967            array[1] = (JournalArticle)objArray[1];
1968            array[2] = (JournalArticle)objArray[2];
1969
1970            return array;
1971        }
1972        catch (Exception e) {
1973            throw processException(e);
1974        }
1975        finally {
1976            closeSession(session);
1977        }
1978    }
1979
1980    public List<JournalArticle> findByG_T(long groupId, String templateId)
1981        throws SystemException {
1982        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
1983        String finderClassName = JournalArticle.class.getName();
1984        String finderMethodName = "findByG_T";
1985        String[] finderParams = new String[] {
1986                Long.class.getName(), String.class.getName()
1987            };
1988        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
1989
1990        Object result = null;
1991
1992        if (finderClassNameCacheEnabled) {
1993            result = FinderCacheUtil.getResult(finderClassName,
1994                    finderMethodName, finderParams, finderArgs, this);
1995        }
1996
1997        if (result == null) {
1998            Session session = null;
1999
2000            try {
2001                session = openSession();
2002
2003                StringBuilder query = new StringBuilder();
2004
2005                query.append(
2006                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2007
2008                query.append("groupId = ?");
2009
2010                query.append(" AND ");
2011
2012                if (templateId == null) {
2013                    query.append("templateId IS NULL");
2014                }
2015                else {
2016                    query.append("templateId = ?");
2017                }
2018
2019                query.append(" ");
2020
2021                query.append("ORDER BY ");
2022
2023                query.append("articleId ASC, ");
2024                query.append("version DESC");
2025
2026                Query q = session.createQuery(query.toString());
2027
2028                QueryPos qPos = QueryPos.getInstance(q);
2029
2030                qPos.add(groupId);
2031
2032                if (templateId != null) {
2033                    qPos.add(templateId);
2034                }
2035
2036                List<JournalArticle> list = q.list();
2037
2038                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2039                    finderClassName, finderMethodName, finderParams,
2040                    finderArgs, list);
2041
2042                return list;
2043            }
2044            catch (Exception e) {
2045                throw processException(e);
2046            }
2047            finally {
2048                closeSession(session);
2049            }
2050        }
2051        else {
2052            return (List<JournalArticle>)result;
2053        }
2054    }
2055
2056    public List<JournalArticle> findByG_T(long groupId, String templateId,
2057        int start, int end) throws SystemException {
2058        return findByG_T(groupId, templateId, start, end, null);
2059    }
2060
2061    public List<JournalArticle> findByG_T(long groupId, String templateId,
2062        int start, int end, OrderByComparator obc) throws SystemException {
2063        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2064        String finderClassName = JournalArticle.class.getName();
2065        String finderMethodName = "findByG_T";
2066        String[] finderParams = new String[] {
2067                Long.class.getName(), String.class.getName(),
2068                
2069                "java.lang.Integer", "java.lang.Integer",
2070                "com.liferay.portal.kernel.util.OrderByComparator"
2071            };
2072        Object[] finderArgs = new Object[] {
2073                new Long(groupId),
2074                
2075                templateId,
2076                
2077                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2078            };
2079
2080        Object result = null;
2081
2082        if (finderClassNameCacheEnabled) {
2083            result = FinderCacheUtil.getResult(finderClassName,
2084                    finderMethodName, finderParams, finderArgs, this);
2085        }
2086
2087        if (result == null) {
2088            Session session = null;
2089
2090            try {
2091                session = openSession();
2092
2093                StringBuilder query = new StringBuilder();
2094
2095                query.append(
2096                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2097
2098                query.append("groupId = ?");
2099
2100                query.append(" AND ");
2101
2102                if (templateId == null) {
2103                    query.append("templateId IS NULL");
2104                }
2105                else {
2106                    query.append("templateId = ?");
2107                }
2108
2109                query.append(" ");
2110
2111                if (obc != null) {
2112                    query.append("ORDER BY ");
2113                    query.append(obc.getOrderBy());
2114                }
2115
2116                else {
2117                    query.append("ORDER BY ");
2118
2119                    query.append("articleId ASC, ");
2120                    query.append("version DESC");
2121                }
2122
2123                Query q = session.createQuery(query.toString());
2124
2125                QueryPos qPos = QueryPos.getInstance(q);
2126
2127                qPos.add(groupId);
2128
2129                if (templateId != null) {
2130                    qPos.add(templateId);
2131                }
2132
2133                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
2134                        getDialect(), start, end);
2135
2136                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2137                    finderClassName, finderMethodName, finderParams,
2138                    finderArgs, list);
2139
2140                return list;
2141            }
2142            catch (Exception e) {
2143                throw processException(e);
2144            }
2145            finally {
2146                closeSession(session);
2147            }
2148        }
2149        else {
2150            return (List<JournalArticle>)result;
2151        }
2152    }
2153
2154    public JournalArticle findByG_T_First(long groupId, String templateId,
2155        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2156        List<JournalArticle> list = findByG_T(groupId, templateId, 0, 1, obc);
2157
2158        if (list.size() == 0) {
2159            StringBuilder msg = new StringBuilder();
2160
2161            msg.append("No JournalArticle exists with the key {");
2162
2163            msg.append("groupId=" + groupId);
2164
2165            msg.append(", ");
2166            msg.append("templateId=" + templateId);
2167
2168            msg.append(StringPool.CLOSE_CURLY_BRACE);
2169
2170            throw new NoSuchArticleException(msg.toString());
2171        }
2172        else {
2173            return list.get(0);
2174        }
2175    }
2176
2177    public JournalArticle findByG_T_Last(long groupId, String templateId,
2178        OrderByComparator obc) throws NoSuchArticleException, SystemException {
2179        int count = countByG_T(groupId, templateId);
2180
2181        List<JournalArticle> list = findByG_T(groupId, templateId, count - 1,
2182                count, obc);
2183
2184        if (list.size() == 0) {
2185            StringBuilder msg = new StringBuilder();
2186
2187            msg.append("No JournalArticle exists with the key {");
2188
2189            msg.append("groupId=" + groupId);
2190
2191            msg.append(", ");
2192            msg.append("templateId=" + templateId);
2193
2194            msg.append(StringPool.CLOSE_CURLY_BRACE);
2195
2196            throw new NoSuchArticleException(msg.toString());
2197        }
2198        else {
2199            return list.get(0);
2200        }
2201    }
2202
2203    public JournalArticle[] findByG_T_PrevAndNext(long id, long groupId,
2204        String templateId, OrderByComparator obc)
2205        throws NoSuchArticleException, SystemException {
2206        JournalArticle journalArticle = findByPrimaryKey(id);
2207
2208        int count = countByG_T(groupId, templateId);
2209
2210        Session session = null;
2211
2212        try {
2213            session = openSession();
2214
2215            StringBuilder query = new StringBuilder();
2216
2217            query.append(
2218                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2219
2220            query.append("groupId = ?");
2221
2222            query.append(" AND ");
2223
2224            if (templateId == null) {
2225                query.append("templateId IS NULL");
2226            }
2227            else {
2228                query.append("templateId = ?");
2229            }
2230
2231            query.append(" ");
2232
2233            if (obc != null) {
2234                query.append("ORDER BY ");
2235                query.append(obc.getOrderBy());
2236            }
2237
2238            else {
2239                query.append("ORDER BY ");
2240
2241                query.append("articleId ASC, ");
2242                query.append("version DESC");
2243            }
2244
2245            Query q = session.createQuery(query.toString());
2246
2247            QueryPos qPos = QueryPos.getInstance(q);
2248
2249            qPos.add(groupId);
2250
2251            if (templateId != null) {
2252                qPos.add(templateId);
2253            }
2254
2255            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2256                    journalArticle);
2257
2258            JournalArticle[] array = new JournalArticleImpl[3];
2259
2260            array[0] = (JournalArticle)objArray[0];
2261            array[1] = (JournalArticle)objArray[1];
2262            array[2] = (JournalArticle)objArray[2];
2263
2264            return array;
2265        }
2266        catch (Exception e) {
2267            throw processException(e);
2268        }
2269        finally {
2270            closeSession(session);
2271        }
2272    }
2273
2274    public JournalArticle findByG_A_V(long groupId, String articleId,
2275        double version) throws NoSuchArticleException, SystemException {
2276        JournalArticle journalArticle = fetchByG_A_V(groupId, articleId, version);
2277
2278        if (journalArticle == null) {
2279            StringBuilder msg = new StringBuilder();
2280
2281            msg.append("No JournalArticle exists with the key {");
2282
2283            msg.append("groupId=" + groupId);
2284
2285            msg.append(", ");
2286            msg.append("articleId=" + articleId);
2287
2288            msg.append(", ");
2289            msg.append("version=" + version);
2290
2291            msg.append(StringPool.CLOSE_CURLY_BRACE);
2292
2293            if (_log.isWarnEnabled()) {
2294                _log.warn(msg.toString());
2295            }
2296
2297            throw new NoSuchArticleException(msg.toString());
2298        }
2299
2300        return journalArticle;
2301    }
2302
2303    public JournalArticle fetchByG_A_V(long groupId, String articleId,
2304        double version) throws SystemException {
2305        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2306        String finderClassName = JournalArticle.class.getName();
2307        String finderMethodName = "fetchByG_A_V";
2308        String[] finderParams = new String[] {
2309                Long.class.getName(), String.class.getName(),
2310                Double.class.getName()
2311            };
2312        Object[] finderArgs = new Object[] {
2313                new Long(groupId),
2314                
2315                articleId, new Double(version)
2316            };
2317
2318        Object result = null;
2319
2320        if (finderClassNameCacheEnabled) {
2321            result = FinderCacheUtil.getResult(finderClassName,
2322                    finderMethodName, finderParams, finderArgs, this);
2323        }
2324
2325        if (result == null) {
2326            Session session = null;
2327
2328            try {
2329                session = openSession();
2330
2331                StringBuilder query = new StringBuilder();
2332
2333                query.append(
2334                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2335
2336                query.append("groupId = ?");
2337
2338                query.append(" AND ");
2339
2340                if (articleId == null) {
2341                    query.append("articleId IS NULL");
2342                }
2343                else {
2344                    query.append("articleId = ?");
2345                }
2346
2347                query.append(" AND ");
2348
2349                query.append("version = ?");
2350
2351                query.append(" ");
2352
2353                query.append("ORDER BY ");
2354
2355                query.append("articleId ASC, ");
2356                query.append("version DESC");
2357
2358                Query q = session.createQuery(query.toString());
2359
2360                QueryPos qPos = QueryPos.getInstance(q);
2361
2362                qPos.add(groupId);
2363
2364                if (articleId != null) {
2365                    qPos.add(articleId);
2366                }
2367
2368                qPos.add(version);
2369
2370                List<JournalArticle> list = q.list();
2371
2372                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2373                    finderClassName, finderMethodName, finderParams,
2374                    finderArgs, list);
2375
2376                if (list.size() == 0) {
2377                    return null;
2378                }
2379                else {
2380                    return list.get(0);
2381                }
2382            }
2383            catch (Exception e) {
2384                throw processException(e);
2385            }
2386            finally {
2387                closeSession(session);
2388            }
2389        }
2390        else {
2391            List<JournalArticle> list = (List<JournalArticle>)result;
2392
2393            if (list.size() == 0) {
2394                return null;
2395            }
2396            else {
2397                return list.get(0);
2398            }
2399        }
2400    }
2401
2402    public List<JournalArticle> findByG_A_A(long groupId, String articleId,
2403        boolean approved) throws SystemException {
2404        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2405        String finderClassName = JournalArticle.class.getName();
2406        String finderMethodName = "findByG_A_A";
2407        String[] finderParams = new String[] {
2408                Long.class.getName(), String.class.getName(),
2409                Boolean.class.getName()
2410            };
2411        Object[] finderArgs = new Object[] {
2412                new Long(groupId),
2413                
2414                articleId, Boolean.valueOf(approved)
2415            };
2416
2417        Object result = null;
2418
2419        if (finderClassNameCacheEnabled) {
2420            result = FinderCacheUtil.getResult(finderClassName,
2421                    finderMethodName, finderParams, finderArgs, this);
2422        }
2423
2424        if (result == null) {
2425            Session session = null;
2426
2427            try {
2428                session = openSession();
2429
2430                StringBuilder query = new StringBuilder();
2431
2432                query.append(
2433                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2434
2435                query.append("groupId = ?");
2436
2437                query.append(" AND ");
2438
2439                if (articleId == null) {
2440                    query.append("articleId IS NULL");
2441                }
2442                else {
2443                    query.append("articleId = ?");
2444                }
2445
2446                query.append(" AND ");
2447
2448                query.append("approved = ?");
2449
2450                query.append(" ");
2451
2452                query.append("ORDER BY ");
2453
2454                query.append("articleId ASC, ");
2455                query.append("version DESC");
2456
2457                Query q = session.createQuery(query.toString());
2458
2459                QueryPos qPos = QueryPos.getInstance(q);
2460
2461                qPos.add(groupId);
2462
2463                if (articleId != null) {
2464                    qPos.add(articleId);
2465                }
2466
2467                qPos.add(approved);
2468
2469                List<JournalArticle> list = q.list();
2470
2471                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2472                    finderClassName, finderMethodName, finderParams,
2473                    finderArgs, list);
2474
2475                return list;
2476            }
2477            catch (Exception e) {
2478                throw processException(e);
2479            }
2480            finally {
2481                closeSession(session);
2482            }
2483        }
2484        else {
2485            return (List<JournalArticle>)result;
2486        }
2487    }
2488
2489    public List<JournalArticle> findByG_A_A(long groupId, String articleId,
2490        boolean approved, int start, int end) throws SystemException {
2491        return findByG_A_A(groupId, articleId, approved, start, end, null);
2492    }
2493
2494    public List<JournalArticle> findByG_A_A(long groupId, String articleId,
2495        boolean approved, int start, int end, OrderByComparator obc)
2496        throws SystemException {
2497        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2498        String finderClassName = JournalArticle.class.getName();
2499        String finderMethodName = "findByG_A_A";
2500        String[] finderParams = new String[] {
2501                Long.class.getName(), String.class.getName(),
2502                Boolean.class.getName(),
2503                
2504                "java.lang.Integer", "java.lang.Integer",
2505                "com.liferay.portal.kernel.util.OrderByComparator"
2506            };
2507        Object[] finderArgs = new Object[] {
2508                new Long(groupId),
2509                
2510                articleId, Boolean.valueOf(approved),
2511                
2512                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2513            };
2514
2515        Object result = null;
2516
2517        if (finderClassNameCacheEnabled) {
2518            result = FinderCacheUtil.getResult(finderClassName,
2519                    finderMethodName, finderParams, finderArgs, this);
2520        }
2521
2522        if (result == null) {
2523            Session session = null;
2524
2525            try {
2526                session = openSession();
2527
2528                StringBuilder query = new StringBuilder();
2529
2530                query.append(
2531                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2532
2533                query.append("groupId = ?");
2534
2535                query.append(" AND ");
2536
2537                if (articleId == null) {
2538                    query.append("articleId IS NULL");
2539                }
2540                else {
2541                    query.append("articleId = ?");
2542                }
2543
2544                query.append(" AND ");
2545
2546                query.append("approved = ?");
2547
2548                query.append(" ");
2549
2550                if (obc != null) {
2551                    query.append("ORDER BY ");
2552                    query.append(obc.getOrderBy());
2553                }
2554
2555                else {
2556                    query.append("ORDER BY ");
2557
2558                    query.append("articleId ASC, ");
2559                    query.append("version DESC");
2560                }
2561
2562                Query q = session.createQuery(query.toString());
2563
2564                QueryPos qPos = QueryPos.getInstance(q);
2565
2566                qPos.add(groupId);
2567
2568                if (articleId != null) {
2569                    qPos.add(articleId);
2570                }
2571
2572                qPos.add(approved);
2573
2574                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
2575                        getDialect(), start, end);
2576
2577                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2578                    finderClassName, finderMethodName, finderParams,
2579                    finderArgs, list);
2580
2581                return list;
2582            }
2583            catch (Exception e) {
2584                throw processException(e);
2585            }
2586            finally {
2587                closeSession(session);
2588            }
2589        }
2590        else {
2591            return (List<JournalArticle>)result;
2592        }
2593    }
2594
2595    public JournalArticle findByG_A_A_First(long groupId, String articleId,
2596        boolean approved, OrderByComparator obc)
2597        throws NoSuchArticleException, SystemException {
2598        List<JournalArticle> list = findByG_A_A(groupId, articleId, approved,
2599                0, 1, obc);
2600
2601        if (list.size() == 0) {
2602            StringBuilder msg = new StringBuilder();
2603
2604            msg.append("No JournalArticle exists with the key {");
2605
2606            msg.append("groupId=" + groupId);
2607
2608            msg.append(", ");
2609            msg.append("articleId=" + articleId);
2610
2611            msg.append(", ");
2612            msg.append("approved=" + approved);
2613
2614            msg.append(StringPool.CLOSE_CURLY_BRACE);
2615
2616            throw new NoSuchArticleException(msg.toString());
2617        }
2618        else {
2619            return list.get(0);
2620        }
2621    }
2622
2623    public JournalArticle findByG_A_A_Last(long groupId, String articleId,
2624        boolean approved, OrderByComparator obc)
2625        throws NoSuchArticleException, SystemException {
2626        int count = countByG_A_A(groupId, articleId, approved);
2627
2628        List<JournalArticle> list = findByG_A_A(groupId, articleId, approved,
2629                count - 1, count, obc);
2630
2631        if (list.size() == 0) {
2632            StringBuilder msg = new StringBuilder();
2633
2634            msg.append("No JournalArticle exists with the key {");
2635
2636            msg.append("groupId=" + groupId);
2637
2638            msg.append(", ");
2639            msg.append("articleId=" + articleId);
2640
2641            msg.append(", ");
2642            msg.append("approved=" + approved);
2643
2644            msg.append(StringPool.CLOSE_CURLY_BRACE);
2645
2646            throw new NoSuchArticleException(msg.toString());
2647        }
2648        else {
2649            return list.get(0);
2650        }
2651    }
2652
2653    public JournalArticle[] findByG_A_A_PrevAndNext(long id, long groupId,
2654        String articleId, boolean approved, OrderByComparator obc)
2655        throws NoSuchArticleException, SystemException {
2656        JournalArticle journalArticle = findByPrimaryKey(id);
2657
2658        int count = countByG_A_A(groupId, articleId, approved);
2659
2660        Session session = null;
2661
2662        try {
2663            session = openSession();
2664
2665            StringBuilder query = new StringBuilder();
2666
2667            query.append(
2668                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2669
2670            query.append("groupId = ?");
2671
2672            query.append(" AND ");
2673
2674            if (articleId == null) {
2675                query.append("articleId IS NULL");
2676            }
2677            else {
2678                query.append("articleId = ?");
2679            }
2680
2681            query.append(" AND ");
2682
2683            query.append("approved = ?");
2684
2685            query.append(" ");
2686
2687            if (obc != null) {
2688                query.append("ORDER BY ");
2689                query.append(obc.getOrderBy());
2690            }
2691
2692            else {
2693                query.append("ORDER BY ");
2694
2695                query.append("articleId ASC, ");
2696                query.append("version DESC");
2697            }
2698
2699            Query q = session.createQuery(query.toString());
2700
2701            QueryPos qPos = QueryPos.getInstance(q);
2702
2703            qPos.add(groupId);
2704
2705            if (articleId != null) {
2706                qPos.add(articleId);
2707            }
2708
2709            qPos.add(approved);
2710
2711            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
2712                    journalArticle);
2713
2714            JournalArticle[] array = new JournalArticleImpl[3];
2715
2716            array[0] = (JournalArticle)objArray[0];
2717            array[1] = (JournalArticle)objArray[1];
2718            array[2] = (JournalArticle)objArray[2];
2719
2720            return array;
2721        }
2722        catch (Exception e) {
2723            throw processException(e);
2724        }
2725        finally {
2726            closeSession(session);
2727        }
2728    }
2729
2730    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
2731        throws SystemException {
2732        Session session = null;
2733
2734        try {
2735            session = openSession();
2736
2737            dynamicQuery.compile(session);
2738
2739            return dynamicQuery.list();
2740        }
2741        catch (Exception e) {
2742            throw processException(e);
2743        }
2744        finally {
2745            closeSession(session);
2746        }
2747    }
2748
2749    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
2750        int start, int end) throws SystemException {
2751        Session session = null;
2752
2753        try {
2754            session = openSession();
2755
2756            dynamicQuery.setLimit(start, end);
2757
2758            dynamicQuery.compile(session);
2759
2760            return dynamicQuery.list();
2761        }
2762        catch (Exception e) {
2763            throw processException(e);
2764        }
2765        finally {
2766            closeSession(session);
2767        }
2768    }
2769
2770    public List<JournalArticle> findAll() throws SystemException {
2771        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2772    }
2773
2774    public List<JournalArticle> findAll(int start, int end)
2775        throws SystemException {
2776        return findAll(start, end, null);
2777    }
2778
2779    public List<JournalArticle> findAll(int start, int end,
2780        OrderByComparator obc) throws SystemException {
2781        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2782        String finderClassName = JournalArticle.class.getName();
2783        String finderMethodName = "findAll";
2784        String[] finderParams = new String[] {
2785                "java.lang.Integer", "java.lang.Integer",
2786                "com.liferay.portal.kernel.util.OrderByComparator"
2787            };
2788        Object[] finderArgs = new Object[] {
2789                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
2790            };
2791
2792        Object result = null;
2793
2794        if (finderClassNameCacheEnabled) {
2795            result = FinderCacheUtil.getResult(finderClassName,
2796                    finderMethodName, finderParams, finderArgs, this);
2797        }
2798
2799        if (result == null) {
2800            Session session = null;
2801
2802            try {
2803                session = openSession();
2804
2805                StringBuilder query = new StringBuilder();
2806
2807                query.append(
2808                    "FROM com.liferay.portlet.journal.model.JournalArticle ");
2809
2810                if (obc != null) {
2811                    query.append("ORDER BY ");
2812                    query.append(obc.getOrderBy());
2813                }
2814
2815                else {
2816                    query.append("ORDER BY ");
2817
2818                    query.append("articleId ASC, ");
2819                    query.append("version DESC");
2820                }
2821
2822                Query q = session.createQuery(query.toString());
2823
2824                List<JournalArticle> list = (List<JournalArticle>)QueryUtil.list(q,
2825                        getDialect(), start, end);
2826
2827                if (obc == null) {
2828                    Collections.sort(list);
2829                }
2830
2831                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2832                    finderClassName, finderMethodName, finderParams,
2833                    finderArgs, list);
2834
2835                return list;
2836            }
2837            catch (Exception e) {
2838                throw processException(e);
2839            }
2840            finally {
2841                closeSession(session);
2842            }
2843        }
2844        else {
2845            return (List<JournalArticle>)result;
2846        }
2847    }
2848
2849    public void removeByUuid(String uuid) throws SystemException {
2850        for (JournalArticle journalArticle : findByUuid(uuid)) {
2851            remove(journalArticle);
2852        }
2853    }
2854
2855    public void removeByUUID_G(String uuid, long groupId)
2856        throws NoSuchArticleException, SystemException {
2857        JournalArticle journalArticle = findByUUID_G(uuid, groupId);
2858
2859        remove(journalArticle);
2860    }
2861
2862    public void removeByGroupId(long groupId) throws SystemException {
2863        for (JournalArticle journalArticle : findByGroupId(groupId)) {
2864            remove(journalArticle);
2865        }
2866    }
2867
2868    public void removeByCompanyId(long companyId) throws SystemException {
2869        for (JournalArticle journalArticle : findByCompanyId(companyId)) {
2870            remove(journalArticle);
2871        }
2872    }
2873
2874    public void removeBySmallImageId(long smallImageId)
2875        throws SystemException {
2876        for (JournalArticle journalArticle : findBySmallImageId(smallImageId)) {
2877            remove(journalArticle);
2878        }
2879    }
2880
2881    public void removeByG_A(long groupId, String articleId)
2882        throws SystemException {
2883        for (JournalArticle journalArticle : findByG_A(groupId, articleId)) {
2884            remove(journalArticle);
2885        }
2886    }
2887
2888    public void removeByG_S(long groupId, String structureId)
2889        throws SystemException {
2890        for (JournalArticle journalArticle : findByG_S(groupId, structureId)) {
2891            remove(journalArticle);
2892        }
2893    }
2894
2895    public void removeByG_T(long groupId, String templateId)
2896        throws SystemException {
2897        for (JournalArticle journalArticle : findByG_T(groupId, templateId)) {
2898            remove(journalArticle);
2899        }
2900    }
2901
2902    public void removeByG_A_V(long groupId, String articleId, double version)
2903        throws NoSuchArticleException, SystemException {
2904        JournalArticle journalArticle = findByG_A_V(groupId, articleId, version);
2905
2906        remove(journalArticle);
2907    }
2908
2909    public void removeByG_A_A(long groupId, String articleId, boolean approved)
2910        throws SystemException {
2911        for (JournalArticle journalArticle : findByG_A_A(groupId, articleId,
2912                approved)) {
2913            remove(journalArticle);
2914        }
2915    }
2916
2917    public void removeAll() throws SystemException {
2918        for (JournalArticle journalArticle : findAll()) {
2919            remove(journalArticle);
2920        }
2921    }
2922
2923    public int countByUuid(String uuid) throws SystemException {
2924        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2925        String finderClassName = JournalArticle.class.getName();
2926        String finderMethodName = "countByUuid";
2927        String[] finderParams = new String[] { String.class.getName() };
2928        Object[] finderArgs = new Object[] { uuid };
2929
2930        Object result = null;
2931
2932        if (finderClassNameCacheEnabled) {
2933            result = FinderCacheUtil.getResult(finderClassName,
2934                    finderMethodName, finderParams, finderArgs, this);
2935        }
2936
2937        if (result == null) {
2938            Session session = null;
2939
2940            try {
2941                session = openSession();
2942
2943                StringBuilder query = new StringBuilder();
2944
2945                query.append("SELECT COUNT(*) ");
2946                query.append(
2947                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2948
2949                if (uuid == null) {
2950                    query.append("uuid_ IS NULL");
2951                }
2952                else {
2953                    query.append("uuid_ = ?");
2954                }
2955
2956                query.append(" ");
2957
2958                Query q = session.createQuery(query.toString());
2959
2960                QueryPos qPos = QueryPos.getInstance(q);
2961
2962                if (uuid != null) {
2963                    qPos.add(uuid);
2964                }
2965
2966                Long count = null;
2967
2968                Iterator<Long> itr = q.list().iterator();
2969
2970                if (itr.hasNext()) {
2971                    count = itr.next();
2972                }
2973
2974                if (count == null) {
2975                    count = new Long(0);
2976                }
2977
2978                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2979                    finderClassName, finderMethodName, finderParams,
2980                    finderArgs, count);
2981
2982                return count.intValue();
2983            }
2984            catch (Exception e) {
2985                throw processException(e);
2986            }
2987            finally {
2988                closeSession(session);
2989            }
2990        }
2991        else {
2992            return ((Long)result).intValue();
2993        }
2994    }
2995
2996    public int countByUUID_G(String uuid, long groupId)
2997        throws SystemException {
2998        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
2999        String finderClassName = JournalArticle.class.getName();
3000        String finderMethodName = "countByUUID_G";
3001        String[] finderParams = new String[] {
3002                String.class.getName(), Long.class.getName()
3003            };
3004        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
3005
3006        Object result = null;
3007
3008        if (finderClassNameCacheEnabled) {
3009            result = FinderCacheUtil.getResult(finderClassName,
3010                    finderMethodName, finderParams, finderArgs, this);
3011        }
3012
3013        if (result == null) {
3014            Session session = null;
3015
3016            try {
3017                session = openSession();
3018
3019                StringBuilder query = new StringBuilder();
3020
3021                query.append("SELECT COUNT(*) ");
3022                query.append(
3023                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3024
3025                if (uuid == null) {
3026                    query.append("uuid_ IS NULL");
3027                }
3028                else {
3029                    query.append("uuid_ = ?");
3030                }
3031
3032                query.append(" AND ");
3033
3034                query.append("groupId = ?");
3035
3036                query.append(" ");
3037
3038                Query q = session.createQuery(query.toString());
3039
3040                QueryPos qPos = QueryPos.getInstance(q);
3041
3042                if (uuid != null) {
3043                    qPos.add(uuid);
3044                }
3045
3046                qPos.add(groupId);
3047
3048                Long count = null;
3049
3050                Iterator<Long> itr = q.list().iterator();
3051
3052                if (itr.hasNext()) {
3053                    count = itr.next();
3054                }
3055
3056                if (count == null) {
3057                    count = new Long(0);
3058                }
3059
3060                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3061                    finderClassName, finderMethodName, finderParams,
3062                    finderArgs, count);
3063
3064                return count.intValue();
3065            }
3066            catch (Exception e) {
3067                throw processException(e);
3068            }
3069            finally {
3070                closeSession(session);
3071            }
3072        }
3073        else {
3074            return ((Long)result).intValue();
3075        }
3076    }
3077
3078    public int countByGroupId(long groupId) throws SystemException {
3079        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3080        String finderClassName = JournalArticle.class.getName();
3081        String finderMethodName = "countByGroupId";
3082        String[] finderParams = new String[] { Long.class.getName() };
3083        Object[] finderArgs = new Object[] { new Long(groupId) };
3084
3085        Object result = null;
3086
3087        if (finderClassNameCacheEnabled) {
3088            result = FinderCacheUtil.getResult(finderClassName,
3089                    finderMethodName, finderParams, finderArgs, this);
3090        }
3091
3092        if (result == null) {
3093            Session session = null;
3094
3095            try {
3096                session = openSession();
3097
3098                StringBuilder query = new StringBuilder();
3099
3100                query.append("SELECT COUNT(*) ");
3101                query.append(
3102                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3103
3104                query.append("groupId = ?");
3105
3106                query.append(" ");
3107
3108                Query q = session.createQuery(query.toString());
3109
3110                QueryPos qPos = QueryPos.getInstance(q);
3111
3112                qPos.add(groupId);
3113
3114                Long count = null;
3115
3116                Iterator<Long> itr = q.list().iterator();
3117
3118                if (itr.hasNext()) {
3119                    count = itr.next();
3120                }
3121
3122                if (count == null) {
3123                    count = new Long(0);
3124                }
3125
3126                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3127                    finderClassName, finderMethodName, finderParams,
3128                    finderArgs, count);
3129
3130                return count.intValue();
3131            }
3132            catch (Exception e) {
3133                throw processException(e);
3134            }
3135            finally {
3136                closeSession(session);
3137            }
3138        }
3139        else {
3140            return ((Long)result).intValue();
3141        }
3142    }
3143
3144    public int countByCompanyId(long companyId) throws SystemException {
3145        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3146        String finderClassName = JournalArticle.class.getName();
3147        String finderMethodName = "countByCompanyId";
3148        String[] finderParams = new String[] { Long.class.getName() };
3149        Object[] finderArgs = new Object[] { new Long(companyId) };
3150
3151        Object result = null;
3152
3153        if (finderClassNameCacheEnabled) {
3154            result = FinderCacheUtil.getResult(finderClassName,
3155                    finderMethodName, finderParams, finderArgs, this);
3156        }
3157
3158        if (result == null) {
3159            Session session = null;
3160
3161            try {
3162                session = openSession();
3163
3164                StringBuilder query = new StringBuilder();
3165
3166                query.append("SELECT COUNT(*) ");
3167                query.append(
3168                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3169
3170                query.append("companyId = ?");
3171
3172                query.append(" ");
3173
3174                Query q = session.createQuery(query.toString());
3175
3176                QueryPos qPos = QueryPos.getInstance(q);
3177
3178                qPos.add(companyId);
3179
3180                Long count = null;
3181
3182                Iterator<Long> itr = q.list().iterator();
3183
3184                if (itr.hasNext()) {
3185                    count = itr.next();
3186                }
3187
3188                if (count == null) {
3189                    count = new Long(0);
3190                }
3191
3192                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3193                    finderClassName, finderMethodName, finderParams,
3194                    finderArgs, count);
3195
3196                return count.intValue();
3197            }
3198            catch (Exception e) {
3199                throw processException(e);
3200            }
3201            finally {
3202                closeSession(session);
3203            }
3204        }
3205        else {
3206            return ((Long)result).intValue();
3207        }
3208    }
3209
3210    public int countBySmallImageId(long smallImageId) throws SystemException {
3211        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3212        String finderClassName = JournalArticle.class.getName();
3213        String finderMethodName = "countBySmallImageId";
3214        String[] finderParams = new String[] { Long.class.getName() };
3215        Object[] finderArgs = new Object[] { new Long(smallImageId) };
3216
3217        Object result = null;
3218
3219        if (finderClassNameCacheEnabled) {
3220            result = FinderCacheUtil.getResult(finderClassName,
3221                    finderMethodName, finderParams, finderArgs, this);
3222        }
3223
3224        if (result == null) {
3225            Session session = null;
3226
3227            try {
3228                session = openSession();
3229
3230                StringBuilder query = new StringBuilder();
3231
3232                query.append("SELECT COUNT(*) ");
3233                query.append(
3234                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3235
3236                query.append("smallImageId = ?");
3237
3238                query.append(" ");
3239
3240                Query q = session.createQuery(query.toString());
3241
3242                QueryPos qPos = QueryPos.getInstance(q);
3243
3244                qPos.add(smallImageId);
3245
3246                Long count = null;
3247
3248                Iterator<Long> itr = q.list().iterator();
3249
3250                if (itr.hasNext()) {
3251                    count = itr.next();
3252                }
3253
3254                if (count == null) {
3255                    count = new Long(0);
3256                }
3257
3258                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3259                    finderClassName, finderMethodName, finderParams,
3260                    finderArgs, count);
3261
3262                return count.intValue();
3263            }
3264            catch (Exception e) {
3265                throw processException(e);
3266            }
3267            finally {
3268                closeSession(session);
3269            }
3270        }
3271        else {
3272            return ((Long)result).intValue();
3273        }
3274    }
3275
3276    public int countByG_A(long groupId, String articleId)
3277        throws SystemException {
3278        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3279        String finderClassName = JournalArticle.class.getName();
3280        String finderMethodName = "countByG_A";
3281        String[] finderParams = new String[] {
3282                Long.class.getName(), String.class.getName()
3283            };
3284        Object[] finderArgs = new Object[] { new Long(groupId), articleId };
3285
3286        Object result = null;
3287
3288        if (finderClassNameCacheEnabled) {
3289            result = FinderCacheUtil.getResult(finderClassName,
3290                    finderMethodName, finderParams, finderArgs, this);
3291        }
3292
3293        if (result == null) {
3294            Session session = null;
3295
3296            try {
3297                session = openSession();
3298
3299                StringBuilder query = new StringBuilder();
3300
3301                query.append("SELECT COUNT(*) ");
3302                query.append(
3303                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3304
3305                query.append("groupId = ?");
3306
3307                query.append(" AND ");
3308
3309                if (articleId == null) {
3310                    query.append("articleId IS NULL");
3311                }
3312                else {
3313                    query.append("articleId = ?");
3314                }
3315
3316                query.append(" ");
3317
3318                Query q = session.createQuery(query.toString());
3319
3320                QueryPos qPos = QueryPos.getInstance(q);
3321
3322                qPos.add(groupId);
3323
3324                if (articleId != null) {
3325                    qPos.add(articleId);
3326                }
3327
3328                Long count = null;
3329
3330                Iterator<Long> itr = q.list().iterator();
3331
3332                if (itr.hasNext()) {
3333                    count = itr.next();
3334                }
3335
3336                if (count == null) {
3337                    count = new Long(0);
3338                }
3339
3340                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3341                    finderClassName, finderMethodName, finderParams,
3342                    finderArgs, count);
3343
3344                return count.intValue();
3345            }
3346            catch (Exception e) {
3347                throw processException(e);
3348            }
3349            finally {
3350                closeSession(session);
3351            }
3352        }
3353        else {
3354            return ((Long)result).intValue();
3355        }
3356    }
3357
3358    public int countByG_S(long groupId, String structureId)
3359        throws SystemException {
3360        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3361        String finderClassName = JournalArticle.class.getName();
3362        String finderMethodName = "countByG_S";
3363        String[] finderParams = new String[] {
3364                Long.class.getName(), String.class.getName()
3365            };
3366        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
3367
3368        Object result = null;
3369
3370        if (finderClassNameCacheEnabled) {
3371            result = FinderCacheUtil.getResult(finderClassName,
3372                    finderMethodName, finderParams, finderArgs, this);
3373        }
3374
3375        if (result == null) {
3376            Session session = null;
3377
3378            try {
3379                session = openSession();
3380
3381                StringBuilder query = new StringBuilder();
3382
3383                query.append("SELECT COUNT(*) ");
3384                query.append(
3385                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3386
3387                query.append("groupId = ?");
3388
3389                query.append(" AND ");
3390
3391                if (structureId == null) {
3392                    query.append("structureId IS NULL");
3393                }
3394                else {
3395                    query.append("structureId = ?");
3396                }
3397
3398                query.append(" ");
3399
3400                Query q = session.createQuery(query.toString());
3401
3402                QueryPos qPos = QueryPos.getInstance(q);
3403
3404                qPos.add(groupId);
3405
3406                if (structureId != null) {
3407                    qPos.add(structureId);
3408                }
3409
3410                Long count = null;
3411
3412                Iterator<Long> itr = q.list().iterator();
3413
3414                if (itr.hasNext()) {
3415                    count = itr.next();
3416                }
3417
3418                if (count == null) {
3419                    count = new Long(0);
3420                }
3421
3422                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3423                    finderClassName, finderMethodName, finderParams,
3424                    finderArgs, count);
3425
3426                return count.intValue();
3427            }
3428            catch (Exception e) {
3429                throw processException(e);
3430            }
3431            finally {
3432                closeSession(session);
3433            }
3434        }
3435        else {
3436            return ((Long)result).intValue();
3437        }
3438    }
3439
3440    public int countByG_T(long groupId, String templateId)
3441        throws SystemException {
3442        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3443        String finderClassName = JournalArticle.class.getName();
3444        String finderMethodName = "countByG_T";
3445        String[] finderParams = new String[] {
3446                Long.class.getName(), String.class.getName()
3447            };
3448        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
3449
3450        Object result = null;
3451
3452        if (finderClassNameCacheEnabled) {
3453            result = FinderCacheUtil.getResult(finderClassName,
3454                    finderMethodName, finderParams, finderArgs, this);
3455        }
3456
3457        if (result == null) {
3458            Session session = null;
3459
3460            try {
3461                session = openSession();
3462
3463                StringBuilder query = new StringBuilder();
3464
3465                query.append("SELECT COUNT(*) ");
3466                query.append(
3467                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3468
3469                query.append("groupId = ?");
3470
3471                query.append(" AND ");
3472
3473                if (templateId == null) {
3474                    query.append("templateId IS NULL");
3475                }
3476                else {
3477                    query.append("templateId = ?");
3478                }
3479
3480                query.append(" ");
3481
3482                Query q = session.createQuery(query.toString());
3483
3484                QueryPos qPos = QueryPos.getInstance(q);
3485
3486                qPos.add(groupId);
3487
3488                if (templateId != null) {
3489                    qPos.add(templateId);
3490                }
3491
3492                Long count = null;
3493
3494                Iterator<Long> itr = q.list().iterator();
3495
3496                if (itr.hasNext()) {
3497                    count = itr.next();
3498                }
3499
3500                if (count == null) {
3501                    count = new Long(0);
3502                }
3503
3504                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3505                    finderClassName, finderMethodName, finderParams,
3506                    finderArgs, count);
3507
3508                return count.intValue();
3509            }
3510            catch (Exception e) {
3511                throw processException(e);
3512            }
3513            finally {
3514                closeSession(session);
3515            }
3516        }
3517        else {
3518            return ((Long)result).intValue();
3519        }
3520    }
3521
3522    public int countByG_A_V(long groupId, String articleId, double version)
3523        throws SystemException {
3524        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3525        String finderClassName = JournalArticle.class.getName();
3526        String finderMethodName = "countByG_A_V";
3527        String[] finderParams = new String[] {
3528                Long.class.getName(), String.class.getName(),
3529                Double.class.getName()
3530            };
3531        Object[] finderArgs = new Object[] {
3532                new Long(groupId),
3533                
3534                articleId, new Double(version)
3535            };
3536
3537        Object result = null;
3538
3539        if (finderClassNameCacheEnabled) {
3540            result = FinderCacheUtil.getResult(finderClassName,
3541                    finderMethodName, finderParams, finderArgs, this);
3542        }
3543
3544        if (result == null) {
3545            Session session = null;
3546
3547            try {
3548                session = openSession();
3549
3550                StringBuilder query = new StringBuilder();
3551
3552                query.append("SELECT COUNT(*) ");
3553                query.append(
3554                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3555
3556                query.append("groupId = ?");
3557
3558                query.append(" AND ");
3559
3560                if (articleId == null) {
3561                    query.append("articleId IS NULL");
3562                }
3563                else {
3564                    query.append("articleId = ?");
3565                }
3566
3567                query.append(" AND ");
3568
3569                query.append("version = ?");
3570
3571                query.append(" ");
3572
3573                Query q = session.createQuery(query.toString());
3574
3575                QueryPos qPos = QueryPos.getInstance(q);
3576
3577                qPos.add(groupId);
3578
3579                if (articleId != null) {
3580                    qPos.add(articleId);
3581                }
3582
3583                qPos.add(version);
3584
3585                Long count = null;
3586
3587                Iterator<Long> itr = q.list().iterator();
3588
3589                if (itr.hasNext()) {
3590                    count = itr.next();
3591                }
3592
3593                if (count == null) {
3594                    count = new Long(0);
3595                }
3596
3597                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3598                    finderClassName, finderMethodName, finderParams,
3599                    finderArgs, count);
3600
3601                return count.intValue();
3602            }
3603            catch (Exception e) {
3604                throw processException(e);
3605            }
3606            finally {
3607                closeSession(session);
3608            }
3609        }
3610        else {
3611            return ((Long)result).intValue();
3612        }
3613    }
3614
3615    public int countByG_A_A(long groupId, String articleId, boolean approved)
3616        throws SystemException {
3617        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3618        String finderClassName = JournalArticle.class.getName();
3619        String finderMethodName = "countByG_A_A";
3620        String[] finderParams = new String[] {
3621                Long.class.getName(), String.class.getName(),
3622                Boolean.class.getName()
3623            };
3624        Object[] finderArgs = new Object[] {
3625                new Long(groupId),
3626                
3627                articleId, Boolean.valueOf(approved)
3628            };
3629
3630        Object result = null;
3631
3632        if (finderClassNameCacheEnabled) {
3633            result = FinderCacheUtil.getResult(finderClassName,
3634                    finderMethodName, finderParams, finderArgs, this);
3635        }
3636
3637        if (result == null) {
3638            Session session = null;
3639
3640            try {
3641                session = openSession();
3642
3643                StringBuilder query = new StringBuilder();
3644
3645                query.append("SELECT COUNT(*) ");
3646                query.append(
3647                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
3648
3649                query.append("groupId = ?");
3650
3651                query.append(" AND ");
3652
3653                if (articleId == null) {
3654                    query.append("articleId IS NULL");
3655                }
3656                else {
3657                    query.append("articleId = ?");
3658                }
3659
3660                query.append(" AND ");
3661
3662                query.append("approved = ?");
3663
3664                query.append(" ");
3665
3666                Query q = session.createQuery(query.toString());
3667
3668                QueryPos qPos = QueryPos.getInstance(q);
3669
3670                qPos.add(groupId);
3671
3672                if (articleId != null) {
3673                    qPos.add(articleId);
3674                }
3675
3676                qPos.add(approved);
3677
3678                Long count = null;
3679
3680                Iterator<Long> itr = q.list().iterator();
3681
3682                if (itr.hasNext()) {
3683                    count = itr.next();
3684                }
3685
3686                if (count == null) {
3687                    count = new Long(0);
3688                }
3689
3690                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3691                    finderClassName, finderMethodName, finderParams,
3692                    finderArgs, count);
3693
3694                return count.intValue();
3695            }
3696            catch (Exception e) {
3697                throw processException(e);
3698            }
3699            finally {
3700                closeSession(session);
3701            }
3702        }
3703        else {
3704            return ((Long)result).intValue();
3705        }
3706    }
3707
3708    public int countAll() throws SystemException {
3709        boolean finderClassNameCacheEnabled = JournalArticleModelImpl.CACHE_ENABLED;
3710        String finderClassName = JournalArticle.class.getName();
3711        String finderMethodName = "countAll";
3712        String[] finderParams = new String[] {  };
3713        Object[] finderArgs = new Object[] {  };
3714
3715        Object result = null;
3716
3717        if (finderClassNameCacheEnabled) {
3718            result = FinderCacheUtil.getResult(finderClassName,
3719                    finderMethodName, finderParams, finderArgs, this);
3720        }
3721
3722        if (result == null) {
3723            Session session = null;
3724
3725            try {
3726                session = openSession();
3727
3728                Query q = session.createQuery(
3729                        "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalArticle");
3730
3731                Long count = null;
3732
3733                Iterator<Long> itr = q.list().iterator();
3734
3735                if (itr.hasNext()) {
3736                    count = itr.next();
3737                }
3738
3739                if (count == null) {
3740                    count = new Long(0);
3741                }
3742
3743                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
3744                    finderClassName, finderMethodName, finderParams,
3745                    finderArgs, count);
3746
3747                return count.intValue();
3748            }
3749            catch (Exception e) {
3750                throw processException(e);
3751            }
3752            finally {
3753                closeSession(session);
3754            }
3755        }
3756        else {
3757            return ((Long)result).intValue();
3758        }
3759    }
3760
3761    public void registerListener(ModelListener listener) {
3762        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3763
3764        listeners.add(listener);
3765
3766        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3767    }
3768
3769    public void unregisterListener(ModelListener listener) {
3770        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
3771
3772        listeners.remove(listener);
3773
3774        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3775    }
3776
3777    public void afterPropertiesSet() {
3778        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3779                    com.liferay.portal.util.PropsUtil.get(
3780                        "value.object.listener.com.liferay.portlet.journal.model.JournalArticle")));
3781
3782        if (listenerClassNames.length > 0) {
3783            try {
3784                List<ModelListener> listeners = new ArrayList<ModelListener>();
3785
3786                for (String listenerClassName : listenerClassNames) {
3787                    listeners.add((ModelListener)Class.forName(
3788                            listenerClassName).newInstance());
3789                }
3790
3791                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
3792            }
3793            catch (Exception e) {
3794                _log.error(e);
3795            }
3796        }
3797    }
3798
3799    private static Log _log = LogFactory.getLog(JournalArticlePersistenceImpl.class);
3800    private ModelListener[] _listeners = new ModelListener[0];
3801}