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