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