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