001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.ArrayUtil;
032 import com.liferay.portal.kernel.util.GetterUtil;
033 import com.liferay.portal.kernel.util.InstanceFactory;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.StringBundler;
036 import com.liferay.portal.kernel.util.StringPool;
037 import com.liferay.portal.kernel.util.StringUtil;
038 import com.liferay.portal.kernel.util.Validator;
039 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040 import com.liferay.portal.model.CacheModel;
041 import com.liferay.portal.model.ModelListener;
042 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043 import com.liferay.portal.service.persistence.BatchSessionUtil;
044 import com.liferay.portal.service.persistence.GroupPersistence;
045 import com.liferay.portal.service.persistence.ResourcePersistence;
046 import com.liferay.portal.service.persistence.SubscriptionPersistence;
047 import com.liferay.portal.service.persistence.UserPersistence;
048 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049
050 import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
051 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
052 import com.liferay.portlet.messageboards.NoSuchCategoryException;
053 import com.liferay.portlet.messageboards.model.MBCategory;
054 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
055 import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
056
057 import java.io.Serializable;
058
059 import java.util.ArrayList;
060 import java.util.Collections;
061 import java.util.List;
062
063
075 public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
076 implements MBCategoryPersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
088 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090 new String[] {
091 String.class.getName(),
092
093 "java.lang.Integer", "java.lang.Integer",
094 "com.liferay.portal.kernel.util.OrderByComparator"
095 });
096 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
097 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
098 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099 new String[] { String.class.getName() },
100 MBCategoryModelImpl.UUID_COLUMN_BITMASK);
101 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
102 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
103 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104 new String[] { String.class.getName() });
105 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
106 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
107 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
108 new String[] { String.class.getName(), Long.class.getName() },
109 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
110 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
112 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
114 new String[] { String.class.getName(), Long.class.getName() });
115 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
116 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
117 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
118 new String[] {
119 Long.class.getName(),
120
121 "java.lang.Integer", "java.lang.Integer",
122 "com.liferay.portal.kernel.util.OrderByComparator"
123 });
124 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
125 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
126 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
127 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
128 new String[] { Long.class.getName() },
129 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
130 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
131 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
132 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
133 new String[] { Long.class.getName() });
134 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
135 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
136 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
137 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
138 new String[] {
139 Long.class.getName(),
140
141 "java.lang.Integer", "java.lang.Integer",
142 "com.liferay.portal.kernel.util.OrderByComparator"
143 });
144 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
145 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
146 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
147 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
148 new String[] { Long.class.getName() },
149 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK);
150 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
151 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
152 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
153 new String[] { Long.class.getName() });
154 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
155 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
156 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
157 new String[] {
158 Long.class.getName(), Long.class.getName(),
159
160 "java.lang.Integer", "java.lang.Integer",
161 "com.liferay.portal.kernel.util.OrderByComparator"
162 });
163 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
164 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
165 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
166 new String[] { Long.class.getName(), Long.class.getName() },
167 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
168 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK);
169 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
170 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
171 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
172 new String[] { Long.class.getName(), Long.class.getName() });
173 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
174 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
175 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
176 new String[] { Long.class.getName(), Long.class.getName() });
177 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
178 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
179 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
180 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
181 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
182 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
183 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
184 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
185 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
186
187
192 public void cacheResult(MBCategory mbCategory) {
193 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
194 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
195
196 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
197 new Object[] {
198 mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
199 }, mbCategory);
200
201 mbCategory.resetOriginalValues();
202 }
203
204
209 public void cacheResult(List<MBCategory> mbCategories) {
210 for (MBCategory mbCategory : mbCategories) {
211 if (EntityCacheUtil.getResult(
212 MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
213 MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
214 cacheResult(mbCategory);
215 }
216 else {
217 mbCategory.resetOriginalValues();
218 }
219 }
220 }
221
222
229 @Override
230 public void clearCache() {
231 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
232 CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
233 }
234
235 EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
236
237 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
238 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
239 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
240 }
241
242
249 @Override
250 public void clearCache(MBCategory mbCategory) {
251 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
252 MBCategoryImpl.class, mbCategory.getPrimaryKey());
253
254 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
255 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
256
257 clearUniqueFindersCache(mbCategory);
258 }
259
260 @Override
261 public void clearCache(List<MBCategory> mbCategories) {
262 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
263 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
264
265 for (MBCategory mbCategory : mbCategories) {
266 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
267 MBCategoryImpl.class, mbCategory.getPrimaryKey());
268
269 clearUniqueFindersCache(mbCategory);
270 }
271 }
272
273 protected void clearUniqueFindersCache(MBCategory mbCategory) {
274 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
275 new Object[] {
276 mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
277 });
278 }
279
280
286 public MBCategory create(long categoryId) {
287 MBCategory mbCategory = new MBCategoryImpl();
288
289 mbCategory.setNew(true);
290 mbCategory.setPrimaryKey(categoryId);
291
292 String uuid = PortalUUIDUtil.generate();
293
294 mbCategory.setUuid(uuid);
295
296 return mbCategory;
297 }
298
299
307 public MBCategory remove(long categoryId)
308 throws NoSuchCategoryException, SystemException {
309 return remove(Long.valueOf(categoryId));
310 }
311
312
320 @Override
321 public MBCategory remove(Serializable primaryKey)
322 throws NoSuchCategoryException, SystemException {
323 Session session = null;
324
325 try {
326 session = openSession();
327
328 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
329 primaryKey);
330
331 if (mbCategory == null) {
332 if (_log.isWarnEnabled()) {
333 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
334 }
335
336 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
337 primaryKey);
338 }
339
340 return remove(mbCategory);
341 }
342 catch (NoSuchCategoryException nsee) {
343 throw nsee;
344 }
345 catch (Exception e) {
346 throw processException(e);
347 }
348 finally {
349 closeSession(session);
350 }
351 }
352
353 @Override
354 protected MBCategory removeImpl(MBCategory mbCategory)
355 throws SystemException {
356 mbCategory = toUnwrappedModel(mbCategory);
357
358 Session session = null;
359
360 try {
361 session = openSession();
362
363 BatchSessionUtil.delete(session, mbCategory);
364 }
365 catch (Exception e) {
366 throw processException(e);
367 }
368 finally {
369 closeSession(session);
370 }
371
372 clearCache(mbCategory);
373
374 return mbCategory;
375 }
376
377 @Override
378 public MBCategory updateImpl(
379 com.liferay.portlet.messageboards.model.MBCategory mbCategory,
380 boolean merge) throws SystemException {
381 mbCategory = toUnwrappedModel(mbCategory);
382
383 boolean isNew = mbCategory.isNew();
384
385 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
386
387 if (Validator.isNull(mbCategory.getUuid())) {
388 String uuid = PortalUUIDUtil.generate();
389
390 mbCategory.setUuid(uuid);
391 }
392
393 Session session = null;
394
395 try {
396 session = openSession();
397
398 BatchSessionUtil.update(session, mbCategory, merge);
399
400 mbCategory.setNew(false);
401 }
402 catch (Exception e) {
403 throw processException(e);
404 }
405 finally {
406 closeSession(session);
407 }
408
409 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
410
411 if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
412 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
413 }
414 else {
415 if ((mbCategoryModelImpl.getColumnBitmask() &
416 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
417 Object[] args = new Object[] {
418 mbCategoryModelImpl.getOriginalUuid()
419 };
420
421 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
422 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
423 args);
424
425 args = new Object[] { mbCategoryModelImpl.getUuid() };
426
427 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
428 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
429 args);
430 }
431
432 if ((mbCategoryModelImpl.getColumnBitmask() &
433 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
434 Object[] args = new Object[] {
435 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId())
436 };
437
438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
439 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
440 args);
441
442 args = new Object[] {
443 Long.valueOf(mbCategoryModelImpl.getGroupId())
444 };
445
446 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
447 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
448 args);
449 }
450
451 if ((mbCategoryModelImpl.getColumnBitmask() &
452 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
453 Object[] args = new Object[] {
454 Long.valueOf(mbCategoryModelImpl.getOriginalCompanyId())
455 };
456
457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
458 args);
459 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
460 args);
461
462 args = new Object[] {
463 Long.valueOf(mbCategoryModelImpl.getCompanyId())
464 };
465
466 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
467 args);
468 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
469 args);
470 }
471
472 if ((mbCategoryModelImpl.getColumnBitmask() &
473 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
474 Object[] args = new Object[] {
475 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId()),
476 Long.valueOf(mbCategoryModelImpl.getOriginalParentCategoryId())
477 };
478
479 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
480 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
481 args);
482
483 args = new Object[] {
484 Long.valueOf(mbCategoryModelImpl.getGroupId()),
485 Long.valueOf(mbCategoryModelImpl.getParentCategoryId())
486 };
487
488 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
489 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
490 args);
491 }
492 }
493
494 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
495 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
496
497 if (isNew) {
498 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
499 new Object[] {
500 mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
501 }, mbCategory);
502 }
503 else {
504 if ((mbCategoryModelImpl.getColumnBitmask() &
505 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
506 Object[] args = new Object[] {
507 mbCategoryModelImpl.getOriginalUuid(),
508 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId())
509 };
510
511 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
512 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
513
514 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
515 new Object[] {
516 mbCategory.getUuid(),
517 Long.valueOf(mbCategory.getGroupId())
518 }, mbCategory);
519 }
520 }
521
522 return mbCategory;
523 }
524
525 protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
526 if (mbCategory instanceof MBCategoryImpl) {
527 return mbCategory;
528 }
529
530 MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
531
532 mbCategoryImpl.setNew(mbCategory.isNew());
533 mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
534
535 mbCategoryImpl.setUuid(mbCategory.getUuid());
536 mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
537 mbCategoryImpl.setGroupId(mbCategory.getGroupId());
538 mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
539 mbCategoryImpl.setUserId(mbCategory.getUserId());
540 mbCategoryImpl.setUserName(mbCategory.getUserName());
541 mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
542 mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
543 mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
544 mbCategoryImpl.setName(mbCategory.getName());
545 mbCategoryImpl.setDescription(mbCategory.getDescription());
546 mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
547 mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
548 mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
549 mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
550
551 return mbCategoryImpl;
552 }
553
554
562 @Override
563 public MBCategory findByPrimaryKey(Serializable primaryKey)
564 throws NoSuchModelException, SystemException {
565 return findByPrimaryKey(((Long)primaryKey).longValue());
566 }
567
568
576 public MBCategory findByPrimaryKey(long categoryId)
577 throws NoSuchCategoryException, SystemException {
578 MBCategory mbCategory = fetchByPrimaryKey(categoryId);
579
580 if (mbCategory == null) {
581 if (_log.isWarnEnabled()) {
582 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
583 }
584
585 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
586 categoryId);
587 }
588
589 return mbCategory;
590 }
591
592
599 @Override
600 public MBCategory fetchByPrimaryKey(Serializable primaryKey)
601 throws SystemException {
602 return fetchByPrimaryKey(((Long)primaryKey).longValue());
603 }
604
605
612 public MBCategory fetchByPrimaryKey(long categoryId)
613 throws SystemException {
614 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
615 MBCategoryImpl.class, categoryId);
616
617 if (mbCategory == _nullMBCategory) {
618 return null;
619 }
620
621 if (mbCategory == null) {
622 Session session = null;
623
624 boolean hasException = false;
625
626 try {
627 session = openSession();
628
629 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
630 Long.valueOf(categoryId));
631 }
632 catch (Exception e) {
633 hasException = true;
634
635 throw processException(e);
636 }
637 finally {
638 if (mbCategory != null) {
639 cacheResult(mbCategory);
640 }
641 else if (!hasException) {
642 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
643 MBCategoryImpl.class, categoryId, _nullMBCategory);
644 }
645
646 closeSession(session);
647 }
648 }
649
650 return mbCategory;
651 }
652
653
660 public List<MBCategory> findByUuid(String uuid) throws SystemException {
661 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
662 }
663
664
677 public List<MBCategory> findByUuid(String uuid, int start, int end)
678 throws SystemException {
679 return findByUuid(uuid, start, end, null);
680 }
681
682
696 public List<MBCategory> findByUuid(String uuid, int start, int end,
697 OrderByComparator orderByComparator) throws SystemException {
698 FinderPath finderPath = null;
699 Object[] finderArgs = null;
700
701 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
702 (orderByComparator == null)) {
703 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
704 finderArgs = new Object[] { uuid };
705 }
706 else {
707 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
708 finderArgs = new Object[] { uuid, start, end, orderByComparator };
709 }
710
711 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
712 finderArgs, this);
713
714 if ((list != null) && !list.isEmpty()) {
715 for (MBCategory mbCategory : list) {
716 if (!Validator.equals(uuid, mbCategory.getUuid())) {
717 list = null;
718
719 break;
720 }
721 }
722 }
723
724 if (list == null) {
725 StringBundler query = null;
726
727 if (orderByComparator != null) {
728 query = new StringBundler(3 +
729 (orderByComparator.getOrderByFields().length * 3));
730 }
731 else {
732 query = new StringBundler(3);
733 }
734
735 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
736
737 if (uuid == null) {
738 query.append(_FINDER_COLUMN_UUID_UUID_1);
739 }
740 else {
741 if (uuid.equals(StringPool.BLANK)) {
742 query.append(_FINDER_COLUMN_UUID_UUID_3);
743 }
744 else {
745 query.append(_FINDER_COLUMN_UUID_UUID_2);
746 }
747 }
748
749 if (orderByComparator != null) {
750 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
751 orderByComparator);
752 }
753
754 else {
755 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
756 }
757
758 String sql = query.toString();
759
760 Session session = null;
761
762 try {
763 session = openSession();
764
765 Query q = session.createQuery(sql);
766
767 QueryPos qPos = QueryPos.getInstance(q);
768
769 if (uuid != null) {
770 qPos.add(uuid);
771 }
772
773 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
774 end);
775 }
776 catch (Exception e) {
777 throw processException(e);
778 }
779 finally {
780 if (list == null) {
781 FinderCacheUtil.removeResult(finderPath, finderArgs);
782 }
783 else {
784 cacheResult(list);
785
786 FinderCacheUtil.putResult(finderPath, finderArgs, list);
787 }
788
789 closeSession(session);
790 }
791 }
792
793 return list;
794 }
795
796
809 public MBCategory findByUuid_First(String uuid,
810 OrderByComparator orderByComparator)
811 throws NoSuchCategoryException, SystemException {
812 List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
813
814 if (list.isEmpty()) {
815 StringBundler msg = new StringBundler(4);
816
817 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
818
819 msg.append("uuid=");
820 msg.append(uuid);
821
822 msg.append(StringPool.CLOSE_CURLY_BRACE);
823
824 throw new NoSuchCategoryException(msg.toString());
825 }
826 else {
827 return list.get(0);
828 }
829 }
830
831
844 public MBCategory findByUuid_Last(String uuid,
845 OrderByComparator orderByComparator)
846 throws NoSuchCategoryException, SystemException {
847 int count = countByUuid(uuid);
848
849 List<MBCategory> list = findByUuid(uuid, count - 1, count,
850 orderByComparator);
851
852 if (list.isEmpty()) {
853 StringBundler msg = new StringBundler(4);
854
855 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
856
857 msg.append("uuid=");
858 msg.append(uuid);
859
860 msg.append(StringPool.CLOSE_CURLY_BRACE);
861
862 throw new NoSuchCategoryException(msg.toString());
863 }
864 else {
865 return list.get(0);
866 }
867 }
868
869
883 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
884 OrderByComparator orderByComparator)
885 throws NoSuchCategoryException, SystemException {
886 MBCategory mbCategory = findByPrimaryKey(categoryId);
887
888 Session session = null;
889
890 try {
891 session = openSession();
892
893 MBCategory[] array = new MBCategoryImpl[3];
894
895 array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
896 orderByComparator, true);
897
898 array[1] = mbCategory;
899
900 array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
901 orderByComparator, false);
902
903 return array;
904 }
905 catch (Exception e) {
906 throw processException(e);
907 }
908 finally {
909 closeSession(session);
910 }
911 }
912
913 protected MBCategory getByUuid_PrevAndNext(Session session,
914 MBCategory mbCategory, String uuid,
915 OrderByComparator orderByComparator, boolean previous) {
916 StringBundler query = null;
917
918 if (orderByComparator != null) {
919 query = new StringBundler(6 +
920 (orderByComparator.getOrderByFields().length * 6));
921 }
922 else {
923 query = new StringBundler(3);
924 }
925
926 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
927
928 if (uuid == null) {
929 query.append(_FINDER_COLUMN_UUID_UUID_1);
930 }
931 else {
932 if (uuid.equals(StringPool.BLANK)) {
933 query.append(_FINDER_COLUMN_UUID_UUID_3);
934 }
935 else {
936 query.append(_FINDER_COLUMN_UUID_UUID_2);
937 }
938 }
939
940 if (orderByComparator != null) {
941 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
942
943 if (orderByConditionFields.length > 0) {
944 query.append(WHERE_AND);
945 }
946
947 for (int i = 0; i < orderByConditionFields.length; i++) {
948 query.append(_ORDER_BY_ENTITY_ALIAS);
949 query.append(orderByConditionFields[i]);
950
951 if ((i + 1) < orderByConditionFields.length) {
952 if (orderByComparator.isAscending() ^ previous) {
953 query.append(WHERE_GREATER_THAN_HAS_NEXT);
954 }
955 else {
956 query.append(WHERE_LESSER_THAN_HAS_NEXT);
957 }
958 }
959 else {
960 if (orderByComparator.isAscending() ^ previous) {
961 query.append(WHERE_GREATER_THAN);
962 }
963 else {
964 query.append(WHERE_LESSER_THAN);
965 }
966 }
967 }
968
969 query.append(ORDER_BY_CLAUSE);
970
971 String[] orderByFields = orderByComparator.getOrderByFields();
972
973 for (int i = 0; i < orderByFields.length; i++) {
974 query.append(_ORDER_BY_ENTITY_ALIAS);
975 query.append(orderByFields[i]);
976
977 if ((i + 1) < orderByFields.length) {
978 if (orderByComparator.isAscending() ^ previous) {
979 query.append(ORDER_BY_ASC_HAS_NEXT);
980 }
981 else {
982 query.append(ORDER_BY_DESC_HAS_NEXT);
983 }
984 }
985 else {
986 if (orderByComparator.isAscending() ^ previous) {
987 query.append(ORDER_BY_ASC);
988 }
989 else {
990 query.append(ORDER_BY_DESC);
991 }
992 }
993 }
994 }
995
996 else {
997 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
998 }
999
1000 String sql = query.toString();
1001
1002 Query q = session.createQuery(sql);
1003
1004 q.setFirstResult(0);
1005 q.setMaxResults(2);
1006
1007 QueryPos qPos = QueryPos.getInstance(q);
1008
1009 if (uuid != null) {
1010 qPos.add(uuid);
1011 }
1012
1013 if (orderByComparator != null) {
1014 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1015
1016 for (Object value : values) {
1017 qPos.add(value);
1018 }
1019 }
1020
1021 List<MBCategory> list = q.list();
1022
1023 if (list.size() == 2) {
1024 return list.get(1);
1025 }
1026 else {
1027 return null;
1028 }
1029 }
1030
1031
1040 public MBCategory findByUUID_G(String uuid, long groupId)
1041 throws NoSuchCategoryException, SystemException {
1042 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
1043
1044 if (mbCategory == null) {
1045 StringBundler msg = new StringBundler(6);
1046
1047 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1048
1049 msg.append("uuid=");
1050 msg.append(uuid);
1051
1052 msg.append(", groupId=");
1053 msg.append(groupId);
1054
1055 msg.append(StringPool.CLOSE_CURLY_BRACE);
1056
1057 if (_log.isWarnEnabled()) {
1058 _log.warn(msg.toString());
1059 }
1060
1061 throw new NoSuchCategoryException(msg.toString());
1062 }
1063
1064 return mbCategory;
1065 }
1066
1067
1075 public MBCategory fetchByUUID_G(String uuid, long groupId)
1076 throws SystemException {
1077 return fetchByUUID_G(uuid, groupId, true);
1078 }
1079
1080
1089 public MBCategory fetchByUUID_G(String uuid, long groupId,
1090 boolean retrieveFromCache) throws SystemException {
1091 Object[] finderArgs = new Object[] { uuid, groupId };
1092
1093 Object result = null;
1094
1095 if (retrieveFromCache) {
1096 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1097 finderArgs, this);
1098 }
1099
1100 if (result instanceof MBCategory) {
1101 MBCategory mbCategory = (MBCategory)result;
1102
1103 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
1104 (groupId != mbCategory.getGroupId())) {
1105 result = null;
1106 }
1107 }
1108
1109 if (result == null) {
1110 StringBundler query = new StringBundler(4);
1111
1112 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1113
1114 if (uuid == null) {
1115 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1116 }
1117 else {
1118 if (uuid.equals(StringPool.BLANK)) {
1119 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1120 }
1121 else {
1122 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1123 }
1124 }
1125
1126 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1127
1128 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1129
1130 String sql = query.toString();
1131
1132 Session session = null;
1133
1134 try {
1135 session = openSession();
1136
1137 Query q = session.createQuery(sql);
1138
1139 QueryPos qPos = QueryPos.getInstance(q);
1140
1141 if (uuid != null) {
1142 qPos.add(uuid);
1143 }
1144
1145 qPos.add(groupId);
1146
1147 List<MBCategory> list = q.list();
1148
1149 result = list;
1150
1151 MBCategory mbCategory = null;
1152
1153 if (list.isEmpty()) {
1154 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1155 finderArgs, list);
1156 }
1157 else {
1158 mbCategory = list.get(0);
1159
1160 cacheResult(mbCategory);
1161
1162 if ((mbCategory.getUuid() == null) ||
1163 !mbCategory.getUuid().equals(uuid) ||
1164 (mbCategory.getGroupId() != groupId)) {
1165 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1166 finderArgs, mbCategory);
1167 }
1168 }
1169
1170 return mbCategory;
1171 }
1172 catch (Exception e) {
1173 throw processException(e);
1174 }
1175 finally {
1176 if (result == null) {
1177 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1178 finderArgs);
1179 }
1180
1181 closeSession(session);
1182 }
1183 }
1184 else {
1185 if (result instanceof List<?>) {
1186 return null;
1187 }
1188 else {
1189 return (MBCategory)result;
1190 }
1191 }
1192 }
1193
1194
1201 public List<MBCategory> findByGroupId(long groupId)
1202 throws SystemException {
1203 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1204 }
1205
1206
1219 public List<MBCategory> findByGroupId(long groupId, int start, int end)
1220 throws SystemException {
1221 return findByGroupId(groupId, start, end, null);
1222 }
1223
1224
1238 public List<MBCategory> findByGroupId(long groupId, int start, int end,
1239 OrderByComparator orderByComparator) throws SystemException {
1240 FinderPath finderPath = null;
1241 Object[] finderArgs = null;
1242
1243 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1244 (orderByComparator == null)) {
1245 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1246 finderArgs = new Object[] { groupId };
1247 }
1248 else {
1249 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1250 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1251 }
1252
1253 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1254 finderArgs, this);
1255
1256 if ((list != null) && !list.isEmpty()) {
1257 for (MBCategory mbCategory : list) {
1258 if ((groupId != mbCategory.getGroupId())) {
1259 list = null;
1260
1261 break;
1262 }
1263 }
1264 }
1265
1266 if (list == null) {
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_GROUPID_GROUPID_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 Session session = null;
1293
1294 try {
1295 session = openSession();
1296
1297 Query q = session.createQuery(sql);
1298
1299 QueryPos qPos = QueryPos.getInstance(q);
1300
1301 qPos.add(groupId);
1302
1303 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1304 end);
1305 }
1306 catch (Exception e) {
1307 throw processException(e);
1308 }
1309 finally {
1310 if (list == null) {
1311 FinderCacheUtil.removeResult(finderPath, finderArgs);
1312 }
1313 else {
1314 cacheResult(list);
1315
1316 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1317 }
1318
1319 closeSession(session);
1320 }
1321 }
1322
1323 return list;
1324 }
1325
1326
1339 public MBCategory findByGroupId_First(long groupId,
1340 OrderByComparator orderByComparator)
1341 throws NoSuchCategoryException, SystemException {
1342 List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1343
1344 if (list.isEmpty()) {
1345 StringBundler msg = new StringBundler(4);
1346
1347 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1348
1349 msg.append("groupId=");
1350 msg.append(groupId);
1351
1352 msg.append(StringPool.CLOSE_CURLY_BRACE);
1353
1354 throw new NoSuchCategoryException(msg.toString());
1355 }
1356 else {
1357 return list.get(0);
1358 }
1359 }
1360
1361
1374 public MBCategory findByGroupId_Last(long groupId,
1375 OrderByComparator orderByComparator)
1376 throws NoSuchCategoryException, SystemException {
1377 int count = countByGroupId(groupId);
1378
1379 List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1380 orderByComparator);
1381
1382 if (list.isEmpty()) {
1383 StringBundler msg = new StringBundler(4);
1384
1385 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1386
1387 msg.append("groupId=");
1388 msg.append(groupId);
1389
1390 msg.append(StringPool.CLOSE_CURLY_BRACE);
1391
1392 throw new NoSuchCategoryException(msg.toString());
1393 }
1394 else {
1395 return list.get(0);
1396 }
1397 }
1398
1399
1413 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1414 long groupId, OrderByComparator orderByComparator)
1415 throws NoSuchCategoryException, SystemException {
1416 MBCategory mbCategory = findByPrimaryKey(categoryId);
1417
1418 Session session = null;
1419
1420 try {
1421 session = openSession();
1422
1423 MBCategory[] array = new MBCategoryImpl[3];
1424
1425 array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1426 orderByComparator, true);
1427
1428 array[1] = mbCategory;
1429
1430 array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1431 orderByComparator, false);
1432
1433 return array;
1434 }
1435 catch (Exception e) {
1436 throw processException(e);
1437 }
1438 finally {
1439 closeSession(session);
1440 }
1441 }
1442
1443 protected MBCategory getByGroupId_PrevAndNext(Session session,
1444 MBCategory mbCategory, long groupId,
1445 OrderByComparator orderByComparator, boolean previous) {
1446 StringBundler query = null;
1447
1448 if (orderByComparator != null) {
1449 query = new StringBundler(6 +
1450 (orderByComparator.getOrderByFields().length * 6));
1451 }
1452 else {
1453 query = new StringBundler(3);
1454 }
1455
1456 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1457
1458 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1459
1460 if (orderByComparator != null) {
1461 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1462
1463 if (orderByConditionFields.length > 0) {
1464 query.append(WHERE_AND);
1465 }
1466
1467 for (int i = 0; i < orderByConditionFields.length; i++) {
1468 query.append(_ORDER_BY_ENTITY_ALIAS);
1469 query.append(orderByConditionFields[i]);
1470
1471 if ((i + 1) < orderByConditionFields.length) {
1472 if (orderByComparator.isAscending() ^ previous) {
1473 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1474 }
1475 else {
1476 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1477 }
1478 }
1479 else {
1480 if (orderByComparator.isAscending() ^ previous) {
1481 query.append(WHERE_GREATER_THAN);
1482 }
1483 else {
1484 query.append(WHERE_LESSER_THAN);
1485 }
1486 }
1487 }
1488
1489 query.append(ORDER_BY_CLAUSE);
1490
1491 String[] orderByFields = orderByComparator.getOrderByFields();
1492
1493 for (int i = 0; i < orderByFields.length; i++) {
1494 query.append(_ORDER_BY_ENTITY_ALIAS);
1495 query.append(orderByFields[i]);
1496
1497 if ((i + 1) < orderByFields.length) {
1498 if (orderByComparator.isAscending() ^ previous) {
1499 query.append(ORDER_BY_ASC_HAS_NEXT);
1500 }
1501 else {
1502 query.append(ORDER_BY_DESC_HAS_NEXT);
1503 }
1504 }
1505 else {
1506 if (orderByComparator.isAscending() ^ previous) {
1507 query.append(ORDER_BY_ASC);
1508 }
1509 else {
1510 query.append(ORDER_BY_DESC);
1511 }
1512 }
1513 }
1514 }
1515
1516 else {
1517 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1518 }
1519
1520 String sql = query.toString();
1521
1522 Query q = session.createQuery(sql);
1523
1524 q.setFirstResult(0);
1525 q.setMaxResults(2);
1526
1527 QueryPos qPos = QueryPos.getInstance(q);
1528
1529 qPos.add(groupId);
1530
1531 if (orderByComparator != null) {
1532 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1533
1534 for (Object value : values) {
1535 qPos.add(value);
1536 }
1537 }
1538
1539 List<MBCategory> list = q.list();
1540
1541 if (list.size() == 2) {
1542 return list.get(1);
1543 }
1544 else {
1545 return null;
1546 }
1547 }
1548
1549
1556 public List<MBCategory> filterFindByGroupId(long groupId)
1557 throws SystemException {
1558 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1559 QueryUtil.ALL_POS, null);
1560 }
1561
1562
1575 public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1576 throws SystemException {
1577 return filterFindByGroupId(groupId, start, end, null);
1578 }
1579
1580
1594 public List<MBCategory> filterFindByGroupId(long groupId, int start,
1595 int end, OrderByComparator orderByComparator) throws SystemException {
1596 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1597 return findByGroupId(groupId, start, end, orderByComparator);
1598 }
1599
1600 StringBundler query = null;
1601
1602 if (orderByComparator != null) {
1603 query = new StringBundler(3 +
1604 (orderByComparator.getOrderByFields().length * 3));
1605 }
1606 else {
1607 query = new StringBundler(3);
1608 }
1609
1610 if (getDB().isSupportsInlineDistinct()) {
1611 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1612 }
1613 else {
1614 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1615 }
1616
1617 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1618
1619 if (!getDB().isSupportsInlineDistinct()) {
1620 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1621 }
1622
1623 if (orderByComparator != null) {
1624 if (getDB().isSupportsInlineDistinct()) {
1625 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1626 orderByComparator);
1627 }
1628 else {
1629 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1630 orderByComparator);
1631 }
1632 }
1633
1634 else {
1635 if (getDB().isSupportsInlineDistinct()) {
1636 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1637 }
1638 else {
1639 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1640 }
1641 }
1642
1643 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1644 MBCategory.class.getName(),
1645 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1646
1647 Session session = null;
1648
1649 try {
1650 session = openSession();
1651
1652 SQLQuery q = session.createSQLQuery(sql);
1653
1654 if (getDB().isSupportsInlineDistinct()) {
1655 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1656 }
1657 else {
1658 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1659 }
1660
1661 QueryPos qPos = QueryPos.getInstance(q);
1662
1663 qPos.add(groupId);
1664
1665 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1666 }
1667 catch (Exception e) {
1668 throw processException(e);
1669 }
1670 finally {
1671 closeSession(session);
1672 }
1673 }
1674
1675
1685 public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
1686 long groupId, OrderByComparator orderByComparator)
1687 throws NoSuchCategoryException, SystemException {
1688 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1689 return findByGroupId_PrevAndNext(categoryId, groupId,
1690 orderByComparator);
1691 }
1692
1693 MBCategory mbCategory = findByPrimaryKey(categoryId);
1694
1695 Session session = null;
1696
1697 try {
1698 session = openSession();
1699
1700 MBCategory[] array = new MBCategoryImpl[3];
1701
1702 array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1703 groupId, orderByComparator, true);
1704
1705 array[1] = mbCategory;
1706
1707 array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1708 groupId, orderByComparator, false);
1709
1710 return array;
1711 }
1712 catch (Exception e) {
1713 throw processException(e);
1714 }
1715 finally {
1716 closeSession(session);
1717 }
1718 }
1719
1720 protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
1721 MBCategory mbCategory, long groupId,
1722 OrderByComparator orderByComparator, boolean previous) {
1723 StringBundler query = null;
1724
1725 if (orderByComparator != null) {
1726 query = new StringBundler(6 +
1727 (orderByComparator.getOrderByFields().length * 6));
1728 }
1729 else {
1730 query = new StringBundler(3);
1731 }
1732
1733 if (getDB().isSupportsInlineDistinct()) {
1734 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1735 }
1736 else {
1737 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1738 }
1739
1740 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1741
1742 if (!getDB().isSupportsInlineDistinct()) {
1743 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1744 }
1745
1746 if (orderByComparator != null) {
1747 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1748
1749 if (orderByConditionFields.length > 0) {
1750 query.append(WHERE_AND);
1751 }
1752
1753 for (int i = 0; i < orderByConditionFields.length; i++) {
1754 if (getDB().isSupportsInlineDistinct()) {
1755 query.append(_ORDER_BY_ENTITY_ALIAS);
1756 }
1757 else {
1758 query.append(_ORDER_BY_ENTITY_TABLE);
1759 }
1760
1761 query.append(orderByConditionFields[i]);
1762
1763 if ((i + 1) < orderByConditionFields.length) {
1764 if (orderByComparator.isAscending() ^ previous) {
1765 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1766 }
1767 else {
1768 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1769 }
1770 }
1771 else {
1772 if (orderByComparator.isAscending() ^ previous) {
1773 query.append(WHERE_GREATER_THAN);
1774 }
1775 else {
1776 query.append(WHERE_LESSER_THAN);
1777 }
1778 }
1779 }
1780
1781 query.append(ORDER_BY_CLAUSE);
1782
1783 String[] orderByFields = orderByComparator.getOrderByFields();
1784
1785 for (int i = 0; i < orderByFields.length; i++) {
1786 if (getDB().isSupportsInlineDistinct()) {
1787 query.append(_ORDER_BY_ENTITY_ALIAS);
1788 }
1789 else {
1790 query.append(_ORDER_BY_ENTITY_TABLE);
1791 }
1792
1793 query.append(orderByFields[i]);
1794
1795 if ((i + 1) < orderByFields.length) {
1796 if (orderByComparator.isAscending() ^ previous) {
1797 query.append(ORDER_BY_ASC_HAS_NEXT);
1798 }
1799 else {
1800 query.append(ORDER_BY_DESC_HAS_NEXT);
1801 }
1802 }
1803 else {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(ORDER_BY_ASC);
1806 }
1807 else {
1808 query.append(ORDER_BY_DESC);
1809 }
1810 }
1811 }
1812 }
1813
1814 else {
1815 if (getDB().isSupportsInlineDistinct()) {
1816 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1817 }
1818 else {
1819 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1820 }
1821 }
1822
1823 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1824 MBCategory.class.getName(),
1825 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1826
1827 SQLQuery q = session.createSQLQuery(sql);
1828
1829 q.setFirstResult(0);
1830 q.setMaxResults(2);
1831
1832 if (getDB().isSupportsInlineDistinct()) {
1833 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1834 }
1835 else {
1836 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1837 }
1838
1839 QueryPos qPos = QueryPos.getInstance(q);
1840
1841 qPos.add(groupId);
1842
1843 if (orderByComparator != null) {
1844 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1845
1846 for (Object value : values) {
1847 qPos.add(value);
1848 }
1849 }
1850
1851 List<MBCategory> list = q.list();
1852
1853 if (list.size() == 2) {
1854 return list.get(1);
1855 }
1856 else {
1857 return null;
1858 }
1859 }
1860
1861
1868 public List<MBCategory> findByCompanyId(long companyId)
1869 throws SystemException {
1870 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1871 null);
1872 }
1873
1874
1887 public List<MBCategory> findByCompanyId(long companyId, int start, int end)
1888 throws SystemException {
1889 return findByCompanyId(companyId, start, end, null);
1890 }
1891
1892
1906 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
1907 OrderByComparator orderByComparator) throws SystemException {
1908 FinderPath finderPath = null;
1909 Object[] finderArgs = null;
1910
1911 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1912 (orderByComparator == null)) {
1913 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
1914 finderArgs = new Object[] { companyId };
1915 }
1916 else {
1917 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
1918 finderArgs = new Object[] { companyId, start, end, orderByComparator };
1919 }
1920
1921 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1922 finderArgs, this);
1923
1924 if ((list != null) && !list.isEmpty()) {
1925 for (MBCategory mbCategory : list) {
1926 if ((companyId != mbCategory.getCompanyId())) {
1927 list = null;
1928
1929 break;
1930 }
1931 }
1932 }
1933
1934 if (list == null) {
1935 StringBundler query = null;
1936
1937 if (orderByComparator != null) {
1938 query = new StringBundler(3 +
1939 (orderByComparator.getOrderByFields().length * 3));
1940 }
1941 else {
1942 query = new StringBundler(3);
1943 }
1944
1945 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1946
1947 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1948
1949 if (orderByComparator != null) {
1950 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1951 orderByComparator);
1952 }
1953
1954 else {
1955 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1956 }
1957
1958 String sql = query.toString();
1959
1960 Session session = null;
1961
1962 try {
1963 session = openSession();
1964
1965 Query q = session.createQuery(sql);
1966
1967 QueryPos qPos = QueryPos.getInstance(q);
1968
1969 qPos.add(companyId);
1970
1971 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1972 end);
1973 }
1974 catch (Exception e) {
1975 throw processException(e);
1976 }
1977 finally {
1978 if (list == null) {
1979 FinderCacheUtil.removeResult(finderPath, finderArgs);
1980 }
1981 else {
1982 cacheResult(list);
1983
1984 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1985 }
1986
1987 closeSession(session);
1988 }
1989 }
1990
1991 return list;
1992 }
1993
1994
2007 public MBCategory findByCompanyId_First(long companyId,
2008 OrderByComparator orderByComparator)
2009 throws NoSuchCategoryException, SystemException {
2010 List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2011 orderByComparator);
2012
2013 if (list.isEmpty()) {
2014 StringBundler msg = new StringBundler(4);
2015
2016 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2017
2018 msg.append("companyId=");
2019 msg.append(companyId);
2020
2021 msg.append(StringPool.CLOSE_CURLY_BRACE);
2022
2023 throw new NoSuchCategoryException(msg.toString());
2024 }
2025 else {
2026 return list.get(0);
2027 }
2028 }
2029
2030
2043 public MBCategory findByCompanyId_Last(long companyId,
2044 OrderByComparator orderByComparator)
2045 throws NoSuchCategoryException, SystemException {
2046 int count = countByCompanyId(companyId);
2047
2048 List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2049 orderByComparator);
2050
2051 if (list.isEmpty()) {
2052 StringBundler msg = new StringBundler(4);
2053
2054 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2055
2056 msg.append("companyId=");
2057 msg.append(companyId);
2058
2059 msg.append(StringPool.CLOSE_CURLY_BRACE);
2060
2061 throw new NoSuchCategoryException(msg.toString());
2062 }
2063 else {
2064 return list.get(0);
2065 }
2066 }
2067
2068
2082 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2083 long companyId, OrderByComparator orderByComparator)
2084 throws NoSuchCategoryException, SystemException {
2085 MBCategory mbCategory = findByPrimaryKey(categoryId);
2086
2087 Session session = null;
2088
2089 try {
2090 session = openSession();
2091
2092 MBCategory[] array = new MBCategoryImpl[3];
2093
2094 array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2095 companyId, orderByComparator, true);
2096
2097 array[1] = mbCategory;
2098
2099 array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2100 companyId, orderByComparator, false);
2101
2102 return array;
2103 }
2104 catch (Exception e) {
2105 throw processException(e);
2106 }
2107 finally {
2108 closeSession(session);
2109 }
2110 }
2111
2112 protected MBCategory getByCompanyId_PrevAndNext(Session session,
2113 MBCategory mbCategory, long companyId,
2114 OrderByComparator orderByComparator, boolean previous) {
2115 StringBundler query = null;
2116
2117 if (orderByComparator != null) {
2118 query = new StringBundler(6 +
2119 (orderByComparator.getOrderByFields().length * 6));
2120 }
2121 else {
2122 query = new StringBundler(3);
2123 }
2124
2125 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2126
2127 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2128
2129 if (orderByComparator != null) {
2130 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2131
2132 if (orderByConditionFields.length > 0) {
2133 query.append(WHERE_AND);
2134 }
2135
2136 for (int i = 0; i < orderByConditionFields.length; i++) {
2137 query.append(_ORDER_BY_ENTITY_ALIAS);
2138 query.append(orderByConditionFields[i]);
2139
2140 if ((i + 1) < orderByConditionFields.length) {
2141 if (orderByComparator.isAscending() ^ previous) {
2142 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2143 }
2144 else {
2145 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2146 }
2147 }
2148 else {
2149 if (orderByComparator.isAscending() ^ previous) {
2150 query.append(WHERE_GREATER_THAN);
2151 }
2152 else {
2153 query.append(WHERE_LESSER_THAN);
2154 }
2155 }
2156 }
2157
2158 query.append(ORDER_BY_CLAUSE);
2159
2160 String[] orderByFields = orderByComparator.getOrderByFields();
2161
2162 for (int i = 0; i < orderByFields.length; i++) {
2163 query.append(_ORDER_BY_ENTITY_ALIAS);
2164 query.append(orderByFields[i]);
2165
2166 if ((i + 1) < orderByFields.length) {
2167 if (orderByComparator.isAscending() ^ previous) {
2168 query.append(ORDER_BY_ASC_HAS_NEXT);
2169 }
2170 else {
2171 query.append(ORDER_BY_DESC_HAS_NEXT);
2172 }
2173 }
2174 else {
2175 if (orderByComparator.isAscending() ^ previous) {
2176 query.append(ORDER_BY_ASC);
2177 }
2178 else {
2179 query.append(ORDER_BY_DESC);
2180 }
2181 }
2182 }
2183 }
2184
2185 else {
2186 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2187 }
2188
2189 String sql = query.toString();
2190
2191 Query q = session.createQuery(sql);
2192
2193 q.setFirstResult(0);
2194 q.setMaxResults(2);
2195
2196 QueryPos qPos = QueryPos.getInstance(q);
2197
2198 qPos.add(companyId);
2199
2200 if (orderByComparator != null) {
2201 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2202
2203 for (Object value : values) {
2204 qPos.add(value);
2205 }
2206 }
2207
2208 List<MBCategory> list = q.list();
2209
2210 if (list.size() == 2) {
2211 return list.get(1);
2212 }
2213 else {
2214 return null;
2215 }
2216 }
2217
2218
2226 public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
2227 throws SystemException {
2228 return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2229 QueryUtil.ALL_POS, null);
2230 }
2231
2232
2246 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2247 int start, int end) throws SystemException {
2248 return findByG_P(groupId, parentCategoryId, start, end, null);
2249 }
2250
2251
2266 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2267 int start, int end, OrderByComparator orderByComparator)
2268 throws SystemException {
2269 FinderPath finderPath = null;
2270 Object[] finderArgs = null;
2271
2272 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2273 (orderByComparator == null)) {
2274 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2275 finderArgs = new Object[] { groupId, parentCategoryId };
2276 }
2277 else {
2278 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2279 finderArgs = new Object[] {
2280 groupId, parentCategoryId,
2281
2282 start, end, orderByComparator
2283 };
2284 }
2285
2286 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2287 finderArgs, this);
2288
2289 if ((list != null) && !list.isEmpty()) {
2290 for (MBCategory mbCategory : list) {
2291 if ((groupId != mbCategory.getGroupId()) ||
2292 (parentCategoryId != mbCategory.getParentCategoryId())) {
2293 list = null;
2294
2295 break;
2296 }
2297 }
2298 }
2299
2300 if (list == null) {
2301 StringBundler query = null;
2302
2303 if (orderByComparator != null) {
2304 query = new StringBundler(4 +
2305 (orderByComparator.getOrderByFields().length * 3));
2306 }
2307 else {
2308 query = new StringBundler(4);
2309 }
2310
2311 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2312
2313 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2314
2315 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2316
2317 if (orderByComparator != null) {
2318 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2319 orderByComparator);
2320 }
2321
2322 else {
2323 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2324 }
2325
2326 String sql = query.toString();
2327
2328 Session session = null;
2329
2330 try {
2331 session = openSession();
2332
2333 Query q = session.createQuery(sql);
2334
2335 QueryPos qPos = QueryPos.getInstance(q);
2336
2337 qPos.add(groupId);
2338
2339 qPos.add(parentCategoryId);
2340
2341 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2342 end);
2343 }
2344 catch (Exception e) {
2345 throw processException(e);
2346 }
2347 finally {
2348 if (list == null) {
2349 FinderCacheUtil.removeResult(finderPath, finderArgs);
2350 }
2351 else {
2352 cacheResult(list);
2353
2354 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2355 }
2356
2357 closeSession(session);
2358 }
2359 }
2360
2361 return list;
2362 }
2363
2364
2378 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
2379 OrderByComparator orderByComparator)
2380 throws NoSuchCategoryException, SystemException {
2381 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
2382 orderByComparator);
2383
2384 if (list.isEmpty()) {
2385 StringBundler msg = new StringBundler(6);
2386
2387 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2388
2389 msg.append("groupId=");
2390 msg.append(groupId);
2391
2392 msg.append(", parentCategoryId=");
2393 msg.append(parentCategoryId);
2394
2395 msg.append(StringPool.CLOSE_CURLY_BRACE);
2396
2397 throw new NoSuchCategoryException(msg.toString());
2398 }
2399 else {
2400 return list.get(0);
2401 }
2402 }
2403
2404
2418 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
2419 OrderByComparator orderByComparator)
2420 throws NoSuchCategoryException, SystemException {
2421 int count = countByG_P(groupId, parentCategoryId);
2422
2423 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
2424 count, orderByComparator);
2425
2426 if (list.isEmpty()) {
2427 StringBundler msg = new StringBundler(6);
2428
2429 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2430
2431 msg.append("groupId=");
2432 msg.append(groupId);
2433
2434 msg.append(", parentCategoryId=");
2435 msg.append(parentCategoryId);
2436
2437 msg.append(StringPool.CLOSE_CURLY_BRACE);
2438
2439 throw new NoSuchCategoryException(msg.toString());
2440 }
2441 else {
2442 return list.get(0);
2443 }
2444 }
2445
2446
2461 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
2462 long parentCategoryId, OrderByComparator orderByComparator)
2463 throws NoSuchCategoryException, SystemException {
2464 MBCategory mbCategory = findByPrimaryKey(categoryId);
2465
2466 Session session = null;
2467
2468 try {
2469 session = openSession();
2470
2471 MBCategory[] array = new MBCategoryImpl[3];
2472
2473 array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2474 parentCategoryId, orderByComparator, true);
2475
2476 array[1] = mbCategory;
2477
2478 array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2479 parentCategoryId, orderByComparator, false);
2480
2481 return array;
2482 }
2483 catch (Exception e) {
2484 throw processException(e);
2485 }
2486 finally {
2487 closeSession(session);
2488 }
2489 }
2490
2491 protected MBCategory getByG_P_PrevAndNext(Session session,
2492 MBCategory mbCategory, long groupId, long parentCategoryId,
2493 OrderByComparator orderByComparator, boolean previous) {
2494 StringBundler query = null;
2495
2496 if (orderByComparator != null) {
2497 query = new StringBundler(6 +
2498 (orderByComparator.getOrderByFields().length * 6));
2499 }
2500 else {
2501 query = new StringBundler(3);
2502 }
2503
2504 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2505
2506 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2507
2508 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2509
2510 if (orderByComparator != null) {
2511 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2512
2513 if (orderByConditionFields.length > 0) {
2514 query.append(WHERE_AND);
2515 }
2516
2517 for (int i = 0; i < orderByConditionFields.length; i++) {
2518 query.append(_ORDER_BY_ENTITY_ALIAS);
2519 query.append(orderByConditionFields[i]);
2520
2521 if ((i + 1) < orderByConditionFields.length) {
2522 if (orderByComparator.isAscending() ^ previous) {
2523 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2524 }
2525 else {
2526 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2527 }
2528 }
2529 else {
2530 if (orderByComparator.isAscending() ^ previous) {
2531 query.append(WHERE_GREATER_THAN);
2532 }
2533 else {
2534 query.append(WHERE_LESSER_THAN);
2535 }
2536 }
2537 }
2538
2539 query.append(ORDER_BY_CLAUSE);
2540
2541 String[] orderByFields = orderByComparator.getOrderByFields();
2542
2543 for (int i = 0; i < orderByFields.length; i++) {
2544 query.append(_ORDER_BY_ENTITY_ALIAS);
2545 query.append(orderByFields[i]);
2546
2547 if ((i + 1) < orderByFields.length) {
2548 if (orderByComparator.isAscending() ^ previous) {
2549 query.append(ORDER_BY_ASC_HAS_NEXT);
2550 }
2551 else {
2552 query.append(ORDER_BY_DESC_HAS_NEXT);
2553 }
2554 }
2555 else {
2556 if (orderByComparator.isAscending() ^ previous) {
2557 query.append(ORDER_BY_ASC);
2558 }
2559 else {
2560 query.append(ORDER_BY_DESC);
2561 }
2562 }
2563 }
2564 }
2565
2566 else {
2567 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2568 }
2569
2570 String sql = query.toString();
2571
2572 Query q = session.createQuery(sql);
2573
2574 q.setFirstResult(0);
2575 q.setMaxResults(2);
2576
2577 QueryPos qPos = QueryPos.getInstance(q);
2578
2579 qPos.add(groupId);
2580
2581 qPos.add(parentCategoryId);
2582
2583 if (orderByComparator != null) {
2584 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2585
2586 for (Object value : values) {
2587 qPos.add(value);
2588 }
2589 }
2590
2591 List<MBCategory> list = q.list();
2592
2593 if (list.size() == 2) {
2594 return list.get(1);
2595 }
2596 else {
2597 return null;
2598 }
2599 }
2600
2601
2613 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
2614 throws SystemException {
2615 return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2616 QueryUtil.ALL_POS, null);
2617 }
2618
2619
2633 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2634 int start, int end) throws SystemException {
2635 return findByG_P(groupId, parentCategoryIds, start, end, null);
2636 }
2637
2638
2653 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2654 int start, int end, OrderByComparator orderByComparator)
2655 throws SystemException {
2656 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2657 Object[] finderArgs = null;
2658
2659 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2660 (orderByComparator == null)) {
2661 finderArgs = new Object[] {
2662 groupId, StringUtil.merge(parentCategoryIds)
2663 };
2664 }
2665 else {
2666 finderArgs = new Object[] {
2667 groupId, StringUtil.merge(parentCategoryIds),
2668
2669 start, end, orderByComparator
2670 };
2671 }
2672
2673 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2674 finderArgs, this);
2675
2676 if ((list != null) && !list.isEmpty()) {
2677 for (MBCategory mbCategory : list) {
2678 if ((groupId != mbCategory.getGroupId()) ||
2679 !ArrayUtil.contains(parentCategoryIds,
2680 mbCategory.getParentCategoryId())) {
2681 list = null;
2682
2683 break;
2684 }
2685 }
2686 }
2687
2688 if (list == null) {
2689 StringBundler query = new StringBundler();
2690
2691 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2692
2693 boolean conjunctionable = false;
2694
2695 if (conjunctionable) {
2696 query.append(WHERE_AND);
2697 }
2698
2699 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2700
2701 conjunctionable = true;
2702
2703 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
2704 if (conjunctionable) {
2705 query.append(WHERE_AND);
2706 }
2707
2708 query.append(StringPool.OPEN_PARENTHESIS);
2709
2710 for (int i = 0; i < parentCategoryIds.length; i++) {
2711 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2712
2713 if ((i + 1) < parentCategoryIds.length) {
2714 query.append(WHERE_OR);
2715 }
2716 }
2717
2718 query.append(StringPool.CLOSE_PARENTHESIS);
2719
2720 conjunctionable = true;
2721 }
2722
2723 if (orderByComparator != null) {
2724 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2725 orderByComparator);
2726 }
2727
2728 else {
2729 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2730 }
2731
2732 String sql = query.toString();
2733
2734 Session session = null;
2735
2736 try {
2737 session = openSession();
2738
2739 Query q = session.createQuery(sql);
2740
2741 QueryPos qPos = QueryPos.getInstance(q);
2742
2743 qPos.add(groupId);
2744
2745 if (parentCategoryIds != null) {
2746 qPos.add(parentCategoryIds);
2747 }
2748
2749 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2750 end);
2751 }
2752 catch (Exception e) {
2753 throw processException(e);
2754 }
2755 finally {
2756 if (list == null) {
2757 FinderCacheUtil.removeResult(finderPath, finderArgs);
2758 }
2759 else {
2760 cacheResult(list);
2761
2762 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2763 }
2764
2765 closeSession(session);
2766 }
2767 }
2768
2769 return list;
2770 }
2771
2772
2780 public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
2781 throws SystemException {
2782 return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2783 QueryUtil.ALL_POS, null);
2784 }
2785
2786
2800 public List<MBCategory> filterFindByG_P(long groupId,
2801 long parentCategoryId, int start, int end) throws SystemException {
2802 return filterFindByG_P(groupId, parentCategoryId, start, end, null);
2803 }
2804
2805
2820 public List<MBCategory> filterFindByG_P(long groupId,
2821 long parentCategoryId, int start, int end,
2822 OrderByComparator orderByComparator) throws SystemException {
2823 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2824 return findByG_P(groupId, parentCategoryId, start, end,
2825 orderByComparator);
2826 }
2827
2828 StringBundler query = null;
2829
2830 if (orderByComparator != null) {
2831 query = new StringBundler(4 +
2832 (orderByComparator.getOrderByFields().length * 3));
2833 }
2834 else {
2835 query = new StringBundler(4);
2836 }
2837
2838 if (getDB().isSupportsInlineDistinct()) {
2839 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2840 }
2841 else {
2842 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2843 }
2844
2845 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2846
2847 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2848
2849 if (!getDB().isSupportsInlineDistinct()) {
2850 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2851 }
2852
2853 if (orderByComparator != null) {
2854 if (getDB().isSupportsInlineDistinct()) {
2855 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2856 orderByComparator);
2857 }
2858 else {
2859 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2860 orderByComparator);
2861 }
2862 }
2863
2864 else {
2865 if (getDB().isSupportsInlineDistinct()) {
2866 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2867 }
2868 else {
2869 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2870 }
2871 }
2872
2873 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2874 MBCategory.class.getName(),
2875 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2876
2877 Session session = null;
2878
2879 try {
2880 session = openSession();
2881
2882 SQLQuery q = session.createSQLQuery(sql);
2883
2884 if (getDB().isSupportsInlineDistinct()) {
2885 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2886 }
2887 else {
2888 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2889 }
2890
2891 QueryPos qPos = QueryPos.getInstance(q);
2892
2893 qPos.add(groupId);
2894
2895 qPos.add(parentCategoryId);
2896
2897 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2898 }
2899 catch (Exception e) {
2900 throw processException(e);
2901 }
2902 finally {
2903 closeSession(session);
2904 }
2905 }
2906
2907
2918 public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
2919 long groupId, long parentCategoryId, OrderByComparator orderByComparator)
2920 throws NoSuchCategoryException, SystemException {
2921 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2922 return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
2923 orderByComparator);
2924 }
2925
2926 MBCategory mbCategory = findByPrimaryKey(categoryId);
2927
2928 Session session = null;
2929
2930 try {
2931 session = openSession();
2932
2933 MBCategory[] array = new MBCategoryImpl[3];
2934
2935 array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
2936 parentCategoryId, orderByComparator, true);
2937
2938 array[1] = mbCategory;
2939
2940 array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
2941 parentCategoryId, orderByComparator, false);
2942
2943 return array;
2944 }
2945 catch (Exception e) {
2946 throw processException(e);
2947 }
2948 finally {
2949 closeSession(session);
2950 }
2951 }
2952
2953 protected MBCategory filterGetByG_P_PrevAndNext(Session session,
2954 MBCategory mbCategory, long groupId, long parentCategoryId,
2955 OrderByComparator orderByComparator, boolean previous) {
2956 StringBundler query = null;
2957
2958 if (orderByComparator != null) {
2959 query = new StringBundler(6 +
2960 (orderByComparator.getOrderByFields().length * 6));
2961 }
2962 else {
2963 query = new StringBundler(3);
2964 }
2965
2966 if (getDB().isSupportsInlineDistinct()) {
2967 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2968 }
2969 else {
2970 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2971 }
2972
2973 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2974
2975 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2976
2977 if (!getDB().isSupportsInlineDistinct()) {
2978 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2979 }
2980
2981 if (orderByComparator != null) {
2982 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2983
2984 if (orderByConditionFields.length > 0) {
2985 query.append(WHERE_AND);
2986 }
2987
2988 for (int i = 0; i < orderByConditionFields.length; i++) {
2989 if (getDB().isSupportsInlineDistinct()) {
2990 query.append(_ORDER_BY_ENTITY_ALIAS);
2991 }
2992 else {
2993 query.append(_ORDER_BY_ENTITY_TABLE);
2994 }
2995
2996 query.append(orderByConditionFields[i]);
2997
2998 if ((i + 1) < orderByConditionFields.length) {
2999 if (orderByComparator.isAscending() ^ previous) {
3000 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3001 }
3002 else {
3003 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3004 }
3005 }
3006 else {
3007 if (orderByComparator.isAscending() ^ previous) {
3008 query.append(WHERE_GREATER_THAN);
3009 }
3010 else {
3011 query.append(WHERE_LESSER_THAN);
3012 }
3013 }
3014 }
3015
3016 query.append(ORDER_BY_CLAUSE);
3017
3018 String[] orderByFields = orderByComparator.getOrderByFields();
3019
3020 for (int i = 0; i < orderByFields.length; i++) {
3021 if (getDB().isSupportsInlineDistinct()) {
3022 query.append(_ORDER_BY_ENTITY_ALIAS);
3023 }
3024 else {
3025 query.append(_ORDER_BY_ENTITY_TABLE);
3026 }
3027
3028 query.append(orderByFields[i]);
3029
3030 if ((i + 1) < orderByFields.length) {
3031 if (orderByComparator.isAscending() ^ previous) {
3032 query.append(ORDER_BY_ASC_HAS_NEXT);
3033 }
3034 else {
3035 query.append(ORDER_BY_DESC_HAS_NEXT);
3036 }
3037 }
3038 else {
3039 if (orderByComparator.isAscending() ^ previous) {
3040 query.append(ORDER_BY_ASC);
3041 }
3042 else {
3043 query.append(ORDER_BY_DESC);
3044 }
3045 }
3046 }
3047 }
3048
3049 else {
3050 if (getDB().isSupportsInlineDistinct()) {
3051 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3052 }
3053 else {
3054 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3055 }
3056 }
3057
3058 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3059 MBCategory.class.getName(),
3060 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3061
3062 SQLQuery q = session.createSQLQuery(sql);
3063
3064 q.setFirstResult(0);
3065 q.setMaxResults(2);
3066
3067 if (getDB().isSupportsInlineDistinct()) {
3068 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3069 }
3070 else {
3071 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3072 }
3073
3074 QueryPos qPos = QueryPos.getInstance(q);
3075
3076 qPos.add(groupId);
3077
3078 qPos.add(parentCategoryId);
3079
3080 if (orderByComparator != null) {
3081 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3082
3083 for (Object value : values) {
3084 qPos.add(value);
3085 }
3086 }
3087
3088 List<MBCategory> list = q.list();
3089
3090 if (list.size() == 2) {
3091 return list.get(1);
3092 }
3093 else {
3094 return null;
3095 }
3096 }
3097
3098
3106 public List<MBCategory> filterFindByG_P(long groupId,
3107 long[] parentCategoryIds) throws SystemException {
3108 return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3109 QueryUtil.ALL_POS, null);
3110 }
3111
3112
3126 public List<MBCategory> filterFindByG_P(long groupId,
3127 long[] parentCategoryIds, int start, int end) throws SystemException {
3128 return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3129 }
3130
3131
3146 public List<MBCategory> filterFindByG_P(long groupId,
3147 long[] parentCategoryIds, int start, int end,
3148 OrderByComparator orderByComparator) throws SystemException {
3149 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3150 return findByG_P(groupId, parentCategoryIds, start, end,
3151 orderByComparator);
3152 }
3153
3154 StringBundler query = new StringBundler();
3155
3156 if (getDB().isSupportsInlineDistinct()) {
3157 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3158 }
3159 else {
3160 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3161 }
3162
3163 boolean conjunctionable = false;
3164
3165 if (conjunctionable) {
3166 query.append(WHERE_AND);
3167 }
3168
3169 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3170
3171 conjunctionable = true;
3172
3173 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3174 if (conjunctionable) {
3175 query.append(WHERE_AND);
3176 }
3177
3178 query.append(StringPool.OPEN_PARENTHESIS);
3179
3180 for (int i = 0; i < parentCategoryIds.length; i++) {
3181 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3182
3183 if ((i + 1) < parentCategoryIds.length) {
3184 query.append(WHERE_OR);
3185 }
3186 }
3187
3188 query.append(StringPool.CLOSE_PARENTHESIS);
3189
3190 conjunctionable = true;
3191 }
3192
3193 if (!getDB().isSupportsInlineDistinct()) {
3194 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3195 }
3196
3197 if (orderByComparator != null) {
3198 if (getDB().isSupportsInlineDistinct()) {
3199 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3200 orderByComparator);
3201 }
3202 else {
3203 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3204 orderByComparator);
3205 }
3206 }
3207
3208 else {
3209 if (getDB().isSupportsInlineDistinct()) {
3210 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3211 }
3212 else {
3213 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3214 }
3215 }
3216
3217 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3218 MBCategory.class.getName(),
3219 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3220
3221 Session session = null;
3222
3223 try {
3224 session = openSession();
3225
3226 SQLQuery q = session.createSQLQuery(sql);
3227
3228 if (getDB().isSupportsInlineDistinct()) {
3229 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3230 }
3231 else {
3232 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3233 }
3234
3235 QueryPos qPos = QueryPos.getInstance(q);
3236
3237 qPos.add(groupId);
3238
3239 if (parentCategoryIds != null) {
3240 qPos.add(parentCategoryIds);
3241 }
3242
3243 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3244 }
3245 catch (Exception e) {
3246 throw processException(e);
3247 }
3248 finally {
3249 closeSession(session);
3250 }
3251 }
3252
3253
3259 public List<MBCategory> findAll() throws SystemException {
3260 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3261 }
3262
3263
3275 public List<MBCategory> findAll(int start, int end)
3276 throws SystemException {
3277 return findAll(start, end, null);
3278 }
3279
3280
3293 public List<MBCategory> findAll(int start, int end,
3294 OrderByComparator orderByComparator) throws SystemException {
3295 FinderPath finderPath = null;
3296 Object[] finderArgs = new Object[] { start, end, orderByComparator };
3297
3298 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3299 (orderByComparator == null)) {
3300 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3301 finderArgs = FINDER_ARGS_EMPTY;
3302 }
3303 else {
3304 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3305 finderArgs = new Object[] { start, end, orderByComparator };
3306 }
3307
3308 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
3309 finderArgs, this);
3310
3311 if (list == null) {
3312 StringBundler query = null;
3313 String sql = null;
3314
3315 if (orderByComparator != null) {
3316 query = new StringBundler(2 +
3317 (orderByComparator.getOrderByFields().length * 3));
3318
3319 query.append(_SQL_SELECT_MBCATEGORY);
3320
3321 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3322 orderByComparator);
3323
3324 sql = query.toString();
3325 }
3326 else {
3327 sql = _SQL_SELECT_MBCATEGORY.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
3328 }
3329
3330 Session session = null;
3331
3332 try {
3333 session = openSession();
3334
3335 Query q = session.createQuery(sql);
3336
3337 if (orderByComparator == null) {
3338 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3339 start, end, false);
3340
3341 Collections.sort(list);
3342 }
3343 else {
3344 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3345 start, end);
3346 }
3347 }
3348 catch (Exception e) {
3349 throw processException(e);
3350 }
3351 finally {
3352 if (list == null) {
3353 FinderCacheUtil.removeResult(finderPath, finderArgs);
3354 }
3355 else {
3356 cacheResult(list);
3357
3358 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3359 }
3360
3361 closeSession(session);
3362 }
3363 }
3364
3365 return list;
3366 }
3367
3368
3374 public void removeByUuid(String uuid) throws SystemException {
3375 for (MBCategory mbCategory : findByUuid(uuid)) {
3376 remove(mbCategory);
3377 }
3378 }
3379
3380
3387 public void removeByUUID_G(String uuid, long groupId)
3388 throws NoSuchCategoryException, SystemException {
3389 MBCategory mbCategory = findByUUID_G(uuid, groupId);
3390
3391 remove(mbCategory);
3392 }
3393
3394
3400 public void removeByGroupId(long groupId) throws SystemException {
3401 for (MBCategory mbCategory : findByGroupId(groupId)) {
3402 remove(mbCategory);
3403 }
3404 }
3405
3406
3412 public void removeByCompanyId(long companyId) throws SystemException {
3413 for (MBCategory mbCategory : findByCompanyId(companyId)) {
3414 remove(mbCategory);
3415 }
3416 }
3417
3418
3425 public void removeByG_P(long groupId, long parentCategoryId)
3426 throws SystemException {
3427 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
3428 remove(mbCategory);
3429 }
3430 }
3431
3432
3437 public void removeAll() throws SystemException {
3438 for (MBCategory mbCategory : findAll()) {
3439 remove(mbCategory);
3440 }
3441 }
3442
3443
3450 public int countByUuid(String uuid) throws SystemException {
3451 Object[] finderArgs = new Object[] { uuid };
3452
3453 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
3454 finderArgs, this);
3455
3456 if (count == null) {
3457 StringBundler query = new StringBundler(2);
3458
3459 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3460
3461 if (uuid == null) {
3462 query.append(_FINDER_COLUMN_UUID_UUID_1);
3463 }
3464 else {
3465 if (uuid.equals(StringPool.BLANK)) {
3466 query.append(_FINDER_COLUMN_UUID_UUID_3);
3467 }
3468 else {
3469 query.append(_FINDER_COLUMN_UUID_UUID_2);
3470 }
3471 }
3472
3473 String sql = query.toString();
3474
3475 Session session = null;
3476
3477 try {
3478 session = openSession();
3479
3480 Query q = session.createQuery(sql);
3481
3482 QueryPos qPos = QueryPos.getInstance(q);
3483
3484 if (uuid != null) {
3485 qPos.add(uuid);
3486 }
3487
3488 count = (Long)q.uniqueResult();
3489 }
3490 catch (Exception e) {
3491 throw processException(e);
3492 }
3493 finally {
3494 if (count == null) {
3495 count = Long.valueOf(0);
3496 }
3497
3498 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
3499 finderArgs, count);
3500
3501 closeSession(session);
3502 }
3503 }
3504
3505 return count.intValue();
3506 }
3507
3508
3516 public int countByUUID_G(String uuid, long groupId)
3517 throws SystemException {
3518 Object[] finderArgs = new Object[] { uuid, groupId };
3519
3520 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
3521 finderArgs, this);
3522
3523 if (count == null) {
3524 StringBundler query = new StringBundler(3);
3525
3526 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3527
3528 if (uuid == null) {
3529 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
3530 }
3531 else {
3532 if (uuid.equals(StringPool.BLANK)) {
3533 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
3534 }
3535 else {
3536 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
3537 }
3538 }
3539
3540 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
3541
3542 String sql = query.toString();
3543
3544 Session session = null;
3545
3546 try {
3547 session = openSession();
3548
3549 Query q = session.createQuery(sql);
3550
3551 QueryPos qPos = QueryPos.getInstance(q);
3552
3553 if (uuid != null) {
3554 qPos.add(uuid);
3555 }
3556
3557 qPos.add(groupId);
3558
3559 count = (Long)q.uniqueResult();
3560 }
3561 catch (Exception e) {
3562 throw processException(e);
3563 }
3564 finally {
3565 if (count == null) {
3566 count = Long.valueOf(0);
3567 }
3568
3569 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
3570 finderArgs, count);
3571
3572 closeSession(session);
3573 }
3574 }
3575
3576 return count.intValue();
3577 }
3578
3579
3586 public int countByGroupId(long groupId) throws SystemException {
3587 Object[] finderArgs = new Object[] { groupId };
3588
3589 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
3590 finderArgs, this);
3591
3592 if (count == null) {
3593 StringBundler query = new StringBundler(2);
3594
3595 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3596
3597 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3598
3599 String sql = query.toString();
3600
3601 Session session = null;
3602
3603 try {
3604 session = openSession();
3605
3606 Query q = session.createQuery(sql);
3607
3608 QueryPos qPos = QueryPos.getInstance(q);
3609
3610 qPos.add(groupId);
3611
3612 count = (Long)q.uniqueResult();
3613 }
3614 catch (Exception e) {
3615 throw processException(e);
3616 }
3617 finally {
3618 if (count == null) {
3619 count = Long.valueOf(0);
3620 }
3621
3622 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
3623 finderArgs, count);
3624
3625 closeSession(session);
3626 }
3627 }
3628
3629 return count.intValue();
3630 }
3631
3632
3639 public int filterCountByGroupId(long groupId) throws SystemException {
3640 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3641 return countByGroupId(groupId);
3642 }
3643
3644 StringBundler query = new StringBundler(2);
3645
3646 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3647
3648 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3649
3650 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3651 MBCategory.class.getName(),
3652 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3653
3654 Session session = null;
3655
3656 try {
3657 session = openSession();
3658
3659 SQLQuery q = session.createSQLQuery(sql);
3660
3661 q.addScalar(COUNT_COLUMN_NAME,
3662 com.liferay.portal.kernel.dao.orm.Type.LONG);
3663
3664 QueryPos qPos = QueryPos.getInstance(q);
3665
3666 qPos.add(groupId);
3667
3668 Long count = (Long)q.uniqueResult();
3669
3670 return count.intValue();
3671 }
3672 catch (Exception e) {
3673 throw processException(e);
3674 }
3675 finally {
3676 closeSession(session);
3677 }
3678 }
3679
3680
3687 public int countByCompanyId(long companyId) throws SystemException {
3688 Object[] finderArgs = new Object[] { companyId };
3689
3690 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3691 finderArgs, this);
3692
3693 if (count == null) {
3694 StringBundler query = new StringBundler(2);
3695
3696 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3697
3698 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3699
3700 String sql = query.toString();
3701
3702 Session session = null;
3703
3704 try {
3705 session = openSession();
3706
3707 Query q = session.createQuery(sql);
3708
3709 QueryPos qPos = QueryPos.getInstance(q);
3710
3711 qPos.add(companyId);
3712
3713 count = (Long)q.uniqueResult();
3714 }
3715 catch (Exception e) {
3716 throw processException(e);
3717 }
3718 finally {
3719 if (count == null) {
3720 count = Long.valueOf(0);
3721 }
3722
3723 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3724 finderArgs, count);
3725
3726 closeSession(session);
3727 }
3728 }
3729
3730 return count.intValue();
3731 }
3732
3733
3741 public int countByG_P(long groupId, long parentCategoryId)
3742 throws SystemException {
3743 Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3744
3745 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3746 finderArgs, this);
3747
3748 if (count == null) {
3749 StringBundler query = new StringBundler(3);
3750
3751 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3752
3753 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3754
3755 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3756
3757 String sql = query.toString();
3758
3759 Session session = null;
3760
3761 try {
3762 session = openSession();
3763
3764 Query q = session.createQuery(sql);
3765
3766 QueryPos qPos = QueryPos.getInstance(q);
3767
3768 qPos.add(groupId);
3769
3770 qPos.add(parentCategoryId);
3771
3772 count = (Long)q.uniqueResult();
3773 }
3774 catch (Exception e) {
3775 throw processException(e);
3776 }
3777 finally {
3778 if (count == null) {
3779 count = Long.valueOf(0);
3780 }
3781
3782 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3783 count);
3784
3785 closeSession(session);
3786 }
3787 }
3788
3789 return count.intValue();
3790 }
3791
3792
3800 public int countByG_P(long groupId, long[] parentCategoryIds)
3801 throws SystemException {
3802 Object[] finderArgs = new Object[] {
3803 groupId, StringUtil.merge(parentCategoryIds)
3804 };
3805
3806 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3807 finderArgs, this);
3808
3809 if (count == null) {
3810 StringBundler query = new StringBundler();
3811
3812 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3813
3814 boolean conjunctionable = false;
3815
3816 if (conjunctionable) {
3817 query.append(WHERE_AND);
3818 }
3819
3820 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3821
3822 conjunctionable = true;
3823
3824 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3825 if (conjunctionable) {
3826 query.append(WHERE_AND);
3827 }
3828
3829 query.append(StringPool.OPEN_PARENTHESIS);
3830
3831 for (int i = 0; i < parentCategoryIds.length; i++) {
3832 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3833
3834 if ((i + 1) < parentCategoryIds.length) {
3835 query.append(WHERE_OR);
3836 }
3837 }
3838
3839 query.append(StringPool.CLOSE_PARENTHESIS);
3840
3841 conjunctionable = true;
3842 }
3843
3844 String sql = query.toString();
3845
3846 Session session = null;
3847
3848 try {
3849 session = openSession();
3850
3851 Query q = session.createQuery(sql);
3852
3853 QueryPos qPos = QueryPos.getInstance(q);
3854
3855 qPos.add(groupId);
3856
3857 if (parentCategoryIds != null) {
3858 qPos.add(parentCategoryIds);
3859 }
3860
3861 count = (Long)q.uniqueResult();
3862 }
3863 catch (Exception e) {
3864 throw processException(e);
3865 }
3866 finally {
3867 if (count == null) {
3868 count = Long.valueOf(0);
3869 }
3870
3871 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3872 finderArgs, count);
3873
3874 closeSession(session);
3875 }
3876 }
3877
3878 return count.intValue();
3879 }
3880
3881
3889 public int filterCountByG_P(long groupId, long parentCategoryId)
3890 throws SystemException {
3891 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3892 return countByG_P(groupId, parentCategoryId);
3893 }
3894
3895 StringBundler query = new StringBundler(3);
3896
3897 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3898
3899 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3900
3901 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3902
3903 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3904 MBCategory.class.getName(),
3905 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3906
3907 Session session = null;
3908
3909 try {
3910 session = openSession();
3911
3912 SQLQuery q = session.createSQLQuery(sql);
3913
3914 q.addScalar(COUNT_COLUMN_NAME,
3915 com.liferay.portal.kernel.dao.orm.Type.LONG);
3916
3917 QueryPos qPos = QueryPos.getInstance(q);
3918
3919 qPos.add(groupId);
3920
3921 qPos.add(parentCategoryId);
3922
3923 Long count = (Long)q.uniqueResult();
3924
3925 return count.intValue();
3926 }
3927 catch (Exception e) {
3928 throw processException(e);
3929 }
3930 finally {
3931 closeSession(session);
3932 }
3933 }
3934
3935
3943 public int filterCountByG_P(long groupId, long[] parentCategoryIds)
3944 throws SystemException {
3945 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3946 return countByG_P(groupId, parentCategoryIds);
3947 }
3948
3949 StringBundler query = new StringBundler();
3950
3951 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3952
3953 boolean conjunctionable = false;
3954
3955 if (conjunctionable) {
3956 query.append(WHERE_AND);
3957 }
3958
3959 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3960
3961 conjunctionable = true;
3962
3963 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3964 if (conjunctionable) {
3965 query.append(WHERE_AND);
3966 }
3967
3968 query.append(StringPool.OPEN_PARENTHESIS);
3969
3970 for (int i = 0; i < parentCategoryIds.length; i++) {
3971 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3972
3973 if ((i + 1) < parentCategoryIds.length) {
3974 query.append(WHERE_OR);
3975 }
3976 }
3977
3978 query.append(StringPool.CLOSE_PARENTHESIS);
3979
3980 conjunctionable = true;
3981 }
3982
3983 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3984 MBCategory.class.getName(),
3985 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3986
3987 Session session = null;
3988
3989 try {
3990 session = openSession();
3991
3992 SQLQuery q = session.createSQLQuery(sql);
3993
3994 q.addScalar(COUNT_COLUMN_NAME,
3995 com.liferay.portal.kernel.dao.orm.Type.LONG);
3996
3997 QueryPos qPos = QueryPos.getInstance(q);
3998
3999 qPos.add(groupId);
4000
4001 if (parentCategoryIds != null) {
4002 qPos.add(parentCategoryIds);
4003 }
4004
4005 Long count = (Long)q.uniqueResult();
4006
4007 return count.intValue();
4008 }
4009 catch (Exception e) {
4010 throw processException(e);
4011 }
4012 finally {
4013 closeSession(session);
4014 }
4015 }
4016
4017
4023 public int countAll() throws SystemException {
4024 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4025 FINDER_ARGS_EMPTY, this);
4026
4027 if (count == null) {
4028 Session session = null;
4029
4030 try {
4031 session = openSession();
4032
4033 Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
4034
4035 count = (Long)q.uniqueResult();
4036 }
4037 catch (Exception e) {
4038 throw processException(e);
4039 }
4040 finally {
4041 if (count == null) {
4042 count = Long.valueOf(0);
4043 }
4044
4045 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4046 FINDER_ARGS_EMPTY, count);
4047
4048 closeSession(session);
4049 }
4050 }
4051
4052 return count.intValue();
4053 }
4054
4055
4058 public void afterPropertiesSet() {
4059 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4060 com.liferay.portal.util.PropsUtil.get(
4061 "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
4062
4063 if (listenerClassNames.length > 0) {
4064 try {
4065 List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
4066
4067 for (String listenerClassName : listenerClassNames) {
4068 listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
4069 listenerClassName));
4070 }
4071
4072 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4073 }
4074 catch (Exception e) {
4075 _log.error(e);
4076 }
4077 }
4078 }
4079
4080 public void destroy() {
4081 EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
4082 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4083 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4084 }
4085
4086 @BeanReference(type = MBBanPersistence.class)
4087 protected MBBanPersistence mbBanPersistence;
4088 @BeanReference(type = MBCategoryPersistence.class)
4089 protected MBCategoryPersistence mbCategoryPersistence;
4090 @BeanReference(type = MBDiscussionPersistence.class)
4091 protected MBDiscussionPersistence mbDiscussionPersistence;
4092 @BeanReference(type = MBMailingListPersistence.class)
4093 protected MBMailingListPersistence mbMailingListPersistence;
4094 @BeanReference(type = MBMessagePersistence.class)
4095 protected MBMessagePersistence mbMessagePersistence;
4096 @BeanReference(type = MBStatsUserPersistence.class)
4097 protected MBStatsUserPersistence mbStatsUserPersistence;
4098 @BeanReference(type = MBThreadPersistence.class)
4099 protected MBThreadPersistence mbThreadPersistence;
4100 @BeanReference(type = MBThreadFlagPersistence.class)
4101 protected MBThreadFlagPersistence mbThreadFlagPersistence;
4102 @BeanReference(type = GroupPersistence.class)
4103 protected GroupPersistence groupPersistence;
4104 @BeanReference(type = ResourcePersistence.class)
4105 protected ResourcePersistence resourcePersistence;
4106 @BeanReference(type = SubscriptionPersistence.class)
4107 protected SubscriptionPersistence subscriptionPersistence;
4108 @BeanReference(type = UserPersistence.class)
4109 protected UserPersistence userPersistence;
4110 @BeanReference(type = AssetTagPersistence.class)
4111 protected AssetTagPersistence assetTagPersistence;
4112 @BeanReference(type = ExpandoValuePersistence.class)
4113 protected ExpandoValuePersistence expandoValuePersistence;
4114 private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
4115 private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
4116 private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
4117 private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
4118 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
4119 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
4120 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?)";
4121 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
4122 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
4123 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
4124 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
4125 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
4126 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
4127 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4128 private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
4129 _removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
4130 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4131 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
4132 _removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
4133
4134 private static String _removeConjunction(String sql) {
4135 int pos = sql.indexOf(" AND ");
4136
4137 if (pos != -1) {
4138 sql = sql.substring(0, pos);
4139 }
4140
4141 return sql;
4142 }
4143
4144 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
4145 private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
4146 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
4147 "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
4148 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
4149 ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
4150 private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
4151 private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
4152 private static final String _FILTER_ENTITY_TABLE = "MBCategory";
4153 private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
4154 private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
4155 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
4156 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
4157 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4158 private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
4159 private static MBCategory _nullMBCategory = new MBCategoryImpl() {
4160 @Override
4161 public Object clone() {
4162 return this;
4163 }
4164
4165 @Override
4166 public CacheModel<MBCategory> toCacheModel() {
4167 return _nullMBCategoryCacheModel;
4168 }
4169 };
4170
4171 private static CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
4172 public MBCategory toEntityModel() {
4173 return _nullMBCategory;
4174 }
4175 };
4176 }