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.BatchSessionUtil;
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 {
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             if (BatchSessionUtil.isEnabled()) {
136                 Object staleObject = session.get(MBCategoryImpl.class,
137                         mbCategory.getPrimaryKeyObj());
138 
139                 if (staleObject != null) {
140                     session.evict(staleObject);
141                 }
142             }
143 
144             session.delete(mbCategory);
145 
146             session.flush();
147 
148             return mbCategory;
149         }
150         catch (Exception e) {
151             throw processException(e);
152         }
153         finally {
154             closeSession(session);
155 
156             FinderCacheUtil.clearCache(MBCategory.class.getName());
157         }
158     }
159 
160     /**
161      * @deprecated Use <code>update(MBCategory mbCategory, boolean merge)</code>.
162      */
163     public MBCategory update(MBCategory mbCategory) throws SystemException {
164         if (_log.isWarnEnabled()) {
165             _log.warn(
166                 "Using the deprecated update(MBCategory mbCategory) method. Use update(MBCategory mbCategory, boolean merge) instead.");
167         }
168 
169         return update(mbCategory, false);
170     }
171 
172     /**
173      * Add, update, or merge, the entity. This method also calls the model
174      * listeners to trigger the proper events associated with adding, deleting,
175      * or updating an entity.
176      *
177      * @param        mbCategory the entity to add, update, or merge
178      * @param        merge boolean value for whether to merge the entity. The
179      *                default value is false. Setting merge to true is more
180      *                expensive and should only be true when mbCategory is
181      *                transient. See LEP-5473 for a detailed discussion of this
182      *                method.
183      * @return        true if the portlet can be displayed via Ajax
184      */
185     public MBCategory update(MBCategory mbCategory, boolean merge)
186         throws SystemException {
187         boolean isNew = mbCategory.isNew();
188 
189         if (_listeners.length > 0) {
190             for (ModelListener listener : _listeners) {
191                 if (isNew) {
192                     listener.onBeforeCreate(mbCategory);
193                 }
194                 else {
195                     listener.onBeforeUpdate(mbCategory);
196                 }
197             }
198         }
199 
200         mbCategory = updateImpl(mbCategory, merge);
201 
202         if (_listeners.length > 0) {
203             for (ModelListener listener : _listeners) {
204                 if (isNew) {
205                     listener.onAfterCreate(mbCategory);
206                 }
207                 else {
208                     listener.onAfterUpdate(mbCategory);
209                 }
210             }
211         }
212 
213         return mbCategory;
214     }
215 
216     public MBCategory updateImpl(
217         com.liferay.portlet.messageboards.model.MBCategory mbCategory,
218         boolean merge) throws SystemException {
219         if (Validator.isNull(mbCategory.getUuid())) {
220             String uuid = PortalUUIDUtil.generate();
221 
222             mbCategory.setUuid(uuid);
223         }
224 
225         Session session = null;
226 
227         try {
228             session = openSession();
229 
230             BatchSessionUtil.update(session, mbCategory, merge);
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 = null;
1514
1515                if (obc == null) {
1516                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1517                            start, end, false);
1518
1519                    Collections.sort(list);
1520                }
1521                else {
1522                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1523                            start, end);
1524                }
1525
1526                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1527                    finderClassName, finderMethodName, finderParams,
1528                    finderArgs, list);
1529
1530                return list;
1531            }
1532            catch (Exception e) {
1533                throw processException(e);
1534            }
1535            finally {
1536                closeSession(session);
1537            }
1538        }
1539        else {
1540            return (List<MBCategory>)result;
1541        }
1542    }
1543
1544    public void removeByUuid(String uuid) throws SystemException {
1545        for (MBCategory mbCategory : findByUuid(uuid)) {
1546            remove(mbCategory);
1547        }
1548    }
1549
1550    public void removeByUUID_G(String uuid, long groupId)
1551        throws NoSuchCategoryException, SystemException {
1552        MBCategory mbCategory = findByUUID_G(uuid, groupId);
1553
1554        remove(mbCategory);
1555    }
1556
1557    public void removeByGroupId(long groupId) throws SystemException {
1558        for (MBCategory mbCategory : findByGroupId(groupId)) {
1559            remove(mbCategory);
1560        }
1561    }
1562
1563    public void removeByCompanyId(long companyId) throws SystemException {
1564        for (MBCategory mbCategory : findByCompanyId(companyId)) {
1565            remove(mbCategory);
1566        }
1567    }
1568
1569    public void removeByG_P(long groupId, long parentCategoryId)
1570        throws SystemException {
1571        for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
1572            remove(mbCategory);
1573        }
1574    }
1575
1576    public void removeAll() throws SystemException {
1577        for (MBCategory mbCategory : findAll()) {
1578            remove(mbCategory);
1579        }
1580    }
1581
1582    public int countByUuid(String uuid) throws SystemException {
1583        boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1584        String finderClassName = MBCategory.class.getName();
1585        String finderMethodName = "countByUuid";
1586        String[] finderParams = new String[] { String.class.getName() };
1587        Object[] finderArgs = new Object[] { uuid };
1588
1589        Object result = null;
1590
1591        if (finderClassNameCacheEnabled) {
1592            result = FinderCacheUtil.getResult(finderClassName,
1593                    finderMethodName, finderParams, finderArgs, this);
1594        }
1595
1596        if (result == null) {
1597            Session session = null;
1598
1599            try {
1600                session = openSession();
1601
1602                StringBuilder query = new StringBuilder();
1603
1604                query.append("SELECT COUNT(*) ");
1605                query.append(
1606                    "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1607
1608                if (uuid == null) {
1609                    query.append("uuid_ IS NULL");
1610                }
1611                else {
1612                    query.append("uuid_ = ?");
1613                }
1614
1615                query.append(" ");
1616
1617                Query q = session.createQuery(query.toString());
1618
1619                QueryPos qPos = QueryPos.getInstance(q);
1620
1621                if (uuid != null) {
1622                    qPos.add(uuid);
1623                }
1624
1625                Long count = null;
1626
1627                Iterator<Long> itr = q.list().iterator();
1628
1629                if (itr.hasNext()) {
1630                    count = itr.next();
1631                }
1632
1633                if (count == null) {
1634                    count = new Long(0);
1635                }
1636
1637                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1638                    finderClassName, finderMethodName, finderParams,
1639                    finderArgs, count);
1640
1641                return count.intValue();
1642            }
1643            catch (Exception e) {
1644                throw processException(e);
1645            }
1646            finally {
1647                closeSession(session);
1648            }
1649        }
1650        else {
1651            return ((Long)result).intValue();
1652        }
1653    }
1654
1655    public int countByUUID_G(String uuid, long groupId)
1656        throws SystemException {
1657        boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1658        String finderClassName = MBCategory.class.getName();
1659        String finderMethodName = "countByUUID_G";
1660        String[] finderParams = new String[] {
1661                String.class.getName(), Long.class.getName()
1662            };
1663        Object[] finderArgs = new Object[] { uuid, new Long(groupId) };
1664
1665        Object result = null;
1666
1667        if (finderClassNameCacheEnabled) {
1668            result = FinderCacheUtil.getResult(finderClassName,
1669                    finderMethodName, finderParams, finderArgs, this);
1670        }
1671
1672        if (result == null) {
1673            Session session = null;
1674
1675            try {
1676                session = openSession();
1677
1678                StringBuilder query = new StringBuilder();
1679
1680                query.append("SELECT COUNT(*) ");
1681                query.append(
1682                    "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1683
1684                if (uuid == null) {
1685                    query.append("uuid_ IS NULL");
1686                }
1687                else {
1688                    query.append("uuid_ = ?");
1689                }
1690
1691                query.append(" AND ");
1692
1693                query.append("groupId = ?");
1694
1695                query.append(" ");
1696
1697                Query q = session.createQuery(query.toString());
1698
1699                QueryPos qPos = QueryPos.getInstance(q);
1700
1701                if (uuid != null) {
1702                    qPos.add(uuid);
1703                }
1704
1705                qPos.add(groupId);
1706
1707                Long count = null;
1708
1709                Iterator<Long> itr = q.list().iterator();
1710
1711                if (itr.hasNext()) {
1712                    count = itr.next();
1713                }
1714
1715                if (count == null) {
1716                    count = new Long(0);
1717                }
1718
1719                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1720                    finderClassName, finderMethodName, finderParams,
1721                    finderArgs, count);
1722
1723                return count.intValue();
1724            }
1725            catch (Exception e) {
1726                throw processException(e);
1727            }
1728            finally {
1729                closeSession(session);
1730            }
1731        }
1732        else {
1733            return ((Long)result).intValue();
1734        }
1735    }
1736
1737    public int countByGroupId(long groupId) throws SystemException {
1738        boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1739        String finderClassName = MBCategory.class.getName();
1740        String finderMethodName = "countByGroupId";
1741        String[] finderParams = new String[] { Long.class.getName() };
1742        Object[] finderArgs = new Object[] { new Long(groupId) };
1743
1744        Object result = null;
1745
1746        if (finderClassNameCacheEnabled) {
1747            result = FinderCacheUtil.getResult(finderClassName,
1748                    finderMethodName, finderParams, finderArgs, this);
1749        }
1750
1751        if (result == null) {
1752            Session session = null;
1753
1754            try {
1755                session = openSession();
1756
1757                StringBuilder query = new StringBuilder();
1758
1759                query.append("SELECT COUNT(*) ");
1760                query.append(
1761                    "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1762
1763                query.append("groupId = ?");
1764
1765                query.append(" ");
1766
1767                Query q = session.createQuery(query.toString());
1768
1769                QueryPos qPos = QueryPos.getInstance(q);
1770
1771                qPos.add(groupId);
1772
1773                Long count = null;
1774
1775                Iterator<Long> itr = q.list().iterator();
1776
1777                if (itr.hasNext()) {
1778                    count = itr.next();
1779                }
1780
1781                if (count == null) {
1782                    count = new Long(0);
1783                }
1784
1785                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1786                    finderClassName, finderMethodName, finderParams,
1787                    finderArgs, count);
1788
1789                return count.intValue();
1790            }
1791            catch (Exception e) {
1792                throw processException(e);
1793            }
1794            finally {
1795                closeSession(session);
1796            }
1797        }
1798        else {
1799            return ((Long)result).intValue();
1800        }
1801    }
1802
1803    public int countByCompanyId(long companyId) throws SystemException {
1804        boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1805        String finderClassName = MBCategory.class.getName();
1806        String finderMethodName = "countByCompanyId";
1807        String[] finderParams = new String[] { Long.class.getName() };
1808        Object[] finderArgs = new Object[] { new Long(companyId) };
1809
1810        Object result = null;
1811
1812        if (finderClassNameCacheEnabled) {
1813            result = FinderCacheUtil.getResult(finderClassName,
1814                    finderMethodName, finderParams, finderArgs, this);
1815        }
1816
1817        if (result == null) {
1818            Session session = null;
1819
1820            try {
1821                session = openSession();
1822
1823                StringBuilder query = new StringBuilder();
1824
1825                query.append("SELECT COUNT(*) ");
1826                query.append(
1827                    "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1828
1829                query.append("companyId = ?");
1830
1831                query.append(" ");
1832
1833                Query q = session.createQuery(query.toString());
1834
1835                QueryPos qPos = QueryPos.getInstance(q);
1836
1837                qPos.add(companyId);
1838
1839                Long count = null;
1840
1841                Iterator<Long> itr = q.list().iterator();
1842
1843                if (itr.hasNext()) {
1844                    count = itr.next();
1845                }
1846
1847                if (count == null) {
1848                    count = new Long(0);
1849                }
1850
1851                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1852                    finderClassName, finderMethodName, finderParams,
1853                    finderArgs, count);
1854
1855                return count.intValue();
1856            }
1857            catch (Exception e) {
1858                throw processException(e);
1859            }
1860            finally {
1861                closeSession(session);
1862            }
1863        }
1864        else {
1865            return ((Long)result).intValue();
1866        }
1867    }
1868
1869    public int countByG_P(long groupId, long parentCategoryId)
1870        throws SystemException {
1871        boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1872        String finderClassName = MBCategory.class.getName();
1873        String finderMethodName = "countByG_P";
1874        String[] finderParams = new String[] {
1875                Long.class.getName(), Long.class.getName()
1876            };
1877        Object[] finderArgs = new Object[] {
1878                new Long(groupId), new Long(parentCategoryId)
1879            };
1880
1881        Object result = null;
1882
1883        if (finderClassNameCacheEnabled) {
1884            result = FinderCacheUtil.getResult(finderClassName,
1885                    finderMethodName, finderParams, finderArgs, this);
1886        }
1887
1888        if (result == null) {
1889            Session session = null;
1890
1891            try {
1892                session = openSession();
1893
1894                StringBuilder query = new StringBuilder();
1895
1896                query.append("SELECT COUNT(*) ");
1897                query.append(
1898                    "FROM com.liferay.portlet.messageboards.model.MBCategory WHERE ");
1899
1900                query.append("groupId = ?");
1901
1902                query.append(" AND ");
1903
1904                query.append("parentCategoryId = ?");
1905
1906                query.append(" ");
1907
1908                Query q = session.createQuery(query.toString());
1909
1910                QueryPos qPos = QueryPos.getInstance(q);
1911
1912                qPos.add(groupId);
1913
1914                qPos.add(parentCategoryId);
1915
1916                Long count = null;
1917
1918                Iterator<Long> itr = q.list().iterator();
1919
1920                if (itr.hasNext()) {
1921                    count = itr.next();
1922                }
1923
1924                if (count == null) {
1925                    count = new Long(0);
1926                }
1927
1928                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1929                    finderClassName, finderMethodName, finderParams,
1930                    finderArgs, count);
1931
1932                return count.intValue();
1933            }
1934            catch (Exception e) {
1935                throw processException(e);
1936            }
1937            finally {
1938                closeSession(session);
1939            }
1940        }
1941        else {
1942            return ((Long)result).intValue();
1943        }
1944    }
1945
1946    public int countAll() throws SystemException {
1947        boolean finderClassNameCacheEnabled = MBCategoryModelImpl.CACHE_ENABLED;
1948        String finderClassName = MBCategory.class.getName();
1949        String finderMethodName = "countAll";
1950        String[] finderParams = new String[] {  };
1951        Object[] finderArgs = new Object[] {  };
1952
1953        Object result = null;
1954
1955        if (finderClassNameCacheEnabled) {
1956            result = FinderCacheUtil.getResult(finderClassName,
1957                    finderMethodName, finderParams, finderArgs, this);
1958        }
1959
1960        if (result == null) {
1961            Session session = null;
1962
1963            try {
1964                session = openSession();
1965
1966                Query q = session.createQuery(
1967                        "SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBCategory");
1968
1969                Long count = null;
1970
1971                Iterator<Long> itr = q.list().iterator();
1972
1973                if (itr.hasNext()) {
1974                    count = itr.next();
1975                }
1976
1977                if (count == null) {
1978                    count = new Long(0);
1979                }
1980
1981                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1982                    finderClassName, finderMethodName, finderParams,
1983                    finderArgs, count);
1984
1985                return count.intValue();
1986            }
1987            catch (Exception e) {
1988                throw processException(e);
1989            }
1990            finally {
1991                closeSession(session);
1992            }
1993        }
1994        else {
1995            return ((Long)result).intValue();
1996        }
1997    }
1998
1999    public void registerListener(ModelListener listener) {
2000        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2001
2002        listeners.add(listener);
2003
2004        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2005    }
2006
2007    public void unregisterListener(ModelListener listener) {
2008        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
2009
2010        listeners.remove(listener);
2011
2012        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2013    }
2014
2015    public void afterPropertiesSet() {
2016        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2017                    com.liferay.portal.util.PropsUtil.get(
2018                        "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
2019
2020        if (listenerClassNames.length > 0) {
2021            try {
2022                List<ModelListener> listeners = new ArrayList<ModelListener>();
2023
2024                for (String listenerClassName : listenerClassNames) {
2025                    listeners.add((ModelListener)Class.forName(
2026                            listenerClassName).newInstance());
2027                }
2028
2029                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
2030            }
2031            catch (Exception e) {
2032                _log.error(e);
2033            }
2034        }
2035    }
2036
2037    private static Log _log = LogFactory.getLog(MBCategoryPersistenceImpl.class);
2038    private ModelListener[] _listeners = new ModelListener[0];
2039}