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