001
014
015 package com.liferay.portlet.messageboards.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderPath;
022 import com.liferay.portal.kernel.dao.orm.Query;
023 import com.liferay.portal.kernel.dao.orm.QueryPos;
024 import com.liferay.portal.kernel.dao.orm.QueryUtil;
025 import com.liferay.portal.kernel.dao.orm.SQLQuery;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.ArrayUtil;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.SetUtil;
032 import com.liferay.portal.kernel.util.StringBundler;
033 import com.liferay.portal.kernel.util.StringPool;
034 import com.liferay.portal.kernel.util.StringUtil;
035 import com.liferay.portal.kernel.util.Validator;
036 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
037 import com.liferay.portal.model.CacheModel;
038 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
039 import com.liferay.portal.service.ServiceContext;
040 import com.liferay.portal.service.ServiceContextThreadLocal;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.messageboards.NoSuchCategoryException;
044 import com.liferay.portlet.messageboards.model.MBCategory;
045 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
046 import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
047 import com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence;
048
049 import java.io.Serializable;
050
051 import java.util.Collections;
052 import java.util.Date;
053 import java.util.HashMap;
054 import java.util.HashSet;
055 import java.util.Iterator;
056 import java.util.List;
057 import java.util.Map;
058 import java.util.Set;
059
060
072 @ProviderType
073 public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
074 implements MBCategoryPersistence {
075
080 public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List1";
083 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List2";
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
086 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
089 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
092 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
095 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097 new String[] {
098 String.class.getName(),
099
100 Integer.class.getName(), Integer.class.getName(),
101 OrderByComparator.class.getName()
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
104 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106 new String[] { String.class.getName() },
107 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
108 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
109 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
111 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
113 new String[] { String.class.getName() });
114
115
121 @Override
122 public List<MBCategory> findByUuid(String uuid) {
123 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124 }
125
126
138 @Override
139 public List<MBCategory> findByUuid(String uuid, int start, int end) {
140 return findByUuid(uuid, start, end, null);
141 }
142
143
156 @Override
157 public List<MBCategory> findByUuid(String uuid, int start, int end,
158 OrderByComparator<MBCategory> orderByComparator) {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171 finderArgs = new Object[] { uuid, start, end, orderByComparator };
172 }
173
174 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
175 finderArgs, this);
176
177 if ((list != null) && !list.isEmpty()) {
178 for (MBCategory mbCategory : list) {
179 if (!Validator.equals(uuid, mbCategory.getUuid())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(3 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(3);
196 }
197
198 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
199
200 boolean bindUuid = false;
201
202 if (uuid == null) {
203 query.append(_FINDER_COLUMN_UUID_UUID_1);
204 }
205 else if (uuid.equals(StringPool.BLANK)) {
206 query.append(_FINDER_COLUMN_UUID_UUID_3);
207 }
208 else {
209 bindUuid = true;
210
211 query.append(_FINDER_COLUMN_UUID_UUID_2);
212 }
213
214 if (orderByComparator != null) {
215 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
216 orderByComparator);
217 }
218 else
219 if (pagination) {
220 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
221 }
222
223 String sql = query.toString();
224
225 Session session = null;
226
227 try {
228 session = openSession();
229
230 Query q = session.createQuery(sql);
231
232 QueryPos qPos = QueryPos.getInstance(q);
233
234 if (bindUuid) {
235 qPos.add(uuid);
236 }
237
238 if (!pagination) {
239 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
240 start, end, false);
241
242 Collections.sort(list);
243
244 list = Collections.unmodifiableList(list);
245 }
246 else {
247 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
248 start, end);
249 }
250
251 cacheResult(list);
252
253 FinderCacheUtil.putResult(finderPath, finderArgs, list);
254 }
255 catch (Exception e) {
256 FinderCacheUtil.removeResult(finderPath, finderArgs);
257
258 throw processException(e);
259 }
260 finally {
261 closeSession(session);
262 }
263 }
264
265 return list;
266 }
267
268
276 @Override
277 public MBCategory findByUuid_First(String uuid,
278 OrderByComparator<MBCategory> orderByComparator)
279 throws NoSuchCategoryException {
280 MBCategory mbCategory = fetchByUuid_First(uuid, orderByComparator);
281
282 if (mbCategory != null) {
283 return mbCategory;
284 }
285
286 StringBundler msg = new StringBundler(4);
287
288 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
289
290 msg.append("uuid=");
291 msg.append(uuid);
292
293 msg.append(StringPool.CLOSE_CURLY_BRACE);
294
295 throw new NoSuchCategoryException(msg.toString());
296 }
297
298
305 @Override
306 public MBCategory fetchByUuid_First(String uuid,
307 OrderByComparator<MBCategory> orderByComparator) {
308 List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
309
310 if (!list.isEmpty()) {
311 return list.get(0);
312 }
313
314 return null;
315 }
316
317
325 @Override
326 public MBCategory findByUuid_Last(String uuid,
327 OrderByComparator<MBCategory> orderByComparator)
328 throws NoSuchCategoryException {
329 MBCategory mbCategory = fetchByUuid_Last(uuid, orderByComparator);
330
331 if (mbCategory != null) {
332 return mbCategory;
333 }
334
335 StringBundler msg = new StringBundler(4);
336
337 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
338
339 msg.append("uuid=");
340 msg.append(uuid);
341
342 msg.append(StringPool.CLOSE_CURLY_BRACE);
343
344 throw new NoSuchCategoryException(msg.toString());
345 }
346
347
354 @Override
355 public MBCategory fetchByUuid_Last(String uuid,
356 OrderByComparator<MBCategory> orderByComparator) {
357 int count = countByUuid(uuid);
358
359 if (count == 0) {
360 return null;
361 }
362
363 List<MBCategory> list = findByUuid(uuid, count - 1, count,
364 orderByComparator);
365
366 if (!list.isEmpty()) {
367 return list.get(0);
368 }
369
370 return null;
371 }
372
373
382 @Override
383 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
384 OrderByComparator<MBCategory> orderByComparator)
385 throws NoSuchCategoryException {
386 MBCategory mbCategory = findByPrimaryKey(categoryId);
387
388 Session session = null;
389
390 try {
391 session = openSession();
392
393 MBCategory[] array = new MBCategoryImpl[3];
394
395 array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
396 orderByComparator, true);
397
398 array[1] = mbCategory;
399
400 array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
401 orderByComparator, false);
402
403 return array;
404 }
405 catch (Exception e) {
406 throw processException(e);
407 }
408 finally {
409 closeSession(session);
410 }
411 }
412
413 protected MBCategory getByUuid_PrevAndNext(Session session,
414 MBCategory mbCategory, String uuid,
415 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
416 StringBundler query = null;
417
418 if (orderByComparator != null) {
419 query = new StringBundler(6 +
420 (orderByComparator.getOrderByFields().length * 6));
421 }
422 else {
423 query = new StringBundler(3);
424 }
425
426 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
427
428 boolean bindUuid = false;
429
430 if (uuid == null) {
431 query.append(_FINDER_COLUMN_UUID_UUID_1);
432 }
433 else if (uuid.equals(StringPool.BLANK)) {
434 query.append(_FINDER_COLUMN_UUID_UUID_3);
435 }
436 else {
437 bindUuid = true;
438
439 query.append(_FINDER_COLUMN_UUID_UUID_2);
440 }
441
442 if (orderByComparator != null) {
443 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
444
445 if (orderByConditionFields.length > 0) {
446 query.append(WHERE_AND);
447 }
448
449 for (int i = 0; i < orderByConditionFields.length; i++) {
450 query.append(_ORDER_BY_ENTITY_ALIAS);
451 query.append(orderByConditionFields[i]);
452
453 if ((i + 1) < orderByConditionFields.length) {
454 if (orderByComparator.isAscending() ^ previous) {
455 query.append(WHERE_GREATER_THAN_HAS_NEXT);
456 }
457 else {
458 query.append(WHERE_LESSER_THAN_HAS_NEXT);
459 }
460 }
461 else {
462 if (orderByComparator.isAscending() ^ previous) {
463 query.append(WHERE_GREATER_THAN);
464 }
465 else {
466 query.append(WHERE_LESSER_THAN);
467 }
468 }
469 }
470
471 query.append(ORDER_BY_CLAUSE);
472
473 String[] orderByFields = orderByComparator.getOrderByFields();
474
475 for (int i = 0; i < orderByFields.length; i++) {
476 query.append(_ORDER_BY_ENTITY_ALIAS);
477 query.append(orderByFields[i]);
478
479 if ((i + 1) < orderByFields.length) {
480 if (orderByComparator.isAscending() ^ previous) {
481 query.append(ORDER_BY_ASC_HAS_NEXT);
482 }
483 else {
484 query.append(ORDER_BY_DESC_HAS_NEXT);
485 }
486 }
487 else {
488 if (orderByComparator.isAscending() ^ previous) {
489 query.append(ORDER_BY_ASC);
490 }
491 else {
492 query.append(ORDER_BY_DESC);
493 }
494 }
495 }
496 }
497 else {
498 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
499 }
500
501 String sql = query.toString();
502
503 Query q = session.createQuery(sql);
504
505 q.setFirstResult(0);
506 q.setMaxResults(2);
507
508 QueryPos qPos = QueryPos.getInstance(q);
509
510 if (bindUuid) {
511 qPos.add(uuid);
512 }
513
514 if (orderByComparator != null) {
515 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
516
517 for (Object value : values) {
518 qPos.add(value);
519 }
520 }
521
522 List<MBCategory> list = q.list();
523
524 if (list.size() == 2) {
525 return list.get(1);
526 }
527 else {
528 return null;
529 }
530 }
531
532
537 @Override
538 public void removeByUuid(String uuid) {
539 for (MBCategory mbCategory : findByUuid(uuid, QueryUtil.ALL_POS,
540 QueryUtil.ALL_POS, null)) {
541 remove(mbCategory);
542 }
543 }
544
545
551 @Override
552 public int countByUuid(String uuid) {
553 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
554
555 Object[] finderArgs = new Object[] { uuid };
556
557 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
558 this);
559
560 if (count == null) {
561 StringBundler query = new StringBundler(2);
562
563 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
564
565 boolean bindUuid = false;
566
567 if (uuid == null) {
568 query.append(_FINDER_COLUMN_UUID_UUID_1);
569 }
570 else if (uuid.equals(StringPool.BLANK)) {
571 query.append(_FINDER_COLUMN_UUID_UUID_3);
572 }
573 else {
574 bindUuid = true;
575
576 query.append(_FINDER_COLUMN_UUID_UUID_2);
577 }
578
579 String sql = query.toString();
580
581 Session session = null;
582
583 try {
584 session = openSession();
585
586 Query q = session.createQuery(sql);
587
588 QueryPos qPos = QueryPos.getInstance(q);
589
590 if (bindUuid) {
591 qPos.add(uuid);
592 }
593
594 count = (Long)q.uniqueResult();
595
596 FinderCacheUtil.putResult(finderPath, finderArgs, count);
597 }
598 catch (Exception e) {
599 FinderCacheUtil.removeResult(finderPath, finderArgs);
600
601 throw processException(e);
602 }
603 finally {
604 closeSession(session);
605 }
606 }
607
608 return count.intValue();
609 }
610
611 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
612 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
613 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '')";
614 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
615 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
616 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
617 new String[] { String.class.getName(), Long.class.getName() },
618 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
619 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
620 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
621 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
622 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
623 new String[] { String.class.getName(), Long.class.getName() });
624
625
633 @Override
634 public MBCategory findByUUID_G(String uuid, long groupId)
635 throws NoSuchCategoryException {
636 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
637
638 if (mbCategory == null) {
639 StringBundler msg = new StringBundler(6);
640
641 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
642
643 msg.append("uuid=");
644 msg.append(uuid);
645
646 msg.append(", groupId=");
647 msg.append(groupId);
648
649 msg.append(StringPool.CLOSE_CURLY_BRACE);
650
651 if (_log.isWarnEnabled()) {
652 _log.warn(msg.toString());
653 }
654
655 throw new NoSuchCategoryException(msg.toString());
656 }
657
658 return mbCategory;
659 }
660
661
668 @Override
669 public MBCategory fetchByUUID_G(String uuid, long groupId) {
670 return fetchByUUID_G(uuid, groupId, true);
671 }
672
673
681 @Override
682 public MBCategory fetchByUUID_G(String uuid, long groupId,
683 boolean retrieveFromCache) {
684 Object[] finderArgs = new Object[] { uuid, groupId };
685
686 Object result = null;
687
688 if (retrieveFromCache) {
689 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
690 finderArgs, this);
691 }
692
693 if (result instanceof MBCategory) {
694 MBCategory mbCategory = (MBCategory)result;
695
696 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
697 (groupId != mbCategory.getGroupId())) {
698 result = null;
699 }
700 }
701
702 if (result == null) {
703 StringBundler query = new StringBundler(4);
704
705 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
706
707 boolean bindUuid = false;
708
709 if (uuid == null) {
710 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
711 }
712 else if (uuid.equals(StringPool.BLANK)) {
713 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
714 }
715 else {
716 bindUuid = true;
717
718 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
719 }
720
721 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
722
723 String sql = query.toString();
724
725 Session session = null;
726
727 try {
728 session = openSession();
729
730 Query q = session.createQuery(sql);
731
732 QueryPos qPos = QueryPos.getInstance(q);
733
734 if (bindUuid) {
735 qPos.add(uuid);
736 }
737
738 qPos.add(groupId);
739
740 List<MBCategory> list = q.list();
741
742 if (list.isEmpty()) {
743 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
744 finderArgs, list);
745 }
746 else {
747 MBCategory mbCategory = list.get(0);
748
749 result = mbCategory;
750
751 cacheResult(mbCategory);
752
753 if ((mbCategory.getUuid() == null) ||
754 !mbCategory.getUuid().equals(uuid) ||
755 (mbCategory.getGroupId() != groupId)) {
756 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs, mbCategory);
758 }
759 }
760 }
761 catch (Exception e) {
762 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
763 finderArgs);
764
765 throw processException(e);
766 }
767 finally {
768 closeSession(session);
769 }
770 }
771
772 if (result instanceof List<?>) {
773 return null;
774 }
775 else {
776 return (MBCategory)result;
777 }
778 }
779
780
787 @Override
788 public MBCategory removeByUUID_G(String uuid, long groupId)
789 throws NoSuchCategoryException {
790 MBCategory mbCategory = findByUUID_G(uuid, groupId);
791
792 return remove(mbCategory);
793 }
794
795
802 @Override
803 public int countByUUID_G(String uuid, long groupId) {
804 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
805
806 Object[] finderArgs = new Object[] { uuid, groupId };
807
808 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
809 this);
810
811 if (count == null) {
812 StringBundler query = new StringBundler(3);
813
814 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
815
816 boolean bindUuid = false;
817
818 if (uuid == null) {
819 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
820 }
821 else if (uuid.equals(StringPool.BLANK)) {
822 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
823 }
824 else {
825 bindUuid = true;
826
827 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
828 }
829
830 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
831
832 String sql = query.toString();
833
834 Session session = null;
835
836 try {
837 session = openSession();
838
839 Query q = session.createQuery(sql);
840
841 QueryPos qPos = QueryPos.getInstance(q);
842
843 if (bindUuid) {
844 qPos.add(uuid);
845 }
846
847 qPos.add(groupId);
848
849 count = (Long)q.uniqueResult();
850
851 FinderCacheUtil.putResult(finderPath, finderArgs, count);
852 }
853 catch (Exception e) {
854 FinderCacheUtil.removeResult(finderPath, finderArgs);
855
856 throw processException(e);
857 }
858 finally {
859 closeSession(session);
860 }
861 }
862
863 return count.intValue();
864 }
865
866 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
867 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
868 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
869 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
870 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
871 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
872 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
873 new String[] {
874 String.class.getName(), Long.class.getName(),
875
876 Integer.class.getName(), Integer.class.getName(),
877 OrderByComparator.class.getName()
878 });
879 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
880 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
881 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
882 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
883 new String[] { String.class.getName(), Long.class.getName() },
884 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
885 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
886 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
887 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
888 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
889 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
890 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
891 new String[] { String.class.getName(), Long.class.getName() });
892
893
900 @Override
901 public List<MBCategory> findByUuid_C(String uuid, long companyId) {
902 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
903 QueryUtil.ALL_POS, null);
904 }
905
906
919 @Override
920 public List<MBCategory> findByUuid_C(String uuid, long companyId,
921 int start, int end) {
922 return findByUuid_C(uuid, companyId, start, end, null);
923 }
924
925
939 @Override
940 public List<MBCategory> findByUuid_C(String uuid, long companyId,
941 int start, int end, OrderByComparator<MBCategory> orderByComparator) {
942 boolean pagination = true;
943 FinderPath finderPath = null;
944 Object[] finderArgs = null;
945
946 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
947 (orderByComparator == null)) {
948 pagination = false;
949 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
950 finderArgs = new Object[] { uuid, companyId };
951 }
952 else {
953 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
954 finderArgs = new Object[] {
955 uuid, companyId,
956
957 start, end, orderByComparator
958 };
959 }
960
961 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
962 finderArgs, this);
963
964 if ((list != null) && !list.isEmpty()) {
965 for (MBCategory mbCategory : list) {
966 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
967 (companyId != mbCategory.getCompanyId())) {
968 list = null;
969
970 break;
971 }
972 }
973 }
974
975 if (list == null) {
976 StringBundler query = null;
977
978 if (orderByComparator != null) {
979 query = new StringBundler(4 +
980 (orderByComparator.getOrderByFields().length * 3));
981 }
982 else {
983 query = new StringBundler(4);
984 }
985
986 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
987
988 boolean bindUuid = false;
989
990 if (uuid == null) {
991 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
992 }
993 else if (uuid.equals(StringPool.BLANK)) {
994 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
995 }
996 else {
997 bindUuid = true;
998
999 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1000 }
1001
1002 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1003
1004 if (orderByComparator != null) {
1005 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1006 orderByComparator);
1007 }
1008 else
1009 if (pagination) {
1010 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1011 }
1012
1013 String sql = query.toString();
1014
1015 Session session = null;
1016
1017 try {
1018 session = openSession();
1019
1020 Query q = session.createQuery(sql);
1021
1022 QueryPos qPos = QueryPos.getInstance(q);
1023
1024 if (bindUuid) {
1025 qPos.add(uuid);
1026 }
1027
1028 qPos.add(companyId);
1029
1030 if (!pagination) {
1031 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1032 start, end, false);
1033
1034 Collections.sort(list);
1035
1036 list = Collections.unmodifiableList(list);
1037 }
1038 else {
1039 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1040 start, end);
1041 }
1042
1043 cacheResult(list);
1044
1045 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1046 }
1047 catch (Exception e) {
1048 FinderCacheUtil.removeResult(finderPath, finderArgs);
1049
1050 throw processException(e);
1051 }
1052 finally {
1053 closeSession(session);
1054 }
1055 }
1056
1057 return list;
1058 }
1059
1060
1069 @Override
1070 public MBCategory findByUuid_C_First(String uuid, long companyId,
1071 OrderByComparator<MBCategory> orderByComparator)
1072 throws NoSuchCategoryException {
1073 MBCategory mbCategory = fetchByUuid_C_First(uuid, companyId,
1074 orderByComparator);
1075
1076 if (mbCategory != null) {
1077 return mbCategory;
1078 }
1079
1080 StringBundler msg = new StringBundler(6);
1081
1082 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1083
1084 msg.append("uuid=");
1085 msg.append(uuid);
1086
1087 msg.append(", companyId=");
1088 msg.append(companyId);
1089
1090 msg.append(StringPool.CLOSE_CURLY_BRACE);
1091
1092 throw new NoSuchCategoryException(msg.toString());
1093 }
1094
1095
1103 @Override
1104 public MBCategory fetchByUuid_C_First(String uuid, long companyId,
1105 OrderByComparator<MBCategory> orderByComparator) {
1106 List<MBCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1107 orderByComparator);
1108
1109 if (!list.isEmpty()) {
1110 return list.get(0);
1111 }
1112
1113 return null;
1114 }
1115
1116
1125 @Override
1126 public MBCategory findByUuid_C_Last(String uuid, long companyId,
1127 OrderByComparator<MBCategory> orderByComparator)
1128 throws NoSuchCategoryException {
1129 MBCategory mbCategory = fetchByUuid_C_Last(uuid, companyId,
1130 orderByComparator);
1131
1132 if (mbCategory != null) {
1133 return mbCategory;
1134 }
1135
1136 StringBundler msg = new StringBundler(6);
1137
1138 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139
1140 msg.append("uuid=");
1141 msg.append(uuid);
1142
1143 msg.append(", companyId=");
1144 msg.append(companyId);
1145
1146 msg.append(StringPool.CLOSE_CURLY_BRACE);
1147
1148 throw new NoSuchCategoryException(msg.toString());
1149 }
1150
1151
1159 @Override
1160 public MBCategory fetchByUuid_C_Last(String uuid, long companyId,
1161 OrderByComparator<MBCategory> orderByComparator) {
1162 int count = countByUuid_C(uuid, companyId);
1163
1164 if (count == 0) {
1165 return null;
1166 }
1167
1168 List<MBCategory> list = findByUuid_C(uuid, companyId, count - 1, count,
1169 orderByComparator);
1170
1171 if (!list.isEmpty()) {
1172 return list.get(0);
1173 }
1174
1175 return null;
1176 }
1177
1178
1188 @Override
1189 public MBCategory[] findByUuid_C_PrevAndNext(long categoryId, String uuid,
1190 long companyId, OrderByComparator<MBCategory> orderByComparator)
1191 throws NoSuchCategoryException {
1192 MBCategory mbCategory = findByPrimaryKey(categoryId);
1193
1194 Session session = null;
1195
1196 try {
1197 session = openSession();
1198
1199 MBCategory[] array = new MBCategoryImpl[3];
1200
1201 array[0] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1202 companyId, orderByComparator, true);
1203
1204 array[1] = mbCategory;
1205
1206 array[2] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1207 companyId, orderByComparator, false);
1208
1209 return array;
1210 }
1211 catch (Exception e) {
1212 throw processException(e);
1213 }
1214 finally {
1215 closeSession(session);
1216 }
1217 }
1218
1219 protected MBCategory getByUuid_C_PrevAndNext(Session session,
1220 MBCategory mbCategory, String uuid, long companyId,
1221 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
1222 StringBundler query = null;
1223
1224 if (orderByComparator != null) {
1225 query = new StringBundler(6 +
1226 (orderByComparator.getOrderByFields().length * 6));
1227 }
1228 else {
1229 query = new StringBundler(3);
1230 }
1231
1232 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1233
1234 boolean bindUuid = false;
1235
1236 if (uuid == null) {
1237 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1238 }
1239 else if (uuid.equals(StringPool.BLANK)) {
1240 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1241 }
1242 else {
1243 bindUuid = true;
1244
1245 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1246 }
1247
1248 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1249
1250 if (orderByComparator != null) {
1251 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1252
1253 if (orderByConditionFields.length > 0) {
1254 query.append(WHERE_AND);
1255 }
1256
1257 for (int i = 0; i < orderByConditionFields.length; i++) {
1258 query.append(_ORDER_BY_ENTITY_ALIAS);
1259 query.append(orderByConditionFields[i]);
1260
1261 if ((i + 1) < orderByConditionFields.length) {
1262 if (orderByComparator.isAscending() ^ previous) {
1263 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1264 }
1265 else {
1266 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1267 }
1268 }
1269 else {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(WHERE_GREATER_THAN);
1272 }
1273 else {
1274 query.append(WHERE_LESSER_THAN);
1275 }
1276 }
1277 }
1278
1279 query.append(ORDER_BY_CLAUSE);
1280
1281 String[] orderByFields = orderByComparator.getOrderByFields();
1282
1283 for (int i = 0; i < orderByFields.length; i++) {
1284 query.append(_ORDER_BY_ENTITY_ALIAS);
1285 query.append(orderByFields[i]);
1286
1287 if ((i + 1) < orderByFields.length) {
1288 if (orderByComparator.isAscending() ^ previous) {
1289 query.append(ORDER_BY_ASC_HAS_NEXT);
1290 }
1291 else {
1292 query.append(ORDER_BY_DESC_HAS_NEXT);
1293 }
1294 }
1295 else {
1296 if (orderByComparator.isAscending() ^ previous) {
1297 query.append(ORDER_BY_ASC);
1298 }
1299 else {
1300 query.append(ORDER_BY_DESC);
1301 }
1302 }
1303 }
1304 }
1305 else {
1306 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1307 }
1308
1309 String sql = query.toString();
1310
1311 Query q = session.createQuery(sql);
1312
1313 q.setFirstResult(0);
1314 q.setMaxResults(2);
1315
1316 QueryPos qPos = QueryPos.getInstance(q);
1317
1318 if (bindUuid) {
1319 qPos.add(uuid);
1320 }
1321
1322 qPos.add(companyId);
1323
1324 if (orderByComparator != null) {
1325 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1326
1327 for (Object value : values) {
1328 qPos.add(value);
1329 }
1330 }
1331
1332 List<MBCategory> list = q.list();
1333
1334 if (list.size() == 2) {
1335 return list.get(1);
1336 }
1337 else {
1338 return null;
1339 }
1340 }
1341
1342
1348 @Override
1349 public void removeByUuid_C(String uuid, long companyId) {
1350 for (MBCategory mbCategory : findByUuid_C(uuid, companyId,
1351 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1352 remove(mbCategory);
1353 }
1354 }
1355
1356
1363 @Override
1364 public int countByUuid_C(String uuid, long companyId) {
1365 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1366
1367 Object[] finderArgs = new Object[] { uuid, companyId };
1368
1369 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1370 this);
1371
1372 if (count == null) {
1373 StringBundler query = new StringBundler(3);
1374
1375 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
1376
1377 boolean bindUuid = false;
1378
1379 if (uuid == null) {
1380 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1381 }
1382 else if (uuid.equals(StringPool.BLANK)) {
1383 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1384 }
1385 else {
1386 bindUuid = true;
1387
1388 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1389 }
1390
1391 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1392
1393 String sql = query.toString();
1394
1395 Session session = null;
1396
1397 try {
1398 session = openSession();
1399
1400 Query q = session.createQuery(sql);
1401
1402 QueryPos qPos = QueryPos.getInstance(q);
1403
1404 if (bindUuid) {
1405 qPos.add(uuid);
1406 }
1407
1408 qPos.add(companyId);
1409
1410 count = (Long)q.uniqueResult();
1411
1412 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1413 }
1414 catch (Exception e) {
1415 FinderCacheUtil.removeResult(finderPath, finderArgs);
1416
1417 throw processException(e);
1418 }
1419 finally {
1420 closeSession(session);
1421 }
1422 }
1423
1424 return count.intValue();
1425 }
1426
1427 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbCategory.uuid IS NULL AND ";
1428 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbCategory.uuid = ? AND ";
1429 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
1430 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbCategory.companyId = ?";
1431 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1432 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1433 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1434 new String[] {
1435 Long.class.getName(),
1436
1437 Integer.class.getName(), Integer.class.getName(),
1438 OrderByComparator.class.getName()
1439 });
1440 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1441 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1442 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1443 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1444 new String[] { Long.class.getName() },
1445 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1446 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
1447 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
1448 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1449 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1450 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1451 new String[] { Long.class.getName() });
1452
1453
1459 @Override
1460 public List<MBCategory> findByGroupId(long groupId) {
1461 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1462 }
1463
1464
1476 @Override
1477 public List<MBCategory> findByGroupId(long groupId, int start, int end) {
1478 return findByGroupId(groupId, start, end, null);
1479 }
1480
1481
1494 @Override
1495 public List<MBCategory> findByGroupId(long groupId, int start, int end,
1496 OrderByComparator<MBCategory> orderByComparator) {
1497 boolean pagination = true;
1498 FinderPath finderPath = null;
1499 Object[] finderArgs = null;
1500
1501 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1502 (orderByComparator == null)) {
1503 pagination = false;
1504 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1505 finderArgs = new Object[] { groupId };
1506 }
1507 else {
1508 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1509 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1510 }
1511
1512 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1513 finderArgs, this);
1514
1515 if ((list != null) && !list.isEmpty()) {
1516 for (MBCategory mbCategory : list) {
1517 if ((groupId != mbCategory.getGroupId())) {
1518 list = null;
1519
1520 break;
1521 }
1522 }
1523 }
1524
1525 if (list == null) {
1526 StringBundler query = null;
1527
1528 if (orderByComparator != null) {
1529 query = new StringBundler(3 +
1530 (orderByComparator.getOrderByFields().length * 3));
1531 }
1532 else {
1533 query = new StringBundler(3);
1534 }
1535
1536 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1537
1538 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1539
1540 if (orderByComparator != null) {
1541 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1542 orderByComparator);
1543 }
1544 else
1545 if (pagination) {
1546 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1547 }
1548
1549 String sql = query.toString();
1550
1551 Session session = null;
1552
1553 try {
1554 session = openSession();
1555
1556 Query q = session.createQuery(sql);
1557
1558 QueryPos qPos = QueryPos.getInstance(q);
1559
1560 qPos.add(groupId);
1561
1562 if (!pagination) {
1563 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1564 start, end, false);
1565
1566 Collections.sort(list);
1567
1568 list = Collections.unmodifiableList(list);
1569 }
1570 else {
1571 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1572 start, end);
1573 }
1574
1575 cacheResult(list);
1576
1577 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1578 }
1579 catch (Exception e) {
1580 FinderCacheUtil.removeResult(finderPath, finderArgs);
1581
1582 throw processException(e);
1583 }
1584 finally {
1585 closeSession(session);
1586 }
1587 }
1588
1589 return list;
1590 }
1591
1592
1600 @Override
1601 public MBCategory findByGroupId_First(long groupId,
1602 OrderByComparator<MBCategory> orderByComparator)
1603 throws NoSuchCategoryException {
1604 MBCategory mbCategory = fetchByGroupId_First(groupId, orderByComparator);
1605
1606 if (mbCategory != null) {
1607 return mbCategory;
1608 }
1609
1610 StringBundler msg = new StringBundler(4);
1611
1612 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1613
1614 msg.append("groupId=");
1615 msg.append(groupId);
1616
1617 msg.append(StringPool.CLOSE_CURLY_BRACE);
1618
1619 throw new NoSuchCategoryException(msg.toString());
1620 }
1621
1622
1629 @Override
1630 public MBCategory fetchByGroupId_First(long groupId,
1631 OrderByComparator<MBCategory> orderByComparator) {
1632 List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1633
1634 if (!list.isEmpty()) {
1635 return list.get(0);
1636 }
1637
1638 return null;
1639 }
1640
1641
1649 @Override
1650 public MBCategory findByGroupId_Last(long groupId,
1651 OrderByComparator<MBCategory> orderByComparator)
1652 throws NoSuchCategoryException {
1653 MBCategory mbCategory = fetchByGroupId_Last(groupId, orderByComparator);
1654
1655 if (mbCategory != null) {
1656 return mbCategory;
1657 }
1658
1659 StringBundler msg = new StringBundler(4);
1660
1661 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1662
1663 msg.append("groupId=");
1664 msg.append(groupId);
1665
1666 msg.append(StringPool.CLOSE_CURLY_BRACE);
1667
1668 throw new NoSuchCategoryException(msg.toString());
1669 }
1670
1671
1678 @Override
1679 public MBCategory fetchByGroupId_Last(long groupId,
1680 OrderByComparator<MBCategory> orderByComparator) {
1681 int count = countByGroupId(groupId);
1682
1683 if (count == 0) {
1684 return null;
1685 }
1686
1687 List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1688 orderByComparator);
1689
1690 if (!list.isEmpty()) {
1691 return list.get(0);
1692 }
1693
1694 return null;
1695 }
1696
1697
1706 @Override
1707 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1708 long groupId, OrderByComparator<MBCategory> orderByComparator)
1709 throws NoSuchCategoryException {
1710 MBCategory mbCategory = findByPrimaryKey(categoryId);
1711
1712 Session session = null;
1713
1714 try {
1715 session = openSession();
1716
1717 MBCategory[] array = new MBCategoryImpl[3];
1718
1719 array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1720 orderByComparator, true);
1721
1722 array[1] = mbCategory;
1723
1724 array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1725 orderByComparator, false);
1726
1727 return array;
1728 }
1729 catch (Exception e) {
1730 throw processException(e);
1731 }
1732 finally {
1733 closeSession(session);
1734 }
1735 }
1736
1737 protected MBCategory getByGroupId_PrevAndNext(Session session,
1738 MBCategory mbCategory, long groupId,
1739 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
1740 StringBundler query = null;
1741
1742 if (orderByComparator != null) {
1743 query = new StringBundler(6 +
1744 (orderByComparator.getOrderByFields().length * 6));
1745 }
1746 else {
1747 query = new StringBundler(3);
1748 }
1749
1750 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1751
1752 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1753
1754 if (orderByComparator != null) {
1755 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1756
1757 if (orderByConditionFields.length > 0) {
1758 query.append(WHERE_AND);
1759 }
1760
1761 for (int i = 0; i < orderByConditionFields.length; i++) {
1762 query.append(_ORDER_BY_ENTITY_ALIAS);
1763 query.append(orderByConditionFields[i]);
1764
1765 if ((i + 1) < orderByConditionFields.length) {
1766 if (orderByComparator.isAscending() ^ previous) {
1767 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1768 }
1769 else {
1770 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1771 }
1772 }
1773 else {
1774 if (orderByComparator.isAscending() ^ previous) {
1775 query.append(WHERE_GREATER_THAN);
1776 }
1777 else {
1778 query.append(WHERE_LESSER_THAN);
1779 }
1780 }
1781 }
1782
1783 query.append(ORDER_BY_CLAUSE);
1784
1785 String[] orderByFields = orderByComparator.getOrderByFields();
1786
1787 for (int i = 0; i < orderByFields.length; i++) {
1788 query.append(_ORDER_BY_ENTITY_ALIAS);
1789 query.append(orderByFields[i]);
1790
1791 if ((i + 1) < orderByFields.length) {
1792 if (orderByComparator.isAscending() ^ previous) {
1793 query.append(ORDER_BY_ASC_HAS_NEXT);
1794 }
1795 else {
1796 query.append(ORDER_BY_DESC_HAS_NEXT);
1797 }
1798 }
1799 else {
1800 if (orderByComparator.isAscending() ^ previous) {
1801 query.append(ORDER_BY_ASC);
1802 }
1803 else {
1804 query.append(ORDER_BY_DESC);
1805 }
1806 }
1807 }
1808 }
1809 else {
1810 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1811 }
1812
1813 String sql = query.toString();
1814
1815 Query q = session.createQuery(sql);
1816
1817 q.setFirstResult(0);
1818 q.setMaxResults(2);
1819
1820 QueryPos qPos = QueryPos.getInstance(q);
1821
1822 qPos.add(groupId);
1823
1824 if (orderByComparator != null) {
1825 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1826
1827 for (Object value : values) {
1828 qPos.add(value);
1829 }
1830 }
1831
1832 List<MBCategory> list = q.list();
1833
1834 if (list.size() == 2) {
1835 return list.get(1);
1836 }
1837 else {
1838 return null;
1839 }
1840 }
1841
1842
1848 @Override
1849 public List<MBCategory> filterFindByGroupId(long groupId) {
1850 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1851 QueryUtil.ALL_POS, null);
1852 }
1853
1854
1866 @Override
1867 public List<MBCategory> filterFindByGroupId(long groupId, int start, int end) {
1868 return filterFindByGroupId(groupId, start, end, null);
1869 }
1870
1871
1884 @Override
1885 public List<MBCategory> filterFindByGroupId(long groupId, int start,
1886 int end, OrderByComparator<MBCategory> orderByComparator) {
1887 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1888 return findByGroupId(groupId, start, end, orderByComparator);
1889 }
1890
1891 StringBundler query = null;
1892
1893 if (orderByComparator != null) {
1894 query = new StringBundler(3 +
1895 (orderByComparator.getOrderByFields().length * 3));
1896 }
1897 else {
1898 query = new StringBundler(3);
1899 }
1900
1901 if (getDB().isSupportsInlineDistinct()) {
1902 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1903 }
1904 else {
1905 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1906 }
1907
1908 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1909
1910 if (!getDB().isSupportsInlineDistinct()) {
1911 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1912 }
1913
1914 if (orderByComparator != null) {
1915 if (getDB().isSupportsInlineDistinct()) {
1916 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1917 orderByComparator, true);
1918 }
1919 else {
1920 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1921 orderByComparator, true);
1922 }
1923 }
1924 else {
1925 if (getDB().isSupportsInlineDistinct()) {
1926 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1927 }
1928 else {
1929 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1930 }
1931 }
1932
1933 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1934 MBCategory.class.getName(),
1935 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1936
1937 Session session = null;
1938
1939 try {
1940 session = openSession();
1941
1942 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1943
1944 if (getDB().isSupportsInlineDistinct()) {
1945 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1946 }
1947 else {
1948 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1949 }
1950
1951 QueryPos qPos = QueryPos.getInstance(q);
1952
1953 qPos.add(groupId);
1954
1955 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1956 }
1957 catch (Exception e) {
1958 throw processException(e);
1959 }
1960 finally {
1961 closeSession(session);
1962 }
1963 }
1964
1965
1974 @Override
1975 public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
1976 long groupId, OrderByComparator<MBCategory> orderByComparator)
1977 throws NoSuchCategoryException {
1978 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1979 return findByGroupId_PrevAndNext(categoryId, groupId,
1980 orderByComparator);
1981 }
1982
1983 MBCategory mbCategory = findByPrimaryKey(categoryId);
1984
1985 Session session = null;
1986
1987 try {
1988 session = openSession();
1989
1990 MBCategory[] array = new MBCategoryImpl[3];
1991
1992 array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1993 groupId, orderByComparator, true);
1994
1995 array[1] = mbCategory;
1996
1997 array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1998 groupId, orderByComparator, false);
1999
2000 return array;
2001 }
2002 catch (Exception e) {
2003 throw processException(e);
2004 }
2005 finally {
2006 closeSession(session);
2007 }
2008 }
2009
2010 protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
2011 MBCategory mbCategory, long groupId,
2012 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
2013 StringBundler query = null;
2014
2015 if (orderByComparator != null) {
2016 query = new StringBundler(6 +
2017 (orderByComparator.getOrderByFields().length * 6));
2018 }
2019 else {
2020 query = new StringBundler(3);
2021 }
2022
2023 if (getDB().isSupportsInlineDistinct()) {
2024 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2025 }
2026 else {
2027 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2028 }
2029
2030 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2031
2032 if (!getDB().isSupportsInlineDistinct()) {
2033 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2034 }
2035
2036 if (orderByComparator != null) {
2037 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2038
2039 if (orderByConditionFields.length > 0) {
2040 query.append(WHERE_AND);
2041 }
2042
2043 for (int i = 0; i < orderByConditionFields.length; i++) {
2044 if (getDB().isSupportsInlineDistinct()) {
2045 query.append(_ORDER_BY_ENTITY_ALIAS);
2046 }
2047 else {
2048 query.append(_ORDER_BY_ENTITY_TABLE);
2049 }
2050
2051 query.append(orderByConditionFields[i]);
2052
2053 if ((i + 1) < orderByConditionFields.length) {
2054 if (orderByComparator.isAscending() ^ previous) {
2055 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2056 }
2057 else {
2058 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2059 }
2060 }
2061 else {
2062 if (orderByComparator.isAscending() ^ previous) {
2063 query.append(WHERE_GREATER_THAN);
2064 }
2065 else {
2066 query.append(WHERE_LESSER_THAN);
2067 }
2068 }
2069 }
2070
2071 query.append(ORDER_BY_CLAUSE);
2072
2073 String[] orderByFields = orderByComparator.getOrderByFields();
2074
2075 for (int i = 0; i < orderByFields.length; i++) {
2076 if (getDB().isSupportsInlineDistinct()) {
2077 query.append(_ORDER_BY_ENTITY_ALIAS);
2078 }
2079 else {
2080 query.append(_ORDER_BY_ENTITY_TABLE);
2081 }
2082
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 else {
2104 if (getDB().isSupportsInlineDistinct()) {
2105 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2106 }
2107 else {
2108 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2109 }
2110 }
2111
2112 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2113 MBCategory.class.getName(),
2114 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2115
2116 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2117
2118 q.setFirstResult(0);
2119 q.setMaxResults(2);
2120
2121 if (getDB().isSupportsInlineDistinct()) {
2122 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2123 }
2124 else {
2125 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2126 }
2127
2128 QueryPos qPos = QueryPos.getInstance(q);
2129
2130 qPos.add(groupId);
2131
2132 if (orderByComparator != null) {
2133 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2134
2135 for (Object value : values) {
2136 qPos.add(value);
2137 }
2138 }
2139
2140 List<MBCategory> list = q.list();
2141
2142 if (list.size() == 2) {
2143 return list.get(1);
2144 }
2145 else {
2146 return null;
2147 }
2148 }
2149
2150
2155 @Override
2156 public void removeByGroupId(long groupId) {
2157 for (MBCategory mbCategory : findByGroupId(groupId, QueryUtil.ALL_POS,
2158 QueryUtil.ALL_POS, null)) {
2159 remove(mbCategory);
2160 }
2161 }
2162
2163
2169 @Override
2170 public int countByGroupId(long groupId) {
2171 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2172
2173 Object[] finderArgs = new Object[] { groupId };
2174
2175 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2176 this);
2177
2178 if (count == null) {
2179 StringBundler query = new StringBundler(2);
2180
2181 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2182
2183 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2184
2185 String sql = query.toString();
2186
2187 Session session = null;
2188
2189 try {
2190 session = openSession();
2191
2192 Query q = session.createQuery(sql);
2193
2194 QueryPos qPos = QueryPos.getInstance(q);
2195
2196 qPos.add(groupId);
2197
2198 count = (Long)q.uniqueResult();
2199
2200 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2201 }
2202 catch (Exception e) {
2203 FinderCacheUtil.removeResult(finderPath, finderArgs);
2204
2205 throw processException(e);
2206 }
2207 finally {
2208 closeSession(session);
2209 }
2210 }
2211
2212 return count.intValue();
2213 }
2214
2215
2221 @Override
2222 public int filterCountByGroupId(long groupId) {
2223 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2224 return countByGroupId(groupId);
2225 }
2226
2227 StringBundler query = new StringBundler(2);
2228
2229 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2230
2231 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2232
2233 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2234 MBCategory.class.getName(),
2235 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2236
2237 Session session = null;
2238
2239 try {
2240 session = openSession();
2241
2242 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2243
2244 q.addScalar(COUNT_COLUMN_NAME,
2245 com.liferay.portal.kernel.dao.orm.Type.LONG);
2246
2247 QueryPos qPos = QueryPos.getInstance(q);
2248
2249 qPos.add(groupId);
2250
2251 Long count = (Long)q.uniqueResult();
2252
2253 return count.intValue();
2254 }
2255 catch (Exception e) {
2256 throw processException(e);
2257 }
2258 finally {
2259 closeSession(session);
2260 }
2261 }
2262
2263 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
2264 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2265 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2266 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2267 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2268 new String[] {
2269 Long.class.getName(),
2270
2271 Integer.class.getName(), Integer.class.getName(),
2272 OrderByComparator.class.getName()
2273 });
2274 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2275 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2276 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2277 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2278 new String[] { Long.class.getName() },
2279 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
2280 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2281 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2282 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2283 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2284 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2285 new String[] { Long.class.getName() });
2286
2287
2293 @Override
2294 public List<MBCategory> findByCompanyId(long companyId) {
2295 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2296 null);
2297 }
2298
2299
2311 @Override
2312 public List<MBCategory> findByCompanyId(long companyId, int start, int end) {
2313 return findByCompanyId(companyId, start, end, null);
2314 }
2315
2316
2329 @Override
2330 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2331 OrderByComparator<MBCategory> orderByComparator) {
2332 boolean pagination = true;
2333 FinderPath finderPath = null;
2334 Object[] finderArgs = null;
2335
2336 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2337 (orderByComparator == null)) {
2338 pagination = false;
2339 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2340 finderArgs = new Object[] { companyId };
2341 }
2342 else {
2343 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2344 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2345 }
2346
2347 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2348 finderArgs, this);
2349
2350 if ((list != null) && !list.isEmpty()) {
2351 for (MBCategory mbCategory : list) {
2352 if ((companyId != mbCategory.getCompanyId())) {
2353 list = null;
2354
2355 break;
2356 }
2357 }
2358 }
2359
2360 if (list == null) {
2361 StringBundler query = null;
2362
2363 if (orderByComparator != null) {
2364 query = new StringBundler(3 +
2365 (orderByComparator.getOrderByFields().length * 3));
2366 }
2367 else {
2368 query = new StringBundler(3);
2369 }
2370
2371 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2372
2373 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2374
2375 if (orderByComparator != null) {
2376 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2377 orderByComparator);
2378 }
2379 else
2380 if (pagination) {
2381 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2382 }
2383
2384 String sql = query.toString();
2385
2386 Session session = null;
2387
2388 try {
2389 session = openSession();
2390
2391 Query q = session.createQuery(sql);
2392
2393 QueryPos qPos = QueryPos.getInstance(q);
2394
2395 qPos.add(companyId);
2396
2397 if (!pagination) {
2398 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2399 start, end, false);
2400
2401 Collections.sort(list);
2402
2403 list = Collections.unmodifiableList(list);
2404 }
2405 else {
2406 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2407 start, end);
2408 }
2409
2410 cacheResult(list);
2411
2412 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2413 }
2414 catch (Exception e) {
2415 FinderCacheUtil.removeResult(finderPath, finderArgs);
2416
2417 throw processException(e);
2418 }
2419 finally {
2420 closeSession(session);
2421 }
2422 }
2423
2424 return list;
2425 }
2426
2427
2435 @Override
2436 public MBCategory findByCompanyId_First(long companyId,
2437 OrderByComparator<MBCategory> orderByComparator)
2438 throws NoSuchCategoryException {
2439 MBCategory mbCategory = fetchByCompanyId_First(companyId,
2440 orderByComparator);
2441
2442 if (mbCategory != null) {
2443 return mbCategory;
2444 }
2445
2446 StringBundler msg = new StringBundler(4);
2447
2448 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2449
2450 msg.append("companyId=");
2451 msg.append(companyId);
2452
2453 msg.append(StringPool.CLOSE_CURLY_BRACE);
2454
2455 throw new NoSuchCategoryException(msg.toString());
2456 }
2457
2458
2465 @Override
2466 public MBCategory fetchByCompanyId_First(long companyId,
2467 OrderByComparator<MBCategory> orderByComparator) {
2468 List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2469 orderByComparator);
2470
2471 if (!list.isEmpty()) {
2472 return list.get(0);
2473 }
2474
2475 return null;
2476 }
2477
2478
2486 @Override
2487 public MBCategory findByCompanyId_Last(long companyId,
2488 OrderByComparator<MBCategory> orderByComparator)
2489 throws NoSuchCategoryException {
2490 MBCategory mbCategory = fetchByCompanyId_Last(companyId,
2491 orderByComparator);
2492
2493 if (mbCategory != null) {
2494 return mbCategory;
2495 }
2496
2497 StringBundler msg = new StringBundler(4);
2498
2499 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2500
2501 msg.append("companyId=");
2502 msg.append(companyId);
2503
2504 msg.append(StringPool.CLOSE_CURLY_BRACE);
2505
2506 throw new NoSuchCategoryException(msg.toString());
2507 }
2508
2509
2516 @Override
2517 public MBCategory fetchByCompanyId_Last(long companyId,
2518 OrderByComparator<MBCategory> orderByComparator) {
2519 int count = countByCompanyId(companyId);
2520
2521 if (count == 0) {
2522 return null;
2523 }
2524
2525 List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2526 orderByComparator);
2527
2528 if (!list.isEmpty()) {
2529 return list.get(0);
2530 }
2531
2532 return null;
2533 }
2534
2535
2544 @Override
2545 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2546 long companyId, OrderByComparator<MBCategory> orderByComparator)
2547 throws NoSuchCategoryException {
2548 MBCategory mbCategory = findByPrimaryKey(categoryId);
2549
2550 Session session = null;
2551
2552 try {
2553 session = openSession();
2554
2555 MBCategory[] array = new MBCategoryImpl[3];
2556
2557 array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2558 companyId, orderByComparator, true);
2559
2560 array[1] = mbCategory;
2561
2562 array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2563 companyId, orderByComparator, false);
2564
2565 return array;
2566 }
2567 catch (Exception e) {
2568 throw processException(e);
2569 }
2570 finally {
2571 closeSession(session);
2572 }
2573 }
2574
2575 protected MBCategory getByCompanyId_PrevAndNext(Session session,
2576 MBCategory mbCategory, long companyId,
2577 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
2578 StringBundler query = null;
2579
2580 if (orderByComparator != null) {
2581 query = new StringBundler(6 +
2582 (orderByComparator.getOrderByFields().length * 6));
2583 }
2584 else {
2585 query = new StringBundler(3);
2586 }
2587
2588 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2589
2590 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2591
2592 if (orderByComparator != null) {
2593 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2594
2595 if (orderByConditionFields.length > 0) {
2596 query.append(WHERE_AND);
2597 }
2598
2599 for (int i = 0; i < orderByConditionFields.length; i++) {
2600 query.append(_ORDER_BY_ENTITY_ALIAS);
2601 query.append(orderByConditionFields[i]);
2602
2603 if ((i + 1) < orderByConditionFields.length) {
2604 if (orderByComparator.isAscending() ^ previous) {
2605 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2606 }
2607 else {
2608 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2609 }
2610 }
2611 else {
2612 if (orderByComparator.isAscending() ^ previous) {
2613 query.append(WHERE_GREATER_THAN);
2614 }
2615 else {
2616 query.append(WHERE_LESSER_THAN);
2617 }
2618 }
2619 }
2620
2621 query.append(ORDER_BY_CLAUSE);
2622
2623 String[] orderByFields = orderByComparator.getOrderByFields();
2624
2625 for (int i = 0; i < orderByFields.length; i++) {
2626 query.append(_ORDER_BY_ENTITY_ALIAS);
2627 query.append(orderByFields[i]);
2628
2629 if ((i + 1) < orderByFields.length) {
2630 if (orderByComparator.isAscending() ^ previous) {
2631 query.append(ORDER_BY_ASC_HAS_NEXT);
2632 }
2633 else {
2634 query.append(ORDER_BY_DESC_HAS_NEXT);
2635 }
2636 }
2637 else {
2638 if (orderByComparator.isAscending() ^ previous) {
2639 query.append(ORDER_BY_ASC);
2640 }
2641 else {
2642 query.append(ORDER_BY_DESC);
2643 }
2644 }
2645 }
2646 }
2647 else {
2648 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2649 }
2650
2651 String sql = query.toString();
2652
2653 Query q = session.createQuery(sql);
2654
2655 q.setFirstResult(0);
2656 q.setMaxResults(2);
2657
2658 QueryPos qPos = QueryPos.getInstance(q);
2659
2660 qPos.add(companyId);
2661
2662 if (orderByComparator != null) {
2663 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2664
2665 for (Object value : values) {
2666 qPos.add(value);
2667 }
2668 }
2669
2670 List<MBCategory> list = q.list();
2671
2672 if (list.size() == 2) {
2673 return list.get(1);
2674 }
2675 else {
2676 return null;
2677 }
2678 }
2679
2680
2685 @Override
2686 public void removeByCompanyId(long companyId) {
2687 for (MBCategory mbCategory : findByCompanyId(companyId,
2688 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2689 remove(mbCategory);
2690 }
2691 }
2692
2693
2699 @Override
2700 public int countByCompanyId(long companyId) {
2701 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2702
2703 Object[] finderArgs = new Object[] { companyId };
2704
2705 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2706 this);
2707
2708 if (count == null) {
2709 StringBundler query = new StringBundler(2);
2710
2711 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2712
2713 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2714
2715 String sql = query.toString();
2716
2717 Session session = null;
2718
2719 try {
2720 session = openSession();
2721
2722 Query q = session.createQuery(sql);
2723
2724 QueryPos qPos = QueryPos.getInstance(q);
2725
2726 qPos.add(companyId);
2727
2728 count = (Long)q.uniqueResult();
2729
2730 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2731 }
2732 catch (Exception e) {
2733 FinderCacheUtil.removeResult(finderPath, finderArgs);
2734
2735 throw processException(e);
2736 }
2737 finally {
2738 closeSession(session);
2739 }
2740 }
2741
2742 return count.intValue();
2743 }
2744
2745 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
2746 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2747 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2748 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
2749 new String[] {
2750 Long.class.getName(), Long.class.getName(),
2751
2752 Integer.class.getName(), Integer.class.getName(),
2753 OrderByComparator.class.getName()
2754 });
2755 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2756 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2757 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
2758 new String[] { Long.class.getName(), Long.class.getName() },
2759 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
2760 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2761 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2762 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2763 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2764 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
2765 new String[] { Long.class.getName(), Long.class.getName() });
2766 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2767 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2768 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
2769 new String[] { Long.class.getName(), Long.class.getName() });
2770
2771
2778 @Override
2779 public List<MBCategory> findByG_P(long groupId, long parentCategoryId) {
2780 return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2781 QueryUtil.ALL_POS, null);
2782 }
2783
2784
2797 @Override
2798 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2799 int start, int end) {
2800 return findByG_P(groupId, parentCategoryId, start, end, null);
2801 }
2802
2803
2817 @Override
2818 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2819 int start, int end, OrderByComparator<MBCategory> orderByComparator) {
2820 boolean pagination = true;
2821 FinderPath finderPath = null;
2822 Object[] finderArgs = null;
2823
2824 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2825 (orderByComparator == null)) {
2826 pagination = false;
2827 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2828 finderArgs = new Object[] { groupId, parentCategoryId };
2829 }
2830 else {
2831 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2832 finderArgs = new Object[] {
2833 groupId, parentCategoryId,
2834
2835 start, end, orderByComparator
2836 };
2837 }
2838
2839 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2840 finderArgs, this);
2841
2842 if ((list != null) && !list.isEmpty()) {
2843 for (MBCategory mbCategory : list) {
2844 if ((groupId != mbCategory.getGroupId()) ||
2845 (parentCategoryId != mbCategory.getParentCategoryId())) {
2846 list = null;
2847
2848 break;
2849 }
2850 }
2851 }
2852
2853 if (list == null) {
2854 StringBundler query = null;
2855
2856 if (orderByComparator != null) {
2857 query = new StringBundler(4 +
2858 (orderByComparator.getOrderByFields().length * 3));
2859 }
2860 else {
2861 query = new StringBundler(4);
2862 }
2863
2864 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2865
2866 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2867
2868 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2869
2870 if (orderByComparator != null) {
2871 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2872 orderByComparator);
2873 }
2874 else
2875 if (pagination) {
2876 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2877 }
2878
2879 String sql = query.toString();
2880
2881 Session session = null;
2882
2883 try {
2884 session = openSession();
2885
2886 Query q = session.createQuery(sql);
2887
2888 QueryPos qPos = QueryPos.getInstance(q);
2889
2890 qPos.add(groupId);
2891
2892 qPos.add(parentCategoryId);
2893
2894 if (!pagination) {
2895 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2896 start, end, false);
2897
2898 Collections.sort(list);
2899
2900 list = Collections.unmodifiableList(list);
2901 }
2902 else {
2903 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2904 start, end);
2905 }
2906
2907 cacheResult(list);
2908
2909 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2910 }
2911 catch (Exception e) {
2912 FinderCacheUtil.removeResult(finderPath, finderArgs);
2913
2914 throw processException(e);
2915 }
2916 finally {
2917 closeSession(session);
2918 }
2919 }
2920
2921 return list;
2922 }
2923
2924
2933 @Override
2934 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
2935 OrderByComparator<MBCategory> orderByComparator)
2936 throws NoSuchCategoryException {
2937 MBCategory mbCategory = fetchByG_P_First(groupId, parentCategoryId,
2938 orderByComparator);
2939
2940 if (mbCategory != null) {
2941 return mbCategory;
2942 }
2943
2944 StringBundler msg = new StringBundler(6);
2945
2946 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2947
2948 msg.append("groupId=");
2949 msg.append(groupId);
2950
2951 msg.append(", parentCategoryId=");
2952 msg.append(parentCategoryId);
2953
2954 msg.append(StringPool.CLOSE_CURLY_BRACE);
2955
2956 throw new NoSuchCategoryException(msg.toString());
2957 }
2958
2959
2967 @Override
2968 public MBCategory fetchByG_P_First(long groupId, long parentCategoryId,
2969 OrderByComparator<MBCategory> orderByComparator) {
2970 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
2971 orderByComparator);
2972
2973 if (!list.isEmpty()) {
2974 return list.get(0);
2975 }
2976
2977 return null;
2978 }
2979
2980
2989 @Override
2990 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
2991 OrderByComparator<MBCategory> orderByComparator)
2992 throws NoSuchCategoryException {
2993 MBCategory mbCategory = fetchByG_P_Last(groupId, parentCategoryId,
2994 orderByComparator);
2995
2996 if (mbCategory != null) {
2997 return mbCategory;
2998 }
2999
3000 StringBundler msg = new StringBundler(6);
3001
3002 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3003
3004 msg.append("groupId=");
3005 msg.append(groupId);
3006
3007 msg.append(", parentCategoryId=");
3008 msg.append(parentCategoryId);
3009
3010 msg.append(StringPool.CLOSE_CURLY_BRACE);
3011
3012 throw new NoSuchCategoryException(msg.toString());
3013 }
3014
3015
3023 @Override
3024 public MBCategory fetchByG_P_Last(long groupId, long parentCategoryId,
3025 OrderByComparator<MBCategory> orderByComparator) {
3026 int count = countByG_P(groupId, parentCategoryId);
3027
3028 if (count == 0) {
3029 return null;
3030 }
3031
3032 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
3033 count, orderByComparator);
3034
3035 if (!list.isEmpty()) {
3036 return list.get(0);
3037 }
3038
3039 return null;
3040 }
3041
3042
3052 @Override
3053 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
3054 long parentCategoryId, OrderByComparator<MBCategory> orderByComparator)
3055 throws NoSuchCategoryException {
3056 MBCategory mbCategory = findByPrimaryKey(categoryId);
3057
3058 Session session = null;
3059
3060 try {
3061 session = openSession();
3062
3063 MBCategory[] array = new MBCategoryImpl[3];
3064
3065 array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3066 parentCategoryId, orderByComparator, true);
3067
3068 array[1] = mbCategory;
3069
3070 array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3071 parentCategoryId, orderByComparator, false);
3072
3073 return array;
3074 }
3075 catch (Exception e) {
3076 throw processException(e);
3077 }
3078 finally {
3079 closeSession(session);
3080 }
3081 }
3082
3083 protected MBCategory getByG_P_PrevAndNext(Session session,
3084 MBCategory mbCategory, long groupId, long parentCategoryId,
3085 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
3086 StringBundler query = null;
3087
3088 if (orderByComparator != null) {
3089 query = new StringBundler(6 +
3090 (orderByComparator.getOrderByFields().length * 6));
3091 }
3092 else {
3093 query = new StringBundler(3);
3094 }
3095
3096 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3097
3098 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3099
3100 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3101
3102 if (orderByComparator != null) {
3103 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3104
3105 if (orderByConditionFields.length > 0) {
3106 query.append(WHERE_AND);
3107 }
3108
3109 for (int i = 0; i < orderByConditionFields.length; i++) {
3110 query.append(_ORDER_BY_ENTITY_ALIAS);
3111 query.append(orderByConditionFields[i]);
3112
3113 if ((i + 1) < orderByConditionFields.length) {
3114 if (orderByComparator.isAscending() ^ previous) {
3115 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3116 }
3117 else {
3118 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3119 }
3120 }
3121 else {
3122 if (orderByComparator.isAscending() ^ previous) {
3123 query.append(WHERE_GREATER_THAN);
3124 }
3125 else {
3126 query.append(WHERE_LESSER_THAN);
3127 }
3128 }
3129 }
3130
3131 query.append(ORDER_BY_CLAUSE);
3132
3133 String[] orderByFields = orderByComparator.getOrderByFields();
3134
3135 for (int i = 0; i < orderByFields.length; i++) {
3136 query.append(_ORDER_BY_ENTITY_ALIAS);
3137 query.append(orderByFields[i]);
3138
3139 if ((i + 1) < orderByFields.length) {
3140 if (orderByComparator.isAscending() ^ previous) {
3141 query.append(ORDER_BY_ASC_HAS_NEXT);
3142 }
3143 else {
3144 query.append(ORDER_BY_DESC_HAS_NEXT);
3145 }
3146 }
3147 else {
3148 if (orderByComparator.isAscending() ^ previous) {
3149 query.append(ORDER_BY_ASC);
3150 }
3151 else {
3152 query.append(ORDER_BY_DESC);
3153 }
3154 }
3155 }
3156 }
3157 else {
3158 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3159 }
3160
3161 String sql = query.toString();
3162
3163 Query q = session.createQuery(sql);
3164
3165 q.setFirstResult(0);
3166 q.setMaxResults(2);
3167
3168 QueryPos qPos = QueryPos.getInstance(q);
3169
3170 qPos.add(groupId);
3171
3172 qPos.add(parentCategoryId);
3173
3174 if (orderByComparator != null) {
3175 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3176
3177 for (Object value : values) {
3178 qPos.add(value);
3179 }
3180 }
3181
3182 List<MBCategory> list = q.list();
3183
3184 if (list.size() == 2) {
3185 return list.get(1);
3186 }
3187 else {
3188 return null;
3189 }
3190 }
3191
3192
3199 @Override
3200 public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId) {
3201 return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
3202 QueryUtil.ALL_POS, null);
3203 }
3204
3205
3218 @Override
3219 public List<MBCategory> filterFindByG_P(long groupId,
3220 long parentCategoryId, int start, int end) {
3221 return filterFindByG_P(groupId, parentCategoryId, start, end, null);
3222 }
3223
3224
3238 @Override
3239 public List<MBCategory> filterFindByG_P(long groupId,
3240 long parentCategoryId, int start, int end,
3241 OrderByComparator<MBCategory> orderByComparator) {
3242 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3243 return findByG_P(groupId, parentCategoryId, start, end,
3244 orderByComparator);
3245 }
3246
3247 StringBundler query = null;
3248
3249 if (orderByComparator != null) {
3250 query = new StringBundler(4 +
3251 (orderByComparator.getOrderByFields().length * 3));
3252 }
3253 else {
3254 query = new StringBundler(4);
3255 }
3256
3257 if (getDB().isSupportsInlineDistinct()) {
3258 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3259 }
3260 else {
3261 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3262 }
3263
3264 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3265
3266 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3267
3268 if (!getDB().isSupportsInlineDistinct()) {
3269 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3270 }
3271
3272 if (orderByComparator != null) {
3273 if (getDB().isSupportsInlineDistinct()) {
3274 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3275 orderByComparator, true);
3276 }
3277 else {
3278 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3279 orderByComparator, true);
3280 }
3281 }
3282 else {
3283 if (getDB().isSupportsInlineDistinct()) {
3284 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3285 }
3286 else {
3287 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3288 }
3289 }
3290
3291 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3292 MBCategory.class.getName(),
3293 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3294
3295 Session session = null;
3296
3297 try {
3298 session = openSession();
3299
3300 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3301
3302 if (getDB().isSupportsInlineDistinct()) {
3303 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3304 }
3305 else {
3306 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3307 }
3308
3309 QueryPos qPos = QueryPos.getInstance(q);
3310
3311 qPos.add(groupId);
3312
3313 qPos.add(parentCategoryId);
3314
3315 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3316 }
3317 catch (Exception e) {
3318 throw processException(e);
3319 }
3320 finally {
3321 closeSession(session);
3322 }
3323 }
3324
3325
3335 @Override
3336 public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
3337 long groupId, long parentCategoryId,
3338 OrderByComparator<MBCategory> orderByComparator)
3339 throws NoSuchCategoryException {
3340 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3341 return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
3342 orderByComparator);
3343 }
3344
3345 MBCategory mbCategory = findByPrimaryKey(categoryId);
3346
3347 Session session = null;
3348
3349 try {
3350 session = openSession();
3351
3352 MBCategory[] array = new MBCategoryImpl[3];
3353
3354 array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3355 parentCategoryId, orderByComparator, true);
3356
3357 array[1] = mbCategory;
3358
3359 array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3360 parentCategoryId, orderByComparator, false);
3361
3362 return array;
3363 }
3364 catch (Exception e) {
3365 throw processException(e);
3366 }
3367 finally {
3368 closeSession(session);
3369 }
3370 }
3371
3372 protected MBCategory filterGetByG_P_PrevAndNext(Session session,
3373 MBCategory mbCategory, long groupId, long parentCategoryId,
3374 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
3375 StringBundler query = null;
3376
3377 if (orderByComparator != null) {
3378 query = new StringBundler(6 +
3379 (orderByComparator.getOrderByFields().length * 6));
3380 }
3381 else {
3382 query = new StringBundler(3);
3383 }
3384
3385 if (getDB().isSupportsInlineDistinct()) {
3386 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3387 }
3388 else {
3389 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3390 }
3391
3392 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3393
3394 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3395
3396 if (!getDB().isSupportsInlineDistinct()) {
3397 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3398 }
3399
3400 if (orderByComparator != null) {
3401 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3402
3403 if (orderByConditionFields.length > 0) {
3404 query.append(WHERE_AND);
3405 }
3406
3407 for (int i = 0; i < orderByConditionFields.length; i++) {
3408 if (getDB().isSupportsInlineDistinct()) {
3409 query.append(_ORDER_BY_ENTITY_ALIAS);
3410 }
3411 else {
3412 query.append(_ORDER_BY_ENTITY_TABLE);
3413 }
3414
3415 query.append(orderByConditionFields[i]);
3416
3417 if ((i + 1) < orderByConditionFields.length) {
3418 if (orderByComparator.isAscending() ^ previous) {
3419 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3420 }
3421 else {
3422 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3423 }
3424 }
3425 else {
3426 if (orderByComparator.isAscending() ^ previous) {
3427 query.append(WHERE_GREATER_THAN);
3428 }
3429 else {
3430 query.append(WHERE_LESSER_THAN);
3431 }
3432 }
3433 }
3434
3435 query.append(ORDER_BY_CLAUSE);
3436
3437 String[] orderByFields = orderByComparator.getOrderByFields();
3438
3439 for (int i = 0; i < orderByFields.length; i++) {
3440 if (getDB().isSupportsInlineDistinct()) {
3441 query.append(_ORDER_BY_ENTITY_ALIAS);
3442 }
3443 else {
3444 query.append(_ORDER_BY_ENTITY_TABLE);
3445 }
3446
3447 query.append(orderByFields[i]);
3448
3449 if ((i + 1) < orderByFields.length) {
3450 if (orderByComparator.isAscending() ^ previous) {
3451 query.append(ORDER_BY_ASC_HAS_NEXT);
3452 }
3453 else {
3454 query.append(ORDER_BY_DESC_HAS_NEXT);
3455 }
3456 }
3457 else {
3458 if (orderByComparator.isAscending() ^ previous) {
3459 query.append(ORDER_BY_ASC);
3460 }
3461 else {
3462 query.append(ORDER_BY_DESC);
3463 }
3464 }
3465 }
3466 }
3467 else {
3468 if (getDB().isSupportsInlineDistinct()) {
3469 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3470 }
3471 else {
3472 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3473 }
3474 }
3475
3476 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3477 MBCategory.class.getName(),
3478 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3479
3480 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3481
3482 q.setFirstResult(0);
3483 q.setMaxResults(2);
3484
3485 if (getDB().isSupportsInlineDistinct()) {
3486 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3487 }
3488 else {
3489 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3490 }
3491
3492 QueryPos qPos = QueryPos.getInstance(q);
3493
3494 qPos.add(groupId);
3495
3496 qPos.add(parentCategoryId);
3497
3498 if (orderByComparator != null) {
3499 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3500
3501 for (Object value : values) {
3502 qPos.add(value);
3503 }
3504 }
3505
3506 List<MBCategory> list = q.list();
3507
3508 if (list.size() == 2) {
3509 return list.get(1);
3510 }
3511 else {
3512 return null;
3513 }
3514 }
3515
3516
3523 @Override
3524 public List<MBCategory> filterFindByG_P(long groupId,
3525 long[] parentCategoryIds) {
3526 return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3527 QueryUtil.ALL_POS, null);
3528 }
3529
3530
3543 @Override
3544 public List<MBCategory> filterFindByG_P(long groupId,
3545 long[] parentCategoryIds, int start, int end) {
3546 return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3547 }
3548
3549
3563 @Override
3564 public List<MBCategory> filterFindByG_P(long groupId,
3565 long[] parentCategoryIds, int start, int end,
3566 OrderByComparator<MBCategory> orderByComparator) {
3567 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3568 return findByG_P(groupId, parentCategoryIds, start, end,
3569 orderByComparator);
3570 }
3571
3572 if (parentCategoryIds == null) {
3573 parentCategoryIds = new long[0];
3574 }
3575 else {
3576 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
3577 }
3578
3579 StringBundler query = new StringBundler();
3580
3581 if (getDB().isSupportsInlineDistinct()) {
3582 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3583 }
3584 else {
3585 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3586 }
3587
3588 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3589
3590 if (parentCategoryIds.length > 0) {
3591 query.append(StringPool.OPEN_PARENTHESIS);
3592
3593 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
3594
3595 query.append(StringUtil.merge(parentCategoryIds));
3596
3597 query.append(StringPool.CLOSE_PARENTHESIS);
3598
3599 query.append(StringPool.CLOSE_PARENTHESIS);
3600 }
3601
3602 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3603 query.index() - 1);
3604
3605 if (!getDB().isSupportsInlineDistinct()) {
3606 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3607 }
3608
3609 if (orderByComparator != null) {
3610 if (getDB().isSupportsInlineDistinct()) {
3611 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3612 orderByComparator, true);
3613 }
3614 else {
3615 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3616 orderByComparator, true);
3617 }
3618 }
3619 else {
3620 if (getDB().isSupportsInlineDistinct()) {
3621 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3622 }
3623 else {
3624 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3625 }
3626 }
3627
3628 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3629 MBCategory.class.getName(),
3630 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3631
3632 Session session = null;
3633
3634 try {
3635 session = openSession();
3636
3637 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3638
3639 if (getDB().isSupportsInlineDistinct()) {
3640 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3641 }
3642 else {
3643 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3644 }
3645
3646 QueryPos qPos = QueryPos.getInstance(q);
3647
3648 qPos.add(groupId);
3649
3650 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3651 }
3652 catch (Exception e) {
3653 throw processException(e);
3654 }
3655 finally {
3656 closeSession(session);
3657 }
3658 }
3659
3660
3671 @Override
3672 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds) {
3673 return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3674 QueryUtil.ALL_POS, null);
3675 }
3676
3677
3690 @Override
3691 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3692 int start, int end) {
3693 return findByG_P(groupId, parentCategoryIds, start, end, null);
3694 }
3695
3696
3710 @Override
3711 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3712 int start, int end, OrderByComparator<MBCategory> orderByComparator) {
3713 if (parentCategoryIds == null) {
3714 parentCategoryIds = new long[0];
3715 }
3716 else {
3717 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
3718 }
3719
3720 if (parentCategoryIds.length == 1) {
3721 return findByG_P(groupId, parentCategoryIds[0], start, end,
3722 orderByComparator);
3723 }
3724
3725 boolean pagination = true;
3726 Object[] finderArgs = null;
3727
3728 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3729 (orderByComparator == null)) {
3730 pagination = false;
3731 finderArgs = new Object[] {
3732 groupId, StringUtil.merge(parentCategoryIds)
3733 };
3734 }
3735 else {
3736 finderArgs = new Object[] {
3737 groupId, StringUtil.merge(parentCategoryIds),
3738
3739 start, end, orderByComparator
3740 };
3741 }
3742
3743 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3744 finderArgs, this);
3745
3746 if ((list != null) && !list.isEmpty()) {
3747 for (MBCategory mbCategory : list) {
3748 if ((groupId != mbCategory.getGroupId()) ||
3749 !ArrayUtil.contains(parentCategoryIds,
3750 mbCategory.getParentCategoryId())) {
3751 list = null;
3752
3753 break;
3754 }
3755 }
3756 }
3757
3758 if (list == null) {
3759 StringBundler query = new StringBundler();
3760
3761 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3762
3763 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3764
3765 if (parentCategoryIds.length > 0) {
3766 query.append(StringPool.OPEN_PARENTHESIS);
3767
3768 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
3769
3770 query.append(StringUtil.merge(parentCategoryIds));
3771
3772 query.append(StringPool.CLOSE_PARENTHESIS);
3773
3774 query.append(StringPool.CLOSE_PARENTHESIS);
3775 }
3776
3777 query.setStringAt(removeConjunction(query.stringAt(query.index() -
3778 1)), query.index() - 1);
3779
3780 if (orderByComparator != null) {
3781 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3782 orderByComparator);
3783 }
3784 else
3785 if (pagination) {
3786 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3787 }
3788
3789 String sql = query.toString();
3790
3791 Session session = null;
3792
3793 try {
3794 session = openSession();
3795
3796 Query q = session.createQuery(sql);
3797
3798 QueryPos qPos = QueryPos.getInstance(q);
3799
3800 qPos.add(groupId);
3801
3802 if (!pagination) {
3803 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3804 start, end, false);
3805
3806 Collections.sort(list);
3807
3808 list = Collections.unmodifiableList(list);
3809 }
3810 else {
3811 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3812 start, end);
3813 }
3814
3815 cacheResult(list);
3816
3817 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3818 finderArgs, list);
3819 }
3820 catch (Exception e) {
3821 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3822 finderArgs);
3823
3824 throw processException(e);
3825 }
3826 finally {
3827 closeSession(session);
3828 }
3829 }
3830
3831 return list;
3832 }
3833
3834
3840 @Override
3841 public void removeByG_P(long groupId, long parentCategoryId) {
3842 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId,
3843 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3844 remove(mbCategory);
3845 }
3846 }
3847
3848
3855 @Override
3856 public int countByG_P(long groupId, long parentCategoryId) {
3857 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
3858
3859 Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3860
3861 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3862 this);
3863
3864 if (count == null) {
3865 StringBundler query = new StringBundler(3);
3866
3867 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3868
3869 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3870
3871 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3872
3873 String sql = query.toString();
3874
3875 Session session = null;
3876
3877 try {
3878 session = openSession();
3879
3880 Query q = session.createQuery(sql);
3881
3882 QueryPos qPos = QueryPos.getInstance(q);
3883
3884 qPos.add(groupId);
3885
3886 qPos.add(parentCategoryId);
3887
3888 count = (Long)q.uniqueResult();
3889
3890 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3891 }
3892 catch (Exception e) {
3893 FinderCacheUtil.removeResult(finderPath, finderArgs);
3894
3895 throw processException(e);
3896 }
3897 finally {
3898 closeSession(session);
3899 }
3900 }
3901
3902 return count.intValue();
3903 }
3904
3905
3912 @Override
3913 public int countByG_P(long groupId, long[] parentCategoryIds) {
3914 if (parentCategoryIds == null) {
3915 parentCategoryIds = new long[0];
3916 }
3917 else {
3918 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
3919 }
3920
3921 Object[] finderArgs = new Object[] {
3922 groupId, StringUtil.merge(parentCategoryIds)
3923 };
3924
3925 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3926 finderArgs, this);
3927
3928 if (count == null) {
3929 StringBundler query = new StringBundler();
3930
3931 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3932
3933 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3934
3935 if (parentCategoryIds.length > 0) {
3936 query.append(StringPool.OPEN_PARENTHESIS);
3937
3938 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
3939
3940 query.append(StringUtil.merge(parentCategoryIds));
3941
3942 query.append(StringPool.CLOSE_PARENTHESIS);
3943
3944 query.append(StringPool.CLOSE_PARENTHESIS);
3945 }
3946
3947 query.setStringAt(removeConjunction(query.stringAt(query.index() -
3948 1)), query.index() - 1);
3949
3950 String sql = query.toString();
3951
3952 Session session = null;
3953
3954 try {
3955 session = openSession();
3956
3957 Query q = session.createQuery(sql);
3958
3959 QueryPos qPos = QueryPos.getInstance(q);
3960
3961 qPos.add(groupId);
3962
3963 count = (Long)q.uniqueResult();
3964
3965 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3966 finderArgs, count);
3967 }
3968 catch (Exception e) {
3969 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3970 finderArgs);
3971
3972 throw processException(e);
3973 }
3974 finally {
3975 closeSession(session);
3976 }
3977 }
3978
3979 return count.intValue();
3980 }
3981
3982
3989 @Override
3990 public int filterCountByG_P(long groupId, long parentCategoryId) {
3991 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3992 return countByG_P(groupId, parentCategoryId);
3993 }
3994
3995 StringBundler query = new StringBundler(3);
3996
3997 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3998
3999 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4000
4001 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4002
4003 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4004 MBCategory.class.getName(),
4005 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4006
4007 Session session = null;
4008
4009 try {
4010 session = openSession();
4011
4012 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4013
4014 q.addScalar(COUNT_COLUMN_NAME,
4015 com.liferay.portal.kernel.dao.orm.Type.LONG);
4016
4017 QueryPos qPos = QueryPos.getInstance(q);
4018
4019 qPos.add(groupId);
4020
4021 qPos.add(parentCategoryId);
4022
4023 Long count = (Long)q.uniqueResult();
4024
4025 return count.intValue();
4026 }
4027 catch (Exception e) {
4028 throw processException(e);
4029 }
4030 finally {
4031 closeSession(session);
4032 }
4033 }
4034
4035
4042 @Override
4043 public int filterCountByG_P(long groupId, long[] parentCategoryIds) {
4044 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4045 return countByG_P(groupId, parentCategoryIds);
4046 }
4047
4048 if (parentCategoryIds == null) {
4049 parentCategoryIds = new long[0];
4050 }
4051 else {
4052 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
4053 }
4054
4055 StringBundler query = new StringBundler();
4056
4057 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4058
4059 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4060
4061 if (parentCategoryIds.length > 0) {
4062 query.append(StringPool.OPEN_PARENTHESIS);
4063
4064 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
4065
4066 query.append(StringUtil.merge(parentCategoryIds));
4067
4068 query.append(StringPool.CLOSE_PARENTHESIS);
4069
4070 query.append(StringPool.CLOSE_PARENTHESIS);
4071 }
4072
4073 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
4074 query.index() - 1);
4075
4076 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4077 MBCategory.class.getName(),
4078 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4079
4080 Session session = null;
4081
4082 try {
4083 session = openSession();
4084
4085 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4086
4087 q.addScalar(COUNT_COLUMN_NAME,
4088 com.liferay.portal.kernel.dao.orm.Type.LONG);
4089
4090 QueryPos qPos = QueryPos.getInstance(q);
4091
4092 qPos.add(groupId);
4093
4094 Long count = (Long)q.uniqueResult();
4095
4096 return count.intValue();
4097 }
4098 catch (Exception e) {
4099 throw processException(e);
4100 }
4101 finally {
4102 closeSession(session);
4103 }
4104 }
4105
4106 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4107 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4108 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
4109 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4110 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4111 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4112 new String[] {
4113 Long.class.getName(), Integer.class.getName(),
4114
4115 Integer.class.getName(), Integer.class.getName(),
4116 OrderByComparator.class.getName()
4117 });
4118 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4119 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4120 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4121 new String[] { Long.class.getName(), Integer.class.getName() },
4122 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
4123 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
4124 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4125 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
4126 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4127 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4129 new String[] { Long.class.getName(), Integer.class.getName() });
4130
4131
4138 @Override
4139 public List<MBCategory> findByG_S(long groupId, int status) {
4140 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4141 null);
4142 }
4143
4144
4157 @Override
4158 public List<MBCategory> findByG_S(long groupId, int status, int start,
4159 int end) {
4160 return findByG_S(groupId, status, start, end, null);
4161 }
4162
4163
4177 @Override
4178 public List<MBCategory> findByG_S(long groupId, int status, int start,
4179 int end, OrderByComparator<MBCategory> orderByComparator) {
4180 boolean pagination = true;
4181 FinderPath finderPath = null;
4182 Object[] finderArgs = null;
4183
4184 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4185 (orderByComparator == null)) {
4186 pagination = false;
4187 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4188 finderArgs = new Object[] { groupId, status };
4189 }
4190 else {
4191 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4192 finderArgs = new Object[] {
4193 groupId, status,
4194
4195 start, end, orderByComparator
4196 };
4197 }
4198
4199 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
4200 finderArgs, this);
4201
4202 if ((list != null) && !list.isEmpty()) {
4203 for (MBCategory mbCategory : list) {
4204 if ((groupId != mbCategory.getGroupId()) ||
4205 (status != mbCategory.getStatus())) {
4206 list = null;
4207
4208 break;
4209 }
4210 }
4211 }
4212
4213 if (list == null) {
4214 StringBundler query = null;
4215
4216 if (orderByComparator != null) {
4217 query = new StringBundler(4 +
4218 (orderByComparator.getOrderByFields().length * 3));
4219 }
4220 else {
4221 query = new StringBundler(4);
4222 }
4223
4224 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4225
4226 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4227
4228 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4229
4230 if (orderByComparator != null) {
4231 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4232 orderByComparator);
4233 }
4234 else
4235 if (pagination) {
4236 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4237 }
4238
4239 String sql = query.toString();
4240
4241 Session session = null;
4242
4243 try {
4244 session = openSession();
4245
4246 Query q = session.createQuery(sql);
4247
4248 QueryPos qPos = QueryPos.getInstance(q);
4249
4250 qPos.add(groupId);
4251
4252 qPos.add(status);
4253
4254 if (!pagination) {
4255 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4256 start, end, false);
4257
4258 Collections.sort(list);
4259
4260 list = Collections.unmodifiableList(list);
4261 }
4262 else {
4263 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4264 start, end);
4265 }
4266
4267 cacheResult(list);
4268
4269 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4270 }
4271 catch (Exception e) {
4272 FinderCacheUtil.removeResult(finderPath, finderArgs);
4273
4274 throw processException(e);
4275 }
4276 finally {
4277 closeSession(session);
4278 }
4279 }
4280
4281 return list;
4282 }
4283
4284
4293 @Override
4294 public MBCategory findByG_S_First(long groupId, int status,
4295 OrderByComparator<MBCategory> orderByComparator)
4296 throws NoSuchCategoryException {
4297 MBCategory mbCategory = fetchByG_S_First(groupId, status,
4298 orderByComparator);
4299
4300 if (mbCategory != null) {
4301 return mbCategory;
4302 }
4303
4304 StringBundler msg = new StringBundler(6);
4305
4306 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4307
4308 msg.append("groupId=");
4309 msg.append(groupId);
4310
4311 msg.append(", status=");
4312 msg.append(status);
4313
4314 msg.append(StringPool.CLOSE_CURLY_BRACE);
4315
4316 throw new NoSuchCategoryException(msg.toString());
4317 }
4318
4319
4327 @Override
4328 public MBCategory fetchByG_S_First(long groupId, int status,
4329 OrderByComparator<MBCategory> orderByComparator) {
4330 List<MBCategory> list = findByG_S(groupId, status, 0, 1,
4331 orderByComparator);
4332
4333 if (!list.isEmpty()) {
4334 return list.get(0);
4335 }
4336
4337 return null;
4338 }
4339
4340
4349 @Override
4350 public MBCategory findByG_S_Last(long groupId, int status,
4351 OrderByComparator<MBCategory> orderByComparator)
4352 throws NoSuchCategoryException {
4353 MBCategory mbCategory = fetchByG_S_Last(groupId, status,
4354 orderByComparator);
4355
4356 if (mbCategory != null) {
4357 return mbCategory;
4358 }
4359
4360 StringBundler msg = new StringBundler(6);
4361
4362 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4363
4364 msg.append("groupId=");
4365 msg.append(groupId);
4366
4367 msg.append(", status=");
4368 msg.append(status);
4369
4370 msg.append(StringPool.CLOSE_CURLY_BRACE);
4371
4372 throw new NoSuchCategoryException(msg.toString());
4373 }
4374
4375
4383 @Override
4384 public MBCategory fetchByG_S_Last(long groupId, int status,
4385 OrderByComparator<MBCategory> orderByComparator) {
4386 int count = countByG_S(groupId, status);
4387
4388 if (count == 0) {
4389 return null;
4390 }
4391
4392 List<MBCategory> list = findByG_S(groupId, status, count - 1, count,
4393 orderByComparator);
4394
4395 if (!list.isEmpty()) {
4396 return list.get(0);
4397 }
4398
4399 return null;
4400 }
4401
4402
4412 @Override
4413 public MBCategory[] findByG_S_PrevAndNext(long categoryId, long groupId,
4414 int status, OrderByComparator<MBCategory> orderByComparator)
4415 throws NoSuchCategoryException {
4416 MBCategory mbCategory = findByPrimaryKey(categoryId);
4417
4418 Session session = null;
4419
4420 try {
4421 session = openSession();
4422
4423 MBCategory[] array = new MBCategoryImpl[3];
4424
4425 array[0] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4426 status, orderByComparator, true);
4427
4428 array[1] = mbCategory;
4429
4430 array[2] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4431 status, orderByComparator, false);
4432
4433 return array;
4434 }
4435 catch (Exception e) {
4436 throw processException(e);
4437 }
4438 finally {
4439 closeSession(session);
4440 }
4441 }
4442
4443 protected MBCategory getByG_S_PrevAndNext(Session session,
4444 MBCategory mbCategory, long groupId, int status,
4445 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
4446 StringBundler query = null;
4447
4448 if (orderByComparator != null) {
4449 query = new StringBundler(6 +
4450 (orderByComparator.getOrderByFields().length * 6));
4451 }
4452 else {
4453 query = new StringBundler(3);
4454 }
4455
4456 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4457
4458 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4459
4460 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4461
4462 if (orderByComparator != null) {
4463 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4464
4465 if (orderByConditionFields.length > 0) {
4466 query.append(WHERE_AND);
4467 }
4468
4469 for (int i = 0; i < orderByConditionFields.length; i++) {
4470 query.append(_ORDER_BY_ENTITY_ALIAS);
4471 query.append(orderByConditionFields[i]);
4472
4473 if ((i + 1) < orderByConditionFields.length) {
4474 if (orderByComparator.isAscending() ^ previous) {
4475 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4476 }
4477 else {
4478 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4479 }
4480 }
4481 else {
4482 if (orderByComparator.isAscending() ^ previous) {
4483 query.append(WHERE_GREATER_THAN);
4484 }
4485 else {
4486 query.append(WHERE_LESSER_THAN);
4487 }
4488 }
4489 }
4490
4491 query.append(ORDER_BY_CLAUSE);
4492
4493 String[] orderByFields = orderByComparator.getOrderByFields();
4494
4495 for (int i = 0; i < orderByFields.length; i++) {
4496 query.append(_ORDER_BY_ENTITY_ALIAS);
4497 query.append(orderByFields[i]);
4498
4499 if ((i + 1) < orderByFields.length) {
4500 if (orderByComparator.isAscending() ^ previous) {
4501 query.append(ORDER_BY_ASC_HAS_NEXT);
4502 }
4503 else {
4504 query.append(ORDER_BY_DESC_HAS_NEXT);
4505 }
4506 }
4507 else {
4508 if (orderByComparator.isAscending() ^ previous) {
4509 query.append(ORDER_BY_ASC);
4510 }
4511 else {
4512 query.append(ORDER_BY_DESC);
4513 }
4514 }
4515 }
4516 }
4517 else {
4518 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4519 }
4520
4521 String sql = query.toString();
4522
4523 Query q = session.createQuery(sql);
4524
4525 q.setFirstResult(0);
4526 q.setMaxResults(2);
4527
4528 QueryPos qPos = QueryPos.getInstance(q);
4529
4530 qPos.add(groupId);
4531
4532 qPos.add(status);
4533
4534 if (orderByComparator != null) {
4535 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4536
4537 for (Object value : values) {
4538 qPos.add(value);
4539 }
4540 }
4541
4542 List<MBCategory> list = q.list();
4543
4544 if (list.size() == 2) {
4545 return list.get(1);
4546 }
4547 else {
4548 return null;
4549 }
4550 }
4551
4552
4559 @Override
4560 public List<MBCategory> filterFindByG_S(long groupId, int status) {
4561 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4562 QueryUtil.ALL_POS, null);
4563 }
4564
4565
4578 @Override
4579 public List<MBCategory> filterFindByG_S(long groupId, int status,
4580 int start, int end) {
4581 return filterFindByG_S(groupId, status, start, end, null);
4582 }
4583
4584
4598 @Override
4599 public List<MBCategory> filterFindByG_S(long groupId, int status,
4600 int start, int end, OrderByComparator<MBCategory> orderByComparator) {
4601 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4602 return findByG_S(groupId, status, start, end, orderByComparator);
4603 }
4604
4605 StringBundler query = null;
4606
4607 if (orderByComparator != null) {
4608 query = new StringBundler(4 +
4609 (orderByComparator.getOrderByFields().length * 3));
4610 }
4611 else {
4612 query = new StringBundler(4);
4613 }
4614
4615 if (getDB().isSupportsInlineDistinct()) {
4616 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4617 }
4618 else {
4619 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4620 }
4621
4622 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4623
4624 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4625
4626 if (!getDB().isSupportsInlineDistinct()) {
4627 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4628 }
4629
4630 if (orderByComparator != null) {
4631 if (getDB().isSupportsInlineDistinct()) {
4632 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4633 orderByComparator, true);
4634 }
4635 else {
4636 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4637 orderByComparator, true);
4638 }
4639 }
4640 else {
4641 if (getDB().isSupportsInlineDistinct()) {
4642 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4643 }
4644 else {
4645 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4646 }
4647 }
4648
4649 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4650 MBCategory.class.getName(),
4651 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4652
4653 Session session = null;
4654
4655 try {
4656 session = openSession();
4657
4658 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4659
4660 if (getDB().isSupportsInlineDistinct()) {
4661 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4662 }
4663 else {
4664 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4665 }
4666
4667 QueryPos qPos = QueryPos.getInstance(q);
4668
4669 qPos.add(groupId);
4670
4671 qPos.add(status);
4672
4673 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
4674 }
4675 catch (Exception e) {
4676 throw processException(e);
4677 }
4678 finally {
4679 closeSession(session);
4680 }
4681 }
4682
4683
4693 @Override
4694 public MBCategory[] filterFindByG_S_PrevAndNext(long categoryId,
4695 long groupId, int status,
4696 OrderByComparator<MBCategory> orderByComparator)
4697 throws NoSuchCategoryException {
4698 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4699 return findByG_S_PrevAndNext(categoryId, groupId, status,
4700 orderByComparator);
4701 }
4702
4703 MBCategory mbCategory = findByPrimaryKey(categoryId);
4704
4705 Session session = null;
4706
4707 try {
4708 session = openSession();
4709
4710 MBCategory[] array = new MBCategoryImpl[3];
4711
4712 array[0] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4713 status, orderByComparator, true);
4714
4715 array[1] = mbCategory;
4716
4717 array[2] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4718 status, orderByComparator, false);
4719
4720 return array;
4721 }
4722 catch (Exception e) {
4723 throw processException(e);
4724 }
4725 finally {
4726 closeSession(session);
4727 }
4728 }
4729
4730 protected MBCategory filterGetByG_S_PrevAndNext(Session session,
4731 MBCategory mbCategory, long groupId, int status,
4732 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
4733 StringBundler query = null;
4734
4735 if (orderByComparator != null) {
4736 query = new StringBundler(6 +
4737 (orderByComparator.getOrderByFields().length * 6));
4738 }
4739 else {
4740 query = new StringBundler(3);
4741 }
4742
4743 if (getDB().isSupportsInlineDistinct()) {
4744 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4745 }
4746 else {
4747 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4748 }
4749
4750 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4751
4752 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4753
4754 if (!getDB().isSupportsInlineDistinct()) {
4755 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4756 }
4757
4758 if (orderByComparator != null) {
4759 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4760
4761 if (orderByConditionFields.length > 0) {
4762 query.append(WHERE_AND);
4763 }
4764
4765 for (int i = 0; i < orderByConditionFields.length; i++) {
4766 if (getDB().isSupportsInlineDistinct()) {
4767 query.append(_ORDER_BY_ENTITY_ALIAS);
4768 }
4769 else {
4770 query.append(_ORDER_BY_ENTITY_TABLE);
4771 }
4772
4773 query.append(orderByConditionFields[i]);
4774
4775 if ((i + 1) < orderByConditionFields.length) {
4776 if (orderByComparator.isAscending() ^ previous) {
4777 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4778 }
4779 else {
4780 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4781 }
4782 }
4783 else {
4784 if (orderByComparator.isAscending() ^ previous) {
4785 query.append(WHERE_GREATER_THAN);
4786 }
4787 else {
4788 query.append(WHERE_LESSER_THAN);
4789 }
4790 }
4791 }
4792
4793 query.append(ORDER_BY_CLAUSE);
4794
4795 String[] orderByFields = orderByComparator.getOrderByFields();
4796
4797 for (int i = 0; i < orderByFields.length; i++) {
4798 if (getDB().isSupportsInlineDistinct()) {
4799 query.append(_ORDER_BY_ENTITY_ALIAS);
4800 }
4801 else {
4802 query.append(_ORDER_BY_ENTITY_TABLE);
4803 }
4804
4805 query.append(orderByFields[i]);
4806
4807 if ((i + 1) < orderByFields.length) {
4808 if (orderByComparator.isAscending() ^ previous) {
4809 query.append(ORDER_BY_ASC_HAS_NEXT);
4810 }
4811 else {
4812 query.append(ORDER_BY_DESC_HAS_NEXT);
4813 }
4814 }
4815 else {
4816 if (orderByComparator.isAscending() ^ previous) {
4817 query.append(ORDER_BY_ASC);
4818 }
4819 else {
4820 query.append(ORDER_BY_DESC);
4821 }
4822 }
4823 }
4824 }
4825 else {
4826 if (getDB().isSupportsInlineDistinct()) {
4827 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4828 }
4829 else {
4830 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4831 }
4832 }
4833
4834 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4835 MBCategory.class.getName(),
4836 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4837
4838 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4839
4840 q.setFirstResult(0);
4841 q.setMaxResults(2);
4842
4843 if (getDB().isSupportsInlineDistinct()) {
4844 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4845 }
4846 else {
4847 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4848 }
4849
4850 QueryPos qPos = QueryPos.getInstance(q);
4851
4852 qPos.add(groupId);
4853
4854 qPos.add(status);
4855
4856 if (orderByComparator != null) {
4857 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4858
4859 for (Object value : values) {
4860 qPos.add(value);
4861 }
4862 }
4863
4864 List<MBCategory> list = q.list();
4865
4866 if (list.size() == 2) {
4867 return list.get(1);
4868 }
4869 else {
4870 return null;
4871 }
4872 }
4873
4874
4880 @Override
4881 public void removeByG_S(long groupId, int status) {
4882 for (MBCategory mbCategory : findByG_S(groupId, status,
4883 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4884 remove(mbCategory);
4885 }
4886 }
4887
4888
4895 @Override
4896 public int countByG_S(long groupId, int status) {
4897 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
4898
4899 Object[] finderArgs = new Object[] { groupId, status };
4900
4901 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4902 this);
4903
4904 if (count == null) {
4905 StringBundler query = new StringBundler(3);
4906
4907 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4908
4909 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4910
4911 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4912
4913 String sql = query.toString();
4914
4915 Session session = null;
4916
4917 try {
4918 session = openSession();
4919
4920 Query q = session.createQuery(sql);
4921
4922 QueryPos qPos = QueryPos.getInstance(q);
4923
4924 qPos.add(groupId);
4925
4926 qPos.add(status);
4927
4928 count = (Long)q.uniqueResult();
4929
4930 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4931 }
4932 catch (Exception e) {
4933 FinderCacheUtil.removeResult(finderPath, finderArgs);
4934
4935 throw processException(e);
4936 }
4937 finally {
4938 closeSession(session);
4939 }
4940 }
4941
4942 return count.intValue();
4943 }
4944
4945
4952 @Override
4953 public int filterCountByG_S(long groupId, int status) {
4954 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4955 return countByG_S(groupId, status);
4956 }
4957
4958 StringBundler query = new StringBundler(3);
4959
4960 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4961
4962 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4963
4964 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4965
4966 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4967 MBCategory.class.getName(),
4968 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4969
4970 Session session = null;
4971
4972 try {
4973 session = openSession();
4974
4975 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4976
4977 q.addScalar(COUNT_COLUMN_NAME,
4978 com.liferay.portal.kernel.dao.orm.Type.LONG);
4979
4980 QueryPos qPos = QueryPos.getInstance(q);
4981
4982 qPos.add(groupId);
4983
4984 qPos.add(status);
4985
4986 Long count = (Long)q.uniqueResult();
4987
4988 return count.intValue();
4989 }
4990 catch (Exception e) {
4991 throw processException(e);
4992 }
4993 finally {
4994 closeSession(session);
4995 }
4996 }
4997
4998 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
4999 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbCategory.status = ?";
5000 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5001 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5002 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
5003 new String[] {
5004 Long.class.getName(), Integer.class.getName(),
5005
5006 Integer.class.getName(), Integer.class.getName(),
5007 OrderByComparator.class.getName()
5008 });
5009 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5010 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5011 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
5012 new String[] { Long.class.getName(), Integer.class.getName() },
5013 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
5014 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5015 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5016 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5017 public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5018 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5019 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
5020 new String[] { Long.class.getName(), Integer.class.getName() });
5021
5022
5029 @Override
5030 public List<MBCategory> findByC_S(long companyId, int status) {
5031 return findByC_S(companyId, status, QueryUtil.ALL_POS,
5032 QueryUtil.ALL_POS, null);
5033 }
5034
5035
5048 @Override
5049 public List<MBCategory> findByC_S(long companyId, int status, int start,
5050 int end) {
5051 return findByC_S(companyId, status, start, end, null);
5052 }
5053
5054
5068 @Override
5069 public List<MBCategory> findByC_S(long companyId, int status, int start,
5070 int end, OrderByComparator<MBCategory> orderByComparator) {
5071 boolean pagination = true;
5072 FinderPath finderPath = null;
5073 Object[] finderArgs = null;
5074
5075 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5076 (orderByComparator == null)) {
5077 pagination = false;
5078 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
5079 finderArgs = new Object[] { companyId, status };
5080 }
5081 else {
5082 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
5083 finderArgs = new Object[] {
5084 companyId, status,
5085
5086 start, end, orderByComparator
5087 };
5088 }
5089
5090 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5091 finderArgs, this);
5092
5093 if ((list != null) && !list.isEmpty()) {
5094 for (MBCategory mbCategory : list) {
5095 if ((companyId != mbCategory.getCompanyId()) ||
5096 (status != mbCategory.getStatus())) {
5097 list = null;
5098
5099 break;
5100 }
5101 }
5102 }
5103
5104 if (list == null) {
5105 StringBundler query = null;
5106
5107 if (orderByComparator != null) {
5108 query = new StringBundler(4 +
5109 (orderByComparator.getOrderByFields().length * 3));
5110 }
5111 else {
5112 query = new StringBundler(4);
5113 }
5114
5115 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5116
5117 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5118
5119 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5120
5121 if (orderByComparator != null) {
5122 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5123 orderByComparator);
5124 }
5125 else
5126 if (pagination) {
5127 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5128 }
5129
5130 String sql = query.toString();
5131
5132 Session session = null;
5133
5134 try {
5135 session = openSession();
5136
5137 Query q = session.createQuery(sql);
5138
5139 QueryPos qPos = QueryPos.getInstance(q);
5140
5141 qPos.add(companyId);
5142
5143 qPos.add(status);
5144
5145 if (!pagination) {
5146 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5147 start, end, false);
5148
5149 Collections.sort(list);
5150
5151 list = Collections.unmodifiableList(list);
5152 }
5153 else {
5154 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5155 start, end);
5156 }
5157
5158 cacheResult(list);
5159
5160 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5161 }
5162 catch (Exception e) {
5163 FinderCacheUtil.removeResult(finderPath, finderArgs);
5164
5165 throw processException(e);
5166 }
5167 finally {
5168 closeSession(session);
5169 }
5170 }
5171
5172 return list;
5173 }
5174
5175
5184 @Override
5185 public MBCategory findByC_S_First(long companyId, int status,
5186 OrderByComparator<MBCategory> orderByComparator)
5187 throws NoSuchCategoryException {
5188 MBCategory mbCategory = fetchByC_S_First(companyId, status,
5189 orderByComparator);
5190
5191 if (mbCategory != null) {
5192 return mbCategory;
5193 }
5194
5195 StringBundler msg = new StringBundler(6);
5196
5197 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5198
5199 msg.append("companyId=");
5200 msg.append(companyId);
5201
5202 msg.append(", status=");
5203 msg.append(status);
5204
5205 msg.append(StringPool.CLOSE_CURLY_BRACE);
5206
5207 throw new NoSuchCategoryException(msg.toString());
5208 }
5209
5210
5218 @Override
5219 public MBCategory fetchByC_S_First(long companyId, int status,
5220 OrderByComparator<MBCategory> orderByComparator) {
5221 List<MBCategory> list = findByC_S(companyId, status, 0, 1,
5222 orderByComparator);
5223
5224 if (!list.isEmpty()) {
5225 return list.get(0);
5226 }
5227
5228 return null;
5229 }
5230
5231
5240 @Override
5241 public MBCategory findByC_S_Last(long companyId, int status,
5242 OrderByComparator<MBCategory> orderByComparator)
5243 throws NoSuchCategoryException {
5244 MBCategory mbCategory = fetchByC_S_Last(companyId, status,
5245 orderByComparator);
5246
5247 if (mbCategory != null) {
5248 return mbCategory;
5249 }
5250
5251 StringBundler msg = new StringBundler(6);
5252
5253 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5254
5255 msg.append("companyId=");
5256 msg.append(companyId);
5257
5258 msg.append(", status=");
5259 msg.append(status);
5260
5261 msg.append(StringPool.CLOSE_CURLY_BRACE);
5262
5263 throw new NoSuchCategoryException(msg.toString());
5264 }
5265
5266
5274 @Override
5275 public MBCategory fetchByC_S_Last(long companyId, int status,
5276 OrderByComparator<MBCategory> orderByComparator) {
5277 int count = countByC_S(companyId, status);
5278
5279 if (count == 0) {
5280 return null;
5281 }
5282
5283 List<MBCategory> list = findByC_S(companyId, status, count - 1, count,
5284 orderByComparator);
5285
5286 if (!list.isEmpty()) {
5287 return list.get(0);
5288 }
5289
5290 return null;
5291 }
5292
5293
5303 @Override
5304 public MBCategory[] findByC_S_PrevAndNext(long categoryId, long companyId,
5305 int status, OrderByComparator<MBCategory> orderByComparator)
5306 throws NoSuchCategoryException {
5307 MBCategory mbCategory = findByPrimaryKey(categoryId);
5308
5309 Session session = null;
5310
5311 try {
5312 session = openSession();
5313
5314 MBCategory[] array = new MBCategoryImpl[3];
5315
5316 array[0] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5317 status, orderByComparator, true);
5318
5319 array[1] = mbCategory;
5320
5321 array[2] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5322 status, orderByComparator, false);
5323
5324 return array;
5325 }
5326 catch (Exception e) {
5327 throw processException(e);
5328 }
5329 finally {
5330 closeSession(session);
5331 }
5332 }
5333
5334 protected MBCategory getByC_S_PrevAndNext(Session session,
5335 MBCategory mbCategory, long companyId, int status,
5336 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
5337 StringBundler query = null;
5338
5339 if (orderByComparator != null) {
5340 query = new StringBundler(6 +
5341 (orderByComparator.getOrderByFields().length * 6));
5342 }
5343 else {
5344 query = new StringBundler(3);
5345 }
5346
5347 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5348
5349 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5350
5351 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5352
5353 if (orderByComparator != null) {
5354 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5355
5356 if (orderByConditionFields.length > 0) {
5357 query.append(WHERE_AND);
5358 }
5359
5360 for (int i = 0; i < orderByConditionFields.length; i++) {
5361 query.append(_ORDER_BY_ENTITY_ALIAS);
5362 query.append(orderByConditionFields[i]);
5363
5364 if ((i + 1) < orderByConditionFields.length) {
5365 if (orderByComparator.isAscending() ^ previous) {
5366 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5367 }
5368 else {
5369 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5370 }
5371 }
5372 else {
5373 if (orderByComparator.isAscending() ^ previous) {
5374 query.append(WHERE_GREATER_THAN);
5375 }
5376 else {
5377 query.append(WHERE_LESSER_THAN);
5378 }
5379 }
5380 }
5381
5382 query.append(ORDER_BY_CLAUSE);
5383
5384 String[] orderByFields = orderByComparator.getOrderByFields();
5385
5386 for (int i = 0; i < orderByFields.length; i++) {
5387 query.append(_ORDER_BY_ENTITY_ALIAS);
5388 query.append(orderByFields[i]);
5389
5390 if ((i + 1) < orderByFields.length) {
5391 if (orderByComparator.isAscending() ^ previous) {
5392 query.append(ORDER_BY_ASC_HAS_NEXT);
5393 }
5394 else {
5395 query.append(ORDER_BY_DESC_HAS_NEXT);
5396 }
5397 }
5398 else {
5399 if (orderByComparator.isAscending() ^ previous) {
5400 query.append(ORDER_BY_ASC);
5401 }
5402 else {
5403 query.append(ORDER_BY_DESC);
5404 }
5405 }
5406 }
5407 }
5408 else {
5409 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5410 }
5411
5412 String sql = query.toString();
5413
5414 Query q = session.createQuery(sql);
5415
5416 q.setFirstResult(0);
5417 q.setMaxResults(2);
5418
5419 QueryPos qPos = QueryPos.getInstance(q);
5420
5421 qPos.add(companyId);
5422
5423 qPos.add(status);
5424
5425 if (orderByComparator != null) {
5426 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5427
5428 for (Object value : values) {
5429 qPos.add(value);
5430 }
5431 }
5432
5433 List<MBCategory> list = q.list();
5434
5435 if (list.size() == 2) {
5436 return list.get(1);
5437 }
5438 else {
5439 return null;
5440 }
5441 }
5442
5443
5449 @Override
5450 public void removeByC_S(long companyId, int status) {
5451 for (MBCategory mbCategory : findByC_S(companyId, status,
5452 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5453 remove(mbCategory);
5454 }
5455 }
5456
5457
5464 @Override
5465 public int countByC_S(long companyId, int status) {
5466 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
5467
5468 Object[] finderArgs = new Object[] { companyId, status };
5469
5470 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5471 this);
5472
5473 if (count == null) {
5474 StringBundler query = new StringBundler(3);
5475
5476 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5477
5478 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5479
5480 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5481
5482 String sql = query.toString();
5483
5484 Session session = null;
5485
5486 try {
5487 session = openSession();
5488
5489 Query q = session.createQuery(sql);
5490
5491 QueryPos qPos = QueryPos.getInstance(q);
5492
5493 qPos.add(companyId);
5494
5495 qPos.add(status);
5496
5497 count = (Long)q.uniqueResult();
5498
5499 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5500 }
5501 catch (Exception e) {
5502 FinderCacheUtil.removeResult(finderPath, finderArgs);
5503
5504 throw processException(e);
5505 }
5506 finally {
5507 closeSession(session);
5508 }
5509 }
5510
5511 return count.intValue();
5512 }
5513
5514 private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbCategory.companyId = ? AND ";
5515 private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbCategory.status = ?";
5516 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5517 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5518 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNotC_G_P",
5519 new String[] {
5520 Long.class.getName(), Long.class.getName(), Long.class.getName(),
5521
5522 Integer.class.getName(), Integer.class.getName(),
5523 OrderByComparator.class.getName()
5524 });
5525 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P =
5526 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5527 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5528 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByNotC_G_P",
5529 new String[] {
5530 Long.class.getName(), Long.class.getName(), Long.class.getName()
5531 });
5532
5533
5541 @Override
5542 public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5543 long parentCategoryId) {
5544 return findByNotC_G_P(categoryId, groupId, parentCategoryId,
5545 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5546 }
5547
5548
5562 @Override
5563 public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5564 long parentCategoryId, int start, int end) {
5565 return findByNotC_G_P(categoryId, groupId, parentCategoryId, start,
5566 end, null);
5567 }
5568
5569
5584 @Override
5585 public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5586 long parentCategoryId, int start, int end,
5587 OrderByComparator<MBCategory> orderByComparator) {
5588 boolean pagination = true;
5589 FinderPath finderPath = null;
5590 Object[] finderArgs = null;
5591
5592 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P;
5593 finderArgs = new Object[] {
5594 categoryId, groupId, parentCategoryId,
5595
5596 start, end, orderByComparator
5597 };
5598
5599 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5600 finderArgs, this);
5601
5602 if ((list != null) && !list.isEmpty()) {
5603 for (MBCategory mbCategory : list) {
5604 if ((categoryId == mbCategory.getCategoryId()) ||
5605 (groupId != mbCategory.getGroupId()) ||
5606 (parentCategoryId != mbCategory.getParentCategoryId())) {
5607 list = null;
5608
5609 break;
5610 }
5611 }
5612 }
5613
5614 if (list == null) {
5615 StringBundler query = null;
5616
5617 if (orderByComparator != null) {
5618 query = new StringBundler(5 +
5619 (orderByComparator.getOrderByFields().length * 3));
5620 }
5621 else {
5622 query = new StringBundler(5);
5623 }
5624
5625 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5626
5627 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
5628
5629 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
5630
5631 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
5632
5633 if (orderByComparator != null) {
5634 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5635 orderByComparator);
5636 }
5637 else
5638 if (pagination) {
5639 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5640 }
5641
5642 String sql = query.toString();
5643
5644 Session session = null;
5645
5646 try {
5647 session = openSession();
5648
5649 Query q = session.createQuery(sql);
5650
5651 QueryPos qPos = QueryPos.getInstance(q);
5652
5653 qPos.add(categoryId);
5654
5655 qPos.add(groupId);
5656
5657 qPos.add(parentCategoryId);
5658
5659 if (!pagination) {
5660 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5661 start, end, false);
5662
5663 Collections.sort(list);
5664
5665 list = Collections.unmodifiableList(list);
5666 }
5667 else {
5668 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5669 start, end);
5670 }
5671
5672 cacheResult(list);
5673
5674 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5675 }
5676 catch (Exception e) {
5677 FinderCacheUtil.removeResult(finderPath, finderArgs);
5678
5679 throw processException(e);
5680 }
5681 finally {
5682 closeSession(session);
5683 }
5684 }
5685
5686 return list;
5687 }
5688
5689
5699 @Override
5700 public MBCategory findByNotC_G_P_First(long categoryId, long groupId,
5701 long parentCategoryId, OrderByComparator<MBCategory> orderByComparator)
5702 throws NoSuchCategoryException {
5703 MBCategory mbCategory = fetchByNotC_G_P_First(categoryId, groupId,
5704 parentCategoryId, orderByComparator);
5705
5706 if (mbCategory != null) {
5707 return mbCategory;
5708 }
5709
5710 StringBundler msg = new StringBundler(8);
5711
5712 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5713
5714 msg.append("categoryId=");
5715 msg.append(categoryId);
5716
5717 msg.append(", groupId=");
5718 msg.append(groupId);
5719
5720 msg.append(", parentCategoryId=");
5721 msg.append(parentCategoryId);
5722
5723 msg.append(StringPool.CLOSE_CURLY_BRACE);
5724
5725 throw new NoSuchCategoryException(msg.toString());
5726 }
5727
5728
5737 @Override
5738 public MBCategory fetchByNotC_G_P_First(long categoryId, long groupId,
5739 long parentCategoryId, OrderByComparator<MBCategory> orderByComparator) {
5740 List<MBCategory> list = findByNotC_G_P(categoryId, groupId,
5741 parentCategoryId, 0, 1, orderByComparator);
5742
5743 if (!list.isEmpty()) {
5744 return list.get(0);
5745 }
5746
5747 return null;
5748 }
5749
5750
5760 @Override
5761 public MBCategory findByNotC_G_P_Last(long categoryId, long groupId,
5762 long parentCategoryId, OrderByComparator<MBCategory> orderByComparator)
5763 throws NoSuchCategoryException {
5764 MBCategory mbCategory = fetchByNotC_G_P_Last(categoryId, groupId,
5765 parentCategoryId, orderByComparator);
5766
5767 if (mbCategory != null) {
5768 return mbCategory;
5769 }
5770
5771 StringBundler msg = new StringBundler(8);
5772
5773 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5774
5775 msg.append("categoryId=");
5776 msg.append(categoryId);
5777
5778 msg.append(", groupId=");
5779 msg.append(groupId);
5780
5781 msg.append(", parentCategoryId=");
5782 msg.append(parentCategoryId);
5783
5784 msg.append(StringPool.CLOSE_CURLY_BRACE);
5785
5786 throw new NoSuchCategoryException(msg.toString());
5787 }
5788
5789
5798 @Override
5799 public MBCategory fetchByNotC_G_P_Last(long categoryId, long groupId,
5800 long parentCategoryId, OrderByComparator<MBCategory> orderByComparator) {
5801 int count = countByNotC_G_P(categoryId, groupId, parentCategoryId);
5802
5803 if (count == 0) {
5804 return null;
5805 }
5806
5807 List<MBCategory> list = findByNotC_G_P(categoryId, groupId,
5808 parentCategoryId, count - 1, count, orderByComparator);
5809
5810 if (!list.isEmpty()) {
5811 return list.get(0);
5812 }
5813
5814 return null;
5815 }
5816
5817
5825 @Override
5826 public List<MBCategory> filterFindByNotC_G_P(long categoryId, long groupId,
5827 long parentCategoryId) {
5828 return filterFindByNotC_G_P(categoryId, groupId, parentCategoryId,
5829 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5830 }
5831
5832
5846 @Override
5847 public List<MBCategory> filterFindByNotC_G_P(long categoryId, long groupId,
5848 long parentCategoryId, int start, int end) {
5849 return filterFindByNotC_G_P(categoryId, groupId, parentCategoryId,
5850 start, end, null);
5851 }
5852
5853
5868 @Override
5869 public List<MBCategory> filterFindByNotC_G_P(long categoryId, long groupId,
5870 long parentCategoryId, int start, int end,
5871 OrderByComparator<MBCategory> orderByComparator) {
5872 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5873 return findByNotC_G_P(categoryId, groupId, parentCategoryId, start,
5874 end, orderByComparator);
5875 }
5876
5877 StringBundler query = null;
5878
5879 if (orderByComparator != null) {
5880 query = new StringBundler(5 +
5881 (orderByComparator.getOrderByFields().length * 3));
5882 }
5883 else {
5884 query = new StringBundler(5);
5885 }
5886
5887 if (getDB().isSupportsInlineDistinct()) {
5888 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
5889 }
5890 else {
5891 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
5892 }
5893
5894 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
5895
5896 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
5897
5898 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
5899
5900 if (!getDB().isSupportsInlineDistinct()) {
5901 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
5902 }
5903
5904 if (orderByComparator != null) {
5905 if (getDB().isSupportsInlineDistinct()) {
5906 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5907 orderByComparator, true);
5908 }
5909 else {
5910 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5911 orderByComparator, true);
5912 }
5913 }
5914 else {
5915 if (getDB().isSupportsInlineDistinct()) {
5916 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5917 }
5918 else {
5919 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
5920 }
5921 }
5922
5923 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5924 MBCategory.class.getName(),
5925 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5926
5927 Session session = null;
5928
5929 try {
5930 session = openSession();
5931
5932 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5933
5934 if (getDB().isSupportsInlineDistinct()) {
5935 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
5936 }
5937 else {
5938 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
5939 }
5940
5941 QueryPos qPos = QueryPos.getInstance(q);
5942
5943 qPos.add(categoryId);
5944
5945 qPos.add(groupId);
5946
5947 qPos.add(parentCategoryId);
5948
5949 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
5950 }
5951 catch (Exception e) {
5952 throw processException(e);
5953 }
5954 finally {
5955 closeSession(session);
5956 }
5957 }
5958
5959
5967 @Override
5968 public List<MBCategory> filterFindByNotC_G_P(long[] categoryIds,
5969 long groupId, long[] parentCategoryIds) {
5970 return filterFindByNotC_G_P(categoryIds, groupId, parentCategoryIds,
5971 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5972 }
5973
5974
5988 @Override
5989 public List<MBCategory> filterFindByNotC_G_P(long[] categoryIds,
5990 long groupId, long[] parentCategoryIds, int start, int end) {
5991 return filterFindByNotC_G_P(categoryIds, groupId, parentCategoryIds,
5992 start, end, null);
5993 }
5994
5995
6010 @Override
6011 public List<MBCategory> filterFindByNotC_G_P(long[] categoryIds,
6012 long groupId, long[] parentCategoryIds, int start, int end,
6013 OrderByComparator<MBCategory> orderByComparator) {
6014 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6015 return findByNotC_G_P(categoryIds, groupId, parentCategoryIds,
6016 start, end, orderByComparator);
6017 }
6018
6019 if (categoryIds == null) {
6020 categoryIds = new long[0];
6021 }
6022 else {
6023 categoryIds = ArrayUtil.unique(categoryIds);
6024 }
6025
6026 if (parentCategoryIds == null) {
6027 parentCategoryIds = new long[0];
6028 }
6029 else {
6030 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6031 }
6032
6033 StringBundler query = new StringBundler();
6034
6035 if (getDB().isSupportsInlineDistinct()) {
6036 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6037 }
6038 else {
6039 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6040 }
6041
6042 if (categoryIds.length > 0) {
6043 query.append(StringPool.OPEN_PARENTHESIS);
6044
6045 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6046
6047 query.append(StringUtil.merge(categoryIds));
6048
6049 query.append(StringPool.CLOSE_PARENTHESIS);
6050
6051 query.append(StringPool.CLOSE_PARENTHESIS);
6052
6053 query.append(WHERE_AND);
6054 }
6055
6056 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6057
6058 if (parentCategoryIds.length > 0) {
6059 query.append(StringPool.OPEN_PARENTHESIS);
6060
6061 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6062
6063 query.append(StringUtil.merge(parentCategoryIds));
6064
6065 query.append(StringPool.CLOSE_PARENTHESIS);
6066
6067 query.append(StringPool.CLOSE_PARENTHESIS);
6068 }
6069
6070 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6071 query.index() - 1);
6072
6073 if (!getDB().isSupportsInlineDistinct()) {
6074 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6075 }
6076
6077 if (orderByComparator != null) {
6078 if (getDB().isSupportsInlineDistinct()) {
6079 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6080 orderByComparator, true);
6081 }
6082 else {
6083 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6084 orderByComparator, true);
6085 }
6086 }
6087 else {
6088 if (getDB().isSupportsInlineDistinct()) {
6089 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6090 }
6091 else {
6092 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6093 }
6094 }
6095
6096 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6097 MBCategory.class.getName(),
6098 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6099
6100 Session session = null;
6101
6102 try {
6103 session = openSession();
6104
6105 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6106
6107 if (getDB().isSupportsInlineDistinct()) {
6108 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6109 }
6110 else {
6111 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6112 }
6113
6114 QueryPos qPos = QueryPos.getInstance(q);
6115
6116 qPos.add(groupId);
6117
6118 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6119 }
6120 catch (Exception e) {
6121 throw processException(e);
6122 }
6123 finally {
6124 closeSession(session);
6125 }
6126 }
6127
6128
6140 @Override
6141 public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6142 long[] parentCategoryIds) {
6143 return findByNotC_G_P(categoryIds, groupId, parentCategoryIds,
6144 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6145 }
6146
6147
6161 @Override
6162 public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6163 long[] parentCategoryIds, int start, int end) {
6164 return findByNotC_G_P(categoryIds, groupId, parentCategoryIds, start,
6165 end, null);
6166 }
6167
6168
6183 @Override
6184 public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6185 long[] parentCategoryIds, int start, int end,
6186 OrderByComparator<MBCategory> orderByComparator) {
6187 if (categoryIds == null) {
6188 categoryIds = new long[0];
6189 }
6190 else {
6191 categoryIds = ArrayUtil.unique(categoryIds);
6192 }
6193
6194 if (parentCategoryIds == null) {
6195 parentCategoryIds = new long[0];
6196 }
6197 else {
6198 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6199 }
6200
6201 if ((categoryIds.length == 1) && (parentCategoryIds.length == 1)) {
6202 return findByNotC_G_P(categoryIds[0], groupId,
6203 parentCategoryIds[0], start, end, orderByComparator);
6204 }
6205
6206 boolean pagination = true;
6207 Object[] finderArgs = null;
6208
6209 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6210 (orderByComparator == null)) {
6211 pagination = false;
6212 finderArgs = new Object[] {
6213 StringUtil.merge(categoryIds), groupId,
6214 StringUtil.merge(parentCategoryIds)
6215 };
6216 }
6217 else {
6218 finderArgs = new Object[] {
6219 StringUtil.merge(categoryIds), groupId,
6220 StringUtil.merge(parentCategoryIds),
6221
6222 start, end, orderByComparator
6223 };
6224 }
6225
6226 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P,
6227 finderArgs, this);
6228
6229 if ((list != null) && !list.isEmpty()) {
6230 for (MBCategory mbCategory : list) {
6231 if (!ArrayUtil.contains(categoryIds, mbCategory.getCategoryId()) ||
6232 (groupId != mbCategory.getGroupId()) ||
6233 !ArrayUtil.contains(parentCategoryIds,
6234 mbCategory.getParentCategoryId())) {
6235 list = null;
6236
6237 break;
6238 }
6239 }
6240 }
6241
6242 if (list == null) {
6243 StringBundler query = new StringBundler();
6244
6245 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6246
6247 if (categoryIds.length > 0) {
6248 query.append(StringPool.OPEN_PARENTHESIS);
6249
6250 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6251
6252 query.append(StringUtil.merge(categoryIds));
6253
6254 query.append(StringPool.CLOSE_PARENTHESIS);
6255
6256 query.append(StringPool.CLOSE_PARENTHESIS);
6257
6258 query.append(WHERE_AND);
6259 }
6260
6261 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6262
6263 if (parentCategoryIds.length > 0) {
6264 query.append(StringPool.OPEN_PARENTHESIS);
6265
6266 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6267
6268 query.append(StringUtil.merge(parentCategoryIds));
6269
6270 query.append(StringPool.CLOSE_PARENTHESIS);
6271
6272 query.append(StringPool.CLOSE_PARENTHESIS);
6273 }
6274
6275 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6276 1)), query.index() - 1);
6277
6278 if (orderByComparator != null) {
6279 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6280 orderByComparator);
6281 }
6282 else
6283 if (pagination) {
6284 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6285 }
6286
6287 String sql = query.toString();
6288
6289 Session session = null;
6290
6291 try {
6292 session = openSession();
6293
6294 Query q = session.createQuery(sql);
6295
6296 QueryPos qPos = QueryPos.getInstance(q);
6297
6298 qPos.add(groupId);
6299
6300 if (!pagination) {
6301 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6302 start, end, false);
6303
6304 Collections.sort(list);
6305
6306 list = Collections.unmodifiableList(list);
6307 }
6308 else {
6309 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6310 start, end);
6311 }
6312
6313 cacheResult(list);
6314
6315 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P,
6316 finderArgs, list);
6317 }
6318 catch (Exception e) {
6319 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P,
6320 finderArgs);
6321
6322 throw processException(e);
6323 }
6324 finally {
6325 closeSession(session);
6326 }
6327 }
6328
6329 return list;
6330 }
6331
6332
6339 @Override
6340 public void removeByNotC_G_P(long categoryId, long groupId,
6341 long parentCategoryId) {
6342 for (MBCategory mbCategory : findByNotC_G_P(categoryId, groupId,
6343 parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6344 remove(mbCategory);
6345 }
6346 }
6347
6348
6356 @Override
6357 public int countByNotC_G_P(long categoryId, long groupId,
6358 long parentCategoryId) {
6359 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P;
6360
6361 Object[] finderArgs = new Object[] { categoryId, groupId, parentCategoryId };
6362
6363 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6364 this);
6365
6366 if (count == null) {
6367 StringBundler query = new StringBundler(4);
6368
6369 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6370
6371 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
6372
6373 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6374
6375 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
6376
6377 String sql = query.toString();
6378
6379 Session session = null;
6380
6381 try {
6382 session = openSession();
6383
6384 Query q = session.createQuery(sql);
6385
6386 QueryPos qPos = QueryPos.getInstance(q);
6387
6388 qPos.add(categoryId);
6389
6390 qPos.add(groupId);
6391
6392 qPos.add(parentCategoryId);
6393
6394 count = (Long)q.uniqueResult();
6395
6396 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6397 }
6398 catch (Exception e) {
6399 FinderCacheUtil.removeResult(finderPath, finderArgs);
6400
6401 throw processException(e);
6402 }
6403 finally {
6404 closeSession(session);
6405 }
6406 }
6407
6408 return count.intValue();
6409 }
6410
6411
6419 @Override
6420 public int countByNotC_G_P(long[] categoryIds, long groupId,
6421 long[] parentCategoryIds) {
6422 if (categoryIds == null) {
6423 categoryIds = new long[0];
6424 }
6425 else {
6426 categoryIds = ArrayUtil.unique(categoryIds);
6427 }
6428
6429 if (parentCategoryIds == null) {
6430 parentCategoryIds = new long[0];
6431 }
6432 else {
6433 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6434 }
6435
6436 Object[] finderArgs = new Object[] {
6437 StringUtil.merge(categoryIds), groupId,
6438 StringUtil.merge(parentCategoryIds)
6439 };
6440
6441 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P,
6442 finderArgs, this);
6443
6444 if (count == null) {
6445 StringBundler query = new StringBundler();
6446
6447 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6448
6449 if (categoryIds.length > 0) {
6450 query.append(StringPool.OPEN_PARENTHESIS);
6451
6452 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6453
6454 query.append(StringUtil.merge(categoryIds));
6455
6456 query.append(StringPool.CLOSE_PARENTHESIS);
6457
6458 query.append(StringPool.CLOSE_PARENTHESIS);
6459
6460 query.append(WHERE_AND);
6461 }
6462
6463 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6464
6465 if (parentCategoryIds.length > 0) {
6466 query.append(StringPool.OPEN_PARENTHESIS);
6467
6468 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6469
6470 query.append(StringUtil.merge(parentCategoryIds));
6471
6472 query.append(StringPool.CLOSE_PARENTHESIS);
6473
6474 query.append(StringPool.CLOSE_PARENTHESIS);
6475 }
6476
6477 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6478 1)), query.index() - 1);
6479
6480 String sql = query.toString();
6481
6482 Session session = null;
6483
6484 try {
6485 session = openSession();
6486
6487 Query q = session.createQuery(sql);
6488
6489 QueryPos qPos = QueryPos.getInstance(q);
6490
6491 qPos.add(groupId);
6492
6493 count = (Long)q.uniqueResult();
6494
6495 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P,
6496 finderArgs, count);
6497 }
6498 catch (Exception e) {
6499 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P,
6500 finderArgs);
6501
6502 throw processException(e);
6503 }
6504 finally {
6505 closeSession(session);
6506 }
6507 }
6508
6509 return count.intValue();
6510 }
6511
6512
6520 @Override
6521 public int filterCountByNotC_G_P(long categoryId, long groupId,
6522 long parentCategoryId) {
6523 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6524 return countByNotC_G_P(categoryId, groupId, parentCategoryId);
6525 }
6526
6527 StringBundler query = new StringBundler(4);
6528
6529 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6530
6531 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
6532
6533 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6534
6535 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
6536
6537 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6538 MBCategory.class.getName(),
6539 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6540
6541 Session session = null;
6542
6543 try {
6544 session = openSession();
6545
6546 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6547
6548 q.addScalar(COUNT_COLUMN_NAME,
6549 com.liferay.portal.kernel.dao.orm.Type.LONG);
6550
6551 QueryPos qPos = QueryPos.getInstance(q);
6552
6553 qPos.add(categoryId);
6554
6555 qPos.add(groupId);
6556
6557 qPos.add(parentCategoryId);
6558
6559 Long count = (Long)q.uniqueResult();
6560
6561 return count.intValue();
6562 }
6563 catch (Exception e) {
6564 throw processException(e);
6565 }
6566 finally {
6567 closeSession(session);
6568 }
6569 }
6570
6571
6579 @Override
6580 public int filterCountByNotC_G_P(long[] categoryIds, long groupId,
6581 long[] parentCategoryIds) {
6582 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6583 return countByNotC_G_P(categoryIds, groupId, parentCategoryIds);
6584 }
6585
6586 if (categoryIds == null) {
6587 categoryIds = new long[0];
6588 }
6589 else {
6590 categoryIds = ArrayUtil.unique(categoryIds);
6591 }
6592
6593 if (parentCategoryIds == null) {
6594 parentCategoryIds = new long[0];
6595 }
6596 else {
6597 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6598 }
6599
6600 StringBundler query = new StringBundler();
6601
6602 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6603
6604 if (categoryIds.length > 0) {
6605 query.append(StringPool.OPEN_PARENTHESIS);
6606
6607 query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6608
6609 query.append(StringUtil.merge(categoryIds));
6610
6611 query.append(StringPool.CLOSE_PARENTHESIS);
6612
6613 query.append(StringPool.CLOSE_PARENTHESIS);
6614
6615 query.append(WHERE_AND);
6616 }
6617
6618 query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6619
6620 if (parentCategoryIds.length > 0) {
6621 query.append(StringPool.OPEN_PARENTHESIS);
6622
6623 query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6624
6625 query.append(StringUtil.merge(parentCategoryIds));
6626
6627 query.append(StringPool.CLOSE_PARENTHESIS);
6628
6629 query.append(StringPool.CLOSE_PARENTHESIS);
6630 }
6631
6632 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6633 query.index() - 1);
6634
6635 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6636 MBCategory.class.getName(),
6637 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6638
6639 Session session = null;
6640
6641 try {
6642 session = openSession();
6643
6644 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6645
6646 q.addScalar(COUNT_COLUMN_NAME,
6647 com.liferay.portal.kernel.dao.orm.Type.LONG);
6648
6649 QueryPos qPos = QueryPos.getInstance(q);
6650
6651 qPos.add(groupId);
6652
6653 Long count = (Long)q.uniqueResult();
6654
6655 return count.intValue();
6656 }
6657 catch (Exception e) {
6658 throw processException(e);
6659 }
6660 finally {
6661 closeSession(session);
6662 }
6663 }
6664
6665 private static final String _FINDER_COLUMN_NOTC_G_P_CATEGORYID_2 = "mbCategory.categoryId != ? AND ";
6666 private static final String _FINDER_COLUMN_NOTC_G_P_CATEGORYID_7 = "mbCategory.categoryId NOT IN (";
6667 private static final String _FINDER_COLUMN_NOTC_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
6668 private static final String _FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
6669 private static final String _FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
6670 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6671 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
6672 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_S",
6673 new String[] {
6674 Long.class.getName(), Long.class.getName(),
6675 Integer.class.getName(),
6676
6677 Integer.class.getName(), Integer.class.getName(),
6678 OrderByComparator.class.getName()
6679 });
6680 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6681 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
6682 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_S",
6683 new String[] {
6684 Long.class.getName(), Long.class.getName(),
6685 Integer.class.getName()
6686 },
6687 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
6688 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
6689 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
6690 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
6691 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6692 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6693 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
6694 new String[] {
6695 Long.class.getName(), Long.class.getName(),
6696 Integer.class.getName()
6697 });
6698 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6699 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6700 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_S",
6701 new String[] {
6702 Long.class.getName(), Long.class.getName(),
6703 Integer.class.getName()
6704 });
6705
6706
6714 @Override
6715 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
6716 int status) {
6717 return findByG_P_S(groupId, parentCategoryId, status,
6718 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6719 }
6720
6721
6735 @Override
6736 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
6737 int status, int start, int end) {
6738 return findByG_P_S(groupId, parentCategoryId, status, start, end, null);
6739 }
6740
6741
6756 @Override
6757 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
6758 int status, int start, int end,
6759 OrderByComparator<MBCategory> orderByComparator) {
6760 boolean pagination = true;
6761 FinderPath finderPath = null;
6762 Object[] finderArgs = null;
6763
6764 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6765 (orderByComparator == null)) {
6766 pagination = false;
6767 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
6768 finderArgs = new Object[] { groupId, parentCategoryId, status };
6769 }
6770 else {
6771 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
6772 finderArgs = new Object[] {
6773 groupId, parentCategoryId, status,
6774
6775 start, end, orderByComparator
6776 };
6777 }
6778
6779 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
6780 finderArgs, this);
6781
6782 if ((list != null) && !list.isEmpty()) {
6783 for (MBCategory mbCategory : list) {
6784 if ((groupId != mbCategory.getGroupId()) ||
6785 (parentCategoryId != mbCategory.getParentCategoryId()) ||
6786 (status != mbCategory.getStatus())) {
6787 list = null;
6788
6789 break;
6790 }
6791 }
6792 }
6793
6794 if (list == null) {
6795 StringBundler query = null;
6796
6797 if (orderByComparator != null) {
6798 query = new StringBundler(5 +
6799 (orderByComparator.getOrderByFields().length * 3));
6800 }
6801 else {
6802 query = new StringBundler(5);
6803 }
6804
6805 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6806
6807 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6808
6809 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6810
6811 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6812
6813 if (orderByComparator != null) {
6814 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6815 orderByComparator);
6816 }
6817 else
6818 if (pagination) {
6819 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6820 }
6821
6822 String sql = query.toString();
6823
6824 Session session = null;
6825
6826 try {
6827 session = openSession();
6828
6829 Query q = session.createQuery(sql);
6830
6831 QueryPos qPos = QueryPos.getInstance(q);
6832
6833 qPos.add(groupId);
6834
6835 qPos.add(parentCategoryId);
6836
6837 qPos.add(status);
6838
6839 if (!pagination) {
6840 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6841 start, end, false);
6842
6843 Collections.sort(list);
6844
6845 list = Collections.unmodifiableList(list);
6846 }
6847 else {
6848 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6849 start, end);
6850 }
6851
6852 cacheResult(list);
6853
6854 FinderCacheUtil.putResult(finderPath, finderArgs, list);
6855 }
6856 catch (Exception e) {
6857 FinderCacheUtil.removeResult(finderPath, finderArgs);
6858
6859 throw processException(e);
6860 }
6861 finally {
6862 closeSession(session);
6863 }
6864 }
6865
6866 return list;
6867 }
6868
6869
6879 @Override
6880 public MBCategory findByG_P_S_First(long groupId, long parentCategoryId,
6881 int status, OrderByComparator<MBCategory> orderByComparator)
6882 throws NoSuchCategoryException {
6883 MBCategory mbCategory = fetchByG_P_S_First(groupId, parentCategoryId,
6884 status, orderByComparator);
6885
6886 if (mbCategory != null) {
6887 return mbCategory;
6888 }
6889
6890 StringBundler msg = new StringBundler(8);
6891
6892 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6893
6894 msg.append("groupId=");
6895 msg.append(groupId);
6896
6897 msg.append(", parentCategoryId=");
6898 msg.append(parentCategoryId);
6899
6900 msg.append(", status=");
6901 msg.append(status);
6902
6903 msg.append(StringPool.CLOSE_CURLY_BRACE);
6904
6905 throw new NoSuchCategoryException(msg.toString());
6906 }
6907
6908
6917 @Override
6918 public MBCategory fetchByG_P_S_First(long groupId, long parentCategoryId,
6919 int status, OrderByComparator<MBCategory> orderByComparator) {
6920 List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
6921 0, 1, orderByComparator);
6922
6923 if (!list.isEmpty()) {
6924 return list.get(0);
6925 }
6926
6927 return null;
6928 }
6929
6930
6940 @Override
6941 public MBCategory findByG_P_S_Last(long groupId, long parentCategoryId,
6942 int status, OrderByComparator<MBCategory> orderByComparator)
6943 throws NoSuchCategoryException {
6944 MBCategory mbCategory = fetchByG_P_S_Last(groupId, parentCategoryId,
6945 status, orderByComparator);
6946
6947 if (mbCategory != null) {
6948 return mbCategory;
6949 }
6950
6951 StringBundler msg = new StringBundler(8);
6952
6953 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6954
6955 msg.append("groupId=");
6956 msg.append(groupId);
6957
6958 msg.append(", parentCategoryId=");
6959 msg.append(parentCategoryId);
6960
6961 msg.append(", status=");
6962 msg.append(status);
6963
6964 msg.append(StringPool.CLOSE_CURLY_BRACE);
6965
6966 throw new NoSuchCategoryException(msg.toString());
6967 }
6968
6969
6978 @Override
6979 public MBCategory fetchByG_P_S_Last(long groupId, long parentCategoryId,
6980 int status, OrderByComparator<MBCategory> orderByComparator) {
6981 int count = countByG_P_S(groupId, parentCategoryId, status);
6982
6983 if (count == 0) {
6984 return null;
6985 }
6986
6987 List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
6988 count - 1, count, orderByComparator);
6989
6990 if (!list.isEmpty()) {
6991 return list.get(0);
6992 }
6993
6994 return null;
6995 }
6996
6997
7008 @Override
7009 public MBCategory[] findByG_P_S_PrevAndNext(long categoryId, long groupId,
7010 long parentCategoryId, int status,
7011 OrderByComparator<MBCategory> orderByComparator)
7012 throws NoSuchCategoryException {
7013 MBCategory mbCategory = findByPrimaryKey(categoryId);
7014
7015 Session session = null;
7016
7017 try {
7018 session = openSession();
7019
7020 MBCategory[] array = new MBCategoryImpl[3];
7021
7022 array[0] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
7023 parentCategoryId, status, orderByComparator, true);
7024
7025 array[1] = mbCategory;
7026
7027 array[2] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
7028 parentCategoryId, status, orderByComparator, false);
7029
7030 return array;
7031 }
7032 catch (Exception e) {
7033 throw processException(e);
7034 }
7035 finally {
7036 closeSession(session);
7037 }
7038 }
7039
7040 protected MBCategory getByG_P_S_PrevAndNext(Session session,
7041 MBCategory mbCategory, long groupId, long parentCategoryId, int status,
7042 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
7043 StringBundler query = null;
7044
7045 if (orderByComparator != null) {
7046 query = new StringBundler(6 +
7047 (orderByComparator.getOrderByFields().length * 6));
7048 }
7049 else {
7050 query = new StringBundler(3);
7051 }
7052
7053 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
7054
7055 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7056
7057 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7058
7059 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7060
7061 if (orderByComparator != null) {
7062 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7063
7064 if (orderByConditionFields.length > 0) {
7065 query.append(WHERE_AND);
7066 }
7067
7068 for (int i = 0; i < orderByConditionFields.length; i++) {
7069 query.append(_ORDER_BY_ENTITY_ALIAS);
7070 query.append(orderByConditionFields[i]);
7071
7072 if ((i + 1) < orderByConditionFields.length) {
7073 if (orderByComparator.isAscending() ^ previous) {
7074 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7075 }
7076 else {
7077 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7078 }
7079 }
7080 else {
7081 if (orderByComparator.isAscending() ^ previous) {
7082 query.append(WHERE_GREATER_THAN);
7083 }
7084 else {
7085 query.append(WHERE_LESSER_THAN);
7086 }
7087 }
7088 }
7089
7090 query.append(ORDER_BY_CLAUSE);
7091
7092 String[] orderByFields = orderByComparator.getOrderByFields();
7093
7094 for (int i = 0; i < orderByFields.length; i++) {
7095 query.append(_ORDER_BY_ENTITY_ALIAS);
7096 query.append(orderByFields[i]);
7097
7098 if ((i + 1) < orderByFields.length) {
7099 if (orderByComparator.isAscending() ^ previous) {
7100 query.append(ORDER_BY_ASC_HAS_NEXT);
7101 }
7102 else {
7103 query.append(ORDER_BY_DESC_HAS_NEXT);
7104 }
7105 }
7106 else {
7107 if (orderByComparator.isAscending() ^ previous) {
7108 query.append(ORDER_BY_ASC);
7109 }
7110 else {
7111 query.append(ORDER_BY_DESC);
7112 }
7113 }
7114 }
7115 }
7116 else {
7117 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7118 }
7119
7120 String sql = query.toString();
7121
7122 Query q = session.createQuery(sql);
7123
7124 q.setFirstResult(0);
7125 q.setMaxResults(2);
7126
7127 QueryPos qPos = QueryPos.getInstance(q);
7128
7129 qPos.add(groupId);
7130
7131 qPos.add(parentCategoryId);
7132
7133 qPos.add(status);
7134
7135 if (orderByComparator != null) {
7136 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
7137
7138 for (Object value : values) {
7139 qPos.add(value);
7140 }
7141 }
7142
7143 List<MBCategory> list = q.list();
7144
7145 if (list.size() == 2) {
7146 return list.get(1);
7147 }
7148 else {
7149 return null;
7150 }
7151 }
7152
7153
7161 @Override
7162 public List<MBCategory> filterFindByG_P_S(long groupId,
7163 long parentCategoryId, int status) {
7164 return filterFindByG_P_S(groupId, parentCategoryId, status,
7165 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7166 }
7167
7168
7182 @Override
7183 public List<MBCategory> filterFindByG_P_S(long groupId,
7184 long parentCategoryId, int status, int start, int end) {
7185 return filterFindByG_P_S(groupId, parentCategoryId, status, start, end,
7186 null);
7187 }
7188
7189
7204 @Override
7205 public List<MBCategory> filterFindByG_P_S(long groupId,
7206 long parentCategoryId, int status, int start, int end,
7207 OrderByComparator<MBCategory> orderByComparator) {
7208 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7209 return findByG_P_S(groupId, parentCategoryId, status, start, end,
7210 orderByComparator);
7211 }
7212
7213 StringBundler query = null;
7214
7215 if (orderByComparator != null) {
7216 query = new StringBundler(5 +
7217 (orderByComparator.getOrderByFields().length * 3));
7218 }
7219 else {
7220 query = new StringBundler(5);
7221 }
7222
7223 if (getDB().isSupportsInlineDistinct()) {
7224 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
7225 }
7226 else {
7227 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7228 }
7229
7230 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7231
7232 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7233
7234 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7235
7236 if (!getDB().isSupportsInlineDistinct()) {
7237 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7238 }
7239
7240 if (orderByComparator != null) {
7241 if (getDB().isSupportsInlineDistinct()) {
7242 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7243 orderByComparator, true);
7244 }
7245 else {
7246 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7247 orderByComparator, true);
7248 }
7249 }
7250 else {
7251 if (getDB().isSupportsInlineDistinct()) {
7252 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7253 }
7254 else {
7255 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
7256 }
7257 }
7258
7259 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7260 MBCategory.class.getName(),
7261 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7262
7263 Session session = null;
7264
7265 try {
7266 session = openSession();
7267
7268 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7269
7270 if (getDB().isSupportsInlineDistinct()) {
7271 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
7272 }
7273 else {
7274 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
7275 }
7276
7277 QueryPos qPos = QueryPos.getInstance(q);
7278
7279 qPos.add(groupId);
7280
7281 qPos.add(parentCategoryId);
7282
7283 qPos.add(status);
7284
7285 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
7286 }
7287 catch (Exception e) {
7288 throw processException(e);
7289 }
7290 finally {
7291 closeSession(session);
7292 }
7293 }
7294
7295
7306 @Override
7307 public MBCategory[] filterFindByG_P_S_PrevAndNext(long categoryId,
7308 long groupId, long parentCategoryId, int status,
7309 OrderByComparator<MBCategory> orderByComparator)
7310 throws NoSuchCategoryException {
7311 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7312 return findByG_P_S_PrevAndNext(categoryId, groupId,
7313 parentCategoryId, status, orderByComparator);
7314 }
7315
7316 MBCategory mbCategory = findByPrimaryKey(categoryId);
7317
7318 Session session = null;
7319
7320 try {
7321 session = openSession();
7322
7323 MBCategory[] array = new MBCategoryImpl[3];
7324
7325 array[0] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
7326 groupId, parentCategoryId, status, orderByComparator, true);
7327
7328 array[1] = mbCategory;
7329
7330 array[2] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
7331 groupId, parentCategoryId, status, orderByComparator, false);
7332
7333 return array;
7334 }
7335 catch (Exception e) {
7336 throw processException(e);
7337 }
7338 finally {
7339 closeSession(session);
7340 }
7341 }
7342
7343 protected MBCategory filterGetByG_P_S_PrevAndNext(Session session,
7344 MBCategory mbCategory, long groupId, long parentCategoryId, int status,
7345 OrderByComparator<MBCategory> orderByComparator, boolean previous) {
7346 StringBundler query = null;
7347
7348 if (orderByComparator != null) {
7349 query = new StringBundler(6 +
7350 (orderByComparator.getOrderByFields().length * 6));
7351 }
7352 else {
7353 query = new StringBundler(3);
7354 }
7355
7356 if (getDB().isSupportsInlineDistinct()) {
7357 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
7358 }
7359 else {
7360 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7361 }
7362
7363 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7364
7365 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7366
7367 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7368
7369 if (!getDB().isSupportsInlineDistinct()) {
7370 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7371 }
7372
7373 if (orderByComparator != null) {
7374 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7375
7376 if (orderByConditionFields.length > 0) {
7377 query.append(WHERE_AND);
7378 }
7379
7380 for (int i = 0; i < orderByConditionFields.length; i++) {
7381 if (getDB().isSupportsInlineDistinct()) {
7382 query.append(_ORDER_BY_ENTITY_ALIAS);
7383 }
7384 else {
7385 query.append(_ORDER_BY_ENTITY_TABLE);
7386 }
7387
7388 query.append(orderByConditionFields[i]);
7389
7390 if ((i + 1) < orderByConditionFields.length) {
7391 if (orderByComparator.isAscending() ^ previous) {
7392 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7393 }
7394 else {
7395 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7396 }
7397 }
7398 else {
7399 if (orderByComparator.isAscending() ^ previous) {
7400 query.append(WHERE_GREATER_THAN);
7401 }
7402 else {
7403 query.append(WHERE_LESSER_THAN);
7404 }
7405 }
7406 }
7407
7408 query.append(ORDER_BY_CLAUSE);
7409
7410 String[] orderByFields = orderByComparator.getOrderByFields();
7411
7412 for (int i = 0; i < orderByFields.length; i++) {
7413 if (getDB().isSupportsInlineDistinct()) {
7414 query.append(_ORDER_BY_ENTITY_ALIAS);
7415 }
7416 else {
7417 query.append(_ORDER_BY_ENTITY_TABLE);
7418 }
7419
7420 query.append(orderByFields[i]);
7421
7422 if ((i + 1) < orderByFields.length) {
7423 if (orderByComparator.isAscending() ^ previous) {
7424 query.append(ORDER_BY_ASC_HAS_NEXT);
7425 }
7426 else {
7427 query.append(ORDER_BY_DESC_HAS_NEXT);
7428 }
7429 }
7430 else {
7431 if (orderByComparator.isAscending() ^ previous) {
7432 query.append(ORDER_BY_ASC);
7433 }
7434 else {
7435 query.append(ORDER_BY_DESC);
7436 }
7437 }
7438 }
7439 }
7440 else {
7441 if (getDB().isSupportsInlineDistinct()) {
7442 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7443 }
7444 else {
7445 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
7446 }
7447 }
7448
7449 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7450 MBCategory.class.getName(),
7451 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7452
7453 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7454
7455 q.setFirstResult(0);
7456 q.setMaxResults(2);
7457
7458 if (getDB().isSupportsInlineDistinct()) {
7459 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
7460 }
7461 else {
7462 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
7463 }
7464
7465 QueryPos qPos = QueryPos.getInstance(q);
7466
7467 qPos.add(groupId);
7468
7469 qPos.add(parentCategoryId);
7470
7471 qPos.add(status);
7472
7473 if (orderByComparator != null) {
7474 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
7475
7476 for (Object value : values) {
7477 qPos.add(value);
7478 }
7479 }
7480
7481 List<MBCategory> list = q.list();
7482
7483 if (list.size() == 2) {
7484 return list.get(1);
7485 }
7486 else {
7487 return null;
7488 }
7489 }
7490
7491
7499 @Override
7500 public List<MBCategory> filterFindByG_P_S(long groupId,
7501 long[] parentCategoryIds, int status) {
7502 return filterFindByG_P_S(groupId, parentCategoryIds, status,
7503 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7504 }
7505
7506
7520 @Override
7521 public List<MBCategory> filterFindByG_P_S(long groupId,
7522 long[] parentCategoryIds, int status, int start, int end) {
7523 return filterFindByG_P_S(groupId, parentCategoryIds, status, start,
7524 end, null);
7525 }
7526
7527
7542 @Override
7543 public List<MBCategory> filterFindByG_P_S(long groupId,
7544 long[] parentCategoryIds, int status, int start, int end,
7545 OrderByComparator<MBCategory> orderByComparator) {
7546 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7547 return findByG_P_S(groupId, parentCategoryIds, status, start, end,
7548 orderByComparator);
7549 }
7550
7551 if (parentCategoryIds == null) {
7552 parentCategoryIds = new long[0];
7553 }
7554 else {
7555 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
7556 }
7557
7558 StringBundler query = new StringBundler();
7559
7560 if (getDB().isSupportsInlineDistinct()) {
7561 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
7562 }
7563 else {
7564 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7565 }
7566
7567 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7568
7569 if (parentCategoryIds.length > 0) {
7570 query.append(StringPool.OPEN_PARENTHESIS);
7571
7572 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
7573
7574 query.append(StringUtil.merge(parentCategoryIds));
7575
7576 query.append(StringPool.CLOSE_PARENTHESIS);
7577
7578 query.append(StringPool.CLOSE_PARENTHESIS);
7579
7580 query.append(WHERE_AND);
7581 }
7582
7583 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7584
7585 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
7586 query.index() - 1);
7587
7588 if (!getDB().isSupportsInlineDistinct()) {
7589 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7590 }
7591
7592 if (orderByComparator != null) {
7593 if (getDB().isSupportsInlineDistinct()) {
7594 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7595 orderByComparator, true);
7596 }
7597 else {
7598 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7599 orderByComparator, true);
7600 }
7601 }
7602 else {
7603 if (getDB().isSupportsInlineDistinct()) {
7604 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7605 }
7606 else {
7607 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
7608 }
7609 }
7610
7611 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7612 MBCategory.class.getName(),
7613 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7614
7615 Session session = null;
7616
7617 try {
7618 session = openSession();
7619
7620 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7621
7622 if (getDB().isSupportsInlineDistinct()) {
7623 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
7624 }
7625 else {
7626 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
7627 }
7628
7629 QueryPos qPos = QueryPos.getInstance(q);
7630
7631 qPos.add(groupId);
7632
7633 qPos.add(status);
7634
7635 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
7636 }
7637 catch (Exception e) {
7638 throw processException(e);
7639 }
7640 finally {
7641 closeSession(session);
7642 }
7643 }
7644
7645
7657 @Override
7658 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
7659 int status) {
7660 return findByG_P_S(groupId, parentCategoryIds, status,
7661 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7662 }
7663
7664
7678 @Override
7679 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
7680 int status, int start, int end) {
7681 return findByG_P_S(groupId, parentCategoryIds, status, start, end, null);
7682 }
7683
7684
7699 @Override
7700 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
7701 int status, int start, int end,
7702 OrderByComparator<MBCategory> orderByComparator) {
7703 if (parentCategoryIds == null) {
7704 parentCategoryIds = new long[0];
7705 }
7706 else {
7707 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
7708 }
7709
7710 if (parentCategoryIds.length == 1) {
7711 return findByG_P_S(groupId, parentCategoryIds[0], status, start,
7712 end, orderByComparator);
7713 }
7714
7715 boolean pagination = true;
7716 Object[] finderArgs = null;
7717
7718 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7719 (orderByComparator == null)) {
7720 pagination = false;
7721 finderArgs = new Object[] {
7722 groupId, StringUtil.merge(parentCategoryIds), status
7723 };
7724 }
7725 else {
7726 finderArgs = new Object[] {
7727 groupId, StringUtil.merge(parentCategoryIds), status,
7728
7729 start, end, orderByComparator
7730 };
7731 }
7732
7733 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
7734 finderArgs, this);
7735
7736 if ((list != null) && !list.isEmpty()) {
7737 for (MBCategory mbCategory : list) {
7738 if ((groupId != mbCategory.getGroupId()) ||
7739 !ArrayUtil.contains(parentCategoryIds,
7740 mbCategory.getParentCategoryId()) ||
7741 (status != mbCategory.getStatus())) {
7742 list = null;
7743
7744 break;
7745 }
7746 }
7747 }
7748
7749 if (list == null) {
7750 StringBundler query = new StringBundler();
7751
7752 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
7753
7754 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7755
7756 if (parentCategoryIds.length > 0) {
7757 query.append(StringPool.OPEN_PARENTHESIS);
7758
7759 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
7760
7761 query.append(StringUtil.merge(parentCategoryIds));
7762
7763 query.append(StringPool.CLOSE_PARENTHESIS);
7764
7765 query.append(StringPool.CLOSE_PARENTHESIS);
7766
7767 query.append(WHERE_AND);
7768 }
7769
7770 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7771
7772 query.setStringAt(removeConjunction(query.stringAt(query.index() -
7773 1)), query.index() - 1);
7774
7775 if (orderByComparator != null) {
7776 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7777 orderByComparator);
7778 }
7779 else
7780 if (pagination) {
7781 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7782 }
7783
7784 String sql = query.toString();
7785
7786 Session session = null;
7787
7788 try {
7789 session = openSession();
7790
7791 Query q = session.createQuery(sql);
7792
7793 QueryPos qPos = QueryPos.getInstance(q);
7794
7795 qPos.add(groupId);
7796
7797 qPos.add(status);
7798
7799 if (!pagination) {
7800 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7801 start, end, false);
7802
7803 Collections.sort(list);
7804
7805 list = Collections.unmodifiableList(list);
7806 }
7807 else {
7808 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7809 start, end);
7810 }
7811
7812 cacheResult(list);
7813
7814 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
7815 finderArgs, list);
7816 }
7817 catch (Exception e) {
7818 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
7819 finderArgs);
7820
7821 throw processException(e);
7822 }
7823 finally {
7824 closeSession(session);
7825 }
7826 }
7827
7828 return list;
7829 }
7830
7831
7838 @Override
7839 public void removeByG_P_S(long groupId, long parentCategoryId, int status) {
7840 for (MBCategory mbCategory : findByG_P_S(groupId, parentCategoryId,
7841 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7842 remove(mbCategory);
7843 }
7844 }
7845
7846
7854 @Override
7855 public int countByG_P_S(long groupId, long parentCategoryId, int status) {
7856 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
7857
7858 Object[] finderArgs = new Object[] { groupId, parentCategoryId, status };
7859
7860 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7861 this);
7862
7863 if (count == null) {
7864 StringBundler query = new StringBundler(4);
7865
7866 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
7867
7868 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7869
7870 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7871
7872 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7873
7874 String sql = query.toString();
7875
7876 Session session = null;
7877
7878 try {
7879 session = openSession();
7880
7881 Query q = session.createQuery(sql);
7882
7883 QueryPos qPos = QueryPos.getInstance(q);
7884
7885 qPos.add(groupId);
7886
7887 qPos.add(parentCategoryId);
7888
7889 qPos.add(status);
7890
7891 count = (Long)q.uniqueResult();
7892
7893 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7894 }
7895 catch (Exception e) {
7896 FinderCacheUtil.removeResult(finderPath, finderArgs);
7897
7898 throw processException(e);
7899 }
7900 finally {
7901 closeSession(session);
7902 }
7903 }
7904
7905 return count.intValue();
7906 }
7907
7908
7916 @Override
7917 public int countByG_P_S(long groupId, long[] parentCategoryIds, int status) {
7918 if (parentCategoryIds == null) {
7919 parentCategoryIds = new long[0];
7920 }
7921 else {
7922 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
7923 }
7924
7925 Object[] finderArgs = new Object[] {
7926 groupId, StringUtil.merge(parentCategoryIds), status
7927 };
7928
7929 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
7930 finderArgs, this);
7931
7932 if (count == null) {
7933 StringBundler query = new StringBundler();
7934
7935 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
7936
7937 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7938
7939 if (parentCategoryIds.length > 0) {
7940 query.append(StringPool.OPEN_PARENTHESIS);
7941
7942 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
7943
7944 query.append(StringUtil.merge(parentCategoryIds));
7945
7946 query.append(StringPool.CLOSE_PARENTHESIS);
7947
7948 query.append(StringPool.CLOSE_PARENTHESIS);
7949
7950 query.append(WHERE_AND);
7951 }
7952
7953 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7954
7955 query.setStringAt(removeConjunction(query.stringAt(query.index() -
7956 1)), query.index() - 1);
7957
7958 String sql = query.toString();
7959
7960 Session session = null;
7961
7962 try {
7963 session = openSession();
7964
7965 Query q = session.createQuery(sql);
7966
7967 QueryPos qPos = QueryPos.getInstance(q);
7968
7969 qPos.add(groupId);
7970
7971 qPos.add(status);
7972
7973 count = (Long)q.uniqueResult();
7974
7975 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
7976 finderArgs, count);
7977 }
7978 catch (Exception e) {
7979 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
7980 finderArgs);
7981
7982 throw processException(e);
7983 }
7984 finally {
7985 closeSession(session);
7986 }
7987 }
7988
7989 return count.intValue();
7990 }
7991
7992
8000 @Override
8001 public int filterCountByG_P_S(long groupId, long parentCategoryId,
8002 int status) {
8003 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8004 return countByG_P_S(groupId, parentCategoryId, status);
8005 }
8006
8007 StringBundler query = new StringBundler(4);
8008
8009 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
8010
8011 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8012
8013 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
8014
8015 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8016
8017 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8018 MBCategory.class.getName(),
8019 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8020
8021 Session session = null;
8022
8023 try {
8024 session = openSession();
8025
8026 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8027
8028 q.addScalar(COUNT_COLUMN_NAME,
8029 com.liferay.portal.kernel.dao.orm.Type.LONG);
8030
8031 QueryPos qPos = QueryPos.getInstance(q);
8032
8033 qPos.add(groupId);
8034
8035 qPos.add(parentCategoryId);
8036
8037 qPos.add(status);
8038
8039 Long count = (Long)q.uniqueResult();
8040
8041 return count.intValue();
8042 }
8043 catch (Exception e) {
8044 throw processException(e);
8045 }
8046 finally {
8047 closeSession(session);
8048 }
8049 }
8050
8051
8059 @Override
8060 public int filterCountByG_P_S(long groupId, long[] parentCategoryIds,
8061 int status) {
8062 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8063 return countByG_P_S(groupId, parentCategoryIds, status);
8064 }
8065
8066 if (parentCategoryIds == null) {
8067 parentCategoryIds = new long[0];
8068 }
8069 else {
8070 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
8071 }
8072
8073 StringBundler query = new StringBundler();
8074
8075 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
8076
8077 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8078
8079 if (parentCategoryIds.length > 0) {
8080 query.append(StringPool.OPEN_PARENTHESIS);
8081
8082 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
8083
8084 query.append(StringUtil.merge(parentCategoryIds));
8085
8086 query.append(StringPool.CLOSE_PARENTHESIS);
8087
8088 query.append(StringPool.CLOSE_PARENTHESIS);
8089
8090 query.append(WHERE_AND);
8091 }
8092
8093 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8094
8095 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
8096 query.index() - 1);
8097
8098 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8099 MBCategory.class.getName(),
8100 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8101
8102 Session session = null;
8103
8104 try {
8105 session = openSession();
8106
8107 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8108
8109 q.addScalar(COUNT_COLUMN_NAME,
8110 com.liferay.portal.kernel.dao.orm.Type.LONG);
8111
8112 QueryPos qPos = QueryPos.getInstance(q);
8113
8114 qPos.add(groupId);
8115
8116 qPos.add(status);
8117
8118 Long count = (Long)q.uniqueResult();
8119
8120 return count.intValue();
8121 }
8122 catch (Exception e) {
8123 throw processException(e);
8124 }
8125 finally {
8126 closeSession(session);
8127 }
8128 }
8129
8130 private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
8131 private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
8132 private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
8133 private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "mbCategory.status = ?";
8134 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S =
8135 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
8136 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
8137 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNotC_G_P_S",
8138 new String[] {
8139 Long.class.getName(), Long.class.getName(), Long.class.getName(),
8140 Integer.class.getName(),
8141
8142 Integer.class.getName(), Integer.class.getName(),
8143 OrderByComparator.class.getName()
8144 });
8145 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S =
8146 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
8147 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
8148 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByNotC_G_P_S",
8149 new String[] {
8150 Long.class.getName(), Long.class.getName(), Long.class.getName(),
8151 Integer.class.getName()
8152 });
8153
8154
8163 @Override
8164 public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8165 long parentCategoryId, int status) {
8166 return findByNotC_G_P_S(categoryId, groupId, parentCategoryId, status,
8167 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8168 }
8169
8170
8185 @Override
8186 public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8187 long parentCategoryId, int status, int start, int end) {
8188 return findByNotC_G_P_S(categoryId, groupId, parentCategoryId, status,
8189 start, end, null);
8190 }
8191
8192
8208 @Override
8209 public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8210 long parentCategoryId, int status, int start, int end,
8211 OrderByComparator<MBCategory> orderByComparator) {
8212 boolean pagination = true;
8213 FinderPath finderPath = null;
8214 Object[] finderArgs = null;
8215
8216 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S;
8217 finderArgs = new Object[] {
8218 categoryId, groupId, parentCategoryId, status,
8219
8220 start, end, orderByComparator
8221 };
8222
8223 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
8224 finderArgs, this);
8225
8226 if ((list != null) && !list.isEmpty()) {
8227 for (MBCategory mbCategory : list) {
8228 if ((categoryId == mbCategory.getCategoryId()) ||
8229 (groupId != mbCategory.getGroupId()) ||
8230 (parentCategoryId != mbCategory.getParentCategoryId()) ||
8231 (status != mbCategory.getStatus())) {
8232 list = null;
8233
8234 break;
8235 }
8236 }
8237 }
8238
8239 if (list == null) {
8240 StringBundler query = null;
8241
8242 if (orderByComparator != null) {
8243 query = new StringBundler(6 +
8244 (orderByComparator.getOrderByFields().length * 3));
8245 }
8246 else {
8247 query = new StringBundler(6);
8248 }
8249
8250 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
8251
8252 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
8253
8254 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
8255
8256 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
8257
8258 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
8259
8260 if (orderByComparator != null) {
8261 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8262 orderByComparator);
8263 }
8264 else
8265 if (pagination) {
8266 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8267 }
8268
8269 String sql = query.toString();
8270
8271 Session session = null;
8272
8273 try {
8274 session = openSession();
8275
8276 Query q = session.createQuery(sql);
8277
8278 QueryPos qPos = QueryPos.getInstance(q);
8279
8280 qPos.add(categoryId);
8281
8282 qPos.add(groupId);
8283
8284 qPos.add(parentCategoryId);
8285
8286 qPos.add(status);
8287
8288 if (!pagination) {
8289 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8290 start, end, false);
8291
8292 Collections.sort(list);
8293
8294 list = Collections.unmodifiableList(list);
8295 }
8296 else {
8297 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8298 start, end);
8299 }
8300
8301 cacheResult(list);
8302
8303 FinderCacheUtil.putResult(finderPath, finderArgs, list);
8304 }
8305 catch (Exception e) {
8306 FinderCacheUtil.removeResult(finderPath, finderArgs);
8307
8308 throw processException(e);
8309 }
8310 finally {
8311 closeSession(session);
8312 }
8313 }
8314
8315 return list;
8316 }
8317
8318
8329 @Override
8330 public MBCategory findByNotC_G_P_S_First(long categoryId, long groupId,
8331 long parentCategoryId, int status,
8332 OrderByComparator<MBCategory> orderByComparator)
8333 throws NoSuchCategoryException {
8334 MBCategory mbCategory = fetchByNotC_G_P_S_First(categoryId, groupId,
8335 parentCategoryId, status, orderByComparator);
8336
8337 if (mbCategory != null) {
8338 return mbCategory;
8339 }
8340
8341 StringBundler msg = new StringBundler(10);
8342
8343 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8344
8345 msg.append("categoryId=");
8346 msg.append(categoryId);
8347
8348 msg.append(", groupId=");
8349 msg.append(groupId);
8350
8351 msg.append(", parentCategoryId=");
8352 msg.append(parentCategoryId);
8353
8354 msg.append(", status=");
8355 msg.append(status);
8356
8357 msg.append(StringPool.CLOSE_CURLY_BRACE);
8358
8359 throw new NoSuchCategoryException(msg.toString());
8360 }
8361
8362
8372 @Override
8373 public MBCategory fetchByNotC_G_P_S_First(long categoryId, long groupId,
8374 long parentCategoryId, int status,
8375 OrderByComparator<MBCategory> orderByComparator) {
8376 List<MBCategory> list = findByNotC_G_P_S(categoryId, groupId,
8377 parentCategoryId, status, 0, 1, orderByComparator);
8378
8379 if (!list.isEmpty()) {
8380 return list.get(0);
8381 }
8382
8383 return null;
8384 }
8385
8386
8397 @Override
8398 public MBCategory findByNotC_G_P_S_Last(long categoryId, long groupId,
8399 long parentCategoryId, int status,
8400 OrderByComparator<MBCategory> orderByComparator)
8401 throws NoSuchCategoryException {
8402 MBCategory mbCategory = fetchByNotC_G_P_S_Last(categoryId, groupId,
8403 parentCategoryId, status, orderByComparator);
8404
8405 if (mbCategory != null) {
8406 return mbCategory;
8407 }
8408
8409 StringBundler msg = new StringBundler(10);
8410
8411 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8412
8413 msg.append("categoryId=");
8414 msg.append(categoryId);
8415
8416 msg.append(", groupId=");
8417 msg.append(groupId);
8418
8419 msg.append(", parentCategoryId=");
8420 msg.append(parentCategoryId);
8421
8422 msg.append(", status=");
8423 msg.append(status);
8424
8425 msg.append(StringPool.CLOSE_CURLY_BRACE);
8426
8427 throw new NoSuchCategoryException(msg.toString());
8428 }
8429
8430
8440 @Override
8441 public MBCategory fetchByNotC_G_P_S_Last(long categoryId, long groupId,
8442 long parentCategoryId, int status,
8443 OrderByComparator<MBCategory> orderByComparator) {
8444 int count = countByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8445 status);
8446
8447 if (count == 0) {
8448 return null;
8449 }
8450
8451 List<MBCategory> list = findByNotC_G_P_S(categoryId, groupId,
8452 parentCategoryId, status, count - 1, count, orderByComparator);
8453
8454 if (!list.isEmpty()) {
8455 return list.get(0);
8456 }
8457
8458 return null;
8459 }
8460
8461
8470 @Override
8471 public List<MBCategory> filterFindByNotC_G_P_S(long categoryId,
8472 long groupId, long parentCategoryId, int status) {
8473 return filterFindByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8474 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8475 }
8476
8477
8492 @Override
8493 public List<MBCategory> filterFindByNotC_G_P_S(long categoryId,
8494 long groupId, long parentCategoryId, int status, int start, int end) {
8495 return filterFindByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8496 status, start, end, null);
8497 }
8498
8499
8515 @Override
8516 public List<MBCategory> filterFindByNotC_G_P_S(long categoryId,
8517 long groupId, long parentCategoryId, int status, int start, int end,
8518 OrderByComparator<MBCategory> orderByComparator) {
8519 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8520 return findByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8521 status, start, end, orderByComparator);
8522 }
8523
8524 StringBundler query = null;
8525
8526 if (orderByComparator != null) {
8527 query = new StringBundler(6 +
8528 (orderByComparator.getOrderByFields().length * 3));
8529 }
8530 else {
8531 query = new StringBundler(6);
8532 }
8533
8534 if (getDB().isSupportsInlineDistinct()) {
8535 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
8536 }
8537 else {
8538 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8539 }
8540
8541 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
8542
8543 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
8544
8545 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
8546
8547 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
8548
8549 if (!getDB().isSupportsInlineDistinct()) {
8550 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8551 }
8552
8553 if (orderByComparator != null) {
8554 if (getDB().isSupportsInlineDistinct()) {
8555 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8556 orderByComparator, true);
8557 }
8558 else {
8559 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8560 orderByComparator, true);
8561 }
8562 }
8563 else {
8564 if (getDB().isSupportsInlineDistinct()) {
8565 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8566 }
8567 else {
8568 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
8569 }
8570 }
8571
8572 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8573 MBCategory.class.getName(),
8574 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8575
8576 Session session = null;
8577
8578 try {
8579 session = openSession();
8580
8581 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8582
8583 if (getDB().isSupportsInlineDistinct()) {
8584 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
8585 }
8586 else {
8587 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
8588 }
8589
8590 QueryPos qPos = QueryPos.getInstance(q);
8591
8592 qPos.add(categoryId);
8593
8594 qPos.add(groupId);
8595
8596 qPos.add(parentCategoryId);
8597
8598 qPos.add(status);
8599
8600 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
8601 }
8602 catch (Exception e) {
8603 throw processException(e);
8604 }
8605 finally {
8606 closeSession(session);
8607 }
8608 }
8609
8610
8619 @Override
8620 public List<MBCategory> filterFindByNotC_G_P_S(long[] categoryIds,
8621 long groupId, long[] parentCategoryIds, int status) {
8622 return filterFindByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
8623 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8624 }
8625
8626
8641 @Override
8642 public List<MBCategory> filterFindByNotC_G_P_S(long[] categoryIds,
8643 long groupId, long[] parentCategoryIds, int status, int start, int end) {
8644 return filterFindByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
8645 status, start, end, null);
8646 }
8647
8648
8664 @Override
8665 public List<MBCategory> filterFindByNotC_G_P_S(long[] categoryIds,
8666 long groupId, long[] parentCategoryIds, int status, int start, int end,
8667 OrderByComparator<MBCategory> orderByComparator) {
8668 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8669 return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
8670 status, start, end, orderByComparator);
8671 }
8672
8673 if (categoryIds == null) {
8674 categoryIds = new long[0];
8675 }
8676 else {
8677 categoryIds = ArrayUtil.unique(categoryIds);
8678 }
8679
8680 if (parentCategoryIds == null) {
8681 parentCategoryIds = new long[0];
8682 }
8683 else {
8684 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
8685 }
8686
8687 StringBundler query = new StringBundler();
8688
8689 if (getDB().isSupportsInlineDistinct()) {
8690 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
8691 }
8692 else {
8693 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8694 }
8695
8696 if (categoryIds.length > 0) {
8697 query.append(StringPool.OPEN_PARENTHESIS);
8698
8699 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
8700
8701 query.append(StringUtil.merge(categoryIds));
8702
8703 query.append(StringPool.CLOSE_PARENTHESIS);
8704
8705 query.append(StringPool.CLOSE_PARENTHESIS);
8706
8707 query.append(WHERE_AND);
8708 }
8709
8710 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
8711
8712 if (parentCategoryIds.length > 0) {
8713 query.append(StringPool.OPEN_PARENTHESIS);
8714
8715 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
8716
8717 query.append(StringUtil.merge(parentCategoryIds));
8718
8719 query.append(StringPool.CLOSE_PARENTHESIS);
8720
8721 query.append(StringPool.CLOSE_PARENTHESIS);
8722
8723 query.append(WHERE_AND);
8724 }
8725
8726 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
8727
8728 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
8729 query.index() - 1);
8730
8731 if (!getDB().isSupportsInlineDistinct()) {
8732 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8733 }
8734
8735 if (orderByComparator != null) {
8736 if (getDB().isSupportsInlineDistinct()) {
8737 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8738 orderByComparator, true);
8739 }
8740 else {
8741 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8742 orderByComparator, true);
8743 }
8744 }
8745 else {
8746 if (getDB().isSupportsInlineDistinct()) {
8747 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8748 }
8749 else {
8750 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
8751 }
8752 }
8753
8754 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8755 MBCategory.class.getName(),
8756 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8757
8758 Session session = null;
8759
8760 try {
8761 session = openSession();
8762
8763 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8764
8765 if (getDB().isSupportsInlineDistinct()) {
8766 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
8767 }
8768 else {
8769 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
8770 }
8771
8772 QueryPos qPos = QueryPos.getInstance(q);
8773
8774 qPos.add(groupId);
8775
8776 qPos.add(status);
8777
8778 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
8779 }
8780 catch (Exception e) {
8781 throw processException(e);
8782 }
8783 finally {
8784 closeSession(session);
8785 }
8786 }
8787
8788
8801 @Override
8802 public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
8803 long[] parentCategoryIds, int status) {
8804 return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
8805 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8806 }
8807
8808
8823 @Override
8824 public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
8825 long[] parentCategoryIds, int status, int start, int end) {
8826 return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
8827 status, start, end, null);
8828 }
8829
8830
8846 @Override
8847 public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
8848 long[] parentCategoryIds, int status, int start, int end,
8849 OrderByComparator<MBCategory> orderByComparator) {
8850 if (categoryIds == null) {
8851 categoryIds = new long[0];
8852 }
8853 else {
8854 categoryIds = ArrayUtil.unique(categoryIds);
8855 }
8856
8857 if (parentCategoryIds == null) {
8858 parentCategoryIds = new long[0];
8859 }
8860 else {
8861 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
8862 }
8863
8864 if ((categoryIds.length == 1) && (parentCategoryIds.length == 1)) {
8865 return findByNotC_G_P_S(categoryIds[0], groupId,
8866 parentCategoryIds[0], status, start, end, orderByComparator);
8867 }
8868
8869 boolean pagination = true;
8870 Object[] finderArgs = null;
8871
8872 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8873 (orderByComparator == null)) {
8874 pagination = false;
8875 finderArgs = new Object[] {
8876 StringUtil.merge(categoryIds), groupId,
8877 StringUtil.merge(parentCategoryIds), status
8878 };
8879 }
8880 else {
8881 finderArgs = new Object[] {
8882 StringUtil.merge(categoryIds), groupId,
8883 StringUtil.merge(parentCategoryIds), status,
8884
8885 start, end, orderByComparator
8886 };
8887 }
8888
8889 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S,
8890 finderArgs, this);
8891
8892 if ((list != null) && !list.isEmpty()) {
8893 for (MBCategory mbCategory : list) {
8894 if (!ArrayUtil.contains(categoryIds, mbCategory.getCategoryId()) ||
8895 (groupId != mbCategory.getGroupId()) ||
8896 !ArrayUtil.contains(parentCategoryIds,
8897 mbCategory.getParentCategoryId()) ||
8898 (status != mbCategory.getStatus())) {
8899 list = null;
8900
8901 break;
8902 }
8903 }
8904 }
8905
8906 if (list == null) {
8907 StringBundler query = new StringBundler();
8908
8909 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
8910
8911 if (categoryIds.length > 0) {
8912 query.append(StringPool.OPEN_PARENTHESIS);
8913
8914 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
8915
8916 query.append(StringUtil.merge(categoryIds));
8917
8918 query.append(StringPool.CLOSE_PARENTHESIS);
8919
8920 query.append(StringPool.CLOSE_PARENTHESIS);
8921
8922 query.append(WHERE_AND);
8923 }
8924
8925 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
8926
8927 if (parentCategoryIds.length > 0) {
8928 query.append(StringPool.OPEN_PARENTHESIS);
8929
8930 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
8931
8932 query.append(StringUtil.merge(parentCategoryIds));
8933
8934 query.append(StringPool.CLOSE_PARENTHESIS);
8935
8936 query.append(StringPool.CLOSE_PARENTHESIS);
8937
8938 query.append(WHERE_AND);
8939 }
8940
8941 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
8942
8943 query.setStringAt(removeConjunction(query.stringAt(query.index() -
8944 1)), query.index() - 1);
8945
8946 if (orderByComparator != null) {
8947 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8948 orderByComparator);
8949 }
8950 else
8951 if (pagination) {
8952 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8953 }
8954
8955 String sql = query.toString();
8956
8957 Session session = null;
8958
8959 try {
8960 session = openSession();
8961
8962 Query q = session.createQuery(sql);
8963
8964 QueryPos qPos = QueryPos.getInstance(q);
8965
8966 qPos.add(groupId);
8967
8968 qPos.add(status);
8969
8970 if (!pagination) {
8971 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8972 start, end, false);
8973
8974 Collections.sort(list);
8975
8976 list = Collections.unmodifiableList(list);
8977 }
8978 else {
8979 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8980 start, end);
8981 }
8982
8983 cacheResult(list);
8984
8985 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S,
8986 finderArgs, list);
8987 }
8988 catch (Exception e) {
8989 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S,
8990 finderArgs);
8991
8992 throw processException(e);
8993 }
8994 finally {
8995 closeSession(session);
8996 }
8997 }
8998
8999 return list;
9000 }
9001
9002
9010 @Override
9011 public void removeByNotC_G_P_S(long categoryId, long groupId,
9012 long parentCategoryId, int status) {
9013 for (MBCategory mbCategory : findByNotC_G_P_S(categoryId, groupId,
9014 parentCategoryId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
9015 null)) {
9016 remove(mbCategory);
9017 }
9018 }
9019
9020
9029 @Override
9030 public int countByNotC_G_P_S(long categoryId, long groupId,
9031 long parentCategoryId, int status) {
9032 FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S;
9033
9034 Object[] finderArgs = new Object[] {
9035 categoryId, groupId, parentCategoryId, status
9036 };
9037
9038 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9039 this);
9040
9041 if (count == null) {
9042 StringBundler query = new StringBundler(5);
9043
9044 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
9045
9046 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
9047
9048 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9049
9050 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
9051
9052 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9053
9054 String sql = query.toString();
9055
9056 Session session = null;
9057
9058 try {
9059 session = openSession();
9060
9061 Query q = session.createQuery(sql);
9062
9063 QueryPos qPos = QueryPos.getInstance(q);
9064
9065 qPos.add(categoryId);
9066
9067 qPos.add(groupId);
9068
9069 qPos.add(parentCategoryId);
9070
9071 qPos.add(status);
9072
9073 count = (Long)q.uniqueResult();
9074
9075 FinderCacheUtil.putResult(finderPath, finderArgs, count);
9076 }
9077 catch (Exception e) {
9078 FinderCacheUtil.removeResult(finderPath, finderArgs);
9079
9080 throw processException(e);
9081 }
9082 finally {
9083 closeSession(session);
9084 }
9085 }
9086
9087 return count.intValue();
9088 }
9089
9090
9099 @Override
9100 public int countByNotC_G_P_S(long[] categoryIds, long groupId,
9101 long[] parentCategoryIds, int status) {
9102 if (categoryIds == null) {
9103 categoryIds = new long[0];
9104 }
9105 else {
9106 categoryIds = ArrayUtil.unique(categoryIds);
9107 }
9108
9109 if (parentCategoryIds == null) {
9110 parentCategoryIds = new long[0];
9111 }
9112 else {
9113 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
9114 }
9115
9116 Object[] finderArgs = new Object[] {
9117 StringUtil.merge(categoryIds), groupId,
9118 StringUtil.merge(parentCategoryIds), status
9119 };
9120
9121 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S,
9122 finderArgs, this);
9123
9124 if (count == null) {
9125 StringBundler query = new StringBundler();
9126
9127 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
9128
9129 if (categoryIds.length > 0) {
9130 query.append(StringPool.OPEN_PARENTHESIS);
9131
9132 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
9133
9134 query.append(StringUtil.merge(categoryIds));
9135
9136 query.append(StringPool.CLOSE_PARENTHESIS);
9137
9138 query.append(StringPool.CLOSE_PARENTHESIS);
9139
9140 query.append(WHERE_AND);
9141 }
9142
9143 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9144
9145 if (parentCategoryIds.length > 0) {
9146 query.append(StringPool.OPEN_PARENTHESIS);
9147
9148 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
9149
9150 query.append(StringUtil.merge(parentCategoryIds));
9151
9152 query.append(StringPool.CLOSE_PARENTHESIS);
9153
9154 query.append(StringPool.CLOSE_PARENTHESIS);
9155
9156 query.append(WHERE_AND);
9157 }
9158
9159 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9160
9161 query.setStringAt(removeConjunction(query.stringAt(query.index() -
9162 1)), query.index() - 1);
9163
9164 String sql = query.toString();
9165
9166 Session session = null;
9167
9168 try {
9169 session = openSession();
9170
9171 Query q = session.createQuery(sql);
9172
9173 QueryPos qPos = QueryPos.getInstance(q);
9174
9175 qPos.add(groupId);
9176
9177 qPos.add(status);
9178
9179 count = (Long)q.uniqueResult();
9180
9181 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S,
9182 finderArgs, count);
9183 }
9184 catch (Exception e) {
9185 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S,
9186 finderArgs);
9187
9188 throw processException(e);
9189 }
9190 finally {
9191 closeSession(session);
9192 }
9193 }
9194
9195 return count.intValue();
9196 }
9197
9198
9207 @Override
9208 public int filterCountByNotC_G_P_S(long categoryId, long groupId,
9209 long parentCategoryId, int status) {
9210 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9211 return countByNotC_G_P_S(categoryId, groupId, parentCategoryId,
9212 status);
9213 }
9214
9215 StringBundler query = new StringBundler(5);
9216
9217 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
9218
9219 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
9220
9221 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9222
9223 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
9224
9225 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9226
9227 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9228 MBCategory.class.getName(),
9229 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9230
9231 Session session = null;
9232
9233 try {
9234 session = openSession();
9235
9236 SQLQuery q = session.createSynchronizedSQLQuery(sql);
9237
9238 q.addScalar(COUNT_COLUMN_NAME,
9239 com.liferay.portal.kernel.dao.orm.Type.LONG);
9240
9241 QueryPos qPos = QueryPos.getInstance(q);
9242
9243 qPos.add(categoryId);
9244
9245 qPos.add(groupId);
9246
9247 qPos.add(parentCategoryId);
9248
9249 qPos.add(status);
9250
9251 Long count = (Long)q.uniqueResult();
9252
9253 return count.intValue();
9254 }
9255 catch (Exception e) {
9256 throw processException(e);
9257 }
9258 finally {
9259 closeSession(session);
9260 }
9261 }
9262
9263
9272 @Override
9273 public int filterCountByNotC_G_P_S(long[] categoryIds, long groupId,
9274 long[] parentCategoryIds, int status) {
9275 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9276 return countByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9277 status);
9278 }
9279
9280 if (categoryIds == null) {
9281 categoryIds = new long[0];
9282 }
9283 else {
9284 categoryIds = ArrayUtil.unique(categoryIds);
9285 }
9286
9287 if (parentCategoryIds == null) {
9288 parentCategoryIds = new long[0];
9289 }
9290 else {
9291 parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
9292 }
9293
9294 StringBundler query = new StringBundler();
9295
9296 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
9297
9298 if (categoryIds.length > 0) {
9299 query.append(StringPool.OPEN_PARENTHESIS);
9300
9301 query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
9302
9303 query.append(StringUtil.merge(categoryIds));
9304
9305 query.append(StringPool.CLOSE_PARENTHESIS);
9306
9307 query.append(StringPool.CLOSE_PARENTHESIS);
9308
9309 query.append(WHERE_AND);
9310 }
9311
9312 query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9313
9314 if (parentCategoryIds.length > 0) {
9315 query.append(StringPool.OPEN_PARENTHESIS);
9316
9317 query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
9318
9319 query.append(StringUtil.merge(parentCategoryIds));
9320
9321 query.append(StringPool.CLOSE_PARENTHESIS);
9322
9323 query.append(StringPool.CLOSE_PARENTHESIS);
9324
9325 query.append(WHERE_AND);
9326 }
9327
9328 query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9329
9330 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
9331 query.index() - 1);
9332
9333 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9334 MBCategory.class.getName(),
9335 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9336
9337 Session session = null;
9338
9339 try {
9340 session = openSession();
9341
9342 SQLQuery q = session.createSynchronizedSQLQuery(sql);
9343
9344 q.addScalar(COUNT_COLUMN_NAME,
9345 com.liferay.portal.kernel.dao.orm.Type.LONG);
9346
9347 QueryPos qPos = QueryPos.getInstance(q);
9348
9349 qPos.add(groupId);
9350
9351 qPos.add(status);
9352
9353 Long count = (Long)q.uniqueResult();
9354
9355 return count.intValue();
9356 }
9357 catch (Exception e) {
9358 throw processException(e);
9359 }
9360 finally {
9361 closeSession(session);
9362 }
9363 }
9364
9365 private static final String _FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2 = "mbCategory.categoryId != ? AND ";
9366 private static final String _FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7 = "mbCategory.categoryId NOT IN (";
9367 private static final String _FINDER_COLUMN_NOTC_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
9368 private static final String _FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
9369 private static final String _FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
9370 private static final String _FINDER_COLUMN_NOTC_G_P_S_STATUS_2 = "mbCategory.status = ?";
9371
9372 public MBCategoryPersistenceImpl() {
9373 setModelClass(MBCategory.class);
9374 }
9375
9376
9381 @Override
9382 public void cacheResult(MBCategory mbCategory) {
9383 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9384 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
9385
9386 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
9387 new Object[] { mbCategory.getUuid(), mbCategory.getGroupId() },
9388 mbCategory);
9389
9390 mbCategory.resetOriginalValues();
9391 }
9392
9393
9398 @Override
9399 public void cacheResult(List<MBCategory> mbCategories) {
9400 for (MBCategory mbCategory : mbCategories) {
9401 if (EntityCacheUtil.getResult(
9402 MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9403 MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
9404 cacheResult(mbCategory);
9405 }
9406 else {
9407 mbCategory.resetOriginalValues();
9408 }
9409 }
9410 }
9411
9412
9419 @Override
9420 public void clearCache() {
9421 EntityCacheUtil.clearCache(MBCategoryImpl.class);
9422
9423 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
9424 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9425 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9426 }
9427
9428
9435 @Override
9436 public void clearCache(MBCategory mbCategory) {
9437 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9438 MBCategoryImpl.class, mbCategory.getPrimaryKey());
9439
9440 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9441 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9442
9443 clearUniqueFindersCache(mbCategory);
9444 }
9445
9446 @Override
9447 public void clearCache(List<MBCategory> mbCategories) {
9448 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9449 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9450
9451 for (MBCategory mbCategory : mbCategories) {
9452 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9453 MBCategoryImpl.class, mbCategory.getPrimaryKey());
9454
9455 clearUniqueFindersCache(mbCategory);
9456 }
9457 }
9458
9459 protected void cacheUniqueFindersCache(MBCategory mbCategory) {
9460 if (mbCategory.isNew()) {
9461 Object[] args = new Object[] {
9462 mbCategory.getUuid(), mbCategory.getGroupId()
9463 };
9464
9465 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9466 Long.valueOf(1));
9467 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9468 mbCategory);
9469 }
9470 else {
9471 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
9472
9473 if ((mbCategoryModelImpl.getColumnBitmask() &
9474 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9475 Object[] args = new Object[] {
9476 mbCategory.getUuid(), mbCategory.getGroupId()
9477 };
9478
9479 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9480 Long.valueOf(1));
9481 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9482 mbCategory);
9483 }
9484 }
9485 }
9486
9487 protected void clearUniqueFindersCache(MBCategory mbCategory) {
9488 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
9489
9490 Object[] args = new Object[] {
9491 mbCategory.getUuid(), mbCategory.getGroupId()
9492 };
9493
9494 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9495 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9496
9497 if ((mbCategoryModelImpl.getColumnBitmask() &
9498 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9499 args = new Object[] {
9500 mbCategoryModelImpl.getOriginalUuid(),
9501 mbCategoryModelImpl.getOriginalGroupId()
9502 };
9503
9504 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9505 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9506 }
9507 }
9508
9509
9515 @Override
9516 public MBCategory create(long categoryId) {
9517 MBCategory mbCategory = new MBCategoryImpl();
9518
9519 mbCategory.setNew(true);
9520 mbCategory.setPrimaryKey(categoryId);
9521
9522 String uuid = PortalUUIDUtil.generate();
9523
9524 mbCategory.setUuid(uuid);
9525
9526 return mbCategory;
9527 }
9528
9529
9536 @Override
9537 public MBCategory remove(long categoryId) throws NoSuchCategoryException {
9538 return remove((Serializable)categoryId);
9539 }
9540
9541
9548 @Override
9549 public MBCategory remove(Serializable primaryKey)
9550 throws NoSuchCategoryException {
9551 Session session = null;
9552
9553 try {
9554 session = openSession();
9555
9556 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
9557 primaryKey);
9558
9559 if (mbCategory == null) {
9560 if (_log.isWarnEnabled()) {
9561 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9562 }
9563
9564 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9565 primaryKey);
9566 }
9567
9568 return remove(mbCategory);
9569 }
9570 catch (NoSuchCategoryException nsee) {
9571 throw nsee;
9572 }
9573 catch (Exception e) {
9574 throw processException(e);
9575 }
9576 finally {
9577 closeSession(session);
9578 }
9579 }
9580
9581 @Override
9582 protected MBCategory removeImpl(MBCategory mbCategory) {
9583 mbCategory = toUnwrappedModel(mbCategory);
9584
9585 Session session = null;
9586
9587 try {
9588 session = openSession();
9589
9590 if (!session.contains(mbCategory)) {
9591 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
9592 mbCategory.getPrimaryKeyObj());
9593 }
9594
9595 if (mbCategory != null) {
9596 session.delete(mbCategory);
9597 }
9598 }
9599 catch (Exception e) {
9600 throw processException(e);
9601 }
9602 finally {
9603 closeSession(session);
9604 }
9605
9606 if (mbCategory != null) {
9607 clearCache(mbCategory);
9608 }
9609
9610 return mbCategory;
9611 }
9612
9613 @Override
9614 public MBCategory updateImpl(MBCategory mbCategory) {
9615 mbCategory = toUnwrappedModel(mbCategory);
9616
9617 boolean isNew = mbCategory.isNew();
9618
9619 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
9620
9621 if (Validator.isNull(mbCategory.getUuid())) {
9622 String uuid = PortalUUIDUtil.generate();
9623
9624 mbCategory.setUuid(uuid);
9625 }
9626
9627 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
9628
9629 Date now = new Date();
9630
9631 if (isNew && (mbCategory.getCreateDate() == null)) {
9632 if (serviceContext == null) {
9633 mbCategory.setCreateDate(now);
9634 }
9635 else {
9636 mbCategory.setCreateDate(serviceContext.getCreateDate(now));
9637 }
9638 }
9639
9640 if (!mbCategoryModelImpl.hasSetModifiedDate()) {
9641 if (serviceContext == null) {
9642 mbCategory.setModifiedDate(now);
9643 }
9644 else {
9645 mbCategory.setModifiedDate(serviceContext.getModifiedDate(now));
9646 }
9647 }
9648
9649 Session session = null;
9650
9651 try {
9652 session = openSession();
9653
9654 if (mbCategory.isNew()) {
9655 session.save(mbCategory);
9656
9657 mbCategory.setNew(false);
9658 }
9659 else {
9660 session.merge(mbCategory);
9661 }
9662 }
9663 catch (Exception e) {
9664 throw processException(e);
9665 }
9666 finally {
9667 closeSession(session);
9668 }
9669
9670 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9671
9672 if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
9673 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9674 }
9675
9676 else {
9677 if ((mbCategoryModelImpl.getColumnBitmask() &
9678 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
9679 Object[] args = new Object[] {
9680 mbCategoryModelImpl.getOriginalUuid()
9681 };
9682
9683 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
9684 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
9685 args);
9686
9687 args = new Object[] { mbCategoryModelImpl.getUuid() };
9688
9689 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
9690 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
9691 args);
9692 }
9693
9694 if ((mbCategoryModelImpl.getColumnBitmask() &
9695 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
9696 Object[] args = new Object[] {
9697 mbCategoryModelImpl.getOriginalUuid(),
9698 mbCategoryModelImpl.getOriginalCompanyId()
9699 };
9700
9701 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9702 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9703 args);
9704
9705 args = new Object[] {
9706 mbCategoryModelImpl.getUuid(),
9707 mbCategoryModelImpl.getCompanyId()
9708 };
9709
9710 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
9711 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
9712 args);
9713 }
9714
9715 if ((mbCategoryModelImpl.getColumnBitmask() &
9716 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
9717 Object[] args = new Object[] {
9718 mbCategoryModelImpl.getOriginalGroupId()
9719 };
9720
9721 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9722 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9723 args);
9724
9725 args = new Object[] { mbCategoryModelImpl.getGroupId() };
9726
9727 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
9728 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
9729 args);
9730 }
9731
9732 if ((mbCategoryModelImpl.getColumnBitmask() &
9733 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
9734 Object[] args = new Object[] {
9735 mbCategoryModelImpl.getOriginalCompanyId()
9736 };
9737
9738 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
9739 args);
9740 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
9741 args);
9742
9743 args = new Object[] { mbCategoryModelImpl.getCompanyId() };
9744
9745 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
9746 args);
9747 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
9748 args);
9749 }
9750
9751 if ((mbCategoryModelImpl.getColumnBitmask() &
9752 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
9753 Object[] args = new Object[] {
9754 mbCategoryModelImpl.getOriginalGroupId(),
9755 mbCategoryModelImpl.getOriginalParentCategoryId()
9756 };
9757
9758 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
9759 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
9760 args);
9761
9762 args = new Object[] {
9763 mbCategoryModelImpl.getGroupId(),
9764 mbCategoryModelImpl.getParentCategoryId()
9765 };
9766
9767 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
9768 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
9769 args);
9770 }
9771
9772 if ((mbCategoryModelImpl.getColumnBitmask() &
9773 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
9774 Object[] args = new Object[] {
9775 mbCategoryModelImpl.getOriginalGroupId(),
9776 mbCategoryModelImpl.getOriginalStatus()
9777 };
9778
9779 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
9780 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
9781 args);
9782
9783 args = new Object[] {
9784 mbCategoryModelImpl.getGroupId(),
9785 mbCategoryModelImpl.getStatus()
9786 };
9787
9788 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
9789 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
9790 args);
9791 }
9792
9793 if ((mbCategoryModelImpl.getColumnBitmask() &
9794 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
9795 Object[] args = new Object[] {
9796 mbCategoryModelImpl.getOriginalCompanyId(),
9797 mbCategoryModelImpl.getOriginalStatus()
9798 };
9799
9800 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
9801 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
9802 args);
9803
9804 args = new Object[] {
9805 mbCategoryModelImpl.getCompanyId(),
9806 mbCategoryModelImpl.getStatus()
9807 };
9808
9809 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
9810 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
9811 args);
9812 }
9813
9814 if ((mbCategoryModelImpl.getColumnBitmask() &
9815 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
9816 Object[] args = new Object[] {
9817 mbCategoryModelImpl.getOriginalGroupId(),
9818 mbCategoryModelImpl.getOriginalParentCategoryId(),
9819 mbCategoryModelImpl.getOriginalStatus()
9820 };
9821
9822 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
9823 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
9824 args);
9825
9826 args = new Object[] {
9827 mbCategoryModelImpl.getGroupId(),
9828 mbCategoryModelImpl.getParentCategoryId(),
9829 mbCategoryModelImpl.getStatus()
9830 };
9831
9832 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
9833 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
9834 args);
9835 }
9836 }
9837
9838 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9839 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory, false);
9840
9841 clearUniqueFindersCache(mbCategory);
9842 cacheUniqueFindersCache(mbCategory);
9843
9844 mbCategory.resetOriginalValues();
9845
9846 return mbCategory;
9847 }
9848
9849 protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
9850 if (mbCategory instanceof MBCategoryImpl) {
9851 return mbCategory;
9852 }
9853
9854 MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
9855
9856 mbCategoryImpl.setNew(mbCategory.isNew());
9857 mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
9858
9859 mbCategoryImpl.setUuid(mbCategory.getUuid());
9860 mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
9861 mbCategoryImpl.setGroupId(mbCategory.getGroupId());
9862 mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
9863 mbCategoryImpl.setUserId(mbCategory.getUserId());
9864 mbCategoryImpl.setUserName(mbCategory.getUserName());
9865 mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
9866 mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
9867 mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
9868 mbCategoryImpl.setName(mbCategory.getName());
9869 mbCategoryImpl.setDescription(mbCategory.getDescription());
9870 mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
9871 mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
9872 mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
9873 mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
9874 mbCategoryImpl.setStatus(mbCategory.getStatus());
9875 mbCategoryImpl.setStatusByUserId(mbCategory.getStatusByUserId());
9876 mbCategoryImpl.setStatusByUserName(mbCategory.getStatusByUserName());
9877 mbCategoryImpl.setStatusDate(mbCategory.getStatusDate());
9878
9879 return mbCategoryImpl;
9880 }
9881
9882
9889 @Override
9890 public MBCategory findByPrimaryKey(Serializable primaryKey)
9891 throws NoSuchCategoryException {
9892 MBCategory mbCategory = fetchByPrimaryKey(primaryKey);
9893
9894 if (mbCategory == null) {
9895 if (_log.isWarnEnabled()) {
9896 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9897 }
9898
9899 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9900 primaryKey);
9901 }
9902
9903 return mbCategory;
9904 }
9905
9906
9913 @Override
9914 public MBCategory findByPrimaryKey(long categoryId)
9915 throws NoSuchCategoryException {
9916 return findByPrimaryKey((Serializable)categoryId);
9917 }
9918
9919
9925 @Override
9926 public MBCategory fetchByPrimaryKey(Serializable primaryKey) {
9927 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9928 MBCategoryImpl.class, primaryKey);
9929
9930 if (mbCategory == _nullMBCategory) {
9931 return null;
9932 }
9933
9934 if (mbCategory == null) {
9935 Session session = null;
9936
9937 try {
9938 session = openSession();
9939
9940 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
9941 primaryKey);
9942
9943 if (mbCategory != null) {
9944 cacheResult(mbCategory);
9945 }
9946 else {
9947 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9948 MBCategoryImpl.class, primaryKey, _nullMBCategory);
9949 }
9950 }
9951 catch (Exception e) {
9952 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9953 MBCategoryImpl.class, primaryKey);
9954
9955 throw processException(e);
9956 }
9957 finally {
9958 closeSession(session);
9959 }
9960 }
9961
9962 return mbCategory;
9963 }
9964
9965
9971 @Override
9972 public MBCategory fetchByPrimaryKey(long categoryId) {
9973 return fetchByPrimaryKey((Serializable)categoryId);
9974 }
9975
9976 @Override
9977 public Map<Serializable, MBCategory> fetchByPrimaryKeys(
9978 Set<Serializable> primaryKeys) {
9979 if (primaryKeys.isEmpty()) {
9980 return Collections.emptyMap();
9981 }
9982
9983 Map<Serializable, MBCategory> map = new HashMap<Serializable, MBCategory>();
9984
9985 if (primaryKeys.size() == 1) {
9986 Iterator<Serializable> iterator = primaryKeys.iterator();
9987
9988 Serializable primaryKey = iterator.next();
9989
9990 MBCategory mbCategory = fetchByPrimaryKey(primaryKey);
9991
9992 if (mbCategory != null) {
9993 map.put(primaryKey, mbCategory);
9994 }
9995
9996 return map;
9997 }
9998
9999 Set<Serializable> uncachedPrimaryKeys = null;
10000
10001 for (Serializable primaryKey : primaryKeys) {
10002 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10003 MBCategoryImpl.class, primaryKey);
10004
10005 if (mbCategory == null) {
10006 if (uncachedPrimaryKeys == null) {
10007 uncachedPrimaryKeys = new HashSet<Serializable>();
10008 }
10009
10010 uncachedPrimaryKeys.add(primaryKey);
10011 }
10012 else {
10013 map.put(primaryKey, mbCategory);
10014 }
10015 }
10016
10017 if (uncachedPrimaryKeys == null) {
10018 return map;
10019 }
10020
10021 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
10022 1);
10023
10024 query.append(_SQL_SELECT_MBCATEGORY_WHERE_PKS_IN);
10025
10026 for (Serializable primaryKey : uncachedPrimaryKeys) {
10027 query.append(String.valueOf(primaryKey));
10028
10029 query.append(StringPool.COMMA);
10030 }
10031
10032 query.setIndex(query.index() - 1);
10033
10034 query.append(StringPool.CLOSE_PARENTHESIS);
10035
10036 String sql = query.toString();
10037
10038 Session session = null;
10039
10040 try {
10041 session = openSession();
10042
10043 Query q = session.createQuery(sql);
10044
10045 for (MBCategory mbCategory : (List<MBCategory>)q.list()) {
10046 map.put(mbCategory.getPrimaryKeyObj(), mbCategory);
10047
10048 cacheResult(mbCategory);
10049
10050 uncachedPrimaryKeys.remove(mbCategory.getPrimaryKeyObj());
10051 }
10052
10053 for (Serializable primaryKey : uncachedPrimaryKeys) {
10054 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10055 MBCategoryImpl.class, primaryKey, _nullMBCategory);
10056 }
10057 }
10058 catch (Exception e) {
10059 throw processException(e);
10060 }
10061 finally {
10062 closeSession(session);
10063 }
10064
10065 return map;
10066 }
10067
10068
10073 @Override
10074 public List<MBCategory> findAll() {
10075 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10076 }
10077
10078
10089 @Override
10090 public List<MBCategory> findAll(int start, int end) {
10091 return findAll(start, end, null);
10092 }
10093
10094
10106 @Override
10107 public List<MBCategory> findAll(int start, int end,
10108 OrderByComparator<MBCategory> orderByComparator) {
10109 boolean pagination = true;
10110 FinderPath finderPath = null;
10111 Object[] finderArgs = null;
10112
10113 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10114 (orderByComparator == null)) {
10115 pagination = false;
10116 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
10117 finderArgs = FINDER_ARGS_EMPTY;
10118 }
10119 else {
10120 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
10121 finderArgs = new Object[] { start, end, orderByComparator };
10122 }
10123
10124 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
10125 finderArgs, this);
10126
10127 if (list == null) {
10128 StringBundler query = null;
10129 String sql = null;
10130
10131 if (orderByComparator != null) {
10132 query = new StringBundler(2 +
10133 (orderByComparator.getOrderByFields().length * 3));
10134
10135 query.append(_SQL_SELECT_MBCATEGORY);
10136
10137 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10138 orderByComparator);
10139
10140 sql = query.toString();
10141 }
10142 else {
10143 sql = _SQL_SELECT_MBCATEGORY;
10144
10145 if (pagination) {
10146 sql = sql.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
10147 }
10148 }
10149
10150 Session session = null;
10151
10152 try {
10153 session = openSession();
10154
10155 Query q = session.createQuery(sql);
10156
10157 if (!pagination) {
10158 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
10159 start, end, false);
10160
10161 Collections.sort(list);
10162
10163 list = Collections.unmodifiableList(list);
10164 }
10165 else {
10166 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
10167 start, end);
10168 }
10169
10170 cacheResult(list);
10171
10172 FinderCacheUtil.putResult(finderPath, finderArgs, list);
10173 }
10174 catch (Exception e) {
10175 FinderCacheUtil.removeResult(finderPath, finderArgs);
10176
10177 throw processException(e);
10178 }
10179 finally {
10180 closeSession(session);
10181 }
10182 }
10183
10184 return list;
10185 }
10186
10187
10191 @Override
10192 public void removeAll() {
10193 for (MBCategory mbCategory : findAll()) {
10194 remove(mbCategory);
10195 }
10196 }
10197
10198
10203 @Override
10204 public int countAll() {
10205 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
10206 FINDER_ARGS_EMPTY, this);
10207
10208 if (count == null) {
10209 Session session = null;
10210
10211 try {
10212 session = openSession();
10213
10214 Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
10215
10216 count = (Long)q.uniqueResult();
10217
10218 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
10219 FINDER_ARGS_EMPTY, count);
10220 }
10221 catch (Exception e) {
10222 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
10223 FINDER_ARGS_EMPTY);
10224
10225 throw processException(e);
10226 }
10227 finally {
10228 closeSession(session);
10229 }
10230 }
10231
10232 return count.intValue();
10233 }
10234
10235 @Override
10236 protected Set<String> getBadColumnNames() {
10237 return _badColumnNames;
10238 }
10239
10240
10243 public void afterPropertiesSet() {
10244 }
10245
10246 public void destroy() {
10247 EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
10248 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
10249 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10250 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10251 }
10252
10253 private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
10254 private static final String _SQL_SELECT_MBCATEGORY_WHERE_PKS_IN = "SELECT mbCategory FROM MBCategory mbCategory WHERE categoryId IN (";
10255 private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
10256 private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
10257 private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
10258 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
10259 private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
10260 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
10261 "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
10262 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
10263 ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
10264 private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
10265 private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
10266 private static final String _FILTER_ENTITY_TABLE = "MBCategory";
10267 private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
10268 private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
10269 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
10270 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
10271 private static final Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
10272 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
10273 "uuid"
10274 });
10275 private static final MBCategory _nullMBCategory = new MBCategoryImpl() {
10276 @Override
10277 public Object clone() {
10278 return this;
10279 }
10280
10281 @Override
10282 public CacheModel<MBCategory> toCacheModel() {
10283 return _nullMBCategoryCacheModel;
10284 }
10285 };
10286
10287 private static final CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
10288 @Override
10289 public MBCategory toEntityModel() {
10290 return _nullMBCategory;
10291 }
10292 };
10293 }