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.blogs.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.blogs.NoSuchEntryException;
36  import com.liferay.portlet.blogs.model.BlogsEntry;
37  import com.liferay.portlet.blogs.model.impl.BlogsEntryImpl;
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="BlogsEntryPersistenceImpl.java.html"><b><i>View Source</i></b></a>
53   *
54   * @author Brian Wing Shun Chan
55   *
56   */
57  public class BlogsEntryPersistenceImpl extends BasePersistence
58      implements BlogsEntryPersistence {
59      public BlogsEntry create(long entryId) {
60          BlogsEntry blogsEntry = new BlogsEntryImpl();
61          blogsEntry.setNew(true);
62          blogsEntry.setPrimaryKey(entryId);
63  
64          return blogsEntry;
65      }
66  
67      public BlogsEntry remove(long entryId)
68          throws NoSuchEntryException, SystemException {
69          Session session = null;
70  
71          try {
72              session = openSession();
73  
74              BlogsEntry blogsEntry = (BlogsEntry)session.get(BlogsEntryImpl.class,
75                      new Long(entryId));
76  
77              if (blogsEntry == null) {
78                  if (_log.isWarnEnabled()) {
79                      _log.warn("No BlogsEntry exists with the primary key " +
80                          entryId);
81                  }
82  
83                  throw new NoSuchEntryException(
84                      "No BlogsEntry exists with the primary key " + entryId);
85              }
86  
87              return remove(blogsEntry);
88          }
89          catch (NoSuchEntryException nsee) {
90              throw nsee;
91          }
92          catch (Exception e) {
93              throw HibernateUtil.processException(e);
94          }
95          finally {
96              closeSession(session);
97          }
98      }
99  
100     public BlogsEntry remove(BlogsEntry blogsEntry) throws SystemException {
101         Session session = null;
102 
103         try {
104             session = openSession();
105             session.delete(blogsEntry);
106             session.flush();
107 
108             return blogsEntry;
109         }
110         catch (Exception e) {
111             throw HibernateUtil.processException(e);
112         }
113         finally {
114             closeSession(session);
115             FinderCache.clearCache(BlogsEntry.class.getName());
116         }
117     }
118 
119     public BlogsEntry update(
120         com.liferay.portlet.blogs.model.BlogsEntry blogsEntry)
121         throws SystemException {
122         return update(blogsEntry, false);
123     }
124 
125     public BlogsEntry update(
126         com.liferay.portlet.blogs.model.BlogsEntry blogsEntry, boolean merge)
127         throws SystemException {
128         Session session = null;
129 
130         try {
131             session = openSession();
132 
133             if (merge) {
134                 session.merge(blogsEntry);
135             }
136             else {
137                 if (blogsEntry.isNew()) {
138                     session.save(blogsEntry);
139                 }
140             }
141 
142             session.flush();
143             blogsEntry.setNew(false);
144 
145             return blogsEntry;
146         }
147         catch (Exception e) {
148             throw HibernateUtil.processException(e);
149         }
150         finally {
151             closeSession(session);
152             FinderCache.clearCache(BlogsEntry.class.getName());
153         }
154     }
155 
156     public BlogsEntry findByPrimaryKey(long entryId)
157         throws NoSuchEntryException, SystemException {
158         BlogsEntry blogsEntry = fetchByPrimaryKey(entryId);
159 
160         if (blogsEntry == null) {
161             if (_log.isWarnEnabled()) {
162                 _log.warn("No BlogsEntry exists with the primary key " +
163                     entryId);
164             }
165 
166             throw new NoSuchEntryException(
167                 "No BlogsEntry exists with the primary key " + entryId);
168         }
169 
170         return blogsEntry;
171     }
172 
173     public BlogsEntry fetchByPrimaryKey(long entryId) throws SystemException {
174         Session session = null;
175 
176         try {
177             session = openSession();
178 
179             return (BlogsEntry)session.get(BlogsEntryImpl.class,
180                 new Long(entryId));
181         }
182         catch (Exception e) {
183             throw HibernateUtil.processException(e);
184         }
185         finally {
186             closeSession(session);
187         }
188     }
189 
190     public List findByGroupId(long groupId) throws SystemException {
191         String finderClassName = BlogsEntry.class.getName();
192         String finderMethodName = "findByGroupId";
193         String[] finderParams = new String[] { Long.class.getName() };
194         Object[] finderArgs = new Object[] { new Long(groupId) };
195         Object result = FinderCache.getResult(finderClassName,
196                 finderMethodName, finderParams, finderArgs, getSessionFactory());
197 
198         if (result == null) {
199             Session session = null;
200 
201             try {
202                 session = openSession();
203 
204                 StringMaker query = new StringMaker();
205                 query.append(
206                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
207                 query.append("groupId = ?");
208                 query.append(" ");
209                 query.append("ORDER BY ");
210                 query.append("displayDate DESC");
211 
212                 Query q = session.createQuery(query.toString());
213                 int queryPos = 0;
214                 q.setLong(queryPos++, groupId);
215 
216                 List list = q.list();
217                 FinderCache.putResult(finderClassName, finderMethodName,
218                     finderParams, finderArgs, list);
219 
220                 return list;
221             }
222             catch (Exception e) {
223                 throw HibernateUtil.processException(e);
224             }
225             finally {
226                 closeSession(session);
227             }
228         }
229         else {
230             return (List)result;
231         }
232     }
233 
234     public List findByGroupId(long groupId, int begin, int end)
235         throws SystemException {
236         return findByGroupId(groupId, begin, end, null);
237     }
238 
239     public List findByGroupId(long groupId, int begin, int end,
240         OrderByComparator obc) throws SystemException {
241         String finderClassName = BlogsEntry.class.getName();
242         String finderMethodName = "findByGroupId";
243         String[] finderParams = new String[] {
244                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
245                 "com.liferay.portal.kernel.util.OrderByComparator"
246             };
247         Object[] finderArgs = new Object[] {
248                 new Long(groupId), String.valueOf(begin), String.valueOf(end),
249                 String.valueOf(obc)
250             };
251         Object result = FinderCache.getResult(finderClassName,
252                 finderMethodName, finderParams, finderArgs, getSessionFactory());
253 
254         if (result == null) {
255             Session session = null;
256 
257             try {
258                 session = openSession();
259 
260                 StringMaker query = new StringMaker();
261                 query.append(
262                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
263                 query.append("groupId = ?");
264                 query.append(" ");
265 
266                 if (obc != null) {
267                     query.append("ORDER BY ");
268                     query.append(obc.getOrderBy());
269                 }
270                 else {
271                     query.append("ORDER BY ");
272                     query.append("displayDate DESC");
273                 }
274 
275                 Query q = session.createQuery(query.toString());
276                 int queryPos = 0;
277                 q.setLong(queryPos++, groupId);
278 
279                 List list = QueryUtil.list(q, getDialect(), begin, end);
280                 FinderCache.putResult(finderClassName, finderMethodName,
281                     finderParams, finderArgs, list);
282 
283                 return list;
284             }
285             catch (Exception e) {
286                 throw HibernateUtil.processException(e);
287             }
288             finally {
289                 closeSession(session);
290             }
291         }
292         else {
293             return (List)result;
294         }
295     }
296 
297     public BlogsEntry findByGroupId_First(long groupId, OrderByComparator obc)
298         throws NoSuchEntryException, SystemException {
299         List list = findByGroupId(groupId, 0, 1, obc);
300 
301         if (list.size() == 0) {
302             StringMaker msg = new StringMaker();
303             msg.append("No BlogsEntry exists with the key ");
304             msg.append(StringPool.OPEN_CURLY_BRACE);
305             msg.append("groupId=");
306             msg.append(groupId);
307             msg.append(StringPool.CLOSE_CURLY_BRACE);
308             throw new NoSuchEntryException(msg.toString());
309         }
310         else {
311             return (BlogsEntry)list.get(0);
312         }
313     }
314 
315     public BlogsEntry findByGroupId_Last(long groupId, OrderByComparator obc)
316         throws NoSuchEntryException, SystemException {
317         int count = countByGroupId(groupId);
318         List list = findByGroupId(groupId, count - 1, count, obc);
319 
320         if (list.size() == 0) {
321             StringMaker msg = new StringMaker();
322             msg.append("No BlogsEntry exists with the key ");
323             msg.append(StringPool.OPEN_CURLY_BRACE);
324             msg.append("groupId=");
325             msg.append(groupId);
326             msg.append(StringPool.CLOSE_CURLY_BRACE);
327             throw new NoSuchEntryException(msg.toString());
328         }
329         else {
330             return (BlogsEntry)list.get(0);
331         }
332     }
333 
334     public BlogsEntry[] findByGroupId_PrevAndNext(long entryId, long groupId,
335         OrderByComparator obc) throws NoSuchEntryException, SystemException {
336         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
337         int count = countByGroupId(groupId);
338         Session session = null;
339 
340         try {
341             session = openSession();
342 
343             StringMaker query = new StringMaker();
344             query.append(
345                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
346             query.append("groupId = ?");
347             query.append(" ");
348 
349             if (obc != null) {
350                 query.append("ORDER BY ");
351                 query.append(obc.getOrderBy());
352             }
353             else {
354                 query.append("ORDER BY ");
355                 query.append("displayDate DESC");
356             }
357 
358             Query q = session.createQuery(query.toString());
359             int queryPos = 0;
360             q.setLong(queryPos++, groupId);
361 
362             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
363                     blogsEntry);
364             BlogsEntry[] array = new BlogsEntryImpl[3];
365             array[0] = (BlogsEntry)objArray[0];
366             array[1] = (BlogsEntry)objArray[1];
367             array[2] = (BlogsEntry)objArray[2];
368 
369             return array;
370         }
371         catch (Exception e) {
372             throw HibernateUtil.processException(e);
373         }
374         finally {
375             closeSession(session);
376         }
377     }
378 
379     public List findByCompanyId(long companyId) throws SystemException {
380         String finderClassName = BlogsEntry.class.getName();
381         String finderMethodName = "findByCompanyId";
382         String[] finderParams = new String[] { Long.class.getName() };
383         Object[] finderArgs = new Object[] { new Long(companyId) };
384         Object result = FinderCache.getResult(finderClassName,
385                 finderMethodName, finderParams, finderArgs, getSessionFactory());
386 
387         if (result == null) {
388             Session session = null;
389 
390             try {
391                 session = openSession();
392 
393                 StringMaker query = new StringMaker();
394                 query.append(
395                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
396                 query.append("companyId = ?");
397                 query.append(" ");
398                 query.append("ORDER BY ");
399                 query.append("displayDate DESC");
400 
401                 Query q = session.createQuery(query.toString());
402                 int queryPos = 0;
403                 q.setLong(queryPos++, companyId);
404 
405                 List list = q.list();
406                 FinderCache.putResult(finderClassName, finderMethodName,
407                     finderParams, finderArgs, list);
408 
409                 return list;
410             }
411             catch (Exception e) {
412                 throw HibernateUtil.processException(e);
413             }
414             finally {
415                 closeSession(session);
416             }
417         }
418         else {
419             return (List)result;
420         }
421     }
422 
423     public List findByCompanyId(long companyId, int begin, int end)
424         throws SystemException {
425         return findByCompanyId(companyId, begin, end, null);
426     }
427 
428     public List findByCompanyId(long companyId, int begin, int end,
429         OrderByComparator obc) throws SystemException {
430         String finderClassName = BlogsEntry.class.getName();
431         String finderMethodName = "findByCompanyId";
432         String[] finderParams = new String[] {
433                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
434                 "com.liferay.portal.kernel.util.OrderByComparator"
435             };
436         Object[] finderArgs = new Object[] {
437                 new Long(companyId), String.valueOf(begin), String.valueOf(end),
438                 String.valueOf(obc)
439             };
440         Object result = FinderCache.getResult(finderClassName,
441                 finderMethodName, finderParams, finderArgs, getSessionFactory());
442 
443         if (result == null) {
444             Session session = null;
445 
446             try {
447                 session = openSession();
448 
449                 StringMaker query = new StringMaker();
450                 query.append(
451                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
452                 query.append("companyId = ?");
453                 query.append(" ");
454 
455                 if (obc != null) {
456                     query.append("ORDER BY ");
457                     query.append(obc.getOrderBy());
458                 }
459                 else {
460                     query.append("ORDER BY ");
461                     query.append("displayDate DESC");
462                 }
463 
464                 Query q = session.createQuery(query.toString());
465                 int queryPos = 0;
466                 q.setLong(queryPos++, companyId);
467 
468                 List list = QueryUtil.list(q, getDialect(), begin, end);
469                 FinderCache.putResult(finderClassName, finderMethodName,
470                     finderParams, finderArgs, list);
471 
472                 return list;
473             }
474             catch (Exception e) {
475                 throw HibernateUtil.processException(e);
476             }
477             finally {
478                 closeSession(session);
479             }
480         }
481         else {
482             return (List)result;
483         }
484     }
485 
486     public BlogsEntry findByCompanyId_First(long companyId,
487         OrderByComparator obc) throws NoSuchEntryException, SystemException {
488         List list = findByCompanyId(companyId, 0, 1, obc);
489 
490         if (list.size() == 0) {
491             StringMaker msg = new StringMaker();
492             msg.append("No BlogsEntry exists with the key ");
493             msg.append(StringPool.OPEN_CURLY_BRACE);
494             msg.append("companyId=");
495             msg.append(companyId);
496             msg.append(StringPool.CLOSE_CURLY_BRACE);
497             throw new NoSuchEntryException(msg.toString());
498         }
499         else {
500             return (BlogsEntry)list.get(0);
501         }
502     }
503 
504     public BlogsEntry findByCompanyId_Last(long companyId, OrderByComparator obc)
505         throws NoSuchEntryException, SystemException {
506         int count = countByCompanyId(companyId);
507         List list = findByCompanyId(companyId, count - 1, count, obc);
508 
509         if (list.size() == 0) {
510             StringMaker msg = new StringMaker();
511             msg.append("No BlogsEntry exists with the key ");
512             msg.append(StringPool.OPEN_CURLY_BRACE);
513             msg.append("companyId=");
514             msg.append(companyId);
515             msg.append(StringPool.CLOSE_CURLY_BRACE);
516             throw new NoSuchEntryException(msg.toString());
517         }
518         else {
519             return (BlogsEntry)list.get(0);
520         }
521     }
522 
523     public BlogsEntry[] findByCompanyId_PrevAndNext(long entryId,
524         long companyId, OrderByComparator obc)
525         throws NoSuchEntryException, SystemException {
526         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
527         int count = countByCompanyId(companyId);
528         Session session = null;
529 
530         try {
531             session = openSession();
532 
533             StringMaker query = new StringMaker();
534             query.append(
535                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
536             query.append("companyId = ?");
537             query.append(" ");
538 
539             if (obc != null) {
540                 query.append("ORDER BY ");
541                 query.append(obc.getOrderBy());
542             }
543             else {
544                 query.append("ORDER BY ");
545                 query.append("displayDate DESC");
546             }
547 
548             Query q = session.createQuery(query.toString());
549             int queryPos = 0;
550             q.setLong(queryPos++, companyId);
551 
552             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
553                     blogsEntry);
554             BlogsEntry[] array = new BlogsEntryImpl[3];
555             array[0] = (BlogsEntry)objArray[0];
556             array[1] = (BlogsEntry)objArray[1];
557             array[2] = (BlogsEntry)objArray[2];
558 
559             return array;
560         }
561         catch (Exception e) {
562             throw HibernateUtil.processException(e);
563         }
564         finally {
565             closeSession(session);
566         }
567     }
568 
569     public List findByCategoryId(long categoryId) throws SystemException {
570         String finderClassName = BlogsEntry.class.getName();
571         String finderMethodName = "findByCategoryId";
572         String[] finderParams = new String[] { Long.class.getName() };
573         Object[] finderArgs = new Object[] { new Long(categoryId) };
574         Object result = FinderCache.getResult(finderClassName,
575                 finderMethodName, finderParams, finderArgs, getSessionFactory());
576 
577         if (result == null) {
578             Session session = null;
579 
580             try {
581                 session = openSession();
582 
583                 StringMaker query = new StringMaker();
584                 query.append(
585                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
586                 query.append("categoryId = ?");
587                 query.append(" ");
588                 query.append("ORDER BY ");
589                 query.append("displayDate DESC");
590 
591                 Query q = session.createQuery(query.toString());
592                 int queryPos = 0;
593                 q.setLong(queryPos++, categoryId);
594 
595                 List list = q.list();
596                 FinderCache.putResult(finderClassName, finderMethodName,
597                     finderParams, finderArgs, list);
598 
599                 return list;
600             }
601             catch (Exception e) {
602                 throw HibernateUtil.processException(e);
603             }
604             finally {
605                 closeSession(session);
606             }
607         }
608         else {
609             return (List)result;
610         }
611     }
612 
613     public List findByCategoryId(long categoryId, int begin, int end)
614         throws SystemException {
615         return findByCategoryId(categoryId, begin, end, null);
616     }
617 
618     public List findByCategoryId(long categoryId, int begin, int end,
619         OrderByComparator obc) throws SystemException {
620         String finderClassName = BlogsEntry.class.getName();
621         String finderMethodName = "findByCategoryId";
622         String[] finderParams = new String[] {
623                 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
624                 "com.liferay.portal.kernel.util.OrderByComparator"
625             };
626         Object[] finderArgs = new Object[] {
627                 new Long(categoryId), String.valueOf(begin), String.valueOf(end),
628                 String.valueOf(obc)
629             };
630         Object result = FinderCache.getResult(finderClassName,
631                 finderMethodName, finderParams, finderArgs, getSessionFactory());
632 
633         if (result == null) {
634             Session session = null;
635 
636             try {
637                 session = openSession();
638 
639                 StringMaker query = new StringMaker();
640                 query.append(
641                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
642                 query.append("categoryId = ?");
643                 query.append(" ");
644 
645                 if (obc != null) {
646                     query.append("ORDER BY ");
647                     query.append(obc.getOrderBy());
648                 }
649                 else {
650                     query.append("ORDER BY ");
651                     query.append("displayDate DESC");
652                 }
653 
654                 Query q = session.createQuery(query.toString());
655                 int queryPos = 0;
656                 q.setLong(queryPos++, categoryId);
657 
658                 List list = QueryUtil.list(q, getDialect(), begin, end);
659                 FinderCache.putResult(finderClassName, finderMethodName,
660                     finderParams, finderArgs, list);
661 
662                 return list;
663             }
664             catch (Exception e) {
665                 throw HibernateUtil.processException(e);
666             }
667             finally {
668                 closeSession(session);
669             }
670         }
671         else {
672             return (List)result;
673         }
674     }
675 
676     public BlogsEntry findByCategoryId_First(long categoryId,
677         OrderByComparator obc) throws NoSuchEntryException, SystemException {
678         List list = findByCategoryId(categoryId, 0, 1, obc);
679 
680         if (list.size() == 0) {
681             StringMaker msg = new StringMaker();
682             msg.append("No BlogsEntry exists with the key ");
683             msg.append(StringPool.OPEN_CURLY_BRACE);
684             msg.append("categoryId=");
685             msg.append(categoryId);
686             msg.append(StringPool.CLOSE_CURLY_BRACE);
687             throw new NoSuchEntryException(msg.toString());
688         }
689         else {
690             return (BlogsEntry)list.get(0);
691         }
692     }
693 
694     public BlogsEntry findByCategoryId_Last(long categoryId,
695         OrderByComparator obc) throws NoSuchEntryException, SystemException {
696         int count = countByCategoryId(categoryId);
697         List list = findByCategoryId(categoryId, count - 1, count, obc);
698 
699         if (list.size() == 0) {
700             StringMaker msg = new StringMaker();
701             msg.append("No BlogsEntry exists with the key ");
702             msg.append(StringPool.OPEN_CURLY_BRACE);
703             msg.append("categoryId=");
704             msg.append(categoryId);
705             msg.append(StringPool.CLOSE_CURLY_BRACE);
706             throw new NoSuchEntryException(msg.toString());
707         }
708         else {
709             return (BlogsEntry)list.get(0);
710         }
711     }
712 
713     public BlogsEntry[] findByCategoryId_PrevAndNext(long entryId,
714         long categoryId, OrderByComparator obc)
715         throws NoSuchEntryException, SystemException {
716         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
717         int count = countByCategoryId(categoryId);
718         Session session = null;
719 
720         try {
721             session = openSession();
722 
723             StringMaker query = new StringMaker();
724             query.append(
725                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
726             query.append("categoryId = ?");
727             query.append(" ");
728 
729             if (obc != null) {
730                 query.append("ORDER BY ");
731                 query.append(obc.getOrderBy());
732             }
733             else {
734                 query.append("ORDER BY ");
735                 query.append("displayDate DESC");
736             }
737 
738             Query q = session.createQuery(query.toString());
739             int queryPos = 0;
740             q.setLong(queryPos++, categoryId);
741 
742             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
743                     blogsEntry);
744             BlogsEntry[] array = new BlogsEntryImpl[3];
745             array[0] = (BlogsEntry)objArray[0];
746             array[1] = (BlogsEntry)objArray[1];
747             array[2] = (BlogsEntry)objArray[2];
748 
749             return array;
750         }
751         catch (Exception e) {
752             throw HibernateUtil.processException(e);
753         }
754         finally {
755             closeSession(session);
756         }
757     }
758 
759     public List findByG_U(long groupId, long userId) throws SystemException {
760         String finderClassName = BlogsEntry.class.getName();
761         String finderMethodName = "findByG_U";
762         String[] finderParams = new String[] {
763                 Long.class.getName(), Long.class.getName()
764             };
765         Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
766         Object result = FinderCache.getResult(finderClassName,
767                 finderMethodName, finderParams, finderArgs, getSessionFactory());
768 
769         if (result == null) {
770             Session session = null;
771 
772             try {
773                 session = openSession();
774 
775                 StringMaker query = new StringMaker();
776                 query.append(
777                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
778                 query.append("groupId = ?");
779                 query.append(" AND ");
780                 query.append("userId = ?");
781                 query.append(" ");
782                 query.append("ORDER BY ");
783                 query.append("displayDate DESC");
784 
785                 Query q = session.createQuery(query.toString());
786                 int queryPos = 0;
787                 q.setLong(queryPos++, groupId);
788                 q.setLong(queryPos++, userId);
789 
790                 List list = q.list();
791                 FinderCache.putResult(finderClassName, finderMethodName,
792                     finderParams, finderArgs, list);
793 
794                 return list;
795             }
796             catch (Exception e) {
797                 throw HibernateUtil.processException(e);
798             }
799             finally {
800                 closeSession(session);
801             }
802         }
803         else {
804             return (List)result;
805         }
806     }
807 
808     public List findByG_U(long groupId, long userId, int begin, int end)
809         throws SystemException {
810         return findByG_U(groupId, userId, begin, end, null);
811     }
812 
813     public List findByG_U(long groupId, long userId, int begin, int end,
814         OrderByComparator obc) throws SystemException {
815         String finderClassName = BlogsEntry.class.getName();
816         String finderMethodName = "findByG_U";
817         String[] finderParams = new String[] {
818                 Long.class.getName(), Long.class.getName(), "java.lang.Integer",
819                 "java.lang.Integer",
820                 "com.liferay.portal.kernel.util.OrderByComparator"
821             };
822         Object[] finderArgs = new Object[] {
823                 new Long(groupId), new Long(userId), String.valueOf(begin),
824                 String.valueOf(end), String.valueOf(obc)
825             };
826         Object result = FinderCache.getResult(finderClassName,
827                 finderMethodName, finderParams, finderArgs, getSessionFactory());
828 
829         if (result == null) {
830             Session session = null;
831 
832             try {
833                 session = openSession();
834 
835                 StringMaker query = new StringMaker();
836                 query.append(
837                     "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
838                 query.append("groupId = ?");
839                 query.append(" AND ");
840                 query.append("userId = ?");
841                 query.append(" ");
842 
843                 if (obc != null) {
844                     query.append("ORDER BY ");
845                     query.append(obc.getOrderBy());
846                 }
847                 else {
848                     query.append("ORDER BY ");
849                     query.append("displayDate DESC");
850                 }
851 
852                 Query q = session.createQuery(query.toString());
853                 int queryPos = 0;
854                 q.setLong(queryPos++, groupId);
855                 q.setLong(queryPos++, userId);
856 
857                 List list = QueryUtil.list(q, getDialect(), begin, end);
858                 FinderCache.putResult(finderClassName, finderMethodName,
859                     finderParams, finderArgs, list);
860 
861                 return list;
862             }
863             catch (Exception e) {
864                 throw HibernateUtil.processException(e);
865             }
866             finally {
867                 closeSession(session);
868             }
869         }
870         else {
871             return (List)result;
872         }
873     }
874 
875     public BlogsEntry findByG_U_First(long groupId, long userId,
876         OrderByComparator obc) throws NoSuchEntryException, SystemException {
877         List list = findByG_U(groupId, userId, 0, 1, obc);
878 
879         if (list.size() == 0) {
880             StringMaker msg = new StringMaker();
881             msg.append("No BlogsEntry exists with the key ");
882             msg.append(StringPool.OPEN_CURLY_BRACE);
883             msg.append("groupId=");
884             msg.append(groupId);
885             msg.append(", ");
886             msg.append("userId=");
887             msg.append(userId);
888             msg.append(StringPool.CLOSE_CURLY_BRACE);
889             throw new NoSuchEntryException(msg.toString());
890         }
891         else {
892             return (BlogsEntry)list.get(0);
893         }
894     }
895 
896     public BlogsEntry findByG_U_Last(long groupId, long userId,
897         OrderByComparator obc) throws NoSuchEntryException, SystemException {
898         int count = countByG_U(groupId, userId);
899         List list = findByG_U(groupId, userId, count - 1, count, obc);
900 
901         if (list.size() == 0) {
902             StringMaker msg = new StringMaker();
903             msg.append("No BlogsEntry exists with the key ");
904             msg.append(StringPool.OPEN_CURLY_BRACE);
905             msg.append("groupId=");
906             msg.append(groupId);
907             msg.append(", ");
908             msg.append("userId=");
909             msg.append(userId);
910             msg.append(StringPool.CLOSE_CURLY_BRACE);
911             throw new NoSuchEntryException(msg.toString());
912         }
913         else {
914             return (BlogsEntry)list.get(0);
915         }
916     }
917 
918     public BlogsEntry[] findByG_U_PrevAndNext(long entryId, long groupId,
919         long userId, OrderByComparator obc)
920         throws NoSuchEntryException, SystemException {
921         BlogsEntry blogsEntry = findByPrimaryKey(entryId);
922         int count = countByG_U(groupId, userId);
923         Session session = null;
924 
925         try {
926             session = openSession();
927 
928             StringMaker query = new StringMaker();
929             query.append(
930                 "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
931             query.append("groupId = ?");
932             query.append(" AND ");
933             query.append("userId = ?");
934             query.append(" ");
935 
936             if (obc != null) {
937                 query.append("ORDER BY ");
938                 query.append(obc.getOrderBy());
939             }
940             else {
941                 query.append("ORDER BY ");
942                 query.append("displayDate DESC");
943             }
944 
945             Query q = session.createQuery(query.toString());
946             int queryPos = 0;
947             q.setLong(queryPos++, groupId);
948             q.setLong(queryPos++, userId);
949 
950             Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
951                     blogsEntry);
952             BlogsEntry[] array = new BlogsEntryImpl[3];
953             array[0] = (BlogsEntry)objArray[0];
954             array[1] = (BlogsEntry)objArray[1];
955             array[2] = (BlogsEntry)objArray[2];
956 
957             return array;
958         }
959         catch (Exception e) {
960             throw HibernateUtil.processException(e);
961         }
962         finally {
963             closeSession(session);
964         }
965     }
966 
967     public BlogsEntry findByG_UT(long groupId, String urlTitle)
968         throws NoSuchEntryException, SystemException {
969         BlogsEntry blogsEntry = fetchByG_UT(groupId, urlTitle);
970 
971         if (blogsEntry == null) {
972             StringMaker msg = new StringMaker();
973             msg.append("No BlogsEntry exists with the key ");
974             msg.append(StringPool.OPEN_CURLY_BRACE);
975             msg.append("groupId=");
976             msg.append(groupId);
977             msg.append(", ");
978             msg.append("urlTitle=");
979             msg.append(urlTitle);
980             msg.append(StringPool.CLOSE_CURLY_BRACE);
981 
982             if (_log.isWarnEnabled()) {
983                 _log.warn(msg.toString());
984             }
985 
986             throw new NoSuchEntryException(msg.toString());
987         }
988 
989         return blogsEntry;
990     }
991 
992     public BlogsEntry fetchByG_UT(long groupId, String urlTitle)
993         throws SystemException {
994         String finderClassName = BlogsEntry.class.getName();
995         String finderMethodName = "fetchByG_UT";
996         String[] finderParams = new String[] {
997                 Long.class.getName(), String.class.getName()
998             };
999         Object[] finderArgs = new Object[] { new Long(groupId), urlTitle };
1000        Object result = FinderCache.getResult(finderClassName,
1001                finderMethodName, finderParams, finderArgs, getSessionFactory());
1002
1003        if (result == null) {
1004            Session session = null;
1005
1006            try {
1007                session = openSession();
1008
1009                StringMaker query = new StringMaker();
1010                query.append(
1011                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1012                query.append("groupId = ?");
1013                query.append(" AND ");
1014
1015                if (urlTitle == null) {
1016                    query.append("urlTitle IS NULL");
1017                }
1018                else {
1019                    query.append("urlTitle = ?");
1020                }
1021
1022                query.append(" ");
1023                query.append("ORDER BY ");
1024                query.append("displayDate DESC");
1025
1026                Query q = session.createQuery(query.toString());
1027                int queryPos = 0;
1028                q.setLong(queryPos++, groupId);
1029
1030                if (urlTitle != null) {
1031                    q.setString(queryPos++, urlTitle);
1032                }
1033
1034                List list = q.list();
1035                FinderCache.putResult(finderClassName, finderMethodName,
1036                    finderParams, finderArgs, list);
1037
1038                if (list.size() == 0) {
1039                    return null;
1040                }
1041                else {
1042                    return (BlogsEntry)list.get(0);
1043                }
1044            }
1045            catch (Exception e) {
1046                throw HibernateUtil.processException(e);
1047            }
1048            finally {
1049                closeSession(session);
1050            }
1051        }
1052        else {
1053            List list = (List)result;
1054
1055            if (list.size() == 0) {
1056                return null;
1057            }
1058            else {
1059                return (BlogsEntry)list.get(0);
1060            }
1061        }
1062    }
1063
1064    public List findByC_U(long companyId, long userId)
1065        throws SystemException {
1066        String finderClassName = BlogsEntry.class.getName();
1067        String finderMethodName = "findByC_U";
1068        String[] finderParams = new String[] {
1069                Long.class.getName(), Long.class.getName()
1070            };
1071        Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
1072        Object result = FinderCache.getResult(finderClassName,
1073                finderMethodName, finderParams, finderArgs, getSessionFactory());
1074
1075        if (result == null) {
1076            Session session = null;
1077
1078            try {
1079                session = openSession();
1080
1081                StringMaker query = new StringMaker();
1082                query.append(
1083                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1084                query.append("companyId = ?");
1085                query.append(" AND ");
1086                query.append("userId = ?");
1087                query.append(" ");
1088                query.append("ORDER BY ");
1089                query.append("displayDate DESC");
1090
1091                Query q = session.createQuery(query.toString());
1092                int queryPos = 0;
1093                q.setLong(queryPos++, companyId);
1094                q.setLong(queryPos++, userId);
1095
1096                List list = q.list();
1097                FinderCache.putResult(finderClassName, finderMethodName,
1098                    finderParams, finderArgs, list);
1099
1100                return list;
1101            }
1102            catch (Exception e) {
1103                throw HibernateUtil.processException(e);
1104            }
1105            finally {
1106                closeSession(session);
1107            }
1108        }
1109        else {
1110            return (List)result;
1111        }
1112    }
1113
1114    public List findByC_U(long companyId, long userId, int begin, int end)
1115        throws SystemException {
1116        return findByC_U(companyId, userId, begin, end, null);
1117    }
1118
1119    public List findByC_U(long companyId, long userId, int begin, int end,
1120        OrderByComparator obc) throws SystemException {
1121        String finderClassName = BlogsEntry.class.getName();
1122        String finderMethodName = "findByC_U";
1123        String[] finderParams = new String[] {
1124                Long.class.getName(), Long.class.getName(), "java.lang.Integer",
1125                "java.lang.Integer",
1126                "com.liferay.portal.kernel.util.OrderByComparator"
1127            };
1128        Object[] finderArgs = new Object[] {
1129                new Long(companyId), new Long(userId), String.valueOf(begin),
1130                String.valueOf(end), String.valueOf(obc)
1131            };
1132        Object result = FinderCache.getResult(finderClassName,
1133                finderMethodName, finderParams, finderArgs, getSessionFactory());
1134
1135        if (result == null) {
1136            Session session = null;
1137
1138            try {
1139                session = openSession();
1140
1141                StringMaker query = new StringMaker();
1142                query.append(
1143                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1144                query.append("companyId = ?");
1145                query.append(" AND ");
1146                query.append("userId = ?");
1147                query.append(" ");
1148
1149                if (obc != null) {
1150                    query.append("ORDER BY ");
1151                    query.append(obc.getOrderBy());
1152                }
1153                else {
1154                    query.append("ORDER BY ");
1155                    query.append("displayDate DESC");
1156                }
1157
1158                Query q = session.createQuery(query.toString());
1159                int queryPos = 0;
1160                q.setLong(queryPos++, companyId);
1161                q.setLong(queryPos++, userId);
1162
1163                List list = QueryUtil.list(q, getDialect(), begin, end);
1164                FinderCache.putResult(finderClassName, finderMethodName,
1165                    finderParams, finderArgs, list);
1166
1167                return list;
1168            }
1169            catch (Exception e) {
1170                throw HibernateUtil.processException(e);
1171            }
1172            finally {
1173                closeSession(session);
1174            }
1175        }
1176        else {
1177            return (List)result;
1178        }
1179    }
1180
1181    public BlogsEntry findByC_U_First(long companyId, long userId,
1182        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1183        List list = findByC_U(companyId, userId, 0, 1, obc);
1184
1185        if (list.size() == 0) {
1186            StringMaker msg = new StringMaker();
1187            msg.append("No BlogsEntry exists with the key ");
1188            msg.append(StringPool.OPEN_CURLY_BRACE);
1189            msg.append("companyId=");
1190            msg.append(companyId);
1191            msg.append(", ");
1192            msg.append("userId=");
1193            msg.append(userId);
1194            msg.append(StringPool.CLOSE_CURLY_BRACE);
1195            throw new NoSuchEntryException(msg.toString());
1196        }
1197        else {
1198            return (BlogsEntry)list.get(0);
1199        }
1200    }
1201
1202    public BlogsEntry findByC_U_Last(long companyId, long userId,
1203        OrderByComparator obc) throws NoSuchEntryException, SystemException {
1204        int count = countByC_U(companyId, userId);
1205        List list = findByC_U(companyId, userId, count - 1, count, obc);
1206
1207        if (list.size() == 0) {
1208            StringMaker msg = new StringMaker();
1209            msg.append("No BlogsEntry exists with the key ");
1210            msg.append(StringPool.OPEN_CURLY_BRACE);
1211            msg.append("companyId=");
1212            msg.append(companyId);
1213            msg.append(", ");
1214            msg.append("userId=");
1215            msg.append(userId);
1216            msg.append(StringPool.CLOSE_CURLY_BRACE);
1217            throw new NoSuchEntryException(msg.toString());
1218        }
1219        else {
1220            return (BlogsEntry)list.get(0);
1221        }
1222    }
1223
1224    public BlogsEntry[] findByC_U_PrevAndNext(long entryId, long companyId,
1225        long userId, OrderByComparator obc)
1226        throws NoSuchEntryException, SystemException {
1227        BlogsEntry blogsEntry = findByPrimaryKey(entryId);
1228        int count = countByC_U(companyId, userId);
1229        Session session = null;
1230
1231        try {
1232            session = openSession();
1233
1234            StringMaker query = new StringMaker();
1235            query.append(
1236                "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1237            query.append("companyId = ?");
1238            query.append(" AND ");
1239            query.append("userId = ?");
1240            query.append(" ");
1241
1242            if (obc != null) {
1243                query.append("ORDER BY ");
1244                query.append(obc.getOrderBy());
1245            }
1246            else {
1247                query.append("ORDER BY ");
1248                query.append("displayDate DESC");
1249            }
1250
1251            Query q = session.createQuery(query.toString());
1252            int queryPos = 0;
1253            q.setLong(queryPos++, companyId);
1254            q.setLong(queryPos++, userId);
1255
1256            Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1257                    blogsEntry);
1258            BlogsEntry[] array = new BlogsEntryImpl[3];
1259            array[0] = (BlogsEntry)objArray[0];
1260            array[1] = (BlogsEntry)objArray[1];
1261            array[2] = (BlogsEntry)objArray[2];
1262
1263            return array;
1264        }
1265        catch (Exception e) {
1266            throw HibernateUtil.processException(e);
1267        }
1268        finally {
1269            closeSession(session);
1270        }
1271    }
1272
1273    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
1274        throws SystemException {
1275        Session session = null;
1276
1277        try {
1278            session = openSession();
1279
1280            DynamicQuery query = queryInitializer.initialize(session);
1281
1282            return query.list();
1283        }
1284        catch (Exception e) {
1285            throw HibernateUtil.processException(e);
1286        }
1287        finally {
1288            closeSession(session);
1289        }
1290    }
1291
1292    public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
1293        int begin, int end) throws SystemException {
1294        Session session = null;
1295
1296        try {
1297            session = openSession();
1298
1299            DynamicQuery query = queryInitializer.initialize(session);
1300            query.setLimit(begin, end);
1301
1302            return query.list();
1303        }
1304        catch (Exception e) {
1305            throw HibernateUtil.processException(e);
1306        }
1307        finally {
1308            closeSession(session);
1309        }
1310    }
1311
1312    public List findAll() throws SystemException {
1313        return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1314    }
1315
1316    public List findAll(int begin, int end) throws SystemException {
1317        return findAll(begin, end, null);
1318    }
1319
1320    public List findAll(int begin, int end, OrderByComparator obc)
1321        throws SystemException {
1322        String finderClassName = BlogsEntry.class.getName();
1323        String finderMethodName = "findAll";
1324        String[] finderParams = new String[] {
1325                "java.lang.Integer", "java.lang.Integer",
1326                "com.liferay.portal.kernel.util.OrderByComparator"
1327            };
1328        Object[] finderArgs = new Object[] {
1329                String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
1330            };
1331        Object result = FinderCache.getResult(finderClassName,
1332                finderMethodName, finderParams, finderArgs, getSessionFactory());
1333
1334        if (result == null) {
1335            Session session = null;
1336
1337            try {
1338                session = openSession();
1339
1340                StringMaker query = new StringMaker();
1341                query.append("FROM com.liferay.portlet.blogs.model.BlogsEntry ");
1342
1343                if (obc != null) {
1344                    query.append("ORDER BY ");
1345                    query.append(obc.getOrderBy());
1346                }
1347                else {
1348                    query.append("ORDER BY ");
1349                    query.append("displayDate DESC");
1350                }
1351
1352                Query q = session.createQuery(query.toString());
1353                List list = QueryUtil.list(q, getDialect(), begin, end);
1354
1355                if (obc == null) {
1356                    Collections.sort(list);
1357                }
1358
1359                FinderCache.putResult(finderClassName, finderMethodName,
1360                    finderParams, finderArgs, list);
1361
1362                return list;
1363            }
1364            catch (Exception e) {
1365                throw HibernateUtil.processException(e);
1366            }
1367            finally {
1368                closeSession(session);
1369            }
1370        }
1371        else {
1372            return (List)result;
1373        }
1374    }
1375
1376    public void removeByGroupId(long groupId) throws SystemException {
1377        Iterator itr = findByGroupId(groupId).iterator();
1378
1379        while (itr.hasNext()) {
1380            BlogsEntry blogsEntry = (BlogsEntry)itr.next();
1381            remove(blogsEntry);
1382        }
1383    }
1384
1385    public void removeByCompanyId(long companyId) throws SystemException {
1386        Iterator itr = findByCompanyId(companyId).iterator();
1387
1388        while (itr.hasNext()) {
1389            BlogsEntry blogsEntry = (BlogsEntry)itr.next();
1390            remove(blogsEntry);
1391        }
1392    }
1393
1394    public void removeByCategoryId(long categoryId) throws SystemException {
1395        Iterator itr = findByCategoryId(categoryId).iterator();
1396
1397        while (itr.hasNext()) {
1398            BlogsEntry blogsEntry = (BlogsEntry)itr.next();
1399            remove(blogsEntry);
1400        }
1401    }
1402
1403    public void removeByG_U(long groupId, long userId)
1404        throws SystemException {
1405        Iterator itr = findByG_U(groupId, userId).iterator();
1406
1407        while (itr.hasNext()) {
1408            BlogsEntry blogsEntry = (BlogsEntry)itr.next();
1409            remove(blogsEntry);
1410        }
1411    }
1412
1413    public void removeByG_UT(long groupId, String urlTitle)
1414        throws NoSuchEntryException, SystemException {
1415        BlogsEntry blogsEntry = findByG_UT(groupId, urlTitle);
1416        remove(blogsEntry);
1417    }
1418
1419    public void removeByC_U(long companyId, long userId)
1420        throws SystemException {
1421        Iterator itr = findByC_U(companyId, userId).iterator();
1422
1423        while (itr.hasNext()) {
1424            BlogsEntry blogsEntry = (BlogsEntry)itr.next();
1425            remove(blogsEntry);
1426        }
1427    }
1428
1429    public void removeAll() throws SystemException {
1430        Iterator itr = findAll().iterator();
1431
1432        while (itr.hasNext()) {
1433            remove((BlogsEntry)itr.next());
1434        }
1435    }
1436
1437    public int countByGroupId(long groupId) throws SystemException {
1438        String finderClassName = BlogsEntry.class.getName();
1439        String finderMethodName = "countByGroupId";
1440        String[] finderParams = new String[] { Long.class.getName() };
1441        Object[] finderArgs = new Object[] { new Long(groupId) };
1442        Object result = FinderCache.getResult(finderClassName,
1443                finderMethodName, finderParams, finderArgs, getSessionFactory());
1444
1445        if (result == null) {
1446            Session session = null;
1447
1448            try {
1449                session = openSession();
1450
1451                StringMaker query = new StringMaker();
1452                query.append("SELECT COUNT(*) ");
1453                query.append(
1454                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1455                query.append("groupId = ?");
1456                query.append(" ");
1457
1458                Query q = session.createQuery(query.toString());
1459                int queryPos = 0;
1460                q.setLong(queryPos++, groupId);
1461
1462                Long count = null;
1463                Iterator itr = q.list().iterator();
1464
1465                if (itr.hasNext()) {
1466                    count = (Long)itr.next();
1467                }
1468
1469                if (count == null) {
1470                    count = new Long(0);
1471                }
1472
1473                FinderCache.putResult(finderClassName, finderMethodName,
1474                    finderParams, finderArgs, count);
1475
1476                return count.intValue();
1477            }
1478            catch (Exception e) {
1479                throw HibernateUtil.processException(e);
1480            }
1481            finally {
1482                closeSession(session);
1483            }
1484        }
1485        else {
1486            return ((Long)result).intValue();
1487        }
1488    }
1489
1490    public int countByCompanyId(long companyId) throws SystemException {
1491        String finderClassName = BlogsEntry.class.getName();
1492        String finderMethodName = "countByCompanyId";
1493        String[] finderParams = new String[] { Long.class.getName() };
1494        Object[] finderArgs = new Object[] { new Long(companyId) };
1495        Object result = FinderCache.getResult(finderClassName,
1496                finderMethodName, finderParams, finderArgs, getSessionFactory());
1497
1498        if (result == null) {
1499            Session session = null;
1500
1501            try {
1502                session = openSession();
1503
1504                StringMaker query = new StringMaker();
1505                query.append("SELECT COUNT(*) ");
1506                query.append(
1507                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1508                query.append("companyId = ?");
1509                query.append(" ");
1510
1511                Query q = session.createQuery(query.toString());
1512                int queryPos = 0;
1513                q.setLong(queryPos++, companyId);
1514
1515                Long count = null;
1516                Iterator itr = q.list().iterator();
1517
1518                if (itr.hasNext()) {
1519                    count = (Long)itr.next();
1520                }
1521
1522                if (count == null) {
1523                    count = new Long(0);
1524                }
1525
1526                FinderCache.putResult(finderClassName, finderMethodName,
1527                    finderParams, finderArgs, count);
1528
1529                return count.intValue();
1530            }
1531            catch (Exception e) {
1532                throw HibernateUtil.processException(e);
1533            }
1534            finally {
1535                closeSession(session);
1536            }
1537        }
1538        else {
1539            return ((Long)result).intValue();
1540        }
1541    }
1542
1543    public int countByCategoryId(long categoryId) throws SystemException {
1544        String finderClassName = BlogsEntry.class.getName();
1545        String finderMethodName = "countByCategoryId";
1546        String[] finderParams = new String[] { Long.class.getName() };
1547        Object[] finderArgs = new Object[] { new Long(categoryId) };
1548        Object result = FinderCache.getResult(finderClassName,
1549                finderMethodName, finderParams, finderArgs, getSessionFactory());
1550
1551        if (result == null) {
1552            Session session = null;
1553
1554            try {
1555                session = openSession();
1556
1557                StringMaker query = new StringMaker();
1558                query.append("SELECT COUNT(*) ");
1559                query.append(
1560                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1561                query.append("categoryId = ?");
1562                query.append(" ");
1563
1564                Query q = session.createQuery(query.toString());
1565                int queryPos = 0;
1566                q.setLong(queryPos++, categoryId);
1567
1568                Long count = null;
1569                Iterator itr = q.list().iterator();
1570
1571                if (itr.hasNext()) {
1572                    count = (Long)itr.next();
1573                }
1574
1575                if (count == null) {
1576                    count = new Long(0);
1577                }
1578
1579                FinderCache.putResult(finderClassName, finderMethodName,
1580                    finderParams, finderArgs, count);
1581
1582                return count.intValue();
1583            }
1584            catch (Exception e) {
1585                throw HibernateUtil.processException(e);
1586            }
1587            finally {
1588                closeSession(session);
1589            }
1590        }
1591        else {
1592            return ((Long)result).intValue();
1593        }
1594    }
1595
1596    public int countByG_U(long groupId, long userId) throws SystemException {
1597        String finderClassName = BlogsEntry.class.getName();
1598        String finderMethodName = "countByG_U";
1599        String[] finderParams = new String[] {
1600                Long.class.getName(), Long.class.getName()
1601            };
1602        Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1603        Object result = FinderCache.getResult(finderClassName,
1604                finderMethodName, finderParams, finderArgs, getSessionFactory());
1605
1606        if (result == null) {
1607            Session session = null;
1608
1609            try {
1610                session = openSession();
1611
1612                StringMaker query = new StringMaker();
1613                query.append("SELECT COUNT(*) ");
1614                query.append(
1615                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1616                query.append("groupId = ?");
1617                query.append(" AND ");
1618                query.append("userId = ?");
1619                query.append(" ");
1620
1621                Query q = session.createQuery(query.toString());
1622                int queryPos = 0;
1623                q.setLong(queryPos++, groupId);
1624                q.setLong(queryPos++, userId);
1625
1626                Long count = null;
1627                Iterator itr = q.list().iterator();
1628
1629                if (itr.hasNext()) {
1630                    count = (Long)itr.next();
1631                }
1632
1633                if (count == null) {
1634                    count = new Long(0);
1635                }
1636
1637                FinderCache.putResult(finderClassName, finderMethodName,
1638                    finderParams, finderArgs, count);
1639
1640                return count.intValue();
1641            }
1642            catch (Exception e) {
1643                throw HibernateUtil.processException(e);
1644            }
1645            finally {
1646                closeSession(session);
1647            }
1648        }
1649        else {
1650            return ((Long)result).intValue();
1651        }
1652    }
1653
1654    public int countByG_UT(long groupId, String urlTitle)
1655        throws SystemException {
1656        String finderClassName = BlogsEntry.class.getName();
1657        String finderMethodName = "countByG_UT";
1658        String[] finderParams = new String[] {
1659                Long.class.getName(), String.class.getName()
1660            };
1661        Object[] finderArgs = new Object[] { new Long(groupId), urlTitle };
1662        Object result = FinderCache.getResult(finderClassName,
1663                finderMethodName, finderParams, finderArgs, getSessionFactory());
1664
1665        if (result == null) {
1666            Session session = null;
1667
1668            try {
1669                session = openSession();
1670
1671                StringMaker query = new StringMaker();
1672                query.append("SELECT COUNT(*) ");
1673                query.append(
1674                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1675                query.append("groupId = ?");
1676                query.append(" AND ");
1677
1678                if (urlTitle == null) {
1679                    query.append("urlTitle IS NULL");
1680                }
1681                else {
1682                    query.append("urlTitle = ?");
1683                }
1684
1685                query.append(" ");
1686
1687                Query q = session.createQuery(query.toString());
1688                int queryPos = 0;
1689                q.setLong(queryPos++, groupId);
1690
1691                if (urlTitle != null) {
1692                    q.setString(queryPos++, urlTitle);
1693                }
1694
1695                Long count = null;
1696                Iterator itr = q.list().iterator();
1697
1698                if (itr.hasNext()) {
1699                    count = (Long)itr.next();
1700                }
1701
1702                if (count == null) {
1703                    count = new Long(0);
1704                }
1705
1706                FinderCache.putResult(finderClassName, finderMethodName,
1707                    finderParams, finderArgs, count);
1708
1709                return count.intValue();
1710            }
1711            catch (Exception e) {
1712                throw HibernateUtil.processException(e);
1713            }
1714            finally {
1715                closeSession(session);
1716            }
1717        }
1718        else {
1719            return ((Long)result).intValue();
1720        }
1721    }
1722
1723    public int countByC_U(long companyId, long userId)
1724        throws SystemException {
1725        String finderClassName = BlogsEntry.class.getName();
1726        String finderMethodName = "countByC_U";
1727        String[] finderParams = new String[] {
1728                Long.class.getName(), Long.class.getName()
1729            };
1730        Object[] finderArgs = new Object[] { new Long(companyId), new Long(userId) };
1731        Object result = FinderCache.getResult(finderClassName,
1732                finderMethodName, finderParams, finderArgs, getSessionFactory());
1733
1734        if (result == null) {
1735            Session session = null;
1736
1737            try {
1738                session = openSession();
1739
1740                StringMaker query = new StringMaker();
1741                query.append("SELECT COUNT(*) ");
1742                query.append(
1743                    "FROM com.liferay.portlet.blogs.model.BlogsEntry WHERE ");
1744                query.append("companyId = ?");
1745                query.append(" AND ");
1746                query.append("userId = ?");
1747                query.append(" ");
1748
1749                Query q = session.createQuery(query.toString());
1750                int queryPos = 0;
1751                q.setLong(queryPos++, companyId);
1752                q.setLong(queryPos++, userId);
1753
1754                Long count = null;
1755                Iterator itr = q.list().iterator();
1756
1757                if (itr.hasNext()) {
1758                    count = (Long)itr.next();
1759                }
1760
1761                if (count == null) {
1762                    count = new Long(0);
1763                }
1764
1765                FinderCache.putResult(finderClassName, finderMethodName,
1766                    finderParams, finderArgs, count);
1767
1768                return count.intValue();
1769            }
1770            catch (Exception e) {
1771                throw HibernateUtil.processException(e);
1772            }
1773            finally {
1774                closeSession(session);
1775            }
1776        }
1777        else {
1778            return ((Long)result).intValue();
1779        }
1780    }
1781
1782    public int countAll() throws SystemException {
1783        String finderClassName = BlogsEntry.class.getName();
1784        String finderMethodName = "countAll";
1785        String[] finderParams = new String[] {  };
1786        Object[] finderArgs = new Object[] {  };
1787        Object result = FinderCache.getResult(finderClassName,
1788                finderMethodName, finderParams, finderArgs, getSessionFactory());
1789
1790        if (result == null) {
1791            Session session = null;
1792
1793            try {
1794                session = openSession();
1795
1796                StringMaker query = new StringMaker();
1797                query.append("SELECT COUNT(*) ");
1798                query.append("FROM com.liferay.portlet.blogs.model.BlogsEntry");
1799
1800                Query q = session.createQuery(query.toString());
1801                Long count = null;
1802                Iterator itr = q.list().iterator();
1803
1804                if (itr.hasNext()) {
1805                    count = (Long)itr.next();
1806                }
1807
1808                if (count == null) {
1809                    count = new Long(0);
1810                }
1811
1812                FinderCache.putResult(finderClassName, finderMethodName,
1813                    finderParams, finderArgs, count);
1814
1815                return count.intValue();
1816            }
1817            catch (Exception e) {
1818                throw HibernateUtil.processException(e);
1819            }
1820            finally {
1821                closeSession(session);
1822            }
1823        }
1824        else {
1825            return ((Long)result).intValue();
1826        }
1827    }
1828
1829    protected void initDao() {
1830    }
1831
1832    private static Log _log = LogFactory.getLog(BlogsEntryPersistenceImpl.class);
1833}