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