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