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