001
014
015 package com.liferay.portlet.messageboards.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.SQLQuery;
025 import com.liferay.portal.kernel.dao.orm.Session;
026 import com.liferay.portal.kernel.exception.SystemException;
027 import com.liferay.portal.kernel.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.ArrayUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.SetUtil;
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 import java.util.Set;
056
057
069 public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
070 implements MBCategoryPersistence {
071
076 public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078 ".List1";
079 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List2";
081 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
082 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
083 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
085 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
088 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
089 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
091 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
092 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093 new String[] {
094 String.class.getName(),
095
096 Integer.class.getName(), Integer.class.getName(),
097 OrderByComparator.class.getName()
098 });
099 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
100 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102 new String[] { String.class.getName() },
103 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
104 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
105 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
107 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109 new String[] { String.class.getName() });
110
111
118 public List<MBCategory> findByUuid(String uuid) throws SystemException {
119 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
120 }
121
122
135 public List<MBCategory> findByUuid(String uuid, int start, int end)
136 throws SystemException {
137 return findByUuid(uuid, start, end, null);
138 }
139
140
154 public List<MBCategory> findByUuid(String uuid, int start, int end,
155 OrderByComparator orderByComparator) throws SystemException {
156 boolean pagination = true;
157 FinderPath finderPath = null;
158 Object[] finderArgs = null;
159
160 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
161 (orderByComparator == null)) {
162 pagination = false;
163 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
164 finderArgs = new Object[] { uuid };
165 }
166 else {
167 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid, start, end, orderByComparator };
169 }
170
171 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
172 finderArgs, this);
173
174 if ((list != null) && !list.isEmpty()) {
175 for (MBCategory mbCategory : list) {
176 if (!Validator.equals(uuid, mbCategory.getUuid())) {
177 list = null;
178
179 break;
180 }
181 }
182 }
183
184 if (list == null) {
185 StringBundler query = null;
186
187 if (orderByComparator != null) {
188 query = new StringBundler(3 +
189 (orderByComparator.getOrderByFields().length * 3));
190 }
191 else {
192 query = new StringBundler(3);
193 }
194
195 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
196
197 boolean bindUuid = false;
198
199 if (uuid == null) {
200 query.append(_FINDER_COLUMN_UUID_UUID_1);
201 }
202 else if (uuid.equals(StringPool.BLANK)) {
203 query.append(_FINDER_COLUMN_UUID_UUID_3);
204 }
205 else {
206 bindUuid = true;
207
208 query.append(_FINDER_COLUMN_UUID_UUID_2);
209 }
210
211 if (orderByComparator != null) {
212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
213 orderByComparator);
214 }
215 else
216 if (pagination) {
217 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
218 }
219
220 String sql = query.toString();
221
222 Session session = null;
223
224 try {
225 session = openSession();
226
227 Query q = session.createQuery(sql);
228
229 QueryPos qPos = QueryPos.getInstance(q);
230
231 if (bindUuid) {
232 qPos.add(uuid);
233 }
234
235 if (!pagination) {
236 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
237 start, end, false);
238
239 Collections.sort(list);
240
241 list = new UnmodifiableList<MBCategory>(list);
242 }
243 else {
244 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
245 start, end);
246 }
247
248 cacheResult(list);
249
250 FinderCacheUtil.putResult(finderPath, finderArgs, list);
251 }
252 catch (Exception e) {
253 FinderCacheUtil.removeResult(finderPath, finderArgs);
254
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260 }
261
262 return list;
263 }
264
265
274 public MBCategory findByUuid_First(String uuid,
275 OrderByComparator orderByComparator)
276 throws NoSuchCategoryException, SystemException {
277 MBCategory mbCategory = fetchByUuid_First(uuid, orderByComparator);
278
279 if (mbCategory != null) {
280 return mbCategory;
281 }
282
283 StringBundler msg = new StringBundler(4);
284
285 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
286
287 msg.append("uuid=");
288 msg.append(uuid);
289
290 msg.append(StringPool.CLOSE_CURLY_BRACE);
291
292 throw new NoSuchCategoryException(msg.toString());
293 }
294
295
303 public MBCategory fetchByUuid_First(String uuid,
304 OrderByComparator orderByComparator) throws SystemException {
305 List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
306
307 if (!list.isEmpty()) {
308 return list.get(0);
309 }
310
311 return null;
312 }
313
314
323 public MBCategory findByUuid_Last(String uuid,
324 OrderByComparator orderByComparator)
325 throws NoSuchCategoryException, SystemException {
326 MBCategory mbCategory = fetchByUuid_Last(uuid, orderByComparator);
327
328 if (mbCategory != null) {
329 return mbCategory;
330 }
331
332 StringBundler msg = new StringBundler(4);
333
334 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
335
336 msg.append("uuid=");
337 msg.append(uuid);
338
339 msg.append(StringPool.CLOSE_CURLY_BRACE);
340
341 throw new NoSuchCategoryException(msg.toString());
342 }
343
344
352 public MBCategory fetchByUuid_Last(String uuid,
353 OrderByComparator orderByComparator) throws SystemException {
354 int count = countByUuid(uuid);
355
356 List<MBCategory> list = findByUuid(uuid, count - 1, count,
357 orderByComparator);
358
359 if (!list.isEmpty()) {
360 return list.get(0);
361 }
362
363 return null;
364 }
365
366
376 public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
377 OrderByComparator orderByComparator)
378 throws NoSuchCategoryException, SystemException {
379 MBCategory mbCategory = findByPrimaryKey(categoryId);
380
381 Session session = null;
382
383 try {
384 session = openSession();
385
386 MBCategory[] array = new MBCategoryImpl[3];
387
388 array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
389 orderByComparator, true);
390
391 array[1] = mbCategory;
392
393 array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
394 orderByComparator, false);
395
396 return array;
397 }
398 catch (Exception e) {
399 throw processException(e);
400 }
401 finally {
402 closeSession(session);
403 }
404 }
405
406 protected MBCategory getByUuid_PrevAndNext(Session session,
407 MBCategory mbCategory, String uuid,
408 OrderByComparator orderByComparator, boolean previous) {
409 StringBundler query = null;
410
411 if (orderByComparator != null) {
412 query = new StringBundler(6 +
413 (orderByComparator.getOrderByFields().length * 6));
414 }
415 else {
416 query = new StringBundler(3);
417 }
418
419 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
420
421 boolean bindUuid = false;
422
423 if (uuid == null) {
424 query.append(_FINDER_COLUMN_UUID_UUID_1);
425 }
426 else if (uuid.equals(StringPool.BLANK)) {
427 query.append(_FINDER_COLUMN_UUID_UUID_3);
428 }
429 else {
430 bindUuid = true;
431
432 query.append(_FINDER_COLUMN_UUID_UUID_2);
433 }
434
435 if (orderByComparator != null) {
436 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
437
438 if (orderByConditionFields.length > 0) {
439 query.append(WHERE_AND);
440 }
441
442 for (int i = 0; i < orderByConditionFields.length; i++) {
443 query.append(_ORDER_BY_ENTITY_ALIAS);
444 query.append(orderByConditionFields[i]);
445
446 if ((i + 1) < orderByConditionFields.length) {
447 if (orderByComparator.isAscending() ^ previous) {
448 query.append(WHERE_GREATER_THAN_HAS_NEXT);
449 }
450 else {
451 query.append(WHERE_LESSER_THAN_HAS_NEXT);
452 }
453 }
454 else {
455 if (orderByComparator.isAscending() ^ previous) {
456 query.append(WHERE_GREATER_THAN);
457 }
458 else {
459 query.append(WHERE_LESSER_THAN);
460 }
461 }
462 }
463
464 query.append(ORDER_BY_CLAUSE);
465
466 String[] orderByFields = orderByComparator.getOrderByFields();
467
468 for (int i = 0; i < orderByFields.length; i++) {
469 query.append(_ORDER_BY_ENTITY_ALIAS);
470 query.append(orderByFields[i]);
471
472 if ((i + 1) < orderByFields.length) {
473 if (orderByComparator.isAscending() ^ previous) {
474 query.append(ORDER_BY_ASC_HAS_NEXT);
475 }
476 else {
477 query.append(ORDER_BY_DESC_HAS_NEXT);
478 }
479 }
480 else {
481 if (orderByComparator.isAscending() ^ previous) {
482 query.append(ORDER_BY_ASC);
483 }
484 else {
485 query.append(ORDER_BY_DESC);
486 }
487 }
488 }
489 }
490 else {
491 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
492 }
493
494 String sql = query.toString();
495
496 Query q = session.createQuery(sql);
497
498 q.setFirstResult(0);
499 q.setMaxResults(2);
500
501 QueryPos qPos = QueryPos.getInstance(q);
502
503 if (bindUuid) {
504 qPos.add(uuid);
505 }
506
507 if (orderByComparator != null) {
508 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
509
510 for (Object value : values) {
511 qPos.add(value);
512 }
513 }
514
515 List<MBCategory> list = q.list();
516
517 if (list.size() == 2) {
518 return list.get(1);
519 }
520 else {
521 return null;
522 }
523 }
524
525
531 public void removeByUuid(String uuid) throws SystemException {
532 for (MBCategory mbCategory : findByUuid(uuid, QueryUtil.ALL_POS,
533 QueryUtil.ALL_POS, null)) {
534 remove(mbCategory);
535 }
536 }
537
538
545 public int countByUuid(String uuid) throws SystemException {
546 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
547
548 Object[] finderArgs = new Object[] { uuid };
549
550 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
551 this);
552
553 if (count == null) {
554 StringBundler query = new StringBundler(2);
555
556 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
557
558 boolean bindUuid = false;
559
560 if (uuid == null) {
561 query.append(_FINDER_COLUMN_UUID_UUID_1);
562 }
563 else if (uuid.equals(StringPool.BLANK)) {
564 query.append(_FINDER_COLUMN_UUID_UUID_3);
565 }
566 else {
567 bindUuid = true;
568
569 query.append(_FINDER_COLUMN_UUID_UUID_2);
570 }
571
572 String sql = query.toString();
573
574 Session session = null;
575
576 try {
577 session = openSession();
578
579 Query q = session.createQuery(sql);
580
581 QueryPos qPos = QueryPos.getInstance(q);
582
583 if (bindUuid) {
584 qPos.add(uuid);
585 }
586
587 count = (Long)q.uniqueResult();
588
589 FinderCacheUtil.putResult(finderPath, finderArgs, count);
590 }
591 catch (Exception e) {
592 FinderCacheUtil.removeResult(finderPath, finderArgs);
593
594 throw processException(e);
595 }
596 finally {
597 closeSession(session);
598 }
599 }
600
601 return count.intValue();
602 }
603
604 private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
605 private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
606 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '')";
607 public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
608 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
609 FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
610 new String[] { String.class.getName(), Long.class.getName() },
611 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
612 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
613 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
614 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
615 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
616 new String[] { String.class.getName(), Long.class.getName() });
617
618
627 public MBCategory findByUUID_G(String uuid, long groupId)
628 throws NoSuchCategoryException, SystemException {
629 MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
630
631 if (mbCategory == null) {
632 StringBundler msg = new StringBundler(6);
633
634 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
635
636 msg.append("uuid=");
637 msg.append(uuid);
638
639 msg.append(", groupId=");
640 msg.append(groupId);
641
642 msg.append(StringPool.CLOSE_CURLY_BRACE);
643
644 if (_log.isWarnEnabled()) {
645 _log.warn(msg.toString());
646 }
647
648 throw new NoSuchCategoryException(msg.toString());
649 }
650
651 return mbCategory;
652 }
653
654
662 public MBCategory fetchByUUID_G(String uuid, long groupId)
663 throws SystemException {
664 return fetchByUUID_G(uuid, groupId, true);
665 }
666
667
676 public MBCategory fetchByUUID_G(String uuid, long groupId,
677 boolean retrieveFromCache) throws SystemException {
678 Object[] finderArgs = new Object[] { uuid, groupId };
679
680 Object result = null;
681
682 if (retrieveFromCache) {
683 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
684 finderArgs, this);
685 }
686
687 if (result instanceof MBCategory) {
688 MBCategory mbCategory = (MBCategory)result;
689
690 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
691 (groupId != mbCategory.getGroupId())) {
692 result = null;
693 }
694 }
695
696 if (result == null) {
697 StringBundler query = new StringBundler(4);
698
699 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
700
701 boolean bindUuid = false;
702
703 if (uuid == null) {
704 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
705 }
706 else if (uuid.equals(StringPool.BLANK)) {
707 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
708 }
709 else {
710 bindUuid = true;
711
712 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
713 }
714
715 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
716
717 String sql = query.toString();
718
719 Session session = null;
720
721 try {
722 session = openSession();
723
724 Query q = session.createQuery(sql);
725
726 QueryPos qPos = QueryPos.getInstance(q);
727
728 if (bindUuid) {
729 qPos.add(uuid);
730 }
731
732 qPos.add(groupId);
733
734 List<MBCategory> list = q.list();
735
736 if (list.isEmpty()) {
737 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
738 finderArgs, list);
739 }
740 else {
741 MBCategory mbCategory = list.get(0);
742
743 result = mbCategory;
744
745 cacheResult(mbCategory);
746
747 if ((mbCategory.getUuid() == null) ||
748 !mbCategory.getUuid().equals(uuid) ||
749 (mbCategory.getGroupId() != groupId)) {
750 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
751 finderArgs, mbCategory);
752 }
753 }
754 }
755 catch (Exception e) {
756 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
757 finderArgs);
758
759 throw processException(e);
760 }
761 finally {
762 closeSession(session);
763 }
764 }
765
766 if (result instanceof List<?>) {
767 return null;
768 }
769 else {
770 return (MBCategory)result;
771 }
772 }
773
774
782 public MBCategory removeByUUID_G(String uuid, long groupId)
783 throws NoSuchCategoryException, SystemException {
784 MBCategory mbCategory = findByUUID_G(uuid, groupId);
785
786 return remove(mbCategory);
787 }
788
789
797 public int countByUUID_G(String uuid, long groupId)
798 throws SystemException {
799 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
800
801 Object[] finderArgs = new Object[] { uuid, groupId };
802
803 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
804 this);
805
806 if (count == null) {
807 StringBundler query = new StringBundler(3);
808
809 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
810
811 boolean bindUuid = false;
812
813 if (uuid == null) {
814 query.append(_FINDER_COLUMN_UUID_G_UUID_1);
815 }
816 else if (uuid.equals(StringPool.BLANK)) {
817 query.append(_FINDER_COLUMN_UUID_G_UUID_3);
818 }
819 else {
820 bindUuid = true;
821
822 query.append(_FINDER_COLUMN_UUID_G_UUID_2);
823 }
824
825 query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
826
827 String sql = query.toString();
828
829 Session session = null;
830
831 try {
832 session = openSession();
833
834 Query q = session.createQuery(sql);
835
836 QueryPos qPos = QueryPos.getInstance(q);
837
838 if (bindUuid) {
839 qPos.add(uuid);
840 }
841
842 qPos.add(groupId);
843
844 count = (Long)q.uniqueResult();
845
846 FinderCacheUtil.putResult(finderPath, finderArgs, count);
847 }
848 catch (Exception e) {
849 FinderCacheUtil.removeResult(finderPath, finderArgs);
850
851 throw processException(e);
852 }
853 finally {
854 closeSession(session);
855 }
856 }
857
858 return count.intValue();
859 }
860
861 private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
862 private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
863 private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
864 private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
865 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
866 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
867 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
868 new String[] {
869 String.class.getName(), Long.class.getName(),
870
871 Integer.class.getName(), Integer.class.getName(),
872 OrderByComparator.class.getName()
873 });
874 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
875 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
876 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
877 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
878 new String[] { String.class.getName(), Long.class.getName() },
879 MBCategoryModelImpl.UUID_COLUMN_BITMASK |
880 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
881 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
882 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
883 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
884 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
885 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
886 new String[] { String.class.getName(), Long.class.getName() });
887
888
896 public List<MBCategory> findByUuid_C(String uuid, long companyId)
897 throws SystemException {
898 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
899 QueryUtil.ALL_POS, null);
900 }
901
902
916 public List<MBCategory> findByUuid_C(String uuid, long companyId,
917 int start, int end) throws SystemException {
918 return findByUuid_C(uuid, companyId, start, end, null);
919 }
920
921
936 public List<MBCategory> findByUuid_C(String uuid, long companyId,
937 int start, int end, OrderByComparator orderByComparator)
938 throws SystemException {
939 boolean pagination = true;
940 FinderPath finderPath = null;
941 Object[] finderArgs = null;
942
943 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
944 (orderByComparator == null)) {
945 pagination = false;
946 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
947 finderArgs = new Object[] { uuid, companyId };
948 }
949 else {
950 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
951 finderArgs = new Object[] {
952 uuid, companyId,
953
954 start, end, orderByComparator
955 };
956 }
957
958 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
959 finderArgs, this);
960
961 if ((list != null) && !list.isEmpty()) {
962 for (MBCategory mbCategory : list) {
963 if (!Validator.equals(uuid, mbCategory.getUuid()) ||
964 (companyId != mbCategory.getCompanyId())) {
965 list = null;
966
967 break;
968 }
969 }
970 }
971
972 if (list == null) {
973 StringBundler query = null;
974
975 if (orderByComparator != null) {
976 query = new StringBundler(4 +
977 (orderByComparator.getOrderByFields().length * 3));
978 }
979 else {
980 query = new StringBundler(4);
981 }
982
983 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
984
985 boolean bindUuid = false;
986
987 if (uuid == null) {
988 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
989 }
990 else if (uuid.equals(StringPool.BLANK)) {
991 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
992 }
993 else {
994 bindUuid = true;
995
996 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
997 }
998
999 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1000
1001 if (orderByComparator != null) {
1002 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1003 orderByComparator);
1004 }
1005 else
1006 if (pagination) {
1007 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1008 }
1009
1010 String sql = query.toString();
1011
1012 Session session = null;
1013
1014 try {
1015 session = openSession();
1016
1017 Query q = session.createQuery(sql);
1018
1019 QueryPos qPos = QueryPos.getInstance(q);
1020
1021 if (bindUuid) {
1022 qPos.add(uuid);
1023 }
1024
1025 qPos.add(companyId);
1026
1027 if (!pagination) {
1028 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1029 start, end, false);
1030
1031 Collections.sort(list);
1032
1033 list = new UnmodifiableList<MBCategory>(list);
1034 }
1035 else {
1036 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1037 start, end);
1038 }
1039
1040 cacheResult(list);
1041
1042 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1043 }
1044 catch (Exception e) {
1045 FinderCacheUtil.removeResult(finderPath, finderArgs);
1046
1047 throw processException(e);
1048 }
1049 finally {
1050 closeSession(session);
1051 }
1052 }
1053
1054 return list;
1055 }
1056
1057
1067 public MBCategory findByUuid_C_First(String uuid, long companyId,
1068 OrderByComparator orderByComparator)
1069 throws NoSuchCategoryException, SystemException {
1070 MBCategory mbCategory = fetchByUuid_C_First(uuid, companyId,
1071 orderByComparator);
1072
1073 if (mbCategory != null) {
1074 return mbCategory;
1075 }
1076
1077 StringBundler msg = new StringBundler(6);
1078
1079 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1080
1081 msg.append("uuid=");
1082 msg.append(uuid);
1083
1084 msg.append(", companyId=");
1085 msg.append(companyId);
1086
1087 msg.append(StringPool.CLOSE_CURLY_BRACE);
1088
1089 throw new NoSuchCategoryException(msg.toString());
1090 }
1091
1092
1101 public MBCategory fetchByUuid_C_First(String uuid, long companyId,
1102 OrderByComparator orderByComparator) throws SystemException {
1103 List<MBCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1104 orderByComparator);
1105
1106 if (!list.isEmpty()) {
1107 return list.get(0);
1108 }
1109
1110 return null;
1111 }
1112
1113
1123 public MBCategory findByUuid_C_Last(String uuid, long companyId,
1124 OrderByComparator orderByComparator)
1125 throws NoSuchCategoryException, SystemException {
1126 MBCategory mbCategory = fetchByUuid_C_Last(uuid, companyId,
1127 orderByComparator);
1128
1129 if (mbCategory != null) {
1130 return mbCategory;
1131 }
1132
1133 StringBundler msg = new StringBundler(6);
1134
1135 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1136
1137 msg.append("uuid=");
1138 msg.append(uuid);
1139
1140 msg.append(", companyId=");
1141 msg.append(companyId);
1142
1143 msg.append(StringPool.CLOSE_CURLY_BRACE);
1144
1145 throw new NoSuchCategoryException(msg.toString());
1146 }
1147
1148
1157 public MBCategory fetchByUuid_C_Last(String uuid, long companyId,
1158 OrderByComparator orderByComparator) throws SystemException {
1159 int count = countByUuid_C(uuid, companyId);
1160
1161 List<MBCategory> list = findByUuid_C(uuid, companyId, count - 1, count,
1162 orderByComparator);
1163
1164 if (!list.isEmpty()) {
1165 return list.get(0);
1166 }
1167
1168 return null;
1169 }
1170
1171
1182 public MBCategory[] findByUuid_C_PrevAndNext(long categoryId, String uuid,
1183 long companyId, OrderByComparator orderByComparator)
1184 throws NoSuchCategoryException, SystemException {
1185 MBCategory mbCategory = findByPrimaryKey(categoryId);
1186
1187 Session session = null;
1188
1189 try {
1190 session = openSession();
1191
1192 MBCategory[] array = new MBCategoryImpl[3];
1193
1194 array[0] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1195 companyId, orderByComparator, true);
1196
1197 array[1] = mbCategory;
1198
1199 array[2] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1200 companyId, orderByComparator, false);
1201
1202 return array;
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 closeSession(session);
1209 }
1210 }
1211
1212 protected MBCategory getByUuid_C_PrevAndNext(Session session,
1213 MBCategory mbCategory, String uuid, long companyId,
1214 OrderByComparator orderByComparator, boolean previous) {
1215 StringBundler query = null;
1216
1217 if (orderByComparator != null) {
1218 query = new StringBundler(6 +
1219 (orderByComparator.getOrderByFields().length * 6));
1220 }
1221 else {
1222 query = new StringBundler(3);
1223 }
1224
1225 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1226
1227 boolean bindUuid = false;
1228
1229 if (uuid == null) {
1230 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1231 }
1232 else if (uuid.equals(StringPool.BLANK)) {
1233 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1234 }
1235 else {
1236 bindUuid = true;
1237
1238 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1239 }
1240
1241 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1242
1243 if (orderByComparator != null) {
1244 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1245
1246 if (orderByConditionFields.length > 0) {
1247 query.append(WHERE_AND);
1248 }
1249
1250 for (int i = 0; i < orderByConditionFields.length; i++) {
1251 query.append(_ORDER_BY_ENTITY_ALIAS);
1252 query.append(orderByConditionFields[i]);
1253
1254 if ((i + 1) < orderByConditionFields.length) {
1255 if (orderByComparator.isAscending() ^ previous) {
1256 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1257 }
1258 else {
1259 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1260 }
1261 }
1262 else {
1263 if (orderByComparator.isAscending() ^ previous) {
1264 query.append(WHERE_GREATER_THAN);
1265 }
1266 else {
1267 query.append(WHERE_LESSER_THAN);
1268 }
1269 }
1270 }
1271
1272 query.append(ORDER_BY_CLAUSE);
1273
1274 String[] orderByFields = orderByComparator.getOrderByFields();
1275
1276 for (int i = 0; i < orderByFields.length; i++) {
1277 query.append(_ORDER_BY_ENTITY_ALIAS);
1278 query.append(orderByFields[i]);
1279
1280 if ((i + 1) < orderByFields.length) {
1281 if (orderByComparator.isAscending() ^ previous) {
1282 query.append(ORDER_BY_ASC_HAS_NEXT);
1283 }
1284 else {
1285 query.append(ORDER_BY_DESC_HAS_NEXT);
1286 }
1287 }
1288 else {
1289 if (orderByComparator.isAscending() ^ previous) {
1290 query.append(ORDER_BY_ASC);
1291 }
1292 else {
1293 query.append(ORDER_BY_DESC);
1294 }
1295 }
1296 }
1297 }
1298 else {
1299 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1300 }
1301
1302 String sql = query.toString();
1303
1304 Query q = session.createQuery(sql);
1305
1306 q.setFirstResult(0);
1307 q.setMaxResults(2);
1308
1309 QueryPos qPos = QueryPos.getInstance(q);
1310
1311 if (bindUuid) {
1312 qPos.add(uuid);
1313 }
1314
1315 qPos.add(companyId);
1316
1317 if (orderByComparator != null) {
1318 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1319
1320 for (Object value : values) {
1321 qPos.add(value);
1322 }
1323 }
1324
1325 List<MBCategory> list = q.list();
1326
1327 if (list.size() == 2) {
1328 return list.get(1);
1329 }
1330 else {
1331 return null;
1332 }
1333 }
1334
1335
1342 public void removeByUuid_C(String uuid, long companyId)
1343 throws SystemException {
1344 for (MBCategory mbCategory : findByUuid_C(uuid, companyId,
1345 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1346 remove(mbCategory);
1347 }
1348 }
1349
1350
1358 public int countByUuid_C(String uuid, long companyId)
1359 throws SystemException {
1360 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1361
1362 Object[] finderArgs = new Object[] { uuid, companyId };
1363
1364 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1365 this);
1366
1367 if (count == null) {
1368 StringBundler query = new StringBundler(3);
1369
1370 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
1371
1372 boolean bindUuid = false;
1373
1374 if (uuid == null) {
1375 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1376 }
1377 else if (uuid.equals(StringPool.BLANK)) {
1378 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1379 }
1380 else {
1381 bindUuid = true;
1382
1383 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1384 }
1385
1386 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1387
1388 String sql = query.toString();
1389
1390 Session session = null;
1391
1392 try {
1393 session = openSession();
1394
1395 Query q = session.createQuery(sql);
1396
1397 QueryPos qPos = QueryPos.getInstance(q);
1398
1399 if (bindUuid) {
1400 qPos.add(uuid);
1401 }
1402
1403 qPos.add(companyId);
1404
1405 count = (Long)q.uniqueResult();
1406
1407 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1408 }
1409 catch (Exception e) {
1410 FinderCacheUtil.removeResult(finderPath, finderArgs);
1411
1412 throw processException(e);
1413 }
1414 finally {
1415 closeSession(session);
1416 }
1417 }
1418
1419 return count.intValue();
1420 }
1421
1422 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbCategory.uuid IS NULL AND ";
1423 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbCategory.uuid = ? AND ";
1424 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
1425 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbCategory.companyId = ?";
1426 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1427 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1428 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1429 new String[] {
1430 Long.class.getName(),
1431
1432 Integer.class.getName(), Integer.class.getName(),
1433 OrderByComparator.class.getName()
1434 });
1435 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1436 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1437 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1438 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1439 new String[] { Long.class.getName() },
1440 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1441 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
1442 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
1443 public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1444 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1445 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1446 new String[] { Long.class.getName() });
1447
1448
1455 public List<MBCategory> findByGroupId(long groupId)
1456 throws SystemException {
1457 return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1458 }
1459
1460
1473 public List<MBCategory> findByGroupId(long groupId, int start, int end)
1474 throws SystemException {
1475 return findByGroupId(groupId, start, end, null);
1476 }
1477
1478
1492 public List<MBCategory> findByGroupId(long groupId, int start, int end,
1493 OrderByComparator orderByComparator) throws SystemException {
1494 boolean pagination = true;
1495 FinderPath finderPath = null;
1496 Object[] finderArgs = null;
1497
1498 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1499 (orderByComparator == null)) {
1500 pagination = false;
1501 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1502 finderArgs = new Object[] { groupId };
1503 }
1504 else {
1505 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1506 finderArgs = new Object[] { groupId, start, end, orderByComparator };
1507 }
1508
1509 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1510 finderArgs, this);
1511
1512 if ((list != null) && !list.isEmpty()) {
1513 for (MBCategory mbCategory : list) {
1514 if ((groupId != mbCategory.getGroupId())) {
1515 list = null;
1516
1517 break;
1518 }
1519 }
1520 }
1521
1522 if (list == null) {
1523 StringBundler query = null;
1524
1525 if (orderByComparator != null) {
1526 query = new StringBundler(3 +
1527 (orderByComparator.getOrderByFields().length * 3));
1528 }
1529 else {
1530 query = new StringBundler(3);
1531 }
1532
1533 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1534
1535 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1536
1537 if (orderByComparator != null) {
1538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1539 orderByComparator);
1540 }
1541 else
1542 if (pagination) {
1543 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1544 }
1545
1546 String sql = query.toString();
1547
1548 Session session = null;
1549
1550 try {
1551 session = openSession();
1552
1553 Query q = session.createQuery(sql);
1554
1555 QueryPos qPos = QueryPos.getInstance(q);
1556
1557 qPos.add(groupId);
1558
1559 if (!pagination) {
1560 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1561 start, end, false);
1562
1563 Collections.sort(list);
1564
1565 list = new UnmodifiableList<MBCategory>(list);
1566 }
1567 else {
1568 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1569 start, end);
1570 }
1571
1572 cacheResult(list);
1573
1574 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1575 }
1576 catch (Exception e) {
1577 FinderCacheUtil.removeResult(finderPath, finderArgs);
1578
1579 throw processException(e);
1580 }
1581 finally {
1582 closeSession(session);
1583 }
1584 }
1585
1586 return list;
1587 }
1588
1589
1598 public MBCategory findByGroupId_First(long groupId,
1599 OrderByComparator orderByComparator)
1600 throws NoSuchCategoryException, SystemException {
1601 MBCategory mbCategory = fetchByGroupId_First(groupId, orderByComparator);
1602
1603 if (mbCategory != null) {
1604 return mbCategory;
1605 }
1606
1607 StringBundler msg = new StringBundler(4);
1608
1609 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1610
1611 msg.append("groupId=");
1612 msg.append(groupId);
1613
1614 msg.append(StringPool.CLOSE_CURLY_BRACE);
1615
1616 throw new NoSuchCategoryException(msg.toString());
1617 }
1618
1619
1627 public MBCategory fetchByGroupId_First(long groupId,
1628 OrderByComparator orderByComparator) throws SystemException {
1629 List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1630
1631 if (!list.isEmpty()) {
1632 return list.get(0);
1633 }
1634
1635 return null;
1636 }
1637
1638
1647 public MBCategory findByGroupId_Last(long groupId,
1648 OrderByComparator orderByComparator)
1649 throws NoSuchCategoryException, SystemException {
1650 MBCategory mbCategory = fetchByGroupId_Last(groupId, orderByComparator);
1651
1652 if (mbCategory != null) {
1653 return mbCategory;
1654 }
1655
1656 StringBundler msg = new StringBundler(4);
1657
1658 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1659
1660 msg.append("groupId=");
1661 msg.append(groupId);
1662
1663 msg.append(StringPool.CLOSE_CURLY_BRACE);
1664
1665 throw new NoSuchCategoryException(msg.toString());
1666 }
1667
1668
1676 public MBCategory fetchByGroupId_Last(long groupId,
1677 OrderByComparator orderByComparator) throws SystemException {
1678 int count = countByGroupId(groupId);
1679
1680 List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1681 orderByComparator);
1682
1683 if (!list.isEmpty()) {
1684 return list.get(0);
1685 }
1686
1687 return null;
1688 }
1689
1690
1700 public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1701 long groupId, OrderByComparator orderByComparator)
1702 throws NoSuchCategoryException, SystemException {
1703 MBCategory mbCategory = findByPrimaryKey(categoryId);
1704
1705 Session session = null;
1706
1707 try {
1708 session = openSession();
1709
1710 MBCategory[] array = new MBCategoryImpl[3];
1711
1712 array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1713 orderByComparator, true);
1714
1715 array[1] = mbCategory;
1716
1717 array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1718 orderByComparator, false);
1719
1720 return array;
1721 }
1722 catch (Exception e) {
1723 throw processException(e);
1724 }
1725 finally {
1726 closeSession(session);
1727 }
1728 }
1729
1730 protected MBCategory getByGroupId_PrevAndNext(Session session,
1731 MBCategory mbCategory, long groupId,
1732 OrderByComparator orderByComparator, boolean previous) {
1733 StringBundler query = null;
1734
1735 if (orderByComparator != null) {
1736 query = new StringBundler(6 +
1737 (orderByComparator.getOrderByFields().length * 6));
1738 }
1739 else {
1740 query = new StringBundler(3);
1741 }
1742
1743 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1744
1745 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1746
1747 if (orderByComparator != null) {
1748 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1749
1750 if (orderByConditionFields.length > 0) {
1751 query.append(WHERE_AND);
1752 }
1753
1754 for (int i = 0; i < orderByConditionFields.length; i++) {
1755 query.append(_ORDER_BY_ENTITY_ALIAS);
1756 query.append(orderByConditionFields[i]);
1757
1758 if ((i + 1) < orderByConditionFields.length) {
1759 if (orderByComparator.isAscending() ^ previous) {
1760 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1761 }
1762 else {
1763 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1764 }
1765 }
1766 else {
1767 if (orderByComparator.isAscending() ^ previous) {
1768 query.append(WHERE_GREATER_THAN);
1769 }
1770 else {
1771 query.append(WHERE_LESSER_THAN);
1772 }
1773 }
1774 }
1775
1776 query.append(ORDER_BY_CLAUSE);
1777
1778 String[] orderByFields = orderByComparator.getOrderByFields();
1779
1780 for (int i = 0; i < orderByFields.length; i++) {
1781 query.append(_ORDER_BY_ENTITY_ALIAS);
1782 query.append(orderByFields[i]);
1783
1784 if ((i + 1) < orderByFields.length) {
1785 if (orderByComparator.isAscending() ^ previous) {
1786 query.append(ORDER_BY_ASC_HAS_NEXT);
1787 }
1788 else {
1789 query.append(ORDER_BY_DESC_HAS_NEXT);
1790 }
1791 }
1792 else {
1793 if (orderByComparator.isAscending() ^ previous) {
1794 query.append(ORDER_BY_ASC);
1795 }
1796 else {
1797 query.append(ORDER_BY_DESC);
1798 }
1799 }
1800 }
1801 }
1802 else {
1803 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1804 }
1805
1806 String sql = query.toString();
1807
1808 Query q = session.createQuery(sql);
1809
1810 q.setFirstResult(0);
1811 q.setMaxResults(2);
1812
1813 QueryPos qPos = QueryPos.getInstance(q);
1814
1815 qPos.add(groupId);
1816
1817 if (orderByComparator != null) {
1818 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1819
1820 for (Object value : values) {
1821 qPos.add(value);
1822 }
1823 }
1824
1825 List<MBCategory> list = q.list();
1826
1827 if (list.size() == 2) {
1828 return list.get(1);
1829 }
1830 else {
1831 return null;
1832 }
1833 }
1834
1835
1842 public List<MBCategory> filterFindByGroupId(long groupId)
1843 throws SystemException {
1844 return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1845 QueryUtil.ALL_POS, null);
1846 }
1847
1848
1861 public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1862 throws SystemException {
1863 return filterFindByGroupId(groupId, start, end, null);
1864 }
1865
1866
1880 public List<MBCategory> filterFindByGroupId(long groupId, int start,
1881 int end, OrderByComparator orderByComparator) throws SystemException {
1882 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1883 return findByGroupId(groupId, start, end, orderByComparator);
1884 }
1885
1886 StringBundler query = null;
1887
1888 if (orderByComparator != null) {
1889 query = new StringBundler(3 +
1890 (orderByComparator.getOrderByFields().length * 3));
1891 }
1892 else {
1893 query = new StringBundler(3);
1894 }
1895
1896 if (getDB().isSupportsInlineDistinct()) {
1897 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1898 }
1899 else {
1900 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1901 }
1902
1903 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1904
1905 if (!getDB().isSupportsInlineDistinct()) {
1906 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1907 }
1908
1909 if (orderByComparator != null) {
1910 if (getDB().isSupportsInlineDistinct()) {
1911 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1912 orderByComparator, true);
1913 }
1914 else {
1915 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1916 orderByComparator, true);
1917 }
1918 }
1919 else {
1920 if (getDB().isSupportsInlineDistinct()) {
1921 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1922 }
1923 else {
1924 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1925 }
1926 }
1927
1928 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1929 MBCategory.class.getName(),
1930 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1931
1932 Session session = null;
1933
1934 try {
1935 session = openSession();
1936
1937 SQLQuery q = session.createSQLQuery(sql);
1938
1939 if (getDB().isSupportsInlineDistinct()) {
1940 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1941 }
1942 else {
1943 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1944 }
1945
1946 QueryPos qPos = QueryPos.getInstance(q);
1947
1948 qPos.add(groupId);
1949
1950 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1951 }
1952 catch (Exception e) {
1953 throw processException(e);
1954 }
1955 finally {
1956 closeSession(session);
1957 }
1958 }
1959
1960
1970 public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
1971 long groupId, OrderByComparator orderByComparator)
1972 throws NoSuchCategoryException, SystemException {
1973 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1974 return findByGroupId_PrevAndNext(categoryId, groupId,
1975 orderByComparator);
1976 }
1977
1978 MBCategory mbCategory = findByPrimaryKey(categoryId);
1979
1980 Session session = null;
1981
1982 try {
1983 session = openSession();
1984
1985 MBCategory[] array = new MBCategoryImpl[3];
1986
1987 array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1988 groupId, orderByComparator, true);
1989
1990 array[1] = mbCategory;
1991
1992 array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
1993 groupId, orderByComparator, false);
1994
1995 return array;
1996 }
1997 catch (Exception e) {
1998 throw processException(e);
1999 }
2000 finally {
2001 closeSession(session);
2002 }
2003 }
2004
2005 protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
2006 MBCategory mbCategory, long groupId,
2007 OrderByComparator orderByComparator, boolean previous) {
2008 StringBundler query = null;
2009
2010 if (orderByComparator != null) {
2011 query = new StringBundler(6 +
2012 (orderByComparator.getOrderByFields().length * 6));
2013 }
2014 else {
2015 query = new StringBundler(3);
2016 }
2017
2018 if (getDB().isSupportsInlineDistinct()) {
2019 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2020 }
2021 else {
2022 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2023 }
2024
2025 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2026
2027 if (!getDB().isSupportsInlineDistinct()) {
2028 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2029 }
2030
2031 if (orderByComparator != null) {
2032 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2033
2034 if (orderByConditionFields.length > 0) {
2035 query.append(WHERE_AND);
2036 }
2037
2038 for (int i = 0; i < orderByConditionFields.length; i++) {
2039 if (getDB().isSupportsInlineDistinct()) {
2040 query.append(_ORDER_BY_ENTITY_ALIAS);
2041 }
2042 else {
2043 query.append(_ORDER_BY_ENTITY_TABLE);
2044 }
2045
2046 query.append(orderByConditionFields[i]);
2047
2048 if ((i + 1) < orderByConditionFields.length) {
2049 if (orderByComparator.isAscending() ^ previous) {
2050 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2051 }
2052 else {
2053 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2054 }
2055 }
2056 else {
2057 if (orderByComparator.isAscending() ^ previous) {
2058 query.append(WHERE_GREATER_THAN);
2059 }
2060 else {
2061 query.append(WHERE_LESSER_THAN);
2062 }
2063 }
2064 }
2065
2066 query.append(ORDER_BY_CLAUSE);
2067
2068 String[] orderByFields = orderByComparator.getOrderByFields();
2069
2070 for (int i = 0; i < orderByFields.length; i++) {
2071 if (getDB().isSupportsInlineDistinct()) {
2072 query.append(_ORDER_BY_ENTITY_ALIAS);
2073 }
2074 else {
2075 query.append(_ORDER_BY_ENTITY_TABLE);
2076 }
2077
2078 query.append(orderByFields[i]);
2079
2080 if ((i + 1) < orderByFields.length) {
2081 if (orderByComparator.isAscending() ^ previous) {
2082 query.append(ORDER_BY_ASC_HAS_NEXT);
2083 }
2084 else {
2085 query.append(ORDER_BY_DESC_HAS_NEXT);
2086 }
2087 }
2088 else {
2089 if (orderByComparator.isAscending() ^ previous) {
2090 query.append(ORDER_BY_ASC);
2091 }
2092 else {
2093 query.append(ORDER_BY_DESC);
2094 }
2095 }
2096 }
2097 }
2098 else {
2099 if (getDB().isSupportsInlineDistinct()) {
2100 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2101 }
2102 else {
2103 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2104 }
2105 }
2106
2107 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2108 MBCategory.class.getName(),
2109 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2110
2111 SQLQuery q = session.createSQLQuery(sql);
2112
2113 q.setFirstResult(0);
2114 q.setMaxResults(2);
2115
2116 if (getDB().isSupportsInlineDistinct()) {
2117 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2118 }
2119 else {
2120 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2121 }
2122
2123 QueryPos qPos = QueryPos.getInstance(q);
2124
2125 qPos.add(groupId);
2126
2127 if (orderByComparator != null) {
2128 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2129
2130 for (Object value : values) {
2131 qPos.add(value);
2132 }
2133 }
2134
2135 List<MBCategory> list = q.list();
2136
2137 if (list.size() == 2) {
2138 return list.get(1);
2139 }
2140 else {
2141 return null;
2142 }
2143 }
2144
2145
2151 public void removeByGroupId(long groupId) throws SystemException {
2152 for (MBCategory mbCategory : findByGroupId(groupId, QueryUtil.ALL_POS,
2153 QueryUtil.ALL_POS, null)) {
2154 remove(mbCategory);
2155 }
2156 }
2157
2158
2165 public int countByGroupId(long groupId) throws SystemException {
2166 FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2167
2168 Object[] finderArgs = new Object[] { groupId };
2169
2170 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2171 this);
2172
2173 if (count == null) {
2174 StringBundler query = new StringBundler(2);
2175
2176 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2177
2178 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2179
2180 String sql = query.toString();
2181
2182 Session session = null;
2183
2184 try {
2185 session = openSession();
2186
2187 Query q = session.createQuery(sql);
2188
2189 QueryPos qPos = QueryPos.getInstance(q);
2190
2191 qPos.add(groupId);
2192
2193 count = (Long)q.uniqueResult();
2194
2195 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2196 }
2197 catch (Exception e) {
2198 FinderCacheUtil.removeResult(finderPath, finderArgs);
2199
2200 throw processException(e);
2201 }
2202 finally {
2203 closeSession(session);
2204 }
2205 }
2206
2207 return count.intValue();
2208 }
2209
2210
2217 public int filterCountByGroupId(long groupId) throws SystemException {
2218 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2219 return countByGroupId(groupId);
2220 }
2221
2222 StringBundler query = new StringBundler(2);
2223
2224 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2225
2226 query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2227
2228 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2229 MBCategory.class.getName(),
2230 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2231
2232 Session session = null;
2233
2234 try {
2235 session = openSession();
2236
2237 SQLQuery q = session.createSQLQuery(sql);
2238
2239 q.addScalar(COUNT_COLUMN_NAME,
2240 com.liferay.portal.kernel.dao.orm.Type.LONG);
2241
2242 QueryPos qPos = QueryPos.getInstance(q);
2243
2244 qPos.add(groupId);
2245
2246 Long count = (Long)q.uniqueResult();
2247
2248 return count.intValue();
2249 }
2250 catch (Exception e) {
2251 throw processException(e);
2252 }
2253 finally {
2254 closeSession(session);
2255 }
2256 }
2257
2258 private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
2259 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2260 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2261 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2262 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2263 new String[] {
2264 Long.class.getName(),
2265
2266 Integer.class.getName(), Integer.class.getName(),
2267 OrderByComparator.class.getName()
2268 });
2269 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2270 new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2271 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2272 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2273 new String[] { Long.class.getName() },
2274 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
2275 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2276 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2277 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2278 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2279 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2280 new String[] { Long.class.getName() });
2281
2282
2289 public List<MBCategory> findByCompanyId(long companyId)
2290 throws SystemException {
2291 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2292 null);
2293 }
2294
2295
2308 public List<MBCategory> findByCompanyId(long companyId, int start, int end)
2309 throws SystemException {
2310 return findByCompanyId(companyId, start, end, null);
2311 }
2312
2313
2327 public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2328 OrderByComparator orderByComparator) throws SystemException {
2329 boolean pagination = true;
2330 FinderPath finderPath = null;
2331 Object[] finderArgs = null;
2332
2333 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2334 (orderByComparator == null)) {
2335 pagination = false;
2336 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2337 finderArgs = new Object[] { companyId };
2338 }
2339 else {
2340 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2341 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2342 }
2343
2344 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2345 finderArgs, this);
2346
2347 if ((list != null) && !list.isEmpty()) {
2348 for (MBCategory mbCategory : list) {
2349 if ((companyId != mbCategory.getCompanyId())) {
2350 list = null;
2351
2352 break;
2353 }
2354 }
2355 }
2356
2357 if (list == null) {
2358 StringBundler query = null;
2359
2360 if (orderByComparator != null) {
2361 query = new StringBundler(3 +
2362 (orderByComparator.getOrderByFields().length * 3));
2363 }
2364 else {
2365 query = new StringBundler(3);
2366 }
2367
2368 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2369
2370 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2371
2372 if (orderByComparator != null) {
2373 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2374 orderByComparator);
2375 }
2376 else
2377 if (pagination) {
2378 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2379 }
2380
2381 String sql = query.toString();
2382
2383 Session session = null;
2384
2385 try {
2386 session = openSession();
2387
2388 Query q = session.createQuery(sql);
2389
2390 QueryPos qPos = QueryPos.getInstance(q);
2391
2392 qPos.add(companyId);
2393
2394 if (!pagination) {
2395 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2396 start, end, false);
2397
2398 Collections.sort(list);
2399
2400 list = new UnmodifiableList<MBCategory>(list);
2401 }
2402 else {
2403 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2404 start, end);
2405 }
2406
2407 cacheResult(list);
2408
2409 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2410 }
2411 catch (Exception e) {
2412 FinderCacheUtil.removeResult(finderPath, finderArgs);
2413
2414 throw processException(e);
2415 }
2416 finally {
2417 closeSession(session);
2418 }
2419 }
2420
2421 return list;
2422 }
2423
2424
2433 public MBCategory findByCompanyId_First(long companyId,
2434 OrderByComparator orderByComparator)
2435 throws NoSuchCategoryException, SystemException {
2436 MBCategory mbCategory = fetchByCompanyId_First(companyId,
2437 orderByComparator);
2438
2439 if (mbCategory != null) {
2440 return mbCategory;
2441 }
2442
2443 StringBundler msg = new StringBundler(4);
2444
2445 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2446
2447 msg.append("companyId=");
2448 msg.append(companyId);
2449
2450 msg.append(StringPool.CLOSE_CURLY_BRACE);
2451
2452 throw new NoSuchCategoryException(msg.toString());
2453 }
2454
2455
2463 public MBCategory fetchByCompanyId_First(long companyId,
2464 OrderByComparator orderByComparator) throws SystemException {
2465 List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2466 orderByComparator);
2467
2468 if (!list.isEmpty()) {
2469 return list.get(0);
2470 }
2471
2472 return null;
2473 }
2474
2475
2484 public MBCategory findByCompanyId_Last(long companyId,
2485 OrderByComparator orderByComparator)
2486 throws NoSuchCategoryException, SystemException {
2487 MBCategory mbCategory = fetchByCompanyId_Last(companyId,
2488 orderByComparator);
2489
2490 if (mbCategory != null) {
2491 return mbCategory;
2492 }
2493
2494 StringBundler msg = new StringBundler(4);
2495
2496 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2497
2498 msg.append("companyId=");
2499 msg.append(companyId);
2500
2501 msg.append(StringPool.CLOSE_CURLY_BRACE);
2502
2503 throw new NoSuchCategoryException(msg.toString());
2504 }
2505
2506
2514 public MBCategory fetchByCompanyId_Last(long companyId,
2515 OrderByComparator orderByComparator) throws SystemException {
2516 int count = countByCompanyId(companyId);
2517
2518 List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2519 orderByComparator);
2520
2521 if (!list.isEmpty()) {
2522 return list.get(0);
2523 }
2524
2525 return null;
2526 }
2527
2528
2538 public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2539 long companyId, OrderByComparator orderByComparator)
2540 throws NoSuchCategoryException, SystemException {
2541 MBCategory mbCategory = findByPrimaryKey(categoryId);
2542
2543 Session session = null;
2544
2545 try {
2546 session = openSession();
2547
2548 MBCategory[] array = new MBCategoryImpl[3];
2549
2550 array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2551 companyId, orderByComparator, true);
2552
2553 array[1] = mbCategory;
2554
2555 array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2556 companyId, orderByComparator, false);
2557
2558 return array;
2559 }
2560 catch (Exception e) {
2561 throw processException(e);
2562 }
2563 finally {
2564 closeSession(session);
2565 }
2566 }
2567
2568 protected MBCategory getByCompanyId_PrevAndNext(Session session,
2569 MBCategory mbCategory, long companyId,
2570 OrderByComparator orderByComparator, boolean previous) {
2571 StringBundler query = null;
2572
2573 if (orderByComparator != null) {
2574 query = new StringBundler(6 +
2575 (orderByComparator.getOrderByFields().length * 6));
2576 }
2577 else {
2578 query = new StringBundler(3);
2579 }
2580
2581 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2582
2583 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2584
2585 if (orderByComparator != null) {
2586 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2587
2588 if (orderByConditionFields.length > 0) {
2589 query.append(WHERE_AND);
2590 }
2591
2592 for (int i = 0; i < orderByConditionFields.length; i++) {
2593 query.append(_ORDER_BY_ENTITY_ALIAS);
2594 query.append(orderByConditionFields[i]);
2595
2596 if ((i + 1) < orderByConditionFields.length) {
2597 if (orderByComparator.isAscending() ^ previous) {
2598 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2599 }
2600 else {
2601 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2602 }
2603 }
2604 else {
2605 if (orderByComparator.isAscending() ^ previous) {
2606 query.append(WHERE_GREATER_THAN);
2607 }
2608 else {
2609 query.append(WHERE_LESSER_THAN);
2610 }
2611 }
2612 }
2613
2614 query.append(ORDER_BY_CLAUSE);
2615
2616 String[] orderByFields = orderByComparator.getOrderByFields();
2617
2618 for (int i = 0; i < orderByFields.length; i++) {
2619 query.append(_ORDER_BY_ENTITY_ALIAS);
2620 query.append(orderByFields[i]);
2621
2622 if ((i + 1) < orderByFields.length) {
2623 if (orderByComparator.isAscending() ^ previous) {
2624 query.append(ORDER_BY_ASC_HAS_NEXT);
2625 }
2626 else {
2627 query.append(ORDER_BY_DESC_HAS_NEXT);
2628 }
2629 }
2630 else {
2631 if (orderByComparator.isAscending() ^ previous) {
2632 query.append(ORDER_BY_ASC);
2633 }
2634 else {
2635 query.append(ORDER_BY_DESC);
2636 }
2637 }
2638 }
2639 }
2640 else {
2641 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2642 }
2643
2644 String sql = query.toString();
2645
2646 Query q = session.createQuery(sql);
2647
2648 q.setFirstResult(0);
2649 q.setMaxResults(2);
2650
2651 QueryPos qPos = QueryPos.getInstance(q);
2652
2653 qPos.add(companyId);
2654
2655 if (orderByComparator != null) {
2656 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2657
2658 for (Object value : values) {
2659 qPos.add(value);
2660 }
2661 }
2662
2663 List<MBCategory> list = q.list();
2664
2665 if (list.size() == 2) {
2666 return list.get(1);
2667 }
2668 else {
2669 return null;
2670 }
2671 }
2672
2673
2679 public void removeByCompanyId(long companyId) throws SystemException {
2680 for (MBCategory mbCategory : findByCompanyId(companyId,
2681 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2682 remove(mbCategory);
2683 }
2684 }
2685
2686
2693 public int countByCompanyId(long companyId) throws SystemException {
2694 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2695
2696 Object[] finderArgs = new Object[] { companyId };
2697
2698 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2699 this);
2700
2701 if (count == null) {
2702 StringBundler query = new StringBundler(2);
2703
2704 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2705
2706 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2707
2708 String sql = query.toString();
2709
2710 Session session = null;
2711
2712 try {
2713 session = openSession();
2714
2715 Query q = session.createQuery(sql);
2716
2717 QueryPos qPos = QueryPos.getInstance(q);
2718
2719 qPos.add(companyId);
2720
2721 count = (Long)q.uniqueResult();
2722
2723 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2724 }
2725 catch (Exception e) {
2726 FinderCacheUtil.removeResult(finderPath, finderArgs);
2727
2728 throw processException(e);
2729 }
2730 finally {
2731 closeSession(session);
2732 }
2733 }
2734
2735 return count.intValue();
2736 }
2737
2738 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
2739 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2740 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2741 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
2742 new String[] {
2743 Long.class.getName(), Long.class.getName(),
2744
2745 Integer.class.getName(), Integer.class.getName(),
2746 OrderByComparator.class.getName()
2747 });
2748 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2749 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2750 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
2751 new String[] { Long.class.getName(), Long.class.getName() },
2752 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
2753 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2754 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2755 public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2756 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2757 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
2758 new String[] { Long.class.getName(), Long.class.getName() });
2759 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2760 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2761 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
2762 new String[] { Long.class.getName(), Long.class.getName() });
2763
2764
2772 public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
2773 throws SystemException {
2774 return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2775 QueryUtil.ALL_POS, null);
2776 }
2777
2778
2792 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2793 int start, int end) throws SystemException {
2794 return findByG_P(groupId, parentCategoryId, start, end, null);
2795 }
2796
2797
2812 public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2813 int start, int end, OrderByComparator orderByComparator)
2814 throws SystemException {
2815 boolean pagination = true;
2816 FinderPath finderPath = null;
2817 Object[] finderArgs = null;
2818
2819 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2820 (orderByComparator == null)) {
2821 pagination = false;
2822 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2823 finderArgs = new Object[] { groupId, parentCategoryId };
2824 }
2825 else {
2826 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2827 finderArgs = new Object[] {
2828 groupId, parentCategoryId,
2829
2830 start, end, orderByComparator
2831 };
2832 }
2833
2834 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2835 finderArgs, this);
2836
2837 if ((list != null) && !list.isEmpty()) {
2838 for (MBCategory mbCategory : list) {
2839 if ((groupId != mbCategory.getGroupId()) ||
2840 (parentCategoryId != mbCategory.getParentCategoryId())) {
2841 list = null;
2842
2843 break;
2844 }
2845 }
2846 }
2847
2848 if (list == null) {
2849 StringBundler query = null;
2850
2851 if (orderByComparator != null) {
2852 query = new StringBundler(4 +
2853 (orderByComparator.getOrderByFields().length * 3));
2854 }
2855 else {
2856 query = new StringBundler(4);
2857 }
2858
2859 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2860
2861 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2862
2863 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2864
2865 if (orderByComparator != null) {
2866 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2867 orderByComparator);
2868 }
2869 else
2870 if (pagination) {
2871 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2872 }
2873
2874 String sql = query.toString();
2875
2876 Session session = null;
2877
2878 try {
2879 session = openSession();
2880
2881 Query q = session.createQuery(sql);
2882
2883 QueryPos qPos = QueryPos.getInstance(q);
2884
2885 qPos.add(groupId);
2886
2887 qPos.add(parentCategoryId);
2888
2889 if (!pagination) {
2890 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2891 start, end, false);
2892
2893 Collections.sort(list);
2894
2895 list = new UnmodifiableList<MBCategory>(list);
2896 }
2897 else {
2898 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2899 start, end);
2900 }
2901
2902 cacheResult(list);
2903
2904 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2905 }
2906 catch (Exception e) {
2907 FinderCacheUtil.removeResult(finderPath, finderArgs);
2908
2909 throw processException(e);
2910 }
2911 finally {
2912 closeSession(session);
2913 }
2914 }
2915
2916 return list;
2917 }
2918
2919
2929 public MBCategory findByG_P_First(long groupId, long parentCategoryId,
2930 OrderByComparator orderByComparator)
2931 throws NoSuchCategoryException, SystemException {
2932 MBCategory mbCategory = fetchByG_P_First(groupId, parentCategoryId,
2933 orderByComparator);
2934
2935 if (mbCategory != null) {
2936 return mbCategory;
2937 }
2938
2939 StringBundler msg = new StringBundler(6);
2940
2941 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2942
2943 msg.append("groupId=");
2944 msg.append(groupId);
2945
2946 msg.append(", parentCategoryId=");
2947 msg.append(parentCategoryId);
2948
2949 msg.append(StringPool.CLOSE_CURLY_BRACE);
2950
2951 throw new NoSuchCategoryException(msg.toString());
2952 }
2953
2954
2963 public MBCategory fetchByG_P_First(long groupId, long parentCategoryId,
2964 OrderByComparator orderByComparator) throws SystemException {
2965 List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
2966 orderByComparator);
2967
2968 if (!list.isEmpty()) {
2969 return list.get(0);
2970 }
2971
2972 return null;
2973 }
2974
2975
2985 public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
2986 OrderByComparator orderByComparator)
2987 throws NoSuchCategoryException, SystemException {
2988 MBCategory mbCategory = fetchByG_P_Last(groupId, parentCategoryId,
2989 orderByComparator);
2990
2991 if (mbCategory != null) {
2992 return mbCategory;
2993 }
2994
2995 StringBundler msg = new StringBundler(6);
2996
2997 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2998
2999 msg.append("groupId=");
3000 msg.append(groupId);
3001
3002 msg.append(", parentCategoryId=");
3003 msg.append(parentCategoryId);
3004
3005 msg.append(StringPool.CLOSE_CURLY_BRACE);
3006
3007 throw new NoSuchCategoryException(msg.toString());
3008 }
3009
3010
3019 public MBCategory fetchByG_P_Last(long groupId, long parentCategoryId,
3020 OrderByComparator orderByComparator) throws SystemException {
3021 int count = countByG_P(groupId, parentCategoryId);
3022
3023 List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
3024 count, orderByComparator);
3025
3026 if (!list.isEmpty()) {
3027 return list.get(0);
3028 }
3029
3030 return null;
3031 }
3032
3033
3044 public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
3045 long parentCategoryId, OrderByComparator orderByComparator)
3046 throws NoSuchCategoryException, SystemException {
3047 MBCategory mbCategory = findByPrimaryKey(categoryId);
3048
3049 Session session = null;
3050
3051 try {
3052 session = openSession();
3053
3054 MBCategory[] array = new MBCategoryImpl[3];
3055
3056 array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3057 parentCategoryId, orderByComparator, true);
3058
3059 array[1] = mbCategory;
3060
3061 array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3062 parentCategoryId, orderByComparator, false);
3063
3064 return array;
3065 }
3066 catch (Exception e) {
3067 throw processException(e);
3068 }
3069 finally {
3070 closeSession(session);
3071 }
3072 }
3073
3074 protected MBCategory getByG_P_PrevAndNext(Session session,
3075 MBCategory mbCategory, long groupId, long parentCategoryId,
3076 OrderByComparator orderByComparator, boolean previous) {
3077 StringBundler query = null;
3078
3079 if (orderByComparator != null) {
3080 query = new StringBundler(6 +
3081 (orderByComparator.getOrderByFields().length * 6));
3082 }
3083 else {
3084 query = new StringBundler(3);
3085 }
3086
3087 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3088
3089 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3090
3091 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3092
3093 if (orderByComparator != null) {
3094 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3095
3096 if (orderByConditionFields.length > 0) {
3097 query.append(WHERE_AND);
3098 }
3099
3100 for (int i = 0; i < orderByConditionFields.length; i++) {
3101 query.append(_ORDER_BY_ENTITY_ALIAS);
3102 query.append(orderByConditionFields[i]);
3103
3104 if ((i + 1) < orderByConditionFields.length) {
3105 if (orderByComparator.isAscending() ^ previous) {
3106 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3107 }
3108 else {
3109 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3110 }
3111 }
3112 else {
3113 if (orderByComparator.isAscending() ^ previous) {
3114 query.append(WHERE_GREATER_THAN);
3115 }
3116 else {
3117 query.append(WHERE_LESSER_THAN);
3118 }
3119 }
3120 }
3121
3122 query.append(ORDER_BY_CLAUSE);
3123
3124 String[] orderByFields = orderByComparator.getOrderByFields();
3125
3126 for (int i = 0; i < orderByFields.length; i++) {
3127 query.append(_ORDER_BY_ENTITY_ALIAS);
3128 query.append(orderByFields[i]);
3129
3130 if ((i + 1) < orderByFields.length) {
3131 if (orderByComparator.isAscending() ^ previous) {
3132 query.append(ORDER_BY_ASC_HAS_NEXT);
3133 }
3134 else {
3135 query.append(ORDER_BY_DESC_HAS_NEXT);
3136 }
3137 }
3138 else {
3139 if (orderByComparator.isAscending() ^ previous) {
3140 query.append(ORDER_BY_ASC);
3141 }
3142 else {
3143 query.append(ORDER_BY_DESC);
3144 }
3145 }
3146 }
3147 }
3148 else {
3149 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3150 }
3151
3152 String sql = query.toString();
3153
3154 Query q = session.createQuery(sql);
3155
3156 q.setFirstResult(0);
3157 q.setMaxResults(2);
3158
3159 QueryPos qPos = QueryPos.getInstance(q);
3160
3161 qPos.add(groupId);
3162
3163 qPos.add(parentCategoryId);
3164
3165 if (orderByComparator != null) {
3166 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3167
3168 for (Object value : values) {
3169 qPos.add(value);
3170 }
3171 }
3172
3173 List<MBCategory> list = q.list();
3174
3175 if (list.size() == 2) {
3176 return list.get(1);
3177 }
3178 else {
3179 return null;
3180 }
3181 }
3182
3183
3191 public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
3192 throws SystemException {
3193 return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
3194 QueryUtil.ALL_POS, null);
3195 }
3196
3197
3211 public List<MBCategory> filterFindByG_P(long groupId,
3212 long parentCategoryId, int start, int end) throws SystemException {
3213 return filterFindByG_P(groupId, parentCategoryId, start, end, null);
3214 }
3215
3216
3231 public List<MBCategory> filterFindByG_P(long groupId,
3232 long parentCategoryId, int start, int end,
3233 OrderByComparator orderByComparator) throws SystemException {
3234 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3235 return findByG_P(groupId, parentCategoryId, start, end,
3236 orderByComparator);
3237 }
3238
3239 StringBundler query = null;
3240
3241 if (orderByComparator != null) {
3242 query = new StringBundler(4 +
3243 (orderByComparator.getOrderByFields().length * 3));
3244 }
3245 else {
3246 query = new StringBundler(4);
3247 }
3248
3249 if (getDB().isSupportsInlineDistinct()) {
3250 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3251 }
3252 else {
3253 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3254 }
3255
3256 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3257
3258 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3259
3260 if (!getDB().isSupportsInlineDistinct()) {
3261 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3262 }
3263
3264 if (orderByComparator != null) {
3265 if (getDB().isSupportsInlineDistinct()) {
3266 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3267 orderByComparator, true);
3268 }
3269 else {
3270 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3271 orderByComparator, true);
3272 }
3273 }
3274 else {
3275 if (getDB().isSupportsInlineDistinct()) {
3276 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3277 }
3278 else {
3279 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3280 }
3281 }
3282
3283 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3284 MBCategory.class.getName(),
3285 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3286
3287 Session session = null;
3288
3289 try {
3290 session = openSession();
3291
3292 SQLQuery q = session.createSQLQuery(sql);
3293
3294 if (getDB().isSupportsInlineDistinct()) {
3295 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3296 }
3297 else {
3298 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3299 }
3300
3301 QueryPos qPos = QueryPos.getInstance(q);
3302
3303 qPos.add(groupId);
3304
3305 qPos.add(parentCategoryId);
3306
3307 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3308 }
3309 catch (Exception e) {
3310 throw processException(e);
3311 }
3312 finally {
3313 closeSession(session);
3314 }
3315 }
3316
3317
3328 public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
3329 long groupId, long parentCategoryId, OrderByComparator orderByComparator)
3330 throws NoSuchCategoryException, SystemException {
3331 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3332 return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
3333 orderByComparator);
3334 }
3335
3336 MBCategory mbCategory = findByPrimaryKey(categoryId);
3337
3338 Session session = null;
3339
3340 try {
3341 session = openSession();
3342
3343 MBCategory[] array = new MBCategoryImpl[3];
3344
3345 array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3346 parentCategoryId, orderByComparator, true);
3347
3348 array[1] = mbCategory;
3349
3350 array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3351 parentCategoryId, orderByComparator, false);
3352
3353 return array;
3354 }
3355 catch (Exception e) {
3356 throw processException(e);
3357 }
3358 finally {
3359 closeSession(session);
3360 }
3361 }
3362
3363 protected MBCategory filterGetByG_P_PrevAndNext(Session session,
3364 MBCategory mbCategory, long groupId, long parentCategoryId,
3365 OrderByComparator orderByComparator, boolean previous) {
3366 StringBundler query = null;
3367
3368 if (orderByComparator != null) {
3369 query = new StringBundler(6 +
3370 (orderByComparator.getOrderByFields().length * 6));
3371 }
3372 else {
3373 query = new StringBundler(3);
3374 }
3375
3376 if (getDB().isSupportsInlineDistinct()) {
3377 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3378 }
3379 else {
3380 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3381 }
3382
3383 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3384
3385 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3386
3387 if (!getDB().isSupportsInlineDistinct()) {
3388 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3389 }
3390
3391 if (orderByComparator != null) {
3392 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3393
3394 if (orderByConditionFields.length > 0) {
3395 query.append(WHERE_AND);
3396 }
3397
3398 for (int i = 0; i < orderByConditionFields.length; i++) {
3399 if (getDB().isSupportsInlineDistinct()) {
3400 query.append(_ORDER_BY_ENTITY_ALIAS);
3401 }
3402 else {
3403 query.append(_ORDER_BY_ENTITY_TABLE);
3404 }
3405
3406 query.append(orderByConditionFields[i]);
3407
3408 if ((i + 1) < orderByConditionFields.length) {
3409 if (orderByComparator.isAscending() ^ previous) {
3410 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3411 }
3412 else {
3413 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3414 }
3415 }
3416 else {
3417 if (orderByComparator.isAscending() ^ previous) {
3418 query.append(WHERE_GREATER_THAN);
3419 }
3420 else {
3421 query.append(WHERE_LESSER_THAN);
3422 }
3423 }
3424 }
3425
3426 query.append(ORDER_BY_CLAUSE);
3427
3428 String[] orderByFields = orderByComparator.getOrderByFields();
3429
3430 for (int i = 0; i < orderByFields.length; i++) {
3431 if (getDB().isSupportsInlineDistinct()) {
3432 query.append(_ORDER_BY_ENTITY_ALIAS);
3433 }
3434 else {
3435 query.append(_ORDER_BY_ENTITY_TABLE);
3436 }
3437
3438 query.append(orderByFields[i]);
3439
3440 if ((i + 1) < orderByFields.length) {
3441 if (orderByComparator.isAscending() ^ previous) {
3442 query.append(ORDER_BY_ASC_HAS_NEXT);
3443 }
3444 else {
3445 query.append(ORDER_BY_DESC_HAS_NEXT);
3446 }
3447 }
3448 else {
3449 if (orderByComparator.isAscending() ^ previous) {
3450 query.append(ORDER_BY_ASC);
3451 }
3452 else {
3453 query.append(ORDER_BY_DESC);
3454 }
3455 }
3456 }
3457 }
3458 else {
3459 if (getDB().isSupportsInlineDistinct()) {
3460 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3461 }
3462 else {
3463 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3464 }
3465 }
3466
3467 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3468 MBCategory.class.getName(),
3469 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3470
3471 SQLQuery q = session.createSQLQuery(sql);
3472
3473 q.setFirstResult(0);
3474 q.setMaxResults(2);
3475
3476 if (getDB().isSupportsInlineDistinct()) {
3477 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3478 }
3479 else {
3480 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3481 }
3482
3483 QueryPos qPos = QueryPos.getInstance(q);
3484
3485 qPos.add(groupId);
3486
3487 qPos.add(parentCategoryId);
3488
3489 if (orderByComparator != null) {
3490 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3491
3492 for (Object value : values) {
3493 qPos.add(value);
3494 }
3495 }
3496
3497 List<MBCategory> list = q.list();
3498
3499 if (list.size() == 2) {
3500 return list.get(1);
3501 }
3502 else {
3503 return null;
3504 }
3505 }
3506
3507
3515 public List<MBCategory> filterFindByG_P(long groupId,
3516 long[] parentCategoryIds) throws SystemException {
3517 return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3518 QueryUtil.ALL_POS, null);
3519 }
3520
3521
3535 public List<MBCategory> filterFindByG_P(long groupId,
3536 long[] parentCategoryIds, int start, int end) throws SystemException {
3537 return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3538 }
3539
3540
3555 public List<MBCategory> filterFindByG_P(long groupId,
3556 long[] parentCategoryIds, int start, int end,
3557 OrderByComparator orderByComparator) throws SystemException {
3558 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3559 return findByG_P(groupId, parentCategoryIds, start, end,
3560 orderByComparator);
3561 }
3562
3563 StringBundler query = new StringBundler();
3564
3565 if (getDB().isSupportsInlineDistinct()) {
3566 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3567 }
3568 else {
3569 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3570 }
3571
3572 boolean conjunctionable = false;
3573
3574 if (conjunctionable) {
3575 query.append(WHERE_AND);
3576 }
3577
3578 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3579
3580 conjunctionable = true;
3581
3582 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3583 if (conjunctionable) {
3584 query.append(WHERE_AND);
3585 }
3586
3587 query.append(StringPool.OPEN_PARENTHESIS);
3588
3589 for (int i = 0; i < parentCategoryIds.length; i++) {
3590 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3591
3592 if ((i + 1) < parentCategoryIds.length) {
3593 query.append(WHERE_OR);
3594 }
3595 }
3596
3597 query.append(StringPool.CLOSE_PARENTHESIS);
3598
3599 conjunctionable = true;
3600 }
3601
3602 if (!getDB().isSupportsInlineDistinct()) {
3603 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3604 }
3605
3606 if (orderByComparator != null) {
3607 if (getDB().isSupportsInlineDistinct()) {
3608 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3609 orderByComparator, true);
3610 }
3611 else {
3612 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3613 orderByComparator, true);
3614 }
3615 }
3616 else {
3617 if (getDB().isSupportsInlineDistinct()) {
3618 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3619 }
3620 else {
3621 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3622 }
3623 }
3624
3625 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3626 MBCategory.class.getName(),
3627 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3628
3629 Session session = null;
3630
3631 try {
3632 session = openSession();
3633
3634 SQLQuery q = session.createSQLQuery(sql);
3635
3636 if (getDB().isSupportsInlineDistinct()) {
3637 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3638 }
3639 else {
3640 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3641 }
3642
3643 QueryPos qPos = QueryPos.getInstance(q);
3644
3645 qPos.add(groupId);
3646
3647 if (parentCategoryIds != null) {
3648 qPos.add(parentCategoryIds);
3649 }
3650
3651 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3652 }
3653 catch (Exception e) {
3654 throw processException(e);
3655 }
3656 finally {
3657 closeSession(session);
3658 }
3659 }
3660
3661
3673 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
3674 throws SystemException {
3675 return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3676 QueryUtil.ALL_POS, null);
3677 }
3678
3679
3693 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3694 int start, int end) throws SystemException {
3695 return findByG_P(groupId, parentCategoryIds, start, end, null);
3696 }
3697
3698
3713 public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3714 int start, int end, OrderByComparator orderByComparator)
3715 throws SystemException {
3716 if ((parentCategoryIds != null) && (parentCategoryIds.length == 1)) {
3717 return findByG_P(groupId, parentCategoryIds[0], start, end,
3718 orderByComparator);
3719 }
3720
3721 boolean pagination = true;
3722 Object[] finderArgs = null;
3723
3724 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3725 (orderByComparator == null)) {
3726 pagination = false;
3727 finderArgs = new Object[] {
3728 groupId, StringUtil.merge(parentCategoryIds)
3729 };
3730 }
3731 else {
3732 finderArgs = new Object[] {
3733 groupId, StringUtil.merge(parentCategoryIds),
3734
3735 start, end, orderByComparator
3736 };
3737 }
3738
3739 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3740 finderArgs, this);
3741
3742 if ((list != null) && !list.isEmpty()) {
3743 for (MBCategory mbCategory : list) {
3744 if ((groupId != mbCategory.getGroupId()) ||
3745 !ArrayUtil.contains(parentCategoryIds,
3746 mbCategory.getParentCategoryId())) {
3747 list = null;
3748
3749 break;
3750 }
3751 }
3752 }
3753
3754 if (list == null) {
3755 StringBundler query = new StringBundler();
3756
3757 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3758
3759 boolean conjunctionable = false;
3760
3761 if (conjunctionable) {
3762 query.append(WHERE_AND);
3763 }
3764
3765 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3766
3767 conjunctionable = true;
3768
3769 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3770 if (conjunctionable) {
3771 query.append(WHERE_AND);
3772 }
3773
3774 query.append(StringPool.OPEN_PARENTHESIS);
3775
3776 for (int i = 0; i < parentCategoryIds.length; i++) {
3777 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3778
3779 if ((i + 1) < parentCategoryIds.length) {
3780 query.append(WHERE_OR);
3781 }
3782 }
3783
3784 query.append(StringPool.CLOSE_PARENTHESIS);
3785
3786 conjunctionable = true;
3787 }
3788
3789 if (orderByComparator != null) {
3790 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3791 orderByComparator);
3792 }
3793 else
3794 if (pagination) {
3795 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3796 }
3797
3798 String sql = query.toString();
3799
3800 Session session = null;
3801
3802 try {
3803 session = openSession();
3804
3805 Query q = session.createQuery(sql);
3806
3807 QueryPos qPos = QueryPos.getInstance(q);
3808
3809 qPos.add(groupId);
3810
3811 if (parentCategoryIds != null) {
3812 qPos.add(parentCategoryIds);
3813 }
3814
3815 if (!pagination) {
3816 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3817 start, end, false);
3818
3819 Collections.sort(list);
3820
3821 list = new UnmodifiableList<MBCategory>(list);
3822 }
3823 else {
3824 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3825 start, end);
3826 }
3827
3828 cacheResult(list);
3829
3830 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3831 finderArgs, list);
3832 }
3833 catch (Exception e) {
3834 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3835 finderArgs);
3836
3837 throw processException(e);
3838 }
3839 finally {
3840 closeSession(session);
3841 }
3842 }
3843
3844 return list;
3845 }
3846
3847
3854 public void removeByG_P(long groupId, long parentCategoryId)
3855 throws SystemException {
3856 for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId,
3857 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3858 remove(mbCategory);
3859 }
3860 }
3861
3862
3870 public int countByG_P(long groupId, long parentCategoryId)
3871 throws SystemException {
3872 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
3873
3874 Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3875
3876 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3877 this);
3878
3879 if (count == null) {
3880 StringBundler query = new StringBundler(3);
3881
3882 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3883
3884 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3885
3886 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3887
3888 String sql = query.toString();
3889
3890 Session session = null;
3891
3892 try {
3893 session = openSession();
3894
3895 Query q = session.createQuery(sql);
3896
3897 QueryPos qPos = QueryPos.getInstance(q);
3898
3899 qPos.add(groupId);
3900
3901 qPos.add(parentCategoryId);
3902
3903 count = (Long)q.uniqueResult();
3904
3905 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3906 }
3907 catch (Exception e) {
3908 FinderCacheUtil.removeResult(finderPath, finderArgs);
3909
3910 throw processException(e);
3911 }
3912 finally {
3913 closeSession(session);
3914 }
3915 }
3916
3917 return count.intValue();
3918 }
3919
3920
3928 public int countByG_P(long groupId, long[] parentCategoryIds)
3929 throws SystemException {
3930 Object[] finderArgs = new Object[] {
3931 groupId, StringUtil.merge(parentCategoryIds)
3932 };
3933
3934 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3935 finderArgs, this);
3936
3937 if (count == null) {
3938 StringBundler query = new StringBundler();
3939
3940 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3941
3942 boolean conjunctionable = false;
3943
3944 if (conjunctionable) {
3945 query.append(WHERE_AND);
3946 }
3947
3948 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3949
3950 conjunctionable = true;
3951
3952 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3953 if (conjunctionable) {
3954 query.append(WHERE_AND);
3955 }
3956
3957 query.append(StringPool.OPEN_PARENTHESIS);
3958
3959 for (int i = 0; i < parentCategoryIds.length; i++) {
3960 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3961
3962 if ((i + 1) < parentCategoryIds.length) {
3963 query.append(WHERE_OR);
3964 }
3965 }
3966
3967 query.append(StringPool.CLOSE_PARENTHESIS);
3968
3969 conjunctionable = true;
3970 }
3971
3972 String sql = query.toString();
3973
3974 Session session = null;
3975
3976 try {
3977 session = openSession();
3978
3979 Query q = session.createQuery(sql);
3980
3981 QueryPos qPos = QueryPos.getInstance(q);
3982
3983 qPos.add(groupId);
3984
3985 if (parentCategoryIds != null) {
3986 qPos.add(parentCategoryIds);
3987 }
3988
3989 count = (Long)q.uniqueResult();
3990
3991 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3992 finderArgs, count);
3993 }
3994 catch (Exception e) {
3995 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
3996 finderArgs);
3997
3998 throw processException(e);
3999 }
4000 finally {
4001 closeSession(session);
4002 }
4003 }
4004
4005 return count.intValue();
4006 }
4007
4008
4016 public int filterCountByG_P(long groupId, long parentCategoryId)
4017 throws SystemException {
4018 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4019 return countByG_P(groupId, parentCategoryId);
4020 }
4021
4022 StringBundler query = new StringBundler(3);
4023
4024 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4025
4026 query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4027
4028 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4029
4030 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4031 MBCategory.class.getName(),
4032 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4033
4034 Session session = null;
4035
4036 try {
4037 session = openSession();
4038
4039 SQLQuery q = session.createSQLQuery(sql);
4040
4041 q.addScalar(COUNT_COLUMN_NAME,
4042 com.liferay.portal.kernel.dao.orm.Type.LONG);
4043
4044 QueryPos qPos = QueryPos.getInstance(q);
4045
4046 qPos.add(groupId);
4047
4048 qPos.add(parentCategoryId);
4049
4050 Long count = (Long)q.uniqueResult();
4051
4052 return count.intValue();
4053 }
4054 catch (Exception e) {
4055 throw processException(e);
4056 }
4057 finally {
4058 closeSession(session);
4059 }
4060 }
4061
4062
4070 public int filterCountByG_P(long groupId, long[] parentCategoryIds)
4071 throws SystemException {
4072 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4073 return countByG_P(groupId, parentCategoryIds);
4074 }
4075
4076 StringBundler query = new StringBundler();
4077
4078 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4079
4080 boolean conjunctionable = false;
4081
4082 if (conjunctionable) {
4083 query.append(WHERE_AND);
4084 }
4085
4086 query.append(_FINDER_COLUMN_G_P_GROUPID_5);
4087
4088 conjunctionable = true;
4089
4090 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
4091 if (conjunctionable) {
4092 query.append(WHERE_AND);
4093 }
4094
4095 query.append(StringPool.OPEN_PARENTHESIS);
4096
4097 for (int i = 0; i < parentCategoryIds.length; i++) {
4098 query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
4099
4100 if ((i + 1) < parentCategoryIds.length) {
4101 query.append(WHERE_OR);
4102 }
4103 }
4104
4105 query.append(StringPool.CLOSE_PARENTHESIS);
4106
4107 conjunctionable = true;
4108 }
4109
4110 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4111 MBCategory.class.getName(),
4112 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4113
4114 Session session = null;
4115
4116 try {
4117 session = openSession();
4118
4119 SQLQuery q = session.createSQLQuery(sql);
4120
4121 q.addScalar(COUNT_COLUMN_NAME,
4122 com.liferay.portal.kernel.dao.orm.Type.LONG);
4123
4124 QueryPos qPos = QueryPos.getInstance(q);
4125
4126 qPos.add(groupId);
4127
4128 if (parentCategoryIds != null) {
4129 qPos.add(parentCategoryIds);
4130 }
4131
4132 Long count = (Long)q.uniqueResult();
4133
4134 return count.intValue();
4135 }
4136 catch (Exception e) {
4137 throw processException(e);
4138 }
4139 finally {
4140 closeSession(session);
4141 }
4142 }
4143
4144 private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4145 private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
4146 removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
4147 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4148 private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
4149 removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
4150 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4151 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4152 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4153 new String[] {
4154 Long.class.getName(), Integer.class.getName(),
4155
4156 Integer.class.getName(), Integer.class.getName(),
4157 OrderByComparator.class.getName()
4158 });
4159 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4160 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4161 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4162 new String[] { Long.class.getName(), Integer.class.getName() },
4163 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
4164 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
4165 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4166 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
4167 public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4168 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4169 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4170 new String[] { Long.class.getName(), Integer.class.getName() });
4171
4172
4180 public List<MBCategory> findByG_S(long groupId, int status)
4181 throws SystemException {
4182 return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4183 null);
4184 }
4185
4186
4200 public List<MBCategory> findByG_S(long groupId, int status, int start,
4201 int end) throws SystemException {
4202 return findByG_S(groupId, status, start, end, null);
4203 }
4204
4205
4220 public List<MBCategory> findByG_S(long groupId, int status, int start,
4221 int end, OrderByComparator orderByComparator) throws SystemException {
4222 boolean pagination = true;
4223 FinderPath finderPath = null;
4224 Object[] finderArgs = null;
4225
4226 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4227 (orderByComparator == null)) {
4228 pagination = false;
4229 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4230 finderArgs = new Object[] { groupId, status };
4231 }
4232 else {
4233 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4234 finderArgs = new Object[] {
4235 groupId, status,
4236
4237 start, end, orderByComparator
4238 };
4239 }
4240
4241 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
4242 finderArgs, this);
4243
4244 if ((list != null) && !list.isEmpty()) {
4245 for (MBCategory mbCategory : list) {
4246 if ((groupId != mbCategory.getGroupId()) ||
4247 (status != mbCategory.getStatus())) {
4248 list = null;
4249
4250 break;
4251 }
4252 }
4253 }
4254
4255 if (list == null) {
4256 StringBundler query = null;
4257
4258 if (orderByComparator != null) {
4259 query = new StringBundler(4 +
4260 (orderByComparator.getOrderByFields().length * 3));
4261 }
4262 else {
4263 query = new StringBundler(4);
4264 }
4265
4266 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4267
4268 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4269
4270 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4271
4272 if (orderByComparator != null) {
4273 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4274 orderByComparator);
4275 }
4276 else
4277 if (pagination) {
4278 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4279 }
4280
4281 String sql = query.toString();
4282
4283 Session session = null;
4284
4285 try {
4286 session = openSession();
4287
4288 Query q = session.createQuery(sql);
4289
4290 QueryPos qPos = QueryPos.getInstance(q);
4291
4292 qPos.add(groupId);
4293
4294 qPos.add(status);
4295
4296 if (!pagination) {
4297 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4298 start, end, false);
4299
4300 Collections.sort(list);
4301
4302 list = new UnmodifiableList<MBCategory>(list);
4303 }
4304 else {
4305 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4306 start, end);
4307 }
4308
4309 cacheResult(list);
4310
4311 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4312 }
4313 catch (Exception e) {
4314 FinderCacheUtil.removeResult(finderPath, finderArgs);
4315
4316 throw processException(e);
4317 }
4318 finally {
4319 closeSession(session);
4320 }
4321 }
4322
4323 return list;
4324 }
4325
4326
4336 public MBCategory findByG_S_First(long groupId, int status,
4337 OrderByComparator orderByComparator)
4338 throws NoSuchCategoryException, SystemException {
4339 MBCategory mbCategory = fetchByG_S_First(groupId, status,
4340 orderByComparator);
4341
4342 if (mbCategory != null) {
4343 return mbCategory;
4344 }
4345
4346 StringBundler msg = new StringBundler(6);
4347
4348 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4349
4350 msg.append("groupId=");
4351 msg.append(groupId);
4352
4353 msg.append(", status=");
4354 msg.append(status);
4355
4356 msg.append(StringPool.CLOSE_CURLY_BRACE);
4357
4358 throw new NoSuchCategoryException(msg.toString());
4359 }
4360
4361
4370 public MBCategory fetchByG_S_First(long groupId, int status,
4371 OrderByComparator orderByComparator) throws SystemException {
4372 List<MBCategory> list = findByG_S(groupId, status, 0, 1,
4373 orderByComparator);
4374
4375 if (!list.isEmpty()) {
4376 return list.get(0);
4377 }
4378
4379 return null;
4380 }
4381
4382
4392 public MBCategory findByG_S_Last(long groupId, int status,
4393 OrderByComparator orderByComparator)
4394 throws NoSuchCategoryException, SystemException {
4395 MBCategory mbCategory = fetchByG_S_Last(groupId, status,
4396 orderByComparator);
4397
4398 if (mbCategory != null) {
4399 return mbCategory;
4400 }
4401
4402 StringBundler msg = new StringBundler(6);
4403
4404 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4405
4406 msg.append("groupId=");
4407 msg.append(groupId);
4408
4409 msg.append(", status=");
4410 msg.append(status);
4411
4412 msg.append(StringPool.CLOSE_CURLY_BRACE);
4413
4414 throw new NoSuchCategoryException(msg.toString());
4415 }
4416
4417
4426 public MBCategory fetchByG_S_Last(long groupId, int status,
4427 OrderByComparator orderByComparator) throws SystemException {
4428 int count = countByG_S(groupId, status);
4429
4430 List<MBCategory> list = findByG_S(groupId, status, count - 1, count,
4431 orderByComparator);
4432
4433 if (!list.isEmpty()) {
4434 return list.get(0);
4435 }
4436
4437 return null;
4438 }
4439
4440
4451 public MBCategory[] findByG_S_PrevAndNext(long categoryId, long groupId,
4452 int status, OrderByComparator orderByComparator)
4453 throws NoSuchCategoryException, SystemException {
4454 MBCategory mbCategory = findByPrimaryKey(categoryId);
4455
4456 Session session = null;
4457
4458 try {
4459 session = openSession();
4460
4461 MBCategory[] array = new MBCategoryImpl[3];
4462
4463 array[0] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4464 status, orderByComparator, true);
4465
4466 array[1] = mbCategory;
4467
4468 array[2] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4469 status, orderByComparator, false);
4470
4471 return array;
4472 }
4473 catch (Exception e) {
4474 throw processException(e);
4475 }
4476 finally {
4477 closeSession(session);
4478 }
4479 }
4480
4481 protected MBCategory getByG_S_PrevAndNext(Session session,
4482 MBCategory mbCategory, long groupId, int status,
4483 OrderByComparator orderByComparator, boolean previous) {
4484 StringBundler query = null;
4485
4486 if (orderByComparator != null) {
4487 query = new StringBundler(6 +
4488 (orderByComparator.getOrderByFields().length * 6));
4489 }
4490 else {
4491 query = new StringBundler(3);
4492 }
4493
4494 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4495
4496 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4497
4498 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4499
4500 if (orderByComparator != null) {
4501 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4502
4503 if (orderByConditionFields.length > 0) {
4504 query.append(WHERE_AND);
4505 }
4506
4507 for (int i = 0; i < orderByConditionFields.length; i++) {
4508 query.append(_ORDER_BY_ENTITY_ALIAS);
4509 query.append(orderByConditionFields[i]);
4510
4511 if ((i + 1) < orderByConditionFields.length) {
4512 if (orderByComparator.isAscending() ^ previous) {
4513 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4514 }
4515 else {
4516 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4517 }
4518 }
4519 else {
4520 if (orderByComparator.isAscending() ^ previous) {
4521 query.append(WHERE_GREATER_THAN);
4522 }
4523 else {
4524 query.append(WHERE_LESSER_THAN);
4525 }
4526 }
4527 }
4528
4529 query.append(ORDER_BY_CLAUSE);
4530
4531 String[] orderByFields = orderByComparator.getOrderByFields();
4532
4533 for (int i = 0; i < orderByFields.length; i++) {
4534 query.append(_ORDER_BY_ENTITY_ALIAS);
4535 query.append(orderByFields[i]);
4536
4537 if ((i + 1) < orderByFields.length) {
4538 if (orderByComparator.isAscending() ^ previous) {
4539 query.append(ORDER_BY_ASC_HAS_NEXT);
4540 }
4541 else {
4542 query.append(ORDER_BY_DESC_HAS_NEXT);
4543 }
4544 }
4545 else {
4546 if (orderByComparator.isAscending() ^ previous) {
4547 query.append(ORDER_BY_ASC);
4548 }
4549 else {
4550 query.append(ORDER_BY_DESC);
4551 }
4552 }
4553 }
4554 }
4555 else {
4556 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4557 }
4558
4559 String sql = query.toString();
4560
4561 Query q = session.createQuery(sql);
4562
4563 q.setFirstResult(0);
4564 q.setMaxResults(2);
4565
4566 QueryPos qPos = QueryPos.getInstance(q);
4567
4568 qPos.add(groupId);
4569
4570 qPos.add(status);
4571
4572 if (orderByComparator != null) {
4573 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4574
4575 for (Object value : values) {
4576 qPos.add(value);
4577 }
4578 }
4579
4580 List<MBCategory> list = q.list();
4581
4582 if (list.size() == 2) {
4583 return list.get(1);
4584 }
4585 else {
4586 return null;
4587 }
4588 }
4589
4590
4598 public List<MBCategory> filterFindByG_S(long groupId, int status)
4599 throws SystemException {
4600 return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4601 QueryUtil.ALL_POS, null);
4602 }
4603
4604
4618 public List<MBCategory> filterFindByG_S(long groupId, int status,
4619 int start, int end) throws SystemException {
4620 return filterFindByG_S(groupId, status, start, end, null);
4621 }
4622
4623
4638 public List<MBCategory> filterFindByG_S(long groupId, int status,
4639 int start, int end, OrderByComparator orderByComparator)
4640 throws SystemException {
4641 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4642 return findByG_S(groupId, status, start, end, orderByComparator);
4643 }
4644
4645 StringBundler query = null;
4646
4647 if (orderByComparator != null) {
4648 query = new StringBundler(4 +
4649 (orderByComparator.getOrderByFields().length * 3));
4650 }
4651 else {
4652 query = new StringBundler(4);
4653 }
4654
4655 if (getDB().isSupportsInlineDistinct()) {
4656 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4657 }
4658 else {
4659 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4660 }
4661
4662 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4663
4664 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4665
4666 if (!getDB().isSupportsInlineDistinct()) {
4667 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4668 }
4669
4670 if (orderByComparator != null) {
4671 if (getDB().isSupportsInlineDistinct()) {
4672 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4673 orderByComparator, true);
4674 }
4675 else {
4676 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4677 orderByComparator, true);
4678 }
4679 }
4680 else {
4681 if (getDB().isSupportsInlineDistinct()) {
4682 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4683 }
4684 else {
4685 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4686 }
4687 }
4688
4689 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4690 MBCategory.class.getName(),
4691 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4692
4693 Session session = null;
4694
4695 try {
4696 session = openSession();
4697
4698 SQLQuery q = session.createSQLQuery(sql);
4699
4700 if (getDB().isSupportsInlineDistinct()) {
4701 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4702 }
4703 else {
4704 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4705 }
4706
4707 QueryPos qPos = QueryPos.getInstance(q);
4708
4709 qPos.add(groupId);
4710
4711 qPos.add(status);
4712
4713 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
4714 }
4715 catch (Exception e) {
4716 throw processException(e);
4717 }
4718 finally {
4719 closeSession(session);
4720 }
4721 }
4722
4723
4734 public MBCategory[] filterFindByG_S_PrevAndNext(long categoryId,
4735 long groupId, int status, OrderByComparator orderByComparator)
4736 throws NoSuchCategoryException, SystemException {
4737 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4738 return findByG_S_PrevAndNext(categoryId, groupId, status,
4739 orderByComparator);
4740 }
4741
4742 MBCategory mbCategory = findByPrimaryKey(categoryId);
4743
4744 Session session = null;
4745
4746 try {
4747 session = openSession();
4748
4749 MBCategory[] array = new MBCategoryImpl[3];
4750
4751 array[0] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4752 status, orderByComparator, true);
4753
4754 array[1] = mbCategory;
4755
4756 array[2] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4757 status, orderByComparator, false);
4758
4759 return array;
4760 }
4761 catch (Exception e) {
4762 throw processException(e);
4763 }
4764 finally {
4765 closeSession(session);
4766 }
4767 }
4768
4769 protected MBCategory filterGetByG_S_PrevAndNext(Session session,
4770 MBCategory mbCategory, long groupId, int status,
4771 OrderByComparator orderByComparator, boolean previous) {
4772 StringBundler query = null;
4773
4774 if (orderByComparator != null) {
4775 query = new StringBundler(6 +
4776 (orderByComparator.getOrderByFields().length * 6));
4777 }
4778 else {
4779 query = new StringBundler(3);
4780 }
4781
4782 if (getDB().isSupportsInlineDistinct()) {
4783 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4784 }
4785 else {
4786 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4787 }
4788
4789 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4790
4791 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4792
4793 if (!getDB().isSupportsInlineDistinct()) {
4794 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4795 }
4796
4797 if (orderByComparator != null) {
4798 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4799
4800 if (orderByConditionFields.length > 0) {
4801 query.append(WHERE_AND);
4802 }
4803
4804 for (int i = 0; i < orderByConditionFields.length; i++) {
4805 if (getDB().isSupportsInlineDistinct()) {
4806 query.append(_ORDER_BY_ENTITY_ALIAS);
4807 }
4808 else {
4809 query.append(_ORDER_BY_ENTITY_TABLE);
4810 }
4811
4812 query.append(orderByConditionFields[i]);
4813
4814 if ((i + 1) < orderByConditionFields.length) {
4815 if (orderByComparator.isAscending() ^ previous) {
4816 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4817 }
4818 else {
4819 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4820 }
4821 }
4822 else {
4823 if (orderByComparator.isAscending() ^ previous) {
4824 query.append(WHERE_GREATER_THAN);
4825 }
4826 else {
4827 query.append(WHERE_LESSER_THAN);
4828 }
4829 }
4830 }
4831
4832 query.append(ORDER_BY_CLAUSE);
4833
4834 String[] orderByFields = orderByComparator.getOrderByFields();
4835
4836 for (int i = 0; i < orderByFields.length; i++) {
4837 if (getDB().isSupportsInlineDistinct()) {
4838 query.append(_ORDER_BY_ENTITY_ALIAS);
4839 }
4840 else {
4841 query.append(_ORDER_BY_ENTITY_TABLE);
4842 }
4843
4844 query.append(orderByFields[i]);
4845
4846 if ((i + 1) < orderByFields.length) {
4847 if (orderByComparator.isAscending() ^ previous) {
4848 query.append(ORDER_BY_ASC_HAS_NEXT);
4849 }
4850 else {
4851 query.append(ORDER_BY_DESC_HAS_NEXT);
4852 }
4853 }
4854 else {
4855 if (orderByComparator.isAscending() ^ previous) {
4856 query.append(ORDER_BY_ASC);
4857 }
4858 else {
4859 query.append(ORDER_BY_DESC);
4860 }
4861 }
4862 }
4863 }
4864 else {
4865 if (getDB().isSupportsInlineDistinct()) {
4866 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4867 }
4868 else {
4869 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4870 }
4871 }
4872
4873 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4874 MBCategory.class.getName(),
4875 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4876
4877 SQLQuery q = session.createSQLQuery(sql);
4878
4879 q.setFirstResult(0);
4880 q.setMaxResults(2);
4881
4882 if (getDB().isSupportsInlineDistinct()) {
4883 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4884 }
4885 else {
4886 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4887 }
4888
4889 QueryPos qPos = QueryPos.getInstance(q);
4890
4891 qPos.add(groupId);
4892
4893 qPos.add(status);
4894
4895 if (orderByComparator != null) {
4896 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4897
4898 for (Object value : values) {
4899 qPos.add(value);
4900 }
4901 }
4902
4903 List<MBCategory> list = q.list();
4904
4905 if (list.size() == 2) {
4906 return list.get(1);
4907 }
4908 else {
4909 return null;
4910 }
4911 }
4912
4913
4920 public void removeByG_S(long groupId, int status) throws SystemException {
4921 for (MBCategory mbCategory : findByG_S(groupId, status,
4922 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4923 remove(mbCategory);
4924 }
4925 }
4926
4927
4935 public int countByG_S(long groupId, int status) throws SystemException {
4936 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
4937
4938 Object[] finderArgs = new Object[] { groupId, status };
4939
4940 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4941 this);
4942
4943 if (count == null) {
4944 StringBundler query = new StringBundler(3);
4945
4946 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4947
4948 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4949
4950 query.append(_FINDER_COLUMN_G_S_STATUS_2);
4951
4952 String sql = query.toString();
4953
4954 Session session = null;
4955
4956 try {
4957 session = openSession();
4958
4959 Query q = session.createQuery(sql);
4960
4961 QueryPos qPos = QueryPos.getInstance(q);
4962
4963 qPos.add(groupId);
4964
4965 qPos.add(status);
4966
4967 count = (Long)q.uniqueResult();
4968
4969 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4970 }
4971 catch (Exception e) {
4972 FinderCacheUtil.removeResult(finderPath, finderArgs);
4973
4974 throw processException(e);
4975 }
4976 finally {
4977 closeSession(session);
4978 }
4979 }
4980
4981 return count.intValue();
4982 }
4983
4984
4992 public int filterCountByG_S(long groupId, int status)
4993 throws SystemException {
4994 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4995 return countByG_S(groupId, status);
4996 }
4997
4998 StringBundler query = new StringBundler(3);
4999
5000 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
5001
5002 query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5003
5004 query.append(_FINDER_COLUMN_G_S_STATUS_2);
5005
5006 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5007 MBCategory.class.getName(),
5008 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5009
5010 Session session = null;
5011
5012 try {
5013 session = openSession();
5014
5015 SQLQuery q = session.createSQLQuery(sql);
5016
5017 q.addScalar(COUNT_COLUMN_NAME,
5018 com.liferay.portal.kernel.dao.orm.Type.LONG);
5019
5020 QueryPos qPos = QueryPos.getInstance(q);
5021
5022 qPos.add(groupId);
5023
5024 qPos.add(status);
5025
5026 Long count = (Long)q.uniqueResult();
5027
5028 return count.intValue();
5029 }
5030 catch (Exception e) {
5031 throw processException(e);
5032 }
5033 finally {
5034 closeSession(session);
5035 }
5036 }
5037
5038 private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
5039 private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbCategory.status = ?";
5040 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5041 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5042 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
5043 new String[] {
5044 Long.class.getName(), Integer.class.getName(),
5045
5046 Integer.class.getName(), Integer.class.getName(),
5047 OrderByComparator.class.getName()
5048 });
5049 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5050 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5051 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
5052 new String[] { Long.class.getName(), Integer.class.getName() },
5053 MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
5054 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5055 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5056 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5057 public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5058 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5059 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
5060 new String[] { Long.class.getName(), Integer.class.getName() });
5061
5062
5070 public List<MBCategory> findByC_S(long companyId, int status)
5071 throws SystemException {
5072 return findByC_S(companyId, status, QueryUtil.ALL_POS,
5073 QueryUtil.ALL_POS, null);
5074 }
5075
5076
5090 public List<MBCategory> findByC_S(long companyId, int status, int start,
5091 int end) throws SystemException {
5092 return findByC_S(companyId, status, start, end, null);
5093 }
5094
5095
5110 public List<MBCategory> findByC_S(long companyId, int status, int start,
5111 int end, OrderByComparator orderByComparator) throws SystemException {
5112 boolean pagination = true;
5113 FinderPath finderPath = null;
5114 Object[] finderArgs = null;
5115
5116 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5117 (orderByComparator == null)) {
5118 pagination = false;
5119 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
5120 finderArgs = new Object[] { companyId, status };
5121 }
5122 else {
5123 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
5124 finderArgs = new Object[] {
5125 companyId, status,
5126
5127 start, end, orderByComparator
5128 };
5129 }
5130
5131 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5132 finderArgs, this);
5133
5134 if ((list != null) && !list.isEmpty()) {
5135 for (MBCategory mbCategory : list) {
5136 if ((companyId != mbCategory.getCompanyId()) ||
5137 (status != mbCategory.getStatus())) {
5138 list = null;
5139
5140 break;
5141 }
5142 }
5143 }
5144
5145 if (list == null) {
5146 StringBundler query = null;
5147
5148 if (orderByComparator != null) {
5149 query = new StringBundler(4 +
5150 (orderByComparator.getOrderByFields().length * 3));
5151 }
5152 else {
5153 query = new StringBundler(4);
5154 }
5155
5156 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5157
5158 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5159
5160 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5161
5162 if (orderByComparator != null) {
5163 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5164 orderByComparator);
5165 }
5166 else
5167 if (pagination) {
5168 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5169 }
5170
5171 String sql = query.toString();
5172
5173 Session session = null;
5174
5175 try {
5176 session = openSession();
5177
5178 Query q = session.createQuery(sql);
5179
5180 QueryPos qPos = QueryPos.getInstance(q);
5181
5182 qPos.add(companyId);
5183
5184 qPos.add(status);
5185
5186 if (!pagination) {
5187 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5188 start, end, false);
5189
5190 Collections.sort(list);
5191
5192 list = new UnmodifiableList<MBCategory>(list);
5193 }
5194 else {
5195 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5196 start, end);
5197 }
5198
5199 cacheResult(list);
5200
5201 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5202 }
5203 catch (Exception e) {
5204 FinderCacheUtil.removeResult(finderPath, finderArgs);
5205
5206 throw processException(e);
5207 }
5208 finally {
5209 closeSession(session);
5210 }
5211 }
5212
5213 return list;
5214 }
5215
5216
5226 public MBCategory findByC_S_First(long companyId, int status,
5227 OrderByComparator orderByComparator)
5228 throws NoSuchCategoryException, SystemException {
5229 MBCategory mbCategory = fetchByC_S_First(companyId, status,
5230 orderByComparator);
5231
5232 if (mbCategory != null) {
5233 return mbCategory;
5234 }
5235
5236 StringBundler msg = new StringBundler(6);
5237
5238 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5239
5240 msg.append("companyId=");
5241 msg.append(companyId);
5242
5243 msg.append(", status=");
5244 msg.append(status);
5245
5246 msg.append(StringPool.CLOSE_CURLY_BRACE);
5247
5248 throw new NoSuchCategoryException(msg.toString());
5249 }
5250
5251
5260 public MBCategory fetchByC_S_First(long companyId, int status,
5261 OrderByComparator orderByComparator) throws SystemException {
5262 List<MBCategory> list = findByC_S(companyId, status, 0, 1,
5263 orderByComparator);
5264
5265 if (!list.isEmpty()) {
5266 return list.get(0);
5267 }
5268
5269 return null;
5270 }
5271
5272
5282 public MBCategory findByC_S_Last(long companyId, int status,
5283 OrderByComparator orderByComparator)
5284 throws NoSuchCategoryException, SystemException {
5285 MBCategory mbCategory = fetchByC_S_Last(companyId, status,
5286 orderByComparator);
5287
5288 if (mbCategory != null) {
5289 return mbCategory;
5290 }
5291
5292 StringBundler msg = new StringBundler(6);
5293
5294 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5295
5296 msg.append("companyId=");
5297 msg.append(companyId);
5298
5299 msg.append(", status=");
5300 msg.append(status);
5301
5302 msg.append(StringPool.CLOSE_CURLY_BRACE);
5303
5304 throw new NoSuchCategoryException(msg.toString());
5305 }
5306
5307
5316 public MBCategory fetchByC_S_Last(long companyId, int status,
5317 OrderByComparator orderByComparator) throws SystemException {
5318 int count = countByC_S(companyId, status);
5319
5320 List<MBCategory> list = findByC_S(companyId, status, count - 1, count,
5321 orderByComparator);
5322
5323 if (!list.isEmpty()) {
5324 return list.get(0);
5325 }
5326
5327 return null;
5328 }
5329
5330
5341 public MBCategory[] findByC_S_PrevAndNext(long categoryId, long companyId,
5342 int status, OrderByComparator orderByComparator)
5343 throws NoSuchCategoryException, SystemException {
5344 MBCategory mbCategory = findByPrimaryKey(categoryId);
5345
5346 Session session = null;
5347
5348 try {
5349 session = openSession();
5350
5351 MBCategory[] array = new MBCategoryImpl[3];
5352
5353 array[0] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5354 status, orderByComparator, true);
5355
5356 array[1] = mbCategory;
5357
5358 array[2] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5359 status, orderByComparator, false);
5360
5361 return array;
5362 }
5363 catch (Exception e) {
5364 throw processException(e);
5365 }
5366 finally {
5367 closeSession(session);
5368 }
5369 }
5370
5371 protected MBCategory getByC_S_PrevAndNext(Session session,
5372 MBCategory mbCategory, long companyId, int status,
5373 OrderByComparator orderByComparator, boolean previous) {
5374 StringBundler query = null;
5375
5376 if (orderByComparator != null) {
5377 query = new StringBundler(6 +
5378 (orderByComparator.getOrderByFields().length * 6));
5379 }
5380 else {
5381 query = new StringBundler(3);
5382 }
5383
5384 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5385
5386 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5387
5388 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5389
5390 if (orderByComparator != null) {
5391 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5392
5393 if (orderByConditionFields.length > 0) {
5394 query.append(WHERE_AND);
5395 }
5396
5397 for (int i = 0; i < orderByConditionFields.length; i++) {
5398 query.append(_ORDER_BY_ENTITY_ALIAS);
5399 query.append(orderByConditionFields[i]);
5400
5401 if ((i + 1) < orderByConditionFields.length) {
5402 if (orderByComparator.isAscending() ^ previous) {
5403 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5404 }
5405 else {
5406 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5407 }
5408 }
5409 else {
5410 if (orderByComparator.isAscending() ^ previous) {
5411 query.append(WHERE_GREATER_THAN);
5412 }
5413 else {
5414 query.append(WHERE_LESSER_THAN);
5415 }
5416 }
5417 }
5418
5419 query.append(ORDER_BY_CLAUSE);
5420
5421 String[] orderByFields = orderByComparator.getOrderByFields();
5422
5423 for (int i = 0; i < orderByFields.length; i++) {
5424 query.append(_ORDER_BY_ENTITY_ALIAS);
5425 query.append(orderByFields[i]);
5426
5427 if ((i + 1) < orderByFields.length) {
5428 if (orderByComparator.isAscending() ^ previous) {
5429 query.append(ORDER_BY_ASC_HAS_NEXT);
5430 }
5431 else {
5432 query.append(ORDER_BY_DESC_HAS_NEXT);
5433 }
5434 }
5435 else {
5436 if (orderByComparator.isAscending() ^ previous) {
5437 query.append(ORDER_BY_ASC);
5438 }
5439 else {
5440 query.append(ORDER_BY_DESC);
5441 }
5442 }
5443 }
5444 }
5445 else {
5446 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5447 }
5448
5449 String sql = query.toString();
5450
5451 Query q = session.createQuery(sql);
5452
5453 q.setFirstResult(0);
5454 q.setMaxResults(2);
5455
5456 QueryPos qPos = QueryPos.getInstance(q);
5457
5458 qPos.add(companyId);
5459
5460 qPos.add(status);
5461
5462 if (orderByComparator != null) {
5463 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5464
5465 for (Object value : values) {
5466 qPos.add(value);
5467 }
5468 }
5469
5470 List<MBCategory> list = q.list();
5471
5472 if (list.size() == 2) {
5473 return list.get(1);
5474 }
5475 else {
5476 return null;
5477 }
5478 }
5479
5480
5487 public void removeByC_S(long companyId, int status)
5488 throws SystemException {
5489 for (MBCategory mbCategory : findByC_S(companyId, status,
5490 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5491 remove(mbCategory);
5492 }
5493 }
5494
5495
5503 public int countByC_S(long companyId, int status) throws SystemException {
5504 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
5505
5506 Object[] finderArgs = new Object[] { companyId, status };
5507
5508 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5509 this);
5510
5511 if (count == null) {
5512 StringBundler query = new StringBundler(3);
5513
5514 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5515
5516 query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5517
5518 query.append(_FINDER_COLUMN_C_S_STATUS_2);
5519
5520 String sql = query.toString();
5521
5522 Session session = null;
5523
5524 try {
5525 session = openSession();
5526
5527 Query q = session.createQuery(sql);
5528
5529 QueryPos qPos = QueryPos.getInstance(q);
5530
5531 qPos.add(companyId);
5532
5533 qPos.add(status);
5534
5535 count = (Long)q.uniqueResult();
5536
5537 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5538 }
5539 catch (Exception e) {
5540 FinderCacheUtil.removeResult(finderPath, finderArgs);
5541
5542 throw processException(e);
5543 }
5544 finally {
5545 closeSession(session);
5546 }
5547 }
5548
5549 return count.intValue();
5550 }
5551
5552 private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbCategory.companyId = ? AND ";
5553 private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbCategory.status = ?";
5554 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5555 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5556 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_S",
5557 new String[] {
5558 Long.class.getName(), Long.class.getName(),
5559 Integer.class.getName(),
5560
5561 Integer.class.getName(), Integer.class.getName(),
5562 OrderByComparator.class.getName()
5563 });
5564 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5565 MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5566 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_S",
5567 new String[] {
5568 Long.class.getName(), Long.class.getName(),
5569 Integer.class.getName()
5570 },
5571 MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
5572 MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5573 MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5574 MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5575 public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5576 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5577 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
5578 new String[] {
5579 Long.class.getName(), Long.class.getName(),
5580 Integer.class.getName()
5581 });
5582 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5583 MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5584 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_S",
5585 new String[] {
5586 Long.class.getName(), Long.class.getName(),
5587 Integer.class.getName()
5588 });
5589
5590
5599 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5600 int status) throws SystemException {
5601 return findByG_P_S(groupId, parentCategoryId, status,
5602 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5603 }
5604
5605
5620 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5621 int status, int start, int end) throws SystemException {
5622 return findByG_P_S(groupId, parentCategoryId, status, start, end, null);
5623 }
5624
5625
5641 public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5642 int status, int start, int end, OrderByComparator orderByComparator)
5643 throws SystemException {
5644 boolean pagination = true;
5645 FinderPath finderPath = null;
5646 Object[] finderArgs = null;
5647
5648 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5649 (orderByComparator == null)) {
5650 pagination = false;
5651 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
5652 finderArgs = new Object[] { groupId, parentCategoryId, status };
5653 }
5654 else {
5655 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
5656 finderArgs = new Object[] {
5657 groupId, parentCategoryId, status,
5658
5659 start, end, orderByComparator
5660 };
5661 }
5662
5663 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5664 finderArgs, this);
5665
5666 if ((list != null) && !list.isEmpty()) {
5667 for (MBCategory mbCategory : list) {
5668 if ((groupId != mbCategory.getGroupId()) ||
5669 (parentCategoryId != mbCategory.getParentCategoryId()) ||
5670 (status != mbCategory.getStatus())) {
5671 list = null;
5672
5673 break;
5674 }
5675 }
5676 }
5677
5678 if (list == null) {
5679 StringBundler query = null;
5680
5681 if (orderByComparator != null) {
5682 query = new StringBundler(5 +
5683 (orderByComparator.getOrderByFields().length * 3));
5684 }
5685 else {
5686 query = new StringBundler(5);
5687 }
5688
5689 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5690
5691 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5692
5693 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
5694
5695 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5696
5697 if (orderByComparator != null) {
5698 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5699 orderByComparator);
5700 }
5701 else
5702 if (pagination) {
5703 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5704 }
5705
5706 String sql = query.toString();
5707
5708 Session session = null;
5709
5710 try {
5711 session = openSession();
5712
5713 Query q = session.createQuery(sql);
5714
5715 QueryPos qPos = QueryPos.getInstance(q);
5716
5717 qPos.add(groupId);
5718
5719 qPos.add(parentCategoryId);
5720
5721 qPos.add(status);
5722
5723 if (!pagination) {
5724 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5725 start, end, false);
5726
5727 Collections.sort(list);
5728
5729 list = new UnmodifiableList<MBCategory>(list);
5730 }
5731 else {
5732 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5733 start, end);
5734 }
5735
5736 cacheResult(list);
5737
5738 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5739 }
5740 catch (Exception e) {
5741 FinderCacheUtil.removeResult(finderPath, finderArgs);
5742
5743 throw processException(e);
5744 }
5745 finally {
5746 closeSession(session);
5747 }
5748 }
5749
5750 return list;
5751 }
5752
5753
5764 public MBCategory findByG_P_S_First(long groupId, long parentCategoryId,
5765 int status, OrderByComparator orderByComparator)
5766 throws NoSuchCategoryException, SystemException {
5767 MBCategory mbCategory = fetchByG_P_S_First(groupId, parentCategoryId,
5768 status, orderByComparator);
5769
5770 if (mbCategory != null) {
5771 return mbCategory;
5772 }
5773
5774 StringBundler msg = new StringBundler(8);
5775
5776 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5777
5778 msg.append("groupId=");
5779 msg.append(groupId);
5780
5781 msg.append(", parentCategoryId=");
5782 msg.append(parentCategoryId);
5783
5784 msg.append(", status=");
5785 msg.append(status);
5786
5787 msg.append(StringPool.CLOSE_CURLY_BRACE);
5788
5789 throw new NoSuchCategoryException(msg.toString());
5790 }
5791
5792
5802 public MBCategory fetchByG_P_S_First(long groupId, long parentCategoryId,
5803 int status, OrderByComparator orderByComparator)
5804 throws SystemException {
5805 List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
5806 0, 1, orderByComparator);
5807
5808 if (!list.isEmpty()) {
5809 return list.get(0);
5810 }
5811
5812 return null;
5813 }
5814
5815
5826 public MBCategory findByG_P_S_Last(long groupId, long parentCategoryId,
5827 int status, OrderByComparator orderByComparator)
5828 throws NoSuchCategoryException, SystemException {
5829 MBCategory mbCategory = fetchByG_P_S_Last(groupId, parentCategoryId,
5830 status, orderByComparator);
5831
5832 if (mbCategory != null) {
5833 return mbCategory;
5834 }
5835
5836 StringBundler msg = new StringBundler(8);
5837
5838 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5839
5840 msg.append("groupId=");
5841 msg.append(groupId);
5842
5843 msg.append(", parentCategoryId=");
5844 msg.append(parentCategoryId);
5845
5846 msg.append(", status=");
5847 msg.append(status);
5848
5849 msg.append(StringPool.CLOSE_CURLY_BRACE);
5850
5851 throw new NoSuchCategoryException(msg.toString());
5852 }
5853
5854
5864 public MBCategory fetchByG_P_S_Last(long groupId, long parentCategoryId,
5865 int status, OrderByComparator orderByComparator)
5866 throws SystemException {
5867 int count = countByG_P_S(groupId, parentCategoryId, status);
5868
5869 List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
5870 count - 1, count, orderByComparator);
5871
5872 if (!list.isEmpty()) {
5873 return list.get(0);
5874 }
5875
5876 return null;
5877 }
5878
5879
5891 public MBCategory[] findByG_P_S_PrevAndNext(long categoryId, long groupId,
5892 long parentCategoryId, int status, OrderByComparator orderByComparator)
5893 throws NoSuchCategoryException, SystemException {
5894 MBCategory mbCategory = findByPrimaryKey(categoryId);
5895
5896 Session session = null;
5897
5898 try {
5899 session = openSession();
5900
5901 MBCategory[] array = new MBCategoryImpl[3];
5902
5903 array[0] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
5904 parentCategoryId, status, orderByComparator, true);
5905
5906 array[1] = mbCategory;
5907
5908 array[2] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
5909 parentCategoryId, status, orderByComparator, false);
5910
5911 return array;
5912 }
5913 catch (Exception e) {
5914 throw processException(e);
5915 }
5916 finally {
5917 closeSession(session);
5918 }
5919 }
5920
5921 protected MBCategory getByG_P_S_PrevAndNext(Session session,
5922 MBCategory mbCategory, long groupId, long parentCategoryId, int status,
5923 OrderByComparator orderByComparator, boolean previous) {
5924 StringBundler query = null;
5925
5926 if (orderByComparator != null) {
5927 query = new StringBundler(6 +
5928 (orderByComparator.getOrderByFields().length * 6));
5929 }
5930 else {
5931 query = new StringBundler(3);
5932 }
5933
5934 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5935
5936 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5937
5938 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
5939
5940 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5941
5942 if (orderByComparator != null) {
5943 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5944
5945 if (orderByConditionFields.length > 0) {
5946 query.append(WHERE_AND);
5947 }
5948
5949 for (int i = 0; i < orderByConditionFields.length; i++) {
5950 query.append(_ORDER_BY_ENTITY_ALIAS);
5951 query.append(orderByConditionFields[i]);
5952
5953 if ((i + 1) < orderByConditionFields.length) {
5954 if (orderByComparator.isAscending() ^ previous) {
5955 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5956 }
5957 else {
5958 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5959 }
5960 }
5961 else {
5962 if (orderByComparator.isAscending() ^ previous) {
5963 query.append(WHERE_GREATER_THAN);
5964 }
5965 else {
5966 query.append(WHERE_LESSER_THAN);
5967 }
5968 }
5969 }
5970
5971 query.append(ORDER_BY_CLAUSE);
5972
5973 String[] orderByFields = orderByComparator.getOrderByFields();
5974
5975 for (int i = 0; i < orderByFields.length; i++) {
5976 query.append(_ORDER_BY_ENTITY_ALIAS);
5977 query.append(orderByFields[i]);
5978
5979 if ((i + 1) < orderByFields.length) {
5980 if (orderByComparator.isAscending() ^ previous) {
5981 query.append(ORDER_BY_ASC_HAS_NEXT);
5982 }
5983 else {
5984 query.append(ORDER_BY_DESC_HAS_NEXT);
5985 }
5986 }
5987 else {
5988 if (orderByComparator.isAscending() ^ previous) {
5989 query.append(ORDER_BY_ASC);
5990 }
5991 else {
5992 query.append(ORDER_BY_DESC);
5993 }
5994 }
5995 }
5996 }
5997 else {
5998 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5999 }
6000
6001 String sql = query.toString();
6002
6003 Query q = session.createQuery(sql);
6004
6005 q.setFirstResult(0);
6006 q.setMaxResults(2);
6007
6008 QueryPos qPos = QueryPos.getInstance(q);
6009
6010 qPos.add(groupId);
6011
6012 qPos.add(parentCategoryId);
6013
6014 qPos.add(status);
6015
6016 if (orderByComparator != null) {
6017 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
6018
6019 for (Object value : values) {
6020 qPos.add(value);
6021 }
6022 }
6023
6024 List<MBCategory> list = q.list();
6025
6026 if (list.size() == 2) {
6027 return list.get(1);
6028 }
6029 else {
6030 return null;
6031 }
6032 }
6033
6034
6043 public List<MBCategory> filterFindByG_P_S(long groupId,
6044 long parentCategoryId, int status) throws SystemException {
6045 return filterFindByG_P_S(groupId, parentCategoryId, status,
6046 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6047 }
6048
6049
6064 public List<MBCategory> filterFindByG_P_S(long groupId,
6065 long parentCategoryId, int status, int start, int end)
6066 throws SystemException {
6067 return filterFindByG_P_S(groupId, parentCategoryId, status, start, end,
6068 null);
6069 }
6070
6071
6087 public List<MBCategory> filterFindByG_P_S(long groupId,
6088 long parentCategoryId, int status, int start, int end,
6089 OrderByComparator orderByComparator) throws SystemException {
6090 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6091 return findByG_P_S(groupId, parentCategoryId, status, start, end,
6092 orderByComparator);
6093 }
6094
6095 StringBundler query = null;
6096
6097 if (orderByComparator != null) {
6098 query = new StringBundler(5 +
6099 (orderByComparator.getOrderByFields().length * 3));
6100 }
6101 else {
6102 query = new StringBundler(5);
6103 }
6104
6105 if (getDB().isSupportsInlineDistinct()) {
6106 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6107 }
6108 else {
6109 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6110 }
6111
6112 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6113
6114 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6115
6116 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6117
6118 if (!getDB().isSupportsInlineDistinct()) {
6119 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6120 }
6121
6122 if (orderByComparator != null) {
6123 if (getDB().isSupportsInlineDistinct()) {
6124 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6125 orderByComparator, true);
6126 }
6127 else {
6128 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6129 orderByComparator, true);
6130 }
6131 }
6132 else {
6133 if (getDB().isSupportsInlineDistinct()) {
6134 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6135 }
6136 else {
6137 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6138 }
6139 }
6140
6141 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6142 MBCategory.class.getName(),
6143 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6144
6145 Session session = null;
6146
6147 try {
6148 session = openSession();
6149
6150 SQLQuery q = session.createSQLQuery(sql);
6151
6152 if (getDB().isSupportsInlineDistinct()) {
6153 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6154 }
6155 else {
6156 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6157 }
6158
6159 QueryPos qPos = QueryPos.getInstance(q);
6160
6161 qPos.add(groupId);
6162
6163 qPos.add(parentCategoryId);
6164
6165 qPos.add(status);
6166
6167 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6168 }
6169 catch (Exception e) {
6170 throw processException(e);
6171 }
6172 finally {
6173 closeSession(session);
6174 }
6175 }
6176
6177
6189 public MBCategory[] filterFindByG_P_S_PrevAndNext(long categoryId,
6190 long groupId, long parentCategoryId, int status,
6191 OrderByComparator orderByComparator)
6192 throws NoSuchCategoryException, SystemException {
6193 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6194 return findByG_P_S_PrevAndNext(categoryId, groupId,
6195 parentCategoryId, status, orderByComparator);
6196 }
6197
6198 MBCategory mbCategory = findByPrimaryKey(categoryId);
6199
6200 Session session = null;
6201
6202 try {
6203 session = openSession();
6204
6205 MBCategory[] array = new MBCategoryImpl[3];
6206
6207 array[0] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
6208 groupId, parentCategoryId, status, orderByComparator, true);
6209
6210 array[1] = mbCategory;
6211
6212 array[2] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
6213 groupId, parentCategoryId, status, orderByComparator, false);
6214
6215 return array;
6216 }
6217 catch (Exception e) {
6218 throw processException(e);
6219 }
6220 finally {
6221 closeSession(session);
6222 }
6223 }
6224
6225 protected MBCategory filterGetByG_P_S_PrevAndNext(Session session,
6226 MBCategory mbCategory, long groupId, long parentCategoryId, int status,
6227 OrderByComparator orderByComparator, boolean previous) {
6228 StringBundler query = null;
6229
6230 if (orderByComparator != null) {
6231 query = new StringBundler(6 +
6232 (orderByComparator.getOrderByFields().length * 6));
6233 }
6234 else {
6235 query = new StringBundler(3);
6236 }
6237
6238 if (getDB().isSupportsInlineDistinct()) {
6239 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6240 }
6241 else {
6242 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6243 }
6244
6245 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6246
6247 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6248
6249 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6250
6251 if (!getDB().isSupportsInlineDistinct()) {
6252 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6253 }
6254
6255 if (orderByComparator != null) {
6256 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6257
6258 if (orderByConditionFields.length > 0) {
6259 query.append(WHERE_AND);
6260 }
6261
6262 for (int i = 0; i < orderByConditionFields.length; i++) {
6263 if (getDB().isSupportsInlineDistinct()) {
6264 query.append(_ORDER_BY_ENTITY_ALIAS);
6265 }
6266 else {
6267 query.append(_ORDER_BY_ENTITY_TABLE);
6268 }
6269
6270 query.append(orderByConditionFields[i]);
6271
6272 if ((i + 1) < orderByConditionFields.length) {
6273 if (orderByComparator.isAscending() ^ previous) {
6274 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6275 }
6276 else {
6277 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6278 }
6279 }
6280 else {
6281 if (orderByComparator.isAscending() ^ previous) {
6282 query.append(WHERE_GREATER_THAN);
6283 }
6284 else {
6285 query.append(WHERE_LESSER_THAN);
6286 }
6287 }
6288 }
6289
6290 query.append(ORDER_BY_CLAUSE);
6291
6292 String[] orderByFields = orderByComparator.getOrderByFields();
6293
6294 for (int i = 0; i < orderByFields.length; i++) {
6295 if (getDB().isSupportsInlineDistinct()) {
6296 query.append(_ORDER_BY_ENTITY_ALIAS);
6297 }
6298 else {
6299 query.append(_ORDER_BY_ENTITY_TABLE);
6300 }
6301
6302 query.append(orderByFields[i]);
6303
6304 if ((i + 1) < orderByFields.length) {
6305 if (orderByComparator.isAscending() ^ previous) {
6306 query.append(ORDER_BY_ASC_HAS_NEXT);
6307 }
6308 else {
6309 query.append(ORDER_BY_DESC_HAS_NEXT);
6310 }
6311 }
6312 else {
6313 if (orderByComparator.isAscending() ^ previous) {
6314 query.append(ORDER_BY_ASC);
6315 }
6316 else {
6317 query.append(ORDER_BY_DESC);
6318 }
6319 }
6320 }
6321 }
6322 else {
6323 if (getDB().isSupportsInlineDistinct()) {
6324 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6325 }
6326 else {
6327 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6328 }
6329 }
6330
6331 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6332 MBCategory.class.getName(),
6333 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6334
6335 SQLQuery q = session.createSQLQuery(sql);
6336
6337 q.setFirstResult(0);
6338 q.setMaxResults(2);
6339
6340 if (getDB().isSupportsInlineDistinct()) {
6341 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6342 }
6343 else {
6344 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6345 }
6346
6347 QueryPos qPos = QueryPos.getInstance(q);
6348
6349 qPos.add(groupId);
6350
6351 qPos.add(parentCategoryId);
6352
6353 qPos.add(status);
6354
6355 if (orderByComparator != null) {
6356 Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
6357
6358 for (Object value : values) {
6359 qPos.add(value);
6360 }
6361 }
6362
6363 List<MBCategory> list = q.list();
6364
6365 if (list.size() == 2) {
6366 return list.get(1);
6367 }
6368 else {
6369 return null;
6370 }
6371 }
6372
6373
6382 public List<MBCategory> filterFindByG_P_S(long groupId,
6383 long[] parentCategoryIds, int status) throws SystemException {
6384 return filterFindByG_P_S(groupId, parentCategoryIds, status,
6385 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6386 }
6387
6388
6403 public List<MBCategory> filterFindByG_P_S(long groupId,
6404 long[] parentCategoryIds, int status, int start, int end)
6405 throws SystemException {
6406 return filterFindByG_P_S(groupId, parentCategoryIds, status, start,
6407 end, null);
6408 }
6409
6410
6426 public List<MBCategory> filterFindByG_P_S(long groupId,
6427 long[] parentCategoryIds, int status, int start, int end,
6428 OrderByComparator orderByComparator) throws SystemException {
6429 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6430 return findByG_P_S(groupId, parentCategoryIds, status, start, end,
6431 orderByComparator);
6432 }
6433
6434 StringBundler query = new StringBundler();
6435
6436 if (getDB().isSupportsInlineDistinct()) {
6437 query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6438 }
6439 else {
6440 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6441 }
6442
6443 boolean conjunctionable = false;
6444
6445 if (conjunctionable) {
6446 query.append(WHERE_AND);
6447 }
6448
6449 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6450
6451 conjunctionable = true;
6452
6453 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6454 if (conjunctionable) {
6455 query.append(WHERE_AND);
6456 }
6457
6458 query.append(StringPool.OPEN_PARENTHESIS);
6459
6460 for (int i = 0; i < parentCategoryIds.length; i++) {
6461 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6462
6463 if ((i + 1) < parentCategoryIds.length) {
6464 query.append(WHERE_OR);
6465 }
6466 }
6467
6468 query.append(StringPool.CLOSE_PARENTHESIS);
6469
6470 conjunctionable = true;
6471 }
6472
6473 if (conjunctionable) {
6474 query.append(WHERE_AND);
6475 }
6476
6477 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6478
6479 conjunctionable = true;
6480
6481 if (!getDB().isSupportsInlineDistinct()) {
6482 query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6483 }
6484
6485 if (orderByComparator != null) {
6486 if (getDB().isSupportsInlineDistinct()) {
6487 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6488 orderByComparator, true);
6489 }
6490 else {
6491 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6492 orderByComparator, true);
6493 }
6494 }
6495 else {
6496 if (getDB().isSupportsInlineDistinct()) {
6497 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6498 }
6499 else {
6500 query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6501 }
6502 }
6503
6504 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6505 MBCategory.class.getName(),
6506 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6507
6508 Session session = null;
6509
6510 try {
6511 session = openSession();
6512
6513 SQLQuery q = session.createSQLQuery(sql);
6514
6515 if (getDB().isSupportsInlineDistinct()) {
6516 q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6517 }
6518 else {
6519 q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6520 }
6521
6522 QueryPos qPos = QueryPos.getInstance(q);
6523
6524 qPos.add(groupId);
6525
6526 if (parentCategoryIds != null) {
6527 qPos.add(parentCategoryIds);
6528 }
6529
6530 qPos.add(status);
6531
6532 return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6533 }
6534 catch (Exception e) {
6535 throw processException(e);
6536 }
6537 finally {
6538 closeSession(session);
6539 }
6540 }
6541
6542
6555 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6556 int status) throws SystemException {
6557 return findByG_P_S(groupId, parentCategoryIds, status,
6558 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6559 }
6560
6561
6576 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6577 int status, int start, int end) throws SystemException {
6578 return findByG_P_S(groupId, parentCategoryIds, status, start, end, null);
6579 }
6580
6581
6597 public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6598 int status, int start, int end, OrderByComparator orderByComparator)
6599 throws SystemException {
6600 if ((parentCategoryIds != null) && (parentCategoryIds.length == 1)) {
6601 return findByG_P_S(groupId, parentCategoryIds[0], status, start,
6602 end, orderByComparator);
6603 }
6604
6605 boolean pagination = true;
6606 Object[] finderArgs = null;
6607
6608 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6609 (orderByComparator == null)) {
6610 pagination = false;
6611 finderArgs = new Object[] {
6612 groupId, StringUtil.merge(parentCategoryIds), status
6613 };
6614 }
6615 else {
6616 finderArgs = new Object[] {
6617 groupId, StringUtil.merge(parentCategoryIds), status,
6618
6619 start, end, orderByComparator
6620 };
6621 }
6622
6623 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6624 finderArgs, this);
6625
6626 if ((list != null) && !list.isEmpty()) {
6627 for (MBCategory mbCategory : list) {
6628 if ((groupId != mbCategory.getGroupId()) ||
6629 !ArrayUtil.contains(parentCategoryIds,
6630 mbCategory.getParentCategoryId()) ||
6631 (status != mbCategory.getStatus())) {
6632 list = null;
6633
6634 break;
6635 }
6636 }
6637 }
6638
6639 if (list == null) {
6640 StringBundler query = new StringBundler();
6641
6642 query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6643
6644 boolean conjunctionable = false;
6645
6646 if (conjunctionable) {
6647 query.append(WHERE_AND);
6648 }
6649
6650 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6651
6652 conjunctionable = true;
6653
6654 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6655 if (conjunctionable) {
6656 query.append(WHERE_AND);
6657 }
6658
6659 query.append(StringPool.OPEN_PARENTHESIS);
6660
6661 for (int i = 0; i < parentCategoryIds.length; i++) {
6662 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6663
6664 if ((i + 1) < parentCategoryIds.length) {
6665 query.append(WHERE_OR);
6666 }
6667 }
6668
6669 query.append(StringPool.CLOSE_PARENTHESIS);
6670
6671 conjunctionable = true;
6672 }
6673
6674 if (conjunctionable) {
6675 query.append(WHERE_AND);
6676 }
6677
6678 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6679
6680 conjunctionable = true;
6681
6682 if (orderByComparator != null) {
6683 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6684 orderByComparator);
6685 }
6686 else
6687 if (pagination) {
6688 query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6689 }
6690
6691 String sql = query.toString();
6692
6693 Session session = null;
6694
6695 try {
6696 session = openSession();
6697
6698 Query q = session.createQuery(sql);
6699
6700 QueryPos qPos = QueryPos.getInstance(q);
6701
6702 qPos.add(groupId);
6703
6704 if (parentCategoryIds != null) {
6705 qPos.add(parentCategoryIds);
6706 }
6707
6708 qPos.add(status);
6709
6710 if (!pagination) {
6711 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6712 start, end, false);
6713
6714 Collections.sort(list);
6715
6716 list = new UnmodifiableList<MBCategory>(list);
6717 }
6718 else {
6719 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6720 start, end);
6721 }
6722
6723 cacheResult(list);
6724
6725 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6726 finderArgs, list);
6727 }
6728 catch (Exception e) {
6729 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6730 finderArgs);
6731
6732 throw processException(e);
6733 }
6734 finally {
6735 closeSession(session);
6736 }
6737 }
6738
6739 return list;
6740 }
6741
6742
6750 public void removeByG_P_S(long groupId, long parentCategoryId, int status)
6751 throws SystemException {
6752 for (MBCategory mbCategory : findByG_P_S(groupId, parentCategoryId,
6753 status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6754 remove(mbCategory);
6755 }
6756 }
6757
6758
6767 public int countByG_P_S(long groupId, long parentCategoryId, int status)
6768 throws SystemException {
6769 FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
6770
6771 Object[] finderArgs = new Object[] { groupId, parentCategoryId, status };
6772
6773 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6774 this);
6775
6776 if (count == null) {
6777 StringBundler query = new StringBundler(4);
6778
6779 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6780
6781 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6782
6783 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6784
6785 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6786
6787 String sql = query.toString();
6788
6789 Session session = null;
6790
6791 try {
6792 session = openSession();
6793
6794 Query q = session.createQuery(sql);
6795
6796 QueryPos qPos = QueryPos.getInstance(q);
6797
6798 qPos.add(groupId);
6799
6800 qPos.add(parentCategoryId);
6801
6802 qPos.add(status);
6803
6804 count = (Long)q.uniqueResult();
6805
6806 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6807 }
6808 catch (Exception e) {
6809 FinderCacheUtil.removeResult(finderPath, finderArgs);
6810
6811 throw processException(e);
6812 }
6813 finally {
6814 closeSession(session);
6815 }
6816 }
6817
6818 return count.intValue();
6819 }
6820
6821
6830 public int countByG_P_S(long groupId, long[] parentCategoryIds, int status)
6831 throws SystemException {
6832 Object[] finderArgs = new Object[] {
6833 groupId, StringUtil.merge(parentCategoryIds), status
6834 };
6835
6836 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6837 finderArgs, this);
6838
6839 if (count == null) {
6840 StringBundler query = new StringBundler();
6841
6842 query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6843
6844 boolean conjunctionable = false;
6845
6846 if (conjunctionable) {
6847 query.append(WHERE_AND);
6848 }
6849
6850 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6851
6852 conjunctionable = true;
6853
6854 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6855 if (conjunctionable) {
6856 query.append(WHERE_AND);
6857 }
6858
6859 query.append(StringPool.OPEN_PARENTHESIS);
6860
6861 for (int i = 0; i < parentCategoryIds.length; i++) {
6862 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6863
6864 if ((i + 1) < parentCategoryIds.length) {
6865 query.append(WHERE_OR);
6866 }
6867 }
6868
6869 query.append(StringPool.CLOSE_PARENTHESIS);
6870
6871 conjunctionable = true;
6872 }
6873
6874 if (conjunctionable) {
6875 query.append(WHERE_AND);
6876 }
6877
6878 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6879
6880 conjunctionable = true;
6881
6882 String sql = query.toString();
6883
6884 Session session = null;
6885
6886 try {
6887 session = openSession();
6888
6889 Query q = session.createQuery(sql);
6890
6891 QueryPos qPos = QueryPos.getInstance(q);
6892
6893 qPos.add(groupId);
6894
6895 if (parentCategoryIds != null) {
6896 qPos.add(parentCategoryIds);
6897 }
6898
6899 qPos.add(status);
6900
6901 count = (Long)q.uniqueResult();
6902
6903 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6904 finderArgs, count);
6905 }
6906 catch (Exception e) {
6907 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6908 finderArgs);
6909
6910 throw processException(e);
6911 }
6912 finally {
6913 closeSession(session);
6914 }
6915 }
6916
6917 return count.intValue();
6918 }
6919
6920
6929 public int filterCountByG_P_S(long groupId, long parentCategoryId,
6930 int status) throws SystemException {
6931 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6932 return countByG_P_S(groupId, parentCategoryId, status);
6933 }
6934
6935 StringBundler query = new StringBundler(4);
6936
6937 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6938
6939 query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6940
6941 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6942
6943 query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6944
6945 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6946 MBCategory.class.getName(),
6947 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6948
6949 Session session = null;
6950
6951 try {
6952 session = openSession();
6953
6954 SQLQuery q = session.createSQLQuery(sql);
6955
6956 q.addScalar(COUNT_COLUMN_NAME,
6957 com.liferay.portal.kernel.dao.orm.Type.LONG);
6958
6959 QueryPos qPos = QueryPos.getInstance(q);
6960
6961 qPos.add(groupId);
6962
6963 qPos.add(parentCategoryId);
6964
6965 qPos.add(status);
6966
6967 Long count = (Long)q.uniqueResult();
6968
6969 return count.intValue();
6970 }
6971 catch (Exception e) {
6972 throw processException(e);
6973 }
6974 finally {
6975 closeSession(session);
6976 }
6977 }
6978
6979
6988 public int filterCountByG_P_S(long groupId, long[] parentCategoryIds,
6989 int status) throws SystemException {
6990 if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6991 return countByG_P_S(groupId, parentCategoryIds, status);
6992 }
6993
6994 StringBundler query = new StringBundler();
6995
6996 query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6997
6998 boolean conjunctionable = false;
6999
7000 if (conjunctionable) {
7001 query.append(WHERE_AND);
7002 }
7003
7004 query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
7005
7006 conjunctionable = true;
7007
7008 if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
7009 if (conjunctionable) {
7010 query.append(WHERE_AND);
7011 }
7012
7013 query.append(StringPool.OPEN_PARENTHESIS);
7014
7015 for (int i = 0; i < parentCategoryIds.length; i++) {
7016 query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
7017
7018 if ((i + 1) < parentCategoryIds.length) {
7019 query.append(WHERE_OR);
7020 }
7021 }
7022
7023 query.append(StringPool.CLOSE_PARENTHESIS);
7024
7025 conjunctionable = true;
7026 }
7027
7028 if (conjunctionable) {
7029 query.append(WHERE_AND);
7030 }
7031
7032 query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
7033
7034 conjunctionable = true;
7035
7036 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7037 MBCategory.class.getName(),
7038 _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7039
7040 Session session = null;
7041
7042 try {
7043 session = openSession();
7044
7045 SQLQuery q = session.createSQLQuery(sql);
7046
7047 q.addScalar(COUNT_COLUMN_NAME,
7048 com.liferay.portal.kernel.dao.orm.Type.LONG);
7049
7050 QueryPos qPos = QueryPos.getInstance(q);
7051
7052 qPos.add(groupId);
7053
7054 if (parentCategoryIds != null) {
7055 qPos.add(parentCategoryIds);
7056 }
7057
7058 qPos.add(status);
7059
7060 Long count = (Long)q.uniqueResult();
7061
7062 return count.intValue();
7063 }
7064 catch (Exception e) {
7065 throw processException(e);
7066 }
7067 finally {
7068 closeSession(session);
7069 }
7070 }
7071
7072 private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
7073 private static final String _FINDER_COLUMN_G_P_S_GROUPID_5 = "(" +
7074 removeConjunction(_FINDER_COLUMN_G_P_S_GROUPID_2) + ")";
7075 private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
7076 private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5 = "(" +
7077 removeConjunction(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2) + ")";
7078 private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "mbCategory.status = ?";
7079 private static final String _FINDER_COLUMN_G_P_S_STATUS_5 = "(" +
7080 removeConjunction(_FINDER_COLUMN_G_P_S_STATUS_2) + ")";
7081
7082
7087 public void cacheResult(MBCategory mbCategory) {
7088 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7089 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
7090
7091 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7092 new Object[] { mbCategory.getUuid(), mbCategory.getGroupId() },
7093 mbCategory);
7094
7095 mbCategory.resetOriginalValues();
7096 }
7097
7098
7103 public void cacheResult(List<MBCategory> mbCategories) {
7104 for (MBCategory mbCategory : mbCategories) {
7105 if (EntityCacheUtil.getResult(
7106 MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7107 MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
7108 cacheResult(mbCategory);
7109 }
7110 else {
7111 mbCategory.resetOriginalValues();
7112 }
7113 }
7114 }
7115
7116
7123 @Override
7124 public void clearCache() {
7125 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7126 CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
7127 }
7128
7129 EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
7130
7131 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7132 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7133 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7134 }
7135
7136
7143 @Override
7144 public void clearCache(MBCategory mbCategory) {
7145 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7146 MBCategoryImpl.class, mbCategory.getPrimaryKey());
7147
7148 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7150
7151 clearUniqueFindersCache(mbCategory);
7152 }
7153
7154 @Override
7155 public void clearCache(List<MBCategory> mbCategories) {
7156 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7157 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7158
7159 for (MBCategory mbCategory : mbCategories) {
7160 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7161 MBCategoryImpl.class, mbCategory.getPrimaryKey());
7162
7163 clearUniqueFindersCache(mbCategory);
7164 }
7165 }
7166
7167 protected void cacheUniqueFindersCache(MBCategory mbCategory) {
7168 if (mbCategory.isNew()) {
7169 Object[] args = new Object[] {
7170 mbCategory.getUuid(), mbCategory.getGroupId()
7171 };
7172
7173 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7174 Long.valueOf(1));
7175 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7176 mbCategory);
7177 }
7178 else {
7179 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7180
7181 if ((mbCategoryModelImpl.getColumnBitmask() &
7182 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7183 Object[] args = new Object[] {
7184 mbCategory.getUuid(), mbCategory.getGroupId()
7185 };
7186
7187 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7188 Long.valueOf(1));
7189 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7190 mbCategory);
7191 }
7192 }
7193 }
7194
7195 protected void clearUniqueFindersCache(MBCategory mbCategory) {
7196 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7197
7198 Object[] args = new Object[] {
7199 mbCategory.getUuid(), mbCategory.getGroupId()
7200 };
7201
7202 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7203 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7204
7205 if ((mbCategoryModelImpl.getColumnBitmask() &
7206 FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7207 args = new Object[] {
7208 mbCategoryModelImpl.getOriginalUuid(),
7209 mbCategoryModelImpl.getOriginalGroupId()
7210 };
7211
7212 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7213 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7214 }
7215 }
7216
7217
7223 public MBCategory create(long categoryId) {
7224 MBCategory mbCategory = new MBCategoryImpl();
7225
7226 mbCategory.setNew(true);
7227 mbCategory.setPrimaryKey(categoryId);
7228
7229 String uuid = PortalUUIDUtil.generate();
7230
7231 mbCategory.setUuid(uuid);
7232
7233 return mbCategory;
7234 }
7235
7236
7244 public MBCategory remove(long categoryId)
7245 throws NoSuchCategoryException, SystemException {
7246 return remove((Serializable)categoryId);
7247 }
7248
7249
7257 @Override
7258 public MBCategory remove(Serializable primaryKey)
7259 throws NoSuchCategoryException, SystemException {
7260 Session session = null;
7261
7262 try {
7263 session = openSession();
7264
7265 MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7266 primaryKey);
7267
7268 if (mbCategory == null) {
7269 if (_log.isWarnEnabled()) {
7270 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7271 }
7272
7273 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7274 primaryKey);
7275 }
7276
7277 return remove(mbCategory);
7278 }
7279 catch (NoSuchCategoryException nsee) {
7280 throw nsee;
7281 }
7282 catch (Exception e) {
7283 throw processException(e);
7284 }
7285 finally {
7286 closeSession(session);
7287 }
7288 }
7289
7290 @Override
7291 protected MBCategory removeImpl(MBCategory mbCategory)
7292 throws SystemException {
7293 mbCategory = toUnwrappedModel(mbCategory);
7294
7295 Session session = null;
7296
7297 try {
7298 session = openSession();
7299
7300 if (!session.contains(mbCategory)) {
7301 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7302 mbCategory.getPrimaryKeyObj());
7303 }
7304
7305 if (mbCategory != null) {
7306 session.delete(mbCategory);
7307 }
7308 }
7309 catch (Exception e) {
7310 throw processException(e);
7311 }
7312 finally {
7313 closeSession(session);
7314 }
7315
7316 if (mbCategory != null) {
7317 clearCache(mbCategory);
7318 }
7319
7320 return mbCategory;
7321 }
7322
7323 @Override
7324 public MBCategory updateImpl(
7325 com.liferay.portlet.messageboards.model.MBCategory mbCategory)
7326 throws SystemException {
7327 mbCategory = toUnwrappedModel(mbCategory);
7328
7329 boolean isNew = mbCategory.isNew();
7330
7331 MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7332
7333 if (Validator.isNull(mbCategory.getUuid())) {
7334 String uuid = PortalUUIDUtil.generate();
7335
7336 mbCategory.setUuid(uuid);
7337 }
7338
7339 Session session = null;
7340
7341 try {
7342 session = openSession();
7343
7344 if (mbCategory.isNew()) {
7345 session.save(mbCategory);
7346
7347 mbCategory.setNew(false);
7348 }
7349 else {
7350 session.merge(mbCategory);
7351 }
7352 }
7353 catch (Exception e) {
7354 throw processException(e);
7355 }
7356 finally {
7357 closeSession(session);
7358 }
7359
7360 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7361
7362 if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
7363 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7364 }
7365
7366 else {
7367 if ((mbCategoryModelImpl.getColumnBitmask() &
7368 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7369 Object[] args = new Object[] {
7370 mbCategoryModelImpl.getOriginalUuid()
7371 };
7372
7373 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7374 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7375 args);
7376
7377 args = new Object[] { mbCategoryModelImpl.getUuid() };
7378
7379 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7380 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7381 args);
7382 }
7383
7384 if ((mbCategoryModelImpl.getColumnBitmask() &
7385 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7386 Object[] args = new Object[] {
7387 mbCategoryModelImpl.getOriginalUuid(),
7388 mbCategoryModelImpl.getOriginalCompanyId()
7389 };
7390
7391 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7392 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7393 args);
7394
7395 args = new Object[] {
7396 mbCategoryModelImpl.getUuid(),
7397 mbCategoryModelImpl.getCompanyId()
7398 };
7399
7400 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7401 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7402 args);
7403 }
7404
7405 if ((mbCategoryModelImpl.getColumnBitmask() &
7406 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7407 Object[] args = new Object[] {
7408 mbCategoryModelImpl.getOriginalGroupId()
7409 };
7410
7411 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7412 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7413 args);
7414
7415 args = new Object[] { mbCategoryModelImpl.getGroupId() };
7416
7417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7418 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7419 args);
7420 }
7421
7422 if ((mbCategoryModelImpl.getColumnBitmask() &
7423 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7424 Object[] args = new Object[] {
7425 mbCategoryModelImpl.getOriginalCompanyId()
7426 };
7427
7428 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7429 args);
7430 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7431 args);
7432
7433 args = new Object[] { mbCategoryModelImpl.getCompanyId() };
7434
7435 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7436 args);
7437 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7438 args);
7439 }
7440
7441 if ((mbCategoryModelImpl.getColumnBitmask() &
7442 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
7443 Object[] args = new Object[] {
7444 mbCategoryModelImpl.getOriginalGroupId(),
7445 mbCategoryModelImpl.getOriginalParentCategoryId()
7446 };
7447
7448 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7449 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7450 args);
7451
7452 args = new Object[] {
7453 mbCategoryModelImpl.getGroupId(),
7454 mbCategoryModelImpl.getParentCategoryId()
7455 };
7456
7457 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7458 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7459 args);
7460 }
7461
7462 if ((mbCategoryModelImpl.getColumnBitmask() &
7463 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
7464 Object[] args = new Object[] {
7465 mbCategoryModelImpl.getOriginalGroupId(),
7466 mbCategoryModelImpl.getOriginalStatus()
7467 };
7468
7469 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7470 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7471 args);
7472
7473 args = new Object[] {
7474 mbCategoryModelImpl.getGroupId(),
7475 mbCategoryModelImpl.getStatus()
7476 };
7477
7478 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7479 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7480 args);
7481 }
7482
7483 if ((mbCategoryModelImpl.getColumnBitmask() &
7484 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
7485 Object[] args = new Object[] {
7486 mbCategoryModelImpl.getOriginalCompanyId(),
7487 mbCategoryModelImpl.getOriginalStatus()
7488 };
7489
7490 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7491 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7492 args);
7493
7494 args = new Object[] {
7495 mbCategoryModelImpl.getCompanyId(),
7496 mbCategoryModelImpl.getStatus()
7497 };
7498
7499 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7500 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7501 args);
7502 }
7503
7504 if ((mbCategoryModelImpl.getColumnBitmask() &
7505 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
7506 Object[] args = new Object[] {
7507 mbCategoryModelImpl.getOriginalGroupId(),
7508 mbCategoryModelImpl.getOriginalParentCategoryId(),
7509 mbCategoryModelImpl.getOriginalStatus()
7510 };
7511
7512 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7513 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7514 args);
7515
7516 args = new Object[] {
7517 mbCategoryModelImpl.getGroupId(),
7518 mbCategoryModelImpl.getParentCategoryId(),
7519 mbCategoryModelImpl.getStatus()
7520 };
7521
7522 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7523 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7524 args);
7525 }
7526 }
7527
7528 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7529 MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
7530
7531 clearUniqueFindersCache(mbCategory);
7532 cacheUniqueFindersCache(mbCategory);
7533
7534 return mbCategory;
7535 }
7536
7537 protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
7538 if (mbCategory instanceof MBCategoryImpl) {
7539 return mbCategory;
7540 }
7541
7542 MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
7543
7544 mbCategoryImpl.setNew(mbCategory.isNew());
7545 mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
7546
7547 mbCategoryImpl.setUuid(mbCategory.getUuid());
7548 mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
7549 mbCategoryImpl.setGroupId(mbCategory.getGroupId());
7550 mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
7551 mbCategoryImpl.setUserId(mbCategory.getUserId());
7552 mbCategoryImpl.setUserName(mbCategory.getUserName());
7553 mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
7554 mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
7555 mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
7556 mbCategoryImpl.setName(mbCategory.getName());
7557 mbCategoryImpl.setDescription(mbCategory.getDescription());
7558 mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
7559 mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
7560 mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
7561 mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
7562 mbCategoryImpl.setStatus(mbCategory.getStatus());
7563 mbCategoryImpl.setStatusByUserId(mbCategory.getStatusByUserId());
7564 mbCategoryImpl.setStatusByUserName(mbCategory.getStatusByUserName());
7565 mbCategoryImpl.setStatusDate(mbCategory.getStatusDate());
7566
7567 return mbCategoryImpl;
7568 }
7569
7570
7578 @Override
7579 public MBCategory findByPrimaryKey(Serializable primaryKey)
7580 throws NoSuchCategoryException, SystemException {
7581 MBCategory mbCategory = fetchByPrimaryKey(primaryKey);
7582
7583 if (mbCategory == null) {
7584 if (_log.isWarnEnabled()) {
7585 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7586 }
7587
7588 throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7589 primaryKey);
7590 }
7591
7592 return mbCategory;
7593 }
7594
7595
7603 public MBCategory findByPrimaryKey(long categoryId)
7604 throws NoSuchCategoryException, SystemException {
7605 return findByPrimaryKey((Serializable)categoryId);
7606 }
7607
7608
7615 @Override
7616 public MBCategory fetchByPrimaryKey(Serializable primaryKey)
7617 throws SystemException {
7618 MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7619 MBCategoryImpl.class, primaryKey);
7620
7621 if (mbCategory == _nullMBCategory) {
7622 return null;
7623 }
7624
7625 if (mbCategory == null) {
7626 Session session = null;
7627
7628 try {
7629 session = openSession();
7630
7631 mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7632 primaryKey);
7633
7634 if (mbCategory != null) {
7635 cacheResult(mbCategory);
7636 }
7637 else {
7638 EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7639 MBCategoryImpl.class, primaryKey, _nullMBCategory);
7640 }
7641 }
7642 catch (Exception e) {
7643 EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7644 MBCategoryImpl.class, primaryKey);
7645
7646 throw processException(e);
7647 }
7648 finally {
7649 closeSession(session);
7650 }
7651 }
7652
7653 return mbCategory;
7654 }
7655
7656
7663 public MBCategory fetchByPrimaryKey(long categoryId)
7664 throws SystemException {
7665 return fetchByPrimaryKey((Serializable)categoryId);
7666 }
7667
7668
7674 public List<MBCategory> findAll() throws SystemException {
7675 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7676 }
7677
7678
7690 public List<MBCategory> findAll(int start, int end)
7691 throws SystemException {
7692 return findAll(start, end, null);
7693 }
7694
7695
7708 public List<MBCategory> findAll(int start, int end,
7709 OrderByComparator orderByComparator) throws SystemException {
7710 boolean pagination = true;
7711 FinderPath finderPath = null;
7712 Object[] finderArgs = null;
7713
7714 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7715 (orderByComparator == null)) {
7716 pagination = false;
7717 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7718 finderArgs = FINDER_ARGS_EMPTY;
7719 }
7720 else {
7721 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7722 finderArgs = new Object[] { start, end, orderByComparator };
7723 }
7724
7725 List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
7726 finderArgs, this);
7727
7728 if (list == null) {
7729 StringBundler query = null;
7730 String sql = null;
7731
7732 if (orderByComparator != null) {
7733 query = new StringBundler(2 +
7734 (orderByComparator.getOrderByFields().length * 3));
7735
7736 query.append(_SQL_SELECT_MBCATEGORY);
7737
7738 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7739 orderByComparator);
7740
7741 sql = query.toString();
7742 }
7743 else {
7744 sql = _SQL_SELECT_MBCATEGORY;
7745
7746 if (pagination) {
7747 sql = sql.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
7748 }
7749 }
7750
7751 Session session = null;
7752
7753 try {
7754 session = openSession();
7755
7756 Query q = session.createQuery(sql);
7757
7758 if (!pagination) {
7759 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7760 start, end, false);
7761
7762 Collections.sort(list);
7763
7764 list = new UnmodifiableList<MBCategory>(list);
7765 }
7766 else {
7767 list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7768 start, end);
7769 }
7770
7771 cacheResult(list);
7772
7773 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7774 }
7775 catch (Exception e) {
7776 FinderCacheUtil.removeResult(finderPath, finderArgs);
7777
7778 throw processException(e);
7779 }
7780 finally {
7781 closeSession(session);
7782 }
7783 }
7784
7785 return list;
7786 }
7787
7788
7793 public void removeAll() throws SystemException {
7794 for (MBCategory mbCategory : findAll()) {
7795 remove(mbCategory);
7796 }
7797 }
7798
7799
7805 public int countAll() throws SystemException {
7806 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7807 FINDER_ARGS_EMPTY, this);
7808
7809 if (count == null) {
7810 Session session = null;
7811
7812 try {
7813 session = openSession();
7814
7815 Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
7816
7817 count = (Long)q.uniqueResult();
7818
7819 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7820 FINDER_ARGS_EMPTY, count);
7821 }
7822 catch (Exception e) {
7823 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7824 FINDER_ARGS_EMPTY);
7825
7826 throw processException(e);
7827 }
7828 finally {
7829 closeSession(session);
7830 }
7831 }
7832
7833 return count.intValue();
7834 }
7835
7836 @Override
7837 protected Set<String> getBadColumnNames() {
7838 return _badColumnNames;
7839 }
7840
7841
7844 public void afterPropertiesSet() {
7845 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
7846 com.liferay.portal.util.PropsUtil.get(
7847 "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
7848
7849 if (listenerClassNames.length > 0) {
7850 try {
7851 List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
7852
7853 for (String listenerClassName : listenerClassNames) {
7854 listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
7855 getClassLoader(), listenerClassName));
7856 }
7857
7858 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
7859 }
7860 catch (Exception e) {
7861 _log.error(e);
7862 }
7863 }
7864 }
7865
7866 public void destroy() {
7867 EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
7868 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
7869 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7870 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7871 }
7872
7873 private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
7874 private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
7875 private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
7876 private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
7877 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
7878 private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
7879 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
7880 "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
7881 private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
7882 ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
7883 private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
7884 private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
7885 private static final String _FILTER_ENTITY_TABLE = "MBCategory";
7886 private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
7887 private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
7888 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
7889 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
7890 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
7891 private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
7892 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
7893 "uuid"
7894 });
7895 private static MBCategory _nullMBCategory = new MBCategoryImpl() {
7896 @Override
7897 public Object clone() {
7898 return this;
7899 }
7900
7901 @Override
7902 public CacheModel<MBCategory> toCacheModel() {
7903 return _nullMBCategoryCacheModel;
7904 }
7905 };
7906
7907 private static CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
7908 public MBCategory toEntityModel() {
7909 return _nullMBCategory;
7910 }
7911 };
7912 }