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