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