001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.NoSuchRoleException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderPath;
024 import com.liferay.portal.kernel.dao.orm.Query;
025 import com.liferay.portal.kernel.dao.orm.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.SQLQuery;
028 import com.liferay.portal.kernel.dao.orm.Session;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.ArrayUtil;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.SetUtil;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039 import com.liferay.portal.model.CacheModel;
040 import com.liferay.portal.model.MVCCModel;
041 import com.liferay.portal.model.Role;
042 import com.liferay.portal.model.impl.RoleImpl;
043 import com.liferay.portal.model.impl.RoleModelImpl;
044 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
045 import com.liferay.portal.service.ServiceContext;
046 import com.liferay.portal.service.ServiceContextThreadLocal;
047 import com.liferay.portal.service.persistence.GroupPersistence;
048 import com.liferay.portal.service.persistence.RolePersistence;
049 import com.liferay.portal.service.persistence.UserPersistence;
050
051 import java.io.Serializable;
052
053 import java.util.Collections;
054 import java.util.Date;
055 import java.util.HashMap;
056 import java.util.HashSet;
057 import java.util.Iterator;
058 import java.util.List;
059 import java.util.Map;
060 import java.util.Set;
061
062
074 @ProviderType
075 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
076 implements RolePersistence {
077
082 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
083 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List1";
085 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
086 ".List2";
087 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
088 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
089 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
090 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
091 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
093 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
094 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
095 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
097 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
099 new String[] {
100 String.class.getName(),
101
102 Integer.class.getName(), Integer.class.getName(),
103 OrderByComparator.class.getName()
104 });
105 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
106 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
108 new String[] { String.class.getName() },
109 RoleModelImpl.UUID_COLUMN_BITMASK |
110 RoleModelImpl.NAME_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
112 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
114 new String[] { String.class.getName() });
115
116
122 @Override
123 public List<Role> findByUuid(String uuid) {
124 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
125 }
126
127
139 @Override
140 public List<Role> findByUuid(String uuid, int start, int end) {
141 return findByUuid(uuid, start, end, null);
142 }
143
144
157 @Override
158 public List<Role> findByUuid(String uuid, int start, int end,
159 OrderByComparator<Role> orderByComparator) {
160 boolean pagination = true;
161 FinderPath finderPath = null;
162 Object[] finderArgs = null;
163
164 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165 (orderByComparator == null)) {
166 pagination = false;
167 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168 finderArgs = new Object[] { uuid };
169 }
170 else {
171 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172 finderArgs = new Object[] { uuid, start, end, orderByComparator };
173 }
174
175 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
176 finderArgs, this);
177
178 if ((list != null) && !list.isEmpty()) {
179 for (Role role : list) {
180 if (!Validator.equals(uuid, role.getUuid())) {
181 list = null;
182
183 break;
184 }
185 }
186 }
187
188 if (list == null) {
189 StringBundler query = null;
190
191 if (orderByComparator != null) {
192 query = new StringBundler(3 +
193 (orderByComparator.getOrderByFields().length * 3));
194 }
195 else {
196 query = new StringBundler(3);
197 }
198
199 query.append(_SQL_SELECT_ROLE_WHERE);
200
201 boolean bindUuid = false;
202
203 if (uuid == null) {
204 query.append(_FINDER_COLUMN_UUID_UUID_1);
205 }
206 else if (uuid.equals(StringPool.BLANK)) {
207 query.append(_FINDER_COLUMN_UUID_UUID_3);
208 }
209 else {
210 bindUuid = true;
211
212 query.append(_FINDER_COLUMN_UUID_UUID_2);
213 }
214
215 if (orderByComparator != null) {
216 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
217 orderByComparator);
218 }
219 else
220 if (pagination) {
221 query.append(RoleModelImpl.ORDER_BY_JPQL);
222 }
223
224 String sql = query.toString();
225
226 Session session = null;
227
228 try {
229 session = openSession();
230
231 Query q = session.createQuery(sql);
232
233 QueryPos qPos = QueryPos.getInstance(q);
234
235 if (bindUuid) {
236 qPos.add(uuid);
237 }
238
239 if (!pagination) {
240 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
241 end, false);
242
243 Collections.sort(list);
244
245 list = Collections.unmodifiableList(list);
246 }
247 else {
248 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
249 end);
250 }
251
252 cacheResult(list);
253
254 FinderCacheUtil.putResult(finderPath, finderArgs, list);
255 }
256 catch (Exception e) {
257 FinderCacheUtil.removeResult(finderPath, finderArgs);
258
259 throw processException(e);
260 }
261 finally {
262 closeSession(session);
263 }
264 }
265
266 return list;
267 }
268
269
277 @Override
278 public Role findByUuid_First(String uuid,
279 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
280 Role role = fetchByUuid_First(uuid, orderByComparator);
281
282 if (role != null) {
283 return role;
284 }
285
286 StringBundler msg = new StringBundler(4);
287
288 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
289
290 msg.append("uuid=");
291 msg.append(uuid);
292
293 msg.append(StringPool.CLOSE_CURLY_BRACE);
294
295 throw new NoSuchRoleException(msg.toString());
296 }
297
298
305 @Override
306 public Role fetchByUuid_First(String uuid,
307 OrderByComparator<Role> orderByComparator) {
308 List<Role> list = findByUuid(uuid, 0, 1, orderByComparator);
309
310 if (!list.isEmpty()) {
311 return list.get(0);
312 }
313
314 return null;
315 }
316
317
325 @Override
326 public Role findByUuid_Last(String uuid,
327 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
328 Role role = fetchByUuid_Last(uuid, orderByComparator);
329
330 if (role != null) {
331 return role;
332 }
333
334 StringBundler msg = new StringBundler(4);
335
336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337
338 msg.append("uuid=");
339 msg.append(uuid);
340
341 msg.append(StringPool.CLOSE_CURLY_BRACE);
342
343 throw new NoSuchRoleException(msg.toString());
344 }
345
346
353 @Override
354 public Role fetchByUuid_Last(String uuid,
355 OrderByComparator<Role> orderByComparator) {
356 int count = countByUuid(uuid);
357
358 if (count == 0) {
359 return null;
360 }
361
362 List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator);
363
364 if (!list.isEmpty()) {
365 return list.get(0);
366 }
367
368 return null;
369 }
370
371
380 @Override
381 public Role[] findByUuid_PrevAndNext(long roleId, String uuid,
382 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
383 Role role = findByPrimaryKey(roleId);
384
385 Session session = null;
386
387 try {
388 session = openSession();
389
390 Role[] array = new RoleImpl[3];
391
392 array[0] = getByUuid_PrevAndNext(session, role, uuid,
393 orderByComparator, true);
394
395 array[1] = role;
396
397 array[2] = getByUuid_PrevAndNext(session, role, uuid,
398 orderByComparator, false);
399
400 return array;
401 }
402 catch (Exception e) {
403 throw processException(e);
404 }
405 finally {
406 closeSession(session);
407 }
408 }
409
410 protected Role getByUuid_PrevAndNext(Session session, Role role,
411 String uuid, OrderByComparator<Role> orderByComparator, boolean previous) {
412 StringBundler query = null;
413
414 if (orderByComparator != null) {
415 query = new StringBundler(6 +
416 (orderByComparator.getOrderByFields().length * 6));
417 }
418 else {
419 query = new StringBundler(3);
420 }
421
422 query.append(_SQL_SELECT_ROLE_WHERE);
423
424 boolean bindUuid = false;
425
426 if (uuid == null) {
427 query.append(_FINDER_COLUMN_UUID_UUID_1);
428 }
429 else if (uuid.equals(StringPool.BLANK)) {
430 query.append(_FINDER_COLUMN_UUID_UUID_3);
431 }
432 else {
433 bindUuid = true;
434
435 query.append(_FINDER_COLUMN_UUID_UUID_2);
436 }
437
438 if (orderByComparator != null) {
439 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
440
441 if (orderByConditionFields.length > 0) {
442 query.append(WHERE_AND);
443 }
444
445 for (int i = 0; i < orderByConditionFields.length; i++) {
446 query.append(_ORDER_BY_ENTITY_ALIAS);
447 query.append(orderByConditionFields[i]);
448
449 if ((i + 1) < orderByConditionFields.length) {
450 if (orderByComparator.isAscending() ^ previous) {
451 query.append(WHERE_GREATER_THAN_HAS_NEXT);
452 }
453 else {
454 query.append(WHERE_LESSER_THAN_HAS_NEXT);
455 }
456 }
457 else {
458 if (orderByComparator.isAscending() ^ previous) {
459 query.append(WHERE_GREATER_THAN);
460 }
461 else {
462 query.append(WHERE_LESSER_THAN);
463 }
464 }
465 }
466
467 query.append(ORDER_BY_CLAUSE);
468
469 String[] orderByFields = orderByComparator.getOrderByFields();
470
471 for (int i = 0; i < orderByFields.length; i++) {
472 query.append(_ORDER_BY_ENTITY_ALIAS);
473 query.append(orderByFields[i]);
474
475 if ((i + 1) < orderByFields.length) {
476 if (orderByComparator.isAscending() ^ previous) {
477 query.append(ORDER_BY_ASC_HAS_NEXT);
478 }
479 else {
480 query.append(ORDER_BY_DESC_HAS_NEXT);
481 }
482 }
483 else {
484 if (orderByComparator.isAscending() ^ previous) {
485 query.append(ORDER_BY_ASC);
486 }
487 else {
488 query.append(ORDER_BY_DESC);
489 }
490 }
491 }
492 }
493 else {
494 query.append(RoleModelImpl.ORDER_BY_JPQL);
495 }
496
497 String sql = query.toString();
498
499 Query q = session.createQuery(sql);
500
501 q.setFirstResult(0);
502 q.setMaxResults(2);
503
504 QueryPos qPos = QueryPos.getInstance(q);
505
506 if (bindUuid) {
507 qPos.add(uuid);
508 }
509
510 if (orderByComparator != null) {
511 Object[] values = orderByComparator.getOrderByConditionValues(role);
512
513 for (Object value : values) {
514 qPos.add(value);
515 }
516 }
517
518 List<Role> list = q.list();
519
520 if (list.size() == 2) {
521 return list.get(1);
522 }
523 else {
524 return null;
525 }
526 }
527
528
534 @Override
535 public List<Role> filterFindByUuid(String uuid) {
536 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
537 }
538
539
551 @Override
552 public List<Role> filterFindByUuid(String uuid, int start, int end) {
553 return filterFindByUuid(uuid, start, end, null);
554 }
555
556
569 @Override
570 public List<Role> filterFindByUuid(String uuid, int start, int end,
571 OrderByComparator<Role> orderByComparator) {
572 if (!InlineSQLHelperUtil.isEnabled()) {
573 return findByUuid(uuid, start, end, orderByComparator);
574 }
575
576 StringBundler query = null;
577
578 if (orderByComparator != null) {
579 query = new StringBundler(3 +
580 (orderByComparator.getOrderByFields().length * 3));
581 }
582 else {
583 query = new StringBundler(3);
584 }
585
586 if (getDB().isSupportsInlineDistinct()) {
587 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
588 }
589 else {
590 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
591 }
592
593 boolean bindUuid = false;
594
595 if (uuid == null) {
596 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
597 }
598 else if (uuid.equals(StringPool.BLANK)) {
599 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
600 }
601 else {
602 bindUuid = true;
603
604 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
605 }
606
607 if (!getDB().isSupportsInlineDistinct()) {
608 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
609 }
610
611 if (orderByComparator != null) {
612 if (getDB().isSupportsInlineDistinct()) {
613 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
614 orderByComparator, true);
615 }
616 else {
617 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
618 orderByComparator, true);
619 }
620 }
621 else {
622 if (getDB().isSupportsInlineDistinct()) {
623 query.append(RoleModelImpl.ORDER_BY_JPQL);
624 }
625 else {
626 query.append(RoleModelImpl.ORDER_BY_SQL);
627 }
628 }
629
630 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
631 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
632
633 Session session = null;
634
635 try {
636 session = openSession();
637
638 SQLQuery q = session.createSynchronizedSQLQuery(sql);
639
640 if (getDB().isSupportsInlineDistinct()) {
641 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
642 }
643 else {
644 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
645 }
646
647 QueryPos qPos = QueryPos.getInstance(q);
648
649 if (bindUuid) {
650 qPos.add(uuid);
651 }
652
653 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
654 }
655 catch (Exception e) {
656 throw processException(e);
657 }
658 finally {
659 closeSession(session);
660 }
661 }
662
663
672 @Override
673 public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid,
674 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
675 if (!InlineSQLHelperUtil.isEnabled()) {
676 return findByUuid_PrevAndNext(roleId, uuid, orderByComparator);
677 }
678
679 Role role = findByPrimaryKey(roleId);
680
681 Session session = null;
682
683 try {
684 session = openSession();
685
686 Role[] array = new RoleImpl[3];
687
688 array[0] = filterGetByUuid_PrevAndNext(session, role, uuid,
689 orderByComparator, true);
690
691 array[1] = role;
692
693 array[2] = filterGetByUuid_PrevAndNext(session, role, uuid,
694 orderByComparator, false);
695
696 return array;
697 }
698 catch (Exception e) {
699 throw processException(e);
700 }
701 finally {
702 closeSession(session);
703 }
704 }
705
706 protected Role filterGetByUuid_PrevAndNext(Session session, Role role,
707 String uuid, OrderByComparator<Role> orderByComparator, boolean previous) {
708 StringBundler query = null;
709
710 if (orderByComparator != null) {
711 query = new StringBundler(6 +
712 (orderByComparator.getOrderByFields().length * 6));
713 }
714 else {
715 query = new StringBundler(3);
716 }
717
718 if (getDB().isSupportsInlineDistinct()) {
719 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
720 }
721 else {
722 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
723 }
724
725 boolean bindUuid = false;
726
727 if (uuid == null) {
728 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
729 }
730 else if (uuid.equals(StringPool.BLANK)) {
731 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
732 }
733 else {
734 bindUuid = true;
735
736 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
737 }
738
739 if (!getDB().isSupportsInlineDistinct()) {
740 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
741 }
742
743 if (orderByComparator != null) {
744 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
745
746 if (orderByConditionFields.length > 0) {
747 query.append(WHERE_AND);
748 }
749
750 for (int i = 0; i < orderByConditionFields.length; i++) {
751 if (getDB().isSupportsInlineDistinct()) {
752 query.append(_ORDER_BY_ENTITY_ALIAS);
753 }
754 else {
755 query.append(_ORDER_BY_ENTITY_TABLE);
756 }
757
758 query.append(orderByConditionFields[i]);
759
760 if ((i + 1) < orderByConditionFields.length) {
761 if (orderByComparator.isAscending() ^ previous) {
762 query.append(WHERE_GREATER_THAN_HAS_NEXT);
763 }
764 else {
765 query.append(WHERE_LESSER_THAN_HAS_NEXT);
766 }
767 }
768 else {
769 if (orderByComparator.isAscending() ^ previous) {
770 query.append(WHERE_GREATER_THAN);
771 }
772 else {
773 query.append(WHERE_LESSER_THAN);
774 }
775 }
776 }
777
778 query.append(ORDER_BY_CLAUSE);
779
780 String[] orderByFields = orderByComparator.getOrderByFields();
781
782 for (int i = 0; i < orderByFields.length; i++) {
783 if (getDB().isSupportsInlineDistinct()) {
784 query.append(_ORDER_BY_ENTITY_ALIAS);
785 }
786 else {
787 query.append(_ORDER_BY_ENTITY_TABLE);
788 }
789
790 query.append(orderByFields[i]);
791
792 if ((i + 1) < orderByFields.length) {
793 if (orderByComparator.isAscending() ^ previous) {
794 query.append(ORDER_BY_ASC_HAS_NEXT);
795 }
796 else {
797 query.append(ORDER_BY_DESC_HAS_NEXT);
798 }
799 }
800 else {
801 if (orderByComparator.isAscending() ^ previous) {
802 query.append(ORDER_BY_ASC);
803 }
804 else {
805 query.append(ORDER_BY_DESC);
806 }
807 }
808 }
809 }
810 else {
811 if (getDB().isSupportsInlineDistinct()) {
812 query.append(RoleModelImpl.ORDER_BY_JPQL);
813 }
814 else {
815 query.append(RoleModelImpl.ORDER_BY_SQL);
816 }
817 }
818
819 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
820 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
821
822 SQLQuery q = session.createSynchronizedSQLQuery(sql);
823
824 q.setFirstResult(0);
825 q.setMaxResults(2);
826
827 if (getDB().isSupportsInlineDistinct()) {
828 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
829 }
830 else {
831 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
832 }
833
834 QueryPos qPos = QueryPos.getInstance(q);
835
836 if (bindUuid) {
837 qPos.add(uuid);
838 }
839
840 if (orderByComparator != null) {
841 Object[] values = orderByComparator.getOrderByConditionValues(role);
842
843 for (Object value : values) {
844 qPos.add(value);
845 }
846 }
847
848 List<Role> list = q.list();
849
850 if (list.size() == 2) {
851 return list.get(1);
852 }
853 else {
854 return null;
855 }
856 }
857
858
863 @Override
864 public void removeByUuid(String uuid) {
865 for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
866 null)) {
867 remove(role);
868 }
869 }
870
871
877 @Override
878 public int countByUuid(String uuid) {
879 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
880
881 Object[] finderArgs = new Object[] { uuid };
882
883 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
884 this);
885
886 if (count == null) {
887 StringBundler query = new StringBundler(2);
888
889 query.append(_SQL_COUNT_ROLE_WHERE);
890
891 boolean bindUuid = false;
892
893 if (uuid == null) {
894 query.append(_FINDER_COLUMN_UUID_UUID_1);
895 }
896 else if (uuid.equals(StringPool.BLANK)) {
897 query.append(_FINDER_COLUMN_UUID_UUID_3);
898 }
899 else {
900 bindUuid = true;
901
902 query.append(_FINDER_COLUMN_UUID_UUID_2);
903 }
904
905 String sql = query.toString();
906
907 Session session = null;
908
909 try {
910 session = openSession();
911
912 Query q = session.createQuery(sql);
913
914 QueryPos qPos = QueryPos.getInstance(q);
915
916 if (bindUuid) {
917 qPos.add(uuid);
918 }
919
920 count = (Long)q.uniqueResult();
921
922 FinderCacheUtil.putResult(finderPath, finderArgs, count);
923 }
924 catch (Exception e) {
925 FinderCacheUtil.removeResult(finderPath, finderArgs);
926
927 throw processException(e);
928 }
929 finally {
930 closeSession(session);
931 }
932 }
933
934 return count.intValue();
935 }
936
937
943 @Override
944 public int filterCountByUuid(String uuid) {
945 if (!InlineSQLHelperUtil.isEnabled()) {
946 return countByUuid(uuid);
947 }
948
949 StringBundler query = new StringBundler(2);
950
951 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
952
953 boolean bindUuid = false;
954
955 if (uuid == null) {
956 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
957 }
958 else if (uuid.equals(StringPool.BLANK)) {
959 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
960 }
961 else {
962 bindUuid = true;
963
964 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
965 }
966
967 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
968 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
969
970 Session session = null;
971
972 try {
973 session = openSession();
974
975 SQLQuery q = session.createSynchronizedSQLQuery(sql);
976
977 q.addScalar(COUNT_COLUMN_NAME,
978 com.liferay.portal.kernel.dao.orm.Type.LONG);
979
980 QueryPos qPos = QueryPos.getInstance(q);
981
982 if (bindUuid) {
983 qPos.add(uuid);
984 }
985
986 Long count = (Long)q.uniqueResult();
987
988 return count.intValue();
989 }
990 catch (Exception e) {
991 throw processException(e);
992 }
993 finally {
994 closeSession(session);
995 }
996 }
997
998 private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL";
999 private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?";
1000 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')";
1001 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL";
1002 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?";
1003 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')";
1004 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1005 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1006 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1007 new String[] {
1008 String.class.getName(), Long.class.getName(),
1009
1010 Integer.class.getName(), Integer.class.getName(),
1011 OrderByComparator.class.getName()
1012 });
1013 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1014 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1015 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1016 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1017 new String[] { String.class.getName(), Long.class.getName() },
1018 RoleModelImpl.UUID_COLUMN_BITMASK |
1019 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1020 RoleModelImpl.NAME_COLUMN_BITMASK);
1021 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1022 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1023 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1024 new String[] { String.class.getName(), Long.class.getName() });
1025
1026
1033 @Override
1034 public List<Role> findByUuid_C(String uuid, long companyId) {
1035 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1036 QueryUtil.ALL_POS, null);
1037 }
1038
1039
1052 @Override
1053 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1054 int end) {
1055 return findByUuid_C(uuid, companyId, start, end, null);
1056 }
1057
1058
1072 @Override
1073 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1074 int end, OrderByComparator<Role> orderByComparator) {
1075 boolean pagination = true;
1076 FinderPath finderPath = null;
1077 Object[] finderArgs = null;
1078
1079 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1080 (orderByComparator == null)) {
1081 pagination = false;
1082 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1083 finderArgs = new Object[] { uuid, companyId };
1084 }
1085 else {
1086 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1087 finderArgs = new Object[] {
1088 uuid, companyId,
1089
1090 start, end, orderByComparator
1091 };
1092 }
1093
1094 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1095 finderArgs, this);
1096
1097 if ((list != null) && !list.isEmpty()) {
1098 for (Role role : list) {
1099 if (!Validator.equals(uuid, role.getUuid()) ||
1100 (companyId != role.getCompanyId())) {
1101 list = null;
1102
1103 break;
1104 }
1105 }
1106 }
1107
1108 if (list == null) {
1109 StringBundler query = null;
1110
1111 if (orderByComparator != null) {
1112 query = new StringBundler(4 +
1113 (orderByComparator.getOrderByFields().length * 3));
1114 }
1115 else {
1116 query = new StringBundler(4);
1117 }
1118
1119 query.append(_SQL_SELECT_ROLE_WHERE);
1120
1121 boolean bindUuid = false;
1122
1123 if (uuid == null) {
1124 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1125 }
1126 else if (uuid.equals(StringPool.BLANK)) {
1127 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1128 }
1129 else {
1130 bindUuid = true;
1131
1132 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1133 }
1134
1135 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1136
1137 if (orderByComparator != null) {
1138 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1139 orderByComparator);
1140 }
1141 else
1142 if (pagination) {
1143 query.append(RoleModelImpl.ORDER_BY_JPQL);
1144 }
1145
1146 String sql = query.toString();
1147
1148 Session session = null;
1149
1150 try {
1151 session = openSession();
1152
1153 Query q = session.createQuery(sql);
1154
1155 QueryPos qPos = QueryPos.getInstance(q);
1156
1157 if (bindUuid) {
1158 qPos.add(uuid);
1159 }
1160
1161 qPos.add(companyId);
1162
1163 if (!pagination) {
1164 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1165 end, false);
1166
1167 Collections.sort(list);
1168
1169 list = Collections.unmodifiableList(list);
1170 }
1171 else {
1172 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1173 end);
1174 }
1175
1176 cacheResult(list);
1177
1178 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1179 }
1180 catch (Exception e) {
1181 FinderCacheUtil.removeResult(finderPath, finderArgs);
1182
1183 throw processException(e);
1184 }
1185 finally {
1186 closeSession(session);
1187 }
1188 }
1189
1190 return list;
1191 }
1192
1193
1202 @Override
1203 public Role findByUuid_C_First(String uuid, long companyId,
1204 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
1205 Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1206
1207 if (role != null) {
1208 return role;
1209 }
1210
1211 StringBundler msg = new StringBundler(6);
1212
1213 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1214
1215 msg.append("uuid=");
1216 msg.append(uuid);
1217
1218 msg.append(", companyId=");
1219 msg.append(companyId);
1220
1221 msg.append(StringPool.CLOSE_CURLY_BRACE);
1222
1223 throw new NoSuchRoleException(msg.toString());
1224 }
1225
1226
1234 @Override
1235 public Role fetchByUuid_C_First(String uuid, long companyId,
1236 OrderByComparator<Role> orderByComparator) {
1237 List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1238
1239 if (!list.isEmpty()) {
1240 return list.get(0);
1241 }
1242
1243 return null;
1244 }
1245
1246
1255 @Override
1256 public Role findByUuid_C_Last(String uuid, long companyId,
1257 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
1258 Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1259
1260 if (role != null) {
1261 return role;
1262 }
1263
1264 StringBundler msg = new StringBundler(6);
1265
1266 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1267
1268 msg.append("uuid=");
1269 msg.append(uuid);
1270
1271 msg.append(", companyId=");
1272 msg.append(companyId);
1273
1274 msg.append(StringPool.CLOSE_CURLY_BRACE);
1275
1276 throw new NoSuchRoleException(msg.toString());
1277 }
1278
1279
1287 @Override
1288 public Role fetchByUuid_C_Last(String uuid, long companyId,
1289 OrderByComparator<Role> orderByComparator) {
1290 int count = countByUuid_C(uuid, companyId);
1291
1292 if (count == 0) {
1293 return null;
1294 }
1295
1296 List<Role> list = findByUuid_C(uuid, companyId, count - 1, count,
1297 orderByComparator);
1298
1299 if (!list.isEmpty()) {
1300 return list.get(0);
1301 }
1302
1303 return null;
1304 }
1305
1306
1316 @Override
1317 public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid,
1318 long companyId, OrderByComparator<Role> orderByComparator)
1319 throws NoSuchRoleException {
1320 Role role = findByPrimaryKey(roleId);
1321
1322 Session session = null;
1323
1324 try {
1325 session = openSession();
1326
1327 Role[] array = new RoleImpl[3];
1328
1329 array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1330 orderByComparator, true);
1331
1332 array[1] = role;
1333
1334 array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1335 orderByComparator, false);
1336
1337 return array;
1338 }
1339 catch (Exception e) {
1340 throw processException(e);
1341 }
1342 finally {
1343 closeSession(session);
1344 }
1345 }
1346
1347 protected Role getByUuid_C_PrevAndNext(Session session, Role role,
1348 String uuid, long companyId, OrderByComparator<Role> orderByComparator,
1349 boolean previous) {
1350 StringBundler query = null;
1351
1352 if (orderByComparator != null) {
1353 query = new StringBundler(6 +
1354 (orderByComparator.getOrderByFields().length * 6));
1355 }
1356 else {
1357 query = new StringBundler(3);
1358 }
1359
1360 query.append(_SQL_SELECT_ROLE_WHERE);
1361
1362 boolean bindUuid = false;
1363
1364 if (uuid == null) {
1365 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1366 }
1367 else if (uuid.equals(StringPool.BLANK)) {
1368 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1369 }
1370 else {
1371 bindUuid = true;
1372
1373 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1374 }
1375
1376 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1377
1378 if (orderByComparator != null) {
1379 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1380
1381 if (orderByConditionFields.length > 0) {
1382 query.append(WHERE_AND);
1383 }
1384
1385 for (int i = 0; i < orderByConditionFields.length; i++) {
1386 query.append(_ORDER_BY_ENTITY_ALIAS);
1387 query.append(orderByConditionFields[i]);
1388
1389 if ((i + 1) < orderByConditionFields.length) {
1390 if (orderByComparator.isAscending() ^ previous) {
1391 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1392 }
1393 else {
1394 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1395 }
1396 }
1397 else {
1398 if (orderByComparator.isAscending() ^ previous) {
1399 query.append(WHERE_GREATER_THAN);
1400 }
1401 else {
1402 query.append(WHERE_LESSER_THAN);
1403 }
1404 }
1405 }
1406
1407 query.append(ORDER_BY_CLAUSE);
1408
1409 String[] orderByFields = orderByComparator.getOrderByFields();
1410
1411 for (int i = 0; i < orderByFields.length; i++) {
1412 query.append(_ORDER_BY_ENTITY_ALIAS);
1413 query.append(orderByFields[i]);
1414
1415 if ((i + 1) < orderByFields.length) {
1416 if (orderByComparator.isAscending() ^ previous) {
1417 query.append(ORDER_BY_ASC_HAS_NEXT);
1418 }
1419 else {
1420 query.append(ORDER_BY_DESC_HAS_NEXT);
1421 }
1422 }
1423 else {
1424 if (orderByComparator.isAscending() ^ previous) {
1425 query.append(ORDER_BY_ASC);
1426 }
1427 else {
1428 query.append(ORDER_BY_DESC);
1429 }
1430 }
1431 }
1432 }
1433 else {
1434 query.append(RoleModelImpl.ORDER_BY_JPQL);
1435 }
1436
1437 String sql = query.toString();
1438
1439 Query q = session.createQuery(sql);
1440
1441 q.setFirstResult(0);
1442 q.setMaxResults(2);
1443
1444 QueryPos qPos = QueryPos.getInstance(q);
1445
1446 if (bindUuid) {
1447 qPos.add(uuid);
1448 }
1449
1450 qPos.add(companyId);
1451
1452 if (orderByComparator != null) {
1453 Object[] values = orderByComparator.getOrderByConditionValues(role);
1454
1455 for (Object value : values) {
1456 qPos.add(value);
1457 }
1458 }
1459
1460 List<Role> list = q.list();
1461
1462 if (list.size() == 2) {
1463 return list.get(1);
1464 }
1465 else {
1466 return null;
1467 }
1468 }
1469
1470
1477 @Override
1478 public List<Role> filterFindByUuid_C(String uuid, long companyId) {
1479 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1480 QueryUtil.ALL_POS, null);
1481 }
1482
1483
1496 @Override
1497 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1498 int start, int end) {
1499 return filterFindByUuid_C(uuid, companyId, start, end, null);
1500 }
1501
1502
1516 @Override
1517 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1518 int start, int end, OrderByComparator<Role> orderByComparator) {
1519 if (!InlineSQLHelperUtil.isEnabled()) {
1520 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1521 }
1522
1523 StringBundler query = null;
1524
1525 if (orderByComparator != null) {
1526 query = new StringBundler(4 +
1527 (orderByComparator.getOrderByFields().length * 3));
1528 }
1529 else {
1530 query = new StringBundler(4);
1531 }
1532
1533 if (getDB().isSupportsInlineDistinct()) {
1534 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1535 }
1536 else {
1537 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1538 }
1539
1540 boolean bindUuid = false;
1541
1542 if (uuid == null) {
1543 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1544 }
1545 else if (uuid.equals(StringPool.BLANK)) {
1546 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1547 }
1548 else {
1549 bindUuid = true;
1550
1551 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1552 }
1553
1554 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1555
1556 if (!getDB().isSupportsInlineDistinct()) {
1557 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1558 }
1559
1560 if (orderByComparator != null) {
1561 if (getDB().isSupportsInlineDistinct()) {
1562 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1563 orderByComparator, true);
1564 }
1565 else {
1566 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1567 orderByComparator, true);
1568 }
1569 }
1570 else {
1571 if (getDB().isSupportsInlineDistinct()) {
1572 query.append(RoleModelImpl.ORDER_BY_JPQL);
1573 }
1574 else {
1575 query.append(RoleModelImpl.ORDER_BY_SQL);
1576 }
1577 }
1578
1579 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1580 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1581
1582 Session session = null;
1583
1584 try {
1585 session = openSession();
1586
1587 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1588
1589 if (getDB().isSupportsInlineDistinct()) {
1590 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1591 }
1592 else {
1593 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1594 }
1595
1596 QueryPos qPos = QueryPos.getInstance(q);
1597
1598 if (bindUuid) {
1599 qPos.add(uuid);
1600 }
1601
1602 qPos.add(companyId);
1603
1604 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1605 }
1606 catch (Exception e) {
1607 throw processException(e);
1608 }
1609 finally {
1610 closeSession(session);
1611 }
1612 }
1613
1614
1624 @Override
1625 public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid,
1626 long companyId, OrderByComparator<Role> orderByComparator)
1627 throws NoSuchRoleException {
1628 if (!InlineSQLHelperUtil.isEnabled()) {
1629 return findByUuid_C_PrevAndNext(roleId, uuid, companyId,
1630 orderByComparator);
1631 }
1632
1633 Role role = findByPrimaryKey(roleId);
1634
1635 Session session = null;
1636
1637 try {
1638 session = openSession();
1639
1640 Role[] array = new RoleImpl[3];
1641
1642 array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1643 companyId, orderByComparator, true);
1644
1645 array[1] = role;
1646
1647 array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1648 companyId, orderByComparator, false);
1649
1650 return array;
1651 }
1652 catch (Exception e) {
1653 throw processException(e);
1654 }
1655 finally {
1656 closeSession(session);
1657 }
1658 }
1659
1660 protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role,
1661 String uuid, long companyId, OrderByComparator<Role> orderByComparator,
1662 boolean previous) {
1663 StringBundler query = null;
1664
1665 if (orderByComparator != null) {
1666 query = new StringBundler(6 +
1667 (orderByComparator.getOrderByFields().length * 6));
1668 }
1669 else {
1670 query = new StringBundler(3);
1671 }
1672
1673 if (getDB().isSupportsInlineDistinct()) {
1674 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1675 }
1676 else {
1677 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1678 }
1679
1680 boolean bindUuid = false;
1681
1682 if (uuid == null) {
1683 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1684 }
1685 else if (uuid.equals(StringPool.BLANK)) {
1686 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1687 }
1688 else {
1689 bindUuid = true;
1690
1691 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1692 }
1693
1694 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1695
1696 if (!getDB().isSupportsInlineDistinct()) {
1697 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1698 }
1699
1700 if (orderByComparator != null) {
1701 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1702
1703 if (orderByConditionFields.length > 0) {
1704 query.append(WHERE_AND);
1705 }
1706
1707 for (int i = 0; i < orderByConditionFields.length; i++) {
1708 if (getDB().isSupportsInlineDistinct()) {
1709 query.append(_ORDER_BY_ENTITY_ALIAS);
1710 }
1711 else {
1712 query.append(_ORDER_BY_ENTITY_TABLE);
1713 }
1714
1715 query.append(orderByConditionFields[i]);
1716
1717 if ((i + 1) < orderByConditionFields.length) {
1718 if (orderByComparator.isAscending() ^ previous) {
1719 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1720 }
1721 else {
1722 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1723 }
1724 }
1725 else {
1726 if (orderByComparator.isAscending() ^ previous) {
1727 query.append(WHERE_GREATER_THAN);
1728 }
1729 else {
1730 query.append(WHERE_LESSER_THAN);
1731 }
1732 }
1733 }
1734
1735 query.append(ORDER_BY_CLAUSE);
1736
1737 String[] orderByFields = orderByComparator.getOrderByFields();
1738
1739 for (int i = 0; i < orderByFields.length; i++) {
1740 if (getDB().isSupportsInlineDistinct()) {
1741 query.append(_ORDER_BY_ENTITY_ALIAS);
1742 }
1743 else {
1744 query.append(_ORDER_BY_ENTITY_TABLE);
1745 }
1746
1747 query.append(orderByFields[i]);
1748
1749 if ((i + 1) < orderByFields.length) {
1750 if (orderByComparator.isAscending() ^ previous) {
1751 query.append(ORDER_BY_ASC_HAS_NEXT);
1752 }
1753 else {
1754 query.append(ORDER_BY_DESC_HAS_NEXT);
1755 }
1756 }
1757 else {
1758 if (orderByComparator.isAscending() ^ previous) {
1759 query.append(ORDER_BY_ASC);
1760 }
1761 else {
1762 query.append(ORDER_BY_DESC);
1763 }
1764 }
1765 }
1766 }
1767 else {
1768 if (getDB().isSupportsInlineDistinct()) {
1769 query.append(RoleModelImpl.ORDER_BY_JPQL);
1770 }
1771 else {
1772 query.append(RoleModelImpl.ORDER_BY_SQL);
1773 }
1774 }
1775
1776 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1777 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1778
1779 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1780
1781 q.setFirstResult(0);
1782 q.setMaxResults(2);
1783
1784 if (getDB().isSupportsInlineDistinct()) {
1785 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1786 }
1787 else {
1788 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1789 }
1790
1791 QueryPos qPos = QueryPos.getInstance(q);
1792
1793 if (bindUuid) {
1794 qPos.add(uuid);
1795 }
1796
1797 qPos.add(companyId);
1798
1799 if (orderByComparator != null) {
1800 Object[] values = orderByComparator.getOrderByConditionValues(role);
1801
1802 for (Object value : values) {
1803 qPos.add(value);
1804 }
1805 }
1806
1807 List<Role> list = q.list();
1808
1809 if (list.size() == 2) {
1810 return list.get(1);
1811 }
1812 else {
1813 return null;
1814 }
1815 }
1816
1817
1823 @Override
1824 public void removeByUuid_C(String uuid, long companyId) {
1825 for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1826 QueryUtil.ALL_POS, null)) {
1827 remove(role);
1828 }
1829 }
1830
1831
1838 @Override
1839 public int countByUuid_C(String uuid, long companyId) {
1840 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1841
1842 Object[] finderArgs = new Object[] { uuid, companyId };
1843
1844 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1845 this);
1846
1847 if (count == null) {
1848 StringBundler query = new StringBundler(3);
1849
1850 query.append(_SQL_COUNT_ROLE_WHERE);
1851
1852 boolean bindUuid = false;
1853
1854 if (uuid == null) {
1855 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1856 }
1857 else if (uuid.equals(StringPool.BLANK)) {
1858 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1859 }
1860 else {
1861 bindUuid = true;
1862
1863 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1864 }
1865
1866 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1867
1868 String sql = query.toString();
1869
1870 Session session = null;
1871
1872 try {
1873 session = openSession();
1874
1875 Query q = session.createQuery(sql);
1876
1877 QueryPos qPos = QueryPos.getInstance(q);
1878
1879 if (bindUuid) {
1880 qPos.add(uuid);
1881 }
1882
1883 qPos.add(companyId);
1884
1885 count = (Long)q.uniqueResult();
1886
1887 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1888 }
1889 catch (Exception e) {
1890 FinderCacheUtil.removeResult(finderPath, finderArgs);
1891
1892 throw processException(e);
1893 }
1894 finally {
1895 closeSession(session);
1896 }
1897 }
1898
1899 return count.intValue();
1900 }
1901
1902
1909 @Override
1910 public int filterCountByUuid_C(String uuid, long companyId) {
1911 if (!InlineSQLHelperUtil.isEnabled()) {
1912 return countByUuid_C(uuid, companyId);
1913 }
1914
1915 StringBundler query = new StringBundler(3);
1916
1917 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1918
1919 boolean bindUuid = false;
1920
1921 if (uuid == null) {
1922 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1923 }
1924 else if (uuid.equals(StringPool.BLANK)) {
1925 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1926 }
1927 else {
1928 bindUuid = true;
1929
1930 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1931 }
1932
1933 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1934
1935 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1936 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1937
1938 Session session = null;
1939
1940 try {
1941 session = openSession();
1942
1943 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1944
1945 q.addScalar(COUNT_COLUMN_NAME,
1946 com.liferay.portal.kernel.dao.orm.Type.LONG);
1947
1948 QueryPos qPos = QueryPos.getInstance(q);
1949
1950 if (bindUuid) {
1951 qPos.add(uuid);
1952 }
1953
1954 qPos.add(companyId);
1955
1956 Long count = (Long)q.uniqueResult();
1957
1958 return count.intValue();
1959 }
1960 catch (Exception e) {
1961 throw processException(e);
1962 }
1963 finally {
1964 closeSession(session);
1965 }
1966 }
1967
1968 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND ";
1969 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND ";
1970 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND ";
1971 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND ";
1972 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND ";
1973 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND ";
1974 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?";
1975 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
1976 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1977 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1978 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
1979 new String[] {
1980 Long.class.getName(),
1981
1982 Integer.class.getName(), Integer.class.getName(),
1983 OrderByComparator.class.getName()
1984 });
1985 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
1986 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1987 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1988 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
1989 new String[] { Long.class.getName() },
1990 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1991 RoleModelImpl.NAME_COLUMN_BITMASK);
1992 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1993 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1994 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
1995 new String[] { Long.class.getName() });
1996
1997
2003 @Override
2004 public List<Role> findByCompanyId(long companyId) {
2005 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2006 null);
2007 }
2008
2009
2021 @Override
2022 public List<Role> findByCompanyId(long companyId, int start, int end) {
2023 return findByCompanyId(companyId, start, end, null);
2024 }
2025
2026
2039 @Override
2040 public List<Role> findByCompanyId(long companyId, int start, int end,
2041 OrderByComparator<Role> orderByComparator) {
2042 boolean pagination = true;
2043 FinderPath finderPath = null;
2044 Object[] finderArgs = null;
2045
2046 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2047 (orderByComparator == null)) {
2048 pagination = false;
2049 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2050 finderArgs = new Object[] { companyId };
2051 }
2052 else {
2053 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2054 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2055 }
2056
2057 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2058 finderArgs, this);
2059
2060 if ((list != null) && !list.isEmpty()) {
2061 for (Role role : list) {
2062 if ((companyId != role.getCompanyId())) {
2063 list = null;
2064
2065 break;
2066 }
2067 }
2068 }
2069
2070 if (list == null) {
2071 StringBundler query = null;
2072
2073 if (orderByComparator != null) {
2074 query = new StringBundler(3 +
2075 (orderByComparator.getOrderByFields().length * 3));
2076 }
2077 else {
2078 query = new StringBundler(3);
2079 }
2080
2081 query.append(_SQL_SELECT_ROLE_WHERE);
2082
2083 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2084
2085 if (orderByComparator != null) {
2086 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2087 orderByComparator);
2088 }
2089 else
2090 if (pagination) {
2091 query.append(RoleModelImpl.ORDER_BY_JPQL);
2092 }
2093
2094 String sql = query.toString();
2095
2096 Session session = null;
2097
2098 try {
2099 session = openSession();
2100
2101 Query q = session.createQuery(sql);
2102
2103 QueryPos qPos = QueryPos.getInstance(q);
2104
2105 qPos.add(companyId);
2106
2107 if (!pagination) {
2108 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2109 end, false);
2110
2111 Collections.sort(list);
2112
2113 list = Collections.unmodifiableList(list);
2114 }
2115 else {
2116 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2117 end);
2118 }
2119
2120 cacheResult(list);
2121
2122 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2123 }
2124 catch (Exception e) {
2125 FinderCacheUtil.removeResult(finderPath, finderArgs);
2126
2127 throw processException(e);
2128 }
2129 finally {
2130 closeSession(session);
2131 }
2132 }
2133
2134 return list;
2135 }
2136
2137
2145 @Override
2146 public Role findByCompanyId_First(long companyId,
2147 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2148 Role role = fetchByCompanyId_First(companyId, orderByComparator);
2149
2150 if (role != null) {
2151 return role;
2152 }
2153
2154 StringBundler msg = new StringBundler(4);
2155
2156 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2157
2158 msg.append("companyId=");
2159 msg.append(companyId);
2160
2161 msg.append(StringPool.CLOSE_CURLY_BRACE);
2162
2163 throw new NoSuchRoleException(msg.toString());
2164 }
2165
2166
2173 @Override
2174 public Role fetchByCompanyId_First(long companyId,
2175 OrderByComparator<Role> orderByComparator) {
2176 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2177
2178 if (!list.isEmpty()) {
2179 return list.get(0);
2180 }
2181
2182 return null;
2183 }
2184
2185
2193 @Override
2194 public Role findByCompanyId_Last(long companyId,
2195 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2196 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
2197
2198 if (role != null) {
2199 return role;
2200 }
2201
2202 StringBundler msg = new StringBundler(4);
2203
2204 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2205
2206 msg.append("companyId=");
2207 msg.append(companyId);
2208
2209 msg.append(StringPool.CLOSE_CURLY_BRACE);
2210
2211 throw new NoSuchRoleException(msg.toString());
2212 }
2213
2214
2221 @Override
2222 public Role fetchByCompanyId_Last(long companyId,
2223 OrderByComparator<Role> orderByComparator) {
2224 int count = countByCompanyId(companyId);
2225
2226 if (count == 0) {
2227 return null;
2228 }
2229
2230 List<Role> list = findByCompanyId(companyId, count - 1, count,
2231 orderByComparator);
2232
2233 if (!list.isEmpty()) {
2234 return list.get(0);
2235 }
2236
2237 return null;
2238 }
2239
2240
2249 @Override
2250 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
2251 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2252 Role role = findByPrimaryKey(roleId);
2253
2254 Session session = null;
2255
2256 try {
2257 session = openSession();
2258
2259 Role[] array = new RoleImpl[3];
2260
2261 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
2262 orderByComparator, true);
2263
2264 array[1] = role;
2265
2266 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
2267 orderByComparator, false);
2268
2269 return array;
2270 }
2271 catch (Exception e) {
2272 throw processException(e);
2273 }
2274 finally {
2275 closeSession(session);
2276 }
2277 }
2278
2279 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
2280 long companyId, OrderByComparator<Role> orderByComparator,
2281 boolean previous) {
2282 StringBundler query = null;
2283
2284 if (orderByComparator != null) {
2285 query = new StringBundler(6 +
2286 (orderByComparator.getOrderByFields().length * 6));
2287 }
2288 else {
2289 query = new StringBundler(3);
2290 }
2291
2292 query.append(_SQL_SELECT_ROLE_WHERE);
2293
2294 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2295
2296 if (orderByComparator != null) {
2297 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2298
2299 if (orderByConditionFields.length > 0) {
2300 query.append(WHERE_AND);
2301 }
2302
2303 for (int i = 0; i < orderByConditionFields.length; i++) {
2304 query.append(_ORDER_BY_ENTITY_ALIAS);
2305 query.append(orderByConditionFields[i]);
2306
2307 if ((i + 1) < orderByConditionFields.length) {
2308 if (orderByComparator.isAscending() ^ previous) {
2309 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2310 }
2311 else {
2312 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2313 }
2314 }
2315 else {
2316 if (orderByComparator.isAscending() ^ previous) {
2317 query.append(WHERE_GREATER_THAN);
2318 }
2319 else {
2320 query.append(WHERE_LESSER_THAN);
2321 }
2322 }
2323 }
2324
2325 query.append(ORDER_BY_CLAUSE);
2326
2327 String[] orderByFields = orderByComparator.getOrderByFields();
2328
2329 for (int i = 0; i < orderByFields.length; i++) {
2330 query.append(_ORDER_BY_ENTITY_ALIAS);
2331 query.append(orderByFields[i]);
2332
2333 if ((i + 1) < orderByFields.length) {
2334 if (orderByComparator.isAscending() ^ previous) {
2335 query.append(ORDER_BY_ASC_HAS_NEXT);
2336 }
2337 else {
2338 query.append(ORDER_BY_DESC_HAS_NEXT);
2339 }
2340 }
2341 else {
2342 if (orderByComparator.isAscending() ^ previous) {
2343 query.append(ORDER_BY_ASC);
2344 }
2345 else {
2346 query.append(ORDER_BY_DESC);
2347 }
2348 }
2349 }
2350 }
2351 else {
2352 query.append(RoleModelImpl.ORDER_BY_JPQL);
2353 }
2354
2355 String sql = query.toString();
2356
2357 Query q = session.createQuery(sql);
2358
2359 q.setFirstResult(0);
2360 q.setMaxResults(2);
2361
2362 QueryPos qPos = QueryPos.getInstance(q);
2363
2364 qPos.add(companyId);
2365
2366 if (orderByComparator != null) {
2367 Object[] values = orderByComparator.getOrderByConditionValues(role);
2368
2369 for (Object value : values) {
2370 qPos.add(value);
2371 }
2372 }
2373
2374 List<Role> list = q.list();
2375
2376 if (list.size() == 2) {
2377 return list.get(1);
2378 }
2379 else {
2380 return null;
2381 }
2382 }
2383
2384
2390 @Override
2391 public List<Role> filterFindByCompanyId(long companyId) {
2392 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2393 QueryUtil.ALL_POS, null);
2394 }
2395
2396
2408 @Override
2409 public List<Role> filterFindByCompanyId(long companyId, int start, int end) {
2410 return filterFindByCompanyId(companyId, start, end, null);
2411 }
2412
2413
2426 @Override
2427 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
2428 OrderByComparator<Role> orderByComparator) {
2429 if (!InlineSQLHelperUtil.isEnabled()) {
2430 return findByCompanyId(companyId, start, end, orderByComparator);
2431 }
2432
2433 StringBundler query = null;
2434
2435 if (orderByComparator != null) {
2436 query = new StringBundler(3 +
2437 (orderByComparator.getOrderByFields().length * 3));
2438 }
2439 else {
2440 query = new StringBundler(3);
2441 }
2442
2443 if (getDB().isSupportsInlineDistinct()) {
2444 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2445 }
2446 else {
2447 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2448 }
2449
2450 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2451
2452 if (!getDB().isSupportsInlineDistinct()) {
2453 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2454 }
2455
2456 if (orderByComparator != null) {
2457 if (getDB().isSupportsInlineDistinct()) {
2458 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2459 orderByComparator, true);
2460 }
2461 else {
2462 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2463 orderByComparator, true);
2464 }
2465 }
2466 else {
2467 if (getDB().isSupportsInlineDistinct()) {
2468 query.append(RoleModelImpl.ORDER_BY_JPQL);
2469 }
2470 else {
2471 query.append(RoleModelImpl.ORDER_BY_SQL);
2472 }
2473 }
2474
2475 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2476 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2477
2478 Session session = null;
2479
2480 try {
2481 session = openSession();
2482
2483 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2484
2485 if (getDB().isSupportsInlineDistinct()) {
2486 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2487 }
2488 else {
2489 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2490 }
2491
2492 QueryPos qPos = QueryPos.getInstance(q);
2493
2494 qPos.add(companyId);
2495
2496 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2497 }
2498 catch (Exception e) {
2499 throw processException(e);
2500 }
2501 finally {
2502 closeSession(session);
2503 }
2504 }
2505
2506
2515 @Override
2516 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
2517 long companyId, OrderByComparator<Role> orderByComparator)
2518 throws NoSuchRoleException {
2519 if (!InlineSQLHelperUtil.isEnabled()) {
2520 return findByCompanyId_PrevAndNext(roleId, companyId,
2521 orderByComparator);
2522 }
2523
2524 Role role = findByPrimaryKey(roleId);
2525
2526 Session session = null;
2527
2528 try {
2529 session = openSession();
2530
2531 Role[] array = new RoleImpl[3];
2532
2533 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
2534 companyId, orderByComparator, true);
2535
2536 array[1] = role;
2537
2538 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
2539 companyId, orderByComparator, false);
2540
2541 return array;
2542 }
2543 catch (Exception e) {
2544 throw processException(e);
2545 }
2546 finally {
2547 closeSession(session);
2548 }
2549 }
2550
2551 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
2552 long companyId, OrderByComparator<Role> orderByComparator,
2553 boolean previous) {
2554 StringBundler query = null;
2555
2556 if (orderByComparator != null) {
2557 query = new StringBundler(6 +
2558 (orderByComparator.getOrderByFields().length * 6));
2559 }
2560 else {
2561 query = new StringBundler(3);
2562 }
2563
2564 if (getDB().isSupportsInlineDistinct()) {
2565 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2566 }
2567 else {
2568 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2569 }
2570
2571 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2572
2573 if (!getDB().isSupportsInlineDistinct()) {
2574 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2575 }
2576
2577 if (orderByComparator != null) {
2578 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2579
2580 if (orderByConditionFields.length > 0) {
2581 query.append(WHERE_AND);
2582 }
2583
2584 for (int i = 0; i < orderByConditionFields.length; i++) {
2585 if (getDB().isSupportsInlineDistinct()) {
2586 query.append(_ORDER_BY_ENTITY_ALIAS);
2587 }
2588 else {
2589 query.append(_ORDER_BY_ENTITY_TABLE);
2590 }
2591
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 if (getDB().isSupportsInlineDistinct()) {
2618 query.append(_ORDER_BY_ENTITY_ALIAS);
2619 }
2620 else {
2621 query.append(_ORDER_BY_ENTITY_TABLE);
2622 }
2623
2624 query.append(orderByFields[i]);
2625
2626 if ((i + 1) < orderByFields.length) {
2627 if (orderByComparator.isAscending() ^ previous) {
2628 query.append(ORDER_BY_ASC_HAS_NEXT);
2629 }
2630 else {
2631 query.append(ORDER_BY_DESC_HAS_NEXT);
2632 }
2633 }
2634 else {
2635 if (orderByComparator.isAscending() ^ previous) {
2636 query.append(ORDER_BY_ASC);
2637 }
2638 else {
2639 query.append(ORDER_BY_DESC);
2640 }
2641 }
2642 }
2643 }
2644 else {
2645 if (getDB().isSupportsInlineDistinct()) {
2646 query.append(RoleModelImpl.ORDER_BY_JPQL);
2647 }
2648 else {
2649 query.append(RoleModelImpl.ORDER_BY_SQL);
2650 }
2651 }
2652
2653 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2654 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2655
2656 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2657
2658 q.setFirstResult(0);
2659 q.setMaxResults(2);
2660
2661 if (getDB().isSupportsInlineDistinct()) {
2662 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2663 }
2664 else {
2665 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2666 }
2667
2668 QueryPos qPos = QueryPos.getInstance(q);
2669
2670 qPos.add(companyId);
2671
2672 if (orderByComparator != null) {
2673 Object[] values = orderByComparator.getOrderByConditionValues(role);
2674
2675 for (Object value : values) {
2676 qPos.add(value);
2677 }
2678 }
2679
2680 List<Role> list = q.list();
2681
2682 if (list.size() == 2) {
2683 return list.get(1);
2684 }
2685 else {
2686 return null;
2687 }
2688 }
2689
2690
2695 @Override
2696 public void removeByCompanyId(long companyId) {
2697 for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
2698 QueryUtil.ALL_POS, null)) {
2699 remove(role);
2700 }
2701 }
2702
2703
2709 @Override
2710 public int countByCompanyId(long companyId) {
2711 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2712
2713 Object[] finderArgs = new Object[] { companyId };
2714
2715 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2716 this);
2717
2718 if (count == null) {
2719 StringBundler query = new StringBundler(2);
2720
2721 query.append(_SQL_COUNT_ROLE_WHERE);
2722
2723 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2724
2725 String sql = query.toString();
2726
2727 Session session = null;
2728
2729 try {
2730 session = openSession();
2731
2732 Query q = session.createQuery(sql);
2733
2734 QueryPos qPos = QueryPos.getInstance(q);
2735
2736 qPos.add(companyId);
2737
2738 count = (Long)q.uniqueResult();
2739
2740 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2741 }
2742 catch (Exception e) {
2743 FinderCacheUtil.removeResult(finderPath, finderArgs);
2744
2745 throw processException(e);
2746 }
2747 finally {
2748 closeSession(session);
2749 }
2750 }
2751
2752 return count.intValue();
2753 }
2754
2755
2761 @Override
2762 public int filterCountByCompanyId(long companyId) {
2763 if (!InlineSQLHelperUtil.isEnabled()) {
2764 return countByCompanyId(companyId);
2765 }
2766
2767 StringBundler query = new StringBundler(2);
2768
2769 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2770
2771 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2772
2773 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2774 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2775
2776 Session session = null;
2777
2778 try {
2779 session = openSession();
2780
2781 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2782
2783 q.addScalar(COUNT_COLUMN_NAME,
2784 com.liferay.portal.kernel.dao.orm.Type.LONG);
2785
2786 QueryPos qPos = QueryPos.getInstance(q);
2787
2788 qPos.add(companyId);
2789
2790 Long count = (Long)q.uniqueResult();
2791
2792 return count.intValue();
2793 }
2794 catch (Exception e) {
2795 throw processException(e);
2796 }
2797 finally {
2798 closeSession(session);
2799 }
2800 }
2801
2802 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
2803 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2804 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2805 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
2806 new String[] {
2807 String.class.getName(),
2808
2809 Integer.class.getName(), Integer.class.getName(),
2810 OrderByComparator.class.getName()
2811 });
2812 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2813 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2814 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
2815 new String[] { String.class.getName() },
2816 RoleModelImpl.NAME_COLUMN_BITMASK);
2817 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2818 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2819 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
2820 new String[] { String.class.getName() });
2821
2822
2828 @Override
2829 public List<Role> findByName(String name) {
2830 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2831 }
2832
2833
2845 @Override
2846 public List<Role> findByName(String name, int start, int end) {
2847 return findByName(name, start, end, null);
2848 }
2849
2850
2863 @Override
2864 public List<Role> findByName(String name, int start, int end,
2865 OrderByComparator<Role> orderByComparator) {
2866 boolean pagination = true;
2867 FinderPath finderPath = null;
2868 Object[] finderArgs = null;
2869
2870 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2871 (orderByComparator == null)) {
2872 pagination = false;
2873 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
2874 finderArgs = new Object[] { name };
2875 }
2876 else {
2877 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
2878 finderArgs = new Object[] { name, start, end, orderByComparator };
2879 }
2880
2881 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2882 finderArgs, this);
2883
2884 if ((list != null) && !list.isEmpty()) {
2885 for (Role role : list) {
2886 if (!Validator.equals(name, role.getName())) {
2887 list = null;
2888
2889 break;
2890 }
2891 }
2892 }
2893
2894 if (list == null) {
2895 StringBundler query = null;
2896
2897 if (orderByComparator != null) {
2898 query = new StringBundler(3 +
2899 (orderByComparator.getOrderByFields().length * 3));
2900 }
2901 else {
2902 query = new StringBundler(3);
2903 }
2904
2905 query.append(_SQL_SELECT_ROLE_WHERE);
2906
2907 boolean bindName = false;
2908
2909 if (name == null) {
2910 query.append(_FINDER_COLUMN_NAME_NAME_1);
2911 }
2912 else if (name.equals(StringPool.BLANK)) {
2913 query.append(_FINDER_COLUMN_NAME_NAME_3);
2914 }
2915 else {
2916 bindName = true;
2917
2918 query.append(_FINDER_COLUMN_NAME_NAME_2);
2919 }
2920
2921 if (orderByComparator != null) {
2922 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2923 orderByComparator);
2924 }
2925 else
2926 if (pagination) {
2927 query.append(RoleModelImpl.ORDER_BY_JPQL);
2928 }
2929
2930 String sql = query.toString();
2931
2932 Session session = null;
2933
2934 try {
2935 session = openSession();
2936
2937 Query q = session.createQuery(sql);
2938
2939 QueryPos qPos = QueryPos.getInstance(q);
2940
2941 if (bindName) {
2942 qPos.add(name);
2943 }
2944
2945 if (!pagination) {
2946 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2947 end, false);
2948
2949 Collections.sort(list);
2950
2951 list = Collections.unmodifiableList(list);
2952 }
2953 else {
2954 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2955 end);
2956 }
2957
2958 cacheResult(list);
2959
2960 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2961 }
2962 catch (Exception e) {
2963 FinderCacheUtil.removeResult(finderPath, finderArgs);
2964
2965 throw processException(e);
2966 }
2967 finally {
2968 closeSession(session);
2969 }
2970 }
2971
2972 return list;
2973 }
2974
2975
2983 @Override
2984 public Role findByName_First(String name,
2985 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2986 Role role = fetchByName_First(name, orderByComparator);
2987
2988 if (role != null) {
2989 return role;
2990 }
2991
2992 StringBundler msg = new StringBundler(4);
2993
2994 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2995
2996 msg.append("name=");
2997 msg.append(name);
2998
2999 msg.append(StringPool.CLOSE_CURLY_BRACE);
3000
3001 throw new NoSuchRoleException(msg.toString());
3002 }
3003
3004
3011 @Override
3012 public Role fetchByName_First(String name,
3013 OrderByComparator<Role> orderByComparator) {
3014 List<Role> list = findByName(name, 0, 1, orderByComparator);
3015
3016 if (!list.isEmpty()) {
3017 return list.get(0);
3018 }
3019
3020 return null;
3021 }
3022
3023
3031 @Override
3032 public Role findByName_Last(String name,
3033 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3034 Role role = fetchByName_Last(name, orderByComparator);
3035
3036 if (role != null) {
3037 return role;
3038 }
3039
3040 StringBundler msg = new StringBundler(4);
3041
3042 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3043
3044 msg.append("name=");
3045 msg.append(name);
3046
3047 msg.append(StringPool.CLOSE_CURLY_BRACE);
3048
3049 throw new NoSuchRoleException(msg.toString());
3050 }
3051
3052
3059 @Override
3060 public Role fetchByName_Last(String name,
3061 OrderByComparator<Role> orderByComparator) {
3062 int count = countByName(name);
3063
3064 if (count == 0) {
3065 return null;
3066 }
3067
3068 List<Role> list = findByName(name, count - 1, count, orderByComparator);
3069
3070 if (!list.isEmpty()) {
3071 return list.get(0);
3072 }
3073
3074 return null;
3075 }
3076
3077
3086 @Override
3087 public Role[] findByName_PrevAndNext(long roleId, String name,
3088 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3089 Role role = findByPrimaryKey(roleId);
3090
3091 Session session = null;
3092
3093 try {
3094 session = openSession();
3095
3096 Role[] array = new RoleImpl[3];
3097
3098 array[0] = getByName_PrevAndNext(session, role, name,
3099 orderByComparator, true);
3100
3101 array[1] = role;
3102
3103 array[2] = getByName_PrevAndNext(session, role, name,
3104 orderByComparator, false);
3105
3106 return array;
3107 }
3108 catch (Exception e) {
3109 throw processException(e);
3110 }
3111 finally {
3112 closeSession(session);
3113 }
3114 }
3115
3116 protected Role getByName_PrevAndNext(Session session, Role role,
3117 String name, OrderByComparator<Role> orderByComparator, boolean previous) {
3118 StringBundler query = null;
3119
3120 if (orderByComparator != null) {
3121 query = new StringBundler(6 +
3122 (orderByComparator.getOrderByFields().length * 6));
3123 }
3124 else {
3125 query = new StringBundler(3);
3126 }
3127
3128 query.append(_SQL_SELECT_ROLE_WHERE);
3129
3130 boolean bindName = false;
3131
3132 if (name == null) {
3133 query.append(_FINDER_COLUMN_NAME_NAME_1);
3134 }
3135 else if (name.equals(StringPool.BLANK)) {
3136 query.append(_FINDER_COLUMN_NAME_NAME_3);
3137 }
3138 else {
3139 bindName = true;
3140
3141 query.append(_FINDER_COLUMN_NAME_NAME_2);
3142 }
3143
3144 if (orderByComparator != null) {
3145 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3146
3147 if (orderByConditionFields.length > 0) {
3148 query.append(WHERE_AND);
3149 }
3150
3151 for (int i = 0; i < orderByConditionFields.length; i++) {
3152 query.append(_ORDER_BY_ENTITY_ALIAS);
3153 query.append(orderByConditionFields[i]);
3154
3155 if ((i + 1) < orderByConditionFields.length) {
3156 if (orderByComparator.isAscending() ^ previous) {
3157 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3158 }
3159 else {
3160 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3161 }
3162 }
3163 else {
3164 if (orderByComparator.isAscending() ^ previous) {
3165 query.append(WHERE_GREATER_THAN);
3166 }
3167 else {
3168 query.append(WHERE_LESSER_THAN);
3169 }
3170 }
3171 }
3172
3173 query.append(ORDER_BY_CLAUSE);
3174
3175 String[] orderByFields = orderByComparator.getOrderByFields();
3176
3177 for (int i = 0; i < orderByFields.length; i++) {
3178 query.append(_ORDER_BY_ENTITY_ALIAS);
3179 query.append(orderByFields[i]);
3180
3181 if ((i + 1) < orderByFields.length) {
3182 if (orderByComparator.isAscending() ^ previous) {
3183 query.append(ORDER_BY_ASC_HAS_NEXT);
3184 }
3185 else {
3186 query.append(ORDER_BY_DESC_HAS_NEXT);
3187 }
3188 }
3189 else {
3190 if (orderByComparator.isAscending() ^ previous) {
3191 query.append(ORDER_BY_ASC);
3192 }
3193 else {
3194 query.append(ORDER_BY_DESC);
3195 }
3196 }
3197 }
3198 }
3199 else {
3200 query.append(RoleModelImpl.ORDER_BY_JPQL);
3201 }
3202
3203 String sql = query.toString();
3204
3205 Query q = session.createQuery(sql);
3206
3207 q.setFirstResult(0);
3208 q.setMaxResults(2);
3209
3210 QueryPos qPos = QueryPos.getInstance(q);
3211
3212 if (bindName) {
3213 qPos.add(name);
3214 }
3215
3216 if (orderByComparator != null) {
3217 Object[] values = orderByComparator.getOrderByConditionValues(role);
3218
3219 for (Object value : values) {
3220 qPos.add(value);
3221 }
3222 }
3223
3224 List<Role> list = q.list();
3225
3226 if (list.size() == 2) {
3227 return list.get(1);
3228 }
3229 else {
3230 return null;
3231 }
3232 }
3233
3234
3240 @Override
3241 public List<Role> filterFindByName(String name) {
3242 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3243 }
3244
3245
3257 @Override
3258 public List<Role> filterFindByName(String name, int start, int end) {
3259 return filterFindByName(name, start, end, null);
3260 }
3261
3262
3275 @Override
3276 public List<Role> filterFindByName(String name, int start, int end,
3277 OrderByComparator<Role> orderByComparator) {
3278 if (!InlineSQLHelperUtil.isEnabled()) {
3279 return findByName(name, start, end, orderByComparator);
3280 }
3281
3282 StringBundler query = null;
3283
3284 if (orderByComparator != null) {
3285 query = new StringBundler(3 +
3286 (orderByComparator.getOrderByFields().length * 3));
3287 }
3288 else {
3289 query = new StringBundler(3);
3290 }
3291
3292 if (getDB().isSupportsInlineDistinct()) {
3293 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3294 }
3295 else {
3296 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3297 }
3298
3299 boolean bindName = false;
3300
3301 if (name == null) {
3302 query.append(_FINDER_COLUMN_NAME_NAME_1);
3303 }
3304 else if (name.equals(StringPool.BLANK)) {
3305 query.append(_FINDER_COLUMN_NAME_NAME_3);
3306 }
3307 else {
3308 bindName = true;
3309
3310 query.append(_FINDER_COLUMN_NAME_NAME_2);
3311 }
3312
3313 if (!getDB().isSupportsInlineDistinct()) {
3314 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3315 }
3316
3317 if (orderByComparator != null) {
3318 if (getDB().isSupportsInlineDistinct()) {
3319 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3320 orderByComparator, true);
3321 }
3322 else {
3323 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3324 orderByComparator, true);
3325 }
3326 }
3327 else {
3328 if (getDB().isSupportsInlineDistinct()) {
3329 query.append(RoleModelImpl.ORDER_BY_JPQL);
3330 }
3331 else {
3332 query.append(RoleModelImpl.ORDER_BY_SQL);
3333 }
3334 }
3335
3336 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3337 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3338
3339 Session session = null;
3340
3341 try {
3342 session = openSession();
3343
3344 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3345
3346 if (getDB().isSupportsInlineDistinct()) {
3347 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3348 }
3349 else {
3350 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3351 }
3352
3353 QueryPos qPos = QueryPos.getInstance(q);
3354
3355 if (bindName) {
3356 qPos.add(name);
3357 }
3358
3359 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3360 }
3361 catch (Exception e) {
3362 throw processException(e);
3363 }
3364 finally {
3365 closeSession(session);
3366 }
3367 }
3368
3369
3378 @Override
3379 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
3380 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3381 if (!InlineSQLHelperUtil.isEnabled()) {
3382 return findByName_PrevAndNext(roleId, name, orderByComparator);
3383 }
3384
3385 Role role = findByPrimaryKey(roleId);
3386
3387 Session session = null;
3388
3389 try {
3390 session = openSession();
3391
3392 Role[] array = new RoleImpl[3];
3393
3394 array[0] = filterGetByName_PrevAndNext(session, role, name,
3395 orderByComparator, true);
3396
3397 array[1] = role;
3398
3399 array[2] = filterGetByName_PrevAndNext(session, role, name,
3400 orderByComparator, false);
3401
3402 return array;
3403 }
3404 catch (Exception e) {
3405 throw processException(e);
3406 }
3407 finally {
3408 closeSession(session);
3409 }
3410 }
3411
3412 protected Role filterGetByName_PrevAndNext(Session session, Role role,
3413 String name, OrderByComparator<Role> orderByComparator, boolean previous) {
3414 StringBundler query = null;
3415
3416 if (orderByComparator != null) {
3417 query = new StringBundler(6 +
3418 (orderByComparator.getOrderByFields().length * 6));
3419 }
3420 else {
3421 query = new StringBundler(3);
3422 }
3423
3424 if (getDB().isSupportsInlineDistinct()) {
3425 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3426 }
3427 else {
3428 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3429 }
3430
3431 boolean bindName = false;
3432
3433 if (name == null) {
3434 query.append(_FINDER_COLUMN_NAME_NAME_1);
3435 }
3436 else if (name.equals(StringPool.BLANK)) {
3437 query.append(_FINDER_COLUMN_NAME_NAME_3);
3438 }
3439 else {
3440 bindName = true;
3441
3442 query.append(_FINDER_COLUMN_NAME_NAME_2);
3443 }
3444
3445 if (!getDB().isSupportsInlineDistinct()) {
3446 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3447 }
3448
3449 if (orderByComparator != null) {
3450 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3451
3452 if (orderByConditionFields.length > 0) {
3453 query.append(WHERE_AND);
3454 }
3455
3456 for (int i = 0; i < orderByConditionFields.length; i++) {
3457 if (getDB().isSupportsInlineDistinct()) {
3458 query.append(_ORDER_BY_ENTITY_ALIAS);
3459 }
3460 else {
3461 query.append(_ORDER_BY_ENTITY_TABLE);
3462 }
3463
3464 query.append(orderByConditionFields[i]);
3465
3466 if ((i + 1) < orderByConditionFields.length) {
3467 if (orderByComparator.isAscending() ^ previous) {
3468 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3469 }
3470 else {
3471 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3472 }
3473 }
3474 else {
3475 if (orderByComparator.isAscending() ^ previous) {
3476 query.append(WHERE_GREATER_THAN);
3477 }
3478 else {
3479 query.append(WHERE_LESSER_THAN);
3480 }
3481 }
3482 }
3483
3484 query.append(ORDER_BY_CLAUSE);
3485
3486 String[] orderByFields = orderByComparator.getOrderByFields();
3487
3488 for (int i = 0; i < orderByFields.length; i++) {
3489 if (getDB().isSupportsInlineDistinct()) {
3490 query.append(_ORDER_BY_ENTITY_ALIAS);
3491 }
3492 else {
3493 query.append(_ORDER_BY_ENTITY_TABLE);
3494 }
3495
3496 query.append(orderByFields[i]);
3497
3498 if ((i + 1) < orderByFields.length) {
3499 if (orderByComparator.isAscending() ^ previous) {
3500 query.append(ORDER_BY_ASC_HAS_NEXT);
3501 }
3502 else {
3503 query.append(ORDER_BY_DESC_HAS_NEXT);
3504 }
3505 }
3506 else {
3507 if (orderByComparator.isAscending() ^ previous) {
3508 query.append(ORDER_BY_ASC);
3509 }
3510 else {
3511 query.append(ORDER_BY_DESC);
3512 }
3513 }
3514 }
3515 }
3516 else {
3517 if (getDB().isSupportsInlineDistinct()) {
3518 query.append(RoleModelImpl.ORDER_BY_JPQL);
3519 }
3520 else {
3521 query.append(RoleModelImpl.ORDER_BY_SQL);
3522 }
3523 }
3524
3525 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3526 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3527
3528 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3529
3530 q.setFirstResult(0);
3531 q.setMaxResults(2);
3532
3533 if (getDB().isSupportsInlineDistinct()) {
3534 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3535 }
3536 else {
3537 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3538 }
3539
3540 QueryPos qPos = QueryPos.getInstance(q);
3541
3542 if (bindName) {
3543 qPos.add(name);
3544 }
3545
3546 if (orderByComparator != null) {
3547 Object[] values = orderByComparator.getOrderByConditionValues(role);
3548
3549 for (Object value : values) {
3550 qPos.add(value);
3551 }
3552 }
3553
3554 List<Role> list = q.list();
3555
3556 if (list.size() == 2) {
3557 return list.get(1);
3558 }
3559 else {
3560 return null;
3561 }
3562 }
3563
3564
3569 @Override
3570 public void removeByName(String name) {
3571 for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3572 null)) {
3573 remove(role);
3574 }
3575 }
3576
3577
3583 @Override
3584 public int countByName(String name) {
3585 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
3586
3587 Object[] finderArgs = new Object[] { name };
3588
3589 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3590 this);
3591
3592 if (count == null) {
3593 StringBundler query = new StringBundler(2);
3594
3595 query.append(_SQL_COUNT_ROLE_WHERE);
3596
3597 boolean bindName = false;
3598
3599 if (name == null) {
3600 query.append(_FINDER_COLUMN_NAME_NAME_1);
3601 }
3602 else if (name.equals(StringPool.BLANK)) {
3603 query.append(_FINDER_COLUMN_NAME_NAME_3);
3604 }
3605 else {
3606 bindName = true;
3607
3608 query.append(_FINDER_COLUMN_NAME_NAME_2);
3609 }
3610
3611 String sql = query.toString();
3612
3613 Session session = null;
3614
3615 try {
3616 session = openSession();
3617
3618 Query q = session.createQuery(sql);
3619
3620 QueryPos qPos = QueryPos.getInstance(q);
3621
3622 if (bindName) {
3623 qPos.add(name);
3624 }
3625
3626 count = (Long)q.uniqueResult();
3627
3628 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3629 }
3630 catch (Exception e) {
3631 FinderCacheUtil.removeResult(finderPath, finderArgs);
3632
3633 throw processException(e);
3634 }
3635 finally {
3636 closeSession(session);
3637 }
3638 }
3639
3640 return count.intValue();
3641 }
3642
3643
3649 @Override
3650 public int filterCountByName(String name) {
3651 if (!InlineSQLHelperUtil.isEnabled()) {
3652 return countByName(name);
3653 }
3654
3655 StringBundler query = new StringBundler(2);
3656
3657 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3658
3659 boolean bindName = false;
3660
3661 if (name == null) {
3662 query.append(_FINDER_COLUMN_NAME_NAME_1);
3663 }
3664 else if (name.equals(StringPool.BLANK)) {
3665 query.append(_FINDER_COLUMN_NAME_NAME_3);
3666 }
3667 else {
3668 bindName = true;
3669
3670 query.append(_FINDER_COLUMN_NAME_NAME_2);
3671 }
3672
3673 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3674 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3675
3676 Session session = null;
3677
3678 try {
3679 session = openSession();
3680
3681 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3682
3683 q.addScalar(COUNT_COLUMN_NAME,
3684 com.liferay.portal.kernel.dao.orm.Type.LONG);
3685
3686 QueryPos qPos = QueryPos.getInstance(q);
3687
3688 if (bindName) {
3689 qPos.add(name);
3690 }
3691
3692 Long count = (Long)q.uniqueResult();
3693
3694 return count.intValue();
3695 }
3696 catch (Exception e) {
3697 throw processException(e);
3698 }
3699 finally {
3700 closeSession(session);
3701 }
3702 }
3703
3704 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
3705 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
3706 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')";
3707 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3708 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3709 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3710 new String[] {
3711 Integer.class.getName(),
3712
3713 Integer.class.getName(), Integer.class.getName(),
3714 OrderByComparator.class.getName()
3715 });
3716 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3717 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3718 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3719 new String[] { Integer.class.getName() },
3720 RoleModelImpl.TYPE_COLUMN_BITMASK |
3721 RoleModelImpl.NAME_COLUMN_BITMASK);
3722 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3723 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3724 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3725 new String[] { Integer.class.getName() });
3726
3727
3733 @Override
3734 public List<Role> findByType(int type) {
3735 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3736 }
3737
3738
3750 @Override
3751 public List<Role> findByType(int type, int start, int end) {
3752 return findByType(type, start, end, null);
3753 }
3754
3755
3768 @Override
3769 public List<Role> findByType(int type, int start, int end,
3770 OrderByComparator<Role> orderByComparator) {
3771 boolean pagination = true;
3772 FinderPath finderPath = null;
3773 Object[] finderArgs = null;
3774
3775 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3776 (orderByComparator == null)) {
3777 pagination = false;
3778 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3779 finderArgs = new Object[] { type };
3780 }
3781 else {
3782 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3783 finderArgs = new Object[] { type, start, end, orderByComparator };
3784 }
3785
3786 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
3787 finderArgs, this);
3788
3789 if ((list != null) && !list.isEmpty()) {
3790 for (Role role : list) {
3791 if ((type != role.getType())) {
3792 list = null;
3793
3794 break;
3795 }
3796 }
3797 }
3798
3799 if (list == null) {
3800 StringBundler query = null;
3801
3802 if (orderByComparator != null) {
3803 query = new StringBundler(3 +
3804 (orderByComparator.getOrderByFields().length * 3));
3805 }
3806 else {
3807 query = new StringBundler(3);
3808 }
3809
3810 query.append(_SQL_SELECT_ROLE_WHERE);
3811
3812 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3813
3814 if (orderByComparator != null) {
3815 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3816 orderByComparator);
3817 }
3818 else
3819 if (pagination) {
3820 query.append(RoleModelImpl.ORDER_BY_JPQL);
3821 }
3822
3823 String sql = query.toString();
3824
3825 Session session = null;
3826
3827 try {
3828 session = openSession();
3829
3830 Query q = session.createQuery(sql);
3831
3832 QueryPos qPos = QueryPos.getInstance(q);
3833
3834 qPos.add(type);
3835
3836 if (!pagination) {
3837 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3838 end, false);
3839
3840 Collections.sort(list);
3841
3842 list = Collections.unmodifiableList(list);
3843 }
3844 else {
3845 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3846 end);
3847 }
3848
3849 cacheResult(list);
3850
3851 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3852 }
3853 catch (Exception e) {
3854 FinderCacheUtil.removeResult(finderPath, finderArgs);
3855
3856 throw processException(e);
3857 }
3858 finally {
3859 closeSession(session);
3860 }
3861 }
3862
3863 return list;
3864 }
3865
3866
3874 @Override
3875 public Role findByType_First(int type,
3876 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3877 Role role = fetchByType_First(type, orderByComparator);
3878
3879 if (role != null) {
3880 return role;
3881 }
3882
3883 StringBundler msg = new StringBundler(4);
3884
3885 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3886
3887 msg.append("type=");
3888 msg.append(type);
3889
3890 msg.append(StringPool.CLOSE_CURLY_BRACE);
3891
3892 throw new NoSuchRoleException(msg.toString());
3893 }
3894
3895
3902 @Override
3903 public Role fetchByType_First(int type,
3904 OrderByComparator<Role> orderByComparator) {
3905 List<Role> list = findByType(type, 0, 1, orderByComparator);
3906
3907 if (!list.isEmpty()) {
3908 return list.get(0);
3909 }
3910
3911 return null;
3912 }
3913
3914
3922 @Override
3923 public Role findByType_Last(int type,
3924 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3925 Role role = fetchByType_Last(type, orderByComparator);
3926
3927 if (role != null) {
3928 return role;
3929 }
3930
3931 StringBundler msg = new StringBundler(4);
3932
3933 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3934
3935 msg.append("type=");
3936 msg.append(type);
3937
3938 msg.append(StringPool.CLOSE_CURLY_BRACE);
3939
3940 throw new NoSuchRoleException(msg.toString());
3941 }
3942
3943
3950 @Override
3951 public Role fetchByType_Last(int type,
3952 OrderByComparator<Role> orderByComparator) {
3953 int count = countByType(type);
3954
3955 if (count == 0) {
3956 return null;
3957 }
3958
3959 List<Role> list = findByType(type, count - 1, count, orderByComparator);
3960
3961 if (!list.isEmpty()) {
3962 return list.get(0);
3963 }
3964
3965 return null;
3966 }
3967
3968
3977 @Override
3978 public Role[] findByType_PrevAndNext(long roleId, int type,
3979 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3980 Role role = findByPrimaryKey(roleId);
3981
3982 Session session = null;
3983
3984 try {
3985 session = openSession();
3986
3987 Role[] array = new RoleImpl[3];
3988
3989 array[0] = getByType_PrevAndNext(session, role, type,
3990 orderByComparator, true);
3991
3992 array[1] = role;
3993
3994 array[2] = getByType_PrevAndNext(session, role, type,
3995 orderByComparator, false);
3996
3997 return array;
3998 }
3999 catch (Exception e) {
4000 throw processException(e);
4001 }
4002 finally {
4003 closeSession(session);
4004 }
4005 }
4006
4007 protected Role getByType_PrevAndNext(Session session, Role role, int type,
4008 OrderByComparator<Role> orderByComparator, boolean previous) {
4009 StringBundler query = null;
4010
4011 if (orderByComparator != null) {
4012 query = new StringBundler(6 +
4013 (orderByComparator.getOrderByFields().length * 6));
4014 }
4015 else {
4016 query = new StringBundler(3);
4017 }
4018
4019 query.append(_SQL_SELECT_ROLE_WHERE);
4020
4021 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4022
4023 if (orderByComparator != null) {
4024 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4025
4026 if (orderByConditionFields.length > 0) {
4027 query.append(WHERE_AND);
4028 }
4029
4030 for (int i = 0; i < orderByConditionFields.length; i++) {
4031 query.append(_ORDER_BY_ENTITY_ALIAS);
4032 query.append(orderByConditionFields[i]);
4033
4034 if ((i + 1) < orderByConditionFields.length) {
4035 if (orderByComparator.isAscending() ^ previous) {
4036 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4037 }
4038 else {
4039 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4040 }
4041 }
4042 else {
4043 if (orderByComparator.isAscending() ^ previous) {
4044 query.append(WHERE_GREATER_THAN);
4045 }
4046 else {
4047 query.append(WHERE_LESSER_THAN);
4048 }
4049 }
4050 }
4051
4052 query.append(ORDER_BY_CLAUSE);
4053
4054 String[] orderByFields = orderByComparator.getOrderByFields();
4055
4056 for (int i = 0; i < orderByFields.length; i++) {
4057 query.append(_ORDER_BY_ENTITY_ALIAS);
4058 query.append(orderByFields[i]);
4059
4060 if ((i + 1) < orderByFields.length) {
4061 if (orderByComparator.isAscending() ^ previous) {
4062 query.append(ORDER_BY_ASC_HAS_NEXT);
4063 }
4064 else {
4065 query.append(ORDER_BY_DESC_HAS_NEXT);
4066 }
4067 }
4068 else {
4069 if (orderByComparator.isAscending() ^ previous) {
4070 query.append(ORDER_BY_ASC);
4071 }
4072 else {
4073 query.append(ORDER_BY_DESC);
4074 }
4075 }
4076 }
4077 }
4078 else {
4079 query.append(RoleModelImpl.ORDER_BY_JPQL);
4080 }
4081
4082 String sql = query.toString();
4083
4084 Query q = session.createQuery(sql);
4085
4086 q.setFirstResult(0);
4087 q.setMaxResults(2);
4088
4089 QueryPos qPos = QueryPos.getInstance(q);
4090
4091 qPos.add(type);
4092
4093 if (orderByComparator != null) {
4094 Object[] values = orderByComparator.getOrderByConditionValues(role);
4095
4096 for (Object value : values) {
4097 qPos.add(value);
4098 }
4099 }
4100
4101 List<Role> list = q.list();
4102
4103 if (list.size() == 2) {
4104 return list.get(1);
4105 }
4106 else {
4107 return null;
4108 }
4109 }
4110
4111
4117 @Override
4118 public List<Role> filterFindByType(int type) {
4119 return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4120 }
4121
4122
4134 @Override
4135 public List<Role> filterFindByType(int type, int start, int end) {
4136 return filterFindByType(type, start, end, null);
4137 }
4138
4139
4152 @Override
4153 public List<Role> filterFindByType(int type, int start, int end,
4154 OrderByComparator<Role> orderByComparator) {
4155 if (!InlineSQLHelperUtil.isEnabled()) {
4156 return findByType(type, start, end, orderByComparator);
4157 }
4158
4159 StringBundler query = null;
4160
4161 if (orderByComparator != null) {
4162 query = new StringBundler(3 +
4163 (orderByComparator.getOrderByFields().length * 3));
4164 }
4165 else {
4166 query = new StringBundler(3);
4167 }
4168
4169 if (getDB().isSupportsInlineDistinct()) {
4170 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4171 }
4172 else {
4173 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4174 }
4175
4176 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4177
4178 if (!getDB().isSupportsInlineDistinct()) {
4179 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4180 }
4181
4182 if (orderByComparator != null) {
4183 if (getDB().isSupportsInlineDistinct()) {
4184 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4185 orderByComparator, true);
4186 }
4187 else {
4188 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4189 orderByComparator, true);
4190 }
4191 }
4192 else {
4193 if (getDB().isSupportsInlineDistinct()) {
4194 query.append(RoleModelImpl.ORDER_BY_JPQL);
4195 }
4196 else {
4197 query.append(RoleModelImpl.ORDER_BY_SQL);
4198 }
4199 }
4200
4201 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4202 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4203
4204 Session session = null;
4205
4206 try {
4207 session = openSession();
4208
4209 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4210
4211 if (getDB().isSupportsInlineDistinct()) {
4212 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4213 }
4214 else {
4215 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4216 }
4217
4218 QueryPos qPos = QueryPos.getInstance(q);
4219
4220 qPos.add(type);
4221
4222 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
4223 }
4224 catch (Exception e) {
4225 throw processException(e);
4226 }
4227 finally {
4228 closeSession(session);
4229 }
4230 }
4231
4232
4241 @Override
4242 public Role[] filterFindByType_PrevAndNext(long roleId, int type,
4243 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4244 if (!InlineSQLHelperUtil.isEnabled()) {
4245 return findByType_PrevAndNext(roleId, type, orderByComparator);
4246 }
4247
4248 Role role = findByPrimaryKey(roleId);
4249
4250 Session session = null;
4251
4252 try {
4253 session = openSession();
4254
4255 Role[] array = new RoleImpl[3];
4256
4257 array[0] = filterGetByType_PrevAndNext(session, role, type,
4258 orderByComparator, true);
4259
4260 array[1] = role;
4261
4262 array[2] = filterGetByType_PrevAndNext(session, role, type,
4263 orderByComparator, false);
4264
4265 return array;
4266 }
4267 catch (Exception e) {
4268 throw processException(e);
4269 }
4270 finally {
4271 closeSession(session);
4272 }
4273 }
4274
4275 protected Role filterGetByType_PrevAndNext(Session session, Role role,
4276 int type, OrderByComparator<Role> orderByComparator, boolean previous) {
4277 StringBundler query = null;
4278
4279 if (orderByComparator != null) {
4280 query = new StringBundler(6 +
4281 (orderByComparator.getOrderByFields().length * 6));
4282 }
4283 else {
4284 query = new StringBundler(3);
4285 }
4286
4287 if (getDB().isSupportsInlineDistinct()) {
4288 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4289 }
4290 else {
4291 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4292 }
4293
4294 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4295
4296 if (!getDB().isSupportsInlineDistinct()) {
4297 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4298 }
4299
4300 if (orderByComparator != null) {
4301 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4302
4303 if (orderByConditionFields.length > 0) {
4304 query.append(WHERE_AND);
4305 }
4306
4307 for (int i = 0; i < orderByConditionFields.length; i++) {
4308 if (getDB().isSupportsInlineDistinct()) {
4309 query.append(_ORDER_BY_ENTITY_ALIAS);
4310 }
4311 else {
4312 query.append(_ORDER_BY_ENTITY_TABLE);
4313 }
4314
4315 query.append(orderByConditionFields[i]);
4316
4317 if ((i + 1) < orderByConditionFields.length) {
4318 if (orderByComparator.isAscending() ^ previous) {
4319 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4320 }
4321 else {
4322 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4323 }
4324 }
4325 else {
4326 if (orderByComparator.isAscending() ^ previous) {
4327 query.append(WHERE_GREATER_THAN);
4328 }
4329 else {
4330 query.append(WHERE_LESSER_THAN);
4331 }
4332 }
4333 }
4334
4335 query.append(ORDER_BY_CLAUSE);
4336
4337 String[] orderByFields = orderByComparator.getOrderByFields();
4338
4339 for (int i = 0; i < orderByFields.length; i++) {
4340 if (getDB().isSupportsInlineDistinct()) {
4341 query.append(_ORDER_BY_ENTITY_ALIAS);
4342 }
4343 else {
4344 query.append(_ORDER_BY_ENTITY_TABLE);
4345 }
4346
4347 query.append(orderByFields[i]);
4348
4349 if ((i + 1) < orderByFields.length) {
4350 if (orderByComparator.isAscending() ^ previous) {
4351 query.append(ORDER_BY_ASC_HAS_NEXT);
4352 }
4353 else {
4354 query.append(ORDER_BY_DESC_HAS_NEXT);
4355 }
4356 }
4357 else {
4358 if (orderByComparator.isAscending() ^ previous) {
4359 query.append(ORDER_BY_ASC);
4360 }
4361 else {
4362 query.append(ORDER_BY_DESC);
4363 }
4364 }
4365 }
4366 }
4367 else {
4368 if (getDB().isSupportsInlineDistinct()) {
4369 query.append(RoleModelImpl.ORDER_BY_JPQL);
4370 }
4371 else {
4372 query.append(RoleModelImpl.ORDER_BY_SQL);
4373 }
4374 }
4375
4376 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4377 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4378
4379 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4380
4381 q.setFirstResult(0);
4382 q.setMaxResults(2);
4383
4384 if (getDB().isSupportsInlineDistinct()) {
4385 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4386 }
4387 else {
4388 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4389 }
4390
4391 QueryPos qPos = QueryPos.getInstance(q);
4392
4393 qPos.add(type);
4394
4395 if (orderByComparator != null) {
4396 Object[] values = orderByComparator.getOrderByConditionValues(role);
4397
4398 for (Object value : values) {
4399 qPos.add(value);
4400 }
4401 }
4402
4403 List<Role> list = q.list();
4404
4405 if (list.size() == 2) {
4406 return list.get(1);
4407 }
4408 else {
4409 return null;
4410 }
4411 }
4412
4413
4418 @Override
4419 public void removeByType(int type) {
4420 for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4421 null)) {
4422 remove(role);
4423 }
4424 }
4425
4426
4432 @Override
4433 public int countByType(int type) {
4434 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
4435
4436 Object[] finderArgs = new Object[] { type };
4437
4438 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4439 this);
4440
4441 if (count == null) {
4442 StringBundler query = new StringBundler(2);
4443
4444 query.append(_SQL_COUNT_ROLE_WHERE);
4445
4446 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4447
4448 String sql = query.toString();
4449
4450 Session session = null;
4451
4452 try {
4453 session = openSession();
4454
4455 Query q = session.createQuery(sql);
4456
4457 QueryPos qPos = QueryPos.getInstance(q);
4458
4459 qPos.add(type);
4460
4461 count = (Long)q.uniqueResult();
4462
4463 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4464 }
4465 catch (Exception e) {
4466 FinderCacheUtil.removeResult(finderPath, finderArgs);
4467
4468 throw processException(e);
4469 }
4470 finally {
4471 closeSession(session);
4472 }
4473 }
4474
4475 return count.intValue();
4476 }
4477
4478
4484 @Override
4485 public int filterCountByType(int type) {
4486 if (!InlineSQLHelperUtil.isEnabled()) {
4487 return countByType(type);
4488 }
4489
4490 StringBundler query = new StringBundler(2);
4491
4492 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4493
4494 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4495
4496 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4497 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4498
4499 Session session = null;
4500
4501 try {
4502 session = openSession();
4503
4504 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4505
4506 q.addScalar(COUNT_COLUMN_NAME,
4507 com.liferay.portal.kernel.dao.orm.Type.LONG);
4508
4509 QueryPos qPos = QueryPos.getInstance(q);
4510
4511 qPos.add(type);
4512
4513 Long count = (Long)q.uniqueResult();
4514
4515 return count.intValue();
4516 }
4517 catch (Exception e) {
4518 throw processException(e);
4519 }
4520 finally {
4521 closeSession(session);
4522 }
4523 }
4524
4525 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?";
4526 private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?";
4527 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4528 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4529 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
4530 new String[] {
4531 String.class.getName(),
4532
4533 Integer.class.getName(), Integer.class.getName(),
4534 OrderByComparator.class.getName()
4535 });
4536 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
4537 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4538 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4539 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
4540 new String[] { String.class.getName() },
4541 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
4542 RoleModelImpl.NAME_COLUMN_BITMASK);
4543 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4544 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4545 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
4546 new String[] { String.class.getName() });
4547
4548
4554 @Override
4555 public List<Role> findBySubtype(String subtype) {
4556 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4557 }
4558
4559
4571 @Override
4572 public List<Role> findBySubtype(String subtype, int start, int end) {
4573 return findBySubtype(subtype, start, end, null);
4574 }
4575
4576
4589 @Override
4590 public List<Role> findBySubtype(String subtype, int start, int end,
4591 OrderByComparator<Role> orderByComparator) {
4592 boolean pagination = true;
4593 FinderPath finderPath = null;
4594 Object[] finderArgs = null;
4595
4596 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4597 (orderByComparator == null)) {
4598 pagination = false;
4599 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
4600 finderArgs = new Object[] { subtype };
4601 }
4602 else {
4603 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
4604 finderArgs = new Object[] { subtype, start, end, orderByComparator };
4605 }
4606
4607 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
4608 finderArgs, this);
4609
4610 if ((list != null) && !list.isEmpty()) {
4611 for (Role role : list) {
4612 if (!Validator.equals(subtype, role.getSubtype())) {
4613 list = null;
4614
4615 break;
4616 }
4617 }
4618 }
4619
4620 if (list == null) {
4621 StringBundler query = null;
4622
4623 if (orderByComparator != null) {
4624 query = new StringBundler(3 +
4625 (orderByComparator.getOrderByFields().length * 3));
4626 }
4627 else {
4628 query = new StringBundler(3);
4629 }
4630
4631 query.append(_SQL_SELECT_ROLE_WHERE);
4632
4633 boolean bindSubtype = false;
4634
4635 if (subtype == null) {
4636 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4637 }
4638 else if (subtype.equals(StringPool.BLANK)) {
4639 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4640 }
4641 else {
4642 bindSubtype = true;
4643
4644 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4645 }
4646
4647 if (orderByComparator != null) {
4648 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4649 orderByComparator);
4650 }
4651 else
4652 if (pagination) {
4653 query.append(RoleModelImpl.ORDER_BY_JPQL);
4654 }
4655
4656 String sql = query.toString();
4657
4658 Session session = null;
4659
4660 try {
4661 session = openSession();
4662
4663 Query q = session.createQuery(sql);
4664
4665 QueryPos qPos = QueryPos.getInstance(q);
4666
4667 if (bindSubtype) {
4668 qPos.add(subtype);
4669 }
4670
4671 if (!pagination) {
4672 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4673 end, false);
4674
4675 Collections.sort(list);
4676
4677 list = Collections.unmodifiableList(list);
4678 }
4679 else {
4680 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4681 end);
4682 }
4683
4684 cacheResult(list);
4685
4686 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4687 }
4688 catch (Exception e) {
4689 FinderCacheUtil.removeResult(finderPath, finderArgs);
4690
4691 throw processException(e);
4692 }
4693 finally {
4694 closeSession(session);
4695 }
4696 }
4697
4698 return list;
4699 }
4700
4701
4709 @Override
4710 public Role findBySubtype_First(String subtype,
4711 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4712 Role role = fetchBySubtype_First(subtype, orderByComparator);
4713
4714 if (role != null) {
4715 return role;
4716 }
4717
4718 StringBundler msg = new StringBundler(4);
4719
4720 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4721
4722 msg.append("subtype=");
4723 msg.append(subtype);
4724
4725 msg.append(StringPool.CLOSE_CURLY_BRACE);
4726
4727 throw new NoSuchRoleException(msg.toString());
4728 }
4729
4730
4737 @Override
4738 public Role fetchBySubtype_First(String subtype,
4739 OrderByComparator<Role> orderByComparator) {
4740 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
4741
4742 if (!list.isEmpty()) {
4743 return list.get(0);
4744 }
4745
4746 return null;
4747 }
4748
4749
4757 @Override
4758 public Role findBySubtype_Last(String subtype,
4759 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4760 Role role = fetchBySubtype_Last(subtype, orderByComparator);
4761
4762 if (role != null) {
4763 return role;
4764 }
4765
4766 StringBundler msg = new StringBundler(4);
4767
4768 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4769
4770 msg.append("subtype=");
4771 msg.append(subtype);
4772
4773 msg.append(StringPool.CLOSE_CURLY_BRACE);
4774
4775 throw new NoSuchRoleException(msg.toString());
4776 }
4777
4778
4785 @Override
4786 public Role fetchBySubtype_Last(String subtype,
4787 OrderByComparator<Role> orderByComparator) {
4788 int count = countBySubtype(subtype);
4789
4790 if (count == 0) {
4791 return null;
4792 }
4793
4794 List<Role> list = findBySubtype(subtype, count - 1, count,
4795 orderByComparator);
4796
4797 if (!list.isEmpty()) {
4798 return list.get(0);
4799 }
4800
4801 return null;
4802 }
4803
4804
4813 @Override
4814 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
4815 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4816 Role role = findByPrimaryKey(roleId);
4817
4818 Session session = null;
4819
4820 try {
4821 session = openSession();
4822
4823 Role[] array = new RoleImpl[3];
4824
4825 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
4826 orderByComparator, true);
4827
4828 array[1] = role;
4829
4830 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
4831 orderByComparator, false);
4832
4833 return array;
4834 }
4835 catch (Exception e) {
4836 throw processException(e);
4837 }
4838 finally {
4839 closeSession(session);
4840 }
4841 }
4842
4843 protected Role getBySubtype_PrevAndNext(Session session, Role role,
4844 String subtype, OrderByComparator<Role> orderByComparator,
4845 boolean previous) {
4846 StringBundler query = null;
4847
4848 if (orderByComparator != null) {
4849 query = new StringBundler(6 +
4850 (orderByComparator.getOrderByFields().length * 6));
4851 }
4852 else {
4853 query = new StringBundler(3);
4854 }
4855
4856 query.append(_SQL_SELECT_ROLE_WHERE);
4857
4858 boolean bindSubtype = false;
4859
4860 if (subtype == null) {
4861 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4862 }
4863 else if (subtype.equals(StringPool.BLANK)) {
4864 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4865 }
4866 else {
4867 bindSubtype = true;
4868
4869 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4870 }
4871
4872 if (orderByComparator != null) {
4873 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4874
4875 if (orderByConditionFields.length > 0) {
4876 query.append(WHERE_AND);
4877 }
4878
4879 for (int i = 0; i < orderByConditionFields.length; i++) {
4880 query.append(_ORDER_BY_ENTITY_ALIAS);
4881 query.append(orderByConditionFields[i]);
4882
4883 if ((i + 1) < orderByConditionFields.length) {
4884 if (orderByComparator.isAscending() ^ previous) {
4885 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4886 }
4887 else {
4888 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4889 }
4890 }
4891 else {
4892 if (orderByComparator.isAscending() ^ previous) {
4893 query.append(WHERE_GREATER_THAN);
4894 }
4895 else {
4896 query.append(WHERE_LESSER_THAN);
4897 }
4898 }
4899 }
4900
4901 query.append(ORDER_BY_CLAUSE);
4902
4903 String[] orderByFields = orderByComparator.getOrderByFields();
4904
4905 for (int i = 0; i < orderByFields.length; i++) {
4906 query.append(_ORDER_BY_ENTITY_ALIAS);
4907 query.append(orderByFields[i]);
4908
4909 if ((i + 1) < orderByFields.length) {
4910 if (orderByComparator.isAscending() ^ previous) {
4911 query.append(ORDER_BY_ASC_HAS_NEXT);
4912 }
4913 else {
4914 query.append(ORDER_BY_DESC_HAS_NEXT);
4915 }
4916 }
4917 else {
4918 if (orderByComparator.isAscending() ^ previous) {
4919 query.append(ORDER_BY_ASC);
4920 }
4921 else {
4922 query.append(ORDER_BY_DESC);
4923 }
4924 }
4925 }
4926 }
4927 else {
4928 query.append(RoleModelImpl.ORDER_BY_JPQL);
4929 }
4930
4931 String sql = query.toString();
4932
4933 Query q = session.createQuery(sql);
4934
4935 q.setFirstResult(0);
4936 q.setMaxResults(2);
4937
4938 QueryPos qPos = QueryPos.getInstance(q);
4939
4940 if (bindSubtype) {
4941 qPos.add(subtype);
4942 }
4943
4944 if (orderByComparator != null) {
4945 Object[] values = orderByComparator.getOrderByConditionValues(role);
4946
4947 for (Object value : values) {
4948 qPos.add(value);
4949 }
4950 }
4951
4952 List<Role> list = q.list();
4953
4954 if (list.size() == 2) {
4955 return list.get(1);
4956 }
4957 else {
4958 return null;
4959 }
4960 }
4961
4962
4968 @Override
4969 public List<Role> filterFindBySubtype(String subtype) {
4970 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
4971 QueryUtil.ALL_POS, null);
4972 }
4973
4974
4986 @Override
4987 public List<Role> filterFindBySubtype(String subtype, int start, int end) {
4988 return filterFindBySubtype(subtype, start, end, null);
4989 }
4990
4991
5004 @Override
5005 public List<Role> filterFindBySubtype(String subtype, int start, int end,
5006 OrderByComparator<Role> orderByComparator) {
5007 if (!InlineSQLHelperUtil.isEnabled()) {
5008 return findBySubtype(subtype, start, end, orderByComparator);
5009 }
5010
5011 StringBundler query = null;
5012
5013 if (orderByComparator != null) {
5014 query = new StringBundler(3 +
5015 (orderByComparator.getOrderByFields().length * 3));
5016 }
5017 else {
5018 query = new StringBundler(3);
5019 }
5020
5021 if (getDB().isSupportsInlineDistinct()) {
5022 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5023 }
5024 else {
5025 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5026 }
5027
5028 boolean bindSubtype = false;
5029
5030 if (subtype == null) {
5031 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5032 }
5033 else if (subtype.equals(StringPool.BLANK)) {
5034 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5035 }
5036 else {
5037 bindSubtype = true;
5038
5039 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5040 }
5041
5042 if (!getDB().isSupportsInlineDistinct()) {
5043 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5044 }
5045
5046 if (orderByComparator != null) {
5047 if (getDB().isSupportsInlineDistinct()) {
5048 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5049 orderByComparator, true);
5050 }
5051 else {
5052 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5053 orderByComparator, true);
5054 }
5055 }
5056 else {
5057 if (getDB().isSupportsInlineDistinct()) {
5058 query.append(RoleModelImpl.ORDER_BY_JPQL);
5059 }
5060 else {
5061 query.append(RoleModelImpl.ORDER_BY_SQL);
5062 }
5063 }
5064
5065 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5066 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5067
5068 Session session = null;
5069
5070 try {
5071 session = openSession();
5072
5073 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5074
5075 if (getDB().isSupportsInlineDistinct()) {
5076 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5077 }
5078 else {
5079 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5080 }
5081
5082 QueryPos qPos = QueryPos.getInstance(q);
5083
5084 if (bindSubtype) {
5085 qPos.add(subtype);
5086 }
5087
5088 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
5089 }
5090 catch (Exception e) {
5091 throw processException(e);
5092 }
5093 finally {
5094 closeSession(session);
5095 }
5096 }
5097
5098
5107 @Override
5108 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
5109 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
5110 if (!InlineSQLHelperUtil.isEnabled()) {
5111 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
5112 }
5113
5114 Role role = findByPrimaryKey(roleId);
5115
5116 Session session = null;
5117
5118 try {
5119 session = openSession();
5120
5121 Role[] array = new RoleImpl[3];
5122
5123 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5124 orderByComparator, true);
5125
5126 array[1] = role;
5127
5128 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5129 orderByComparator, false);
5130
5131 return array;
5132 }
5133 catch (Exception e) {
5134 throw processException(e);
5135 }
5136 finally {
5137 closeSession(session);
5138 }
5139 }
5140
5141 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
5142 String subtype, OrderByComparator<Role> orderByComparator,
5143 boolean previous) {
5144 StringBundler query = null;
5145
5146 if (orderByComparator != null) {
5147 query = new StringBundler(6 +
5148 (orderByComparator.getOrderByFields().length * 6));
5149 }
5150 else {
5151 query = new StringBundler(3);
5152 }
5153
5154 if (getDB().isSupportsInlineDistinct()) {
5155 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5156 }
5157 else {
5158 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5159 }
5160
5161 boolean bindSubtype = false;
5162
5163 if (subtype == null) {
5164 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5165 }
5166 else if (subtype.equals(StringPool.BLANK)) {
5167 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5168 }
5169 else {
5170 bindSubtype = true;
5171
5172 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5173 }
5174
5175 if (!getDB().isSupportsInlineDistinct()) {
5176 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5177 }
5178
5179 if (orderByComparator != null) {
5180 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5181
5182 if (orderByConditionFields.length > 0) {
5183 query.append(WHERE_AND);
5184 }
5185
5186 for (int i = 0; i < orderByConditionFields.length; i++) {
5187 if (getDB().isSupportsInlineDistinct()) {
5188 query.append(_ORDER_BY_ENTITY_ALIAS);
5189 }
5190 else {
5191 query.append(_ORDER_BY_ENTITY_TABLE);
5192 }
5193
5194 query.append(orderByConditionFields[i]);
5195
5196 if ((i + 1) < orderByConditionFields.length) {
5197 if (orderByComparator.isAscending() ^ previous) {
5198 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5199 }
5200 else {
5201 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5202 }
5203 }
5204 else {
5205 if (orderByComparator.isAscending() ^ previous) {
5206 query.append(WHERE_GREATER_THAN);
5207 }
5208 else {
5209 query.append(WHERE_LESSER_THAN);
5210 }
5211 }
5212 }
5213
5214 query.append(ORDER_BY_CLAUSE);
5215
5216 String[] orderByFields = orderByComparator.getOrderByFields();
5217
5218 for (int i = 0; i < orderByFields.length; i++) {
5219 if (getDB().isSupportsInlineDistinct()) {
5220 query.append(_ORDER_BY_ENTITY_ALIAS);
5221 }
5222 else {
5223 query.append(_ORDER_BY_ENTITY_TABLE);
5224 }
5225
5226 query.append(orderByFields[i]);
5227
5228 if ((i + 1) < orderByFields.length) {
5229 if (orderByComparator.isAscending() ^ previous) {
5230 query.append(ORDER_BY_ASC_HAS_NEXT);
5231 }
5232 else {
5233 query.append(ORDER_BY_DESC_HAS_NEXT);
5234 }
5235 }
5236 else {
5237 if (orderByComparator.isAscending() ^ previous) {
5238 query.append(ORDER_BY_ASC);
5239 }
5240 else {
5241 query.append(ORDER_BY_DESC);
5242 }
5243 }
5244 }
5245 }
5246 else {
5247 if (getDB().isSupportsInlineDistinct()) {
5248 query.append(RoleModelImpl.ORDER_BY_JPQL);
5249 }
5250 else {
5251 query.append(RoleModelImpl.ORDER_BY_SQL);
5252 }
5253 }
5254
5255 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5256 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5257
5258 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5259
5260 q.setFirstResult(0);
5261 q.setMaxResults(2);
5262
5263 if (getDB().isSupportsInlineDistinct()) {
5264 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5265 }
5266 else {
5267 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5268 }
5269
5270 QueryPos qPos = QueryPos.getInstance(q);
5271
5272 if (bindSubtype) {
5273 qPos.add(subtype);
5274 }
5275
5276 if (orderByComparator != null) {
5277 Object[] values = orderByComparator.getOrderByConditionValues(role);
5278
5279 for (Object value : values) {
5280 qPos.add(value);
5281 }
5282 }
5283
5284 List<Role> list = q.list();
5285
5286 if (list.size() == 2) {
5287 return list.get(1);
5288 }
5289 else {
5290 return null;
5291 }
5292 }
5293
5294
5299 @Override
5300 public void removeBySubtype(String subtype) {
5301 for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
5302 QueryUtil.ALL_POS, null)) {
5303 remove(role);
5304 }
5305 }
5306
5307
5313 @Override
5314 public int countBySubtype(String subtype) {
5315 FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
5316
5317 Object[] finderArgs = new Object[] { subtype };
5318
5319 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5320 this);
5321
5322 if (count == null) {
5323 StringBundler query = new StringBundler(2);
5324
5325 query.append(_SQL_COUNT_ROLE_WHERE);
5326
5327 boolean bindSubtype = false;
5328
5329 if (subtype == null) {
5330 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5331 }
5332 else if (subtype.equals(StringPool.BLANK)) {
5333 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5334 }
5335 else {
5336 bindSubtype = true;
5337
5338 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5339 }
5340
5341 String sql = query.toString();
5342
5343 Session session = null;
5344
5345 try {
5346 session = openSession();
5347
5348 Query q = session.createQuery(sql);
5349
5350 QueryPos qPos = QueryPos.getInstance(q);
5351
5352 if (bindSubtype) {
5353 qPos.add(subtype);
5354 }
5355
5356 count = (Long)q.uniqueResult();
5357
5358 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5359 }
5360 catch (Exception e) {
5361 FinderCacheUtil.removeResult(finderPath, finderArgs);
5362
5363 throw processException(e);
5364 }
5365 finally {
5366 closeSession(session);
5367 }
5368 }
5369
5370 return count.intValue();
5371 }
5372
5373
5379 @Override
5380 public int filterCountBySubtype(String subtype) {
5381 if (!InlineSQLHelperUtil.isEnabled()) {
5382 return countBySubtype(subtype);
5383 }
5384
5385 StringBundler query = new StringBundler(2);
5386
5387 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
5388
5389 boolean bindSubtype = false;
5390
5391 if (subtype == null) {
5392 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5393 }
5394 else if (subtype.equals(StringPool.BLANK)) {
5395 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5396 }
5397 else {
5398 bindSubtype = true;
5399
5400 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5401 }
5402
5403 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5404 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5405
5406 Session session = null;
5407
5408 try {
5409 session = openSession();
5410
5411 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5412
5413 q.addScalar(COUNT_COLUMN_NAME,
5414 com.liferay.portal.kernel.dao.orm.Type.LONG);
5415
5416 QueryPos qPos = QueryPos.getInstance(q);
5417
5418 if (bindSubtype) {
5419 qPos.add(subtype);
5420 }
5421
5422 Long count = (Long)q.uniqueResult();
5423
5424 return count.intValue();
5425 }
5426 catch (Exception e) {
5427 throw processException(e);
5428 }
5429 finally {
5430 closeSession(session);
5431 }
5432 }
5433
5434 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5435 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5436 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
5437 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5438 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5439 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5440 new String[] { Long.class.getName(), String.class.getName() },
5441 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5442 RoleModelImpl.NAME_COLUMN_BITMASK);
5443 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5444 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5445 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5446 new String[] { Long.class.getName(), String.class.getName() });
5447
5448
5456 @Override
5457 public Role findByC_N(long companyId, String name)
5458 throws NoSuchRoleException {
5459 Role role = fetchByC_N(companyId, name);
5460
5461 if (role == null) {
5462 StringBundler msg = new StringBundler(6);
5463
5464 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5465
5466 msg.append("companyId=");
5467 msg.append(companyId);
5468
5469 msg.append(", name=");
5470 msg.append(name);
5471
5472 msg.append(StringPool.CLOSE_CURLY_BRACE);
5473
5474 if (_log.isWarnEnabled()) {
5475 _log.warn(msg.toString());
5476 }
5477
5478 throw new NoSuchRoleException(msg.toString());
5479 }
5480
5481 return role;
5482 }
5483
5484
5491 @Override
5492 public Role fetchByC_N(long companyId, String name) {
5493 return fetchByC_N(companyId, name, true);
5494 }
5495
5496
5504 @Override
5505 public Role fetchByC_N(long companyId, String name,
5506 boolean retrieveFromCache) {
5507 Object[] finderArgs = new Object[] { companyId, name };
5508
5509 Object result = null;
5510
5511 if (retrieveFromCache) {
5512 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5513 finderArgs, this);
5514 }
5515
5516 if (result instanceof Role) {
5517 Role role = (Role)result;
5518
5519 if ((companyId != role.getCompanyId()) ||
5520 !Validator.equals(name, role.getName())) {
5521 result = null;
5522 }
5523 }
5524
5525 if (result == null) {
5526 StringBundler query = new StringBundler(4);
5527
5528 query.append(_SQL_SELECT_ROLE_WHERE);
5529
5530 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5531
5532 boolean bindName = false;
5533
5534 if (name == null) {
5535 query.append(_FINDER_COLUMN_C_N_NAME_1);
5536 }
5537 else if (name.equals(StringPool.BLANK)) {
5538 query.append(_FINDER_COLUMN_C_N_NAME_3);
5539 }
5540 else {
5541 bindName = true;
5542
5543 query.append(_FINDER_COLUMN_C_N_NAME_2);
5544 }
5545
5546 String sql = query.toString();
5547
5548 Session session = null;
5549
5550 try {
5551 session = openSession();
5552
5553 Query q = session.createQuery(sql);
5554
5555 QueryPos qPos = QueryPos.getInstance(q);
5556
5557 qPos.add(companyId);
5558
5559 if (bindName) {
5560 qPos.add(StringUtil.toLowerCase(name));
5561 }
5562
5563 List<Role> list = q.list();
5564
5565 if (list.isEmpty()) {
5566 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5567 finderArgs, list);
5568 }
5569 else {
5570 Role role = list.get(0);
5571
5572 result = role;
5573
5574 cacheResult(role);
5575
5576 if ((role.getCompanyId() != companyId) ||
5577 (role.getName() == null) ||
5578 !role.getName().equals(name)) {
5579 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5580 finderArgs, role);
5581 }
5582 }
5583 }
5584 catch (Exception e) {
5585 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5586 finderArgs);
5587
5588 throw processException(e);
5589 }
5590 finally {
5591 closeSession(session);
5592 }
5593 }
5594
5595 if (result instanceof List<?>) {
5596 return null;
5597 }
5598 else {
5599 return (Role)result;
5600 }
5601 }
5602
5603
5610 @Override
5611 public Role removeByC_N(long companyId, String name)
5612 throws NoSuchRoleException {
5613 Role role = findByC_N(companyId, name);
5614
5615 return remove(role);
5616 }
5617
5618
5625 @Override
5626 public int countByC_N(long companyId, String name) {
5627 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5628
5629 Object[] finderArgs = new Object[] { companyId, name };
5630
5631 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5632 this);
5633
5634 if (count == null) {
5635 StringBundler query = new StringBundler(3);
5636
5637 query.append(_SQL_COUNT_ROLE_WHERE);
5638
5639 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5640
5641 boolean bindName = false;
5642
5643 if (name == null) {
5644 query.append(_FINDER_COLUMN_C_N_NAME_1);
5645 }
5646 else if (name.equals(StringPool.BLANK)) {
5647 query.append(_FINDER_COLUMN_C_N_NAME_3);
5648 }
5649 else {
5650 bindName = true;
5651
5652 query.append(_FINDER_COLUMN_C_N_NAME_2);
5653 }
5654
5655 String sql = query.toString();
5656
5657 Session session = null;
5658
5659 try {
5660 session = openSession();
5661
5662 Query q = session.createQuery(sql);
5663
5664 QueryPos qPos = QueryPos.getInstance(q);
5665
5666 qPos.add(companyId);
5667
5668 if (bindName) {
5669 qPos.add(StringUtil.toLowerCase(name));
5670 }
5671
5672 count = (Long)q.uniqueResult();
5673
5674 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5675 }
5676 catch (Exception e) {
5677 FinderCacheUtil.removeResult(finderPath, finderArgs);
5678
5679 throw processException(e);
5680 }
5681 finally {
5682 closeSession(session);
5683 }
5684 }
5685
5686 return count.intValue();
5687 }
5688
5689 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5690 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5691 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?";
5692 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')";
5693 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5694 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5695 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
5696 new String[] {
5697 Long.class.getName(), Integer.class.getName(),
5698
5699 Integer.class.getName(), Integer.class.getName(),
5700 OrderByComparator.class.getName()
5701 });
5702 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5703 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5704 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
5705 new String[] { Long.class.getName(), Integer.class.getName() },
5706 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5707 RoleModelImpl.TYPE_COLUMN_BITMASK |
5708 RoleModelImpl.NAME_COLUMN_BITMASK);
5709 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5710 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5711 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
5712 new String[] { Long.class.getName(), Integer.class.getName() });
5713 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5714 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5715 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
5716 new String[] { Long.class.getName(), Integer.class.getName() });
5717
5718
5725 @Override
5726 public List<Role> findByC_T(long companyId, int type) {
5727 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5728 null);
5729 }
5730
5731
5744 @Override
5745 public List<Role> findByC_T(long companyId, int type, int start, int end) {
5746 return findByC_T(companyId, type, start, end, null);
5747 }
5748
5749
5763 @Override
5764 public List<Role> findByC_T(long companyId, int type, int start, int end,
5765 OrderByComparator<Role> orderByComparator) {
5766 boolean pagination = true;
5767 FinderPath finderPath = null;
5768 Object[] finderArgs = null;
5769
5770 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5771 (orderByComparator == null)) {
5772 pagination = false;
5773 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
5774 finderArgs = new Object[] { companyId, type };
5775 }
5776 else {
5777 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
5778 finderArgs = new Object[] {
5779 companyId, type,
5780
5781 start, end, orderByComparator
5782 };
5783 }
5784
5785 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
5786 finderArgs, this);
5787
5788 if ((list != null) && !list.isEmpty()) {
5789 for (Role role : list) {
5790 if ((companyId != role.getCompanyId()) ||
5791 (type != role.getType())) {
5792 list = null;
5793
5794 break;
5795 }
5796 }
5797 }
5798
5799 if (list == null) {
5800 StringBundler query = null;
5801
5802 if (orderByComparator != null) {
5803 query = new StringBundler(4 +
5804 (orderByComparator.getOrderByFields().length * 3));
5805 }
5806 else {
5807 query = new StringBundler(4);
5808 }
5809
5810 query.append(_SQL_SELECT_ROLE_WHERE);
5811
5812 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5813
5814 query.append(_FINDER_COLUMN_C_T_TYPE_2);
5815
5816 if (orderByComparator != null) {
5817 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5818 orderByComparator);
5819 }
5820 else
5821 if (pagination) {
5822 query.append(RoleModelImpl.ORDER_BY_JPQL);
5823 }
5824
5825 String sql = query.toString();
5826
5827 Session session = null;
5828
5829 try {
5830 session = openSession();
5831
5832 Query q = session.createQuery(sql);
5833
5834 QueryPos qPos = QueryPos.getInstance(q);
5835
5836 qPos.add(companyId);
5837
5838 qPos.add(type);
5839
5840 if (!pagination) {
5841 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5842 end, false);
5843
5844 Collections.sort(list);
5845
5846 list = Collections.unmodifiableList(list);
5847 }
5848 else {
5849 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5850 end);
5851 }
5852
5853 cacheResult(list);
5854
5855 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5856 }
5857 catch (Exception e) {
5858 FinderCacheUtil.removeResult(finderPath, finderArgs);
5859
5860 throw processException(e);
5861 }
5862 finally {
5863 closeSession(session);
5864 }
5865 }
5866
5867 return list;
5868 }
5869
5870
5879 @Override
5880 public Role findByC_T_First(long companyId, int type,
5881 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
5882 Role role = fetchByC_T_First(companyId, type, orderByComparator);
5883
5884 if (role != null) {
5885 return role;
5886 }
5887
5888 StringBundler msg = new StringBundler(6);
5889
5890 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5891
5892 msg.append("companyId=");
5893 msg.append(companyId);
5894
5895 msg.append(", type=");
5896 msg.append(type);
5897
5898 msg.append(StringPool.CLOSE_CURLY_BRACE);
5899
5900 throw new NoSuchRoleException(msg.toString());
5901 }
5902
5903
5911 @Override
5912 public Role fetchByC_T_First(long companyId, int type,
5913 OrderByComparator<Role> orderByComparator) {
5914 List<Role> list = findByC_T(companyId, type, 0, 1, orderByComparator);
5915
5916 if (!list.isEmpty()) {
5917 return list.get(0);
5918 }
5919
5920 return null;
5921 }
5922
5923
5932 @Override
5933 public Role findByC_T_Last(long companyId, int type,
5934 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
5935 Role role = fetchByC_T_Last(companyId, type, orderByComparator);
5936
5937 if (role != null) {
5938 return role;
5939 }
5940
5941 StringBundler msg = new StringBundler(6);
5942
5943 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5944
5945 msg.append("companyId=");
5946 msg.append(companyId);
5947
5948 msg.append(", type=");
5949 msg.append(type);
5950
5951 msg.append(StringPool.CLOSE_CURLY_BRACE);
5952
5953 throw new NoSuchRoleException(msg.toString());
5954 }
5955
5956
5964 @Override
5965 public Role fetchByC_T_Last(long companyId, int type,
5966 OrderByComparator<Role> orderByComparator) {
5967 int count = countByC_T(companyId, type);
5968
5969 if (count == 0) {
5970 return null;
5971 }
5972
5973 List<Role> list = findByC_T(companyId, type, count - 1, count,
5974 orderByComparator);
5975
5976 if (!list.isEmpty()) {
5977 return list.get(0);
5978 }
5979
5980 return null;
5981 }
5982
5983
5993 @Override
5994 public Role[] findByC_T_PrevAndNext(long roleId, long companyId, int type,
5995 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
5996 Role role = findByPrimaryKey(roleId);
5997
5998 Session session = null;
5999
6000 try {
6001 session = openSession();
6002
6003 Role[] array = new RoleImpl[3];
6004
6005 array[0] = getByC_T_PrevAndNext(session, role, companyId, type,
6006 orderByComparator, true);
6007
6008 array[1] = role;
6009
6010 array[2] = getByC_T_PrevAndNext(session, role, companyId, type,
6011 orderByComparator, false);
6012
6013 return array;
6014 }
6015 catch (Exception e) {
6016 throw processException(e);
6017 }
6018 finally {
6019 closeSession(session);
6020 }
6021 }
6022
6023 protected Role getByC_T_PrevAndNext(Session session, Role role,
6024 long companyId, int type, OrderByComparator<Role> orderByComparator,
6025 boolean previous) {
6026 StringBundler query = null;
6027
6028 if (orderByComparator != null) {
6029 query = new StringBundler(6 +
6030 (orderByComparator.getOrderByFields().length * 6));
6031 }
6032 else {
6033 query = new StringBundler(3);
6034 }
6035
6036 query.append(_SQL_SELECT_ROLE_WHERE);
6037
6038 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6039
6040 query.append(_FINDER_COLUMN_C_T_TYPE_2);
6041
6042 if (orderByComparator != null) {
6043 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6044
6045 if (orderByConditionFields.length > 0) {
6046 query.append(WHERE_AND);
6047 }
6048
6049 for (int i = 0; i < orderByConditionFields.length; i++) {
6050 query.append(_ORDER_BY_ENTITY_ALIAS);
6051 query.append(orderByConditionFields[i]);
6052
6053 if ((i + 1) < orderByConditionFields.length) {
6054 if (orderByComparator.isAscending() ^ previous) {
6055 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6056 }
6057 else {
6058 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6059 }
6060 }
6061 else {
6062 if (orderByComparator.isAscending() ^ previous) {
6063 query.append(WHERE_GREATER_THAN);
6064 }
6065 else {
6066 query.append(WHERE_LESSER_THAN);
6067 }
6068 }
6069 }
6070
6071 query.append(ORDER_BY_CLAUSE);
6072
6073 String[] orderByFields = orderByComparator.getOrderByFields();
6074
6075 for (int i = 0; i < orderByFields.length; i++) {
6076 query.append(_ORDER_BY_ENTITY_ALIAS);
6077 query.append(orderByFields[i]);
6078
6079 if ((i + 1) < orderByFields.length) {
6080 if (orderByComparator.isAscending() ^ previous) {
6081 query.append(ORDER_BY_ASC_HAS_NEXT);
6082 }
6083 else {
6084 query.append(ORDER_BY_DESC_HAS_NEXT);
6085 }
6086 }
6087 else {
6088 if (orderByComparator.isAscending() ^ previous) {
6089 query.append(ORDER_BY_ASC);
6090 }
6091 else {
6092 query.append(ORDER_BY_DESC);
6093 }
6094 }
6095 }
6096 }
6097 else {
6098 query.append(RoleModelImpl.ORDER_BY_JPQL);
6099 }
6100
6101 String sql = query.toString();
6102
6103 Query q = session.createQuery(sql);
6104
6105 q.setFirstResult(0);
6106 q.setMaxResults(2);
6107
6108 QueryPos qPos = QueryPos.getInstance(q);
6109
6110 qPos.add(companyId);
6111
6112 qPos.add(type);
6113
6114 if (orderByComparator != null) {
6115 Object[] values = orderByComparator.getOrderByConditionValues(role);
6116
6117 for (Object value : values) {
6118 qPos.add(value);
6119 }
6120 }
6121
6122 List<Role> list = q.list();
6123
6124 if (list.size() == 2) {
6125 return list.get(1);
6126 }
6127 else {
6128 return null;
6129 }
6130 }
6131
6132
6139 @Override
6140 public List<Role> filterFindByC_T(long companyId, int type) {
6141 return filterFindByC_T(companyId, type, QueryUtil.ALL_POS,
6142 QueryUtil.ALL_POS, null);
6143 }
6144
6145
6158 @Override
6159 public List<Role> filterFindByC_T(long companyId, int type, int start,
6160 int end) {
6161 return filterFindByC_T(companyId, type, start, end, null);
6162 }
6163
6164
6178 @Override
6179 public List<Role> filterFindByC_T(long companyId, int type, int start,
6180 int end, OrderByComparator<Role> orderByComparator) {
6181 if (!InlineSQLHelperUtil.isEnabled()) {
6182 return findByC_T(companyId, type, start, end, orderByComparator);
6183 }
6184
6185 StringBundler query = null;
6186
6187 if (orderByComparator != null) {
6188 query = new StringBundler(4 +
6189 (orderByComparator.getOrderByFields().length * 3));
6190 }
6191 else {
6192 query = new StringBundler(4);
6193 }
6194
6195 if (getDB().isSupportsInlineDistinct()) {
6196 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6197 }
6198 else {
6199 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6200 }
6201
6202 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6203
6204 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6205
6206 if (!getDB().isSupportsInlineDistinct()) {
6207 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6208 }
6209
6210 if (orderByComparator != null) {
6211 if (getDB().isSupportsInlineDistinct()) {
6212 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6213 orderByComparator, true);
6214 }
6215 else {
6216 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6217 orderByComparator, true);
6218 }
6219 }
6220 else {
6221 if (getDB().isSupportsInlineDistinct()) {
6222 query.append(RoleModelImpl.ORDER_BY_JPQL);
6223 }
6224 else {
6225 query.append(RoleModelImpl.ORDER_BY_SQL);
6226 }
6227 }
6228
6229 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6230 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6231
6232 Session session = null;
6233
6234 try {
6235 session = openSession();
6236
6237 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6238
6239 if (getDB().isSupportsInlineDistinct()) {
6240 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6241 }
6242 else {
6243 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6244 }
6245
6246 QueryPos qPos = QueryPos.getInstance(q);
6247
6248 qPos.add(companyId);
6249
6250 qPos.add(type);
6251
6252 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6253 }
6254 catch (Exception e) {
6255 throw processException(e);
6256 }
6257 finally {
6258 closeSession(session);
6259 }
6260 }
6261
6262
6272 @Override
6273 public Role[] filterFindByC_T_PrevAndNext(long roleId, long companyId,
6274 int type, OrderByComparator<Role> orderByComparator)
6275 throws NoSuchRoleException {
6276 if (!InlineSQLHelperUtil.isEnabled()) {
6277 return findByC_T_PrevAndNext(roleId, companyId, type,
6278 orderByComparator);
6279 }
6280
6281 Role role = findByPrimaryKey(roleId);
6282
6283 Session session = null;
6284
6285 try {
6286 session = openSession();
6287
6288 Role[] array = new RoleImpl[3];
6289
6290 array[0] = filterGetByC_T_PrevAndNext(session, role, companyId,
6291 type, orderByComparator, true);
6292
6293 array[1] = role;
6294
6295 array[2] = filterGetByC_T_PrevAndNext(session, role, companyId,
6296 type, orderByComparator, false);
6297
6298 return array;
6299 }
6300 catch (Exception e) {
6301 throw processException(e);
6302 }
6303 finally {
6304 closeSession(session);
6305 }
6306 }
6307
6308 protected Role filterGetByC_T_PrevAndNext(Session session, Role role,
6309 long companyId, int type, OrderByComparator<Role> orderByComparator,
6310 boolean previous) {
6311 StringBundler query = null;
6312
6313 if (orderByComparator != null) {
6314 query = new StringBundler(6 +
6315 (orderByComparator.getOrderByFields().length * 6));
6316 }
6317 else {
6318 query = new StringBundler(3);
6319 }
6320
6321 if (getDB().isSupportsInlineDistinct()) {
6322 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6323 }
6324 else {
6325 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6326 }
6327
6328 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6329
6330 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6331
6332 if (!getDB().isSupportsInlineDistinct()) {
6333 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6334 }
6335
6336 if (orderByComparator != null) {
6337 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6338
6339 if (orderByConditionFields.length > 0) {
6340 query.append(WHERE_AND);
6341 }
6342
6343 for (int i = 0; i < orderByConditionFields.length; i++) {
6344 if (getDB().isSupportsInlineDistinct()) {
6345 query.append(_ORDER_BY_ENTITY_ALIAS);
6346 }
6347 else {
6348 query.append(_ORDER_BY_ENTITY_TABLE);
6349 }
6350
6351 query.append(orderByConditionFields[i]);
6352
6353 if ((i + 1) < orderByConditionFields.length) {
6354 if (orderByComparator.isAscending() ^ previous) {
6355 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6356 }
6357 else {
6358 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6359 }
6360 }
6361 else {
6362 if (orderByComparator.isAscending() ^ previous) {
6363 query.append(WHERE_GREATER_THAN);
6364 }
6365 else {
6366 query.append(WHERE_LESSER_THAN);
6367 }
6368 }
6369 }
6370
6371 query.append(ORDER_BY_CLAUSE);
6372
6373 String[] orderByFields = orderByComparator.getOrderByFields();
6374
6375 for (int i = 0; i < orderByFields.length; i++) {
6376 if (getDB().isSupportsInlineDistinct()) {
6377 query.append(_ORDER_BY_ENTITY_ALIAS);
6378 }
6379 else {
6380 query.append(_ORDER_BY_ENTITY_TABLE);
6381 }
6382
6383 query.append(orderByFields[i]);
6384
6385 if ((i + 1) < orderByFields.length) {
6386 if (orderByComparator.isAscending() ^ previous) {
6387 query.append(ORDER_BY_ASC_HAS_NEXT);
6388 }
6389 else {
6390 query.append(ORDER_BY_DESC_HAS_NEXT);
6391 }
6392 }
6393 else {
6394 if (orderByComparator.isAscending() ^ previous) {
6395 query.append(ORDER_BY_ASC);
6396 }
6397 else {
6398 query.append(ORDER_BY_DESC);
6399 }
6400 }
6401 }
6402 }
6403 else {
6404 if (getDB().isSupportsInlineDistinct()) {
6405 query.append(RoleModelImpl.ORDER_BY_JPQL);
6406 }
6407 else {
6408 query.append(RoleModelImpl.ORDER_BY_SQL);
6409 }
6410 }
6411
6412 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6413 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6414
6415 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6416
6417 q.setFirstResult(0);
6418 q.setMaxResults(2);
6419
6420 if (getDB().isSupportsInlineDistinct()) {
6421 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6422 }
6423 else {
6424 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6425 }
6426
6427 QueryPos qPos = QueryPos.getInstance(q);
6428
6429 qPos.add(companyId);
6430
6431 qPos.add(type);
6432
6433 if (orderByComparator != null) {
6434 Object[] values = orderByComparator.getOrderByConditionValues(role);
6435
6436 for (Object value : values) {
6437 qPos.add(value);
6438 }
6439 }
6440
6441 List<Role> list = q.list();
6442
6443 if (list.size() == 2) {
6444 return list.get(1);
6445 }
6446 else {
6447 return null;
6448 }
6449 }
6450
6451
6458 @Override
6459 public List<Role> filterFindByC_T(long companyId, int[] types) {
6460 return filterFindByC_T(companyId, types, QueryUtil.ALL_POS,
6461 QueryUtil.ALL_POS, null);
6462 }
6463
6464
6477 @Override
6478 public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6479 int end) {
6480 return filterFindByC_T(companyId, types, start, end, null);
6481 }
6482
6483
6497 @Override
6498 public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6499 int end, OrderByComparator<Role> orderByComparator) {
6500 if (!InlineSQLHelperUtil.isEnabled()) {
6501 return findByC_T(companyId, types, start, end, orderByComparator);
6502 }
6503
6504 if (types == null) {
6505 types = new int[0];
6506 }
6507 else {
6508 types = ArrayUtil.unique(types);
6509 }
6510
6511 StringBundler query = new StringBundler();
6512
6513 if (getDB().isSupportsInlineDistinct()) {
6514 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6515 }
6516 else {
6517 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6518 }
6519
6520 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6521
6522 if (types.length > 0) {
6523 query.append(StringPool.OPEN_PARENTHESIS);
6524
6525 query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL);
6526
6527 query.append(StringUtil.merge(types));
6528
6529 query.append(StringPool.CLOSE_PARENTHESIS);
6530
6531 query.append(StringPool.CLOSE_PARENTHESIS);
6532 }
6533
6534 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6535 query.index() - 1);
6536
6537 if (!getDB().isSupportsInlineDistinct()) {
6538 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6539 }
6540
6541 if (orderByComparator != null) {
6542 if (getDB().isSupportsInlineDistinct()) {
6543 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6544 orderByComparator, true);
6545 }
6546 else {
6547 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6548 orderByComparator, true);
6549 }
6550 }
6551 else {
6552 if (getDB().isSupportsInlineDistinct()) {
6553 query.append(RoleModelImpl.ORDER_BY_JPQL);
6554 }
6555 else {
6556 query.append(RoleModelImpl.ORDER_BY_SQL);
6557 }
6558 }
6559
6560 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6561 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6562
6563 Session session = null;
6564
6565 try {
6566 session = openSession();
6567
6568 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6569
6570 if (getDB().isSupportsInlineDistinct()) {
6571 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6572 }
6573 else {
6574 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6575 }
6576
6577 QueryPos qPos = QueryPos.getInstance(q);
6578
6579 qPos.add(companyId);
6580
6581 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6582 }
6583 catch (Exception e) {
6584 throw processException(e);
6585 }
6586 finally {
6587 closeSession(session);
6588 }
6589 }
6590
6591
6602 @Override
6603 public List<Role> findByC_T(long companyId, int[] types) {
6604 return findByC_T(companyId, types, QueryUtil.ALL_POS,
6605 QueryUtil.ALL_POS, null);
6606 }
6607
6608
6621 @Override
6622 public List<Role> findByC_T(long companyId, int[] types, int start, int end) {
6623 return findByC_T(companyId, types, start, end, null);
6624 }
6625
6626
6640 @Override
6641 public List<Role> findByC_T(long companyId, int[] types, int start,
6642 int end, OrderByComparator<Role> orderByComparator) {
6643 if (types == null) {
6644 types = new int[0];
6645 }
6646 else {
6647 types = ArrayUtil.unique(types);
6648 }
6649
6650 if (types.length == 1) {
6651 return findByC_T(companyId, types[0], start, end, orderByComparator);
6652 }
6653
6654 boolean pagination = true;
6655 Object[] finderArgs = null;
6656
6657 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6658 (orderByComparator == null)) {
6659 pagination = false;
6660 finderArgs = new Object[] { companyId, StringUtil.merge(types) };
6661 }
6662 else {
6663 finderArgs = new Object[] {
6664 companyId, StringUtil.merge(types),
6665
6666 start, end, orderByComparator
6667 };
6668 }
6669
6670 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6671 finderArgs, this);
6672
6673 if ((list != null) && !list.isEmpty()) {
6674 for (Role role : list) {
6675 if ((companyId != role.getCompanyId()) ||
6676 !ArrayUtil.contains(types, role.getType())) {
6677 list = null;
6678
6679 break;
6680 }
6681 }
6682 }
6683
6684 if (list == null) {
6685 StringBundler query = new StringBundler();
6686
6687 query.append(_SQL_SELECT_ROLE_WHERE);
6688
6689 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6690
6691 if (types.length > 0) {
6692 query.append(StringPool.OPEN_PARENTHESIS);
6693
6694 query.append(_FINDER_COLUMN_C_T_TYPE_7);
6695
6696 query.append(StringUtil.merge(types));
6697
6698 query.append(StringPool.CLOSE_PARENTHESIS);
6699
6700 query.append(StringPool.CLOSE_PARENTHESIS);
6701 }
6702
6703 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6704 1)), query.index() - 1);
6705
6706 if (orderByComparator != null) {
6707 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6708 orderByComparator);
6709 }
6710 else
6711 if (pagination) {
6712 query.append(RoleModelImpl.ORDER_BY_JPQL);
6713 }
6714
6715 String sql = query.toString();
6716
6717 Session session = null;
6718
6719 try {
6720 session = openSession();
6721
6722 Query q = session.createQuery(sql);
6723
6724 QueryPos qPos = QueryPos.getInstance(q);
6725
6726 qPos.add(companyId);
6727
6728 if (!pagination) {
6729 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6730 end, false);
6731
6732 Collections.sort(list);
6733
6734 list = Collections.unmodifiableList(list);
6735 }
6736 else {
6737 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6738 end);
6739 }
6740
6741 cacheResult(list);
6742
6743 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6744 finderArgs, list);
6745 }
6746 catch (Exception e) {
6747 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6748 finderArgs);
6749
6750 throw processException(e);
6751 }
6752 finally {
6753 closeSession(session);
6754 }
6755 }
6756
6757 return list;
6758 }
6759
6760
6766 @Override
6767 public void removeByC_T(long companyId, int type) {
6768 for (Role role : findByC_T(companyId, type, QueryUtil.ALL_POS,
6769 QueryUtil.ALL_POS, null)) {
6770 remove(role);
6771 }
6772 }
6773
6774
6781 @Override
6782 public int countByC_T(long companyId, int type) {
6783 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
6784
6785 Object[] finderArgs = new Object[] { companyId, type };
6786
6787 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6788 this);
6789
6790 if (count == null) {
6791 StringBundler query = new StringBundler(3);
6792
6793 query.append(_SQL_COUNT_ROLE_WHERE);
6794
6795 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6796
6797 query.append(_FINDER_COLUMN_C_T_TYPE_2);
6798
6799 String sql = query.toString();
6800
6801 Session session = null;
6802
6803 try {
6804 session = openSession();
6805
6806 Query q = session.createQuery(sql);
6807
6808 QueryPos qPos = QueryPos.getInstance(q);
6809
6810 qPos.add(companyId);
6811
6812 qPos.add(type);
6813
6814 count = (Long)q.uniqueResult();
6815
6816 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6817 }
6818 catch (Exception e) {
6819 FinderCacheUtil.removeResult(finderPath, finderArgs);
6820
6821 throw processException(e);
6822 }
6823 finally {
6824 closeSession(session);
6825 }
6826 }
6827
6828 return count.intValue();
6829 }
6830
6831
6838 @Override
6839 public int countByC_T(long companyId, int[] types) {
6840 if (types == null) {
6841 types = new int[0];
6842 }
6843 else {
6844 types = ArrayUtil.unique(types);
6845 }
6846
6847 Object[] finderArgs = new Object[] { companyId, StringUtil.merge(types) };
6848
6849 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
6850 finderArgs, this);
6851
6852 if (count == null) {
6853 StringBundler query = new StringBundler();
6854
6855 query.append(_SQL_COUNT_ROLE_WHERE);
6856
6857 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6858
6859 if (types.length > 0) {
6860 query.append(StringPool.OPEN_PARENTHESIS);
6861
6862 query.append(_FINDER_COLUMN_C_T_TYPE_7);
6863
6864 query.append(StringUtil.merge(types));
6865
6866 query.append(StringPool.CLOSE_PARENTHESIS);
6867
6868 query.append(StringPool.CLOSE_PARENTHESIS);
6869 }
6870
6871 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6872 1)), query.index() - 1);
6873
6874 String sql = query.toString();
6875
6876 Session session = null;
6877
6878 try {
6879 session = openSession();
6880
6881 Query q = session.createQuery(sql);
6882
6883 QueryPos qPos = QueryPos.getInstance(q);
6884
6885 qPos.add(companyId);
6886
6887 count = (Long)q.uniqueResult();
6888
6889 FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
6890 finderArgs, count);
6891 }
6892 catch (Exception e) {
6893 FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
6894 finderArgs);
6895
6896 throw processException(e);
6897 }
6898 finally {
6899 closeSession(session);
6900 }
6901 }
6902
6903 return count.intValue();
6904 }
6905
6906
6913 @Override
6914 public int filterCountByC_T(long companyId, int type) {
6915 if (!InlineSQLHelperUtil.isEnabled()) {
6916 return countByC_T(companyId, type);
6917 }
6918
6919 StringBundler query = new StringBundler(3);
6920
6921 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
6922
6923 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6924
6925 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6926
6927 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6928 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6929
6930 Session session = null;
6931
6932 try {
6933 session = openSession();
6934
6935 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6936
6937 q.addScalar(COUNT_COLUMN_NAME,
6938 com.liferay.portal.kernel.dao.orm.Type.LONG);
6939
6940 QueryPos qPos = QueryPos.getInstance(q);
6941
6942 qPos.add(companyId);
6943
6944 qPos.add(type);
6945
6946 Long count = (Long)q.uniqueResult();
6947
6948 return count.intValue();
6949 }
6950 catch (Exception e) {
6951 throw processException(e);
6952 }
6953 finally {
6954 closeSession(session);
6955 }
6956 }
6957
6958
6965 @Override
6966 public int filterCountByC_T(long companyId, int[] types) {
6967 if (!InlineSQLHelperUtil.isEnabled()) {
6968 return countByC_T(companyId, types);
6969 }
6970
6971 if (types == null) {
6972 types = new int[0];
6973 }
6974 else {
6975 types = ArrayUtil.unique(types);
6976 }
6977
6978 StringBundler query = new StringBundler();
6979
6980 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
6981
6982 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6983
6984 if (types.length > 0) {
6985 query.append(StringPool.OPEN_PARENTHESIS);
6986
6987 query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL);
6988
6989 query.append(StringUtil.merge(types));
6990
6991 query.append(StringPool.CLOSE_PARENTHESIS);
6992
6993 query.append(StringPool.CLOSE_PARENTHESIS);
6994 }
6995
6996 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6997 query.index() - 1);
6998
6999 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7000 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7001
7002 Session session = null;
7003
7004 try {
7005 session = openSession();
7006
7007 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7008
7009 q.addScalar(COUNT_COLUMN_NAME,
7010 com.liferay.portal.kernel.dao.orm.Type.LONG);
7011
7012 QueryPos qPos = QueryPos.getInstance(q);
7013
7014 qPos.add(companyId);
7015
7016 Long count = (Long)q.uniqueResult();
7017
7018 return count.intValue();
7019 }
7020 catch (Exception e) {
7021 throw processException(e);
7022 }
7023 finally {
7024 closeSession(session);
7025 }
7026 }
7027
7028 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "role.companyId = ? AND ";
7029 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "role.type = ?";
7030 private static final String _FINDER_COLUMN_C_T_TYPE_7 = "role.type IN (";
7031 private static final String _FINDER_COLUMN_C_T_TYPE_2_SQL = "role.type_ = ?";
7032 private static final String _FINDER_COLUMN_C_T_TYPE_7_SQL = "role.type_ IN (";
7033 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7034 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7035 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
7036 new String[] {
7037 Integer.class.getName(), String.class.getName(),
7038
7039 Integer.class.getName(), Integer.class.getName(),
7040 OrderByComparator.class.getName()
7041 });
7042 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7043 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7044 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
7045 new String[] { Integer.class.getName(), String.class.getName() },
7046 RoleModelImpl.TYPE_COLUMN_BITMASK |
7047 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
7048 RoleModelImpl.NAME_COLUMN_BITMASK);
7049 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7050 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7051 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
7052 new String[] { Integer.class.getName(), String.class.getName() });
7053
7054
7061 @Override
7062 public List<Role> findByT_S(int type, String subtype) {
7063 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7064 null);
7065 }
7066
7067
7080 @Override
7081 public List<Role> findByT_S(int type, String subtype, int start, int end) {
7082 return findByT_S(type, subtype, start, end, null);
7083 }
7084
7085
7099 @Override
7100 public List<Role> findByT_S(int type, String subtype, int start, int end,
7101 OrderByComparator<Role> orderByComparator) {
7102 boolean pagination = true;
7103 FinderPath finderPath = null;
7104 Object[] finderArgs = null;
7105
7106 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7107 (orderByComparator == null)) {
7108 pagination = false;
7109 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
7110 finderArgs = new Object[] { type, subtype };
7111 }
7112 else {
7113 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
7114 finderArgs = new Object[] {
7115 type, subtype,
7116
7117 start, end, orderByComparator
7118 };
7119 }
7120
7121 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
7122 finderArgs, this);
7123
7124 if ((list != null) && !list.isEmpty()) {
7125 for (Role role : list) {
7126 if ((type != role.getType()) ||
7127 !Validator.equals(subtype, role.getSubtype())) {
7128 list = null;
7129
7130 break;
7131 }
7132 }
7133 }
7134
7135 if (list == null) {
7136 StringBundler query = null;
7137
7138 if (orderByComparator != null) {
7139 query = new StringBundler(4 +
7140 (orderByComparator.getOrderByFields().length * 3));
7141 }
7142 else {
7143 query = new StringBundler(4);
7144 }
7145
7146 query.append(_SQL_SELECT_ROLE_WHERE);
7147
7148 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7149
7150 boolean bindSubtype = false;
7151
7152 if (subtype == null) {
7153 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7154 }
7155 else if (subtype.equals(StringPool.BLANK)) {
7156 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7157 }
7158 else {
7159 bindSubtype = true;
7160
7161 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7162 }
7163
7164 if (orderByComparator != null) {
7165 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7166 orderByComparator);
7167 }
7168 else
7169 if (pagination) {
7170 query.append(RoleModelImpl.ORDER_BY_JPQL);
7171 }
7172
7173 String sql = query.toString();
7174
7175 Session session = null;
7176
7177 try {
7178 session = openSession();
7179
7180 Query q = session.createQuery(sql);
7181
7182 QueryPos qPos = QueryPos.getInstance(q);
7183
7184 qPos.add(type);
7185
7186 if (bindSubtype) {
7187 qPos.add(subtype);
7188 }
7189
7190 if (!pagination) {
7191 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7192 end, false);
7193
7194 Collections.sort(list);
7195
7196 list = Collections.unmodifiableList(list);
7197 }
7198 else {
7199 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7200 end);
7201 }
7202
7203 cacheResult(list);
7204
7205 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7206 }
7207 catch (Exception e) {
7208 FinderCacheUtil.removeResult(finderPath, finderArgs);
7209
7210 throw processException(e);
7211 }
7212 finally {
7213 closeSession(session);
7214 }
7215 }
7216
7217 return list;
7218 }
7219
7220
7229 @Override
7230 public Role findByT_S_First(int type, String subtype,
7231 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7232 Role role = fetchByT_S_First(type, subtype, orderByComparator);
7233
7234 if (role != null) {
7235 return role;
7236 }
7237
7238 StringBundler msg = new StringBundler(6);
7239
7240 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7241
7242 msg.append("type=");
7243 msg.append(type);
7244
7245 msg.append(", subtype=");
7246 msg.append(subtype);
7247
7248 msg.append(StringPool.CLOSE_CURLY_BRACE);
7249
7250 throw new NoSuchRoleException(msg.toString());
7251 }
7252
7253
7261 @Override
7262 public Role fetchByT_S_First(int type, String subtype,
7263 OrderByComparator<Role> orderByComparator) {
7264 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
7265
7266 if (!list.isEmpty()) {
7267 return list.get(0);
7268 }
7269
7270 return null;
7271 }
7272
7273
7282 @Override
7283 public Role findByT_S_Last(int type, String subtype,
7284 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7285 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
7286
7287 if (role != null) {
7288 return role;
7289 }
7290
7291 StringBundler msg = new StringBundler(6);
7292
7293 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7294
7295 msg.append("type=");
7296 msg.append(type);
7297
7298 msg.append(", subtype=");
7299 msg.append(subtype);
7300
7301 msg.append(StringPool.CLOSE_CURLY_BRACE);
7302
7303 throw new NoSuchRoleException(msg.toString());
7304 }
7305
7306
7314 @Override
7315 public Role fetchByT_S_Last(int type, String subtype,
7316 OrderByComparator<Role> orderByComparator) {
7317 int count = countByT_S(type, subtype);
7318
7319 if (count == 0) {
7320 return null;
7321 }
7322
7323 List<Role> list = findByT_S(type, subtype, count - 1, count,
7324 orderByComparator);
7325
7326 if (!list.isEmpty()) {
7327 return list.get(0);
7328 }
7329
7330 return null;
7331 }
7332
7333
7343 @Override
7344 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
7345 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7346 Role role = findByPrimaryKey(roleId);
7347
7348 Session session = null;
7349
7350 try {
7351 session = openSession();
7352
7353 Role[] array = new RoleImpl[3];
7354
7355 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
7356 orderByComparator, true);
7357
7358 array[1] = role;
7359
7360 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
7361 orderByComparator, false);
7362
7363 return array;
7364 }
7365 catch (Exception e) {
7366 throw processException(e);
7367 }
7368 finally {
7369 closeSession(session);
7370 }
7371 }
7372
7373 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
7374 String subtype, OrderByComparator<Role> orderByComparator,
7375 boolean previous) {
7376 StringBundler query = null;
7377
7378 if (orderByComparator != null) {
7379 query = new StringBundler(6 +
7380 (orderByComparator.getOrderByFields().length * 6));
7381 }
7382 else {
7383 query = new StringBundler(3);
7384 }
7385
7386 query.append(_SQL_SELECT_ROLE_WHERE);
7387
7388 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7389
7390 boolean bindSubtype = false;
7391
7392 if (subtype == null) {
7393 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7394 }
7395 else if (subtype.equals(StringPool.BLANK)) {
7396 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7397 }
7398 else {
7399 bindSubtype = true;
7400
7401 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7402 }
7403
7404 if (orderByComparator != null) {
7405 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7406
7407 if (orderByConditionFields.length > 0) {
7408 query.append(WHERE_AND);
7409 }
7410
7411 for (int i = 0; i < orderByConditionFields.length; i++) {
7412 query.append(_ORDER_BY_ENTITY_ALIAS);
7413 query.append(orderByConditionFields[i]);
7414
7415 if ((i + 1) < orderByConditionFields.length) {
7416 if (orderByComparator.isAscending() ^ previous) {
7417 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7418 }
7419 else {
7420 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7421 }
7422 }
7423 else {
7424 if (orderByComparator.isAscending() ^ previous) {
7425 query.append(WHERE_GREATER_THAN);
7426 }
7427 else {
7428 query.append(WHERE_LESSER_THAN);
7429 }
7430 }
7431 }
7432
7433 query.append(ORDER_BY_CLAUSE);
7434
7435 String[] orderByFields = orderByComparator.getOrderByFields();
7436
7437 for (int i = 0; i < orderByFields.length; i++) {
7438 query.append(_ORDER_BY_ENTITY_ALIAS);
7439 query.append(orderByFields[i]);
7440
7441 if ((i + 1) < orderByFields.length) {
7442 if (orderByComparator.isAscending() ^ previous) {
7443 query.append(ORDER_BY_ASC_HAS_NEXT);
7444 }
7445 else {
7446 query.append(ORDER_BY_DESC_HAS_NEXT);
7447 }
7448 }
7449 else {
7450 if (orderByComparator.isAscending() ^ previous) {
7451 query.append(ORDER_BY_ASC);
7452 }
7453 else {
7454 query.append(ORDER_BY_DESC);
7455 }
7456 }
7457 }
7458 }
7459 else {
7460 query.append(RoleModelImpl.ORDER_BY_JPQL);
7461 }
7462
7463 String sql = query.toString();
7464
7465 Query q = session.createQuery(sql);
7466
7467 q.setFirstResult(0);
7468 q.setMaxResults(2);
7469
7470 QueryPos qPos = QueryPos.getInstance(q);
7471
7472 qPos.add(type);
7473
7474 if (bindSubtype) {
7475 qPos.add(subtype);
7476 }
7477
7478 if (orderByComparator != null) {
7479 Object[] values = orderByComparator.getOrderByConditionValues(role);
7480
7481 for (Object value : values) {
7482 qPos.add(value);
7483 }
7484 }
7485
7486 List<Role> list = q.list();
7487
7488 if (list.size() == 2) {
7489 return list.get(1);
7490 }
7491 else {
7492 return null;
7493 }
7494 }
7495
7496
7503 @Override
7504 public List<Role> filterFindByT_S(int type, String subtype) {
7505 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
7506 QueryUtil.ALL_POS, null);
7507 }
7508
7509
7522 @Override
7523 public List<Role> filterFindByT_S(int type, String subtype, int start,
7524 int end) {
7525 return filterFindByT_S(type, subtype, start, end, null);
7526 }
7527
7528
7542 @Override
7543 public List<Role> filterFindByT_S(int type, String subtype, int start,
7544 int end, OrderByComparator<Role> orderByComparator) {
7545 if (!InlineSQLHelperUtil.isEnabled()) {
7546 return findByT_S(type, subtype, start, end, orderByComparator);
7547 }
7548
7549 StringBundler query = null;
7550
7551 if (orderByComparator != null) {
7552 query = new StringBundler(4 +
7553 (orderByComparator.getOrderByFields().length * 3));
7554 }
7555 else {
7556 query = new StringBundler(4);
7557 }
7558
7559 if (getDB().isSupportsInlineDistinct()) {
7560 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7561 }
7562 else {
7563 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7564 }
7565
7566 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7567
7568 boolean bindSubtype = false;
7569
7570 if (subtype == null) {
7571 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7572 }
7573 else if (subtype.equals(StringPool.BLANK)) {
7574 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7575 }
7576 else {
7577 bindSubtype = true;
7578
7579 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7580 }
7581
7582 if (!getDB().isSupportsInlineDistinct()) {
7583 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7584 }
7585
7586 if (orderByComparator != null) {
7587 if (getDB().isSupportsInlineDistinct()) {
7588 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7589 orderByComparator, true);
7590 }
7591 else {
7592 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7593 orderByComparator, true);
7594 }
7595 }
7596 else {
7597 if (getDB().isSupportsInlineDistinct()) {
7598 query.append(RoleModelImpl.ORDER_BY_JPQL);
7599 }
7600 else {
7601 query.append(RoleModelImpl.ORDER_BY_SQL);
7602 }
7603 }
7604
7605 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7606 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7607
7608 Session session = null;
7609
7610 try {
7611 session = openSession();
7612
7613 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7614
7615 if (getDB().isSupportsInlineDistinct()) {
7616 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
7617 }
7618 else {
7619 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
7620 }
7621
7622 QueryPos qPos = QueryPos.getInstance(q);
7623
7624 qPos.add(type);
7625
7626 if (bindSubtype) {
7627 qPos.add(subtype);
7628 }
7629
7630 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
7631 }
7632 catch (Exception e) {
7633 throw processException(e);
7634 }
7635 finally {
7636 closeSession(session);
7637 }
7638 }
7639
7640
7650 @Override
7651 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
7652 String subtype, OrderByComparator<Role> orderByComparator)
7653 throws NoSuchRoleException {
7654 if (!InlineSQLHelperUtil.isEnabled()) {
7655 return findByT_S_PrevAndNext(roleId, type, subtype,
7656 orderByComparator);
7657 }
7658
7659 Role role = findByPrimaryKey(roleId);
7660
7661 Session session = null;
7662
7663 try {
7664 session = openSession();
7665
7666 Role[] array = new RoleImpl[3];
7667
7668 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7669 orderByComparator, true);
7670
7671 array[1] = role;
7672
7673 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7674 orderByComparator, false);
7675
7676 return array;
7677 }
7678 catch (Exception e) {
7679 throw processException(e);
7680 }
7681 finally {
7682 closeSession(session);
7683 }
7684 }
7685
7686 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
7687 int type, String subtype, OrderByComparator<Role> orderByComparator,
7688 boolean previous) {
7689 StringBundler query = null;
7690
7691 if (orderByComparator != null) {
7692 query = new StringBundler(6 +
7693 (orderByComparator.getOrderByFields().length * 6));
7694 }
7695 else {
7696 query = new StringBundler(3);
7697 }
7698
7699 if (getDB().isSupportsInlineDistinct()) {
7700 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7701 }
7702 else {
7703 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7704 }
7705
7706 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7707
7708 boolean bindSubtype = false;
7709
7710 if (subtype == null) {
7711 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7712 }
7713 else if (subtype.equals(StringPool.BLANK)) {
7714 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7715 }
7716 else {
7717 bindSubtype = true;
7718
7719 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7720 }
7721
7722 if (!getDB().isSupportsInlineDistinct()) {
7723 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7724 }
7725
7726 if (orderByComparator != null) {
7727 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7728
7729 if (orderByConditionFields.length > 0) {
7730 query.append(WHERE_AND);
7731 }
7732
7733 for (int i = 0; i < orderByConditionFields.length; i++) {
7734 if (getDB().isSupportsInlineDistinct()) {
7735 query.append(_ORDER_BY_ENTITY_ALIAS);
7736 }
7737 else {
7738 query.append(_ORDER_BY_ENTITY_TABLE);
7739 }
7740
7741 query.append(orderByConditionFields[i]);
7742
7743 if ((i + 1) < orderByConditionFields.length) {
7744 if (orderByComparator.isAscending() ^ previous) {
7745 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7746 }
7747 else {
7748 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7749 }
7750 }
7751 else {
7752 if (orderByComparator.isAscending() ^ previous) {
7753 query.append(WHERE_GREATER_THAN);
7754 }
7755 else {
7756 query.append(WHERE_LESSER_THAN);
7757 }
7758 }
7759 }
7760
7761 query.append(ORDER_BY_CLAUSE);
7762
7763 String[] orderByFields = orderByComparator.getOrderByFields();
7764
7765 for (int i = 0; i < orderByFields.length; i++) {
7766 if (getDB().isSupportsInlineDistinct()) {
7767 query.append(_ORDER_BY_ENTITY_ALIAS);
7768 }
7769 else {
7770 query.append(_ORDER_BY_ENTITY_TABLE);
7771 }
7772
7773 query.append(orderByFields[i]);
7774
7775 if ((i + 1) < orderByFields.length) {
7776 if (orderByComparator.isAscending() ^ previous) {
7777 query.append(ORDER_BY_ASC_HAS_NEXT);
7778 }
7779 else {
7780 query.append(ORDER_BY_DESC_HAS_NEXT);
7781 }
7782 }
7783 else {
7784 if (orderByComparator.isAscending() ^ previous) {
7785 query.append(ORDER_BY_ASC);
7786 }
7787 else {
7788 query.append(ORDER_BY_DESC);
7789 }
7790 }
7791 }
7792 }
7793 else {
7794 if (getDB().isSupportsInlineDistinct()) {
7795 query.append(RoleModelImpl.ORDER_BY_JPQL);
7796 }
7797 else {
7798 query.append(RoleModelImpl.ORDER_BY_SQL);
7799 }
7800 }
7801
7802 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7803 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7804
7805 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7806
7807 q.setFirstResult(0);
7808 q.setMaxResults(2);
7809
7810 if (getDB().isSupportsInlineDistinct()) {
7811 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
7812 }
7813 else {
7814 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
7815 }
7816
7817 QueryPos qPos = QueryPos.getInstance(q);
7818
7819 qPos.add(type);
7820
7821 if (bindSubtype) {
7822 qPos.add(subtype);
7823 }
7824
7825 if (orderByComparator != null) {
7826 Object[] values = orderByComparator.getOrderByConditionValues(role);
7827
7828 for (Object value : values) {
7829 qPos.add(value);
7830 }
7831 }
7832
7833 List<Role> list = q.list();
7834
7835 if (list.size() == 2) {
7836 return list.get(1);
7837 }
7838 else {
7839 return null;
7840 }
7841 }
7842
7843
7849 @Override
7850 public void removeByT_S(int type, String subtype) {
7851 for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
7852 QueryUtil.ALL_POS, null)) {
7853 remove(role);
7854 }
7855 }
7856
7857
7864 @Override
7865 public int countByT_S(int type, String subtype) {
7866 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
7867
7868 Object[] finderArgs = new Object[] { type, subtype };
7869
7870 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7871 this);
7872
7873 if (count == null) {
7874 StringBundler query = new StringBundler(3);
7875
7876 query.append(_SQL_COUNT_ROLE_WHERE);
7877
7878 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7879
7880 boolean bindSubtype = false;
7881
7882 if (subtype == null) {
7883 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7884 }
7885 else if (subtype.equals(StringPool.BLANK)) {
7886 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7887 }
7888 else {
7889 bindSubtype = true;
7890
7891 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7892 }
7893
7894 String sql = query.toString();
7895
7896 Session session = null;
7897
7898 try {
7899 session = openSession();
7900
7901 Query q = session.createQuery(sql);
7902
7903 QueryPos qPos = QueryPos.getInstance(q);
7904
7905 qPos.add(type);
7906
7907 if (bindSubtype) {
7908 qPos.add(subtype);
7909 }
7910
7911 count = (Long)q.uniqueResult();
7912
7913 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7914 }
7915 catch (Exception e) {
7916 FinderCacheUtil.removeResult(finderPath, finderArgs);
7917
7918 throw processException(e);
7919 }
7920 finally {
7921 closeSession(session);
7922 }
7923 }
7924
7925 return count.intValue();
7926 }
7927
7928
7935 @Override
7936 public int filterCountByT_S(int type, String subtype) {
7937 if (!InlineSQLHelperUtil.isEnabled()) {
7938 return countByT_S(type, subtype);
7939 }
7940
7941 StringBundler query = new StringBundler(3);
7942
7943 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7944
7945 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7946
7947 boolean bindSubtype = false;
7948
7949 if (subtype == null) {
7950 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7951 }
7952 else if (subtype.equals(StringPool.BLANK)) {
7953 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7954 }
7955 else {
7956 bindSubtype = true;
7957
7958 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7959 }
7960
7961 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7962 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7963
7964 Session session = null;
7965
7966 try {
7967 session = openSession();
7968
7969 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7970
7971 q.addScalar(COUNT_COLUMN_NAME,
7972 com.liferay.portal.kernel.dao.orm.Type.LONG);
7973
7974 QueryPos qPos = QueryPos.getInstance(q);
7975
7976 qPos.add(type);
7977
7978 if (bindSubtype) {
7979 qPos.add(subtype);
7980 }
7981
7982 Long count = (Long)q.uniqueResult();
7983
7984 return count.intValue();
7985 }
7986 catch (Exception e) {
7987 throw processException(e);
7988 }
7989 finally {
7990 closeSession(session);
7991 }
7992 }
7993
7994 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
7995 private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND ";
7996 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
7997 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
7998 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
7999 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8000 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
8001 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
8002 new String[] {
8003 Long.class.getName(), Long.class.getName(), Long.class.getName()
8004 },
8005 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
8006 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8007 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
8008 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8009 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8010 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
8011 new String[] {
8012 Long.class.getName(), Long.class.getName(), Long.class.getName()
8013 });
8014
8015
8024 @Override
8025 public Role findByC_C_C(long companyId, long classNameId, long classPK)
8026 throws NoSuchRoleException {
8027 Role role = fetchByC_C_C(companyId, classNameId, classPK);
8028
8029 if (role == null) {
8030 StringBundler msg = new StringBundler(8);
8031
8032 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8033
8034 msg.append("companyId=");
8035 msg.append(companyId);
8036
8037 msg.append(", classNameId=");
8038 msg.append(classNameId);
8039
8040 msg.append(", classPK=");
8041 msg.append(classPK);
8042
8043 msg.append(StringPool.CLOSE_CURLY_BRACE);
8044
8045 if (_log.isWarnEnabled()) {
8046 _log.warn(msg.toString());
8047 }
8048
8049 throw new NoSuchRoleException(msg.toString());
8050 }
8051
8052 return role;
8053 }
8054
8055
8063 @Override
8064 public Role fetchByC_C_C(long companyId, long classNameId, long classPK) {
8065 return fetchByC_C_C(companyId, classNameId, classPK, true);
8066 }
8067
8068
8077 @Override
8078 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
8079 boolean retrieveFromCache) {
8080 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8081
8082 Object result = null;
8083
8084 if (retrieveFromCache) {
8085 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
8086 finderArgs, this);
8087 }
8088
8089 if (result instanceof Role) {
8090 Role role = (Role)result;
8091
8092 if ((companyId != role.getCompanyId()) ||
8093 (classNameId != role.getClassNameId()) ||
8094 (classPK != role.getClassPK())) {
8095 result = null;
8096 }
8097 }
8098
8099 if (result == null) {
8100 StringBundler query = new StringBundler(5);
8101
8102 query.append(_SQL_SELECT_ROLE_WHERE);
8103
8104 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8105
8106 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8107
8108 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8109
8110 String sql = query.toString();
8111
8112 Session session = null;
8113
8114 try {
8115 session = openSession();
8116
8117 Query q = session.createQuery(sql);
8118
8119 QueryPos qPos = QueryPos.getInstance(q);
8120
8121 qPos.add(companyId);
8122
8123 qPos.add(classNameId);
8124
8125 qPos.add(classPK);
8126
8127 List<Role> list = q.list();
8128
8129 if (list.isEmpty()) {
8130 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8131 finderArgs, list);
8132 }
8133 else {
8134 Role role = list.get(0);
8135
8136 result = role;
8137
8138 cacheResult(role);
8139
8140 if ((role.getCompanyId() != companyId) ||
8141 (role.getClassNameId() != classNameId) ||
8142 (role.getClassPK() != classPK)) {
8143 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8144 finderArgs, role);
8145 }
8146 }
8147 }
8148 catch (Exception e) {
8149 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
8150 finderArgs);
8151
8152 throw processException(e);
8153 }
8154 finally {
8155 closeSession(session);
8156 }
8157 }
8158
8159 if (result instanceof List<?>) {
8160 return null;
8161 }
8162 else {
8163 return (Role)result;
8164 }
8165 }
8166
8167
8175 @Override
8176 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
8177 throws NoSuchRoleException {
8178 Role role = findByC_C_C(companyId, classNameId, classPK);
8179
8180 return remove(role);
8181 }
8182
8183
8191 @Override
8192 public int countByC_C_C(long companyId, long classNameId, long classPK) {
8193 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
8194
8195 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8196
8197 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8198 this);
8199
8200 if (count == null) {
8201 StringBundler query = new StringBundler(4);
8202
8203 query.append(_SQL_COUNT_ROLE_WHERE);
8204
8205 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8206
8207 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8208
8209 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8210
8211 String sql = query.toString();
8212
8213 Session session = null;
8214
8215 try {
8216 session = openSession();
8217
8218 Query q = session.createQuery(sql);
8219
8220 QueryPos qPos = QueryPos.getInstance(q);
8221
8222 qPos.add(companyId);
8223
8224 qPos.add(classNameId);
8225
8226 qPos.add(classPK);
8227
8228 count = (Long)q.uniqueResult();
8229
8230 FinderCacheUtil.putResult(finderPath, finderArgs, count);
8231 }
8232 catch (Exception e) {
8233 FinderCacheUtil.removeResult(finderPath, finderArgs);
8234
8235 throw processException(e);
8236 }
8237 finally {
8238 closeSession(session);
8239 }
8240 }
8241
8242 return count.intValue();
8243 }
8244
8245 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
8246 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
8247 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
8248
8249 public RolePersistenceImpl() {
8250 setModelClass(Role.class);
8251 }
8252
8253
8258 @Override
8259 public void cacheResult(Role role) {
8260 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8261 RoleImpl.class, role.getPrimaryKey(), role);
8262
8263 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
8264 new Object[] { role.getCompanyId(), role.getName() }, role);
8265
8266 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8267 new Object[] {
8268 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
8269 }, role);
8270
8271 role.resetOriginalValues();
8272 }
8273
8274
8279 @Override
8280 public void cacheResult(List<Role> roles) {
8281 for (Role role : roles) {
8282 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8283 RoleImpl.class, role.getPrimaryKey()) == null) {
8284 cacheResult(role);
8285 }
8286 else {
8287 role.resetOriginalValues();
8288 }
8289 }
8290 }
8291
8292
8299 @Override
8300 public void clearCache() {
8301 EntityCacheUtil.clearCache(RoleImpl.class);
8302
8303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
8304 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8305 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8306 }
8307
8308
8315 @Override
8316 public void clearCache(Role role) {
8317 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8318 RoleImpl.class, role.getPrimaryKey());
8319
8320 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8321 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8322
8323 clearUniqueFindersCache(role);
8324 }
8325
8326 @Override
8327 public void clearCache(List<Role> roles) {
8328 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8329 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8330
8331 for (Role role : roles) {
8332 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8333 RoleImpl.class, role.getPrimaryKey());
8334
8335 clearUniqueFindersCache(role);
8336 }
8337 }
8338
8339 protected void cacheUniqueFindersCache(Role role) {
8340 if (role.isNew()) {
8341 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
8342
8343 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8344 Long.valueOf(1));
8345 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
8346
8347 args = new Object[] {
8348 role.getCompanyId(), role.getClassNameId(),
8349 role.getClassPK()
8350 };
8351
8352 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8353 Long.valueOf(1));
8354 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
8355 }
8356 else {
8357 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8358
8359 if ((roleModelImpl.getColumnBitmask() &
8360 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8361 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
8362
8363 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8364 Long.valueOf(1));
8365 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
8366 }
8367
8368 if ((roleModelImpl.getColumnBitmask() &
8369 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8370 Object[] args = new Object[] {
8371 role.getCompanyId(), role.getClassNameId(),
8372 role.getClassPK()
8373 };
8374
8375 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8376 Long.valueOf(1));
8377 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
8378 }
8379 }
8380 }
8381
8382 protected void clearUniqueFindersCache(Role role) {
8383 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8384
8385 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
8386
8387 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8388 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8389
8390 if ((roleModelImpl.getColumnBitmask() &
8391 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8392 args = new Object[] {
8393 roleModelImpl.getOriginalCompanyId(),
8394 roleModelImpl.getOriginalName()
8395 };
8396
8397 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8398 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8399 }
8400
8401 args = new Object[] {
8402 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
8403 };
8404
8405 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8406 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8407
8408 if ((roleModelImpl.getColumnBitmask() &
8409 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8410 args = new Object[] {
8411 roleModelImpl.getOriginalCompanyId(),
8412 roleModelImpl.getOriginalClassNameId(),
8413 roleModelImpl.getOriginalClassPK()
8414 };
8415
8416 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8417 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8418 }
8419 }
8420
8421
8427 @Override
8428 public Role create(long roleId) {
8429 Role role = new RoleImpl();
8430
8431 role.setNew(true);
8432 role.setPrimaryKey(roleId);
8433
8434 String uuid = PortalUUIDUtil.generate();
8435
8436 role.setUuid(uuid);
8437
8438 return role;
8439 }
8440
8441
8448 @Override
8449 public Role remove(long roleId) throws NoSuchRoleException {
8450 return remove((Serializable)roleId);
8451 }
8452
8453
8460 @Override
8461 public Role remove(Serializable primaryKey) throws NoSuchRoleException {
8462 Session session = null;
8463
8464 try {
8465 session = openSession();
8466
8467 Role role = (Role)session.get(RoleImpl.class, primaryKey);
8468
8469 if (role == null) {
8470 if (_log.isWarnEnabled()) {
8471 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8472 }
8473
8474 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8475 primaryKey);
8476 }
8477
8478 return remove(role);
8479 }
8480 catch (NoSuchRoleException nsee) {
8481 throw nsee;
8482 }
8483 catch (Exception e) {
8484 throw processException(e);
8485 }
8486 finally {
8487 closeSession(session);
8488 }
8489 }
8490
8491 @Override
8492 protected Role removeImpl(Role role) {
8493 role = toUnwrappedModel(role);
8494
8495 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8496
8497 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8498
8499 Session session = null;
8500
8501 try {
8502 session = openSession();
8503
8504 if (!session.contains(role)) {
8505 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
8506 }
8507
8508 if (role != null) {
8509 session.delete(role);
8510 }
8511 }
8512 catch (Exception e) {
8513 throw processException(e);
8514 }
8515 finally {
8516 closeSession(session);
8517 }
8518
8519 if (role != null) {
8520 clearCache(role);
8521 }
8522
8523 return role;
8524 }
8525
8526 @Override
8527 public Role updateImpl(Role role) {
8528 role = toUnwrappedModel(role);
8529
8530 boolean isNew = role.isNew();
8531
8532 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8533
8534 if (Validator.isNull(role.getUuid())) {
8535 String uuid = PortalUUIDUtil.generate();
8536
8537 role.setUuid(uuid);
8538 }
8539
8540 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
8541
8542 Date now = new Date();
8543
8544 if (isNew && (role.getCreateDate() == null)) {
8545 if (serviceContext == null) {
8546 role.setCreateDate(now);
8547 }
8548 else {
8549 role.setCreateDate(serviceContext.getCreateDate(now));
8550 }
8551 }
8552
8553 if (!roleModelImpl.hasSetModifiedDate()) {
8554 if (serviceContext == null) {
8555 role.setModifiedDate(now);
8556 }
8557 else {
8558 role.setModifiedDate(serviceContext.getModifiedDate(now));
8559 }
8560 }
8561
8562 Session session = null;
8563
8564 try {
8565 session = openSession();
8566
8567 if (role.isNew()) {
8568 session.save(role);
8569
8570 role.setNew(false);
8571 }
8572 else {
8573 session.merge(role);
8574 }
8575 }
8576 catch (Exception e) {
8577 throw processException(e);
8578 }
8579 finally {
8580 closeSession(session);
8581 }
8582
8583 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8584
8585 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
8586 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8587 }
8588
8589 else {
8590 if ((roleModelImpl.getColumnBitmask() &
8591 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8592 Object[] args = new Object[] { roleModelImpl.getOriginalUuid() };
8593
8594 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8595 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8596 args);
8597
8598 args = new Object[] { roleModelImpl.getUuid() };
8599
8600 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8601 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8602 args);
8603 }
8604
8605 if ((roleModelImpl.getColumnBitmask() &
8606 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8607 Object[] args = new Object[] {
8608 roleModelImpl.getOriginalUuid(),
8609 roleModelImpl.getOriginalCompanyId()
8610 };
8611
8612 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8613 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8614 args);
8615
8616 args = new Object[] {
8617 roleModelImpl.getUuid(), roleModelImpl.getCompanyId()
8618 };
8619
8620 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8621 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8622 args);
8623 }
8624
8625 if ((roleModelImpl.getColumnBitmask() &
8626 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8627 Object[] args = new Object[] {
8628 roleModelImpl.getOriginalCompanyId()
8629 };
8630
8631 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8632 args);
8633 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8634 args);
8635
8636 args = new Object[] { roleModelImpl.getCompanyId() };
8637
8638 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
8639 args);
8640 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8641 args);
8642 }
8643
8644 if ((roleModelImpl.getColumnBitmask() &
8645 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
8646 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
8647
8648 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8649 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8650 args);
8651
8652 args = new Object[] { roleModelImpl.getName() };
8653
8654 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8655 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8656 args);
8657 }
8658
8659 if ((roleModelImpl.getColumnBitmask() &
8660 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
8661 Object[] args = new Object[] { roleModelImpl.getOriginalType() };
8662
8663 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8664 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8665 args);
8666
8667 args = new Object[] { roleModelImpl.getType() };
8668
8669 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8670 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8671 args);
8672 }
8673
8674 if ((roleModelImpl.getColumnBitmask() &
8675 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
8676 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
8677
8678 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8679 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8680 args);
8681
8682 args = new Object[] { roleModelImpl.getSubtype() };
8683
8684 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8685 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8686 args);
8687 }
8688
8689 if ((roleModelImpl.getColumnBitmask() &
8690 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
8691 Object[] args = new Object[] {
8692 roleModelImpl.getOriginalCompanyId(),
8693 roleModelImpl.getOriginalType()
8694 };
8695
8696 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8697 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8698 args);
8699
8700 args = new Object[] {
8701 roleModelImpl.getCompanyId(), roleModelImpl.getType()
8702 };
8703
8704 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8705 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8706 args);
8707 }
8708
8709 if ((roleModelImpl.getColumnBitmask() &
8710 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
8711 Object[] args = new Object[] {
8712 roleModelImpl.getOriginalType(),
8713 roleModelImpl.getOriginalSubtype()
8714 };
8715
8716 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8717 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8718 args);
8719
8720 args = new Object[] {
8721 roleModelImpl.getType(), roleModelImpl.getSubtype()
8722 };
8723
8724 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8725 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8726 args);
8727 }
8728 }
8729
8730 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8731 RoleImpl.class, role.getPrimaryKey(), role, false);
8732
8733 clearUniqueFindersCache(role);
8734 cacheUniqueFindersCache(role);
8735
8736 role.resetOriginalValues();
8737
8738 return role;
8739 }
8740
8741 protected Role toUnwrappedModel(Role role) {
8742 if (role instanceof RoleImpl) {
8743 return role;
8744 }
8745
8746 RoleImpl roleImpl = new RoleImpl();
8747
8748 roleImpl.setNew(role.isNew());
8749 roleImpl.setPrimaryKey(role.getPrimaryKey());
8750
8751 roleImpl.setMvccVersion(role.getMvccVersion());
8752 roleImpl.setUuid(role.getUuid());
8753 roleImpl.setRoleId(role.getRoleId());
8754 roleImpl.setCompanyId(role.getCompanyId());
8755 roleImpl.setUserId(role.getUserId());
8756 roleImpl.setUserName(role.getUserName());
8757 roleImpl.setCreateDate(role.getCreateDate());
8758 roleImpl.setModifiedDate(role.getModifiedDate());
8759 roleImpl.setClassNameId(role.getClassNameId());
8760 roleImpl.setClassPK(role.getClassPK());
8761 roleImpl.setName(role.getName());
8762 roleImpl.setTitle(role.getTitle());
8763 roleImpl.setDescription(role.getDescription());
8764 roleImpl.setType(role.getType());
8765 roleImpl.setSubtype(role.getSubtype());
8766
8767 return roleImpl;
8768 }
8769
8770
8777 @Override
8778 public Role findByPrimaryKey(Serializable primaryKey)
8779 throws NoSuchRoleException {
8780 Role role = fetchByPrimaryKey(primaryKey);
8781
8782 if (role == null) {
8783 if (_log.isWarnEnabled()) {
8784 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8785 }
8786
8787 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8788 primaryKey);
8789 }
8790
8791 return role;
8792 }
8793
8794
8801 @Override
8802 public Role findByPrimaryKey(long roleId) throws NoSuchRoleException {
8803 return findByPrimaryKey((Serializable)roleId);
8804 }
8805
8806
8812 @Override
8813 public Role fetchByPrimaryKey(Serializable primaryKey) {
8814 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8815 RoleImpl.class, primaryKey);
8816
8817 if (role == _nullRole) {
8818 return null;
8819 }
8820
8821 if (role == null) {
8822 Session session = null;
8823
8824 try {
8825 session = openSession();
8826
8827 role = (Role)session.get(RoleImpl.class, primaryKey);
8828
8829 if (role != null) {
8830 cacheResult(role);
8831 }
8832 else {
8833 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8834 RoleImpl.class, primaryKey, _nullRole);
8835 }
8836 }
8837 catch (Exception e) {
8838 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8839 RoleImpl.class, primaryKey);
8840
8841 throw processException(e);
8842 }
8843 finally {
8844 closeSession(session);
8845 }
8846 }
8847
8848 return role;
8849 }
8850
8851
8857 @Override
8858 public Role fetchByPrimaryKey(long roleId) {
8859 return fetchByPrimaryKey((Serializable)roleId);
8860 }
8861
8862 @Override
8863 public Map<Serializable, Role> fetchByPrimaryKeys(
8864 Set<Serializable> primaryKeys) {
8865 if (primaryKeys.isEmpty()) {
8866 return Collections.emptyMap();
8867 }
8868
8869 Map<Serializable, Role> map = new HashMap<Serializable, Role>();
8870
8871 if (primaryKeys.size() == 1) {
8872 Iterator<Serializable> iterator = primaryKeys.iterator();
8873
8874 Serializable primaryKey = iterator.next();
8875
8876 Role role = fetchByPrimaryKey(primaryKey);
8877
8878 if (role != null) {
8879 map.put(primaryKey, role);
8880 }
8881
8882 return map;
8883 }
8884
8885 Set<Serializable> uncachedPrimaryKeys = null;
8886
8887 for (Serializable primaryKey : primaryKeys) {
8888 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8889 RoleImpl.class, primaryKey);
8890
8891 if (role == null) {
8892 if (uncachedPrimaryKeys == null) {
8893 uncachedPrimaryKeys = new HashSet<Serializable>();
8894 }
8895
8896 uncachedPrimaryKeys.add(primaryKey);
8897 }
8898 else {
8899 map.put(primaryKey, role);
8900 }
8901 }
8902
8903 if (uncachedPrimaryKeys == null) {
8904 return map;
8905 }
8906
8907 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
8908 1);
8909
8910 query.append(_SQL_SELECT_ROLE_WHERE_PKS_IN);
8911
8912 for (Serializable primaryKey : uncachedPrimaryKeys) {
8913 query.append(String.valueOf(primaryKey));
8914
8915 query.append(StringPool.COMMA);
8916 }
8917
8918 query.setIndex(query.index() - 1);
8919
8920 query.append(StringPool.CLOSE_PARENTHESIS);
8921
8922 String sql = query.toString();
8923
8924 Session session = null;
8925
8926 try {
8927 session = openSession();
8928
8929 Query q = session.createQuery(sql);
8930
8931 for (Role role : (List<Role>)q.list()) {
8932 map.put(role.getPrimaryKeyObj(), role);
8933
8934 cacheResult(role);
8935
8936 uncachedPrimaryKeys.remove(role.getPrimaryKeyObj());
8937 }
8938
8939 for (Serializable primaryKey : uncachedPrimaryKeys) {
8940 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8941 RoleImpl.class, primaryKey, _nullRole);
8942 }
8943 }
8944 catch (Exception e) {
8945 throw processException(e);
8946 }
8947 finally {
8948 closeSession(session);
8949 }
8950
8951 return map;
8952 }
8953
8954
8959 @Override
8960 public List<Role> findAll() {
8961 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8962 }
8963
8964
8975 @Override
8976 public List<Role> findAll(int start, int end) {
8977 return findAll(start, end, null);
8978 }
8979
8980
8992 @Override
8993 public List<Role> findAll(int start, int end,
8994 OrderByComparator<Role> orderByComparator) {
8995 boolean pagination = true;
8996 FinderPath finderPath = null;
8997 Object[] finderArgs = null;
8998
8999 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9000 (orderByComparator == null)) {
9001 pagination = false;
9002 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9003 finderArgs = FINDER_ARGS_EMPTY;
9004 }
9005 else {
9006 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9007 finderArgs = new Object[] { start, end, orderByComparator };
9008 }
9009
9010 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
9011 finderArgs, this);
9012
9013 if (list == null) {
9014 StringBundler query = null;
9015 String sql = null;
9016
9017 if (orderByComparator != null) {
9018 query = new StringBundler(2 +
9019 (orderByComparator.getOrderByFields().length * 3));
9020
9021 query.append(_SQL_SELECT_ROLE);
9022
9023 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9024 orderByComparator);
9025
9026 sql = query.toString();
9027 }
9028 else {
9029 sql = _SQL_SELECT_ROLE;
9030
9031 if (pagination) {
9032 sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
9033 }
9034 }
9035
9036 Session session = null;
9037
9038 try {
9039 session = openSession();
9040
9041 Query q = session.createQuery(sql);
9042
9043 if (!pagination) {
9044 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9045 end, false);
9046
9047 Collections.sort(list);
9048
9049 list = Collections.unmodifiableList(list);
9050 }
9051 else {
9052 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9053 end);
9054 }
9055
9056 cacheResult(list);
9057
9058 FinderCacheUtil.putResult(finderPath, finderArgs, list);
9059 }
9060 catch (Exception e) {
9061 FinderCacheUtil.removeResult(finderPath, finderArgs);
9062
9063 throw processException(e);
9064 }
9065 finally {
9066 closeSession(session);
9067 }
9068 }
9069
9070 return list;
9071 }
9072
9073
9077 @Override
9078 public void removeAll() {
9079 for (Role role : findAll()) {
9080 remove(role);
9081 }
9082 }
9083
9084
9089 @Override
9090 public int countAll() {
9091 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
9092 FINDER_ARGS_EMPTY, this);
9093
9094 if (count == null) {
9095 Session session = null;
9096
9097 try {
9098 session = openSession();
9099
9100 Query q = session.createQuery(_SQL_COUNT_ROLE);
9101
9102 count = (Long)q.uniqueResult();
9103
9104 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
9105 FINDER_ARGS_EMPTY, count);
9106 }
9107 catch (Exception e) {
9108 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
9109 FINDER_ARGS_EMPTY);
9110
9111 throw processException(e);
9112 }
9113 finally {
9114 closeSession(session);
9115 }
9116 }
9117
9118 return count.intValue();
9119 }
9120
9121
9127 @Override
9128 public long[] getGroupPrimaryKeys(long pk) {
9129 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9130
9131 return pks.clone();
9132 }
9133
9134
9140 @Override
9141 public List<com.liferay.portal.model.Group> getGroups(long pk) {
9142 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9143 }
9144
9145
9157 @Override
9158 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
9159 int end) {
9160 return getGroups(pk, start, end, null);
9161 }
9162
9163
9176 @Override
9177 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
9178 int end,
9179 OrderByComparator<com.liferay.portal.model.Group> orderByComparator) {
9180 return roleToGroupTableMapper.getRightBaseModels(pk, start, end,
9181 orderByComparator);
9182 }
9183
9184
9190 @Override
9191 public int getGroupsSize(long pk) {
9192 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9193
9194 return pks.length;
9195 }
9196
9197
9204 @Override
9205 public boolean containsGroup(long pk, long groupPK) {
9206 return roleToGroupTableMapper.containsTableMapping(pk, groupPK);
9207 }
9208
9209
9215 @Override
9216 public boolean containsGroups(long pk) {
9217 if (getGroupsSize(pk) > 0) {
9218 return true;
9219 }
9220 else {
9221 return false;
9222 }
9223 }
9224
9225
9231 @Override
9232 public void addGroup(long pk, long groupPK) {
9233 roleToGroupTableMapper.addTableMapping(pk, groupPK);
9234 }
9235
9236
9242 @Override
9243 public void addGroup(long pk, com.liferay.portal.model.Group group) {
9244 roleToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
9245 }
9246
9247
9253 @Override
9254 public void addGroups(long pk, long[] groupPKs) {
9255 for (long groupPK : groupPKs) {
9256 roleToGroupTableMapper.addTableMapping(pk, groupPK);
9257 }
9258 }
9259
9260
9266 @Override
9267 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups) {
9268 for (com.liferay.portal.model.Group group : groups) {
9269 roleToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
9270 }
9271 }
9272
9273
9278 @Override
9279 public void clearGroups(long pk) {
9280 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9281 }
9282
9283
9289 @Override
9290 public void removeGroup(long pk, long groupPK) {
9291 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9292 }
9293
9294
9300 @Override
9301 public void removeGroup(long pk, com.liferay.portal.model.Group group) {
9302 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9303 }
9304
9305
9311 @Override
9312 public void removeGroups(long pk, long[] groupPKs) {
9313 for (long groupPK : groupPKs) {
9314 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9315 }
9316 }
9317
9318
9324 @Override
9325 public void removeGroups(long pk,
9326 List<com.liferay.portal.model.Group> groups) {
9327 for (com.liferay.portal.model.Group group : groups) {
9328 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9329 }
9330 }
9331
9332
9338 @Override
9339 public void setGroups(long pk, long[] groupPKs) {
9340 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
9341 Set<Long> oldGroupPKsSet = SetUtil.fromArray(roleToGroupTableMapper.getRightPrimaryKeys(
9342 pk));
9343
9344 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
9345
9346 removeGroupPKsSet.removeAll(newGroupPKsSet);
9347
9348 for (long removeGroupPK : removeGroupPKsSet) {
9349 roleToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
9350 }
9351
9352 newGroupPKsSet.removeAll(oldGroupPKsSet);
9353
9354 for (long newGroupPK : newGroupPKsSet) {
9355 roleToGroupTableMapper.addTableMapping(pk, newGroupPK);
9356 }
9357 }
9358
9359
9365 @Override
9366 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups) {
9367 try {
9368 long[] groupPKs = new long[groups.size()];
9369
9370 for (int i = 0; i < groups.size(); i++) {
9371 com.liferay.portal.model.Group group = groups.get(i);
9372
9373 groupPKs[i] = group.getPrimaryKey();
9374 }
9375
9376 setGroups(pk, groupPKs);
9377 }
9378 catch (Exception e) {
9379 throw processException(e);
9380 }
9381 }
9382
9383
9389 @Override
9390 public long[] getUserPrimaryKeys(long pk) {
9391 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9392
9393 return pks.clone();
9394 }
9395
9396
9402 @Override
9403 public List<com.liferay.portal.model.User> getUsers(long pk) {
9404 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9405 }
9406
9407
9419 @Override
9420 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9421 int end) {
9422 return getUsers(pk, start, end, null);
9423 }
9424
9425
9438 @Override
9439 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9440 int end,
9441 OrderByComparator<com.liferay.portal.model.User> orderByComparator) {
9442 return roleToUserTableMapper.getRightBaseModels(pk, start, end,
9443 orderByComparator);
9444 }
9445
9446
9452 @Override
9453 public int getUsersSize(long pk) {
9454 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9455
9456 return pks.length;
9457 }
9458
9459
9466 @Override
9467 public boolean containsUser(long pk, long userPK) {
9468 return roleToUserTableMapper.containsTableMapping(pk, userPK);
9469 }
9470
9471
9477 @Override
9478 public boolean containsUsers(long pk) {
9479 if (getUsersSize(pk) > 0) {
9480 return true;
9481 }
9482 else {
9483 return false;
9484 }
9485 }
9486
9487
9493 @Override
9494 public void addUser(long pk, long userPK) {
9495 roleToUserTableMapper.addTableMapping(pk, userPK);
9496 }
9497
9498
9504 @Override
9505 public void addUser(long pk, com.liferay.portal.model.User user) {
9506 roleToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
9507 }
9508
9509
9515 @Override
9516 public void addUsers(long pk, long[] userPKs) {
9517 for (long userPK : userPKs) {
9518 roleToUserTableMapper.addTableMapping(pk, userPK);
9519 }
9520 }
9521
9522
9528 @Override
9529 public void addUsers(long pk, List<com.liferay.portal.model.User> users) {
9530 for (com.liferay.portal.model.User user : users) {
9531 roleToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
9532 }
9533 }
9534
9535
9540 @Override
9541 public void clearUsers(long pk) {
9542 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9543 }
9544
9545
9551 @Override
9552 public void removeUser(long pk, long userPK) {
9553 roleToUserTableMapper.deleteTableMapping(pk, userPK);
9554 }
9555
9556
9562 @Override
9563 public void removeUser(long pk, com.liferay.portal.model.User user) {
9564 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9565 }
9566
9567
9573 @Override
9574 public void removeUsers(long pk, long[] userPKs) {
9575 for (long userPK : userPKs) {
9576 roleToUserTableMapper.deleteTableMapping(pk, userPK);
9577 }
9578 }
9579
9580
9586 @Override
9587 public void removeUsers(long pk, List<com.liferay.portal.model.User> users) {
9588 for (com.liferay.portal.model.User user : users) {
9589 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9590 }
9591 }
9592
9593
9599 @Override
9600 public void setUsers(long pk, long[] userPKs) {
9601 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
9602 Set<Long> oldUserPKsSet = SetUtil.fromArray(roleToUserTableMapper.getRightPrimaryKeys(
9603 pk));
9604
9605 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
9606
9607 removeUserPKsSet.removeAll(newUserPKsSet);
9608
9609 for (long removeUserPK : removeUserPKsSet) {
9610 roleToUserTableMapper.deleteTableMapping(pk, removeUserPK);
9611 }
9612
9613 newUserPKsSet.removeAll(oldUserPKsSet);
9614
9615 for (long newUserPK : newUserPKsSet) {
9616 roleToUserTableMapper.addTableMapping(pk, newUserPK);
9617 }
9618 }
9619
9620
9626 @Override
9627 public void setUsers(long pk, List<com.liferay.portal.model.User> users) {
9628 try {
9629 long[] userPKs = new long[users.size()];
9630
9631 for (int i = 0; i < users.size(); i++) {
9632 com.liferay.portal.model.User user = users.get(i);
9633
9634 userPKs[i] = user.getPrimaryKey();
9635 }
9636
9637 setUsers(pk, userPKs);
9638 }
9639 catch (Exception e) {
9640 throw processException(e);
9641 }
9642 }
9643
9644 @Override
9645 protected Set<String> getBadColumnNames() {
9646 return _badColumnNames;
9647 }
9648
9649
9652 public void afterPropertiesSet() {
9653 roleToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Roles",
9654 "roleId", "groupId", this, groupPersistence);
9655
9656 roleToUserTableMapper = TableMapperFactory.getTableMapper("Users_Roles",
9657 "roleId", "userId", this, userPersistence);
9658 }
9659
9660 public void destroy() {
9661 EntityCacheUtil.removeCache(RoleImpl.class.getName());
9662 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
9663 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9664 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9665
9666 TableMapperFactory.removeTableMapper("Groups_Roles");
9667 TableMapperFactory.removeTableMapper("Users_Roles");
9668 }
9669
9670 @BeanReference(type = GroupPersistence.class)
9671 protected GroupPersistence groupPersistence;
9672 protected TableMapper<Role, com.liferay.portal.model.Group> roleToGroupTableMapper;
9673 @BeanReference(type = UserPersistence.class)
9674 protected UserPersistence userPersistence;
9675 protected TableMapper<Role, com.liferay.portal.model.User> roleToUserTableMapper;
9676 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
9677 private static final String _SQL_SELECT_ROLE_WHERE_PKS_IN = "SELECT role FROM Role role WHERE roleId IN (";
9678 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
9679 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
9680 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
9681 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
9682 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
9683 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
9684 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
9685 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
9686 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
9687 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
9688 private static final String _FILTER_ENTITY_ALIAS = "role";
9689 private static final String _FILTER_ENTITY_TABLE = "Role_";
9690 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
9691 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
9692 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
9693 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
9694 private static final Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
9695 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9696 "uuid", "type"
9697 });
9698 private static final Role _nullRole = new RoleImpl() {
9699 @Override
9700 public Object clone() {
9701 return this;
9702 }
9703
9704 @Override
9705 public CacheModel<Role> toCacheModel() {
9706 return _nullRoleCacheModel;
9707 }
9708 };
9709
9710 private static final CacheModel<Role> _nullRoleCacheModel = new NullCacheModel();
9711
9712 private static class NullCacheModel implements CacheModel<Role>, MVCCModel {
9713 @Override
9714 public long getMvccVersion() {
9715 return -1;
9716 }
9717
9718 @Override
9719 public void setMvccVersion(long mvccVersion) {
9720 }
9721
9722 @Override
9723 public Role toEntityModel() {
9724 return _nullRole;
9725 }
9726 }
9727 }