001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.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.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041 import com.liferay.portal.service.persistence.BatchSessionUtil;
042 import com.liferay.portal.service.persistence.GroupPersistence;
043 import com.liferay.portal.service.persistence.ResourcePersistence;
044 import com.liferay.portal.service.persistence.SubscriptionPersistence;
045 import com.liferay.portal.service.persistence.UserPersistence;
046 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047
048 import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
049 import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
050 import com.liferay.portlet.messageboards.NoSuchCategoryException;
051 import com.liferay.portlet.messageboards.model.MBCategory;
052 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
053 import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
054
055 import java.io.Serializable;
056
057 import java.util.ArrayList;
058 import java.util.Collections;
059 import java.util.List;
060
061
077 public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
078 implements MBCategoryPersistence {
079 public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
080 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
081 ".List";
082 public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
083 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084 "findByUuid",
085 new String[] {
086 String.class.getName(),
087
088 "java.lang.Integer", "java.lang.Integer",
089 "com.liferay.portal.kernel.util.OrderByComparator"
090 });
091 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
092 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093 "countByUuid", new String[] { String.class.getName() });
094 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
095 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
096 "fetchByUUID_G",
097 new String[] { String.class.getName(), Long.class.getName() });
098 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
099 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100 "countByUUID_G",
101 new String[] { String.class.getName(), Long.class.getName() });
102 public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
103 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "findByGroupId",
105 new String[] {
106 Long.class.getName(),
107
108 "java.lang.Integer", "java.lang.Integer",
109 "com.liferay.portal.kernel.util.OrderByComparator"
110 });
111 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
112 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113 "countByGroupId", new String[] { Long.class.getName() });
114 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
115 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116 "findByCompanyId",
117 new String[] {
118 Long.class.getName(),
119
120 "java.lang.Integer", "java.lang.Integer",
121 "com.liferay.portal.kernel.util.OrderByComparator"
122 });
123 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
124 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125 "countByCompanyId", new String[] { Long.class.getName() });
126 public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
127 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128 "findByG_P",
129 new String[] {
130 Long.class.getName(), Long.class.getName(),
131
132 "java.lang.Integer", "java.lang.Integer",
133 "com.liferay.portal.kernel.util.OrderByComparator"
134 });
135 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
136 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137 "countByG_P",
138 new String[] { Long.class.getName(), Long.class.getName() });
139 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
140 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
141 "findAll", new String[0]);
142 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
143 MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144 "countAll", new String[0]);
145
146
151 public void cacheResult(MBCategory mbCategory) {
152 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
153 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
154
155 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
156 new Object[] { mbCategory.getUuid(), new Long(
157 mbCategory.getGroupId()) }, mbCategory);
158 }
159
160
165 public void cacheResult(List<MBCategory> mbCategories) {
166 for (MBCategory mbCategory : mbCategories) {
167 if (EntityCacheUtil.getResult(
168 MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
169 MBCategoryImpl.class, mbCategory.getPrimaryKey(), this) == null) {
170 cacheResult(mbCategory);
171 }
172 }
173 }
174
175
182 public void clearCache() {
183 CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
184 EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
185 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
186 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
187 }
188
189
196 public void clearCache(MBCategory mbCategory) {
197 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
198 MBCategoryImpl.class, mbCategory.getPrimaryKey());
199
200 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
201 new Object[] { mbCategory.getUuid(), new Long(
202 mbCategory.getGroupId()) });
203 }
204
205
211 public MBCategory create(long categoryId) {
212 MBCategory mbCategory = new MBCategoryImpl();
213
214 mbCategory.setNew(true);
215 mbCategory.setPrimaryKey(categoryId);
216
217 String uuid = PortalUUIDUtil.generate();
218
219 mbCategory.setUuid(uuid);
220
221 return mbCategory;
222 }
223
224
232 public MBCategory remove(Serializable primaryKey)
233 throws NoSuchModelException, SystemException {
234 return remove(((Long)primaryKey).longValue());
235 }
236
237
245 public MBCategory remove(long categoryId)
246 throws NoSuchCategoryException, SystemException {
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
253 new Long(categoryId));
254
255 if (mbCategory == null) {
256 if (_log.isWarnEnabled()) {
257 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
258 }
259
260 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
261 categoryId);
262 }
263
264 return remove(mbCategory);
265 }
266 catch (NoSuchCategoryException nsee) {
267 throw nsee;
268 }
269 catch (Exception e) {
270 throw processException(e);
271 }
272 finally {
273 closeSession(session);
274 }
275 }
276
277 protected MBCategory removeImpl(MBCategory mbCategory)
278 throws SystemException {
279 mbCategory = toUnwrappedModel(mbCategory);
280
281 Session session = null;
282
283 try {
284 session = openSession();
285
286 if (mbCategory.isCachedModel() || BatchSessionUtil.isEnabled()) {
287 Object staleObject = session.get(MBCategoryImpl.class,
288 mbCategory.getPrimaryKeyObj());
289
290 if (staleObject != null) {
291 session.evict(staleObject);
292 }
293 }
294
295 session.delete(mbCategory);
296
297 session.flush();
298 }
299 catch (Exception e) {
300 throw processException(e);
301 }
302 finally {
303 closeSession(session);
304 }
305
306 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
307
308 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
309
310 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
311 new Object[] {
312 mbCategoryModelImpl.getOriginalUuid(),
313 new Long(mbCategoryModelImpl.getOriginalGroupId())
314 });
315
316 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
317 MBCategoryImpl.class, mbCategory.getPrimaryKey());
318
319 return mbCategory;
320 }
321
322 public MBCategory updateImpl(
323 com.liferay.portlet.messageboards.model.MBCategory mbCategory,
324 boolean merge) throws SystemException {
325 mbCategory = toUnwrappedModel(mbCategory);
326
327 boolean isNew = mbCategory.isNew();
328
329 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
330
331 if (Validator.isNull(mbCategory.getUuid())) {
332 String uuid = PortalUUIDUtil.generate();
333
334 mbCategory.setUuid(uuid);
335 }
336
337 Session session = null;
338
339 try {
340 session = openSession();
341
342 BatchSessionUtil.update(session, mbCategory, merge);
343
344 mbCategory.setNew(false);
345 }
346 catch (Exception e) {
347 throw processException(e);
348 }
349 finally {
350 closeSession(session);
351 }
352
353 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
354
355 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
356 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
357
358 if (!isNew &&
359 (!Validator.equals(mbCategory.getUuid(),
360 mbCategoryModelImpl.getOriginalUuid()) ||
361 (mbCategory.getGroupId() != mbCategoryModelImpl.getOriginalGroupId()))) {
362 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
363 new Object[] {
364 mbCategoryModelImpl.getOriginalUuid(),
365 new Long(mbCategoryModelImpl.getOriginalGroupId())
366 });
367 }
368
369 if (isNew ||
370 (!Validator.equals(mbCategory.getUuid(),
371 mbCategoryModelImpl.getOriginalUuid()) ||
372 (mbCategory.getGroupId() != mbCategoryModelImpl.getOriginalGroupId()))) {
373 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
374 new Object[] {
375 mbCategory.getUuid(), new Long(mbCategory.getGroupId())
376 }, mbCategory);
377 }
378
379 return mbCategory;
380 }
381
382 protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
383 if (mbCategory instanceof MBCategoryImpl) {
384 return mbCategory;
385 }
386
387 MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
388
389 mbCategoryImpl.setNew(mbCategory.isNew());
390 mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
391
392 mbCategoryImpl.setUuid(mbCategory.getUuid());
393 mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
394 mbCategoryImpl.setGroupId(mbCategory.getGroupId());
395 mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
396 mbCategoryImpl.setUserId(mbCategory.getUserId());
397 mbCategoryImpl.setUserName(mbCategory.getUserName());
398 mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
399 mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
400 mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
401 mbCategoryImpl.setName(mbCategory.getName());
402 mbCategoryImpl.setDescription(mbCategory.getDescription());
403 mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
404 mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
405 mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
406
407 return mbCategoryImpl;
408 }
409
410
418 public MBCategory findByPrimaryKey(Serializable primaryKey)
419 throws NoSuchModelException, SystemException {
420 return findByPrimaryKey(((Long)primaryKey).longValue());
421 }
422
423
431 public MBCategory findByPrimaryKey(long categoryId)
432 throws NoSuchCategoryException, SystemException {
433 MBCategory mbCategory = fetchByPrimaryKey(categoryId);
434
435 if (mbCategory == null) {
436 if (_log.isWarnEnabled()) {
437 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
438 }
439
440 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
441 categoryId);
442 }
443
444 return mbCategory;
445 }
446
447
454 public MBCategory fetchByPrimaryKey(Serializable primaryKey)
455 throws SystemException {
456 return fetchByPrimaryKey(((Long)primaryKey).longValue());
457 }
458
459
466 public MBCategory fetchByPrimaryKey(long categoryId)
467 throws SystemException {
468 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
469 MBCategoryImpl.class, categoryId, this);
470
471 if (mbCategory == null) {
472 Session session = null;
473
474 try {
475 session = openSession();
476
477 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
478 new Long(categoryId));
479 }
480 catch (Exception e) {
481 throw processException(e);
482 }
483 finally {
484 if (mbCategory != null) {
485 cacheResult(mbCategory);
486 }
487
488 closeSession(session);
489 }
490 }
491
492 return mbCategory;
493 }
494
495
502 public List<MBCategory> findByUuid(String uuid) throws SystemException {
503 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
504 }
505
506
519 public List<MBCategory> findByUuid(String uuid, int start, int end)
520 throws SystemException {
521 return findByUuid(uuid, start, end, null);
522 }
523
524
538 public List<MBCategory> findByUuid(String uuid, int start, int end,
539 OrderByComparator orderByComparator) throws SystemException {
540 Object[] finderArgs = new Object[] {
541 uuid,
542
543 String.valueOf(start), String.valueOf(end),
544 String.valueOf(orderByComparator)
545 };
546
547 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
548 finderArgs, this);
549
550 if (list == null) {
551 Session session = null;
552
553 try {
554 session = openSession();
555
556 StringBundler query = null;
557
558 if (orderByComparator != null) {
559 query = new StringBundler(3 +
560 (orderByComparator.getOrderByFields().length * 3));
561 }
562 else {
563 query = new StringBundler(3);
564 }
565
566 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
567
568 if (uuid == null) {
569 query.append(_FINDER_COLUMN_UUID_UUID_1);
570 }
571 else {
572 if (uuid.equals(StringPool.BLANK)) {
573 query.append(_FINDER_COLUMN_UUID_UUID_3);
574 }
575 else {
576 query.append(_FINDER_COLUMN_UUID_UUID_2);
577 }
578 }
579
580 if (orderByComparator != null) {
581 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
582 orderByComparator);
583 }
584
585 else {
586 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
587 }
588
589 String sql = query.toString();
590
591 Query q = session.createQuery(sql);
592
593 QueryPos qPos = QueryPos.getInstance(q);
594
595 if (uuid != null) {
596 qPos.add(uuid);
597 }
598
599 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
600 end);
601 }
602 catch (Exception e) {
603 throw processException(e);
604 }
605 finally {
606 if (list == null) {
607 list = new ArrayList<MBCategory>();
608 }
609
610 cacheResult(list);
611
612 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
613 list);
614
615 closeSession(session);
616 }
617 }
618
619 return list;
620 }
621
622
635 public MBCategory findByUuid_First(String uuid,
636 OrderByComparator orderByComparator)
637 throws NoSuchCategoryException, SystemException {
638 List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
639
640 if (list.isEmpty()) {
641 StringBundler msg = new StringBundler(4);
642
643 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
644
645 msg.append("uuid=");
646 msg.append(uuid);
647
648 msg.append(StringPool.CLOSE_CURLY_BRACE);
649
650 throw new NoSuchCategoryException(msg.toString());
651 }
652 else {
653 return list.get(0);
654 }
655 }
656
657
670 public MBCategory findByUuid_Last(String uuid,
671 OrderByComparator orderByComparator)
672 throws NoSuchCategoryException, SystemException {
673 int count = countByUuid(uuid);
674
675 List<MBCategory> list = findByUuid(uuid, count - 1, count,
676 orderByComparator);
677
678 if (list.isEmpty()) {
679 StringBundler msg = new StringBundler(4);
680
681 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
682
683 msg.append("uuid=");
684 msg.append(uuid);
685
686 msg.append(StringPool.CLOSE_CURLY_BRACE);
687
688 throw new NoSuchCategoryException(msg.toString());
689 }
690 else {
691 return list.get(0);
692 }
693 }
694
695
709 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
710 OrderByComparator orderByComparator)
711 throws NoSuchCategoryException, SystemException {
712 MBCategory mbCategory = findByPrimaryKey(categoryId);
713
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 MBCategory[] array = new MBCategoryImpl[3];
720
721 array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
722 orderByComparator, true);
723
724 array[1] = mbCategory;
725
726 array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
727 orderByComparator, false);
728
729 return array;
730 }
731 catch (Exception e) {
732 throw processException(e);
733 }
734 finally {
735 closeSession(session);
736 }
737 }
738
739 protected MBCategory getByUuid_PrevAndNext(Session session,
740 MBCategory mbCategory, String uuid,
741 OrderByComparator orderByComparator, boolean previous) {
742 StringBundler query = null;
743
744 if (orderByComparator != null) {
745 query = new StringBundler(6 +
746 (orderByComparator.getOrderByFields().length * 6));
747 }
748 else {
749 query = new StringBundler(3);
750 }
751
752 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
753
754 if (uuid == null) {
755 query.append(_FINDER_COLUMN_UUID_UUID_1);
756 }
757 else {
758 if (uuid.equals(StringPool.BLANK)) {
759 query.append(_FINDER_COLUMN_UUID_UUID_3);
760 }
761 else {
762 query.append(_FINDER_COLUMN_UUID_UUID_2);
763 }
764 }
765
766 if (orderByComparator != null) {
767 String[] orderByFields = orderByComparator.getOrderByFields();
768
769 if (orderByFields.length > 0) {
770 query.append(WHERE_AND);
771 }
772
773 for (int i = 0; i < orderByFields.length; i++) {
774 query.append(_ORDER_BY_ENTITY_ALIAS);
775 query.append(orderByFields[i]);
776
777 if ((i + 1) < orderByFields.length) {
778 if (orderByComparator.isAscending() ^ previous) {
779 query.append(WHERE_GREATER_THAN_HAS_NEXT);
780 }
781 else {
782 query.append(WHERE_LESSER_THAN_HAS_NEXT);
783 }
784 }
785 else {
786 if (orderByComparator.isAscending() ^ previous) {
787 query.append(WHERE_GREATER_THAN);
788 }
789 else {
790 query.append(WHERE_LESSER_THAN);
791 }
792 }
793 }
794
795 query.append(ORDER_BY_CLAUSE);
796
797 for (int i = 0; i < orderByFields.length; i++) {
798 query.append(_ORDER_BY_ENTITY_ALIAS);
799 query.append(orderByFields[i]);
800
801 if ((i + 1) < orderByFields.length) {
802 if (orderByComparator.isAscending() ^ previous) {
803 query.append(ORDER_BY_ASC_HAS_NEXT);
804 }
805 else {
806 query.append(ORDER_BY_DESC_HAS_NEXT);
807 }
808 }
809 else {
810 if (orderByComparator.isAscending() ^ previous) {
811 query.append(ORDER_BY_ASC);
812 }
813 else {
814 query.append(ORDER_BY_DESC);
815 }
816 }
817 }
818 }
819
820 else {
821 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
822 }
823
824 String sql = query.toString();
825
826 Query q = session.createQuery(sql);
827
828 q.setFirstResult(0);
829 q.setMaxResults(2);
830
831 QueryPos qPos = QueryPos.getInstance(q);
832
833 if (uuid != null) {
834 qPos.add(uuid);
835 }
836
837 if (orderByComparator != null) {
838 Object[] values = orderByComparator.getOrderByValues(mbCategory);
839
840 for (Object value : values) {
841 qPos.add(value);
842 }
843 }
844
845 List<MBCategory> list = q.list();
846
847 if (list.size() == 2) {
848 return list.get(1);
849 }
850 else {
851 return null;
852 }
853 }
854
855
864 public MBCategory findByUUID_G(String uuid, long groupId)
865 throws NoSuchCategoryException, SystemException {
866 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
867
868 if (mbCategory == null) {
869 StringBundler msg = new StringBundler(6);
870
871 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
872
873 msg.append("uuid=");
874 msg.append(uuid);
875
876 msg.append(", groupId=");
877 msg.append(groupId);
878
879 msg.append(StringPool.CLOSE_CURLY_BRACE);
880
881 if (_log.isWarnEnabled()) {
882 _log.warn(msg.toString());
883 }
884
885 throw new NoSuchCategoryException(msg.toString());
886 }
887
888 return mbCategory;
889 }
890
891
899 public MBCategory fetchByUUID_G(String uuid, long groupId)
900 throws SystemException {
901 return fetchByUUID_G(uuid, groupId, true);
902 }
903
904
912 public MBCategory fetchByUUID_G(String uuid, long groupId,
913 boolean retrieveFromCache) throws SystemException {
914 Object[] finderArgs = new Object[] { uuid, groupId };
915
916 Object result = null;
917
918 if (retrieveFromCache) {
919 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
920 finderArgs, this);
921 }
922
923 if (result == null) {
924 Session session = null;
925
926 try {
927 session = openSession();
928
929 StringBundler query = new StringBundler(4);
930
931 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
932
933 if (uuid == null) {
934 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
935 }
936 else {
937 if (uuid.equals(StringPool.BLANK)) {
938 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
939 }
940 else {
941 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
942 }
943 }
944
945 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
946
947 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
948
949 String sql = query.toString();
950
951 Query q = session.createQuery(sql);
952
953 QueryPos qPos = QueryPos.getInstance(q);
954
955 if (uuid != null) {
956 qPos.add(uuid);
957 }
958
959 qPos.add(groupId);
960
961 List<MBCategory> list = q.list();
962
963 result = list;
964
965 MBCategory mbCategory = null;
966
967 if (list.isEmpty()) {
968 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
969 finderArgs, list);
970 }
971 else {
972 mbCategory = list.get(0);
973
974 cacheResult(mbCategory);
975
976 if ((mbCategory.getUuid() == null) ||
977 !mbCategory.getUuid().equals(uuid) ||
978 (mbCategory.getGroupId() != groupId)) {
979 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
980 finderArgs, mbCategory);
981 }
982 }
983
984 return mbCategory;
985 }
986 catch (Exception e) {
987 throw processException(e);
988 }
989 finally {
990 if (result == null) {
991 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
992 finderArgs, new ArrayList<MBCategory>());
993 }
994
995 closeSession(session);
996 }
997 }
998 else {
999 if (result instanceof List<?>) {
1000 return null;
1001 }
1002 else {
1003 return (MBCategory)result;
1004 }
1005 }
1006 }
1007
1008
1015 public List<MBCategory> findByGroupId(long groupId)
1016 throws SystemException {
1017 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1018 }
1019
1020
1033 public List<MBCategory> findByGroupId(long groupId, int start, int end)
1034 throws SystemException {
1035 return findByGroupId(groupId, start, end, null);
1036 }
1037
1038
1052 public List<MBCategory> findByGroupId(long groupId, int start, int end,
1053 OrderByComparator orderByComparator) throws SystemException {
1054 Object[] finderArgs = new Object[] {
1055 groupId,
1056
1057 String.valueOf(start), String.valueOf(end),
1058 String.valueOf(orderByComparator)
1059 };
1060
1061 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1062 finderArgs, this);
1063
1064 if (list == null) {
1065 Session session = null;
1066
1067 try {
1068 session = openSession();
1069
1070 StringBundler query = null;
1071
1072 if (orderByComparator != null) {
1073 query = new StringBundler(3 +
1074 (orderByComparator.getOrderByFields().length * 3));
1075 }
1076 else {
1077 query = new StringBundler(3);
1078 }
1079
1080 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1081
1082 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1083
1084 if (orderByComparator != null) {
1085 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1086 orderByComparator);
1087 }
1088
1089 else {
1090 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1091 }
1092
1093 String sql = query.toString();
1094
1095 Query q = session.createQuery(sql);
1096
1097 QueryPos qPos = QueryPos.getInstance(q);
1098
1099 qPos.add(groupId);
1100
1101 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1102 end);
1103 }
1104 catch (Exception e) {
1105 throw processException(e);
1106 }
1107 finally {
1108 if (list == null) {
1109 list = new ArrayList<MBCategory>();
1110 }
1111
1112 cacheResult(list);
1113
1114 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1115 finderArgs, list);
1116
1117 closeSession(session);
1118 }
1119 }
1120
1121 return list;
1122 }
1123
1124
1137 public MBCategory findByGroupId_First(long groupId,
1138 OrderByComparator orderByComparator)
1139 throws NoSuchCategoryException, SystemException {
1140 List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1141
1142 if (list.isEmpty()) {
1143 StringBundler msg = new StringBundler(4);
1144
1145 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1146
1147 msg.append("groupId=");
1148 msg.append(groupId);
1149
1150 msg.append(StringPool.CLOSE_CURLY_BRACE);
1151
1152 throw new NoSuchCategoryException(msg.toString());
1153 }
1154 else {
1155 return list.get(0);
1156 }
1157 }
1158
1159
1172 public MBCategory findByGroupId_Last(long groupId,
1173 OrderByComparator orderByComparator)
1174 throws NoSuchCategoryException, SystemException {
1175 int count = countByGroupId(groupId);
1176
1177 List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1178 orderByComparator);
1179
1180 if (list.isEmpty()) {
1181 StringBundler msg = new StringBundler(4);
1182
1183 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1184
1185 msg.append("groupId=");
1186 msg.append(groupId);
1187
1188 msg.append(StringPool.CLOSE_CURLY_BRACE);
1189
1190 throw new NoSuchCategoryException(msg.toString());
1191 }
1192 else {
1193 return list.get(0);
1194 }
1195 }
1196
1197
1211 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1212 long groupId, OrderByComparator orderByComparator)
1213 throws NoSuchCategoryException, SystemException {
1214 MBCategory mbCategory = findByPrimaryKey(categoryId);
1215
1216 Session session = null;
1217
1218 try {
1219 session = openSession();
1220
1221 MBCategory[] array = new MBCategoryImpl[3];
1222
1223 array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1224 orderByComparator, true);
1225
1226 array[1] = mbCategory;
1227
1228 array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1229 orderByComparator, false);
1230
1231 return array;
1232 }
1233 catch (Exception e) {
1234 throw processException(e);
1235 }
1236 finally {
1237 closeSession(session);
1238 }
1239 }
1240
1241 protected MBCategory getByGroupId_PrevAndNext(Session session,
1242 MBCategory mbCategory, long groupId,
1243 OrderByComparator orderByComparator, boolean previous) {
1244 StringBundler query = null;
1245
1246 if (orderByComparator != null) {
1247 query = new StringBundler(6 +
1248 (orderByComparator.getOrderByFields().length * 6));
1249 }
1250 else {
1251 query = new StringBundler(3);
1252 }
1253
1254 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1255
1256 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1257
1258 if (orderByComparator != null) {
1259 String[] orderByFields = orderByComparator.getOrderByFields();
1260
1261 if (orderByFields.length > 0) {
1262 query.append(WHERE_AND);
1263 }
1264
1265 for (int i = 0; i < orderByFields.length; i++) {
1266 query.append(_ORDER_BY_ENTITY_ALIAS);
1267 query.append(orderByFields[i]);
1268
1269 if ((i + 1) < orderByFields.length) {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1272 }
1273 else {
1274 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1275 }
1276 }
1277 else {
1278 if (orderByComparator.isAscending() ^ previous) {
1279 query.append(WHERE_GREATER_THAN);
1280 }
1281 else {
1282 query.append(WHERE_LESSER_THAN);
1283 }
1284 }
1285 }
1286
1287 query.append(ORDER_BY_CLAUSE);
1288
1289 for (int i = 0; i < orderByFields.length; i++) {
1290 query.append(_ORDER_BY_ENTITY_ALIAS);
1291 query.append(orderByFields[i]);
1292
1293 if ((i + 1) < orderByFields.length) {
1294 if (orderByComparator.isAscending() ^ previous) {
1295 query.append(ORDER_BY_ASC_HAS_NEXT);
1296 }
1297 else {
1298 query.append(ORDER_BY_DESC_HAS_NEXT);
1299 }
1300 }
1301 else {
1302 if (orderByComparator.isAscending() ^ previous) {
1303 query.append(ORDER_BY_ASC);
1304 }
1305 else {
1306 query.append(ORDER_BY_DESC);
1307 }
1308 }
1309 }
1310 }
1311
1312 else {
1313 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1314 }
1315
1316 String sql = query.toString();
1317
1318 Query q = session.createQuery(sql);
1319
1320 q.setFirstResult(0);
1321 q.setMaxResults(2);
1322
1323 QueryPos qPos = QueryPos.getInstance(q);
1324
1325 qPos.add(groupId);
1326
1327 if (orderByComparator != null) {
1328 Object[] values = orderByComparator.getOrderByValues(mbCategory);
1329
1330 for (Object value : values) {
1331 qPos.add(value);
1332 }
1333 }
1334
1335 List<MBCategory> list = q.list();
1336
1337 if (list.size() == 2) {
1338 return list.get(1);
1339 }
1340 else {
1341 return null;
1342 }
1343 }
1344
1345
1352 public List<MBCategory> filterFindByGroupId(long groupId)
1353 throws SystemException {
1354 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1355 QueryUtil.ALL_POS, null);
1356 }
1357
1358
1371 public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1372 throws SystemException {
1373 return filterFindByGroupId(groupId, start, end, null);
1374 }
1375
1376
1390 public List<MBCategory> filterFindByGroupId(long groupId, int start,
1391 int end, OrderByComparator orderByComparator) throws SystemException {
1392 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1393 return findByGroupId(groupId, start, end, orderByComparator);
1394 }
1395
1396 Session session = null;
1397
1398 try {
1399 session = openSession();
1400
1401 StringBundler query = null;
1402
1403 if (orderByComparator != null) {
1404 query = new StringBundler(3 +
1405 (orderByComparator.getOrderByFields().length * 3));
1406 }
1407 else {
1408 query = new StringBundler(3);
1409 }
1410
1411 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1412
1413 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1414
1415 if (orderByComparator != null) {
1416 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1417 orderByComparator);
1418 }
1419
1420 else {
1421 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1422 }
1423
1424 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1425 MBCategory.class.getName(), _FILTER_COLUMN_PK,
1426 _FILTER_COLUMN_USERID, groupId);
1427
1428 SQLQuery q = session.createSQLQuery(sql);
1429
1430 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1431
1432 QueryPos qPos = QueryPos.getInstance(q);
1433
1434 qPos.add(groupId);
1435
1436 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1437 }
1438 catch (Exception e) {
1439 throw processException(e);
1440 }
1441 finally {
1442 closeSession(session);
1443 }
1444 }
1445
1446
1453 public List<MBCategory> findByCompanyId(long companyId)
1454 throws SystemException {
1455 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1456 null);
1457 }
1458
1459
1472 public List<MBCategory> findByCompanyId(long companyId, int start, int end)
1473 throws SystemException {
1474 return findByCompanyId(companyId, start, end, null);
1475 }
1476
1477
1491 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
1492 OrderByComparator orderByComparator) throws SystemException {
1493 Object[] finderArgs = new Object[] {
1494 companyId,
1495
1496 String.valueOf(start), String.valueOf(end),
1497 String.valueOf(orderByComparator)
1498 };
1499
1500 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1501 finderArgs, this);
1502
1503 if (list == null) {
1504 Session session = null;
1505
1506 try {
1507 session = openSession();
1508
1509 StringBundler query = null;
1510
1511 if (orderByComparator != null) {
1512 query = new StringBundler(3 +
1513 (orderByComparator.getOrderByFields().length * 3));
1514 }
1515 else {
1516 query = new StringBundler(3);
1517 }
1518
1519 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1520
1521 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1522
1523 if (orderByComparator != null) {
1524 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1525 orderByComparator);
1526 }
1527
1528 else {
1529 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1530 }
1531
1532 String sql = query.toString();
1533
1534 Query q = session.createQuery(sql);
1535
1536 QueryPos qPos = QueryPos.getInstance(q);
1537
1538 qPos.add(companyId);
1539
1540 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1541 end);
1542 }
1543 catch (Exception e) {
1544 throw processException(e);
1545 }
1546 finally {
1547 if (list == null) {
1548 list = new ArrayList<MBCategory>();
1549 }
1550
1551 cacheResult(list);
1552
1553 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1554 finderArgs, list);
1555
1556 closeSession(session);
1557 }
1558 }
1559
1560 return list;
1561 }
1562
1563
1576 public MBCategory findByCompanyId_First(long companyId,
1577 OrderByComparator orderByComparator)
1578 throws NoSuchCategoryException, SystemException {
1579 List<MBCategory> list = findByCompanyId(companyId, 0, 1,
1580 orderByComparator);
1581
1582 if (list.isEmpty()) {
1583 StringBundler msg = new StringBundler(4);
1584
1585 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1586
1587 msg.append("companyId=");
1588 msg.append(companyId);
1589
1590 msg.append(StringPool.CLOSE_CURLY_BRACE);
1591
1592 throw new NoSuchCategoryException(msg.toString());
1593 }
1594 else {
1595 return list.get(0);
1596 }
1597 }
1598
1599
1612 public MBCategory findByCompanyId_Last(long companyId,
1613 OrderByComparator orderByComparator)
1614 throws NoSuchCategoryException, SystemException {
1615 int count = countByCompanyId(companyId);
1616
1617 List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
1618 orderByComparator);
1619
1620 if (list.isEmpty()) {
1621 StringBundler msg = new StringBundler(4);
1622
1623 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1624
1625 msg.append("companyId=");
1626 msg.append(companyId);
1627
1628 msg.append(StringPool.CLOSE_CURLY_BRACE);
1629
1630 throw new NoSuchCategoryException(msg.toString());
1631 }
1632 else {
1633 return list.get(0);
1634 }
1635 }
1636
1637
1651 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
1652 long companyId, OrderByComparator orderByComparator)
1653 throws NoSuchCategoryException, SystemException {
1654 MBCategory mbCategory = findByPrimaryKey(categoryId);
1655
1656 Session session = null;
1657
1658 try {
1659 session = openSession();
1660
1661 MBCategory[] array = new MBCategoryImpl[3];
1662
1663 array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
1664 companyId, orderByComparator, true);
1665
1666 array[1] = mbCategory;
1667
1668 array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
1669 companyId, orderByComparator, false);
1670
1671 return array;
1672 }
1673 catch (Exception e) {
1674 throw processException(e);
1675 }
1676 finally {
1677 closeSession(session);
1678 }
1679 }
1680
1681 protected MBCategory getByCompanyId_PrevAndNext(Session session,
1682 MBCategory mbCategory, long companyId,
1683 OrderByComparator orderByComparator, boolean previous) {
1684 StringBundler query = null;
1685
1686 if (orderByComparator != null) {
1687 query = new StringBundler(6 +
1688 (orderByComparator.getOrderByFields().length * 6));
1689 }
1690 else {
1691 query = new StringBundler(3);
1692 }
1693
1694 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1695
1696 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1697
1698 if (orderByComparator != null) {
1699 String[] orderByFields = orderByComparator.getOrderByFields();
1700
1701 if (orderByFields.length > 0) {
1702 query.append(WHERE_AND);
1703 }
1704
1705 for (int i = 0; i < orderByFields.length; i++) {
1706 query.append(_ORDER_BY_ENTITY_ALIAS);
1707 query.append(orderByFields[i]);
1708
1709 if ((i + 1) < orderByFields.length) {
1710 if (orderByComparator.isAscending() ^ previous) {
1711 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1712 }
1713 else {
1714 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1715 }
1716 }
1717 else {
1718 if (orderByComparator.isAscending() ^ previous) {
1719 query.append(WHERE_GREATER_THAN);
1720 }
1721 else {
1722 query.append(WHERE_LESSER_THAN);
1723 }
1724 }
1725 }
1726
1727 query.append(ORDER_BY_CLAUSE);
1728
1729 for (int i = 0; i < orderByFields.length; i++) {
1730 query.append(_ORDER_BY_ENTITY_ALIAS);
1731 query.append(orderByFields[i]);
1732
1733 if ((i + 1) < orderByFields.length) {
1734 if (orderByComparator.isAscending() ^ previous) {
1735 query.append(ORDER_BY_ASC_HAS_NEXT);
1736 }
1737 else {
1738 query.append(ORDER_BY_DESC_HAS_NEXT);
1739 }
1740 }
1741 else {
1742 if (orderByComparator.isAscending() ^ previous) {
1743 query.append(ORDER_BY_ASC);
1744 }
1745 else {
1746 query.append(ORDER_BY_DESC);
1747 }
1748 }
1749 }
1750 }
1751
1752 else {
1753 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1754 }
1755
1756 String sql = query.toString();
1757
1758 Query q = session.createQuery(sql);
1759
1760 q.setFirstResult(0);
1761 q.setMaxResults(2);
1762
1763 QueryPos qPos = QueryPos.getInstance(q);
1764
1765 qPos.add(companyId);
1766
1767 if (orderByComparator != null) {
1768 Object[] values = orderByComparator.getOrderByValues(mbCategory);
1769
1770 for (Object value : values) {
1771 qPos.add(value);
1772 }
1773 }
1774
1775 List<MBCategory> list = q.list();
1776
1777 if (list.size() == 2) {
1778 return list.get(1);
1779 }
1780 else {
1781 return null;
1782 }
1783 }
1784
1785
1793 public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
1794 throws SystemException {
1795 return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
1796 QueryUtil.ALL_POS, null);
1797 }
1798
1799
1813 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1814 int start, int end) throws SystemException {
1815 return findByG_P(groupId, parentCategoryId, start, end, null);
1816 }
1817
1818
1833 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1834 int start, int end, OrderByComparator orderByComparator)
1835 throws SystemException {
1836 Object[] finderArgs = new Object[] {
1837 groupId, parentCategoryId,
1838
1839 String.valueOf(start), String.valueOf(end),
1840 String.valueOf(orderByComparator)
1841 };
1842
1843 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1844 finderArgs, this);
1845
1846 if (list == null) {
1847 Session session = null;
1848
1849 try {
1850 session = openSession();
1851
1852 StringBundler query = null;
1853
1854 if (orderByComparator != null) {
1855 query = new StringBundler(4 +
1856 (orderByComparator.getOrderByFields().length * 3));
1857 }
1858 else {
1859 query = new StringBundler(4);
1860 }
1861
1862 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1863
1864 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1865
1866 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1867
1868 if (orderByComparator != null) {
1869 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1870 orderByComparator);
1871 }
1872
1873 else {
1874 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1875 }
1876
1877 String sql = query.toString();
1878
1879 Query q = session.createQuery(sql);
1880
1881 QueryPos qPos = QueryPos.getInstance(q);
1882
1883 qPos.add(groupId);
1884
1885 qPos.add(parentCategoryId);
1886
1887 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1888 end);
1889 }
1890 catch (Exception e) {
1891 throw processException(e);
1892 }
1893 finally {
1894 if (list == null) {
1895 list = new ArrayList<MBCategory>();
1896 }
1897
1898 cacheResult(list);
1899
1900 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1901 list);
1902
1903 closeSession(session);
1904 }
1905 }
1906
1907 return list;
1908 }
1909
1910
1924 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
1925 OrderByComparator orderByComparator)
1926 throws NoSuchCategoryException, SystemException {
1927 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
1928 orderByComparator);
1929
1930 if (list.isEmpty()) {
1931 StringBundler msg = new StringBundler(6);
1932
1933 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1934
1935 msg.append("groupId=");
1936 msg.append(groupId);
1937
1938 msg.append(", parentCategoryId=");
1939 msg.append(parentCategoryId);
1940
1941 msg.append(StringPool.CLOSE_CURLY_BRACE);
1942
1943 throw new NoSuchCategoryException(msg.toString());
1944 }
1945 else {
1946 return list.get(0);
1947 }
1948 }
1949
1950
1964 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
1965 OrderByComparator orderByComparator)
1966 throws NoSuchCategoryException, SystemException {
1967 int count = countByG_P(groupId, parentCategoryId);
1968
1969 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
1970 count, orderByComparator);
1971
1972 if (list.isEmpty()) {
1973 StringBundler msg = new StringBundler(6);
1974
1975 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1976
1977 msg.append("groupId=");
1978 msg.append(groupId);
1979
1980 msg.append(", parentCategoryId=");
1981 msg.append(parentCategoryId);
1982
1983 msg.append(StringPool.CLOSE_CURLY_BRACE);
1984
1985 throw new NoSuchCategoryException(msg.toString());
1986 }
1987 else {
1988 return list.get(0);
1989 }
1990 }
1991
1992
2007 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
2008 long parentCategoryId, OrderByComparator orderByComparator)
2009 throws NoSuchCategoryException, SystemException {
2010 MBCategory mbCategory = findByPrimaryKey(categoryId);
2011
2012 Session session = null;
2013
2014 try {
2015 session = openSession();
2016
2017 MBCategory[] array = new MBCategoryImpl[3];
2018
2019 array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2020 parentCategoryId, orderByComparator, true);
2021
2022 array[1] = mbCategory;
2023
2024 array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2025 parentCategoryId, orderByComparator, false);
2026
2027 return array;
2028 }
2029 catch (Exception e) {
2030 throw processException(e);
2031 }
2032 finally {
2033 closeSession(session);
2034 }
2035 }
2036
2037 protected MBCategory getByG_P_PrevAndNext(Session session,
2038 MBCategory mbCategory, long groupId, long parentCategoryId,
2039 OrderByComparator orderByComparator, boolean previous) {
2040 StringBundler query = null;
2041
2042 if (orderByComparator != null) {
2043 query = new StringBundler(6 +
2044 (orderByComparator.getOrderByFields().length * 6));
2045 }
2046 else {
2047 query = new StringBundler(3);
2048 }
2049
2050 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2051
2052 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2053
2054 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2055
2056 if (orderByComparator != null) {
2057 String[] orderByFields = orderByComparator.getOrderByFields();
2058
2059 if (orderByFields.length > 0) {
2060 query.append(WHERE_AND);
2061 }
2062
2063 for (int i = 0; i < orderByFields.length; i++) {
2064 query.append(_ORDER_BY_ENTITY_ALIAS);
2065 query.append(orderByFields[i]);
2066
2067 if ((i + 1) < orderByFields.length) {
2068 if (orderByComparator.isAscending() ^ previous) {
2069 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2070 }
2071 else {
2072 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2073 }
2074 }
2075 else {
2076 if (orderByComparator.isAscending() ^ previous) {
2077 query.append(WHERE_GREATER_THAN);
2078 }
2079 else {
2080 query.append(WHERE_LESSER_THAN);
2081 }
2082 }
2083 }
2084
2085 query.append(ORDER_BY_CLAUSE);
2086
2087 for (int i = 0; i < orderByFields.length; i++) {
2088 query.append(_ORDER_BY_ENTITY_ALIAS);
2089 query.append(orderByFields[i]);
2090
2091 if ((i + 1) < orderByFields.length) {
2092 if (orderByComparator.isAscending() ^ previous) {
2093 query.append(ORDER_BY_ASC_HAS_NEXT);
2094 }
2095 else {
2096 query.append(ORDER_BY_DESC_HAS_NEXT);
2097 }
2098 }
2099 else {
2100 if (orderByComparator.isAscending() ^ previous) {
2101 query.append(ORDER_BY_ASC);
2102 }
2103 else {
2104 query.append(ORDER_BY_DESC);
2105 }
2106 }
2107 }
2108 }
2109
2110 else {
2111 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2112 }
2113
2114 String sql = query.toString();
2115
2116 Query q = session.createQuery(sql);
2117
2118 q.setFirstResult(0);
2119 q.setMaxResults(2);
2120
2121 QueryPos qPos = QueryPos.getInstance(q);
2122
2123 qPos.add(groupId);
2124
2125 qPos.add(parentCategoryId);
2126
2127 if (orderByComparator != null) {
2128 Object[] values = orderByComparator.getOrderByValues(mbCategory);
2129
2130 for (Object value : values) {
2131 qPos.add(value);
2132 }
2133 }
2134
2135 List<MBCategory> list = q.list();
2136
2137 if (list.size() == 2) {
2138 return list.get(1);
2139 }
2140 else {
2141 return null;
2142 }
2143 }
2144
2145
2157 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
2158 throws SystemException {
2159 return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2160 QueryUtil.ALL_POS, null);
2161 }
2162
2163
2177 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2178 int start, int end) throws SystemException {
2179 return findByG_P(groupId, parentCategoryIds, start, end, null);
2180 }
2181
2182
2197 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2198 int start, int end, OrderByComparator orderByComparator)
2199 throws SystemException {
2200 Object[] finderArgs = new Object[] {
2201 groupId, StringUtil.merge(parentCategoryIds),
2202
2203 String.valueOf(start), String.valueOf(end),
2204 String.valueOf(orderByComparator)
2205 };
2206
2207 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
2208 finderArgs, this);
2209
2210 if (list == null) {
2211 Session session = null;
2212
2213 try {
2214 session = openSession();
2215
2216 StringBundler query = new StringBundler();
2217
2218 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2219
2220 boolean conjunctionable = false;
2221
2222 if (conjunctionable) {
2223 query.append(WHERE_AND);
2224 }
2225
2226 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2227
2228 conjunctionable = true;
2229
2230 if ((parentCategoryIds == null) ||
2231 (parentCategoryIds.length > 0)) {
2232 if (conjunctionable) {
2233 query.append(WHERE_AND);
2234 }
2235
2236 query.append(StringPool.OPEN_PARENTHESIS);
2237
2238 for (int i = 0; i < parentCategoryIds.length; i++) {
2239 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2240
2241 if ((i + 1) < parentCategoryIds.length) {
2242 query.append(WHERE_OR);
2243 }
2244 }
2245
2246 query.append(StringPool.CLOSE_PARENTHESIS);
2247
2248 conjunctionable = true;
2249 }
2250
2251 if (orderByComparator != null) {
2252 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2253 orderByComparator);
2254 }
2255
2256 else {
2257 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2258 }
2259
2260 String sql = query.toString();
2261
2262 Query q = session.createQuery(sql);
2263
2264 QueryPos qPos = QueryPos.getInstance(q);
2265
2266 qPos.add(groupId);
2267
2268 if (parentCategoryIds != null) {
2269 qPos.add(parentCategoryIds);
2270 }
2271
2272 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2273 end);
2274 }
2275 catch (Exception e) {
2276 throw processException(e);
2277 }
2278 finally {
2279 if (list == null) {
2280 list = new ArrayList<MBCategory>();
2281 }
2282
2283 cacheResult(list);
2284
2285 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
2286 list);
2287
2288 closeSession(session);
2289 }
2290 }
2291
2292 return list;
2293 }
2294
2295
2303 public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
2304 throws SystemException {
2305 return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2306 QueryUtil.ALL_POS, null);
2307 }
2308
2309
2323 public List<MBCategory> filterFindByG_P(long groupId,
2324 long parentCategoryId, int start, int end) throws SystemException {
2325 return filterFindByG_P(groupId, parentCategoryId, start, end, null);
2326 }
2327
2328
2343 public List<MBCategory> filterFindByG_P(long groupId,
2344 long parentCategoryId, int start, int end,
2345 OrderByComparator orderByComparator) throws SystemException {
2346 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2347 return findByG_P(groupId, parentCategoryId, start, end,
2348 orderByComparator);
2349 }
2350
2351 Session session = null;
2352
2353 try {
2354 session = openSession();
2355
2356 StringBundler query = null;
2357
2358 if (orderByComparator != null) {
2359 query = new StringBundler(4 +
2360 (orderByComparator.getOrderByFields().length * 3));
2361 }
2362 else {
2363 query = new StringBundler(4);
2364 }
2365
2366 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2367
2368 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2369
2370 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2371
2372 if (orderByComparator != null) {
2373 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2374 orderByComparator);
2375 }
2376
2377 else {
2378 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2379 }
2380
2381 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2382 MBCategory.class.getName(), _FILTER_COLUMN_PK,
2383 _FILTER_COLUMN_USERID, groupId);
2384
2385 SQLQuery q = session.createSQLQuery(sql);
2386
2387 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2388
2389 QueryPos qPos = QueryPos.getInstance(q);
2390
2391 qPos.add(groupId);
2392
2393 qPos.add(parentCategoryId);
2394
2395 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2396 }
2397 catch (Exception e) {
2398 throw processException(e);
2399 }
2400 finally {
2401 closeSession(session);
2402 }
2403 }
2404
2405
2417 public List<MBCategory> filterFindByG_P(long groupId,
2418 long[] parentCategoryIds) throws SystemException {
2419 return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2420 QueryUtil.ALL_POS, null);
2421 }
2422
2423
2437 public List<MBCategory> filterFindByG_P(long groupId,
2438 long[] parentCategoryIds, int start, int end) throws SystemException {
2439 return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
2440 }
2441
2442
2457 public List<MBCategory> filterFindByG_P(long groupId,
2458 long[] parentCategoryIds, int start, int end,
2459 OrderByComparator orderByComparator) throws SystemException {
2460 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2461 return findByG_P(groupId, parentCategoryIds, start, end,
2462 orderByComparator);
2463 }
2464
2465 Session session = null;
2466
2467 try {
2468 session = openSession();
2469
2470 StringBundler query = new StringBundler();
2471
2472 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2473
2474 boolean conjunctionable = false;
2475
2476 if (conjunctionable) {
2477 query.append(WHERE_AND);
2478 }
2479
2480 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2481
2482 conjunctionable = true;
2483
2484 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
2485 if (conjunctionable) {
2486 query.append(WHERE_AND);
2487 }
2488
2489 query.append(StringPool.OPEN_PARENTHESIS);
2490
2491 for (int i = 0; i < parentCategoryIds.length; i++) {
2492 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2493
2494 if ((i + 1) < parentCategoryIds.length) {
2495 query.append(WHERE_OR);
2496 }
2497 }
2498
2499 query.append(StringPool.CLOSE_PARENTHESIS);
2500
2501 conjunctionable = true;
2502 }
2503
2504 if (orderByComparator != null) {
2505 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2506 orderByComparator);
2507 }
2508
2509 else {
2510 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2511 }
2512
2513 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2514 MBCategory.class.getName(), _FILTER_COLUMN_PK,
2515 _FILTER_COLUMN_USERID, groupId);
2516
2517 SQLQuery q = session.createSQLQuery(sql);
2518
2519 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2520
2521 QueryPos qPos = QueryPos.getInstance(q);
2522
2523 qPos.add(groupId);
2524
2525 if (parentCategoryIds != null) {
2526 qPos.add(parentCategoryIds);
2527 }
2528
2529 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2530 }
2531 catch (Exception e) {
2532 throw processException(e);
2533 }
2534 finally {
2535 closeSession(session);
2536 }
2537 }
2538
2539
2545 public List<MBCategory> findAll() throws SystemException {
2546 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2547 }
2548
2549
2561 public List<MBCategory> findAll(int start, int end)
2562 throws SystemException {
2563 return findAll(start, end, null);
2564 }
2565
2566
2579 public List<MBCategory> findAll(int start, int end,
2580 OrderByComparator orderByComparator) throws SystemException {
2581 Object[] finderArgs = new Object[] {
2582 String.valueOf(start), String.valueOf(end),
2583 String.valueOf(orderByComparator)
2584 };
2585
2586 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2587 finderArgs, this);
2588
2589 if (list == null) {
2590 Session session = null;
2591
2592 try {
2593 session = openSession();
2594
2595 StringBundler query = null;
2596 String sql = null;
2597
2598 if (orderByComparator != null) {
2599 query = new StringBundler(2 +
2600 (orderByComparator.getOrderByFields().length * 3));
2601
2602 query.append(_SQL_SELECT_MBCATEGORY);
2603
2604 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2605 orderByComparator);
2606
2607 sql = query.toString();
2608 }
2609 else {
2610 sql = _SQL_SELECT_MBCATEGORY.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
2611 }
2612
2613 Query q = session.createQuery(sql);
2614
2615 if (orderByComparator == null) {
2616 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2617 start, end, false);
2618
2619 Collections.sort(list);
2620 }
2621 else {
2622 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2623 start, end);
2624 }
2625 }
2626 catch (Exception e) {
2627 throw processException(e);
2628 }
2629 finally {
2630 if (list == null) {
2631 list = new ArrayList<MBCategory>();
2632 }
2633
2634 cacheResult(list);
2635
2636 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2637
2638 closeSession(session);
2639 }
2640 }
2641
2642 return list;
2643 }
2644
2645
2651 public void removeByUuid(String uuid) throws SystemException {
2652 for (MBCategory mbCategory : findByUuid(uuid)) {
2653 remove(mbCategory);
2654 }
2655 }
2656
2657
2664 public void removeByUUID_G(String uuid, long groupId)
2665 throws NoSuchCategoryException, SystemException {
2666 MBCategory mbCategory = findByUUID_G(uuid, groupId);
2667
2668 remove(mbCategory);
2669 }
2670
2671
2677 public void removeByGroupId(long groupId) throws SystemException {
2678 for (MBCategory mbCategory : findByGroupId(groupId)) {
2679 remove(mbCategory);
2680 }
2681 }
2682
2683
2689 public void removeByCompanyId(long companyId) throws SystemException {
2690 for (MBCategory mbCategory : findByCompanyId(companyId)) {
2691 remove(mbCategory);
2692 }
2693 }
2694
2695
2702 public void removeByG_P(long groupId, long parentCategoryId)
2703 throws SystemException {
2704 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
2705 remove(mbCategory);
2706 }
2707 }
2708
2709
2714 public void removeAll() throws SystemException {
2715 for (MBCategory mbCategory : findAll()) {
2716 remove(mbCategory);
2717 }
2718 }
2719
2720
2727 public int countByUuid(String uuid) throws SystemException {
2728 Object[] finderArgs = new Object[] { uuid };
2729
2730 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2731 finderArgs, this);
2732
2733 if (count == null) {
2734 Session session = null;
2735
2736 try {
2737 session = openSession();
2738
2739 StringBundler query = new StringBundler(2);
2740
2741 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2742
2743 if (uuid == null) {
2744 query.append(_FINDER_COLUMN_UUID_UUID_1);
2745 }
2746 else {
2747 if (uuid.equals(StringPool.BLANK)) {
2748 query.append(_FINDER_COLUMN_UUID_UUID_3);
2749 }
2750 else {
2751 query.append(_FINDER_COLUMN_UUID_UUID_2);
2752 }
2753 }
2754
2755 String sql = query.toString();
2756
2757 Query q = session.createQuery(sql);
2758
2759 QueryPos qPos = QueryPos.getInstance(q);
2760
2761 if (uuid != null) {
2762 qPos.add(uuid);
2763 }
2764
2765 count = (Long)q.uniqueResult();
2766 }
2767 catch (Exception e) {
2768 throw processException(e);
2769 }
2770 finally {
2771 if (count == null) {
2772 count = Long.valueOf(0);
2773 }
2774
2775 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2776 finderArgs, count);
2777
2778 closeSession(session);
2779 }
2780 }
2781
2782 return count.intValue();
2783 }
2784
2785
2793 public int countByUUID_G(String uuid, long groupId)
2794 throws SystemException {
2795 Object[] finderArgs = new Object[] { uuid, groupId };
2796
2797 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2798 finderArgs, this);
2799
2800 if (count == null) {
2801 Session session = null;
2802
2803 try {
2804 session = openSession();
2805
2806 StringBundler query = new StringBundler(3);
2807
2808 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2809
2810 if (uuid == null) {
2811 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2812 }
2813 else {
2814 if (uuid.equals(StringPool.BLANK)) {
2815 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2816 }
2817 else {
2818 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2819 }
2820 }
2821
2822 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2823
2824 String sql = query.toString();
2825
2826 Query q = session.createQuery(sql);
2827
2828 QueryPos qPos = QueryPos.getInstance(q);
2829
2830 if (uuid != null) {
2831 qPos.add(uuid);
2832 }
2833
2834 qPos.add(groupId);
2835
2836 count = (Long)q.uniqueResult();
2837 }
2838 catch (Exception e) {
2839 throw processException(e);
2840 }
2841 finally {
2842 if (count == null) {
2843 count = Long.valueOf(0);
2844 }
2845
2846 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2847 finderArgs, count);
2848
2849 closeSession(session);
2850 }
2851 }
2852
2853 return count.intValue();
2854 }
2855
2856
2863 public int countByGroupId(long groupId) throws SystemException {
2864 Object[] finderArgs = new Object[] { groupId };
2865
2866 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2867 finderArgs, this);
2868
2869 if (count == null) {
2870 Session session = null;
2871
2872 try {
2873 session = openSession();
2874
2875 StringBundler query = new StringBundler(2);
2876
2877 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2878
2879 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2880
2881 String sql = query.toString();
2882
2883 Query q = session.createQuery(sql);
2884
2885 QueryPos qPos = QueryPos.getInstance(q);
2886
2887 qPos.add(groupId);
2888
2889 count = (Long)q.uniqueResult();
2890 }
2891 catch (Exception e) {
2892 throw processException(e);
2893 }
2894 finally {
2895 if (count == null) {
2896 count = Long.valueOf(0);
2897 }
2898
2899 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2900 finderArgs, count);
2901
2902 closeSession(session);
2903 }
2904 }
2905
2906 return count.intValue();
2907 }
2908
2909
2916 public int filterCountByGroupId(long groupId) throws SystemException {
2917 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2918 return countByGroupId(groupId);
2919 }
2920
2921 Session session = null;
2922
2923 try {
2924 session = openSession();
2925
2926 StringBundler query = new StringBundler(2);
2927
2928 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2929
2930 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2931
2932 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2933 MBCategory.class.getName(), _FILTER_COLUMN_PK,
2934 _FILTER_COLUMN_USERID, groupId);
2935
2936 SQLQuery q = session.createSQLQuery(sql);
2937
2938 q.addScalar(COUNT_COLUMN_NAME,
2939 com.liferay.portal.kernel.dao.orm.Type.LONG);
2940
2941 QueryPos qPos = QueryPos.getInstance(q);
2942
2943 qPos.add(groupId);
2944
2945 Long count = (Long)q.uniqueResult();
2946
2947 return count.intValue();
2948 }
2949 catch (Exception e) {
2950 throw processException(e);
2951 }
2952 finally {
2953 closeSession(session);
2954 }
2955 }
2956
2957
2964 public int countByCompanyId(long companyId) throws SystemException {
2965 Object[] finderArgs = new Object[] { companyId };
2966
2967 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2968 finderArgs, this);
2969
2970 if (count == null) {
2971 Session session = null;
2972
2973 try {
2974 session = openSession();
2975
2976 StringBundler query = new StringBundler(2);
2977
2978 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2979
2980 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2981
2982 String sql = query.toString();
2983
2984 Query q = session.createQuery(sql);
2985
2986 QueryPos qPos = QueryPos.getInstance(q);
2987
2988 qPos.add(companyId);
2989
2990 count = (Long)q.uniqueResult();
2991 }
2992 catch (Exception e) {
2993 throw processException(e);
2994 }
2995 finally {
2996 if (count == null) {
2997 count = Long.valueOf(0);
2998 }
2999
3000 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3001 finderArgs, count);
3002
3003 closeSession(session);
3004 }
3005 }
3006
3007 return count.intValue();
3008 }
3009
3010
3018 public int countByG_P(long groupId, long parentCategoryId)
3019 throws SystemException {
3020 Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3021
3022 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3023 finderArgs, this);
3024
3025 if (count == null) {
3026 Session session = null;
3027
3028 try {
3029 session = openSession();
3030
3031 StringBundler query = new StringBundler(3);
3032
3033 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3034
3035 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3036
3037 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3038
3039 String sql = query.toString();
3040
3041 Query q = session.createQuery(sql);
3042
3043 QueryPos qPos = QueryPos.getInstance(q);
3044
3045 qPos.add(groupId);
3046
3047 qPos.add(parentCategoryId);
3048
3049 count = (Long)q.uniqueResult();
3050 }
3051 catch (Exception e) {
3052 throw processException(e);
3053 }
3054 finally {
3055 if (count == null) {
3056 count = Long.valueOf(0);
3057 }
3058
3059 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3060 count);
3061
3062 closeSession(session);
3063 }
3064 }
3065
3066 return count.intValue();
3067 }
3068
3069
3077 public int countByG_P(long groupId, long[] parentCategoryIds)
3078 throws SystemException {
3079 Object[] finderArgs = new Object[] {
3080 groupId, StringUtil.merge(parentCategoryIds)
3081 };
3082
3083 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3084 finderArgs, this);
3085
3086 if (count == null) {
3087 Session session = null;
3088
3089 try {
3090 session = openSession();
3091
3092 StringBundler query = new StringBundler();
3093
3094 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3095
3096 boolean conjunctionable = false;
3097
3098 if (conjunctionable) {
3099 query.append(WHERE_AND);
3100 }
3101
3102 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3103
3104 conjunctionable = true;
3105
3106 if ((parentCategoryIds == null) ||
3107 (parentCategoryIds.length > 0)) {
3108 if (conjunctionable) {
3109 query.append(WHERE_AND);
3110 }
3111
3112 query.append(StringPool.OPEN_PARENTHESIS);
3113
3114 for (int i = 0; i < parentCategoryIds.length; i++) {
3115 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3116
3117 if ((i + 1) < parentCategoryIds.length) {
3118 query.append(WHERE_OR);
3119 }
3120 }
3121
3122 query.append(StringPool.CLOSE_PARENTHESIS);
3123
3124 conjunctionable = true;
3125 }
3126
3127 String sql = query.toString();
3128
3129 Query q = session.createQuery(sql);
3130
3131 QueryPos qPos = QueryPos.getInstance(q);
3132
3133 qPos.add(groupId);
3134
3135 if (parentCategoryIds != null) {
3136 qPos.add(parentCategoryIds);
3137 }
3138
3139 count = (Long)q.uniqueResult();
3140 }
3141 catch (Exception e) {
3142 throw processException(e);
3143 }
3144 finally {
3145 if (count == null) {
3146 count = Long.valueOf(0);
3147 }
3148
3149 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3150 count);
3151
3152 closeSession(session);
3153 }
3154 }
3155
3156 return count.intValue();
3157 }
3158
3159
3167 public int filterCountByG_P(long groupId, long parentCategoryId)
3168 throws SystemException {
3169 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3170 return countByG_P(groupId, parentCategoryId);
3171 }
3172
3173 Session session = null;
3174
3175 try {
3176 session = openSession();
3177
3178 StringBundler query = new StringBundler(3);
3179
3180 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3181
3182 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3183
3184 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3185
3186 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3187 MBCategory.class.getName(), _FILTER_COLUMN_PK,
3188 _FILTER_COLUMN_USERID, groupId);
3189
3190 SQLQuery q = session.createSQLQuery(sql);
3191
3192 q.addScalar(COUNT_COLUMN_NAME,
3193 com.liferay.portal.kernel.dao.orm.Type.LONG);
3194
3195 QueryPos qPos = QueryPos.getInstance(q);
3196
3197 qPos.add(groupId);
3198
3199 qPos.add(parentCategoryId);
3200
3201 Long count = (Long)q.uniqueResult();
3202
3203 return count.intValue();
3204 }
3205 catch (Exception e) {
3206 throw processException(e);
3207 }
3208 finally {
3209 closeSession(session);
3210 }
3211 }
3212
3213
3221 public int filterCountByG_P(long groupId, long[] parentCategoryIds)
3222 throws SystemException {
3223 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3224 return countByG_P(groupId, parentCategoryIds);
3225 }
3226
3227 Session session = null;
3228
3229 try {
3230 session = openSession();
3231
3232 StringBundler query = new StringBundler();
3233
3234 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3235
3236 boolean conjunctionable = false;
3237
3238 if (conjunctionable) {
3239 query.append(WHERE_AND);
3240 }
3241
3242 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3243
3244 conjunctionable = true;
3245
3246 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3247 if (conjunctionable) {
3248 query.append(WHERE_AND);
3249 }
3250
3251 query.append(StringPool.OPEN_PARENTHESIS);
3252
3253 for (int i = 0; i < parentCategoryIds.length; i++) {
3254 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3255
3256 if ((i + 1) < parentCategoryIds.length) {
3257 query.append(WHERE_OR);
3258 }
3259 }
3260
3261 query.append(StringPool.CLOSE_PARENTHESIS);
3262
3263 conjunctionable = true;
3264 }
3265
3266 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3267 MBCategory.class.getName(), _FILTER_COLUMN_PK,
3268 _FILTER_COLUMN_USERID, groupId);
3269
3270 SQLQuery q = session.createSQLQuery(sql);
3271
3272 q.addScalar(COUNT_COLUMN_NAME,
3273 com.liferay.portal.kernel.dao.orm.Type.LONG);
3274
3275 QueryPos qPos = QueryPos.getInstance(q);
3276
3277 qPos.add(groupId);
3278
3279 if (parentCategoryIds != null) {
3280 qPos.add(parentCategoryIds);
3281 }
3282
3283 Long count = (Long)q.uniqueResult();
3284
3285 return count.intValue();
3286 }
3287 catch (Exception e) {
3288 throw processException(e);
3289 }
3290 finally {
3291 closeSession(session);
3292 }
3293 }
3294
3295
3301 public int countAll() throws SystemException {
3302 Object[] finderArgs = new Object[0];
3303
3304 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3305 finderArgs, this);
3306
3307 if (count == null) {
3308 Session session = null;
3309
3310 try {
3311 session = openSession();
3312
3313 Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
3314
3315 count = (Long)q.uniqueResult();
3316 }
3317 catch (Exception e) {
3318 throw processException(e);
3319 }
3320 finally {
3321 if (count == null) {
3322 count = Long.valueOf(0);
3323 }
3324
3325 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3326 count);
3327
3328 closeSession(session);
3329 }
3330 }
3331
3332 return count.intValue();
3333 }
3334
3335
3338 public void afterPropertiesSet() {
3339 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3340 com.liferay.portal.util.PropsUtil.get(
3341 "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
3342
3343 if (listenerClassNames.length > 0) {
3344 try {
3345 List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
3346
3347 for (String listenerClassName : listenerClassNames) {
3348 listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
3349 listenerClassName));
3350 }
3351
3352 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3353 }
3354 catch (Exception e) {
3355 _log.error(e);
3356 }
3357 }
3358 }
3359
3360 @BeanReference(type = MBBanPersistence.class)
3361 protected MBBanPersistence mbBanPersistence;
3362 @BeanReference(type = MBCategoryPersistence.class)
3363 protected MBCategoryPersistence mbCategoryPersistence;
3364 @BeanReference(type = MBDiscussionPersistence.class)
3365 protected MBDiscussionPersistence mbDiscussionPersistence;
3366 @BeanReference(type = MBMailingListPersistence.class)
3367 protected MBMailingListPersistence mbMailingListPersistence;
3368 @BeanReference(type = MBMessagePersistence.class)
3369 protected MBMessagePersistence mbMessagePersistence;
3370 @BeanReference(type = MBMessageFlagPersistence.class)
3371 protected MBMessageFlagPersistence mbMessageFlagPersistence;
3372 @BeanReference(type = MBStatsUserPersistence.class)
3373 protected MBStatsUserPersistence mbStatsUserPersistence;
3374 @BeanReference(type = MBThreadPersistence.class)
3375 protected MBThreadPersistence mbThreadPersistence;
3376 @BeanReference(type = GroupPersistence.class)
3377 protected GroupPersistence groupPersistence;
3378 @BeanReference(type = ResourcePersistence.class)
3379 protected ResourcePersistence resourcePersistence;
3380 @BeanReference(type = SubscriptionPersistence.class)
3381 protected SubscriptionPersistence subscriptionPersistence;
3382 @BeanReference(type = UserPersistence.class)
3383 protected UserPersistence userPersistence;
3384 @BeanReference(type = AssetTagPersistence.class)
3385 protected AssetTagPersistence assetTagPersistence;
3386 @BeanReference(type = ExpandoValuePersistence.class)
3387 protected ExpandoValuePersistence expandoValuePersistence;
3388 private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
3389 private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
3390 private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
3391 private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
3392 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
3393 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
3394 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?)";
3395 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
3396 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
3397 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
3398 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
3399 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
3400 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
3401 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
3402 private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
3403 _removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
3404 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
3405 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
3406 _removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
3407
3408 private static String _removeConjunction(String sql) {
3409 int pos = sql.indexOf(" AND ");
3410
3411 if (pos != -1) {
3412 sql = sql.substring(0, pos);
3413 }
3414
3415 return sql;
3416 }
3417
3418 private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
3419 private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
3420 private static final String _FILTER_COLUMN_PK = "mbCategory.categoryId";
3421 private static final String _FILTER_COLUMN_USERID = "mbCategory.userId";
3422 private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
3423 private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
3424 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
3425 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
3426 private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
3427 }