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