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