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