1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portlet.journal.service.persistence;
24  
25  import com.liferay.portal.SystemException;
26  import com.liferay.portal.kernel.bean.InitializingBean;
27  import com.liferay.portal.kernel.dao.orm.DynamicQuery;
28  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
29  import com.liferay.portal.kernel.dao.orm.Query;
30  import com.liferay.portal.kernel.dao.orm.QueryPos;
31  import com.liferay.portal.kernel.dao.orm.QueryUtil;
32  import com.liferay.portal.kernel.dao.orm.Session;
33  import com.liferay.portal.kernel.util.GetterUtil;
34  import com.liferay.portal.kernel.util.ListUtil;
35  import com.liferay.portal.kernel.util.OrderByComparator;
36  import com.liferay.portal.kernel.util.StringPool;
37  import com.liferay.portal.kernel.util.StringUtil;
38  import com.liferay.portal.model.ModelListener;
39  import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40  
41  import com.liferay.portlet.journal.NoSuchContentSearchException;
42  import com.liferay.portlet.journal.model.JournalContentSearch;
43  import com.liferay.portlet.journal.model.impl.JournalContentSearchImpl;
44  import com.liferay.portlet.journal.model.impl.JournalContentSearchModelImpl;
45  
46  import org.apache.commons.logging.Log;
47  import org.apache.commons.logging.LogFactory;
48  
49  import java.util.ArrayList;
50  import java.util.Collections;
51  import java.util.Iterator;
52  import java.util.List;
53  
54  /**
55   * <a href="JournalContentSearchPersistenceImpl.java.html"><b><i>View Source</i></b></a>
56   *
57   * @author Brian Wing Shun Chan
58   *
59   */
60  public class JournalContentSearchPersistenceImpl extends BasePersistenceImpl
61      implements JournalContentSearchPersistence, InitializingBean {
62      public JournalContentSearch create(long contentSearchId) {
63          JournalContentSearch journalContentSearch = new JournalContentSearchImpl();
64  
65          journalContentSearch.setNew(true);
66          journalContentSearch.setPrimaryKey(contentSearchId);
67  
68          return journalContentSearch;
69      }
70  
71      public JournalContentSearch remove(long contentSearchId)
72          throws NoSuchContentSearchException, SystemException {
73          Session session = null;
74  
75          try {
76              session = openSession();
77  
78              JournalContentSearch journalContentSearch = (JournalContentSearch)session.get(JournalContentSearchImpl.class,
79                      new Long(contentSearchId));
80  
81              if (journalContentSearch == null) {
82                  if (_log.isWarnEnabled()) {
83                      _log.warn(
84                          "No JournalContentSearch exists with the primary key " +
85                          contentSearchId);
86                  }
87  
88                  throw new NoSuchContentSearchException(
89                      "No JournalContentSearch exists with the primary key " +
90                      contentSearchId);
91              }
92  
93              return remove(journalContentSearch);
94          }
95          catch (NoSuchContentSearchException nsee) {
96              throw nsee;
97          }
98          catch (Exception e) {
99              throw processException(e);
100         }
101         finally {
102             closeSession(session);
103         }
104     }
105 
106     public JournalContentSearch remove(
107         JournalContentSearch journalContentSearch) throws SystemException {
108         if (_listeners.length > 0) {
109             for (ModelListener listener : _listeners) {
110                 listener.onBeforeRemove(journalContentSearch);
111             }
112         }
113 
114         journalContentSearch = removeImpl(journalContentSearch);
115 
116         if (_listeners.length > 0) {
117             for (ModelListener listener : _listeners) {
118                 listener.onAfterRemove(journalContentSearch);
119             }
120         }
121 
122         return journalContentSearch;
123     }
124 
125     protected JournalContentSearch removeImpl(
126         JournalContentSearch journalContentSearch) throws SystemException {
127         Session session = null;
128 
129         try {
130             session = openSession();
131 
132             session.delete(journalContentSearch);
133 
134             session.flush();
135 
136             return journalContentSearch;
137         }
138         catch (Exception e) {
139             throw processException(e);
140         }
141         finally {
142             closeSession(session);
143 
144             FinderCacheUtil.clearCache(JournalContentSearch.class.getName());
145         }
146     }
147 
148     /**
149      * @deprecated Use <code>update(JournalContentSearch journalContentSearch, boolean merge)</code>.
150      */
151     public JournalContentSearch update(
152         JournalContentSearch journalContentSearch) throws SystemException {
153         if (_log.isWarnEnabled()) {
154             _log.warn(
155                 "Using the deprecated update(JournalContentSearch journalContentSearch) method. Use update(JournalContentSearch journalContentSearch, boolean merge) instead.");
156         }
157 
158         return update(journalContentSearch, false);
159     }
160 
161     /**
162      * Add, update, or merge, the entity. This method also calls the model
163      * listeners to trigger the proper events associated with adding, deleting,
164      * or updating an entity.
165      *
166      * @param        journalContentSearch the entity to add, update, or merge
167      * @param        merge boolean value for whether to merge the entity. The
168      *                default value is false. Setting merge to true is more
169      *                expensive and should only be true when journalContentSearch is
170      *                transient. See LEP-5473 for a detailed discussion of this
171      *                method.
172      * @return        true if the portlet can be displayed via Ajax
173      */
174     public JournalContentSearch update(
175         JournalContentSearch journalContentSearch, boolean merge)
176         throws SystemException {
177         boolean isNew = journalContentSearch.isNew();
178 
179         if (_listeners.length > 0) {
180             for (ModelListener listener : _listeners) {
181                 if (isNew) {
182                     listener.onBeforeCreate(journalContentSearch);
183                 }
184                 else {
185                     listener.onBeforeUpdate(journalContentSearch);
186                 }
187             }
188         }
189 
190         journalContentSearch = updateImpl(journalContentSearch, merge);
191 
192         if (_listeners.length > 0) {
193             for (ModelListener listener : _listeners) {
194                 if (isNew) {
195                     listener.onAfterCreate(journalContentSearch);
196                 }
197                 else {
198                     listener.onAfterUpdate(journalContentSearch);
199                 }
200             }
201         }
202 
203         return journalContentSearch;
204     }
205 
206     public JournalContentSearch updateImpl(
207         com.liferay.portlet.journal.model.JournalContentSearch journalContentSearch,
208         boolean merge) throws SystemException {
209         Session session = null;
210 
211         try {
212             session = openSession();
213 
214             if (merge) {
215                 session.merge(journalContentSearch);
216             }
217             else {
218                 if (journalContentSearch.isNew()) {
219                     session.save(journalContentSearch);
220                 }
221             }
222 
223             session.flush();
224 
225             journalContentSearch.setNew(false);
226 
227             return journalContentSearch;
228         }
229         catch (Exception e) {
230             throw processException(e);
231         }
232         finally {
233             closeSession(session);
234 
235             FinderCacheUtil.clearCache(JournalContentSearch.class.getName());
236         }
237     }
238 
239     public JournalContentSearch findByPrimaryKey(long contentSearchId)
240         throws NoSuchContentSearchException, SystemException {
241         JournalContentSearch journalContentSearch = fetchByPrimaryKey(contentSearchId);
242 
243         if (journalContentSearch == null) {
244             if (_log.isWarnEnabled()) {
245                 _log.warn(
246                     "No JournalContentSearch exists with the primary key " +
247                     contentSearchId);
248             }
249 
250             throw new NoSuchContentSearchException(
251                 "No JournalContentSearch exists with the primary key " +
252                 contentSearchId);
253         }
254 
255         return journalContentSearch;
256     }
257 
258     public JournalContentSearch fetchByPrimaryKey(long contentSearchId)
259         throws SystemException {
260         Session session = null;
261 
262         try {
263             session = openSession();
264 
265             return (JournalContentSearch)session.get(JournalContentSearchImpl.class,
266                 new Long(contentSearchId));
267         }
268         catch (Exception e) {
269             throw processException(e);
270         }
271         finally {
272             closeSession(session);
273         }
274     }
275 
276     public List<JournalContentSearch> findByG_P(long groupId,
277         boolean privateLayout) throws SystemException {
278         boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
279         String finderClassName = JournalContentSearch.class.getName();
280         String finderMethodName = "findByG_P";
281         String[] finderParams = new String[] {
282                 Long.class.getName(), Boolean.class.getName()
283             };
284         Object[] finderArgs = new Object[] {
285                 new Long(groupId), Boolean.valueOf(privateLayout)
286             };
287 
288         Object result = null;
289 
290         if (finderClassNameCacheEnabled) {
291             result = FinderCacheUtil.getResult(finderClassName,
292                     finderMethodName, finderParams, finderArgs, this);
293         }
294 
295         if (result == null) {
296             Session session = null;
297 
298             try {
299                 session = openSession();
300 
301                 StringBuilder query = new StringBuilder();
302 
303                 query.append(
304                     "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
305 
306                 query.append("groupId = ?");
307 
308                 query.append(" AND ");
309 
310                 query.append("privateLayout = ?");
311 
312                 query.append(" ");
313 
314                 Query q = session.createQuery(query.toString());
315 
316                 QueryPos qPos = QueryPos.getInstance(q);
317 
318                 qPos.add(groupId);
319 
320                 qPos.add(privateLayout);
321 
322                 List<JournalContentSearch> list = q.list();
323 
324                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
325                     finderClassName, finderMethodName, finderParams,
326                     finderArgs, list);
327 
328                 return list;
329             }
330             catch (Exception e) {
331                 throw processException(e);
332             }
333             finally {
334                 closeSession(session);
335             }
336         }
337         else {
338             return (List<JournalContentSearch>)result;
339         }
340     }
341 
342     public List<JournalContentSearch> findByG_P(long groupId,
343         boolean privateLayout, int start, int end) throws SystemException {
344         return findByG_P(groupId, privateLayout, start, end, null);
345     }
346 
347     public List<JournalContentSearch> findByG_P(long groupId,
348         boolean privateLayout, int start, int end, OrderByComparator obc)
349         throws SystemException {
350         boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
351         String finderClassName = JournalContentSearch.class.getName();
352         String finderMethodName = "findByG_P";
353         String[] finderParams = new String[] {
354                 Long.class.getName(), Boolean.class.getName(),
355                 
356                 "java.lang.Integer", "java.lang.Integer",
357                 "com.liferay.portal.kernel.util.OrderByComparator"
358             };
359         Object[] finderArgs = new Object[] {
360                 new Long(groupId), Boolean.valueOf(privateLayout),
361                 
362                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
363             };
364 
365         Object result = null;
366 
367         if (finderClassNameCacheEnabled) {
368             result = FinderCacheUtil.getResult(finderClassName,
369                     finderMethodName, finderParams, finderArgs, this);
370         }
371 
372         if (result == null) {
373             Session session = null;
374 
375             try {
376                 session = openSession();
377 
378                 StringBuilder query = new StringBuilder();
379 
380                 query.append(
381                     "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
382 
383                 query.append("groupId = ?");
384 
385                 query.append(" AND ");
386 
387                 query.append("privateLayout = ?");
388 
389                 query.append(" ");
390 
391                 if (obc != null) {
392                     query.append("ORDER BY ");
393                     query.append(obc.getOrderBy());
394                 }
395 
396                 Query q = session.createQuery(query.toString());
397 
398                 QueryPos qPos = QueryPos.getInstance(q);
399 
400                 qPos.add(groupId);
401 
402                 qPos.add(privateLayout);
403 
404                 List<JournalContentSearch> list = (List<JournalContentSearch>)QueryUtil.list(q,
405                         getDialect(), start, end);
406 
407                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
408                     finderClassName, finderMethodName, finderParams,
409                     finderArgs, list);
410 
411                 return list;
412             }
413             catch (Exception e) {
414                 throw processException(e);
415             }
416             finally {
417                 closeSession(session);
418             }
419         }
420         else {
421             return (List<JournalContentSearch>)result;
422         }
423     }
424 
425     public JournalContentSearch findByG_P_First(long groupId,
426         boolean privateLayout, OrderByComparator obc)
427         throws NoSuchContentSearchException, SystemException {
428         List<JournalContentSearch> list = findByG_P(groupId, privateLayout, 0,
429                 1, obc);
430 
431         if (list.size() == 0) {
432             StringBuilder msg = new StringBuilder();
433 
434             msg.append("No JournalContentSearch exists with the key {");
435 
436             msg.append("groupId=" + groupId);
437 
438             msg.append(", ");
439             msg.append("privateLayout=" + privateLayout);
440 
441             msg.append(StringPool.CLOSE_CURLY_BRACE);
442 
443             throw new NoSuchContentSearchException(msg.toString());
444         }
445         else {
446             return list.get(0);
447         }
448     }
449 
450     public JournalContentSearch findByG_P_Last(long groupId,
451         boolean privateLayout, OrderByComparator obc)
452         throws NoSuchContentSearchException, SystemException {
453         int count = countByG_P(groupId, privateLayout);
454 
455         List<JournalContentSearch> list = findByG_P(groupId, privateLayout,
456                 count - 1, count, obc);
457 
458         if (list.size() == 0) {
459             StringBuilder msg = new StringBuilder();
460 
461             msg.append("No JournalContentSearch exists with the key {");
462 
463             msg.append("groupId=" + groupId);
464 
465             msg.append(", ");
466             msg.append("privateLayout=" + privateLayout);
467 
468             msg.append(StringPool.CLOSE_CURLY_BRACE);
469 
470             throw new NoSuchContentSearchException(msg.toString());
471         }
472         else {
473             return list.get(0);
474         }
475     }
476 
477     public JournalContentSearch[] findByG_P_PrevAndNext(long contentSearchId,
478         long groupId, boolean privateLayout, OrderByComparator obc)
479         throws NoSuchContentSearchException, SystemException {
480         JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
481 
482         int count = countByG_P(groupId, privateLayout);
483 
484         Session session = null;
485 
486         try {
487             session = openSession();
488 
489             StringBuilder query = new StringBuilder();
490 
491             query.append(
492                 "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
493 
494             query.append("groupId = ?");
495 
496             query.append(" AND ");
497 
498             query.append("privateLayout = ?");
499 
500             query.append(" ");
501 
502             if (obc != null) {
503                 query.append("ORDER BY ");
504                 query.append(obc.getOrderBy());
505             }
506 
507             Query q = session.createQuery(query.toString());
508 
509             QueryPos qPos = QueryPos.getInstance(q);
510 
511             qPos.add(groupId);
512 
513             qPos.add(privateLayout);
514 
515             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
516                     journalContentSearch);
517 
518             JournalContentSearch[] array = new JournalContentSearchImpl[3];
519 
520             array[0] = (JournalContentSearch)objArray[0];
521             array[1] = (JournalContentSearch)objArray[1];
522             array[2] = (JournalContentSearch)objArray[2];
523 
524             return array;
525         }
526         catch (Exception e) {
527             throw processException(e);
528         }
529         finally {
530             closeSession(session);
531         }
532     }
533 
534     public List<JournalContentSearch> findByG_A(long groupId, String articleId)
535         throws SystemException {
536         boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
537         String finderClassName = JournalContentSearch.class.getName();
538         String finderMethodName = "findByG_A";
539         String[] finderParams = new String[] {
540                 Long.class.getName(), String.class.getName()
541             };
542         Object[] finderArgs = new Object[] { new Long(groupId), articleId };
543 
544         Object result = null;
545 
546         if (finderClassNameCacheEnabled) {
547             result = FinderCacheUtil.getResult(finderClassName,
548                     finderMethodName, finderParams, finderArgs, this);
549         }
550 
551         if (result == null) {
552             Session session = null;
553 
554             try {
555                 session = openSession();
556 
557                 StringBuilder query = new StringBuilder();
558 
559                 query.append(
560                     "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
561 
562                 query.append("groupId = ?");
563 
564                 query.append(" AND ");
565 
566                 if (articleId == null) {
567                     query.append("articleId IS NULL");
568                 }
569                 else {
570                     query.append("articleId = ?");
571                 }
572 
573                 query.append(" ");
574 
575                 Query q = session.createQuery(query.toString());
576 
577                 QueryPos qPos = QueryPos.getInstance(q);
578 
579                 qPos.add(groupId);
580 
581                 if (articleId != null) {
582                     qPos.add(articleId);
583                 }
584 
585                 List<JournalContentSearch> list = q.list();
586 
587                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
588                     finderClassName, finderMethodName, finderParams,
589                     finderArgs, list);
590 
591                 return list;
592             }
593             catch (Exception e) {
594                 throw processException(e);
595             }
596             finally {
597                 closeSession(session);
598             }
599         }
600         else {
601             return (List<JournalContentSearch>)result;
602         }
603     }
604 
605     public List<JournalContentSearch> findByG_A(long groupId, String articleId,
606         int start, int end) throws SystemException {
607         return findByG_A(groupId, articleId, start, end, null);
608     }
609 
610     public List<JournalContentSearch> findByG_A(long groupId, String articleId,
611         int start, int end, OrderByComparator obc) throws SystemException {
612         boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
613         String finderClassName = JournalContentSearch.class.getName();
614         String finderMethodName = "findByG_A";
615         String[] finderParams = new String[] {
616                 Long.class.getName(), String.class.getName(),
617                 
618                 "java.lang.Integer", "java.lang.Integer",
619                 "com.liferay.portal.kernel.util.OrderByComparator"
620             };
621         Object[] finderArgs = new Object[] {
622                 new Long(groupId),
623                 
624                 articleId,
625                 
626                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
627             };
628 
629         Object result = null;
630 
631         if (finderClassNameCacheEnabled) {
632             result = FinderCacheUtil.getResult(finderClassName,
633                     finderMethodName, finderParams, finderArgs, this);
634         }
635 
636         if (result == null) {
637             Session session = null;
638 
639             try {
640                 session = openSession();
641 
642                 StringBuilder query = new StringBuilder();
643 
644                 query.append(
645                     "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
646 
647                 query.append("groupId = ?");
648 
649                 query.append(" AND ");
650 
651                 if (articleId == null) {
652                     query.append("articleId IS NULL");
653                 }
654                 else {
655                     query.append("articleId = ?");
656                 }
657 
658                 query.append(" ");
659 
660                 if (obc != null) {
661                     query.append("ORDER BY ");
662                     query.append(obc.getOrderBy());
663                 }
664 
665                 Query q = session.createQuery(query.toString());
666 
667                 QueryPos qPos = QueryPos.getInstance(q);
668 
669                 qPos.add(groupId);
670 
671                 if (articleId != null) {
672                     qPos.add(articleId);
673                 }
674 
675                 List<JournalContentSearch> list = (List<JournalContentSearch>)QueryUtil.list(q,
676                         getDialect(), start, end);
677 
678                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
679                     finderClassName, finderMethodName, finderParams,
680                     finderArgs, list);
681 
682                 return list;
683             }
684             catch (Exception e) {
685                 throw processException(e);
686             }
687             finally {
688                 closeSession(session);
689             }
690         }
691         else {
692             return (List<JournalContentSearch>)result;
693         }
694     }
695 
696     public JournalContentSearch findByG_A_First(long groupId, String articleId,
697         OrderByComparator obc)
698         throws NoSuchContentSearchException, SystemException {
699         List<JournalContentSearch> list = findByG_A(groupId, articleId, 0, 1,
700                 obc);
701 
702         if (list.size() == 0) {
703             StringBuilder msg = new StringBuilder();
704 
705             msg.append("No JournalContentSearch exists with the key {");
706 
707             msg.append("groupId=" + groupId);
708 
709             msg.append(", ");
710             msg.append("articleId=" + articleId);
711 
712             msg.append(StringPool.CLOSE_CURLY_BRACE);
713 
714             throw new NoSuchContentSearchException(msg.toString());
715         }
716         else {
717             return list.get(0);
718         }
719     }
720 
721     public JournalContentSearch findByG_A_Last(long groupId, String articleId,
722         OrderByComparator obc)
723         throws NoSuchContentSearchException, SystemException {
724         int count = countByG_A(groupId, articleId);
725 
726         List<JournalContentSearch> list = findByG_A(groupId, articleId,
727                 count - 1, count, obc);
728 
729         if (list.size() == 0) {
730             StringBuilder msg = new StringBuilder();
731 
732             msg.append("No JournalContentSearch exists with the key {");
733 
734             msg.append("groupId=" + groupId);
735 
736             msg.append(", ");
737             msg.append("articleId=" + articleId);
738 
739             msg.append(StringPool.CLOSE_CURLY_BRACE);
740 
741             throw new NoSuchContentSearchException(msg.toString());
742         }
743         else {
744             return list.get(0);
745         }
746     }
747 
748     public JournalContentSearch[] findByG_A_PrevAndNext(long contentSearchId,
749         long groupId, String articleId, OrderByComparator obc)
750         throws NoSuchContentSearchException, SystemException {
751         JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
752 
753         int count = countByG_A(groupId, articleId);
754 
755         Session session = null;
756 
757         try {
758             session = openSession();
759 
760             StringBuilder query = new StringBuilder();
761 
762             query.append(
763                 "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
764 
765             query.append("groupId = ?");
766 
767             query.append(" AND ");
768 
769             if (articleId == null) {
770                 query.append("articleId IS NULL");
771             }
772             else {
773                 query.append("articleId = ?");
774             }
775 
776             query.append(" ");
777 
778             if (obc != null) {
779                 query.append("ORDER BY ");
780                 query.append(obc.getOrderBy());
781             }
782 
783             Query q = session.createQuery(query.toString());
784 
785             QueryPos qPos = QueryPos.getInstance(q);
786 
787             qPos.add(groupId);
788 
789             if (articleId != null) {
790                 qPos.add(articleId);
791             }
792 
793             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
794                     journalContentSearch);
795 
796             JournalContentSearch[] array = new JournalContentSearchImpl[3];
797 
798             array[0] = (JournalContentSearch)objArray[0];
799             array[1] = (JournalContentSearch)objArray[1];
800             array[2] = (JournalContentSearch)objArray[2];
801 
802             return array;
803         }
804         catch (Exception e) {
805             throw processException(e);
806         }
807         finally {
808             closeSession(session);
809         }
810     }
811 
812     public List<JournalContentSearch> findByG_P_L(long groupId,
813         boolean privateLayout, long layoutId) throws SystemException {
814         boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
815         String finderClassName = JournalContentSearch.class.getName();
816         String finderMethodName = "findByG_P_L";
817         String[] finderParams = new String[] {
818                 Long.class.getName(), Boolean.class.getName(),
819                 Long.class.getName()
820             };
821         Object[] finderArgs = new Object[] {
822                 new Long(groupId), Boolean.valueOf(privateLayout),
823                 new Long(layoutId)
824             };
825 
826         Object result = null;
827 
828         if (finderClassNameCacheEnabled) {
829             result = FinderCacheUtil.getResult(finderClassName,
830                     finderMethodName, finderParams, finderArgs, this);
831         }
832 
833         if (result == null) {
834             Session session = null;
835 
836             try {
837                 session = openSession();
838 
839                 StringBuilder query = new StringBuilder();
840 
841                 query.append(
842                     "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
843 
844                 query.append("groupId = ?");
845 
846                 query.append(" AND ");
847 
848                 query.append("privateLayout = ?");
849 
850                 query.append(" AND ");
851 
852                 query.append("layoutId = ?");
853 
854                 query.append(" ");
855 
856                 Query q = session.createQuery(query.toString());
857 
858                 QueryPos qPos = QueryPos.getInstance(q);
859 
860                 qPos.add(groupId);
861 
862                 qPos.add(privateLayout);
863 
864                 qPos.add(layoutId);
865 
866                 List<JournalContentSearch> list = q.list();
867 
868                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
869                     finderClassName, finderMethodName, finderParams,
870                     finderArgs, list);
871 
872                 return list;
873             }
874             catch (Exception e) {
875                 throw processException(e);
876             }
877             finally {
878                 closeSession(session);
879             }
880         }
881         else {
882             return (List<JournalContentSearch>)result;
883         }
884     }
885 
886     public List<JournalContentSearch> findByG_P_L(long groupId,
887         boolean privateLayout, long layoutId, int start, int end)
888         throws SystemException {
889         return findByG_P_L(groupId, privateLayout, layoutId, start, end, null);
890     }
891 
892     public List<JournalContentSearch> findByG_P_L(long groupId,
893         boolean privateLayout, long layoutId, int start, int end,
894         OrderByComparator obc) throws SystemException {
895         boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
896         String finderClassName = JournalContentSearch.class.getName();
897         String finderMethodName = "findByG_P_L";
898         String[] finderParams = new String[] {
899                 Long.class.getName(), Boolean.class.getName(),
900                 Long.class.getName(),
901                 
902                 "java.lang.Integer", "java.lang.Integer",
903                 "com.liferay.portal.kernel.util.OrderByComparator"
904             };
905         Object[] finderArgs = new Object[] {
906                 new Long(groupId), Boolean.valueOf(privateLayout),
907                 new Long(layoutId),
908                 
909                 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
910             };
911 
912         Object result = null;
913 
914         if (finderClassNameCacheEnabled) {
915             result = FinderCacheUtil.getResult(finderClassName,
916                     finderMethodName, finderParams, finderArgs, this);
917         }
918 
919         if (result == null) {
920             Session session = null;
921 
922             try {
923                 session = openSession();
924 
925                 StringBuilder query = new StringBuilder();
926 
927                 query.append(
928                     "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
929 
930                 query.append("groupId = ?");
931 
932                 query.append(" AND ");
933 
934                 query.append("privateLayout = ?");
935 
936                 query.append(" AND ");
937 
938                 query.append("layoutId = ?");
939 
940                 query.append(" ");
941 
942                 if (obc != null) {
943                     query.append("ORDER BY ");
944                     query.append(obc.getOrderBy());
945                 }
946 
947                 Query q = session.createQuery(query.toString());
948 
949                 QueryPos qPos = QueryPos.getInstance(q);
950 
951                 qPos.add(groupId);
952 
953                 qPos.add(privateLayout);
954 
955                 qPos.add(layoutId);
956 
957                 List<JournalContentSearch> list = (List<JournalContentSearch>)QueryUtil.list(q,
958                         getDialect(), start, end);
959 
960                 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
961                     finderClassName, finderMethodName, finderParams,
962                     finderArgs, list);
963 
964                 return list;
965             }
966             catch (Exception e) {
967                 throw processException(e);
968             }
969             finally {
970                 closeSession(session);
971             }
972         }
973         else {
974             return (List<JournalContentSearch>)result;
975         }
976     }
977 
978     public JournalContentSearch findByG_P_L_First(long groupId,
979         boolean privateLayout, long layoutId, OrderByComparator obc)
980         throws NoSuchContentSearchException, SystemException {
981         List<JournalContentSearch> list = findByG_P_L(groupId, privateLayout,
982                 layoutId, 0, 1, obc);
983 
984         if (list.size() == 0) {
985             StringBuilder msg = new StringBuilder();
986 
987             msg.append("No JournalContentSearch exists with the key {");
988 
989             msg.append("groupId=" + groupId);
990 
991             msg.append(", ");
992             msg.append("privateLayout=" + privateLayout);
993 
994             msg.append(", ");
995             msg.append("layoutId=" + layoutId);
996 
997             msg.append(StringPool.CLOSE_CURLY_BRACE);
998 
999             throw new NoSuchContentSearchException(msg.toString());
1000        }
1001        else {
1002            return list.get(0);
1003        }
1004    }
1005
1006    public JournalContentSearch findByG_P_L_Last(long groupId,
1007        boolean privateLayout, long layoutId, OrderByComparator obc)
1008        throws NoSuchContentSearchException, SystemException {
1009        int count = countByG_P_L(groupId, privateLayout, layoutId);
1010
1011        List<JournalContentSearch> list = findByG_P_L(groupId, privateLayout,
1012                layoutId, count - 1, count, obc);
1013
1014        if (list.size() == 0) {
1015            StringBuilder msg = new StringBuilder();
1016
1017            msg.append("No JournalContentSearch exists with the key {");
1018
1019            msg.append("groupId=" + groupId);
1020
1021            msg.append(", ");
1022            msg.append("privateLayout=" + privateLayout);
1023
1024            msg.append(", ");
1025            msg.append("layoutId=" + layoutId);
1026
1027            msg.append(StringPool.CLOSE_CURLY_BRACE);
1028
1029            throw new NoSuchContentSearchException(msg.toString());
1030        }
1031        else {
1032            return list.get(0);
1033        }
1034    }
1035
1036    public JournalContentSearch[] findByG_P_L_PrevAndNext(
1037        long contentSearchId, long groupId, boolean privateLayout,
1038        long layoutId, OrderByComparator obc)
1039        throws NoSuchContentSearchException, SystemException {
1040        JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
1041
1042        int count = countByG_P_L(groupId, privateLayout, layoutId);
1043
1044        Session session = null;
1045
1046        try {
1047            session = openSession();
1048
1049            StringBuilder query = new StringBuilder();
1050
1051            query.append(
1052                "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1053
1054            query.append("groupId = ?");
1055
1056            query.append(" AND ");
1057
1058            query.append("privateLayout = ?");
1059
1060            query.append(" AND ");
1061
1062            query.append("layoutId = ?");
1063
1064            query.append(" ");
1065
1066            if (obc != null) {
1067                query.append("ORDER BY ");
1068                query.append(obc.getOrderBy());
1069            }
1070
1071            Query q = session.createQuery(query.toString());
1072
1073            QueryPos qPos = QueryPos.getInstance(q);
1074
1075            qPos.add(groupId);
1076
1077            qPos.add(privateLayout);
1078
1079            qPos.add(layoutId);
1080
1081            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1082                    journalContentSearch);
1083
1084            JournalContentSearch[] array = new JournalContentSearchImpl[3];
1085
1086            array[0] = (JournalContentSearch)objArray[0];
1087            array[1] = (JournalContentSearch)objArray[1];
1088            array[2] = (JournalContentSearch)objArray[2];
1089
1090            return array;
1091        }
1092        catch (Exception e) {
1093            throw processException(e);
1094        }
1095        finally {
1096            closeSession(session);
1097        }
1098    }
1099
1100    public List<JournalContentSearch> findByG_P_A(long groupId,
1101        boolean privateLayout, String articleId) throws SystemException {
1102        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
1103        String finderClassName = JournalContentSearch.class.getName();
1104        String finderMethodName = "findByG_P_A";
1105        String[] finderParams = new String[] {
1106                Long.class.getName(), Boolean.class.getName(),
1107                String.class.getName()
1108            };
1109        Object[] finderArgs = new Object[] {
1110                new Long(groupId), Boolean.valueOf(privateLayout),
1111                
1112                articleId
1113            };
1114
1115        Object result = null;
1116
1117        if (finderClassNameCacheEnabled) {
1118            result = FinderCacheUtil.getResult(finderClassName,
1119                    finderMethodName, finderParams, finderArgs, this);
1120        }
1121
1122        if (result == null) {
1123            Session session = null;
1124
1125            try {
1126                session = openSession();
1127
1128                StringBuilder query = new StringBuilder();
1129
1130                query.append(
1131                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1132
1133                query.append("groupId = ?");
1134
1135                query.append(" AND ");
1136
1137                query.append("privateLayout = ?");
1138
1139                query.append(" AND ");
1140
1141                if (articleId == null) {
1142                    query.append("articleId IS NULL");
1143                }
1144                else {
1145                    query.append("articleId = ?");
1146                }
1147
1148                query.append(" ");
1149
1150                Query q = session.createQuery(query.toString());
1151
1152                QueryPos qPos = QueryPos.getInstance(q);
1153
1154                qPos.add(groupId);
1155
1156                qPos.add(privateLayout);
1157
1158                if (articleId != null) {
1159                    qPos.add(articleId);
1160                }
1161
1162                List<JournalContentSearch> list = q.list();
1163
1164                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1165                    finderClassName, finderMethodName, finderParams,
1166                    finderArgs, list);
1167
1168                return list;
1169            }
1170            catch (Exception e) {
1171                throw processException(e);
1172            }
1173            finally {
1174                closeSession(session);
1175            }
1176        }
1177        else {
1178            return (List<JournalContentSearch>)result;
1179        }
1180    }
1181
1182    public List<JournalContentSearch> findByG_P_A(long groupId,
1183        boolean privateLayout, String articleId, int start, int end)
1184        throws SystemException {
1185        return findByG_P_A(groupId, privateLayout, articleId, start, end, null);
1186    }
1187
1188    public List<JournalContentSearch> findByG_P_A(long groupId,
1189        boolean privateLayout, String articleId, int start, int end,
1190        OrderByComparator obc) throws SystemException {
1191        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
1192        String finderClassName = JournalContentSearch.class.getName();
1193        String finderMethodName = "findByG_P_A";
1194        String[] finderParams = new String[] {
1195                Long.class.getName(), Boolean.class.getName(),
1196                String.class.getName(),
1197                
1198                "java.lang.Integer", "java.lang.Integer",
1199                "com.liferay.portal.kernel.util.OrderByComparator"
1200            };
1201        Object[] finderArgs = new Object[] {
1202                new Long(groupId), Boolean.valueOf(privateLayout),
1203                
1204                articleId,
1205                
1206                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1207            };
1208
1209        Object result = null;
1210
1211        if (finderClassNameCacheEnabled) {
1212            result = FinderCacheUtil.getResult(finderClassName,
1213                    finderMethodName, finderParams, finderArgs, this);
1214        }
1215
1216        if (result == null) {
1217            Session session = null;
1218
1219            try {
1220                session = openSession();
1221
1222                StringBuilder query = new StringBuilder();
1223
1224                query.append(
1225                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1226
1227                query.append("groupId = ?");
1228
1229                query.append(" AND ");
1230
1231                query.append("privateLayout = ?");
1232
1233                query.append(" AND ");
1234
1235                if (articleId == null) {
1236                    query.append("articleId IS NULL");
1237                }
1238                else {
1239                    query.append("articleId = ?");
1240                }
1241
1242                query.append(" ");
1243
1244                if (obc != null) {
1245                    query.append("ORDER BY ");
1246                    query.append(obc.getOrderBy());
1247                }
1248
1249                Query q = session.createQuery(query.toString());
1250
1251                QueryPos qPos = QueryPos.getInstance(q);
1252
1253                qPos.add(groupId);
1254
1255                qPos.add(privateLayout);
1256
1257                if (articleId != null) {
1258                    qPos.add(articleId);
1259                }
1260
1261                List<JournalContentSearch> list = (List<JournalContentSearch>)QueryUtil.list(q,
1262                        getDialect(), start, end);
1263
1264                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1265                    finderClassName, finderMethodName, finderParams,
1266                    finderArgs, list);
1267
1268                return list;
1269            }
1270            catch (Exception e) {
1271                throw processException(e);
1272            }
1273            finally {
1274                closeSession(session);
1275            }
1276        }
1277        else {
1278            return (List<JournalContentSearch>)result;
1279        }
1280    }
1281
1282    public JournalContentSearch findByG_P_A_First(long groupId,
1283        boolean privateLayout, String articleId, OrderByComparator obc)
1284        throws NoSuchContentSearchException, SystemException {
1285        List<JournalContentSearch> list = findByG_P_A(groupId, privateLayout,
1286                articleId, 0, 1, obc);
1287
1288        if (list.size() == 0) {
1289            StringBuilder msg = new StringBuilder();
1290
1291            msg.append("No JournalContentSearch exists with the key {");
1292
1293            msg.append("groupId=" + groupId);
1294
1295            msg.append(", ");
1296            msg.append("privateLayout=" + privateLayout);
1297
1298            msg.append(", ");
1299            msg.append("articleId=" + articleId);
1300
1301            msg.append(StringPool.CLOSE_CURLY_BRACE);
1302
1303            throw new NoSuchContentSearchException(msg.toString());
1304        }
1305        else {
1306            return list.get(0);
1307        }
1308    }
1309
1310    public JournalContentSearch findByG_P_A_Last(long groupId,
1311        boolean privateLayout, String articleId, OrderByComparator obc)
1312        throws NoSuchContentSearchException, SystemException {
1313        int count = countByG_P_A(groupId, privateLayout, articleId);
1314
1315        List<JournalContentSearch> list = findByG_P_A(groupId, privateLayout,
1316                articleId, count - 1, count, obc);
1317
1318        if (list.size() == 0) {
1319            StringBuilder msg = new StringBuilder();
1320
1321            msg.append("No JournalContentSearch exists with the key {");
1322
1323            msg.append("groupId=" + groupId);
1324
1325            msg.append(", ");
1326            msg.append("privateLayout=" + privateLayout);
1327
1328            msg.append(", ");
1329            msg.append("articleId=" + articleId);
1330
1331            msg.append(StringPool.CLOSE_CURLY_BRACE);
1332
1333            throw new NoSuchContentSearchException(msg.toString());
1334        }
1335        else {
1336            return list.get(0);
1337        }
1338    }
1339
1340    public JournalContentSearch[] findByG_P_A_PrevAndNext(
1341        long contentSearchId, long groupId, boolean privateLayout,
1342        String articleId, OrderByComparator obc)
1343        throws NoSuchContentSearchException, SystemException {
1344        JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
1345
1346        int count = countByG_P_A(groupId, privateLayout, articleId);
1347
1348        Session session = null;
1349
1350        try {
1351            session = openSession();
1352
1353            StringBuilder query = new StringBuilder();
1354
1355            query.append(
1356                "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1357
1358            query.append("groupId = ?");
1359
1360            query.append(" AND ");
1361
1362            query.append("privateLayout = ?");
1363
1364            query.append(" AND ");
1365
1366            if (articleId == null) {
1367                query.append("articleId IS NULL");
1368            }
1369            else {
1370                query.append("articleId = ?");
1371            }
1372
1373            query.append(" ");
1374
1375            if (obc != null) {
1376                query.append("ORDER BY ");
1377                query.append(obc.getOrderBy());
1378            }
1379
1380            Query q = session.createQuery(query.toString());
1381
1382            QueryPos qPos = QueryPos.getInstance(q);
1383
1384            qPos.add(groupId);
1385
1386            qPos.add(privateLayout);
1387
1388            if (articleId != null) {
1389                qPos.add(articleId);
1390            }
1391
1392            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1393                    journalContentSearch);
1394
1395            JournalContentSearch[] array = new JournalContentSearchImpl[3];
1396
1397            array[0] = (JournalContentSearch)objArray[0];
1398            array[1] = (JournalContentSearch)objArray[1];
1399            array[2] = (JournalContentSearch)objArray[2];
1400
1401            return array;
1402        }
1403        catch (Exception e) {
1404            throw processException(e);
1405        }
1406        finally {
1407            closeSession(session);
1408        }
1409    }
1410
1411    public List<JournalContentSearch> findByG_P_L_P(long groupId,
1412        boolean privateLayout, long layoutId, String portletId)
1413        throws SystemException {
1414        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
1415        String finderClassName = JournalContentSearch.class.getName();
1416        String finderMethodName = "findByG_P_L_P";
1417        String[] finderParams = new String[] {
1418                Long.class.getName(), Boolean.class.getName(),
1419                Long.class.getName(), String.class.getName()
1420            };
1421        Object[] finderArgs = new Object[] {
1422                new Long(groupId), Boolean.valueOf(privateLayout),
1423                new Long(layoutId),
1424                
1425                portletId
1426            };
1427
1428        Object result = null;
1429
1430        if (finderClassNameCacheEnabled) {
1431            result = FinderCacheUtil.getResult(finderClassName,
1432                    finderMethodName, finderParams, finderArgs, this);
1433        }
1434
1435        if (result == null) {
1436            Session session = null;
1437
1438            try {
1439                session = openSession();
1440
1441                StringBuilder query = new StringBuilder();
1442
1443                query.append(
1444                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1445
1446                query.append("groupId = ?");
1447
1448                query.append(" AND ");
1449
1450                query.append("privateLayout = ?");
1451
1452                query.append(" AND ");
1453
1454                query.append("layoutId = ?");
1455
1456                query.append(" AND ");
1457
1458                if (portletId == null) {
1459                    query.append("portletId IS NULL");
1460                }
1461                else {
1462                    query.append("portletId = ?");
1463                }
1464
1465                query.append(" ");
1466
1467                Query q = session.createQuery(query.toString());
1468
1469                QueryPos qPos = QueryPos.getInstance(q);
1470
1471                qPos.add(groupId);
1472
1473                qPos.add(privateLayout);
1474
1475                qPos.add(layoutId);
1476
1477                if (portletId != null) {
1478                    qPos.add(portletId);
1479                }
1480
1481                List<JournalContentSearch> list = q.list();
1482
1483                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1484                    finderClassName, finderMethodName, finderParams,
1485                    finderArgs, list);
1486
1487                return list;
1488            }
1489            catch (Exception e) {
1490                throw processException(e);
1491            }
1492            finally {
1493                closeSession(session);
1494            }
1495        }
1496        else {
1497            return (List<JournalContentSearch>)result;
1498        }
1499    }
1500
1501    public List<JournalContentSearch> findByG_P_L_P(long groupId,
1502        boolean privateLayout, long layoutId, String portletId, int start,
1503        int end) throws SystemException {
1504        return findByG_P_L_P(groupId, privateLayout, layoutId, portletId,
1505            start, end, null);
1506    }
1507
1508    public List<JournalContentSearch> findByG_P_L_P(long groupId,
1509        boolean privateLayout, long layoutId, String portletId, int start,
1510        int end, OrderByComparator obc) throws SystemException {
1511        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
1512        String finderClassName = JournalContentSearch.class.getName();
1513        String finderMethodName = "findByG_P_L_P";
1514        String[] finderParams = new String[] {
1515                Long.class.getName(), Boolean.class.getName(),
1516                Long.class.getName(), String.class.getName(),
1517                
1518                "java.lang.Integer", "java.lang.Integer",
1519                "com.liferay.portal.kernel.util.OrderByComparator"
1520            };
1521        Object[] finderArgs = new Object[] {
1522                new Long(groupId), Boolean.valueOf(privateLayout),
1523                new Long(layoutId),
1524                
1525                portletId,
1526                
1527                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1528            };
1529
1530        Object result = null;
1531
1532        if (finderClassNameCacheEnabled) {
1533            result = FinderCacheUtil.getResult(finderClassName,
1534                    finderMethodName, finderParams, finderArgs, this);
1535        }
1536
1537        if (result == null) {
1538            Session session = null;
1539
1540            try {
1541                session = openSession();
1542
1543                StringBuilder query = new StringBuilder();
1544
1545                query.append(
1546                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1547
1548                query.append("groupId = ?");
1549
1550                query.append(" AND ");
1551
1552                query.append("privateLayout = ?");
1553
1554                query.append(" AND ");
1555
1556                query.append("layoutId = ?");
1557
1558                query.append(" AND ");
1559
1560                if (portletId == null) {
1561                    query.append("portletId IS NULL");
1562                }
1563                else {
1564                    query.append("portletId = ?");
1565                }
1566
1567                query.append(" ");
1568
1569                if (obc != null) {
1570                    query.append("ORDER BY ");
1571                    query.append(obc.getOrderBy());
1572                }
1573
1574                Query q = session.createQuery(query.toString());
1575
1576                QueryPos qPos = QueryPos.getInstance(q);
1577
1578                qPos.add(groupId);
1579
1580                qPos.add(privateLayout);
1581
1582                qPos.add(layoutId);
1583
1584                if (portletId != null) {
1585                    qPos.add(portletId);
1586                }
1587
1588                List<JournalContentSearch> list = (List<JournalContentSearch>)QueryUtil.list(q,
1589                        getDialect(), start, end);
1590
1591                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1592                    finderClassName, finderMethodName, finderParams,
1593                    finderArgs, list);
1594
1595                return list;
1596            }
1597            catch (Exception e) {
1598                throw processException(e);
1599            }
1600            finally {
1601                closeSession(session);
1602            }
1603        }
1604        else {
1605            return (List<JournalContentSearch>)result;
1606        }
1607    }
1608
1609    public JournalContentSearch findByG_P_L_P_First(long groupId,
1610        boolean privateLayout, long layoutId, String portletId,
1611        OrderByComparator obc)
1612        throws NoSuchContentSearchException, SystemException {
1613        List<JournalContentSearch> list = findByG_P_L_P(groupId, privateLayout,
1614                layoutId, portletId, 0, 1, obc);
1615
1616        if (list.size() == 0) {
1617            StringBuilder msg = new StringBuilder();
1618
1619            msg.append("No JournalContentSearch exists with the key {");
1620
1621            msg.append("groupId=" + groupId);
1622
1623            msg.append(", ");
1624            msg.append("privateLayout=" + privateLayout);
1625
1626            msg.append(", ");
1627            msg.append("layoutId=" + layoutId);
1628
1629            msg.append(", ");
1630            msg.append("portletId=" + portletId);
1631
1632            msg.append(StringPool.CLOSE_CURLY_BRACE);
1633
1634            throw new NoSuchContentSearchException(msg.toString());
1635        }
1636        else {
1637            return list.get(0);
1638        }
1639    }
1640
1641    public JournalContentSearch findByG_P_L_P_Last(long groupId,
1642        boolean privateLayout, long layoutId, String portletId,
1643        OrderByComparator obc)
1644        throws NoSuchContentSearchException, SystemException {
1645        int count = countByG_P_L_P(groupId, privateLayout, layoutId, portletId);
1646
1647        List<JournalContentSearch> list = findByG_P_L_P(groupId, privateLayout,
1648                layoutId, portletId, count - 1, count, obc);
1649
1650        if (list.size() == 0) {
1651            StringBuilder msg = new StringBuilder();
1652
1653            msg.append("No JournalContentSearch exists with the key {");
1654
1655            msg.append("groupId=" + groupId);
1656
1657            msg.append(", ");
1658            msg.append("privateLayout=" + privateLayout);
1659
1660            msg.append(", ");
1661            msg.append("layoutId=" + layoutId);
1662
1663            msg.append(", ");
1664            msg.append("portletId=" + portletId);
1665
1666            msg.append(StringPool.CLOSE_CURLY_BRACE);
1667
1668            throw new NoSuchContentSearchException(msg.toString());
1669        }
1670        else {
1671            return list.get(0);
1672        }
1673    }
1674
1675    public JournalContentSearch[] findByG_P_L_P_PrevAndNext(
1676        long contentSearchId, long groupId, boolean privateLayout,
1677        long layoutId, String portletId, OrderByComparator obc)
1678        throws NoSuchContentSearchException, SystemException {
1679        JournalContentSearch journalContentSearch = findByPrimaryKey(contentSearchId);
1680
1681        int count = countByG_P_L_P(groupId, privateLayout, layoutId, portletId);
1682
1683        Session session = null;
1684
1685        try {
1686            session = openSession();
1687
1688            StringBuilder query = new StringBuilder();
1689
1690            query.append(
1691                "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1692
1693            query.append("groupId = ?");
1694
1695            query.append(" AND ");
1696
1697            query.append("privateLayout = ?");
1698
1699            query.append(" AND ");
1700
1701            query.append("layoutId = ?");
1702
1703            query.append(" AND ");
1704
1705            if (portletId == null) {
1706                query.append("portletId IS NULL");
1707            }
1708            else {
1709                query.append("portletId = ?");
1710            }
1711
1712            query.append(" ");
1713
1714            if (obc != null) {
1715                query.append("ORDER BY ");
1716                query.append(obc.getOrderBy());
1717            }
1718
1719            Query q = session.createQuery(query.toString());
1720
1721            QueryPos qPos = QueryPos.getInstance(q);
1722
1723            qPos.add(groupId);
1724
1725            qPos.add(privateLayout);
1726
1727            qPos.add(layoutId);
1728
1729            if (portletId != null) {
1730                qPos.add(portletId);
1731            }
1732
1733            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1734                    journalContentSearch);
1735
1736            JournalContentSearch[] array = new JournalContentSearchImpl[3];
1737
1738            array[0] = (JournalContentSearch)objArray[0];
1739            array[1] = (JournalContentSearch)objArray[1];
1740            array[2] = (JournalContentSearch)objArray[2];
1741
1742            return array;
1743        }
1744        catch (Exception e) {
1745            throw processException(e);
1746        }
1747        finally {
1748            closeSession(session);
1749        }
1750    }
1751
1752    public JournalContentSearch findByG_P_L_P_A(long groupId,
1753        boolean privateLayout, long layoutId, String portletId, String articleId)
1754        throws NoSuchContentSearchException, SystemException {
1755        JournalContentSearch journalContentSearch = fetchByG_P_L_P_A(groupId,
1756                privateLayout, layoutId, portletId, articleId);
1757
1758        if (journalContentSearch == null) {
1759            StringBuilder msg = new StringBuilder();
1760
1761            msg.append("No JournalContentSearch exists with the key {");
1762
1763            msg.append("groupId=" + groupId);
1764
1765            msg.append(", ");
1766            msg.append("privateLayout=" + privateLayout);
1767
1768            msg.append(", ");
1769            msg.append("layoutId=" + layoutId);
1770
1771            msg.append(", ");
1772            msg.append("portletId=" + portletId);
1773
1774            msg.append(", ");
1775            msg.append("articleId=" + articleId);
1776
1777            msg.append(StringPool.CLOSE_CURLY_BRACE);
1778
1779            if (_log.isWarnEnabled()) {
1780                _log.warn(msg.toString());
1781            }
1782
1783            throw new NoSuchContentSearchException(msg.toString());
1784        }
1785
1786        return journalContentSearch;
1787    }
1788
1789    public JournalContentSearch fetchByG_P_L_P_A(long groupId,
1790        boolean privateLayout, long layoutId, String portletId, String articleId)
1791        throws SystemException {
1792        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
1793        String finderClassName = JournalContentSearch.class.getName();
1794        String finderMethodName = "fetchByG_P_L_P_A";
1795        String[] finderParams = new String[] {
1796                Long.class.getName(), Boolean.class.getName(),
1797                Long.class.getName(), String.class.getName(),
1798                String.class.getName()
1799            };
1800        Object[] finderArgs = new Object[] {
1801                new Long(groupId), Boolean.valueOf(privateLayout),
1802                new Long(layoutId),
1803                
1804                portletId,
1805                
1806                articleId
1807            };
1808
1809        Object result = null;
1810
1811        if (finderClassNameCacheEnabled) {
1812            result = FinderCacheUtil.getResult(finderClassName,
1813                    finderMethodName, finderParams, finderArgs, this);
1814        }
1815
1816        if (result == null) {
1817            Session session = null;
1818
1819            try {
1820                session = openSession();
1821
1822                StringBuilder query = new StringBuilder();
1823
1824                query.append(
1825                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
1826
1827                query.append("groupId = ?");
1828
1829                query.append(" AND ");
1830
1831                query.append("privateLayout = ?");
1832
1833                query.append(" AND ");
1834
1835                query.append("layoutId = ?");
1836
1837                query.append(" AND ");
1838
1839                if (portletId == null) {
1840                    query.append("portletId IS NULL");
1841                }
1842                else {
1843                    query.append("portletId = ?");
1844                }
1845
1846                query.append(" AND ");
1847
1848                if (articleId == null) {
1849                    query.append("articleId IS NULL");
1850                }
1851                else {
1852                    query.append("articleId = ?");
1853                }
1854
1855                query.append(" ");
1856
1857                Query q = session.createQuery(query.toString());
1858
1859                QueryPos qPos = QueryPos.getInstance(q);
1860
1861                qPos.add(groupId);
1862
1863                qPos.add(privateLayout);
1864
1865                qPos.add(layoutId);
1866
1867                if (portletId != null) {
1868                    qPos.add(portletId);
1869                }
1870
1871                if (articleId != null) {
1872                    qPos.add(articleId);
1873                }
1874
1875                List<JournalContentSearch> list = q.list();
1876
1877                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1878                    finderClassName, finderMethodName, finderParams,
1879                    finderArgs, list);
1880
1881                if (list.size() == 0) {
1882                    return null;
1883                }
1884                else {
1885                    return list.get(0);
1886                }
1887            }
1888            catch (Exception e) {
1889                throw processException(e);
1890            }
1891            finally {
1892                closeSession(session);
1893            }
1894        }
1895        else {
1896            List<JournalContentSearch> list = (List<JournalContentSearch>)result;
1897
1898            if (list.size() == 0) {
1899                return null;
1900            }
1901            else {
1902                return list.get(0);
1903            }
1904        }
1905    }
1906
1907    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1908        throws SystemException {
1909        Session session = null;
1910
1911        try {
1912            session = openSession();
1913
1914            dynamicQuery.compile(session);
1915
1916            return dynamicQuery.list();
1917        }
1918        catch (Exception e) {
1919            throw processException(e);
1920        }
1921        finally {
1922            closeSession(session);
1923        }
1924    }
1925
1926    public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1927        int start, int end) throws SystemException {
1928        Session session = null;
1929
1930        try {
1931            session = openSession();
1932
1933            dynamicQuery.setLimit(start, end);
1934
1935            dynamicQuery.compile(session);
1936
1937            return dynamicQuery.list();
1938        }
1939        catch (Exception e) {
1940            throw processException(e);
1941        }
1942        finally {
1943            closeSession(session);
1944        }
1945    }
1946
1947    public List<JournalContentSearch> findAll() throws SystemException {
1948        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1949    }
1950
1951    public List<JournalContentSearch> findAll(int start, int end)
1952        throws SystemException {
1953        return findAll(start, end, null);
1954    }
1955
1956    public List<JournalContentSearch> findAll(int start, int end,
1957        OrderByComparator obc) throws SystemException {
1958        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
1959        String finderClassName = JournalContentSearch.class.getName();
1960        String finderMethodName = "findAll";
1961        String[] finderParams = new String[] {
1962                "java.lang.Integer", "java.lang.Integer",
1963                "com.liferay.portal.kernel.util.OrderByComparator"
1964            };
1965        Object[] finderArgs = new Object[] {
1966                String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1967            };
1968
1969        Object result = null;
1970
1971        if (finderClassNameCacheEnabled) {
1972            result = FinderCacheUtil.getResult(finderClassName,
1973                    finderMethodName, finderParams, finderArgs, this);
1974        }
1975
1976        if (result == null) {
1977            Session session = null;
1978
1979            try {
1980                session = openSession();
1981
1982                StringBuilder query = new StringBuilder();
1983
1984                query.append(
1985                    "FROM com.liferay.portlet.journal.model.JournalContentSearch ");
1986
1987                if (obc != null) {
1988                    query.append("ORDER BY ");
1989                    query.append(obc.getOrderBy());
1990                }
1991
1992                Query q = session.createQuery(query.toString());
1993
1994                List<JournalContentSearch> list = (List<JournalContentSearch>)QueryUtil.list(q,
1995                        getDialect(), start, end);
1996
1997                if (obc == null) {
1998                    Collections.sort(list);
1999                }
2000
2001                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2002                    finderClassName, finderMethodName, finderParams,
2003                    finderArgs, list);
2004
2005                return list;
2006            }
2007            catch (Exception e) {
2008                throw processException(e);
2009            }
2010            finally {
2011                closeSession(session);
2012            }
2013        }
2014        else {
2015            return (List<JournalContentSearch>)result;
2016        }
2017    }
2018
2019    public void removeByG_P(long groupId, boolean privateLayout)
2020        throws SystemException {
2021        for (JournalContentSearch journalContentSearch : findByG_P(groupId,
2022                privateLayout)) {
2023            remove(journalContentSearch);
2024        }
2025    }
2026
2027    public void removeByG_A(long groupId, String articleId)
2028        throws SystemException {
2029        for (JournalContentSearch journalContentSearch : findByG_A(groupId,
2030                articleId)) {
2031            remove(journalContentSearch);
2032        }
2033    }
2034
2035    public void removeByG_P_L(long groupId, boolean privateLayout, long layoutId)
2036        throws SystemException {
2037        for (JournalContentSearch journalContentSearch : findByG_P_L(groupId,
2038                privateLayout, layoutId)) {
2039            remove(journalContentSearch);
2040        }
2041    }
2042
2043    public void removeByG_P_A(long groupId, boolean privateLayout,
2044        String articleId) throws SystemException {
2045        for (JournalContentSearch journalContentSearch : findByG_P_A(groupId,
2046                privateLayout, articleId)) {
2047            remove(journalContentSearch);
2048        }
2049    }
2050
2051    public void removeByG_P_L_P(long groupId, boolean privateLayout,
2052        long layoutId, String portletId) throws SystemException {
2053        for (JournalContentSearch journalContentSearch : findByG_P_L_P(
2054                groupId, privateLayout, layoutId, portletId)) {
2055            remove(journalContentSearch);
2056        }
2057    }
2058
2059    public void removeByG_P_L_P_A(long groupId, boolean privateLayout,
2060        long layoutId, String portletId, String articleId)
2061        throws NoSuchContentSearchException, SystemException {
2062        JournalContentSearch journalContentSearch = findByG_P_L_P_A(groupId,
2063                privateLayout, layoutId, portletId, articleId);
2064
2065        remove(journalContentSearch);
2066    }
2067
2068    public void removeAll() throws SystemException {
2069        for (JournalContentSearch journalContentSearch : findAll()) {
2070            remove(journalContentSearch);
2071        }
2072    }
2073
2074    public int countByG_P(long groupId, boolean privateLayout)
2075        throws SystemException {
2076        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2077        String finderClassName = JournalContentSearch.class.getName();
2078        String finderMethodName = "countByG_P";
2079        String[] finderParams = new String[] {
2080                Long.class.getName(), Boolean.class.getName()
2081            };
2082        Object[] finderArgs = new Object[] {
2083                new Long(groupId), Boolean.valueOf(privateLayout)
2084            };
2085
2086        Object result = null;
2087
2088        if (finderClassNameCacheEnabled) {
2089            result = FinderCacheUtil.getResult(finderClassName,
2090                    finderMethodName, finderParams, finderArgs, this);
2091        }
2092
2093        if (result == null) {
2094            Session session = null;
2095
2096            try {
2097                session = openSession();
2098
2099                StringBuilder query = new StringBuilder();
2100
2101                query.append("SELECT COUNT(*) ");
2102                query.append(
2103                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
2104
2105                query.append("groupId = ?");
2106
2107                query.append(" AND ");
2108
2109                query.append("privateLayout = ?");
2110
2111                query.append(" ");
2112
2113                Query q = session.createQuery(query.toString());
2114
2115                QueryPos qPos = QueryPos.getInstance(q);
2116
2117                qPos.add(groupId);
2118
2119                qPos.add(privateLayout);
2120
2121                Long count = null;
2122
2123                Iterator<Long> itr = q.list().iterator();
2124
2125                if (itr.hasNext()) {
2126                    count = itr.next();
2127                }
2128
2129                if (count == null) {
2130                    count = new Long(0);
2131                }
2132
2133                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2134                    finderClassName, finderMethodName, finderParams,
2135                    finderArgs, count);
2136
2137                return count.intValue();
2138            }
2139            catch (Exception e) {
2140                throw processException(e);
2141            }
2142            finally {
2143                closeSession(session);
2144            }
2145        }
2146        else {
2147            return ((Long)result).intValue();
2148        }
2149    }
2150
2151    public int countByG_A(long groupId, String articleId)
2152        throws SystemException {
2153        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2154        String finderClassName = JournalContentSearch.class.getName();
2155        String finderMethodName = "countByG_A";
2156        String[] finderParams = new String[] {
2157                Long.class.getName(), String.class.getName()
2158            };
2159        Object[] finderArgs = new Object[] { new Long(groupId), articleId };
2160
2161        Object result = null;
2162
2163        if (finderClassNameCacheEnabled) {
2164            result = FinderCacheUtil.getResult(finderClassName,
2165                    finderMethodName, finderParams, finderArgs, this);
2166        }
2167
2168        if (result == null) {
2169            Session session = null;
2170
2171            try {
2172                session = openSession();
2173
2174                StringBuilder query = new StringBuilder();
2175
2176                query.append("SELECT COUNT(*) ");
2177                query.append(
2178                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
2179
2180                query.append("groupId = ?");
2181
2182                query.append(" AND ");
2183
2184                if (articleId == null) {
2185                    query.append("articleId IS NULL");
2186                }
2187                else {
2188                    query.append("articleId = ?");
2189                }
2190
2191                query.append(" ");
2192
2193                Query q = session.createQuery(query.toString());
2194
2195                QueryPos qPos = QueryPos.getInstance(q);
2196
2197                qPos.add(groupId);
2198
2199                if (articleId != null) {
2200                    qPos.add(articleId);
2201                }
2202
2203                Long count = null;
2204
2205                Iterator<Long> itr = q.list().iterator();
2206
2207                if (itr.hasNext()) {
2208                    count = itr.next();
2209                }
2210
2211                if (count == null) {
2212                    count = new Long(0);
2213                }
2214
2215                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2216                    finderClassName, finderMethodName, finderParams,
2217                    finderArgs, count);
2218
2219                return count.intValue();
2220            }
2221            catch (Exception e) {
2222                throw processException(e);
2223            }
2224            finally {
2225                closeSession(session);
2226            }
2227        }
2228        else {
2229            return ((Long)result).intValue();
2230        }
2231    }
2232
2233    public int countByG_P_L(long groupId, boolean privateLayout, long layoutId)
2234        throws SystemException {
2235        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2236        String finderClassName = JournalContentSearch.class.getName();
2237        String finderMethodName = "countByG_P_L";
2238        String[] finderParams = new String[] {
2239                Long.class.getName(), Boolean.class.getName(),
2240                Long.class.getName()
2241            };
2242        Object[] finderArgs = new Object[] {
2243                new Long(groupId), Boolean.valueOf(privateLayout),
2244                new Long(layoutId)
2245            };
2246
2247        Object result = null;
2248
2249        if (finderClassNameCacheEnabled) {
2250            result = FinderCacheUtil.getResult(finderClassName,
2251                    finderMethodName, finderParams, finderArgs, this);
2252        }
2253
2254        if (result == null) {
2255            Session session = null;
2256
2257            try {
2258                session = openSession();
2259
2260                StringBuilder query = new StringBuilder();
2261
2262                query.append("SELECT COUNT(*) ");
2263                query.append(
2264                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
2265
2266                query.append("groupId = ?");
2267
2268                query.append(" AND ");
2269
2270                query.append("privateLayout = ?");
2271
2272                query.append(" AND ");
2273
2274                query.append("layoutId = ?");
2275
2276                query.append(" ");
2277
2278                Query q = session.createQuery(query.toString());
2279
2280                QueryPos qPos = QueryPos.getInstance(q);
2281
2282                qPos.add(groupId);
2283
2284                qPos.add(privateLayout);
2285
2286                qPos.add(layoutId);
2287
2288                Long count = null;
2289
2290                Iterator<Long> itr = q.list().iterator();
2291
2292                if (itr.hasNext()) {
2293                    count = itr.next();
2294                }
2295
2296                if (count == null) {
2297                    count = new Long(0);
2298                }
2299
2300                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2301                    finderClassName, finderMethodName, finderParams,
2302                    finderArgs, count);
2303
2304                return count.intValue();
2305            }
2306            catch (Exception e) {
2307                throw processException(e);
2308            }
2309            finally {
2310                closeSession(session);
2311            }
2312        }
2313        else {
2314            return ((Long)result).intValue();
2315        }
2316    }
2317
2318    public int countByG_P_A(long groupId, boolean privateLayout,
2319        String articleId) throws SystemException {
2320        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2321        String finderClassName = JournalContentSearch.class.getName();
2322        String finderMethodName = "countByG_P_A";
2323        String[] finderParams = new String[] {
2324                Long.class.getName(), Boolean.class.getName(),
2325                String.class.getName()
2326            };
2327        Object[] finderArgs = new Object[] {
2328                new Long(groupId), Boolean.valueOf(privateLayout),
2329                
2330                articleId
2331            };
2332
2333        Object result = null;
2334
2335        if (finderClassNameCacheEnabled) {
2336            result = FinderCacheUtil.getResult(finderClassName,
2337                    finderMethodName, finderParams, finderArgs, this);
2338        }
2339
2340        if (result == null) {
2341            Session session = null;
2342
2343            try {
2344                session = openSession();
2345
2346                StringBuilder query = new StringBuilder();
2347
2348                query.append("SELECT COUNT(*) ");
2349                query.append(
2350                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
2351
2352                query.append("groupId = ?");
2353
2354                query.append(" AND ");
2355
2356                query.append("privateLayout = ?");
2357
2358                query.append(" AND ");
2359
2360                if (articleId == null) {
2361                    query.append("articleId IS NULL");
2362                }
2363                else {
2364                    query.append("articleId = ?");
2365                }
2366
2367                query.append(" ");
2368
2369                Query q = session.createQuery(query.toString());
2370
2371                QueryPos qPos = QueryPos.getInstance(q);
2372
2373                qPos.add(groupId);
2374
2375                qPos.add(privateLayout);
2376
2377                if (articleId != null) {
2378                    qPos.add(articleId);
2379                }
2380
2381                Long count = null;
2382
2383                Iterator<Long> itr = q.list().iterator();
2384
2385                if (itr.hasNext()) {
2386                    count = itr.next();
2387                }
2388
2389                if (count == null) {
2390                    count = new Long(0);
2391                }
2392
2393                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2394                    finderClassName, finderMethodName, finderParams,
2395                    finderArgs, count);
2396
2397                return count.intValue();
2398            }
2399            catch (Exception e) {
2400                throw processException(e);
2401            }
2402            finally {
2403                closeSession(session);
2404            }
2405        }
2406        else {
2407            return ((Long)result).intValue();
2408        }
2409    }
2410
2411    public int countByG_P_L_P(long groupId, boolean privateLayout,
2412        long layoutId, String portletId) throws SystemException {
2413        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2414        String finderClassName = JournalContentSearch.class.getName();
2415        String finderMethodName = "countByG_P_L_P";
2416        String[] finderParams = new String[] {
2417                Long.class.getName(), Boolean.class.getName(),
2418                Long.class.getName(), String.class.getName()
2419            };
2420        Object[] finderArgs = new Object[] {
2421                new Long(groupId), Boolean.valueOf(privateLayout),
2422                new Long(layoutId),
2423                
2424                portletId
2425            };
2426
2427        Object result = null;
2428
2429        if (finderClassNameCacheEnabled) {
2430            result = FinderCacheUtil.getResult(finderClassName,
2431                    finderMethodName, finderParams, finderArgs, this);
2432        }
2433
2434        if (result == null) {
2435            Session session = null;
2436
2437            try {
2438                session = openSession();
2439
2440                StringBuilder query = new StringBuilder();
2441
2442                query.append("SELECT COUNT(*) ");
2443                query.append(
2444                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
2445
2446                query.append("groupId = ?");
2447
2448                query.append(" AND ");
2449
2450                query.append("privateLayout = ?");
2451
2452                query.append(" AND ");
2453
2454                query.append("layoutId = ?");
2455
2456                query.append(" AND ");
2457
2458                if (portletId == null) {
2459                    query.append("portletId IS NULL");
2460                }
2461                else {
2462                    query.append("portletId = ?");
2463                }
2464
2465                query.append(" ");
2466
2467                Query q = session.createQuery(query.toString());
2468
2469                QueryPos qPos = QueryPos.getInstance(q);
2470
2471                qPos.add(groupId);
2472
2473                qPos.add(privateLayout);
2474
2475                qPos.add(layoutId);
2476
2477                if (portletId != null) {
2478                    qPos.add(portletId);
2479                }
2480
2481                Long count = null;
2482
2483                Iterator<Long> itr = q.list().iterator();
2484
2485                if (itr.hasNext()) {
2486                    count = itr.next();
2487                }
2488
2489                if (count == null) {
2490                    count = new Long(0);
2491                }
2492
2493                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2494                    finderClassName, finderMethodName, finderParams,
2495                    finderArgs, count);
2496
2497                return count.intValue();
2498            }
2499            catch (Exception e) {
2500                throw processException(e);
2501            }
2502            finally {
2503                closeSession(session);
2504            }
2505        }
2506        else {
2507            return ((Long)result).intValue();
2508        }
2509    }
2510
2511    public int countByG_P_L_P_A(long groupId, boolean privateLayout,
2512        long layoutId, String portletId, String articleId)
2513        throws SystemException {
2514        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2515        String finderClassName = JournalContentSearch.class.getName();
2516        String finderMethodName = "countByG_P_L_P_A";
2517        String[] finderParams = new String[] {
2518                Long.class.getName(), Boolean.class.getName(),
2519                Long.class.getName(), String.class.getName(),
2520                String.class.getName()
2521            };
2522        Object[] finderArgs = new Object[] {
2523                new Long(groupId), Boolean.valueOf(privateLayout),
2524                new Long(layoutId),
2525                
2526                portletId,
2527                
2528                articleId
2529            };
2530
2531        Object result = null;
2532
2533        if (finderClassNameCacheEnabled) {
2534            result = FinderCacheUtil.getResult(finderClassName,
2535                    finderMethodName, finderParams, finderArgs, this);
2536        }
2537
2538        if (result == null) {
2539            Session session = null;
2540
2541            try {
2542                session = openSession();
2543
2544                StringBuilder query = new StringBuilder();
2545
2546                query.append("SELECT COUNT(*) ");
2547                query.append(
2548                    "FROM com.liferay.portlet.journal.model.JournalContentSearch WHERE ");
2549
2550                query.append("groupId = ?");
2551
2552                query.append(" AND ");
2553
2554                query.append("privateLayout = ?");
2555
2556                query.append(" AND ");
2557
2558                query.append("layoutId = ?");
2559
2560                query.append(" AND ");
2561
2562                if (portletId == null) {
2563                    query.append("portletId IS NULL");
2564                }
2565                else {
2566                    query.append("portletId = ?");
2567                }
2568
2569                query.append(" AND ");
2570
2571                if (articleId == null) {
2572                    query.append("articleId IS NULL");
2573                }
2574                else {
2575                    query.append("articleId = ?");
2576                }
2577
2578                query.append(" ");
2579
2580                Query q = session.createQuery(query.toString());
2581
2582                QueryPos qPos = QueryPos.getInstance(q);
2583
2584                qPos.add(groupId);
2585
2586                qPos.add(privateLayout);
2587
2588                qPos.add(layoutId);
2589
2590                if (portletId != null) {
2591                    qPos.add(portletId);
2592                }
2593
2594                if (articleId != null) {
2595                    qPos.add(articleId);
2596                }
2597
2598                Long count = null;
2599
2600                Iterator<Long> itr = q.list().iterator();
2601
2602                if (itr.hasNext()) {
2603                    count = itr.next();
2604                }
2605
2606                if (count == null) {
2607                    count = new Long(0);
2608                }
2609
2610                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2611                    finderClassName, finderMethodName, finderParams,
2612                    finderArgs, count);
2613
2614                return count.intValue();
2615            }
2616            catch (Exception e) {
2617                throw processException(e);
2618            }
2619            finally {
2620                closeSession(session);
2621            }
2622        }
2623        else {
2624            return ((Long)result).intValue();
2625        }
2626    }
2627
2628    public int countAll() throws SystemException {
2629        boolean finderClassNameCacheEnabled = JournalContentSearchModelImpl.CACHE_ENABLED;
2630        String finderClassName = JournalContentSearch.class.getName();
2631        String finderMethodName = "countAll";
2632        String[] finderParams = new String[] {  };
2633        Object[] finderArgs = new Object[] {  };
2634
2635        Object result = null;
2636
2637        if (finderClassNameCacheEnabled) {
2638            result = FinderCacheUtil.getResult(finderClassName,
2639                    finderMethodName, finderParams, finderArgs, this);
2640        }
2641
2642        if (result == null) {
2643            Session session = null;
2644
2645            try {
2646                session = openSession();
2647
2648                Query q = session.createQuery(
2649                        "SELECT COUNT(*) FROM com.liferay.portlet.journal.model.JournalContentSearch");
2650
2651                Long count = null;
2652
2653                Iterator<Long> itr = q.list().iterator();
2654
2655                if (itr.hasNext()) {
2656                    count = itr.next();
2657                }
2658
2659                if (count == null) {
2660                    count = new Long(0);
2661                }
2662
2663                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
2664                    finderClassName, finderMethodName, finderParams,
2665                    finderArgs, count);
2666
2667                return count.intValue();
2668            }
2669            catch (Exception e) {
2670                throw processException(e);
2671            }
2672            finally {
2673                closeSession(session);
2674            }
2675        }
2676        else {
2677            return ((Long)result).intValue();
2678        }
2679    }
2680
2681    public void registerListener(ModelListener listener) {
2682        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2683
2684        listeners.add(listener);
2685
2686        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2687    }
2688
2689    public void unregisterListener(ModelListener listener) {
2690        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2691
2692        listeners.remove(listener);
2693
2694        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2695    }
2696
2697    public void afterPropertiesSet() {
2698        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2699                    com.liferay.portal.util.PropsUtil.get(
2700                        "value.object.listener.com.liferay.portlet.journal.model.JournalContentSearch")));
2701
2702        if (listenerClassNames.length > 0) {
2703            try {
2704                List<ModelListener> listeners = new ArrayList<ModelListener>();
2705
2706                for (String listenerClassName : listenerClassNames) {
2707                    listeners.add((ModelListener)Class.forName(
2708                            listenerClassName).newInstance());
2709                }
2710
2711                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2712            }
2713            catch (Exception e) {
2714                _log.error(e);
2715            }
2716        }
2717    }
2718
2719    private static Log _log = LogFactory.getLog(JournalContentSearchPersistenceImpl.class);
2720    private ModelListener[] _listeners = new ModelListener[0];
2721}