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