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