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