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