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 BatchSessionUtil.delete(session, mbCategory);
287 }
288 catch (Exception e) {
289 throw processException(e);
290 }
291 finally {
292 closeSession(session);
293 }
294
295 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
296
297 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
298
299 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
300 new Object[] {
301 mbCategoryModelImpl.getOriginalUuid(),
302 new Long(mbCategoryModelImpl.getOriginalGroupId())
303 });
304
305 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
306 MBCategoryImpl.class, mbCategory.getPrimaryKey());
307
308 return mbCategory;
309 }
310
311 public MBCategory updateImpl(
312 com.liferay.portlet.messageboards.model.MBCategory mbCategory,
313 boolean merge) throws SystemException {
314 mbCategory = toUnwrappedModel(mbCategory);
315
316 boolean isNew = mbCategory.isNew();
317
318 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
319
320 if (Validator.isNull(mbCategory.getUuid())) {
321 String uuid = PortalUUIDUtil.generate();
322
323 mbCategory.setUuid(uuid);
324 }
325
326 Session session = null;
327
328 try {
329 session = openSession();
330
331 BatchSessionUtil.update(session, mbCategory, merge);
332
333 mbCategory.setNew(false);
334 }
335 catch (Exception e) {
336 throw processException(e);
337 }
338 finally {
339 closeSession(session);
340 }
341
342 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
343
344 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
345 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
346
347 if (!isNew &&
348 (!Validator.equals(mbCategory.getUuid(),
349 mbCategoryModelImpl.getOriginalUuid()) ||
350 (mbCategory.getGroupId() != mbCategoryModelImpl.getOriginalGroupId()))) {
351 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
352 new Object[] {
353 mbCategoryModelImpl.getOriginalUuid(),
354 new Long(mbCategoryModelImpl.getOriginalGroupId())
355 });
356 }
357
358 if (isNew ||
359 (!Validator.equals(mbCategory.getUuid(),
360 mbCategoryModelImpl.getOriginalUuid()) ||
361 (mbCategory.getGroupId() != mbCategoryModelImpl.getOriginalGroupId()))) {
362 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
363 new Object[] {
364 mbCategory.getUuid(), new Long(mbCategory.getGroupId())
365 }, mbCategory);
366 }
367
368 return mbCategory;
369 }
370
371 protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
372 if (mbCategory instanceof MBCategoryImpl) {
373 return mbCategory;
374 }
375
376 MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
377
378 mbCategoryImpl.setNew(mbCategory.isNew());
379 mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
380
381 mbCategoryImpl.setUuid(mbCategory.getUuid());
382 mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
383 mbCategoryImpl.setGroupId(mbCategory.getGroupId());
384 mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
385 mbCategoryImpl.setUserId(mbCategory.getUserId());
386 mbCategoryImpl.setUserName(mbCategory.getUserName());
387 mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
388 mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
389 mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
390 mbCategoryImpl.setName(mbCategory.getName());
391 mbCategoryImpl.setDescription(mbCategory.getDescription());
392 mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
393 mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
394 mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
395
396 return mbCategoryImpl;
397 }
398
399
407 public MBCategory findByPrimaryKey(Serializable primaryKey)
408 throws NoSuchModelException, SystemException {
409 return findByPrimaryKey(((Long)primaryKey).longValue());
410 }
411
412
420 public MBCategory findByPrimaryKey(long categoryId)
421 throws NoSuchCategoryException, SystemException {
422 MBCategory mbCategory = fetchByPrimaryKey(categoryId);
423
424 if (mbCategory == null) {
425 if (_log.isWarnEnabled()) {
426 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
427 }
428
429 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
430 categoryId);
431 }
432
433 return mbCategory;
434 }
435
436
443 public MBCategory fetchByPrimaryKey(Serializable primaryKey)
444 throws SystemException {
445 return fetchByPrimaryKey(((Long)primaryKey).longValue());
446 }
447
448
455 public MBCategory fetchByPrimaryKey(long categoryId)
456 throws SystemException {
457 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
458 MBCategoryImpl.class, categoryId, this);
459
460 if (mbCategory == null) {
461 Session session = null;
462
463 try {
464 session = openSession();
465
466 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
467 new Long(categoryId));
468 }
469 catch (Exception e) {
470 throw processException(e);
471 }
472 finally {
473 if (mbCategory != null) {
474 cacheResult(mbCategory);
475 }
476
477 closeSession(session);
478 }
479 }
480
481 return mbCategory;
482 }
483
484
491 public List<MBCategory> findByUuid(String uuid) throws SystemException {
492 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
493 }
494
495
508 public List<MBCategory> findByUuid(String uuid, int start, int end)
509 throws SystemException {
510 return findByUuid(uuid, start, end, null);
511 }
512
513
527 public List<MBCategory> findByUuid(String uuid, int start, int end,
528 OrderByComparator orderByComparator) throws SystemException {
529 Object[] finderArgs = new Object[] {
530 uuid,
531
532 String.valueOf(start), String.valueOf(end),
533 String.valueOf(orderByComparator)
534 };
535
536 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
537 finderArgs, this);
538
539 if (list == null) {
540 Session session = null;
541
542 try {
543 session = openSession();
544
545 StringBundler query = null;
546
547 if (orderByComparator != null) {
548 query = new StringBundler(3 +
549 (orderByComparator.getOrderByFields().length * 3));
550 }
551 else {
552 query = new StringBundler(3);
553 }
554
555 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
556
557 if (uuid == null) {
558 query.append(_FINDER_COLUMN_UUID_UUID_1);
559 }
560 else {
561 if (uuid.equals(StringPool.BLANK)) {
562 query.append(_FINDER_COLUMN_UUID_UUID_3);
563 }
564 else {
565 query.append(_FINDER_COLUMN_UUID_UUID_2);
566 }
567 }
568
569 if (orderByComparator != null) {
570 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
571 orderByComparator);
572 }
573
574 else {
575 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
576 }
577
578 String sql = query.toString();
579
580 Query q = session.createQuery(sql);
581
582 QueryPos qPos = QueryPos.getInstance(q);
583
584 if (uuid != null) {
585 qPos.add(uuid);
586 }
587
588 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
589 end);
590 }
591 catch (Exception e) {
592 throw processException(e);
593 }
594 finally {
595 if (list == null) {
596 list = new ArrayList<MBCategory>();
597 }
598
599 cacheResult(list);
600
601 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID, finderArgs,
602 list);
603
604 closeSession(session);
605 }
606 }
607
608 return list;
609 }
610
611
624 public MBCategory findByUuid_First(String uuid,
625 OrderByComparator orderByComparator)
626 throws NoSuchCategoryException, SystemException {
627 List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
628
629 if (list.isEmpty()) {
630 StringBundler msg = new StringBundler(4);
631
632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633
634 msg.append("uuid=");
635 msg.append(uuid);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 throw new NoSuchCategoryException(msg.toString());
640 }
641 else {
642 return list.get(0);
643 }
644 }
645
646
659 public MBCategory findByUuid_Last(String uuid,
660 OrderByComparator orderByComparator)
661 throws NoSuchCategoryException, SystemException {
662 int count = countByUuid(uuid);
663
664 List<MBCategory> list = findByUuid(uuid, count - 1, count,
665 orderByComparator);
666
667 if (list.isEmpty()) {
668 StringBundler msg = new StringBundler(4);
669
670 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
671
672 msg.append("uuid=");
673 msg.append(uuid);
674
675 msg.append(StringPool.CLOSE_CURLY_BRACE);
676
677 throw new NoSuchCategoryException(msg.toString());
678 }
679 else {
680 return list.get(0);
681 }
682 }
683
684
698 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
699 OrderByComparator orderByComparator)
700 throws NoSuchCategoryException, SystemException {
701 MBCategory mbCategory = findByPrimaryKey(categoryId);
702
703 Session session = null;
704
705 try {
706 session = openSession();
707
708 MBCategory[] array = new MBCategoryImpl[3];
709
710 array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
711 orderByComparator, true);
712
713 array[1] = mbCategory;
714
715 array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
716 orderByComparator, false);
717
718 return array;
719 }
720 catch (Exception e) {
721 throw processException(e);
722 }
723 finally {
724 closeSession(session);
725 }
726 }
727
728 protected MBCategory getByUuid_PrevAndNext(Session session,
729 MBCategory mbCategory, String uuid,
730 OrderByComparator orderByComparator, boolean previous) {
731 StringBundler query = null;
732
733 if (orderByComparator != null) {
734 query = new StringBundler(6 +
735 (orderByComparator.getOrderByFields().length * 6));
736 }
737 else {
738 query = new StringBundler(3);
739 }
740
741 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
742
743 if (uuid == null) {
744 query.append(_FINDER_COLUMN_UUID_UUID_1);
745 }
746 else {
747 if (uuid.equals(StringPool.BLANK)) {
748 query.append(_FINDER_COLUMN_UUID_UUID_3);
749 }
750 else {
751 query.append(_FINDER_COLUMN_UUID_UUID_2);
752 }
753 }
754
755 if (orderByComparator != null) {
756 String[] orderByFields = orderByComparator.getOrderByFields();
757
758 if (orderByFields.length > 0) {
759 query.append(WHERE_AND);
760 }
761
762 for (int i = 0; i < orderByFields.length; i++) {
763 query.append(_ORDER_BY_ENTITY_ALIAS);
764 query.append(orderByFields[i]);
765
766 if ((i + 1) < orderByFields.length) {
767 if (orderByComparator.isAscending() ^ previous) {
768 query.append(WHERE_GREATER_THAN_HAS_NEXT);
769 }
770 else {
771 query.append(WHERE_LESSER_THAN_HAS_NEXT);
772 }
773 }
774 else {
775 if (orderByComparator.isAscending() ^ previous) {
776 query.append(WHERE_GREATER_THAN);
777 }
778 else {
779 query.append(WHERE_LESSER_THAN);
780 }
781 }
782 }
783
784 query.append(ORDER_BY_CLAUSE);
785
786 for (int i = 0; i < orderByFields.length; i++) {
787 query.append(_ORDER_BY_ENTITY_ALIAS);
788 query.append(orderByFields[i]);
789
790 if ((i + 1) < orderByFields.length) {
791 if (orderByComparator.isAscending() ^ previous) {
792 query.append(ORDER_BY_ASC_HAS_NEXT);
793 }
794 else {
795 query.append(ORDER_BY_DESC_HAS_NEXT);
796 }
797 }
798 else {
799 if (orderByComparator.isAscending() ^ previous) {
800 query.append(ORDER_BY_ASC);
801 }
802 else {
803 query.append(ORDER_BY_DESC);
804 }
805 }
806 }
807 }
808
809 else {
810 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
811 }
812
813 String sql = query.toString();
814
815 Query q = session.createQuery(sql);
816
817 q.setFirstResult(0);
818 q.setMaxResults(2);
819
820 QueryPos qPos = QueryPos.getInstance(q);
821
822 if (uuid != null) {
823 qPos.add(uuid);
824 }
825
826 if (orderByComparator != null) {
827 Object[] values = orderByComparator.getOrderByValues(mbCategory);
828
829 for (Object value : values) {
830 qPos.add(value);
831 }
832 }
833
834 List<MBCategory> list = q.list();
835
836 if (list.size() == 2) {
837 return list.get(1);
838 }
839 else {
840 return null;
841 }
842 }
843
844
853 public MBCategory findByUUID_G(String uuid, long groupId)
854 throws NoSuchCategoryException, SystemException {
855 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
856
857 if (mbCategory == null) {
858 StringBundler msg = new StringBundler(6);
859
860 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
861
862 msg.append("uuid=");
863 msg.append(uuid);
864
865 msg.append(", groupId=");
866 msg.append(groupId);
867
868 msg.append(StringPool.CLOSE_CURLY_BRACE);
869
870 if (_log.isWarnEnabled()) {
871 _log.warn(msg.toString());
872 }
873
874 throw new NoSuchCategoryException(msg.toString());
875 }
876
877 return mbCategory;
878 }
879
880
888 public MBCategory fetchByUUID_G(String uuid, long groupId)
889 throws SystemException {
890 return fetchByUUID_G(uuid, groupId, true);
891 }
892
893
901 public MBCategory fetchByUUID_G(String uuid, long groupId,
902 boolean retrieveFromCache) throws SystemException {
903 Object[] finderArgs = new Object[] { uuid, groupId };
904
905 Object result = null;
906
907 if (retrieveFromCache) {
908 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
909 finderArgs, this);
910 }
911
912 if (result == null) {
913 Session session = null;
914
915 try {
916 session = openSession();
917
918 StringBundler query = new StringBundler(4);
919
920 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
921
922 if (uuid == null) {
923 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
924 }
925 else {
926 if (uuid.equals(StringPool.BLANK)) {
927 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
928 }
929 else {
930 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
931 }
932 }
933
934 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
935
936 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
937
938 String sql = query.toString();
939
940 Query q = session.createQuery(sql);
941
942 QueryPos qPos = QueryPos.getInstance(q);
943
944 if (uuid != null) {
945 qPos.add(uuid);
946 }
947
948 qPos.add(groupId);
949
950 List<MBCategory> list = q.list();
951
952 result = list;
953
954 MBCategory mbCategory = null;
955
956 if (list.isEmpty()) {
957 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
958 finderArgs, list);
959 }
960 else {
961 mbCategory = list.get(0);
962
963 cacheResult(mbCategory);
964
965 if ((mbCategory.getUuid() == null) ||
966 !mbCategory.getUuid().equals(uuid) ||
967 (mbCategory.getGroupId() != groupId)) {
968 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
969 finderArgs, mbCategory);
970 }
971 }
972
973 return mbCategory;
974 }
975 catch (Exception e) {
976 throw processException(e);
977 }
978 finally {
979 if (result == null) {
980 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
981 finderArgs, new ArrayList<MBCategory>());
982 }
983
984 closeSession(session);
985 }
986 }
987 else {
988 if (result instanceof List<?>) {
989 return null;
990 }
991 else {
992 return (MBCategory)result;
993 }
994 }
995 }
996
997
1004 public List<MBCategory> findByGroupId(long groupId)
1005 throws SystemException {
1006 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1007 }
1008
1009
1022 public List<MBCategory> findByGroupId(long groupId, int start, int end)
1023 throws SystemException {
1024 return findByGroupId(groupId, start, end, null);
1025 }
1026
1027
1041 public List<MBCategory> findByGroupId(long groupId, int start, int end,
1042 OrderByComparator orderByComparator) throws SystemException {
1043 Object[] finderArgs = new Object[] {
1044 groupId,
1045
1046 String.valueOf(start), String.valueOf(end),
1047 String.valueOf(orderByComparator)
1048 };
1049
1050 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1051 finderArgs, this);
1052
1053 if (list == null) {
1054 Session session = null;
1055
1056 try {
1057 session = openSession();
1058
1059 StringBundler query = null;
1060
1061 if (orderByComparator != null) {
1062 query = new StringBundler(3 +
1063 (orderByComparator.getOrderByFields().length * 3));
1064 }
1065 else {
1066 query = new StringBundler(3);
1067 }
1068
1069 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1070
1071 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1072
1073 if (orderByComparator != null) {
1074 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1075 orderByComparator);
1076 }
1077
1078 else {
1079 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1080 }
1081
1082 String sql = query.toString();
1083
1084 Query q = session.createQuery(sql);
1085
1086 QueryPos qPos = QueryPos.getInstance(q);
1087
1088 qPos.add(groupId);
1089
1090 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1091 end);
1092 }
1093 catch (Exception e) {
1094 throw processException(e);
1095 }
1096 finally {
1097 if (list == null) {
1098 list = new ArrayList<MBCategory>();
1099 }
1100
1101 cacheResult(list);
1102
1103 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1104 finderArgs, list);
1105
1106 closeSession(session);
1107 }
1108 }
1109
1110 return list;
1111 }
1112
1113
1126 public MBCategory findByGroupId_First(long groupId,
1127 OrderByComparator orderByComparator)
1128 throws NoSuchCategoryException, SystemException {
1129 List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1130
1131 if (list.isEmpty()) {
1132 StringBundler msg = new StringBundler(4);
1133
1134 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1135
1136 msg.append("groupId=");
1137 msg.append(groupId);
1138
1139 msg.append(StringPool.CLOSE_CURLY_BRACE);
1140
1141 throw new NoSuchCategoryException(msg.toString());
1142 }
1143 else {
1144 return list.get(0);
1145 }
1146 }
1147
1148
1161 public MBCategory findByGroupId_Last(long groupId,
1162 OrderByComparator orderByComparator)
1163 throws NoSuchCategoryException, SystemException {
1164 int count = countByGroupId(groupId);
1165
1166 List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1167 orderByComparator);
1168
1169 if (list.isEmpty()) {
1170 StringBundler msg = new StringBundler(4);
1171
1172 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1173
1174 msg.append("groupId=");
1175 msg.append(groupId);
1176
1177 msg.append(StringPool.CLOSE_CURLY_BRACE);
1178
1179 throw new NoSuchCategoryException(msg.toString());
1180 }
1181 else {
1182 return list.get(0);
1183 }
1184 }
1185
1186
1200 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1201 long groupId, OrderByComparator orderByComparator)
1202 throws NoSuchCategoryException, SystemException {
1203 MBCategory mbCategory = findByPrimaryKey(categoryId);
1204
1205 Session session = null;
1206
1207 try {
1208 session = openSession();
1209
1210 MBCategory[] array = new MBCategoryImpl[3];
1211
1212 array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1213 orderByComparator, true);
1214
1215 array[1] = mbCategory;
1216
1217 array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1218 orderByComparator, false);
1219
1220 return array;
1221 }
1222 catch (Exception e) {
1223 throw processException(e);
1224 }
1225 finally {
1226 closeSession(session);
1227 }
1228 }
1229
1230 protected MBCategory getByGroupId_PrevAndNext(Session session,
1231 MBCategory mbCategory, long groupId,
1232 OrderByComparator orderByComparator, boolean previous) {
1233 StringBundler query = null;
1234
1235 if (orderByComparator != null) {
1236 query = new StringBundler(6 +
1237 (orderByComparator.getOrderByFields().length * 6));
1238 }
1239 else {
1240 query = new StringBundler(3);
1241 }
1242
1243 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1244
1245 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1246
1247 if (orderByComparator != null) {
1248 String[] orderByFields = orderByComparator.getOrderByFields();
1249
1250 if (orderByFields.length > 0) {
1251 query.append(WHERE_AND);
1252 }
1253
1254 for (int i = 0; i < orderByFields.length; i++) {
1255 query.append(_ORDER_BY_ENTITY_ALIAS);
1256 query.append(orderByFields[i]);
1257
1258 if ((i + 1) < orderByFields.length) {
1259 if (orderByComparator.isAscending() ^ previous) {
1260 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1261 }
1262 else {
1263 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1264 }
1265 }
1266 else {
1267 if (orderByComparator.isAscending() ^ previous) {
1268 query.append(WHERE_GREATER_THAN);
1269 }
1270 else {
1271 query.append(WHERE_LESSER_THAN);
1272 }
1273 }
1274 }
1275
1276 query.append(ORDER_BY_CLAUSE);
1277
1278 for (int i = 0; i < orderByFields.length; i++) {
1279 query.append(_ORDER_BY_ENTITY_ALIAS);
1280 query.append(orderByFields[i]);
1281
1282 if ((i + 1) < orderByFields.length) {
1283 if (orderByComparator.isAscending() ^ previous) {
1284 query.append(ORDER_BY_ASC_HAS_NEXT);
1285 }
1286 else {
1287 query.append(ORDER_BY_DESC_HAS_NEXT);
1288 }
1289 }
1290 else {
1291 if (orderByComparator.isAscending() ^ previous) {
1292 query.append(ORDER_BY_ASC);
1293 }
1294 else {
1295 query.append(ORDER_BY_DESC);
1296 }
1297 }
1298 }
1299 }
1300
1301 else {
1302 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1303 }
1304
1305 String sql = query.toString();
1306
1307 Query q = session.createQuery(sql);
1308
1309 q.setFirstResult(0);
1310 q.setMaxResults(2);
1311
1312 QueryPos qPos = QueryPos.getInstance(q);
1313
1314 qPos.add(groupId);
1315
1316 if (orderByComparator != null) {
1317 Object[] values = orderByComparator.getOrderByValues(mbCategory);
1318
1319 for (Object value : values) {
1320 qPos.add(value);
1321 }
1322 }
1323
1324 List<MBCategory> list = q.list();
1325
1326 if (list.size() == 2) {
1327 return list.get(1);
1328 }
1329 else {
1330 return null;
1331 }
1332 }
1333
1334
1341 public List<MBCategory> filterFindByGroupId(long groupId)
1342 throws SystemException {
1343 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1344 QueryUtil.ALL_POS, null);
1345 }
1346
1347
1360 public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1361 throws SystemException {
1362 return filterFindByGroupId(groupId, start, end, null);
1363 }
1364
1365
1379 public List<MBCategory> filterFindByGroupId(long groupId, int start,
1380 int end, OrderByComparator orderByComparator) throws SystemException {
1381 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1382 return findByGroupId(groupId, start, end, orderByComparator);
1383 }
1384
1385 Session session = null;
1386
1387 try {
1388 session = openSession();
1389
1390 StringBundler query = null;
1391
1392 if (orderByComparator != null) {
1393 query = new StringBundler(3 +
1394 (orderByComparator.getOrderByFields().length * 3));
1395 }
1396 else {
1397 query = new StringBundler(3);
1398 }
1399
1400 if (getDB().isSupportsInlineDistinct()) {
1401 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1402 }
1403 else {
1404 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE);
1405 }
1406
1407 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1408
1409 if (orderByComparator != null) {
1410 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1411 orderByComparator);
1412 }
1413
1414 else {
1415 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1416 }
1417
1418 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1419 MBCategory.class.getName(), _FILTER_COLUMN_PK,
1420 _FILTER_COLUMN_USERID, groupId);
1421
1422 SQLQuery q = session.createSQLQuery(sql);
1423
1424 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1425
1426 QueryPos qPos = QueryPos.getInstance(q);
1427
1428 qPos.add(groupId);
1429
1430 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1431 }
1432 catch (Exception e) {
1433 throw processException(e);
1434 }
1435 finally {
1436 closeSession(session);
1437 }
1438 }
1439
1440
1447 public List<MBCategory> findByCompanyId(long companyId)
1448 throws SystemException {
1449 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1450 null);
1451 }
1452
1453
1466 public List<MBCategory> findByCompanyId(long companyId, int start, int end)
1467 throws SystemException {
1468 return findByCompanyId(companyId, start, end, null);
1469 }
1470
1471
1485 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
1486 OrderByComparator orderByComparator) throws SystemException {
1487 Object[] finderArgs = new Object[] {
1488 companyId,
1489
1490 String.valueOf(start), String.valueOf(end),
1491 String.valueOf(orderByComparator)
1492 };
1493
1494 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1495 finderArgs, this);
1496
1497 if (list == null) {
1498 Session session = null;
1499
1500 try {
1501 session = openSession();
1502
1503 StringBundler query = null;
1504
1505 if (orderByComparator != null) {
1506 query = new StringBundler(3 +
1507 (orderByComparator.getOrderByFields().length * 3));
1508 }
1509 else {
1510 query = new StringBundler(3);
1511 }
1512
1513 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1514
1515 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1516
1517 if (orderByComparator != null) {
1518 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1519 orderByComparator);
1520 }
1521
1522 else {
1523 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1524 }
1525
1526 String sql = query.toString();
1527
1528 Query q = session.createQuery(sql);
1529
1530 QueryPos qPos = QueryPos.getInstance(q);
1531
1532 qPos.add(companyId);
1533
1534 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1535 end);
1536 }
1537 catch (Exception e) {
1538 throw processException(e);
1539 }
1540 finally {
1541 if (list == null) {
1542 list = new ArrayList<MBCategory>();
1543 }
1544
1545 cacheResult(list);
1546
1547 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1548 finderArgs, list);
1549
1550 closeSession(session);
1551 }
1552 }
1553
1554 return list;
1555 }
1556
1557
1570 public MBCategory findByCompanyId_First(long companyId,
1571 OrderByComparator orderByComparator)
1572 throws NoSuchCategoryException, SystemException {
1573 List<MBCategory> list = findByCompanyId(companyId, 0, 1,
1574 orderByComparator);
1575
1576 if (list.isEmpty()) {
1577 StringBundler msg = new StringBundler(4);
1578
1579 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1580
1581 msg.append("companyId=");
1582 msg.append(companyId);
1583
1584 msg.append(StringPool.CLOSE_CURLY_BRACE);
1585
1586 throw new NoSuchCategoryException(msg.toString());
1587 }
1588 else {
1589 return list.get(0);
1590 }
1591 }
1592
1593
1606 public MBCategory findByCompanyId_Last(long companyId,
1607 OrderByComparator orderByComparator)
1608 throws NoSuchCategoryException, SystemException {
1609 int count = countByCompanyId(companyId);
1610
1611 List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
1612 orderByComparator);
1613
1614 if (list.isEmpty()) {
1615 StringBundler msg = new StringBundler(4);
1616
1617 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1618
1619 msg.append("companyId=");
1620 msg.append(companyId);
1621
1622 msg.append(StringPool.CLOSE_CURLY_BRACE);
1623
1624 throw new NoSuchCategoryException(msg.toString());
1625 }
1626 else {
1627 return list.get(0);
1628 }
1629 }
1630
1631
1645 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
1646 long companyId, OrderByComparator orderByComparator)
1647 throws NoSuchCategoryException, SystemException {
1648 MBCategory mbCategory = findByPrimaryKey(categoryId);
1649
1650 Session session = null;
1651
1652 try {
1653 session = openSession();
1654
1655 MBCategory[] array = new MBCategoryImpl[3];
1656
1657 array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
1658 companyId, orderByComparator, true);
1659
1660 array[1] = mbCategory;
1661
1662 array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
1663 companyId, orderByComparator, false);
1664
1665 return array;
1666 }
1667 catch (Exception e) {
1668 throw processException(e);
1669 }
1670 finally {
1671 closeSession(session);
1672 }
1673 }
1674
1675 protected MBCategory getByCompanyId_PrevAndNext(Session session,
1676 MBCategory mbCategory, long companyId,
1677 OrderByComparator orderByComparator, boolean previous) {
1678 StringBundler query = null;
1679
1680 if (orderByComparator != null) {
1681 query = new StringBundler(6 +
1682 (orderByComparator.getOrderByFields().length * 6));
1683 }
1684 else {
1685 query = new StringBundler(3);
1686 }
1687
1688 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1689
1690 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1691
1692 if (orderByComparator != null) {
1693 String[] orderByFields = orderByComparator.getOrderByFields();
1694
1695 if (orderByFields.length > 0) {
1696 query.append(WHERE_AND);
1697 }
1698
1699 for (int i = 0; i < orderByFields.length; i++) {
1700 query.append(_ORDER_BY_ENTITY_ALIAS);
1701 query.append(orderByFields[i]);
1702
1703 if ((i + 1) < orderByFields.length) {
1704 if (orderByComparator.isAscending() ^ previous) {
1705 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1706 }
1707 else {
1708 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1709 }
1710 }
1711 else {
1712 if (orderByComparator.isAscending() ^ previous) {
1713 query.append(WHERE_GREATER_THAN);
1714 }
1715 else {
1716 query.append(WHERE_LESSER_THAN);
1717 }
1718 }
1719 }
1720
1721 query.append(ORDER_BY_CLAUSE);
1722
1723 for (int i = 0; i < orderByFields.length; i++) {
1724 query.append(_ORDER_BY_ENTITY_ALIAS);
1725 query.append(orderByFields[i]);
1726
1727 if ((i + 1) < orderByFields.length) {
1728 if (orderByComparator.isAscending() ^ previous) {
1729 query.append(ORDER_BY_ASC_HAS_NEXT);
1730 }
1731 else {
1732 query.append(ORDER_BY_DESC_HAS_NEXT);
1733 }
1734 }
1735 else {
1736 if (orderByComparator.isAscending() ^ previous) {
1737 query.append(ORDER_BY_ASC);
1738 }
1739 else {
1740 query.append(ORDER_BY_DESC);
1741 }
1742 }
1743 }
1744 }
1745
1746 else {
1747 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1748 }
1749
1750 String sql = query.toString();
1751
1752 Query q = session.createQuery(sql);
1753
1754 q.setFirstResult(0);
1755 q.setMaxResults(2);
1756
1757 QueryPos qPos = QueryPos.getInstance(q);
1758
1759 qPos.add(companyId);
1760
1761 if (orderByComparator != null) {
1762 Object[] values = orderByComparator.getOrderByValues(mbCategory);
1763
1764 for (Object value : values) {
1765 qPos.add(value);
1766 }
1767 }
1768
1769 List<MBCategory> list = q.list();
1770
1771 if (list.size() == 2) {
1772 return list.get(1);
1773 }
1774 else {
1775 return null;
1776 }
1777 }
1778
1779
1787 public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
1788 throws SystemException {
1789 return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
1790 QueryUtil.ALL_POS, null);
1791 }
1792
1793
1807 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1808 int start, int end) throws SystemException {
1809 return findByG_P(groupId, parentCategoryId, start, end, null);
1810 }
1811
1812
1827 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1828 int start, int end, OrderByComparator orderByComparator)
1829 throws SystemException {
1830 Object[] finderArgs = new Object[] {
1831 groupId, parentCategoryId,
1832
1833 String.valueOf(start), String.valueOf(end),
1834 String.valueOf(orderByComparator)
1835 };
1836
1837 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1838 finderArgs, this);
1839
1840 if (list == null) {
1841 Session session = null;
1842
1843 try {
1844 session = openSession();
1845
1846 StringBundler query = null;
1847
1848 if (orderByComparator != null) {
1849 query = new StringBundler(4 +
1850 (orderByComparator.getOrderByFields().length * 3));
1851 }
1852 else {
1853 query = new StringBundler(4);
1854 }
1855
1856 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1857
1858 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1859
1860 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1861
1862 if (orderByComparator != null) {
1863 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1864 orderByComparator);
1865 }
1866
1867 else {
1868 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1869 }
1870
1871 String sql = query.toString();
1872
1873 Query q = session.createQuery(sql);
1874
1875 QueryPos qPos = QueryPos.getInstance(q);
1876
1877 qPos.add(groupId);
1878
1879 qPos.add(parentCategoryId);
1880
1881 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1882 end);
1883 }
1884 catch (Exception e) {
1885 throw processException(e);
1886 }
1887 finally {
1888 if (list == null) {
1889 list = new ArrayList<MBCategory>();
1890 }
1891
1892 cacheResult(list);
1893
1894 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
1895 list);
1896
1897 closeSession(session);
1898 }
1899 }
1900
1901 return list;
1902 }
1903
1904
1918 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
1919 OrderByComparator orderByComparator)
1920 throws NoSuchCategoryException, SystemException {
1921 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
1922 orderByComparator);
1923
1924 if (list.isEmpty()) {
1925 StringBundler msg = new StringBundler(6);
1926
1927 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1928
1929 msg.append("groupId=");
1930 msg.append(groupId);
1931
1932 msg.append(", parentCategoryId=");
1933 msg.append(parentCategoryId);
1934
1935 msg.append(StringPool.CLOSE_CURLY_BRACE);
1936
1937 throw new NoSuchCategoryException(msg.toString());
1938 }
1939 else {
1940 return list.get(0);
1941 }
1942 }
1943
1944
1958 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
1959 OrderByComparator orderByComparator)
1960 throws NoSuchCategoryException, SystemException {
1961 int count = countByG_P(groupId, parentCategoryId);
1962
1963 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
1964 count, orderByComparator);
1965
1966 if (list.isEmpty()) {
1967 StringBundler msg = new StringBundler(6);
1968
1969 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1970
1971 msg.append("groupId=");
1972 msg.append(groupId);
1973
1974 msg.append(", parentCategoryId=");
1975 msg.append(parentCategoryId);
1976
1977 msg.append(StringPool.CLOSE_CURLY_BRACE);
1978
1979 throw new NoSuchCategoryException(msg.toString());
1980 }
1981 else {
1982 return list.get(0);
1983 }
1984 }
1985
1986
2001 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
2002 long parentCategoryId, OrderByComparator orderByComparator)
2003 throws NoSuchCategoryException, SystemException {
2004 MBCategory mbCategory = findByPrimaryKey(categoryId);
2005
2006 Session session = null;
2007
2008 try {
2009 session = openSession();
2010
2011 MBCategory[] array = new MBCategoryImpl[3];
2012
2013 array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2014 parentCategoryId, orderByComparator, true);
2015
2016 array[1] = mbCategory;
2017
2018 array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2019 parentCategoryId, orderByComparator, false);
2020
2021 return array;
2022 }
2023 catch (Exception e) {
2024 throw processException(e);
2025 }
2026 finally {
2027 closeSession(session);
2028 }
2029 }
2030
2031 protected MBCategory getByG_P_PrevAndNext(Session session,
2032 MBCategory mbCategory, long groupId, long parentCategoryId,
2033 OrderByComparator orderByComparator, boolean previous) {
2034 StringBundler query = null;
2035
2036 if (orderByComparator != null) {
2037 query = new StringBundler(6 +
2038 (orderByComparator.getOrderByFields().length * 6));
2039 }
2040 else {
2041 query = new StringBundler(3);
2042 }
2043
2044 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2045
2046 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2047
2048 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2049
2050 if (orderByComparator != null) {
2051 String[] orderByFields = orderByComparator.getOrderByFields();
2052
2053 if (orderByFields.length > 0) {
2054 query.append(WHERE_AND);
2055 }
2056
2057 for (int i = 0; i < orderByFields.length; i++) {
2058 query.append(_ORDER_BY_ENTITY_ALIAS);
2059 query.append(orderByFields[i]);
2060
2061 if ((i + 1) < orderByFields.length) {
2062 if (orderByComparator.isAscending() ^ previous) {
2063 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2064 }
2065 else {
2066 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2067 }
2068 }
2069 else {
2070 if (orderByComparator.isAscending() ^ previous) {
2071 query.append(WHERE_GREATER_THAN);
2072 }
2073 else {
2074 query.append(WHERE_LESSER_THAN);
2075 }
2076 }
2077 }
2078
2079 query.append(ORDER_BY_CLAUSE);
2080
2081 for (int i = 0; i < orderByFields.length; i++) {
2082 query.append(_ORDER_BY_ENTITY_ALIAS);
2083 query.append(orderByFields[i]);
2084
2085 if ((i + 1) < orderByFields.length) {
2086 if (orderByComparator.isAscending() ^ previous) {
2087 query.append(ORDER_BY_ASC_HAS_NEXT);
2088 }
2089 else {
2090 query.append(ORDER_BY_DESC_HAS_NEXT);
2091 }
2092 }
2093 else {
2094 if (orderByComparator.isAscending() ^ previous) {
2095 query.append(ORDER_BY_ASC);
2096 }
2097 else {
2098 query.append(ORDER_BY_DESC);
2099 }
2100 }
2101 }
2102 }
2103
2104 else {
2105 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2106 }
2107
2108 String sql = query.toString();
2109
2110 Query q = session.createQuery(sql);
2111
2112 q.setFirstResult(0);
2113 q.setMaxResults(2);
2114
2115 QueryPos qPos = QueryPos.getInstance(q);
2116
2117 qPos.add(groupId);
2118
2119 qPos.add(parentCategoryId);
2120
2121 if (orderByComparator != null) {
2122 Object[] values = orderByComparator.getOrderByValues(mbCategory);
2123
2124 for (Object value : values) {
2125 qPos.add(value);
2126 }
2127 }
2128
2129 List<MBCategory> list = q.list();
2130
2131 if (list.size() == 2) {
2132 return list.get(1);
2133 }
2134 else {
2135 return null;
2136 }
2137 }
2138
2139
2151 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
2152 throws SystemException {
2153 return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2154 QueryUtil.ALL_POS, null);
2155 }
2156
2157
2171 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2172 int start, int end) throws SystemException {
2173 return findByG_P(groupId, parentCategoryIds, start, end, null);
2174 }
2175
2176
2191 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2192 int start, int end, OrderByComparator orderByComparator)
2193 throws SystemException {
2194 Object[] finderArgs = new Object[] {
2195 groupId, StringUtil.merge(parentCategoryIds),
2196
2197 String.valueOf(start), String.valueOf(end),
2198 String.valueOf(orderByComparator)
2199 };
2200
2201 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
2202 finderArgs, this);
2203
2204 if (list == null) {
2205 Session session = null;
2206
2207 try {
2208 session = openSession();
2209
2210 StringBundler query = new StringBundler();
2211
2212 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2213
2214 boolean conjunctionable = false;
2215
2216 if (conjunctionable) {
2217 query.append(WHERE_AND);
2218 }
2219
2220 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2221
2222 conjunctionable = true;
2223
2224 if ((parentCategoryIds == null) ||
2225 (parentCategoryIds.length > 0)) {
2226 if (conjunctionable) {
2227 query.append(WHERE_AND);
2228 }
2229
2230 query.append(StringPool.OPEN_PARENTHESIS);
2231
2232 for (int i = 0; i < parentCategoryIds.length; i++) {
2233 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2234
2235 if ((i + 1) < parentCategoryIds.length) {
2236 query.append(WHERE_OR);
2237 }
2238 }
2239
2240 query.append(StringPool.CLOSE_PARENTHESIS);
2241
2242 conjunctionable = true;
2243 }
2244
2245 if (orderByComparator != null) {
2246 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2247 orderByComparator);
2248 }
2249
2250 else {
2251 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2252 }
2253
2254 String sql = query.toString();
2255
2256 Query q = session.createQuery(sql);
2257
2258 QueryPos qPos = QueryPos.getInstance(q);
2259
2260 qPos.add(groupId);
2261
2262 if (parentCategoryIds != null) {
2263 qPos.add(parentCategoryIds);
2264 }
2265
2266 list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2267 end);
2268 }
2269 catch (Exception e) {
2270 throw processException(e);
2271 }
2272 finally {
2273 if (list == null) {
2274 list = new ArrayList<MBCategory>();
2275 }
2276
2277 cacheResult(list);
2278
2279 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P, finderArgs,
2280 list);
2281
2282 closeSession(session);
2283 }
2284 }
2285
2286 return list;
2287 }
2288
2289
2297 public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
2298 throws SystemException {
2299 return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2300 QueryUtil.ALL_POS, null);
2301 }
2302
2303
2317 public List<MBCategory> filterFindByG_P(long groupId,
2318 long parentCategoryId, int start, int end) throws SystemException {
2319 return filterFindByG_P(groupId, parentCategoryId, start, end, null);
2320 }
2321
2322
2337 public List<MBCategory> filterFindByG_P(long groupId,
2338 long parentCategoryId, int start, int end,
2339 OrderByComparator orderByComparator) throws SystemException {
2340 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2341 return findByG_P(groupId, parentCategoryId, start, end,
2342 orderByComparator);
2343 }
2344
2345 Session session = null;
2346
2347 try {
2348 session = openSession();
2349
2350 StringBundler query = null;
2351
2352 if (orderByComparator != null) {
2353 query = new StringBundler(4 +
2354 (orderByComparator.getOrderByFields().length * 3));
2355 }
2356 else {
2357 query = new StringBundler(4);
2358 }
2359
2360 if (getDB().isSupportsInlineDistinct()) {
2361 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2362 }
2363 else {
2364 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE);
2365 }
2366
2367 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2368
2369 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2370
2371 if (orderByComparator != null) {
2372 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2373 orderByComparator);
2374 }
2375
2376 else {
2377 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2378 }
2379
2380 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2381 MBCategory.class.getName(), _FILTER_COLUMN_PK,
2382 _FILTER_COLUMN_USERID, groupId);
2383
2384 SQLQuery q = session.createSQLQuery(sql);
2385
2386 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2387
2388 QueryPos qPos = QueryPos.getInstance(q);
2389
2390 qPos.add(groupId);
2391
2392 qPos.add(parentCategoryId);
2393
2394 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2395 }
2396 catch (Exception e) {
2397 throw processException(e);
2398 }
2399 finally {
2400 closeSession(session);
2401 }
2402 }
2403
2404
2416 public List<MBCategory> filterFindByG_P(long groupId,
2417 long[] parentCategoryIds) throws SystemException {
2418 return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2419 QueryUtil.ALL_POS, null);
2420 }
2421
2422
2436 public List<MBCategory> filterFindByG_P(long groupId,
2437 long[] parentCategoryIds, int start, int end) throws SystemException {
2438 return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
2439 }
2440
2441
2456 public List<MBCategory> filterFindByG_P(long groupId,
2457 long[] parentCategoryIds, int start, int end,
2458 OrderByComparator orderByComparator) throws SystemException {
2459 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2460 return findByG_P(groupId, parentCategoryIds, start, end,
2461 orderByComparator);
2462 }
2463
2464 Session session = null;
2465
2466 try {
2467 session = openSession();
2468
2469 StringBundler query = new StringBundler();
2470
2471 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2472
2473 boolean conjunctionable = false;
2474
2475 if (conjunctionable) {
2476 query.append(WHERE_AND);
2477 }
2478
2479 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2480
2481 conjunctionable = true;
2482
2483 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
2484 if (conjunctionable) {
2485 query.append(WHERE_AND);
2486 }
2487
2488 query.append(StringPool.OPEN_PARENTHESIS);
2489
2490 for (int i = 0; i < parentCategoryIds.length; i++) {
2491 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2492
2493 if ((i + 1) < parentCategoryIds.length) {
2494 query.append(WHERE_OR);
2495 }
2496 }
2497
2498 query.append(StringPool.CLOSE_PARENTHESIS);
2499
2500 conjunctionable = true;
2501 }
2502
2503 if (orderByComparator != null) {
2504 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2505 orderByComparator);
2506 }
2507
2508 else {
2509 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2510 }
2511
2512 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2513 MBCategory.class.getName(), _FILTER_COLUMN_PK,
2514 _FILTER_COLUMN_USERID, groupId);
2515
2516 SQLQuery q = session.createSQLQuery(sql);
2517
2518 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2519
2520 QueryPos qPos = QueryPos.getInstance(q);
2521
2522 qPos.add(groupId);
2523
2524 if (parentCategoryIds != null) {
2525 qPos.add(parentCategoryIds);
2526 }
2527
2528 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2529 }
2530 catch (Exception e) {
2531 throw processException(e);
2532 }
2533 finally {
2534 closeSession(session);
2535 }
2536 }
2537
2538
2544 public List<MBCategory> findAll() throws SystemException {
2545 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2546 }
2547
2548
2560 public List<MBCategory> findAll(int start, int end)
2561 throws SystemException {
2562 return findAll(start, end, null);
2563 }
2564
2565
2578 public List<MBCategory> findAll(int start, int end,
2579 OrderByComparator orderByComparator) throws SystemException {
2580 Object[] finderArgs = new Object[] {
2581 String.valueOf(start), String.valueOf(end),
2582 String.valueOf(orderByComparator)
2583 };
2584
2585 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2586 finderArgs, this);
2587
2588 if (list == null) {
2589 Session session = null;
2590
2591 try {
2592 session = openSession();
2593
2594 StringBundler query = null;
2595 String sql = null;
2596
2597 if (orderByComparator != null) {
2598 query = new StringBundler(2 +
2599 (orderByComparator.getOrderByFields().length * 3));
2600
2601 query.append(_SQL_SELECT_MBCATEGORY);
2602
2603 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2604 orderByComparator);
2605
2606 sql = query.toString();
2607 }
2608 else {
2609 sql = _SQL_SELECT_MBCATEGORY.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
2610 }
2611
2612 Query q = session.createQuery(sql);
2613
2614 if (orderByComparator == null) {
2615 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2616 start, end, false);
2617
2618 Collections.sort(list);
2619 }
2620 else {
2621 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2622 start, end);
2623 }
2624 }
2625 catch (Exception e) {
2626 throw processException(e);
2627 }
2628 finally {
2629 if (list == null) {
2630 list = new ArrayList<MBCategory>();
2631 }
2632
2633 cacheResult(list);
2634
2635 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
2636
2637 closeSession(session);
2638 }
2639 }
2640
2641 return list;
2642 }
2643
2644
2650 public void removeByUuid(String uuid) throws SystemException {
2651 for (MBCategory mbCategory : findByUuid(uuid)) {
2652 remove(mbCategory);
2653 }
2654 }
2655
2656
2663 public void removeByUUID_G(String uuid, long groupId)
2664 throws NoSuchCategoryException, SystemException {
2665 MBCategory mbCategory = findByUUID_G(uuid, groupId);
2666
2667 remove(mbCategory);
2668 }
2669
2670
2676 public void removeByGroupId(long groupId) throws SystemException {
2677 for (MBCategory mbCategory : findByGroupId(groupId)) {
2678 remove(mbCategory);
2679 }
2680 }
2681
2682
2688 public void removeByCompanyId(long companyId) throws SystemException {
2689 for (MBCategory mbCategory : findByCompanyId(companyId)) {
2690 remove(mbCategory);
2691 }
2692 }
2693
2694
2701 public void removeByG_P(long groupId, long parentCategoryId)
2702 throws SystemException {
2703 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
2704 remove(mbCategory);
2705 }
2706 }
2707
2708
2713 public void removeAll() throws SystemException {
2714 for (MBCategory mbCategory : findAll()) {
2715 remove(mbCategory);
2716 }
2717 }
2718
2719
2726 public int countByUuid(String uuid) throws SystemException {
2727 Object[] finderArgs = new Object[] { uuid };
2728
2729 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2730 finderArgs, this);
2731
2732 if (count == null) {
2733 Session session = null;
2734
2735 try {
2736 session = openSession();
2737
2738 StringBundler query = new StringBundler(2);
2739
2740 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2741
2742 if (uuid == null) {
2743 query.append(_FINDER_COLUMN_UUID_UUID_1);
2744 }
2745 else {
2746 if (uuid.equals(StringPool.BLANK)) {
2747 query.append(_FINDER_COLUMN_UUID_UUID_3);
2748 }
2749 else {
2750 query.append(_FINDER_COLUMN_UUID_UUID_2);
2751 }
2752 }
2753
2754 String sql = query.toString();
2755
2756 Query q = session.createQuery(sql);
2757
2758 QueryPos qPos = QueryPos.getInstance(q);
2759
2760 if (uuid != null) {
2761 qPos.add(uuid);
2762 }
2763
2764 count = (Long)q.uniqueResult();
2765 }
2766 catch (Exception e) {
2767 throw processException(e);
2768 }
2769 finally {
2770 if (count == null) {
2771 count = Long.valueOf(0);
2772 }
2773
2774 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2775 finderArgs, count);
2776
2777 closeSession(session);
2778 }
2779 }
2780
2781 return count.intValue();
2782 }
2783
2784
2792 public int countByUUID_G(String uuid, long groupId)
2793 throws SystemException {
2794 Object[] finderArgs = new Object[] { uuid, groupId };
2795
2796 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2797 finderArgs, this);
2798
2799 if (count == null) {
2800 Session session = null;
2801
2802 try {
2803 session = openSession();
2804
2805 StringBundler query = new StringBundler(3);
2806
2807 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2808
2809 if (uuid == null) {
2810 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2811 }
2812 else {
2813 if (uuid.equals(StringPool.BLANK)) {
2814 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2815 }
2816 else {
2817 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2818 }
2819 }
2820
2821 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2822
2823 String sql = query.toString();
2824
2825 Query q = session.createQuery(sql);
2826
2827 QueryPos qPos = QueryPos.getInstance(q);
2828
2829 if (uuid != null) {
2830 qPos.add(uuid);
2831 }
2832
2833 qPos.add(groupId);
2834
2835 count = (Long)q.uniqueResult();
2836 }
2837 catch (Exception e) {
2838 throw processException(e);
2839 }
2840 finally {
2841 if (count == null) {
2842 count = Long.valueOf(0);
2843 }
2844
2845 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2846 finderArgs, count);
2847
2848 closeSession(session);
2849 }
2850 }
2851
2852 return count.intValue();
2853 }
2854
2855
2862 public int countByGroupId(long groupId) throws SystemException {
2863 Object[] finderArgs = new Object[] { groupId };
2864
2865 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2866 finderArgs, this);
2867
2868 if (count == null) {
2869 Session session = null;
2870
2871 try {
2872 session = openSession();
2873
2874 StringBundler query = new StringBundler(2);
2875
2876 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2877
2878 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2879
2880 String sql = query.toString();
2881
2882 Query q = session.createQuery(sql);
2883
2884 QueryPos qPos = QueryPos.getInstance(q);
2885
2886 qPos.add(groupId);
2887
2888 count = (Long)q.uniqueResult();
2889 }
2890 catch (Exception e) {
2891 throw processException(e);
2892 }
2893 finally {
2894 if (count == null) {
2895 count = Long.valueOf(0);
2896 }
2897
2898 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2899 finderArgs, count);
2900
2901 closeSession(session);
2902 }
2903 }
2904
2905 return count.intValue();
2906 }
2907
2908
2915 public int filterCountByGroupId(long groupId) throws SystemException {
2916 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2917 return countByGroupId(groupId);
2918 }
2919
2920 Session session = null;
2921
2922 try {
2923 session = openSession();
2924
2925 StringBundler query = new StringBundler(2);
2926
2927 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2928
2929 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2930
2931 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2932 MBCategory.class.getName(), _FILTER_COLUMN_PK,
2933 _FILTER_COLUMN_USERID, groupId);
2934
2935 SQLQuery q = session.createSQLQuery(sql);
2936
2937 q.addScalar(COUNT_COLUMN_NAME,
2938 com.liferay.portal.kernel.dao.orm.Type.LONG);
2939
2940 QueryPos qPos = QueryPos.getInstance(q);
2941
2942 qPos.add(groupId);
2943
2944 Long count = (Long)q.uniqueResult();
2945
2946 return count.intValue();
2947 }
2948 catch (Exception e) {
2949 throw processException(e);
2950 }
2951 finally {
2952 closeSession(session);
2953 }
2954 }
2955
2956
2963 public int countByCompanyId(long companyId) throws SystemException {
2964 Object[] finderArgs = new Object[] { companyId };
2965
2966 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2967 finderArgs, this);
2968
2969 if (count == null) {
2970 Session session = null;
2971
2972 try {
2973 session = openSession();
2974
2975 StringBundler query = new StringBundler(2);
2976
2977 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2978
2979 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2980
2981 String sql = query.toString();
2982
2983 Query q = session.createQuery(sql);
2984
2985 QueryPos qPos = QueryPos.getInstance(q);
2986
2987 qPos.add(companyId);
2988
2989 count = (Long)q.uniqueResult();
2990 }
2991 catch (Exception e) {
2992 throw processException(e);
2993 }
2994 finally {
2995 if (count == null) {
2996 count = Long.valueOf(0);
2997 }
2998
2999 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3000 finderArgs, count);
3001
3002 closeSession(session);
3003 }
3004 }
3005
3006 return count.intValue();
3007 }
3008
3009
3017 public int countByG_P(long groupId, long parentCategoryId)
3018 throws SystemException {
3019 Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3020
3021 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3022 finderArgs, this);
3023
3024 if (count == null) {
3025 Session session = null;
3026
3027 try {
3028 session = openSession();
3029
3030 StringBundler query = new StringBundler(3);
3031
3032 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3033
3034 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3035
3036 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3037
3038 String sql = query.toString();
3039
3040 Query q = session.createQuery(sql);
3041
3042 QueryPos qPos = QueryPos.getInstance(q);
3043
3044 qPos.add(groupId);
3045
3046 qPos.add(parentCategoryId);
3047
3048 count = (Long)q.uniqueResult();
3049 }
3050 catch (Exception e) {
3051 throw processException(e);
3052 }
3053 finally {
3054 if (count == null) {
3055 count = Long.valueOf(0);
3056 }
3057
3058 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3059 count);
3060
3061 closeSession(session);
3062 }
3063 }
3064
3065 return count.intValue();
3066 }
3067
3068
3076 public int countByG_P(long groupId, long[] parentCategoryIds)
3077 throws SystemException {
3078 Object[] finderArgs = new Object[] {
3079 groupId, StringUtil.merge(parentCategoryIds)
3080 };
3081
3082 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3083 finderArgs, this);
3084
3085 if (count == null) {
3086 Session session = null;
3087
3088 try {
3089 session = openSession();
3090
3091 StringBundler query = new StringBundler();
3092
3093 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3094
3095 boolean conjunctionable = false;
3096
3097 if (conjunctionable) {
3098 query.append(WHERE_AND);
3099 }
3100
3101 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3102
3103 conjunctionable = true;
3104
3105 if ((parentCategoryIds == null) ||
3106 (parentCategoryIds.length > 0)) {
3107 if (conjunctionable) {
3108 query.append(WHERE_AND);
3109 }
3110
3111 query.append(StringPool.OPEN_PARENTHESIS);
3112
3113 for (int i = 0; i < parentCategoryIds.length; i++) {
3114 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3115
3116 if ((i + 1) < parentCategoryIds.length) {
3117 query.append(WHERE_OR);
3118 }
3119 }
3120
3121 query.append(StringPool.CLOSE_PARENTHESIS);
3122
3123 conjunctionable = true;
3124 }
3125
3126 String sql = query.toString();
3127
3128 Query q = session.createQuery(sql);
3129
3130 QueryPos qPos = QueryPos.getInstance(q);
3131
3132 qPos.add(groupId);
3133
3134 if (parentCategoryIds != null) {
3135 qPos.add(parentCategoryIds);
3136 }
3137
3138 count = (Long)q.uniqueResult();
3139 }
3140 catch (Exception e) {
3141 throw processException(e);
3142 }
3143 finally {
3144 if (count == null) {
3145 count = Long.valueOf(0);
3146 }
3147
3148 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3149 count);
3150
3151 closeSession(session);
3152 }
3153 }
3154
3155 return count.intValue();
3156 }
3157
3158
3166 public int filterCountByG_P(long groupId, long parentCategoryId)
3167 throws SystemException {
3168 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3169 return countByG_P(groupId, parentCategoryId);
3170 }
3171
3172 Session session = null;
3173
3174 try {
3175 session = openSession();
3176
3177 StringBundler query = new StringBundler(3);
3178
3179 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3180
3181 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3182
3183 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3184
3185 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3186 MBCategory.class.getName(), _FILTER_COLUMN_PK,
3187 _FILTER_COLUMN_USERID, groupId);
3188
3189 SQLQuery q = session.createSQLQuery(sql);
3190
3191 q.addScalar(COUNT_COLUMN_NAME,
3192 com.liferay.portal.kernel.dao.orm.Type.LONG);
3193
3194 QueryPos qPos = QueryPos.getInstance(q);
3195
3196 qPos.add(groupId);
3197
3198 qPos.add(parentCategoryId);
3199
3200 Long count = (Long)q.uniqueResult();
3201
3202 return count.intValue();
3203 }
3204 catch (Exception e) {
3205 throw processException(e);
3206 }
3207 finally {
3208 closeSession(session);
3209 }
3210 }
3211
3212
3220 public int filterCountByG_P(long groupId, long[] parentCategoryIds)
3221 throws SystemException {
3222 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3223 return countByG_P(groupId, parentCategoryIds);
3224 }
3225
3226 Session session = null;
3227
3228 try {
3229 session = openSession();
3230
3231 StringBundler query = new StringBundler();
3232
3233 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3234
3235 boolean conjunctionable = false;
3236
3237 if (conjunctionable) {
3238 query.append(WHERE_AND);
3239 }
3240
3241 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3242
3243 conjunctionable = true;
3244
3245 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3246 if (conjunctionable) {
3247 query.append(WHERE_AND);
3248 }
3249
3250 query.append(StringPool.OPEN_PARENTHESIS);
3251
3252 for (int i = 0; i < parentCategoryIds.length; i++) {
3253 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3254
3255 if ((i + 1) < parentCategoryIds.length) {
3256 query.append(WHERE_OR);
3257 }
3258 }
3259
3260 query.append(StringPool.CLOSE_PARENTHESIS);
3261
3262 conjunctionable = true;
3263 }
3264
3265 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3266 MBCategory.class.getName(), _FILTER_COLUMN_PK,
3267 _FILTER_COLUMN_USERID, groupId);
3268
3269 SQLQuery q = session.createSQLQuery(sql);
3270
3271 q.addScalar(COUNT_COLUMN_NAME,
3272 com.liferay.portal.kernel.dao.orm.Type.LONG);
3273
3274 QueryPos qPos = QueryPos.getInstance(q);
3275
3276 qPos.add(groupId);
3277
3278 if (parentCategoryIds != null) {
3279 qPos.add(parentCategoryIds);
3280 }
3281
3282 Long count = (Long)q.uniqueResult();
3283
3284 return count.intValue();
3285 }
3286 catch (Exception e) {
3287 throw processException(e);
3288 }
3289 finally {
3290 closeSession(session);
3291 }
3292 }
3293
3294
3300 public int countAll() throws SystemException {
3301 Object[] finderArgs = new Object[0];
3302
3303 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3304 finderArgs, this);
3305
3306 if (count == null) {
3307 Session session = null;
3308
3309 try {
3310 session = openSession();
3311
3312 Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
3313
3314 count = (Long)q.uniqueResult();
3315 }
3316 catch (Exception e) {
3317 throw processException(e);
3318 }
3319 finally {
3320 if (count == null) {
3321 count = Long.valueOf(0);
3322 }
3323
3324 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3325 count);
3326
3327 closeSession(session);
3328 }
3329 }
3330
3331 return count.intValue();
3332 }
3333
3334
3337 public void afterPropertiesSet() {
3338 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3339 com.liferay.portal.util.PropsUtil.get(
3340 "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
3341
3342 if (listenerClassNames.length > 0) {
3343 try {
3344 List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
3345
3346 for (String listenerClassName : listenerClassNames) {
3347 listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
3348 listenerClassName));
3349 }
3350
3351 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3352 }
3353 catch (Exception e) {
3354 _log.error(e);
3355 }
3356 }
3357 }
3358
3359 public void destroy() {
3360 EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
3361 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3362 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3363 }
3364
3365 @BeanReference(type = MBBanPersistence.class)
3366 protected MBBanPersistence mbBanPersistence;
3367 @BeanReference(type = MBCategoryPersistence.class)
3368 protected MBCategoryPersistence mbCategoryPersistence;
3369 @BeanReference(type = MBDiscussionPersistence.class)
3370 protected MBDiscussionPersistence mbDiscussionPersistence;
3371 @BeanReference(type = MBMailingListPersistence.class)
3372 protected MBMailingListPersistence mbMailingListPersistence;
3373 @BeanReference(type = MBMessagePersistence.class)
3374 protected MBMessagePersistence mbMessagePersistence;
3375 @BeanReference(type = MBMessageFlagPersistence.class)
3376 protected MBMessageFlagPersistence mbMessageFlagPersistence;
3377 @BeanReference(type = MBStatsUserPersistence.class)
3378 protected MBStatsUserPersistence mbStatsUserPersistence;
3379 @BeanReference(type = MBThreadPersistence.class)
3380 protected MBThreadPersistence mbThreadPersistence;
3381 @BeanReference(type = GroupPersistence.class)
3382 protected GroupPersistence groupPersistence;
3383 @BeanReference(type = ResourcePersistence.class)
3384 protected ResourcePersistence resourcePersistence;
3385 @BeanReference(type = SubscriptionPersistence.class)
3386 protected SubscriptionPersistence subscriptionPersistence;
3387 @BeanReference(type = UserPersistence.class)
3388 protected UserPersistence userPersistence;
3389 @BeanReference(type = AssetTagPersistence.class)
3390 protected AssetTagPersistence assetTagPersistence;
3391 @BeanReference(type = ExpandoValuePersistence.class)
3392 protected ExpandoValuePersistence expandoValuePersistence;
3393 private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
3394 private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
3395 private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
3396 private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
3397 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
3398 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
3399 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?)";
3400 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
3401 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
3402 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
3403 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
3404 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
3405 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
3406 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
3407 private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
3408 _removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
3409 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
3410 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
3411 _removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
3412
3413 private static String _removeConjunction(String sql) {
3414 int pos = sql.indexOf(" AND ");
3415
3416 if (pos != -1) {
3417 sql = sql.substring(0, pos);
3418 }
3419
3420 return sql;
3421 }
3422
3423 private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
3424 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE =
3425 "SELECT {mbCategory.*} FROM (SELECT DISTINCT categoryId FROM MBCategory) mbCategory2 INNER JOIN MBCategory mbCategory ON (mbCategory2.categoryId = mbCategory.categoryId) WHERE ";
3426 private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
3427 private static final String _FILTER_COLUMN_PK = "mbCategory.categoryId";
3428 private static final String _FILTER_COLUMN_USERID = "mbCategory.userId";
3429 private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
3430 private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
3431 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
3432 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
3433 private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
3434 }