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