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