1   /**
2    * Copyright (c) 2000-2007 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.OrderByComparator;
29  import com.liferay.portal.kernel.util.StringMaker;
30  import com.liferay.portal.kernel.util.StringPool;
31  import com.liferay.portal.service.persistence.BasePersistence;
32  import com.liferay.portal.spring.hibernate.FinderCache;
33  import com.liferay.portal.spring.hibernate.HibernateUtil;
34  
35  import com.liferay.portlet.journal.NoSuchArticleException;
36  import com.liferay.portlet.journal.model.JournalArticle;
37  import com.liferay.portlet.journal.model.impl.JournalArticleImpl;
38  
39  import com.liferay.util.dao.hibernate.QueryUtil;
40  
41  import org.apache.commons.logging.Log;
42  import org.apache.commons.logging.LogFactory;
43  
44  import org.hibernate.Query;
45  import org.hibernate.Session;
46  
47  import java.util.Collections;
48  import java.util.Iterator;
49  import java.util.List;
50  
51  /**
52   * <a href="JournalArticlePersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class JournalArticlePersistenceImpl extends BasePersistence
58      implements JournalArticlePersistence {
59      public JournalArticle create(long id) {
60          JournalArticle journalArticle = new JournalArticleImpl();
61          journalArticle.setNew(true);
62          journalArticle.setPrimaryKey(id);
63  
64          return journalArticle;
65      }
66  
67      public JournalArticle remove(long id)
68          throws NoSuchArticleException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              JournalArticle journalArticle = (JournalArticle)session.get(JournalArticleImpl.class,
75                      new Long(id));
76  
77              if (journalArticle == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No JournalArticle exists with the primary key " +
80                          id);
81                  }
82  
83                  throw new NoSuchArticleException(
84                      "No JournalArticle exists with the primary key " + id);
85              }
86  
87              return remove(journalArticle);
88          }
89          catch (NoSuchArticleException nsee) {
90              throw nsee;
91          }
92          catch (Exception e) {
93              throw HibernateUtil.processException(e);
94          }
95          finally {
96              closeSession(session);
97          }
98      }
99  
100     public JournalArticle remove(JournalArticle journalArticle)
101         throws SystemException {
102         Session session = null;
103 
104         try {
105             session = openSession();
106             session.delete(journalArticle);
107             session.flush();
108 
109             return journalArticle;
110         }
111         catch (Exception e) {
112             throw HibernateUtil.processException(e);
113         }
114         finally {
115             closeSession(session);
116             FinderCache.clearCache(JournalArticle.class.getName());
117         }
118     }
119 
120     public JournalArticle update(
121         com.liferay.portlet.journal.model.JournalArticle journalArticle)
122         throws SystemException {
123         return update(journalArticle, false);
124     }
125 
126     public JournalArticle update(
127         com.liferay.portlet.journal.model.JournalArticle journalArticle,
128         boolean merge) throws SystemException {
129         Session session = null;
130 
131         try {
132             session = openSession();
133 
134             if (merge) {
135                 session.merge(journalArticle);
136             }
137             else {
138                 if (journalArticle.isNew()) {
139                     session.save(journalArticle);
140                 }
141             }
142 
143             session.flush();
144             journalArticle.setNew(false);
145 
146             return journalArticle;
147         }
148         catch (Exception e) {
149             throw HibernateUtil.processException(e);
150         }
151         finally {
152             closeSession(session);
153             FinderCache.clearCache(JournalArticle.class.getName());
154         }
155     }
156 
157     public JournalArticle findByPrimaryKey(long id)
158         throws NoSuchArticleException, SystemException {
159         JournalArticle journalArticle = fetchByPrimaryKey(id);
160 
161         if (journalArticle == null) {
162             if (_log.isWarnEnabled()) {
163                 _log.warn("No JournalArticle exists with the primary key " +
164                     id);
165             }
166 
167             throw new NoSuchArticleException(
168                 "No JournalArticle exists with the primary key " + id);
169         }
170 
171         return journalArticle;
172     }
173 
174     public JournalArticle fetchByPrimaryKey(long id) throws SystemException {
175         Session session = null;
176 
177         try {
178             session = openSession();
179 
180             return (JournalArticle)session.get(JournalArticleImpl.class,
181                 new Long(id));
182         }
183         catch (Exception e) {
184             throw HibernateUtil.processException(e);
185         }
186         finally {
187             closeSession(session);
188         }
189     }
190 
191     public List findByGroupId(long groupId) throws SystemException {
192         String finderClassName = JournalArticle.class.getName();
193         String finderMethodName = "findByGroupId";
194         String[] finderParams = new String[] { Long.class.getName() };
195         Object[] finderArgs = new Object[] { new Long(groupId) };
196         Object result = FinderCache.getResult(finderClassName,
197                 finderMethodName, finderParams, finderArgs, getSessionFactory());
198 
199         if (result == null) {
200             Session session = null;
201 
202             try {
203                 session = openSession();
204 
205                 StringMaker query = new StringMaker();
206                 query.append(
207                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
208                 query.append("groupId = ?");
209                 query.append(" ");
210                 query.append("ORDER BY ");
211                 query.append("articleId ASC").append(", ");
212                 query.append("version DESC");
213 
214                 Query q = session.createQuery(query.toString());
215                 int queryPos = 0;
216                 q.setLong(queryPos++, groupId);
217 
218                 List list = q.list();
219                 FinderCache.putResult(finderClassName, finderMethodName,
220                     finderParams, finderArgs, list);
221 
222                 return list;
223             }
224             catch (Exception e) {
225                 throw HibernateUtil.processException(e);
226             }
227             finally {
228                 closeSession(session);
229             }
230         }
231         else {
232             return (List)result;
233         }
234     }
235 
236     public List findByGroupId(long groupId, int begin, int end)
237         throws SystemException {
238         return findByGroupId(groupId, begin, end, null);
239     }
240 
241     public List findByGroupId(long groupId, int begin, int end,
242         OrderByComparator obc) throws SystemException {
243         String finderClassName = JournalArticle.class.getName();
244         String finderMethodName = "findByGroupId";
245         String[] finderParams = new String[] {
246                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
247                 "com.liferay.portal.kernel.util.OrderByComparator"
248             };
249         Object[] finderArgs = new Object[] {
250                 new Long(groupId), String.valueOf(begin), String.valueOf(end),
251                 String.valueOf(obc)
252             };
253         Object result = FinderCache.getResult(finderClassName,
254                 finderMethodName, finderParams, finderArgs, getSessionFactory());
255 
256         if (result == null) {
257             Session session = null;
258 
259             try {
260                 session = openSession();
261 
262                 StringMaker query = new StringMaker();
263                 query.append(
264                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
265                 query.append("groupId = ?");
266                 query.append(" ");
267 
268                 if (obc != null) {
269                     query.append("ORDER BY ");
270                     query.append(obc.getOrderBy());
271                 }
272                 else {
273                     query.append("ORDER BY ");
274                     query.append("articleId ASC").append(", ");
275                     query.append("version DESC");
276                 }
277 
278                 Query q = session.createQuery(query.toString());
279                 int queryPos = 0;
280                 q.setLong(queryPos++, groupId);
281 
282                 List list = QueryUtil.list(q, getDialect(), begin, end);
283                 FinderCache.putResult(finderClassName, finderMethodName,
284                     finderParams, finderArgs, list);
285 
286                 return list;
287             }
288             catch (Exception e) {
289                 throw HibernateUtil.processException(e);
290             }
291             finally {
292                 closeSession(session);
293             }
294         }
295         else {
296             return (List)result;
297         }
298     }
299 
300     public JournalArticle findByGroupId_First(long groupId,
301         OrderByComparator obc) throws NoSuchArticleException, SystemException {
302         List list = findByGroupId(groupId, 0, 1, obc);
303 
304         if (list.size() == 0) {
305             StringMaker msg = new StringMaker();
306             msg.append("No JournalArticle exists with the key ");
307             msg.append(StringPool.OPEN_CURLY_BRACE);
308             msg.append("groupId=");
309             msg.append(groupId);
310             msg.append(StringPool.CLOSE_CURLY_BRACE);
311             throw new NoSuchArticleException(msg.toString());
312         }
313         else {
314             return (JournalArticle)list.get(0);
315         }
316     }
317 
318     public JournalArticle findByGroupId_Last(long groupId, OrderByComparator obc)
319         throws NoSuchArticleException, SystemException {
320         int count = countByGroupId(groupId);
321         List list = findByGroupId(groupId, count - 1, count, obc);
322 
323         if (list.size() == 0) {
324             StringMaker msg = new StringMaker();
325             msg.append("No JournalArticle exists with the key ");
326             msg.append(StringPool.OPEN_CURLY_BRACE);
327             msg.append("groupId=");
328             msg.append(groupId);
329             msg.append(StringPool.CLOSE_CURLY_BRACE);
330             throw new NoSuchArticleException(msg.toString());
331         }
332         else {
333             return (JournalArticle)list.get(0);
334         }
335     }
336 
337     public JournalArticle[] findByGroupId_PrevAndNext(long id, long groupId,
338         OrderByComparator obc) throws NoSuchArticleException, SystemException {
339         JournalArticle journalArticle = findByPrimaryKey(id);
340         int count = countByGroupId(groupId);
341         Session session = null;
342 
343         try {
344             session = openSession();
345 
346             StringMaker query = new StringMaker();
347             query.append(
348                 "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
349             query.append("groupId = ?");
350             query.append(" ");
351 
352             if (obc != null) {
353                 query.append("ORDER BY ");
354                 query.append(obc.getOrderBy());
355             }
356             else {
357                 query.append("ORDER BY ");
358                 query.append("articleId ASC").append(", ");
359                 query.append("version DESC");
360             }
361 
362             Query q = session.createQuery(query.toString());
363             int queryPos = 0;
364             q.setLong(queryPos++, groupId);
365 
366             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
367                     journalArticle);
368             JournalArticle[] array = new JournalArticleImpl[3];
369             array[0] = (JournalArticle)objArray[0];
370             array[1] = (JournalArticle)objArray[1];
371             array[2] = (JournalArticle)objArray[2];
372 
373             return array;
374         }
375         catch (Exception e) {
376             throw HibernateUtil.processException(e);
377         }
378         finally {
379             closeSession(session);
380         }
381     }
382 
383     public List findByCompanyId(long companyId) throws SystemException {
384         String finderClassName = JournalArticle.class.getName();
385         String finderMethodName = "findByCompanyId";
386         String[] finderParams = new String[] { Long.class.getName() };
387         Object[] finderArgs = new Object[] { new Long(companyId) };
388         Object result = FinderCache.getResult(finderClassName,
389                 finderMethodName, finderParams, finderArgs, getSessionFactory());
390 
391         if (result == null) {
392             Session session = null;
393 
394             try {
395                 session = openSession();
396 
397                 StringMaker query = new StringMaker();
398                 query.append(
399                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
400                 query.append("companyId = ?");
401                 query.append(" ");
402                 query.append("ORDER BY ");
403                 query.append("articleId ASC").append(", ");
404                 query.append("version DESC");
405 
406                 Query q = session.createQuery(query.toString());
407                 int queryPos = 0;
408                 q.setLong(queryPos++, companyId);
409 
410                 List list = q.list();
411                 FinderCache.putResult(finderClassName, finderMethodName,
412                     finderParams, finderArgs, list);
413 
414                 return list;
415             }
416             catch (Exception e) {
417                 throw HibernateUtil.processException(e);
418             }
419             finally {
420                 closeSession(session);
421             }
422         }
423         else {
424             return (List)result;
425         }
426     }
427 
428     public List findByCompanyId(long companyId, int begin, int end)
429         throws SystemException {
430         return findByCompanyId(companyId, begin, end, null);
431     }
432 
433     public List findByCompanyId(long companyId, int begin, int end,
434         OrderByComparator obc) throws SystemException {
435         String finderClassName = JournalArticle.class.getName();
436         String finderMethodName = "findByCompanyId";
437         String[] finderParams = new String[] {
438                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
439                 "com.liferay.portal.kernel.util.OrderByComparator"
440             };
441         Object[] finderArgs = new Object[] {
442                 new Long(companyId), String.valueOf(begin), String.valueOf(end),
443                 String.valueOf(obc)
444             };
445         Object result = FinderCache.getResult(finderClassName,
446                 finderMethodName, finderParams, finderArgs, getSessionFactory());
447 
448         if (result == null) {
449             Session session = null;
450 
451             try {
452                 session = openSession();
453 
454                 StringMaker query = new StringMaker();
455                 query.append(
456                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
457                 query.append("companyId = ?");
458                 query.append(" ");
459 
460                 if (obc != null) {
461                     query.append("ORDER BY ");
462                     query.append(obc.getOrderBy());
463                 }
464                 else {
465                     query.append("ORDER BY ");
466                     query.append("articleId ASC").append(", ");
467                     query.append("version DESC");
468                 }
469 
470                 Query q = session.createQuery(query.toString());
471                 int queryPos = 0;
472                 q.setLong(queryPos++, companyId);
473 
474                 List list = QueryUtil.list(q, getDialect(), begin, end);
475                 FinderCache.putResult(finderClassName, finderMethodName,
476                     finderParams, finderArgs, list);
477 
478                 return list;
479             }
480             catch (Exception e) {
481                 throw HibernateUtil.processException(e);
482             }
483             finally {
484                 closeSession(session);
485             }
486         }
487         else {
488             return (List)result;
489         }
490     }
491 
492     public JournalArticle findByCompanyId_First(long companyId,
493         OrderByComparator obc) throws NoSuchArticleException, SystemException {
494         List list = findByCompanyId(companyId, 0, 1, obc);
495 
496         if (list.size() == 0) {
497             StringMaker msg = new StringMaker();
498             msg.append("No JournalArticle exists with the key ");
499             msg.append(StringPool.OPEN_CURLY_BRACE);
500             msg.append("companyId=");
501             msg.append(companyId);
502             msg.append(StringPool.CLOSE_CURLY_BRACE);
503             throw new NoSuchArticleException(msg.toString());
504         }
505         else {
506             return (JournalArticle)list.get(0);
507         }
508     }
509 
510     public JournalArticle findByCompanyId_Last(long companyId,
511         OrderByComparator obc) throws NoSuchArticleException, SystemException {
512         int count = countByCompanyId(companyId);
513         List list = findByCompanyId(companyId, count - 1, count, obc);
514 
515         if (list.size() == 0) {
516             StringMaker msg = new StringMaker();
517             msg.append("No JournalArticle exists with the key ");
518             msg.append(StringPool.OPEN_CURLY_BRACE);
519             msg.append("companyId=");
520             msg.append(companyId);
521             msg.append(StringPool.CLOSE_CURLY_BRACE);
522             throw new NoSuchArticleException(msg.toString());
523         }
524         else {
525             return (JournalArticle)list.get(0);
526         }
527     }
528 
529     public JournalArticle[] findByCompanyId_PrevAndNext(long id,
530         long companyId, OrderByComparator obc)
531         throws NoSuchArticleException, SystemException {
532         JournalArticle journalArticle = findByPrimaryKey(id);
533         int count = countByCompanyId(companyId);
534         Session session = null;
535 
536         try {
537             session = openSession();
538 
539             StringMaker query = new StringMaker();
540             query.append(
541                 "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
542             query.append("companyId = ?");
543             query.append(" ");
544 
545             if (obc != null) {
546                 query.append("ORDER BY ");
547                 query.append(obc.getOrderBy());
548             }
549             else {
550                 query.append("ORDER BY ");
551                 query.append("articleId ASC").append(", ");
552                 query.append("version DESC");
553             }
554 
555             Query q = session.createQuery(query.toString());
556             int queryPos = 0;
557             q.setLong(queryPos++, companyId);
558 
559             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
560                     journalArticle);
561             JournalArticle[] array = new JournalArticleImpl[3];
562             array[0] = (JournalArticle)objArray[0];
563             array[1] = (JournalArticle)objArray[1];
564             array[2] = (JournalArticle)objArray[2];
565 
566             return array;
567         }
568         catch (Exception e) {
569             throw HibernateUtil.processException(e);
570         }
571         finally {
572             closeSession(session);
573         }
574     }
575 
576     public List findByG_A(long groupId, String articleId)
577         throws SystemException {
578         String finderClassName = JournalArticle.class.getName();
579         String finderMethodName = "findByG_A";
580         String[] finderParams = new String[] {
581                 Long.class.getName(), String.class.getName()
582             };
583         Object[] finderArgs = new Object[] { new Long(groupId), articleId };
584         Object result = FinderCache.getResult(finderClassName,
585                 finderMethodName, finderParams, finderArgs, getSessionFactory());
586 
587         if (result == null) {
588             Session session = null;
589 
590             try {
591                 session = openSession();
592 
593                 StringMaker query = new StringMaker();
594                 query.append(
595                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
596                 query.append("groupId = ?");
597                 query.append(" AND ");
598 
599                 if (articleId == null) {
600                     query.append("articleId IS NULL");
601                 }
602                 else {
603                     query.append("articleId = ?");
604                 }
605 
606                 query.append(" ");
607                 query.append("ORDER BY ");
608                 query.append("articleId ASC").append(", ");
609                 query.append("version DESC");
610 
611                 Query q = session.createQuery(query.toString());
612                 int queryPos = 0;
613                 q.setLong(queryPos++, groupId);
614 
615                 if (articleId != null) {
616                     q.setString(queryPos++, articleId);
617                 }
618 
619                 List list = q.list();
620                 FinderCache.putResult(finderClassName, finderMethodName,
621                     finderParams, finderArgs, list);
622 
623                 return list;
624             }
625             catch (Exception e) {
626                 throw HibernateUtil.processException(e);
627             }
628             finally {
629                 closeSession(session);
630             }
631         }
632         else {
633             return (List)result;
634         }
635     }
636 
637     public List findByG_A(long groupId, String articleId, int begin, int end)
638         throws SystemException {
639         return findByG_A(groupId, articleId, begin, end, null);
640     }
641 
642     public List findByG_A(long groupId, String articleId, int begin, int end,
643         OrderByComparator obc) throws SystemException {
644         String finderClassName = JournalArticle.class.getName();
645         String finderMethodName = "findByG_A";
646         String[] finderParams = new String[] {
647                 Long.class.getName(), String.class.getName(),
648                 "java.lang.Integer", "java.lang.Integer",
649                 "com.liferay.portal.kernel.util.OrderByComparator"
650             };
651         Object[] finderArgs = new Object[] {
652                 new Long(groupId), articleId, String.valueOf(begin),
653                 String.valueOf(end), String.valueOf(obc)
654             };
655         Object result = FinderCache.getResult(finderClassName,
656                 finderMethodName, finderParams, finderArgs, getSessionFactory());
657 
658         if (result == null) {
659             Session session = null;
660 
661             try {
662                 session = openSession();
663 
664                 StringMaker query = new StringMaker();
665                 query.append(
666                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
667                 query.append("groupId = ?");
668                 query.append(" AND ");
669 
670                 if (articleId == null) {
671                     query.append("articleId IS NULL");
672                 }
673                 else {
674                     query.append("articleId = ?");
675                 }
676 
677                 query.append(" ");
678 
679                 if (obc != null) {
680                     query.append("ORDER BY ");
681                     query.append(obc.getOrderBy());
682                 }
683                 else {
684                     query.append("ORDER BY ");
685                     query.append("articleId ASC").append(", ");
686                     query.append("version DESC");
687                 }
688 
689                 Query q = session.createQuery(query.toString());
690                 int queryPos = 0;
691                 q.setLong(queryPos++, groupId);
692 
693                 if (articleId != null) {
694                     q.setString(queryPos++, articleId);
695                 }
696 
697                 List list = QueryUtil.list(q, getDialect(), begin, end);
698                 FinderCache.putResult(finderClassName, finderMethodName,
699                     finderParams, finderArgs, list);
700 
701                 return list;
702             }
703             catch (Exception e) {
704                 throw HibernateUtil.processException(e);
705             }
706             finally {
707                 closeSession(session);
708             }
709         }
710         else {
711             return (List)result;
712         }
713     }
714 
715     public JournalArticle findByG_A_First(long groupId, String articleId,
716         OrderByComparator obc) throws NoSuchArticleException, SystemException {
717         List list = findByG_A(groupId, articleId, 0, 1, obc);
718 
719         if (list.size() == 0) {
720             StringMaker msg = new StringMaker();
721             msg.append("No JournalArticle exists with the key ");
722             msg.append(StringPool.OPEN_CURLY_BRACE);
723             msg.append("groupId=");
724             msg.append(groupId);
725             msg.append(", ");
726             msg.append("articleId=");
727             msg.append(articleId);
728             msg.append(StringPool.CLOSE_CURLY_BRACE);
729             throw new NoSuchArticleException(msg.toString());
730         }
731         else {
732             return (JournalArticle)list.get(0);
733         }
734     }
735 
736     public JournalArticle findByG_A_Last(long groupId, String articleId,
737         OrderByComparator obc) throws NoSuchArticleException, SystemException {
738         int count = countByG_A(groupId, articleId);
739         List list = findByG_A(groupId, articleId, count - 1, count, obc);
740 
741         if (list.size() == 0) {
742             StringMaker msg = new StringMaker();
743             msg.append("No JournalArticle exists with the key ");
744             msg.append(StringPool.OPEN_CURLY_BRACE);
745             msg.append("groupId=");
746             msg.append(groupId);
747             msg.append(", ");
748             msg.append("articleId=");
749             msg.append(articleId);
750             msg.append(StringPool.CLOSE_CURLY_BRACE);
751             throw new NoSuchArticleException(msg.toString());
752         }
753         else {
754             return (JournalArticle)list.get(0);
755         }
756     }
757 
758     public JournalArticle[] findByG_A_PrevAndNext(long id, long groupId,
759         String articleId, OrderByComparator obc)
760         throws NoSuchArticleException, SystemException {
761         JournalArticle journalArticle = findByPrimaryKey(id);
762         int count = countByG_A(groupId, articleId);
763         Session session = null;
764 
765         try {
766             session = openSession();
767 
768             StringMaker query = new StringMaker();
769             query.append(
770                 "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
771             query.append("groupId = ?");
772             query.append(" AND ");
773 
774             if (articleId == null) {
775                 query.append("articleId IS NULL");
776             }
777             else {
778                 query.append("articleId = ?");
779             }
780 
781             query.append(" ");
782 
783             if (obc != null) {
784                 query.append("ORDER BY ");
785                 query.append(obc.getOrderBy());
786             }
787             else {
788                 query.append("ORDER BY ");
789                 query.append("articleId ASC").append(", ");
790                 query.append("version DESC");
791             }
792 
793             Query q = session.createQuery(query.toString());
794             int queryPos = 0;
795             q.setLong(queryPos++, groupId);
796 
797             if (articleId != null) {
798                 q.setString(queryPos++, articleId);
799             }
800 
801             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
802                     journalArticle);
803             JournalArticle[] array = new JournalArticleImpl[3];
804             array[0] = (JournalArticle)objArray[0];
805             array[1] = (JournalArticle)objArray[1];
806             array[2] = (JournalArticle)objArray[2];
807 
808             return array;
809         }
810         catch (Exception e) {
811             throw HibernateUtil.processException(e);
812         }
813         finally {
814             closeSession(session);
815         }
816     }
817 
818     public List findByG_S(long groupId, String structureId)
819         throws SystemException {
820         String finderClassName = JournalArticle.class.getName();
821         String finderMethodName = "findByG_S";
822         String[] finderParams = new String[] {
823                 Long.class.getName(), String.class.getName()
824             };
825         Object[] finderArgs = new Object[] { new Long(groupId), structureId };
826         Object result = FinderCache.getResult(finderClassName,
827                 finderMethodName, finderParams, finderArgs, getSessionFactory());
828 
829         if (result == null) {
830             Session session = null;
831 
832             try {
833                 session = openSession();
834 
835                 StringMaker query = new StringMaker();
836                 query.append(
837                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
838                 query.append("groupId = ?");
839                 query.append(" AND ");
840 
841                 if (structureId == null) {
842                     query.append("structureId IS NULL");
843                 }
844                 else {
845                     query.append("structureId = ?");
846                 }
847 
848                 query.append(" ");
849                 query.append("ORDER BY ");
850                 query.append("articleId ASC").append(", ");
851                 query.append("version DESC");
852 
853                 Query q = session.createQuery(query.toString());
854                 int queryPos = 0;
855                 q.setLong(queryPos++, groupId);
856 
857                 if (structureId != null) {
858                     q.setString(queryPos++, structureId);
859                 }
860 
861                 List list = q.list();
862                 FinderCache.putResult(finderClassName, finderMethodName,
863                     finderParams, finderArgs, list);
864 
865                 return list;
866             }
867             catch (Exception e) {
868                 throw HibernateUtil.processException(e);
869             }
870             finally {
871                 closeSession(session);
872             }
873         }
874         else {
875             return (List)result;
876         }
877     }
878 
879     public List findByG_S(long groupId, String structureId, int begin, int end)
880         throws SystemException {
881         return findByG_S(groupId, structureId, begin, end, null);
882     }
883 
884     public List findByG_S(long groupId, String structureId, int begin, int end,
885         OrderByComparator obc) throws SystemException {
886         String finderClassName = JournalArticle.class.getName();
887         String finderMethodName = "findByG_S";
888         String[] finderParams = new String[] {
889                 Long.class.getName(), String.class.getName(),
890                 "java.lang.Integer", "java.lang.Integer",
891                 "com.liferay.portal.kernel.util.OrderByComparator"
892             };
893         Object[] finderArgs = new Object[] {
894                 new Long(groupId), structureId, String.valueOf(begin),
895                 String.valueOf(end), String.valueOf(obc)
896             };
897         Object result = FinderCache.getResult(finderClassName,
898                 finderMethodName, finderParams, finderArgs, getSessionFactory());
899 
900         if (result == null) {
901             Session session = null;
902 
903             try {
904                 session = openSession();
905 
906                 StringMaker query = new StringMaker();
907                 query.append(
908                     "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
909                 query.append("groupId = ?");
910                 query.append(" AND ");
911 
912                 if (structureId == null) {
913                     query.append("structureId IS NULL");
914                 }
915                 else {
916                     query.append("structureId = ?");
917                 }
918 
919                 query.append(" ");
920 
921                 if (obc != null) {
922                     query.append("ORDER BY ");
923                     query.append(obc.getOrderBy());
924                 }
925                 else {
926                     query.append("ORDER BY ");
927                     query.append("articleId ASC").append(", ");
928                     query.append("version DESC");
929                 }
930 
931                 Query q = session.createQuery(query.toString());
932                 int queryPos = 0;
933                 q.setLong(queryPos++, groupId);
934 
935                 if (structureId != null) {
936                     q.setString(queryPos++, structureId);
937                 }
938 
939                 List list = QueryUtil.list(q, getDialect(), begin, end);
940                 FinderCache.putResult(finderClassName, finderMethodName,
941                     finderParams, finderArgs, list);
942 
943                 return list;
944             }
945             catch (Exception e) {
946                 throw HibernateUtil.processException(e);
947             }
948             finally {
949                 closeSession(session);
950             }
951         }
952         else {
953             return (List)result;
954         }
955     }
956 
957     public JournalArticle findByG_S_First(long groupId, String structureId,
958         OrderByComparator obc) throws NoSuchArticleException, SystemException {
959         List list = findByG_S(groupId, structureId, 0, 1, obc);
960 
961         if (list.size() == 0) {
962             StringMaker msg = new StringMaker();
963             msg.append("No JournalArticle exists with the key ");
964             msg.append(StringPool.OPEN_CURLY_BRACE);
965             msg.append("groupId=");
966             msg.append(groupId);
967             msg.append(", ");
968             msg.append("structureId=");
969             msg.append(structureId);
970             msg.append(StringPool.CLOSE_CURLY_BRACE);
971             throw new NoSuchArticleException(msg.toString());
972         }
973         else {
974             return (JournalArticle)list.get(0);
975         }
976     }
977 
978     public JournalArticle findByG_S_Last(long groupId, String structureId,
979         OrderByComparator obc) throws NoSuchArticleException, SystemException {
980         int count = countByG_S(groupId, structureId);
981         List list = findByG_S(groupId, structureId, count - 1, count, obc);
982 
983         if (list.size() == 0) {
984             StringMaker msg = new StringMaker();
985             msg.append("No JournalArticle exists with the key ");
986             msg.append(StringPool.OPEN_CURLY_BRACE);
987             msg.append("groupId=");
988             msg.append(groupId);
989             msg.append(", ");
990             msg.append("structureId=");
991             msg.append(structureId);
992             msg.append(StringPool.CLOSE_CURLY_BRACE);
993             throw new NoSuchArticleException(msg.toString());
994         }
995         else {
996             return (JournalArticle)list.get(0);
997         }
998     }
999 
1000    public JournalArticle[] findByG_S_PrevAndNext(long id, long groupId,
1001        String structureId, OrderByComparator obc)
1002        throws NoSuchArticleException, SystemException {
1003        JournalArticle journalArticle = findByPrimaryKey(id);
1004        int count = countByG_S(groupId, structureId);
1005        Session session = null;
1006
1007        try {
1008            session = openSession();
1009
1010            StringMaker query = new StringMaker();
1011            query.append(
1012                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1013            query.append("groupId = ?");
1014            query.append(" AND ");
1015
1016            if (structureId == null) {
1017                query.append("structureId IS NULL");
1018            }
1019            else {
1020                query.append("structureId = ?");
1021            }
1022
1023            query.append(" ");
1024
1025            if (obc != null) {
1026                query.append("ORDER BY ");
1027                query.append(obc.getOrderBy());
1028            }
1029            else {
1030                query.append("ORDER BY ");
1031                query.append("articleId ASC").append(", ");
1032                query.append("version DESC");
1033            }
1034
1035            Query q = session.createQuery(query.toString());
1036            int queryPos = 0;
1037            q.setLong(queryPos++, groupId);
1038
1039            if (structureId != null) {
1040                q.setString(queryPos++, structureId);
1041            }
1042
1043            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1044                    journalArticle);
1045            JournalArticle[] array = new JournalArticleImpl[3];
1046            array[0] = (JournalArticle)objArray[0];
1047            array[1] = (JournalArticle)objArray[1];
1048            array[2] = (JournalArticle)objArray[2];
1049
1050            return array;
1051        }
1052        catch (Exception e) {
1053            throw HibernateUtil.processException(e);
1054        }
1055        finally {
1056            closeSession(session);
1057        }
1058    }
1059
1060    public List findByG_T(long groupId, String templateId)
1061        throws SystemException {
1062        String finderClassName = JournalArticle.class.getName();
1063        String finderMethodName = "findByG_T";
1064        String[] finderParams = new String[] {
1065                Long.class.getName(), String.class.getName()
1066            };
1067        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
1068        Object result = FinderCache.getResult(finderClassName,
1069                finderMethodName, finderParams, finderArgs, getSessionFactory());
1070
1071        if (result == null) {
1072            Session session = null;
1073
1074            try {
1075                session = openSession();
1076
1077                StringMaker query = new StringMaker();
1078                query.append(
1079                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1080                query.append("groupId = ?");
1081                query.append(" AND ");
1082
1083                if (templateId == null) {
1084                    query.append("templateId IS NULL");
1085                }
1086                else {
1087                    query.append("templateId = ?");
1088                }
1089
1090                query.append(" ");
1091                query.append("ORDER BY ");
1092                query.append("articleId ASC").append(", ");
1093                query.append("version DESC");
1094
1095                Query q = session.createQuery(query.toString());
1096                int queryPos = 0;
1097                q.setLong(queryPos++, groupId);
1098
1099                if (templateId != null) {
1100                    q.setString(queryPos++, templateId);
1101                }
1102
1103                List list = q.list();
1104                FinderCache.putResult(finderClassName, finderMethodName,
1105                    finderParams, finderArgs, list);
1106
1107                return list;
1108            }
1109            catch (Exception e) {
1110                throw HibernateUtil.processException(e);
1111            }
1112            finally {
1113                closeSession(session);
1114            }
1115        }
1116        else {
1117            return (List)result;
1118        }
1119    }
1120
1121    public List findByG_T(long groupId, String templateId, int begin, int end)
1122        throws SystemException {
1123        return findByG_T(groupId, templateId, begin, end, null);
1124    }
1125
1126    public List findByG_T(long groupId, String templateId, int begin, int end,
1127        OrderByComparator obc) throws SystemException {
1128        String finderClassName = JournalArticle.class.getName();
1129        String finderMethodName = "findByG_T";
1130        String[] finderParams = new String[] {
1131                Long.class.getName(), String.class.getName(),
1132                "java.lang.Integer", "java.lang.Integer",
1133                "com.liferay.portal.kernel.util.OrderByComparator"
1134            };
1135        Object[] finderArgs = new Object[] {
1136                new Long(groupId), templateId, String.valueOf(begin),
1137                String.valueOf(end), String.valueOf(obc)
1138            };
1139        Object result = FinderCache.getResult(finderClassName,
1140                finderMethodName, finderParams, finderArgs, getSessionFactory());
1141
1142        if (result == null) {
1143            Session session = null;
1144
1145            try {
1146                session = openSession();
1147
1148                StringMaker query = new StringMaker();
1149                query.append(
1150                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1151                query.append("groupId = ?");
1152                query.append(" AND ");
1153
1154                if (templateId == null) {
1155                    query.append("templateId IS NULL");
1156                }
1157                else {
1158                    query.append("templateId = ?");
1159                }
1160
1161                query.append(" ");
1162
1163                if (obc != null) {
1164                    query.append("ORDER BY ");
1165                    query.append(obc.getOrderBy());
1166                }
1167                else {
1168                    query.append("ORDER BY ");
1169                    query.append("articleId ASC").append(", ");
1170                    query.append("version DESC");
1171                }
1172
1173                Query q = session.createQuery(query.toString());
1174                int queryPos = 0;
1175                q.setLong(queryPos++, groupId);
1176
1177                if (templateId != null) {
1178                    q.setString(queryPos++, templateId);
1179                }
1180
1181                List list = QueryUtil.list(q, getDialect(), begin, end);
1182                FinderCache.putResult(finderClassName, finderMethodName,
1183                    finderParams, finderArgs, list);
1184
1185                return list;
1186            }
1187            catch (Exception e) {
1188                throw HibernateUtil.processException(e);
1189            }
1190            finally {
1191                closeSession(session);
1192            }
1193        }
1194        else {
1195            return (List)result;
1196        }
1197    }
1198
1199    public JournalArticle findByG_T_First(long groupId, String templateId,
1200        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1201        List list = findByG_T(groupId, templateId, 0, 1, obc);
1202
1203        if (list.size() == 0) {
1204            StringMaker msg = new StringMaker();
1205            msg.append("No JournalArticle exists with the key ");
1206            msg.append(StringPool.OPEN_CURLY_BRACE);
1207            msg.append("groupId=");
1208            msg.append(groupId);
1209            msg.append(", ");
1210            msg.append("templateId=");
1211            msg.append(templateId);
1212            msg.append(StringPool.CLOSE_CURLY_BRACE);
1213            throw new NoSuchArticleException(msg.toString());
1214        }
1215        else {
1216            return (JournalArticle)list.get(0);
1217        }
1218    }
1219
1220    public JournalArticle findByG_T_Last(long groupId, String templateId,
1221        OrderByComparator obc) throws NoSuchArticleException, SystemException {
1222        int count = countByG_T(groupId, templateId);
1223        List list = findByG_T(groupId, templateId, count - 1, count, obc);
1224
1225        if (list.size() == 0) {
1226            StringMaker msg = new StringMaker();
1227            msg.append("No JournalArticle exists with the key ");
1228            msg.append(StringPool.OPEN_CURLY_BRACE);
1229            msg.append("groupId=");
1230            msg.append(groupId);
1231            msg.append(", ");
1232            msg.append("templateId=");
1233            msg.append(templateId);
1234            msg.append(StringPool.CLOSE_CURLY_BRACE);
1235            throw new NoSuchArticleException(msg.toString());
1236        }
1237        else {
1238            return (JournalArticle)list.get(0);
1239        }
1240    }
1241
1242    public JournalArticle[] findByG_T_PrevAndNext(long id, long groupId,
1243        String templateId, OrderByComparator obc)
1244        throws NoSuchArticleException, SystemException {
1245        JournalArticle journalArticle = findByPrimaryKey(id);
1246        int count = countByG_T(groupId, templateId);
1247        Session session = null;
1248
1249        try {
1250            session = openSession();
1251
1252            StringMaker query = new StringMaker();
1253            query.append(
1254                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1255            query.append("groupId = ?");
1256            query.append(" AND ");
1257
1258            if (templateId == null) {
1259                query.append("templateId IS NULL");
1260            }
1261            else {
1262                query.append("templateId = ?");
1263            }
1264
1265            query.append(" ");
1266
1267            if (obc != null) {
1268                query.append("ORDER BY ");
1269                query.append(obc.getOrderBy());
1270            }
1271            else {
1272                query.append("ORDER BY ");
1273                query.append("articleId ASC").append(", ");
1274                query.append("version DESC");
1275            }
1276
1277            Query q = session.createQuery(query.toString());
1278            int queryPos = 0;
1279            q.setLong(queryPos++, groupId);
1280
1281            if (templateId != null) {
1282                q.setString(queryPos++, templateId);
1283            }
1284
1285            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1286                    journalArticle);
1287            JournalArticle[] array = new JournalArticleImpl[3];
1288            array[0] = (JournalArticle)objArray[0];
1289            array[1] = (JournalArticle)objArray[1];
1290            array[2] = (JournalArticle)objArray[2];
1291
1292            return array;
1293        }
1294        catch (Exception e) {
1295            throw HibernateUtil.processException(e);
1296        }
1297        finally {
1298            closeSession(session);
1299        }
1300    }
1301
1302    public JournalArticle findByG_A_V(long groupId, String articleId,
1303        double version) throws NoSuchArticleException, SystemException {
1304        JournalArticle journalArticle = fetchByG_A_V(groupId, articleId, version);
1305
1306        if (journalArticle == null) {
1307            StringMaker msg = new StringMaker();
1308            msg.append("No JournalArticle exists with the key ");
1309            msg.append(StringPool.OPEN_CURLY_BRACE);
1310            msg.append("groupId=");
1311            msg.append(groupId);
1312            msg.append(", ");
1313            msg.append("articleId=");
1314            msg.append(articleId);
1315            msg.append(", ");
1316            msg.append("version=");
1317            msg.append(version);
1318            msg.append(StringPool.CLOSE_CURLY_BRACE);
1319
1320            if (_log.isWarnEnabled()) {
1321                _log.warn(msg.toString());
1322            }
1323
1324            throw new NoSuchArticleException(msg.toString());
1325        }
1326
1327        return journalArticle;
1328    }
1329
1330    public JournalArticle fetchByG_A_V(long groupId, String articleId,
1331        double version) throws SystemException {
1332        String finderClassName = JournalArticle.class.getName();
1333        String finderMethodName = "fetchByG_A_V";
1334        String[] finderParams = new String[] {
1335                Long.class.getName(), String.class.getName(),
1336                Double.class.getName()
1337            };
1338        Object[] finderArgs = new Object[] {
1339                new Long(groupId), articleId, new Double(version)
1340            };
1341        Object result = FinderCache.getResult(finderClassName,
1342                finderMethodName, finderParams, finderArgs, getSessionFactory());
1343
1344        if (result == null) {
1345            Session session = null;
1346
1347            try {
1348                session = openSession();
1349
1350                StringMaker query = new StringMaker();
1351                query.append(
1352                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1353                query.append("groupId = ?");
1354                query.append(" AND ");
1355
1356                if (articleId == null) {
1357                    query.append("articleId IS NULL");
1358                }
1359                else {
1360                    query.append("articleId = ?");
1361                }
1362
1363                query.append(" AND ");
1364                query.append("version = ?");
1365                query.append(" ");
1366                query.append("ORDER BY ");
1367                query.append("articleId ASC").append(", ");
1368                query.append("version DESC");
1369
1370                Query q = session.createQuery(query.toString());
1371                int queryPos = 0;
1372                q.setLong(queryPos++, groupId);
1373
1374                if (articleId != null) {
1375                    q.setString(queryPos++, articleId);
1376                }
1377
1378                q.setDouble(queryPos++, version);
1379
1380                List list = q.list();
1381                FinderCache.putResult(finderClassName, finderMethodName,
1382                    finderParams, finderArgs, list);
1383
1384                if (list.size() == 0) {
1385                    return null;
1386                }
1387                else {
1388                    return (JournalArticle)list.get(0);
1389                }
1390            }
1391            catch (Exception e) {
1392                throw HibernateUtil.processException(e);
1393            }
1394            finally {
1395                closeSession(session);
1396            }
1397        }
1398        else {
1399            List list = (List)result;
1400
1401            if (list.size() == 0) {
1402                return null;
1403            }
1404            else {
1405                return (JournalArticle)list.get(0);
1406            }
1407        }
1408    }
1409
1410    public List findByG_A_A(long groupId, String articleId, boolean approved)
1411        throws SystemException {
1412        String finderClassName = JournalArticle.class.getName();
1413        String finderMethodName = "findByG_A_A";
1414        String[] finderParams = new String[] {
1415                Long.class.getName(), String.class.getName(),
1416                Boolean.class.getName()
1417            };
1418        Object[] finderArgs = new Object[] {
1419                new Long(groupId), articleId, Boolean.valueOf(approved)
1420            };
1421        Object result = FinderCache.getResult(finderClassName,
1422                finderMethodName, finderParams, finderArgs, getSessionFactory());
1423
1424        if (result == null) {
1425            Session session = null;
1426
1427            try {
1428                session = openSession();
1429
1430                StringMaker query = new StringMaker();
1431                query.append(
1432                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1433                query.append("groupId = ?");
1434                query.append(" AND ");
1435
1436                if (articleId == null) {
1437                    query.append("articleId IS NULL");
1438                }
1439                else {
1440                    query.append("articleId = ?");
1441                }
1442
1443                query.append(" AND ");
1444                query.append("approved = ?");
1445                query.append(" ");
1446                query.append("ORDER BY ");
1447                query.append("articleId ASC").append(", ");
1448                query.append("version DESC");
1449
1450                Query q = session.createQuery(query.toString());
1451                int queryPos = 0;
1452                q.setLong(queryPos++, groupId);
1453
1454                if (articleId != null) {
1455                    q.setString(queryPos++, articleId);
1456                }
1457
1458                q.setBoolean(queryPos++, approved);
1459
1460                List list = q.list();
1461                FinderCache.putResult(finderClassName, finderMethodName,
1462                    finderParams, finderArgs, list);
1463
1464                return list;
1465            }
1466            catch (Exception e) {
1467                throw HibernateUtil.processException(e);
1468            }
1469            finally {
1470                closeSession(session);
1471            }
1472        }
1473        else {
1474            return (List)result;
1475        }
1476    }
1477
1478    public List findByG_A_A(long groupId, String articleId, boolean approved,
1479        int begin, int end) throws SystemException {
1480        return findByG_A_A(groupId, articleId, approved, begin, end, null);
1481    }
1482
1483    public List findByG_A_A(long groupId, String articleId, boolean approved,
1484        int begin, int end, OrderByComparator obc) throws SystemException {
1485        String finderClassName = JournalArticle.class.getName();
1486        String finderMethodName = "findByG_A_A";
1487        String[] finderParams = new String[] {
1488                Long.class.getName(), String.class.getName(),
1489                Boolean.class.getName(), "java.lang.Integer",
1490                "java.lang.Integer",
1491                "com.liferay.portal.kernel.util.OrderByComparator"
1492            };
1493        Object[] finderArgs = new Object[] {
1494                new Long(groupId), articleId, Boolean.valueOf(approved),
1495                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1496            };
1497        Object result = FinderCache.getResult(finderClassName,
1498                finderMethodName, finderParams, finderArgs, getSessionFactory());
1499
1500        if (result == null) {
1501            Session session = null;
1502
1503            try {
1504                session = openSession();
1505
1506                StringMaker query = new StringMaker();
1507                query.append(
1508                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1509                query.append("groupId = ?");
1510                query.append(" AND ");
1511
1512                if (articleId == null) {
1513                    query.append("articleId IS NULL");
1514                }
1515                else {
1516                    query.append("articleId = ?");
1517                }
1518
1519                query.append(" AND ");
1520                query.append("approved = ?");
1521                query.append(" ");
1522
1523                if (obc != null) {
1524                    query.append("ORDER BY ");
1525                    query.append(obc.getOrderBy());
1526                }
1527                else {
1528                    query.append("ORDER BY ");
1529                    query.append("articleId ASC").append(", ");
1530                    query.append("version DESC");
1531                }
1532
1533                Query q = session.createQuery(query.toString());
1534                int queryPos = 0;
1535                q.setLong(queryPos++, groupId);
1536
1537                if (articleId != null) {
1538                    q.setString(queryPos++, articleId);
1539                }
1540
1541                q.setBoolean(queryPos++, approved);
1542
1543                List list = QueryUtil.list(q, getDialect(), begin, end);
1544                FinderCache.putResult(finderClassName, finderMethodName,
1545                    finderParams, finderArgs, list);
1546
1547                return list;
1548            }
1549            catch (Exception e) {
1550                throw HibernateUtil.processException(e);
1551            }
1552            finally {
1553                closeSession(session);
1554            }
1555        }
1556        else {
1557            return (List)result;
1558        }
1559    }
1560
1561    public JournalArticle findByG_A_A_First(long groupId, String articleId,
1562        boolean approved, OrderByComparator obc)
1563        throws NoSuchArticleException, SystemException {
1564        List list = findByG_A_A(groupId, articleId, approved, 0, 1, obc);
1565
1566        if (list.size() == 0) {
1567            StringMaker msg = new StringMaker();
1568            msg.append("No JournalArticle exists with the key ");
1569            msg.append(StringPool.OPEN_CURLY_BRACE);
1570            msg.append("groupId=");
1571            msg.append(groupId);
1572            msg.append(", ");
1573            msg.append("articleId=");
1574            msg.append(articleId);
1575            msg.append(", ");
1576            msg.append("approved=");
1577            msg.append(approved);
1578            msg.append(StringPool.CLOSE_CURLY_BRACE);
1579            throw new NoSuchArticleException(msg.toString());
1580        }
1581        else {
1582            return (JournalArticle)list.get(0);
1583        }
1584    }
1585
1586    public JournalArticle findByG_A_A_Last(long groupId, String articleId,
1587        boolean approved, OrderByComparator obc)
1588        throws NoSuchArticleException, SystemException {
1589        int count = countByG_A_A(groupId, articleId, approved);
1590        List list = findByG_A_A(groupId, articleId, approved, count - 1, count,
1591                obc);
1592
1593        if (list.size() == 0) {
1594            StringMaker msg = new StringMaker();
1595            msg.append("No JournalArticle exists with the key ");
1596            msg.append(StringPool.OPEN_CURLY_BRACE);
1597            msg.append("groupId=");
1598            msg.append(groupId);
1599            msg.append(", ");
1600            msg.append("articleId=");
1601            msg.append(articleId);
1602            msg.append(", ");
1603            msg.append("approved=");
1604            msg.append(approved);
1605            msg.append(StringPool.CLOSE_CURLY_BRACE);
1606            throw new NoSuchArticleException(msg.toString());
1607        }
1608        else {
1609            return (JournalArticle)list.get(0);
1610        }
1611    }
1612
1613    public JournalArticle[] findByG_A_A_PrevAndNext(long id, long groupId,
1614        String articleId, boolean approved, OrderByComparator obc)
1615        throws NoSuchArticleException, SystemException {
1616        JournalArticle journalArticle = findByPrimaryKey(id);
1617        int count = countByG_A_A(groupId, articleId, approved);
1618        Session session = null;
1619
1620        try {
1621            session = openSession();
1622
1623            StringMaker query = new StringMaker();
1624            query.append(
1625                "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1626            query.append("groupId = ?");
1627            query.append(" AND ");
1628
1629            if (articleId == null) {
1630                query.append("articleId IS NULL");
1631            }
1632            else {
1633                query.append("articleId = ?");
1634            }
1635
1636            query.append(" AND ");
1637            query.append("approved = ?");
1638            query.append(" ");
1639
1640            if (obc != null) {
1641                query.append("ORDER BY ");
1642                query.append(obc.getOrderBy());
1643            }
1644            else {
1645                query.append("ORDER BY ");
1646                query.append("articleId ASC").append(", ");
1647                query.append("version DESC");
1648            }
1649
1650            Query q = session.createQuery(query.toString());
1651            int queryPos = 0;
1652            q.setLong(queryPos++, groupId);
1653
1654            if (articleId != null) {
1655                q.setString(queryPos++, articleId);
1656            }
1657
1658            q.setBoolean(queryPos++, approved);
1659
1660            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1661                    journalArticle);
1662            JournalArticle[] array = new JournalArticleImpl[3];
1663            array[0] = (JournalArticle)objArray[0];
1664            array[1] = (JournalArticle)objArray[1];
1665            array[2] = (JournalArticle)objArray[2];
1666
1667            return array;
1668        }
1669        catch (Exception e) {
1670            throw HibernateUtil.processException(e);
1671        }
1672        finally {
1673            closeSession(session);
1674        }
1675    }
1676
1677    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1678        throws SystemException {
1679        Session session = null;
1680
1681        try {
1682            session = openSession();
1683
1684            DynamicQuery query = queryInitializer.initialize(session);
1685
1686            return query.list();
1687        }
1688        catch (Exception e) {
1689            throw HibernateUtil.processException(e);
1690        }
1691        finally {
1692            closeSession(session);
1693        }
1694    }
1695
1696    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1697        int begin, int end) throws SystemException {
1698        Session session = null;
1699
1700        try {
1701            session = openSession();
1702
1703            DynamicQuery query = queryInitializer.initialize(session);
1704            query.setLimit(begin, end);
1705
1706            return query.list();
1707        }
1708        catch (Exception e) {
1709            throw HibernateUtil.processException(e);
1710        }
1711        finally {
1712            closeSession(session);
1713        }
1714    }
1715
1716    public List findAll() throws SystemException {
1717        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1718    }
1719
1720    public List findAll(int begin, int end) throws SystemException {
1721        return findAll(begin, end, null);
1722    }
1723
1724    public List findAll(int begin, int end, OrderByComparator obc)
1725        throws SystemException {
1726        String finderClassName = JournalArticle.class.getName();
1727        String finderMethodName = "findAll";
1728        String[] finderParams = new String[] {
1729                "java.lang.Integer", "java.lang.Integer",
1730                "com.liferay.portal.kernel.util.OrderByComparator"
1731            };
1732        Object[] finderArgs = new Object[] {
1733                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1734            };
1735        Object result = FinderCache.getResult(finderClassName,
1736                finderMethodName, finderParams, finderArgs, getSessionFactory());
1737
1738        if (result == null) {
1739            Session session = null;
1740
1741            try {
1742                session = openSession();
1743
1744                StringMaker query = new StringMaker();
1745                query.append(
1746                    "FROM com.liferay.portlet.journal.model.JournalArticle ");
1747
1748                if (obc != null) {
1749                    query.append("ORDER BY ");
1750                    query.append(obc.getOrderBy());
1751                }
1752                else {
1753                    query.append("ORDER BY ");
1754                    query.append("articleId ASC").append(", ");
1755                    query.append("version DESC");
1756                }
1757
1758                Query q = session.createQuery(query.toString());
1759                List list = QueryUtil.list(q, getDialect(), begin, end);
1760
1761                if (obc == null) {
1762                    Collections.sort(list);
1763                }
1764
1765                FinderCache.putResult(finderClassName, finderMethodName,
1766                    finderParams, finderArgs, list);
1767
1768                return list;
1769            }
1770            catch (Exception e) {
1771                throw HibernateUtil.processException(e);
1772            }
1773            finally {
1774                closeSession(session);
1775            }
1776        }
1777        else {
1778            return (List)result;
1779        }
1780    }
1781
1782    public void removeByGroupId(long groupId) throws SystemException {
1783        Iterator itr = findByGroupId(groupId).iterator();
1784
1785        while (itr.hasNext()) {
1786            JournalArticle journalArticle = (JournalArticle)itr.next();
1787            remove(journalArticle);
1788        }
1789    }
1790
1791    public void removeByCompanyId(long companyId) throws SystemException {
1792        Iterator itr = findByCompanyId(companyId).iterator();
1793
1794        while (itr.hasNext()) {
1795            JournalArticle journalArticle = (JournalArticle)itr.next();
1796            remove(journalArticle);
1797        }
1798    }
1799
1800    public void removeByG_A(long groupId, String articleId)
1801        throws SystemException {
1802        Iterator itr = findByG_A(groupId, articleId).iterator();
1803
1804        while (itr.hasNext()) {
1805            JournalArticle journalArticle = (JournalArticle)itr.next();
1806            remove(journalArticle);
1807        }
1808    }
1809
1810    public void removeByG_S(long groupId, String structureId)
1811        throws SystemException {
1812        Iterator itr = findByG_S(groupId, structureId).iterator();
1813
1814        while (itr.hasNext()) {
1815            JournalArticle journalArticle = (JournalArticle)itr.next();
1816            remove(journalArticle);
1817        }
1818    }
1819
1820    public void removeByG_T(long groupId, String templateId)
1821        throws SystemException {
1822        Iterator itr = findByG_T(groupId, templateId).iterator();
1823
1824        while (itr.hasNext()) {
1825            JournalArticle journalArticle = (JournalArticle)itr.next();
1826            remove(journalArticle);
1827        }
1828    }
1829
1830    public void removeByG_A_V(long groupId, String articleId, double version)
1831        throws NoSuchArticleException, SystemException {
1832        JournalArticle journalArticle = findByG_A_V(groupId, articleId, version);
1833        remove(journalArticle);
1834    }
1835
1836    public void removeByG_A_A(long groupId, String articleId, boolean approved)
1837        throws SystemException {
1838        Iterator itr = findByG_A_A(groupId, articleId, approved).iterator();
1839
1840        while (itr.hasNext()) {
1841            JournalArticle journalArticle = (JournalArticle)itr.next();
1842            remove(journalArticle);
1843        }
1844    }
1845
1846    public void removeAll() throws SystemException {
1847        Iterator itr = findAll().iterator();
1848
1849        while (itr.hasNext()) {
1850            remove((JournalArticle)itr.next());
1851        }
1852    }
1853
1854    public int countByGroupId(long groupId) throws SystemException {
1855        String finderClassName = JournalArticle.class.getName();
1856        String finderMethodName = "countByGroupId";
1857        String[] finderParams = new String[] { Long.class.getName() };
1858        Object[] finderArgs = new Object[] { new Long(groupId) };
1859        Object result = FinderCache.getResult(finderClassName,
1860                finderMethodName, finderParams, finderArgs, getSessionFactory());
1861
1862        if (result == null) {
1863            Session session = null;
1864
1865            try {
1866                session = openSession();
1867
1868                StringMaker query = new StringMaker();
1869                query.append("SELECT COUNT(*) ");
1870                query.append(
1871                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1872                query.append("groupId = ?");
1873                query.append(" ");
1874
1875                Query q = session.createQuery(query.toString());
1876                int queryPos = 0;
1877                q.setLong(queryPos++, groupId);
1878
1879                Long count = null;
1880                Iterator itr = q.list().iterator();
1881
1882                if (itr.hasNext()) {
1883                    count = (Long)itr.next();
1884                }
1885
1886                if (count == null) {
1887                    count = new Long(0);
1888                }
1889
1890                FinderCache.putResult(finderClassName, finderMethodName,
1891                    finderParams, finderArgs, count);
1892
1893                return count.intValue();
1894            }
1895            catch (Exception e) {
1896                throw HibernateUtil.processException(e);
1897            }
1898            finally {
1899                closeSession(session);
1900            }
1901        }
1902        else {
1903            return ((Long)result).intValue();
1904        }
1905    }
1906
1907    public int countByCompanyId(long companyId) throws SystemException {
1908        String finderClassName = JournalArticle.class.getName();
1909        String finderMethodName = "countByCompanyId";
1910        String[] finderParams = new String[] { Long.class.getName() };
1911        Object[] finderArgs = new Object[] { new Long(companyId) };
1912        Object result = FinderCache.getResult(finderClassName,
1913                finderMethodName, finderParams, finderArgs, getSessionFactory());
1914
1915        if (result == null) {
1916            Session session = null;
1917
1918            try {
1919                session = openSession();
1920
1921                StringMaker query = new StringMaker();
1922                query.append("SELECT COUNT(*) ");
1923                query.append(
1924                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1925                query.append("companyId = ?");
1926                query.append(" ");
1927
1928                Query q = session.createQuery(query.toString());
1929                int queryPos = 0;
1930                q.setLong(queryPos++, companyId);
1931
1932                Long count = null;
1933                Iterator itr = q.list().iterator();
1934
1935                if (itr.hasNext()) {
1936                    count = (Long)itr.next();
1937                }
1938
1939                if (count == null) {
1940                    count = new Long(0);
1941                }
1942
1943                FinderCache.putResult(finderClassName, finderMethodName,
1944                    finderParams, finderArgs, count);
1945
1946                return count.intValue();
1947            }
1948            catch (Exception e) {
1949                throw HibernateUtil.processException(e);
1950            }
1951            finally {
1952                closeSession(session);
1953            }
1954        }
1955        else {
1956            return ((Long)result).intValue();
1957        }
1958    }
1959
1960    public int countByG_A(long groupId, String articleId)
1961        throws SystemException {
1962        String finderClassName = JournalArticle.class.getName();
1963        String finderMethodName = "countByG_A";
1964        String[] finderParams = new String[] {
1965                Long.class.getName(), String.class.getName()
1966            };
1967        Object[] finderArgs = new Object[] { new Long(groupId), articleId };
1968        Object result = FinderCache.getResult(finderClassName,
1969                finderMethodName, finderParams, finderArgs, getSessionFactory());
1970
1971        if (result == null) {
1972            Session session = null;
1973
1974            try {
1975                session = openSession();
1976
1977                StringMaker query = new StringMaker();
1978                query.append("SELECT COUNT(*) ");
1979                query.append(
1980                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
1981                query.append("groupId = ?");
1982                query.append(" AND ");
1983
1984                if (articleId == null) {
1985                    query.append("articleId IS NULL");
1986                }
1987                else {
1988                    query.append("articleId = ?");
1989                }
1990
1991                query.append(" ");
1992
1993                Query q = session.createQuery(query.toString());
1994                int queryPos = 0;
1995                q.setLong(queryPos++, groupId);
1996
1997                if (articleId != null) {
1998                    q.setString(queryPos++, articleId);
1999                }
2000
2001                Long count = null;
2002                Iterator itr = q.list().iterator();
2003
2004                if (itr.hasNext()) {
2005                    count = (Long)itr.next();
2006                }
2007
2008                if (count == null) {
2009                    count = new Long(0);
2010                }
2011
2012                FinderCache.putResult(finderClassName, finderMethodName,
2013                    finderParams, finderArgs, count);
2014
2015                return count.intValue();
2016            }
2017            catch (Exception e) {
2018                throw HibernateUtil.processException(e);
2019            }
2020            finally {
2021                closeSession(session);
2022            }
2023        }
2024        else {
2025            return ((Long)result).intValue();
2026        }
2027    }
2028
2029    public int countByG_S(long groupId, String structureId)
2030        throws SystemException {
2031        String finderClassName = JournalArticle.class.getName();
2032        String finderMethodName = "countByG_S";
2033        String[] finderParams = new String[] {
2034                Long.class.getName(), String.class.getName()
2035            };
2036        Object[] finderArgs = new Object[] { new Long(groupId), structureId };
2037        Object result = FinderCache.getResult(finderClassName,
2038                finderMethodName, finderParams, finderArgs, getSessionFactory());
2039
2040        if (result == null) {
2041            Session session = null;
2042
2043            try {
2044                session = openSession();
2045
2046                StringMaker query = new StringMaker();
2047                query.append("SELECT COUNT(*) ");
2048                query.append(
2049                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2050                query.append("groupId = ?");
2051                query.append(" AND ");
2052
2053                if (structureId == null) {
2054                    query.append("structureId IS NULL");
2055                }
2056                else {
2057                    query.append("structureId = ?");
2058                }
2059
2060                query.append(" ");
2061
2062                Query q = session.createQuery(query.toString());
2063                int queryPos = 0;
2064                q.setLong(queryPos++, groupId);
2065
2066                if (structureId != null) {
2067                    q.setString(queryPos++, structureId);
2068                }
2069
2070                Long count = null;
2071                Iterator itr = q.list().iterator();
2072
2073                if (itr.hasNext()) {
2074                    count = (Long)itr.next();
2075                }
2076
2077                if (count == null) {
2078                    count = new Long(0);
2079                }
2080
2081                FinderCache.putResult(finderClassName, finderMethodName,
2082                    finderParams, finderArgs, count);
2083
2084                return count.intValue();
2085            }
2086            catch (Exception e) {
2087                throw HibernateUtil.processException(e);
2088            }
2089            finally {
2090                closeSession(session);
2091            }
2092        }
2093        else {
2094            return ((Long)result).intValue();
2095        }
2096    }
2097
2098    public int countByG_T(long groupId, String templateId)
2099        throws SystemException {
2100        String finderClassName = JournalArticle.class.getName();
2101        String finderMethodName = "countByG_T";
2102        String[] finderParams = new String[] {
2103                Long.class.getName(), String.class.getName()
2104            };
2105        Object[] finderArgs = new Object[] { new Long(groupId), templateId };
2106        Object result = FinderCache.getResult(finderClassName,
2107                finderMethodName, finderParams, finderArgs, getSessionFactory());
2108
2109        if (result == null) {
2110            Session session = null;
2111
2112            try {
2113                session = openSession();
2114
2115                StringMaker query = new StringMaker();
2116                query.append("SELECT COUNT(*) ");
2117                query.append(
2118                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2119                query.append("groupId = ?");
2120                query.append(" AND ");
2121
2122                if (templateId == null) {
2123                    query.append("templateId IS NULL");
2124                }
2125                else {
2126                    query.append("templateId = ?");
2127                }
2128
2129                query.append(" ");
2130
2131                Query q = session.createQuery(query.toString());
2132                int queryPos = 0;
2133                q.setLong(queryPos++, groupId);
2134
2135                if (templateId != null) {
2136                    q.setString(queryPos++, templateId);
2137                }
2138
2139                Long count = null;
2140                Iterator itr = q.list().iterator();
2141
2142                if (itr.hasNext()) {
2143                    count = (Long)itr.next();
2144                }
2145
2146                if (count == null) {
2147                    count = new Long(0);
2148                }
2149
2150                FinderCache.putResult(finderClassName, finderMethodName,
2151                    finderParams, finderArgs, count);
2152
2153                return count.intValue();
2154            }
2155            catch (Exception e) {
2156                throw HibernateUtil.processException(e);
2157            }
2158            finally {
2159                closeSession(session);
2160            }
2161        }
2162        else {
2163            return ((Long)result).intValue();
2164        }
2165    }
2166
2167    public int countByG_A_V(long groupId, String articleId, double version)
2168        throws SystemException {
2169        String finderClassName = JournalArticle.class.getName();
2170        String finderMethodName = "countByG_A_V";
2171        String[] finderParams = new String[] {
2172                Long.class.getName(), String.class.getName(),
2173                Double.class.getName()
2174            };
2175        Object[] finderArgs = new Object[] {
2176                new Long(groupId), articleId, new Double(version)
2177            };
2178        Object result = FinderCache.getResult(finderClassName,
2179                finderMethodName, finderParams, finderArgs, getSessionFactory());
2180
2181        if (result == null) {
2182            Session session = null;
2183
2184            try {
2185                session = openSession();
2186
2187                StringMaker query = new StringMaker();
2188                query.append("SELECT COUNT(*) ");
2189                query.append(
2190                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2191                query.append("groupId = ?");
2192                query.append(" AND ");
2193
2194                if (articleId == null) {
2195                    query.append("articleId IS NULL");
2196                }
2197                else {
2198                    query.append("articleId = ?");
2199                }
2200
2201                query.append(" AND ");
2202                query.append("version = ?");
2203                query.append(" ");
2204
2205                Query q = session.createQuery(query.toString());
2206                int queryPos = 0;
2207                q.setLong(queryPos++, groupId);
2208
2209                if (articleId != null) {
2210                    q.setString(queryPos++, articleId);
2211                }
2212
2213                q.setDouble(queryPos++, version);
2214
2215                Long count = null;
2216                Iterator itr = q.list().iterator();
2217
2218                if (itr.hasNext()) {
2219                    count = (Long)itr.next();
2220                }
2221
2222                if (count == null) {
2223                    count = new Long(0);
2224                }
2225
2226                FinderCache.putResult(finderClassName, finderMethodName,
2227                    finderParams, finderArgs, count);
2228
2229                return count.intValue();
2230            }
2231            catch (Exception e) {
2232                throw HibernateUtil.processException(e);
2233            }
2234            finally {
2235                closeSession(session);
2236            }
2237        }
2238        else {
2239            return ((Long)result).intValue();
2240        }
2241    }
2242
2243    public int countByG_A_A(long groupId, String articleId, boolean approved)
2244        throws SystemException {
2245        String finderClassName = JournalArticle.class.getName();
2246        String finderMethodName = "countByG_A_A";
2247        String[] finderParams = new String[] {
2248                Long.class.getName(), String.class.getName(),
2249                Boolean.class.getName()
2250            };
2251        Object[] finderArgs = new Object[] {
2252                new Long(groupId), articleId, Boolean.valueOf(approved)
2253            };
2254        Object result = FinderCache.getResult(finderClassName,
2255                finderMethodName, finderParams, finderArgs, getSessionFactory());
2256
2257        if (result == null) {
2258            Session session = null;
2259
2260            try {
2261                session = openSession();
2262
2263                StringMaker query = new StringMaker();
2264                query.append("SELECT COUNT(*) ");
2265                query.append(
2266                    "FROM com.liferay.portlet.journal.model.JournalArticle WHERE ");
2267                query.append("groupId = ?");
2268                query.append(" AND ");
2269
2270                if (articleId == null) {
2271                    query.append("articleId IS NULL");
2272                }
2273                else {
2274                    query.append("articleId = ?");
2275                }
2276
2277                query.append(" AND ");
2278                query.append("approved = ?");
2279                query.append(" ");
2280
2281                Query q = session.createQuery(query.toString());
2282                int queryPos = 0;
2283                q.setLong(queryPos++, groupId);
2284
2285                if (articleId != null) {
2286                    q.setString(queryPos++, articleId);
2287                }
2288
2289                q.setBoolean(queryPos++, approved);
2290
2291                Long count = null;
2292                Iterator itr = q.list().iterator();
2293
2294                if (itr.hasNext()) {
2295                    count = (Long)itr.next();
2296                }
2297
2298                if (count == null) {
2299                    count = new Long(0);
2300                }
2301
2302                FinderCache.putResult(finderClassName, finderMethodName,
2303                    finderParams, finderArgs, count);
2304
2305                return count.intValue();
2306            }
2307            catch (Exception e) {
2308                throw HibernateUtil.processException(e);
2309            }
2310            finally {
2311                closeSession(session);
2312            }
2313        }
2314        else {
2315            return ((Long)result).intValue();
2316        }
2317    }
2318
2319    public int countAll() throws SystemException {
2320        String finderClassName = JournalArticle.class.getName();
2321        String finderMethodName = "countAll";
2322        String[] finderParams = new String[] {  };
2323        Object[] finderArgs = new Object[] {  };
2324        Object result = FinderCache.getResult(finderClassName,
2325                finderMethodName, finderParams, finderArgs, getSessionFactory());
2326
2327        if (result == null) {
2328            Session session = null;
2329
2330            try {
2331                session = openSession();
2332
2333                StringMaker query = new StringMaker();
2334                query.append("SELECT COUNT(*) ");
2335                query.append(
2336                    "FROM com.liferay.portlet.journal.model.JournalArticle");
2337
2338                Query q = session.createQuery(query.toString());
2339                Long count = null;
2340                Iterator itr = q.list().iterator();
2341
2342                if (itr.hasNext()) {
2343                    count = (Long)itr.next();
2344                }
2345
2346                if (count == null) {
2347                    count = new Long(0);
2348                }
2349
2350                FinderCache.putResult(finderClassName, finderMethodName,
2351                    finderParams, finderArgs, count);
2352
2353                return count.intValue();
2354            }
2355            catch (Exception e) {
2356                throw HibernateUtil.processException(e);
2357            }
2358            finally {
2359                closeSession(session);
2360            }
2361        }
2362        else {
2363            return ((Long)result).intValue();
2364        }
2365    }
2366
2367    protected void initDao() {
2368    }
2369
2370    private static Log _log = LogFactory.getLog(JournalArticlePersistenceImpl.class);
2371}