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