001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
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.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.ArrayUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.UnmodifiableList;
038 import com.liferay.portal.kernel.util.Validator;
039 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040 import com.liferay.portal.model.CacheModel;
041 import com.liferay.portal.model.ModelListener;
042 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import com.liferay.portlet.messageboards.NoSuchCategoryException;
046 import com.liferay.portlet.messageboards.model.MBCategory;
047 import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
048 import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
068 public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
069 implements MBCategoryPersistence {
070
075 public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
076 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List1";
078 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List2";
080 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
081 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
082 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
084 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
085 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
086 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
087 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
088 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
089 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
090 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
091 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
092 new String[] {
093 String.class.getName(),
094
095 Integer.class.getName(), Integer.class.getName(),
096 OrderByComparator.class.getName()
097 });
098 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
099 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
101 new String[] { String.class.getName() },
102 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
103 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
104 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
105 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
106 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
108 new String[] { String.class.getName() });
109
110
117 public List<MBCategory> findByUuid(String uuid) throws SystemException {
118 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
119 }
120
121
134 public List<MBCategory> findByUuid(String uuid, int start, int end)
135 throws SystemException {
136 return findByUuid(uuid, start, end, null);
137 }
138
139
153 public List<MBCategory> findByUuid(String uuid, int start, int end,
154 OrderByComparator orderByComparator) throws SystemException {
155 boolean pagination = true;
156 FinderPath finderPath = null;
157 Object[] finderArgs = null;
158
159 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
160 (orderByComparator == null)) {
161 pagination = false;
162 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
163 finderArgs = new Object[] { uuid };
164 }
165 else {
166 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid, start, end, orderByComparator };
168 }
169
170 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
171 finderArgs, this);
172
173 if ((list != null) && !list.isEmpty()) {
174 for (MBCategory mbCategory : list) {
175 if (!Validator.equals(uuid, mbCategory.getUuid())) {
176 list = null;
177
178 break;
179 }
180 }
181 }
182
183 if (list == null) {
184 StringBundler query = null;
185
186 if (orderByComparator != null) {
187 query = new StringBundler(3 +
188 (orderByComparator.getOrderByFields().length * 3));
189 }
190 else {
191 query = new StringBundler(3);
192 }
193
194 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
195
196 if (uuid == null) {
197 query.append(_FINDER_COLUMN_UUID_UUID_1);
198 }
199 else {
200 if (uuid.equals(StringPool.BLANK)) {
201 query.append(_FINDER_COLUMN_UUID_UUID_3);
202 }
203 else {
204 query.append(_FINDER_COLUMN_UUID_UUID_2);
205 }
206 }
207
208 if (orderByComparator != null) {
209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
210 orderByComparator);
211 }
212 else
213 if (pagination) {
214 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
215 }
216
217 String sql = query.toString();
218
219 Session session = null;
220
221 try {
222 session = openSession();
223
224 Query q = session.createQuery(sql);
225
226 QueryPos qPos = QueryPos.getInstance(q);
227
228 if (uuid != null) {
229 qPos.add(uuid);
230 }
231
232 if (!pagination) {
233 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
234 start, end, false);
235
236 Collections.sort(list);
237
238 list = new UnmodifiableList<MBCategory>(list);
239 }
240 else {
241 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
242 start, end);
243 }
244
245 cacheResult(list);
246
247 FinderCacheUtil.putResult(finderPath, finderArgs, list);
248 }
249 catch (Exception e) {
250 FinderCacheUtil.removeResult(finderPath, finderArgs);
251
252 throw processException(e);
253 }
254 finally {
255 closeSession(session);
256 }
257 }
258
259 return list;
260 }
261
262
271 public MBCategory findByUuid_First(String uuid,
272 OrderByComparator orderByComparator)
273 throws NoSuchCategoryException, SystemException {
274 MBCategory mbCategory = fetchByUuid_First(uuid, orderByComparator);
275
276 if (mbCategory != null) {
277 return mbCategory;
278 }
279
280 StringBundler msg = new StringBundler(4);
281
282 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
283
284 msg.append("uuid=");
285 msg.append(uuid);
286
287 msg.append(StringPool.CLOSE_CURLY_BRACE);
288
289 throw new NoSuchCategoryException(msg.toString());
290 }
291
292
300 public MBCategory fetchByUuid_First(String uuid,
301 OrderByComparator orderByComparator) throws SystemException {
302 List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
303
304 if (!list.isEmpty()) {
305 return list.get(0);
306 }
307
308 return null;
309 }
310
311
320 public MBCategory findByUuid_Last(String uuid,
321 OrderByComparator orderByComparator)
322 throws NoSuchCategoryException, SystemException {
323 MBCategory mbCategory = fetchByUuid_Last(uuid, orderByComparator);
324
325 if (mbCategory != null) {
326 return mbCategory;
327 }
328
329 StringBundler msg = new StringBundler(4);
330
331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
332
333 msg.append("uuid=");
334 msg.append(uuid);
335
336 msg.append(StringPool.CLOSE_CURLY_BRACE);
337
338 throw new NoSuchCategoryException(msg.toString());
339 }
340
341
349 public MBCategory fetchByUuid_Last(String uuid,
350 OrderByComparator orderByComparator) throws SystemException {
351 int count = countByUuid(uuid);
352
353 List<MBCategory> list = findByUuid(uuid, count - 1, count,
354 orderByComparator);
355
356 if (!list.isEmpty()) {
357 return list.get(0);
358 }
359
360 return null;
361 }
362
363
373 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
374 OrderByComparator orderByComparator)
375 throws NoSuchCategoryException, SystemException {
376 MBCategory mbCategory = findByPrimaryKey(categoryId);
377
378 Session session = null;
379
380 try {
381 session = openSession();
382
383 MBCategory[] array = new MBCategoryImpl[3];
384
385 array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
386 orderByComparator, true);
387
388 array[1] = mbCategory;
389
390 array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
391 orderByComparator, false);
392
393 return array;
394 }
395 catch (Exception e) {
396 throw processException(e);
397 }
398 finally {
399 closeSession(session);
400 }
401 }
402
403 protected MBCategory getByUuid_PrevAndNext(Session session,
404 MBCategory mbCategory, String uuid,
405 OrderByComparator orderByComparator, boolean previous) {
406 StringBundler query = null;
407
408 if (orderByComparator != null) {
409 query = new StringBundler(6 +
410 (orderByComparator.getOrderByFields().length * 6));
411 }
412 else {
413 query = new StringBundler(3);
414 }
415
416 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
417
418 if (uuid == null) {
419 query.append(_FINDER_COLUMN_UUID_UUID_1);
420 }
421 else {
422 if (uuid.equals(StringPool.BLANK)) {
423 query.append(_FINDER_COLUMN_UUID_UUID_3);
424 }
425 else {
426 query.append(_FINDER_COLUMN_UUID_UUID_2);
427 }
428 }
429
430 if (orderByComparator != null) {
431 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
432
433 if (orderByConditionFields.length > 0) {
434 query.append(WHERE_AND);
435 }
436
437 for (int i = 0; i < orderByConditionFields.length; i++) {
438 query.append(_ORDER_BY_ENTITY_ALIAS);
439 query.append(orderByConditionFields[i]);
440
441 if ((i + 1) < orderByConditionFields.length) {
442 if (orderByComparator.isAscending() ^ previous) {
443 query.append(WHERE_GREATER_THAN_HAS_NEXT);
444 }
445 else {
446 query.append(WHERE_LESSER_THAN_HAS_NEXT);
447 }
448 }
449 else {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(WHERE_GREATER_THAN);
452 }
453 else {
454 query.append(WHERE_LESSER_THAN);
455 }
456 }
457 }
458
459 query.append(ORDER_BY_CLAUSE);
460
461 String[] orderByFields = orderByComparator.getOrderByFields();
462
463 for (int i = 0; i < orderByFields.length; i++) {
464 query.append(_ORDER_BY_ENTITY_ALIAS);
465 query.append(orderByFields[i]);
466
467 if ((i + 1) < orderByFields.length) {
468 if (orderByComparator.isAscending() ^ previous) {
469 query.append(ORDER_BY_ASC_HAS_NEXT);
470 }
471 else {
472 query.append(ORDER_BY_DESC_HAS_NEXT);
473 }
474 }
475 else {
476 if (orderByComparator.isAscending() ^ previous) {
477 query.append(ORDER_BY_ASC);
478 }
479 else {
480 query.append(ORDER_BY_DESC);
481 }
482 }
483 }
484 }
485 else {
486 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
487 }
488
489 String sql = query.toString();
490
491 Query q = session.createQuery(sql);
492
493 q.setFirstResult(0);
494 q.setMaxResults(2);
495
496 QueryPos qPos = QueryPos.getInstance(q);
497
498 if (uuid != null) {
499 qPos.add(uuid);
500 }
501
502 if (orderByComparator != null) {
503 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
504
505 for (Object value : values) {
506 qPos.add(value);
507 }
508 }
509
510 List<MBCategory> list = q.list();
511
512 if (list.size() == 2) {
513 return list.get(1);
514 }
515 else {
516 return null;
517 }
518 }
519
520
526 public void removeByUuid(String uuid) throws SystemException {
527 for (MBCategory mbCategory : findByUuid(uuid, QueryUtil.ALL_POS,
528 QueryUtil.ALL_POS, null)) {
529 remove(mbCategory);
530 }
531 }
532
533
540 public int countByUuid(String uuid) throws SystemException {
541 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
542
543 Object[] finderArgs = new Object[] { uuid };
544
545 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
546 this);
547
548 if (count == null) {
549 StringBundler query = new StringBundler(2);
550
551 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
552
553 if (uuid == null) {
554 query.append(_FINDER_COLUMN_UUID_UUID_1);
555 }
556 else {
557 if (uuid.equals(StringPool.BLANK)) {
558 query.append(_FINDER_COLUMN_UUID_UUID_3);
559 }
560 else {
561 query.append(_FINDER_COLUMN_UUID_UUID_2);
562 }
563 }
564
565 String sql = query.toString();
566
567 Session session = null;
568
569 try {
570 session = openSession();
571
572 Query q = session.createQuery(sql);
573
574 QueryPos qPos = QueryPos.getInstance(q);
575
576 if (uuid != null) {
577 qPos.add(uuid);
578 }
579
580 count = (Long)q.uniqueResult();
581
582 FinderCacheUtil.putResult(finderPath, finderArgs, count);
583 }
584 catch (Exception e) {
585 FinderCacheUtil.removeResult(finderPath, finderArgs);
586
587 throw processException(e);
588 }
589 finally {
590 closeSession(session);
591 }
592 }
593
594 return count.intValue();
595 }
596
597 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
598 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
599 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?)";
600 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
601 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
602 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
603 new String[] { String.class.getName(), Long.class.getName() },
604 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
605 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
606 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
607 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
608 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
609 new String[] { String.class.getName(), Long.class.getName() });
610
611
620 public MBCategory findByUUID_G(String uuid, long groupId)
621 throws NoSuchCategoryException, SystemException {
622 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
623
624 if (mbCategory == null) {
625 StringBundler msg = new StringBundler(6);
626
627 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
628
629 msg.append("uuid=");
630 msg.append(uuid);
631
632 msg.append(", groupId=");
633 msg.append(groupId);
634
635 msg.append(StringPool.CLOSE_CURLY_BRACE);
636
637 if (_log.isWarnEnabled()) {
638 _log.warn(msg.toString());
639 }
640
641 throw new NoSuchCategoryException(msg.toString());
642 }
643
644 return mbCategory;
645 }
646
647
655 public MBCategory fetchByUUID_G(String uuid, long groupId)
656 throws SystemException {
657 return fetchByUUID_G(uuid, groupId, true);
658 }
659
660
669 public MBCategory fetchByUUID_G(String uuid, long groupId,
670 boolean retrieveFromCache) throws SystemException {
671 Object[] finderArgs = new Object[] { uuid, groupId };
672
673 Object result = null;
674
675 if (retrieveFromCache) {
676 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
677 finderArgs, this);
678 }
679
680 if (result instanceof MBCategory) {
681 MBCategory mbCategory = (MBCategory)result;
682
683 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
684 (groupId != mbCategory.getGroupId())) {
685 result = null;
686 }
687 }
688
689 if (result == null) {
690 StringBundler query = new StringBundler(4);
691
692 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
693
694 if (uuid == null) {
695 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
696 }
697 else {
698 if (uuid.equals(StringPool.BLANK)) {
699 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
700 }
701 else {
702 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
703 }
704 }
705
706 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
707
708 String sql = query.toString();
709
710 Session session = null;
711
712 try {
713 session = openSession();
714
715 Query q = session.createQuery(sql);
716
717 QueryPos qPos = QueryPos.getInstance(q);
718
719 if (uuid != null) {
720 qPos.add(uuid);
721 }
722
723 qPos.add(groupId);
724
725 List<MBCategory> list = q.list();
726
727 if (list.isEmpty()) {
728 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
729 finderArgs, list);
730 }
731 else {
732 MBCategory mbCategory = list.get(0);
733
734 result = mbCategory;
735
736 cacheResult(mbCategory);
737
738 if ((mbCategory.getUuid() == null) ||
739 !mbCategory.getUuid().equals(uuid) ||
740 (mbCategory.getGroupId() != groupId)) {
741 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
742 finderArgs, mbCategory);
743 }
744 }
745 }
746 catch (Exception e) {
747 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
748 finderArgs);
749
750 throw processException(e);
751 }
752 finally {
753 closeSession(session);
754 }
755 }
756
757 if (result instanceof List<?>) {
758 return null;
759 }
760 else {
761 return (MBCategory)result;
762 }
763 }
764
765
773 public MBCategory removeByUUID_G(String uuid, long groupId)
774 throws NoSuchCategoryException, SystemException {
775 MBCategory mbCategory = findByUUID_G(uuid, groupId);
776
777 return remove(mbCategory);
778 }
779
780
788 public int countByUUID_G(String uuid, long groupId)
789 throws SystemException {
790 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
791
792 Object[] finderArgs = new Object[] { uuid, groupId };
793
794 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
795 this);
796
797 if (count == null) {
798 StringBundler query = new StringBundler(3);
799
800 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
801
802 if (uuid == null) {
803 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
804 }
805 else {
806 if (uuid.equals(StringPool.BLANK)) {
807 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
808 }
809 else {
810 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
811 }
812 }
813
814 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
815
816 String sql = query.toString();
817
818 Session session = null;
819
820 try {
821 session = openSession();
822
823 Query q = session.createQuery(sql);
824
825 QueryPos qPos = QueryPos.getInstance(q);
826
827 if (uuid != null) {
828 qPos.add(uuid);
829 }
830
831 qPos.add(groupId);
832
833 count = (Long)q.uniqueResult();
834
835 FinderCacheUtil.putResult(finderPath, finderArgs, count);
836 }
837 catch (Exception e) {
838 FinderCacheUtil.removeResult(finderPath, finderArgs);
839
840 throw processException(e);
841 }
842 finally {
843 closeSession(session);
844 }
845 }
846
847 return count.intValue();
848 }
849
850 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
851 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
852 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
853 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
854 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
855 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
856 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
857 new String[] {
858 String.class.getName(), Long.class.getName(),
859
860 Integer.class.getName(), Integer.class.getName(),
861 OrderByComparator.class.getName()
862 });
863 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
864 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
865 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
866 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
867 new String[] { String.class.getName(), Long.class.getName() },
868 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
869 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
870 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
871 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
872 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
873 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
874 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
875 new String[] { String.class.getName(), Long.class.getName() });
876
877
885 public List<MBCategory> findByUuid_C(String uuid, long companyId)
886 throws SystemException {
887 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
888 QueryUtil.ALL_POS, null);
889 }
890
891
905 public List<MBCategory> findByUuid_C(String uuid, long companyId,
906 int start, int end) throws SystemException {
907 return findByUuid_C(uuid, companyId, start, end, null);
908 }
909
910
925 public List<MBCategory> findByUuid_C(String uuid, long companyId,
926 int start, int end, OrderByComparator orderByComparator)
927 throws SystemException {
928 boolean pagination = true;
929 FinderPath finderPath = null;
930 Object[] finderArgs = null;
931
932 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
933 (orderByComparator == null)) {
934 pagination = false;
935 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
936 finderArgs = new Object[] { uuid, companyId };
937 }
938 else {
939 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
940 finderArgs = new Object[] {
941 uuid, companyId,
942
943 start, end, orderByComparator
944 };
945 }
946
947 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
948 finderArgs, this);
949
950 if ((list != null) && !list.isEmpty()) {
951 for (MBCategory mbCategory : list) {
952 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
953 (companyId != mbCategory.getCompanyId())) {
954 list = null;
955
956 break;
957 }
958 }
959 }
960
961 if (list == null) {
962 StringBundler query = null;
963
964 if (orderByComparator != null) {
965 query = new StringBundler(4 +
966 (orderByComparator.getOrderByFields().length * 3));
967 }
968 else {
969 query = new StringBundler(4);
970 }
971
972 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
973
974 if (uuid == null) {
975 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
976 }
977 else {
978 if (uuid.equals(StringPool.BLANK)) {
979 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
980 }
981 else {
982 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
983 }
984 }
985
986 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
987
988 if (orderByComparator != null) {
989 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
990 orderByComparator);
991 }
992 else
993 if (pagination) {
994 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
995 }
996
997 String sql = query.toString();
998
999 Session session = null;
1000
1001 try {
1002 session = openSession();
1003
1004 Query q = session.createQuery(sql);
1005
1006 QueryPos qPos = QueryPos.getInstance(q);
1007
1008 if (uuid != null) {
1009 qPos.add(uuid);
1010 }
1011
1012 qPos.add(companyId);
1013
1014 if (!pagination) {
1015 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1016 start, end, false);
1017
1018 Collections.sort(list);
1019
1020 list = new UnmodifiableList<MBCategory>(list);
1021 }
1022 else {
1023 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1024 start, end);
1025 }
1026
1027 cacheResult(list);
1028
1029 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1030 }
1031 catch (Exception e) {
1032 FinderCacheUtil.removeResult(finderPath, finderArgs);
1033
1034 throw processException(e);
1035 }
1036 finally {
1037 closeSession(session);
1038 }
1039 }
1040
1041 return list;
1042 }
1043
1044
1054 public MBCategory findByUuid_C_First(String uuid, long companyId,
1055 OrderByComparator orderByComparator)
1056 throws NoSuchCategoryException, SystemException {
1057 MBCategory mbCategory = fetchByUuid_C_First(uuid, companyId,
1058 orderByComparator);
1059
1060 if (mbCategory != null) {
1061 return mbCategory;
1062 }
1063
1064 StringBundler msg = new StringBundler(6);
1065
1066 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1067
1068 msg.append("uuid=");
1069 msg.append(uuid);
1070
1071 msg.append(", companyId=");
1072 msg.append(companyId);
1073
1074 msg.append(StringPool.CLOSE_CURLY_BRACE);
1075
1076 throw new NoSuchCategoryException(msg.toString());
1077 }
1078
1079
1088 public MBCategory fetchByUuid_C_First(String uuid, long companyId,
1089 OrderByComparator orderByComparator) throws SystemException {
1090 List<MBCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1091 orderByComparator);
1092
1093 if (!list.isEmpty()) {
1094 return list.get(0);
1095 }
1096
1097 return null;
1098 }
1099
1100
1110 public MBCategory findByUuid_C_Last(String uuid, long companyId,
1111 OrderByComparator orderByComparator)
1112 throws NoSuchCategoryException, SystemException {
1113 MBCategory mbCategory = fetchByUuid_C_Last(uuid, companyId,
1114 orderByComparator);
1115
1116 if (mbCategory != null) {
1117 return mbCategory;
1118 }
1119
1120 StringBundler msg = new StringBundler(6);
1121
1122 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1123
1124 msg.append("uuid=");
1125 msg.append(uuid);
1126
1127 msg.append(", companyId=");
1128 msg.append(companyId);
1129
1130 msg.append(StringPool.CLOSE_CURLY_BRACE);
1131
1132 throw new NoSuchCategoryException(msg.toString());
1133 }
1134
1135
1144 public MBCategory fetchByUuid_C_Last(String uuid, long companyId,
1145 OrderByComparator orderByComparator) throws SystemException {
1146 int count = countByUuid_C(uuid, companyId);
1147
1148 List<MBCategory> list = findByUuid_C(uuid, companyId, count - 1, count,
1149 orderByComparator);
1150
1151 if (!list.isEmpty()) {
1152 return list.get(0);
1153 }
1154
1155 return null;
1156 }
1157
1158
1169 public MBCategory[] findByUuid_C_PrevAndNext(long categoryId, String uuid,
1170 long companyId, OrderByComparator orderByComparator)
1171 throws NoSuchCategoryException, SystemException {
1172 MBCategory mbCategory = findByPrimaryKey(categoryId);
1173
1174 Session session = null;
1175
1176 try {
1177 session = openSession();
1178
1179 MBCategory[] array = new MBCategoryImpl[3];
1180
1181 array[0] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1182 companyId, orderByComparator, true);
1183
1184 array[1] = mbCategory;
1185
1186 array[2] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1187 companyId, orderByComparator, false);
1188
1189 return array;
1190 }
1191 catch (Exception e) {
1192 throw processException(e);
1193 }
1194 finally {
1195 closeSession(session);
1196 }
1197 }
1198
1199 protected MBCategory getByUuid_C_PrevAndNext(Session session,
1200 MBCategory mbCategory, String uuid, long companyId,
1201 OrderByComparator orderByComparator, boolean previous) {
1202 StringBundler query = null;
1203
1204 if (orderByComparator != null) {
1205 query = new StringBundler(6 +
1206 (orderByComparator.getOrderByFields().length * 6));
1207 }
1208 else {
1209 query = new StringBundler(3);
1210 }
1211
1212 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1213
1214 if (uuid == null) {
1215 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1216 }
1217 else {
1218 if (uuid.equals(StringPool.BLANK)) {
1219 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1220 }
1221 else {
1222 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1223 }
1224 }
1225
1226 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1227
1228 if (orderByComparator != null) {
1229 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1230
1231 if (orderByConditionFields.length > 0) {
1232 query.append(WHERE_AND);
1233 }
1234
1235 for (int i = 0; i < orderByConditionFields.length; i++) {
1236 query.append(_ORDER_BY_ENTITY_ALIAS);
1237 query.append(orderByConditionFields[i]);
1238
1239 if ((i + 1) < orderByConditionFields.length) {
1240 if (orderByComparator.isAscending() ^ previous) {
1241 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1242 }
1243 else {
1244 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1245 }
1246 }
1247 else {
1248 if (orderByComparator.isAscending() ^ previous) {
1249 query.append(WHERE_GREATER_THAN);
1250 }
1251 else {
1252 query.append(WHERE_LESSER_THAN);
1253 }
1254 }
1255 }
1256
1257 query.append(ORDER_BY_CLAUSE);
1258
1259 String[] orderByFields = orderByComparator.getOrderByFields();
1260
1261 for (int i = 0; i < orderByFields.length; i++) {
1262 query.append(_ORDER_BY_ENTITY_ALIAS);
1263 query.append(orderByFields[i]);
1264
1265 if ((i + 1) < orderByFields.length) {
1266 if (orderByComparator.isAscending() ^ previous) {
1267 query.append(ORDER_BY_ASC_HAS_NEXT);
1268 }
1269 else {
1270 query.append(ORDER_BY_DESC_HAS_NEXT);
1271 }
1272 }
1273 else {
1274 if (orderByComparator.isAscending() ^ previous) {
1275 query.append(ORDER_BY_ASC);
1276 }
1277 else {
1278 query.append(ORDER_BY_DESC);
1279 }
1280 }
1281 }
1282 }
1283 else {
1284 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1285 }
1286
1287 String sql = query.toString();
1288
1289 Query q = session.createQuery(sql);
1290
1291 q.setFirstResult(0);
1292 q.setMaxResults(2);
1293
1294 QueryPos qPos = QueryPos.getInstance(q);
1295
1296 if (uuid != null) {
1297 qPos.add(uuid);
1298 }
1299
1300 qPos.add(companyId);
1301
1302 if (orderByComparator != null) {
1303 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1304
1305 for (Object value : values) {
1306 qPos.add(value);
1307 }
1308 }
1309
1310 List<MBCategory> list = q.list();
1311
1312 if (list.size() == 2) {
1313 return list.get(1);
1314 }
1315 else {
1316 return null;
1317 }
1318 }
1319
1320
1327 public void removeByUuid_C(String uuid, long companyId)
1328 throws SystemException {
1329 for (MBCategory mbCategory : findByUuid_C(uuid, companyId,
1330 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1331 remove(mbCategory);
1332 }
1333 }
1334
1335
1343 public int countByUuid_C(String uuid, long companyId)
1344 throws SystemException {
1345 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1346
1347 Object[] finderArgs = new Object[] { uuid, companyId };
1348
1349 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1350 this);
1351
1352 if (count == null) {
1353 StringBundler query = new StringBundler(3);
1354
1355 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
1356
1357 if (uuid == null) {
1358 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1359 }
1360 else {
1361 if (uuid.equals(StringPool.BLANK)) {
1362 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1363 }
1364 else {
1365 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1366 }
1367 }
1368
1369 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1370
1371 String sql = query.toString();
1372
1373 Session session = null;
1374
1375 try {
1376 session = openSession();
1377
1378 Query q = session.createQuery(sql);
1379
1380 QueryPos qPos = QueryPos.getInstance(q);
1381
1382 if (uuid != null) {
1383 qPos.add(uuid);
1384 }
1385
1386 qPos.add(companyId);
1387
1388 count = (Long)q.uniqueResult();
1389
1390 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1391 }
1392 catch (Exception e) {
1393 FinderCacheUtil.removeResult(finderPath, finderArgs);
1394
1395 throw processException(e);
1396 }
1397 finally {
1398 closeSession(session);
1399 }
1400 }
1401
1402 return count.intValue();
1403 }
1404
1405 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbCategory.uuid IS NULL AND ";
1406 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbCategory.uuid = ? AND ";
1407 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
1408 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbCategory.companyId = ?";
1409 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1410 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1411 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1412 new String[] {
1413 Long.class.getName(),
1414
1415 Integer.class.getName(), Integer.class.getName(),
1416 OrderByComparator.class.getName()
1417 });
1418 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1419 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1420 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1421 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1422 new String[] { Long.class.getName() },
1423 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1424 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
1425 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
1426 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1427 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1428 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1429 new String[] { Long.class.getName() });
1430
1431
1438 public List<MBCategory> findByGroupId(long groupId)
1439 throws SystemException {
1440 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1441 }
1442
1443
1456 public List<MBCategory> findByGroupId(long groupId, int start, int end)
1457 throws SystemException {
1458 return findByGroupId(groupId, start, end, null);
1459 }
1460
1461
1475 public List<MBCategory> findByGroupId(long groupId, int start, int end,
1476 OrderByComparator orderByComparator) throws SystemException {
1477 boolean pagination = true;
1478 FinderPath finderPath = null;
1479 Object[] finderArgs = null;
1480
1481 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1482 (orderByComparator == null)) {
1483 pagination = false;
1484 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1485 finderArgs = new Object[] { groupId };
1486 }
1487 else {
1488 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1489 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1490 }
1491
1492 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1493 finderArgs, this);
1494
1495 if ((list != null) && !list.isEmpty()) {
1496 for (MBCategory mbCategory : list) {
1497 if ((groupId != mbCategory.getGroupId())) {
1498 list = null;
1499
1500 break;
1501 }
1502 }
1503 }
1504
1505 if (list == null) {
1506 StringBundler query = null;
1507
1508 if (orderByComparator != null) {
1509 query = new StringBundler(3 +
1510 (orderByComparator.getOrderByFields().length * 3));
1511 }
1512 else {
1513 query = new StringBundler(3);
1514 }
1515
1516 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1517
1518 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1519
1520 if (orderByComparator != null) {
1521 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1522 orderByComparator);
1523 }
1524 else
1525 if (pagination) {
1526 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1527 }
1528
1529 String sql = query.toString();
1530
1531 Session session = null;
1532
1533 try {
1534 session = openSession();
1535
1536 Query q = session.createQuery(sql);
1537
1538 QueryPos qPos = QueryPos.getInstance(q);
1539
1540 qPos.add(groupId);
1541
1542 if (!pagination) {
1543 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1544 start, end, false);
1545
1546 Collections.sort(list);
1547
1548 list = new UnmodifiableList<MBCategory>(list);
1549 }
1550 else {
1551 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1552 start, end);
1553 }
1554
1555 cacheResult(list);
1556
1557 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1558 }
1559 catch (Exception e) {
1560 FinderCacheUtil.removeResult(finderPath, finderArgs);
1561
1562 throw processException(e);
1563 }
1564 finally {
1565 closeSession(session);
1566 }
1567 }
1568
1569 return list;
1570 }
1571
1572
1581 public MBCategory findByGroupId_First(long groupId,
1582 OrderByComparator orderByComparator)
1583 throws NoSuchCategoryException, SystemException {
1584 MBCategory mbCategory = fetchByGroupId_First(groupId, orderByComparator);
1585
1586 if (mbCategory != null) {
1587 return mbCategory;
1588 }
1589
1590 StringBundler msg = new StringBundler(4);
1591
1592 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1593
1594 msg.append("groupId=");
1595 msg.append(groupId);
1596
1597 msg.append(StringPool.CLOSE_CURLY_BRACE);
1598
1599 throw new NoSuchCategoryException(msg.toString());
1600 }
1601
1602
1610 public MBCategory fetchByGroupId_First(long groupId,
1611 OrderByComparator orderByComparator) throws SystemException {
1612 List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1613
1614 if (!list.isEmpty()) {
1615 return list.get(0);
1616 }
1617
1618 return null;
1619 }
1620
1621
1630 public MBCategory findByGroupId_Last(long groupId,
1631 OrderByComparator orderByComparator)
1632 throws NoSuchCategoryException, SystemException {
1633 MBCategory mbCategory = fetchByGroupId_Last(groupId, orderByComparator);
1634
1635 if (mbCategory != null) {
1636 return mbCategory;
1637 }
1638
1639 StringBundler msg = new StringBundler(4);
1640
1641 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1642
1643 msg.append("groupId=");
1644 msg.append(groupId);
1645
1646 msg.append(StringPool.CLOSE_CURLY_BRACE);
1647
1648 throw new NoSuchCategoryException(msg.toString());
1649 }
1650
1651
1659 public MBCategory fetchByGroupId_Last(long groupId,
1660 OrderByComparator orderByComparator) throws SystemException {
1661 int count = countByGroupId(groupId);
1662
1663 List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1664 orderByComparator);
1665
1666 if (!list.isEmpty()) {
1667 return list.get(0);
1668 }
1669
1670 return null;
1671 }
1672
1673
1683 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1684 long groupId, OrderByComparator orderByComparator)
1685 throws NoSuchCategoryException, SystemException {
1686 MBCategory mbCategory = findByPrimaryKey(categoryId);
1687
1688 Session session = null;
1689
1690 try {
1691 session = openSession();
1692
1693 MBCategory[] array = new MBCategoryImpl[3];
1694
1695 array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1696 orderByComparator, true);
1697
1698 array[1] = mbCategory;
1699
1700 array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1701 orderByComparator, false);
1702
1703 return array;
1704 }
1705 catch (Exception e) {
1706 throw processException(e);
1707 }
1708 finally {
1709 closeSession(session);
1710 }
1711 }
1712
1713 protected MBCategory getByGroupId_PrevAndNext(Session session,
1714 MBCategory mbCategory, long groupId,
1715 OrderByComparator orderByComparator, boolean previous) {
1716 StringBundler query = null;
1717
1718 if (orderByComparator != null) {
1719 query = new StringBundler(6 +
1720 (orderByComparator.getOrderByFields().length * 6));
1721 }
1722 else {
1723 query = new StringBundler(3);
1724 }
1725
1726 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1727
1728 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1729
1730 if (orderByComparator != null) {
1731 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1732
1733 if (orderByConditionFields.length > 0) {
1734 query.append(WHERE_AND);
1735 }
1736
1737 for (int i = 0; i < orderByConditionFields.length; i++) {
1738 query.append(_ORDER_BY_ENTITY_ALIAS);
1739 query.append(orderByConditionFields[i]);
1740
1741 if ((i + 1) < orderByConditionFields.length) {
1742 if (orderByComparator.isAscending() ^ previous) {
1743 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1744 }
1745 else {
1746 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1747 }
1748 }
1749 else {
1750 if (orderByComparator.isAscending() ^ previous) {
1751 query.append(WHERE_GREATER_THAN);
1752 }
1753 else {
1754 query.append(WHERE_LESSER_THAN);
1755 }
1756 }
1757 }
1758
1759 query.append(ORDER_BY_CLAUSE);
1760
1761 String[] orderByFields = orderByComparator.getOrderByFields();
1762
1763 for (int i = 0; i < orderByFields.length; i++) {
1764 query.append(_ORDER_BY_ENTITY_ALIAS);
1765 query.append(orderByFields[i]);
1766
1767 if ((i + 1) < orderByFields.length) {
1768 if (orderByComparator.isAscending() ^ previous) {
1769 query.append(ORDER_BY_ASC_HAS_NEXT);
1770 }
1771 else {
1772 query.append(ORDER_BY_DESC_HAS_NEXT);
1773 }
1774 }
1775 else {
1776 if (orderByComparator.isAscending() ^ previous) {
1777 query.append(ORDER_BY_ASC);
1778 }
1779 else {
1780 query.append(ORDER_BY_DESC);
1781 }
1782 }
1783 }
1784 }
1785 else {
1786 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1787 }
1788
1789 String sql = query.toString();
1790
1791 Query q = session.createQuery(sql);
1792
1793 q.setFirstResult(0);
1794 q.setMaxResults(2);
1795
1796 QueryPos qPos = QueryPos.getInstance(q);
1797
1798 qPos.add(groupId);
1799
1800 if (orderByComparator != null) {
1801 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1802
1803 for (Object value : values) {
1804 qPos.add(value);
1805 }
1806 }
1807
1808 List<MBCategory> list = q.list();
1809
1810 if (list.size() == 2) {
1811 return list.get(1);
1812 }
1813 else {
1814 return null;
1815 }
1816 }
1817
1818
1825 public List<MBCategory> filterFindByGroupId(long groupId)
1826 throws SystemException {
1827 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1828 QueryUtil.ALL_POS, null);
1829 }
1830
1831
1844 public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1845 throws SystemException {
1846 return filterFindByGroupId(groupId, start, end, null);
1847 }
1848
1849
1863 public List<MBCategory> filterFindByGroupId(long groupId, int start,
1864 int end, OrderByComparator orderByComparator) throws SystemException {
1865 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1866 return findByGroupId(groupId, start, end, orderByComparator);
1867 }
1868
1869 StringBundler query = null;
1870
1871 if (orderByComparator != null) {
1872 query = new StringBundler(3 +
1873 (orderByComparator.getOrderByFields().length * 3));
1874 }
1875 else {
1876 query = new StringBundler(3);
1877 }
1878
1879 if (getDB().isSupportsInlineDistinct()) {
1880 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1881 }
1882 else {
1883 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1884 }
1885
1886 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1887
1888 if (!getDB().isSupportsInlineDistinct()) {
1889 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1890 }
1891
1892 if (orderByComparator != null) {
1893 if (getDB().isSupportsInlineDistinct()) {
1894 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1895 orderByComparator);
1896 }
1897 else {
1898 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1899 orderByComparator);
1900 }
1901 }
1902 else {
1903 if (getDB().isSupportsInlineDistinct()) {
1904 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1905 }
1906 else {
1907 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1908 }
1909 }
1910
1911 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1912 MBCategory.class.getName(),
1913 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1914
1915 Session session = null;
1916
1917 try {
1918 session = openSession();
1919
1920 SQLQuery q = session.createSQLQuery(sql);
1921
1922 if (getDB().isSupportsInlineDistinct()) {
1923 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1924 }
1925 else {
1926 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1927 }
1928
1929 QueryPos qPos = QueryPos.getInstance(q);
1930
1931 qPos.add(groupId);
1932
1933 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1934 }
1935 catch (Exception e) {
1936 throw processException(e);
1937 }
1938 finally {
1939 closeSession(session);
1940 }
1941 }
1942
1943
1953 public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
1954 long groupId, OrderByComparator orderByComparator)
1955 throws NoSuchCategoryException, SystemException {
1956 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1957 return findByGroupId_PrevAndNext(categoryId, groupId,
1958 orderByComparator);
1959 }
1960
1961 MBCategory mbCategory = findByPrimaryKey(categoryId);
1962
1963 Session session = null;
1964
1965 try {
1966 session = openSession();
1967
1968 MBCategory[] array = new MBCategoryImpl[3];
1969
1970 array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1971 groupId, orderByComparator, true);
1972
1973 array[1] = mbCategory;
1974
1975 array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1976 groupId, orderByComparator, false);
1977
1978 return array;
1979 }
1980 catch (Exception e) {
1981 throw processException(e);
1982 }
1983 finally {
1984 closeSession(session);
1985 }
1986 }
1987
1988 protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
1989 MBCategory mbCategory, long groupId,
1990 OrderByComparator orderByComparator, boolean previous) {
1991 StringBundler query = null;
1992
1993 if (orderByComparator != null) {
1994 query = new StringBundler(6 +
1995 (orderByComparator.getOrderByFields().length * 6));
1996 }
1997 else {
1998 query = new StringBundler(3);
1999 }
2000
2001 if (getDB().isSupportsInlineDistinct()) {
2002 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2003 }
2004 else {
2005 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2006 }
2007
2008 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2009
2010 if (!getDB().isSupportsInlineDistinct()) {
2011 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2012 }
2013
2014 if (orderByComparator != null) {
2015 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2016
2017 if (orderByConditionFields.length > 0) {
2018 query.append(WHERE_AND);
2019 }
2020
2021 for (int i = 0; i < orderByConditionFields.length; i++) {
2022 if (getDB().isSupportsInlineDistinct()) {
2023 query.append(_ORDER_BY_ENTITY_ALIAS);
2024 }
2025 else {
2026 query.append(_ORDER_BY_ENTITY_TABLE);
2027 }
2028
2029 query.append(orderByConditionFields[i]);
2030
2031 if ((i + 1) < orderByConditionFields.length) {
2032 if (orderByComparator.isAscending() ^ previous) {
2033 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2034 }
2035 else {
2036 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2037 }
2038 }
2039 else {
2040 if (orderByComparator.isAscending() ^ previous) {
2041 query.append(WHERE_GREATER_THAN);
2042 }
2043 else {
2044 query.append(WHERE_LESSER_THAN);
2045 }
2046 }
2047 }
2048
2049 query.append(ORDER_BY_CLAUSE);
2050
2051 String[] orderByFields = orderByComparator.getOrderByFields();
2052
2053 for (int i = 0; i < orderByFields.length; i++) {
2054 if (getDB().isSupportsInlineDistinct()) {
2055 query.append(_ORDER_BY_ENTITY_ALIAS);
2056 }
2057 else {
2058 query.append(_ORDER_BY_ENTITY_TABLE);
2059 }
2060
2061 query.append(orderByFields[i]);
2062
2063 if ((i + 1) < orderByFields.length) {
2064 if (orderByComparator.isAscending() ^ previous) {
2065 query.append(ORDER_BY_ASC_HAS_NEXT);
2066 }
2067 else {
2068 query.append(ORDER_BY_DESC_HAS_NEXT);
2069 }
2070 }
2071 else {
2072 if (orderByComparator.isAscending() ^ previous) {
2073 query.append(ORDER_BY_ASC);
2074 }
2075 else {
2076 query.append(ORDER_BY_DESC);
2077 }
2078 }
2079 }
2080 }
2081 else {
2082 if (getDB().isSupportsInlineDistinct()) {
2083 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2084 }
2085 else {
2086 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2087 }
2088 }
2089
2090 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2091 MBCategory.class.getName(),
2092 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2093
2094 SQLQuery q = session.createSQLQuery(sql);
2095
2096 q.setFirstResult(0);
2097 q.setMaxResults(2);
2098
2099 if (getDB().isSupportsInlineDistinct()) {
2100 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2101 }
2102 else {
2103 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2104 }
2105
2106 QueryPos qPos = QueryPos.getInstance(q);
2107
2108 qPos.add(groupId);
2109
2110 if (orderByComparator != null) {
2111 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2112
2113 for (Object value : values) {
2114 qPos.add(value);
2115 }
2116 }
2117
2118 List<MBCategory> list = q.list();
2119
2120 if (list.size() == 2) {
2121 return list.get(1);
2122 }
2123 else {
2124 return null;
2125 }
2126 }
2127
2128
2134 public void removeByGroupId(long groupId) throws SystemException {
2135 for (MBCategory mbCategory : findByGroupId(groupId, QueryUtil.ALL_POS,
2136 QueryUtil.ALL_POS, null)) {
2137 remove(mbCategory);
2138 }
2139 }
2140
2141
2148 public int countByGroupId(long groupId) throws SystemException {
2149 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2150
2151 Object[] finderArgs = new Object[] { groupId };
2152
2153 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2154 this);
2155
2156 if (count == null) {
2157 StringBundler query = new StringBundler(2);
2158
2159 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2160
2161 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2162
2163 String sql = query.toString();
2164
2165 Session session = null;
2166
2167 try {
2168 session = openSession();
2169
2170 Query q = session.createQuery(sql);
2171
2172 QueryPos qPos = QueryPos.getInstance(q);
2173
2174 qPos.add(groupId);
2175
2176 count = (Long)q.uniqueResult();
2177
2178 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2179 }
2180 catch (Exception e) {
2181 FinderCacheUtil.removeResult(finderPath, finderArgs);
2182
2183 throw processException(e);
2184 }
2185 finally {
2186 closeSession(session);
2187 }
2188 }
2189
2190 return count.intValue();
2191 }
2192
2193
2200 public int filterCountByGroupId(long groupId) throws SystemException {
2201 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2202 return countByGroupId(groupId);
2203 }
2204
2205 StringBundler query = new StringBundler(2);
2206
2207 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2208
2209 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2210
2211 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2212 MBCategory.class.getName(),
2213 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2214
2215 Session session = null;
2216
2217 try {
2218 session = openSession();
2219
2220 SQLQuery q = session.createSQLQuery(sql);
2221
2222 q.addScalar(COUNT_COLUMN_NAME,
2223 com.liferay.portal.kernel.dao.orm.Type.LONG);
2224
2225 QueryPos qPos = QueryPos.getInstance(q);
2226
2227 qPos.add(groupId);
2228
2229 Long count = (Long)q.uniqueResult();
2230
2231 return count.intValue();
2232 }
2233 catch (Exception e) {
2234 throw processException(e);
2235 }
2236 finally {
2237 closeSession(session);
2238 }
2239 }
2240
2241 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
2242 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2243 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2244 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2245 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2246 new String[] {
2247 Long.class.getName(),
2248
2249 Integer.class.getName(), Integer.class.getName(),
2250 OrderByComparator.class.getName()
2251 });
2252 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2253 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2254 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2255 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2256 new String[] { Long.class.getName() },
2257 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
2258 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2259 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2260 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2261 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2262 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2263 new String[] { Long.class.getName() });
2264
2265
2272 public List<MBCategory> findByCompanyId(long companyId)
2273 throws SystemException {
2274 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2275 null);
2276 }
2277
2278
2291 public List<MBCategory> findByCompanyId(long companyId, int start, int end)
2292 throws SystemException {
2293 return findByCompanyId(companyId, start, end, null);
2294 }
2295
2296
2310 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2311 OrderByComparator orderByComparator) throws SystemException {
2312 boolean pagination = true;
2313 FinderPath finderPath = null;
2314 Object[] finderArgs = null;
2315
2316 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2317 (orderByComparator == null)) {
2318 pagination = false;
2319 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2320 finderArgs = new Object[] { companyId };
2321 }
2322 else {
2323 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2324 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2325 }
2326
2327 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2328 finderArgs, this);
2329
2330 if ((list != null) && !list.isEmpty()) {
2331 for (MBCategory mbCategory : list) {
2332 if ((companyId != mbCategory.getCompanyId())) {
2333 list = null;
2334
2335 break;
2336 }
2337 }
2338 }
2339
2340 if (list == null) {
2341 StringBundler query = null;
2342
2343 if (orderByComparator != null) {
2344 query = new StringBundler(3 +
2345 (orderByComparator.getOrderByFields().length * 3));
2346 }
2347 else {
2348 query = new StringBundler(3);
2349 }
2350
2351 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2352
2353 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2354
2355 if (orderByComparator != null) {
2356 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2357 orderByComparator);
2358 }
2359 else
2360 if (pagination) {
2361 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2362 }
2363
2364 String sql = query.toString();
2365
2366 Session session = null;
2367
2368 try {
2369 session = openSession();
2370
2371 Query q = session.createQuery(sql);
2372
2373 QueryPos qPos = QueryPos.getInstance(q);
2374
2375 qPos.add(companyId);
2376
2377 if (!pagination) {
2378 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2379 start, end, false);
2380
2381 Collections.sort(list);
2382
2383 list = new UnmodifiableList<MBCategory>(list);
2384 }
2385 else {
2386 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2387 start, end);
2388 }
2389
2390 cacheResult(list);
2391
2392 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2393 }
2394 catch (Exception e) {
2395 FinderCacheUtil.removeResult(finderPath, finderArgs);
2396
2397 throw processException(e);
2398 }
2399 finally {
2400 closeSession(session);
2401 }
2402 }
2403
2404 return list;
2405 }
2406
2407
2416 public MBCategory findByCompanyId_First(long companyId,
2417 OrderByComparator orderByComparator)
2418 throws NoSuchCategoryException, SystemException {
2419 MBCategory mbCategory = fetchByCompanyId_First(companyId,
2420 orderByComparator);
2421
2422 if (mbCategory != null) {
2423 return mbCategory;
2424 }
2425
2426 StringBundler msg = new StringBundler(4);
2427
2428 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2429
2430 msg.append("companyId=");
2431 msg.append(companyId);
2432
2433 msg.append(StringPool.CLOSE_CURLY_BRACE);
2434
2435 throw new NoSuchCategoryException(msg.toString());
2436 }
2437
2438
2446 public MBCategory fetchByCompanyId_First(long companyId,
2447 OrderByComparator orderByComparator) throws SystemException {
2448 List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2449 orderByComparator);
2450
2451 if (!list.isEmpty()) {
2452 return list.get(0);
2453 }
2454
2455 return null;
2456 }
2457
2458
2467 public MBCategory findByCompanyId_Last(long companyId,
2468 OrderByComparator orderByComparator)
2469 throws NoSuchCategoryException, SystemException {
2470 MBCategory mbCategory = fetchByCompanyId_Last(companyId,
2471 orderByComparator);
2472
2473 if (mbCategory != null) {
2474 return mbCategory;
2475 }
2476
2477 StringBundler msg = new StringBundler(4);
2478
2479 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2480
2481 msg.append("companyId=");
2482 msg.append(companyId);
2483
2484 msg.append(StringPool.CLOSE_CURLY_BRACE);
2485
2486 throw new NoSuchCategoryException(msg.toString());
2487 }
2488
2489
2497 public MBCategory fetchByCompanyId_Last(long companyId,
2498 OrderByComparator orderByComparator) throws SystemException {
2499 int count = countByCompanyId(companyId);
2500
2501 List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2502 orderByComparator);
2503
2504 if (!list.isEmpty()) {
2505 return list.get(0);
2506 }
2507
2508 return null;
2509 }
2510
2511
2521 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2522 long companyId, OrderByComparator orderByComparator)
2523 throws NoSuchCategoryException, SystemException {
2524 MBCategory mbCategory = findByPrimaryKey(categoryId);
2525
2526 Session session = null;
2527
2528 try {
2529 session = openSession();
2530
2531 MBCategory[] array = new MBCategoryImpl[3];
2532
2533 array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2534 companyId, orderByComparator, true);
2535
2536 array[1] = mbCategory;
2537
2538 array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2539 companyId, orderByComparator, false);
2540
2541 return array;
2542 }
2543 catch (Exception e) {
2544 throw processException(e);
2545 }
2546 finally {
2547 closeSession(session);
2548 }
2549 }
2550
2551 protected MBCategory getByCompanyId_PrevAndNext(Session session,
2552 MBCategory mbCategory, long companyId,
2553 OrderByComparator orderByComparator, boolean previous) {
2554 StringBundler query = null;
2555
2556 if (orderByComparator != null) {
2557 query = new StringBundler(6 +
2558 (orderByComparator.getOrderByFields().length * 6));
2559 }
2560 else {
2561 query = new StringBundler(3);
2562 }
2563
2564 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2565
2566 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2567
2568 if (orderByComparator != null) {
2569 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2570
2571 if (orderByConditionFields.length > 0) {
2572 query.append(WHERE_AND);
2573 }
2574
2575 for (int i = 0; i < orderByConditionFields.length; i++) {
2576 query.append(_ORDER_BY_ENTITY_ALIAS);
2577 query.append(orderByConditionFields[i]);
2578
2579 if ((i + 1) < orderByConditionFields.length) {
2580 if (orderByComparator.isAscending() ^ previous) {
2581 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2582 }
2583 else {
2584 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2585 }
2586 }
2587 else {
2588 if (orderByComparator.isAscending() ^ previous) {
2589 query.append(WHERE_GREATER_THAN);
2590 }
2591 else {
2592 query.append(WHERE_LESSER_THAN);
2593 }
2594 }
2595 }
2596
2597 query.append(ORDER_BY_CLAUSE);
2598
2599 String[] orderByFields = orderByComparator.getOrderByFields();
2600
2601 for (int i = 0; i < orderByFields.length; i++) {
2602 query.append(_ORDER_BY_ENTITY_ALIAS);
2603 query.append(orderByFields[i]);
2604
2605 if ((i + 1) < orderByFields.length) {
2606 if (orderByComparator.isAscending() ^ previous) {
2607 query.append(ORDER_BY_ASC_HAS_NEXT);
2608 }
2609 else {
2610 query.append(ORDER_BY_DESC_HAS_NEXT);
2611 }
2612 }
2613 else {
2614 if (orderByComparator.isAscending() ^ previous) {
2615 query.append(ORDER_BY_ASC);
2616 }
2617 else {
2618 query.append(ORDER_BY_DESC);
2619 }
2620 }
2621 }
2622 }
2623 else {
2624 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2625 }
2626
2627 String sql = query.toString();
2628
2629 Query q = session.createQuery(sql);
2630
2631 q.setFirstResult(0);
2632 q.setMaxResults(2);
2633
2634 QueryPos qPos = QueryPos.getInstance(q);
2635
2636 qPos.add(companyId);
2637
2638 if (orderByComparator != null) {
2639 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2640
2641 for (Object value : values) {
2642 qPos.add(value);
2643 }
2644 }
2645
2646 List<MBCategory> list = q.list();
2647
2648 if (list.size() == 2) {
2649 return list.get(1);
2650 }
2651 else {
2652 return null;
2653 }
2654 }
2655
2656
2662 public void removeByCompanyId(long companyId) throws SystemException {
2663 for (MBCategory mbCategory : findByCompanyId(companyId,
2664 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2665 remove(mbCategory);
2666 }
2667 }
2668
2669
2676 public int countByCompanyId(long companyId) throws SystemException {
2677 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2678
2679 Object[] finderArgs = new Object[] { companyId };
2680
2681 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2682 this);
2683
2684 if (count == null) {
2685 StringBundler query = new StringBundler(2);
2686
2687 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2688
2689 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2690
2691 String sql = query.toString();
2692
2693 Session session = null;
2694
2695 try {
2696 session = openSession();
2697
2698 Query q = session.createQuery(sql);
2699
2700 QueryPos qPos = QueryPos.getInstance(q);
2701
2702 qPos.add(companyId);
2703
2704 count = (Long)q.uniqueResult();
2705
2706 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2707 }
2708 catch (Exception e) {
2709 FinderCacheUtil.removeResult(finderPath, finderArgs);
2710
2711 throw processException(e);
2712 }
2713 finally {
2714 closeSession(session);
2715 }
2716 }
2717
2718 return count.intValue();
2719 }
2720
2721 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
2722 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2723 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2724 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
2725 new String[] {
2726 Long.class.getName(), Long.class.getName(),
2727
2728 Integer.class.getName(), Integer.class.getName(),
2729 OrderByComparator.class.getName()
2730 });
2731 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2732 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2733 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
2734 new String[] { Long.class.getName(), Long.class.getName() },
2735 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
2736 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2737 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2738 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2739 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2740 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
2741 new String[] { Long.class.getName(), Long.class.getName() });
2742 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2743 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2744 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
2745 new String[] { Long.class.getName(), Long.class.getName() });
2746
2747
2755 public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
2756 throws SystemException {
2757 return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2758 QueryUtil.ALL_POS, null);
2759 }
2760
2761
2775 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2776 int start, int end) throws SystemException {
2777 return findByG_P(groupId, parentCategoryId, start, end, null);
2778 }
2779
2780
2795 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2796 int start, int end, OrderByComparator orderByComparator)
2797 throws SystemException {
2798 boolean pagination = true;
2799 FinderPath finderPath = null;
2800 Object[] finderArgs = null;
2801
2802 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2803 (orderByComparator == null)) {
2804 pagination = false;
2805 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2806 finderArgs = new Object[] { groupId, parentCategoryId };
2807 }
2808 else {
2809 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2810 finderArgs = new Object[] {
2811 groupId, parentCategoryId,
2812
2813 start, end, orderByComparator
2814 };
2815 }
2816
2817 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2818 finderArgs, this);
2819
2820 if ((list != null) && !list.isEmpty()) {
2821 for (MBCategory mbCategory : list) {
2822 if ((groupId != mbCategory.getGroupId()) ||
2823 (parentCategoryId != mbCategory.getParentCategoryId())) {
2824 list = null;
2825
2826 break;
2827 }
2828 }
2829 }
2830
2831 if (list == null) {
2832 StringBundler query = null;
2833
2834 if (orderByComparator != null) {
2835 query = new StringBundler(4 +
2836 (orderByComparator.getOrderByFields().length * 3));
2837 }
2838 else {
2839 query = new StringBundler(4);
2840 }
2841
2842 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2843
2844 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2845
2846 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2847
2848 if (orderByComparator != null) {
2849 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2850 orderByComparator);
2851 }
2852 else
2853 if (pagination) {
2854 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2855 }
2856
2857 String sql = query.toString();
2858
2859 Session session = null;
2860
2861 try {
2862 session = openSession();
2863
2864 Query q = session.createQuery(sql);
2865
2866 QueryPos qPos = QueryPos.getInstance(q);
2867
2868 qPos.add(groupId);
2869
2870 qPos.add(parentCategoryId);
2871
2872 if (!pagination) {
2873 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2874 start, end, false);
2875
2876 Collections.sort(list);
2877
2878 list = new UnmodifiableList<MBCategory>(list);
2879 }
2880 else {
2881 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2882 start, end);
2883 }
2884
2885 cacheResult(list);
2886
2887 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2888 }
2889 catch (Exception e) {
2890 FinderCacheUtil.removeResult(finderPath, finderArgs);
2891
2892 throw processException(e);
2893 }
2894 finally {
2895 closeSession(session);
2896 }
2897 }
2898
2899 return list;
2900 }
2901
2902
2912 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
2913 OrderByComparator orderByComparator)
2914 throws NoSuchCategoryException, SystemException {
2915 MBCategory mbCategory = fetchByG_P_First(groupId, parentCategoryId,
2916 orderByComparator);
2917
2918 if (mbCategory != null) {
2919 return mbCategory;
2920 }
2921
2922 StringBundler msg = new StringBundler(6);
2923
2924 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2925
2926 msg.append("groupId=");
2927 msg.append(groupId);
2928
2929 msg.append(", parentCategoryId=");
2930 msg.append(parentCategoryId);
2931
2932 msg.append(StringPool.CLOSE_CURLY_BRACE);
2933
2934 throw new NoSuchCategoryException(msg.toString());
2935 }
2936
2937
2946 public MBCategory fetchByG_P_First(long groupId, long parentCategoryId,
2947 OrderByComparator orderByComparator) throws SystemException {
2948 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
2949 orderByComparator);
2950
2951 if (!list.isEmpty()) {
2952 return list.get(0);
2953 }
2954
2955 return null;
2956 }
2957
2958
2968 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
2969 OrderByComparator orderByComparator)
2970 throws NoSuchCategoryException, SystemException {
2971 MBCategory mbCategory = fetchByG_P_Last(groupId, parentCategoryId,
2972 orderByComparator);
2973
2974 if (mbCategory != null) {
2975 return mbCategory;
2976 }
2977
2978 StringBundler msg = new StringBundler(6);
2979
2980 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2981
2982 msg.append("groupId=");
2983 msg.append(groupId);
2984
2985 msg.append(", parentCategoryId=");
2986 msg.append(parentCategoryId);
2987
2988 msg.append(StringPool.CLOSE_CURLY_BRACE);
2989
2990 throw new NoSuchCategoryException(msg.toString());
2991 }
2992
2993
3002 public MBCategory fetchByG_P_Last(long groupId, long parentCategoryId,
3003 OrderByComparator orderByComparator) throws SystemException {
3004 int count = countByG_P(groupId, parentCategoryId);
3005
3006 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
3007 count, orderByComparator);
3008
3009 if (!list.isEmpty()) {
3010 return list.get(0);
3011 }
3012
3013 return null;
3014 }
3015
3016
3027 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
3028 long parentCategoryId, OrderByComparator orderByComparator)
3029 throws NoSuchCategoryException, SystemException {
3030 MBCategory mbCategory = findByPrimaryKey(categoryId);
3031
3032 Session session = null;
3033
3034 try {
3035 session = openSession();
3036
3037 MBCategory[] array = new MBCategoryImpl[3];
3038
3039 array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3040 parentCategoryId, orderByComparator, true);
3041
3042 array[1] = mbCategory;
3043
3044 array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3045 parentCategoryId, orderByComparator, false);
3046
3047 return array;
3048 }
3049 catch (Exception e) {
3050 throw processException(e);
3051 }
3052 finally {
3053 closeSession(session);
3054 }
3055 }
3056
3057 protected MBCategory getByG_P_PrevAndNext(Session session,
3058 MBCategory mbCategory, long groupId, long parentCategoryId,
3059 OrderByComparator orderByComparator, boolean previous) {
3060 StringBundler query = null;
3061
3062 if (orderByComparator != null) {
3063 query = new StringBundler(6 +
3064 (orderByComparator.getOrderByFields().length * 6));
3065 }
3066 else {
3067 query = new StringBundler(3);
3068 }
3069
3070 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3071
3072 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3073
3074 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3075
3076 if (orderByComparator != null) {
3077 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3078
3079 if (orderByConditionFields.length > 0) {
3080 query.append(WHERE_AND);
3081 }
3082
3083 for (int i = 0; i < orderByConditionFields.length; i++) {
3084 query.append(_ORDER_BY_ENTITY_ALIAS);
3085 query.append(orderByConditionFields[i]);
3086
3087 if ((i + 1) < orderByConditionFields.length) {
3088 if (orderByComparator.isAscending() ^ previous) {
3089 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3090 }
3091 else {
3092 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3093 }
3094 }
3095 else {
3096 if (orderByComparator.isAscending() ^ previous) {
3097 query.append(WHERE_GREATER_THAN);
3098 }
3099 else {
3100 query.append(WHERE_LESSER_THAN);
3101 }
3102 }
3103 }
3104
3105 query.append(ORDER_BY_CLAUSE);
3106
3107 String[] orderByFields = orderByComparator.getOrderByFields();
3108
3109 for (int i = 0; i < orderByFields.length; i++) {
3110 query.append(_ORDER_BY_ENTITY_ALIAS);
3111 query.append(orderByFields[i]);
3112
3113 if ((i + 1) < orderByFields.length) {
3114 if (orderByComparator.isAscending() ^ previous) {
3115 query.append(ORDER_BY_ASC_HAS_NEXT);
3116 }
3117 else {
3118 query.append(ORDER_BY_DESC_HAS_NEXT);
3119 }
3120 }
3121 else {
3122 if (orderByComparator.isAscending() ^ previous) {
3123 query.append(ORDER_BY_ASC);
3124 }
3125 else {
3126 query.append(ORDER_BY_DESC);
3127 }
3128 }
3129 }
3130 }
3131 else {
3132 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3133 }
3134
3135 String sql = query.toString();
3136
3137 Query q = session.createQuery(sql);
3138
3139 q.setFirstResult(0);
3140 q.setMaxResults(2);
3141
3142 QueryPos qPos = QueryPos.getInstance(q);
3143
3144 qPos.add(groupId);
3145
3146 qPos.add(parentCategoryId);
3147
3148 if (orderByComparator != null) {
3149 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3150
3151 for (Object value : values) {
3152 qPos.add(value);
3153 }
3154 }
3155
3156 List<MBCategory> list = q.list();
3157
3158 if (list.size() == 2) {
3159 return list.get(1);
3160 }
3161 else {
3162 return null;
3163 }
3164 }
3165
3166
3174 public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
3175 throws SystemException {
3176 return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
3177 QueryUtil.ALL_POS, null);
3178 }
3179
3180
3194 public List<MBCategory> filterFindByG_P(long groupId,
3195 long parentCategoryId, int start, int end) throws SystemException {
3196 return filterFindByG_P(groupId, parentCategoryId, start, end, null);
3197 }
3198
3199
3214 public List<MBCategory> filterFindByG_P(long groupId,
3215 long parentCategoryId, int start, int end,
3216 OrderByComparator orderByComparator) throws SystemException {
3217 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3218 return findByG_P(groupId, parentCategoryId, start, end,
3219 orderByComparator);
3220 }
3221
3222 StringBundler query = null;
3223
3224 if (orderByComparator != null) {
3225 query = new StringBundler(4 +
3226 (orderByComparator.getOrderByFields().length * 3));
3227 }
3228 else {
3229 query = new StringBundler(4);
3230 }
3231
3232 if (getDB().isSupportsInlineDistinct()) {
3233 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3234 }
3235 else {
3236 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3237 }
3238
3239 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3240
3241 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3242
3243 if (!getDB().isSupportsInlineDistinct()) {
3244 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3245 }
3246
3247 if (orderByComparator != null) {
3248 if (getDB().isSupportsInlineDistinct()) {
3249 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3250 orderByComparator);
3251 }
3252 else {
3253 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3254 orderByComparator);
3255 }
3256 }
3257 else {
3258 if (getDB().isSupportsInlineDistinct()) {
3259 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3260 }
3261 else {
3262 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3263 }
3264 }
3265
3266 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3267 MBCategory.class.getName(),
3268 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3269
3270 Session session = null;
3271
3272 try {
3273 session = openSession();
3274
3275 SQLQuery q = session.createSQLQuery(sql);
3276
3277 if (getDB().isSupportsInlineDistinct()) {
3278 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3279 }
3280 else {
3281 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3282 }
3283
3284 QueryPos qPos = QueryPos.getInstance(q);
3285
3286 qPos.add(groupId);
3287
3288 qPos.add(parentCategoryId);
3289
3290 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3291 }
3292 catch (Exception e) {
3293 throw processException(e);
3294 }
3295 finally {
3296 closeSession(session);
3297 }
3298 }
3299
3300
3311 public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
3312 long groupId, long parentCategoryId, OrderByComparator orderByComparator)
3313 throws NoSuchCategoryException, SystemException {
3314 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3315 return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
3316 orderByComparator);
3317 }
3318
3319 MBCategory mbCategory = findByPrimaryKey(categoryId);
3320
3321 Session session = null;
3322
3323 try {
3324 session = openSession();
3325
3326 MBCategory[] array = new MBCategoryImpl[3];
3327
3328 array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3329 parentCategoryId, orderByComparator, true);
3330
3331 array[1] = mbCategory;
3332
3333 array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3334 parentCategoryId, orderByComparator, false);
3335
3336 return array;
3337 }
3338 catch (Exception e) {
3339 throw processException(e);
3340 }
3341 finally {
3342 closeSession(session);
3343 }
3344 }
3345
3346 protected MBCategory filterGetByG_P_PrevAndNext(Session session,
3347 MBCategory mbCategory, long groupId, long parentCategoryId,
3348 OrderByComparator orderByComparator, boolean previous) {
3349 StringBundler query = null;
3350
3351 if (orderByComparator != null) {
3352 query = new StringBundler(6 +
3353 (orderByComparator.getOrderByFields().length * 6));
3354 }
3355 else {
3356 query = new StringBundler(3);
3357 }
3358
3359 if (getDB().isSupportsInlineDistinct()) {
3360 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3361 }
3362 else {
3363 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3364 }
3365
3366 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3367
3368 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3369
3370 if (!getDB().isSupportsInlineDistinct()) {
3371 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3372 }
3373
3374 if (orderByComparator != null) {
3375 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3376
3377 if (orderByConditionFields.length > 0) {
3378 query.append(WHERE_AND);
3379 }
3380
3381 for (int i = 0; i < orderByConditionFields.length; i++) {
3382 if (getDB().isSupportsInlineDistinct()) {
3383 query.append(_ORDER_BY_ENTITY_ALIAS);
3384 }
3385 else {
3386 query.append(_ORDER_BY_ENTITY_TABLE);
3387 }
3388
3389 query.append(orderByConditionFields[i]);
3390
3391 if ((i + 1) < orderByConditionFields.length) {
3392 if (orderByComparator.isAscending() ^ previous) {
3393 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3394 }
3395 else {
3396 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3397 }
3398 }
3399 else {
3400 if (orderByComparator.isAscending() ^ previous) {
3401 query.append(WHERE_GREATER_THAN);
3402 }
3403 else {
3404 query.append(WHERE_LESSER_THAN);
3405 }
3406 }
3407 }
3408
3409 query.append(ORDER_BY_CLAUSE);
3410
3411 String[] orderByFields = orderByComparator.getOrderByFields();
3412
3413 for (int i = 0; i < orderByFields.length; i++) {
3414 if (getDB().isSupportsInlineDistinct()) {
3415 query.append(_ORDER_BY_ENTITY_ALIAS);
3416 }
3417 else {
3418 query.append(_ORDER_BY_ENTITY_TABLE);
3419 }
3420
3421 query.append(orderByFields[i]);
3422
3423 if ((i + 1) < orderByFields.length) {
3424 if (orderByComparator.isAscending() ^ previous) {
3425 query.append(ORDER_BY_ASC_HAS_NEXT);
3426 }
3427 else {
3428 query.append(ORDER_BY_DESC_HAS_NEXT);
3429 }
3430 }
3431 else {
3432 if (orderByComparator.isAscending() ^ previous) {
3433 query.append(ORDER_BY_ASC);
3434 }
3435 else {
3436 query.append(ORDER_BY_DESC);
3437 }
3438 }
3439 }
3440 }
3441 else {
3442 if (getDB().isSupportsInlineDistinct()) {
3443 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3444 }
3445 else {
3446 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3447 }
3448 }
3449
3450 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3451 MBCategory.class.getName(),
3452 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3453
3454 SQLQuery q = session.createSQLQuery(sql);
3455
3456 q.setFirstResult(0);
3457 q.setMaxResults(2);
3458
3459 if (getDB().isSupportsInlineDistinct()) {
3460 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3461 }
3462 else {
3463 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3464 }
3465
3466 QueryPos qPos = QueryPos.getInstance(q);
3467
3468 qPos.add(groupId);
3469
3470 qPos.add(parentCategoryId);
3471
3472 if (orderByComparator != null) {
3473 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3474
3475 for (Object value : values) {
3476 qPos.add(value);
3477 }
3478 }
3479
3480 List<MBCategory> list = q.list();
3481
3482 if (list.size() == 2) {
3483 return list.get(1);
3484 }
3485 else {
3486 return null;
3487 }
3488 }
3489
3490
3498 public List<MBCategory> filterFindByG_P(long groupId,
3499 long[] parentCategoryIds) throws SystemException {
3500 return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3501 QueryUtil.ALL_POS, null);
3502 }
3503
3504
3518 public List<MBCategory> filterFindByG_P(long groupId,
3519 long[] parentCategoryIds, int start, int end) throws SystemException {
3520 return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3521 }
3522
3523
3538 public List<MBCategory> filterFindByG_P(long groupId,
3539 long[] parentCategoryIds, int start, int end,
3540 OrderByComparator orderByComparator) throws SystemException {
3541 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3542 return findByG_P(groupId, parentCategoryIds, start, end,
3543 orderByComparator);
3544 }
3545
3546 StringBundler query = new StringBundler();
3547
3548 if (getDB().isSupportsInlineDistinct()) {
3549 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3550 }
3551 else {
3552 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3553 }
3554
3555 boolean conjunctionable = false;
3556
3557 if (conjunctionable) {
3558 query.append(WHERE_AND);
3559 }
3560
3561 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3562
3563 conjunctionable = true;
3564
3565 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3566 if (conjunctionable) {
3567 query.append(WHERE_AND);
3568 }
3569
3570 query.append(StringPool.OPEN_PARENTHESIS);
3571
3572 for (int i = 0; i < parentCategoryIds.length; i++) {
3573 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3574
3575 if ((i + 1) < parentCategoryIds.length) {
3576 query.append(WHERE_OR);
3577 }
3578 }
3579
3580 query.append(StringPool.CLOSE_PARENTHESIS);
3581
3582 conjunctionable = true;
3583 }
3584
3585 if (!getDB().isSupportsInlineDistinct()) {
3586 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3587 }
3588
3589 if (orderByComparator != null) {
3590 if (getDB().isSupportsInlineDistinct()) {
3591 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3592 orderByComparator);
3593 }
3594 else {
3595 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3596 orderByComparator);
3597 }
3598 }
3599 else {
3600 if (getDB().isSupportsInlineDistinct()) {
3601 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3602 }
3603 else {
3604 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3605 }
3606 }
3607
3608 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3609 MBCategory.class.getName(),
3610 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3611
3612 Session session = null;
3613
3614 try {
3615 session = openSession();
3616
3617 SQLQuery q = session.createSQLQuery(sql);
3618
3619 if (getDB().isSupportsInlineDistinct()) {
3620 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3621 }
3622 else {
3623 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3624 }
3625
3626 QueryPos qPos = QueryPos.getInstance(q);
3627
3628 qPos.add(groupId);
3629
3630 if (parentCategoryIds != null) {
3631 qPos.add(parentCategoryIds);
3632 }
3633
3634 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3635 }
3636 catch (Exception e) {
3637 throw processException(e);
3638 }
3639 finally {
3640 closeSession(session);
3641 }
3642 }
3643
3644
3656 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
3657 throws SystemException {
3658 return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3659 QueryUtil.ALL_POS, null);
3660 }
3661
3662
3676 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3677 int start, int end) throws SystemException {
3678 return findByG_P(groupId, parentCategoryIds, start, end, null);
3679 }
3680
3681
3696 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3697 int start, int end, OrderByComparator orderByComparator)
3698 throws SystemException {
3699 if ((parentCategoryIds != null) && (parentCategoryIds.length == 1)) {
3700 return findByG_P(groupId, parentCategoryIds[0], start, end,
3701 orderByComparator);
3702 }
3703
3704 boolean pagination = true;
3705 Object[] finderArgs = null;
3706
3707 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3708 (orderByComparator == null)) {
3709 pagination = false;
3710 finderArgs = new Object[] {
3711 groupId, StringUtil.merge(parentCategoryIds)
3712 };
3713 }
3714 else {
3715 finderArgs = new Object[] {
3716 groupId, StringUtil.merge(parentCategoryIds),
3717
3718 start, end, orderByComparator
3719 };
3720 }
3721
3722 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3723 finderArgs, this);
3724
3725 if ((list != null) && !list.isEmpty()) {
3726 for (MBCategory mbCategory : list) {
3727 if ((groupId != mbCategory.getGroupId()) ||
3728 !ArrayUtil.contains(parentCategoryIds,
3729 mbCategory.getParentCategoryId())) {
3730 list = null;
3731
3732 break;
3733 }
3734 }
3735 }
3736
3737 if (list == null) {
3738 StringBundler query = new StringBundler();
3739
3740 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3741
3742 boolean conjunctionable = false;
3743
3744 if (conjunctionable) {
3745 query.append(WHERE_AND);
3746 }
3747
3748 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3749
3750 conjunctionable = true;
3751
3752 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3753 if (conjunctionable) {
3754 query.append(WHERE_AND);
3755 }
3756
3757 query.append(StringPool.OPEN_PARENTHESIS);
3758
3759 for (int i = 0; i < parentCategoryIds.length; i++) {
3760 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3761
3762 if ((i + 1) < parentCategoryIds.length) {
3763 query.append(WHERE_OR);
3764 }
3765 }
3766
3767 query.append(StringPool.CLOSE_PARENTHESIS);
3768
3769 conjunctionable = true;
3770 }
3771
3772 if (orderByComparator != null) {
3773 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3774 orderByComparator);
3775 }
3776 else
3777 if (pagination) {
3778 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3779 }
3780
3781 String sql = query.toString();
3782
3783 Session session = null;
3784
3785 try {
3786 session = openSession();
3787
3788 Query q = session.createQuery(sql);
3789
3790 QueryPos qPos = QueryPos.getInstance(q);
3791
3792 qPos.add(groupId);
3793
3794 if (parentCategoryIds != null) {
3795 qPos.add(parentCategoryIds);
3796 }
3797
3798 if (!pagination) {
3799 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3800 start, end, false);
3801
3802 Collections.sort(list);
3803
3804 list = new UnmodifiableList<MBCategory>(list);
3805 }
3806 else {
3807 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3808 start, end);
3809 }
3810
3811 cacheResult(list);
3812
3813 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3814 finderArgs, list);
3815 }
3816 catch (Exception e) {
3817 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3818 finderArgs);
3819
3820 throw processException(e);
3821 }
3822 finally {
3823 closeSession(session);
3824 }
3825 }
3826
3827 return list;
3828 }
3829
3830
3837 public void removeByG_P(long groupId, long parentCategoryId)
3838 throws SystemException {
3839 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId,
3840 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3841 remove(mbCategory);
3842 }
3843 }
3844
3845
3853 public int countByG_P(long groupId, long parentCategoryId)
3854 throws SystemException {
3855 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
3856
3857 Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3858
3859 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3860 this);
3861
3862 if (count == null) {
3863 StringBundler query = new StringBundler(3);
3864
3865 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3866
3867 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3868
3869 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3870
3871 String sql = query.toString();
3872
3873 Session session = null;
3874
3875 try {
3876 session = openSession();
3877
3878 Query q = session.createQuery(sql);
3879
3880 QueryPos qPos = QueryPos.getInstance(q);
3881
3882 qPos.add(groupId);
3883
3884 qPos.add(parentCategoryId);
3885
3886 count = (Long)q.uniqueResult();
3887
3888 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3889 }
3890 catch (Exception e) {
3891 FinderCacheUtil.removeResult(finderPath, finderArgs);
3892
3893 throw processException(e);
3894 }
3895 finally {
3896 closeSession(session);
3897 }
3898 }
3899
3900 return count.intValue();
3901 }
3902
3903
3911 public int countByG_P(long groupId, long[] parentCategoryIds)
3912 throws SystemException {
3913 Object[] finderArgs = new Object[] {
3914 groupId, StringUtil.merge(parentCategoryIds)
3915 };
3916
3917 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3918 finderArgs, this);
3919
3920 if (count == null) {
3921 StringBundler query = new StringBundler();
3922
3923 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3924
3925 boolean conjunctionable = false;
3926
3927 if (conjunctionable) {
3928 query.append(WHERE_AND);
3929 }
3930
3931 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3932
3933 conjunctionable = true;
3934
3935 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3936 if (conjunctionable) {
3937 query.append(WHERE_AND);
3938 }
3939
3940 query.append(StringPool.OPEN_PARENTHESIS);
3941
3942 for (int i = 0; i < parentCategoryIds.length; i++) {
3943 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3944
3945 if ((i + 1) < parentCategoryIds.length) {
3946 query.append(WHERE_OR);
3947 }
3948 }
3949
3950 query.append(StringPool.CLOSE_PARENTHESIS);
3951
3952 conjunctionable = true;
3953 }
3954
3955 String sql = query.toString();
3956
3957 Session session = null;
3958
3959 try {
3960 session = openSession();
3961
3962 Query q = session.createQuery(sql);
3963
3964 QueryPos qPos = QueryPos.getInstance(q);
3965
3966 qPos.add(groupId);
3967
3968 if (parentCategoryIds != null) {
3969 qPos.add(parentCategoryIds);
3970 }
3971
3972 count = (Long)q.uniqueResult();
3973
3974 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3975 finderArgs, count);
3976 }
3977 catch (Exception e) {
3978 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3979 finderArgs);
3980
3981 throw processException(e);
3982 }
3983 finally {
3984 closeSession(session);
3985 }
3986 }
3987
3988 return count.intValue();
3989 }
3990
3991
3999 public int filterCountByG_P(long groupId, long parentCategoryId)
4000 throws SystemException {
4001 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4002 return countByG_P(groupId, parentCategoryId);
4003 }
4004
4005 StringBundler query = new StringBundler(3);
4006
4007 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4008
4009 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4010
4011 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4012
4013 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4014 MBCategory.class.getName(),
4015 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4016
4017 Session session = null;
4018
4019 try {
4020 session = openSession();
4021
4022 SQLQuery q = session.createSQLQuery(sql);
4023
4024 q.addScalar(COUNT_COLUMN_NAME,
4025 com.liferay.portal.kernel.dao.orm.Type.LONG);
4026
4027 QueryPos qPos = QueryPos.getInstance(q);
4028
4029 qPos.add(groupId);
4030
4031 qPos.add(parentCategoryId);
4032
4033 Long count = (Long)q.uniqueResult();
4034
4035 return count.intValue();
4036 }
4037 catch (Exception e) {
4038 throw processException(e);
4039 }
4040 finally {
4041 closeSession(session);
4042 }
4043 }
4044
4045
4053 public int filterCountByG_P(long groupId, long[] parentCategoryIds)
4054 throws SystemException {
4055 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4056 return countByG_P(groupId, parentCategoryIds);
4057 }
4058
4059 StringBundler query = new StringBundler();
4060
4061 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4062
4063 boolean conjunctionable = false;
4064
4065 if (conjunctionable) {
4066 query.append(WHERE_AND);
4067 }
4068
4069 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
4070
4071 conjunctionable = true;
4072
4073 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
4074 if (conjunctionable) {
4075 query.append(WHERE_AND);
4076 }
4077
4078 query.append(StringPool.OPEN_PARENTHESIS);
4079
4080 for (int i = 0; i < parentCategoryIds.length; i++) {
4081 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
4082
4083 if ((i + 1) < parentCategoryIds.length) {
4084 query.append(WHERE_OR);
4085 }
4086 }
4087
4088 query.append(StringPool.CLOSE_PARENTHESIS);
4089
4090 conjunctionable = true;
4091 }
4092
4093 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4094 MBCategory.class.getName(),
4095 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4096
4097 Session session = null;
4098
4099 try {
4100 session = openSession();
4101
4102 SQLQuery q = session.createSQLQuery(sql);
4103
4104 q.addScalar(COUNT_COLUMN_NAME,
4105 com.liferay.portal.kernel.dao.orm.Type.LONG);
4106
4107 QueryPos qPos = QueryPos.getInstance(q);
4108
4109 qPos.add(groupId);
4110
4111 if (parentCategoryIds != null) {
4112 qPos.add(parentCategoryIds);
4113 }
4114
4115 Long count = (Long)q.uniqueResult();
4116
4117 return count.intValue();
4118 }
4119 catch (Exception e) {
4120 throw processException(e);
4121 }
4122 finally {
4123 closeSession(session);
4124 }
4125 }
4126
4127 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4128 private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
4129 _removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
4130 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4131 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
4132 _removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
4133 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4134 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4135 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4136 new String[] {
4137 Long.class.getName(), Integer.class.getName(),
4138
4139 Integer.class.getName(), Integer.class.getName(),
4140 OrderByComparator.class.getName()
4141 });
4142 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4143 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4144 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4145 new String[] { Long.class.getName(), Integer.class.getName() },
4146 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
4147 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
4148 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4149 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
4150 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4151 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4152 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4153 new String[] { Long.class.getName(), Integer.class.getName() });
4154
4155
4163 public List<MBCategory> findByG_S(long groupId, int status)
4164 throws SystemException {
4165 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4166 null);
4167 }
4168
4169
4183 public List<MBCategory> findByG_S(long groupId, int status, int start,
4184 int end) throws SystemException {
4185 return findByG_S(groupId, status, start, end, null);
4186 }
4187
4188
4203 public List<MBCategory> findByG_S(long groupId, int status, int start,
4204 int end, OrderByComparator orderByComparator) throws SystemException {
4205 boolean pagination = true;
4206 FinderPath finderPath = null;
4207 Object[] finderArgs = null;
4208
4209 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4210 (orderByComparator == null)) {
4211 pagination = false;
4212 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4213 finderArgs = new Object[] { groupId, status };
4214 }
4215 else {
4216 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4217 finderArgs = new Object[] {
4218 groupId, status,
4219
4220 start, end, orderByComparator
4221 };
4222 }
4223
4224 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
4225 finderArgs, this);
4226
4227 if ((list != null) && !list.isEmpty()) {
4228 for (MBCategory mbCategory : list) {
4229 if ((groupId != mbCategory.getGroupId()) ||
4230 (status != mbCategory.getStatus())) {
4231 list = null;
4232
4233 break;
4234 }
4235 }
4236 }
4237
4238 if (list == null) {
4239 StringBundler query = null;
4240
4241 if (orderByComparator != null) {
4242 query = new StringBundler(4 +
4243 (orderByComparator.getOrderByFields().length * 3));
4244 }
4245 else {
4246 query = new StringBundler(4);
4247 }
4248
4249 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4250
4251 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4252
4253 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4254
4255 if (orderByComparator != null) {
4256 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4257 orderByComparator);
4258 }
4259 else
4260 if (pagination) {
4261 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4262 }
4263
4264 String sql = query.toString();
4265
4266 Session session = null;
4267
4268 try {
4269 session = openSession();
4270
4271 Query q = session.createQuery(sql);
4272
4273 QueryPos qPos = QueryPos.getInstance(q);
4274
4275 qPos.add(groupId);
4276
4277 qPos.add(status);
4278
4279 if (!pagination) {
4280 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4281 start, end, false);
4282
4283 Collections.sort(list);
4284
4285 list = new UnmodifiableList<MBCategory>(list);
4286 }
4287 else {
4288 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4289 start, end);
4290 }
4291
4292 cacheResult(list);
4293
4294 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4295 }
4296 catch (Exception e) {
4297 FinderCacheUtil.removeResult(finderPath, finderArgs);
4298
4299 throw processException(e);
4300 }
4301 finally {
4302 closeSession(session);
4303 }
4304 }
4305
4306 return list;
4307 }
4308
4309
4319 public MBCategory findByG_S_First(long groupId, int status,
4320 OrderByComparator orderByComparator)
4321 throws NoSuchCategoryException, SystemException {
4322 MBCategory mbCategory = fetchByG_S_First(groupId, status,
4323 orderByComparator);
4324
4325 if (mbCategory != null) {
4326 return mbCategory;
4327 }
4328
4329 StringBundler msg = new StringBundler(6);
4330
4331 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4332
4333 msg.append("groupId=");
4334 msg.append(groupId);
4335
4336 msg.append(", status=");
4337 msg.append(status);
4338
4339 msg.append(StringPool.CLOSE_CURLY_BRACE);
4340
4341 throw new NoSuchCategoryException(msg.toString());
4342 }
4343
4344
4353 public MBCategory fetchByG_S_First(long groupId, int status,
4354 OrderByComparator orderByComparator) throws SystemException {
4355 List<MBCategory> list = findByG_S(groupId, status, 0, 1,
4356 orderByComparator);
4357
4358 if (!list.isEmpty()) {
4359 return list.get(0);
4360 }
4361
4362 return null;
4363 }
4364
4365
4375 public MBCategory findByG_S_Last(long groupId, int status,
4376 OrderByComparator orderByComparator)
4377 throws NoSuchCategoryException, SystemException {
4378 MBCategory mbCategory = fetchByG_S_Last(groupId, status,
4379 orderByComparator);
4380
4381 if (mbCategory != null) {
4382 return mbCategory;
4383 }
4384
4385 StringBundler msg = new StringBundler(6);
4386
4387 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4388
4389 msg.append("groupId=");
4390 msg.append(groupId);
4391
4392 msg.append(", status=");
4393 msg.append(status);
4394
4395 msg.append(StringPool.CLOSE_CURLY_BRACE);
4396
4397 throw new NoSuchCategoryException(msg.toString());
4398 }
4399
4400
4409 public MBCategory fetchByG_S_Last(long groupId, int status,
4410 OrderByComparator orderByComparator) throws SystemException {
4411 int count = countByG_S(groupId, status);
4412
4413 List<MBCategory> list = findByG_S(groupId, status, count - 1, count,
4414 orderByComparator);
4415
4416 if (!list.isEmpty()) {
4417 return list.get(0);
4418 }
4419
4420 return null;
4421 }
4422
4423
4434 public MBCategory[] findByG_S_PrevAndNext(long categoryId, long groupId,
4435 int status, OrderByComparator orderByComparator)
4436 throws NoSuchCategoryException, SystemException {
4437 MBCategory mbCategory = findByPrimaryKey(categoryId);
4438
4439 Session session = null;
4440
4441 try {
4442 session = openSession();
4443
4444 MBCategory[] array = new MBCategoryImpl[3];
4445
4446 array[0] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4447 status, orderByComparator, true);
4448
4449 array[1] = mbCategory;
4450
4451 array[2] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4452 status, orderByComparator, false);
4453
4454 return array;
4455 }
4456 catch (Exception e) {
4457 throw processException(e);
4458 }
4459 finally {
4460 closeSession(session);
4461 }
4462 }
4463
4464 protected MBCategory getByG_S_PrevAndNext(Session session,
4465 MBCategory mbCategory, long groupId, int status,
4466 OrderByComparator orderByComparator, boolean previous) {
4467 StringBundler query = null;
4468
4469 if (orderByComparator != null) {
4470 query = new StringBundler(6 +
4471 (orderByComparator.getOrderByFields().length * 6));
4472 }
4473 else {
4474 query = new StringBundler(3);
4475 }
4476
4477 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4478
4479 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4480
4481 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4482
4483 if (orderByComparator != null) {
4484 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4485
4486 if (orderByConditionFields.length > 0) {
4487 query.append(WHERE_AND);
4488 }
4489
4490 for (int i = 0; i < orderByConditionFields.length; i++) {
4491 query.append(_ORDER_BY_ENTITY_ALIAS);
4492 query.append(orderByConditionFields[i]);
4493
4494 if ((i + 1) < orderByConditionFields.length) {
4495 if (orderByComparator.isAscending() ^ previous) {
4496 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4497 }
4498 else {
4499 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4500 }
4501 }
4502 else {
4503 if (orderByComparator.isAscending() ^ previous) {
4504 query.append(WHERE_GREATER_THAN);
4505 }
4506 else {
4507 query.append(WHERE_LESSER_THAN);
4508 }
4509 }
4510 }
4511
4512 query.append(ORDER_BY_CLAUSE);
4513
4514 String[] orderByFields = orderByComparator.getOrderByFields();
4515
4516 for (int i = 0; i < orderByFields.length; i++) {
4517 query.append(_ORDER_BY_ENTITY_ALIAS);
4518 query.append(orderByFields[i]);
4519
4520 if ((i + 1) < orderByFields.length) {
4521 if (orderByComparator.isAscending() ^ previous) {
4522 query.append(ORDER_BY_ASC_HAS_NEXT);
4523 }
4524 else {
4525 query.append(ORDER_BY_DESC_HAS_NEXT);
4526 }
4527 }
4528 else {
4529 if (orderByComparator.isAscending() ^ previous) {
4530 query.append(ORDER_BY_ASC);
4531 }
4532 else {
4533 query.append(ORDER_BY_DESC);
4534 }
4535 }
4536 }
4537 }
4538 else {
4539 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4540 }
4541
4542 String sql = query.toString();
4543
4544 Query q = session.createQuery(sql);
4545
4546 q.setFirstResult(0);
4547 q.setMaxResults(2);
4548
4549 QueryPos qPos = QueryPos.getInstance(q);
4550
4551 qPos.add(groupId);
4552
4553 qPos.add(status);
4554
4555 if (orderByComparator != null) {
4556 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4557
4558 for (Object value : values) {
4559 qPos.add(value);
4560 }
4561 }
4562
4563 List<MBCategory> list = q.list();
4564
4565 if (list.size() == 2) {
4566 return list.get(1);
4567 }
4568 else {
4569 return null;
4570 }
4571 }
4572
4573
4581 public List<MBCategory> filterFindByG_S(long groupId, int status)
4582 throws SystemException {
4583 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4584 QueryUtil.ALL_POS, null);
4585 }
4586
4587
4601 public List<MBCategory> filterFindByG_S(long groupId, int status,
4602 int start, int end) throws SystemException {
4603 return filterFindByG_S(groupId, status, start, end, null);
4604 }
4605
4606
4621 public List<MBCategory> filterFindByG_S(long groupId, int status,
4622 int start, int end, OrderByComparator orderByComparator)
4623 throws SystemException {
4624 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4625 return findByG_S(groupId, status, start, end, orderByComparator);
4626 }
4627
4628 StringBundler query = null;
4629
4630 if (orderByComparator != null) {
4631 query = new StringBundler(4 +
4632 (orderByComparator.getOrderByFields().length * 3));
4633 }
4634 else {
4635 query = new StringBundler(4);
4636 }
4637
4638 if (getDB().isSupportsInlineDistinct()) {
4639 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4640 }
4641 else {
4642 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4643 }
4644
4645 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4646
4647 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4648
4649 if (!getDB().isSupportsInlineDistinct()) {
4650 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4651 }
4652
4653 if (orderByComparator != null) {
4654 if (getDB().isSupportsInlineDistinct()) {
4655 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4656 orderByComparator);
4657 }
4658 else {
4659 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4660 orderByComparator);
4661 }
4662 }
4663 else {
4664 if (getDB().isSupportsInlineDistinct()) {
4665 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4666 }
4667 else {
4668 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4669 }
4670 }
4671
4672 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4673 MBCategory.class.getName(),
4674 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4675
4676 Session session = null;
4677
4678 try {
4679 session = openSession();
4680
4681 SQLQuery q = session.createSQLQuery(sql);
4682
4683 if (getDB().isSupportsInlineDistinct()) {
4684 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4685 }
4686 else {
4687 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4688 }
4689
4690 QueryPos qPos = QueryPos.getInstance(q);
4691
4692 qPos.add(groupId);
4693
4694 qPos.add(status);
4695
4696 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
4697 }
4698 catch (Exception e) {
4699 throw processException(e);
4700 }
4701 finally {
4702 closeSession(session);
4703 }
4704 }
4705
4706
4717 public MBCategory[] filterFindByG_S_PrevAndNext(long categoryId,
4718 long groupId, int status, OrderByComparator orderByComparator)
4719 throws NoSuchCategoryException, SystemException {
4720 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4721 return findByG_S_PrevAndNext(categoryId, groupId, status,
4722 orderByComparator);
4723 }
4724
4725 MBCategory mbCategory = findByPrimaryKey(categoryId);
4726
4727 Session session = null;
4728
4729 try {
4730 session = openSession();
4731
4732 MBCategory[] array = new MBCategoryImpl[3];
4733
4734 array[0] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4735 status, orderByComparator, true);
4736
4737 array[1] = mbCategory;
4738
4739 array[2] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4740 status, orderByComparator, false);
4741
4742 return array;
4743 }
4744 catch (Exception e) {
4745 throw processException(e);
4746 }
4747 finally {
4748 closeSession(session);
4749 }
4750 }
4751
4752 protected MBCategory filterGetByG_S_PrevAndNext(Session session,
4753 MBCategory mbCategory, long groupId, int status,
4754 OrderByComparator orderByComparator, boolean previous) {
4755 StringBundler query = null;
4756
4757 if (orderByComparator != null) {
4758 query = new StringBundler(6 +
4759 (orderByComparator.getOrderByFields().length * 6));
4760 }
4761 else {
4762 query = new StringBundler(3);
4763 }
4764
4765 if (getDB().isSupportsInlineDistinct()) {
4766 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4767 }
4768 else {
4769 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4770 }
4771
4772 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4773
4774 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4775
4776 if (!getDB().isSupportsInlineDistinct()) {
4777 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4778 }
4779
4780 if (orderByComparator != null) {
4781 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4782
4783 if (orderByConditionFields.length > 0) {
4784 query.append(WHERE_AND);
4785 }
4786
4787 for (int i = 0; i < orderByConditionFields.length; i++) {
4788 if (getDB().isSupportsInlineDistinct()) {
4789 query.append(_ORDER_BY_ENTITY_ALIAS);
4790 }
4791 else {
4792 query.append(_ORDER_BY_ENTITY_TABLE);
4793 }
4794
4795 query.append(orderByConditionFields[i]);
4796
4797 if ((i + 1) < orderByConditionFields.length) {
4798 if (orderByComparator.isAscending() ^ previous) {
4799 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4800 }
4801 else {
4802 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4803 }
4804 }
4805 else {
4806 if (orderByComparator.isAscending() ^ previous) {
4807 query.append(WHERE_GREATER_THAN);
4808 }
4809 else {
4810 query.append(WHERE_LESSER_THAN);
4811 }
4812 }
4813 }
4814
4815 query.append(ORDER_BY_CLAUSE);
4816
4817 String[] orderByFields = orderByComparator.getOrderByFields();
4818
4819 for (int i = 0; i < orderByFields.length; i++) {
4820 if (getDB().isSupportsInlineDistinct()) {
4821 query.append(_ORDER_BY_ENTITY_ALIAS);
4822 }
4823 else {
4824 query.append(_ORDER_BY_ENTITY_TABLE);
4825 }
4826
4827 query.append(orderByFields[i]);
4828
4829 if ((i + 1) < orderByFields.length) {
4830 if (orderByComparator.isAscending() ^ previous) {
4831 query.append(ORDER_BY_ASC_HAS_NEXT);
4832 }
4833 else {
4834 query.append(ORDER_BY_DESC_HAS_NEXT);
4835 }
4836 }
4837 else {
4838 if (orderByComparator.isAscending() ^ previous) {
4839 query.append(ORDER_BY_ASC);
4840 }
4841 else {
4842 query.append(ORDER_BY_DESC);
4843 }
4844 }
4845 }
4846 }
4847 else {
4848 if (getDB().isSupportsInlineDistinct()) {
4849 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4850 }
4851 else {
4852 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4853 }
4854 }
4855
4856 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4857 MBCategory.class.getName(),
4858 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4859
4860 SQLQuery q = session.createSQLQuery(sql);
4861
4862 q.setFirstResult(0);
4863 q.setMaxResults(2);
4864
4865 if (getDB().isSupportsInlineDistinct()) {
4866 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4867 }
4868 else {
4869 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4870 }
4871
4872 QueryPos qPos = QueryPos.getInstance(q);
4873
4874 qPos.add(groupId);
4875
4876 qPos.add(status);
4877
4878 if (orderByComparator != null) {
4879 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4880
4881 for (Object value : values) {
4882 qPos.add(value);
4883 }
4884 }
4885
4886 List<MBCategory> list = q.list();
4887
4888 if (list.size() == 2) {
4889 return list.get(1);
4890 }
4891 else {
4892 return null;
4893 }
4894 }
4895
4896
4903 public void removeByG_S(long groupId, int status) throws SystemException {
4904 for (MBCategory mbCategory : findByG_S(groupId, status,
4905 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4906 remove(mbCategory);
4907 }
4908 }
4909
4910
4918 public int countByG_S(long groupId, int status) throws SystemException {
4919 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
4920
4921 Object[] finderArgs = new Object[] { groupId, status };
4922
4923 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4924 this);
4925
4926 if (count == null) {
4927 StringBundler query = new StringBundler(3);
4928
4929 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4930
4931 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4932
4933 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4934
4935 String sql = query.toString();
4936
4937 Session session = null;
4938
4939 try {
4940 session = openSession();
4941
4942 Query q = session.createQuery(sql);
4943
4944 QueryPos qPos = QueryPos.getInstance(q);
4945
4946 qPos.add(groupId);
4947
4948 qPos.add(status);
4949
4950 count = (Long)q.uniqueResult();
4951
4952 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4953 }
4954 catch (Exception e) {
4955 FinderCacheUtil.removeResult(finderPath, finderArgs);
4956
4957 throw processException(e);
4958 }
4959 finally {
4960 closeSession(session);
4961 }
4962 }
4963
4964 return count.intValue();
4965 }
4966
4967
4975 public int filterCountByG_S(long groupId, int status)
4976 throws SystemException {
4977 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4978 return countByG_S(groupId, status);
4979 }
4980
4981 StringBundler query = new StringBundler(3);
4982
4983 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4984
4985 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4986
4987 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4988
4989 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4990 MBCategory.class.getName(),
4991 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4992
4993 Session session = null;
4994
4995 try {
4996 session = openSession();
4997
4998 SQLQuery q = session.createSQLQuery(sql);
4999
5000 q.addScalar(COUNT_COLUMN_NAME,
5001 com.liferay.portal.kernel.dao.orm.Type.LONG);
5002
5003 QueryPos qPos = QueryPos.getInstance(q);
5004
5005 qPos.add(groupId);
5006
5007 qPos.add(status);
5008
5009 Long count = (Long)q.uniqueResult();
5010
5011 return count.intValue();
5012 }
5013 catch (Exception e) {
5014 throw processException(e);
5015 }
5016 finally {
5017 closeSession(session);
5018 }
5019 }
5020
5021 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
5022 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbCategory.status = ?";
5023 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5024 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5025 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
5026 new String[] {
5027 Long.class.getName(), Integer.class.getName(),
5028
5029 Integer.class.getName(), Integer.class.getName(),
5030 OrderByComparator.class.getName()
5031 });
5032 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5033 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5034 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
5035 new String[] { Long.class.getName(), Integer.class.getName() },
5036 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
5037 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5038 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5039 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5040 public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5041 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5042 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
5043 new String[] { Long.class.getName(), Integer.class.getName() });
5044
5045
5053 public List<MBCategory> findByC_S(long companyId, int status)
5054 throws SystemException {
5055 return findByC_S(companyId, status, QueryUtil.ALL_POS,
5056 QueryUtil.ALL_POS, null);
5057 }
5058
5059
5073 public List<MBCategory> findByC_S(long companyId, int status, int start,
5074 int end) throws SystemException {
5075 return findByC_S(companyId, status, start, end, null);
5076 }
5077
5078
5093 public List<MBCategory> findByC_S(long companyId, int status, int start,
5094 int end, OrderByComparator orderByComparator) throws SystemException {
5095 boolean pagination = true;
5096 FinderPath finderPath = null;
5097 Object[] finderArgs = null;
5098
5099 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5100 (orderByComparator == null)) {
5101 pagination = false;
5102 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
5103 finderArgs = new Object[] { companyId, status };
5104 }
5105 else {
5106 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
5107 finderArgs = new Object[] {
5108 companyId, status,
5109
5110 start, end, orderByComparator
5111 };
5112 }
5113
5114 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5115 finderArgs, this);
5116
5117 if ((list != null) && !list.isEmpty()) {
5118 for (MBCategory mbCategory : list) {
5119 if ((companyId != mbCategory.getCompanyId()) ||
5120 (status != mbCategory.getStatus())) {
5121 list = null;
5122
5123 break;
5124 }
5125 }
5126 }
5127
5128 if (list == null) {
5129 StringBundler query = null;
5130
5131 if (orderByComparator != null) {
5132 query = new StringBundler(4 +
5133 (orderByComparator.getOrderByFields().length * 3));
5134 }
5135 else {
5136 query = new StringBundler(4);
5137 }
5138
5139 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5140
5141 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5142
5143 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5144
5145 if (orderByComparator != null) {
5146 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5147 orderByComparator);
5148 }
5149 else
5150 if (pagination) {
5151 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5152 }
5153
5154 String sql = query.toString();
5155
5156 Session session = null;
5157
5158 try {
5159 session = openSession();
5160
5161 Query q = session.createQuery(sql);
5162
5163 QueryPos qPos = QueryPos.getInstance(q);
5164
5165 qPos.add(companyId);
5166
5167 qPos.add(status);
5168
5169 if (!pagination) {
5170 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5171 start, end, false);
5172
5173 Collections.sort(list);
5174
5175 list = new UnmodifiableList<MBCategory>(list);
5176 }
5177 else {
5178 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5179 start, end);
5180 }
5181
5182 cacheResult(list);
5183
5184 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5185 }
5186 catch (Exception e) {
5187 FinderCacheUtil.removeResult(finderPath, finderArgs);
5188
5189 throw processException(e);
5190 }
5191 finally {
5192 closeSession(session);
5193 }
5194 }
5195
5196 return list;
5197 }
5198
5199
5209 public MBCategory findByC_S_First(long companyId, int status,
5210 OrderByComparator orderByComparator)
5211 throws NoSuchCategoryException, SystemException {
5212 MBCategory mbCategory = fetchByC_S_First(companyId, status,
5213 orderByComparator);
5214
5215 if (mbCategory != null) {
5216 return mbCategory;
5217 }
5218
5219 StringBundler msg = new StringBundler(6);
5220
5221 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5222
5223 msg.append("companyId=");
5224 msg.append(companyId);
5225
5226 msg.append(", status=");
5227 msg.append(status);
5228
5229 msg.append(StringPool.CLOSE_CURLY_BRACE);
5230
5231 throw new NoSuchCategoryException(msg.toString());
5232 }
5233
5234
5243 public MBCategory fetchByC_S_First(long companyId, int status,
5244 OrderByComparator orderByComparator) throws SystemException {
5245 List<MBCategory> list = findByC_S(companyId, status, 0, 1,
5246 orderByComparator);
5247
5248 if (!list.isEmpty()) {
5249 return list.get(0);
5250 }
5251
5252 return null;
5253 }
5254
5255
5265 public MBCategory findByC_S_Last(long companyId, int status,
5266 OrderByComparator orderByComparator)
5267 throws NoSuchCategoryException, SystemException {
5268 MBCategory mbCategory = fetchByC_S_Last(companyId, status,
5269 orderByComparator);
5270
5271 if (mbCategory != null) {
5272 return mbCategory;
5273 }
5274
5275 StringBundler msg = new StringBundler(6);
5276
5277 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5278
5279 msg.append("companyId=");
5280 msg.append(companyId);
5281
5282 msg.append(", status=");
5283 msg.append(status);
5284
5285 msg.append(StringPool.CLOSE_CURLY_BRACE);
5286
5287 throw new NoSuchCategoryException(msg.toString());
5288 }
5289
5290
5299 public MBCategory fetchByC_S_Last(long companyId, int status,
5300 OrderByComparator orderByComparator) throws SystemException {
5301 int count = countByC_S(companyId, status);
5302
5303 List<MBCategory> list = findByC_S(companyId, status, count - 1, count,
5304 orderByComparator);
5305
5306 if (!list.isEmpty()) {
5307 return list.get(0);
5308 }
5309
5310 return null;
5311 }
5312
5313
5324 public MBCategory[] findByC_S_PrevAndNext(long categoryId, long companyId,
5325 int status, OrderByComparator orderByComparator)
5326 throws NoSuchCategoryException, SystemException {
5327 MBCategory mbCategory = findByPrimaryKey(categoryId);
5328
5329 Session session = null;
5330
5331 try {
5332 session = openSession();
5333
5334 MBCategory[] array = new MBCategoryImpl[3];
5335
5336 array[0] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5337 status, orderByComparator, true);
5338
5339 array[1] = mbCategory;
5340
5341 array[2] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5342 status, orderByComparator, false);
5343
5344 return array;
5345 }
5346 catch (Exception e) {
5347 throw processException(e);
5348 }
5349 finally {
5350 closeSession(session);
5351 }
5352 }
5353
5354 protected MBCategory getByC_S_PrevAndNext(Session session,
5355 MBCategory mbCategory, long companyId, int status,
5356 OrderByComparator orderByComparator, boolean previous) {
5357 StringBundler query = null;
5358
5359 if (orderByComparator != null) {
5360 query = new StringBundler(6 +
5361 (orderByComparator.getOrderByFields().length * 6));
5362 }
5363 else {
5364 query = new StringBundler(3);
5365 }
5366
5367 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5368
5369 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5370
5371 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5372
5373 if (orderByComparator != null) {
5374 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5375
5376 if (orderByConditionFields.length > 0) {
5377 query.append(WHERE_AND);
5378 }
5379
5380 for (int i = 0; i < orderByConditionFields.length; i++) {
5381 query.append(_ORDER_BY_ENTITY_ALIAS);
5382 query.append(orderByConditionFields[i]);
5383
5384 if ((i + 1) < orderByConditionFields.length) {
5385 if (orderByComparator.isAscending() ^ previous) {
5386 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5387 }
5388 else {
5389 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5390 }
5391 }
5392 else {
5393 if (orderByComparator.isAscending() ^ previous) {
5394 query.append(WHERE_GREATER_THAN);
5395 }
5396 else {
5397 query.append(WHERE_LESSER_THAN);
5398 }
5399 }
5400 }
5401
5402 query.append(ORDER_BY_CLAUSE);
5403
5404 String[] orderByFields = orderByComparator.getOrderByFields();
5405
5406 for (int i = 0; i < orderByFields.length; i++) {
5407 query.append(_ORDER_BY_ENTITY_ALIAS);
5408 query.append(orderByFields[i]);
5409
5410 if ((i + 1) < orderByFields.length) {
5411 if (orderByComparator.isAscending() ^ previous) {
5412 query.append(ORDER_BY_ASC_HAS_NEXT);
5413 }
5414 else {
5415 query.append(ORDER_BY_DESC_HAS_NEXT);
5416 }
5417 }
5418 else {
5419 if (orderByComparator.isAscending() ^ previous) {
5420 query.append(ORDER_BY_ASC);
5421 }
5422 else {
5423 query.append(ORDER_BY_DESC);
5424 }
5425 }
5426 }
5427 }
5428 else {
5429 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5430 }
5431
5432 String sql = query.toString();
5433
5434 Query q = session.createQuery(sql);
5435
5436 q.setFirstResult(0);
5437 q.setMaxResults(2);
5438
5439 QueryPos qPos = QueryPos.getInstance(q);
5440
5441 qPos.add(companyId);
5442
5443 qPos.add(status);
5444
5445 if (orderByComparator != null) {
5446 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5447
5448 for (Object value : values) {
5449 qPos.add(value);
5450 }
5451 }
5452
5453 List<MBCategory> list = q.list();
5454
5455 if (list.size() == 2) {
5456 return list.get(1);
5457 }
5458 else {
5459 return null;
5460 }
5461 }
5462
5463
5470 public void removeByC_S(long companyId, int status)
5471 throws SystemException {
5472 for (MBCategory mbCategory : findByC_S(companyId, status,
5473 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5474 remove(mbCategory);
5475 }
5476 }
5477
5478
5486 public int countByC_S(long companyId, int status) throws SystemException {
5487 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
5488
5489 Object[] finderArgs = new Object[] { companyId, status };
5490
5491 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5492 this);
5493
5494 if (count == null) {
5495 StringBundler query = new StringBundler(3);
5496
5497 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5498
5499 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5500
5501 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5502
5503 String sql = query.toString();
5504
5505 Session session = null;
5506
5507 try {
5508 session = openSession();
5509
5510 Query q = session.createQuery(sql);
5511
5512 QueryPos qPos = QueryPos.getInstance(q);
5513
5514 qPos.add(companyId);
5515
5516 qPos.add(status);
5517
5518 count = (Long)q.uniqueResult();
5519
5520 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5521 }
5522 catch (Exception e) {
5523 FinderCacheUtil.removeResult(finderPath, finderArgs);
5524
5525 throw processException(e);
5526 }
5527 finally {
5528 closeSession(session);
5529 }
5530 }
5531
5532 return count.intValue();
5533 }
5534
5535 private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbCategory.companyId = ? AND ";
5536 private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbCategory.status = ?";
5537 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5538 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5539 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_S",
5540 new String[] {
5541 Long.class.getName(), Long.class.getName(),
5542 Integer.class.getName(),
5543
5544 Integer.class.getName(), Integer.class.getName(),
5545 OrderByComparator.class.getName()
5546 });
5547 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5548 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5549 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_S",
5550 new String[] {
5551 Long.class.getName(), Long.class.getName(),
5552 Integer.class.getName()
5553 },
5554 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
5555 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5556 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5557 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5558 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5559 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5560 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
5561 new String[] {
5562 Long.class.getName(), Long.class.getName(),
5563 Integer.class.getName()
5564 });
5565 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5566 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5567 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_S",
5568 new String[] {
5569 Long.class.getName(), Long.class.getName(),
5570 Integer.class.getName()
5571 });
5572
5573
5582 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5583 int status) throws SystemException {
5584 return findByG_P_S(groupId, parentCategoryId, status,
5585 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5586 }
5587
5588
5603 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5604 int status, int start, int end) throws SystemException {
5605 return findByG_P_S(groupId, parentCategoryId, status, start, end, null);
5606 }
5607
5608
5624 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5625 int status, int start, int end, OrderByComparator orderByComparator)
5626 throws SystemException {
5627 boolean pagination = true;
5628 FinderPath finderPath = null;
5629 Object[] finderArgs = null;
5630
5631 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5632 (orderByComparator == null)) {
5633 pagination = false;
5634 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
5635 finderArgs = new Object[] { groupId, parentCategoryId, status };
5636 }
5637 else {
5638 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
5639 finderArgs = new Object[] {
5640 groupId, parentCategoryId, status,
5641
5642 start, end, orderByComparator
5643 };
5644 }
5645
5646 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5647 finderArgs, this);
5648
5649 if ((list != null) && !list.isEmpty()) {
5650 for (MBCategory mbCategory : list) {
5651 if ((groupId != mbCategory.getGroupId()) ||
5652 (parentCategoryId != mbCategory.getParentCategoryId()) ||
5653 (status != mbCategory.getStatus())) {
5654 list = null;
5655
5656 break;
5657 }
5658 }
5659 }
5660
5661 if (list == null) {
5662 StringBundler query = null;
5663
5664 if (orderByComparator != null) {
5665 query = new StringBundler(5 +
5666 (orderByComparator.getOrderByFields().length * 3));
5667 }
5668 else {
5669 query = new StringBundler(5);
5670 }
5671
5672 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5673
5674 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5675
5676 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
5677
5678 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5679
5680 if (orderByComparator != null) {
5681 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5682 orderByComparator);
5683 }
5684 else
5685 if (pagination) {
5686 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5687 }
5688
5689 String sql = query.toString();
5690
5691 Session session = null;
5692
5693 try {
5694 session = openSession();
5695
5696 Query q = session.createQuery(sql);
5697
5698 QueryPos qPos = QueryPos.getInstance(q);
5699
5700 qPos.add(groupId);
5701
5702 qPos.add(parentCategoryId);
5703
5704 qPos.add(status);
5705
5706 if (!pagination) {
5707 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5708 start, end, false);
5709
5710 Collections.sort(list);
5711
5712 list = new UnmodifiableList<MBCategory>(list);
5713 }
5714 else {
5715 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5716 start, end);
5717 }
5718
5719 cacheResult(list);
5720
5721 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5722 }
5723 catch (Exception e) {
5724 FinderCacheUtil.removeResult(finderPath, finderArgs);
5725
5726 throw processException(e);
5727 }
5728 finally {
5729 closeSession(session);
5730 }
5731 }
5732
5733 return list;
5734 }
5735
5736
5747 public MBCategory findByG_P_S_First(long groupId, long parentCategoryId,
5748 int status, OrderByComparator orderByComparator)
5749 throws NoSuchCategoryException, SystemException {
5750 MBCategory mbCategory = fetchByG_P_S_First(groupId, parentCategoryId,
5751 status, orderByComparator);
5752
5753 if (mbCategory != null) {
5754 return mbCategory;
5755 }
5756
5757 StringBundler msg = new StringBundler(8);
5758
5759 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5760
5761 msg.append("groupId=");
5762 msg.append(groupId);
5763
5764 msg.append(", parentCategoryId=");
5765 msg.append(parentCategoryId);
5766
5767 msg.append(", status=");
5768 msg.append(status);
5769
5770 msg.append(StringPool.CLOSE_CURLY_BRACE);
5771
5772 throw new NoSuchCategoryException(msg.toString());
5773 }
5774
5775
5785 public MBCategory fetchByG_P_S_First(long groupId, long parentCategoryId,
5786 int status, OrderByComparator orderByComparator)
5787 throws SystemException {
5788 List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
5789 0, 1, orderByComparator);
5790
5791 if (!list.isEmpty()) {
5792 return list.get(0);
5793 }
5794
5795 return null;
5796 }
5797
5798
5809 public MBCategory findByG_P_S_Last(long groupId, long parentCategoryId,
5810 int status, OrderByComparator orderByComparator)
5811 throws NoSuchCategoryException, SystemException {
5812 MBCategory mbCategory = fetchByG_P_S_Last(groupId, parentCategoryId,
5813 status, orderByComparator);
5814
5815 if (mbCategory != null) {
5816 return mbCategory;
5817 }
5818
5819 StringBundler msg = new StringBundler(8);
5820
5821 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5822
5823 msg.append("groupId=");
5824 msg.append(groupId);
5825
5826 msg.append(", parentCategoryId=");
5827 msg.append(parentCategoryId);
5828
5829 msg.append(", status=");
5830 msg.append(status);
5831
5832 msg.append(StringPool.CLOSE_CURLY_BRACE);
5833
5834 throw new NoSuchCategoryException(msg.toString());
5835 }
5836
5837
5847 public MBCategory fetchByG_P_S_Last(long groupId, long parentCategoryId,
5848 int status, OrderByComparator orderByComparator)
5849 throws SystemException {
5850 int count = countByG_P_S(groupId, parentCategoryId, status);
5851
5852 List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
5853 count - 1, count, orderByComparator);
5854
5855 if (!list.isEmpty()) {
5856 return list.get(0);
5857 }
5858
5859 return null;
5860 }
5861
5862
5874 public MBCategory[] findByG_P_S_PrevAndNext(long categoryId, long groupId,
5875 long parentCategoryId, int status, OrderByComparator orderByComparator)
5876 throws NoSuchCategoryException, SystemException {
5877 MBCategory mbCategory = findByPrimaryKey(categoryId);
5878
5879 Session session = null;
5880
5881 try {
5882 session = openSession();
5883
5884 MBCategory[] array = new MBCategoryImpl[3];
5885
5886 array[0] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
5887 parentCategoryId, status, orderByComparator, true);
5888
5889 array[1] = mbCategory;
5890
5891 array[2] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
5892 parentCategoryId, status, orderByComparator, false);
5893
5894 return array;
5895 }
5896 catch (Exception e) {
5897 throw processException(e);
5898 }
5899 finally {
5900 closeSession(session);
5901 }
5902 }
5903
5904 protected MBCategory getByG_P_S_PrevAndNext(Session session,
5905 MBCategory mbCategory, long groupId, long parentCategoryId, int status,
5906 OrderByComparator orderByComparator, boolean previous) {
5907 StringBundler query = null;
5908
5909 if (orderByComparator != null) {
5910 query = new StringBundler(6 +
5911 (orderByComparator.getOrderByFields().length * 6));
5912 }
5913 else {
5914 query = new StringBundler(3);
5915 }
5916
5917 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5918
5919 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5920
5921 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
5922
5923 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5924
5925 if (orderByComparator != null) {
5926 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5927
5928 if (orderByConditionFields.length > 0) {
5929 query.append(WHERE_AND);
5930 }
5931
5932 for (int i = 0; i < orderByConditionFields.length; i++) {
5933 query.append(_ORDER_BY_ENTITY_ALIAS);
5934 query.append(orderByConditionFields[i]);
5935
5936 if ((i + 1) < orderByConditionFields.length) {
5937 if (orderByComparator.isAscending() ^ previous) {
5938 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5939 }
5940 else {
5941 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5942 }
5943 }
5944 else {
5945 if (orderByComparator.isAscending() ^ previous) {
5946 query.append(WHERE_GREATER_THAN);
5947 }
5948 else {
5949 query.append(WHERE_LESSER_THAN);
5950 }
5951 }
5952 }
5953
5954 query.append(ORDER_BY_CLAUSE);
5955
5956 String[] orderByFields = orderByComparator.getOrderByFields();
5957
5958 for (int i = 0; i < orderByFields.length; i++) {
5959 query.append(_ORDER_BY_ENTITY_ALIAS);
5960 query.append(orderByFields[i]);
5961
5962 if ((i + 1) < orderByFields.length) {
5963 if (orderByComparator.isAscending() ^ previous) {
5964 query.append(ORDER_BY_ASC_HAS_NEXT);
5965 }
5966 else {
5967 query.append(ORDER_BY_DESC_HAS_NEXT);
5968 }
5969 }
5970 else {
5971 if (orderByComparator.isAscending() ^ previous) {
5972 query.append(ORDER_BY_ASC);
5973 }
5974 else {
5975 query.append(ORDER_BY_DESC);
5976 }
5977 }
5978 }
5979 }
5980 else {
5981 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5982 }
5983
5984 String sql = query.toString();
5985
5986 Query q = session.createQuery(sql);
5987
5988 q.setFirstResult(0);
5989 q.setMaxResults(2);
5990
5991 QueryPos qPos = QueryPos.getInstance(q);
5992
5993 qPos.add(groupId);
5994
5995 qPos.add(parentCategoryId);
5996
5997 qPos.add(status);
5998
5999 if (orderByComparator != null) {
6000 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
6001
6002 for (Object value : values) {
6003 qPos.add(value);
6004 }
6005 }
6006
6007 List<MBCategory> list = q.list();
6008
6009 if (list.size() == 2) {
6010 return list.get(1);
6011 }
6012 else {
6013 return null;
6014 }
6015 }
6016
6017
6026 public List<MBCategory> filterFindByG_P_S(long groupId,
6027 long parentCategoryId, int status) throws SystemException {
6028 return filterFindByG_P_S(groupId, parentCategoryId, status,
6029 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6030 }
6031
6032
6047 public List<MBCategory> filterFindByG_P_S(long groupId,
6048 long parentCategoryId, int status, int start, int end)
6049 throws SystemException {
6050 return filterFindByG_P_S(groupId, parentCategoryId, status, start, end,
6051 null);
6052 }
6053
6054
6070 public List<MBCategory> filterFindByG_P_S(long groupId,
6071 long parentCategoryId, int status, int start, int end,
6072 OrderByComparator orderByComparator) throws SystemException {
6073 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6074 return findByG_P_S(groupId, parentCategoryId, status, start, end,
6075 orderByComparator);
6076 }
6077
6078 StringBundler query = null;
6079
6080 if (orderByComparator != null) {
6081 query = new StringBundler(5 +
6082 (orderByComparator.getOrderByFields().length * 3));
6083 }
6084 else {
6085 query = new StringBundler(5);
6086 }
6087
6088 if (getDB().isSupportsInlineDistinct()) {
6089 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6090 }
6091 else {
6092 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6093 }
6094
6095 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6096
6097 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6098
6099 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6100
6101 if (!getDB().isSupportsInlineDistinct()) {
6102 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6103 }
6104
6105 if (orderByComparator != null) {
6106 if (getDB().isSupportsInlineDistinct()) {
6107 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6108 orderByComparator);
6109 }
6110 else {
6111 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6112 orderByComparator);
6113 }
6114 }
6115 else {
6116 if (getDB().isSupportsInlineDistinct()) {
6117 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6118 }
6119 else {
6120 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6121 }
6122 }
6123
6124 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6125 MBCategory.class.getName(),
6126 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6127
6128 Session session = null;
6129
6130 try {
6131 session = openSession();
6132
6133 SQLQuery q = session.createSQLQuery(sql);
6134
6135 if (getDB().isSupportsInlineDistinct()) {
6136 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6137 }
6138 else {
6139 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6140 }
6141
6142 QueryPos qPos = QueryPos.getInstance(q);
6143
6144 qPos.add(groupId);
6145
6146 qPos.add(parentCategoryId);
6147
6148 qPos.add(status);
6149
6150 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6151 }
6152 catch (Exception e) {
6153 throw processException(e);
6154 }
6155 finally {
6156 closeSession(session);
6157 }
6158 }
6159
6160
6172 public MBCategory[] filterFindByG_P_S_PrevAndNext(long categoryId,
6173 long groupId, long parentCategoryId, int status,
6174 OrderByComparator orderByComparator)
6175 throws NoSuchCategoryException, SystemException {
6176 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6177 return findByG_P_S_PrevAndNext(categoryId, groupId,
6178 parentCategoryId, status, orderByComparator);
6179 }
6180
6181 MBCategory mbCategory = findByPrimaryKey(categoryId);
6182
6183 Session session = null;
6184
6185 try {
6186 session = openSession();
6187
6188 MBCategory[] array = new MBCategoryImpl[3];
6189
6190 array[0] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
6191 groupId, parentCategoryId, status, orderByComparator, true);
6192
6193 array[1] = mbCategory;
6194
6195 array[2] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
6196 groupId, parentCategoryId, status, orderByComparator, false);
6197
6198 return array;
6199 }
6200 catch (Exception e) {
6201 throw processException(e);
6202 }
6203 finally {
6204 closeSession(session);
6205 }
6206 }
6207
6208 protected MBCategory filterGetByG_P_S_PrevAndNext(Session session,
6209 MBCategory mbCategory, long groupId, long parentCategoryId, int status,
6210 OrderByComparator orderByComparator, boolean previous) {
6211 StringBundler query = null;
6212
6213 if (orderByComparator != null) {
6214 query = new StringBundler(6 +
6215 (orderByComparator.getOrderByFields().length * 6));
6216 }
6217 else {
6218 query = new StringBundler(3);
6219 }
6220
6221 if (getDB().isSupportsInlineDistinct()) {
6222 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6223 }
6224 else {
6225 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6226 }
6227
6228 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6229
6230 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6231
6232 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6233
6234 if (!getDB().isSupportsInlineDistinct()) {
6235 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6236 }
6237
6238 if (orderByComparator != null) {
6239 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6240
6241 if (orderByConditionFields.length > 0) {
6242 query.append(WHERE_AND);
6243 }
6244
6245 for (int i = 0; i < orderByConditionFields.length; i++) {
6246 if (getDB().isSupportsInlineDistinct()) {
6247 query.append(_ORDER_BY_ENTITY_ALIAS);
6248 }
6249 else {
6250 query.append(_ORDER_BY_ENTITY_TABLE);
6251 }
6252
6253 query.append(orderByConditionFields[i]);
6254
6255 if ((i + 1) < orderByConditionFields.length) {
6256 if (orderByComparator.isAscending() ^ previous) {
6257 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6258 }
6259 else {
6260 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6261 }
6262 }
6263 else {
6264 if (orderByComparator.isAscending() ^ previous) {
6265 query.append(WHERE_GREATER_THAN);
6266 }
6267 else {
6268 query.append(WHERE_LESSER_THAN);
6269 }
6270 }
6271 }
6272
6273 query.append(ORDER_BY_CLAUSE);
6274
6275 String[] orderByFields = orderByComparator.getOrderByFields();
6276
6277 for (int i = 0; i < orderByFields.length; i++) {
6278 if (getDB().isSupportsInlineDistinct()) {
6279 query.append(_ORDER_BY_ENTITY_ALIAS);
6280 }
6281 else {
6282 query.append(_ORDER_BY_ENTITY_TABLE);
6283 }
6284
6285 query.append(orderByFields[i]);
6286
6287 if ((i + 1) < orderByFields.length) {
6288 if (orderByComparator.isAscending() ^ previous) {
6289 query.append(ORDER_BY_ASC_HAS_NEXT);
6290 }
6291 else {
6292 query.append(ORDER_BY_DESC_HAS_NEXT);
6293 }
6294 }
6295 else {
6296 if (orderByComparator.isAscending() ^ previous) {
6297 query.append(ORDER_BY_ASC);
6298 }
6299 else {
6300 query.append(ORDER_BY_DESC);
6301 }
6302 }
6303 }
6304 }
6305 else {
6306 if (getDB().isSupportsInlineDistinct()) {
6307 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6308 }
6309 else {
6310 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6311 }
6312 }
6313
6314 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6315 MBCategory.class.getName(),
6316 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6317
6318 SQLQuery q = session.createSQLQuery(sql);
6319
6320 q.setFirstResult(0);
6321 q.setMaxResults(2);
6322
6323 if (getDB().isSupportsInlineDistinct()) {
6324 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6325 }
6326 else {
6327 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6328 }
6329
6330 QueryPos qPos = QueryPos.getInstance(q);
6331
6332 qPos.add(groupId);
6333
6334 qPos.add(parentCategoryId);
6335
6336 qPos.add(status);
6337
6338 if (orderByComparator != null) {
6339 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
6340
6341 for (Object value : values) {
6342 qPos.add(value);
6343 }
6344 }
6345
6346 List<MBCategory> list = q.list();
6347
6348 if (list.size() == 2) {
6349 return list.get(1);
6350 }
6351 else {
6352 return null;
6353 }
6354 }
6355
6356
6365 public List<MBCategory> filterFindByG_P_S(long groupId,
6366 long[] parentCategoryIds, int status) throws SystemException {
6367 return filterFindByG_P_S(groupId, parentCategoryIds, status,
6368 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6369 }
6370
6371
6386 public List<MBCategory> filterFindByG_P_S(long groupId,
6387 long[] parentCategoryIds, int status, int start, int end)
6388 throws SystemException {
6389 return filterFindByG_P_S(groupId, parentCategoryIds, status, start,
6390 end, null);
6391 }
6392
6393
6409 public List<MBCategory> filterFindByG_P_S(long groupId,
6410 long[] parentCategoryIds, int status, int start, int end,
6411 OrderByComparator orderByComparator) throws SystemException {
6412 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6413 return findByG_P_S(groupId, parentCategoryIds, status, start, end,
6414 orderByComparator);
6415 }
6416
6417 StringBundler query = new StringBundler();
6418
6419 if (getDB().isSupportsInlineDistinct()) {
6420 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6421 }
6422 else {
6423 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6424 }
6425
6426 boolean conjunctionable = false;
6427
6428 if (conjunctionable) {
6429 query.append(WHERE_AND);
6430 }
6431
6432 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6433
6434 conjunctionable = true;
6435
6436 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6437 if (conjunctionable) {
6438 query.append(WHERE_AND);
6439 }
6440
6441 query.append(StringPool.OPEN_PARENTHESIS);
6442
6443 for (int i = 0; i < parentCategoryIds.length; i++) {
6444 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6445
6446 if ((i + 1) < parentCategoryIds.length) {
6447 query.append(WHERE_OR);
6448 }
6449 }
6450
6451 query.append(StringPool.CLOSE_PARENTHESIS);
6452
6453 conjunctionable = true;
6454 }
6455
6456 if (conjunctionable) {
6457 query.append(WHERE_AND);
6458 }
6459
6460 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6461
6462 conjunctionable = true;
6463
6464 if (!getDB().isSupportsInlineDistinct()) {
6465 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6466 }
6467
6468 if (orderByComparator != null) {
6469 if (getDB().isSupportsInlineDistinct()) {
6470 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6471 orderByComparator);
6472 }
6473 else {
6474 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6475 orderByComparator);
6476 }
6477 }
6478 else {
6479 if (getDB().isSupportsInlineDistinct()) {
6480 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6481 }
6482 else {
6483 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6484 }
6485 }
6486
6487 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6488 MBCategory.class.getName(),
6489 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6490
6491 Session session = null;
6492
6493 try {
6494 session = openSession();
6495
6496 SQLQuery q = session.createSQLQuery(sql);
6497
6498 if (getDB().isSupportsInlineDistinct()) {
6499 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6500 }
6501 else {
6502 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6503 }
6504
6505 QueryPos qPos = QueryPos.getInstance(q);
6506
6507 qPos.add(groupId);
6508
6509 if (parentCategoryIds != null) {
6510 qPos.add(parentCategoryIds);
6511 }
6512
6513 qPos.add(status);
6514
6515 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6516 }
6517 catch (Exception e) {
6518 throw processException(e);
6519 }
6520 finally {
6521 closeSession(session);
6522 }
6523 }
6524
6525
6538 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6539 int status) throws SystemException {
6540 return findByG_P_S(groupId, parentCategoryIds, status,
6541 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6542 }
6543
6544
6559 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6560 int status, int start, int end) throws SystemException {
6561 return findByG_P_S(groupId, parentCategoryIds, status, start, end, null);
6562 }
6563
6564
6580 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6581 int status, int start, int end, OrderByComparator orderByComparator)
6582 throws SystemException {
6583 if ((parentCategoryIds != null) && (parentCategoryIds.length == 1)) {
6584 return findByG_P_S(groupId, parentCategoryIds[0], status, start,
6585 end, orderByComparator);
6586 }
6587
6588 boolean pagination = true;
6589 Object[] finderArgs = null;
6590
6591 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6592 (orderByComparator == null)) {
6593 pagination = false;
6594 finderArgs = new Object[] {
6595 groupId, StringUtil.merge(parentCategoryIds), status
6596 };
6597 }
6598 else {
6599 finderArgs = new Object[] {
6600 groupId, StringUtil.merge(parentCategoryIds), status,
6601
6602 start, end, orderByComparator
6603 };
6604 }
6605
6606 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6607 finderArgs, this);
6608
6609 if ((list != null) && !list.isEmpty()) {
6610 for (MBCategory mbCategory : list) {
6611 if ((groupId != mbCategory.getGroupId()) ||
6612 !ArrayUtil.contains(parentCategoryIds,
6613 mbCategory.getParentCategoryId()) ||
6614 (status != mbCategory.getStatus())) {
6615 list = null;
6616
6617 break;
6618 }
6619 }
6620 }
6621
6622 if (list == null) {
6623 StringBundler query = new StringBundler();
6624
6625 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6626
6627 boolean conjunctionable = false;
6628
6629 if (conjunctionable) {
6630 query.append(WHERE_AND);
6631 }
6632
6633 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6634
6635 conjunctionable = true;
6636
6637 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6638 if (conjunctionable) {
6639 query.append(WHERE_AND);
6640 }
6641
6642 query.append(StringPool.OPEN_PARENTHESIS);
6643
6644 for (int i = 0; i < parentCategoryIds.length; i++) {
6645 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6646
6647 if ((i + 1) < parentCategoryIds.length) {
6648 query.append(WHERE_OR);
6649 }
6650 }
6651
6652 query.append(StringPool.CLOSE_PARENTHESIS);
6653
6654 conjunctionable = true;
6655 }
6656
6657 if (conjunctionable) {
6658 query.append(WHERE_AND);
6659 }
6660
6661 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6662
6663 conjunctionable = true;
6664
6665 if (orderByComparator != null) {
6666 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6667 orderByComparator);
6668 }
6669 else
6670 if (pagination) {
6671 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6672 }
6673
6674 String sql = query.toString();
6675
6676 Session session = null;
6677
6678 try {
6679 session = openSession();
6680
6681 Query q = session.createQuery(sql);
6682
6683 QueryPos qPos = QueryPos.getInstance(q);
6684
6685 qPos.add(groupId);
6686
6687 if (parentCategoryIds != null) {
6688 qPos.add(parentCategoryIds);
6689 }
6690
6691 qPos.add(status);
6692
6693 if (!pagination) {
6694 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6695 start, end, false);
6696
6697 Collections.sort(list);
6698
6699 list = new UnmodifiableList<MBCategory>(list);
6700 }
6701 else {
6702 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6703 start, end);
6704 }
6705
6706 cacheResult(list);
6707
6708 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6709 finderArgs, list);
6710 }
6711 catch (Exception e) {
6712 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6713 finderArgs);
6714
6715 throw processException(e);
6716 }
6717 finally {
6718 closeSession(session);
6719 }
6720 }
6721
6722 return list;
6723 }
6724
6725
6733 public void removeByG_P_S(long groupId, long parentCategoryId, int status)
6734 throws SystemException {
6735 for (MBCategory mbCategory : findByG_P_S(groupId, parentCategoryId,
6736 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6737 remove(mbCategory);
6738 }
6739 }
6740
6741
6750 public int countByG_P_S(long groupId, long parentCategoryId, int status)
6751 throws SystemException {
6752 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
6753
6754 Object[] finderArgs = new Object[] { groupId, parentCategoryId, status };
6755
6756 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6757 this);
6758
6759 if (count == null) {
6760 StringBundler query = new StringBundler(4);
6761
6762 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6763
6764 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6765
6766 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6767
6768 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6769
6770 String sql = query.toString();
6771
6772 Session session = null;
6773
6774 try {
6775 session = openSession();
6776
6777 Query q = session.createQuery(sql);
6778
6779 QueryPos qPos = QueryPos.getInstance(q);
6780
6781 qPos.add(groupId);
6782
6783 qPos.add(parentCategoryId);
6784
6785 qPos.add(status);
6786
6787 count = (Long)q.uniqueResult();
6788
6789 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6790 }
6791 catch (Exception e) {
6792 FinderCacheUtil.removeResult(finderPath, finderArgs);
6793
6794 throw processException(e);
6795 }
6796 finally {
6797 closeSession(session);
6798 }
6799 }
6800
6801 return count.intValue();
6802 }
6803
6804
6813 public int countByG_P_S(long groupId, long[] parentCategoryIds, int status)
6814 throws SystemException {
6815 Object[] finderArgs = new Object[] {
6816 groupId, StringUtil.merge(parentCategoryIds), status
6817 };
6818
6819 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6820 finderArgs, this);
6821
6822 if (count == null) {
6823 StringBundler query = new StringBundler();
6824
6825 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6826
6827 boolean conjunctionable = false;
6828
6829 if (conjunctionable) {
6830 query.append(WHERE_AND);
6831 }
6832
6833 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6834
6835 conjunctionable = true;
6836
6837 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6838 if (conjunctionable) {
6839 query.append(WHERE_AND);
6840 }
6841
6842 query.append(StringPool.OPEN_PARENTHESIS);
6843
6844 for (int i = 0; i < parentCategoryIds.length; i++) {
6845 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6846
6847 if ((i + 1) < parentCategoryIds.length) {
6848 query.append(WHERE_OR);
6849 }
6850 }
6851
6852 query.append(StringPool.CLOSE_PARENTHESIS);
6853
6854 conjunctionable = true;
6855 }
6856
6857 if (conjunctionable) {
6858 query.append(WHERE_AND);
6859 }
6860
6861 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6862
6863 conjunctionable = true;
6864
6865 String sql = query.toString();
6866
6867 Session session = null;
6868
6869 try {
6870 session = openSession();
6871
6872 Query q = session.createQuery(sql);
6873
6874 QueryPos qPos = QueryPos.getInstance(q);
6875
6876 qPos.add(groupId);
6877
6878 if (parentCategoryIds != null) {
6879 qPos.add(parentCategoryIds);
6880 }
6881
6882 qPos.add(status);
6883
6884 count = (Long)q.uniqueResult();
6885
6886 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6887 finderArgs, count);
6888 }
6889 catch (Exception e) {
6890 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6891 finderArgs);
6892
6893 throw processException(e);
6894 }
6895 finally {
6896 closeSession(session);
6897 }
6898 }
6899
6900 return count.intValue();
6901 }
6902
6903
6912 public int filterCountByG_P_S(long groupId, long parentCategoryId,
6913 int status) throws SystemException {
6914 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6915 return countByG_P_S(groupId, parentCategoryId, status);
6916 }
6917
6918 StringBundler query = new StringBundler(4);
6919
6920 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6921
6922 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6923
6924 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6925
6926 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6927
6928 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6929 MBCategory.class.getName(),
6930 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6931
6932 Session session = null;
6933
6934 try {
6935 session = openSession();
6936
6937 SQLQuery q = session.createSQLQuery(sql);
6938
6939 q.addScalar(COUNT_COLUMN_NAME,
6940 com.liferay.portal.kernel.dao.orm.Type.LONG);
6941
6942 QueryPos qPos = QueryPos.getInstance(q);
6943
6944 qPos.add(groupId);
6945
6946 qPos.add(parentCategoryId);
6947
6948 qPos.add(status);
6949
6950 Long count = (Long)q.uniqueResult();
6951
6952 return count.intValue();
6953 }
6954 catch (Exception e) {
6955 throw processException(e);
6956 }
6957 finally {
6958 closeSession(session);
6959 }
6960 }
6961
6962
6971 public int filterCountByG_P_S(long groupId, long[] parentCategoryIds,
6972 int status) throws SystemException {
6973 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6974 return countByG_P_S(groupId, parentCategoryIds, status);
6975 }
6976
6977 StringBundler query = new StringBundler();
6978
6979 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6980
6981 boolean conjunctionable = false;
6982
6983 if (conjunctionable) {
6984 query.append(WHERE_AND);
6985 }
6986
6987 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6988
6989 conjunctionable = true;
6990
6991 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6992 if (conjunctionable) {
6993 query.append(WHERE_AND);
6994 }
6995
6996 query.append(StringPool.OPEN_PARENTHESIS);
6997
6998 for (int i = 0; i < parentCategoryIds.length; i++) {
6999 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
7000
7001 if ((i + 1) < parentCategoryIds.length) {
7002 query.append(WHERE_OR);
7003 }
7004 }
7005
7006 query.append(StringPool.CLOSE_PARENTHESIS);
7007
7008 conjunctionable = true;
7009 }
7010
7011 if (conjunctionable) {
7012 query.append(WHERE_AND);
7013 }
7014
7015 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
7016
7017 conjunctionable = true;
7018
7019 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7020 MBCategory.class.getName(),
7021 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7022
7023 Session session = null;
7024
7025 try {
7026 session = openSession();
7027
7028 SQLQuery q = session.createSQLQuery(sql);
7029
7030 q.addScalar(COUNT_COLUMN_NAME,
7031 com.liferay.portal.kernel.dao.orm.Type.LONG);
7032
7033 QueryPos qPos = QueryPos.getInstance(q);
7034
7035 qPos.add(groupId);
7036
7037 if (parentCategoryIds != null) {
7038 qPos.add(parentCategoryIds);
7039 }
7040
7041 qPos.add(status);
7042
7043 Long count = (Long)q.uniqueResult();
7044
7045 return count.intValue();
7046 }
7047 catch (Exception e) {
7048 throw processException(e);
7049 }
7050 finally {
7051 closeSession(session);
7052 }
7053 }
7054
7055 private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
7056 private static final String _FINDER_COLUMN_G_P_S_GROUPID_5 = "(" +
7057 _removeConjunction(_FINDER_COLUMN_G_P_S_GROUPID_2) + ")";
7058 private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
7059 private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5 = "(" +
7060 _removeConjunction(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2) + ")";
7061 private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "mbCategory.status = ?";
7062 private static final String _FINDER_COLUMN_G_P_S_STATUS_5 = "(" +
7063 _removeConjunction(_FINDER_COLUMN_G_P_S_STATUS_2) + ")";
7064
7065
7070 public void cacheResult(MBCategory mbCategory) {
7071 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7072 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
7073
7074 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7075 new Object[] {
7076 mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
7077 }, mbCategory);
7078
7079 mbCategory.resetOriginalValues();
7080 }
7081
7082
7087 public void cacheResult(List<MBCategory> mbCategories) {
7088 for (MBCategory mbCategory : mbCategories) {
7089 if (EntityCacheUtil.getResult(
7090 MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7091 MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
7092 cacheResult(mbCategory);
7093 }
7094 else {
7095 mbCategory.resetOriginalValues();
7096 }
7097 }
7098 }
7099
7100
7107 @Override
7108 public void clearCache() {
7109 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7110 CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
7111 }
7112
7113 EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
7114
7115 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7116 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7117 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7118 }
7119
7120
7127 @Override
7128 public void clearCache(MBCategory mbCategory) {
7129 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7130 MBCategoryImpl.class, mbCategory.getPrimaryKey());
7131
7132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7133 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7134
7135 clearUniqueFindersCache(mbCategory);
7136 }
7137
7138 @Override
7139 public void clearCache(List<MBCategory> mbCategories) {
7140 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7141 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7142
7143 for (MBCategory mbCategory : mbCategories) {
7144 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7145 MBCategoryImpl.class, mbCategory.getPrimaryKey());
7146
7147 clearUniqueFindersCache(mbCategory);
7148 }
7149 }
7150
7151 protected void cacheUniqueFindersCache(MBCategory mbCategory) {
7152 if (mbCategory.isNew()) {
7153 Object[] args = new Object[] {
7154 mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
7155 };
7156
7157 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7158 Long.valueOf(1));
7159 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7160 mbCategory);
7161 }
7162 else {
7163 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7164
7165 if ((mbCategoryModelImpl.getColumnBitmask() &
7166 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7167 Object[] args = new Object[] {
7168 mbCategory.getUuid(),
7169 Long.valueOf(mbCategory.getGroupId())
7170 };
7171
7172 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7173 Long.valueOf(1));
7174 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7175 mbCategory);
7176 }
7177 }
7178 }
7179
7180 protected void clearUniqueFindersCache(MBCategory mbCategory) {
7181 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7182
7183 Object[] args = new Object[] {
7184 mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
7185 };
7186
7187 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7188 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7189
7190 if ((mbCategoryModelImpl.getColumnBitmask() &
7191 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7192 args = new Object[] {
7193 mbCategoryModelImpl.getOriginalUuid(),
7194 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId())
7195 };
7196
7197 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7198 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7199 }
7200 }
7201
7202
7208 public MBCategory create(long categoryId) {
7209 MBCategory mbCategory = new MBCategoryImpl();
7210
7211 mbCategory.setNew(true);
7212 mbCategory.setPrimaryKey(categoryId);
7213
7214 String uuid = PortalUUIDUtil.generate();
7215
7216 mbCategory.setUuid(uuid);
7217
7218 return mbCategory;
7219 }
7220
7221
7229 public MBCategory remove(long categoryId)
7230 throws NoSuchCategoryException, SystemException {
7231 return remove(Long.valueOf(categoryId));
7232 }
7233
7234
7242 @Override
7243 public MBCategory remove(Serializable primaryKey)
7244 throws NoSuchCategoryException, SystemException {
7245 Session session = null;
7246
7247 try {
7248 session = openSession();
7249
7250 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7251 primaryKey);
7252
7253 if (mbCategory == null) {
7254 if (_log.isWarnEnabled()) {
7255 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7256 }
7257
7258 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7259 primaryKey);
7260 }
7261
7262 return remove(mbCategory);
7263 }
7264 catch (NoSuchCategoryException nsee) {
7265 throw nsee;
7266 }
7267 catch (Exception e) {
7268 throw processException(e);
7269 }
7270 finally {
7271 closeSession(session);
7272 }
7273 }
7274
7275 @Override
7276 protected MBCategory removeImpl(MBCategory mbCategory)
7277 throws SystemException {
7278 mbCategory = toUnwrappedModel(mbCategory);
7279
7280 Session session = null;
7281
7282 try {
7283 session = openSession();
7284
7285 if (!session.contains(mbCategory)) {
7286 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7287 mbCategory.getPrimaryKeyObj());
7288 }
7289
7290 if (mbCategory != null) {
7291 session.delete(mbCategory);
7292 }
7293 }
7294 catch (Exception e) {
7295 throw processException(e);
7296 }
7297 finally {
7298 closeSession(session);
7299 }
7300
7301 if (mbCategory != null) {
7302 clearCache(mbCategory);
7303 }
7304
7305 return mbCategory;
7306 }
7307
7308 @Override
7309 public MBCategory updateImpl(
7310 com.liferay.portlet.messageboards.model.MBCategory mbCategory)
7311 throws SystemException {
7312 mbCategory = toUnwrappedModel(mbCategory);
7313
7314 boolean isNew = mbCategory.isNew();
7315
7316 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7317
7318 if (Validator.isNull(mbCategory.getUuid())) {
7319 String uuid = PortalUUIDUtil.generate();
7320
7321 mbCategory.setUuid(uuid);
7322 }
7323
7324 Session session = null;
7325
7326 try {
7327 session = openSession();
7328
7329 if (mbCategory.isNew()) {
7330 session.save(mbCategory);
7331
7332 mbCategory.setNew(false);
7333 }
7334 else {
7335 session.merge(mbCategory);
7336 }
7337 }
7338 catch (Exception e) {
7339 throw processException(e);
7340 }
7341 finally {
7342 closeSession(session);
7343 }
7344
7345 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7346
7347 if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
7348 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7349 }
7350
7351 else {
7352 if ((mbCategoryModelImpl.getColumnBitmask() &
7353 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7354 Object[] args = new Object[] {
7355 mbCategoryModelImpl.getOriginalUuid()
7356 };
7357
7358 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7359 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7360 args);
7361
7362 args = new Object[] { mbCategoryModelImpl.getUuid() };
7363
7364 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7365 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7366 args);
7367 }
7368
7369 if ((mbCategoryModelImpl.getColumnBitmask() &
7370 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7371 Object[] args = new Object[] {
7372 mbCategoryModelImpl.getOriginalUuid(),
7373 Long.valueOf(mbCategoryModelImpl.getOriginalCompanyId())
7374 };
7375
7376 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7377 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7378 args);
7379
7380 args = new Object[] {
7381 mbCategoryModelImpl.getUuid(),
7382 Long.valueOf(mbCategoryModelImpl.getCompanyId())
7383 };
7384
7385 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7386 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7387 args);
7388 }
7389
7390 if ((mbCategoryModelImpl.getColumnBitmask() &
7391 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7392 Object[] args = new Object[] {
7393 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId())
7394 };
7395
7396 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7397 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7398 args);
7399
7400 args = new Object[] {
7401 Long.valueOf(mbCategoryModelImpl.getGroupId())
7402 };
7403
7404 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7405 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7406 args);
7407 }
7408
7409 if ((mbCategoryModelImpl.getColumnBitmask() &
7410 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7411 Object[] args = new Object[] {
7412 Long.valueOf(mbCategoryModelImpl.getOriginalCompanyId())
7413 };
7414
7415 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7416 args);
7417 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7418 args);
7419
7420 args = new Object[] {
7421 Long.valueOf(mbCategoryModelImpl.getCompanyId())
7422 };
7423
7424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7425 args);
7426 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7427 args);
7428 }
7429
7430 if ((mbCategoryModelImpl.getColumnBitmask() &
7431 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
7432 Object[] args = new Object[] {
7433 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId()),
7434 Long.valueOf(mbCategoryModelImpl.getOriginalParentCategoryId())
7435 };
7436
7437 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7438 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7439 args);
7440
7441 args = new Object[] {
7442 Long.valueOf(mbCategoryModelImpl.getGroupId()),
7443 Long.valueOf(mbCategoryModelImpl.getParentCategoryId())
7444 };
7445
7446 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7447 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7448 args);
7449 }
7450
7451 if ((mbCategoryModelImpl.getColumnBitmask() &
7452 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
7453 Object[] args = new Object[] {
7454 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId()),
7455 Integer.valueOf(mbCategoryModelImpl.getOriginalStatus())
7456 };
7457
7458 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7459 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7460 args);
7461
7462 args = new Object[] {
7463 Long.valueOf(mbCategoryModelImpl.getGroupId()),
7464 Integer.valueOf(mbCategoryModelImpl.getStatus())
7465 };
7466
7467 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7468 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7469 args);
7470 }
7471
7472 if ((mbCategoryModelImpl.getColumnBitmask() &
7473 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
7474 Object[] args = new Object[] {
7475 Long.valueOf(mbCategoryModelImpl.getOriginalCompanyId()),
7476 Integer.valueOf(mbCategoryModelImpl.getOriginalStatus())
7477 };
7478
7479 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7480 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7481 args);
7482
7483 args = new Object[] {
7484 Long.valueOf(mbCategoryModelImpl.getCompanyId()),
7485 Integer.valueOf(mbCategoryModelImpl.getStatus())
7486 };
7487
7488 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7489 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7490 args);
7491 }
7492
7493 if ((mbCategoryModelImpl.getColumnBitmask() &
7494 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
7495 Object[] args = new Object[] {
7496 Long.valueOf(mbCategoryModelImpl.getOriginalGroupId()),
7497 Long.valueOf(mbCategoryModelImpl.getOriginalParentCategoryId()),
7498 Integer.valueOf(mbCategoryModelImpl.getOriginalStatus())
7499 };
7500
7501 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7502 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7503 args);
7504
7505 args = new Object[] {
7506 Long.valueOf(mbCategoryModelImpl.getGroupId()),
7507 Long.valueOf(mbCategoryModelImpl.getParentCategoryId()),
7508 Integer.valueOf(mbCategoryModelImpl.getStatus())
7509 };
7510
7511 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7512 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7513 args);
7514 }
7515 }
7516
7517 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7518 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
7519
7520 clearUniqueFindersCache(mbCategory);
7521 cacheUniqueFindersCache(mbCategory);
7522
7523 return mbCategory;
7524 }
7525
7526 protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
7527 if (mbCategory instanceof MBCategoryImpl) {
7528 return mbCategory;
7529 }
7530
7531 MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
7532
7533 mbCategoryImpl.setNew(mbCategory.isNew());
7534 mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
7535
7536 mbCategoryImpl.setUuid(mbCategory.getUuid());
7537 mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
7538 mbCategoryImpl.setGroupId(mbCategory.getGroupId());
7539 mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
7540 mbCategoryImpl.setUserId(mbCategory.getUserId());
7541 mbCategoryImpl.setUserName(mbCategory.getUserName());
7542 mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
7543 mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
7544 mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
7545 mbCategoryImpl.setName(mbCategory.getName());
7546 mbCategoryImpl.setDescription(mbCategory.getDescription());
7547 mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
7548 mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
7549 mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
7550 mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
7551 mbCategoryImpl.setStatus(mbCategory.getStatus());
7552 mbCategoryImpl.setStatusByUserId(mbCategory.getStatusByUserId());
7553 mbCategoryImpl.setStatusByUserName(mbCategory.getStatusByUserName());
7554 mbCategoryImpl.setStatusDate(mbCategory.getStatusDate());
7555
7556 return mbCategoryImpl;
7557 }
7558
7559
7567 @Override
7568 public MBCategory findByPrimaryKey(Serializable primaryKey)
7569 throws NoSuchModelException, SystemException {
7570 return findByPrimaryKey(((Long)primaryKey).longValue());
7571 }
7572
7573
7581 public MBCategory findByPrimaryKey(long categoryId)
7582 throws NoSuchCategoryException, SystemException {
7583 MBCategory mbCategory = fetchByPrimaryKey(categoryId);
7584
7585 if (mbCategory == null) {
7586 if (_log.isWarnEnabled()) {
7587 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
7588 }
7589
7590 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7591 categoryId);
7592 }
7593
7594 return mbCategory;
7595 }
7596
7597
7604 @Override
7605 public MBCategory fetchByPrimaryKey(Serializable primaryKey)
7606 throws SystemException {
7607 return fetchByPrimaryKey(((Long)primaryKey).longValue());
7608 }
7609
7610
7617 public MBCategory fetchByPrimaryKey(long categoryId)
7618 throws SystemException {
7619 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7620 MBCategoryImpl.class, categoryId);
7621
7622 if (mbCategory == _nullMBCategory) {
7623 return null;
7624 }
7625
7626 if (mbCategory == null) {
7627 Session session = null;
7628
7629 try {
7630 session = openSession();
7631
7632 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7633 Long.valueOf(categoryId));
7634
7635 if (mbCategory != null) {
7636 cacheResult(mbCategory);
7637 }
7638 else {
7639 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7640 MBCategoryImpl.class, categoryId, _nullMBCategory);
7641 }
7642 }
7643 catch (Exception e) {
7644 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7645 MBCategoryImpl.class, categoryId);
7646
7647 throw processException(e);
7648 }
7649 finally {
7650 closeSession(session);
7651 }
7652 }
7653
7654 return mbCategory;
7655 }
7656
7657
7663 public List<MBCategory> findAll() throws SystemException {
7664 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7665 }
7666
7667
7679 public List<MBCategory> findAll(int start, int end)
7680 throws SystemException {
7681 return findAll(start, end, null);
7682 }
7683
7684
7697 public List<MBCategory> findAll(int start, int end,
7698 OrderByComparator orderByComparator) throws SystemException {
7699 boolean pagination = true;
7700 FinderPath finderPath = null;
7701 Object[] finderArgs = null;
7702
7703 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7704 (orderByComparator == null)) {
7705 pagination = false;
7706 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7707 finderArgs = FINDER_ARGS_EMPTY;
7708 }
7709 else {
7710 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7711 finderArgs = new Object[] { start, end, orderByComparator };
7712 }
7713
7714 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
7715 finderArgs, this);
7716
7717 if (list == null) {
7718 StringBundler query = null;
7719 String sql = null;
7720
7721 if (orderByComparator != null) {
7722 query = new StringBundler(2 +
7723 (orderByComparator.getOrderByFields().length * 3));
7724
7725 query.append(_SQL_SELECT_MBCATEGORY);
7726
7727 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7728 orderByComparator);
7729
7730 sql = query.toString();
7731 }
7732 else {
7733 sql = _SQL_SELECT_MBCATEGORY;
7734
7735 if (pagination) {
7736 sql = sql.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
7737 }
7738 }
7739
7740 Session session = null;
7741
7742 try {
7743 session = openSession();
7744
7745 Query q = session.createQuery(sql);
7746
7747 if (!pagination) {
7748 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7749 start, end, false);
7750
7751 Collections.sort(list);
7752
7753 list = new UnmodifiableList<MBCategory>(list);
7754 }
7755 else {
7756 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7757 start, end);
7758 }
7759
7760 cacheResult(list);
7761
7762 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7763 }
7764 catch (Exception e) {
7765 FinderCacheUtil.removeResult(finderPath, finderArgs);
7766
7767 throw processException(e);
7768 }
7769 finally {
7770 closeSession(session);
7771 }
7772 }
7773
7774 return list;
7775 }
7776
7777
7782 public void removeAll() throws SystemException {
7783 for (MBCategory mbCategory : findAll()) {
7784 remove(mbCategory);
7785 }
7786 }
7787
7788
7794 public int countAll() throws SystemException {
7795 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7796 FINDER_ARGS_EMPTY, this);
7797
7798 if (count == null) {
7799 Session session = null;
7800
7801 try {
7802 session = openSession();
7803
7804 Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
7805
7806 count = (Long)q.uniqueResult();
7807
7808 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7809 FINDER_ARGS_EMPTY, count);
7810 }
7811 catch (Exception e) {
7812 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7813 FINDER_ARGS_EMPTY);
7814
7815 throw processException(e);
7816 }
7817 finally {
7818 closeSession(session);
7819 }
7820 }
7821
7822 return count.intValue();
7823 }
7824
7825
7828 public void afterPropertiesSet() {
7829 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7830 com.liferay.portal.util.PropsUtil.get(
7831 "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
7832
7833 if (listenerClassNames.length > 0) {
7834 try {
7835 List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
7836
7837 for (String listenerClassName : listenerClassNames) {
7838 listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
7839 listenerClassName));
7840 }
7841
7842 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7843 }
7844 catch (Exception e) {
7845 _log.error(e);
7846 }
7847 }
7848 }
7849
7850 public void destroy() {
7851 EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
7852 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7853 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7854 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7855 }
7856
7857 private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
7858 private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
7859 private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
7860 private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
7861
7862 private static String _removeConjunction(String sql) {
7863 int pos = sql.indexOf(" AND ");
7864
7865 if (pos != -1) {
7866 sql = sql.substring(0, pos);
7867 }
7868
7869 return sql;
7870 }
7871
7872 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
7873 private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
7874 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
7875 "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
7876 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
7877 ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
7878 private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
7879 private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
7880 private static final String _FILTER_ENTITY_TABLE = "MBCategory";
7881 private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
7882 private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
7883 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
7884 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
7885 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7886 private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
7887 private static MBCategory _nullMBCategory = new MBCategoryImpl() {
7888 @Override
7889 public Object clone() {
7890 return this;
7891 }
7892
7893 @Override
7894 public CacheModel<MBCategory> toCacheModel() {
7895 return _nullMBCategoryCacheModel;
7896 }
7897 };
7898
7899 private static CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
7900 public MBCategory toEntityModel() {
7901 return _nullMBCategory;
7902 }
7903 };
7904 }