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