001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.dao.orm.EntityCache;
021 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderCache;
023 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024 import com.liferay.portal.kernel.dao.orm.FinderPath;
025 import com.liferay.portal.kernel.dao.orm.Query;
026 import com.liferay.portal.kernel.dao.orm.QueryPos;
027 import com.liferay.portal.kernel.dao.orm.QueryUtil;
028 import com.liferay.portal.kernel.dao.orm.SQLQuery;
029 import com.liferay.portal.kernel.dao.orm.Session;
030 import com.liferay.portal.kernel.exception.NoSuchRoleException;
031 import com.liferay.portal.kernel.log.Log;
032 import com.liferay.portal.kernel.log.LogFactoryUtil;
033 import com.liferay.portal.kernel.model.CacheModel;
034 import com.liferay.portal.kernel.model.MVCCModel;
035 import com.liferay.portal.kernel.model.Role;
036 import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
037 import com.liferay.portal.kernel.service.ServiceContext;
038 import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
039 import com.liferay.portal.kernel.service.persistence.CompanyProvider;
040 import com.liferay.portal.kernel.service.persistence.CompanyProviderWrapper;
041 import com.liferay.portal.kernel.service.persistence.GroupPersistence;
042 import com.liferay.portal.kernel.service.persistence.RolePersistence;
043 import com.liferay.portal.kernel.service.persistence.UserPersistence;
044 import com.liferay.portal.kernel.service.persistence.impl.BasePersistenceImpl;
045 import com.liferay.portal.kernel.service.persistence.impl.TableMapper;
046 import com.liferay.portal.kernel.service.persistence.impl.TableMapperFactory;
047 import com.liferay.portal.kernel.util.ArrayUtil;
048 import com.liferay.portal.kernel.util.OrderByComparator;
049 import com.liferay.portal.kernel.util.SetUtil;
050 import com.liferay.portal.kernel.util.StringBundler;
051 import com.liferay.portal.kernel.util.StringPool;
052 import com.liferay.portal.kernel.util.StringUtil;
053 import com.liferay.portal.kernel.util.Validator;
054 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
055 import com.liferay.portal.model.impl.RoleImpl;
056 import com.liferay.portal.model.impl.RoleModelImpl;
057
058 import java.io.Serializable;
059
060 import java.util.Arrays;
061 import java.util.Collections;
062 import java.util.Date;
063 import java.util.HashMap;
064 import java.util.HashSet;
065 import java.util.Iterator;
066 import java.util.List;
067 import java.util.Map;
068 import java.util.Objects;
069 import java.util.Set;
070
071
083 @ProviderType
084 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
085 implements RolePersistence {
086
091 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
092 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
093 ".List1";
094 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
095 ".List2";
096 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
097 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
098 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
099 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
100 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
102 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
103 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
104 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
105 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
106 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
107 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
108 new String[] {
109 String.class.getName(),
110
111 Integer.class.getName(), Integer.class.getName(),
112 OrderByComparator.class.getName()
113 });
114 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
115 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
116 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
117 new String[] { String.class.getName() },
118 RoleModelImpl.UUID_COLUMN_BITMASK |
119 RoleModelImpl.NAME_COLUMN_BITMASK);
120 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
121 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
122 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
123 new String[] { String.class.getName() });
124
125
131 @Override
132 public List<Role> findByUuid(String uuid) {
133 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
134 }
135
136
148 @Override
149 public List<Role> findByUuid(String uuid, int start, int end) {
150 return findByUuid(uuid, start, end, null);
151 }
152
153
166 @Override
167 public List<Role> findByUuid(String uuid, int start, int end,
168 OrderByComparator<Role> orderByComparator) {
169 return findByUuid(uuid, start, end, orderByComparator, true);
170 }
171
172
186 @Override
187 public List<Role> findByUuid(String uuid, int start, int end,
188 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
189 boolean pagination = true;
190 FinderPath finderPath = null;
191 Object[] finderArgs = null;
192
193 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
194 (orderByComparator == null)) {
195 pagination = false;
196 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
197 finderArgs = new Object[] { uuid };
198 }
199 else {
200 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
201 finderArgs = new Object[] { uuid, start, end, orderByComparator };
202 }
203
204 List<Role> list = null;
205
206 if (retrieveFromCache) {
207 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
208 this);
209
210 if ((list != null) && !list.isEmpty()) {
211 for (Role role : list) {
212 if (!Objects.equals(uuid, role.getUuid())) {
213 list = null;
214
215 break;
216 }
217 }
218 }
219 }
220
221 if (list == null) {
222 StringBundler query = null;
223
224 if (orderByComparator != null) {
225 query = new StringBundler(3 +
226 (orderByComparator.getOrderByFields().length * 2));
227 }
228 else {
229 query = new StringBundler(3);
230 }
231
232 query.append(_SQL_SELECT_ROLE_WHERE);
233
234 boolean bindUuid = false;
235
236 if (uuid == null) {
237 query.append(_FINDER_COLUMN_UUID_UUID_1);
238 }
239 else if (uuid.equals(StringPool.BLANK)) {
240 query.append(_FINDER_COLUMN_UUID_UUID_3);
241 }
242 else {
243 bindUuid = true;
244
245 query.append(_FINDER_COLUMN_UUID_UUID_2);
246 }
247
248 if (orderByComparator != null) {
249 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
250 orderByComparator);
251 }
252 else
253 if (pagination) {
254 query.append(RoleModelImpl.ORDER_BY_JPQL);
255 }
256
257 String sql = query.toString();
258
259 Session session = null;
260
261 try {
262 session = openSession();
263
264 Query q = session.createQuery(sql);
265
266 QueryPos qPos = QueryPos.getInstance(q);
267
268 if (bindUuid) {
269 qPos.add(uuid);
270 }
271
272 if (!pagination) {
273 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
274 end, false);
275
276 Collections.sort(list);
277
278 list = Collections.unmodifiableList(list);
279 }
280 else {
281 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
282 end);
283 }
284
285 cacheResult(list);
286
287 finderCache.putResult(finderPath, finderArgs, list);
288 }
289 catch (Exception e) {
290 finderCache.removeResult(finderPath, finderArgs);
291
292 throw processException(e);
293 }
294 finally {
295 closeSession(session);
296 }
297 }
298
299 return list;
300 }
301
302
310 @Override
311 public Role findByUuid_First(String uuid,
312 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
313 Role role = fetchByUuid_First(uuid, orderByComparator);
314
315 if (role != null) {
316 return role;
317 }
318
319 StringBundler msg = new StringBundler(4);
320
321 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
322
323 msg.append("uuid=");
324 msg.append(uuid);
325
326 msg.append(StringPool.CLOSE_CURLY_BRACE);
327
328 throw new NoSuchRoleException(msg.toString());
329 }
330
331
338 @Override
339 public Role fetchByUuid_First(String uuid,
340 OrderByComparator<Role> orderByComparator) {
341 List<Role> list = findByUuid(uuid, 0, 1, orderByComparator);
342
343 if (!list.isEmpty()) {
344 return list.get(0);
345 }
346
347 return null;
348 }
349
350
358 @Override
359 public Role findByUuid_Last(String uuid,
360 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
361 Role role = fetchByUuid_Last(uuid, orderByComparator);
362
363 if (role != null) {
364 return role;
365 }
366
367 StringBundler msg = new StringBundler(4);
368
369 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
370
371 msg.append("uuid=");
372 msg.append(uuid);
373
374 msg.append(StringPool.CLOSE_CURLY_BRACE);
375
376 throw new NoSuchRoleException(msg.toString());
377 }
378
379
386 @Override
387 public Role fetchByUuid_Last(String uuid,
388 OrderByComparator<Role> orderByComparator) {
389 int count = countByUuid(uuid);
390
391 if (count == 0) {
392 return null;
393 }
394
395 List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator);
396
397 if (!list.isEmpty()) {
398 return list.get(0);
399 }
400
401 return null;
402 }
403
404
413 @Override
414 public Role[] findByUuid_PrevAndNext(long roleId, String uuid,
415 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
416 Role role = findByPrimaryKey(roleId);
417
418 Session session = null;
419
420 try {
421 session = openSession();
422
423 Role[] array = new RoleImpl[3];
424
425 array[0] = getByUuid_PrevAndNext(session, role, uuid,
426 orderByComparator, true);
427
428 array[1] = role;
429
430 array[2] = getByUuid_PrevAndNext(session, role, uuid,
431 orderByComparator, false);
432
433 return array;
434 }
435 catch (Exception e) {
436 throw processException(e);
437 }
438 finally {
439 closeSession(session);
440 }
441 }
442
443 protected Role getByUuid_PrevAndNext(Session session, Role role,
444 String uuid, OrderByComparator<Role> orderByComparator, boolean previous) {
445 StringBundler query = null;
446
447 if (orderByComparator != null) {
448 query = new StringBundler(4 +
449 (orderByComparator.getOrderByConditionFields().length * 3) +
450 (orderByComparator.getOrderByFields().length * 3));
451 }
452 else {
453 query = new StringBundler(3);
454 }
455
456 query.append(_SQL_SELECT_ROLE_WHERE);
457
458 boolean bindUuid = false;
459
460 if (uuid == null) {
461 query.append(_FINDER_COLUMN_UUID_UUID_1);
462 }
463 else if (uuid.equals(StringPool.BLANK)) {
464 query.append(_FINDER_COLUMN_UUID_UUID_3);
465 }
466 else {
467 bindUuid = true;
468
469 query.append(_FINDER_COLUMN_UUID_UUID_2);
470 }
471
472 if (orderByComparator != null) {
473 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
474
475 if (orderByConditionFields.length > 0) {
476 query.append(WHERE_AND);
477 }
478
479 for (int i = 0; i < orderByConditionFields.length; i++) {
480 query.append(_ORDER_BY_ENTITY_ALIAS);
481 query.append(orderByConditionFields[i]);
482
483 if ((i + 1) < orderByConditionFields.length) {
484 if (orderByComparator.isAscending() ^ previous) {
485 query.append(WHERE_GREATER_THAN_HAS_NEXT);
486 }
487 else {
488 query.append(WHERE_LESSER_THAN_HAS_NEXT);
489 }
490 }
491 else {
492 if (orderByComparator.isAscending() ^ previous) {
493 query.append(WHERE_GREATER_THAN);
494 }
495 else {
496 query.append(WHERE_LESSER_THAN);
497 }
498 }
499 }
500
501 query.append(ORDER_BY_CLAUSE);
502
503 String[] orderByFields = orderByComparator.getOrderByFields();
504
505 for (int i = 0; i < orderByFields.length; i++) {
506 query.append(_ORDER_BY_ENTITY_ALIAS);
507 query.append(orderByFields[i]);
508
509 if ((i + 1) < orderByFields.length) {
510 if (orderByComparator.isAscending() ^ previous) {
511 query.append(ORDER_BY_ASC_HAS_NEXT);
512 }
513 else {
514 query.append(ORDER_BY_DESC_HAS_NEXT);
515 }
516 }
517 else {
518 if (orderByComparator.isAscending() ^ previous) {
519 query.append(ORDER_BY_ASC);
520 }
521 else {
522 query.append(ORDER_BY_DESC);
523 }
524 }
525 }
526 }
527 else {
528 query.append(RoleModelImpl.ORDER_BY_JPQL);
529 }
530
531 String sql = query.toString();
532
533 Query q = session.createQuery(sql);
534
535 q.setFirstResult(0);
536 q.setMaxResults(2);
537
538 QueryPos qPos = QueryPos.getInstance(q);
539
540 if (bindUuid) {
541 qPos.add(uuid);
542 }
543
544 if (orderByComparator != null) {
545 Object[] values = orderByComparator.getOrderByConditionValues(role);
546
547 for (Object value : values) {
548 qPos.add(value);
549 }
550 }
551
552 List<Role> list = q.list();
553
554 if (list.size() == 2) {
555 return list.get(1);
556 }
557 else {
558 return null;
559 }
560 }
561
562
568 @Override
569 public List<Role> filterFindByUuid(String uuid) {
570 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
571 }
572
573
585 @Override
586 public List<Role> filterFindByUuid(String uuid, int start, int end) {
587 return filterFindByUuid(uuid, start, end, null);
588 }
589
590
603 @Override
604 public List<Role> filterFindByUuid(String uuid, int start, int end,
605 OrderByComparator<Role> orderByComparator) {
606 if (!InlineSQLHelperUtil.isEnabled()) {
607 return findByUuid(uuid, start, end, orderByComparator);
608 }
609
610 StringBundler query = null;
611
612 if (orderByComparator != null) {
613 query = new StringBundler(3 +
614 (orderByComparator.getOrderByFields().length * 2));
615 }
616 else {
617 query = new StringBundler(4);
618 }
619
620 if (getDB().isSupportsInlineDistinct()) {
621 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
622 }
623 else {
624 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
625 }
626
627 boolean bindUuid = false;
628
629 if (uuid == null) {
630 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
631 }
632 else if (uuid.equals(StringPool.BLANK)) {
633 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
634 }
635 else {
636 bindUuid = true;
637
638 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
639 }
640
641 if (!getDB().isSupportsInlineDistinct()) {
642 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
643 }
644
645 if (orderByComparator != null) {
646 if (getDB().isSupportsInlineDistinct()) {
647 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
648 orderByComparator, true);
649 }
650 else {
651 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
652 orderByComparator, true);
653 }
654 }
655 else {
656 if (getDB().isSupportsInlineDistinct()) {
657 query.append(RoleModelImpl.ORDER_BY_JPQL);
658 }
659 else {
660 query.append(RoleModelImpl.ORDER_BY_SQL);
661 }
662 }
663
664 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
665 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
666
667 Session session = null;
668
669 try {
670 session = openSession();
671
672 SQLQuery q = session.createSynchronizedSQLQuery(sql);
673
674 if (getDB().isSupportsInlineDistinct()) {
675 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
676 }
677 else {
678 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
679 }
680
681 QueryPos qPos = QueryPos.getInstance(q);
682
683 if (bindUuid) {
684 qPos.add(uuid);
685 }
686
687 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
688 }
689 catch (Exception e) {
690 throw processException(e);
691 }
692 finally {
693 closeSession(session);
694 }
695 }
696
697
706 @Override
707 public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid,
708 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
709 if (!InlineSQLHelperUtil.isEnabled()) {
710 return findByUuid_PrevAndNext(roleId, uuid, orderByComparator);
711 }
712
713 Role role = findByPrimaryKey(roleId);
714
715 Session session = null;
716
717 try {
718 session = openSession();
719
720 Role[] array = new RoleImpl[3];
721
722 array[0] = filterGetByUuid_PrevAndNext(session, role, uuid,
723 orderByComparator, true);
724
725 array[1] = role;
726
727 array[2] = filterGetByUuid_PrevAndNext(session, role, uuid,
728 orderByComparator, false);
729
730 return array;
731 }
732 catch (Exception e) {
733 throw processException(e);
734 }
735 finally {
736 closeSession(session);
737 }
738 }
739
740 protected Role filterGetByUuid_PrevAndNext(Session session, Role role,
741 String uuid, OrderByComparator<Role> orderByComparator, boolean previous) {
742 StringBundler query = null;
743
744 if (orderByComparator != null) {
745 query = new StringBundler(5 +
746 (orderByComparator.getOrderByConditionFields().length * 3) +
747 (orderByComparator.getOrderByFields().length * 3));
748 }
749 else {
750 query = new StringBundler(4);
751 }
752
753 if (getDB().isSupportsInlineDistinct()) {
754 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
755 }
756 else {
757 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
758 }
759
760 boolean bindUuid = false;
761
762 if (uuid == null) {
763 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
764 }
765 else if (uuid.equals(StringPool.BLANK)) {
766 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
767 }
768 else {
769 bindUuid = true;
770
771 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
772 }
773
774 if (!getDB().isSupportsInlineDistinct()) {
775 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
776 }
777
778 if (orderByComparator != null) {
779 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
780
781 if (orderByConditionFields.length > 0) {
782 query.append(WHERE_AND);
783 }
784
785 for (int i = 0; i < orderByConditionFields.length; i++) {
786 if (getDB().isSupportsInlineDistinct()) {
787 query.append(_ORDER_BY_ENTITY_ALIAS);
788 }
789 else {
790 query.append(_ORDER_BY_ENTITY_TABLE);
791 }
792
793 query.append(orderByConditionFields[i]);
794
795 if ((i + 1) < orderByConditionFields.length) {
796 if (orderByComparator.isAscending() ^ previous) {
797 query.append(WHERE_GREATER_THAN_HAS_NEXT);
798 }
799 else {
800 query.append(WHERE_LESSER_THAN_HAS_NEXT);
801 }
802 }
803 else {
804 if (orderByComparator.isAscending() ^ previous) {
805 query.append(WHERE_GREATER_THAN);
806 }
807 else {
808 query.append(WHERE_LESSER_THAN);
809 }
810 }
811 }
812
813 query.append(ORDER_BY_CLAUSE);
814
815 String[] orderByFields = orderByComparator.getOrderByFields();
816
817 for (int i = 0; i < orderByFields.length; i++) {
818 if (getDB().isSupportsInlineDistinct()) {
819 query.append(_ORDER_BY_ENTITY_ALIAS);
820 }
821 else {
822 query.append(_ORDER_BY_ENTITY_TABLE);
823 }
824
825 query.append(orderByFields[i]);
826
827 if ((i + 1) < orderByFields.length) {
828 if (orderByComparator.isAscending() ^ previous) {
829 query.append(ORDER_BY_ASC_HAS_NEXT);
830 }
831 else {
832 query.append(ORDER_BY_DESC_HAS_NEXT);
833 }
834 }
835 else {
836 if (orderByComparator.isAscending() ^ previous) {
837 query.append(ORDER_BY_ASC);
838 }
839 else {
840 query.append(ORDER_BY_DESC);
841 }
842 }
843 }
844 }
845 else {
846 if (getDB().isSupportsInlineDistinct()) {
847 query.append(RoleModelImpl.ORDER_BY_JPQL);
848 }
849 else {
850 query.append(RoleModelImpl.ORDER_BY_SQL);
851 }
852 }
853
854 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
855 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
856
857 SQLQuery q = session.createSynchronizedSQLQuery(sql);
858
859 q.setFirstResult(0);
860 q.setMaxResults(2);
861
862 if (getDB().isSupportsInlineDistinct()) {
863 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
864 }
865 else {
866 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
867 }
868
869 QueryPos qPos = QueryPos.getInstance(q);
870
871 if (bindUuid) {
872 qPos.add(uuid);
873 }
874
875 if (orderByComparator != null) {
876 Object[] values = orderByComparator.getOrderByConditionValues(role);
877
878 for (Object value : values) {
879 qPos.add(value);
880 }
881 }
882
883 List<Role> list = q.list();
884
885 if (list.size() == 2) {
886 return list.get(1);
887 }
888 else {
889 return null;
890 }
891 }
892
893
898 @Override
899 public void removeByUuid(String uuid) {
900 for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
901 null)) {
902 remove(role);
903 }
904 }
905
906
912 @Override
913 public int countByUuid(String uuid) {
914 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
915
916 Object[] finderArgs = new Object[] { uuid };
917
918 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
919
920 if (count == null) {
921 StringBundler query = new StringBundler(2);
922
923 query.append(_SQL_COUNT_ROLE_WHERE);
924
925 boolean bindUuid = false;
926
927 if (uuid == null) {
928 query.append(_FINDER_COLUMN_UUID_UUID_1);
929 }
930 else if (uuid.equals(StringPool.BLANK)) {
931 query.append(_FINDER_COLUMN_UUID_UUID_3);
932 }
933 else {
934 bindUuid = true;
935
936 query.append(_FINDER_COLUMN_UUID_UUID_2);
937 }
938
939 String sql = query.toString();
940
941 Session session = null;
942
943 try {
944 session = openSession();
945
946 Query q = session.createQuery(sql);
947
948 QueryPos qPos = QueryPos.getInstance(q);
949
950 if (bindUuid) {
951 qPos.add(uuid);
952 }
953
954 count = (Long)q.uniqueResult();
955
956 finderCache.putResult(finderPath, finderArgs, count);
957 }
958 catch (Exception e) {
959 finderCache.removeResult(finderPath, finderArgs);
960
961 throw processException(e);
962 }
963 finally {
964 closeSession(session);
965 }
966 }
967
968 return count.intValue();
969 }
970
971
977 @Override
978 public int filterCountByUuid(String uuid) {
979 if (!InlineSQLHelperUtil.isEnabled()) {
980 return countByUuid(uuid);
981 }
982
983 StringBundler query = new StringBundler(2);
984
985 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
986
987 boolean bindUuid = false;
988
989 if (uuid == null) {
990 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
991 }
992 else if (uuid.equals(StringPool.BLANK)) {
993 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
994 }
995 else {
996 bindUuid = true;
997
998 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
999 }
1000
1001 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1002 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1003
1004 Session session = null;
1005
1006 try {
1007 session = openSession();
1008
1009 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1010
1011 q.addScalar(COUNT_COLUMN_NAME,
1012 com.liferay.portal.kernel.dao.orm.Type.LONG);
1013
1014 QueryPos qPos = QueryPos.getInstance(q);
1015
1016 if (bindUuid) {
1017 qPos.add(uuid);
1018 }
1019
1020 Long count = (Long)q.uniqueResult();
1021
1022 return count.intValue();
1023 }
1024 catch (Exception e) {
1025 throw processException(e);
1026 }
1027 finally {
1028 closeSession(session);
1029 }
1030 }
1031
1032 private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL";
1033 private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?";
1034 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')";
1035 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL";
1036 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?";
1037 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')";
1038 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1039 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1040 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1041 new String[] {
1042 String.class.getName(), Long.class.getName(),
1043
1044 Integer.class.getName(), Integer.class.getName(),
1045 OrderByComparator.class.getName()
1046 });
1047 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1048 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1049 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1050 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1051 new String[] { String.class.getName(), Long.class.getName() },
1052 RoleModelImpl.UUID_COLUMN_BITMASK |
1053 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1054 RoleModelImpl.NAME_COLUMN_BITMASK);
1055 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1056 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1057 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1058 new String[] { String.class.getName(), Long.class.getName() });
1059
1060
1067 @Override
1068 public List<Role> findByUuid_C(String uuid, long companyId) {
1069 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1070 QueryUtil.ALL_POS, null);
1071 }
1072
1073
1086 @Override
1087 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1088 int end) {
1089 return findByUuid_C(uuid, companyId, start, end, null);
1090 }
1091
1092
1106 @Override
1107 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1108 int end, OrderByComparator<Role> orderByComparator) {
1109 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
1110 }
1111
1112
1127 @Override
1128 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1129 int end, OrderByComparator<Role> orderByComparator,
1130 boolean retrieveFromCache) {
1131 boolean pagination = true;
1132 FinderPath finderPath = null;
1133 Object[] finderArgs = null;
1134
1135 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1136 (orderByComparator == null)) {
1137 pagination = false;
1138 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1139 finderArgs = new Object[] { uuid, companyId };
1140 }
1141 else {
1142 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1143 finderArgs = new Object[] {
1144 uuid, companyId,
1145
1146 start, end, orderByComparator
1147 };
1148 }
1149
1150 List<Role> list = null;
1151
1152 if (retrieveFromCache) {
1153 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
1154 this);
1155
1156 if ((list != null) && !list.isEmpty()) {
1157 for (Role role : list) {
1158 if (!Objects.equals(uuid, role.getUuid()) ||
1159 (companyId != role.getCompanyId())) {
1160 list = null;
1161
1162 break;
1163 }
1164 }
1165 }
1166 }
1167
1168 if (list == null) {
1169 StringBundler query = null;
1170
1171 if (orderByComparator != null) {
1172 query = new StringBundler(4 +
1173 (orderByComparator.getOrderByFields().length * 2));
1174 }
1175 else {
1176 query = new StringBundler(4);
1177 }
1178
1179 query.append(_SQL_SELECT_ROLE_WHERE);
1180
1181 boolean bindUuid = false;
1182
1183 if (uuid == null) {
1184 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1185 }
1186 else if (uuid.equals(StringPool.BLANK)) {
1187 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1188 }
1189 else {
1190 bindUuid = true;
1191
1192 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1193 }
1194
1195 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1196
1197 if (orderByComparator != null) {
1198 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1199 orderByComparator);
1200 }
1201 else
1202 if (pagination) {
1203 query.append(RoleModelImpl.ORDER_BY_JPQL);
1204 }
1205
1206 String sql = query.toString();
1207
1208 Session session = null;
1209
1210 try {
1211 session = openSession();
1212
1213 Query q = session.createQuery(sql);
1214
1215 QueryPos qPos = QueryPos.getInstance(q);
1216
1217 if (bindUuid) {
1218 qPos.add(uuid);
1219 }
1220
1221 qPos.add(companyId);
1222
1223 if (!pagination) {
1224 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1225 end, false);
1226
1227 Collections.sort(list);
1228
1229 list = Collections.unmodifiableList(list);
1230 }
1231 else {
1232 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1233 end);
1234 }
1235
1236 cacheResult(list);
1237
1238 finderCache.putResult(finderPath, finderArgs, list);
1239 }
1240 catch (Exception e) {
1241 finderCache.removeResult(finderPath, finderArgs);
1242
1243 throw processException(e);
1244 }
1245 finally {
1246 closeSession(session);
1247 }
1248 }
1249
1250 return list;
1251 }
1252
1253
1262 @Override
1263 public Role findByUuid_C_First(String uuid, long companyId,
1264 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
1265 Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1266
1267 if (role != null) {
1268 return role;
1269 }
1270
1271 StringBundler msg = new StringBundler(6);
1272
1273 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1274
1275 msg.append("uuid=");
1276 msg.append(uuid);
1277
1278 msg.append(", companyId=");
1279 msg.append(companyId);
1280
1281 msg.append(StringPool.CLOSE_CURLY_BRACE);
1282
1283 throw new NoSuchRoleException(msg.toString());
1284 }
1285
1286
1294 @Override
1295 public Role fetchByUuid_C_First(String uuid, long companyId,
1296 OrderByComparator<Role> orderByComparator) {
1297 List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1298
1299 if (!list.isEmpty()) {
1300 return list.get(0);
1301 }
1302
1303 return null;
1304 }
1305
1306
1315 @Override
1316 public Role findByUuid_C_Last(String uuid, long companyId,
1317 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
1318 Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1319
1320 if (role != null) {
1321 return role;
1322 }
1323
1324 StringBundler msg = new StringBundler(6);
1325
1326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1327
1328 msg.append("uuid=");
1329 msg.append(uuid);
1330
1331 msg.append(", companyId=");
1332 msg.append(companyId);
1333
1334 msg.append(StringPool.CLOSE_CURLY_BRACE);
1335
1336 throw new NoSuchRoleException(msg.toString());
1337 }
1338
1339
1347 @Override
1348 public Role fetchByUuid_C_Last(String uuid, long companyId,
1349 OrderByComparator<Role> orderByComparator) {
1350 int count = countByUuid_C(uuid, companyId);
1351
1352 if (count == 0) {
1353 return null;
1354 }
1355
1356 List<Role> list = findByUuid_C(uuid, companyId, count - 1, count,
1357 orderByComparator);
1358
1359 if (!list.isEmpty()) {
1360 return list.get(0);
1361 }
1362
1363 return null;
1364 }
1365
1366
1376 @Override
1377 public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid,
1378 long companyId, OrderByComparator<Role> orderByComparator)
1379 throws NoSuchRoleException {
1380 Role role = findByPrimaryKey(roleId);
1381
1382 Session session = null;
1383
1384 try {
1385 session = openSession();
1386
1387 Role[] array = new RoleImpl[3];
1388
1389 array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1390 orderByComparator, true);
1391
1392 array[1] = role;
1393
1394 array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1395 orderByComparator, false);
1396
1397 return array;
1398 }
1399 catch (Exception e) {
1400 throw processException(e);
1401 }
1402 finally {
1403 closeSession(session);
1404 }
1405 }
1406
1407 protected Role getByUuid_C_PrevAndNext(Session session, Role role,
1408 String uuid, long companyId, OrderByComparator<Role> orderByComparator,
1409 boolean previous) {
1410 StringBundler query = null;
1411
1412 if (orderByComparator != null) {
1413 query = new StringBundler(5 +
1414 (orderByComparator.getOrderByConditionFields().length * 3) +
1415 (orderByComparator.getOrderByFields().length * 3));
1416 }
1417 else {
1418 query = new StringBundler(4);
1419 }
1420
1421 query.append(_SQL_SELECT_ROLE_WHERE);
1422
1423 boolean bindUuid = false;
1424
1425 if (uuid == null) {
1426 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1427 }
1428 else if (uuid.equals(StringPool.BLANK)) {
1429 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1430 }
1431 else {
1432 bindUuid = true;
1433
1434 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1435 }
1436
1437 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1438
1439 if (orderByComparator != null) {
1440 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1441
1442 if (orderByConditionFields.length > 0) {
1443 query.append(WHERE_AND);
1444 }
1445
1446 for (int i = 0; i < orderByConditionFields.length; i++) {
1447 query.append(_ORDER_BY_ENTITY_ALIAS);
1448 query.append(orderByConditionFields[i]);
1449
1450 if ((i + 1) < orderByConditionFields.length) {
1451 if (orderByComparator.isAscending() ^ previous) {
1452 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1453 }
1454 else {
1455 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1456 }
1457 }
1458 else {
1459 if (orderByComparator.isAscending() ^ previous) {
1460 query.append(WHERE_GREATER_THAN);
1461 }
1462 else {
1463 query.append(WHERE_LESSER_THAN);
1464 }
1465 }
1466 }
1467
1468 query.append(ORDER_BY_CLAUSE);
1469
1470 String[] orderByFields = orderByComparator.getOrderByFields();
1471
1472 for (int i = 0; i < orderByFields.length; i++) {
1473 query.append(_ORDER_BY_ENTITY_ALIAS);
1474 query.append(orderByFields[i]);
1475
1476 if ((i + 1) < orderByFields.length) {
1477 if (orderByComparator.isAscending() ^ previous) {
1478 query.append(ORDER_BY_ASC_HAS_NEXT);
1479 }
1480 else {
1481 query.append(ORDER_BY_DESC_HAS_NEXT);
1482 }
1483 }
1484 else {
1485 if (orderByComparator.isAscending() ^ previous) {
1486 query.append(ORDER_BY_ASC);
1487 }
1488 else {
1489 query.append(ORDER_BY_DESC);
1490 }
1491 }
1492 }
1493 }
1494 else {
1495 query.append(RoleModelImpl.ORDER_BY_JPQL);
1496 }
1497
1498 String sql = query.toString();
1499
1500 Query q = session.createQuery(sql);
1501
1502 q.setFirstResult(0);
1503 q.setMaxResults(2);
1504
1505 QueryPos qPos = QueryPos.getInstance(q);
1506
1507 if (bindUuid) {
1508 qPos.add(uuid);
1509 }
1510
1511 qPos.add(companyId);
1512
1513 if (orderByComparator != null) {
1514 Object[] values = orderByComparator.getOrderByConditionValues(role);
1515
1516 for (Object value : values) {
1517 qPos.add(value);
1518 }
1519 }
1520
1521 List<Role> list = q.list();
1522
1523 if (list.size() == 2) {
1524 return list.get(1);
1525 }
1526 else {
1527 return null;
1528 }
1529 }
1530
1531
1538 @Override
1539 public List<Role> filterFindByUuid_C(String uuid, long companyId) {
1540 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1541 QueryUtil.ALL_POS, null);
1542 }
1543
1544
1557 @Override
1558 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1559 int start, int end) {
1560 return filterFindByUuid_C(uuid, companyId, start, end, null);
1561 }
1562
1563
1577 @Override
1578 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1579 int start, int end, OrderByComparator<Role> orderByComparator) {
1580 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
1581 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1582 }
1583
1584 StringBundler query = null;
1585
1586 if (orderByComparator != null) {
1587 query = new StringBundler(4 +
1588 (orderByComparator.getOrderByFields().length * 2));
1589 }
1590 else {
1591 query = new StringBundler(5);
1592 }
1593
1594 if (getDB().isSupportsInlineDistinct()) {
1595 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1596 }
1597 else {
1598 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1599 }
1600
1601 boolean bindUuid = false;
1602
1603 if (uuid == null) {
1604 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1605 }
1606 else if (uuid.equals(StringPool.BLANK)) {
1607 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1608 }
1609 else {
1610 bindUuid = true;
1611
1612 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1613 }
1614
1615 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1616
1617 if (!getDB().isSupportsInlineDistinct()) {
1618 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1619 }
1620
1621 if (orderByComparator != null) {
1622 if (getDB().isSupportsInlineDistinct()) {
1623 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1624 orderByComparator, true);
1625 }
1626 else {
1627 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1628 orderByComparator, true);
1629 }
1630 }
1631 else {
1632 if (getDB().isSupportsInlineDistinct()) {
1633 query.append(RoleModelImpl.ORDER_BY_JPQL);
1634 }
1635 else {
1636 query.append(RoleModelImpl.ORDER_BY_SQL);
1637 }
1638 }
1639
1640 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1641 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1642
1643 Session session = null;
1644
1645 try {
1646 session = openSession();
1647
1648 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1649
1650 if (getDB().isSupportsInlineDistinct()) {
1651 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1652 }
1653 else {
1654 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1655 }
1656
1657 QueryPos qPos = QueryPos.getInstance(q);
1658
1659 if (bindUuid) {
1660 qPos.add(uuid);
1661 }
1662
1663 qPos.add(companyId);
1664
1665 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1666 }
1667 catch (Exception e) {
1668 throw processException(e);
1669 }
1670 finally {
1671 closeSession(session);
1672 }
1673 }
1674
1675
1685 @Override
1686 public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid,
1687 long companyId, OrderByComparator<Role> orderByComparator)
1688 throws NoSuchRoleException {
1689 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
1690 return findByUuid_C_PrevAndNext(roleId, uuid, companyId,
1691 orderByComparator);
1692 }
1693
1694 Role role = findByPrimaryKey(roleId);
1695
1696 Session session = null;
1697
1698 try {
1699 session = openSession();
1700
1701 Role[] array = new RoleImpl[3];
1702
1703 array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1704 companyId, orderByComparator, true);
1705
1706 array[1] = role;
1707
1708 array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1709 companyId, orderByComparator, false);
1710
1711 return array;
1712 }
1713 catch (Exception e) {
1714 throw processException(e);
1715 }
1716 finally {
1717 closeSession(session);
1718 }
1719 }
1720
1721 protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role,
1722 String uuid, long companyId, OrderByComparator<Role> orderByComparator,
1723 boolean previous) {
1724 StringBundler query = null;
1725
1726 if (orderByComparator != null) {
1727 query = new StringBundler(6 +
1728 (orderByComparator.getOrderByConditionFields().length * 3) +
1729 (orderByComparator.getOrderByFields().length * 3));
1730 }
1731 else {
1732 query = new StringBundler(5);
1733 }
1734
1735 if (getDB().isSupportsInlineDistinct()) {
1736 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1737 }
1738 else {
1739 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1740 }
1741
1742 boolean bindUuid = false;
1743
1744 if (uuid == null) {
1745 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1746 }
1747 else if (uuid.equals(StringPool.BLANK)) {
1748 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1749 }
1750 else {
1751 bindUuid = true;
1752
1753 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1754 }
1755
1756 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1757
1758 if (!getDB().isSupportsInlineDistinct()) {
1759 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1760 }
1761
1762 if (orderByComparator != null) {
1763 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1764
1765 if (orderByConditionFields.length > 0) {
1766 query.append(WHERE_AND);
1767 }
1768
1769 for (int i = 0; i < orderByConditionFields.length; i++) {
1770 if (getDB().isSupportsInlineDistinct()) {
1771 query.append(_ORDER_BY_ENTITY_ALIAS);
1772 }
1773 else {
1774 query.append(_ORDER_BY_ENTITY_TABLE);
1775 }
1776
1777 query.append(orderByConditionFields[i]);
1778
1779 if ((i + 1) < orderByConditionFields.length) {
1780 if (orderByComparator.isAscending() ^ previous) {
1781 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1782 }
1783 else {
1784 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1785 }
1786 }
1787 else {
1788 if (orderByComparator.isAscending() ^ previous) {
1789 query.append(WHERE_GREATER_THAN);
1790 }
1791 else {
1792 query.append(WHERE_LESSER_THAN);
1793 }
1794 }
1795 }
1796
1797 query.append(ORDER_BY_CLAUSE);
1798
1799 String[] orderByFields = orderByComparator.getOrderByFields();
1800
1801 for (int i = 0; i < orderByFields.length; i++) {
1802 if (getDB().isSupportsInlineDistinct()) {
1803 query.append(_ORDER_BY_ENTITY_ALIAS);
1804 }
1805 else {
1806 query.append(_ORDER_BY_ENTITY_TABLE);
1807 }
1808
1809 query.append(orderByFields[i]);
1810
1811 if ((i + 1) < orderByFields.length) {
1812 if (orderByComparator.isAscending() ^ previous) {
1813 query.append(ORDER_BY_ASC_HAS_NEXT);
1814 }
1815 else {
1816 query.append(ORDER_BY_DESC_HAS_NEXT);
1817 }
1818 }
1819 else {
1820 if (orderByComparator.isAscending() ^ previous) {
1821 query.append(ORDER_BY_ASC);
1822 }
1823 else {
1824 query.append(ORDER_BY_DESC);
1825 }
1826 }
1827 }
1828 }
1829 else {
1830 if (getDB().isSupportsInlineDistinct()) {
1831 query.append(RoleModelImpl.ORDER_BY_JPQL);
1832 }
1833 else {
1834 query.append(RoleModelImpl.ORDER_BY_SQL);
1835 }
1836 }
1837
1838 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1839 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1840
1841 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1842
1843 q.setFirstResult(0);
1844 q.setMaxResults(2);
1845
1846 if (getDB().isSupportsInlineDistinct()) {
1847 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1848 }
1849 else {
1850 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1851 }
1852
1853 QueryPos qPos = QueryPos.getInstance(q);
1854
1855 if (bindUuid) {
1856 qPos.add(uuid);
1857 }
1858
1859 qPos.add(companyId);
1860
1861 if (orderByComparator != null) {
1862 Object[] values = orderByComparator.getOrderByConditionValues(role);
1863
1864 for (Object value : values) {
1865 qPos.add(value);
1866 }
1867 }
1868
1869 List<Role> list = q.list();
1870
1871 if (list.size() == 2) {
1872 return list.get(1);
1873 }
1874 else {
1875 return null;
1876 }
1877 }
1878
1879
1885 @Override
1886 public void removeByUuid_C(String uuid, long companyId) {
1887 for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1888 QueryUtil.ALL_POS, null)) {
1889 remove(role);
1890 }
1891 }
1892
1893
1900 @Override
1901 public int countByUuid_C(String uuid, long companyId) {
1902 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1903
1904 Object[] finderArgs = new Object[] { uuid, companyId };
1905
1906 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1907
1908 if (count == null) {
1909 StringBundler query = new StringBundler(3);
1910
1911 query.append(_SQL_COUNT_ROLE_WHERE);
1912
1913 boolean bindUuid = false;
1914
1915 if (uuid == null) {
1916 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1917 }
1918 else if (uuid.equals(StringPool.BLANK)) {
1919 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1920 }
1921 else {
1922 bindUuid = true;
1923
1924 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1925 }
1926
1927 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1928
1929 String sql = query.toString();
1930
1931 Session session = null;
1932
1933 try {
1934 session = openSession();
1935
1936 Query q = session.createQuery(sql);
1937
1938 QueryPos qPos = QueryPos.getInstance(q);
1939
1940 if (bindUuid) {
1941 qPos.add(uuid);
1942 }
1943
1944 qPos.add(companyId);
1945
1946 count = (Long)q.uniqueResult();
1947
1948 finderCache.putResult(finderPath, finderArgs, count);
1949 }
1950 catch (Exception e) {
1951 finderCache.removeResult(finderPath, finderArgs);
1952
1953 throw processException(e);
1954 }
1955 finally {
1956 closeSession(session);
1957 }
1958 }
1959
1960 return count.intValue();
1961 }
1962
1963
1970 @Override
1971 public int filterCountByUuid_C(String uuid, long companyId) {
1972 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
1973 return countByUuid_C(uuid, companyId);
1974 }
1975
1976 StringBundler query = new StringBundler(3);
1977
1978 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1979
1980 boolean bindUuid = false;
1981
1982 if (uuid == null) {
1983 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1984 }
1985 else if (uuid.equals(StringPool.BLANK)) {
1986 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1987 }
1988 else {
1989 bindUuid = true;
1990
1991 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1992 }
1993
1994 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1995
1996 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1997 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1998
1999 Session session = null;
2000
2001 try {
2002 session = openSession();
2003
2004 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2005
2006 q.addScalar(COUNT_COLUMN_NAME,
2007 com.liferay.portal.kernel.dao.orm.Type.LONG);
2008
2009 QueryPos qPos = QueryPos.getInstance(q);
2010
2011 if (bindUuid) {
2012 qPos.add(uuid);
2013 }
2014
2015 qPos.add(companyId);
2016
2017 Long count = (Long)q.uniqueResult();
2018
2019 return count.intValue();
2020 }
2021 catch (Exception e) {
2022 throw processException(e);
2023 }
2024 finally {
2025 closeSession(session);
2026 }
2027 }
2028
2029 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND ";
2030 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND ";
2031 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND ";
2032 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND ";
2033 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND ";
2034 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND ";
2035 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?";
2036 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2037 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2038 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2039 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2040 new String[] {
2041 Long.class.getName(),
2042
2043 Integer.class.getName(), Integer.class.getName(),
2044 OrderByComparator.class.getName()
2045 });
2046 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2047 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2048 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2049 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2050 new String[] { Long.class.getName() },
2051 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
2052 RoleModelImpl.NAME_COLUMN_BITMASK);
2053 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2054 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2055 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2056 new String[] { Long.class.getName() });
2057
2058
2064 @Override
2065 public List<Role> findByCompanyId(long companyId) {
2066 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2067 null);
2068 }
2069
2070
2082 @Override
2083 public List<Role> findByCompanyId(long companyId, int start, int end) {
2084 return findByCompanyId(companyId, start, end, null);
2085 }
2086
2087
2100 @Override
2101 public List<Role> findByCompanyId(long companyId, int start, int end,
2102 OrderByComparator<Role> orderByComparator) {
2103 return findByCompanyId(companyId, start, end, orderByComparator, true);
2104 }
2105
2106
2120 @Override
2121 public List<Role> findByCompanyId(long companyId, int start, int end,
2122 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
2123 boolean pagination = true;
2124 FinderPath finderPath = null;
2125 Object[] finderArgs = null;
2126
2127 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2128 (orderByComparator == null)) {
2129 pagination = false;
2130 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2131 finderArgs = new Object[] { companyId };
2132 }
2133 else {
2134 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2135 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2136 }
2137
2138 List<Role> list = null;
2139
2140 if (retrieveFromCache) {
2141 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
2142 this);
2143
2144 if ((list != null) && !list.isEmpty()) {
2145 for (Role role : list) {
2146 if ((companyId != role.getCompanyId())) {
2147 list = null;
2148
2149 break;
2150 }
2151 }
2152 }
2153 }
2154
2155 if (list == null) {
2156 StringBundler query = null;
2157
2158 if (orderByComparator != null) {
2159 query = new StringBundler(3 +
2160 (orderByComparator.getOrderByFields().length * 2));
2161 }
2162 else {
2163 query = new StringBundler(3);
2164 }
2165
2166 query.append(_SQL_SELECT_ROLE_WHERE);
2167
2168 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2169
2170 if (orderByComparator != null) {
2171 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2172 orderByComparator);
2173 }
2174 else
2175 if (pagination) {
2176 query.append(RoleModelImpl.ORDER_BY_JPQL);
2177 }
2178
2179 String sql = query.toString();
2180
2181 Session session = null;
2182
2183 try {
2184 session = openSession();
2185
2186 Query q = session.createQuery(sql);
2187
2188 QueryPos qPos = QueryPos.getInstance(q);
2189
2190 qPos.add(companyId);
2191
2192 if (!pagination) {
2193 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2194 end, false);
2195
2196 Collections.sort(list);
2197
2198 list = Collections.unmodifiableList(list);
2199 }
2200 else {
2201 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2202 end);
2203 }
2204
2205 cacheResult(list);
2206
2207 finderCache.putResult(finderPath, finderArgs, list);
2208 }
2209 catch (Exception e) {
2210 finderCache.removeResult(finderPath, finderArgs);
2211
2212 throw processException(e);
2213 }
2214 finally {
2215 closeSession(session);
2216 }
2217 }
2218
2219 return list;
2220 }
2221
2222
2230 @Override
2231 public Role findByCompanyId_First(long companyId,
2232 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2233 Role role = fetchByCompanyId_First(companyId, orderByComparator);
2234
2235 if (role != null) {
2236 return role;
2237 }
2238
2239 StringBundler msg = new StringBundler(4);
2240
2241 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2242
2243 msg.append("companyId=");
2244 msg.append(companyId);
2245
2246 msg.append(StringPool.CLOSE_CURLY_BRACE);
2247
2248 throw new NoSuchRoleException(msg.toString());
2249 }
2250
2251
2258 @Override
2259 public Role fetchByCompanyId_First(long companyId,
2260 OrderByComparator<Role> orderByComparator) {
2261 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2262
2263 if (!list.isEmpty()) {
2264 return list.get(0);
2265 }
2266
2267 return null;
2268 }
2269
2270
2278 @Override
2279 public Role findByCompanyId_Last(long companyId,
2280 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2281 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
2282
2283 if (role != null) {
2284 return role;
2285 }
2286
2287 StringBundler msg = new StringBundler(4);
2288
2289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2290
2291 msg.append("companyId=");
2292 msg.append(companyId);
2293
2294 msg.append(StringPool.CLOSE_CURLY_BRACE);
2295
2296 throw new NoSuchRoleException(msg.toString());
2297 }
2298
2299
2306 @Override
2307 public Role fetchByCompanyId_Last(long companyId,
2308 OrderByComparator<Role> orderByComparator) {
2309 int count = countByCompanyId(companyId);
2310
2311 if (count == 0) {
2312 return null;
2313 }
2314
2315 List<Role> list = findByCompanyId(companyId, count - 1, count,
2316 orderByComparator);
2317
2318 if (!list.isEmpty()) {
2319 return list.get(0);
2320 }
2321
2322 return null;
2323 }
2324
2325
2334 @Override
2335 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
2336 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2337 Role role = findByPrimaryKey(roleId);
2338
2339 Session session = null;
2340
2341 try {
2342 session = openSession();
2343
2344 Role[] array = new RoleImpl[3];
2345
2346 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
2347 orderByComparator, true);
2348
2349 array[1] = role;
2350
2351 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
2352 orderByComparator, false);
2353
2354 return array;
2355 }
2356 catch (Exception e) {
2357 throw processException(e);
2358 }
2359 finally {
2360 closeSession(session);
2361 }
2362 }
2363
2364 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
2365 long companyId, OrderByComparator<Role> orderByComparator,
2366 boolean previous) {
2367 StringBundler query = null;
2368
2369 if (orderByComparator != null) {
2370 query = new StringBundler(4 +
2371 (orderByComparator.getOrderByConditionFields().length * 3) +
2372 (orderByComparator.getOrderByFields().length * 3));
2373 }
2374 else {
2375 query = new StringBundler(3);
2376 }
2377
2378 query.append(_SQL_SELECT_ROLE_WHERE);
2379
2380 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2381
2382 if (orderByComparator != null) {
2383 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2384
2385 if (orderByConditionFields.length > 0) {
2386 query.append(WHERE_AND);
2387 }
2388
2389 for (int i = 0; i < orderByConditionFields.length; i++) {
2390 query.append(_ORDER_BY_ENTITY_ALIAS);
2391 query.append(orderByConditionFields[i]);
2392
2393 if ((i + 1) < orderByConditionFields.length) {
2394 if (orderByComparator.isAscending() ^ previous) {
2395 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2396 }
2397 else {
2398 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2399 }
2400 }
2401 else {
2402 if (orderByComparator.isAscending() ^ previous) {
2403 query.append(WHERE_GREATER_THAN);
2404 }
2405 else {
2406 query.append(WHERE_LESSER_THAN);
2407 }
2408 }
2409 }
2410
2411 query.append(ORDER_BY_CLAUSE);
2412
2413 String[] orderByFields = orderByComparator.getOrderByFields();
2414
2415 for (int i = 0; i < orderByFields.length; i++) {
2416 query.append(_ORDER_BY_ENTITY_ALIAS);
2417 query.append(orderByFields[i]);
2418
2419 if ((i + 1) < orderByFields.length) {
2420 if (orderByComparator.isAscending() ^ previous) {
2421 query.append(ORDER_BY_ASC_HAS_NEXT);
2422 }
2423 else {
2424 query.append(ORDER_BY_DESC_HAS_NEXT);
2425 }
2426 }
2427 else {
2428 if (orderByComparator.isAscending() ^ previous) {
2429 query.append(ORDER_BY_ASC);
2430 }
2431 else {
2432 query.append(ORDER_BY_DESC);
2433 }
2434 }
2435 }
2436 }
2437 else {
2438 query.append(RoleModelImpl.ORDER_BY_JPQL);
2439 }
2440
2441 String sql = query.toString();
2442
2443 Query q = session.createQuery(sql);
2444
2445 q.setFirstResult(0);
2446 q.setMaxResults(2);
2447
2448 QueryPos qPos = QueryPos.getInstance(q);
2449
2450 qPos.add(companyId);
2451
2452 if (orderByComparator != null) {
2453 Object[] values = orderByComparator.getOrderByConditionValues(role);
2454
2455 for (Object value : values) {
2456 qPos.add(value);
2457 }
2458 }
2459
2460 List<Role> list = q.list();
2461
2462 if (list.size() == 2) {
2463 return list.get(1);
2464 }
2465 else {
2466 return null;
2467 }
2468 }
2469
2470
2476 @Override
2477 public List<Role> filterFindByCompanyId(long companyId) {
2478 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2479 QueryUtil.ALL_POS, null);
2480 }
2481
2482
2494 @Override
2495 public List<Role> filterFindByCompanyId(long companyId, int start, int end) {
2496 return filterFindByCompanyId(companyId, start, end, null);
2497 }
2498
2499
2512 @Override
2513 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
2514 OrderByComparator<Role> orderByComparator) {
2515 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
2516 return findByCompanyId(companyId, start, end, orderByComparator);
2517 }
2518
2519 StringBundler query = null;
2520
2521 if (orderByComparator != null) {
2522 query = new StringBundler(3 +
2523 (orderByComparator.getOrderByFields().length * 2));
2524 }
2525 else {
2526 query = new StringBundler(4);
2527 }
2528
2529 if (getDB().isSupportsInlineDistinct()) {
2530 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2531 }
2532 else {
2533 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2534 }
2535
2536 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2537
2538 if (!getDB().isSupportsInlineDistinct()) {
2539 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2540 }
2541
2542 if (orderByComparator != null) {
2543 if (getDB().isSupportsInlineDistinct()) {
2544 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2545 orderByComparator, true);
2546 }
2547 else {
2548 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2549 orderByComparator, true);
2550 }
2551 }
2552 else {
2553 if (getDB().isSupportsInlineDistinct()) {
2554 query.append(RoleModelImpl.ORDER_BY_JPQL);
2555 }
2556 else {
2557 query.append(RoleModelImpl.ORDER_BY_SQL);
2558 }
2559 }
2560
2561 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2562 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2563
2564 Session session = null;
2565
2566 try {
2567 session = openSession();
2568
2569 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2570
2571 if (getDB().isSupportsInlineDistinct()) {
2572 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2573 }
2574 else {
2575 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2576 }
2577
2578 QueryPos qPos = QueryPos.getInstance(q);
2579
2580 qPos.add(companyId);
2581
2582 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2583 }
2584 catch (Exception e) {
2585 throw processException(e);
2586 }
2587 finally {
2588 closeSession(session);
2589 }
2590 }
2591
2592
2601 @Override
2602 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
2603 long companyId, OrderByComparator<Role> orderByComparator)
2604 throws NoSuchRoleException {
2605 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
2606 return findByCompanyId_PrevAndNext(roleId, companyId,
2607 orderByComparator);
2608 }
2609
2610 Role role = findByPrimaryKey(roleId);
2611
2612 Session session = null;
2613
2614 try {
2615 session = openSession();
2616
2617 Role[] array = new RoleImpl[3];
2618
2619 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
2620 companyId, orderByComparator, true);
2621
2622 array[1] = role;
2623
2624 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
2625 companyId, orderByComparator, false);
2626
2627 return array;
2628 }
2629 catch (Exception e) {
2630 throw processException(e);
2631 }
2632 finally {
2633 closeSession(session);
2634 }
2635 }
2636
2637 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
2638 long companyId, OrderByComparator<Role> orderByComparator,
2639 boolean previous) {
2640 StringBundler query = null;
2641
2642 if (orderByComparator != null) {
2643 query = new StringBundler(5 +
2644 (orderByComparator.getOrderByConditionFields().length * 3) +
2645 (orderByComparator.getOrderByFields().length * 3));
2646 }
2647 else {
2648 query = new StringBundler(4);
2649 }
2650
2651 if (getDB().isSupportsInlineDistinct()) {
2652 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2653 }
2654 else {
2655 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2656 }
2657
2658 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2659
2660 if (!getDB().isSupportsInlineDistinct()) {
2661 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2662 }
2663
2664 if (orderByComparator != null) {
2665 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2666
2667 if (orderByConditionFields.length > 0) {
2668 query.append(WHERE_AND);
2669 }
2670
2671 for (int i = 0; i < orderByConditionFields.length; i++) {
2672 if (getDB().isSupportsInlineDistinct()) {
2673 query.append(_ORDER_BY_ENTITY_ALIAS);
2674 }
2675 else {
2676 query.append(_ORDER_BY_ENTITY_TABLE);
2677 }
2678
2679 query.append(orderByConditionFields[i]);
2680
2681 if ((i + 1) < orderByConditionFields.length) {
2682 if (orderByComparator.isAscending() ^ previous) {
2683 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2684 }
2685 else {
2686 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2687 }
2688 }
2689 else {
2690 if (orderByComparator.isAscending() ^ previous) {
2691 query.append(WHERE_GREATER_THAN);
2692 }
2693 else {
2694 query.append(WHERE_LESSER_THAN);
2695 }
2696 }
2697 }
2698
2699 query.append(ORDER_BY_CLAUSE);
2700
2701 String[] orderByFields = orderByComparator.getOrderByFields();
2702
2703 for (int i = 0; i < orderByFields.length; i++) {
2704 if (getDB().isSupportsInlineDistinct()) {
2705 query.append(_ORDER_BY_ENTITY_ALIAS);
2706 }
2707 else {
2708 query.append(_ORDER_BY_ENTITY_TABLE);
2709 }
2710
2711 query.append(orderByFields[i]);
2712
2713 if ((i + 1) < orderByFields.length) {
2714 if (orderByComparator.isAscending() ^ previous) {
2715 query.append(ORDER_BY_ASC_HAS_NEXT);
2716 }
2717 else {
2718 query.append(ORDER_BY_DESC_HAS_NEXT);
2719 }
2720 }
2721 else {
2722 if (orderByComparator.isAscending() ^ previous) {
2723 query.append(ORDER_BY_ASC);
2724 }
2725 else {
2726 query.append(ORDER_BY_DESC);
2727 }
2728 }
2729 }
2730 }
2731 else {
2732 if (getDB().isSupportsInlineDistinct()) {
2733 query.append(RoleModelImpl.ORDER_BY_JPQL);
2734 }
2735 else {
2736 query.append(RoleModelImpl.ORDER_BY_SQL);
2737 }
2738 }
2739
2740 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2741 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2742
2743 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2744
2745 q.setFirstResult(0);
2746 q.setMaxResults(2);
2747
2748 if (getDB().isSupportsInlineDistinct()) {
2749 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2750 }
2751 else {
2752 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2753 }
2754
2755 QueryPos qPos = QueryPos.getInstance(q);
2756
2757 qPos.add(companyId);
2758
2759 if (orderByComparator != null) {
2760 Object[] values = orderByComparator.getOrderByConditionValues(role);
2761
2762 for (Object value : values) {
2763 qPos.add(value);
2764 }
2765 }
2766
2767 List<Role> list = q.list();
2768
2769 if (list.size() == 2) {
2770 return list.get(1);
2771 }
2772 else {
2773 return null;
2774 }
2775 }
2776
2777
2782 @Override
2783 public void removeByCompanyId(long companyId) {
2784 for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
2785 QueryUtil.ALL_POS, null)) {
2786 remove(role);
2787 }
2788 }
2789
2790
2796 @Override
2797 public int countByCompanyId(long companyId) {
2798 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2799
2800 Object[] finderArgs = new Object[] { companyId };
2801
2802 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2803
2804 if (count == null) {
2805 StringBundler query = new StringBundler(2);
2806
2807 query.append(_SQL_COUNT_ROLE_WHERE);
2808
2809 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2810
2811 String sql = query.toString();
2812
2813 Session session = null;
2814
2815 try {
2816 session = openSession();
2817
2818 Query q = session.createQuery(sql);
2819
2820 QueryPos qPos = QueryPos.getInstance(q);
2821
2822 qPos.add(companyId);
2823
2824 count = (Long)q.uniqueResult();
2825
2826 finderCache.putResult(finderPath, finderArgs, count);
2827 }
2828 catch (Exception e) {
2829 finderCache.removeResult(finderPath, finderArgs);
2830
2831 throw processException(e);
2832 }
2833 finally {
2834 closeSession(session);
2835 }
2836 }
2837
2838 return count.intValue();
2839 }
2840
2841
2847 @Override
2848 public int filterCountByCompanyId(long companyId) {
2849 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
2850 return countByCompanyId(companyId);
2851 }
2852
2853 StringBundler query = new StringBundler(2);
2854
2855 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2856
2857 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2858
2859 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2860 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2861
2862 Session session = null;
2863
2864 try {
2865 session = openSession();
2866
2867 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2868
2869 q.addScalar(COUNT_COLUMN_NAME,
2870 com.liferay.portal.kernel.dao.orm.Type.LONG);
2871
2872 QueryPos qPos = QueryPos.getInstance(q);
2873
2874 qPos.add(companyId);
2875
2876 Long count = (Long)q.uniqueResult();
2877
2878 return count.intValue();
2879 }
2880 catch (Exception e) {
2881 throw processException(e);
2882 }
2883 finally {
2884 closeSession(session);
2885 }
2886 }
2887
2888 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
2889 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2890 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2891 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
2892 new String[] {
2893 String.class.getName(),
2894
2895 Integer.class.getName(), Integer.class.getName(),
2896 OrderByComparator.class.getName()
2897 });
2898 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2899 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2900 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
2901 new String[] { String.class.getName() },
2902 RoleModelImpl.NAME_COLUMN_BITMASK);
2903 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2904 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2905 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
2906 new String[] { String.class.getName() });
2907
2908
2914 @Override
2915 public List<Role> findByName(String name) {
2916 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2917 }
2918
2919
2931 @Override
2932 public List<Role> findByName(String name, int start, int end) {
2933 return findByName(name, start, end, null);
2934 }
2935
2936
2949 @Override
2950 public List<Role> findByName(String name, int start, int end,
2951 OrderByComparator<Role> orderByComparator) {
2952 return findByName(name, start, end, orderByComparator, true);
2953 }
2954
2955
2969 @Override
2970 public List<Role> findByName(String name, int start, int end,
2971 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
2972 boolean pagination = true;
2973 FinderPath finderPath = null;
2974 Object[] finderArgs = null;
2975
2976 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2977 (orderByComparator == null)) {
2978 pagination = false;
2979 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
2980 finderArgs = new Object[] { name };
2981 }
2982 else {
2983 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
2984 finderArgs = new Object[] { name, start, end, orderByComparator };
2985 }
2986
2987 List<Role> list = null;
2988
2989 if (retrieveFromCache) {
2990 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
2991 this);
2992
2993 if ((list != null) && !list.isEmpty()) {
2994 for (Role role : list) {
2995 if (!Objects.equals(name, role.getName())) {
2996 list = null;
2997
2998 break;
2999 }
3000 }
3001 }
3002 }
3003
3004 if (list == null) {
3005 StringBundler query = null;
3006
3007 if (orderByComparator != null) {
3008 query = new StringBundler(3 +
3009 (orderByComparator.getOrderByFields().length * 2));
3010 }
3011 else {
3012 query = new StringBundler(3);
3013 }
3014
3015 query.append(_SQL_SELECT_ROLE_WHERE);
3016
3017 boolean bindName = false;
3018
3019 if (name == null) {
3020 query.append(_FINDER_COLUMN_NAME_NAME_1);
3021 }
3022 else if (name.equals(StringPool.BLANK)) {
3023 query.append(_FINDER_COLUMN_NAME_NAME_3);
3024 }
3025 else {
3026 bindName = true;
3027
3028 query.append(_FINDER_COLUMN_NAME_NAME_2);
3029 }
3030
3031 if (orderByComparator != null) {
3032 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3033 orderByComparator);
3034 }
3035 else
3036 if (pagination) {
3037 query.append(RoleModelImpl.ORDER_BY_JPQL);
3038 }
3039
3040 String sql = query.toString();
3041
3042 Session session = null;
3043
3044 try {
3045 session = openSession();
3046
3047 Query q = session.createQuery(sql);
3048
3049 QueryPos qPos = QueryPos.getInstance(q);
3050
3051 if (bindName) {
3052 qPos.add(name);
3053 }
3054
3055 if (!pagination) {
3056 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3057 end, false);
3058
3059 Collections.sort(list);
3060
3061 list = Collections.unmodifiableList(list);
3062 }
3063 else {
3064 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3065 end);
3066 }
3067
3068 cacheResult(list);
3069
3070 finderCache.putResult(finderPath, finderArgs, list);
3071 }
3072 catch (Exception e) {
3073 finderCache.removeResult(finderPath, finderArgs);
3074
3075 throw processException(e);
3076 }
3077 finally {
3078 closeSession(session);
3079 }
3080 }
3081
3082 return list;
3083 }
3084
3085
3093 @Override
3094 public Role findByName_First(String name,
3095 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3096 Role role = fetchByName_First(name, orderByComparator);
3097
3098 if (role != null) {
3099 return role;
3100 }
3101
3102 StringBundler msg = new StringBundler(4);
3103
3104 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3105
3106 msg.append("name=");
3107 msg.append(name);
3108
3109 msg.append(StringPool.CLOSE_CURLY_BRACE);
3110
3111 throw new NoSuchRoleException(msg.toString());
3112 }
3113
3114
3121 @Override
3122 public Role fetchByName_First(String name,
3123 OrderByComparator<Role> orderByComparator) {
3124 List<Role> list = findByName(name, 0, 1, orderByComparator);
3125
3126 if (!list.isEmpty()) {
3127 return list.get(0);
3128 }
3129
3130 return null;
3131 }
3132
3133
3141 @Override
3142 public Role findByName_Last(String name,
3143 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3144 Role role = fetchByName_Last(name, orderByComparator);
3145
3146 if (role != null) {
3147 return role;
3148 }
3149
3150 StringBundler msg = new StringBundler(4);
3151
3152 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3153
3154 msg.append("name=");
3155 msg.append(name);
3156
3157 msg.append(StringPool.CLOSE_CURLY_BRACE);
3158
3159 throw new NoSuchRoleException(msg.toString());
3160 }
3161
3162
3169 @Override
3170 public Role fetchByName_Last(String name,
3171 OrderByComparator<Role> orderByComparator) {
3172 int count = countByName(name);
3173
3174 if (count == 0) {
3175 return null;
3176 }
3177
3178 List<Role> list = findByName(name, count - 1, count, orderByComparator);
3179
3180 if (!list.isEmpty()) {
3181 return list.get(0);
3182 }
3183
3184 return null;
3185 }
3186
3187
3196 @Override
3197 public Role[] findByName_PrevAndNext(long roleId, String name,
3198 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3199 Role role = findByPrimaryKey(roleId);
3200
3201 Session session = null;
3202
3203 try {
3204 session = openSession();
3205
3206 Role[] array = new RoleImpl[3];
3207
3208 array[0] = getByName_PrevAndNext(session, role, name,
3209 orderByComparator, true);
3210
3211 array[1] = role;
3212
3213 array[2] = getByName_PrevAndNext(session, role, name,
3214 orderByComparator, false);
3215
3216 return array;
3217 }
3218 catch (Exception e) {
3219 throw processException(e);
3220 }
3221 finally {
3222 closeSession(session);
3223 }
3224 }
3225
3226 protected Role getByName_PrevAndNext(Session session, Role role,
3227 String name, OrderByComparator<Role> orderByComparator, boolean previous) {
3228 StringBundler query = null;
3229
3230 if (orderByComparator != null) {
3231 query = new StringBundler(4 +
3232 (orderByComparator.getOrderByConditionFields().length * 3) +
3233 (orderByComparator.getOrderByFields().length * 3));
3234 }
3235 else {
3236 query = new StringBundler(3);
3237 }
3238
3239 query.append(_SQL_SELECT_ROLE_WHERE);
3240
3241 boolean bindName = false;
3242
3243 if (name == null) {
3244 query.append(_FINDER_COLUMN_NAME_NAME_1);
3245 }
3246 else if (name.equals(StringPool.BLANK)) {
3247 query.append(_FINDER_COLUMN_NAME_NAME_3);
3248 }
3249 else {
3250 bindName = true;
3251
3252 query.append(_FINDER_COLUMN_NAME_NAME_2);
3253 }
3254
3255 if (orderByComparator != null) {
3256 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3257
3258 if (orderByConditionFields.length > 0) {
3259 query.append(WHERE_AND);
3260 }
3261
3262 for (int i = 0; i < orderByConditionFields.length; i++) {
3263 query.append(_ORDER_BY_ENTITY_ALIAS);
3264 query.append(orderByConditionFields[i]);
3265
3266 if ((i + 1) < orderByConditionFields.length) {
3267 if (orderByComparator.isAscending() ^ previous) {
3268 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3269 }
3270 else {
3271 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3272 }
3273 }
3274 else {
3275 if (orderByComparator.isAscending() ^ previous) {
3276 query.append(WHERE_GREATER_THAN);
3277 }
3278 else {
3279 query.append(WHERE_LESSER_THAN);
3280 }
3281 }
3282 }
3283
3284 query.append(ORDER_BY_CLAUSE);
3285
3286 String[] orderByFields = orderByComparator.getOrderByFields();
3287
3288 for (int i = 0; i < orderByFields.length; i++) {
3289 query.append(_ORDER_BY_ENTITY_ALIAS);
3290 query.append(orderByFields[i]);
3291
3292 if ((i + 1) < orderByFields.length) {
3293 if (orderByComparator.isAscending() ^ previous) {
3294 query.append(ORDER_BY_ASC_HAS_NEXT);
3295 }
3296 else {
3297 query.append(ORDER_BY_DESC_HAS_NEXT);
3298 }
3299 }
3300 else {
3301 if (orderByComparator.isAscending() ^ previous) {
3302 query.append(ORDER_BY_ASC);
3303 }
3304 else {
3305 query.append(ORDER_BY_DESC);
3306 }
3307 }
3308 }
3309 }
3310 else {
3311 query.append(RoleModelImpl.ORDER_BY_JPQL);
3312 }
3313
3314 String sql = query.toString();
3315
3316 Query q = session.createQuery(sql);
3317
3318 q.setFirstResult(0);
3319 q.setMaxResults(2);
3320
3321 QueryPos qPos = QueryPos.getInstance(q);
3322
3323 if (bindName) {
3324 qPos.add(name);
3325 }
3326
3327 if (orderByComparator != null) {
3328 Object[] values = orderByComparator.getOrderByConditionValues(role);
3329
3330 for (Object value : values) {
3331 qPos.add(value);
3332 }
3333 }
3334
3335 List<Role> list = q.list();
3336
3337 if (list.size() == 2) {
3338 return list.get(1);
3339 }
3340 else {
3341 return null;
3342 }
3343 }
3344
3345
3351 @Override
3352 public List<Role> filterFindByName(String name) {
3353 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3354 }
3355
3356
3368 @Override
3369 public List<Role> filterFindByName(String name, int start, int end) {
3370 return filterFindByName(name, start, end, null);
3371 }
3372
3373
3386 @Override
3387 public List<Role> filterFindByName(String name, int start, int end,
3388 OrderByComparator<Role> orderByComparator) {
3389 if (!InlineSQLHelperUtil.isEnabled()) {
3390 return findByName(name, start, end, orderByComparator);
3391 }
3392
3393 StringBundler query = null;
3394
3395 if (orderByComparator != null) {
3396 query = new StringBundler(3 +
3397 (orderByComparator.getOrderByFields().length * 2));
3398 }
3399 else {
3400 query = new StringBundler(4);
3401 }
3402
3403 if (getDB().isSupportsInlineDistinct()) {
3404 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3405 }
3406 else {
3407 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3408 }
3409
3410 boolean bindName = false;
3411
3412 if (name == null) {
3413 query.append(_FINDER_COLUMN_NAME_NAME_1);
3414 }
3415 else if (name.equals(StringPool.BLANK)) {
3416 query.append(_FINDER_COLUMN_NAME_NAME_3);
3417 }
3418 else {
3419 bindName = true;
3420
3421 query.append(_FINDER_COLUMN_NAME_NAME_2);
3422 }
3423
3424 if (!getDB().isSupportsInlineDistinct()) {
3425 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3426 }
3427
3428 if (orderByComparator != null) {
3429 if (getDB().isSupportsInlineDistinct()) {
3430 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3431 orderByComparator, true);
3432 }
3433 else {
3434 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3435 orderByComparator, true);
3436 }
3437 }
3438 else {
3439 if (getDB().isSupportsInlineDistinct()) {
3440 query.append(RoleModelImpl.ORDER_BY_JPQL);
3441 }
3442 else {
3443 query.append(RoleModelImpl.ORDER_BY_SQL);
3444 }
3445 }
3446
3447 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3448 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3449
3450 Session session = null;
3451
3452 try {
3453 session = openSession();
3454
3455 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3456
3457 if (getDB().isSupportsInlineDistinct()) {
3458 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3459 }
3460 else {
3461 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3462 }
3463
3464 QueryPos qPos = QueryPos.getInstance(q);
3465
3466 if (bindName) {
3467 qPos.add(name);
3468 }
3469
3470 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3471 }
3472 catch (Exception e) {
3473 throw processException(e);
3474 }
3475 finally {
3476 closeSession(session);
3477 }
3478 }
3479
3480
3489 @Override
3490 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
3491 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3492 if (!InlineSQLHelperUtil.isEnabled()) {
3493 return findByName_PrevAndNext(roleId, name, orderByComparator);
3494 }
3495
3496 Role role = findByPrimaryKey(roleId);
3497
3498 Session session = null;
3499
3500 try {
3501 session = openSession();
3502
3503 Role[] array = new RoleImpl[3];
3504
3505 array[0] = filterGetByName_PrevAndNext(session, role, name,
3506 orderByComparator, true);
3507
3508 array[1] = role;
3509
3510 array[2] = filterGetByName_PrevAndNext(session, role, name,
3511 orderByComparator, false);
3512
3513 return array;
3514 }
3515 catch (Exception e) {
3516 throw processException(e);
3517 }
3518 finally {
3519 closeSession(session);
3520 }
3521 }
3522
3523 protected Role filterGetByName_PrevAndNext(Session session, Role role,
3524 String name, OrderByComparator<Role> orderByComparator, boolean previous) {
3525 StringBundler query = null;
3526
3527 if (orderByComparator != null) {
3528 query = new StringBundler(5 +
3529 (orderByComparator.getOrderByConditionFields().length * 3) +
3530 (orderByComparator.getOrderByFields().length * 3));
3531 }
3532 else {
3533 query = new StringBundler(4);
3534 }
3535
3536 if (getDB().isSupportsInlineDistinct()) {
3537 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3538 }
3539 else {
3540 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3541 }
3542
3543 boolean bindName = false;
3544
3545 if (name == null) {
3546 query.append(_FINDER_COLUMN_NAME_NAME_1);
3547 }
3548 else if (name.equals(StringPool.BLANK)) {
3549 query.append(_FINDER_COLUMN_NAME_NAME_3);
3550 }
3551 else {
3552 bindName = true;
3553
3554 query.append(_FINDER_COLUMN_NAME_NAME_2);
3555 }
3556
3557 if (!getDB().isSupportsInlineDistinct()) {
3558 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3559 }
3560
3561 if (orderByComparator != null) {
3562 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3563
3564 if (orderByConditionFields.length > 0) {
3565 query.append(WHERE_AND);
3566 }
3567
3568 for (int i = 0; i < orderByConditionFields.length; i++) {
3569 if (getDB().isSupportsInlineDistinct()) {
3570 query.append(_ORDER_BY_ENTITY_ALIAS);
3571 }
3572 else {
3573 query.append(_ORDER_BY_ENTITY_TABLE);
3574 }
3575
3576 query.append(orderByConditionFields[i]);
3577
3578 if ((i + 1) < orderByConditionFields.length) {
3579 if (orderByComparator.isAscending() ^ previous) {
3580 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3581 }
3582 else {
3583 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3584 }
3585 }
3586 else {
3587 if (orderByComparator.isAscending() ^ previous) {
3588 query.append(WHERE_GREATER_THAN);
3589 }
3590 else {
3591 query.append(WHERE_LESSER_THAN);
3592 }
3593 }
3594 }
3595
3596 query.append(ORDER_BY_CLAUSE);
3597
3598 String[] orderByFields = orderByComparator.getOrderByFields();
3599
3600 for (int i = 0; i < orderByFields.length; i++) {
3601 if (getDB().isSupportsInlineDistinct()) {
3602 query.append(_ORDER_BY_ENTITY_ALIAS);
3603 }
3604 else {
3605 query.append(_ORDER_BY_ENTITY_TABLE);
3606 }
3607
3608 query.append(orderByFields[i]);
3609
3610 if ((i + 1) < orderByFields.length) {
3611 if (orderByComparator.isAscending() ^ previous) {
3612 query.append(ORDER_BY_ASC_HAS_NEXT);
3613 }
3614 else {
3615 query.append(ORDER_BY_DESC_HAS_NEXT);
3616 }
3617 }
3618 else {
3619 if (orderByComparator.isAscending() ^ previous) {
3620 query.append(ORDER_BY_ASC);
3621 }
3622 else {
3623 query.append(ORDER_BY_DESC);
3624 }
3625 }
3626 }
3627 }
3628 else {
3629 if (getDB().isSupportsInlineDistinct()) {
3630 query.append(RoleModelImpl.ORDER_BY_JPQL);
3631 }
3632 else {
3633 query.append(RoleModelImpl.ORDER_BY_SQL);
3634 }
3635 }
3636
3637 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3638 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3639
3640 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3641
3642 q.setFirstResult(0);
3643 q.setMaxResults(2);
3644
3645 if (getDB().isSupportsInlineDistinct()) {
3646 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3647 }
3648 else {
3649 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3650 }
3651
3652 QueryPos qPos = QueryPos.getInstance(q);
3653
3654 if (bindName) {
3655 qPos.add(name);
3656 }
3657
3658 if (orderByComparator != null) {
3659 Object[] values = orderByComparator.getOrderByConditionValues(role);
3660
3661 for (Object value : values) {
3662 qPos.add(value);
3663 }
3664 }
3665
3666 List<Role> list = q.list();
3667
3668 if (list.size() == 2) {
3669 return list.get(1);
3670 }
3671 else {
3672 return null;
3673 }
3674 }
3675
3676
3681 @Override
3682 public void removeByName(String name) {
3683 for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3684 null)) {
3685 remove(role);
3686 }
3687 }
3688
3689
3695 @Override
3696 public int countByName(String name) {
3697 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
3698
3699 Object[] finderArgs = new Object[] { name };
3700
3701 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3702
3703 if (count == null) {
3704 StringBundler query = new StringBundler(2);
3705
3706 query.append(_SQL_COUNT_ROLE_WHERE);
3707
3708 boolean bindName = false;
3709
3710 if (name == null) {
3711 query.append(_FINDER_COLUMN_NAME_NAME_1);
3712 }
3713 else if (name.equals(StringPool.BLANK)) {
3714 query.append(_FINDER_COLUMN_NAME_NAME_3);
3715 }
3716 else {
3717 bindName = true;
3718
3719 query.append(_FINDER_COLUMN_NAME_NAME_2);
3720 }
3721
3722 String sql = query.toString();
3723
3724 Session session = null;
3725
3726 try {
3727 session = openSession();
3728
3729 Query q = session.createQuery(sql);
3730
3731 QueryPos qPos = QueryPos.getInstance(q);
3732
3733 if (bindName) {
3734 qPos.add(name);
3735 }
3736
3737 count = (Long)q.uniqueResult();
3738
3739 finderCache.putResult(finderPath, finderArgs, count);
3740 }
3741 catch (Exception e) {
3742 finderCache.removeResult(finderPath, finderArgs);
3743
3744 throw processException(e);
3745 }
3746 finally {
3747 closeSession(session);
3748 }
3749 }
3750
3751 return count.intValue();
3752 }
3753
3754
3760 @Override
3761 public int filterCountByName(String name) {
3762 if (!InlineSQLHelperUtil.isEnabled()) {
3763 return countByName(name);
3764 }
3765
3766 StringBundler query = new StringBundler(2);
3767
3768 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3769
3770 boolean bindName = false;
3771
3772 if (name == null) {
3773 query.append(_FINDER_COLUMN_NAME_NAME_1);
3774 }
3775 else if (name.equals(StringPool.BLANK)) {
3776 query.append(_FINDER_COLUMN_NAME_NAME_3);
3777 }
3778 else {
3779 bindName = true;
3780
3781 query.append(_FINDER_COLUMN_NAME_NAME_2);
3782 }
3783
3784 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3785 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3786
3787 Session session = null;
3788
3789 try {
3790 session = openSession();
3791
3792 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3793
3794 q.addScalar(COUNT_COLUMN_NAME,
3795 com.liferay.portal.kernel.dao.orm.Type.LONG);
3796
3797 QueryPos qPos = QueryPos.getInstance(q);
3798
3799 if (bindName) {
3800 qPos.add(name);
3801 }
3802
3803 Long count = (Long)q.uniqueResult();
3804
3805 return count.intValue();
3806 }
3807 catch (Exception e) {
3808 throw processException(e);
3809 }
3810 finally {
3811 closeSession(session);
3812 }
3813 }
3814
3815 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
3816 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
3817 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')";
3818 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3819 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3820 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3821 new String[] {
3822 Integer.class.getName(),
3823
3824 Integer.class.getName(), Integer.class.getName(),
3825 OrderByComparator.class.getName()
3826 });
3827 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3828 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3829 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3830 new String[] { Integer.class.getName() },
3831 RoleModelImpl.TYPE_COLUMN_BITMASK |
3832 RoleModelImpl.NAME_COLUMN_BITMASK);
3833 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3834 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3835 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3836 new String[] { Integer.class.getName() });
3837
3838
3844 @Override
3845 public List<Role> findByType(int type) {
3846 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3847 }
3848
3849
3861 @Override
3862 public List<Role> findByType(int type, int start, int end) {
3863 return findByType(type, start, end, null);
3864 }
3865
3866
3879 @Override
3880 public List<Role> findByType(int type, int start, int end,
3881 OrderByComparator<Role> orderByComparator) {
3882 return findByType(type, start, end, orderByComparator, true);
3883 }
3884
3885
3899 @Override
3900 public List<Role> findByType(int type, int start, int end,
3901 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
3902 boolean pagination = true;
3903 FinderPath finderPath = null;
3904 Object[] finderArgs = null;
3905
3906 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3907 (orderByComparator == null)) {
3908 pagination = false;
3909 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3910 finderArgs = new Object[] { type };
3911 }
3912 else {
3913 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3914 finderArgs = new Object[] { type, start, end, orderByComparator };
3915 }
3916
3917 List<Role> list = null;
3918
3919 if (retrieveFromCache) {
3920 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
3921 this);
3922
3923 if ((list != null) && !list.isEmpty()) {
3924 for (Role role : list) {
3925 if ((type != role.getType())) {
3926 list = null;
3927
3928 break;
3929 }
3930 }
3931 }
3932 }
3933
3934 if (list == null) {
3935 StringBundler query = null;
3936
3937 if (orderByComparator != null) {
3938 query = new StringBundler(3 +
3939 (orderByComparator.getOrderByFields().length * 2));
3940 }
3941 else {
3942 query = new StringBundler(3);
3943 }
3944
3945 query.append(_SQL_SELECT_ROLE_WHERE);
3946
3947 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3948
3949 if (orderByComparator != null) {
3950 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3951 orderByComparator);
3952 }
3953 else
3954 if (pagination) {
3955 query.append(RoleModelImpl.ORDER_BY_JPQL);
3956 }
3957
3958 String sql = query.toString();
3959
3960 Session session = null;
3961
3962 try {
3963 session = openSession();
3964
3965 Query q = session.createQuery(sql);
3966
3967 QueryPos qPos = QueryPos.getInstance(q);
3968
3969 qPos.add(type);
3970
3971 if (!pagination) {
3972 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3973 end, false);
3974
3975 Collections.sort(list);
3976
3977 list = Collections.unmodifiableList(list);
3978 }
3979 else {
3980 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3981 end);
3982 }
3983
3984 cacheResult(list);
3985
3986 finderCache.putResult(finderPath, finderArgs, list);
3987 }
3988 catch (Exception e) {
3989 finderCache.removeResult(finderPath, finderArgs);
3990
3991 throw processException(e);
3992 }
3993 finally {
3994 closeSession(session);
3995 }
3996 }
3997
3998 return list;
3999 }
4000
4001
4009 @Override
4010 public Role findByType_First(int type,
4011 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4012 Role role = fetchByType_First(type, orderByComparator);
4013
4014 if (role != null) {
4015 return role;
4016 }
4017
4018 StringBundler msg = new StringBundler(4);
4019
4020 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4021
4022 msg.append("type=");
4023 msg.append(type);
4024
4025 msg.append(StringPool.CLOSE_CURLY_BRACE);
4026
4027 throw new NoSuchRoleException(msg.toString());
4028 }
4029
4030
4037 @Override
4038 public Role fetchByType_First(int type,
4039 OrderByComparator<Role> orderByComparator) {
4040 List<Role> list = findByType(type, 0, 1, orderByComparator);
4041
4042 if (!list.isEmpty()) {
4043 return list.get(0);
4044 }
4045
4046 return null;
4047 }
4048
4049
4057 @Override
4058 public Role findByType_Last(int type,
4059 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4060 Role role = fetchByType_Last(type, orderByComparator);
4061
4062 if (role != null) {
4063 return role;
4064 }
4065
4066 StringBundler msg = new StringBundler(4);
4067
4068 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4069
4070 msg.append("type=");
4071 msg.append(type);
4072
4073 msg.append(StringPool.CLOSE_CURLY_BRACE);
4074
4075 throw new NoSuchRoleException(msg.toString());
4076 }
4077
4078
4085 @Override
4086 public Role fetchByType_Last(int type,
4087 OrderByComparator<Role> orderByComparator) {
4088 int count = countByType(type);
4089
4090 if (count == 0) {
4091 return null;
4092 }
4093
4094 List<Role> list = findByType(type, count - 1, count, orderByComparator);
4095
4096 if (!list.isEmpty()) {
4097 return list.get(0);
4098 }
4099
4100 return null;
4101 }
4102
4103
4112 @Override
4113 public Role[] findByType_PrevAndNext(long roleId, int type,
4114 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4115 Role role = findByPrimaryKey(roleId);
4116
4117 Session session = null;
4118
4119 try {
4120 session = openSession();
4121
4122 Role[] array = new RoleImpl[3];
4123
4124 array[0] = getByType_PrevAndNext(session, role, type,
4125 orderByComparator, true);
4126
4127 array[1] = role;
4128
4129 array[2] = getByType_PrevAndNext(session, role, type,
4130 orderByComparator, false);
4131
4132 return array;
4133 }
4134 catch (Exception e) {
4135 throw processException(e);
4136 }
4137 finally {
4138 closeSession(session);
4139 }
4140 }
4141
4142 protected Role getByType_PrevAndNext(Session session, Role role, int type,
4143 OrderByComparator<Role> orderByComparator, boolean previous) {
4144 StringBundler query = null;
4145
4146 if (orderByComparator != null) {
4147 query = new StringBundler(4 +
4148 (orderByComparator.getOrderByConditionFields().length * 3) +
4149 (orderByComparator.getOrderByFields().length * 3));
4150 }
4151 else {
4152 query = new StringBundler(3);
4153 }
4154
4155 query.append(_SQL_SELECT_ROLE_WHERE);
4156
4157 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4158
4159 if (orderByComparator != null) {
4160 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4161
4162 if (orderByConditionFields.length > 0) {
4163 query.append(WHERE_AND);
4164 }
4165
4166 for (int i = 0; i < orderByConditionFields.length; i++) {
4167 query.append(_ORDER_BY_ENTITY_ALIAS);
4168 query.append(orderByConditionFields[i]);
4169
4170 if ((i + 1) < orderByConditionFields.length) {
4171 if (orderByComparator.isAscending() ^ previous) {
4172 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4173 }
4174 else {
4175 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4176 }
4177 }
4178 else {
4179 if (orderByComparator.isAscending() ^ previous) {
4180 query.append(WHERE_GREATER_THAN);
4181 }
4182 else {
4183 query.append(WHERE_LESSER_THAN);
4184 }
4185 }
4186 }
4187
4188 query.append(ORDER_BY_CLAUSE);
4189
4190 String[] orderByFields = orderByComparator.getOrderByFields();
4191
4192 for (int i = 0; i < orderByFields.length; i++) {
4193 query.append(_ORDER_BY_ENTITY_ALIAS);
4194 query.append(orderByFields[i]);
4195
4196 if ((i + 1) < orderByFields.length) {
4197 if (orderByComparator.isAscending() ^ previous) {
4198 query.append(ORDER_BY_ASC_HAS_NEXT);
4199 }
4200 else {
4201 query.append(ORDER_BY_DESC_HAS_NEXT);
4202 }
4203 }
4204 else {
4205 if (orderByComparator.isAscending() ^ previous) {
4206 query.append(ORDER_BY_ASC);
4207 }
4208 else {
4209 query.append(ORDER_BY_DESC);
4210 }
4211 }
4212 }
4213 }
4214 else {
4215 query.append(RoleModelImpl.ORDER_BY_JPQL);
4216 }
4217
4218 String sql = query.toString();
4219
4220 Query q = session.createQuery(sql);
4221
4222 q.setFirstResult(0);
4223 q.setMaxResults(2);
4224
4225 QueryPos qPos = QueryPos.getInstance(q);
4226
4227 qPos.add(type);
4228
4229 if (orderByComparator != null) {
4230 Object[] values = orderByComparator.getOrderByConditionValues(role);
4231
4232 for (Object value : values) {
4233 qPos.add(value);
4234 }
4235 }
4236
4237 List<Role> list = q.list();
4238
4239 if (list.size() == 2) {
4240 return list.get(1);
4241 }
4242 else {
4243 return null;
4244 }
4245 }
4246
4247
4253 @Override
4254 public List<Role> filterFindByType(int type) {
4255 return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4256 }
4257
4258
4270 @Override
4271 public List<Role> filterFindByType(int type, int start, int end) {
4272 return filterFindByType(type, start, end, null);
4273 }
4274
4275
4288 @Override
4289 public List<Role> filterFindByType(int type, int start, int end,
4290 OrderByComparator<Role> orderByComparator) {
4291 if (!InlineSQLHelperUtil.isEnabled()) {
4292 return findByType(type, start, end, orderByComparator);
4293 }
4294
4295 StringBundler query = null;
4296
4297 if (orderByComparator != null) {
4298 query = new StringBundler(3 +
4299 (orderByComparator.getOrderByFields().length * 2));
4300 }
4301 else {
4302 query = new StringBundler(4);
4303 }
4304
4305 if (getDB().isSupportsInlineDistinct()) {
4306 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4307 }
4308 else {
4309 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4310 }
4311
4312 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4313
4314 if (!getDB().isSupportsInlineDistinct()) {
4315 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4316 }
4317
4318 if (orderByComparator != null) {
4319 if (getDB().isSupportsInlineDistinct()) {
4320 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4321 orderByComparator, true);
4322 }
4323 else {
4324 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4325 orderByComparator, true);
4326 }
4327 }
4328 else {
4329 if (getDB().isSupportsInlineDistinct()) {
4330 query.append(RoleModelImpl.ORDER_BY_JPQL);
4331 }
4332 else {
4333 query.append(RoleModelImpl.ORDER_BY_SQL);
4334 }
4335 }
4336
4337 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4338 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4339
4340 Session session = null;
4341
4342 try {
4343 session = openSession();
4344
4345 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4346
4347 if (getDB().isSupportsInlineDistinct()) {
4348 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4349 }
4350 else {
4351 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4352 }
4353
4354 QueryPos qPos = QueryPos.getInstance(q);
4355
4356 qPos.add(type);
4357
4358 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
4359 }
4360 catch (Exception e) {
4361 throw processException(e);
4362 }
4363 finally {
4364 closeSession(session);
4365 }
4366 }
4367
4368
4377 @Override
4378 public Role[] filterFindByType_PrevAndNext(long roleId, int type,
4379 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4380 if (!InlineSQLHelperUtil.isEnabled()) {
4381 return findByType_PrevAndNext(roleId, type, orderByComparator);
4382 }
4383
4384 Role role = findByPrimaryKey(roleId);
4385
4386 Session session = null;
4387
4388 try {
4389 session = openSession();
4390
4391 Role[] array = new RoleImpl[3];
4392
4393 array[0] = filterGetByType_PrevAndNext(session, role, type,
4394 orderByComparator, true);
4395
4396 array[1] = role;
4397
4398 array[2] = filterGetByType_PrevAndNext(session, role, type,
4399 orderByComparator, false);
4400
4401 return array;
4402 }
4403 catch (Exception e) {
4404 throw processException(e);
4405 }
4406 finally {
4407 closeSession(session);
4408 }
4409 }
4410
4411 protected Role filterGetByType_PrevAndNext(Session session, Role role,
4412 int type, OrderByComparator<Role> orderByComparator, boolean previous) {
4413 StringBundler query = null;
4414
4415 if (orderByComparator != null) {
4416 query = new StringBundler(5 +
4417 (orderByComparator.getOrderByConditionFields().length * 3) +
4418 (orderByComparator.getOrderByFields().length * 3));
4419 }
4420 else {
4421 query = new StringBundler(4);
4422 }
4423
4424 if (getDB().isSupportsInlineDistinct()) {
4425 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4426 }
4427 else {
4428 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4429 }
4430
4431 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4432
4433 if (!getDB().isSupportsInlineDistinct()) {
4434 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4435 }
4436
4437 if (orderByComparator != null) {
4438 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4439
4440 if (orderByConditionFields.length > 0) {
4441 query.append(WHERE_AND);
4442 }
4443
4444 for (int i = 0; i < orderByConditionFields.length; i++) {
4445 if (getDB().isSupportsInlineDistinct()) {
4446 query.append(_ORDER_BY_ENTITY_ALIAS);
4447 }
4448 else {
4449 query.append(_ORDER_BY_ENTITY_TABLE);
4450 }
4451
4452 query.append(orderByConditionFields[i]);
4453
4454 if ((i + 1) < orderByConditionFields.length) {
4455 if (orderByComparator.isAscending() ^ previous) {
4456 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4457 }
4458 else {
4459 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4460 }
4461 }
4462 else {
4463 if (orderByComparator.isAscending() ^ previous) {
4464 query.append(WHERE_GREATER_THAN);
4465 }
4466 else {
4467 query.append(WHERE_LESSER_THAN);
4468 }
4469 }
4470 }
4471
4472 query.append(ORDER_BY_CLAUSE);
4473
4474 String[] orderByFields = orderByComparator.getOrderByFields();
4475
4476 for (int i = 0; i < orderByFields.length; i++) {
4477 if (getDB().isSupportsInlineDistinct()) {
4478 query.append(_ORDER_BY_ENTITY_ALIAS);
4479 }
4480 else {
4481 query.append(_ORDER_BY_ENTITY_TABLE);
4482 }
4483
4484 query.append(orderByFields[i]);
4485
4486 if ((i + 1) < orderByFields.length) {
4487 if (orderByComparator.isAscending() ^ previous) {
4488 query.append(ORDER_BY_ASC_HAS_NEXT);
4489 }
4490 else {
4491 query.append(ORDER_BY_DESC_HAS_NEXT);
4492 }
4493 }
4494 else {
4495 if (orderByComparator.isAscending() ^ previous) {
4496 query.append(ORDER_BY_ASC);
4497 }
4498 else {
4499 query.append(ORDER_BY_DESC);
4500 }
4501 }
4502 }
4503 }
4504 else {
4505 if (getDB().isSupportsInlineDistinct()) {
4506 query.append(RoleModelImpl.ORDER_BY_JPQL);
4507 }
4508 else {
4509 query.append(RoleModelImpl.ORDER_BY_SQL);
4510 }
4511 }
4512
4513 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4514 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4515
4516 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4517
4518 q.setFirstResult(0);
4519 q.setMaxResults(2);
4520
4521 if (getDB().isSupportsInlineDistinct()) {
4522 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4523 }
4524 else {
4525 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4526 }
4527
4528 QueryPos qPos = QueryPos.getInstance(q);
4529
4530 qPos.add(type);
4531
4532 if (orderByComparator != null) {
4533 Object[] values = orderByComparator.getOrderByConditionValues(role);
4534
4535 for (Object value : values) {
4536 qPos.add(value);
4537 }
4538 }
4539
4540 List<Role> list = q.list();
4541
4542 if (list.size() == 2) {
4543 return list.get(1);
4544 }
4545 else {
4546 return null;
4547 }
4548 }
4549
4550
4555 @Override
4556 public void removeByType(int type) {
4557 for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4558 null)) {
4559 remove(role);
4560 }
4561 }
4562
4563
4569 @Override
4570 public int countByType(int type) {
4571 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
4572
4573 Object[] finderArgs = new Object[] { type };
4574
4575 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4576
4577 if (count == null) {
4578 StringBundler query = new StringBundler(2);
4579
4580 query.append(_SQL_COUNT_ROLE_WHERE);
4581
4582 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4583
4584 String sql = query.toString();
4585
4586 Session session = null;
4587
4588 try {
4589 session = openSession();
4590
4591 Query q = session.createQuery(sql);
4592
4593 QueryPos qPos = QueryPos.getInstance(q);
4594
4595 qPos.add(type);
4596
4597 count = (Long)q.uniqueResult();
4598
4599 finderCache.putResult(finderPath, finderArgs, count);
4600 }
4601 catch (Exception e) {
4602 finderCache.removeResult(finderPath, finderArgs);
4603
4604 throw processException(e);
4605 }
4606 finally {
4607 closeSession(session);
4608 }
4609 }
4610
4611 return count.intValue();
4612 }
4613
4614
4620 @Override
4621 public int filterCountByType(int type) {
4622 if (!InlineSQLHelperUtil.isEnabled()) {
4623 return countByType(type);
4624 }
4625
4626 StringBundler query = new StringBundler(2);
4627
4628 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4629
4630 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4631
4632 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4633 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4634
4635 Session session = null;
4636
4637 try {
4638 session = openSession();
4639
4640 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4641
4642 q.addScalar(COUNT_COLUMN_NAME,
4643 com.liferay.portal.kernel.dao.orm.Type.LONG);
4644
4645 QueryPos qPos = QueryPos.getInstance(q);
4646
4647 qPos.add(type);
4648
4649 Long count = (Long)q.uniqueResult();
4650
4651 return count.intValue();
4652 }
4653 catch (Exception e) {
4654 throw processException(e);
4655 }
4656 finally {
4657 closeSession(session);
4658 }
4659 }
4660
4661 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?";
4662 private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?";
4663 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4664 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4665 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
4666 new String[] {
4667 String.class.getName(),
4668
4669 Integer.class.getName(), Integer.class.getName(),
4670 OrderByComparator.class.getName()
4671 });
4672 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
4673 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4674 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4675 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
4676 new String[] { String.class.getName() },
4677 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
4678 RoleModelImpl.NAME_COLUMN_BITMASK);
4679 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4680 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4681 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
4682 new String[] { String.class.getName() });
4683
4684
4690 @Override
4691 public List<Role> findBySubtype(String subtype) {
4692 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4693 }
4694
4695
4707 @Override
4708 public List<Role> findBySubtype(String subtype, int start, int end) {
4709 return findBySubtype(subtype, start, end, null);
4710 }
4711
4712
4725 @Override
4726 public List<Role> findBySubtype(String subtype, int start, int end,
4727 OrderByComparator<Role> orderByComparator) {
4728 return findBySubtype(subtype, start, end, orderByComparator, true);
4729 }
4730
4731
4745 @Override
4746 public List<Role> findBySubtype(String subtype, int start, int end,
4747 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
4748 boolean pagination = true;
4749 FinderPath finderPath = null;
4750 Object[] finderArgs = null;
4751
4752 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4753 (orderByComparator == null)) {
4754 pagination = false;
4755 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
4756 finderArgs = new Object[] { subtype };
4757 }
4758 else {
4759 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
4760 finderArgs = new Object[] { subtype, start, end, orderByComparator };
4761 }
4762
4763 List<Role> list = null;
4764
4765 if (retrieveFromCache) {
4766 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
4767 this);
4768
4769 if ((list != null) && !list.isEmpty()) {
4770 for (Role role : list) {
4771 if (!Objects.equals(subtype, role.getSubtype())) {
4772 list = null;
4773
4774 break;
4775 }
4776 }
4777 }
4778 }
4779
4780 if (list == null) {
4781 StringBundler query = null;
4782
4783 if (orderByComparator != null) {
4784 query = new StringBundler(3 +
4785 (orderByComparator.getOrderByFields().length * 2));
4786 }
4787 else {
4788 query = new StringBundler(3);
4789 }
4790
4791 query.append(_SQL_SELECT_ROLE_WHERE);
4792
4793 boolean bindSubtype = false;
4794
4795 if (subtype == null) {
4796 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4797 }
4798 else if (subtype.equals(StringPool.BLANK)) {
4799 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4800 }
4801 else {
4802 bindSubtype = true;
4803
4804 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4805 }
4806
4807 if (orderByComparator != null) {
4808 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4809 orderByComparator);
4810 }
4811 else
4812 if (pagination) {
4813 query.append(RoleModelImpl.ORDER_BY_JPQL);
4814 }
4815
4816 String sql = query.toString();
4817
4818 Session session = null;
4819
4820 try {
4821 session = openSession();
4822
4823 Query q = session.createQuery(sql);
4824
4825 QueryPos qPos = QueryPos.getInstance(q);
4826
4827 if (bindSubtype) {
4828 qPos.add(subtype);
4829 }
4830
4831 if (!pagination) {
4832 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4833 end, false);
4834
4835 Collections.sort(list);
4836
4837 list = Collections.unmodifiableList(list);
4838 }
4839 else {
4840 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4841 end);
4842 }
4843
4844 cacheResult(list);
4845
4846 finderCache.putResult(finderPath, finderArgs, list);
4847 }
4848 catch (Exception e) {
4849 finderCache.removeResult(finderPath, finderArgs);
4850
4851 throw processException(e);
4852 }
4853 finally {
4854 closeSession(session);
4855 }
4856 }
4857
4858 return list;
4859 }
4860
4861
4869 @Override
4870 public Role findBySubtype_First(String subtype,
4871 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4872 Role role = fetchBySubtype_First(subtype, orderByComparator);
4873
4874 if (role != null) {
4875 return role;
4876 }
4877
4878 StringBundler msg = new StringBundler(4);
4879
4880 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4881
4882 msg.append("subtype=");
4883 msg.append(subtype);
4884
4885 msg.append(StringPool.CLOSE_CURLY_BRACE);
4886
4887 throw new NoSuchRoleException(msg.toString());
4888 }
4889
4890
4897 @Override
4898 public Role fetchBySubtype_First(String subtype,
4899 OrderByComparator<Role> orderByComparator) {
4900 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
4901
4902 if (!list.isEmpty()) {
4903 return list.get(0);
4904 }
4905
4906 return null;
4907 }
4908
4909
4917 @Override
4918 public Role findBySubtype_Last(String subtype,
4919 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4920 Role role = fetchBySubtype_Last(subtype, orderByComparator);
4921
4922 if (role != null) {
4923 return role;
4924 }
4925
4926 StringBundler msg = new StringBundler(4);
4927
4928 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4929
4930 msg.append("subtype=");
4931 msg.append(subtype);
4932
4933 msg.append(StringPool.CLOSE_CURLY_BRACE);
4934
4935 throw new NoSuchRoleException(msg.toString());
4936 }
4937
4938
4945 @Override
4946 public Role fetchBySubtype_Last(String subtype,
4947 OrderByComparator<Role> orderByComparator) {
4948 int count = countBySubtype(subtype);
4949
4950 if (count == 0) {
4951 return null;
4952 }
4953
4954 List<Role> list = findBySubtype(subtype, count - 1, count,
4955 orderByComparator);
4956
4957 if (!list.isEmpty()) {
4958 return list.get(0);
4959 }
4960
4961 return null;
4962 }
4963
4964
4973 @Override
4974 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
4975 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4976 Role role = findByPrimaryKey(roleId);
4977
4978 Session session = null;
4979
4980 try {
4981 session = openSession();
4982
4983 Role[] array = new RoleImpl[3];
4984
4985 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
4986 orderByComparator, true);
4987
4988 array[1] = role;
4989
4990 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
4991 orderByComparator, false);
4992
4993 return array;
4994 }
4995 catch (Exception e) {
4996 throw processException(e);
4997 }
4998 finally {
4999 closeSession(session);
5000 }
5001 }
5002
5003 protected Role getBySubtype_PrevAndNext(Session session, Role role,
5004 String subtype, OrderByComparator<Role> orderByComparator,
5005 boolean previous) {
5006 StringBundler query = null;
5007
5008 if (orderByComparator != null) {
5009 query = new StringBundler(4 +
5010 (orderByComparator.getOrderByConditionFields().length * 3) +
5011 (orderByComparator.getOrderByFields().length * 3));
5012 }
5013 else {
5014 query = new StringBundler(3);
5015 }
5016
5017 query.append(_SQL_SELECT_ROLE_WHERE);
5018
5019 boolean bindSubtype = false;
5020
5021 if (subtype == null) {
5022 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5023 }
5024 else if (subtype.equals(StringPool.BLANK)) {
5025 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5026 }
5027 else {
5028 bindSubtype = true;
5029
5030 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5031 }
5032
5033 if (orderByComparator != null) {
5034 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5035
5036 if (orderByConditionFields.length > 0) {
5037 query.append(WHERE_AND);
5038 }
5039
5040 for (int i = 0; i < orderByConditionFields.length; i++) {
5041 query.append(_ORDER_BY_ENTITY_ALIAS);
5042 query.append(orderByConditionFields[i]);
5043
5044 if ((i + 1) < orderByConditionFields.length) {
5045 if (orderByComparator.isAscending() ^ previous) {
5046 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5047 }
5048 else {
5049 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5050 }
5051 }
5052 else {
5053 if (orderByComparator.isAscending() ^ previous) {
5054 query.append(WHERE_GREATER_THAN);
5055 }
5056 else {
5057 query.append(WHERE_LESSER_THAN);
5058 }
5059 }
5060 }
5061
5062 query.append(ORDER_BY_CLAUSE);
5063
5064 String[] orderByFields = orderByComparator.getOrderByFields();
5065
5066 for (int i = 0; i < orderByFields.length; i++) {
5067 query.append(_ORDER_BY_ENTITY_ALIAS);
5068 query.append(orderByFields[i]);
5069
5070 if ((i + 1) < orderByFields.length) {
5071 if (orderByComparator.isAscending() ^ previous) {
5072 query.append(ORDER_BY_ASC_HAS_NEXT);
5073 }
5074 else {
5075 query.append(ORDER_BY_DESC_HAS_NEXT);
5076 }
5077 }
5078 else {
5079 if (orderByComparator.isAscending() ^ previous) {
5080 query.append(ORDER_BY_ASC);
5081 }
5082 else {
5083 query.append(ORDER_BY_DESC);
5084 }
5085 }
5086 }
5087 }
5088 else {
5089 query.append(RoleModelImpl.ORDER_BY_JPQL);
5090 }
5091
5092 String sql = query.toString();
5093
5094 Query q = session.createQuery(sql);
5095
5096 q.setFirstResult(0);
5097 q.setMaxResults(2);
5098
5099 QueryPos qPos = QueryPos.getInstance(q);
5100
5101 if (bindSubtype) {
5102 qPos.add(subtype);
5103 }
5104
5105 if (orderByComparator != null) {
5106 Object[] values = orderByComparator.getOrderByConditionValues(role);
5107
5108 for (Object value : values) {
5109 qPos.add(value);
5110 }
5111 }
5112
5113 List<Role> list = q.list();
5114
5115 if (list.size() == 2) {
5116 return list.get(1);
5117 }
5118 else {
5119 return null;
5120 }
5121 }
5122
5123
5129 @Override
5130 public List<Role> filterFindBySubtype(String subtype) {
5131 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
5132 QueryUtil.ALL_POS, null);
5133 }
5134
5135
5147 @Override
5148 public List<Role> filterFindBySubtype(String subtype, int start, int end) {
5149 return filterFindBySubtype(subtype, start, end, null);
5150 }
5151
5152
5165 @Override
5166 public List<Role> filterFindBySubtype(String subtype, int start, int end,
5167 OrderByComparator<Role> orderByComparator) {
5168 if (!InlineSQLHelperUtil.isEnabled()) {
5169 return findBySubtype(subtype, start, end, orderByComparator);
5170 }
5171
5172 StringBundler query = null;
5173
5174 if (orderByComparator != null) {
5175 query = new StringBundler(3 +
5176 (orderByComparator.getOrderByFields().length * 2));
5177 }
5178 else {
5179 query = new StringBundler(4);
5180 }
5181
5182 if (getDB().isSupportsInlineDistinct()) {
5183 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5184 }
5185 else {
5186 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5187 }
5188
5189 boolean bindSubtype = false;
5190
5191 if (subtype == null) {
5192 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5193 }
5194 else if (subtype.equals(StringPool.BLANK)) {
5195 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5196 }
5197 else {
5198 bindSubtype = true;
5199
5200 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5201 }
5202
5203 if (!getDB().isSupportsInlineDistinct()) {
5204 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5205 }
5206
5207 if (orderByComparator != null) {
5208 if (getDB().isSupportsInlineDistinct()) {
5209 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5210 orderByComparator, true);
5211 }
5212 else {
5213 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5214 orderByComparator, true);
5215 }
5216 }
5217 else {
5218 if (getDB().isSupportsInlineDistinct()) {
5219 query.append(RoleModelImpl.ORDER_BY_JPQL);
5220 }
5221 else {
5222 query.append(RoleModelImpl.ORDER_BY_SQL);
5223 }
5224 }
5225
5226 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5227 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5228
5229 Session session = null;
5230
5231 try {
5232 session = openSession();
5233
5234 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5235
5236 if (getDB().isSupportsInlineDistinct()) {
5237 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5238 }
5239 else {
5240 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5241 }
5242
5243 QueryPos qPos = QueryPos.getInstance(q);
5244
5245 if (bindSubtype) {
5246 qPos.add(subtype);
5247 }
5248
5249 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
5250 }
5251 catch (Exception e) {
5252 throw processException(e);
5253 }
5254 finally {
5255 closeSession(session);
5256 }
5257 }
5258
5259
5268 @Override
5269 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
5270 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
5271 if (!InlineSQLHelperUtil.isEnabled()) {
5272 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
5273 }
5274
5275 Role role = findByPrimaryKey(roleId);
5276
5277 Session session = null;
5278
5279 try {
5280 session = openSession();
5281
5282 Role[] array = new RoleImpl[3];
5283
5284 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5285 orderByComparator, true);
5286
5287 array[1] = role;
5288
5289 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5290 orderByComparator, false);
5291
5292 return array;
5293 }
5294 catch (Exception e) {
5295 throw processException(e);
5296 }
5297 finally {
5298 closeSession(session);
5299 }
5300 }
5301
5302 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
5303 String subtype, OrderByComparator<Role> orderByComparator,
5304 boolean previous) {
5305 StringBundler query = null;
5306
5307 if (orderByComparator != null) {
5308 query = new StringBundler(5 +
5309 (orderByComparator.getOrderByConditionFields().length * 3) +
5310 (orderByComparator.getOrderByFields().length * 3));
5311 }
5312 else {
5313 query = new StringBundler(4);
5314 }
5315
5316 if (getDB().isSupportsInlineDistinct()) {
5317 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5318 }
5319 else {
5320 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5321 }
5322
5323 boolean bindSubtype = false;
5324
5325 if (subtype == null) {
5326 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5327 }
5328 else if (subtype.equals(StringPool.BLANK)) {
5329 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5330 }
5331 else {
5332 bindSubtype = true;
5333
5334 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5335 }
5336
5337 if (!getDB().isSupportsInlineDistinct()) {
5338 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5339 }
5340
5341 if (orderByComparator != null) {
5342 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5343
5344 if (orderByConditionFields.length > 0) {
5345 query.append(WHERE_AND);
5346 }
5347
5348 for (int i = 0; i < orderByConditionFields.length; i++) {
5349 if (getDB().isSupportsInlineDistinct()) {
5350 query.append(_ORDER_BY_ENTITY_ALIAS);
5351 }
5352 else {
5353 query.append(_ORDER_BY_ENTITY_TABLE);
5354 }
5355
5356 query.append(orderByConditionFields[i]);
5357
5358 if ((i + 1) < orderByConditionFields.length) {
5359 if (orderByComparator.isAscending() ^ previous) {
5360 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5361 }
5362 else {
5363 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5364 }
5365 }
5366 else {
5367 if (orderByComparator.isAscending() ^ previous) {
5368 query.append(WHERE_GREATER_THAN);
5369 }
5370 else {
5371 query.append(WHERE_LESSER_THAN);
5372 }
5373 }
5374 }
5375
5376 query.append(ORDER_BY_CLAUSE);
5377
5378 String[] orderByFields = orderByComparator.getOrderByFields();
5379
5380 for (int i = 0; i < orderByFields.length; i++) {
5381 if (getDB().isSupportsInlineDistinct()) {
5382 query.append(_ORDER_BY_ENTITY_ALIAS);
5383 }
5384 else {
5385 query.append(_ORDER_BY_ENTITY_TABLE);
5386 }
5387
5388 query.append(orderByFields[i]);
5389
5390 if ((i + 1) < orderByFields.length) {
5391 if (orderByComparator.isAscending() ^ previous) {
5392 query.append(ORDER_BY_ASC_HAS_NEXT);
5393 }
5394 else {
5395 query.append(ORDER_BY_DESC_HAS_NEXT);
5396 }
5397 }
5398 else {
5399 if (orderByComparator.isAscending() ^ previous) {
5400 query.append(ORDER_BY_ASC);
5401 }
5402 else {
5403 query.append(ORDER_BY_DESC);
5404 }
5405 }
5406 }
5407 }
5408 else {
5409 if (getDB().isSupportsInlineDistinct()) {
5410 query.append(RoleModelImpl.ORDER_BY_JPQL);
5411 }
5412 else {
5413 query.append(RoleModelImpl.ORDER_BY_SQL);
5414 }
5415 }
5416
5417 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5418 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5419
5420 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5421
5422 q.setFirstResult(0);
5423 q.setMaxResults(2);
5424
5425 if (getDB().isSupportsInlineDistinct()) {
5426 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5427 }
5428 else {
5429 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5430 }
5431
5432 QueryPos qPos = QueryPos.getInstance(q);
5433
5434 if (bindSubtype) {
5435 qPos.add(subtype);
5436 }
5437
5438 if (orderByComparator != null) {
5439 Object[] values = orderByComparator.getOrderByConditionValues(role);
5440
5441 for (Object value : values) {
5442 qPos.add(value);
5443 }
5444 }
5445
5446 List<Role> list = q.list();
5447
5448 if (list.size() == 2) {
5449 return list.get(1);
5450 }
5451 else {
5452 return null;
5453 }
5454 }
5455
5456
5461 @Override
5462 public void removeBySubtype(String subtype) {
5463 for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
5464 QueryUtil.ALL_POS, null)) {
5465 remove(role);
5466 }
5467 }
5468
5469
5475 @Override
5476 public int countBySubtype(String subtype) {
5477 FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
5478
5479 Object[] finderArgs = new Object[] { subtype };
5480
5481 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5482
5483 if (count == null) {
5484 StringBundler query = new StringBundler(2);
5485
5486 query.append(_SQL_COUNT_ROLE_WHERE);
5487
5488 boolean bindSubtype = false;
5489
5490 if (subtype == null) {
5491 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5492 }
5493 else if (subtype.equals(StringPool.BLANK)) {
5494 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5495 }
5496 else {
5497 bindSubtype = true;
5498
5499 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5500 }
5501
5502 String sql = query.toString();
5503
5504 Session session = null;
5505
5506 try {
5507 session = openSession();
5508
5509 Query q = session.createQuery(sql);
5510
5511 QueryPos qPos = QueryPos.getInstance(q);
5512
5513 if (bindSubtype) {
5514 qPos.add(subtype);
5515 }
5516
5517 count = (Long)q.uniqueResult();
5518
5519 finderCache.putResult(finderPath, finderArgs, count);
5520 }
5521 catch (Exception e) {
5522 finderCache.removeResult(finderPath, finderArgs);
5523
5524 throw processException(e);
5525 }
5526 finally {
5527 closeSession(session);
5528 }
5529 }
5530
5531 return count.intValue();
5532 }
5533
5534
5540 @Override
5541 public int filterCountBySubtype(String subtype) {
5542 if (!InlineSQLHelperUtil.isEnabled()) {
5543 return countBySubtype(subtype);
5544 }
5545
5546 StringBundler query = new StringBundler(2);
5547
5548 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
5549
5550 boolean bindSubtype = false;
5551
5552 if (subtype == null) {
5553 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5554 }
5555 else if (subtype.equals(StringPool.BLANK)) {
5556 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5557 }
5558 else {
5559 bindSubtype = true;
5560
5561 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5562 }
5563
5564 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5565 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5566
5567 Session session = null;
5568
5569 try {
5570 session = openSession();
5571
5572 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5573
5574 q.addScalar(COUNT_COLUMN_NAME,
5575 com.liferay.portal.kernel.dao.orm.Type.LONG);
5576
5577 QueryPos qPos = QueryPos.getInstance(q);
5578
5579 if (bindSubtype) {
5580 qPos.add(subtype);
5581 }
5582
5583 Long count = (Long)q.uniqueResult();
5584
5585 return count.intValue();
5586 }
5587 catch (Exception e) {
5588 throw processException(e);
5589 }
5590 finally {
5591 closeSession(session);
5592 }
5593 }
5594
5595 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5596 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5597 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
5598 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5599 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5600 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5601 new String[] { Long.class.getName(), String.class.getName() },
5602 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5603 RoleModelImpl.NAME_COLUMN_BITMASK);
5604 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5605 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5606 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5607 new String[] { Long.class.getName(), String.class.getName() });
5608
5609
5617 @Override
5618 public Role findByC_N(long companyId, String name)
5619 throws NoSuchRoleException {
5620 Role role = fetchByC_N(companyId, name);
5621
5622 if (role == null) {
5623 StringBundler msg = new StringBundler(6);
5624
5625 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5626
5627 msg.append("companyId=");
5628 msg.append(companyId);
5629
5630 msg.append(", name=");
5631 msg.append(name);
5632
5633 msg.append(StringPool.CLOSE_CURLY_BRACE);
5634
5635 if (_log.isDebugEnabled()) {
5636 _log.debug(msg.toString());
5637 }
5638
5639 throw new NoSuchRoleException(msg.toString());
5640 }
5641
5642 return role;
5643 }
5644
5645
5652 @Override
5653 public Role fetchByC_N(long companyId, String name) {
5654 return fetchByC_N(companyId, name, true);
5655 }
5656
5657
5665 @Override
5666 public Role fetchByC_N(long companyId, String name,
5667 boolean retrieveFromCache) {
5668 Object[] finderArgs = new Object[] { companyId, name };
5669
5670 Object result = null;
5671
5672 if (retrieveFromCache) {
5673 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_N,
5674 finderArgs, this);
5675 }
5676
5677 if (result instanceof Role) {
5678 Role role = (Role)result;
5679
5680 if ((companyId != role.getCompanyId()) ||
5681 !Objects.equals(name, role.getName())) {
5682 result = null;
5683 }
5684 }
5685
5686 if (result == null) {
5687 StringBundler query = new StringBundler(4);
5688
5689 query.append(_SQL_SELECT_ROLE_WHERE);
5690
5691 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5692
5693 boolean bindName = false;
5694
5695 if (name == null) {
5696 query.append(_FINDER_COLUMN_C_N_NAME_1);
5697 }
5698 else if (name.equals(StringPool.BLANK)) {
5699 query.append(_FINDER_COLUMN_C_N_NAME_3);
5700 }
5701 else {
5702 bindName = true;
5703
5704 query.append(_FINDER_COLUMN_C_N_NAME_2);
5705 }
5706
5707 String sql = query.toString();
5708
5709 Session session = null;
5710
5711 try {
5712 session = openSession();
5713
5714 Query q = session.createQuery(sql);
5715
5716 QueryPos qPos = QueryPos.getInstance(q);
5717
5718 qPos.add(companyId);
5719
5720 if (bindName) {
5721 qPos.add(StringUtil.toLowerCase(name));
5722 }
5723
5724 List<Role> list = q.list();
5725
5726 if (list.isEmpty()) {
5727 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, finderArgs,
5728 list);
5729 }
5730 else {
5731 Role role = list.get(0);
5732
5733 result = role;
5734
5735 cacheResult(role);
5736
5737 if ((role.getCompanyId() != companyId) ||
5738 (role.getName() == null) ||
5739 !role.getName().equals(name)) {
5740 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
5741 finderArgs, role);
5742 }
5743 }
5744 }
5745 catch (Exception e) {
5746 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, finderArgs);
5747
5748 throw processException(e);
5749 }
5750 finally {
5751 closeSession(session);
5752 }
5753 }
5754
5755 if (result instanceof List<?>) {
5756 return null;
5757 }
5758 else {
5759 return (Role)result;
5760 }
5761 }
5762
5763
5770 @Override
5771 public Role removeByC_N(long companyId, String name)
5772 throws NoSuchRoleException {
5773 Role role = findByC_N(companyId, name);
5774
5775 return remove(role);
5776 }
5777
5778
5785 @Override
5786 public int countByC_N(long companyId, String name) {
5787 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5788
5789 Object[] finderArgs = new Object[] { companyId, name };
5790
5791 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5792
5793 if (count == null) {
5794 StringBundler query = new StringBundler(3);
5795
5796 query.append(_SQL_COUNT_ROLE_WHERE);
5797
5798 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5799
5800 boolean bindName = false;
5801
5802 if (name == null) {
5803 query.append(_FINDER_COLUMN_C_N_NAME_1);
5804 }
5805 else if (name.equals(StringPool.BLANK)) {
5806 query.append(_FINDER_COLUMN_C_N_NAME_3);
5807 }
5808 else {
5809 bindName = true;
5810
5811 query.append(_FINDER_COLUMN_C_N_NAME_2);
5812 }
5813
5814 String sql = query.toString();
5815
5816 Session session = null;
5817
5818 try {
5819 session = openSession();
5820
5821 Query q = session.createQuery(sql);
5822
5823 QueryPos qPos = QueryPos.getInstance(q);
5824
5825 qPos.add(companyId);
5826
5827 if (bindName) {
5828 qPos.add(StringUtil.toLowerCase(name));
5829 }
5830
5831 count = (Long)q.uniqueResult();
5832
5833 finderCache.putResult(finderPath, finderArgs, count);
5834 }
5835 catch (Exception e) {
5836 finderCache.removeResult(finderPath, finderArgs);
5837
5838 throw processException(e);
5839 }
5840 finally {
5841 closeSession(session);
5842 }
5843 }
5844
5845 return count.intValue();
5846 }
5847
5848 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5849 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5850 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?";
5851 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')";
5852 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5853 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5854 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
5855 new String[] {
5856 Long.class.getName(), Integer.class.getName(),
5857
5858 Integer.class.getName(), Integer.class.getName(),
5859 OrderByComparator.class.getName()
5860 });
5861 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5862 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5863 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
5864 new String[] { Long.class.getName(), Integer.class.getName() },
5865 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5866 RoleModelImpl.TYPE_COLUMN_BITMASK |
5867 RoleModelImpl.NAME_COLUMN_BITMASK);
5868 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5869 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5870 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
5871 new String[] { Long.class.getName(), Integer.class.getName() });
5872 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5873 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5874 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
5875 new String[] { Long.class.getName(), Integer.class.getName() });
5876
5877
5884 @Override
5885 public List<Role> findByC_T(long companyId, int type) {
5886 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5887 null);
5888 }
5889
5890
5903 @Override
5904 public List<Role> findByC_T(long companyId, int type, int start, int end) {
5905 return findByC_T(companyId, type, start, end, null);
5906 }
5907
5908
5922 @Override
5923 public List<Role> findByC_T(long companyId, int type, int start, int end,
5924 OrderByComparator<Role> orderByComparator) {
5925 return findByC_T(companyId, type, start, end, orderByComparator, true);
5926 }
5927
5928
5943 @Override
5944 public List<Role> findByC_T(long companyId, int type, int start, int end,
5945 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
5946 boolean pagination = true;
5947 FinderPath finderPath = null;
5948 Object[] finderArgs = null;
5949
5950 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5951 (orderByComparator == null)) {
5952 pagination = false;
5953 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
5954 finderArgs = new Object[] { companyId, type };
5955 }
5956 else {
5957 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
5958 finderArgs = new Object[] {
5959 companyId, type,
5960
5961 start, end, orderByComparator
5962 };
5963 }
5964
5965 List<Role> list = null;
5966
5967 if (retrieveFromCache) {
5968 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
5969 this);
5970
5971 if ((list != null) && !list.isEmpty()) {
5972 for (Role role : list) {
5973 if ((companyId != role.getCompanyId()) ||
5974 (type != role.getType())) {
5975 list = null;
5976
5977 break;
5978 }
5979 }
5980 }
5981 }
5982
5983 if (list == null) {
5984 StringBundler query = null;
5985
5986 if (orderByComparator != null) {
5987 query = new StringBundler(4 +
5988 (orderByComparator.getOrderByFields().length * 2));
5989 }
5990 else {
5991 query = new StringBundler(4);
5992 }
5993
5994 query.append(_SQL_SELECT_ROLE_WHERE);
5995
5996 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5997
5998 query.append(_FINDER_COLUMN_C_T_TYPE_2);
5999
6000 if (orderByComparator != null) {
6001 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6002 orderByComparator);
6003 }
6004 else
6005 if (pagination) {
6006 query.append(RoleModelImpl.ORDER_BY_JPQL);
6007 }
6008
6009 String sql = query.toString();
6010
6011 Session session = null;
6012
6013 try {
6014 session = openSession();
6015
6016 Query q = session.createQuery(sql);
6017
6018 QueryPos qPos = QueryPos.getInstance(q);
6019
6020 qPos.add(companyId);
6021
6022 qPos.add(type);
6023
6024 if (!pagination) {
6025 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6026 end, false);
6027
6028 Collections.sort(list);
6029
6030 list = Collections.unmodifiableList(list);
6031 }
6032 else {
6033 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6034 end);
6035 }
6036
6037 cacheResult(list);
6038
6039 finderCache.putResult(finderPath, finderArgs, list);
6040 }
6041 catch (Exception e) {
6042 finderCache.removeResult(finderPath, finderArgs);
6043
6044 throw processException(e);
6045 }
6046 finally {
6047 closeSession(session);
6048 }
6049 }
6050
6051 return list;
6052 }
6053
6054
6063 @Override
6064 public Role findByC_T_First(long companyId, int type,
6065 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
6066 Role role = fetchByC_T_First(companyId, type, orderByComparator);
6067
6068 if (role != null) {
6069 return role;
6070 }
6071
6072 StringBundler msg = new StringBundler(6);
6073
6074 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6075
6076 msg.append("companyId=");
6077 msg.append(companyId);
6078
6079 msg.append(", type=");
6080 msg.append(type);
6081
6082 msg.append(StringPool.CLOSE_CURLY_BRACE);
6083
6084 throw new NoSuchRoleException(msg.toString());
6085 }
6086
6087
6095 @Override
6096 public Role fetchByC_T_First(long companyId, int type,
6097 OrderByComparator<Role> orderByComparator) {
6098 List<Role> list = findByC_T(companyId, type, 0, 1, orderByComparator);
6099
6100 if (!list.isEmpty()) {
6101 return list.get(0);
6102 }
6103
6104 return null;
6105 }
6106
6107
6116 @Override
6117 public Role findByC_T_Last(long companyId, int type,
6118 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
6119 Role role = fetchByC_T_Last(companyId, type, orderByComparator);
6120
6121 if (role != null) {
6122 return role;
6123 }
6124
6125 StringBundler msg = new StringBundler(6);
6126
6127 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6128
6129 msg.append("companyId=");
6130 msg.append(companyId);
6131
6132 msg.append(", type=");
6133 msg.append(type);
6134
6135 msg.append(StringPool.CLOSE_CURLY_BRACE);
6136
6137 throw new NoSuchRoleException(msg.toString());
6138 }
6139
6140
6148 @Override
6149 public Role fetchByC_T_Last(long companyId, int type,
6150 OrderByComparator<Role> orderByComparator) {
6151 int count = countByC_T(companyId, type);
6152
6153 if (count == 0) {
6154 return null;
6155 }
6156
6157 List<Role> list = findByC_T(companyId, type, count - 1, count,
6158 orderByComparator);
6159
6160 if (!list.isEmpty()) {
6161 return list.get(0);
6162 }
6163
6164 return null;
6165 }
6166
6167
6177 @Override
6178 public Role[] findByC_T_PrevAndNext(long roleId, long companyId, int type,
6179 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
6180 Role role = findByPrimaryKey(roleId);
6181
6182 Session session = null;
6183
6184 try {
6185 session = openSession();
6186
6187 Role[] array = new RoleImpl[3];
6188
6189 array[0] = getByC_T_PrevAndNext(session, role, companyId, type,
6190 orderByComparator, true);
6191
6192 array[1] = role;
6193
6194 array[2] = getByC_T_PrevAndNext(session, role, companyId, type,
6195 orderByComparator, false);
6196
6197 return array;
6198 }
6199 catch (Exception e) {
6200 throw processException(e);
6201 }
6202 finally {
6203 closeSession(session);
6204 }
6205 }
6206
6207 protected Role getByC_T_PrevAndNext(Session session, Role role,
6208 long companyId, int type, OrderByComparator<Role> orderByComparator,
6209 boolean previous) {
6210 StringBundler query = null;
6211
6212 if (orderByComparator != null) {
6213 query = new StringBundler(5 +
6214 (orderByComparator.getOrderByConditionFields().length * 3) +
6215 (orderByComparator.getOrderByFields().length * 3));
6216 }
6217 else {
6218 query = new StringBundler(4);
6219 }
6220
6221 query.append(_SQL_SELECT_ROLE_WHERE);
6222
6223 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6224
6225 query.append(_FINDER_COLUMN_C_T_TYPE_2);
6226
6227 if (orderByComparator != null) {
6228 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6229
6230 if (orderByConditionFields.length > 0) {
6231 query.append(WHERE_AND);
6232 }
6233
6234 for (int i = 0; i < orderByConditionFields.length; i++) {
6235 query.append(_ORDER_BY_ENTITY_ALIAS);
6236 query.append(orderByConditionFields[i]);
6237
6238 if ((i + 1) < orderByConditionFields.length) {
6239 if (orderByComparator.isAscending() ^ previous) {
6240 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6241 }
6242 else {
6243 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6244 }
6245 }
6246 else {
6247 if (orderByComparator.isAscending() ^ previous) {
6248 query.append(WHERE_GREATER_THAN);
6249 }
6250 else {
6251 query.append(WHERE_LESSER_THAN);
6252 }
6253 }
6254 }
6255
6256 query.append(ORDER_BY_CLAUSE);
6257
6258 String[] orderByFields = orderByComparator.getOrderByFields();
6259
6260 for (int i = 0; i < orderByFields.length; i++) {
6261 query.append(_ORDER_BY_ENTITY_ALIAS);
6262 query.append(orderByFields[i]);
6263
6264 if ((i + 1) < orderByFields.length) {
6265 if (orderByComparator.isAscending() ^ previous) {
6266 query.append(ORDER_BY_ASC_HAS_NEXT);
6267 }
6268 else {
6269 query.append(ORDER_BY_DESC_HAS_NEXT);
6270 }
6271 }
6272 else {
6273 if (orderByComparator.isAscending() ^ previous) {
6274 query.append(ORDER_BY_ASC);
6275 }
6276 else {
6277 query.append(ORDER_BY_DESC);
6278 }
6279 }
6280 }
6281 }
6282 else {
6283 query.append(RoleModelImpl.ORDER_BY_JPQL);
6284 }
6285
6286 String sql = query.toString();
6287
6288 Query q = session.createQuery(sql);
6289
6290 q.setFirstResult(0);
6291 q.setMaxResults(2);
6292
6293 QueryPos qPos = QueryPos.getInstance(q);
6294
6295 qPos.add(companyId);
6296
6297 qPos.add(type);
6298
6299 if (orderByComparator != null) {
6300 Object[] values = orderByComparator.getOrderByConditionValues(role);
6301
6302 for (Object value : values) {
6303 qPos.add(value);
6304 }
6305 }
6306
6307 List<Role> list = q.list();
6308
6309 if (list.size() == 2) {
6310 return list.get(1);
6311 }
6312 else {
6313 return null;
6314 }
6315 }
6316
6317
6324 @Override
6325 public List<Role> filterFindByC_T(long companyId, int type) {
6326 return filterFindByC_T(companyId, type, QueryUtil.ALL_POS,
6327 QueryUtil.ALL_POS, null);
6328 }
6329
6330
6343 @Override
6344 public List<Role> filterFindByC_T(long companyId, int type, int start,
6345 int end) {
6346 return filterFindByC_T(companyId, type, start, end, null);
6347 }
6348
6349
6363 @Override
6364 public List<Role> filterFindByC_T(long companyId, int type, int start,
6365 int end, OrderByComparator<Role> orderByComparator) {
6366 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
6367 return findByC_T(companyId, type, start, end, orderByComparator);
6368 }
6369
6370 StringBundler query = null;
6371
6372 if (orderByComparator != null) {
6373 query = new StringBundler(4 +
6374 (orderByComparator.getOrderByFields().length * 2));
6375 }
6376 else {
6377 query = new StringBundler(5);
6378 }
6379
6380 if (getDB().isSupportsInlineDistinct()) {
6381 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6382 }
6383 else {
6384 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6385 }
6386
6387 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6388
6389 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6390
6391 if (!getDB().isSupportsInlineDistinct()) {
6392 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6393 }
6394
6395 if (orderByComparator != null) {
6396 if (getDB().isSupportsInlineDistinct()) {
6397 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6398 orderByComparator, true);
6399 }
6400 else {
6401 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6402 orderByComparator, true);
6403 }
6404 }
6405 else {
6406 if (getDB().isSupportsInlineDistinct()) {
6407 query.append(RoleModelImpl.ORDER_BY_JPQL);
6408 }
6409 else {
6410 query.append(RoleModelImpl.ORDER_BY_SQL);
6411 }
6412 }
6413
6414 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6415 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6416
6417 Session session = null;
6418
6419 try {
6420 session = openSession();
6421
6422 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6423
6424 if (getDB().isSupportsInlineDistinct()) {
6425 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6426 }
6427 else {
6428 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6429 }
6430
6431 QueryPos qPos = QueryPos.getInstance(q);
6432
6433 qPos.add(companyId);
6434
6435 qPos.add(type);
6436
6437 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6438 }
6439 catch (Exception e) {
6440 throw processException(e);
6441 }
6442 finally {
6443 closeSession(session);
6444 }
6445 }
6446
6447
6457 @Override
6458 public Role[] filterFindByC_T_PrevAndNext(long roleId, long companyId,
6459 int type, OrderByComparator<Role> orderByComparator)
6460 throws NoSuchRoleException {
6461 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
6462 return findByC_T_PrevAndNext(roleId, companyId, type,
6463 orderByComparator);
6464 }
6465
6466 Role role = findByPrimaryKey(roleId);
6467
6468 Session session = null;
6469
6470 try {
6471 session = openSession();
6472
6473 Role[] array = new RoleImpl[3];
6474
6475 array[0] = filterGetByC_T_PrevAndNext(session, role, companyId,
6476 type, orderByComparator, true);
6477
6478 array[1] = role;
6479
6480 array[2] = filterGetByC_T_PrevAndNext(session, role, companyId,
6481 type, orderByComparator, false);
6482
6483 return array;
6484 }
6485 catch (Exception e) {
6486 throw processException(e);
6487 }
6488 finally {
6489 closeSession(session);
6490 }
6491 }
6492
6493 protected Role filterGetByC_T_PrevAndNext(Session session, Role role,
6494 long companyId, int type, OrderByComparator<Role> orderByComparator,
6495 boolean previous) {
6496 StringBundler query = null;
6497
6498 if (orderByComparator != null) {
6499 query = new StringBundler(6 +
6500 (orderByComparator.getOrderByConditionFields().length * 3) +
6501 (orderByComparator.getOrderByFields().length * 3));
6502 }
6503 else {
6504 query = new StringBundler(5);
6505 }
6506
6507 if (getDB().isSupportsInlineDistinct()) {
6508 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6509 }
6510 else {
6511 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6512 }
6513
6514 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6515
6516 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6517
6518 if (!getDB().isSupportsInlineDistinct()) {
6519 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6520 }
6521
6522 if (orderByComparator != null) {
6523 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6524
6525 if (orderByConditionFields.length > 0) {
6526 query.append(WHERE_AND);
6527 }
6528
6529 for (int i = 0; i < orderByConditionFields.length; i++) {
6530 if (getDB().isSupportsInlineDistinct()) {
6531 query.append(_ORDER_BY_ENTITY_ALIAS);
6532 }
6533 else {
6534 query.append(_ORDER_BY_ENTITY_TABLE);
6535 }
6536
6537 query.append(orderByConditionFields[i]);
6538
6539 if ((i + 1) < orderByConditionFields.length) {
6540 if (orderByComparator.isAscending() ^ previous) {
6541 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6542 }
6543 else {
6544 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6545 }
6546 }
6547 else {
6548 if (orderByComparator.isAscending() ^ previous) {
6549 query.append(WHERE_GREATER_THAN);
6550 }
6551 else {
6552 query.append(WHERE_LESSER_THAN);
6553 }
6554 }
6555 }
6556
6557 query.append(ORDER_BY_CLAUSE);
6558
6559 String[] orderByFields = orderByComparator.getOrderByFields();
6560
6561 for (int i = 0; i < orderByFields.length; i++) {
6562 if (getDB().isSupportsInlineDistinct()) {
6563 query.append(_ORDER_BY_ENTITY_ALIAS);
6564 }
6565 else {
6566 query.append(_ORDER_BY_ENTITY_TABLE);
6567 }
6568
6569 query.append(orderByFields[i]);
6570
6571 if ((i + 1) < orderByFields.length) {
6572 if (orderByComparator.isAscending() ^ previous) {
6573 query.append(ORDER_BY_ASC_HAS_NEXT);
6574 }
6575 else {
6576 query.append(ORDER_BY_DESC_HAS_NEXT);
6577 }
6578 }
6579 else {
6580 if (orderByComparator.isAscending() ^ previous) {
6581 query.append(ORDER_BY_ASC);
6582 }
6583 else {
6584 query.append(ORDER_BY_DESC);
6585 }
6586 }
6587 }
6588 }
6589 else {
6590 if (getDB().isSupportsInlineDistinct()) {
6591 query.append(RoleModelImpl.ORDER_BY_JPQL);
6592 }
6593 else {
6594 query.append(RoleModelImpl.ORDER_BY_SQL);
6595 }
6596 }
6597
6598 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6599 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6600
6601 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6602
6603 q.setFirstResult(0);
6604 q.setMaxResults(2);
6605
6606 if (getDB().isSupportsInlineDistinct()) {
6607 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6608 }
6609 else {
6610 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6611 }
6612
6613 QueryPos qPos = QueryPos.getInstance(q);
6614
6615 qPos.add(companyId);
6616
6617 qPos.add(type);
6618
6619 if (orderByComparator != null) {
6620 Object[] values = orderByComparator.getOrderByConditionValues(role);
6621
6622 for (Object value : values) {
6623 qPos.add(value);
6624 }
6625 }
6626
6627 List<Role> list = q.list();
6628
6629 if (list.size() == 2) {
6630 return list.get(1);
6631 }
6632 else {
6633 return null;
6634 }
6635 }
6636
6637
6644 @Override
6645 public List<Role> filterFindByC_T(long companyId, int[] types) {
6646 return filterFindByC_T(companyId, types, QueryUtil.ALL_POS,
6647 QueryUtil.ALL_POS, null);
6648 }
6649
6650
6663 @Override
6664 public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6665 int end) {
6666 return filterFindByC_T(companyId, types, start, end, null);
6667 }
6668
6669
6683 @Override
6684 public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6685 int end, OrderByComparator<Role> orderByComparator) {
6686 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
6687 return findByC_T(companyId, types, start, end, orderByComparator);
6688 }
6689
6690 if (types == null) {
6691 types = new int[0];
6692 }
6693 else if (types.length > 1) {
6694 types = ArrayUtil.unique(types);
6695
6696 Arrays.sort(types);
6697 }
6698
6699 StringBundler query = new StringBundler();
6700
6701 if (getDB().isSupportsInlineDistinct()) {
6702 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6703 }
6704 else {
6705 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6706 }
6707
6708 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6709
6710 if (types.length > 0) {
6711 query.append(StringPool.OPEN_PARENTHESIS);
6712
6713 query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL);
6714
6715 query.append(StringUtil.merge(types));
6716
6717 query.append(StringPool.CLOSE_PARENTHESIS);
6718
6719 query.append(StringPool.CLOSE_PARENTHESIS);
6720 }
6721
6722 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6723 query.index() - 1);
6724
6725 if (!getDB().isSupportsInlineDistinct()) {
6726 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6727 }
6728
6729 if (orderByComparator != null) {
6730 if (getDB().isSupportsInlineDistinct()) {
6731 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6732 orderByComparator, true);
6733 }
6734 else {
6735 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6736 orderByComparator, true);
6737 }
6738 }
6739 else {
6740 if (getDB().isSupportsInlineDistinct()) {
6741 query.append(RoleModelImpl.ORDER_BY_JPQL);
6742 }
6743 else {
6744 query.append(RoleModelImpl.ORDER_BY_SQL);
6745 }
6746 }
6747
6748 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6749 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6750
6751 Session session = null;
6752
6753 try {
6754 session = openSession();
6755
6756 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6757
6758 if (getDB().isSupportsInlineDistinct()) {
6759 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6760 }
6761 else {
6762 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6763 }
6764
6765 QueryPos qPos = QueryPos.getInstance(q);
6766
6767 qPos.add(companyId);
6768
6769 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6770 }
6771 catch (Exception e) {
6772 throw processException(e);
6773 }
6774 finally {
6775 closeSession(session);
6776 }
6777 }
6778
6779
6790 @Override
6791 public List<Role> findByC_T(long companyId, int[] types) {
6792 return findByC_T(companyId, types, QueryUtil.ALL_POS,
6793 QueryUtil.ALL_POS, null);
6794 }
6795
6796
6809 @Override
6810 public List<Role> findByC_T(long companyId, int[] types, int start, int end) {
6811 return findByC_T(companyId, types, start, end, null);
6812 }
6813
6814
6828 @Override
6829 public List<Role> findByC_T(long companyId, int[] types, int start,
6830 int end, OrderByComparator<Role> orderByComparator) {
6831 return findByC_T(companyId, types, start, end, orderByComparator, true);
6832 }
6833
6834
6849 @Override
6850 public List<Role> findByC_T(long companyId, int[] types, int start,
6851 int end, OrderByComparator<Role> orderByComparator,
6852 boolean retrieveFromCache) {
6853 if (types == null) {
6854 types = new int[0];
6855 }
6856 else if (types.length > 1) {
6857 types = ArrayUtil.unique(types);
6858
6859 Arrays.sort(types);
6860 }
6861
6862 if (types.length == 1) {
6863 return findByC_T(companyId, types[0], start, end, orderByComparator);
6864 }
6865
6866 boolean pagination = true;
6867 Object[] finderArgs = null;
6868
6869 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6870 (orderByComparator == null)) {
6871 pagination = false;
6872 finderArgs = new Object[] { companyId, StringUtil.merge(types) };
6873 }
6874 else {
6875 finderArgs = new Object[] {
6876 companyId, StringUtil.merge(types),
6877
6878 start, end, orderByComparator
6879 };
6880 }
6881
6882 List<Role> list = null;
6883
6884 if (retrieveFromCache) {
6885 list = (List<Role>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6886 finderArgs, this);
6887
6888 if ((list != null) && !list.isEmpty()) {
6889 for (Role role : list) {
6890 if ((companyId != role.getCompanyId()) ||
6891 !ArrayUtil.contains(types, role.getType())) {
6892 list = null;
6893
6894 break;
6895 }
6896 }
6897 }
6898 }
6899
6900 if (list == null) {
6901 StringBundler query = new StringBundler();
6902
6903 query.append(_SQL_SELECT_ROLE_WHERE);
6904
6905 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6906
6907 if (types.length > 0) {
6908 query.append(StringPool.OPEN_PARENTHESIS);
6909
6910 query.append(_FINDER_COLUMN_C_T_TYPE_7);
6911
6912 query.append(StringUtil.merge(types));
6913
6914 query.append(StringPool.CLOSE_PARENTHESIS);
6915
6916 query.append(StringPool.CLOSE_PARENTHESIS);
6917 }
6918
6919 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6920 1)), query.index() - 1);
6921
6922 if (orderByComparator != null) {
6923 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6924 orderByComparator);
6925 }
6926 else
6927 if (pagination) {
6928 query.append(RoleModelImpl.ORDER_BY_JPQL);
6929 }
6930
6931 String sql = query.toString();
6932
6933 Session session = null;
6934
6935 try {
6936 session = openSession();
6937
6938 Query q = session.createQuery(sql);
6939
6940 QueryPos qPos = QueryPos.getInstance(q);
6941
6942 qPos.add(companyId);
6943
6944 if (!pagination) {
6945 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6946 end, false);
6947
6948 Collections.sort(list);
6949
6950 list = Collections.unmodifiableList(list);
6951 }
6952 else {
6953 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6954 end);
6955 }
6956
6957 cacheResult(list);
6958
6959 finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6960 finderArgs, list);
6961 }
6962 catch (Exception e) {
6963 finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6964 finderArgs);
6965
6966 throw processException(e);
6967 }
6968 finally {
6969 closeSession(session);
6970 }
6971 }
6972
6973 return list;
6974 }
6975
6976
6982 @Override
6983 public void removeByC_T(long companyId, int type) {
6984 for (Role role : findByC_T(companyId, type, QueryUtil.ALL_POS,
6985 QueryUtil.ALL_POS, null)) {
6986 remove(role);
6987 }
6988 }
6989
6990
6997 @Override
6998 public int countByC_T(long companyId, int type) {
6999 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
7000
7001 Object[] finderArgs = new Object[] { companyId, type };
7002
7003 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
7004
7005 if (count == null) {
7006 StringBundler query = new StringBundler(3);
7007
7008 query.append(_SQL_COUNT_ROLE_WHERE);
7009
7010 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7011
7012 query.append(_FINDER_COLUMN_C_T_TYPE_2);
7013
7014 String sql = query.toString();
7015
7016 Session session = null;
7017
7018 try {
7019 session = openSession();
7020
7021 Query q = session.createQuery(sql);
7022
7023 QueryPos qPos = QueryPos.getInstance(q);
7024
7025 qPos.add(companyId);
7026
7027 qPos.add(type);
7028
7029 count = (Long)q.uniqueResult();
7030
7031 finderCache.putResult(finderPath, finderArgs, count);
7032 }
7033 catch (Exception e) {
7034 finderCache.removeResult(finderPath, finderArgs);
7035
7036 throw processException(e);
7037 }
7038 finally {
7039 closeSession(session);
7040 }
7041 }
7042
7043 return count.intValue();
7044 }
7045
7046
7053 @Override
7054 public int countByC_T(long companyId, int[] types) {
7055 if (types == null) {
7056 types = new int[0];
7057 }
7058 else if (types.length > 1) {
7059 types = ArrayUtil.unique(types);
7060
7061 Arrays.sort(types);
7062 }
7063
7064 Object[] finderArgs = new Object[] { companyId, StringUtil.merge(types) };
7065
7066 Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7067 finderArgs, this);
7068
7069 if (count == null) {
7070 StringBundler query = new StringBundler();
7071
7072 query.append(_SQL_COUNT_ROLE_WHERE);
7073
7074 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7075
7076 if (types.length > 0) {
7077 query.append(StringPool.OPEN_PARENTHESIS);
7078
7079 query.append(_FINDER_COLUMN_C_T_TYPE_7);
7080
7081 query.append(StringUtil.merge(types));
7082
7083 query.append(StringPool.CLOSE_PARENTHESIS);
7084
7085 query.append(StringPool.CLOSE_PARENTHESIS);
7086 }
7087
7088 query.setStringAt(removeConjunction(query.stringAt(query.index() -
7089 1)), query.index() - 1);
7090
7091 String sql = query.toString();
7092
7093 Session session = null;
7094
7095 try {
7096 session = openSession();
7097
7098 Query q = session.createQuery(sql);
7099
7100 QueryPos qPos = QueryPos.getInstance(q);
7101
7102 qPos.add(companyId);
7103
7104 count = (Long)q.uniqueResult();
7105
7106 finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7107 finderArgs, count);
7108 }
7109 catch (Exception e) {
7110 finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7111 finderArgs);
7112
7113 throw processException(e);
7114 }
7115 finally {
7116 closeSession(session);
7117 }
7118 }
7119
7120 return count.intValue();
7121 }
7122
7123
7130 @Override
7131 public int filterCountByC_T(long companyId, int type) {
7132 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
7133 return countByC_T(companyId, type);
7134 }
7135
7136 StringBundler query = new StringBundler(3);
7137
7138 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7139
7140 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7141
7142 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
7143
7144 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7145 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7146
7147 Session session = null;
7148
7149 try {
7150 session = openSession();
7151
7152 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7153
7154 q.addScalar(COUNT_COLUMN_NAME,
7155 com.liferay.portal.kernel.dao.orm.Type.LONG);
7156
7157 QueryPos qPos = QueryPos.getInstance(q);
7158
7159 qPos.add(companyId);
7160
7161 qPos.add(type);
7162
7163 Long count = (Long)q.uniqueResult();
7164
7165 return count.intValue();
7166 }
7167 catch (Exception e) {
7168 throw processException(e);
7169 }
7170 finally {
7171 closeSession(session);
7172 }
7173 }
7174
7175
7182 @Override
7183 public int filterCountByC_T(long companyId, int[] types) {
7184 if (!InlineSQLHelperUtil.isEnabled(companyId, 0)) {
7185 return countByC_T(companyId, types);
7186 }
7187
7188 if (types == null) {
7189 types = new int[0];
7190 }
7191 else if (types.length > 1) {
7192 types = ArrayUtil.unique(types);
7193
7194 Arrays.sort(types);
7195 }
7196
7197 StringBundler query = new StringBundler();
7198
7199 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7200
7201 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7202
7203 if (types.length > 0) {
7204 query.append(StringPool.OPEN_PARENTHESIS);
7205
7206 query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL);
7207
7208 query.append(StringUtil.merge(types));
7209
7210 query.append(StringPool.CLOSE_PARENTHESIS);
7211
7212 query.append(StringPool.CLOSE_PARENTHESIS);
7213 }
7214
7215 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
7216 query.index() - 1);
7217
7218 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7219 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7220
7221 Session session = null;
7222
7223 try {
7224 session = openSession();
7225
7226 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7227
7228 q.addScalar(COUNT_COLUMN_NAME,
7229 com.liferay.portal.kernel.dao.orm.Type.LONG);
7230
7231 QueryPos qPos = QueryPos.getInstance(q);
7232
7233 qPos.add(companyId);
7234
7235 Long count = (Long)q.uniqueResult();
7236
7237 return count.intValue();
7238 }
7239 catch (Exception e) {
7240 throw processException(e);
7241 }
7242 finally {
7243 closeSession(session);
7244 }
7245 }
7246
7247 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "role.companyId = ? AND ";
7248 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "role.type = ?";
7249 private static final String _FINDER_COLUMN_C_T_TYPE_7 = "role.type IN (";
7250 private static final String _FINDER_COLUMN_C_T_TYPE_2_SQL = "role.type_ = ?";
7251 private static final String _FINDER_COLUMN_C_T_TYPE_7_SQL = "role.type_ IN (";
7252 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7253 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7254 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
7255 new String[] {
7256 Integer.class.getName(), String.class.getName(),
7257
7258 Integer.class.getName(), Integer.class.getName(),
7259 OrderByComparator.class.getName()
7260 });
7261 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7262 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7263 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
7264 new String[] { Integer.class.getName(), String.class.getName() },
7265 RoleModelImpl.TYPE_COLUMN_BITMASK |
7266 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
7267 RoleModelImpl.NAME_COLUMN_BITMASK);
7268 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7269 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7270 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
7271 new String[] { Integer.class.getName(), String.class.getName() });
7272
7273
7280 @Override
7281 public List<Role> findByT_S(int type, String subtype) {
7282 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7283 null);
7284 }
7285
7286
7299 @Override
7300 public List<Role> findByT_S(int type, String subtype, int start, int end) {
7301 return findByT_S(type, subtype, start, end, null);
7302 }
7303
7304
7318 @Override
7319 public List<Role> findByT_S(int type, String subtype, int start, int end,
7320 OrderByComparator<Role> orderByComparator) {
7321 return findByT_S(type, subtype, start, end, orderByComparator, true);
7322 }
7323
7324
7339 @Override
7340 public List<Role> findByT_S(int type, String subtype, int start, int end,
7341 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
7342 boolean pagination = true;
7343 FinderPath finderPath = null;
7344 Object[] finderArgs = null;
7345
7346 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7347 (orderByComparator == null)) {
7348 pagination = false;
7349 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
7350 finderArgs = new Object[] { type, subtype };
7351 }
7352 else {
7353 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
7354 finderArgs = new Object[] {
7355 type, subtype,
7356
7357 start, end, orderByComparator
7358 };
7359 }
7360
7361 List<Role> list = null;
7362
7363 if (retrieveFromCache) {
7364 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
7365 this);
7366
7367 if ((list != null) && !list.isEmpty()) {
7368 for (Role role : list) {
7369 if ((type != role.getType()) ||
7370 !Objects.equals(subtype, role.getSubtype())) {
7371 list = null;
7372
7373 break;
7374 }
7375 }
7376 }
7377 }
7378
7379 if (list == null) {
7380 StringBundler query = null;
7381
7382 if (orderByComparator != null) {
7383 query = new StringBundler(4 +
7384 (orderByComparator.getOrderByFields().length * 2));
7385 }
7386 else {
7387 query = new StringBundler(4);
7388 }
7389
7390 query.append(_SQL_SELECT_ROLE_WHERE);
7391
7392 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7393
7394 boolean bindSubtype = false;
7395
7396 if (subtype == null) {
7397 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7398 }
7399 else if (subtype.equals(StringPool.BLANK)) {
7400 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7401 }
7402 else {
7403 bindSubtype = true;
7404
7405 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7406 }
7407
7408 if (orderByComparator != null) {
7409 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7410 orderByComparator);
7411 }
7412 else
7413 if (pagination) {
7414 query.append(RoleModelImpl.ORDER_BY_JPQL);
7415 }
7416
7417 String sql = query.toString();
7418
7419 Session session = null;
7420
7421 try {
7422 session = openSession();
7423
7424 Query q = session.createQuery(sql);
7425
7426 QueryPos qPos = QueryPos.getInstance(q);
7427
7428 qPos.add(type);
7429
7430 if (bindSubtype) {
7431 qPos.add(subtype);
7432 }
7433
7434 if (!pagination) {
7435 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7436 end, false);
7437
7438 Collections.sort(list);
7439
7440 list = Collections.unmodifiableList(list);
7441 }
7442 else {
7443 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7444 end);
7445 }
7446
7447 cacheResult(list);
7448
7449 finderCache.putResult(finderPath, finderArgs, list);
7450 }
7451 catch (Exception e) {
7452 finderCache.removeResult(finderPath, finderArgs);
7453
7454 throw processException(e);
7455 }
7456 finally {
7457 closeSession(session);
7458 }
7459 }
7460
7461 return list;
7462 }
7463
7464
7473 @Override
7474 public Role findByT_S_First(int type, String subtype,
7475 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7476 Role role = fetchByT_S_First(type, subtype, orderByComparator);
7477
7478 if (role != null) {
7479 return role;
7480 }
7481
7482 StringBundler msg = new StringBundler(6);
7483
7484 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7485
7486 msg.append("type=");
7487 msg.append(type);
7488
7489 msg.append(", subtype=");
7490 msg.append(subtype);
7491
7492 msg.append(StringPool.CLOSE_CURLY_BRACE);
7493
7494 throw new NoSuchRoleException(msg.toString());
7495 }
7496
7497
7505 @Override
7506 public Role fetchByT_S_First(int type, String subtype,
7507 OrderByComparator<Role> orderByComparator) {
7508 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
7509
7510 if (!list.isEmpty()) {
7511 return list.get(0);
7512 }
7513
7514 return null;
7515 }
7516
7517
7526 @Override
7527 public Role findByT_S_Last(int type, String subtype,
7528 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7529 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
7530
7531 if (role != null) {
7532 return role;
7533 }
7534
7535 StringBundler msg = new StringBundler(6);
7536
7537 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7538
7539 msg.append("type=");
7540 msg.append(type);
7541
7542 msg.append(", subtype=");
7543 msg.append(subtype);
7544
7545 msg.append(StringPool.CLOSE_CURLY_BRACE);
7546
7547 throw new NoSuchRoleException(msg.toString());
7548 }
7549
7550
7558 @Override
7559 public Role fetchByT_S_Last(int type, String subtype,
7560 OrderByComparator<Role> orderByComparator) {
7561 int count = countByT_S(type, subtype);
7562
7563 if (count == 0) {
7564 return null;
7565 }
7566
7567 List<Role> list = findByT_S(type, subtype, count - 1, count,
7568 orderByComparator);
7569
7570 if (!list.isEmpty()) {
7571 return list.get(0);
7572 }
7573
7574 return null;
7575 }
7576
7577
7587 @Override
7588 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
7589 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7590 Role role = findByPrimaryKey(roleId);
7591
7592 Session session = null;
7593
7594 try {
7595 session = openSession();
7596
7597 Role[] array = new RoleImpl[3];
7598
7599 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
7600 orderByComparator, true);
7601
7602 array[1] = role;
7603
7604 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
7605 orderByComparator, false);
7606
7607 return array;
7608 }
7609 catch (Exception e) {
7610 throw processException(e);
7611 }
7612 finally {
7613 closeSession(session);
7614 }
7615 }
7616
7617 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
7618 String subtype, OrderByComparator<Role> orderByComparator,
7619 boolean previous) {
7620 StringBundler query = null;
7621
7622 if (orderByComparator != null) {
7623 query = new StringBundler(5 +
7624 (orderByComparator.getOrderByConditionFields().length * 3) +
7625 (orderByComparator.getOrderByFields().length * 3));
7626 }
7627 else {
7628 query = new StringBundler(4);
7629 }
7630
7631 query.append(_SQL_SELECT_ROLE_WHERE);
7632
7633 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7634
7635 boolean bindSubtype = false;
7636
7637 if (subtype == null) {
7638 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7639 }
7640 else if (subtype.equals(StringPool.BLANK)) {
7641 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7642 }
7643 else {
7644 bindSubtype = true;
7645
7646 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7647 }
7648
7649 if (orderByComparator != null) {
7650 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7651
7652 if (orderByConditionFields.length > 0) {
7653 query.append(WHERE_AND);
7654 }
7655
7656 for (int i = 0; i < orderByConditionFields.length; i++) {
7657 query.append(_ORDER_BY_ENTITY_ALIAS);
7658 query.append(orderByConditionFields[i]);
7659
7660 if ((i + 1) < orderByConditionFields.length) {
7661 if (orderByComparator.isAscending() ^ previous) {
7662 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7663 }
7664 else {
7665 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7666 }
7667 }
7668 else {
7669 if (orderByComparator.isAscending() ^ previous) {
7670 query.append(WHERE_GREATER_THAN);
7671 }
7672 else {
7673 query.append(WHERE_LESSER_THAN);
7674 }
7675 }
7676 }
7677
7678 query.append(ORDER_BY_CLAUSE);
7679
7680 String[] orderByFields = orderByComparator.getOrderByFields();
7681
7682 for (int i = 0; i < orderByFields.length; i++) {
7683 query.append(_ORDER_BY_ENTITY_ALIAS);
7684 query.append(orderByFields[i]);
7685
7686 if ((i + 1) < orderByFields.length) {
7687 if (orderByComparator.isAscending() ^ previous) {
7688 query.append(ORDER_BY_ASC_HAS_NEXT);
7689 }
7690 else {
7691 query.append(ORDER_BY_DESC_HAS_NEXT);
7692 }
7693 }
7694 else {
7695 if (orderByComparator.isAscending() ^ previous) {
7696 query.append(ORDER_BY_ASC);
7697 }
7698 else {
7699 query.append(ORDER_BY_DESC);
7700 }
7701 }
7702 }
7703 }
7704 else {
7705 query.append(RoleModelImpl.ORDER_BY_JPQL);
7706 }
7707
7708 String sql = query.toString();
7709
7710 Query q = session.createQuery(sql);
7711
7712 q.setFirstResult(0);
7713 q.setMaxResults(2);
7714
7715 QueryPos qPos = QueryPos.getInstance(q);
7716
7717 qPos.add(type);
7718
7719 if (bindSubtype) {
7720 qPos.add(subtype);
7721 }
7722
7723 if (orderByComparator != null) {
7724 Object[] values = orderByComparator.getOrderByConditionValues(role);
7725
7726 for (Object value : values) {
7727 qPos.add(value);
7728 }
7729 }
7730
7731 List<Role> list = q.list();
7732
7733 if (list.size() == 2) {
7734 return list.get(1);
7735 }
7736 else {
7737 return null;
7738 }
7739 }
7740
7741
7748 @Override
7749 public List<Role> filterFindByT_S(int type, String subtype) {
7750 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
7751 QueryUtil.ALL_POS, null);
7752 }
7753
7754
7767 @Override
7768 public List<Role> filterFindByT_S(int type, String subtype, int start,
7769 int end) {
7770 return filterFindByT_S(type, subtype, start, end, null);
7771 }
7772
7773
7787 @Override
7788 public List<Role> filterFindByT_S(int type, String subtype, int start,
7789 int end, OrderByComparator<Role> orderByComparator) {
7790 if (!InlineSQLHelperUtil.isEnabled()) {
7791 return findByT_S(type, subtype, start, end, orderByComparator);
7792 }
7793
7794 StringBundler query = null;
7795
7796 if (orderByComparator != null) {
7797 query = new StringBundler(4 +
7798 (orderByComparator.getOrderByFields().length * 2));
7799 }
7800 else {
7801 query = new StringBundler(5);
7802 }
7803
7804 if (getDB().isSupportsInlineDistinct()) {
7805 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7806 }
7807 else {
7808 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7809 }
7810
7811 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7812
7813 boolean bindSubtype = false;
7814
7815 if (subtype == null) {
7816 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7817 }
7818 else if (subtype.equals(StringPool.BLANK)) {
7819 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7820 }
7821 else {
7822 bindSubtype = true;
7823
7824 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7825 }
7826
7827 if (!getDB().isSupportsInlineDistinct()) {
7828 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7829 }
7830
7831 if (orderByComparator != null) {
7832 if (getDB().isSupportsInlineDistinct()) {
7833 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7834 orderByComparator, true);
7835 }
7836 else {
7837 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7838 orderByComparator, true);
7839 }
7840 }
7841 else {
7842 if (getDB().isSupportsInlineDistinct()) {
7843 query.append(RoleModelImpl.ORDER_BY_JPQL);
7844 }
7845 else {
7846 query.append(RoleModelImpl.ORDER_BY_SQL);
7847 }
7848 }
7849
7850 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7851 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7852
7853 Session session = null;
7854
7855 try {
7856 session = openSession();
7857
7858 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7859
7860 if (getDB().isSupportsInlineDistinct()) {
7861 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
7862 }
7863 else {
7864 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
7865 }
7866
7867 QueryPos qPos = QueryPos.getInstance(q);
7868
7869 qPos.add(type);
7870
7871 if (bindSubtype) {
7872 qPos.add(subtype);
7873 }
7874
7875 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
7876 }
7877 catch (Exception e) {
7878 throw processException(e);
7879 }
7880 finally {
7881 closeSession(session);
7882 }
7883 }
7884
7885
7895 @Override
7896 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
7897 String subtype, OrderByComparator<Role> orderByComparator)
7898 throws NoSuchRoleException {
7899 if (!InlineSQLHelperUtil.isEnabled()) {
7900 return findByT_S_PrevAndNext(roleId, type, subtype,
7901 orderByComparator);
7902 }
7903
7904 Role role = findByPrimaryKey(roleId);
7905
7906 Session session = null;
7907
7908 try {
7909 session = openSession();
7910
7911 Role[] array = new RoleImpl[3];
7912
7913 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7914 orderByComparator, true);
7915
7916 array[1] = role;
7917
7918 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7919 orderByComparator, false);
7920
7921 return array;
7922 }
7923 catch (Exception e) {
7924 throw processException(e);
7925 }
7926 finally {
7927 closeSession(session);
7928 }
7929 }
7930
7931 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
7932 int type, String subtype, OrderByComparator<Role> orderByComparator,
7933 boolean previous) {
7934 StringBundler query = null;
7935
7936 if (orderByComparator != null) {
7937 query = new StringBundler(6 +
7938 (orderByComparator.getOrderByConditionFields().length * 3) +
7939 (orderByComparator.getOrderByFields().length * 3));
7940 }
7941 else {
7942 query = new StringBundler(5);
7943 }
7944
7945 if (getDB().isSupportsInlineDistinct()) {
7946 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7947 }
7948 else {
7949 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7950 }
7951
7952 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7953
7954 boolean bindSubtype = false;
7955
7956 if (subtype == null) {
7957 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7958 }
7959 else if (subtype.equals(StringPool.BLANK)) {
7960 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7961 }
7962 else {
7963 bindSubtype = true;
7964
7965 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7966 }
7967
7968 if (!getDB().isSupportsInlineDistinct()) {
7969 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7970 }
7971
7972 if (orderByComparator != null) {
7973 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7974
7975 if (orderByConditionFields.length > 0) {
7976 query.append(WHERE_AND);
7977 }
7978
7979 for (int i = 0; i < orderByConditionFields.length; i++) {
7980 if (getDB().isSupportsInlineDistinct()) {
7981 query.append(_ORDER_BY_ENTITY_ALIAS);
7982 }
7983 else {
7984 query.append(_ORDER_BY_ENTITY_TABLE);
7985 }
7986
7987 query.append(orderByConditionFields[i]);
7988
7989 if ((i + 1) < orderByConditionFields.length) {
7990 if (orderByComparator.isAscending() ^ previous) {
7991 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7992 }
7993 else {
7994 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7995 }
7996 }
7997 else {
7998 if (orderByComparator.isAscending() ^ previous) {
7999 query.append(WHERE_GREATER_THAN);
8000 }
8001 else {
8002 query.append(WHERE_LESSER_THAN);
8003 }
8004 }
8005 }
8006
8007 query.append(ORDER_BY_CLAUSE);
8008
8009 String[] orderByFields = orderByComparator.getOrderByFields();
8010
8011 for (int i = 0; i < orderByFields.length; i++) {
8012 if (getDB().isSupportsInlineDistinct()) {
8013 query.append(_ORDER_BY_ENTITY_ALIAS);
8014 }
8015 else {
8016 query.append(_ORDER_BY_ENTITY_TABLE);
8017 }
8018
8019 query.append(orderByFields[i]);
8020
8021 if ((i + 1) < orderByFields.length) {
8022 if (orderByComparator.isAscending() ^ previous) {
8023 query.append(ORDER_BY_ASC_HAS_NEXT);
8024 }
8025 else {
8026 query.append(ORDER_BY_DESC_HAS_NEXT);
8027 }
8028 }
8029 else {
8030 if (orderByComparator.isAscending() ^ previous) {
8031 query.append(ORDER_BY_ASC);
8032 }
8033 else {
8034 query.append(ORDER_BY_DESC);
8035 }
8036 }
8037 }
8038 }
8039 else {
8040 if (getDB().isSupportsInlineDistinct()) {
8041 query.append(RoleModelImpl.ORDER_BY_JPQL);
8042 }
8043 else {
8044 query.append(RoleModelImpl.ORDER_BY_SQL);
8045 }
8046 }
8047
8048 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8049 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
8050
8051 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8052
8053 q.setFirstResult(0);
8054 q.setMaxResults(2);
8055
8056 if (getDB().isSupportsInlineDistinct()) {
8057 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
8058 }
8059 else {
8060 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
8061 }
8062
8063 QueryPos qPos = QueryPos.getInstance(q);
8064
8065 qPos.add(type);
8066
8067 if (bindSubtype) {
8068 qPos.add(subtype);
8069 }
8070
8071 if (orderByComparator != null) {
8072 Object[] values = orderByComparator.getOrderByConditionValues(role);
8073
8074 for (Object value : values) {
8075 qPos.add(value);
8076 }
8077 }
8078
8079 List<Role> list = q.list();
8080
8081 if (list.size() == 2) {
8082 return list.get(1);
8083 }
8084 else {
8085 return null;
8086 }
8087 }
8088
8089
8095 @Override
8096 public void removeByT_S(int type, String subtype) {
8097 for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
8098 QueryUtil.ALL_POS, null)) {
8099 remove(role);
8100 }
8101 }
8102
8103
8110 @Override
8111 public int countByT_S(int type, String subtype) {
8112 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
8113
8114 Object[] finderArgs = new Object[] { type, subtype };
8115
8116 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8117
8118 if (count == null) {
8119 StringBundler query = new StringBundler(3);
8120
8121 query.append(_SQL_COUNT_ROLE_WHERE);
8122
8123 query.append(_FINDER_COLUMN_T_S_TYPE_2);
8124
8125 boolean bindSubtype = false;
8126
8127 if (subtype == null) {
8128 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
8129 }
8130 else if (subtype.equals(StringPool.BLANK)) {
8131 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
8132 }
8133 else {
8134 bindSubtype = true;
8135
8136 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
8137 }
8138
8139 String sql = query.toString();
8140
8141 Session session = null;
8142
8143 try {
8144 session = openSession();
8145
8146 Query q = session.createQuery(sql);
8147
8148 QueryPos qPos = QueryPos.getInstance(q);
8149
8150 qPos.add(type);
8151
8152 if (bindSubtype) {
8153 qPos.add(subtype);
8154 }
8155
8156 count = (Long)q.uniqueResult();
8157
8158 finderCache.putResult(finderPath, finderArgs, count);
8159 }
8160 catch (Exception e) {
8161 finderCache.removeResult(finderPath, finderArgs);
8162
8163 throw processException(e);
8164 }
8165 finally {
8166 closeSession(session);
8167 }
8168 }
8169
8170 return count.intValue();
8171 }
8172
8173
8180 @Override
8181 public int filterCountByT_S(int type, String subtype) {
8182 if (!InlineSQLHelperUtil.isEnabled()) {
8183 return countByT_S(type, subtype);
8184 }
8185
8186 StringBundler query = new StringBundler(3);
8187
8188 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
8189
8190 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
8191
8192 boolean bindSubtype = false;
8193
8194 if (subtype == null) {
8195 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
8196 }
8197 else if (subtype.equals(StringPool.BLANK)) {
8198 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
8199 }
8200 else {
8201 bindSubtype = true;
8202
8203 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
8204 }
8205
8206 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8207 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
8208
8209 Session session = null;
8210
8211 try {
8212 session = openSession();
8213
8214 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8215
8216 q.addScalar(COUNT_COLUMN_NAME,
8217 com.liferay.portal.kernel.dao.orm.Type.LONG);
8218
8219 QueryPos qPos = QueryPos.getInstance(q);
8220
8221 qPos.add(type);
8222
8223 if (bindSubtype) {
8224 qPos.add(subtype);
8225 }
8226
8227 Long count = (Long)q.uniqueResult();
8228
8229 return count.intValue();
8230 }
8231 catch (Exception e) {
8232 throw processException(e);
8233 }
8234 finally {
8235 closeSession(session);
8236 }
8237 }
8238
8239 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
8240 private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND ";
8241 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
8242 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
8243 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
8244 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8245 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
8246 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
8247 new String[] {
8248 Long.class.getName(), Long.class.getName(), Long.class.getName()
8249 },
8250 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
8251 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8252 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
8253 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8254 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8255 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
8256 new String[] {
8257 Long.class.getName(), Long.class.getName(), Long.class.getName()
8258 });
8259
8260
8269 @Override
8270 public Role findByC_C_C(long companyId, long classNameId, long classPK)
8271 throws NoSuchRoleException {
8272 Role role = fetchByC_C_C(companyId, classNameId, classPK);
8273
8274 if (role == null) {
8275 StringBundler msg = new StringBundler(8);
8276
8277 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8278
8279 msg.append("companyId=");
8280 msg.append(companyId);
8281
8282 msg.append(", classNameId=");
8283 msg.append(classNameId);
8284
8285 msg.append(", classPK=");
8286 msg.append(classPK);
8287
8288 msg.append(StringPool.CLOSE_CURLY_BRACE);
8289
8290 if (_log.isDebugEnabled()) {
8291 _log.debug(msg.toString());
8292 }
8293
8294 throw new NoSuchRoleException(msg.toString());
8295 }
8296
8297 return role;
8298 }
8299
8300
8308 @Override
8309 public Role fetchByC_C_C(long companyId, long classNameId, long classPK) {
8310 return fetchByC_C_C(companyId, classNameId, classPK, true);
8311 }
8312
8313
8322 @Override
8323 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
8324 boolean retrieveFromCache) {
8325 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8326
8327 Object result = null;
8328
8329 if (retrieveFromCache) {
8330 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C_C,
8331 finderArgs, this);
8332 }
8333
8334 if (result instanceof Role) {
8335 Role role = (Role)result;
8336
8337 if ((companyId != role.getCompanyId()) ||
8338 (classNameId != role.getClassNameId()) ||
8339 (classPK != role.getClassPK())) {
8340 result = null;
8341 }
8342 }
8343
8344 if (result == null) {
8345 StringBundler query = new StringBundler(5);
8346
8347 query.append(_SQL_SELECT_ROLE_WHERE);
8348
8349 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8350
8351 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8352
8353 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8354
8355 String sql = query.toString();
8356
8357 Session session = null;
8358
8359 try {
8360 session = openSession();
8361
8362 Query q = session.createQuery(sql);
8363
8364 QueryPos qPos = QueryPos.getInstance(q);
8365
8366 qPos.add(companyId);
8367
8368 qPos.add(classNameId);
8369
8370 qPos.add(classPK);
8371
8372 List<Role> list = q.list();
8373
8374 if (list.isEmpty()) {
8375 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8376 finderArgs, list);
8377 }
8378 else {
8379 Role role = list.get(0);
8380
8381 result = role;
8382
8383 cacheResult(role);
8384
8385 if ((role.getCompanyId() != companyId) ||
8386 (role.getClassNameId() != classNameId) ||
8387 (role.getClassPK() != classPK)) {
8388 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8389 finderArgs, role);
8390 }
8391 }
8392 }
8393 catch (Exception e) {
8394 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, finderArgs);
8395
8396 throw processException(e);
8397 }
8398 finally {
8399 closeSession(session);
8400 }
8401 }
8402
8403 if (result instanceof List<?>) {
8404 return null;
8405 }
8406 else {
8407 return (Role)result;
8408 }
8409 }
8410
8411
8419 @Override
8420 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
8421 throws NoSuchRoleException {
8422 Role role = findByC_C_C(companyId, classNameId, classPK);
8423
8424 return remove(role);
8425 }
8426
8427
8435 @Override
8436 public int countByC_C_C(long companyId, long classNameId, long classPK) {
8437 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
8438
8439 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8440
8441 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8442
8443 if (count == null) {
8444 StringBundler query = new StringBundler(4);
8445
8446 query.append(_SQL_COUNT_ROLE_WHERE);
8447
8448 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8449
8450 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8451
8452 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8453
8454 String sql = query.toString();
8455
8456 Session session = null;
8457
8458 try {
8459 session = openSession();
8460
8461 Query q = session.createQuery(sql);
8462
8463 QueryPos qPos = QueryPos.getInstance(q);
8464
8465 qPos.add(companyId);
8466
8467 qPos.add(classNameId);
8468
8469 qPos.add(classPK);
8470
8471 count = (Long)q.uniqueResult();
8472
8473 finderCache.putResult(finderPath, finderArgs, count);
8474 }
8475 catch (Exception e) {
8476 finderCache.removeResult(finderPath, finderArgs);
8477
8478 throw processException(e);
8479 }
8480 finally {
8481 closeSession(session);
8482 }
8483 }
8484
8485 return count.intValue();
8486 }
8487
8488 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
8489 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
8490 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
8491
8492 public RolePersistenceImpl() {
8493 setModelClass(Role.class);
8494 }
8495
8496
8501 @Override
8502 public void cacheResult(Role role) {
8503 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8504 RoleImpl.class, role.getPrimaryKey(), role);
8505
8506 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
8507 new Object[] { role.getCompanyId(), role.getName() }, role);
8508
8509 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8510 new Object[] {
8511 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
8512 }, role);
8513
8514 role.resetOriginalValues();
8515 }
8516
8517
8522 @Override
8523 public void cacheResult(List<Role> roles) {
8524 for (Role role : roles) {
8525 if (entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8526 RoleImpl.class, role.getPrimaryKey()) == null) {
8527 cacheResult(role);
8528 }
8529 else {
8530 role.resetOriginalValues();
8531 }
8532 }
8533 }
8534
8535
8542 @Override
8543 public void clearCache() {
8544 entityCache.clearCache(RoleImpl.class);
8545
8546 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
8547 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8548 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8549 }
8550
8551
8558 @Override
8559 public void clearCache(Role role) {
8560 entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8561 RoleImpl.class, role.getPrimaryKey());
8562
8563 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8564 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8565
8566 clearUniqueFindersCache((RoleModelImpl)role);
8567 }
8568
8569 @Override
8570 public void clearCache(List<Role> roles) {
8571 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8572 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8573
8574 for (Role role : roles) {
8575 entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8576 RoleImpl.class, role.getPrimaryKey());
8577
8578 clearUniqueFindersCache((RoleModelImpl)role);
8579 }
8580 }
8581
8582 protected void cacheUniqueFindersCache(RoleModelImpl roleModelImpl,
8583 boolean isNew) {
8584 if (isNew) {
8585 Object[] args = new Object[] {
8586 roleModelImpl.getCompanyId(), roleModelImpl.getName()
8587 };
8588
8589 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8590 Long.valueOf(1));
8591 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args, roleModelImpl);
8592
8593 args = new Object[] {
8594 roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(),
8595 roleModelImpl.getClassPK()
8596 };
8597
8598 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8599 Long.valueOf(1));
8600 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, args,
8601 roleModelImpl);
8602 }
8603 else {
8604 if ((roleModelImpl.getColumnBitmask() &
8605 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8606 Object[] args = new Object[] {
8607 roleModelImpl.getCompanyId(), roleModelImpl.getName()
8608 };
8609
8610 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8611 Long.valueOf(1));
8612 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args,
8613 roleModelImpl);
8614 }
8615
8616 if ((roleModelImpl.getColumnBitmask() &
8617 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8618 Object[] args = new Object[] {
8619 roleModelImpl.getCompanyId(),
8620 roleModelImpl.getClassNameId(),
8621 roleModelImpl.getClassPK()
8622 };
8623
8624 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8625 Long.valueOf(1));
8626 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, args,
8627 roleModelImpl);
8628 }
8629 }
8630 }
8631
8632 protected void clearUniqueFindersCache(RoleModelImpl roleModelImpl) {
8633 Object[] args = new Object[] {
8634 roleModelImpl.getCompanyId(), roleModelImpl.getName()
8635 };
8636
8637 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8638 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8639
8640 if ((roleModelImpl.getColumnBitmask() &
8641 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8642 args = new Object[] {
8643 roleModelImpl.getOriginalCompanyId(),
8644 roleModelImpl.getOriginalName()
8645 };
8646
8647 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8648 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8649 }
8650
8651 args = new Object[] {
8652 roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(),
8653 roleModelImpl.getClassPK()
8654 };
8655
8656 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8657 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8658
8659 if ((roleModelImpl.getColumnBitmask() &
8660 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8661 args = new Object[] {
8662 roleModelImpl.getOriginalCompanyId(),
8663 roleModelImpl.getOriginalClassNameId(),
8664 roleModelImpl.getOriginalClassPK()
8665 };
8666
8667 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8668 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8669 }
8670 }
8671
8672
8678 @Override
8679 public Role create(long roleId) {
8680 Role role = new RoleImpl();
8681
8682 role.setNew(true);
8683 role.setPrimaryKey(roleId);
8684
8685 String uuid = PortalUUIDUtil.generate();
8686
8687 role.setUuid(uuid);
8688
8689 role.setCompanyId(companyProvider.getCompanyId());
8690
8691 return role;
8692 }
8693
8694
8701 @Override
8702 public Role remove(long roleId) throws NoSuchRoleException {
8703 return remove((Serializable)roleId);
8704 }
8705
8706
8713 @Override
8714 public Role remove(Serializable primaryKey) throws NoSuchRoleException {
8715 Session session = null;
8716
8717 try {
8718 session = openSession();
8719
8720 Role role = (Role)session.get(RoleImpl.class, primaryKey);
8721
8722 if (role == null) {
8723 if (_log.isDebugEnabled()) {
8724 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8725 }
8726
8727 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8728 primaryKey);
8729 }
8730
8731 return remove(role);
8732 }
8733 catch (NoSuchRoleException nsee) {
8734 throw nsee;
8735 }
8736 catch (Exception e) {
8737 throw processException(e);
8738 }
8739 finally {
8740 closeSession(session);
8741 }
8742 }
8743
8744 @Override
8745 protected Role removeImpl(Role role) {
8746 role = toUnwrappedModel(role);
8747
8748 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8749
8750 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8751
8752 Session session = null;
8753
8754 try {
8755 session = openSession();
8756
8757 if (!session.contains(role)) {
8758 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
8759 }
8760
8761 if (role != null) {
8762 session.delete(role);
8763 }
8764 }
8765 catch (Exception e) {
8766 throw processException(e);
8767 }
8768 finally {
8769 closeSession(session);
8770 }
8771
8772 if (role != null) {
8773 clearCache(role);
8774 }
8775
8776 return role;
8777 }
8778
8779 @Override
8780 public Role updateImpl(Role role) {
8781 role = toUnwrappedModel(role);
8782
8783 boolean isNew = role.isNew();
8784
8785 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8786
8787 if (Validator.isNull(role.getUuid())) {
8788 String uuid = PortalUUIDUtil.generate();
8789
8790 role.setUuid(uuid);
8791 }
8792
8793 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
8794
8795 Date now = new Date();
8796
8797 if (isNew && (role.getCreateDate() == null)) {
8798 if (serviceContext == null) {
8799 role.setCreateDate(now);
8800 }
8801 else {
8802 role.setCreateDate(serviceContext.getCreateDate(now));
8803 }
8804 }
8805
8806 if (!roleModelImpl.hasSetModifiedDate()) {
8807 if (serviceContext == null) {
8808 role.setModifiedDate(now);
8809 }
8810 else {
8811 role.setModifiedDate(serviceContext.getModifiedDate(now));
8812 }
8813 }
8814
8815 Session session = null;
8816
8817 try {
8818 session = openSession();
8819
8820 if (role.isNew()) {
8821 session.save(role);
8822
8823 role.setNew(false);
8824 }
8825 else {
8826 role = (Role)session.merge(role);
8827 }
8828 }
8829 catch (Exception e) {
8830 throw processException(e);
8831 }
8832 finally {
8833 closeSession(session);
8834 }
8835
8836 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8837
8838 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
8839 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8840 }
8841
8842 else {
8843 if ((roleModelImpl.getColumnBitmask() &
8844 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8845 Object[] args = new Object[] { roleModelImpl.getOriginalUuid() };
8846
8847 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8848 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8849 args);
8850
8851 args = new Object[] { roleModelImpl.getUuid() };
8852
8853 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8854 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8855 args);
8856 }
8857
8858 if ((roleModelImpl.getColumnBitmask() &
8859 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8860 Object[] args = new Object[] {
8861 roleModelImpl.getOriginalUuid(),
8862 roleModelImpl.getOriginalCompanyId()
8863 };
8864
8865 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8866 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8867 args);
8868
8869 args = new Object[] {
8870 roleModelImpl.getUuid(), roleModelImpl.getCompanyId()
8871 };
8872
8873 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8874 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8875 args);
8876 }
8877
8878 if ((roleModelImpl.getColumnBitmask() &
8879 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8880 Object[] args = new Object[] {
8881 roleModelImpl.getOriginalCompanyId()
8882 };
8883
8884 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
8885 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8886 args);
8887
8888 args = new Object[] { roleModelImpl.getCompanyId() };
8889
8890 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
8891 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8892 args);
8893 }
8894
8895 if ((roleModelImpl.getColumnBitmask() &
8896 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
8897 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
8898
8899 finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8900 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8901 args);
8902
8903 args = new Object[] { roleModelImpl.getName() };
8904
8905 finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8906 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8907 args);
8908 }
8909
8910 if ((roleModelImpl.getColumnBitmask() &
8911 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
8912 Object[] args = new Object[] { roleModelImpl.getOriginalType() };
8913
8914 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8915 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8916 args);
8917
8918 args = new Object[] { roleModelImpl.getType() };
8919
8920 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8921 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8922 args);
8923 }
8924
8925 if ((roleModelImpl.getColumnBitmask() &
8926 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
8927 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
8928
8929 finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8930 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8931 args);
8932
8933 args = new Object[] { roleModelImpl.getSubtype() };
8934
8935 finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8936 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8937 args);
8938 }
8939
8940 if ((roleModelImpl.getColumnBitmask() &
8941 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
8942 Object[] args = new Object[] {
8943 roleModelImpl.getOriginalCompanyId(),
8944 roleModelImpl.getOriginalType()
8945 };
8946
8947 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8948 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8949 args);
8950
8951 args = new Object[] {
8952 roleModelImpl.getCompanyId(), roleModelImpl.getType()
8953 };
8954
8955 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8956 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8957 args);
8958 }
8959
8960 if ((roleModelImpl.getColumnBitmask() &
8961 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
8962 Object[] args = new Object[] {
8963 roleModelImpl.getOriginalType(),
8964 roleModelImpl.getOriginalSubtype()
8965 };
8966
8967 finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8968 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8969 args);
8970
8971 args = new Object[] {
8972 roleModelImpl.getType(), roleModelImpl.getSubtype()
8973 };
8974
8975 finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8976 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8977 args);
8978 }
8979 }
8980
8981 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8982 RoleImpl.class, role.getPrimaryKey(), role, false);
8983
8984 clearUniqueFindersCache(roleModelImpl);
8985 cacheUniqueFindersCache(roleModelImpl, isNew);
8986
8987 role.resetOriginalValues();
8988
8989 return role;
8990 }
8991
8992 protected Role toUnwrappedModel(Role role) {
8993 if (role instanceof RoleImpl) {
8994 return role;
8995 }
8996
8997 RoleImpl roleImpl = new RoleImpl();
8998
8999 roleImpl.setNew(role.isNew());
9000 roleImpl.setPrimaryKey(role.getPrimaryKey());
9001
9002 roleImpl.setMvccVersion(role.getMvccVersion());
9003 roleImpl.setUuid(role.getUuid());
9004 roleImpl.setRoleId(role.getRoleId());
9005 roleImpl.setCompanyId(role.getCompanyId());
9006 roleImpl.setUserId(role.getUserId());
9007 roleImpl.setUserName(role.getUserName());
9008 roleImpl.setCreateDate(role.getCreateDate());
9009 roleImpl.setModifiedDate(role.getModifiedDate());
9010 roleImpl.setClassNameId(role.getClassNameId());
9011 roleImpl.setClassPK(role.getClassPK());
9012 roleImpl.setName(role.getName());
9013 roleImpl.setTitle(role.getTitle());
9014 roleImpl.setDescription(role.getDescription());
9015 roleImpl.setType(role.getType());
9016 roleImpl.setSubtype(role.getSubtype());
9017
9018 return roleImpl;
9019 }
9020
9021
9028 @Override
9029 public Role findByPrimaryKey(Serializable primaryKey)
9030 throws NoSuchRoleException {
9031 Role role = fetchByPrimaryKey(primaryKey);
9032
9033 if (role == null) {
9034 if (_log.isDebugEnabled()) {
9035 _log.debug(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9036 }
9037
9038 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9039 primaryKey);
9040 }
9041
9042 return role;
9043 }
9044
9045
9052 @Override
9053 public Role findByPrimaryKey(long roleId) throws NoSuchRoleException {
9054 return findByPrimaryKey((Serializable)roleId);
9055 }
9056
9057
9063 @Override
9064 public Role fetchByPrimaryKey(Serializable primaryKey) {
9065 Role role = (Role)entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9066 RoleImpl.class, primaryKey);
9067
9068 if (role == _nullRole) {
9069 return null;
9070 }
9071
9072 if (role == null) {
9073 Session session = null;
9074
9075 try {
9076 session = openSession();
9077
9078 role = (Role)session.get(RoleImpl.class, primaryKey);
9079
9080 if (role != null) {
9081 cacheResult(role);
9082 }
9083 else {
9084 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9085 RoleImpl.class, primaryKey, _nullRole);
9086 }
9087 }
9088 catch (Exception e) {
9089 entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9090 RoleImpl.class, primaryKey);
9091
9092 throw processException(e);
9093 }
9094 finally {
9095 closeSession(session);
9096 }
9097 }
9098
9099 return role;
9100 }
9101
9102
9108 @Override
9109 public Role fetchByPrimaryKey(long roleId) {
9110 return fetchByPrimaryKey((Serializable)roleId);
9111 }
9112
9113 @Override
9114 public Map<Serializable, Role> fetchByPrimaryKeys(
9115 Set<Serializable> primaryKeys) {
9116 if (primaryKeys.isEmpty()) {
9117 return Collections.emptyMap();
9118 }
9119
9120 Map<Serializable, Role> map = new HashMap<Serializable, Role>();
9121
9122 if (primaryKeys.size() == 1) {
9123 Iterator<Serializable> iterator = primaryKeys.iterator();
9124
9125 Serializable primaryKey = iterator.next();
9126
9127 Role role = fetchByPrimaryKey(primaryKey);
9128
9129 if (role != null) {
9130 map.put(primaryKey, role);
9131 }
9132
9133 return map;
9134 }
9135
9136 Set<Serializable> uncachedPrimaryKeys = null;
9137
9138 for (Serializable primaryKey : primaryKeys) {
9139 Role role = (Role)entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9140 RoleImpl.class, primaryKey);
9141
9142 if (role == null) {
9143 if (uncachedPrimaryKeys == null) {
9144 uncachedPrimaryKeys = new HashSet<Serializable>();
9145 }
9146
9147 uncachedPrimaryKeys.add(primaryKey);
9148 }
9149 else {
9150 map.put(primaryKey, role);
9151 }
9152 }
9153
9154 if (uncachedPrimaryKeys == null) {
9155 return map;
9156 }
9157
9158 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
9159 1);
9160
9161 query.append(_SQL_SELECT_ROLE_WHERE_PKS_IN);
9162
9163 for (Serializable primaryKey : uncachedPrimaryKeys) {
9164 query.append(String.valueOf(primaryKey));
9165
9166 query.append(StringPool.COMMA);
9167 }
9168
9169 query.setIndex(query.index() - 1);
9170
9171 query.append(StringPool.CLOSE_PARENTHESIS);
9172
9173 String sql = query.toString();
9174
9175 Session session = null;
9176
9177 try {
9178 session = openSession();
9179
9180 Query q = session.createQuery(sql);
9181
9182 for (Role role : (List<Role>)q.list()) {
9183 map.put(role.getPrimaryKeyObj(), role);
9184
9185 cacheResult(role);
9186
9187 uncachedPrimaryKeys.remove(role.getPrimaryKeyObj());
9188 }
9189
9190 for (Serializable primaryKey : uncachedPrimaryKeys) {
9191 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9192 RoleImpl.class, primaryKey, _nullRole);
9193 }
9194 }
9195 catch (Exception e) {
9196 throw processException(e);
9197 }
9198 finally {
9199 closeSession(session);
9200 }
9201
9202 return map;
9203 }
9204
9205
9210 @Override
9211 public List<Role> findAll() {
9212 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9213 }
9214
9215
9226 @Override
9227 public List<Role> findAll(int start, int end) {
9228 return findAll(start, end, null);
9229 }
9230
9231
9243 @Override
9244 public List<Role> findAll(int start, int end,
9245 OrderByComparator<Role> orderByComparator) {
9246 return findAll(start, end, orderByComparator, true);
9247 }
9248
9249
9262 @Override
9263 public List<Role> findAll(int start, int end,
9264 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
9265 boolean pagination = true;
9266 FinderPath finderPath = null;
9267 Object[] finderArgs = null;
9268
9269 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9270 (orderByComparator == null)) {
9271 pagination = false;
9272 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9273 finderArgs = FINDER_ARGS_EMPTY;
9274 }
9275 else {
9276 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9277 finderArgs = new Object[] { start, end, orderByComparator };
9278 }
9279
9280 List<Role> list = null;
9281
9282 if (retrieveFromCache) {
9283 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
9284 this);
9285 }
9286
9287 if (list == null) {
9288 StringBundler query = null;
9289 String sql = null;
9290
9291 if (orderByComparator != null) {
9292 query = new StringBundler(2 +
9293 (orderByComparator.getOrderByFields().length * 2));
9294
9295 query.append(_SQL_SELECT_ROLE);
9296
9297 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9298 orderByComparator);
9299
9300 sql = query.toString();
9301 }
9302 else {
9303 sql = _SQL_SELECT_ROLE;
9304
9305 if (pagination) {
9306 sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
9307 }
9308 }
9309
9310 Session session = null;
9311
9312 try {
9313 session = openSession();
9314
9315 Query q = session.createQuery(sql);
9316
9317 if (!pagination) {
9318 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9319 end, false);
9320
9321 Collections.sort(list);
9322
9323 list = Collections.unmodifiableList(list);
9324 }
9325 else {
9326 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9327 end);
9328 }
9329
9330 cacheResult(list);
9331
9332 finderCache.putResult(finderPath, finderArgs, list);
9333 }
9334 catch (Exception e) {
9335 finderCache.removeResult(finderPath, finderArgs);
9336
9337 throw processException(e);
9338 }
9339 finally {
9340 closeSession(session);
9341 }
9342 }
9343
9344 return list;
9345 }
9346
9347
9351 @Override
9352 public void removeAll() {
9353 for (Role role : findAll()) {
9354 remove(role);
9355 }
9356 }
9357
9358
9363 @Override
9364 public int countAll() {
9365 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
9366 FINDER_ARGS_EMPTY, this);
9367
9368 if (count == null) {
9369 Session session = null;
9370
9371 try {
9372 session = openSession();
9373
9374 Query q = session.createQuery(_SQL_COUNT_ROLE);
9375
9376 count = (Long)q.uniqueResult();
9377
9378 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
9379 count);
9380 }
9381 catch (Exception e) {
9382 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
9383 FINDER_ARGS_EMPTY);
9384
9385 throw processException(e);
9386 }
9387 finally {
9388 closeSession(session);
9389 }
9390 }
9391
9392 return count.intValue();
9393 }
9394
9395
9401 @Override
9402 public long[] getGroupPrimaryKeys(long pk) {
9403 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9404
9405 return pks.clone();
9406 }
9407
9408
9414 @Override
9415 public List<com.liferay.portal.kernel.model.Group> getGroups(long pk) {
9416 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9417 }
9418
9419
9431 @Override
9432 public List<com.liferay.portal.kernel.model.Group> getGroups(long pk,
9433 int start, int end) {
9434 return getGroups(pk, start, end, null);
9435 }
9436
9437
9450 @Override
9451 public List<com.liferay.portal.kernel.model.Group> getGroups(long pk,
9452 int start, int end,
9453 OrderByComparator<com.liferay.portal.kernel.model.Group> orderByComparator) {
9454 return roleToGroupTableMapper.getRightBaseModels(pk, start, end,
9455 orderByComparator);
9456 }
9457
9458
9464 @Override
9465 public int getGroupsSize(long pk) {
9466 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9467
9468 return pks.length;
9469 }
9470
9471
9478 @Override
9479 public boolean containsGroup(long pk, long groupPK) {
9480 return roleToGroupTableMapper.containsTableMapping(pk, groupPK);
9481 }
9482
9483
9489 @Override
9490 public boolean containsGroups(long pk) {
9491 if (getGroupsSize(pk) > 0) {
9492 return true;
9493 }
9494 else {
9495 return false;
9496 }
9497 }
9498
9499
9505 @Override
9506 public void addGroup(long pk, long groupPK) {
9507 Role role = fetchByPrimaryKey(pk);
9508
9509 if (role == null) {
9510 roleToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(),
9511 pk, groupPK);
9512 }
9513 else {
9514 roleToGroupTableMapper.addTableMapping(role.getCompanyId(), pk,
9515 groupPK);
9516 }
9517 }
9518
9519
9525 @Override
9526 public void addGroup(long pk, com.liferay.portal.kernel.model.Group group) {
9527 Role role = fetchByPrimaryKey(pk);
9528
9529 if (role == null) {
9530 roleToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(),
9531 pk, group.getPrimaryKey());
9532 }
9533 else {
9534 roleToGroupTableMapper.addTableMapping(role.getCompanyId(), pk,
9535 group.getPrimaryKey());
9536 }
9537 }
9538
9539
9545 @Override
9546 public void addGroups(long pk, long[] groupPKs) {
9547 long companyId = 0;
9548
9549 Role role = fetchByPrimaryKey(pk);
9550
9551 if (role == null) {
9552 companyId = companyProvider.getCompanyId();
9553 }
9554 else {
9555 companyId = role.getCompanyId();
9556 }
9557
9558 for (long groupPK : groupPKs) {
9559 roleToGroupTableMapper.addTableMapping(companyId, pk, groupPK);
9560 }
9561 }
9562
9563
9569 @Override
9570 public void addGroups(long pk,
9571 List<com.liferay.portal.kernel.model.Group> groups) {
9572 long companyId = 0;
9573
9574 Role role = fetchByPrimaryKey(pk);
9575
9576 if (role == null) {
9577 companyId = companyProvider.getCompanyId();
9578 }
9579 else {
9580 companyId = role.getCompanyId();
9581 }
9582
9583 for (com.liferay.portal.kernel.model.Group group : groups) {
9584 roleToGroupTableMapper.addTableMapping(companyId, pk,
9585 group.getPrimaryKey());
9586 }
9587 }
9588
9589
9594 @Override
9595 public void clearGroups(long pk) {
9596 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9597 }
9598
9599
9605 @Override
9606 public void removeGroup(long pk, long groupPK) {
9607 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9608 }
9609
9610
9616 @Override
9617 public void removeGroup(long pk, com.liferay.portal.kernel.model.Group group) {
9618 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9619 }
9620
9621
9627 @Override
9628 public void removeGroups(long pk, long[] groupPKs) {
9629 for (long groupPK : groupPKs) {
9630 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9631 }
9632 }
9633
9634
9640 @Override
9641 public void removeGroups(long pk,
9642 List<com.liferay.portal.kernel.model.Group> groups) {
9643 for (com.liferay.portal.kernel.model.Group group : groups) {
9644 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9645 }
9646 }
9647
9648
9654 @Override
9655 public void setGroups(long pk, long[] groupPKs) {
9656 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
9657 Set<Long> oldGroupPKsSet = SetUtil.fromArray(roleToGroupTableMapper.getRightPrimaryKeys(
9658 pk));
9659
9660 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
9661
9662 removeGroupPKsSet.removeAll(newGroupPKsSet);
9663
9664 for (long removeGroupPK : removeGroupPKsSet) {
9665 roleToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
9666 }
9667
9668 newGroupPKsSet.removeAll(oldGroupPKsSet);
9669
9670 long companyId = 0;
9671
9672 Role role = fetchByPrimaryKey(pk);
9673
9674 if (role == null) {
9675 companyId = companyProvider.getCompanyId();
9676 }
9677 else {
9678 companyId = role.getCompanyId();
9679 }
9680
9681 for (long newGroupPK : newGroupPKsSet) {
9682 roleToGroupTableMapper.addTableMapping(companyId, pk, newGroupPK);
9683 }
9684 }
9685
9686
9692 @Override
9693 public void setGroups(long pk,
9694 List<com.liferay.portal.kernel.model.Group> groups) {
9695 try {
9696 long[] groupPKs = new long[groups.size()];
9697
9698 for (int i = 0; i < groups.size(); i++) {
9699 com.liferay.portal.kernel.model.Group group = groups.get(i);
9700
9701 groupPKs[i] = group.getPrimaryKey();
9702 }
9703
9704 setGroups(pk, groupPKs);
9705 }
9706 catch (Exception e) {
9707 throw processException(e);
9708 }
9709 }
9710
9711
9717 @Override
9718 public long[] getUserPrimaryKeys(long pk) {
9719 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9720
9721 return pks.clone();
9722 }
9723
9724
9730 @Override
9731 public List<com.liferay.portal.kernel.model.User> getUsers(long pk) {
9732 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9733 }
9734
9735
9747 @Override
9748 public List<com.liferay.portal.kernel.model.User> getUsers(long pk,
9749 int start, int end) {
9750 return getUsers(pk, start, end, null);
9751 }
9752
9753
9766 @Override
9767 public List<com.liferay.portal.kernel.model.User> getUsers(long pk,
9768 int start, int end,
9769 OrderByComparator<com.liferay.portal.kernel.model.User> orderByComparator) {
9770 return roleToUserTableMapper.getRightBaseModels(pk, start, end,
9771 orderByComparator);
9772 }
9773
9774
9780 @Override
9781 public int getUsersSize(long pk) {
9782 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9783
9784 return pks.length;
9785 }
9786
9787
9794 @Override
9795 public boolean containsUser(long pk, long userPK) {
9796 return roleToUserTableMapper.containsTableMapping(pk, userPK);
9797 }
9798
9799
9805 @Override
9806 public boolean containsUsers(long pk) {
9807 if (getUsersSize(pk) > 0) {
9808 return true;
9809 }
9810 else {
9811 return false;
9812 }
9813 }
9814
9815
9821 @Override
9822 public void addUser(long pk, long userPK) {
9823 Role role = fetchByPrimaryKey(pk);
9824
9825 if (role == null) {
9826 roleToUserTableMapper.addTableMapping(companyProvider.getCompanyId(),
9827 pk, userPK);
9828 }
9829 else {
9830 roleToUserTableMapper.addTableMapping(role.getCompanyId(), pk,
9831 userPK);
9832 }
9833 }
9834
9835
9841 @Override
9842 public void addUser(long pk, com.liferay.portal.kernel.model.User user) {
9843 Role role = fetchByPrimaryKey(pk);
9844
9845 if (role == null) {
9846 roleToUserTableMapper.addTableMapping(companyProvider.getCompanyId(),
9847 pk, user.getPrimaryKey());
9848 }
9849 else {
9850 roleToUserTableMapper.addTableMapping(role.getCompanyId(), pk,
9851 user.getPrimaryKey());
9852 }
9853 }
9854
9855
9861 @Override
9862 public void addUsers(long pk, long[] userPKs) {
9863 long companyId = 0;
9864
9865 Role role = fetchByPrimaryKey(pk);
9866
9867 if (role == null) {
9868 companyId = companyProvider.getCompanyId();
9869 }
9870 else {
9871 companyId = role.getCompanyId();
9872 }
9873
9874 for (long userPK : userPKs) {
9875 roleToUserTableMapper.addTableMapping(companyId, pk, userPK);
9876 }
9877 }
9878
9879
9885 @Override
9886 public void addUsers(long pk,
9887 List<com.liferay.portal.kernel.model.User> users) {
9888 long companyId = 0;
9889
9890 Role role = fetchByPrimaryKey(pk);
9891
9892 if (role == null) {
9893 companyId = companyProvider.getCompanyId();
9894 }
9895 else {
9896 companyId = role.getCompanyId();
9897 }
9898
9899 for (com.liferay.portal.kernel.model.User user : users) {
9900 roleToUserTableMapper.addTableMapping(companyId, pk,
9901 user.getPrimaryKey());
9902 }
9903 }
9904
9905
9910 @Override
9911 public void clearUsers(long pk) {
9912 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9913 }
9914
9915
9921 @Override
9922 public void removeUser(long pk, long userPK) {
9923 roleToUserTableMapper.deleteTableMapping(pk, userPK);
9924 }
9925
9926
9932 @Override
9933 public void removeUser(long pk, com.liferay.portal.kernel.model.User user) {
9934 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9935 }
9936
9937
9943 @Override
9944 public void removeUsers(long pk, long[] userPKs) {
9945 for (long userPK : userPKs) {
9946 roleToUserTableMapper.deleteTableMapping(pk, userPK);
9947 }
9948 }
9949
9950
9956 @Override
9957 public void removeUsers(long pk,
9958 List<com.liferay.portal.kernel.model.User> users) {
9959 for (com.liferay.portal.kernel.model.User user : users) {
9960 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9961 }
9962 }
9963
9964
9970 @Override
9971 public void setUsers(long pk, long[] userPKs) {
9972 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
9973 Set<Long> oldUserPKsSet = SetUtil.fromArray(roleToUserTableMapper.getRightPrimaryKeys(
9974 pk));
9975
9976 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
9977
9978 removeUserPKsSet.removeAll(newUserPKsSet);
9979
9980 for (long removeUserPK : removeUserPKsSet) {
9981 roleToUserTableMapper.deleteTableMapping(pk, removeUserPK);
9982 }
9983
9984 newUserPKsSet.removeAll(oldUserPKsSet);
9985
9986 long companyId = 0;
9987
9988 Role role = fetchByPrimaryKey(pk);
9989
9990 if (role == null) {
9991 companyId = companyProvider.getCompanyId();
9992 }
9993 else {
9994 companyId = role.getCompanyId();
9995 }
9996
9997 for (long newUserPK : newUserPKsSet) {
9998 roleToUserTableMapper.addTableMapping(companyId, pk, newUserPK);
9999 }
10000 }
10001
10002
10008 @Override
10009 public void setUsers(long pk,
10010 List<com.liferay.portal.kernel.model.User> users) {
10011 try {
10012 long[] userPKs = new long[users.size()];
10013
10014 for (int i = 0; i < users.size(); i++) {
10015 com.liferay.portal.kernel.model.User user = users.get(i);
10016
10017 userPKs[i] = user.getPrimaryKey();
10018 }
10019
10020 setUsers(pk, userPKs);
10021 }
10022 catch (Exception e) {
10023 throw processException(e);
10024 }
10025 }
10026
10027 @Override
10028 public Set<String> getBadColumnNames() {
10029 return _badColumnNames;
10030 }
10031
10032 @Override
10033 protected Map<String, Integer> getTableColumnsMap() {
10034 return RoleModelImpl.TABLE_COLUMNS_MAP;
10035 }
10036
10037
10040 public void afterPropertiesSet() {
10041 roleToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Roles",
10042 "companyId", "roleId", "groupId", this, groupPersistence);
10043
10044 roleToUserTableMapper = TableMapperFactory.getTableMapper("Users_Roles",
10045 "companyId", "roleId", "userId", this, userPersistence);
10046 }
10047
10048 public void destroy() {
10049 entityCache.removeCache(RoleImpl.class.getName());
10050 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
10051 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10052 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10053
10054 TableMapperFactory.removeTableMapper("Groups_Roles");
10055 TableMapperFactory.removeTableMapper("Users_Roles");
10056 }
10057
10058 @BeanReference(type = CompanyProviderWrapper.class)
10059 protected CompanyProvider companyProvider;
10060 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
10061 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
10062 @BeanReference(type = GroupPersistence.class)
10063 protected GroupPersistence groupPersistence;
10064 protected TableMapper<Role, com.liferay.portal.kernel.model.Group> roleToGroupTableMapper;
10065 @BeanReference(type = UserPersistence.class)
10066 protected UserPersistence userPersistence;
10067 protected TableMapper<Role, com.liferay.portal.kernel.model.User> roleToUserTableMapper;
10068 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
10069 private static final String _SQL_SELECT_ROLE_WHERE_PKS_IN = "SELECT role FROM Role role WHERE roleId IN (";
10070 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
10071 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
10072 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
10073 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
10074 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
10075 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
10076 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
10077 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
10078 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
10079 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
10080 private static final String _FILTER_ENTITY_ALIAS = "role";
10081 private static final String _FILTER_ENTITY_TABLE = "Role_";
10082 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
10083 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
10084 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
10085 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
10086 private static final Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
10087 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
10088 "uuid", "type"
10089 });
10090 private static final Role _nullRole = new RoleImpl() {
10091 @Override
10092 public Object clone() {
10093 return this;
10094 }
10095
10096 @Override
10097 public CacheModel<Role> toCacheModel() {
10098 return _nullRoleCacheModel;
10099 }
10100 };
10101
10102 private static final CacheModel<Role> _nullRoleCacheModel = new NullCacheModel();
10103
10104 private static class NullCacheModel implements CacheModel<Role>, MVCCModel {
10105 @Override
10106 public long getMvccVersion() {
10107 return -1;
10108 }
10109
10110 @Override
10111 public void setMvccVersion(long mvccVersion) {
10112 }
10113
10114 @Override
10115 public Role toEntityModel() {
10116 return _nullRole;
10117 }
10118 }
10119 }