001
014
015 package com.liferay.portal.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
019 import com.liferay.portal.exception.NoSuchRoleException;
020 import com.liferay.portal.kernel.bean.BeanReference;
021 import com.liferay.portal.kernel.dao.orm.EntityCache;
022 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
023 import com.liferay.portal.kernel.dao.orm.FinderCache;
024 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
025 import com.liferay.portal.kernel.dao.orm.FinderPath;
026 import com.liferay.portal.kernel.dao.orm.Query;
027 import com.liferay.portal.kernel.dao.orm.QueryPos;
028 import com.liferay.portal.kernel.dao.orm.QueryUtil;
029 import com.liferay.portal.kernel.dao.orm.SQLQuery;
030 import com.liferay.portal.kernel.dao.orm.Session;
031 import com.liferay.portal.kernel.log.Log;
032 import com.liferay.portal.kernel.log.LogFactoryUtil;
033 import com.liferay.portal.kernel.util.ArrayUtil;
034 import com.liferay.portal.kernel.util.OrderByComparator;
035 import com.liferay.portal.kernel.util.SetUtil;
036 import com.liferay.portal.kernel.util.StringBundler;
037 import com.liferay.portal.kernel.util.StringPool;
038 import com.liferay.portal.kernel.util.StringUtil;
039 import com.liferay.portal.kernel.util.Validator;
040 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
041 import com.liferay.portal.model.CacheModel;
042 import com.liferay.portal.model.MVCCModel;
043 import com.liferay.portal.model.Role;
044 import com.liferay.portal.model.impl.RoleImpl;
045 import com.liferay.portal.model.impl.RoleModelImpl;
046 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047 import com.liferay.portal.service.ServiceContext;
048 import com.liferay.portal.service.ServiceContextThreadLocal;
049 import com.liferay.portal.service.persistence.CompanyProvider;
050 import com.liferay.portal.service.persistence.CompanyProviderWrapper;
051 import com.liferay.portal.service.persistence.GroupPersistence;
052 import com.liferay.portal.service.persistence.RolePersistence;
053 import com.liferay.portal.service.persistence.UserPersistence;
054
055 import java.io.Serializable;
056
057 import java.util.Arrays;
058 import java.util.Collections;
059 import java.util.Date;
060 import java.util.HashMap;
061 import java.util.HashSet;
062 import java.util.Iterator;
063 import java.util.List;
064 import java.util.Map;
065 import java.util.Set;
066
067
079 @ProviderType
080 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
081 implements RolePersistence {
082
087 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
088 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
089 ".List1";
090 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
091 ".List2";
092 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
093 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
094 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
095 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
096 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
097 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
098 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
099 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
101 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
102 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
103 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
104 new String[] {
105 String.class.getName(),
106
107 Integer.class.getName(), Integer.class.getName(),
108 OrderByComparator.class.getName()
109 });
110 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
111 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
113 new String[] { String.class.getName() },
114 RoleModelImpl.UUID_COLUMN_BITMASK |
115 RoleModelImpl.NAME_COLUMN_BITMASK);
116 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
117 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
119 new String[] { String.class.getName() });
120
121
127 @Override
128 public List<Role> findByUuid(String uuid) {
129 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
130 }
131
132
144 @Override
145 public List<Role> findByUuid(String uuid, int start, int end) {
146 return findByUuid(uuid, start, end, null);
147 }
148
149
162 @Override
163 public List<Role> findByUuid(String uuid, int start, int end,
164 OrderByComparator<Role> orderByComparator) {
165 return findByUuid(uuid, start, end, orderByComparator, true);
166 }
167
168
182 @Override
183 public List<Role> findByUuid(String uuid, int start, int end,
184 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
185 boolean pagination = true;
186 FinderPath finderPath = null;
187 Object[] finderArgs = null;
188
189 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
190 (orderByComparator == null)) {
191 pagination = false;
192 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
193 finderArgs = new Object[] { uuid };
194 }
195 else {
196 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
197 finderArgs = new Object[] { uuid, start, end, orderByComparator };
198 }
199
200 List<Role> list = null;
201
202 if (retrieveFromCache) {
203 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
204 this);
205
206 if ((list != null) && !list.isEmpty()) {
207 for (Role role : list) {
208 if (!Validator.equals(uuid, role.getUuid())) {
209 list = null;
210
211 break;
212 }
213 }
214 }
215 }
216
217 if (list == null) {
218 StringBundler query = null;
219
220 if (orderByComparator != null) {
221 query = new StringBundler(3 +
222 (orderByComparator.getOrderByFields().length * 3));
223 }
224 else {
225 query = new StringBundler(3);
226 }
227
228 query.append(_SQL_SELECT_ROLE_WHERE);
229
230 boolean bindUuid = false;
231
232 if (uuid == null) {
233 query.append(_FINDER_COLUMN_UUID_UUID_1);
234 }
235 else if (uuid.equals(StringPool.BLANK)) {
236 query.append(_FINDER_COLUMN_UUID_UUID_3);
237 }
238 else {
239 bindUuid = true;
240
241 query.append(_FINDER_COLUMN_UUID_UUID_2);
242 }
243
244 if (orderByComparator != null) {
245 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
246 orderByComparator);
247 }
248 else
249 if (pagination) {
250 query.append(RoleModelImpl.ORDER_BY_JPQL);
251 }
252
253 String sql = query.toString();
254
255 Session session = null;
256
257 try {
258 session = openSession();
259
260 Query q = session.createQuery(sql);
261
262 QueryPos qPos = QueryPos.getInstance(q);
263
264 if (bindUuid) {
265 qPos.add(uuid);
266 }
267
268 if (!pagination) {
269 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
270 end, false);
271
272 Collections.sort(list);
273
274 list = Collections.unmodifiableList(list);
275 }
276 else {
277 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
278 end);
279 }
280
281 cacheResult(list);
282
283 finderCache.putResult(finderPath, finderArgs, list);
284 }
285 catch (Exception e) {
286 finderCache.removeResult(finderPath, finderArgs);
287
288 throw processException(e);
289 }
290 finally {
291 closeSession(session);
292 }
293 }
294
295 return list;
296 }
297
298
306 @Override
307 public Role findByUuid_First(String uuid,
308 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
309 Role role = fetchByUuid_First(uuid, orderByComparator);
310
311 if (role != null) {
312 return role;
313 }
314
315 StringBundler msg = new StringBundler(4);
316
317 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
318
319 msg.append("uuid=");
320 msg.append(uuid);
321
322 msg.append(StringPool.CLOSE_CURLY_BRACE);
323
324 throw new NoSuchRoleException(msg.toString());
325 }
326
327
334 @Override
335 public Role fetchByUuid_First(String uuid,
336 OrderByComparator<Role> orderByComparator) {
337 List<Role> list = findByUuid(uuid, 0, 1, orderByComparator);
338
339 if (!list.isEmpty()) {
340 return list.get(0);
341 }
342
343 return null;
344 }
345
346
354 @Override
355 public Role findByUuid_Last(String uuid,
356 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
357 Role role = fetchByUuid_Last(uuid, orderByComparator);
358
359 if (role != null) {
360 return role;
361 }
362
363 StringBundler msg = new StringBundler(4);
364
365 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
366
367 msg.append("uuid=");
368 msg.append(uuid);
369
370 msg.append(StringPool.CLOSE_CURLY_BRACE);
371
372 throw new NoSuchRoleException(msg.toString());
373 }
374
375
382 @Override
383 public Role fetchByUuid_Last(String uuid,
384 OrderByComparator<Role> orderByComparator) {
385 int count = countByUuid(uuid);
386
387 if (count == 0) {
388 return null;
389 }
390
391 List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator);
392
393 if (!list.isEmpty()) {
394 return list.get(0);
395 }
396
397 return null;
398 }
399
400
409 @Override
410 public Role[] findByUuid_PrevAndNext(long roleId, String uuid,
411 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
412 Role role = findByPrimaryKey(roleId);
413
414 Session session = null;
415
416 try {
417 session = openSession();
418
419 Role[] array = new RoleImpl[3];
420
421 array[0] = getByUuid_PrevAndNext(session, role, uuid,
422 orderByComparator, true);
423
424 array[1] = role;
425
426 array[2] = getByUuid_PrevAndNext(session, role, uuid,
427 orderByComparator, false);
428
429 return array;
430 }
431 catch (Exception e) {
432 throw processException(e);
433 }
434 finally {
435 closeSession(session);
436 }
437 }
438
439 protected Role getByUuid_PrevAndNext(Session session, Role role,
440 String uuid, OrderByComparator<Role> orderByComparator, boolean previous) {
441 StringBundler query = null;
442
443 if (orderByComparator != null) {
444 query = new StringBundler(6 +
445 (orderByComparator.getOrderByFields().length * 6));
446 }
447 else {
448 query = new StringBundler(3);
449 }
450
451 query.append(_SQL_SELECT_ROLE_WHERE);
452
453 boolean bindUuid = false;
454
455 if (uuid == null) {
456 query.append(_FINDER_COLUMN_UUID_UUID_1);
457 }
458 else if (uuid.equals(StringPool.BLANK)) {
459 query.append(_FINDER_COLUMN_UUID_UUID_3);
460 }
461 else {
462 bindUuid = true;
463
464 query.append(_FINDER_COLUMN_UUID_UUID_2);
465 }
466
467 if (orderByComparator != null) {
468 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
469
470 if (orderByConditionFields.length > 0) {
471 query.append(WHERE_AND);
472 }
473
474 for (int i = 0; i < orderByConditionFields.length; i++) {
475 query.append(_ORDER_BY_ENTITY_ALIAS);
476 query.append(orderByConditionFields[i]);
477
478 if ((i + 1) < orderByConditionFields.length) {
479 if (orderByComparator.isAscending() ^ previous) {
480 query.append(WHERE_GREATER_THAN_HAS_NEXT);
481 }
482 else {
483 query.append(WHERE_LESSER_THAN_HAS_NEXT);
484 }
485 }
486 else {
487 if (orderByComparator.isAscending() ^ previous) {
488 query.append(WHERE_GREATER_THAN);
489 }
490 else {
491 query.append(WHERE_LESSER_THAN);
492 }
493 }
494 }
495
496 query.append(ORDER_BY_CLAUSE);
497
498 String[] orderByFields = orderByComparator.getOrderByFields();
499
500 for (int i = 0; i < orderByFields.length; i++) {
501 query.append(_ORDER_BY_ENTITY_ALIAS);
502 query.append(orderByFields[i]);
503
504 if ((i + 1) < orderByFields.length) {
505 if (orderByComparator.isAscending() ^ previous) {
506 query.append(ORDER_BY_ASC_HAS_NEXT);
507 }
508 else {
509 query.append(ORDER_BY_DESC_HAS_NEXT);
510 }
511 }
512 else {
513 if (orderByComparator.isAscending() ^ previous) {
514 query.append(ORDER_BY_ASC);
515 }
516 else {
517 query.append(ORDER_BY_DESC);
518 }
519 }
520 }
521 }
522 else {
523 query.append(RoleModelImpl.ORDER_BY_JPQL);
524 }
525
526 String sql = query.toString();
527
528 Query q = session.createQuery(sql);
529
530 q.setFirstResult(0);
531 q.setMaxResults(2);
532
533 QueryPos qPos = QueryPos.getInstance(q);
534
535 if (bindUuid) {
536 qPos.add(uuid);
537 }
538
539 if (orderByComparator != null) {
540 Object[] values = orderByComparator.getOrderByConditionValues(role);
541
542 for (Object value : values) {
543 qPos.add(value);
544 }
545 }
546
547 List<Role> list = q.list();
548
549 if (list.size() == 2) {
550 return list.get(1);
551 }
552 else {
553 return null;
554 }
555 }
556
557
563 @Override
564 public List<Role> filterFindByUuid(String uuid) {
565 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
566 }
567
568
580 @Override
581 public List<Role> filterFindByUuid(String uuid, int start, int end) {
582 return filterFindByUuid(uuid, start, end, null);
583 }
584
585
598 @Override
599 public List<Role> filterFindByUuid(String uuid, int start, int end,
600 OrderByComparator<Role> orderByComparator) {
601 if (!InlineSQLHelperUtil.isEnabled()) {
602 return findByUuid(uuid, start, end, orderByComparator);
603 }
604
605 StringBundler query = null;
606
607 if (orderByComparator != null) {
608 query = new StringBundler(3 +
609 (orderByComparator.getOrderByFields().length * 3));
610 }
611 else {
612 query = new StringBundler(3);
613 }
614
615 if (getDB().isSupportsInlineDistinct()) {
616 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
617 }
618 else {
619 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
620 }
621
622 boolean bindUuid = false;
623
624 if (uuid == null) {
625 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
626 }
627 else if (uuid.equals(StringPool.BLANK)) {
628 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
629 }
630 else {
631 bindUuid = true;
632
633 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
634 }
635
636 if (!getDB().isSupportsInlineDistinct()) {
637 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
638 }
639
640 if (orderByComparator != null) {
641 if (getDB().isSupportsInlineDistinct()) {
642 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
643 orderByComparator, true);
644 }
645 else {
646 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
647 orderByComparator, true);
648 }
649 }
650 else {
651 if (getDB().isSupportsInlineDistinct()) {
652 query.append(RoleModelImpl.ORDER_BY_JPQL);
653 }
654 else {
655 query.append(RoleModelImpl.ORDER_BY_SQL);
656 }
657 }
658
659 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
660 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
661
662 Session session = null;
663
664 try {
665 session = openSession();
666
667 SQLQuery q = session.createSynchronizedSQLQuery(sql);
668
669 if (getDB().isSupportsInlineDistinct()) {
670 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
671 }
672 else {
673 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
674 }
675
676 QueryPos qPos = QueryPos.getInstance(q);
677
678 if (bindUuid) {
679 qPos.add(uuid);
680 }
681
682 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
683 }
684 catch (Exception e) {
685 throw processException(e);
686 }
687 finally {
688 closeSession(session);
689 }
690 }
691
692
701 @Override
702 public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid,
703 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
704 if (!InlineSQLHelperUtil.isEnabled()) {
705 return findByUuid_PrevAndNext(roleId, uuid, orderByComparator);
706 }
707
708 Role role = findByPrimaryKey(roleId);
709
710 Session session = null;
711
712 try {
713 session = openSession();
714
715 Role[] array = new RoleImpl[3];
716
717 array[0] = filterGetByUuid_PrevAndNext(session, role, uuid,
718 orderByComparator, true);
719
720 array[1] = role;
721
722 array[2] = filterGetByUuid_PrevAndNext(session, role, uuid,
723 orderByComparator, false);
724
725 return array;
726 }
727 catch (Exception e) {
728 throw processException(e);
729 }
730 finally {
731 closeSession(session);
732 }
733 }
734
735 protected Role filterGetByUuid_PrevAndNext(Session session, Role role,
736 String uuid, OrderByComparator<Role> orderByComparator, boolean previous) {
737 StringBundler query = null;
738
739 if (orderByComparator != null) {
740 query = new StringBundler(6 +
741 (orderByComparator.getOrderByFields().length * 6));
742 }
743 else {
744 query = new StringBundler(3);
745 }
746
747 if (getDB().isSupportsInlineDistinct()) {
748 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
749 }
750 else {
751 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
752 }
753
754 boolean bindUuid = false;
755
756 if (uuid == null) {
757 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
758 }
759 else if (uuid.equals(StringPool.BLANK)) {
760 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
761 }
762 else {
763 bindUuid = true;
764
765 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
766 }
767
768 if (!getDB().isSupportsInlineDistinct()) {
769 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
770 }
771
772 if (orderByComparator != null) {
773 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
774
775 if (orderByConditionFields.length > 0) {
776 query.append(WHERE_AND);
777 }
778
779 for (int i = 0; i < orderByConditionFields.length; i++) {
780 if (getDB().isSupportsInlineDistinct()) {
781 query.append(_ORDER_BY_ENTITY_ALIAS);
782 }
783 else {
784 query.append(_ORDER_BY_ENTITY_TABLE);
785 }
786
787 query.append(orderByConditionFields[i]);
788
789 if ((i + 1) < orderByConditionFields.length) {
790 if (orderByComparator.isAscending() ^ previous) {
791 query.append(WHERE_GREATER_THAN_HAS_NEXT);
792 }
793 else {
794 query.append(WHERE_LESSER_THAN_HAS_NEXT);
795 }
796 }
797 else {
798 if (orderByComparator.isAscending() ^ previous) {
799 query.append(WHERE_GREATER_THAN);
800 }
801 else {
802 query.append(WHERE_LESSER_THAN);
803 }
804 }
805 }
806
807 query.append(ORDER_BY_CLAUSE);
808
809 String[] orderByFields = orderByComparator.getOrderByFields();
810
811 for (int i = 0; i < orderByFields.length; i++) {
812 if (getDB().isSupportsInlineDistinct()) {
813 query.append(_ORDER_BY_ENTITY_ALIAS);
814 }
815 else {
816 query.append(_ORDER_BY_ENTITY_TABLE);
817 }
818
819 query.append(orderByFields[i]);
820
821 if ((i + 1) < orderByFields.length) {
822 if (orderByComparator.isAscending() ^ previous) {
823 query.append(ORDER_BY_ASC_HAS_NEXT);
824 }
825 else {
826 query.append(ORDER_BY_DESC_HAS_NEXT);
827 }
828 }
829 else {
830 if (orderByComparator.isAscending() ^ previous) {
831 query.append(ORDER_BY_ASC);
832 }
833 else {
834 query.append(ORDER_BY_DESC);
835 }
836 }
837 }
838 }
839 else {
840 if (getDB().isSupportsInlineDistinct()) {
841 query.append(RoleModelImpl.ORDER_BY_JPQL);
842 }
843 else {
844 query.append(RoleModelImpl.ORDER_BY_SQL);
845 }
846 }
847
848 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
849 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
850
851 SQLQuery q = session.createSynchronizedSQLQuery(sql);
852
853 q.setFirstResult(0);
854 q.setMaxResults(2);
855
856 if (getDB().isSupportsInlineDistinct()) {
857 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
858 }
859 else {
860 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
861 }
862
863 QueryPos qPos = QueryPos.getInstance(q);
864
865 if (bindUuid) {
866 qPos.add(uuid);
867 }
868
869 if (orderByComparator != null) {
870 Object[] values = orderByComparator.getOrderByConditionValues(role);
871
872 for (Object value : values) {
873 qPos.add(value);
874 }
875 }
876
877 List<Role> list = q.list();
878
879 if (list.size() == 2) {
880 return list.get(1);
881 }
882 else {
883 return null;
884 }
885 }
886
887
892 @Override
893 public void removeByUuid(String uuid) {
894 for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
895 null)) {
896 remove(role);
897 }
898 }
899
900
906 @Override
907 public int countByUuid(String uuid) {
908 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
909
910 Object[] finderArgs = new Object[] { uuid };
911
912 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
913
914 if (count == null) {
915 StringBundler query = new StringBundler(2);
916
917 query.append(_SQL_COUNT_ROLE_WHERE);
918
919 boolean bindUuid = false;
920
921 if (uuid == null) {
922 query.append(_FINDER_COLUMN_UUID_UUID_1);
923 }
924 else if (uuid.equals(StringPool.BLANK)) {
925 query.append(_FINDER_COLUMN_UUID_UUID_3);
926 }
927 else {
928 bindUuid = true;
929
930 query.append(_FINDER_COLUMN_UUID_UUID_2);
931 }
932
933 String sql = query.toString();
934
935 Session session = null;
936
937 try {
938 session = openSession();
939
940 Query q = session.createQuery(sql);
941
942 QueryPos qPos = QueryPos.getInstance(q);
943
944 if (bindUuid) {
945 qPos.add(uuid);
946 }
947
948 count = (Long)q.uniqueResult();
949
950 finderCache.putResult(finderPath, finderArgs, count);
951 }
952 catch (Exception e) {
953 finderCache.removeResult(finderPath, finderArgs);
954
955 throw processException(e);
956 }
957 finally {
958 closeSession(session);
959 }
960 }
961
962 return count.intValue();
963 }
964
965
971 @Override
972 public int filterCountByUuid(String uuid) {
973 if (!InlineSQLHelperUtil.isEnabled()) {
974 return countByUuid(uuid);
975 }
976
977 StringBundler query = new StringBundler(2);
978
979 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
980
981 boolean bindUuid = false;
982
983 if (uuid == null) {
984 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
985 }
986 else if (uuid.equals(StringPool.BLANK)) {
987 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
988 }
989 else {
990 bindUuid = true;
991
992 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
993 }
994
995 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
996 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
997
998 Session session = null;
999
1000 try {
1001 session = openSession();
1002
1003 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1004
1005 q.addScalar(COUNT_COLUMN_NAME,
1006 com.liferay.portal.kernel.dao.orm.Type.LONG);
1007
1008 QueryPos qPos = QueryPos.getInstance(q);
1009
1010 if (bindUuid) {
1011 qPos.add(uuid);
1012 }
1013
1014 Long count = (Long)q.uniqueResult();
1015
1016 return count.intValue();
1017 }
1018 catch (Exception e) {
1019 throw processException(e);
1020 }
1021 finally {
1022 closeSession(session);
1023 }
1024 }
1025
1026 private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL";
1027 private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?";
1028 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')";
1029 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL";
1030 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?";
1031 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')";
1032 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1033 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1034 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1035 new String[] {
1036 String.class.getName(), Long.class.getName(),
1037
1038 Integer.class.getName(), Integer.class.getName(),
1039 OrderByComparator.class.getName()
1040 });
1041 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1042 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1043 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1044 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1045 new String[] { String.class.getName(), Long.class.getName() },
1046 RoleModelImpl.UUID_COLUMN_BITMASK |
1047 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1048 RoleModelImpl.NAME_COLUMN_BITMASK);
1049 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1050 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1051 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1052 new String[] { String.class.getName(), Long.class.getName() });
1053
1054
1061 @Override
1062 public List<Role> findByUuid_C(String uuid, long companyId) {
1063 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1064 QueryUtil.ALL_POS, null);
1065 }
1066
1067
1080 @Override
1081 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1082 int end) {
1083 return findByUuid_C(uuid, companyId, start, end, null);
1084 }
1085
1086
1100 @Override
1101 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1102 int end, OrderByComparator<Role> orderByComparator) {
1103 return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
1104 }
1105
1106
1121 @Override
1122 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1123 int end, OrderByComparator<Role> orderByComparator,
1124 boolean retrieveFromCache) {
1125 boolean pagination = true;
1126 FinderPath finderPath = null;
1127 Object[] finderArgs = null;
1128
1129 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1130 (orderByComparator == null)) {
1131 pagination = false;
1132 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1133 finderArgs = new Object[] { uuid, companyId };
1134 }
1135 else {
1136 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1137 finderArgs = new Object[] {
1138 uuid, companyId,
1139
1140 start, end, orderByComparator
1141 };
1142 }
1143
1144 List<Role> list = null;
1145
1146 if (retrieveFromCache) {
1147 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
1148 this);
1149
1150 if ((list != null) && !list.isEmpty()) {
1151 for (Role role : list) {
1152 if (!Validator.equals(uuid, role.getUuid()) ||
1153 (companyId != role.getCompanyId())) {
1154 list = null;
1155
1156 break;
1157 }
1158 }
1159 }
1160 }
1161
1162 if (list == null) {
1163 StringBundler query = null;
1164
1165 if (orderByComparator != null) {
1166 query = new StringBundler(4 +
1167 (orderByComparator.getOrderByFields().length * 3));
1168 }
1169 else {
1170 query = new StringBundler(4);
1171 }
1172
1173 query.append(_SQL_SELECT_ROLE_WHERE);
1174
1175 boolean bindUuid = false;
1176
1177 if (uuid == null) {
1178 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1179 }
1180 else if (uuid.equals(StringPool.BLANK)) {
1181 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1182 }
1183 else {
1184 bindUuid = true;
1185
1186 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1187 }
1188
1189 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1190
1191 if (orderByComparator != null) {
1192 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1193 orderByComparator);
1194 }
1195 else
1196 if (pagination) {
1197 query.append(RoleModelImpl.ORDER_BY_JPQL);
1198 }
1199
1200 String sql = query.toString();
1201
1202 Session session = null;
1203
1204 try {
1205 session = openSession();
1206
1207 Query q = session.createQuery(sql);
1208
1209 QueryPos qPos = QueryPos.getInstance(q);
1210
1211 if (bindUuid) {
1212 qPos.add(uuid);
1213 }
1214
1215 qPos.add(companyId);
1216
1217 if (!pagination) {
1218 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1219 end, false);
1220
1221 Collections.sort(list);
1222
1223 list = Collections.unmodifiableList(list);
1224 }
1225 else {
1226 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1227 end);
1228 }
1229
1230 cacheResult(list);
1231
1232 finderCache.putResult(finderPath, finderArgs, list);
1233 }
1234 catch (Exception e) {
1235 finderCache.removeResult(finderPath, finderArgs);
1236
1237 throw processException(e);
1238 }
1239 finally {
1240 closeSession(session);
1241 }
1242 }
1243
1244 return list;
1245 }
1246
1247
1256 @Override
1257 public Role findByUuid_C_First(String uuid, long companyId,
1258 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
1259 Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1260
1261 if (role != null) {
1262 return role;
1263 }
1264
1265 StringBundler msg = new StringBundler(6);
1266
1267 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1268
1269 msg.append("uuid=");
1270 msg.append(uuid);
1271
1272 msg.append(", companyId=");
1273 msg.append(companyId);
1274
1275 msg.append(StringPool.CLOSE_CURLY_BRACE);
1276
1277 throw new NoSuchRoleException(msg.toString());
1278 }
1279
1280
1288 @Override
1289 public Role fetchByUuid_C_First(String uuid, long companyId,
1290 OrderByComparator<Role> orderByComparator) {
1291 List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1292
1293 if (!list.isEmpty()) {
1294 return list.get(0);
1295 }
1296
1297 return null;
1298 }
1299
1300
1309 @Override
1310 public Role findByUuid_C_Last(String uuid, long companyId,
1311 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
1312 Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1313
1314 if (role != null) {
1315 return role;
1316 }
1317
1318 StringBundler msg = new StringBundler(6);
1319
1320 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1321
1322 msg.append("uuid=");
1323 msg.append(uuid);
1324
1325 msg.append(", companyId=");
1326 msg.append(companyId);
1327
1328 msg.append(StringPool.CLOSE_CURLY_BRACE);
1329
1330 throw new NoSuchRoleException(msg.toString());
1331 }
1332
1333
1341 @Override
1342 public Role fetchByUuid_C_Last(String uuid, long companyId,
1343 OrderByComparator<Role> orderByComparator) {
1344 int count = countByUuid_C(uuid, companyId);
1345
1346 if (count == 0) {
1347 return null;
1348 }
1349
1350 List<Role> list = findByUuid_C(uuid, companyId, count - 1, count,
1351 orderByComparator);
1352
1353 if (!list.isEmpty()) {
1354 return list.get(0);
1355 }
1356
1357 return null;
1358 }
1359
1360
1370 @Override
1371 public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid,
1372 long companyId, OrderByComparator<Role> orderByComparator)
1373 throws NoSuchRoleException {
1374 Role role = findByPrimaryKey(roleId);
1375
1376 Session session = null;
1377
1378 try {
1379 session = openSession();
1380
1381 Role[] array = new RoleImpl[3];
1382
1383 array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1384 orderByComparator, true);
1385
1386 array[1] = role;
1387
1388 array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1389 orderByComparator, false);
1390
1391 return array;
1392 }
1393 catch (Exception e) {
1394 throw processException(e);
1395 }
1396 finally {
1397 closeSession(session);
1398 }
1399 }
1400
1401 protected Role getByUuid_C_PrevAndNext(Session session, Role role,
1402 String uuid, long companyId, OrderByComparator<Role> orderByComparator,
1403 boolean previous) {
1404 StringBundler query = null;
1405
1406 if (orderByComparator != null) {
1407 query = new StringBundler(6 +
1408 (orderByComparator.getOrderByFields().length * 6));
1409 }
1410 else {
1411 query = new StringBundler(3);
1412 }
1413
1414 query.append(_SQL_SELECT_ROLE_WHERE);
1415
1416 boolean bindUuid = false;
1417
1418 if (uuid == null) {
1419 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1420 }
1421 else if (uuid.equals(StringPool.BLANK)) {
1422 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1423 }
1424 else {
1425 bindUuid = true;
1426
1427 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1428 }
1429
1430 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1431
1432 if (orderByComparator != null) {
1433 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1434
1435 if (orderByConditionFields.length > 0) {
1436 query.append(WHERE_AND);
1437 }
1438
1439 for (int i = 0; i < orderByConditionFields.length; i++) {
1440 query.append(_ORDER_BY_ENTITY_ALIAS);
1441 query.append(orderByConditionFields[i]);
1442
1443 if ((i + 1) < orderByConditionFields.length) {
1444 if (orderByComparator.isAscending() ^ previous) {
1445 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1446 }
1447 else {
1448 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1449 }
1450 }
1451 else {
1452 if (orderByComparator.isAscending() ^ previous) {
1453 query.append(WHERE_GREATER_THAN);
1454 }
1455 else {
1456 query.append(WHERE_LESSER_THAN);
1457 }
1458 }
1459 }
1460
1461 query.append(ORDER_BY_CLAUSE);
1462
1463 String[] orderByFields = orderByComparator.getOrderByFields();
1464
1465 for (int i = 0; i < orderByFields.length; i++) {
1466 query.append(_ORDER_BY_ENTITY_ALIAS);
1467 query.append(orderByFields[i]);
1468
1469 if ((i + 1) < orderByFields.length) {
1470 if (orderByComparator.isAscending() ^ previous) {
1471 query.append(ORDER_BY_ASC_HAS_NEXT);
1472 }
1473 else {
1474 query.append(ORDER_BY_DESC_HAS_NEXT);
1475 }
1476 }
1477 else {
1478 if (orderByComparator.isAscending() ^ previous) {
1479 query.append(ORDER_BY_ASC);
1480 }
1481 else {
1482 query.append(ORDER_BY_DESC);
1483 }
1484 }
1485 }
1486 }
1487 else {
1488 query.append(RoleModelImpl.ORDER_BY_JPQL);
1489 }
1490
1491 String sql = query.toString();
1492
1493 Query q = session.createQuery(sql);
1494
1495 q.setFirstResult(0);
1496 q.setMaxResults(2);
1497
1498 QueryPos qPos = QueryPos.getInstance(q);
1499
1500 if (bindUuid) {
1501 qPos.add(uuid);
1502 }
1503
1504 qPos.add(companyId);
1505
1506 if (orderByComparator != null) {
1507 Object[] values = orderByComparator.getOrderByConditionValues(role);
1508
1509 for (Object value : values) {
1510 qPos.add(value);
1511 }
1512 }
1513
1514 List<Role> list = q.list();
1515
1516 if (list.size() == 2) {
1517 return list.get(1);
1518 }
1519 else {
1520 return null;
1521 }
1522 }
1523
1524
1531 @Override
1532 public List<Role> filterFindByUuid_C(String uuid, long companyId) {
1533 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1534 QueryUtil.ALL_POS, null);
1535 }
1536
1537
1550 @Override
1551 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1552 int start, int end) {
1553 return filterFindByUuid_C(uuid, companyId, start, end, null);
1554 }
1555
1556
1570 @Override
1571 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1572 int start, int end, OrderByComparator<Role> orderByComparator) {
1573 if (!InlineSQLHelperUtil.isEnabled()) {
1574 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1575 }
1576
1577 StringBundler query = null;
1578
1579 if (orderByComparator != null) {
1580 query = new StringBundler(4 +
1581 (orderByComparator.getOrderByFields().length * 3));
1582 }
1583 else {
1584 query = new StringBundler(4);
1585 }
1586
1587 if (getDB().isSupportsInlineDistinct()) {
1588 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1589 }
1590 else {
1591 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1592 }
1593
1594 boolean bindUuid = false;
1595
1596 if (uuid == null) {
1597 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1598 }
1599 else if (uuid.equals(StringPool.BLANK)) {
1600 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1601 }
1602 else {
1603 bindUuid = true;
1604
1605 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1606 }
1607
1608 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1609
1610 if (!getDB().isSupportsInlineDistinct()) {
1611 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1612 }
1613
1614 if (orderByComparator != null) {
1615 if (getDB().isSupportsInlineDistinct()) {
1616 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1617 orderByComparator, true);
1618 }
1619 else {
1620 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1621 orderByComparator, true);
1622 }
1623 }
1624 else {
1625 if (getDB().isSupportsInlineDistinct()) {
1626 query.append(RoleModelImpl.ORDER_BY_JPQL);
1627 }
1628 else {
1629 query.append(RoleModelImpl.ORDER_BY_SQL);
1630 }
1631 }
1632
1633 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1634 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1635
1636 Session session = null;
1637
1638 try {
1639 session = openSession();
1640
1641 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1642
1643 if (getDB().isSupportsInlineDistinct()) {
1644 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1645 }
1646 else {
1647 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1648 }
1649
1650 QueryPos qPos = QueryPos.getInstance(q);
1651
1652 if (bindUuid) {
1653 qPos.add(uuid);
1654 }
1655
1656 qPos.add(companyId);
1657
1658 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1659 }
1660 catch (Exception e) {
1661 throw processException(e);
1662 }
1663 finally {
1664 closeSession(session);
1665 }
1666 }
1667
1668
1678 @Override
1679 public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid,
1680 long companyId, OrderByComparator<Role> orderByComparator)
1681 throws NoSuchRoleException {
1682 if (!InlineSQLHelperUtil.isEnabled()) {
1683 return findByUuid_C_PrevAndNext(roleId, uuid, companyId,
1684 orderByComparator);
1685 }
1686
1687 Role role = findByPrimaryKey(roleId);
1688
1689 Session session = null;
1690
1691 try {
1692 session = openSession();
1693
1694 Role[] array = new RoleImpl[3];
1695
1696 array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1697 companyId, orderByComparator, true);
1698
1699 array[1] = role;
1700
1701 array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1702 companyId, orderByComparator, false);
1703
1704 return array;
1705 }
1706 catch (Exception e) {
1707 throw processException(e);
1708 }
1709 finally {
1710 closeSession(session);
1711 }
1712 }
1713
1714 protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role,
1715 String uuid, long companyId, OrderByComparator<Role> orderByComparator,
1716 boolean previous) {
1717 StringBundler query = null;
1718
1719 if (orderByComparator != null) {
1720 query = new StringBundler(6 +
1721 (orderByComparator.getOrderByFields().length * 6));
1722 }
1723 else {
1724 query = new StringBundler(3);
1725 }
1726
1727 if (getDB().isSupportsInlineDistinct()) {
1728 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1729 }
1730 else {
1731 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1732 }
1733
1734 boolean bindUuid = false;
1735
1736 if (uuid == null) {
1737 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1738 }
1739 else if (uuid.equals(StringPool.BLANK)) {
1740 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1741 }
1742 else {
1743 bindUuid = true;
1744
1745 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1746 }
1747
1748 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1749
1750 if (!getDB().isSupportsInlineDistinct()) {
1751 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1752 }
1753
1754 if (orderByComparator != null) {
1755 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1756
1757 if (orderByConditionFields.length > 0) {
1758 query.append(WHERE_AND);
1759 }
1760
1761 for (int i = 0; i < orderByConditionFields.length; i++) {
1762 if (getDB().isSupportsInlineDistinct()) {
1763 query.append(_ORDER_BY_ENTITY_ALIAS);
1764 }
1765 else {
1766 query.append(_ORDER_BY_ENTITY_TABLE);
1767 }
1768
1769 query.append(orderByConditionFields[i]);
1770
1771 if ((i + 1) < orderByConditionFields.length) {
1772 if (orderByComparator.isAscending() ^ previous) {
1773 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1774 }
1775 else {
1776 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1777 }
1778 }
1779 else {
1780 if (orderByComparator.isAscending() ^ previous) {
1781 query.append(WHERE_GREATER_THAN);
1782 }
1783 else {
1784 query.append(WHERE_LESSER_THAN);
1785 }
1786 }
1787 }
1788
1789 query.append(ORDER_BY_CLAUSE);
1790
1791 String[] orderByFields = orderByComparator.getOrderByFields();
1792
1793 for (int i = 0; i < orderByFields.length; i++) {
1794 if (getDB().isSupportsInlineDistinct()) {
1795 query.append(_ORDER_BY_ENTITY_ALIAS);
1796 }
1797 else {
1798 query.append(_ORDER_BY_ENTITY_TABLE);
1799 }
1800
1801 query.append(orderByFields[i]);
1802
1803 if ((i + 1) < orderByFields.length) {
1804 if (orderByComparator.isAscending() ^ previous) {
1805 query.append(ORDER_BY_ASC_HAS_NEXT);
1806 }
1807 else {
1808 query.append(ORDER_BY_DESC_HAS_NEXT);
1809 }
1810 }
1811 else {
1812 if (orderByComparator.isAscending() ^ previous) {
1813 query.append(ORDER_BY_ASC);
1814 }
1815 else {
1816 query.append(ORDER_BY_DESC);
1817 }
1818 }
1819 }
1820 }
1821 else {
1822 if (getDB().isSupportsInlineDistinct()) {
1823 query.append(RoleModelImpl.ORDER_BY_JPQL);
1824 }
1825 else {
1826 query.append(RoleModelImpl.ORDER_BY_SQL);
1827 }
1828 }
1829
1830 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1831 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1832
1833 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1834
1835 q.setFirstResult(0);
1836 q.setMaxResults(2);
1837
1838 if (getDB().isSupportsInlineDistinct()) {
1839 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1840 }
1841 else {
1842 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1843 }
1844
1845 QueryPos qPos = QueryPos.getInstance(q);
1846
1847 if (bindUuid) {
1848 qPos.add(uuid);
1849 }
1850
1851 qPos.add(companyId);
1852
1853 if (orderByComparator != null) {
1854 Object[] values = orderByComparator.getOrderByConditionValues(role);
1855
1856 for (Object value : values) {
1857 qPos.add(value);
1858 }
1859 }
1860
1861 List<Role> list = q.list();
1862
1863 if (list.size() == 2) {
1864 return list.get(1);
1865 }
1866 else {
1867 return null;
1868 }
1869 }
1870
1871
1877 @Override
1878 public void removeByUuid_C(String uuid, long companyId) {
1879 for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1880 QueryUtil.ALL_POS, null)) {
1881 remove(role);
1882 }
1883 }
1884
1885
1892 @Override
1893 public int countByUuid_C(String uuid, long companyId) {
1894 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1895
1896 Object[] finderArgs = new Object[] { uuid, companyId };
1897
1898 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1899
1900 if (count == null) {
1901 StringBundler query = new StringBundler(3);
1902
1903 query.append(_SQL_COUNT_ROLE_WHERE);
1904
1905 boolean bindUuid = false;
1906
1907 if (uuid == null) {
1908 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1909 }
1910 else if (uuid.equals(StringPool.BLANK)) {
1911 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1912 }
1913 else {
1914 bindUuid = true;
1915
1916 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1917 }
1918
1919 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1920
1921 String sql = query.toString();
1922
1923 Session session = null;
1924
1925 try {
1926 session = openSession();
1927
1928 Query q = session.createQuery(sql);
1929
1930 QueryPos qPos = QueryPos.getInstance(q);
1931
1932 if (bindUuid) {
1933 qPos.add(uuid);
1934 }
1935
1936 qPos.add(companyId);
1937
1938 count = (Long)q.uniqueResult();
1939
1940 finderCache.putResult(finderPath, finderArgs, count);
1941 }
1942 catch (Exception e) {
1943 finderCache.removeResult(finderPath, finderArgs);
1944
1945 throw processException(e);
1946 }
1947 finally {
1948 closeSession(session);
1949 }
1950 }
1951
1952 return count.intValue();
1953 }
1954
1955
1962 @Override
1963 public int filterCountByUuid_C(String uuid, long companyId) {
1964 if (!InlineSQLHelperUtil.isEnabled()) {
1965 return countByUuid_C(uuid, companyId);
1966 }
1967
1968 StringBundler query = new StringBundler(3);
1969
1970 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1971
1972 boolean bindUuid = false;
1973
1974 if (uuid == null) {
1975 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1976 }
1977 else if (uuid.equals(StringPool.BLANK)) {
1978 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1979 }
1980 else {
1981 bindUuid = true;
1982
1983 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1984 }
1985
1986 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1987
1988 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1989 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1990
1991 Session session = null;
1992
1993 try {
1994 session = openSession();
1995
1996 SQLQuery q = session.createSynchronizedSQLQuery(sql);
1997
1998 q.addScalar(COUNT_COLUMN_NAME,
1999 com.liferay.portal.kernel.dao.orm.Type.LONG);
2000
2001 QueryPos qPos = QueryPos.getInstance(q);
2002
2003 if (bindUuid) {
2004 qPos.add(uuid);
2005 }
2006
2007 qPos.add(companyId);
2008
2009 Long count = (Long)q.uniqueResult();
2010
2011 return count.intValue();
2012 }
2013 catch (Exception e) {
2014 throw processException(e);
2015 }
2016 finally {
2017 closeSession(session);
2018 }
2019 }
2020
2021 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND ";
2022 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND ";
2023 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND ";
2024 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND ";
2025 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND ";
2026 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND ";
2027 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?";
2028 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2029 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2030 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2031 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2032 new String[] {
2033 Long.class.getName(),
2034
2035 Integer.class.getName(), Integer.class.getName(),
2036 OrderByComparator.class.getName()
2037 });
2038 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2039 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2040 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2041 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2042 new String[] { Long.class.getName() },
2043 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
2044 RoleModelImpl.NAME_COLUMN_BITMASK);
2045 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2046 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2047 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2048 new String[] { Long.class.getName() });
2049
2050
2056 @Override
2057 public List<Role> findByCompanyId(long companyId) {
2058 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2059 null);
2060 }
2061
2062
2074 @Override
2075 public List<Role> findByCompanyId(long companyId, int start, int end) {
2076 return findByCompanyId(companyId, start, end, null);
2077 }
2078
2079
2092 @Override
2093 public List<Role> findByCompanyId(long companyId, int start, int end,
2094 OrderByComparator<Role> orderByComparator) {
2095 return findByCompanyId(companyId, start, end, orderByComparator, true);
2096 }
2097
2098
2112 @Override
2113 public List<Role> findByCompanyId(long companyId, int start, int end,
2114 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
2115 boolean pagination = true;
2116 FinderPath finderPath = null;
2117 Object[] finderArgs = null;
2118
2119 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2120 (orderByComparator == null)) {
2121 pagination = false;
2122 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2123 finderArgs = new Object[] { companyId };
2124 }
2125 else {
2126 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2127 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2128 }
2129
2130 List<Role> list = null;
2131
2132 if (retrieveFromCache) {
2133 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
2134 this);
2135
2136 if ((list != null) && !list.isEmpty()) {
2137 for (Role role : list) {
2138 if ((companyId != role.getCompanyId())) {
2139 list = null;
2140
2141 break;
2142 }
2143 }
2144 }
2145 }
2146
2147 if (list == null) {
2148 StringBundler query = null;
2149
2150 if (orderByComparator != null) {
2151 query = new StringBundler(3 +
2152 (orderByComparator.getOrderByFields().length * 3));
2153 }
2154 else {
2155 query = new StringBundler(3);
2156 }
2157
2158 query.append(_SQL_SELECT_ROLE_WHERE);
2159
2160 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2161
2162 if (orderByComparator != null) {
2163 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2164 orderByComparator);
2165 }
2166 else
2167 if (pagination) {
2168 query.append(RoleModelImpl.ORDER_BY_JPQL);
2169 }
2170
2171 String sql = query.toString();
2172
2173 Session session = null;
2174
2175 try {
2176 session = openSession();
2177
2178 Query q = session.createQuery(sql);
2179
2180 QueryPos qPos = QueryPos.getInstance(q);
2181
2182 qPos.add(companyId);
2183
2184 if (!pagination) {
2185 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2186 end, false);
2187
2188 Collections.sort(list);
2189
2190 list = Collections.unmodifiableList(list);
2191 }
2192 else {
2193 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2194 end);
2195 }
2196
2197 cacheResult(list);
2198
2199 finderCache.putResult(finderPath, finderArgs, list);
2200 }
2201 catch (Exception e) {
2202 finderCache.removeResult(finderPath, finderArgs);
2203
2204 throw processException(e);
2205 }
2206 finally {
2207 closeSession(session);
2208 }
2209 }
2210
2211 return list;
2212 }
2213
2214
2222 @Override
2223 public Role findByCompanyId_First(long companyId,
2224 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2225 Role role = fetchByCompanyId_First(companyId, orderByComparator);
2226
2227 if (role != null) {
2228 return role;
2229 }
2230
2231 StringBundler msg = new StringBundler(4);
2232
2233 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2234
2235 msg.append("companyId=");
2236 msg.append(companyId);
2237
2238 msg.append(StringPool.CLOSE_CURLY_BRACE);
2239
2240 throw new NoSuchRoleException(msg.toString());
2241 }
2242
2243
2250 @Override
2251 public Role fetchByCompanyId_First(long companyId,
2252 OrderByComparator<Role> orderByComparator) {
2253 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2254
2255 if (!list.isEmpty()) {
2256 return list.get(0);
2257 }
2258
2259 return null;
2260 }
2261
2262
2270 @Override
2271 public Role findByCompanyId_Last(long companyId,
2272 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2273 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
2274
2275 if (role != null) {
2276 return role;
2277 }
2278
2279 StringBundler msg = new StringBundler(4);
2280
2281 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2282
2283 msg.append("companyId=");
2284 msg.append(companyId);
2285
2286 msg.append(StringPool.CLOSE_CURLY_BRACE);
2287
2288 throw new NoSuchRoleException(msg.toString());
2289 }
2290
2291
2298 @Override
2299 public Role fetchByCompanyId_Last(long companyId,
2300 OrderByComparator<Role> orderByComparator) {
2301 int count = countByCompanyId(companyId);
2302
2303 if (count == 0) {
2304 return null;
2305 }
2306
2307 List<Role> list = findByCompanyId(companyId, count - 1, count,
2308 orderByComparator);
2309
2310 if (!list.isEmpty()) {
2311 return list.get(0);
2312 }
2313
2314 return null;
2315 }
2316
2317
2326 @Override
2327 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
2328 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
2329 Role role = findByPrimaryKey(roleId);
2330
2331 Session session = null;
2332
2333 try {
2334 session = openSession();
2335
2336 Role[] array = new RoleImpl[3];
2337
2338 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
2339 orderByComparator, true);
2340
2341 array[1] = role;
2342
2343 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
2344 orderByComparator, false);
2345
2346 return array;
2347 }
2348 catch (Exception e) {
2349 throw processException(e);
2350 }
2351 finally {
2352 closeSession(session);
2353 }
2354 }
2355
2356 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
2357 long companyId, OrderByComparator<Role> orderByComparator,
2358 boolean previous) {
2359 StringBundler query = null;
2360
2361 if (orderByComparator != null) {
2362 query = new StringBundler(6 +
2363 (orderByComparator.getOrderByFields().length * 6));
2364 }
2365 else {
2366 query = new StringBundler(3);
2367 }
2368
2369 query.append(_SQL_SELECT_ROLE_WHERE);
2370
2371 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2372
2373 if (orderByComparator != null) {
2374 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2375
2376 if (orderByConditionFields.length > 0) {
2377 query.append(WHERE_AND);
2378 }
2379
2380 for (int i = 0; i < orderByConditionFields.length; i++) {
2381 query.append(_ORDER_BY_ENTITY_ALIAS);
2382 query.append(orderByConditionFields[i]);
2383
2384 if ((i + 1) < orderByConditionFields.length) {
2385 if (orderByComparator.isAscending() ^ previous) {
2386 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2387 }
2388 else {
2389 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2390 }
2391 }
2392 else {
2393 if (orderByComparator.isAscending() ^ previous) {
2394 query.append(WHERE_GREATER_THAN);
2395 }
2396 else {
2397 query.append(WHERE_LESSER_THAN);
2398 }
2399 }
2400 }
2401
2402 query.append(ORDER_BY_CLAUSE);
2403
2404 String[] orderByFields = orderByComparator.getOrderByFields();
2405
2406 for (int i = 0; i < orderByFields.length; i++) {
2407 query.append(_ORDER_BY_ENTITY_ALIAS);
2408 query.append(orderByFields[i]);
2409
2410 if ((i + 1) < orderByFields.length) {
2411 if (orderByComparator.isAscending() ^ previous) {
2412 query.append(ORDER_BY_ASC_HAS_NEXT);
2413 }
2414 else {
2415 query.append(ORDER_BY_DESC_HAS_NEXT);
2416 }
2417 }
2418 else {
2419 if (orderByComparator.isAscending() ^ previous) {
2420 query.append(ORDER_BY_ASC);
2421 }
2422 else {
2423 query.append(ORDER_BY_DESC);
2424 }
2425 }
2426 }
2427 }
2428 else {
2429 query.append(RoleModelImpl.ORDER_BY_JPQL);
2430 }
2431
2432 String sql = query.toString();
2433
2434 Query q = session.createQuery(sql);
2435
2436 q.setFirstResult(0);
2437 q.setMaxResults(2);
2438
2439 QueryPos qPos = QueryPos.getInstance(q);
2440
2441 qPos.add(companyId);
2442
2443 if (orderByComparator != null) {
2444 Object[] values = orderByComparator.getOrderByConditionValues(role);
2445
2446 for (Object value : values) {
2447 qPos.add(value);
2448 }
2449 }
2450
2451 List<Role> list = q.list();
2452
2453 if (list.size() == 2) {
2454 return list.get(1);
2455 }
2456 else {
2457 return null;
2458 }
2459 }
2460
2461
2467 @Override
2468 public List<Role> filterFindByCompanyId(long companyId) {
2469 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2470 QueryUtil.ALL_POS, null);
2471 }
2472
2473
2485 @Override
2486 public List<Role> filterFindByCompanyId(long companyId, int start, int end) {
2487 return filterFindByCompanyId(companyId, start, end, null);
2488 }
2489
2490
2503 @Override
2504 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
2505 OrderByComparator<Role> orderByComparator) {
2506 if (!InlineSQLHelperUtil.isEnabled()) {
2507 return findByCompanyId(companyId, start, end, orderByComparator);
2508 }
2509
2510 StringBundler query = null;
2511
2512 if (orderByComparator != null) {
2513 query = new StringBundler(3 +
2514 (orderByComparator.getOrderByFields().length * 3));
2515 }
2516 else {
2517 query = new StringBundler(3);
2518 }
2519
2520 if (getDB().isSupportsInlineDistinct()) {
2521 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2522 }
2523 else {
2524 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2525 }
2526
2527 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2528
2529 if (!getDB().isSupportsInlineDistinct()) {
2530 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2531 }
2532
2533 if (orderByComparator != null) {
2534 if (getDB().isSupportsInlineDistinct()) {
2535 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2536 orderByComparator, true);
2537 }
2538 else {
2539 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2540 orderByComparator, true);
2541 }
2542 }
2543 else {
2544 if (getDB().isSupportsInlineDistinct()) {
2545 query.append(RoleModelImpl.ORDER_BY_JPQL);
2546 }
2547 else {
2548 query.append(RoleModelImpl.ORDER_BY_SQL);
2549 }
2550 }
2551
2552 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2553 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2554
2555 Session session = null;
2556
2557 try {
2558 session = openSession();
2559
2560 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2561
2562 if (getDB().isSupportsInlineDistinct()) {
2563 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2564 }
2565 else {
2566 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2567 }
2568
2569 QueryPos qPos = QueryPos.getInstance(q);
2570
2571 qPos.add(companyId);
2572
2573 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2574 }
2575 catch (Exception e) {
2576 throw processException(e);
2577 }
2578 finally {
2579 closeSession(session);
2580 }
2581 }
2582
2583
2592 @Override
2593 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
2594 long companyId, OrderByComparator<Role> orderByComparator)
2595 throws NoSuchRoleException {
2596 if (!InlineSQLHelperUtil.isEnabled()) {
2597 return findByCompanyId_PrevAndNext(roleId, companyId,
2598 orderByComparator);
2599 }
2600
2601 Role role = findByPrimaryKey(roleId);
2602
2603 Session session = null;
2604
2605 try {
2606 session = openSession();
2607
2608 Role[] array = new RoleImpl[3];
2609
2610 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
2611 companyId, orderByComparator, true);
2612
2613 array[1] = role;
2614
2615 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
2616 companyId, orderByComparator, false);
2617
2618 return array;
2619 }
2620 catch (Exception e) {
2621 throw processException(e);
2622 }
2623 finally {
2624 closeSession(session);
2625 }
2626 }
2627
2628 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
2629 long companyId, OrderByComparator<Role> orderByComparator,
2630 boolean previous) {
2631 StringBundler query = null;
2632
2633 if (orderByComparator != null) {
2634 query = new StringBundler(6 +
2635 (orderByComparator.getOrderByFields().length * 6));
2636 }
2637 else {
2638 query = new StringBundler(3);
2639 }
2640
2641 if (getDB().isSupportsInlineDistinct()) {
2642 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2643 }
2644 else {
2645 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2646 }
2647
2648 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2649
2650 if (!getDB().isSupportsInlineDistinct()) {
2651 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2652 }
2653
2654 if (orderByComparator != null) {
2655 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2656
2657 if (orderByConditionFields.length > 0) {
2658 query.append(WHERE_AND);
2659 }
2660
2661 for (int i = 0; i < orderByConditionFields.length; i++) {
2662 if (getDB().isSupportsInlineDistinct()) {
2663 query.append(_ORDER_BY_ENTITY_ALIAS);
2664 }
2665 else {
2666 query.append(_ORDER_BY_ENTITY_TABLE);
2667 }
2668
2669 query.append(orderByConditionFields[i]);
2670
2671 if ((i + 1) < orderByConditionFields.length) {
2672 if (orderByComparator.isAscending() ^ previous) {
2673 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2674 }
2675 else {
2676 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2677 }
2678 }
2679 else {
2680 if (orderByComparator.isAscending() ^ previous) {
2681 query.append(WHERE_GREATER_THAN);
2682 }
2683 else {
2684 query.append(WHERE_LESSER_THAN);
2685 }
2686 }
2687 }
2688
2689 query.append(ORDER_BY_CLAUSE);
2690
2691 String[] orderByFields = orderByComparator.getOrderByFields();
2692
2693 for (int i = 0; i < orderByFields.length; i++) {
2694 if (getDB().isSupportsInlineDistinct()) {
2695 query.append(_ORDER_BY_ENTITY_ALIAS);
2696 }
2697 else {
2698 query.append(_ORDER_BY_ENTITY_TABLE);
2699 }
2700
2701 query.append(orderByFields[i]);
2702
2703 if ((i + 1) < orderByFields.length) {
2704 if (orderByComparator.isAscending() ^ previous) {
2705 query.append(ORDER_BY_ASC_HAS_NEXT);
2706 }
2707 else {
2708 query.append(ORDER_BY_DESC_HAS_NEXT);
2709 }
2710 }
2711 else {
2712 if (orderByComparator.isAscending() ^ previous) {
2713 query.append(ORDER_BY_ASC);
2714 }
2715 else {
2716 query.append(ORDER_BY_DESC);
2717 }
2718 }
2719 }
2720 }
2721 else {
2722 if (getDB().isSupportsInlineDistinct()) {
2723 query.append(RoleModelImpl.ORDER_BY_JPQL);
2724 }
2725 else {
2726 query.append(RoleModelImpl.ORDER_BY_SQL);
2727 }
2728 }
2729
2730 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2731 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2732
2733 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2734
2735 q.setFirstResult(0);
2736 q.setMaxResults(2);
2737
2738 if (getDB().isSupportsInlineDistinct()) {
2739 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2740 }
2741 else {
2742 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2743 }
2744
2745 QueryPos qPos = QueryPos.getInstance(q);
2746
2747 qPos.add(companyId);
2748
2749 if (orderByComparator != null) {
2750 Object[] values = orderByComparator.getOrderByConditionValues(role);
2751
2752 for (Object value : values) {
2753 qPos.add(value);
2754 }
2755 }
2756
2757 List<Role> list = q.list();
2758
2759 if (list.size() == 2) {
2760 return list.get(1);
2761 }
2762 else {
2763 return null;
2764 }
2765 }
2766
2767
2772 @Override
2773 public void removeByCompanyId(long companyId) {
2774 for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
2775 QueryUtil.ALL_POS, null)) {
2776 remove(role);
2777 }
2778 }
2779
2780
2786 @Override
2787 public int countByCompanyId(long companyId) {
2788 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2789
2790 Object[] finderArgs = new Object[] { companyId };
2791
2792 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2793
2794 if (count == null) {
2795 StringBundler query = new StringBundler(2);
2796
2797 query.append(_SQL_COUNT_ROLE_WHERE);
2798
2799 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2800
2801 String sql = query.toString();
2802
2803 Session session = null;
2804
2805 try {
2806 session = openSession();
2807
2808 Query q = session.createQuery(sql);
2809
2810 QueryPos qPos = QueryPos.getInstance(q);
2811
2812 qPos.add(companyId);
2813
2814 count = (Long)q.uniqueResult();
2815
2816 finderCache.putResult(finderPath, finderArgs, count);
2817 }
2818 catch (Exception e) {
2819 finderCache.removeResult(finderPath, finderArgs);
2820
2821 throw processException(e);
2822 }
2823 finally {
2824 closeSession(session);
2825 }
2826 }
2827
2828 return count.intValue();
2829 }
2830
2831
2837 @Override
2838 public int filterCountByCompanyId(long companyId) {
2839 if (!InlineSQLHelperUtil.isEnabled()) {
2840 return countByCompanyId(companyId);
2841 }
2842
2843 StringBundler query = new StringBundler(2);
2844
2845 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2846
2847 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2848
2849 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2850 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2851
2852 Session session = null;
2853
2854 try {
2855 session = openSession();
2856
2857 SQLQuery q = session.createSynchronizedSQLQuery(sql);
2858
2859 q.addScalar(COUNT_COLUMN_NAME,
2860 com.liferay.portal.kernel.dao.orm.Type.LONG);
2861
2862 QueryPos qPos = QueryPos.getInstance(q);
2863
2864 qPos.add(companyId);
2865
2866 Long count = (Long)q.uniqueResult();
2867
2868 return count.intValue();
2869 }
2870 catch (Exception e) {
2871 throw processException(e);
2872 }
2873 finally {
2874 closeSession(session);
2875 }
2876 }
2877
2878 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
2879 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2880 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2881 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
2882 new String[] {
2883 String.class.getName(),
2884
2885 Integer.class.getName(), Integer.class.getName(),
2886 OrderByComparator.class.getName()
2887 });
2888 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2889 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2890 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
2891 new String[] { String.class.getName() },
2892 RoleModelImpl.NAME_COLUMN_BITMASK);
2893 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2894 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2895 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
2896 new String[] { String.class.getName() });
2897
2898
2904 @Override
2905 public List<Role> findByName(String name) {
2906 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2907 }
2908
2909
2921 @Override
2922 public List<Role> findByName(String name, int start, int end) {
2923 return findByName(name, start, end, null);
2924 }
2925
2926
2939 @Override
2940 public List<Role> findByName(String name, int start, int end,
2941 OrderByComparator<Role> orderByComparator) {
2942 return findByName(name, start, end, orderByComparator, true);
2943 }
2944
2945
2959 @Override
2960 public List<Role> findByName(String name, int start, int end,
2961 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
2962 boolean pagination = true;
2963 FinderPath finderPath = null;
2964 Object[] finderArgs = null;
2965
2966 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2967 (orderByComparator == null)) {
2968 pagination = false;
2969 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
2970 finderArgs = new Object[] { name };
2971 }
2972 else {
2973 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
2974 finderArgs = new Object[] { name, start, end, orderByComparator };
2975 }
2976
2977 List<Role> list = null;
2978
2979 if (retrieveFromCache) {
2980 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
2981 this);
2982
2983 if ((list != null) && !list.isEmpty()) {
2984 for (Role role : list) {
2985 if (!Validator.equals(name, role.getName())) {
2986 list = null;
2987
2988 break;
2989 }
2990 }
2991 }
2992 }
2993
2994 if (list == null) {
2995 StringBundler query = null;
2996
2997 if (orderByComparator != null) {
2998 query = new StringBundler(3 +
2999 (orderByComparator.getOrderByFields().length * 3));
3000 }
3001 else {
3002 query = new StringBundler(3);
3003 }
3004
3005 query.append(_SQL_SELECT_ROLE_WHERE);
3006
3007 boolean bindName = false;
3008
3009 if (name == null) {
3010 query.append(_FINDER_COLUMN_NAME_NAME_1);
3011 }
3012 else if (name.equals(StringPool.BLANK)) {
3013 query.append(_FINDER_COLUMN_NAME_NAME_3);
3014 }
3015 else {
3016 bindName = true;
3017
3018 query.append(_FINDER_COLUMN_NAME_NAME_2);
3019 }
3020
3021 if (orderByComparator != null) {
3022 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3023 orderByComparator);
3024 }
3025 else
3026 if (pagination) {
3027 query.append(RoleModelImpl.ORDER_BY_JPQL);
3028 }
3029
3030 String sql = query.toString();
3031
3032 Session session = null;
3033
3034 try {
3035 session = openSession();
3036
3037 Query q = session.createQuery(sql);
3038
3039 QueryPos qPos = QueryPos.getInstance(q);
3040
3041 if (bindName) {
3042 qPos.add(name);
3043 }
3044
3045 if (!pagination) {
3046 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3047 end, false);
3048
3049 Collections.sort(list);
3050
3051 list = Collections.unmodifiableList(list);
3052 }
3053 else {
3054 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3055 end);
3056 }
3057
3058 cacheResult(list);
3059
3060 finderCache.putResult(finderPath, finderArgs, list);
3061 }
3062 catch (Exception e) {
3063 finderCache.removeResult(finderPath, finderArgs);
3064
3065 throw processException(e);
3066 }
3067 finally {
3068 closeSession(session);
3069 }
3070 }
3071
3072 return list;
3073 }
3074
3075
3083 @Override
3084 public Role findByName_First(String name,
3085 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3086 Role role = fetchByName_First(name, orderByComparator);
3087
3088 if (role != null) {
3089 return role;
3090 }
3091
3092 StringBundler msg = new StringBundler(4);
3093
3094 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3095
3096 msg.append("name=");
3097 msg.append(name);
3098
3099 msg.append(StringPool.CLOSE_CURLY_BRACE);
3100
3101 throw new NoSuchRoleException(msg.toString());
3102 }
3103
3104
3111 @Override
3112 public Role fetchByName_First(String name,
3113 OrderByComparator<Role> orderByComparator) {
3114 List<Role> list = findByName(name, 0, 1, orderByComparator);
3115
3116 if (!list.isEmpty()) {
3117 return list.get(0);
3118 }
3119
3120 return null;
3121 }
3122
3123
3131 @Override
3132 public Role findByName_Last(String name,
3133 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3134 Role role = fetchByName_Last(name, orderByComparator);
3135
3136 if (role != null) {
3137 return role;
3138 }
3139
3140 StringBundler msg = new StringBundler(4);
3141
3142 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3143
3144 msg.append("name=");
3145 msg.append(name);
3146
3147 msg.append(StringPool.CLOSE_CURLY_BRACE);
3148
3149 throw new NoSuchRoleException(msg.toString());
3150 }
3151
3152
3159 @Override
3160 public Role fetchByName_Last(String name,
3161 OrderByComparator<Role> orderByComparator) {
3162 int count = countByName(name);
3163
3164 if (count == 0) {
3165 return null;
3166 }
3167
3168 List<Role> list = findByName(name, count - 1, count, orderByComparator);
3169
3170 if (!list.isEmpty()) {
3171 return list.get(0);
3172 }
3173
3174 return null;
3175 }
3176
3177
3186 @Override
3187 public Role[] findByName_PrevAndNext(long roleId, String name,
3188 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3189 Role role = findByPrimaryKey(roleId);
3190
3191 Session session = null;
3192
3193 try {
3194 session = openSession();
3195
3196 Role[] array = new RoleImpl[3];
3197
3198 array[0] = getByName_PrevAndNext(session, role, name,
3199 orderByComparator, true);
3200
3201 array[1] = role;
3202
3203 array[2] = getByName_PrevAndNext(session, role, name,
3204 orderByComparator, false);
3205
3206 return array;
3207 }
3208 catch (Exception e) {
3209 throw processException(e);
3210 }
3211 finally {
3212 closeSession(session);
3213 }
3214 }
3215
3216 protected Role getByName_PrevAndNext(Session session, Role role,
3217 String name, OrderByComparator<Role> orderByComparator, boolean previous) {
3218 StringBundler query = null;
3219
3220 if (orderByComparator != null) {
3221 query = new StringBundler(6 +
3222 (orderByComparator.getOrderByFields().length * 6));
3223 }
3224 else {
3225 query = new StringBundler(3);
3226 }
3227
3228 query.append(_SQL_SELECT_ROLE_WHERE);
3229
3230 boolean bindName = false;
3231
3232 if (name == null) {
3233 query.append(_FINDER_COLUMN_NAME_NAME_1);
3234 }
3235 else if (name.equals(StringPool.BLANK)) {
3236 query.append(_FINDER_COLUMN_NAME_NAME_3);
3237 }
3238 else {
3239 bindName = true;
3240
3241 query.append(_FINDER_COLUMN_NAME_NAME_2);
3242 }
3243
3244 if (orderByComparator != null) {
3245 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3246
3247 if (orderByConditionFields.length > 0) {
3248 query.append(WHERE_AND);
3249 }
3250
3251 for (int i = 0; i < orderByConditionFields.length; i++) {
3252 query.append(_ORDER_BY_ENTITY_ALIAS);
3253 query.append(orderByConditionFields[i]);
3254
3255 if ((i + 1) < orderByConditionFields.length) {
3256 if (orderByComparator.isAscending() ^ previous) {
3257 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3258 }
3259 else {
3260 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3261 }
3262 }
3263 else {
3264 if (orderByComparator.isAscending() ^ previous) {
3265 query.append(WHERE_GREATER_THAN);
3266 }
3267 else {
3268 query.append(WHERE_LESSER_THAN);
3269 }
3270 }
3271 }
3272
3273 query.append(ORDER_BY_CLAUSE);
3274
3275 String[] orderByFields = orderByComparator.getOrderByFields();
3276
3277 for (int i = 0; i < orderByFields.length; i++) {
3278 query.append(_ORDER_BY_ENTITY_ALIAS);
3279 query.append(orderByFields[i]);
3280
3281 if ((i + 1) < orderByFields.length) {
3282 if (orderByComparator.isAscending() ^ previous) {
3283 query.append(ORDER_BY_ASC_HAS_NEXT);
3284 }
3285 else {
3286 query.append(ORDER_BY_DESC_HAS_NEXT);
3287 }
3288 }
3289 else {
3290 if (orderByComparator.isAscending() ^ previous) {
3291 query.append(ORDER_BY_ASC);
3292 }
3293 else {
3294 query.append(ORDER_BY_DESC);
3295 }
3296 }
3297 }
3298 }
3299 else {
3300 query.append(RoleModelImpl.ORDER_BY_JPQL);
3301 }
3302
3303 String sql = query.toString();
3304
3305 Query q = session.createQuery(sql);
3306
3307 q.setFirstResult(0);
3308 q.setMaxResults(2);
3309
3310 QueryPos qPos = QueryPos.getInstance(q);
3311
3312 if (bindName) {
3313 qPos.add(name);
3314 }
3315
3316 if (orderByComparator != null) {
3317 Object[] values = orderByComparator.getOrderByConditionValues(role);
3318
3319 for (Object value : values) {
3320 qPos.add(value);
3321 }
3322 }
3323
3324 List<Role> list = q.list();
3325
3326 if (list.size() == 2) {
3327 return list.get(1);
3328 }
3329 else {
3330 return null;
3331 }
3332 }
3333
3334
3340 @Override
3341 public List<Role> filterFindByName(String name) {
3342 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3343 }
3344
3345
3357 @Override
3358 public List<Role> filterFindByName(String name, int start, int end) {
3359 return filterFindByName(name, start, end, null);
3360 }
3361
3362
3375 @Override
3376 public List<Role> filterFindByName(String name, int start, int end,
3377 OrderByComparator<Role> orderByComparator) {
3378 if (!InlineSQLHelperUtil.isEnabled()) {
3379 return findByName(name, start, end, orderByComparator);
3380 }
3381
3382 StringBundler query = null;
3383
3384 if (orderByComparator != null) {
3385 query = new StringBundler(3 +
3386 (orderByComparator.getOrderByFields().length * 3));
3387 }
3388 else {
3389 query = new StringBundler(3);
3390 }
3391
3392 if (getDB().isSupportsInlineDistinct()) {
3393 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3394 }
3395 else {
3396 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3397 }
3398
3399 boolean bindName = false;
3400
3401 if (name == null) {
3402 query.append(_FINDER_COLUMN_NAME_NAME_1);
3403 }
3404 else if (name.equals(StringPool.BLANK)) {
3405 query.append(_FINDER_COLUMN_NAME_NAME_3);
3406 }
3407 else {
3408 bindName = true;
3409
3410 query.append(_FINDER_COLUMN_NAME_NAME_2);
3411 }
3412
3413 if (!getDB().isSupportsInlineDistinct()) {
3414 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3415 }
3416
3417 if (orderByComparator != null) {
3418 if (getDB().isSupportsInlineDistinct()) {
3419 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3420 orderByComparator, true);
3421 }
3422 else {
3423 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3424 orderByComparator, true);
3425 }
3426 }
3427 else {
3428 if (getDB().isSupportsInlineDistinct()) {
3429 query.append(RoleModelImpl.ORDER_BY_JPQL);
3430 }
3431 else {
3432 query.append(RoleModelImpl.ORDER_BY_SQL);
3433 }
3434 }
3435
3436 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3437 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3438
3439 Session session = null;
3440
3441 try {
3442 session = openSession();
3443
3444 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3445
3446 if (getDB().isSupportsInlineDistinct()) {
3447 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3448 }
3449 else {
3450 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3451 }
3452
3453 QueryPos qPos = QueryPos.getInstance(q);
3454
3455 if (bindName) {
3456 qPos.add(name);
3457 }
3458
3459 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3460 }
3461 catch (Exception e) {
3462 throw processException(e);
3463 }
3464 finally {
3465 closeSession(session);
3466 }
3467 }
3468
3469
3478 @Override
3479 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
3480 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
3481 if (!InlineSQLHelperUtil.isEnabled()) {
3482 return findByName_PrevAndNext(roleId, name, orderByComparator);
3483 }
3484
3485 Role role = findByPrimaryKey(roleId);
3486
3487 Session session = null;
3488
3489 try {
3490 session = openSession();
3491
3492 Role[] array = new RoleImpl[3];
3493
3494 array[0] = filterGetByName_PrevAndNext(session, role, name,
3495 orderByComparator, true);
3496
3497 array[1] = role;
3498
3499 array[2] = filterGetByName_PrevAndNext(session, role, name,
3500 orderByComparator, false);
3501
3502 return array;
3503 }
3504 catch (Exception e) {
3505 throw processException(e);
3506 }
3507 finally {
3508 closeSession(session);
3509 }
3510 }
3511
3512 protected Role filterGetByName_PrevAndNext(Session session, Role role,
3513 String name, OrderByComparator<Role> orderByComparator, boolean previous) {
3514 StringBundler query = null;
3515
3516 if (orderByComparator != null) {
3517 query = new StringBundler(6 +
3518 (orderByComparator.getOrderByFields().length * 6));
3519 }
3520 else {
3521 query = new StringBundler(3);
3522 }
3523
3524 if (getDB().isSupportsInlineDistinct()) {
3525 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3526 }
3527 else {
3528 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3529 }
3530
3531 boolean bindName = false;
3532
3533 if (name == null) {
3534 query.append(_FINDER_COLUMN_NAME_NAME_1);
3535 }
3536 else if (name.equals(StringPool.BLANK)) {
3537 query.append(_FINDER_COLUMN_NAME_NAME_3);
3538 }
3539 else {
3540 bindName = true;
3541
3542 query.append(_FINDER_COLUMN_NAME_NAME_2);
3543 }
3544
3545 if (!getDB().isSupportsInlineDistinct()) {
3546 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3547 }
3548
3549 if (orderByComparator != null) {
3550 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3551
3552 if (orderByConditionFields.length > 0) {
3553 query.append(WHERE_AND);
3554 }
3555
3556 for (int i = 0; i < orderByConditionFields.length; i++) {
3557 if (getDB().isSupportsInlineDistinct()) {
3558 query.append(_ORDER_BY_ENTITY_ALIAS);
3559 }
3560 else {
3561 query.append(_ORDER_BY_ENTITY_TABLE);
3562 }
3563
3564 query.append(orderByConditionFields[i]);
3565
3566 if ((i + 1) < orderByConditionFields.length) {
3567 if (orderByComparator.isAscending() ^ previous) {
3568 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3569 }
3570 else {
3571 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3572 }
3573 }
3574 else {
3575 if (orderByComparator.isAscending() ^ previous) {
3576 query.append(WHERE_GREATER_THAN);
3577 }
3578 else {
3579 query.append(WHERE_LESSER_THAN);
3580 }
3581 }
3582 }
3583
3584 query.append(ORDER_BY_CLAUSE);
3585
3586 String[] orderByFields = orderByComparator.getOrderByFields();
3587
3588 for (int i = 0; i < orderByFields.length; i++) {
3589 if (getDB().isSupportsInlineDistinct()) {
3590 query.append(_ORDER_BY_ENTITY_ALIAS);
3591 }
3592 else {
3593 query.append(_ORDER_BY_ENTITY_TABLE);
3594 }
3595
3596 query.append(orderByFields[i]);
3597
3598 if ((i + 1) < orderByFields.length) {
3599 if (orderByComparator.isAscending() ^ previous) {
3600 query.append(ORDER_BY_ASC_HAS_NEXT);
3601 }
3602 else {
3603 query.append(ORDER_BY_DESC_HAS_NEXT);
3604 }
3605 }
3606 else {
3607 if (orderByComparator.isAscending() ^ previous) {
3608 query.append(ORDER_BY_ASC);
3609 }
3610 else {
3611 query.append(ORDER_BY_DESC);
3612 }
3613 }
3614 }
3615 }
3616 else {
3617 if (getDB().isSupportsInlineDistinct()) {
3618 query.append(RoleModelImpl.ORDER_BY_JPQL);
3619 }
3620 else {
3621 query.append(RoleModelImpl.ORDER_BY_SQL);
3622 }
3623 }
3624
3625 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3626 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3627
3628 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3629
3630 q.setFirstResult(0);
3631 q.setMaxResults(2);
3632
3633 if (getDB().isSupportsInlineDistinct()) {
3634 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3635 }
3636 else {
3637 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3638 }
3639
3640 QueryPos qPos = QueryPos.getInstance(q);
3641
3642 if (bindName) {
3643 qPos.add(name);
3644 }
3645
3646 if (orderByComparator != null) {
3647 Object[] values = orderByComparator.getOrderByConditionValues(role);
3648
3649 for (Object value : values) {
3650 qPos.add(value);
3651 }
3652 }
3653
3654 List<Role> list = q.list();
3655
3656 if (list.size() == 2) {
3657 return list.get(1);
3658 }
3659 else {
3660 return null;
3661 }
3662 }
3663
3664
3669 @Override
3670 public void removeByName(String name) {
3671 for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3672 null)) {
3673 remove(role);
3674 }
3675 }
3676
3677
3683 @Override
3684 public int countByName(String name) {
3685 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
3686
3687 Object[] finderArgs = new Object[] { name };
3688
3689 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
3690
3691 if (count == null) {
3692 StringBundler query = new StringBundler(2);
3693
3694 query.append(_SQL_COUNT_ROLE_WHERE);
3695
3696 boolean bindName = false;
3697
3698 if (name == null) {
3699 query.append(_FINDER_COLUMN_NAME_NAME_1);
3700 }
3701 else if (name.equals(StringPool.BLANK)) {
3702 query.append(_FINDER_COLUMN_NAME_NAME_3);
3703 }
3704 else {
3705 bindName = true;
3706
3707 query.append(_FINDER_COLUMN_NAME_NAME_2);
3708 }
3709
3710 String sql = query.toString();
3711
3712 Session session = null;
3713
3714 try {
3715 session = openSession();
3716
3717 Query q = session.createQuery(sql);
3718
3719 QueryPos qPos = QueryPos.getInstance(q);
3720
3721 if (bindName) {
3722 qPos.add(name);
3723 }
3724
3725 count = (Long)q.uniqueResult();
3726
3727 finderCache.putResult(finderPath, finderArgs, count);
3728 }
3729 catch (Exception e) {
3730 finderCache.removeResult(finderPath, finderArgs);
3731
3732 throw processException(e);
3733 }
3734 finally {
3735 closeSession(session);
3736 }
3737 }
3738
3739 return count.intValue();
3740 }
3741
3742
3748 @Override
3749 public int filterCountByName(String name) {
3750 if (!InlineSQLHelperUtil.isEnabled()) {
3751 return countByName(name);
3752 }
3753
3754 StringBundler query = new StringBundler(2);
3755
3756 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3757
3758 boolean bindName = false;
3759
3760 if (name == null) {
3761 query.append(_FINDER_COLUMN_NAME_NAME_1);
3762 }
3763 else if (name.equals(StringPool.BLANK)) {
3764 query.append(_FINDER_COLUMN_NAME_NAME_3);
3765 }
3766 else {
3767 bindName = true;
3768
3769 query.append(_FINDER_COLUMN_NAME_NAME_2);
3770 }
3771
3772 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3773 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3774
3775 Session session = null;
3776
3777 try {
3778 session = openSession();
3779
3780 SQLQuery q = session.createSynchronizedSQLQuery(sql);
3781
3782 q.addScalar(COUNT_COLUMN_NAME,
3783 com.liferay.portal.kernel.dao.orm.Type.LONG);
3784
3785 QueryPos qPos = QueryPos.getInstance(q);
3786
3787 if (bindName) {
3788 qPos.add(name);
3789 }
3790
3791 Long count = (Long)q.uniqueResult();
3792
3793 return count.intValue();
3794 }
3795 catch (Exception e) {
3796 throw processException(e);
3797 }
3798 finally {
3799 closeSession(session);
3800 }
3801 }
3802
3803 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
3804 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
3805 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')";
3806 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3807 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3808 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3809 new String[] {
3810 Integer.class.getName(),
3811
3812 Integer.class.getName(), Integer.class.getName(),
3813 OrderByComparator.class.getName()
3814 });
3815 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3816 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3817 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3818 new String[] { Integer.class.getName() },
3819 RoleModelImpl.TYPE_COLUMN_BITMASK |
3820 RoleModelImpl.NAME_COLUMN_BITMASK);
3821 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3822 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3823 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3824 new String[] { Integer.class.getName() });
3825
3826
3832 @Override
3833 public List<Role> findByType(int type) {
3834 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3835 }
3836
3837
3849 @Override
3850 public List<Role> findByType(int type, int start, int end) {
3851 return findByType(type, start, end, null);
3852 }
3853
3854
3867 @Override
3868 public List<Role> findByType(int type, int start, int end,
3869 OrderByComparator<Role> orderByComparator) {
3870 return findByType(type, start, end, orderByComparator, true);
3871 }
3872
3873
3887 @Override
3888 public List<Role> findByType(int type, int start, int end,
3889 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
3890 boolean pagination = true;
3891 FinderPath finderPath = null;
3892 Object[] finderArgs = null;
3893
3894 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3895 (orderByComparator == null)) {
3896 pagination = false;
3897 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3898 finderArgs = new Object[] { type };
3899 }
3900 else {
3901 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3902 finderArgs = new Object[] { type, start, end, orderByComparator };
3903 }
3904
3905 List<Role> list = null;
3906
3907 if (retrieveFromCache) {
3908 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
3909 this);
3910
3911 if ((list != null) && !list.isEmpty()) {
3912 for (Role role : list) {
3913 if ((type != role.getType())) {
3914 list = null;
3915
3916 break;
3917 }
3918 }
3919 }
3920 }
3921
3922 if (list == null) {
3923 StringBundler query = null;
3924
3925 if (orderByComparator != null) {
3926 query = new StringBundler(3 +
3927 (orderByComparator.getOrderByFields().length * 3));
3928 }
3929 else {
3930 query = new StringBundler(3);
3931 }
3932
3933 query.append(_SQL_SELECT_ROLE_WHERE);
3934
3935 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3936
3937 if (orderByComparator != null) {
3938 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3939 orderByComparator);
3940 }
3941 else
3942 if (pagination) {
3943 query.append(RoleModelImpl.ORDER_BY_JPQL);
3944 }
3945
3946 String sql = query.toString();
3947
3948 Session session = null;
3949
3950 try {
3951 session = openSession();
3952
3953 Query q = session.createQuery(sql);
3954
3955 QueryPos qPos = QueryPos.getInstance(q);
3956
3957 qPos.add(type);
3958
3959 if (!pagination) {
3960 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3961 end, false);
3962
3963 Collections.sort(list);
3964
3965 list = Collections.unmodifiableList(list);
3966 }
3967 else {
3968 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3969 end);
3970 }
3971
3972 cacheResult(list);
3973
3974 finderCache.putResult(finderPath, finderArgs, list);
3975 }
3976 catch (Exception e) {
3977 finderCache.removeResult(finderPath, finderArgs);
3978
3979 throw processException(e);
3980 }
3981 finally {
3982 closeSession(session);
3983 }
3984 }
3985
3986 return list;
3987 }
3988
3989
3997 @Override
3998 public Role findByType_First(int type,
3999 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4000 Role role = fetchByType_First(type, orderByComparator);
4001
4002 if (role != null) {
4003 return role;
4004 }
4005
4006 StringBundler msg = new StringBundler(4);
4007
4008 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4009
4010 msg.append("type=");
4011 msg.append(type);
4012
4013 msg.append(StringPool.CLOSE_CURLY_BRACE);
4014
4015 throw new NoSuchRoleException(msg.toString());
4016 }
4017
4018
4025 @Override
4026 public Role fetchByType_First(int type,
4027 OrderByComparator<Role> orderByComparator) {
4028 List<Role> list = findByType(type, 0, 1, orderByComparator);
4029
4030 if (!list.isEmpty()) {
4031 return list.get(0);
4032 }
4033
4034 return null;
4035 }
4036
4037
4045 @Override
4046 public Role findByType_Last(int type,
4047 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4048 Role role = fetchByType_Last(type, orderByComparator);
4049
4050 if (role != null) {
4051 return role;
4052 }
4053
4054 StringBundler msg = new StringBundler(4);
4055
4056 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4057
4058 msg.append("type=");
4059 msg.append(type);
4060
4061 msg.append(StringPool.CLOSE_CURLY_BRACE);
4062
4063 throw new NoSuchRoleException(msg.toString());
4064 }
4065
4066
4073 @Override
4074 public Role fetchByType_Last(int type,
4075 OrderByComparator<Role> orderByComparator) {
4076 int count = countByType(type);
4077
4078 if (count == 0) {
4079 return null;
4080 }
4081
4082 List<Role> list = findByType(type, count - 1, count, orderByComparator);
4083
4084 if (!list.isEmpty()) {
4085 return list.get(0);
4086 }
4087
4088 return null;
4089 }
4090
4091
4100 @Override
4101 public Role[] findByType_PrevAndNext(long roleId, int type,
4102 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4103 Role role = findByPrimaryKey(roleId);
4104
4105 Session session = null;
4106
4107 try {
4108 session = openSession();
4109
4110 Role[] array = new RoleImpl[3];
4111
4112 array[0] = getByType_PrevAndNext(session, role, type,
4113 orderByComparator, true);
4114
4115 array[1] = role;
4116
4117 array[2] = getByType_PrevAndNext(session, role, type,
4118 orderByComparator, false);
4119
4120 return array;
4121 }
4122 catch (Exception e) {
4123 throw processException(e);
4124 }
4125 finally {
4126 closeSession(session);
4127 }
4128 }
4129
4130 protected Role getByType_PrevAndNext(Session session, Role role, int type,
4131 OrderByComparator<Role> orderByComparator, boolean previous) {
4132 StringBundler query = null;
4133
4134 if (orderByComparator != null) {
4135 query = new StringBundler(6 +
4136 (orderByComparator.getOrderByFields().length * 6));
4137 }
4138 else {
4139 query = new StringBundler(3);
4140 }
4141
4142 query.append(_SQL_SELECT_ROLE_WHERE);
4143
4144 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4145
4146 if (orderByComparator != null) {
4147 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4148
4149 if (orderByConditionFields.length > 0) {
4150 query.append(WHERE_AND);
4151 }
4152
4153 for (int i = 0; i < orderByConditionFields.length; i++) {
4154 query.append(_ORDER_BY_ENTITY_ALIAS);
4155 query.append(orderByConditionFields[i]);
4156
4157 if ((i + 1) < orderByConditionFields.length) {
4158 if (orderByComparator.isAscending() ^ previous) {
4159 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4160 }
4161 else {
4162 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4163 }
4164 }
4165 else {
4166 if (orderByComparator.isAscending() ^ previous) {
4167 query.append(WHERE_GREATER_THAN);
4168 }
4169 else {
4170 query.append(WHERE_LESSER_THAN);
4171 }
4172 }
4173 }
4174
4175 query.append(ORDER_BY_CLAUSE);
4176
4177 String[] orderByFields = orderByComparator.getOrderByFields();
4178
4179 for (int i = 0; i < orderByFields.length; i++) {
4180 query.append(_ORDER_BY_ENTITY_ALIAS);
4181 query.append(orderByFields[i]);
4182
4183 if ((i + 1) < orderByFields.length) {
4184 if (orderByComparator.isAscending() ^ previous) {
4185 query.append(ORDER_BY_ASC_HAS_NEXT);
4186 }
4187 else {
4188 query.append(ORDER_BY_DESC_HAS_NEXT);
4189 }
4190 }
4191 else {
4192 if (orderByComparator.isAscending() ^ previous) {
4193 query.append(ORDER_BY_ASC);
4194 }
4195 else {
4196 query.append(ORDER_BY_DESC);
4197 }
4198 }
4199 }
4200 }
4201 else {
4202 query.append(RoleModelImpl.ORDER_BY_JPQL);
4203 }
4204
4205 String sql = query.toString();
4206
4207 Query q = session.createQuery(sql);
4208
4209 q.setFirstResult(0);
4210 q.setMaxResults(2);
4211
4212 QueryPos qPos = QueryPos.getInstance(q);
4213
4214 qPos.add(type);
4215
4216 if (orderByComparator != null) {
4217 Object[] values = orderByComparator.getOrderByConditionValues(role);
4218
4219 for (Object value : values) {
4220 qPos.add(value);
4221 }
4222 }
4223
4224 List<Role> list = q.list();
4225
4226 if (list.size() == 2) {
4227 return list.get(1);
4228 }
4229 else {
4230 return null;
4231 }
4232 }
4233
4234
4240 @Override
4241 public List<Role> filterFindByType(int type) {
4242 return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4243 }
4244
4245
4257 @Override
4258 public List<Role> filterFindByType(int type, int start, int end) {
4259 return filterFindByType(type, start, end, null);
4260 }
4261
4262
4275 @Override
4276 public List<Role> filterFindByType(int type, int start, int end,
4277 OrderByComparator<Role> orderByComparator) {
4278 if (!InlineSQLHelperUtil.isEnabled()) {
4279 return findByType(type, start, end, orderByComparator);
4280 }
4281
4282 StringBundler query = null;
4283
4284 if (orderByComparator != null) {
4285 query = new StringBundler(3 +
4286 (orderByComparator.getOrderByFields().length * 3));
4287 }
4288 else {
4289 query = new StringBundler(3);
4290 }
4291
4292 if (getDB().isSupportsInlineDistinct()) {
4293 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4294 }
4295 else {
4296 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4297 }
4298
4299 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4300
4301 if (!getDB().isSupportsInlineDistinct()) {
4302 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4303 }
4304
4305 if (orderByComparator != null) {
4306 if (getDB().isSupportsInlineDistinct()) {
4307 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4308 orderByComparator, true);
4309 }
4310 else {
4311 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4312 orderByComparator, true);
4313 }
4314 }
4315 else {
4316 if (getDB().isSupportsInlineDistinct()) {
4317 query.append(RoleModelImpl.ORDER_BY_JPQL);
4318 }
4319 else {
4320 query.append(RoleModelImpl.ORDER_BY_SQL);
4321 }
4322 }
4323
4324 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4325 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4326
4327 Session session = null;
4328
4329 try {
4330 session = openSession();
4331
4332 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4333
4334 if (getDB().isSupportsInlineDistinct()) {
4335 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4336 }
4337 else {
4338 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4339 }
4340
4341 QueryPos qPos = QueryPos.getInstance(q);
4342
4343 qPos.add(type);
4344
4345 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
4346 }
4347 catch (Exception e) {
4348 throw processException(e);
4349 }
4350 finally {
4351 closeSession(session);
4352 }
4353 }
4354
4355
4364 @Override
4365 public Role[] filterFindByType_PrevAndNext(long roleId, int type,
4366 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4367 if (!InlineSQLHelperUtil.isEnabled()) {
4368 return findByType_PrevAndNext(roleId, type, orderByComparator);
4369 }
4370
4371 Role role = findByPrimaryKey(roleId);
4372
4373 Session session = null;
4374
4375 try {
4376 session = openSession();
4377
4378 Role[] array = new RoleImpl[3];
4379
4380 array[0] = filterGetByType_PrevAndNext(session, role, type,
4381 orderByComparator, true);
4382
4383 array[1] = role;
4384
4385 array[2] = filterGetByType_PrevAndNext(session, role, type,
4386 orderByComparator, false);
4387
4388 return array;
4389 }
4390 catch (Exception e) {
4391 throw processException(e);
4392 }
4393 finally {
4394 closeSession(session);
4395 }
4396 }
4397
4398 protected Role filterGetByType_PrevAndNext(Session session, Role role,
4399 int type, OrderByComparator<Role> orderByComparator, boolean previous) {
4400 StringBundler query = null;
4401
4402 if (orderByComparator != null) {
4403 query = new StringBundler(6 +
4404 (orderByComparator.getOrderByFields().length * 6));
4405 }
4406 else {
4407 query = new StringBundler(3);
4408 }
4409
4410 if (getDB().isSupportsInlineDistinct()) {
4411 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4412 }
4413 else {
4414 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4415 }
4416
4417 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4418
4419 if (!getDB().isSupportsInlineDistinct()) {
4420 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4421 }
4422
4423 if (orderByComparator != null) {
4424 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4425
4426 if (orderByConditionFields.length > 0) {
4427 query.append(WHERE_AND);
4428 }
4429
4430 for (int i = 0; i < orderByConditionFields.length; i++) {
4431 if (getDB().isSupportsInlineDistinct()) {
4432 query.append(_ORDER_BY_ENTITY_ALIAS);
4433 }
4434 else {
4435 query.append(_ORDER_BY_ENTITY_TABLE);
4436 }
4437
4438 query.append(orderByConditionFields[i]);
4439
4440 if ((i + 1) < orderByConditionFields.length) {
4441 if (orderByComparator.isAscending() ^ previous) {
4442 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4443 }
4444 else {
4445 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4446 }
4447 }
4448 else {
4449 if (orderByComparator.isAscending() ^ previous) {
4450 query.append(WHERE_GREATER_THAN);
4451 }
4452 else {
4453 query.append(WHERE_LESSER_THAN);
4454 }
4455 }
4456 }
4457
4458 query.append(ORDER_BY_CLAUSE);
4459
4460 String[] orderByFields = orderByComparator.getOrderByFields();
4461
4462 for (int i = 0; i < orderByFields.length; i++) {
4463 if (getDB().isSupportsInlineDistinct()) {
4464 query.append(_ORDER_BY_ENTITY_ALIAS);
4465 }
4466 else {
4467 query.append(_ORDER_BY_ENTITY_TABLE);
4468 }
4469
4470 query.append(orderByFields[i]);
4471
4472 if ((i + 1) < orderByFields.length) {
4473 if (orderByComparator.isAscending() ^ previous) {
4474 query.append(ORDER_BY_ASC_HAS_NEXT);
4475 }
4476 else {
4477 query.append(ORDER_BY_DESC_HAS_NEXT);
4478 }
4479 }
4480 else {
4481 if (orderByComparator.isAscending() ^ previous) {
4482 query.append(ORDER_BY_ASC);
4483 }
4484 else {
4485 query.append(ORDER_BY_DESC);
4486 }
4487 }
4488 }
4489 }
4490 else {
4491 if (getDB().isSupportsInlineDistinct()) {
4492 query.append(RoleModelImpl.ORDER_BY_JPQL);
4493 }
4494 else {
4495 query.append(RoleModelImpl.ORDER_BY_SQL);
4496 }
4497 }
4498
4499 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4500 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4501
4502 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4503
4504 q.setFirstResult(0);
4505 q.setMaxResults(2);
4506
4507 if (getDB().isSupportsInlineDistinct()) {
4508 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4509 }
4510 else {
4511 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4512 }
4513
4514 QueryPos qPos = QueryPos.getInstance(q);
4515
4516 qPos.add(type);
4517
4518 if (orderByComparator != null) {
4519 Object[] values = orderByComparator.getOrderByConditionValues(role);
4520
4521 for (Object value : values) {
4522 qPos.add(value);
4523 }
4524 }
4525
4526 List<Role> list = q.list();
4527
4528 if (list.size() == 2) {
4529 return list.get(1);
4530 }
4531 else {
4532 return null;
4533 }
4534 }
4535
4536
4541 @Override
4542 public void removeByType(int type) {
4543 for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4544 null)) {
4545 remove(role);
4546 }
4547 }
4548
4549
4555 @Override
4556 public int countByType(int type) {
4557 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
4558
4559 Object[] finderArgs = new Object[] { type };
4560
4561 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4562
4563 if (count == null) {
4564 StringBundler query = new StringBundler(2);
4565
4566 query.append(_SQL_COUNT_ROLE_WHERE);
4567
4568 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4569
4570 String sql = query.toString();
4571
4572 Session session = null;
4573
4574 try {
4575 session = openSession();
4576
4577 Query q = session.createQuery(sql);
4578
4579 QueryPos qPos = QueryPos.getInstance(q);
4580
4581 qPos.add(type);
4582
4583 count = (Long)q.uniqueResult();
4584
4585 finderCache.putResult(finderPath, finderArgs, count);
4586 }
4587 catch (Exception e) {
4588 finderCache.removeResult(finderPath, finderArgs);
4589
4590 throw processException(e);
4591 }
4592 finally {
4593 closeSession(session);
4594 }
4595 }
4596
4597 return count.intValue();
4598 }
4599
4600
4606 @Override
4607 public int filterCountByType(int type) {
4608 if (!InlineSQLHelperUtil.isEnabled()) {
4609 return countByType(type);
4610 }
4611
4612 StringBundler query = new StringBundler(2);
4613
4614 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4615
4616 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4617
4618 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4619 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4620
4621 Session session = null;
4622
4623 try {
4624 session = openSession();
4625
4626 SQLQuery q = session.createSynchronizedSQLQuery(sql);
4627
4628 q.addScalar(COUNT_COLUMN_NAME,
4629 com.liferay.portal.kernel.dao.orm.Type.LONG);
4630
4631 QueryPos qPos = QueryPos.getInstance(q);
4632
4633 qPos.add(type);
4634
4635 Long count = (Long)q.uniqueResult();
4636
4637 return count.intValue();
4638 }
4639 catch (Exception e) {
4640 throw processException(e);
4641 }
4642 finally {
4643 closeSession(session);
4644 }
4645 }
4646
4647 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?";
4648 private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?";
4649 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4650 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4651 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
4652 new String[] {
4653 String.class.getName(),
4654
4655 Integer.class.getName(), Integer.class.getName(),
4656 OrderByComparator.class.getName()
4657 });
4658 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
4659 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4660 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4661 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
4662 new String[] { String.class.getName() },
4663 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
4664 RoleModelImpl.NAME_COLUMN_BITMASK);
4665 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4666 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4667 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
4668 new String[] { String.class.getName() });
4669
4670
4676 @Override
4677 public List<Role> findBySubtype(String subtype) {
4678 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4679 }
4680
4681
4693 @Override
4694 public List<Role> findBySubtype(String subtype, int start, int end) {
4695 return findBySubtype(subtype, start, end, null);
4696 }
4697
4698
4711 @Override
4712 public List<Role> findBySubtype(String subtype, int start, int end,
4713 OrderByComparator<Role> orderByComparator) {
4714 return findBySubtype(subtype, start, end, orderByComparator, true);
4715 }
4716
4717
4731 @Override
4732 public List<Role> findBySubtype(String subtype, int start, int end,
4733 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
4734 boolean pagination = true;
4735 FinderPath finderPath = null;
4736 Object[] finderArgs = null;
4737
4738 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4739 (orderByComparator == null)) {
4740 pagination = false;
4741 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
4742 finderArgs = new Object[] { subtype };
4743 }
4744 else {
4745 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
4746 finderArgs = new Object[] { subtype, start, end, orderByComparator };
4747 }
4748
4749 List<Role> list = null;
4750
4751 if (retrieveFromCache) {
4752 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
4753 this);
4754
4755 if ((list != null) && !list.isEmpty()) {
4756 for (Role role : list) {
4757 if (!Validator.equals(subtype, role.getSubtype())) {
4758 list = null;
4759
4760 break;
4761 }
4762 }
4763 }
4764 }
4765
4766 if (list == null) {
4767 StringBundler query = null;
4768
4769 if (orderByComparator != null) {
4770 query = new StringBundler(3 +
4771 (orderByComparator.getOrderByFields().length * 3));
4772 }
4773 else {
4774 query = new StringBundler(3);
4775 }
4776
4777 query.append(_SQL_SELECT_ROLE_WHERE);
4778
4779 boolean bindSubtype = false;
4780
4781 if (subtype == null) {
4782 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4783 }
4784 else if (subtype.equals(StringPool.BLANK)) {
4785 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4786 }
4787 else {
4788 bindSubtype = true;
4789
4790 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4791 }
4792
4793 if (orderByComparator != null) {
4794 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4795 orderByComparator);
4796 }
4797 else
4798 if (pagination) {
4799 query.append(RoleModelImpl.ORDER_BY_JPQL);
4800 }
4801
4802 String sql = query.toString();
4803
4804 Session session = null;
4805
4806 try {
4807 session = openSession();
4808
4809 Query q = session.createQuery(sql);
4810
4811 QueryPos qPos = QueryPos.getInstance(q);
4812
4813 if (bindSubtype) {
4814 qPos.add(subtype);
4815 }
4816
4817 if (!pagination) {
4818 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4819 end, false);
4820
4821 Collections.sort(list);
4822
4823 list = Collections.unmodifiableList(list);
4824 }
4825 else {
4826 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4827 end);
4828 }
4829
4830 cacheResult(list);
4831
4832 finderCache.putResult(finderPath, finderArgs, list);
4833 }
4834 catch (Exception e) {
4835 finderCache.removeResult(finderPath, finderArgs);
4836
4837 throw processException(e);
4838 }
4839 finally {
4840 closeSession(session);
4841 }
4842 }
4843
4844 return list;
4845 }
4846
4847
4855 @Override
4856 public Role findBySubtype_First(String subtype,
4857 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4858 Role role = fetchBySubtype_First(subtype, orderByComparator);
4859
4860 if (role != null) {
4861 return role;
4862 }
4863
4864 StringBundler msg = new StringBundler(4);
4865
4866 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4867
4868 msg.append("subtype=");
4869 msg.append(subtype);
4870
4871 msg.append(StringPool.CLOSE_CURLY_BRACE);
4872
4873 throw new NoSuchRoleException(msg.toString());
4874 }
4875
4876
4883 @Override
4884 public Role fetchBySubtype_First(String subtype,
4885 OrderByComparator<Role> orderByComparator) {
4886 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
4887
4888 if (!list.isEmpty()) {
4889 return list.get(0);
4890 }
4891
4892 return null;
4893 }
4894
4895
4903 @Override
4904 public Role findBySubtype_Last(String subtype,
4905 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4906 Role role = fetchBySubtype_Last(subtype, orderByComparator);
4907
4908 if (role != null) {
4909 return role;
4910 }
4911
4912 StringBundler msg = new StringBundler(4);
4913
4914 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4915
4916 msg.append("subtype=");
4917 msg.append(subtype);
4918
4919 msg.append(StringPool.CLOSE_CURLY_BRACE);
4920
4921 throw new NoSuchRoleException(msg.toString());
4922 }
4923
4924
4931 @Override
4932 public Role fetchBySubtype_Last(String subtype,
4933 OrderByComparator<Role> orderByComparator) {
4934 int count = countBySubtype(subtype);
4935
4936 if (count == 0) {
4937 return null;
4938 }
4939
4940 List<Role> list = findBySubtype(subtype, count - 1, count,
4941 orderByComparator);
4942
4943 if (!list.isEmpty()) {
4944 return list.get(0);
4945 }
4946
4947 return null;
4948 }
4949
4950
4959 @Override
4960 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
4961 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
4962 Role role = findByPrimaryKey(roleId);
4963
4964 Session session = null;
4965
4966 try {
4967 session = openSession();
4968
4969 Role[] array = new RoleImpl[3];
4970
4971 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
4972 orderByComparator, true);
4973
4974 array[1] = role;
4975
4976 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
4977 orderByComparator, false);
4978
4979 return array;
4980 }
4981 catch (Exception e) {
4982 throw processException(e);
4983 }
4984 finally {
4985 closeSession(session);
4986 }
4987 }
4988
4989 protected Role getBySubtype_PrevAndNext(Session session, Role role,
4990 String subtype, OrderByComparator<Role> orderByComparator,
4991 boolean previous) {
4992 StringBundler query = null;
4993
4994 if (orderByComparator != null) {
4995 query = new StringBundler(6 +
4996 (orderByComparator.getOrderByFields().length * 6));
4997 }
4998 else {
4999 query = new StringBundler(3);
5000 }
5001
5002 query.append(_SQL_SELECT_ROLE_WHERE);
5003
5004 boolean bindSubtype = false;
5005
5006 if (subtype == null) {
5007 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5008 }
5009 else if (subtype.equals(StringPool.BLANK)) {
5010 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5011 }
5012 else {
5013 bindSubtype = true;
5014
5015 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5016 }
5017
5018 if (orderByComparator != null) {
5019 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5020
5021 if (orderByConditionFields.length > 0) {
5022 query.append(WHERE_AND);
5023 }
5024
5025 for (int i = 0; i < orderByConditionFields.length; i++) {
5026 query.append(_ORDER_BY_ENTITY_ALIAS);
5027 query.append(orderByConditionFields[i]);
5028
5029 if ((i + 1) < orderByConditionFields.length) {
5030 if (orderByComparator.isAscending() ^ previous) {
5031 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5032 }
5033 else {
5034 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5035 }
5036 }
5037 else {
5038 if (orderByComparator.isAscending() ^ previous) {
5039 query.append(WHERE_GREATER_THAN);
5040 }
5041 else {
5042 query.append(WHERE_LESSER_THAN);
5043 }
5044 }
5045 }
5046
5047 query.append(ORDER_BY_CLAUSE);
5048
5049 String[] orderByFields = orderByComparator.getOrderByFields();
5050
5051 for (int i = 0; i < orderByFields.length; i++) {
5052 query.append(_ORDER_BY_ENTITY_ALIAS);
5053 query.append(orderByFields[i]);
5054
5055 if ((i + 1) < orderByFields.length) {
5056 if (orderByComparator.isAscending() ^ previous) {
5057 query.append(ORDER_BY_ASC_HAS_NEXT);
5058 }
5059 else {
5060 query.append(ORDER_BY_DESC_HAS_NEXT);
5061 }
5062 }
5063 else {
5064 if (orderByComparator.isAscending() ^ previous) {
5065 query.append(ORDER_BY_ASC);
5066 }
5067 else {
5068 query.append(ORDER_BY_DESC);
5069 }
5070 }
5071 }
5072 }
5073 else {
5074 query.append(RoleModelImpl.ORDER_BY_JPQL);
5075 }
5076
5077 String sql = query.toString();
5078
5079 Query q = session.createQuery(sql);
5080
5081 q.setFirstResult(0);
5082 q.setMaxResults(2);
5083
5084 QueryPos qPos = QueryPos.getInstance(q);
5085
5086 if (bindSubtype) {
5087 qPos.add(subtype);
5088 }
5089
5090 if (orderByComparator != null) {
5091 Object[] values = orderByComparator.getOrderByConditionValues(role);
5092
5093 for (Object value : values) {
5094 qPos.add(value);
5095 }
5096 }
5097
5098 List<Role> list = q.list();
5099
5100 if (list.size() == 2) {
5101 return list.get(1);
5102 }
5103 else {
5104 return null;
5105 }
5106 }
5107
5108
5114 @Override
5115 public List<Role> filterFindBySubtype(String subtype) {
5116 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
5117 QueryUtil.ALL_POS, null);
5118 }
5119
5120
5132 @Override
5133 public List<Role> filterFindBySubtype(String subtype, int start, int end) {
5134 return filterFindBySubtype(subtype, start, end, null);
5135 }
5136
5137
5150 @Override
5151 public List<Role> filterFindBySubtype(String subtype, int start, int end,
5152 OrderByComparator<Role> orderByComparator) {
5153 if (!InlineSQLHelperUtil.isEnabled()) {
5154 return findBySubtype(subtype, start, end, orderByComparator);
5155 }
5156
5157 StringBundler query = null;
5158
5159 if (orderByComparator != null) {
5160 query = new StringBundler(3 +
5161 (orderByComparator.getOrderByFields().length * 3));
5162 }
5163 else {
5164 query = new StringBundler(3);
5165 }
5166
5167 if (getDB().isSupportsInlineDistinct()) {
5168 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5169 }
5170 else {
5171 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5172 }
5173
5174 boolean bindSubtype = false;
5175
5176 if (subtype == null) {
5177 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5178 }
5179 else if (subtype.equals(StringPool.BLANK)) {
5180 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5181 }
5182 else {
5183 bindSubtype = true;
5184
5185 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5186 }
5187
5188 if (!getDB().isSupportsInlineDistinct()) {
5189 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5190 }
5191
5192 if (orderByComparator != null) {
5193 if (getDB().isSupportsInlineDistinct()) {
5194 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5195 orderByComparator, true);
5196 }
5197 else {
5198 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5199 orderByComparator, true);
5200 }
5201 }
5202 else {
5203 if (getDB().isSupportsInlineDistinct()) {
5204 query.append(RoleModelImpl.ORDER_BY_JPQL);
5205 }
5206 else {
5207 query.append(RoleModelImpl.ORDER_BY_SQL);
5208 }
5209 }
5210
5211 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5212 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5213
5214 Session session = null;
5215
5216 try {
5217 session = openSession();
5218
5219 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5220
5221 if (getDB().isSupportsInlineDistinct()) {
5222 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5223 }
5224 else {
5225 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5226 }
5227
5228 QueryPos qPos = QueryPos.getInstance(q);
5229
5230 if (bindSubtype) {
5231 qPos.add(subtype);
5232 }
5233
5234 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
5235 }
5236 catch (Exception e) {
5237 throw processException(e);
5238 }
5239 finally {
5240 closeSession(session);
5241 }
5242 }
5243
5244
5253 @Override
5254 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
5255 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
5256 if (!InlineSQLHelperUtil.isEnabled()) {
5257 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
5258 }
5259
5260 Role role = findByPrimaryKey(roleId);
5261
5262 Session session = null;
5263
5264 try {
5265 session = openSession();
5266
5267 Role[] array = new RoleImpl[3];
5268
5269 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5270 orderByComparator, true);
5271
5272 array[1] = role;
5273
5274 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5275 orderByComparator, false);
5276
5277 return array;
5278 }
5279 catch (Exception e) {
5280 throw processException(e);
5281 }
5282 finally {
5283 closeSession(session);
5284 }
5285 }
5286
5287 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
5288 String subtype, OrderByComparator<Role> orderByComparator,
5289 boolean previous) {
5290 StringBundler query = null;
5291
5292 if (orderByComparator != null) {
5293 query = new StringBundler(6 +
5294 (orderByComparator.getOrderByFields().length * 6));
5295 }
5296 else {
5297 query = new StringBundler(3);
5298 }
5299
5300 if (getDB().isSupportsInlineDistinct()) {
5301 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5302 }
5303 else {
5304 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5305 }
5306
5307 boolean bindSubtype = false;
5308
5309 if (subtype == null) {
5310 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5311 }
5312 else if (subtype.equals(StringPool.BLANK)) {
5313 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5314 }
5315 else {
5316 bindSubtype = true;
5317
5318 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5319 }
5320
5321 if (!getDB().isSupportsInlineDistinct()) {
5322 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5323 }
5324
5325 if (orderByComparator != null) {
5326 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5327
5328 if (orderByConditionFields.length > 0) {
5329 query.append(WHERE_AND);
5330 }
5331
5332 for (int i = 0; i < orderByConditionFields.length; i++) {
5333 if (getDB().isSupportsInlineDistinct()) {
5334 query.append(_ORDER_BY_ENTITY_ALIAS);
5335 }
5336 else {
5337 query.append(_ORDER_BY_ENTITY_TABLE);
5338 }
5339
5340 query.append(orderByConditionFields[i]);
5341
5342 if ((i + 1) < orderByConditionFields.length) {
5343 if (orderByComparator.isAscending() ^ previous) {
5344 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5345 }
5346 else {
5347 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5348 }
5349 }
5350 else {
5351 if (orderByComparator.isAscending() ^ previous) {
5352 query.append(WHERE_GREATER_THAN);
5353 }
5354 else {
5355 query.append(WHERE_LESSER_THAN);
5356 }
5357 }
5358 }
5359
5360 query.append(ORDER_BY_CLAUSE);
5361
5362 String[] orderByFields = orderByComparator.getOrderByFields();
5363
5364 for (int i = 0; i < orderByFields.length; i++) {
5365 if (getDB().isSupportsInlineDistinct()) {
5366 query.append(_ORDER_BY_ENTITY_ALIAS);
5367 }
5368 else {
5369 query.append(_ORDER_BY_ENTITY_TABLE);
5370 }
5371
5372 query.append(orderByFields[i]);
5373
5374 if ((i + 1) < orderByFields.length) {
5375 if (orderByComparator.isAscending() ^ previous) {
5376 query.append(ORDER_BY_ASC_HAS_NEXT);
5377 }
5378 else {
5379 query.append(ORDER_BY_DESC_HAS_NEXT);
5380 }
5381 }
5382 else {
5383 if (orderByComparator.isAscending() ^ previous) {
5384 query.append(ORDER_BY_ASC);
5385 }
5386 else {
5387 query.append(ORDER_BY_DESC);
5388 }
5389 }
5390 }
5391 }
5392 else {
5393 if (getDB().isSupportsInlineDistinct()) {
5394 query.append(RoleModelImpl.ORDER_BY_JPQL);
5395 }
5396 else {
5397 query.append(RoleModelImpl.ORDER_BY_SQL);
5398 }
5399 }
5400
5401 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5402 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5403
5404 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5405
5406 q.setFirstResult(0);
5407 q.setMaxResults(2);
5408
5409 if (getDB().isSupportsInlineDistinct()) {
5410 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5411 }
5412 else {
5413 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5414 }
5415
5416 QueryPos qPos = QueryPos.getInstance(q);
5417
5418 if (bindSubtype) {
5419 qPos.add(subtype);
5420 }
5421
5422 if (orderByComparator != null) {
5423 Object[] values = orderByComparator.getOrderByConditionValues(role);
5424
5425 for (Object value : values) {
5426 qPos.add(value);
5427 }
5428 }
5429
5430 List<Role> list = q.list();
5431
5432 if (list.size() == 2) {
5433 return list.get(1);
5434 }
5435 else {
5436 return null;
5437 }
5438 }
5439
5440
5445 @Override
5446 public void removeBySubtype(String subtype) {
5447 for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
5448 QueryUtil.ALL_POS, null)) {
5449 remove(role);
5450 }
5451 }
5452
5453
5459 @Override
5460 public int countBySubtype(String subtype) {
5461 FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
5462
5463 Object[] finderArgs = new Object[] { subtype };
5464
5465 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5466
5467 if (count == null) {
5468 StringBundler query = new StringBundler(2);
5469
5470 query.append(_SQL_COUNT_ROLE_WHERE);
5471
5472 boolean bindSubtype = false;
5473
5474 if (subtype == null) {
5475 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5476 }
5477 else if (subtype.equals(StringPool.BLANK)) {
5478 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5479 }
5480 else {
5481 bindSubtype = true;
5482
5483 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5484 }
5485
5486 String sql = query.toString();
5487
5488 Session session = null;
5489
5490 try {
5491 session = openSession();
5492
5493 Query q = session.createQuery(sql);
5494
5495 QueryPos qPos = QueryPos.getInstance(q);
5496
5497 if (bindSubtype) {
5498 qPos.add(subtype);
5499 }
5500
5501 count = (Long)q.uniqueResult();
5502
5503 finderCache.putResult(finderPath, finderArgs, count);
5504 }
5505 catch (Exception e) {
5506 finderCache.removeResult(finderPath, finderArgs);
5507
5508 throw processException(e);
5509 }
5510 finally {
5511 closeSession(session);
5512 }
5513 }
5514
5515 return count.intValue();
5516 }
5517
5518
5524 @Override
5525 public int filterCountBySubtype(String subtype) {
5526 if (!InlineSQLHelperUtil.isEnabled()) {
5527 return countBySubtype(subtype);
5528 }
5529
5530 StringBundler query = new StringBundler(2);
5531
5532 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
5533
5534 boolean bindSubtype = false;
5535
5536 if (subtype == null) {
5537 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5538 }
5539 else if (subtype.equals(StringPool.BLANK)) {
5540 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5541 }
5542 else {
5543 bindSubtype = true;
5544
5545 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5546 }
5547
5548 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5549 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5550
5551 Session session = null;
5552
5553 try {
5554 session = openSession();
5555
5556 SQLQuery q = session.createSynchronizedSQLQuery(sql);
5557
5558 q.addScalar(COUNT_COLUMN_NAME,
5559 com.liferay.portal.kernel.dao.orm.Type.LONG);
5560
5561 QueryPos qPos = QueryPos.getInstance(q);
5562
5563 if (bindSubtype) {
5564 qPos.add(subtype);
5565 }
5566
5567 Long count = (Long)q.uniqueResult();
5568
5569 return count.intValue();
5570 }
5571 catch (Exception e) {
5572 throw processException(e);
5573 }
5574 finally {
5575 closeSession(session);
5576 }
5577 }
5578
5579 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5580 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5581 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
5582 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5583 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5584 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5585 new String[] { Long.class.getName(), String.class.getName() },
5586 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5587 RoleModelImpl.NAME_COLUMN_BITMASK);
5588 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5589 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5590 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5591 new String[] { Long.class.getName(), String.class.getName() });
5592
5593
5601 @Override
5602 public Role findByC_N(long companyId, String name)
5603 throws NoSuchRoleException {
5604 Role role = fetchByC_N(companyId, name);
5605
5606 if (role == null) {
5607 StringBundler msg = new StringBundler(6);
5608
5609 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5610
5611 msg.append("companyId=");
5612 msg.append(companyId);
5613
5614 msg.append(", name=");
5615 msg.append(name);
5616
5617 msg.append(StringPool.CLOSE_CURLY_BRACE);
5618
5619 if (_log.isWarnEnabled()) {
5620 _log.warn(msg.toString());
5621 }
5622
5623 throw new NoSuchRoleException(msg.toString());
5624 }
5625
5626 return role;
5627 }
5628
5629
5636 @Override
5637 public Role fetchByC_N(long companyId, String name) {
5638 return fetchByC_N(companyId, name, true);
5639 }
5640
5641
5649 @Override
5650 public Role fetchByC_N(long companyId, String name,
5651 boolean retrieveFromCache) {
5652 Object[] finderArgs = new Object[] { companyId, name };
5653
5654 Object result = null;
5655
5656 if (retrieveFromCache) {
5657 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_N,
5658 finderArgs, this);
5659 }
5660
5661 if (result instanceof Role) {
5662 Role role = (Role)result;
5663
5664 if ((companyId != role.getCompanyId()) ||
5665 !Validator.equals(name, role.getName())) {
5666 result = null;
5667 }
5668 }
5669
5670 if (result == null) {
5671 StringBundler query = new StringBundler(4);
5672
5673 query.append(_SQL_SELECT_ROLE_WHERE);
5674
5675 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5676
5677 boolean bindName = false;
5678
5679 if (name == null) {
5680 query.append(_FINDER_COLUMN_C_N_NAME_1);
5681 }
5682 else if (name.equals(StringPool.BLANK)) {
5683 query.append(_FINDER_COLUMN_C_N_NAME_3);
5684 }
5685 else {
5686 bindName = true;
5687
5688 query.append(_FINDER_COLUMN_C_N_NAME_2);
5689 }
5690
5691 String sql = query.toString();
5692
5693 Session session = null;
5694
5695 try {
5696 session = openSession();
5697
5698 Query q = session.createQuery(sql);
5699
5700 QueryPos qPos = QueryPos.getInstance(q);
5701
5702 qPos.add(companyId);
5703
5704 if (bindName) {
5705 qPos.add(StringUtil.toLowerCase(name));
5706 }
5707
5708 List<Role> list = q.list();
5709
5710 if (list.isEmpty()) {
5711 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, finderArgs,
5712 list);
5713 }
5714 else {
5715 Role role = list.get(0);
5716
5717 result = role;
5718
5719 cacheResult(role);
5720
5721 if ((role.getCompanyId() != companyId) ||
5722 (role.getName() == null) ||
5723 !role.getName().equals(name)) {
5724 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
5725 finderArgs, role);
5726 }
5727 }
5728 }
5729 catch (Exception e) {
5730 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, finderArgs);
5731
5732 throw processException(e);
5733 }
5734 finally {
5735 closeSession(session);
5736 }
5737 }
5738
5739 if (result instanceof List<?>) {
5740 return null;
5741 }
5742 else {
5743 return (Role)result;
5744 }
5745 }
5746
5747
5754 @Override
5755 public Role removeByC_N(long companyId, String name)
5756 throws NoSuchRoleException {
5757 Role role = findByC_N(companyId, name);
5758
5759 return remove(role);
5760 }
5761
5762
5769 @Override
5770 public int countByC_N(long companyId, String name) {
5771 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5772
5773 Object[] finderArgs = new Object[] { companyId, name };
5774
5775 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5776
5777 if (count == null) {
5778 StringBundler query = new StringBundler(3);
5779
5780 query.append(_SQL_COUNT_ROLE_WHERE);
5781
5782 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5783
5784 boolean bindName = false;
5785
5786 if (name == null) {
5787 query.append(_FINDER_COLUMN_C_N_NAME_1);
5788 }
5789 else if (name.equals(StringPool.BLANK)) {
5790 query.append(_FINDER_COLUMN_C_N_NAME_3);
5791 }
5792 else {
5793 bindName = true;
5794
5795 query.append(_FINDER_COLUMN_C_N_NAME_2);
5796 }
5797
5798 String sql = query.toString();
5799
5800 Session session = null;
5801
5802 try {
5803 session = openSession();
5804
5805 Query q = session.createQuery(sql);
5806
5807 QueryPos qPos = QueryPos.getInstance(q);
5808
5809 qPos.add(companyId);
5810
5811 if (bindName) {
5812 qPos.add(StringUtil.toLowerCase(name));
5813 }
5814
5815 count = (Long)q.uniqueResult();
5816
5817 finderCache.putResult(finderPath, finderArgs, count);
5818 }
5819 catch (Exception e) {
5820 finderCache.removeResult(finderPath, finderArgs);
5821
5822 throw processException(e);
5823 }
5824 finally {
5825 closeSession(session);
5826 }
5827 }
5828
5829 return count.intValue();
5830 }
5831
5832 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5833 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5834 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?";
5835 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')";
5836 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5837 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5838 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_T",
5839 new String[] {
5840 Long.class.getName(), Integer.class.getName(),
5841
5842 Integer.class.getName(), Integer.class.getName(),
5843 OrderByComparator.class.getName()
5844 });
5845 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5846 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5847 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_T",
5848 new String[] { Long.class.getName(), Integer.class.getName() },
5849 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5850 RoleModelImpl.TYPE_COLUMN_BITMASK |
5851 RoleModelImpl.NAME_COLUMN_BITMASK);
5852 public static final FinderPath FINDER_PATH_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5853 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5854 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_T",
5855 new String[] { Long.class.getName(), Integer.class.getName() });
5856 public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5857 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5858 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByC_T",
5859 new String[] { Long.class.getName(), Integer.class.getName() });
5860
5861
5868 @Override
5869 public List<Role> findByC_T(long companyId, int type) {
5870 return findByC_T(companyId, type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5871 null);
5872 }
5873
5874
5887 @Override
5888 public List<Role> findByC_T(long companyId, int type, int start, int end) {
5889 return findByC_T(companyId, type, start, end, null);
5890 }
5891
5892
5906 @Override
5907 public List<Role> findByC_T(long companyId, int type, int start, int end,
5908 OrderByComparator<Role> orderByComparator) {
5909 return findByC_T(companyId, type, start, end, orderByComparator, true);
5910 }
5911
5912
5927 @Override
5928 public List<Role> findByC_T(long companyId, int type, int start, int end,
5929 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
5930 boolean pagination = true;
5931 FinderPath finderPath = null;
5932 Object[] finderArgs = null;
5933
5934 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5935 (orderByComparator == null)) {
5936 pagination = false;
5937 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T;
5938 finderArgs = new Object[] { companyId, type };
5939 }
5940 else {
5941 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T;
5942 finderArgs = new Object[] {
5943 companyId, type,
5944
5945 start, end, orderByComparator
5946 };
5947 }
5948
5949 List<Role> list = null;
5950
5951 if (retrieveFromCache) {
5952 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
5953 this);
5954
5955 if ((list != null) && !list.isEmpty()) {
5956 for (Role role : list) {
5957 if ((companyId != role.getCompanyId()) ||
5958 (type != role.getType())) {
5959 list = null;
5960
5961 break;
5962 }
5963 }
5964 }
5965 }
5966
5967 if (list == null) {
5968 StringBundler query = null;
5969
5970 if (orderByComparator != null) {
5971 query = new StringBundler(4 +
5972 (orderByComparator.getOrderByFields().length * 3));
5973 }
5974 else {
5975 query = new StringBundler(4);
5976 }
5977
5978 query.append(_SQL_SELECT_ROLE_WHERE);
5979
5980 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
5981
5982 query.append(_FINDER_COLUMN_C_T_TYPE_2);
5983
5984 if (orderByComparator != null) {
5985 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5986 orderByComparator);
5987 }
5988 else
5989 if (pagination) {
5990 query.append(RoleModelImpl.ORDER_BY_JPQL);
5991 }
5992
5993 String sql = query.toString();
5994
5995 Session session = null;
5996
5997 try {
5998 session = openSession();
5999
6000 Query q = session.createQuery(sql);
6001
6002 QueryPos qPos = QueryPos.getInstance(q);
6003
6004 qPos.add(companyId);
6005
6006 qPos.add(type);
6007
6008 if (!pagination) {
6009 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6010 end, false);
6011
6012 Collections.sort(list);
6013
6014 list = Collections.unmodifiableList(list);
6015 }
6016 else {
6017 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6018 end);
6019 }
6020
6021 cacheResult(list);
6022
6023 finderCache.putResult(finderPath, finderArgs, list);
6024 }
6025 catch (Exception e) {
6026 finderCache.removeResult(finderPath, finderArgs);
6027
6028 throw processException(e);
6029 }
6030 finally {
6031 closeSession(session);
6032 }
6033 }
6034
6035 return list;
6036 }
6037
6038
6047 @Override
6048 public Role findByC_T_First(long companyId, int type,
6049 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
6050 Role role = fetchByC_T_First(companyId, type, orderByComparator);
6051
6052 if (role != null) {
6053 return role;
6054 }
6055
6056 StringBundler msg = new StringBundler(6);
6057
6058 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6059
6060 msg.append("companyId=");
6061 msg.append(companyId);
6062
6063 msg.append(", type=");
6064 msg.append(type);
6065
6066 msg.append(StringPool.CLOSE_CURLY_BRACE);
6067
6068 throw new NoSuchRoleException(msg.toString());
6069 }
6070
6071
6079 @Override
6080 public Role fetchByC_T_First(long companyId, int type,
6081 OrderByComparator<Role> orderByComparator) {
6082 List<Role> list = findByC_T(companyId, type, 0, 1, orderByComparator);
6083
6084 if (!list.isEmpty()) {
6085 return list.get(0);
6086 }
6087
6088 return null;
6089 }
6090
6091
6100 @Override
6101 public Role findByC_T_Last(long companyId, int type,
6102 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
6103 Role role = fetchByC_T_Last(companyId, type, orderByComparator);
6104
6105 if (role != null) {
6106 return role;
6107 }
6108
6109 StringBundler msg = new StringBundler(6);
6110
6111 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6112
6113 msg.append("companyId=");
6114 msg.append(companyId);
6115
6116 msg.append(", type=");
6117 msg.append(type);
6118
6119 msg.append(StringPool.CLOSE_CURLY_BRACE);
6120
6121 throw new NoSuchRoleException(msg.toString());
6122 }
6123
6124
6132 @Override
6133 public Role fetchByC_T_Last(long companyId, int type,
6134 OrderByComparator<Role> orderByComparator) {
6135 int count = countByC_T(companyId, type);
6136
6137 if (count == 0) {
6138 return null;
6139 }
6140
6141 List<Role> list = findByC_T(companyId, type, count - 1, count,
6142 orderByComparator);
6143
6144 if (!list.isEmpty()) {
6145 return list.get(0);
6146 }
6147
6148 return null;
6149 }
6150
6151
6161 @Override
6162 public Role[] findByC_T_PrevAndNext(long roleId, long companyId, int type,
6163 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
6164 Role role = findByPrimaryKey(roleId);
6165
6166 Session session = null;
6167
6168 try {
6169 session = openSession();
6170
6171 Role[] array = new RoleImpl[3];
6172
6173 array[0] = getByC_T_PrevAndNext(session, role, companyId, type,
6174 orderByComparator, true);
6175
6176 array[1] = role;
6177
6178 array[2] = getByC_T_PrevAndNext(session, role, companyId, type,
6179 orderByComparator, false);
6180
6181 return array;
6182 }
6183 catch (Exception e) {
6184 throw processException(e);
6185 }
6186 finally {
6187 closeSession(session);
6188 }
6189 }
6190
6191 protected Role getByC_T_PrevAndNext(Session session, Role role,
6192 long companyId, int type, OrderByComparator<Role> orderByComparator,
6193 boolean previous) {
6194 StringBundler query = null;
6195
6196 if (orderByComparator != null) {
6197 query = new StringBundler(6 +
6198 (orderByComparator.getOrderByFields().length * 6));
6199 }
6200 else {
6201 query = new StringBundler(3);
6202 }
6203
6204 query.append(_SQL_SELECT_ROLE_WHERE);
6205
6206 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6207
6208 query.append(_FINDER_COLUMN_C_T_TYPE_2);
6209
6210 if (orderByComparator != null) {
6211 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6212
6213 if (orderByConditionFields.length > 0) {
6214 query.append(WHERE_AND);
6215 }
6216
6217 for (int i = 0; i < orderByConditionFields.length; i++) {
6218 query.append(_ORDER_BY_ENTITY_ALIAS);
6219 query.append(orderByConditionFields[i]);
6220
6221 if ((i + 1) < orderByConditionFields.length) {
6222 if (orderByComparator.isAscending() ^ previous) {
6223 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6224 }
6225 else {
6226 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6227 }
6228 }
6229 else {
6230 if (orderByComparator.isAscending() ^ previous) {
6231 query.append(WHERE_GREATER_THAN);
6232 }
6233 else {
6234 query.append(WHERE_LESSER_THAN);
6235 }
6236 }
6237 }
6238
6239 query.append(ORDER_BY_CLAUSE);
6240
6241 String[] orderByFields = orderByComparator.getOrderByFields();
6242
6243 for (int i = 0; i < orderByFields.length; i++) {
6244 query.append(_ORDER_BY_ENTITY_ALIAS);
6245 query.append(orderByFields[i]);
6246
6247 if ((i + 1) < orderByFields.length) {
6248 if (orderByComparator.isAscending() ^ previous) {
6249 query.append(ORDER_BY_ASC_HAS_NEXT);
6250 }
6251 else {
6252 query.append(ORDER_BY_DESC_HAS_NEXT);
6253 }
6254 }
6255 else {
6256 if (orderByComparator.isAscending() ^ previous) {
6257 query.append(ORDER_BY_ASC);
6258 }
6259 else {
6260 query.append(ORDER_BY_DESC);
6261 }
6262 }
6263 }
6264 }
6265 else {
6266 query.append(RoleModelImpl.ORDER_BY_JPQL);
6267 }
6268
6269 String sql = query.toString();
6270
6271 Query q = session.createQuery(sql);
6272
6273 q.setFirstResult(0);
6274 q.setMaxResults(2);
6275
6276 QueryPos qPos = QueryPos.getInstance(q);
6277
6278 qPos.add(companyId);
6279
6280 qPos.add(type);
6281
6282 if (orderByComparator != null) {
6283 Object[] values = orderByComparator.getOrderByConditionValues(role);
6284
6285 for (Object value : values) {
6286 qPos.add(value);
6287 }
6288 }
6289
6290 List<Role> list = q.list();
6291
6292 if (list.size() == 2) {
6293 return list.get(1);
6294 }
6295 else {
6296 return null;
6297 }
6298 }
6299
6300
6307 @Override
6308 public List<Role> filterFindByC_T(long companyId, int type) {
6309 return filterFindByC_T(companyId, type, QueryUtil.ALL_POS,
6310 QueryUtil.ALL_POS, null);
6311 }
6312
6313
6326 @Override
6327 public List<Role> filterFindByC_T(long companyId, int type, int start,
6328 int end) {
6329 return filterFindByC_T(companyId, type, start, end, null);
6330 }
6331
6332
6346 @Override
6347 public List<Role> filterFindByC_T(long companyId, int type, int start,
6348 int end, OrderByComparator<Role> orderByComparator) {
6349 if (!InlineSQLHelperUtil.isEnabled()) {
6350 return findByC_T(companyId, type, start, end, orderByComparator);
6351 }
6352
6353 StringBundler query = null;
6354
6355 if (orderByComparator != null) {
6356 query = new StringBundler(4 +
6357 (orderByComparator.getOrderByFields().length * 3));
6358 }
6359 else {
6360 query = new StringBundler(4);
6361 }
6362
6363 if (getDB().isSupportsInlineDistinct()) {
6364 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6365 }
6366 else {
6367 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6368 }
6369
6370 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6371
6372 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6373
6374 if (!getDB().isSupportsInlineDistinct()) {
6375 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6376 }
6377
6378 if (orderByComparator != null) {
6379 if (getDB().isSupportsInlineDistinct()) {
6380 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6381 orderByComparator, true);
6382 }
6383 else {
6384 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6385 orderByComparator, true);
6386 }
6387 }
6388 else {
6389 if (getDB().isSupportsInlineDistinct()) {
6390 query.append(RoleModelImpl.ORDER_BY_JPQL);
6391 }
6392 else {
6393 query.append(RoleModelImpl.ORDER_BY_SQL);
6394 }
6395 }
6396
6397 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6398 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6399
6400 Session session = null;
6401
6402 try {
6403 session = openSession();
6404
6405 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6406
6407 if (getDB().isSupportsInlineDistinct()) {
6408 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6409 }
6410 else {
6411 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6412 }
6413
6414 QueryPos qPos = QueryPos.getInstance(q);
6415
6416 qPos.add(companyId);
6417
6418 qPos.add(type);
6419
6420 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6421 }
6422 catch (Exception e) {
6423 throw processException(e);
6424 }
6425 finally {
6426 closeSession(session);
6427 }
6428 }
6429
6430
6440 @Override
6441 public Role[] filterFindByC_T_PrevAndNext(long roleId, long companyId,
6442 int type, OrderByComparator<Role> orderByComparator)
6443 throws NoSuchRoleException {
6444 if (!InlineSQLHelperUtil.isEnabled()) {
6445 return findByC_T_PrevAndNext(roleId, companyId, type,
6446 orderByComparator);
6447 }
6448
6449 Role role = findByPrimaryKey(roleId);
6450
6451 Session session = null;
6452
6453 try {
6454 session = openSession();
6455
6456 Role[] array = new RoleImpl[3];
6457
6458 array[0] = filterGetByC_T_PrevAndNext(session, role, companyId,
6459 type, orderByComparator, true);
6460
6461 array[1] = role;
6462
6463 array[2] = filterGetByC_T_PrevAndNext(session, role, companyId,
6464 type, orderByComparator, false);
6465
6466 return array;
6467 }
6468 catch (Exception e) {
6469 throw processException(e);
6470 }
6471 finally {
6472 closeSession(session);
6473 }
6474 }
6475
6476 protected Role filterGetByC_T_PrevAndNext(Session session, Role role,
6477 long companyId, int type, OrderByComparator<Role> orderByComparator,
6478 boolean previous) {
6479 StringBundler query = null;
6480
6481 if (orderByComparator != null) {
6482 query = new StringBundler(6 +
6483 (orderByComparator.getOrderByFields().length * 6));
6484 }
6485 else {
6486 query = new StringBundler(3);
6487 }
6488
6489 if (getDB().isSupportsInlineDistinct()) {
6490 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6491 }
6492 else {
6493 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6494 }
6495
6496 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6497
6498 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
6499
6500 if (!getDB().isSupportsInlineDistinct()) {
6501 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6502 }
6503
6504 if (orderByComparator != null) {
6505 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6506
6507 if (orderByConditionFields.length > 0) {
6508 query.append(WHERE_AND);
6509 }
6510
6511 for (int i = 0; i < orderByConditionFields.length; i++) {
6512 if (getDB().isSupportsInlineDistinct()) {
6513 query.append(_ORDER_BY_ENTITY_ALIAS);
6514 }
6515 else {
6516 query.append(_ORDER_BY_ENTITY_TABLE);
6517 }
6518
6519 query.append(orderByConditionFields[i]);
6520
6521 if ((i + 1) < orderByConditionFields.length) {
6522 if (orderByComparator.isAscending() ^ previous) {
6523 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6524 }
6525 else {
6526 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6527 }
6528 }
6529 else {
6530 if (orderByComparator.isAscending() ^ previous) {
6531 query.append(WHERE_GREATER_THAN);
6532 }
6533 else {
6534 query.append(WHERE_LESSER_THAN);
6535 }
6536 }
6537 }
6538
6539 query.append(ORDER_BY_CLAUSE);
6540
6541 String[] orderByFields = orderByComparator.getOrderByFields();
6542
6543 for (int i = 0; i < orderByFields.length; i++) {
6544 if (getDB().isSupportsInlineDistinct()) {
6545 query.append(_ORDER_BY_ENTITY_ALIAS);
6546 }
6547 else {
6548 query.append(_ORDER_BY_ENTITY_TABLE);
6549 }
6550
6551 query.append(orderByFields[i]);
6552
6553 if ((i + 1) < orderByFields.length) {
6554 if (orderByComparator.isAscending() ^ previous) {
6555 query.append(ORDER_BY_ASC_HAS_NEXT);
6556 }
6557 else {
6558 query.append(ORDER_BY_DESC_HAS_NEXT);
6559 }
6560 }
6561 else {
6562 if (orderByComparator.isAscending() ^ previous) {
6563 query.append(ORDER_BY_ASC);
6564 }
6565 else {
6566 query.append(ORDER_BY_DESC);
6567 }
6568 }
6569 }
6570 }
6571 else {
6572 if (getDB().isSupportsInlineDistinct()) {
6573 query.append(RoleModelImpl.ORDER_BY_JPQL);
6574 }
6575 else {
6576 query.append(RoleModelImpl.ORDER_BY_SQL);
6577 }
6578 }
6579
6580 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6581 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6582
6583 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6584
6585 q.setFirstResult(0);
6586 q.setMaxResults(2);
6587
6588 if (getDB().isSupportsInlineDistinct()) {
6589 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6590 }
6591 else {
6592 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6593 }
6594
6595 QueryPos qPos = QueryPos.getInstance(q);
6596
6597 qPos.add(companyId);
6598
6599 qPos.add(type);
6600
6601 if (orderByComparator != null) {
6602 Object[] values = orderByComparator.getOrderByConditionValues(role);
6603
6604 for (Object value : values) {
6605 qPos.add(value);
6606 }
6607 }
6608
6609 List<Role> list = q.list();
6610
6611 if (list.size() == 2) {
6612 return list.get(1);
6613 }
6614 else {
6615 return null;
6616 }
6617 }
6618
6619
6626 @Override
6627 public List<Role> filterFindByC_T(long companyId, int[] types) {
6628 return filterFindByC_T(companyId, types, QueryUtil.ALL_POS,
6629 QueryUtil.ALL_POS, null);
6630 }
6631
6632
6645 @Override
6646 public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6647 int end) {
6648 return filterFindByC_T(companyId, types, start, end, null);
6649 }
6650
6651
6665 @Override
6666 public List<Role> filterFindByC_T(long companyId, int[] types, int start,
6667 int end, OrderByComparator<Role> orderByComparator) {
6668 if (!InlineSQLHelperUtil.isEnabled()) {
6669 return findByC_T(companyId, types, start, end, orderByComparator);
6670 }
6671
6672 if (types == null) {
6673 types = new int[0];
6674 }
6675 else if (types.length > 1) {
6676 types = ArrayUtil.unique(types);
6677
6678 Arrays.sort(types);
6679 }
6680
6681 StringBundler query = new StringBundler();
6682
6683 if (getDB().isSupportsInlineDistinct()) {
6684 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6685 }
6686 else {
6687 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6688 }
6689
6690 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6691
6692 if (types.length > 0) {
6693 query.append(StringPool.OPEN_PARENTHESIS);
6694
6695 query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL);
6696
6697 query.append(StringUtil.merge(types));
6698
6699 query.append(StringPool.CLOSE_PARENTHESIS);
6700
6701 query.append(StringPool.CLOSE_PARENTHESIS);
6702 }
6703
6704 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6705 query.index() - 1);
6706
6707 if (!getDB().isSupportsInlineDistinct()) {
6708 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6709 }
6710
6711 if (orderByComparator != null) {
6712 if (getDB().isSupportsInlineDistinct()) {
6713 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6714 orderByComparator, true);
6715 }
6716 else {
6717 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6718 orderByComparator, true);
6719 }
6720 }
6721 else {
6722 if (getDB().isSupportsInlineDistinct()) {
6723 query.append(RoleModelImpl.ORDER_BY_JPQL);
6724 }
6725 else {
6726 query.append(RoleModelImpl.ORDER_BY_SQL);
6727 }
6728 }
6729
6730 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6731 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6732
6733 Session session = null;
6734
6735 try {
6736 session = openSession();
6737
6738 SQLQuery q = session.createSynchronizedSQLQuery(sql);
6739
6740 if (getDB().isSupportsInlineDistinct()) {
6741 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6742 }
6743 else {
6744 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6745 }
6746
6747 QueryPos qPos = QueryPos.getInstance(q);
6748
6749 qPos.add(companyId);
6750
6751 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6752 }
6753 catch (Exception e) {
6754 throw processException(e);
6755 }
6756 finally {
6757 closeSession(session);
6758 }
6759 }
6760
6761
6772 @Override
6773 public List<Role> findByC_T(long companyId, int[] types) {
6774 return findByC_T(companyId, types, QueryUtil.ALL_POS,
6775 QueryUtil.ALL_POS, null);
6776 }
6777
6778
6791 @Override
6792 public List<Role> findByC_T(long companyId, int[] types, int start, int end) {
6793 return findByC_T(companyId, types, start, end, null);
6794 }
6795
6796
6810 @Override
6811 public List<Role> findByC_T(long companyId, int[] types, int start,
6812 int end, OrderByComparator<Role> orderByComparator) {
6813 return findByC_T(companyId, types, start, end, orderByComparator, true);
6814 }
6815
6816
6831 @Override
6832 public List<Role> findByC_T(long companyId, int[] types, int start,
6833 int end, OrderByComparator<Role> orderByComparator,
6834 boolean retrieveFromCache) {
6835 if (types == null) {
6836 types = new int[0];
6837 }
6838 else if (types.length > 1) {
6839 types = ArrayUtil.unique(types);
6840
6841 Arrays.sort(types);
6842 }
6843
6844 if (types.length == 1) {
6845 return findByC_T(companyId, types[0], start, end, orderByComparator);
6846 }
6847
6848 boolean pagination = true;
6849 Object[] finderArgs = null;
6850
6851 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6852 (orderByComparator == null)) {
6853 pagination = false;
6854 finderArgs = new Object[] { companyId, StringUtil.merge(types) };
6855 }
6856 else {
6857 finderArgs = new Object[] {
6858 companyId, StringUtil.merge(types),
6859
6860 start, end, orderByComparator
6861 };
6862 }
6863
6864 List<Role> list = null;
6865
6866 if (retrieveFromCache) {
6867 list = (List<Role>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6868 finderArgs, this);
6869
6870 if ((list != null) && !list.isEmpty()) {
6871 for (Role role : list) {
6872 if ((companyId != role.getCompanyId()) ||
6873 !ArrayUtil.contains(types, role.getType())) {
6874 list = null;
6875
6876 break;
6877 }
6878 }
6879 }
6880 }
6881
6882 if (list == null) {
6883 StringBundler query = new StringBundler();
6884
6885 query.append(_SQL_SELECT_ROLE_WHERE);
6886
6887 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6888
6889 if (types.length > 0) {
6890 query.append(StringPool.OPEN_PARENTHESIS);
6891
6892 query.append(_FINDER_COLUMN_C_T_TYPE_7);
6893
6894 query.append(StringUtil.merge(types));
6895
6896 query.append(StringPool.CLOSE_PARENTHESIS);
6897
6898 query.append(StringPool.CLOSE_PARENTHESIS);
6899 }
6900
6901 query.setStringAt(removeConjunction(query.stringAt(query.index() -
6902 1)), query.index() - 1);
6903
6904 if (orderByComparator != null) {
6905 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6906 orderByComparator);
6907 }
6908 else
6909 if (pagination) {
6910 query.append(RoleModelImpl.ORDER_BY_JPQL);
6911 }
6912
6913 String sql = query.toString();
6914
6915 Session session = null;
6916
6917 try {
6918 session = openSession();
6919
6920 Query q = session.createQuery(sql);
6921
6922 QueryPos qPos = QueryPos.getInstance(q);
6923
6924 qPos.add(companyId);
6925
6926 if (!pagination) {
6927 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6928 end, false);
6929
6930 Collections.sort(list);
6931
6932 list = Collections.unmodifiableList(list);
6933 }
6934 else {
6935 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
6936 end);
6937 }
6938
6939 cacheResult(list);
6940
6941 finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6942 finderArgs, list);
6943 }
6944 catch (Exception e) {
6945 finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_C_T,
6946 finderArgs);
6947
6948 throw processException(e);
6949 }
6950 finally {
6951 closeSession(session);
6952 }
6953 }
6954
6955 return list;
6956 }
6957
6958
6964 @Override
6965 public void removeByC_T(long companyId, int type) {
6966 for (Role role : findByC_T(companyId, type, QueryUtil.ALL_POS,
6967 QueryUtil.ALL_POS, null)) {
6968 remove(role);
6969 }
6970 }
6971
6972
6979 @Override
6980 public int countByC_T(long companyId, int type) {
6981 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_T;
6982
6983 Object[] finderArgs = new Object[] { companyId, type };
6984
6985 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6986
6987 if (count == null) {
6988 StringBundler query = new StringBundler(3);
6989
6990 query.append(_SQL_COUNT_ROLE_WHERE);
6991
6992 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
6993
6994 query.append(_FINDER_COLUMN_C_T_TYPE_2);
6995
6996 String sql = query.toString();
6997
6998 Session session = null;
6999
7000 try {
7001 session = openSession();
7002
7003 Query q = session.createQuery(sql);
7004
7005 QueryPos qPos = QueryPos.getInstance(q);
7006
7007 qPos.add(companyId);
7008
7009 qPos.add(type);
7010
7011 count = (Long)q.uniqueResult();
7012
7013 finderCache.putResult(finderPath, finderArgs, count);
7014 }
7015 catch (Exception e) {
7016 finderCache.removeResult(finderPath, finderArgs);
7017
7018 throw processException(e);
7019 }
7020 finally {
7021 closeSession(session);
7022 }
7023 }
7024
7025 return count.intValue();
7026 }
7027
7028
7035 @Override
7036 public int countByC_T(long companyId, int[] types) {
7037 if (types == null) {
7038 types = new int[0];
7039 }
7040 else if (types.length > 1) {
7041 types = ArrayUtil.unique(types);
7042
7043 Arrays.sort(types);
7044 }
7045
7046 Object[] finderArgs = new Object[] { companyId, StringUtil.merge(types) };
7047
7048 Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7049 finderArgs, this);
7050
7051 if (count == null) {
7052 StringBundler query = new StringBundler();
7053
7054 query.append(_SQL_COUNT_ROLE_WHERE);
7055
7056 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7057
7058 if (types.length > 0) {
7059 query.append(StringPool.OPEN_PARENTHESIS);
7060
7061 query.append(_FINDER_COLUMN_C_T_TYPE_7);
7062
7063 query.append(StringUtil.merge(types));
7064
7065 query.append(StringPool.CLOSE_PARENTHESIS);
7066
7067 query.append(StringPool.CLOSE_PARENTHESIS);
7068 }
7069
7070 query.setStringAt(removeConjunction(query.stringAt(query.index() -
7071 1)), query.index() - 1);
7072
7073 String sql = query.toString();
7074
7075 Session session = null;
7076
7077 try {
7078 session = openSession();
7079
7080 Query q = session.createQuery(sql);
7081
7082 QueryPos qPos = QueryPos.getInstance(q);
7083
7084 qPos.add(companyId);
7085
7086 count = (Long)q.uniqueResult();
7087
7088 finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7089 finderArgs, count);
7090 }
7091 catch (Exception e) {
7092 finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_C_T,
7093 finderArgs);
7094
7095 throw processException(e);
7096 }
7097 finally {
7098 closeSession(session);
7099 }
7100 }
7101
7102 return count.intValue();
7103 }
7104
7105
7112 @Override
7113 public int filterCountByC_T(long companyId, int type) {
7114 if (!InlineSQLHelperUtil.isEnabled()) {
7115 return countByC_T(companyId, type);
7116 }
7117
7118 StringBundler query = new StringBundler(3);
7119
7120 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7121
7122 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7123
7124 query.append(_FINDER_COLUMN_C_T_TYPE_2_SQL);
7125
7126 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7127 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7128
7129 Session session = null;
7130
7131 try {
7132 session = openSession();
7133
7134 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7135
7136 q.addScalar(COUNT_COLUMN_NAME,
7137 com.liferay.portal.kernel.dao.orm.Type.LONG);
7138
7139 QueryPos qPos = QueryPos.getInstance(q);
7140
7141 qPos.add(companyId);
7142
7143 qPos.add(type);
7144
7145 Long count = (Long)q.uniqueResult();
7146
7147 return count.intValue();
7148 }
7149 catch (Exception e) {
7150 throw processException(e);
7151 }
7152 finally {
7153 closeSession(session);
7154 }
7155 }
7156
7157
7164 @Override
7165 public int filterCountByC_T(long companyId, int[] types) {
7166 if (!InlineSQLHelperUtil.isEnabled()) {
7167 return countByC_T(companyId, types);
7168 }
7169
7170 if (types == null) {
7171 types = new int[0];
7172 }
7173 else if (types.length > 1) {
7174 types = ArrayUtil.unique(types);
7175
7176 Arrays.sort(types);
7177 }
7178
7179 StringBundler query = new StringBundler();
7180
7181 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
7182
7183 query.append(_FINDER_COLUMN_C_T_COMPANYID_2);
7184
7185 if (types.length > 0) {
7186 query.append(StringPool.OPEN_PARENTHESIS);
7187
7188 query.append(_FINDER_COLUMN_C_T_TYPE_7_SQL);
7189
7190 query.append(StringUtil.merge(types));
7191
7192 query.append(StringPool.CLOSE_PARENTHESIS);
7193
7194 query.append(StringPool.CLOSE_PARENTHESIS);
7195 }
7196
7197 query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
7198 query.index() - 1);
7199
7200 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7201 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7202
7203 Session session = null;
7204
7205 try {
7206 session = openSession();
7207
7208 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7209
7210 q.addScalar(COUNT_COLUMN_NAME,
7211 com.liferay.portal.kernel.dao.orm.Type.LONG);
7212
7213 QueryPos qPos = QueryPos.getInstance(q);
7214
7215 qPos.add(companyId);
7216
7217 Long count = (Long)q.uniqueResult();
7218
7219 return count.intValue();
7220 }
7221 catch (Exception e) {
7222 throw processException(e);
7223 }
7224 finally {
7225 closeSession(session);
7226 }
7227 }
7228
7229 private static final String _FINDER_COLUMN_C_T_COMPANYID_2 = "role.companyId = ? AND ";
7230 private static final String _FINDER_COLUMN_C_T_TYPE_2 = "role.type = ?";
7231 private static final String _FINDER_COLUMN_C_T_TYPE_7 = "role.type IN (";
7232 private static final String _FINDER_COLUMN_C_T_TYPE_2_SQL = "role.type_ = ?";
7233 private static final String _FINDER_COLUMN_C_T_TYPE_7_SQL = "role.type_ IN (";
7234 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7235 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7236 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
7237 new String[] {
7238 Integer.class.getName(), String.class.getName(),
7239
7240 Integer.class.getName(), Integer.class.getName(),
7241 OrderByComparator.class.getName()
7242 });
7243 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7244 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
7245 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
7246 new String[] { Integer.class.getName(), String.class.getName() },
7247 RoleModelImpl.TYPE_COLUMN_BITMASK |
7248 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
7249 RoleModelImpl.NAME_COLUMN_BITMASK);
7250 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
7251 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
7252 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
7253 new String[] { Integer.class.getName(), String.class.getName() });
7254
7255
7262 @Override
7263 public List<Role> findByT_S(int type, String subtype) {
7264 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
7265 null);
7266 }
7267
7268
7281 @Override
7282 public List<Role> findByT_S(int type, String subtype, int start, int end) {
7283 return findByT_S(type, subtype, start, end, null);
7284 }
7285
7286
7300 @Override
7301 public List<Role> findByT_S(int type, String subtype, int start, int end,
7302 OrderByComparator<Role> orderByComparator) {
7303 return findByT_S(type, subtype, start, end, orderByComparator, true);
7304 }
7305
7306
7321 @Override
7322 public List<Role> findByT_S(int type, String subtype, int start, int end,
7323 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
7324 boolean pagination = true;
7325 FinderPath finderPath = null;
7326 Object[] finderArgs = null;
7327
7328 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7329 (orderByComparator == null)) {
7330 pagination = false;
7331 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
7332 finderArgs = new Object[] { type, subtype };
7333 }
7334 else {
7335 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
7336 finderArgs = new Object[] {
7337 type, subtype,
7338
7339 start, end, orderByComparator
7340 };
7341 }
7342
7343 List<Role> list = null;
7344
7345 if (retrieveFromCache) {
7346 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
7347 this);
7348
7349 if ((list != null) && !list.isEmpty()) {
7350 for (Role role : list) {
7351 if ((type != role.getType()) ||
7352 !Validator.equals(subtype, role.getSubtype())) {
7353 list = null;
7354
7355 break;
7356 }
7357 }
7358 }
7359 }
7360
7361 if (list == null) {
7362 StringBundler query = null;
7363
7364 if (orderByComparator != null) {
7365 query = new StringBundler(4 +
7366 (orderByComparator.getOrderByFields().length * 3));
7367 }
7368 else {
7369 query = new StringBundler(4);
7370 }
7371
7372 query.append(_SQL_SELECT_ROLE_WHERE);
7373
7374 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7375
7376 boolean bindSubtype = false;
7377
7378 if (subtype == null) {
7379 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7380 }
7381 else if (subtype.equals(StringPool.BLANK)) {
7382 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7383 }
7384 else {
7385 bindSubtype = true;
7386
7387 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7388 }
7389
7390 if (orderByComparator != null) {
7391 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7392 orderByComparator);
7393 }
7394 else
7395 if (pagination) {
7396 query.append(RoleModelImpl.ORDER_BY_JPQL);
7397 }
7398
7399 String sql = query.toString();
7400
7401 Session session = null;
7402
7403 try {
7404 session = openSession();
7405
7406 Query q = session.createQuery(sql);
7407
7408 QueryPos qPos = QueryPos.getInstance(q);
7409
7410 qPos.add(type);
7411
7412 if (bindSubtype) {
7413 qPos.add(subtype);
7414 }
7415
7416 if (!pagination) {
7417 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7418 end, false);
7419
7420 Collections.sort(list);
7421
7422 list = Collections.unmodifiableList(list);
7423 }
7424 else {
7425 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7426 end);
7427 }
7428
7429 cacheResult(list);
7430
7431 finderCache.putResult(finderPath, finderArgs, list);
7432 }
7433 catch (Exception e) {
7434 finderCache.removeResult(finderPath, finderArgs);
7435
7436 throw processException(e);
7437 }
7438 finally {
7439 closeSession(session);
7440 }
7441 }
7442
7443 return list;
7444 }
7445
7446
7455 @Override
7456 public Role findByT_S_First(int type, String subtype,
7457 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7458 Role role = fetchByT_S_First(type, subtype, orderByComparator);
7459
7460 if (role != null) {
7461 return role;
7462 }
7463
7464 StringBundler msg = new StringBundler(6);
7465
7466 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7467
7468 msg.append("type=");
7469 msg.append(type);
7470
7471 msg.append(", subtype=");
7472 msg.append(subtype);
7473
7474 msg.append(StringPool.CLOSE_CURLY_BRACE);
7475
7476 throw new NoSuchRoleException(msg.toString());
7477 }
7478
7479
7487 @Override
7488 public Role fetchByT_S_First(int type, String subtype,
7489 OrderByComparator<Role> orderByComparator) {
7490 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
7491
7492 if (!list.isEmpty()) {
7493 return list.get(0);
7494 }
7495
7496 return null;
7497 }
7498
7499
7508 @Override
7509 public Role findByT_S_Last(int type, String subtype,
7510 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7511 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
7512
7513 if (role != null) {
7514 return role;
7515 }
7516
7517 StringBundler msg = new StringBundler(6);
7518
7519 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7520
7521 msg.append("type=");
7522 msg.append(type);
7523
7524 msg.append(", subtype=");
7525 msg.append(subtype);
7526
7527 msg.append(StringPool.CLOSE_CURLY_BRACE);
7528
7529 throw new NoSuchRoleException(msg.toString());
7530 }
7531
7532
7540 @Override
7541 public Role fetchByT_S_Last(int type, String subtype,
7542 OrderByComparator<Role> orderByComparator) {
7543 int count = countByT_S(type, subtype);
7544
7545 if (count == 0) {
7546 return null;
7547 }
7548
7549 List<Role> list = findByT_S(type, subtype, count - 1, count,
7550 orderByComparator);
7551
7552 if (!list.isEmpty()) {
7553 return list.get(0);
7554 }
7555
7556 return null;
7557 }
7558
7559
7569 @Override
7570 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
7571 OrderByComparator<Role> orderByComparator) throws NoSuchRoleException {
7572 Role role = findByPrimaryKey(roleId);
7573
7574 Session session = null;
7575
7576 try {
7577 session = openSession();
7578
7579 Role[] array = new RoleImpl[3];
7580
7581 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
7582 orderByComparator, true);
7583
7584 array[1] = role;
7585
7586 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
7587 orderByComparator, false);
7588
7589 return array;
7590 }
7591 catch (Exception e) {
7592 throw processException(e);
7593 }
7594 finally {
7595 closeSession(session);
7596 }
7597 }
7598
7599 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
7600 String subtype, OrderByComparator<Role> orderByComparator,
7601 boolean previous) {
7602 StringBundler query = null;
7603
7604 if (orderByComparator != null) {
7605 query = new StringBundler(6 +
7606 (orderByComparator.getOrderByFields().length * 6));
7607 }
7608 else {
7609 query = new StringBundler(3);
7610 }
7611
7612 query.append(_SQL_SELECT_ROLE_WHERE);
7613
7614 query.append(_FINDER_COLUMN_T_S_TYPE_2);
7615
7616 boolean bindSubtype = false;
7617
7618 if (subtype == null) {
7619 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7620 }
7621 else if (subtype.equals(StringPool.BLANK)) {
7622 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7623 }
7624 else {
7625 bindSubtype = true;
7626
7627 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7628 }
7629
7630 if (orderByComparator != null) {
7631 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7632
7633 if (orderByConditionFields.length > 0) {
7634 query.append(WHERE_AND);
7635 }
7636
7637 for (int i = 0; i < orderByConditionFields.length; i++) {
7638 query.append(_ORDER_BY_ENTITY_ALIAS);
7639 query.append(orderByConditionFields[i]);
7640
7641 if ((i + 1) < orderByConditionFields.length) {
7642 if (orderByComparator.isAscending() ^ previous) {
7643 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7644 }
7645 else {
7646 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7647 }
7648 }
7649 else {
7650 if (orderByComparator.isAscending() ^ previous) {
7651 query.append(WHERE_GREATER_THAN);
7652 }
7653 else {
7654 query.append(WHERE_LESSER_THAN);
7655 }
7656 }
7657 }
7658
7659 query.append(ORDER_BY_CLAUSE);
7660
7661 String[] orderByFields = orderByComparator.getOrderByFields();
7662
7663 for (int i = 0; i < orderByFields.length; i++) {
7664 query.append(_ORDER_BY_ENTITY_ALIAS);
7665 query.append(orderByFields[i]);
7666
7667 if ((i + 1) < orderByFields.length) {
7668 if (orderByComparator.isAscending() ^ previous) {
7669 query.append(ORDER_BY_ASC_HAS_NEXT);
7670 }
7671 else {
7672 query.append(ORDER_BY_DESC_HAS_NEXT);
7673 }
7674 }
7675 else {
7676 if (orderByComparator.isAscending() ^ previous) {
7677 query.append(ORDER_BY_ASC);
7678 }
7679 else {
7680 query.append(ORDER_BY_DESC);
7681 }
7682 }
7683 }
7684 }
7685 else {
7686 query.append(RoleModelImpl.ORDER_BY_JPQL);
7687 }
7688
7689 String sql = query.toString();
7690
7691 Query q = session.createQuery(sql);
7692
7693 q.setFirstResult(0);
7694 q.setMaxResults(2);
7695
7696 QueryPos qPos = QueryPos.getInstance(q);
7697
7698 qPos.add(type);
7699
7700 if (bindSubtype) {
7701 qPos.add(subtype);
7702 }
7703
7704 if (orderByComparator != null) {
7705 Object[] values = orderByComparator.getOrderByConditionValues(role);
7706
7707 for (Object value : values) {
7708 qPos.add(value);
7709 }
7710 }
7711
7712 List<Role> list = q.list();
7713
7714 if (list.size() == 2) {
7715 return list.get(1);
7716 }
7717 else {
7718 return null;
7719 }
7720 }
7721
7722
7729 @Override
7730 public List<Role> filterFindByT_S(int type, String subtype) {
7731 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
7732 QueryUtil.ALL_POS, null);
7733 }
7734
7735
7748 @Override
7749 public List<Role> filterFindByT_S(int type, String subtype, int start,
7750 int end) {
7751 return filterFindByT_S(type, subtype, start, end, null);
7752 }
7753
7754
7768 @Override
7769 public List<Role> filterFindByT_S(int type, String subtype, int start,
7770 int end, OrderByComparator<Role> orderByComparator) {
7771 if (!InlineSQLHelperUtil.isEnabled()) {
7772 return findByT_S(type, subtype, start, end, orderByComparator);
7773 }
7774
7775 StringBundler query = null;
7776
7777 if (orderByComparator != null) {
7778 query = new StringBundler(4 +
7779 (orderByComparator.getOrderByFields().length * 3));
7780 }
7781 else {
7782 query = new StringBundler(4);
7783 }
7784
7785 if (getDB().isSupportsInlineDistinct()) {
7786 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7787 }
7788 else {
7789 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7790 }
7791
7792 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7793
7794 boolean bindSubtype = false;
7795
7796 if (subtype == null) {
7797 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7798 }
7799 else if (subtype.equals(StringPool.BLANK)) {
7800 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7801 }
7802 else {
7803 bindSubtype = true;
7804
7805 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7806 }
7807
7808 if (!getDB().isSupportsInlineDistinct()) {
7809 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7810 }
7811
7812 if (orderByComparator != null) {
7813 if (getDB().isSupportsInlineDistinct()) {
7814 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7815 orderByComparator, true);
7816 }
7817 else {
7818 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7819 orderByComparator, true);
7820 }
7821 }
7822 else {
7823 if (getDB().isSupportsInlineDistinct()) {
7824 query.append(RoleModelImpl.ORDER_BY_JPQL);
7825 }
7826 else {
7827 query.append(RoleModelImpl.ORDER_BY_SQL);
7828 }
7829 }
7830
7831 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7832 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
7833
7834 Session session = null;
7835
7836 try {
7837 session = openSession();
7838
7839 SQLQuery q = session.createSynchronizedSQLQuery(sql);
7840
7841 if (getDB().isSupportsInlineDistinct()) {
7842 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
7843 }
7844 else {
7845 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
7846 }
7847
7848 QueryPos qPos = QueryPos.getInstance(q);
7849
7850 qPos.add(type);
7851
7852 if (bindSubtype) {
7853 qPos.add(subtype);
7854 }
7855
7856 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
7857 }
7858 catch (Exception e) {
7859 throw processException(e);
7860 }
7861 finally {
7862 closeSession(session);
7863 }
7864 }
7865
7866
7876 @Override
7877 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
7878 String subtype, OrderByComparator<Role> orderByComparator)
7879 throws NoSuchRoleException {
7880 if (!InlineSQLHelperUtil.isEnabled()) {
7881 return findByT_S_PrevAndNext(roleId, type, subtype,
7882 orderByComparator);
7883 }
7884
7885 Role role = findByPrimaryKey(roleId);
7886
7887 Session session = null;
7888
7889 try {
7890 session = openSession();
7891
7892 Role[] array = new RoleImpl[3];
7893
7894 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7895 orderByComparator, true);
7896
7897 array[1] = role;
7898
7899 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
7900 orderByComparator, false);
7901
7902 return array;
7903 }
7904 catch (Exception e) {
7905 throw processException(e);
7906 }
7907 finally {
7908 closeSession(session);
7909 }
7910 }
7911
7912 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
7913 int type, String subtype, OrderByComparator<Role> orderByComparator,
7914 boolean previous) {
7915 StringBundler query = null;
7916
7917 if (orderByComparator != null) {
7918 query = new StringBundler(6 +
7919 (orderByComparator.getOrderByFields().length * 6));
7920 }
7921 else {
7922 query = new StringBundler(3);
7923 }
7924
7925 if (getDB().isSupportsInlineDistinct()) {
7926 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
7927 }
7928 else {
7929 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
7930 }
7931
7932 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
7933
7934 boolean bindSubtype = false;
7935
7936 if (subtype == null) {
7937 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
7938 }
7939 else if (subtype.equals(StringPool.BLANK)) {
7940 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
7941 }
7942 else {
7943 bindSubtype = true;
7944
7945 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
7946 }
7947
7948 if (!getDB().isSupportsInlineDistinct()) {
7949 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
7950 }
7951
7952 if (orderByComparator != null) {
7953 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7954
7955 if (orderByConditionFields.length > 0) {
7956 query.append(WHERE_AND);
7957 }
7958
7959 for (int i = 0; i < orderByConditionFields.length; i++) {
7960 if (getDB().isSupportsInlineDistinct()) {
7961 query.append(_ORDER_BY_ENTITY_ALIAS);
7962 }
7963 else {
7964 query.append(_ORDER_BY_ENTITY_TABLE);
7965 }
7966
7967 query.append(orderByConditionFields[i]);
7968
7969 if ((i + 1) < orderByConditionFields.length) {
7970 if (orderByComparator.isAscending() ^ previous) {
7971 query.append(WHERE_GREATER_THAN_HAS_NEXT);
7972 }
7973 else {
7974 query.append(WHERE_LESSER_THAN_HAS_NEXT);
7975 }
7976 }
7977 else {
7978 if (orderByComparator.isAscending() ^ previous) {
7979 query.append(WHERE_GREATER_THAN);
7980 }
7981 else {
7982 query.append(WHERE_LESSER_THAN);
7983 }
7984 }
7985 }
7986
7987 query.append(ORDER_BY_CLAUSE);
7988
7989 String[] orderByFields = orderByComparator.getOrderByFields();
7990
7991 for (int i = 0; i < orderByFields.length; i++) {
7992 if (getDB().isSupportsInlineDistinct()) {
7993 query.append(_ORDER_BY_ENTITY_ALIAS);
7994 }
7995 else {
7996 query.append(_ORDER_BY_ENTITY_TABLE);
7997 }
7998
7999 query.append(orderByFields[i]);
8000
8001 if ((i + 1) < orderByFields.length) {
8002 if (orderByComparator.isAscending() ^ previous) {
8003 query.append(ORDER_BY_ASC_HAS_NEXT);
8004 }
8005 else {
8006 query.append(ORDER_BY_DESC_HAS_NEXT);
8007 }
8008 }
8009 else {
8010 if (orderByComparator.isAscending() ^ previous) {
8011 query.append(ORDER_BY_ASC);
8012 }
8013 else {
8014 query.append(ORDER_BY_DESC);
8015 }
8016 }
8017 }
8018 }
8019 else {
8020 if (getDB().isSupportsInlineDistinct()) {
8021 query.append(RoleModelImpl.ORDER_BY_JPQL);
8022 }
8023 else {
8024 query.append(RoleModelImpl.ORDER_BY_SQL);
8025 }
8026 }
8027
8028 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8029 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
8030
8031 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8032
8033 q.setFirstResult(0);
8034 q.setMaxResults(2);
8035
8036 if (getDB().isSupportsInlineDistinct()) {
8037 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
8038 }
8039 else {
8040 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
8041 }
8042
8043 QueryPos qPos = QueryPos.getInstance(q);
8044
8045 qPos.add(type);
8046
8047 if (bindSubtype) {
8048 qPos.add(subtype);
8049 }
8050
8051 if (orderByComparator != null) {
8052 Object[] values = orderByComparator.getOrderByConditionValues(role);
8053
8054 for (Object value : values) {
8055 qPos.add(value);
8056 }
8057 }
8058
8059 List<Role> list = q.list();
8060
8061 if (list.size() == 2) {
8062 return list.get(1);
8063 }
8064 else {
8065 return null;
8066 }
8067 }
8068
8069
8075 @Override
8076 public void removeByT_S(int type, String subtype) {
8077 for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
8078 QueryUtil.ALL_POS, null)) {
8079 remove(role);
8080 }
8081 }
8082
8083
8090 @Override
8091 public int countByT_S(int type, String subtype) {
8092 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
8093
8094 Object[] finderArgs = new Object[] { type, subtype };
8095
8096 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8097
8098 if (count == null) {
8099 StringBundler query = new StringBundler(3);
8100
8101 query.append(_SQL_COUNT_ROLE_WHERE);
8102
8103 query.append(_FINDER_COLUMN_T_S_TYPE_2);
8104
8105 boolean bindSubtype = false;
8106
8107 if (subtype == null) {
8108 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
8109 }
8110 else if (subtype.equals(StringPool.BLANK)) {
8111 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
8112 }
8113 else {
8114 bindSubtype = true;
8115
8116 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
8117 }
8118
8119 String sql = query.toString();
8120
8121 Session session = null;
8122
8123 try {
8124 session = openSession();
8125
8126 Query q = session.createQuery(sql);
8127
8128 QueryPos qPos = QueryPos.getInstance(q);
8129
8130 qPos.add(type);
8131
8132 if (bindSubtype) {
8133 qPos.add(subtype);
8134 }
8135
8136 count = (Long)q.uniqueResult();
8137
8138 finderCache.putResult(finderPath, finderArgs, count);
8139 }
8140 catch (Exception e) {
8141 finderCache.removeResult(finderPath, finderArgs);
8142
8143 throw processException(e);
8144 }
8145 finally {
8146 closeSession(session);
8147 }
8148 }
8149
8150 return count.intValue();
8151 }
8152
8153
8160 @Override
8161 public int filterCountByT_S(int type, String subtype) {
8162 if (!InlineSQLHelperUtil.isEnabled()) {
8163 return countByT_S(type, subtype);
8164 }
8165
8166 StringBundler query = new StringBundler(3);
8167
8168 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
8169
8170 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
8171
8172 boolean bindSubtype = false;
8173
8174 if (subtype == null) {
8175 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
8176 }
8177 else if (subtype.equals(StringPool.BLANK)) {
8178 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
8179 }
8180 else {
8181 bindSubtype = true;
8182
8183 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
8184 }
8185
8186 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8187 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
8188
8189 Session session = null;
8190
8191 try {
8192 session = openSession();
8193
8194 SQLQuery q = session.createSynchronizedSQLQuery(sql);
8195
8196 q.addScalar(COUNT_COLUMN_NAME,
8197 com.liferay.portal.kernel.dao.orm.Type.LONG);
8198
8199 QueryPos qPos = QueryPos.getInstance(q);
8200
8201 qPos.add(type);
8202
8203 if (bindSubtype) {
8204 qPos.add(subtype);
8205 }
8206
8207 Long count = (Long)q.uniqueResult();
8208
8209 return count.intValue();
8210 }
8211 catch (Exception e) {
8212 throw processException(e);
8213 }
8214 finally {
8215 closeSession(session);
8216 }
8217 }
8218
8219 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
8220 private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND ";
8221 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
8222 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
8223 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
8224 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8225 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
8226 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
8227 new String[] {
8228 Long.class.getName(), Long.class.getName(), Long.class.getName()
8229 },
8230 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
8231 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8232 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
8233 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
8234 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
8235 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
8236 new String[] {
8237 Long.class.getName(), Long.class.getName(), Long.class.getName()
8238 });
8239
8240
8249 @Override
8250 public Role findByC_C_C(long companyId, long classNameId, long classPK)
8251 throws NoSuchRoleException {
8252 Role role = fetchByC_C_C(companyId, classNameId, classPK);
8253
8254 if (role == null) {
8255 StringBundler msg = new StringBundler(8);
8256
8257 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8258
8259 msg.append("companyId=");
8260 msg.append(companyId);
8261
8262 msg.append(", classNameId=");
8263 msg.append(classNameId);
8264
8265 msg.append(", classPK=");
8266 msg.append(classPK);
8267
8268 msg.append(StringPool.CLOSE_CURLY_BRACE);
8269
8270 if (_log.isWarnEnabled()) {
8271 _log.warn(msg.toString());
8272 }
8273
8274 throw new NoSuchRoleException(msg.toString());
8275 }
8276
8277 return role;
8278 }
8279
8280
8288 @Override
8289 public Role fetchByC_C_C(long companyId, long classNameId, long classPK) {
8290 return fetchByC_C_C(companyId, classNameId, classPK, true);
8291 }
8292
8293
8302 @Override
8303 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
8304 boolean retrieveFromCache) {
8305 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8306
8307 Object result = null;
8308
8309 if (retrieveFromCache) {
8310 result = finderCache.getResult(FINDER_PATH_FETCH_BY_C_C_C,
8311 finderArgs, this);
8312 }
8313
8314 if (result instanceof Role) {
8315 Role role = (Role)result;
8316
8317 if ((companyId != role.getCompanyId()) ||
8318 (classNameId != role.getClassNameId()) ||
8319 (classPK != role.getClassPK())) {
8320 result = null;
8321 }
8322 }
8323
8324 if (result == null) {
8325 StringBundler query = new StringBundler(5);
8326
8327 query.append(_SQL_SELECT_ROLE_WHERE);
8328
8329 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8330
8331 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8332
8333 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8334
8335 String sql = query.toString();
8336
8337 Session session = null;
8338
8339 try {
8340 session = openSession();
8341
8342 Query q = session.createQuery(sql);
8343
8344 QueryPos qPos = QueryPos.getInstance(q);
8345
8346 qPos.add(companyId);
8347
8348 qPos.add(classNameId);
8349
8350 qPos.add(classPK);
8351
8352 List<Role> list = q.list();
8353
8354 if (list.isEmpty()) {
8355 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8356 finderArgs, list);
8357 }
8358 else {
8359 Role role = list.get(0);
8360
8361 result = role;
8362
8363 cacheResult(role);
8364
8365 if ((role.getCompanyId() != companyId) ||
8366 (role.getClassNameId() != classNameId) ||
8367 (role.getClassPK() != classPK)) {
8368 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8369 finderArgs, role);
8370 }
8371 }
8372 }
8373 catch (Exception e) {
8374 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, finderArgs);
8375
8376 throw processException(e);
8377 }
8378 finally {
8379 closeSession(session);
8380 }
8381 }
8382
8383 if (result instanceof List<?>) {
8384 return null;
8385 }
8386 else {
8387 return (Role)result;
8388 }
8389 }
8390
8391
8399 @Override
8400 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
8401 throws NoSuchRoleException {
8402 Role role = findByC_C_C(companyId, classNameId, classPK);
8403
8404 return remove(role);
8405 }
8406
8407
8415 @Override
8416 public int countByC_C_C(long companyId, long classNameId, long classPK) {
8417 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
8418
8419 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
8420
8421 Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8422
8423 if (count == null) {
8424 StringBundler query = new StringBundler(4);
8425
8426 query.append(_SQL_COUNT_ROLE_WHERE);
8427
8428 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
8429
8430 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
8431
8432 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
8433
8434 String sql = query.toString();
8435
8436 Session session = null;
8437
8438 try {
8439 session = openSession();
8440
8441 Query q = session.createQuery(sql);
8442
8443 QueryPos qPos = QueryPos.getInstance(q);
8444
8445 qPos.add(companyId);
8446
8447 qPos.add(classNameId);
8448
8449 qPos.add(classPK);
8450
8451 count = (Long)q.uniqueResult();
8452
8453 finderCache.putResult(finderPath, finderArgs, count);
8454 }
8455 catch (Exception e) {
8456 finderCache.removeResult(finderPath, finderArgs);
8457
8458 throw processException(e);
8459 }
8460 finally {
8461 closeSession(session);
8462 }
8463 }
8464
8465 return count.intValue();
8466 }
8467
8468 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
8469 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
8470 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
8471
8472 public RolePersistenceImpl() {
8473 setModelClass(Role.class);
8474 }
8475
8476
8481 @Override
8482 public void cacheResult(Role role) {
8483 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8484 RoleImpl.class, role.getPrimaryKey(), role);
8485
8486 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N,
8487 new Object[] { role.getCompanyId(), role.getName() }, role);
8488
8489 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C,
8490 new Object[] {
8491 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
8492 }, role);
8493
8494 role.resetOriginalValues();
8495 }
8496
8497
8502 @Override
8503 public void cacheResult(List<Role> roles) {
8504 for (Role role : roles) {
8505 if (entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8506 RoleImpl.class, role.getPrimaryKey()) == null) {
8507 cacheResult(role);
8508 }
8509 else {
8510 role.resetOriginalValues();
8511 }
8512 }
8513 }
8514
8515
8522 @Override
8523 public void clearCache() {
8524 entityCache.clearCache(RoleImpl.class);
8525
8526 finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
8527 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8528 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8529 }
8530
8531
8538 @Override
8539 public void clearCache(Role role) {
8540 entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8541 RoleImpl.class, role.getPrimaryKey());
8542
8543 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8544 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8545
8546 clearUniqueFindersCache((RoleModelImpl)role);
8547 }
8548
8549 @Override
8550 public void clearCache(List<Role> roles) {
8551 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8552 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8553
8554 for (Role role : roles) {
8555 entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8556 RoleImpl.class, role.getPrimaryKey());
8557
8558 clearUniqueFindersCache((RoleModelImpl)role);
8559 }
8560 }
8561
8562 protected void cacheUniqueFindersCache(RoleModelImpl roleModelImpl,
8563 boolean isNew) {
8564 if (isNew) {
8565 Object[] args = new Object[] {
8566 roleModelImpl.getCompanyId(), roleModelImpl.getName()
8567 };
8568
8569 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8570 Long.valueOf(1));
8571 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args, roleModelImpl);
8572
8573 args = new Object[] {
8574 roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(),
8575 roleModelImpl.getClassPK()
8576 };
8577
8578 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8579 Long.valueOf(1));
8580 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, args,
8581 roleModelImpl);
8582 }
8583 else {
8584 if ((roleModelImpl.getColumnBitmask() &
8585 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8586 Object[] args = new Object[] {
8587 roleModelImpl.getCompanyId(), roleModelImpl.getName()
8588 };
8589
8590 finderCache.putResult(FINDER_PATH_COUNT_BY_C_N, args,
8591 Long.valueOf(1));
8592 finderCache.putResult(FINDER_PATH_FETCH_BY_C_N, args,
8593 roleModelImpl);
8594 }
8595
8596 if ((roleModelImpl.getColumnBitmask() &
8597 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8598 Object[] args = new Object[] {
8599 roleModelImpl.getCompanyId(),
8600 roleModelImpl.getClassNameId(),
8601 roleModelImpl.getClassPK()
8602 };
8603
8604 finderCache.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
8605 Long.valueOf(1));
8606 finderCache.putResult(FINDER_PATH_FETCH_BY_C_C_C, args,
8607 roleModelImpl);
8608 }
8609 }
8610 }
8611
8612 protected void clearUniqueFindersCache(RoleModelImpl roleModelImpl) {
8613 Object[] args = new Object[] {
8614 roleModelImpl.getCompanyId(), roleModelImpl.getName()
8615 };
8616
8617 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8618 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8619
8620 if ((roleModelImpl.getColumnBitmask() &
8621 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
8622 args = new Object[] {
8623 roleModelImpl.getOriginalCompanyId(),
8624 roleModelImpl.getOriginalName()
8625 };
8626
8627 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
8628 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
8629 }
8630
8631 args = new Object[] {
8632 roleModelImpl.getCompanyId(), roleModelImpl.getClassNameId(),
8633 roleModelImpl.getClassPK()
8634 };
8635
8636 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8637 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8638
8639 if ((roleModelImpl.getColumnBitmask() &
8640 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
8641 args = new Object[] {
8642 roleModelImpl.getOriginalCompanyId(),
8643 roleModelImpl.getOriginalClassNameId(),
8644 roleModelImpl.getOriginalClassPK()
8645 };
8646
8647 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
8648 finderCache.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
8649 }
8650 }
8651
8652
8658 @Override
8659 public Role create(long roleId) {
8660 Role role = new RoleImpl();
8661
8662 role.setNew(true);
8663 role.setPrimaryKey(roleId);
8664
8665 String uuid = PortalUUIDUtil.generate();
8666
8667 role.setUuid(uuid);
8668
8669 role.setCompanyId(companyProvider.getCompanyId());
8670
8671 return role;
8672 }
8673
8674
8681 @Override
8682 public Role remove(long roleId) throws NoSuchRoleException {
8683 return remove((Serializable)roleId);
8684 }
8685
8686
8693 @Override
8694 public Role remove(Serializable primaryKey) throws NoSuchRoleException {
8695 Session session = null;
8696
8697 try {
8698 session = openSession();
8699
8700 Role role = (Role)session.get(RoleImpl.class, primaryKey);
8701
8702 if (role == null) {
8703 if (_log.isWarnEnabled()) {
8704 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
8705 }
8706
8707 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
8708 primaryKey);
8709 }
8710
8711 return remove(role);
8712 }
8713 catch (NoSuchRoleException nsee) {
8714 throw nsee;
8715 }
8716 catch (Exception e) {
8717 throw processException(e);
8718 }
8719 finally {
8720 closeSession(session);
8721 }
8722 }
8723
8724 @Override
8725 protected Role removeImpl(Role role) {
8726 role = toUnwrappedModel(role);
8727
8728 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8729
8730 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
8731
8732 Session session = null;
8733
8734 try {
8735 session = openSession();
8736
8737 if (!session.contains(role)) {
8738 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
8739 }
8740
8741 if (role != null) {
8742 session.delete(role);
8743 }
8744 }
8745 catch (Exception e) {
8746 throw processException(e);
8747 }
8748 finally {
8749 closeSession(session);
8750 }
8751
8752 if (role != null) {
8753 clearCache(role);
8754 }
8755
8756 return role;
8757 }
8758
8759 @Override
8760 public Role updateImpl(Role role) {
8761 role = toUnwrappedModel(role);
8762
8763 boolean isNew = role.isNew();
8764
8765 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
8766
8767 if (Validator.isNull(role.getUuid())) {
8768 String uuid = PortalUUIDUtil.generate();
8769
8770 role.setUuid(uuid);
8771 }
8772
8773 ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
8774
8775 Date now = new Date();
8776
8777 if (isNew && (role.getCreateDate() == null)) {
8778 if (serviceContext == null) {
8779 role.setCreateDate(now);
8780 }
8781 else {
8782 role.setCreateDate(serviceContext.getCreateDate(now));
8783 }
8784 }
8785
8786 if (!roleModelImpl.hasSetModifiedDate()) {
8787 if (serviceContext == null) {
8788 role.setModifiedDate(now);
8789 }
8790 else {
8791 role.setModifiedDate(serviceContext.getModifiedDate(now));
8792 }
8793 }
8794
8795 Session session = null;
8796
8797 try {
8798 session = openSession();
8799
8800 if (role.isNew()) {
8801 session.save(role);
8802
8803 role.setNew(false);
8804 }
8805 else {
8806 role = (Role)session.merge(role);
8807 }
8808 }
8809 catch (Exception e) {
8810 throw processException(e);
8811 }
8812 finally {
8813 closeSession(session);
8814 }
8815
8816 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8817
8818 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
8819 finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8820 }
8821
8822 else {
8823 if ((roleModelImpl.getColumnBitmask() &
8824 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
8825 Object[] args = new Object[] { roleModelImpl.getOriginalUuid() };
8826
8827 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8828 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8829 args);
8830
8831 args = new Object[] { roleModelImpl.getUuid() };
8832
8833 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
8834 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
8835 args);
8836 }
8837
8838 if ((roleModelImpl.getColumnBitmask() &
8839 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
8840 Object[] args = new Object[] {
8841 roleModelImpl.getOriginalUuid(),
8842 roleModelImpl.getOriginalCompanyId()
8843 };
8844
8845 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8846 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8847 args);
8848
8849 args = new Object[] {
8850 roleModelImpl.getUuid(), roleModelImpl.getCompanyId()
8851 };
8852
8853 finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
8854 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
8855 args);
8856 }
8857
8858 if ((roleModelImpl.getColumnBitmask() &
8859 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
8860 Object[] args = new Object[] {
8861 roleModelImpl.getOriginalCompanyId()
8862 };
8863
8864 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
8865 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8866 args);
8867
8868 args = new Object[] { roleModelImpl.getCompanyId() };
8869
8870 finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
8871 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
8872 args);
8873 }
8874
8875 if ((roleModelImpl.getColumnBitmask() &
8876 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
8877 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
8878
8879 finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8880 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8881 args);
8882
8883 args = new Object[] { roleModelImpl.getName() };
8884
8885 finderCache.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
8886 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
8887 args);
8888 }
8889
8890 if ((roleModelImpl.getColumnBitmask() &
8891 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
8892 Object[] args = new Object[] { roleModelImpl.getOriginalType() };
8893
8894 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8895 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8896 args);
8897
8898 args = new Object[] { roleModelImpl.getType() };
8899
8900 finderCache.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
8901 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
8902 args);
8903 }
8904
8905 if ((roleModelImpl.getColumnBitmask() &
8906 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
8907 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
8908
8909 finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8910 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8911 args);
8912
8913 args = new Object[] { roleModelImpl.getSubtype() };
8914
8915 finderCache.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
8916 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
8917 args);
8918 }
8919
8920 if ((roleModelImpl.getColumnBitmask() &
8921 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T.getColumnBitmask()) != 0) {
8922 Object[] args = new Object[] {
8923 roleModelImpl.getOriginalCompanyId(),
8924 roleModelImpl.getOriginalType()
8925 };
8926
8927 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8928 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8929 args);
8930
8931 args = new Object[] {
8932 roleModelImpl.getCompanyId(), roleModelImpl.getType()
8933 };
8934
8935 finderCache.removeResult(FINDER_PATH_COUNT_BY_C_T, args);
8936 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_T,
8937 args);
8938 }
8939
8940 if ((roleModelImpl.getColumnBitmask() &
8941 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
8942 Object[] args = new Object[] {
8943 roleModelImpl.getOriginalType(),
8944 roleModelImpl.getOriginalSubtype()
8945 };
8946
8947 finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8948 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8949 args);
8950
8951 args = new Object[] {
8952 roleModelImpl.getType(), roleModelImpl.getSubtype()
8953 };
8954
8955 finderCache.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
8956 finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
8957 args);
8958 }
8959 }
8960
8961 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
8962 RoleImpl.class, role.getPrimaryKey(), role, false);
8963
8964 clearUniqueFindersCache(roleModelImpl);
8965 cacheUniqueFindersCache(roleModelImpl, isNew);
8966
8967 role.resetOriginalValues();
8968
8969 return role;
8970 }
8971
8972 protected Role toUnwrappedModel(Role role) {
8973 if (role instanceof RoleImpl) {
8974 return role;
8975 }
8976
8977 RoleImpl roleImpl = new RoleImpl();
8978
8979 roleImpl.setNew(role.isNew());
8980 roleImpl.setPrimaryKey(role.getPrimaryKey());
8981
8982 roleImpl.setMvccVersion(role.getMvccVersion());
8983 roleImpl.setUuid(role.getUuid());
8984 roleImpl.setRoleId(role.getRoleId());
8985 roleImpl.setCompanyId(role.getCompanyId());
8986 roleImpl.setUserId(role.getUserId());
8987 roleImpl.setUserName(role.getUserName());
8988 roleImpl.setCreateDate(role.getCreateDate());
8989 roleImpl.setModifiedDate(role.getModifiedDate());
8990 roleImpl.setClassNameId(role.getClassNameId());
8991 roleImpl.setClassPK(role.getClassPK());
8992 roleImpl.setName(role.getName());
8993 roleImpl.setTitle(role.getTitle());
8994 roleImpl.setDescription(role.getDescription());
8995 roleImpl.setType(role.getType());
8996 roleImpl.setSubtype(role.getSubtype());
8997
8998 return roleImpl;
8999 }
9000
9001
9008 @Override
9009 public Role findByPrimaryKey(Serializable primaryKey)
9010 throws NoSuchRoleException {
9011 Role role = fetchByPrimaryKey(primaryKey);
9012
9013 if (role == null) {
9014 if (_log.isWarnEnabled()) {
9015 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9016 }
9017
9018 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9019 primaryKey);
9020 }
9021
9022 return role;
9023 }
9024
9025
9032 @Override
9033 public Role findByPrimaryKey(long roleId) throws NoSuchRoleException {
9034 return findByPrimaryKey((Serializable)roleId);
9035 }
9036
9037
9043 @Override
9044 public Role fetchByPrimaryKey(Serializable primaryKey) {
9045 Role role = (Role)entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9046 RoleImpl.class, primaryKey);
9047
9048 if (role == _nullRole) {
9049 return null;
9050 }
9051
9052 if (role == null) {
9053 Session session = null;
9054
9055 try {
9056 session = openSession();
9057
9058 role = (Role)session.get(RoleImpl.class, primaryKey);
9059
9060 if (role != null) {
9061 cacheResult(role);
9062 }
9063 else {
9064 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9065 RoleImpl.class, primaryKey, _nullRole);
9066 }
9067 }
9068 catch (Exception e) {
9069 entityCache.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9070 RoleImpl.class, primaryKey);
9071
9072 throw processException(e);
9073 }
9074 finally {
9075 closeSession(session);
9076 }
9077 }
9078
9079 return role;
9080 }
9081
9082
9088 @Override
9089 public Role fetchByPrimaryKey(long roleId) {
9090 return fetchByPrimaryKey((Serializable)roleId);
9091 }
9092
9093 @Override
9094 public Map<Serializable, Role> fetchByPrimaryKeys(
9095 Set<Serializable> primaryKeys) {
9096 if (primaryKeys.isEmpty()) {
9097 return Collections.emptyMap();
9098 }
9099
9100 Map<Serializable, Role> map = new HashMap<Serializable, Role>();
9101
9102 if (primaryKeys.size() == 1) {
9103 Iterator<Serializable> iterator = primaryKeys.iterator();
9104
9105 Serializable primaryKey = iterator.next();
9106
9107 Role role = fetchByPrimaryKey(primaryKey);
9108
9109 if (role != null) {
9110 map.put(primaryKey, role);
9111 }
9112
9113 return map;
9114 }
9115
9116 Set<Serializable> uncachedPrimaryKeys = null;
9117
9118 for (Serializable primaryKey : primaryKeys) {
9119 Role role = (Role)entityCache.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9120 RoleImpl.class, primaryKey);
9121
9122 if (role == null) {
9123 if (uncachedPrimaryKeys == null) {
9124 uncachedPrimaryKeys = new HashSet<Serializable>();
9125 }
9126
9127 uncachedPrimaryKeys.add(primaryKey);
9128 }
9129 else {
9130 map.put(primaryKey, role);
9131 }
9132 }
9133
9134 if (uncachedPrimaryKeys == null) {
9135 return map;
9136 }
9137
9138 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
9139 1);
9140
9141 query.append(_SQL_SELECT_ROLE_WHERE_PKS_IN);
9142
9143 for (Serializable primaryKey : uncachedPrimaryKeys) {
9144 query.append(String.valueOf(primaryKey));
9145
9146 query.append(StringPool.COMMA);
9147 }
9148
9149 query.setIndex(query.index() - 1);
9150
9151 query.append(StringPool.CLOSE_PARENTHESIS);
9152
9153 String sql = query.toString();
9154
9155 Session session = null;
9156
9157 try {
9158 session = openSession();
9159
9160 Query q = session.createQuery(sql);
9161
9162 for (Role role : (List<Role>)q.list()) {
9163 map.put(role.getPrimaryKeyObj(), role);
9164
9165 cacheResult(role);
9166
9167 uncachedPrimaryKeys.remove(role.getPrimaryKeyObj());
9168 }
9169
9170 for (Serializable primaryKey : uncachedPrimaryKeys) {
9171 entityCache.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
9172 RoleImpl.class, primaryKey, _nullRole);
9173 }
9174 }
9175 catch (Exception e) {
9176 throw processException(e);
9177 }
9178 finally {
9179 closeSession(session);
9180 }
9181
9182 return map;
9183 }
9184
9185
9190 @Override
9191 public List<Role> findAll() {
9192 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9193 }
9194
9195
9206 @Override
9207 public List<Role> findAll(int start, int end) {
9208 return findAll(start, end, null);
9209 }
9210
9211
9223 @Override
9224 public List<Role> findAll(int start, int end,
9225 OrderByComparator<Role> orderByComparator) {
9226 return findAll(start, end, orderByComparator, true);
9227 }
9228
9229
9242 @Override
9243 public List<Role> findAll(int start, int end,
9244 OrderByComparator<Role> orderByComparator, boolean retrieveFromCache) {
9245 boolean pagination = true;
9246 FinderPath finderPath = null;
9247 Object[] finderArgs = null;
9248
9249 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9250 (orderByComparator == null)) {
9251 pagination = false;
9252 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
9253 finderArgs = FINDER_ARGS_EMPTY;
9254 }
9255 else {
9256 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
9257 finderArgs = new Object[] { start, end, orderByComparator };
9258 }
9259
9260 List<Role> list = null;
9261
9262 if (retrieveFromCache) {
9263 list = (List<Role>)finderCache.getResult(finderPath, finderArgs,
9264 this);
9265 }
9266
9267 if (list == null) {
9268 StringBundler query = null;
9269 String sql = null;
9270
9271 if (orderByComparator != null) {
9272 query = new StringBundler(2 +
9273 (orderByComparator.getOrderByFields().length * 3));
9274
9275 query.append(_SQL_SELECT_ROLE);
9276
9277 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9278 orderByComparator);
9279
9280 sql = query.toString();
9281 }
9282 else {
9283 sql = _SQL_SELECT_ROLE;
9284
9285 if (pagination) {
9286 sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
9287 }
9288 }
9289
9290 Session session = null;
9291
9292 try {
9293 session = openSession();
9294
9295 Query q = session.createQuery(sql);
9296
9297 if (!pagination) {
9298 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9299 end, false);
9300
9301 Collections.sort(list);
9302
9303 list = Collections.unmodifiableList(list);
9304 }
9305 else {
9306 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
9307 end);
9308 }
9309
9310 cacheResult(list);
9311
9312 finderCache.putResult(finderPath, finderArgs, list);
9313 }
9314 catch (Exception e) {
9315 finderCache.removeResult(finderPath, finderArgs);
9316
9317 throw processException(e);
9318 }
9319 finally {
9320 closeSession(session);
9321 }
9322 }
9323
9324 return list;
9325 }
9326
9327
9331 @Override
9332 public void removeAll() {
9333 for (Role role : findAll()) {
9334 remove(role);
9335 }
9336 }
9337
9338
9343 @Override
9344 public int countAll() {
9345 Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
9346 FINDER_ARGS_EMPTY, this);
9347
9348 if (count == null) {
9349 Session session = null;
9350
9351 try {
9352 session = openSession();
9353
9354 Query q = session.createQuery(_SQL_COUNT_ROLE);
9355
9356 count = (Long)q.uniqueResult();
9357
9358 finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
9359 count);
9360 }
9361 catch (Exception e) {
9362 finderCache.removeResult(FINDER_PATH_COUNT_ALL,
9363 FINDER_ARGS_EMPTY);
9364
9365 throw processException(e);
9366 }
9367 finally {
9368 closeSession(session);
9369 }
9370 }
9371
9372 return count.intValue();
9373 }
9374
9375
9381 @Override
9382 public long[] getGroupPrimaryKeys(long pk) {
9383 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9384
9385 return pks.clone();
9386 }
9387
9388
9394 @Override
9395 public List<com.liferay.portal.model.Group> getGroups(long pk) {
9396 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9397 }
9398
9399
9411 @Override
9412 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
9413 int end) {
9414 return getGroups(pk, start, end, null);
9415 }
9416
9417
9430 @Override
9431 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
9432 int end,
9433 OrderByComparator<com.liferay.portal.model.Group> orderByComparator) {
9434 return roleToGroupTableMapper.getRightBaseModels(pk, start, end,
9435 orderByComparator);
9436 }
9437
9438
9444 @Override
9445 public int getGroupsSize(long pk) {
9446 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
9447
9448 return pks.length;
9449 }
9450
9451
9458 @Override
9459 public boolean containsGroup(long pk, long groupPK) {
9460 return roleToGroupTableMapper.containsTableMapping(pk, groupPK);
9461 }
9462
9463
9469 @Override
9470 public boolean containsGroups(long pk) {
9471 if (getGroupsSize(pk) > 0) {
9472 return true;
9473 }
9474 else {
9475 return false;
9476 }
9477 }
9478
9479
9485 @Override
9486 public void addGroup(long pk, long groupPK) {
9487 Role role = fetchByPrimaryKey(pk);
9488
9489 if (role == null) {
9490 roleToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(),
9491 pk, groupPK);
9492 }
9493 else {
9494 roleToGroupTableMapper.addTableMapping(role.getCompanyId(), pk,
9495 groupPK);
9496 }
9497 }
9498
9499
9505 @Override
9506 public void addGroup(long pk, com.liferay.portal.model.Group group) {
9507 Role role = fetchByPrimaryKey(pk);
9508
9509 if (role == null) {
9510 roleToGroupTableMapper.addTableMapping(companyProvider.getCompanyId(),
9511 pk, group.getPrimaryKey());
9512 }
9513 else {
9514 roleToGroupTableMapper.addTableMapping(role.getCompanyId(), pk,
9515 group.getPrimaryKey());
9516 }
9517 }
9518
9519
9525 @Override
9526 public void addGroups(long pk, long[] groupPKs) {
9527 long companyId = 0;
9528
9529 Role role = fetchByPrimaryKey(pk);
9530
9531 if (role == null) {
9532 companyId = companyProvider.getCompanyId();
9533 }
9534 else {
9535 companyId = role.getCompanyId();
9536 }
9537
9538 for (long groupPK : groupPKs) {
9539 roleToGroupTableMapper.addTableMapping(companyId, pk, groupPK);
9540 }
9541 }
9542
9543
9549 @Override
9550 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups) {
9551 long companyId = 0;
9552
9553 Role role = fetchByPrimaryKey(pk);
9554
9555 if (role == null) {
9556 companyId = companyProvider.getCompanyId();
9557 }
9558 else {
9559 companyId = role.getCompanyId();
9560 }
9561
9562 for (com.liferay.portal.model.Group group : groups) {
9563 roleToGroupTableMapper.addTableMapping(companyId, pk,
9564 group.getPrimaryKey());
9565 }
9566 }
9567
9568
9573 @Override
9574 public void clearGroups(long pk) {
9575 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9576 }
9577
9578
9584 @Override
9585 public void removeGroup(long pk, long groupPK) {
9586 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9587 }
9588
9589
9595 @Override
9596 public void removeGroup(long pk, com.liferay.portal.model.Group group) {
9597 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9598 }
9599
9600
9606 @Override
9607 public void removeGroups(long pk, long[] groupPKs) {
9608 for (long groupPK : groupPKs) {
9609 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
9610 }
9611 }
9612
9613
9619 @Override
9620 public void removeGroups(long pk,
9621 List<com.liferay.portal.model.Group> groups) {
9622 for (com.liferay.portal.model.Group group : groups) {
9623 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
9624 }
9625 }
9626
9627
9633 @Override
9634 public void setGroups(long pk, long[] groupPKs) {
9635 Set<Long> newGroupPKsSet = SetUtil.fromArray(groupPKs);
9636 Set<Long> oldGroupPKsSet = SetUtil.fromArray(roleToGroupTableMapper.getRightPrimaryKeys(
9637 pk));
9638
9639 Set<Long> removeGroupPKsSet = new HashSet<Long>(oldGroupPKsSet);
9640
9641 removeGroupPKsSet.removeAll(newGroupPKsSet);
9642
9643 for (long removeGroupPK : removeGroupPKsSet) {
9644 roleToGroupTableMapper.deleteTableMapping(pk, removeGroupPK);
9645 }
9646
9647 newGroupPKsSet.removeAll(oldGroupPKsSet);
9648
9649 long companyId = 0;
9650
9651 Role role = fetchByPrimaryKey(pk);
9652
9653 if (role == null) {
9654 companyId = companyProvider.getCompanyId();
9655 }
9656 else {
9657 companyId = role.getCompanyId();
9658 }
9659
9660 for (long newGroupPK : newGroupPKsSet) {
9661 roleToGroupTableMapper.addTableMapping(companyId, pk, newGroupPK);
9662 }
9663 }
9664
9665
9671 @Override
9672 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups) {
9673 try {
9674 long[] groupPKs = new long[groups.size()];
9675
9676 for (int i = 0; i < groups.size(); i++) {
9677 com.liferay.portal.model.Group group = groups.get(i);
9678
9679 groupPKs[i] = group.getPrimaryKey();
9680 }
9681
9682 setGroups(pk, groupPKs);
9683 }
9684 catch (Exception e) {
9685 throw processException(e);
9686 }
9687 }
9688
9689
9695 @Override
9696 public long[] getUserPrimaryKeys(long pk) {
9697 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9698
9699 return pks.clone();
9700 }
9701
9702
9708 @Override
9709 public List<com.liferay.portal.model.User> getUsers(long pk) {
9710 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
9711 }
9712
9713
9725 @Override
9726 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9727 int end) {
9728 return getUsers(pk, start, end, null);
9729 }
9730
9731
9744 @Override
9745 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
9746 int end,
9747 OrderByComparator<com.liferay.portal.model.User> orderByComparator) {
9748 return roleToUserTableMapper.getRightBaseModels(pk, start, end,
9749 orderByComparator);
9750 }
9751
9752
9758 @Override
9759 public int getUsersSize(long pk) {
9760 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
9761
9762 return pks.length;
9763 }
9764
9765
9772 @Override
9773 public boolean containsUser(long pk, long userPK) {
9774 return roleToUserTableMapper.containsTableMapping(pk, userPK);
9775 }
9776
9777
9783 @Override
9784 public boolean containsUsers(long pk) {
9785 if (getUsersSize(pk) > 0) {
9786 return true;
9787 }
9788 else {
9789 return false;
9790 }
9791 }
9792
9793
9799 @Override
9800 public void addUser(long pk, long userPK) {
9801 Role role = fetchByPrimaryKey(pk);
9802
9803 if (role == null) {
9804 roleToUserTableMapper.addTableMapping(companyProvider.getCompanyId(),
9805 pk, userPK);
9806 }
9807 else {
9808 roleToUserTableMapper.addTableMapping(role.getCompanyId(), pk,
9809 userPK);
9810 }
9811 }
9812
9813
9819 @Override
9820 public void addUser(long pk, com.liferay.portal.model.User user) {
9821 Role role = fetchByPrimaryKey(pk);
9822
9823 if (role == null) {
9824 roleToUserTableMapper.addTableMapping(companyProvider.getCompanyId(),
9825 pk, user.getPrimaryKey());
9826 }
9827 else {
9828 roleToUserTableMapper.addTableMapping(role.getCompanyId(), pk,
9829 user.getPrimaryKey());
9830 }
9831 }
9832
9833
9839 @Override
9840 public void addUsers(long pk, long[] userPKs) {
9841 long companyId = 0;
9842
9843 Role role = fetchByPrimaryKey(pk);
9844
9845 if (role == null) {
9846 companyId = companyProvider.getCompanyId();
9847 }
9848 else {
9849 companyId = role.getCompanyId();
9850 }
9851
9852 for (long userPK : userPKs) {
9853 roleToUserTableMapper.addTableMapping(companyId, pk, userPK);
9854 }
9855 }
9856
9857
9863 @Override
9864 public void addUsers(long pk, List<com.liferay.portal.model.User> users) {
9865 long companyId = 0;
9866
9867 Role role = fetchByPrimaryKey(pk);
9868
9869 if (role == null) {
9870 companyId = companyProvider.getCompanyId();
9871 }
9872 else {
9873 companyId = role.getCompanyId();
9874 }
9875
9876 for (com.liferay.portal.model.User user : users) {
9877 roleToUserTableMapper.addTableMapping(companyId, pk,
9878 user.getPrimaryKey());
9879 }
9880 }
9881
9882
9887 @Override
9888 public void clearUsers(long pk) {
9889 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
9890 }
9891
9892
9898 @Override
9899 public void removeUser(long pk, long userPK) {
9900 roleToUserTableMapper.deleteTableMapping(pk, userPK);
9901 }
9902
9903
9909 @Override
9910 public void removeUser(long pk, com.liferay.portal.model.User user) {
9911 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9912 }
9913
9914
9920 @Override
9921 public void removeUsers(long pk, long[] userPKs) {
9922 for (long userPK : userPKs) {
9923 roleToUserTableMapper.deleteTableMapping(pk, userPK);
9924 }
9925 }
9926
9927
9933 @Override
9934 public void removeUsers(long pk, List<com.liferay.portal.model.User> users) {
9935 for (com.liferay.portal.model.User user : users) {
9936 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
9937 }
9938 }
9939
9940
9946 @Override
9947 public void setUsers(long pk, long[] userPKs) {
9948 Set<Long> newUserPKsSet = SetUtil.fromArray(userPKs);
9949 Set<Long> oldUserPKsSet = SetUtil.fromArray(roleToUserTableMapper.getRightPrimaryKeys(
9950 pk));
9951
9952 Set<Long> removeUserPKsSet = new HashSet<Long>(oldUserPKsSet);
9953
9954 removeUserPKsSet.removeAll(newUserPKsSet);
9955
9956 for (long removeUserPK : removeUserPKsSet) {
9957 roleToUserTableMapper.deleteTableMapping(pk, removeUserPK);
9958 }
9959
9960 newUserPKsSet.removeAll(oldUserPKsSet);
9961
9962 long companyId = 0;
9963
9964 Role role = fetchByPrimaryKey(pk);
9965
9966 if (role == null) {
9967 companyId = companyProvider.getCompanyId();
9968 }
9969 else {
9970 companyId = role.getCompanyId();
9971 }
9972
9973 for (long newUserPK : newUserPKsSet) {
9974 roleToUserTableMapper.addTableMapping(companyId, pk, newUserPK);
9975 }
9976 }
9977
9978
9984 @Override
9985 public void setUsers(long pk, List<com.liferay.portal.model.User> users) {
9986 try {
9987 long[] userPKs = new long[users.size()];
9988
9989 for (int i = 0; i < users.size(); i++) {
9990 com.liferay.portal.model.User user = users.get(i);
9991
9992 userPKs[i] = user.getPrimaryKey();
9993 }
9994
9995 setUsers(pk, userPKs);
9996 }
9997 catch (Exception e) {
9998 throw processException(e);
9999 }
10000 }
10001
10002 @Override
10003 public Set<String> getBadColumnNames() {
10004 return _badColumnNames;
10005 }
10006
10007 @Override
10008 protected Map<String, Integer> getTableColumnsMap() {
10009 return RoleModelImpl.TABLE_COLUMNS_MAP;
10010 }
10011
10012
10015 public void afterPropertiesSet() {
10016 roleToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Roles",
10017 "companyId", "roleId", "groupId", this, groupPersistence);
10018
10019 roleToUserTableMapper = TableMapperFactory.getTableMapper("Users_Roles",
10020 "companyId", "roleId", "userId", this, userPersistence);
10021 }
10022
10023 public void destroy() {
10024 entityCache.removeCache(RoleImpl.class.getName());
10025 finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
10026 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10027 finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10028
10029 TableMapperFactory.removeTableMapper("Groups_Roles");
10030 TableMapperFactory.removeTableMapper("Users_Roles");
10031 }
10032
10033 @BeanReference(type = CompanyProviderWrapper.class)
10034 protected CompanyProvider companyProvider;
10035 protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
10036 protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
10037 @BeanReference(type = GroupPersistence.class)
10038 protected GroupPersistence groupPersistence;
10039 protected TableMapper<Role, com.liferay.portal.model.Group> roleToGroupTableMapper;
10040 @BeanReference(type = UserPersistence.class)
10041 protected UserPersistence userPersistence;
10042 protected TableMapper<Role, com.liferay.portal.model.User> roleToUserTableMapper;
10043 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
10044 private static final String _SQL_SELECT_ROLE_WHERE_PKS_IN = "SELECT role FROM Role role WHERE roleId IN (";
10045 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
10046 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
10047 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
10048 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
10049 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
10050 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
10051 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
10052 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
10053 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
10054 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
10055 private static final String _FILTER_ENTITY_ALIAS = "role";
10056 private static final String _FILTER_ENTITY_TABLE = "Role_";
10057 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
10058 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
10059 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
10060 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
10061 private static final Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
10062 private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
10063 "uuid", "type"
10064 });
10065 private static final Role _nullRole = new RoleImpl() {
10066 @Override
10067 public Object clone() {
10068 return this;
10069 }
10070
10071 @Override
10072 public CacheModel<Role> toCacheModel() {
10073 return _nullRoleCacheModel;
10074 }
10075 };
10076
10077 private static final CacheModel<Role> _nullRoleCacheModel = new NullCacheModel();
10078
10079 private static class NullCacheModel implements CacheModel<Role>, MVCCModel {
10080 @Override
10081 public long getMvccVersion() {
10082 return -1;
10083 }
10084
10085 @Override
10086 public void setMvccVersion(long mvccVersion) {
10087 }
10088
10089 @Override
10090 public Role toEntityModel() {
10091 return _nullRole;
10092 }
10093 }
10094 }