001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchRoleException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.SQLQuery;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.SetUtil;
035 import com.liferay.portal.kernel.util.StringBundler;
036 import com.liferay.portal.kernel.util.StringPool;
037 import com.liferay.portal.kernel.util.StringUtil;
038 import com.liferay.portal.kernel.util.UnmodifiableList;
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.ModelListener;
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.persistence.impl.BasePersistenceImpl;
048 import com.liferay.portal.service.persistence.impl.TableMapper;
049 import com.liferay.portal.service.persistence.impl.TableMapperFactory;
050
051 import java.io.Serializable;
052
053 import java.util.ArrayList;
054 import java.util.Collections;
055 import java.util.List;
056 import java.util.Set;
057
058
070 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
071 implements RolePersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List1";
080 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List2";
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
083 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
085 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
086 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
087 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
089 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
092 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
093 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
094 new String[] {
095 String.class.getName(),
096
097 Integer.class.getName(), Integer.class.getName(),
098 OrderByComparator.class.getName()
099 });
100 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
101 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
103 new String[] { String.class.getName() },
104 RoleModelImpl.UUID_COLUMN_BITMASK |
105 RoleModelImpl.NAME_COLUMN_BITMASK);
106 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
107 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
108 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109 new String[] { String.class.getName() });
110
111
118 @Override
119 public List<Role> findByUuid(String uuid) throws SystemException {
120 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121 }
122
123
136 @Override
137 public List<Role> findByUuid(String uuid, int start, int end)
138 throws SystemException {
139 return findByUuid(uuid, start, end, null);
140 }
141
142
156 @Override
157 public List<Role> findByUuid(String uuid, int start, int end,
158 OrderByComparator orderByComparator) throws SystemException {
159 boolean pagination = true;
160 FinderPath finderPath = null;
161 Object[] finderArgs = null;
162
163 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164 (orderByComparator == null)) {
165 pagination = false;
166 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167 finderArgs = new Object[] { uuid };
168 }
169 else {
170 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171 finderArgs = new Object[] { uuid, start, end, orderByComparator };
172 }
173
174 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
175 finderArgs, this);
176
177 if ((list != null) && !list.isEmpty()) {
178 for (Role role : list) {
179 if (!Validator.equals(uuid, role.getUuid())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(3 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(3);
196 }
197
198 query.append(_SQL_SELECT_ROLE_WHERE);
199
200 boolean bindUuid = false;
201
202 if (uuid == null) {
203 query.append(_FINDER_COLUMN_UUID_UUID_1);
204 }
205 else if (uuid.equals(StringPool.BLANK)) {
206 query.append(_FINDER_COLUMN_UUID_UUID_3);
207 }
208 else {
209 bindUuid = true;
210
211 query.append(_FINDER_COLUMN_UUID_UUID_2);
212 }
213
214 if (orderByComparator != null) {
215 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
216 orderByComparator);
217 }
218 else
219 if (pagination) {
220 query.append(RoleModelImpl.ORDER_BY_JPQL);
221 }
222
223 String sql = query.toString();
224
225 Session session = null;
226
227 try {
228 session = openSession();
229
230 Query q = session.createQuery(sql);
231
232 QueryPos qPos = QueryPos.getInstance(q);
233
234 if (bindUuid) {
235 qPos.add(uuid);
236 }
237
238 if (!pagination) {
239 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
240 end, false);
241
242 Collections.sort(list);
243
244 list = new UnmodifiableList<Role>(list);
245 }
246 else {
247 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
248 end);
249 }
250
251 cacheResult(list);
252
253 FinderCacheUtil.putResult(finderPath, finderArgs, list);
254 }
255 catch (Exception e) {
256 FinderCacheUtil.removeResult(finderPath, finderArgs);
257
258 throw processException(e);
259 }
260 finally {
261 closeSession(session);
262 }
263 }
264
265 return list;
266 }
267
268
277 @Override
278 public Role findByUuid_First(String uuid,
279 OrderByComparator orderByComparator)
280 throws NoSuchRoleException, SystemException {
281 Role role = fetchByUuid_First(uuid, orderByComparator);
282
283 if (role != null) {
284 return role;
285 }
286
287 StringBundler msg = new StringBundler(4);
288
289 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290
291 msg.append("uuid=");
292 msg.append(uuid);
293
294 msg.append(StringPool.CLOSE_CURLY_BRACE);
295
296 throw new NoSuchRoleException(msg.toString());
297 }
298
299
307 @Override
308 public Role fetchByUuid_First(String uuid,
309 OrderByComparator orderByComparator) throws SystemException {
310 List<Role> list = findByUuid(uuid, 0, 1, orderByComparator);
311
312 if (!list.isEmpty()) {
313 return list.get(0);
314 }
315
316 return null;
317 }
318
319
328 @Override
329 public Role findByUuid_Last(String uuid, OrderByComparator orderByComparator)
330 throws NoSuchRoleException, SystemException {
331 Role role = fetchByUuid_Last(uuid, orderByComparator);
332
333 if (role != null) {
334 return role;
335 }
336
337 StringBundler msg = new StringBundler(4);
338
339 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
340
341 msg.append("uuid=");
342 msg.append(uuid);
343
344 msg.append(StringPool.CLOSE_CURLY_BRACE);
345
346 throw new NoSuchRoleException(msg.toString());
347 }
348
349
357 @Override
358 public Role fetchByUuid_Last(String uuid,
359 OrderByComparator orderByComparator) throws SystemException {
360 int count = countByUuid(uuid);
361
362 if (count == 0) {
363 return null;
364 }
365
366 List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator);
367
368 if (!list.isEmpty()) {
369 return list.get(0);
370 }
371
372 return null;
373 }
374
375
385 @Override
386 public Role[] findByUuid_PrevAndNext(long roleId, String uuid,
387 OrderByComparator orderByComparator)
388 throws NoSuchRoleException, SystemException {
389 Role role = findByPrimaryKey(roleId);
390
391 Session session = null;
392
393 try {
394 session = openSession();
395
396 Role[] array = new RoleImpl[3];
397
398 array[0] = getByUuid_PrevAndNext(session, role, uuid,
399 orderByComparator, true);
400
401 array[1] = role;
402
403 array[2] = getByUuid_PrevAndNext(session, role, uuid,
404 orderByComparator, false);
405
406 return array;
407 }
408 catch (Exception e) {
409 throw processException(e);
410 }
411 finally {
412 closeSession(session);
413 }
414 }
415
416 protected Role getByUuid_PrevAndNext(Session session, Role role,
417 String uuid, OrderByComparator orderByComparator, boolean previous) {
418 StringBundler query = null;
419
420 if (orderByComparator != null) {
421 query = new StringBundler(6 +
422 (orderByComparator.getOrderByFields().length * 6));
423 }
424 else {
425 query = new StringBundler(3);
426 }
427
428 query.append(_SQL_SELECT_ROLE_WHERE);
429
430 boolean bindUuid = false;
431
432 if (uuid == null) {
433 query.append(_FINDER_COLUMN_UUID_UUID_1);
434 }
435 else if (uuid.equals(StringPool.BLANK)) {
436 query.append(_FINDER_COLUMN_UUID_UUID_3);
437 }
438 else {
439 bindUuid = true;
440
441 query.append(_FINDER_COLUMN_UUID_UUID_2);
442 }
443
444 if (orderByComparator != null) {
445 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446
447 if (orderByConditionFields.length > 0) {
448 query.append(WHERE_AND);
449 }
450
451 for (int i = 0; i < orderByConditionFields.length; i++) {
452 query.append(_ORDER_BY_ENTITY_ALIAS);
453 query.append(orderByConditionFields[i]);
454
455 if ((i + 1) < orderByConditionFields.length) {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN_HAS_NEXT);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN_HAS_NEXT);
461 }
462 }
463 else {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN);
469 }
470 }
471 }
472
473 query.append(ORDER_BY_CLAUSE);
474
475 String[] orderByFields = orderByComparator.getOrderByFields();
476
477 for (int i = 0; i < orderByFields.length; i++) {
478 query.append(_ORDER_BY_ENTITY_ALIAS);
479 query.append(orderByFields[i]);
480
481 if ((i + 1) < orderByFields.length) {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC_HAS_NEXT);
484 }
485 else {
486 query.append(ORDER_BY_DESC_HAS_NEXT);
487 }
488 }
489 else {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC);
492 }
493 else {
494 query.append(ORDER_BY_DESC);
495 }
496 }
497 }
498 }
499 else {
500 query.append(RoleModelImpl.ORDER_BY_JPQL);
501 }
502
503 String sql = query.toString();
504
505 Query q = session.createQuery(sql);
506
507 q.setFirstResult(0);
508 q.setMaxResults(2);
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 if (bindUuid) {
513 qPos.add(uuid);
514 }
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(role);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<Role> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
541 @Override
542 public List<Role> filterFindByUuid(String uuid) throws SystemException {
543 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
544 }
545
546
559 @Override
560 public List<Role> filterFindByUuid(String uuid, int start, int end)
561 throws SystemException {
562 return filterFindByUuid(uuid, start, end, null);
563 }
564
565
579 @Override
580 public List<Role> filterFindByUuid(String uuid, int start, int end,
581 OrderByComparator orderByComparator) throws SystemException {
582 if (!InlineSQLHelperUtil.isEnabled()) {
583 return findByUuid(uuid, start, end, orderByComparator);
584 }
585
586 StringBundler query = null;
587
588 if (orderByComparator != null) {
589 query = new StringBundler(3 +
590 (orderByComparator.getOrderByFields().length * 3));
591 }
592 else {
593 query = new StringBundler(3);
594 }
595
596 if (getDB().isSupportsInlineDistinct()) {
597 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
598 }
599 else {
600 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
601 }
602
603 boolean bindUuid = false;
604
605 if (uuid == null) {
606 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
607 }
608 else if (uuid.equals(StringPool.BLANK)) {
609 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
610 }
611 else {
612 bindUuid = true;
613
614 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
615 }
616
617 if (!getDB().isSupportsInlineDistinct()) {
618 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
619 }
620
621 if (orderByComparator != null) {
622 if (getDB().isSupportsInlineDistinct()) {
623 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
624 orderByComparator, true);
625 }
626 else {
627 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
628 orderByComparator, true);
629 }
630 }
631 else {
632 if (getDB().isSupportsInlineDistinct()) {
633 query.append(RoleModelImpl.ORDER_BY_JPQL);
634 }
635 else {
636 query.append(RoleModelImpl.ORDER_BY_SQL);
637 }
638 }
639
640 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
641 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
642
643 Session session = null;
644
645 try {
646 session = openSession();
647
648 SQLQuery q = session.createSQLQuery(sql);
649
650 if (getDB().isSupportsInlineDistinct()) {
651 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
652 }
653 else {
654 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
655 }
656
657 QueryPos qPos = QueryPos.getInstance(q);
658
659 if (bindUuid) {
660 qPos.add(uuid);
661 }
662
663 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
664 }
665 catch (Exception e) {
666 throw processException(e);
667 }
668 finally {
669 closeSession(session);
670 }
671 }
672
673
683 @Override
684 public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid,
685 OrderByComparator orderByComparator)
686 throws NoSuchRoleException, SystemException {
687 if (!InlineSQLHelperUtil.isEnabled()) {
688 return findByUuid_PrevAndNext(roleId, uuid, orderByComparator);
689 }
690
691 Role role = findByPrimaryKey(roleId);
692
693 Session session = null;
694
695 try {
696 session = openSession();
697
698 Role[] array = new RoleImpl[3];
699
700 array[0] = filterGetByUuid_PrevAndNext(session, role, uuid,
701 orderByComparator, true);
702
703 array[1] = role;
704
705 array[2] = filterGetByUuid_PrevAndNext(session, role, uuid,
706 orderByComparator, false);
707
708 return array;
709 }
710 catch (Exception e) {
711 throw processException(e);
712 }
713 finally {
714 closeSession(session);
715 }
716 }
717
718 protected Role filterGetByUuid_PrevAndNext(Session session, Role role,
719 String uuid, OrderByComparator orderByComparator, boolean previous) {
720 StringBundler query = null;
721
722 if (orderByComparator != null) {
723 query = new StringBundler(6 +
724 (orderByComparator.getOrderByFields().length * 6));
725 }
726 else {
727 query = new StringBundler(3);
728 }
729
730 if (getDB().isSupportsInlineDistinct()) {
731 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
732 }
733 else {
734 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
735 }
736
737 boolean bindUuid = false;
738
739 if (uuid == null) {
740 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
741 }
742 else if (uuid.equals(StringPool.BLANK)) {
743 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
744 }
745 else {
746 bindUuid = true;
747
748 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
749 }
750
751 if (!getDB().isSupportsInlineDistinct()) {
752 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
753 }
754
755 if (orderByComparator != null) {
756 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
757
758 if (orderByConditionFields.length > 0) {
759 query.append(WHERE_AND);
760 }
761
762 for (int i = 0; i < orderByConditionFields.length; i++) {
763 if (getDB().isSupportsInlineDistinct()) {
764 query.append(_ORDER_BY_ENTITY_ALIAS);
765 }
766 else {
767 query.append(_ORDER_BY_ENTITY_TABLE);
768 }
769
770 query.append(orderByConditionFields[i]);
771
772 if ((i + 1) < orderByConditionFields.length) {
773 if (orderByComparator.isAscending() ^ previous) {
774 query.append(WHERE_GREATER_THAN_HAS_NEXT);
775 }
776 else {
777 query.append(WHERE_LESSER_THAN_HAS_NEXT);
778 }
779 }
780 else {
781 if (orderByComparator.isAscending() ^ previous) {
782 query.append(WHERE_GREATER_THAN);
783 }
784 else {
785 query.append(WHERE_LESSER_THAN);
786 }
787 }
788 }
789
790 query.append(ORDER_BY_CLAUSE);
791
792 String[] orderByFields = orderByComparator.getOrderByFields();
793
794 for (int i = 0; i < orderByFields.length; i++) {
795 if (getDB().isSupportsInlineDistinct()) {
796 query.append(_ORDER_BY_ENTITY_ALIAS);
797 }
798 else {
799 query.append(_ORDER_BY_ENTITY_TABLE);
800 }
801
802 query.append(orderByFields[i]);
803
804 if ((i + 1) < orderByFields.length) {
805 if (orderByComparator.isAscending() ^ previous) {
806 query.append(ORDER_BY_ASC_HAS_NEXT);
807 }
808 else {
809 query.append(ORDER_BY_DESC_HAS_NEXT);
810 }
811 }
812 else {
813 if (orderByComparator.isAscending() ^ previous) {
814 query.append(ORDER_BY_ASC);
815 }
816 else {
817 query.append(ORDER_BY_DESC);
818 }
819 }
820 }
821 }
822 else {
823 if (getDB().isSupportsInlineDistinct()) {
824 query.append(RoleModelImpl.ORDER_BY_JPQL);
825 }
826 else {
827 query.append(RoleModelImpl.ORDER_BY_SQL);
828 }
829 }
830
831 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
832 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
833
834 SQLQuery q = session.createSQLQuery(sql);
835
836 q.setFirstResult(0);
837 q.setMaxResults(2);
838
839 if (getDB().isSupportsInlineDistinct()) {
840 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
841 }
842 else {
843 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
844 }
845
846 QueryPos qPos = QueryPos.getInstance(q);
847
848 if (bindUuid) {
849 qPos.add(uuid);
850 }
851
852 if (orderByComparator != null) {
853 Object[] values = orderByComparator.getOrderByConditionValues(role);
854
855 for (Object value : values) {
856 qPos.add(value);
857 }
858 }
859
860 List<Role> list = q.list();
861
862 if (list.size() == 2) {
863 return list.get(1);
864 }
865 else {
866 return null;
867 }
868 }
869
870
876 @Override
877 public void removeByUuid(String uuid) throws SystemException {
878 for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
879 null)) {
880 remove(role);
881 }
882 }
883
884
891 @Override
892 public int countByUuid(String uuid) throws SystemException {
893 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
894
895 Object[] finderArgs = new Object[] { uuid };
896
897 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
898 this);
899
900 if (count == null) {
901 StringBundler query = new StringBundler(2);
902
903 query.append(_SQL_COUNT_ROLE_WHERE);
904
905 boolean bindUuid = false;
906
907 if (uuid == null) {
908 query.append(_FINDER_COLUMN_UUID_UUID_1);
909 }
910 else if (uuid.equals(StringPool.BLANK)) {
911 query.append(_FINDER_COLUMN_UUID_UUID_3);
912 }
913 else {
914 bindUuid = true;
915
916 query.append(_FINDER_COLUMN_UUID_UUID_2);
917 }
918
919 String sql = query.toString();
920
921 Session session = null;
922
923 try {
924 session = openSession();
925
926 Query q = session.createQuery(sql);
927
928 QueryPos qPos = QueryPos.getInstance(q);
929
930 if (bindUuid) {
931 qPos.add(uuid);
932 }
933
934 count = (Long)q.uniqueResult();
935
936 FinderCacheUtil.putResult(finderPath, finderArgs, count);
937 }
938 catch (Exception e) {
939 FinderCacheUtil.removeResult(finderPath, finderArgs);
940
941 throw processException(e);
942 }
943 finally {
944 closeSession(session);
945 }
946 }
947
948 return count.intValue();
949 }
950
951
958 @Override
959 public int filterCountByUuid(String uuid) throws SystemException {
960 if (!InlineSQLHelperUtil.isEnabled()) {
961 return countByUuid(uuid);
962 }
963
964 StringBundler query = new StringBundler(2);
965
966 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
967
968 boolean bindUuid = false;
969
970 if (uuid == null) {
971 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
972 }
973 else if (uuid.equals(StringPool.BLANK)) {
974 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
975 }
976 else {
977 bindUuid = true;
978
979 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
980 }
981
982 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
983 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
984
985 Session session = null;
986
987 try {
988 session = openSession();
989
990 SQLQuery q = session.createSQLQuery(sql);
991
992 q.addScalar(COUNT_COLUMN_NAME,
993 com.liferay.portal.kernel.dao.orm.Type.LONG);
994
995 QueryPos qPos = QueryPos.getInstance(q);
996
997 if (bindUuid) {
998 qPos.add(uuid);
999 }
1000
1001 Long count = (Long)q.uniqueResult();
1002
1003 return count.intValue();
1004 }
1005 catch (Exception e) {
1006 throw processException(e);
1007 }
1008 finally {
1009 closeSession(session);
1010 }
1011 }
1012
1013 private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL";
1014 private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?";
1015 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')";
1016 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL";
1017 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?";
1018 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')";
1019 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1020 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1021 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1022 new String[] {
1023 String.class.getName(), Long.class.getName(),
1024
1025 Integer.class.getName(), Integer.class.getName(),
1026 OrderByComparator.class.getName()
1027 });
1028 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1029 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1030 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1031 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1032 new String[] { String.class.getName(), Long.class.getName() },
1033 RoleModelImpl.UUID_COLUMN_BITMASK |
1034 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1035 RoleModelImpl.NAME_COLUMN_BITMASK);
1036 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1037 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1038 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1039 new String[] { String.class.getName(), Long.class.getName() });
1040
1041
1049 @Override
1050 public List<Role> findByUuid_C(String uuid, long companyId)
1051 throws SystemException {
1052 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1053 QueryUtil.ALL_POS, null);
1054 }
1055
1056
1070 @Override
1071 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1072 int end) throws SystemException {
1073 return findByUuid_C(uuid, companyId, start, end, null);
1074 }
1075
1076
1091 @Override
1092 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1093 int end, OrderByComparator orderByComparator) throws SystemException {
1094 boolean pagination = true;
1095 FinderPath finderPath = null;
1096 Object[] finderArgs = null;
1097
1098 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1099 (orderByComparator == null)) {
1100 pagination = false;
1101 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1102 finderArgs = new Object[] { uuid, companyId };
1103 }
1104 else {
1105 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1106 finderArgs = new Object[] {
1107 uuid, companyId,
1108
1109 start, end, orderByComparator
1110 };
1111 }
1112
1113 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1114 finderArgs, this);
1115
1116 if ((list != null) && !list.isEmpty()) {
1117 for (Role role : list) {
1118 if (!Validator.equals(uuid, role.getUuid()) ||
1119 (companyId != role.getCompanyId())) {
1120 list = null;
1121
1122 break;
1123 }
1124 }
1125 }
1126
1127 if (list == null) {
1128 StringBundler query = null;
1129
1130 if (orderByComparator != null) {
1131 query = new StringBundler(4 +
1132 (orderByComparator.getOrderByFields().length * 3));
1133 }
1134 else {
1135 query = new StringBundler(4);
1136 }
1137
1138 query.append(_SQL_SELECT_ROLE_WHERE);
1139
1140 boolean bindUuid = false;
1141
1142 if (uuid == null) {
1143 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1144 }
1145 else if (uuid.equals(StringPool.BLANK)) {
1146 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1147 }
1148 else {
1149 bindUuid = true;
1150
1151 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1152 }
1153
1154 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1155
1156 if (orderByComparator != null) {
1157 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1158 orderByComparator);
1159 }
1160 else
1161 if (pagination) {
1162 query.append(RoleModelImpl.ORDER_BY_JPQL);
1163 }
1164
1165 String sql = query.toString();
1166
1167 Session session = null;
1168
1169 try {
1170 session = openSession();
1171
1172 Query q = session.createQuery(sql);
1173
1174 QueryPos qPos = QueryPos.getInstance(q);
1175
1176 if (bindUuid) {
1177 qPos.add(uuid);
1178 }
1179
1180 qPos.add(companyId);
1181
1182 if (!pagination) {
1183 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1184 end, false);
1185
1186 Collections.sort(list);
1187
1188 list = new UnmodifiableList<Role>(list);
1189 }
1190 else {
1191 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1192 end);
1193 }
1194
1195 cacheResult(list);
1196
1197 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1198 }
1199 catch (Exception e) {
1200 FinderCacheUtil.removeResult(finderPath, finderArgs);
1201
1202 throw processException(e);
1203 }
1204 finally {
1205 closeSession(session);
1206 }
1207 }
1208
1209 return list;
1210 }
1211
1212
1222 @Override
1223 public Role findByUuid_C_First(String uuid, long companyId,
1224 OrderByComparator orderByComparator)
1225 throws NoSuchRoleException, SystemException {
1226 Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1227
1228 if (role != null) {
1229 return role;
1230 }
1231
1232 StringBundler msg = new StringBundler(6);
1233
1234 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1235
1236 msg.append("uuid=");
1237 msg.append(uuid);
1238
1239 msg.append(", companyId=");
1240 msg.append(companyId);
1241
1242 msg.append(StringPool.CLOSE_CURLY_BRACE);
1243
1244 throw new NoSuchRoleException(msg.toString());
1245 }
1246
1247
1256 @Override
1257 public Role fetchByUuid_C_First(String uuid, long companyId,
1258 OrderByComparator orderByComparator) throws SystemException {
1259 List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1260
1261 if (!list.isEmpty()) {
1262 return list.get(0);
1263 }
1264
1265 return null;
1266 }
1267
1268
1278 @Override
1279 public Role findByUuid_C_Last(String uuid, long companyId,
1280 OrderByComparator orderByComparator)
1281 throws NoSuchRoleException, SystemException {
1282 Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1283
1284 if (role != null) {
1285 return role;
1286 }
1287
1288 StringBundler msg = new StringBundler(6);
1289
1290 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1291
1292 msg.append("uuid=");
1293 msg.append(uuid);
1294
1295 msg.append(", companyId=");
1296 msg.append(companyId);
1297
1298 msg.append(StringPool.CLOSE_CURLY_BRACE);
1299
1300 throw new NoSuchRoleException(msg.toString());
1301 }
1302
1303
1312 @Override
1313 public Role fetchByUuid_C_Last(String uuid, long companyId,
1314 OrderByComparator orderByComparator) throws SystemException {
1315 int count = countByUuid_C(uuid, companyId);
1316
1317 if (count == 0) {
1318 return null;
1319 }
1320
1321 List<Role> list = findByUuid_C(uuid, companyId, count - 1, count,
1322 orderByComparator);
1323
1324 if (!list.isEmpty()) {
1325 return list.get(0);
1326 }
1327
1328 return null;
1329 }
1330
1331
1342 @Override
1343 public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid,
1344 long companyId, OrderByComparator orderByComparator)
1345 throws NoSuchRoleException, SystemException {
1346 Role role = findByPrimaryKey(roleId);
1347
1348 Session session = null;
1349
1350 try {
1351 session = openSession();
1352
1353 Role[] array = new RoleImpl[3];
1354
1355 array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1356 orderByComparator, true);
1357
1358 array[1] = role;
1359
1360 array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1361 orderByComparator, false);
1362
1363 return array;
1364 }
1365 catch (Exception e) {
1366 throw processException(e);
1367 }
1368 finally {
1369 closeSession(session);
1370 }
1371 }
1372
1373 protected Role getByUuid_C_PrevAndNext(Session session, Role role,
1374 String uuid, long companyId, OrderByComparator orderByComparator,
1375 boolean previous) {
1376 StringBundler query = null;
1377
1378 if (orderByComparator != null) {
1379 query = new StringBundler(6 +
1380 (orderByComparator.getOrderByFields().length * 6));
1381 }
1382 else {
1383 query = new StringBundler(3);
1384 }
1385
1386 query.append(_SQL_SELECT_ROLE_WHERE);
1387
1388 boolean bindUuid = false;
1389
1390 if (uuid == null) {
1391 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1392 }
1393 else if (uuid.equals(StringPool.BLANK)) {
1394 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1395 }
1396 else {
1397 bindUuid = true;
1398
1399 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1400 }
1401
1402 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1403
1404 if (orderByComparator != null) {
1405 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1406
1407 if (orderByConditionFields.length > 0) {
1408 query.append(WHERE_AND);
1409 }
1410
1411 for (int i = 0; i < orderByConditionFields.length; i++) {
1412 query.append(_ORDER_BY_ENTITY_ALIAS);
1413 query.append(orderByConditionFields[i]);
1414
1415 if ((i + 1) < orderByConditionFields.length) {
1416 if (orderByComparator.isAscending() ^ previous) {
1417 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1418 }
1419 else {
1420 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1421 }
1422 }
1423 else {
1424 if (orderByComparator.isAscending() ^ previous) {
1425 query.append(WHERE_GREATER_THAN);
1426 }
1427 else {
1428 query.append(WHERE_LESSER_THAN);
1429 }
1430 }
1431 }
1432
1433 query.append(ORDER_BY_CLAUSE);
1434
1435 String[] orderByFields = orderByComparator.getOrderByFields();
1436
1437 for (int i = 0; i < orderByFields.length; i++) {
1438 query.append(_ORDER_BY_ENTITY_ALIAS);
1439 query.append(orderByFields[i]);
1440
1441 if ((i + 1) < orderByFields.length) {
1442 if (orderByComparator.isAscending() ^ previous) {
1443 query.append(ORDER_BY_ASC_HAS_NEXT);
1444 }
1445 else {
1446 query.append(ORDER_BY_DESC_HAS_NEXT);
1447 }
1448 }
1449 else {
1450 if (orderByComparator.isAscending() ^ previous) {
1451 query.append(ORDER_BY_ASC);
1452 }
1453 else {
1454 query.append(ORDER_BY_DESC);
1455 }
1456 }
1457 }
1458 }
1459 else {
1460 query.append(RoleModelImpl.ORDER_BY_JPQL);
1461 }
1462
1463 String sql = query.toString();
1464
1465 Query q = session.createQuery(sql);
1466
1467 q.setFirstResult(0);
1468 q.setMaxResults(2);
1469
1470 QueryPos qPos = QueryPos.getInstance(q);
1471
1472 if (bindUuid) {
1473 qPos.add(uuid);
1474 }
1475
1476 qPos.add(companyId);
1477
1478 if (orderByComparator != null) {
1479 Object[] values = orderByComparator.getOrderByConditionValues(role);
1480
1481 for (Object value : values) {
1482 qPos.add(value);
1483 }
1484 }
1485
1486 List<Role> list = q.list();
1487
1488 if (list.size() == 2) {
1489 return list.get(1);
1490 }
1491 else {
1492 return null;
1493 }
1494 }
1495
1496
1504 @Override
1505 public List<Role> filterFindByUuid_C(String uuid, long companyId)
1506 throws SystemException {
1507 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1508 QueryUtil.ALL_POS, null);
1509 }
1510
1511
1525 @Override
1526 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1527 int start, int end) throws SystemException {
1528 return filterFindByUuid_C(uuid, companyId, start, end, null);
1529 }
1530
1531
1546 @Override
1547 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1548 int start, int end, OrderByComparator orderByComparator)
1549 throws SystemException {
1550 if (!InlineSQLHelperUtil.isEnabled()) {
1551 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1552 }
1553
1554 StringBundler query = null;
1555
1556 if (orderByComparator != null) {
1557 query = new StringBundler(4 +
1558 (orderByComparator.getOrderByFields().length * 3));
1559 }
1560 else {
1561 query = new StringBundler(4);
1562 }
1563
1564 if (getDB().isSupportsInlineDistinct()) {
1565 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1566 }
1567 else {
1568 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1569 }
1570
1571 boolean bindUuid = false;
1572
1573 if (uuid == null) {
1574 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1575 }
1576 else if (uuid.equals(StringPool.BLANK)) {
1577 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1578 }
1579 else {
1580 bindUuid = true;
1581
1582 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1583 }
1584
1585 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1586
1587 if (!getDB().isSupportsInlineDistinct()) {
1588 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1589 }
1590
1591 if (orderByComparator != null) {
1592 if (getDB().isSupportsInlineDistinct()) {
1593 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1594 orderByComparator, true);
1595 }
1596 else {
1597 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1598 orderByComparator, true);
1599 }
1600 }
1601 else {
1602 if (getDB().isSupportsInlineDistinct()) {
1603 query.append(RoleModelImpl.ORDER_BY_JPQL);
1604 }
1605 else {
1606 query.append(RoleModelImpl.ORDER_BY_SQL);
1607 }
1608 }
1609
1610 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1611 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1612
1613 Session session = null;
1614
1615 try {
1616 session = openSession();
1617
1618 SQLQuery q = session.createSQLQuery(sql);
1619
1620 if (getDB().isSupportsInlineDistinct()) {
1621 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1622 }
1623 else {
1624 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1625 }
1626
1627 QueryPos qPos = QueryPos.getInstance(q);
1628
1629 if (bindUuid) {
1630 qPos.add(uuid);
1631 }
1632
1633 qPos.add(companyId);
1634
1635 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1636 }
1637 catch (Exception e) {
1638 throw processException(e);
1639 }
1640 finally {
1641 closeSession(session);
1642 }
1643 }
1644
1645
1656 @Override
1657 public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid,
1658 long companyId, OrderByComparator orderByComparator)
1659 throws NoSuchRoleException, SystemException {
1660 if (!InlineSQLHelperUtil.isEnabled()) {
1661 return findByUuid_C_PrevAndNext(roleId, uuid, companyId,
1662 orderByComparator);
1663 }
1664
1665 Role role = findByPrimaryKey(roleId);
1666
1667 Session session = null;
1668
1669 try {
1670 session = openSession();
1671
1672 Role[] array = new RoleImpl[3];
1673
1674 array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1675 companyId, orderByComparator, true);
1676
1677 array[1] = role;
1678
1679 array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1680 companyId, orderByComparator, false);
1681
1682 return array;
1683 }
1684 catch (Exception e) {
1685 throw processException(e);
1686 }
1687 finally {
1688 closeSession(session);
1689 }
1690 }
1691
1692 protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role,
1693 String uuid, long companyId, OrderByComparator orderByComparator,
1694 boolean previous) {
1695 StringBundler query = null;
1696
1697 if (orderByComparator != null) {
1698 query = new StringBundler(6 +
1699 (orderByComparator.getOrderByFields().length * 6));
1700 }
1701 else {
1702 query = new StringBundler(3);
1703 }
1704
1705 if (getDB().isSupportsInlineDistinct()) {
1706 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1707 }
1708 else {
1709 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1710 }
1711
1712 boolean bindUuid = false;
1713
1714 if (uuid == null) {
1715 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1716 }
1717 else if (uuid.equals(StringPool.BLANK)) {
1718 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1719 }
1720 else {
1721 bindUuid = true;
1722
1723 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1724 }
1725
1726 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1727
1728 if (!getDB().isSupportsInlineDistinct()) {
1729 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1730 }
1731
1732 if (orderByComparator != null) {
1733 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1734
1735 if (orderByConditionFields.length > 0) {
1736 query.append(WHERE_AND);
1737 }
1738
1739 for (int i = 0; i < orderByConditionFields.length; i++) {
1740 if (getDB().isSupportsInlineDistinct()) {
1741 query.append(_ORDER_BY_ENTITY_ALIAS);
1742 }
1743 else {
1744 query.append(_ORDER_BY_ENTITY_TABLE);
1745 }
1746
1747 query.append(orderByConditionFields[i]);
1748
1749 if ((i + 1) < orderByConditionFields.length) {
1750 if (orderByComparator.isAscending() ^ previous) {
1751 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1752 }
1753 else {
1754 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1755 }
1756 }
1757 else {
1758 if (orderByComparator.isAscending() ^ previous) {
1759 query.append(WHERE_GREATER_THAN);
1760 }
1761 else {
1762 query.append(WHERE_LESSER_THAN);
1763 }
1764 }
1765 }
1766
1767 query.append(ORDER_BY_CLAUSE);
1768
1769 String[] orderByFields = orderByComparator.getOrderByFields();
1770
1771 for (int i = 0; i < orderByFields.length; i++) {
1772 if (getDB().isSupportsInlineDistinct()) {
1773 query.append(_ORDER_BY_ENTITY_ALIAS);
1774 }
1775 else {
1776 query.append(_ORDER_BY_ENTITY_TABLE);
1777 }
1778
1779 query.append(orderByFields[i]);
1780
1781 if ((i + 1) < orderByFields.length) {
1782 if (orderByComparator.isAscending() ^ previous) {
1783 query.append(ORDER_BY_ASC_HAS_NEXT);
1784 }
1785 else {
1786 query.append(ORDER_BY_DESC_HAS_NEXT);
1787 }
1788 }
1789 else {
1790 if (orderByComparator.isAscending() ^ previous) {
1791 query.append(ORDER_BY_ASC);
1792 }
1793 else {
1794 query.append(ORDER_BY_DESC);
1795 }
1796 }
1797 }
1798 }
1799 else {
1800 if (getDB().isSupportsInlineDistinct()) {
1801 query.append(RoleModelImpl.ORDER_BY_JPQL);
1802 }
1803 else {
1804 query.append(RoleModelImpl.ORDER_BY_SQL);
1805 }
1806 }
1807
1808 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1809 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1810
1811 SQLQuery q = session.createSQLQuery(sql);
1812
1813 q.setFirstResult(0);
1814 q.setMaxResults(2);
1815
1816 if (getDB().isSupportsInlineDistinct()) {
1817 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1818 }
1819 else {
1820 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1821 }
1822
1823 QueryPos qPos = QueryPos.getInstance(q);
1824
1825 if (bindUuid) {
1826 qPos.add(uuid);
1827 }
1828
1829 qPos.add(companyId);
1830
1831 if (orderByComparator != null) {
1832 Object[] values = orderByComparator.getOrderByConditionValues(role);
1833
1834 for (Object value : values) {
1835 qPos.add(value);
1836 }
1837 }
1838
1839 List<Role> list = q.list();
1840
1841 if (list.size() == 2) {
1842 return list.get(1);
1843 }
1844 else {
1845 return null;
1846 }
1847 }
1848
1849
1856 @Override
1857 public void removeByUuid_C(String uuid, long companyId)
1858 throws SystemException {
1859 for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1860 QueryUtil.ALL_POS, null)) {
1861 remove(role);
1862 }
1863 }
1864
1865
1873 @Override
1874 public int countByUuid_C(String uuid, long companyId)
1875 throws SystemException {
1876 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1877
1878 Object[] finderArgs = new Object[] { uuid, companyId };
1879
1880 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1881 this);
1882
1883 if (count == null) {
1884 StringBundler query = new StringBundler(3);
1885
1886 query.append(_SQL_COUNT_ROLE_WHERE);
1887
1888 boolean bindUuid = false;
1889
1890 if (uuid == null) {
1891 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1892 }
1893 else if (uuid.equals(StringPool.BLANK)) {
1894 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1895 }
1896 else {
1897 bindUuid = true;
1898
1899 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1900 }
1901
1902 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1903
1904 String sql = query.toString();
1905
1906 Session session = null;
1907
1908 try {
1909 session = openSession();
1910
1911 Query q = session.createQuery(sql);
1912
1913 QueryPos qPos = QueryPos.getInstance(q);
1914
1915 if (bindUuid) {
1916 qPos.add(uuid);
1917 }
1918
1919 qPos.add(companyId);
1920
1921 count = (Long)q.uniqueResult();
1922
1923 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1924 }
1925 catch (Exception e) {
1926 FinderCacheUtil.removeResult(finderPath, finderArgs);
1927
1928 throw processException(e);
1929 }
1930 finally {
1931 closeSession(session);
1932 }
1933 }
1934
1935 return count.intValue();
1936 }
1937
1938
1946 @Override
1947 public int filterCountByUuid_C(String uuid, long companyId)
1948 throws SystemException {
1949 if (!InlineSQLHelperUtil.isEnabled()) {
1950 return countByUuid_C(uuid, companyId);
1951 }
1952
1953 StringBundler query = new StringBundler(3);
1954
1955 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1956
1957 boolean bindUuid = false;
1958
1959 if (uuid == null) {
1960 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1961 }
1962 else if (uuid.equals(StringPool.BLANK)) {
1963 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1964 }
1965 else {
1966 bindUuid = true;
1967
1968 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1969 }
1970
1971 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1972
1973 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1974 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1975
1976 Session session = null;
1977
1978 try {
1979 session = openSession();
1980
1981 SQLQuery q = session.createSQLQuery(sql);
1982
1983 q.addScalar(COUNT_COLUMN_NAME,
1984 com.liferay.portal.kernel.dao.orm.Type.LONG);
1985
1986 QueryPos qPos = QueryPos.getInstance(q);
1987
1988 if (bindUuid) {
1989 qPos.add(uuid);
1990 }
1991
1992 qPos.add(companyId);
1993
1994 Long count = (Long)q.uniqueResult();
1995
1996 return count.intValue();
1997 }
1998 catch (Exception e) {
1999 throw processException(e);
2000 }
2001 finally {
2002 closeSession(session);
2003 }
2004 }
2005
2006 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND ";
2007 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND ";
2008 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND ";
2009 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND ";
2010 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND ";
2011 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND ";
2012 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?";
2013 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2014 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2015 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2016 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2017 new String[] {
2018 Long.class.getName(),
2019
2020 Integer.class.getName(), Integer.class.getName(),
2021 OrderByComparator.class.getName()
2022 });
2023 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2024 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2025 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2026 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2027 new String[] { Long.class.getName() },
2028 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
2029 RoleModelImpl.NAME_COLUMN_BITMASK);
2030 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2031 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2032 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2033 new String[] { Long.class.getName() });
2034
2035
2042 @Override
2043 public List<Role> findByCompanyId(long companyId) throws SystemException {
2044 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2045 null);
2046 }
2047
2048
2061 @Override
2062 public List<Role> findByCompanyId(long companyId, int start, int end)
2063 throws SystemException {
2064 return findByCompanyId(companyId, start, end, null);
2065 }
2066
2067
2081 @Override
2082 public List<Role> findByCompanyId(long companyId, int start, int end,
2083 OrderByComparator orderByComparator) throws SystemException {
2084 boolean pagination = true;
2085 FinderPath finderPath = null;
2086 Object[] finderArgs = null;
2087
2088 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2089 (orderByComparator == null)) {
2090 pagination = false;
2091 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2092 finderArgs = new Object[] { companyId };
2093 }
2094 else {
2095 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2096 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2097 }
2098
2099 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2100 finderArgs, this);
2101
2102 if ((list != null) && !list.isEmpty()) {
2103 for (Role role : list) {
2104 if ((companyId != role.getCompanyId())) {
2105 list = null;
2106
2107 break;
2108 }
2109 }
2110 }
2111
2112 if (list == null) {
2113 StringBundler query = null;
2114
2115 if (orderByComparator != null) {
2116 query = new StringBundler(3 +
2117 (orderByComparator.getOrderByFields().length * 3));
2118 }
2119 else {
2120 query = new StringBundler(3);
2121 }
2122
2123 query.append(_SQL_SELECT_ROLE_WHERE);
2124
2125 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2126
2127 if (orderByComparator != null) {
2128 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2129 orderByComparator);
2130 }
2131 else
2132 if (pagination) {
2133 query.append(RoleModelImpl.ORDER_BY_JPQL);
2134 }
2135
2136 String sql = query.toString();
2137
2138 Session session = null;
2139
2140 try {
2141 session = openSession();
2142
2143 Query q = session.createQuery(sql);
2144
2145 QueryPos qPos = QueryPos.getInstance(q);
2146
2147 qPos.add(companyId);
2148
2149 if (!pagination) {
2150 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2151 end, false);
2152
2153 Collections.sort(list);
2154
2155 list = new UnmodifiableList<Role>(list);
2156 }
2157 else {
2158 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2159 end);
2160 }
2161
2162 cacheResult(list);
2163
2164 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2165 }
2166 catch (Exception e) {
2167 FinderCacheUtil.removeResult(finderPath, finderArgs);
2168
2169 throw processException(e);
2170 }
2171 finally {
2172 closeSession(session);
2173 }
2174 }
2175
2176 return list;
2177 }
2178
2179
2188 @Override
2189 public Role findByCompanyId_First(long companyId,
2190 OrderByComparator orderByComparator)
2191 throws NoSuchRoleException, SystemException {
2192 Role role = fetchByCompanyId_First(companyId, orderByComparator);
2193
2194 if (role != null) {
2195 return role;
2196 }
2197
2198 StringBundler msg = new StringBundler(4);
2199
2200 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2201
2202 msg.append("companyId=");
2203 msg.append(companyId);
2204
2205 msg.append(StringPool.CLOSE_CURLY_BRACE);
2206
2207 throw new NoSuchRoleException(msg.toString());
2208 }
2209
2210
2218 @Override
2219 public Role fetchByCompanyId_First(long companyId,
2220 OrderByComparator orderByComparator) throws SystemException {
2221 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2222
2223 if (!list.isEmpty()) {
2224 return list.get(0);
2225 }
2226
2227 return null;
2228 }
2229
2230
2239 @Override
2240 public Role findByCompanyId_Last(long companyId,
2241 OrderByComparator orderByComparator)
2242 throws NoSuchRoleException, SystemException {
2243 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
2244
2245 if (role != null) {
2246 return role;
2247 }
2248
2249 StringBundler msg = new StringBundler(4);
2250
2251 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2252
2253 msg.append("companyId=");
2254 msg.append(companyId);
2255
2256 msg.append(StringPool.CLOSE_CURLY_BRACE);
2257
2258 throw new NoSuchRoleException(msg.toString());
2259 }
2260
2261
2269 @Override
2270 public Role fetchByCompanyId_Last(long companyId,
2271 OrderByComparator orderByComparator) throws SystemException {
2272 int count = countByCompanyId(companyId);
2273
2274 if (count == 0) {
2275 return null;
2276 }
2277
2278 List<Role> list = findByCompanyId(companyId, count - 1, count,
2279 orderByComparator);
2280
2281 if (!list.isEmpty()) {
2282 return list.get(0);
2283 }
2284
2285 return null;
2286 }
2287
2288
2298 @Override
2299 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
2300 OrderByComparator orderByComparator)
2301 throws NoSuchRoleException, SystemException {
2302 Role role = findByPrimaryKey(roleId);
2303
2304 Session session = null;
2305
2306 try {
2307 session = openSession();
2308
2309 Role[] array = new RoleImpl[3];
2310
2311 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
2312 orderByComparator, true);
2313
2314 array[1] = role;
2315
2316 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
2317 orderByComparator, false);
2318
2319 return array;
2320 }
2321 catch (Exception e) {
2322 throw processException(e);
2323 }
2324 finally {
2325 closeSession(session);
2326 }
2327 }
2328
2329 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
2330 long companyId, OrderByComparator orderByComparator, boolean previous) {
2331 StringBundler query = null;
2332
2333 if (orderByComparator != null) {
2334 query = new StringBundler(6 +
2335 (orderByComparator.getOrderByFields().length * 6));
2336 }
2337 else {
2338 query = new StringBundler(3);
2339 }
2340
2341 query.append(_SQL_SELECT_ROLE_WHERE);
2342
2343 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2344
2345 if (orderByComparator != null) {
2346 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2347
2348 if (orderByConditionFields.length > 0) {
2349 query.append(WHERE_AND);
2350 }
2351
2352 for (int i = 0; i < orderByConditionFields.length; i++) {
2353 query.append(_ORDER_BY_ENTITY_ALIAS);
2354 query.append(orderByConditionFields[i]);
2355
2356 if ((i + 1) < orderByConditionFields.length) {
2357 if (orderByComparator.isAscending() ^ previous) {
2358 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2359 }
2360 else {
2361 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2362 }
2363 }
2364 else {
2365 if (orderByComparator.isAscending() ^ previous) {
2366 query.append(WHERE_GREATER_THAN);
2367 }
2368 else {
2369 query.append(WHERE_LESSER_THAN);
2370 }
2371 }
2372 }
2373
2374 query.append(ORDER_BY_CLAUSE);
2375
2376 String[] orderByFields = orderByComparator.getOrderByFields();
2377
2378 for (int i = 0; i < orderByFields.length; i++) {
2379 query.append(_ORDER_BY_ENTITY_ALIAS);
2380 query.append(orderByFields[i]);
2381
2382 if ((i + 1) < orderByFields.length) {
2383 if (orderByComparator.isAscending() ^ previous) {
2384 query.append(ORDER_BY_ASC_HAS_NEXT);
2385 }
2386 else {
2387 query.append(ORDER_BY_DESC_HAS_NEXT);
2388 }
2389 }
2390 else {
2391 if (orderByComparator.isAscending() ^ previous) {
2392 query.append(ORDER_BY_ASC);
2393 }
2394 else {
2395 query.append(ORDER_BY_DESC);
2396 }
2397 }
2398 }
2399 }
2400 else {
2401 query.append(RoleModelImpl.ORDER_BY_JPQL);
2402 }
2403
2404 String sql = query.toString();
2405
2406 Query q = session.createQuery(sql);
2407
2408 q.setFirstResult(0);
2409 q.setMaxResults(2);
2410
2411 QueryPos qPos = QueryPos.getInstance(q);
2412
2413 qPos.add(companyId);
2414
2415 if (orderByComparator != null) {
2416 Object[] values = orderByComparator.getOrderByConditionValues(role);
2417
2418 for (Object value : values) {
2419 qPos.add(value);
2420 }
2421 }
2422
2423 List<Role> list = q.list();
2424
2425 if (list.size() == 2) {
2426 return list.get(1);
2427 }
2428 else {
2429 return null;
2430 }
2431 }
2432
2433
2440 @Override
2441 public List<Role> filterFindByCompanyId(long companyId)
2442 throws SystemException {
2443 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2444 QueryUtil.ALL_POS, null);
2445 }
2446
2447
2460 @Override
2461 public List<Role> filterFindByCompanyId(long companyId, int start, int end)
2462 throws SystemException {
2463 return filterFindByCompanyId(companyId, start, end, null);
2464 }
2465
2466
2480 @Override
2481 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
2482 OrderByComparator orderByComparator) throws SystemException {
2483 if (!InlineSQLHelperUtil.isEnabled()) {
2484 return findByCompanyId(companyId, start, end, orderByComparator);
2485 }
2486
2487 StringBundler query = null;
2488
2489 if (orderByComparator != null) {
2490 query = new StringBundler(3 +
2491 (orderByComparator.getOrderByFields().length * 3));
2492 }
2493 else {
2494 query = new StringBundler(3);
2495 }
2496
2497 if (getDB().isSupportsInlineDistinct()) {
2498 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2499 }
2500 else {
2501 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2502 }
2503
2504 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2505
2506 if (!getDB().isSupportsInlineDistinct()) {
2507 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2508 }
2509
2510 if (orderByComparator != null) {
2511 if (getDB().isSupportsInlineDistinct()) {
2512 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2513 orderByComparator, true);
2514 }
2515 else {
2516 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2517 orderByComparator, true);
2518 }
2519 }
2520 else {
2521 if (getDB().isSupportsInlineDistinct()) {
2522 query.append(RoleModelImpl.ORDER_BY_JPQL);
2523 }
2524 else {
2525 query.append(RoleModelImpl.ORDER_BY_SQL);
2526 }
2527 }
2528
2529 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2530 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2531
2532 Session session = null;
2533
2534 try {
2535 session = openSession();
2536
2537 SQLQuery q = session.createSQLQuery(sql);
2538
2539 if (getDB().isSupportsInlineDistinct()) {
2540 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2541 }
2542 else {
2543 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2544 }
2545
2546 QueryPos qPos = QueryPos.getInstance(q);
2547
2548 qPos.add(companyId);
2549
2550 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2551 }
2552 catch (Exception e) {
2553 throw processException(e);
2554 }
2555 finally {
2556 closeSession(session);
2557 }
2558 }
2559
2560
2570 @Override
2571 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
2572 long companyId, OrderByComparator orderByComparator)
2573 throws NoSuchRoleException, SystemException {
2574 if (!InlineSQLHelperUtil.isEnabled()) {
2575 return findByCompanyId_PrevAndNext(roleId, companyId,
2576 orderByComparator);
2577 }
2578
2579 Role role = findByPrimaryKey(roleId);
2580
2581 Session session = null;
2582
2583 try {
2584 session = openSession();
2585
2586 Role[] array = new RoleImpl[3];
2587
2588 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
2589 companyId, orderByComparator, true);
2590
2591 array[1] = role;
2592
2593 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
2594 companyId, orderByComparator, false);
2595
2596 return array;
2597 }
2598 catch (Exception e) {
2599 throw processException(e);
2600 }
2601 finally {
2602 closeSession(session);
2603 }
2604 }
2605
2606 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
2607 long companyId, OrderByComparator orderByComparator, boolean previous) {
2608 StringBundler query = null;
2609
2610 if (orderByComparator != null) {
2611 query = new StringBundler(6 +
2612 (orderByComparator.getOrderByFields().length * 6));
2613 }
2614 else {
2615 query = new StringBundler(3);
2616 }
2617
2618 if (getDB().isSupportsInlineDistinct()) {
2619 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2620 }
2621 else {
2622 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2623 }
2624
2625 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2626
2627 if (!getDB().isSupportsInlineDistinct()) {
2628 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2629 }
2630
2631 if (orderByComparator != null) {
2632 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2633
2634 if (orderByConditionFields.length > 0) {
2635 query.append(WHERE_AND);
2636 }
2637
2638 for (int i = 0; i < orderByConditionFields.length; i++) {
2639 if (getDB().isSupportsInlineDistinct()) {
2640 query.append(_ORDER_BY_ENTITY_ALIAS);
2641 }
2642 else {
2643 query.append(_ORDER_BY_ENTITY_TABLE);
2644 }
2645
2646 query.append(orderByConditionFields[i]);
2647
2648 if ((i + 1) < orderByConditionFields.length) {
2649 if (orderByComparator.isAscending() ^ previous) {
2650 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2651 }
2652 else {
2653 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2654 }
2655 }
2656 else {
2657 if (orderByComparator.isAscending() ^ previous) {
2658 query.append(WHERE_GREATER_THAN);
2659 }
2660 else {
2661 query.append(WHERE_LESSER_THAN);
2662 }
2663 }
2664 }
2665
2666 query.append(ORDER_BY_CLAUSE);
2667
2668 String[] orderByFields = orderByComparator.getOrderByFields();
2669
2670 for (int i = 0; i < orderByFields.length; i++) {
2671 if (getDB().isSupportsInlineDistinct()) {
2672 query.append(_ORDER_BY_ENTITY_ALIAS);
2673 }
2674 else {
2675 query.append(_ORDER_BY_ENTITY_TABLE);
2676 }
2677
2678 query.append(orderByFields[i]);
2679
2680 if ((i + 1) < orderByFields.length) {
2681 if (orderByComparator.isAscending() ^ previous) {
2682 query.append(ORDER_BY_ASC_HAS_NEXT);
2683 }
2684 else {
2685 query.append(ORDER_BY_DESC_HAS_NEXT);
2686 }
2687 }
2688 else {
2689 if (orderByComparator.isAscending() ^ previous) {
2690 query.append(ORDER_BY_ASC);
2691 }
2692 else {
2693 query.append(ORDER_BY_DESC);
2694 }
2695 }
2696 }
2697 }
2698 else {
2699 if (getDB().isSupportsInlineDistinct()) {
2700 query.append(RoleModelImpl.ORDER_BY_JPQL);
2701 }
2702 else {
2703 query.append(RoleModelImpl.ORDER_BY_SQL);
2704 }
2705 }
2706
2707 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2708 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2709
2710 SQLQuery q = session.createSQLQuery(sql);
2711
2712 q.setFirstResult(0);
2713 q.setMaxResults(2);
2714
2715 if (getDB().isSupportsInlineDistinct()) {
2716 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2717 }
2718 else {
2719 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2720 }
2721
2722 QueryPos qPos = QueryPos.getInstance(q);
2723
2724 qPos.add(companyId);
2725
2726 if (orderByComparator != null) {
2727 Object[] values = orderByComparator.getOrderByConditionValues(role);
2728
2729 for (Object value : values) {
2730 qPos.add(value);
2731 }
2732 }
2733
2734 List<Role> list = q.list();
2735
2736 if (list.size() == 2) {
2737 return list.get(1);
2738 }
2739 else {
2740 return null;
2741 }
2742 }
2743
2744
2750 @Override
2751 public void removeByCompanyId(long companyId) throws SystemException {
2752 for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
2753 QueryUtil.ALL_POS, null)) {
2754 remove(role);
2755 }
2756 }
2757
2758
2765 @Override
2766 public int countByCompanyId(long companyId) throws SystemException {
2767 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2768
2769 Object[] finderArgs = new Object[] { companyId };
2770
2771 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2772 this);
2773
2774 if (count == null) {
2775 StringBundler query = new StringBundler(2);
2776
2777 query.append(_SQL_COUNT_ROLE_WHERE);
2778
2779 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2780
2781 String sql = query.toString();
2782
2783 Session session = null;
2784
2785 try {
2786 session = openSession();
2787
2788 Query q = session.createQuery(sql);
2789
2790 QueryPos qPos = QueryPos.getInstance(q);
2791
2792 qPos.add(companyId);
2793
2794 count = (Long)q.uniqueResult();
2795
2796 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2797 }
2798 catch (Exception e) {
2799 FinderCacheUtil.removeResult(finderPath, finderArgs);
2800
2801 throw processException(e);
2802 }
2803 finally {
2804 closeSession(session);
2805 }
2806 }
2807
2808 return count.intValue();
2809 }
2810
2811
2818 @Override
2819 public int filterCountByCompanyId(long companyId) throws SystemException {
2820 if (!InlineSQLHelperUtil.isEnabled()) {
2821 return countByCompanyId(companyId);
2822 }
2823
2824 StringBundler query = new StringBundler(2);
2825
2826 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2827
2828 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2829
2830 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2831 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2832
2833 Session session = null;
2834
2835 try {
2836 session = openSession();
2837
2838 SQLQuery q = session.createSQLQuery(sql);
2839
2840 q.addScalar(COUNT_COLUMN_NAME,
2841 com.liferay.portal.kernel.dao.orm.Type.LONG);
2842
2843 QueryPos qPos = QueryPos.getInstance(q);
2844
2845 qPos.add(companyId);
2846
2847 Long count = (Long)q.uniqueResult();
2848
2849 return count.intValue();
2850 }
2851 catch (Exception e) {
2852 throw processException(e);
2853 }
2854 finally {
2855 closeSession(session);
2856 }
2857 }
2858
2859 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
2860 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2861 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2862 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
2863 new String[] {
2864 String.class.getName(),
2865
2866 Integer.class.getName(), Integer.class.getName(),
2867 OrderByComparator.class.getName()
2868 });
2869 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2870 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2871 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
2872 new String[] { String.class.getName() },
2873 RoleModelImpl.NAME_COLUMN_BITMASK);
2874 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2875 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2876 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
2877 new String[] { String.class.getName() });
2878
2879
2886 @Override
2887 public List<Role> findByName(String name) throws SystemException {
2888 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2889 }
2890
2891
2904 @Override
2905 public List<Role> findByName(String name, int start, int end)
2906 throws SystemException {
2907 return findByName(name, start, end, null);
2908 }
2909
2910
2924 @Override
2925 public List<Role> findByName(String name, int start, int end,
2926 OrderByComparator orderByComparator) throws SystemException {
2927 boolean pagination = true;
2928 FinderPath finderPath = null;
2929 Object[] finderArgs = null;
2930
2931 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2932 (orderByComparator == null)) {
2933 pagination = false;
2934 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
2935 finderArgs = new Object[] { name };
2936 }
2937 else {
2938 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
2939 finderArgs = new Object[] { name, start, end, orderByComparator };
2940 }
2941
2942 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2943 finderArgs, this);
2944
2945 if ((list != null) && !list.isEmpty()) {
2946 for (Role role : list) {
2947 if (!Validator.equals(name, role.getName())) {
2948 list = null;
2949
2950 break;
2951 }
2952 }
2953 }
2954
2955 if (list == null) {
2956 StringBundler query = null;
2957
2958 if (orderByComparator != null) {
2959 query = new StringBundler(3 +
2960 (orderByComparator.getOrderByFields().length * 3));
2961 }
2962 else {
2963 query = new StringBundler(3);
2964 }
2965
2966 query.append(_SQL_SELECT_ROLE_WHERE);
2967
2968 boolean bindName = false;
2969
2970 if (name == null) {
2971 query.append(_FINDER_COLUMN_NAME_NAME_1);
2972 }
2973 else if (name.equals(StringPool.BLANK)) {
2974 query.append(_FINDER_COLUMN_NAME_NAME_3);
2975 }
2976 else {
2977 bindName = true;
2978
2979 query.append(_FINDER_COLUMN_NAME_NAME_2);
2980 }
2981
2982 if (orderByComparator != null) {
2983 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2984 orderByComparator);
2985 }
2986 else
2987 if (pagination) {
2988 query.append(RoleModelImpl.ORDER_BY_JPQL);
2989 }
2990
2991 String sql = query.toString();
2992
2993 Session session = null;
2994
2995 try {
2996 session = openSession();
2997
2998 Query q = session.createQuery(sql);
2999
3000 QueryPos qPos = QueryPos.getInstance(q);
3001
3002 if (bindName) {
3003 qPos.add(name);
3004 }
3005
3006 if (!pagination) {
3007 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3008 end, false);
3009
3010 Collections.sort(list);
3011
3012 list = new UnmodifiableList<Role>(list);
3013 }
3014 else {
3015 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3016 end);
3017 }
3018
3019 cacheResult(list);
3020
3021 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3022 }
3023 catch (Exception e) {
3024 FinderCacheUtil.removeResult(finderPath, finderArgs);
3025
3026 throw processException(e);
3027 }
3028 finally {
3029 closeSession(session);
3030 }
3031 }
3032
3033 return list;
3034 }
3035
3036
3045 @Override
3046 public Role findByName_First(String name,
3047 OrderByComparator orderByComparator)
3048 throws NoSuchRoleException, SystemException {
3049 Role role = fetchByName_First(name, orderByComparator);
3050
3051 if (role != null) {
3052 return role;
3053 }
3054
3055 StringBundler msg = new StringBundler(4);
3056
3057 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3058
3059 msg.append("name=");
3060 msg.append(name);
3061
3062 msg.append(StringPool.CLOSE_CURLY_BRACE);
3063
3064 throw new NoSuchRoleException(msg.toString());
3065 }
3066
3067
3075 @Override
3076 public Role fetchByName_First(String name,
3077 OrderByComparator orderByComparator) throws SystemException {
3078 List<Role> list = findByName(name, 0, 1, orderByComparator);
3079
3080 if (!list.isEmpty()) {
3081 return list.get(0);
3082 }
3083
3084 return null;
3085 }
3086
3087
3096 @Override
3097 public Role findByName_Last(String name, OrderByComparator orderByComparator)
3098 throws NoSuchRoleException, SystemException {
3099 Role role = fetchByName_Last(name, orderByComparator);
3100
3101 if (role != null) {
3102 return role;
3103 }
3104
3105 StringBundler msg = new StringBundler(4);
3106
3107 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3108
3109 msg.append("name=");
3110 msg.append(name);
3111
3112 msg.append(StringPool.CLOSE_CURLY_BRACE);
3113
3114 throw new NoSuchRoleException(msg.toString());
3115 }
3116
3117
3125 @Override
3126 public Role fetchByName_Last(String name,
3127 OrderByComparator orderByComparator) throws SystemException {
3128 int count = countByName(name);
3129
3130 if (count == 0) {
3131 return null;
3132 }
3133
3134 List<Role> list = findByName(name, count - 1, count, orderByComparator);
3135
3136 if (!list.isEmpty()) {
3137 return list.get(0);
3138 }
3139
3140 return null;
3141 }
3142
3143
3153 @Override
3154 public Role[] findByName_PrevAndNext(long roleId, String name,
3155 OrderByComparator orderByComparator)
3156 throws NoSuchRoleException, SystemException {
3157 Role role = findByPrimaryKey(roleId);
3158
3159 Session session = null;
3160
3161 try {
3162 session = openSession();
3163
3164 Role[] array = new RoleImpl[3];
3165
3166 array[0] = getByName_PrevAndNext(session, role, name,
3167 orderByComparator, true);
3168
3169 array[1] = role;
3170
3171 array[2] = getByName_PrevAndNext(session, role, name,
3172 orderByComparator, false);
3173
3174 return array;
3175 }
3176 catch (Exception e) {
3177 throw processException(e);
3178 }
3179 finally {
3180 closeSession(session);
3181 }
3182 }
3183
3184 protected Role getByName_PrevAndNext(Session session, Role role,
3185 String name, OrderByComparator orderByComparator, boolean previous) {
3186 StringBundler query = null;
3187
3188 if (orderByComparator != null) {
3189 query = new StringBundler(6 +
3190 (orderByComparator.getOrderByFields().length * 6));
3191 }
3192 else {
3193 query = new StringBundler(3);
3194 }
3195
3196 query.append(_SQL_SELECT_ROLE_WHERE);
3197
3198 boolean bindName = false;
3199
3200 if (name == null) {
3201 query.append(_FINDER_COLUMN_NAME_NAME_1);
3202 }
3203 else if (name.equals(StringPool.BLANK)) {
3204 query.append(_FINDER_COLUMN_NAME_NAME_3);
3205 }
3206 else {
3207 bindName = true;
3208
3209 query.append(_FINDER_COLUMN_NAME_NAME_2);
3210 }
3211
3212 if (orderByComparator != null) {
3213 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3214
3215 if (orderByConditionFields.length > 0) {
3216 query.append(WHERE_AND);
3217 }
3218
3219 for (int i = 0; i < orderByConditionFields.length; i++) {
3220 query.append(_ORDER_BY_ENTITY_ALIAS);
3221 query.append(orderByConditionFields[i]);
3222
3223 if ((i + 1) < orderByConditionFields.length) {
3224 if (orderByComparator.isAscending() ^ previous) {
3225 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3226 }
3227 else {
3228 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3229 }
3230 }
3231 else {
3232 if (orderByComparator.isAscending() ^ previous) {
3233 query.append(WHERE_GREATER_THAN);
3234 }
3235 else {
3236 query.append(WHERE_LESSER_THAN);
3237 }
3238 }
3239 }
3240
3241 query.append(ORDER_BY_CLAUSE);
3242
3243 String[] orderByFields = orderByComparator.getOrderByFields();
3244
3245 for (int i = 0; i < orderByFields.length; i++) {
3246 query.append(_ORDER_BY_ENTITY_ALIAS);
3247 query.append(orderByFields[i]);
3248
3249 if ((i + 1) < orderByFields.length) {
3250 if (orderByComparator.isAscending() ^ previous) {
3251 query.append(ORDER_BY_ASC_HAS_NEXT);
3252 }
3253 else {
3254 query.append(ORDER_BY_DESC_HAS_NEXT);
3255 }
3256 }
3257 else {
3258 if (orderByComparator.isAscending() ^ previous) {
3259 query.append(ORDER_BY_ASC);
3260 }
3261 else {
3262 query.append(ORDER_BY_DESC);
3263 }
3264 }
3265 }
3266 }
3267 else {
3268 query.append(RoleModelImpl.ORDER_BY_JPQL);
3269 }
3270
3271 String sql = query.toString();
3272
3273 Query q = session.createQuery(sql);
3274
3275 q.setFirstResult(0);
3276 q.setMaxResults(2);
3277
3278 QueryPos qPos = QueryPos.getInstance(q);
3279
3280 if (bindName) {
3281 qPos.add(name);
3282 }
3283
3284 if (orderByComparator != null) {
3285 Object[] values = orderByComparator.getOrderByConditionValues(role);
3286
3287 for (Object value : values) {
3288 qPos.add(value);
3289 }
3290 }
3291
3292 List<Role> list = q.list();
3293
3294 if (list.size() == 2) {
3295 return list.get(1);
3296 }
3297 else {
3298 return null;
3299 }
3300 }
3301
3302
3309 @Override
3310 public List<Role> filterFindByName(String name) throws SystemException {
3311 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3312 }
3313
3314
3327 @Override
3328 public List<Role> filterFindByName(String name, int start, int end)
3329 throws SystemException {
3330 return filterFindByName(name, start, end, null);
3331 }
3332
3333
3347 @Override
3348 public List<Role> filterFindByName(String name, int start, int end,
3349 OrderByComparator orderByComparator) throws SystemException {
3350 if (!InlineSQLHelperUtil.isEnabled()) {
3351 return findByName(name, start, end, orderByComparator);
3352 }
3353
3354 StringBundler query = null;
3355
3356 if (orderByComparator != null) {
3357 query = new StringBundler(3 +
3358 (orderByComparator.getOrderByFields().length * 3));
3359 }
3360 else {
3361 query = new StringBundler(3);
3362 }
3363
3364 if (getDB().isSupportsInlineDistinct()) {
3365 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3366 }
3367 else {
3368 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3369 }
3370
3371 boolean bindName = false;
3372
3373 if (name == null) {
3374 query.append(_FINDER_COLUMN_NAME_NAME_1);
3375 }
3376 else if (name.equals(StringPool.BLANK)) {
3377 query.append(_FINDER_COLUMN_NAME_NAME_3);
3378 }
3379 else {
3380 bindName = true;
3381
3382 query.append(_FINDER_COLUMN_NAME_NAME_2);
3383 }
3384
3385 if (!getDB().isSupportsInlineDistinct()) {
3386 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3387 }
3388
3389 if (orderByComparator != null) {
3390 if (getDB().isSupportsInlineDistinct()) {
3391 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3392 orderByComparator, true);
3393 }
3394 else {
3395 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3396 orderByComparator, true);
3397 }
3398 }
3399 else {
3400 if (getDB().isSupportsInlineDistinct()) {
3401 query.append(RoleModelImpl.ORDER_BY_JPQL);
3402 }
3403 else {
3404 query.append(RoleModelImpl.ORDER_BY_SQL);
3405 }
3406 }
3407
3408 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3409 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3410
3411 Session session = null;
3412
3413 try {
3414 session = openSession();
3415
3416 SQLQuery q = session.createSQLQuery(sql);
3417
3418 if (getDB().isSupportsInlineDistinct()) {
3419 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3420 }
3421 else {
3422 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3423 }
3424
3425 QueryPos qPos = QueryPos.getInstance(q);
3426
3427 if (bindName) {
3428 qPos.add(name);
3429 }
3430
3431 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3432 }
3433 catch (Exception e) {
3434 throw processException(e);
3435 }
3436 finally {
3437 closeSession(session);
3438 }
3439 }
3440
3441
3451 @Override
3452 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
3453 OrderByComparator orderByComparator)
3454 throws NoSuchRoleException, SystemException {
3455 if (!InlineSQLHelperUtil.isEnabled()) {
3456 return findByName_PrevAndNext(roleId, name, orderByComparator);
3457 }
3458
3459 Role role = findByPrimaryKey(roleId);
3460
3461 Session session = null;
3462
3463 try {
3464 session = openSession();
3465
3466 Role[] array = new RoleImpl[3];
3467
3468 array[0] = filterGetByName_PrevAndNext(session, role, name,
3469 orderByComparator, true);
3470
3471 array[1] = role;
3472
3473 array[2] = filterGetByName_PrevAndNext(session, role, name,
3474 orderByComparator, false);
3475
3476 return array;
3477 }
3478 catch (Exception e) {
3479 throw processException(e);
3480 }
3481 finally {
3482 closeSession(session);
3483 }
3484 }
3485
3486 protected Role filterGetByName_PrevAndNext(Session session, Role role,
3487 String name, OrderByComparator orderByComparator, boolean previous) {
3488 StringBundler query = null;
3489
3490 if (orderByComparator != null) {
3491 query = new StringBundler(6 +
3492 (orderByComparator.getOrderByFields().length * 6));
3493 }
3494 else {
3495 query = new StringBundler(3);
3496 }
3497
3498 if (getDB().isSupportsInlineDistinct()) {
3499 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3500 }
3501 else {
3502 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3503 }
3504
3505 boolean bindName = false;
3506
3507 if (name == null) {
3508 query.append(_FINDER_COLUMN_NAME_NAME_1);
3509 }
3510 else if (name.equals(StringPool.BLANK)) {
3511 query.append(_FINDER_COLUMN_NAME_NAME_3);
3512 }
3513 else {
3514 bindName = true;
3515
3516 query.append(_FINDER_COLUMN_NAME_NAME_2);
3517 }
3518
3519 if (!getDB().isSupportsInlineDistinct()) {
3520 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3521 }
3522
3523 if (orderByComparator != null) {
3524 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3525
3526 if (orderByConditionFields.length > 0) {
3527 query.append(WHERE_AND);
3528 }
3529
3530 for (int i = 0; i < orderByConditionFields.length; i++) {
3531 if (getDB().isSupportsInlineDistinct()) {
3532 query.append(_ORDER_BY_ENTITY_ALIAS);
3533 }
3534 else {
3535 query.append(_ORDER_BY_ENTITY_TABLE);
3536 }
3537
3538 query.append(orderByConditionFields[i]);
3539
3540 if ((i + 1) < orderByConditionFields.length) {
3541 if (orderByComparator.isAscending() ^ previous) {
3542 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3543 }
3544 else {
3545 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3546 }
3547 }
3548 else {
3549 if (orderByComparator.isAscending() ^ previous) {
3550 query.append(WHERE_GREATER_THAN);
3551 }
3552 else {
3553 query.append(WHERE_LESSER_THAN);
3554 }
3555 }
3556 }
3557
3558 query.append(ORDER_BY_CLAUSE);
3559
3560 String[] orderByFields = orderByComparator.getOrderByFields();
3561
3562 for (int i = 0; i < orderByFields.length; i++) {
3563 if (getDB().isSupportsInlineDistinct()) {
3564 query.append(_ORDER_BY_ENTITY_ALIAS);
3565 }
3566 else {
3567 query.append(_ORDER_BY_ENTITY_TABLE);
3568 }
3569
3570 query.append(orderByFields[i]);
3571
3572 if ((i + 1) < orderByFields.length) {
3573 if (orderByComparator.isAscending() ^ previous) {
3574 query.append(ORDER_BY_ASC_HAS_NEXT);
3575 }
3576 else {
3577 query.append(ORDER_BY_DESC_HAS_NEXT);
3578 }
3579 }
3580 else {
3581 if (orderByComparator.isAscending() ^ previous) {
3582 query.append(ORDER_BY_ASC);
3583 }
3584 else {
3585 query.append(ORDER_BY_DESC);
3586 }
3587 }
3588 }
3589 }
3590 else {
3591 if (getDB().isSupportsInlineDistinct()) {
3592 query.append(RoleModelImpl.ORDER_BY_JPQL);
3593 }
3594 else {
3595 query.append(RoleModelImpl.ORDER_BY_SQL);
3596 }
3597 }
3598
3599 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3600 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3601
3602 SQLQuery q = session.createSQLQuery(sql);
3603
3604 q.setFirstResult(0);
3605 q.setMaxResults(2);
3606
3607 if (getDB().isSupportsInlineDistinct()) {
3608 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3609 }
3610 else {
3611 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3612 }
3613
3614 QueryPos qPos = QueryPos.getInstance(q);
3615
3616 if (bindName) {
3617 qPos.add(name);
3618 }
3619
3620 if (orderByComparator != null) {
3621 Object[] values = orderByComparator.getOrderByConditionValues(role);
3622
3623 for (Object value : values) {
3624 qPos.add(value);
3625 }
3626 }
3627
3628 List<Role> list = q.list();
3629
3630 if (list.size() == 2) {
3631 return list.get(1);
3632 }
3633 else {
3634 return null;
3635 }
3636 }
3637
3638
3644 @Override
3645 public void removeByName(String name) throws SystemException {
3646 for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3647 null)) {
3648 remove(role);
3649 }
3650 }
3651
3652
3659 @Override
3660 public int countByName(String name) throws SystemException {
3661 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
3662
3663 Object[] finderArgs = new Object[] { name };
3664
3665 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3666 this);
3667
3668 if (count == null) {
3669 StringBundler query = new StringBundler(2);
3670
3671 query.append(_SQL_COUNT_ROLE_WHERE);
3672
3673 boolean bindName = false;
3674
3675 if (name == null) {
3676 query.append(_FINDER_COLUMN_NAME_NAME_1);
3677 }
3678 else if (name.equals(StringPool.BLANK)) {
3679 query.append(_FINDER_COLUMN_NAME_NAME_3);
3680 }
3681 else {
3682 bindName = true;
3683
3684 query.append(_FINDER_COLUMN_NAME_NAME_2);
3685 }
3686
3687 String sql = query.toString();
3688
3689 Session session = null;
3690
3691 try {
3692 session = openSession();
3693
3694 Query q = session.createQuery(sql);
3695
3696 QueryPos qPos = QueryPos.getInstance(q);
3697
3698 if (bindName) {
3699 qPos.add(name);
3700 }
3701
3702 count = (Long)q.uniqueResult();
3703
3704 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3705 }
3706 catch (Exception e) {
3707 FinderCacheUtil.removeResult(finderPath, finderArgs);
3708
3709 throw processException(e);
3710 }
3711 finally {
3712 closeSession(session);
3713 }
3714 }
3715
3716 return count.intValue();
3717 }
3718
3719
3726 @Override
3727 public int filterCountByName(String name) throws SystemException {
3728 if (!InlineSQLHelperUtil.isEnabled()) {
3729 return countByName(name);
3730 }
3731
3732 StringBundler query = new StringBundler(2);
3733
3734 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3735
3736 boolean bindName = false;
3737
3738 if (name == null) {
3739 query.append(_FINDER_COLUMN_NAME_NAME_1);
3740 }
3741 else if (name.equals(StringPool.BLANK)) {
3742 query.append(_FINDER_COLUMN_NAME_NAME_3);
3743 }
3744 else {
3745 bindName = true;
3746
3747 query.append(_FINDER_COLUMN_NAME_NAME_2);
3748 }
3749
3750 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3751 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3752
3753 Session session = null;
3754
3755 try {
3756 session = openSession();
3757
3758 SQLQuery q = session.createSQLQuery(sql);
3759
3760 q.addScalar(COUNT_COLUMN_NAME,
3761 com.liferay.portal.kernel.dao.orm.Type.LONG);
3762
3763 QueryPos qPos = QueryPos.getInstance(q);
3764
3765 if (bindName) {
3766 qPos.add(name);
3767 }
3768
3769 Long count = (Long)q.uniqueResult();
3770
3771 return count.intValue();
3772 }
3773 catch (Exception e) {
3774 throw processException(e);
3775 }
3776 finally {
3777 closeSession(session);
3778 }
3779 }
3780
3781 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
3782 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
3783 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')";
3784 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3785 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3786 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3787 new String[] {
3788 Integer.class.getName(),
3789
3790 Integer.class.getName(), Integer.class.getName(),
3791 OrderByComparator.class.getName()
3792 });
3793 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3794 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3795 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3796 new String[] { Integer.class.getName() },
3797 RoleModelImpl.TYPE_COLUMN_BITMASK |
3798 RoleModelImpl.NAME_COLUMN_BITMASK);
3799 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3800 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3801 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3802 new String[] { Integer.class.getName() });
3803
3804
3811 @Override
3812 public List<Role> findByType(int type) throws SystemException {
3813 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3814 }
3815
3816
3829 @Override
3830 public List<Role> findByType(int type, int start, int end)
3831 throws SystemException {
3832 return findByType(type, start, end, null);
3833 }
3834
3835
3849 @Override
3850 public List<Role> findByType(int type, int start, int end,
3851 OrderByComparator orderByComparator) throws SystemException {
3852 boolean pagination = true;
3853 FinderPath finderPath = null;
3854 Object[] finderArgs = null;
3855
3856 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3857 (orderByComparator == null)) {
3858 pagination = false;
3859 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3860 finderArgs = new Object[] { type };
3861 }
3862 else {
3863 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3864 finderArgs = new Object[] { type, start, end, orderByComparator };
3865 }
3866
3867 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
3868 finderArgs, this);
3869
3870 if ((list != null) && !list.isEmpty()) {
3871 for (Role role : list) {
3872 if ((type != role.getType())) {
3873 list = null;
3874
3875 break;
3876 }
3877 }
3878 }
3879
3880 if (list == null) {
3881 StringBundler query = null;
3882
3883 if (orderByComparator != null) {
3884 query = new StringBundler(3 +
3885 (orderByComparator.getOrderByFields().length * 3));
3886 }
3887 else {
3888 query = new StringBundler(3);
3889 }
3890
3891 query.append(_SQL_SELECT_ROLE_WHERE);
3892
3893 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3894
3895 if (orderByComparator != null) {
3896 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3897 orderByComparator);
3898 }
3899 else
3900 if (pagination) {
3901 query.append(RoleModelImpl.ORDER_BY_JPQL);
3902 }
3903
3904 String sql = query.toString();
3905
3906 Session session = null;
3907
3908 try {
3909 session = openSession();
3910
3911 Query q = session.createQuery(sql);
3912
3913 QueryPos qPos = QueryPos.getInstance(q);
3914
3915 qPos.add(type);
3916
3917 if (!pagination) {
3918 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3919 end, false);
3920
3921 Collections.sort(list);
3922
3923 list = new UnmodifiableList<Role>(list);
3924 }
3925 else {
3926 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3927 end);
3928 }
3929
3930 cacheResult(list);
3931
3932 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3933 }
3934 catch (Exception e) {
3935 FinderCacheUtil.removeResult(finderPath, finderArgs);
3936
3937 throw processException(e);
3938 }
3939 finally {
3940 closeSession(session);
3941 }
3942 }
3943
3944 return list;
3945 }
3946
3947
3956 @Override
3957 public Role findByType_First(int type, OrderByComparator orderByComparator)
3958 throws NoSuchRoleException, SystemException {
3959 Role role = fetchByType_First(type, orderByComparator);
3960
3961 if (role != null) {
3962 return role;
3963 }
3964
3965 StringBundler msg = new StringBundler(4);
3966
3967 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3968
3969 msg.append("type=");
3970 msg.append(type);
3971
3972 msg.append(StringPool.CLOSE_CURLY_BRACE);
3973
3974 throw new NoSuchRoleException(msg.toString());
3975 }
3976
3977
3985 @Override
3986 public Role fetchByType_First(int type, OrderByComparator orderByComparator)
3987 throws SystemException {
3988 List<Role> list = findByType(type, 0, 1, orderByComparator);
3989
3990 if (!list.isEmpty()) {
3991 return list.get(0);
3992 }
3993
3994 return null;
3995 }
3996
3997
4006 @Override
4007 public Role findByType_Last(int type, OrderByComparator orderByComparator)
4008 throws NoSuchRoleException, SystemException {
4009 Role role = fetchByType_Last(type, orderByComparator);
4010
4011 if (role != null) {
4012 return role;
4013 }
4014
4015 StringBundler msg = new StringBundler(4);
4016
4017 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4018
4019 msg.append("type=");
4020 msg.append(type);
4021
4022 msg.append(StringPool.CLOSE_CURLY_BRACE);
4023
4024 throw new NoSuchRoleException(msg.toString());
4025 }
4026
4027
4035 @Override
4036 public Role fetchByType_Last(int type, OrderByComparator orderByComparator)
4037 throws SystemException {
4038 int count = countByType(type);
4039
4040 if (count == 0) {
4041 return null;
4042 }
4043
4044 List<Role> list = findByType(type, count - 1, count, orderByComparator);
4045
4046 if (!list.isEmpty()) {
4047 return list.get(0);
4048 }
4049
4050 return null;
4051 }
4052
4053
4063 @Override
4064 public Role[] findByType_PrevAndNext(long roleId, int type,
4065 OrderByComparator orderByComparator)
4066 throws NoSuchRoleException, SystemException {
4067 Role role = findByPrimaryKey(roleId);
4068
4069 Session session = null;
4070
4071 try {
4072 session = openSession();
4073
4074 Role[] array = new RoleImpl[3];
4075
4076 array[0] = getByType_PrevAndNext(session, role, type,
4077 orderByComparator, true);
4078
4079 array[1] = role;
4080
4081 array[2] = getByType_PrevAndNext(session, role, type,
4082 orderByComparator, false);
4083
4084 return array;
4085 }
4086 catch (Exception e) {
4087 throw processException(e);
4088 }
4089 finally {
4090 closeSession(session);
4091 }
4092 }
4093
4094 protected Role getByType_PrevAndNext(Session session, Role role, int type,
4095 OrderByComparator orderByComparator, boolean previous) {
4096 StringBundler query = null;
4097
4098 if (orderByComparator != null) {
4099 query = new StringBundler(6 +
4100 (orderByComparator.getOrderByFields().length * 6));
4101 }
4102 else {
4103 query = new StringBundler(3);
4104 }
4105
4106 query.append(_SQL_SELECT_ROLE_WHERE);
4107
4108 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4109
4110 if (orderByComparator != null) {
4111 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4112
4113 if (orderByConditionFields.length > 0) {
4114 query.append(WHERE_AND);
4115 }
4116
4117 for (int i = 0; i < orderByConditionFields.length; i++) {
4118 query.append(_ORDER_BY_ENTITY_ALIAS);
4119 query.append(orderByConditionFields[i]);
4120
4121 if ((i + 1) < orderByConditionFields.length) {
4122 if (orderByComparator.isAscending() ^ previous) {
4123 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4124 }
4125 else {
4126 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4127 }
4128 }
4129 else {
4130 if (orderByComparator.isAscending() ^ previous) {
4131 query.append(WHERE_GREATER_THAN);
4132 }
4133 else {
4134 query.append(WHERE_LESSER_THAN);
4135 }
4136 }
4137 }
4138
4139 query.append(ORDER_BY_CLAUSE);
4140
4141 String[] orderByFields = orderByComparator.getOrderByFields();
4142
4143 for (int i = 0; i < orderByFields.length; i++) {
4144 query.append(_ORDER_BY_ENTITY_ALIAS);
4145 query.append(orderByFields[i]);
4146
4147 if ((i + 1) < orderByFields.length) {
4148 if (orderByComparator.isAscending() ^ previous) {
4149 query.append(ORDER_BY_ASC_HAS_NEXT);
4150 }
4151 else {
4152 query.append(ORDER_BY_DESC_HAS_NEXT);
4153 }
4154 }
4155 else {
4156 if (orderByComparator.isAscending() ^ previous) {
4157 query.append(ORDER_BY_ASC);
4158 }
4159 else {
4160 query.append(ORDER_BY_DESC);
4161 }
4162 }
4163 }
4164 }
4165 else {
4166 query.append(RoleModelImpl.ORDER_BY_JPQL);
4167 }
4168
4169 String sql = query.toString();
4170
4171 Query q = session.createQuery(sql);
4172
4173 q.setFirstResult(0);
4174 q.setMaxResults(2);
4175
4176 QueryPos qPos = QueryPos.getInstance(q);
4177
4178 qPos.add(type);
4179
4180 if (orderByComparator != null) {
4181 Object[] values = orderByComparator.getOrderByConditionValues(role);
4182
4183 for (Object value : values) {
4184 qPos.add(value);
4185 }
4186 }
4187
4188 List<Role> list = q.list();
4189
4190 if (list.size() == 2) {
4191 return list.get(1);
4192 }
4193 else {
4194 return null;
4195 }
4196 }
4197
4198
4205 @Override
4206 public List<Role> filterFindByType(int type) throws SystemException {
4207 return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4208 }
4209
4210
4223 @Override
4224 public List<Role> filterFindByType(int type, int start, int end)
4225 throws SystemException {
4226 return filterFindByType(type, start, end, null);
4227 }
4228
4229
4243 @Override
4244 public List<Role> filterFindByType(int type, int start, int end,
4245 OrderByComparator orderByComparator) throws SystemException {
4246 if (!InlineSQLHelperUtil.isEnabled()) {
4247 return findByType(type, start, end, orderByComparator);
4248 }
4249
4250 StringBundler query = null;
4251
4252 if (orderByComparator != null) {
4253 query = new StringBundler(3 +
4254 (orderByComparator.getOrderByFields().length * 3));
4255 }
4256 else {
4257 query = new StringBundler(3);
4258 }
4259
4260 if (getDB().isSupportsInlineDistinct()) {
4261 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4262 }
4263 else {
4264 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4265 }
4266
4267 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4268
4269 if (!getDB().isSupportsInlineDistinct()) {
4270 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4271 }
4272
4273 if (orderByComparator != null) {
4274 if (getDB().isSupportsInlineDistinct()) {
4275 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4276 orderByComparator, true);
4277 }
4278 else {
4279 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4280 orderByComparator, true);
4281 }
4282 }
4283 else {
4284 if (getDB().isSupportsInlineDistinct()) {
4285 query.append(RoleModelImpl.ORDER_BY_JPQL);
4286 }
4287 else {
4288 query.append(RoleModelImpl.ORDER_BY_SQL);
4289 }
4290 }
4291
4292 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4293 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4294
4295 Session session = null;
4296
4297 try {
4298 session = openSession();
4299
4300 SQLQuery q = session.createSQLQuery(sql);
4301
4302 if (getDB().isSupportsInlineDistinct()) {
4303 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4304 }
4305 else {
4306 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4307 }
4308
4309 QueryPos qPos = QueryPos.getInstance(q);
4310
4311 qPos.add(type);
4312
4313 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
4314 }
4315 catch (Exception e) {
4316 throw processException(e);
4317 }
4318 finally {
4319 closeSession(session);
4320 }
4321 }
4322
4323
4333 @Override
4334 public Role[] filterFindByType_PrevAndNext(long roleId, int type,
4335 OrderByComparator orderByComparator)
4336 throws NoSuchRoleException, SystemException {
4337 if (!InlineSQLHelperUtil.isEnabled()) {
4338 return findByType_PrevAndNext(roleId, type, orderByComparator);
4339 }
4340
4341 Role role = findByPrimaryKey(roleId);
4342
4343 Session session = null;
4344
4345 try {
4346 session = openSession();
4347
4348 Role[] array = new RoleImpl[3];
4349
4350 array[0] = filterGetByType_PrevAndNext(session, role, type,
4351 orderByComparator, true);
4352
4353 array[1] = role;
4354
4355 array[2] = filterGetByType_PrevAndNext(session, role, type,
4356 orderByComparator, false);
4357
4358 return array;
4359 }
4360 catch (Exception e) {
4361 throw processException(e);
4362 }
4363 finally {
4364 closeSession(session);
4365 }
4366 }
4367
4368 protected Role filterGetByType_PrevAndNext(Session session, Role role,
4369 int type, OrderByComparator orderByComparator, boolean previous) {
4370 StringBundler query = null;
4371
4372 if (orderByComparator != null) {
4373 query = new StringBundler(6 +
4374 (orderByComparator.getOrderByFields().length * 6));
4375 }
4376 else {
4377 query = new StringBundler(3);
4378 }
4379
4380 if (getDB().isSupportsInlineDistinct()) {
4381 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4382 }
4383 else {
4384 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4385 }
4386
4387 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4388
4389 if (!getDB().isSupportsInlineDistinct()) {
4390 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4391 }
4392
4393 if (orderByComparator != null) {
4394 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4395
4396 if (orderByConditionFields.length > 0) {
4397 query.append(WHERE_AND);
4398 }
4399
4400 for (int i = 0; i < orderByConditionFields.length; i++) {
4401 if (getDB().isSupportsInlineDistinct()) {
4402 query.append(_ORDER_BY_ENTITY_ALIAS);
4403 }
4404 else {
4405 query.append(_ORDER_BY_ENTITY_TABLE);
4406 }
4407
4408 query.append(orderByConditionFields[i]);
4409
4410 if ((i + 1) < orderByConditionFields.length) {
4411 if (orderByComparator.isAscending() ^ previous) {
4412 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4413 }
4414 else {
4415 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4416 }
4417 }
4418 else {
4419 if (orderByComparator.isAscending() ^ previous) {
4420 query.append(WHERE_GREATER_THAN);
4421 }
4422 else {
4423 query.append(WHERE_LESSER_THAN);
4424 }
4425 }
4426 }
4427
4428 query.append(ORDER_BY_CLAUSE);
4429
4430 String[] orderByFields = orderByComparator.getOrderByFields();
4431
4432 for (int i = 0; i < orderByFields.length; i++) {
4433 if (getDB().isSupportsInlineDistinct()) {
4434 query.append(_ORDER_BY_ENTITY_ALIAS);
4435 }
4436 else {
4437 query.append(_ORDER_BY_ENTITY_TABLE);
4438 }
4439
4440 query.append(orderByFields[i]);
4441
4442 if ((i + 1) < orderByFields.length) {
4443 if (orderByComparator.isAscending() ^ previous) {
4444 query.append(ORDER_BY_ASC_HAS_NEXT);
4445 }
4446 else {
4447 query.append(ORDER_BY_DESC_HAS_NEXT);
4448 }
4449 }
4450 else {
4451 if (orderByComparator.isAscending() ^ previous) {
4452 query.append(ORDER_BY_ASC);
4453 }
4454 else {
4455 query.append(ORDER_BY_DESC);
4456 }
4457 }
4458 }
4459 }
4460 else {
4461 if (getDB().isSupportsInlineDistinct()) {
4462 query.append(RoleModelImpl.ORDER_BY_JPQL);
4463 }
4464 else {
4465 query.append(RoleModelImpl.ORDER_BY_SQL);
4466 }
4467 }
4468
4469 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4470 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4471
4472 SQLQuery q = session.createSQLQuery(sql);
4473
4474 q.setFirstResult(0);
4475 q.setMaxResults(2);
4476
4477 if (getDB().isSupportsInlineDistinct()) {
4478 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4479 }
4480 else {
4481 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4482 }
4483
4484 QueryPos qPos = QueryPos.getInstance(q);
4485
4486 qPos.add(type);
4487
4488 if (orderByComparator != null) {
4489 Object[] values = orderByComparator.getOrderByConditionValues(role);
4490
4491 for (Object value : values) {
4492 qPos.add(value);
4493 }
4494 }
4495
4496 List<Role> list = q.list();
4497
4498 if (list.size() == 2) {
4499 return list.get(1);
4500 }
4501 else {
4502 return null;
4503 }
4504 }
4505
4506
4512 @Override
4513 public void removeByType(int type) throws SystemException {
4514 for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4515 null)) {
4516 remove(role);
4517 }
4518 }
4519
4520
4527 @Override
4528 public int countByType(int type) throws SystemException {
4529 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
4530
4531 Object[] finderArgs = new Object[] { type };
4532
4533 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4534 this);
4535
4536 if (count == null) {
4537 StringBundler query = new StringBundler(2);
4538
4539 query.append(_SQL_COUNT_ROLE_WHERE);
4540
4541 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4542
4543 String sql = query.toString();
4544
4545 Session session = null;
4546
4547 try {
4548 session = openSession();
4549
4550 Query q = session.createQuery(sql);
4551
4552 QueryPos qPos = QueryPos.getInstance(q);
4553
4554 qPos.add(type);
4555
4556 count = (Long)q.uniqueResult();
4557
4558 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4559 }
4560 catch (Exception e) {
4561 FinderCacheUtil.removeResult(finderPath, finderArgs);
4562
4563 throw processException(e);
4564 }
4565 finally {
4566 closeSession(session);
4567 }
4568 }
4569
4570 return count.intValue();
4571 }
4572
4573
4580 @Override
4581 public int filterCountByType(int type) throws SystemException {
4582 if (!InlineSQLHelperUtil.isEnabled()) {
4583 return countByType(type);
4584 }
4585
4586 StringBundler query = new StringBundler(2);
4587
4588 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4589
4590 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4591
4592 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4593 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4594
4595 Session session = null;
4596
4597 try {
4598 session = openSession();
4599
4600 SQLQuery q = session.createSQLQuery(sql);
4601
4602 q.addScalar(COUNT_COLUMN_NAME,
4603 com.liferay.portal.kernel.dao.orm.Type.LONG);
4604
4605 QueryPos qPos = QueryPos.getInstance(q);
4606
4607 qPos.add(type);
4608
4609 Long count = (Long)q.uniqueResult();
4610
4611 return count.intValue();
4612 }
4613 catch (Exception e) {
4614 throw processException(e);
4615 }
4616 finally {
4617 closeSession(session);
4618 }
4619 }
4620
4621 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?";
4622 private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?";
4623 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4624 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4625 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
4626 new String[] {
4627 String.class.getName(),
4628
4629 Integer.class.getName(), Integer.class.getName(),
4630 OrderByComparator.class.getName()
4631 });
4632 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
4633 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4634 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4635 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
4636 new String[] { String.class.getName() },
4637 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
4638 RoleModelImpl.NAME_COLUMN_BITMASK);
4639 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4640 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4641 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
4642 new String[] { String.class.getName() });
4643
4644
4651 @Override
4652 public List<Role> findBySubtype(String subtype) throws SystemException {
4653 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4654 }
4655
4656
4669 @Override
4670 public List<Role> findBySubtype(String subtype, int start, int end)
4671 throws SystemException {
4672 return findBySubtype(subtype, start, end, null);
4673 }
4674
4675
4689 @Override
4690 public List<Role> findBySubtype(String subtype, int start, int end,
4691 OrderByComparator orderByComparator) throws SystemException {
4692 boolean pagination = true;
4693 FinderPath finderPath = null;
4694 Object[] finderArgs = null;
4695
4696 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4697 (orderByComparator == null)) {
4698 pagination = false;
4699 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
4700 finderArgs = new Object[] { subtype };
4701 }
4702 else {
4703 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
4704 finderArgs = new Object[] { subtype, start, end, orderByComparator };
4705 }
4706
4707 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
4708 finderArgs, this);
4709
4710 if ((list != null) && !list.isEmpty()) {
4711 for (Role role : list) {
4712 if (!Validator.equals(subtype, role.getSubtype())) {
4713 list = null;
4714
4715 break;
4716 }
4717 }
4718 }
4719
4720 if (list == null) {
4721 StringBundler query = null;
4722
4723 if (orderByComparator != null) {
4724 query = new StringBundler(3 +
4725 (orderByComparator.getOrderByFields().length * 3));
4726 }
4727 else {
4728 query = new StringBundler(3);
4729 }
4730
4731 query.append(_SQL_SELECT_ROLE_WHERE);
4732
4733 boolean bindSubtype = false;
4734
4735 if (subtype == null) {
4736 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4737 }
4738 else if (subtype.equals(StringPool.BLANK)) {
4739 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4740 }
4741 else {
4742 bindSubtype = true;
4743
4744 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4745 }
4746
4747 if (orderByComparator != null) {
4748 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4749 orderByComparator);
4750 }
4751 else
4752 if (pagination) {
4753 query.append(RoleModelImpl.ORDER_BY_JPQL);
4754 }
4755
4756 String sql = query.toString();
4757
4758 Session session = null;
4759
4760 try {
4761 session = openSession();
4762
4763 Query q = session.createQuery(sql);
4764
4765 QueryPos qPos = QueryPos.getInstance(q);
4766
4767 if (bindSubtype) {
4768 qPos.add(subtype);
4769 }
4770
4771 if (!pagination) {
4772 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4773 end, false);
4774
4775 Collections.sort(list);
4776
4777 list = new UnmodifiableList<Role>(list);
4778 }
4779 else {
4780 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4781 end);
4782 }
4783
4784 cacheResult(list);
4785
4786 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4787 }
4788 catch (Exception e) {
4789 FinderCacheUtil.removeResult(finderPath, finderArgs);
4790
4791 throw processException(e);
4792 }
4793 finally {
4794 closeSession(session);
4795 }
4796 }
4797
4798 return list;
4799 }
4800
4801
4810 @Override
4811 public Role findBySubtype_First(String subtype,
4812 OrderByComparator orderByComparator)
4813 throws NoSuchRoleException, SystemException {
4814 Role role = fetchBySubtype_First(subtype, orderByComparator);
4815
4816 if (role != null) {
4817 return role;
4818 }
4819
4820 StringBundler msg = new StringBundler(4);
4821
4822 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4823
4824 msg.append("subtype=");
4825 msg.append(subtype);
4826
4827 msg.append(StringPool.CLOSE_CURLY_BRACE);
4828
4829 throw new NoSuchRoleException(msg.toString());
4830 }
4831
4832
4840 @Override
4841 public Role fetchBySubtype_First(String subtype,
4842 OrderByComparator orderByComparator) throws SystemException {
4843 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
4844
4845 if (!list.isEmpty()) {
4846 return list.get(0);
4847 }
4848
4849 return null;
4850 }
4851
4852
4861 @Override
4862 public Role findBySubtype_Last(String subtype,
4863 OrderByComparator orderByComparator)
4864 throws NoSuchRoleException, SystemException {
4865 Role role = fetchBySubtype_Last(subtype, orderByComparator);
4866
4867 if (role != null) {
4868 return role;
4869 }
4870
4871 StringBundler msg = new StringBundler(4);
4872
4873 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4874
4875 msg.append("subtype=");
4876 msg.append(subtype);
4877
4878 msg.append(StringPool.CLOSE_CURLY_BRACE);
4879
4880 throw new NoSuchRoleException(msg.toString());
4881 }
4882
4883
4891 @Override
4892 public Role fetchBySubtype_Last(String subtype,
4893 OrderByComparator orderByComparator) throws SystemException {
4894 int count = countBySubtype(subtype);
4895
4896 if (count == 0) {
4897 return null;
4898 }
4899
4900 List<Role> list = findBySubtype(subtype, count - 1, count,
4901 orderByComparator);
4902
4903 if (!list.isEmpty()) {
4904 return list.get(0);
4905 }
4906
4907 return null;
4908 }
4909
4910
4920 @Override
4921 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
4922 OrderByComparator orderByComparator)
4923 throws NoSuchRoleException, SystemException {
4924 Role role = findByPrimaryKey(roleId);
4925
4926 Session session = null;
4927
4928 try {
4929 session = openSession();
4930
4931 Role[] array = new RoleImpl[3];
4932
4933 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
4934 orderByComparator, true);
4935
4936 array[1] = role;
4937
4938 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
4939 orderByComparator, false);
4940
4941 return array;
4942 }
4943 catch (Exception e) {
4944 throw processException(e);
4945 }
4946 finally {
4947 closeSession(session);
4948 }
4949 }
4950
4951 protected Role getBySubtype_PrevAndNext(Session session, Role role,
4952 String subtype, OrderByComparator orderByComparator, boolean previous) {
4953 StringBundler query = null;
4954
4955 if (orderByComparator != null) {
4956 query = new StringBundler(6 +
4957 (orderByComparator.getOrderByFields().length * 6));
4958 }
4959 else {
4960 query = new StringBundler(3);
4961 }
4962
4963 query.append(_SQL_SELECT_ROLE_WHERE);
4964
4965 boolean bindSubtype = false;
4966
4967 if (subtype == null) {
4968 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4969 }
4970 else if (subtype.equals(StringPool.BLANK)) {
4971 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4972 }
4973 else {
4974 bindSubtype = true;
4975
4976 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4977 }
4978
4979 if (orderByComparator != null) {
4980 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4981
4982 if (orderByConditionFields.length > 0) {
4983 query.append(WHERE_AND);
4984 }
4985
4986 for (int i = 0; i < orderByConditionFields.length; i++) {
4987 query.append(_ORDER_BY_ENTITY_ALIAS);
4988 query.append(orderByConditionFields[i]);
4989
4990 if ((i + 1) < orderByConditionFields.length) {
4991 if (orderByComparator.isAscending() ^ previous) {
4992 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4993 }
4994 else {
4995 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4996 }
4997 }
4998 else {
4999 if (orderByComparator.isAscending() ^ previous) {
5000 query.append(WHERE_GREATER_THAN);
5001 }
5002 else {
5003 query.append(WHERE_LESSER_THAN);
5004 }
5005 }
5006 }
5007
5008 query.append(ORDER_BY_CLAUSE);
5009
5010 String[] orderByFields = orderByComparator.getOrderByFields();
5011
5012 for (int i = 0; i < orderByFields.length; i++) {
5013 query.append(_ORDER_BY_ENTITY_ALIAS);
5014 query.append(orderByFields[i]);
5015
5016 if ((i + 1) < orderByFields.length) {
5017 if (orderByComparator.isAscending() ^ previous) {
5018 query.append(ORDER_BY_ASC_HAS_NEXT);
5019 }
5020 else {
5021 query.append(ORDER_BY_DESC_HAS_NEXT);
5022 }
5023 }
5024 else {
5025 if (orderByComparator.isAscending() ^ previous) {
5026 query.append(ORDER_BY_ASC);
5027 }
5028 else {
5029 query.append(ORDER_BY_DESC);
5030 }
5031 }
5032 }
5033 }
5034 else {
5035 query.append(RoleModelImpl.ORDER_BY_JPQL);
5036 }
5037
5038 String sql = query.toString();
5039
5040 Query q = session.createQuery(sql);
5041
5042 q.setFirstResult(0);
5043 q.setMaxResults(2);
5044
5045 QueryPos qPos = QueryPos.getInstance(q);
5046
5047 if (bindSubtype) {
5048 qPos.add(subtype);
5049 }
5050
5051 if (orderByComparator != null) {
5052 Object[] values = orderByComparator.getOrderByConditionValues(role);
5053
5054 for (Object value : values) {
5055 qPos.add(value);
5056 }
5057 }
5058
5059 List<Role> list = q.list();
5060
5061 if (list.size() == 2) {
5062 return list.get(1);
5063 }
5064 else {
5065 return null;
5066 }
5067 }
5068
5069
5076 @Override
5077 public List<Role> filterFindBySubtype(String subtype)
5078 throws SystemException {
5079 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
5080 QueryUtil.ALL_POS, null);
5081 }
5082
5083
5096 @Override
5097 public List<Role> filterFindBySubtype(String subtype, int start, int end)
5098 throws SystemException {
5099 return filterFindBySubtype(subtype, start, end, null);
5100 }
5101
5102
5116 @Override
5117 public List<Role> filterFindBySubtype(String subtype, int start, int end,
5118 OrderByComparator orderByComparator) throws SystemException {
5119 if (!InlineSQLHelperUtil.isEnabled()) {
5120 return findBySubtype(subtype, start, end, orderByComparator);
5121 }
5122
5123 StringBundler query = null;
5124
5125 if (orderByComparator != null) {
5126 query = new StringBundler(3 +
5127 (orderByComparator.getOrderByFields().length * 3));
5128 }
5129 else {
5130 query = new StringBundler(3);
5131 }
5132
5133 if (getDB().isSupportsInlineDistinct()) {
5134 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5135 }
5136 else {
5137 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5138 }
5139
5140 boolean bindSubtype = false;
5141
5142 if (subtype == null) {
5143 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5144 }
5145 else if (subtype.equals(StringPool.BLANK)) {
5146 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5147 }
5148 else {
5149 bindSubtype = true;
5150
5151 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5152 }
5153
5154 if (!getDB().isSupportsInlineDistinct()) {
5155 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5156 }
5157
5158 if (orderByComparator != null) {
5159 if (getDB().isSupportsInlineDistinct()) {
5160 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5161 orderByComparator, true);
5162 }
5163 else {
5164 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5165 orderByComparator, true);
5166 }
5167 }
5168 else {
5169 if (getDB().isSupportsInlineDistinct()) {
5170 query.append(RoleModelImpl.ORDER_BY_JPQL);
5171 }
5172 else {
5173 query.append(RoleModelImpl.ORDER_BY_SQL);
5174 }
5175 }
5176
5177 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5178 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5179
5180 Session session = null;
5181
5182 try {
5183 session = openSession();
5184
5185 SQLQuery q = session.createSQLQuery(sql);
5186
5187 if (getDB().isSupportsInlineDistinct()) {
5188 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5189 }
5190 else {
5191 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5192 }
5193
5194 QueryPos qPos = QueryPos.getInstance(q);
5195
5196 if (bindSubtype) {
5197 qPos.add(subtype);
5198 }
5199
5200 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
5201 }
5202 catch (Exception e) {
5203 throw processException(e);
5204 }
5205 finally {
5206 closeSession(session);
5207 }
5208 }
5209
5210
5220 @Override
5221 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
5222 OrderByComparator orderByComparator)
5223 throws NoSuchRoleException, SystemException {
5224 if (!InlineSQLHelperUtil.isEnabled()) {
5225 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
5226 }
5227
5228 Role role = findByPrimaryKey(roleId);
5229
5230 Session session = null;
5231
5232 try {
5233 session = openSession();
5234
5235 Role[] array = new RoleImpl[3];
5236
5237 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5238 orderByComparator, true);
5239
5240 array[1] = role;
5241
5242 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5243 orderByComparator, false);
5244
5245 return array;
5246 }
5247 catch (Exception e) {
5248 throw processException(e);
5249 }
5250 finally {
5251 closeSession(session);
5252 }
5253 }
5254
5255 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
5256 String subtype, OrderByComparator orderByComparator, boolean previous) {
5257 StringBundler query = null;
5258
5259 if (orderByComparator != null) {
5260 query = new StringBundler(6 +
5261 (orderByComparator.getOrderByFields().length * 6));
5262 }
5263 else {
5264 query = new StringBundler(3);
5265 }
5266
5267 if (getDB().isSupportsInlineDistinct()) {
5268 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5269 }
5270 else {
5271 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5272 }
5273
5274 boolean bindSubtype = false;
5275
5276 if (subtype == null) {
5277 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5278 }
5279 else if (subtype.equals(StringPool.BLANK)) {
5280 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5281 }
5282 else {
5283 bindSubtype = true;
5284
5285 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5286 }
5287
5288 if (!getDB().isSupportsInlineDistinct()) {
5289 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5290 }
5291
5292 if (orderByComparator != null) {
5293 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5294
5295 if (orderByConditionFields.length > 0) {
5296 query.append(WHERE_AND);
5297 }
5298
5299 for (int i = 0; i < orderByConditionFields.length; i++) {
5300 if (getDB().isSupportsInlineDistinct()) {
5301 query.append(_ORDER_BY_ENTITY_ALIAS);
5302 }
5303 else {
5304 query.append(_ORDER_BY_ENTITY_TABLE);
5305 }
5306
5307 query.append(orderByConditionFields[i]);
5308
5309 if ((i + 1) < orderByConditionFields.length) {
5310 if (orderByComparator.isAscending() ^ previous) {
5311 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5312 }
5313 else {
5314 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5315 }
5316 }
5317 else {
5318 if (orderByComparator.isAscending() ^ previous) {
5319 query.append(WHERE_GREATER_THAN);
5320 }
5321 else {
5322 query.append(WHERE_LESSER_THAN);
5323 }
5324 }
5325 }
5326
5327 query.append(ORDER_BY_CLAUSE);
5328
5329 String[] orderByFields = orderByComparator.getOrderByFields();
5330
5331 for (int i = 0; i < orderByFields.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(orderByFields[i]);
5340
5341 if ((i + 1) < orderByFields.length) {
5342 if (orderByComparator.isAscending() ^ previous) {
5343 query.append(ORDER_BY_ASC_HAS_NEXT);
5344 }
5345 else {
5346 query.append(ORDER_BY_DESC_HAS_NEXT);
5347 }
5348 }
5349 else {
5350 if (orderByComparator.isAscending() ^ previous) {
5351 query.append(ORDER_BY_ASC);
5352 }
5353 else {
5354 query.append(ORDER_BY_DESC);
5355 }
5356 }
5357 }
5358 }
5359 else {
5360 if (getDB().isSupportsInlineDistinct()) {
5361 query.append(RoleModelImpl.ORDER_BY_JPQL);
5362 }
5363 else {
5364 query.append(RoleModelImpl.ORDER_BY_SQL);
5365 }
5366 }
5367
5368 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5369 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5370
5371 SQLQuery q = session.createSQLQuery(sql);
5372
5373 q.setFirstResult(0);
5374 q.setMaxResults(2);
5375
5376 if (getDB().isSupportsInlineDistinct()) {
5377 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5378 }
5379 else {
5380 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5381 }
5382
5383 QueryPos qPos = QueryPos.getInstance(q);
5384
5385 if (bindSubtype) {
5386 qPos.add(subtype);
5387 }
5388
5389 if (orderByComparator != null) {
5390 Object[] values = orderByComparator.getOrderByConditionValues(role);
5391
5392 for (Object value : values) {
5393 qPos.add(value);
5394 }
5395 }
5396
5397 List<Role> list = q.list();
5398
5399 if (list.size() == 2) {
5400 return list.get(1);
5401 }
5402 else {
5403 return null;
5404 }
5405 }
5406
5407
5413 @Override
5414 public void removeBySubtype(String subtype) throws SystemException {
5415 for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
5416 QueryUtil.ALL_POS, null)) {
5417 remove(role);
5418 }
5419 }
5420
5421
5428 @Override
5429 public int countBySubtype(String subtype) throws SystemException {
5430 FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
5431
5432 Object[] finderArgs = new Object[] { subtype };
5433
5434 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5435 this);
5436
5437 if (count == null) {
5438 StringBundler query = new StringBundler(2);
5439
5440 query.append(_SQL_COUNT_ROLE_WHERE);
5441
5442 boolean bindSubtype = false;
5443
5444 if (subtype == null) {
5445 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5446 }
5447 else if (subtype.equals(StringPool.BLANK)) {
5448 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5449 }
5450 else {
5451 bindSubtype = true;
5452
5453 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5454 }
5455
5456 String sql = query.toString();
5457
5458 Session session = null;
5459
5460 try {
5461 session = openSession();
5462
5463 Query q = session.createQuery(sql);
5464
5465 QueryPos qPos = QueryPos.getInstance(q);
5466
5467 if (bindSubtype) {
5468 qPos.add(subtype);
5469 }
5470
5471 count = (Long)q.uniqueResult();
5472
5473 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5474 }
5475 catch (Exception e) {
5476 FinderCacheUtil.removeResult(finderPath, finderArgs);
5477
5478 throw processException(e);
5479 }
5480 finally {
5481 closeSession(session);
5482 }
5483 }
5484
5485 return count.intValue();
5486 }
5487
5488
5495 @Override
5496 public int filterCountBySubtype(String subtype) throws SystemException {
5497 if (!InlineSQLHelperUtil.isEnabled()) {
5498 return countBySubtype(subtype);
5499 }
5500
5501 StringBundler query = new StringBundler(2);
5502
5503 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
5504
5505 boolean bindSubtype = false;
5506
5507 if (subtype == null) {
5508 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5509 }
5510 else if (subtype.equals(StringPool.BLANK)) {
5511 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5512 }
5513 else {
5514 bindSubtype = true;
5515
5516 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5517 }
5518
5519 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5520 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5521
5522 Session session = null;
5523
5524 try {
5525 session = openSession();
5526
5527 SQLQuery q = session.createSQLQuery(sql);
5528
5529 q.addScalar(COUNT_COLUMN_NAME,
5530 com.liferay.portal.kernel.dao.orm.Type.LONG);
5531
5532 QueryPos qPos = QueryPos.getInstance(q);
5533
5534 if (bindSubtype) {
5535 qPos.add(subtype);
5536 }
5537
5538 Long count = (Long)q.uniqueResult();
5539
5540 return count.intValue();
5541 }
5542 catch (Exception e) {
5543 throw processException(e);
5544 }
5545 finally {
5546 closeSession(session);
5547 }
5548 }
5549
5550 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5551 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5552 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
5553 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5554 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5555 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5556 new String[] { Long.class.getName(), String.class.getName() },
5557 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5558 RoleModelImpl.NAME_COLUMN_BITMASK);
5559 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5560 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5561 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5562 new String[] { Long.class.getName(), String.class.getName() });
5563
5564
5573 @Override
5574 public Role findByC_N(long companyId, String name)
5575 throws NoSuchRoleException, SystemException {
5576 Role role = fetchByC_N(companyId, name);
5577
5578 if (role == null) {
5579 StringBundler msg = new StringBundler(6);
5580
5581 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5582
5583 msg.append("companyId=");
5584 msg.append(companyId);
5585
5586 msg.append(", name=");
5587 msg.append(name);
5588
5589 msg.append(StringPool.CLOSE_CURLY_BRACE);
5590
5591 if (_log.isWarnEnabled()) {
5592 _log.warn(msg.toString());
5593 }
5594
5595 throw new NoSuchRoleException(msg.toString());
5596 }
5597
5598 return role;
5599 }
5600
5601
5609 @Override
5610 public Role fetchByC_N(long companyId, String name)
5611 throws SystemException {
5612 return fetchByC_N(companyId, name, true);
5613 }
5614
5615
5624 @Override
5625 public Role fetchByC_N(long companyId, String name,
5626 boolean retrieveFromCache) throws SystemException {
5627 Object[] finderArgs = new Object[] { companyId, name };
5628
5629 Object result = null;
5630
5631 if (retrieveFromCache) {
5632 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5633 finderArgs, this);
5634 }
5635
5636 if (result instanceof Role) {
5637 Role role = (Role)result;
5638
5639 if ((companyId != role.getCompanyId()) ||
5640 !Validator.equals(name, role.getName())) {
5641 result = null;
5642 }
5643 }
5644
5645 if (result == null) {
5646 StringBundler query = new StringBundler(4);
5647
5648 query.append(_SQL_SELECT_ROLE_WHERE);
5649
5650 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5651
5652 boolean bindName = false;
5653
5654 if (name == null) {
5655 query.append(_FINDER_COLUMN_C_N_NAME_1);
5656 }
5657 else if (name.equals(StringPool.BLANK)) {
5658 query.append(_FINDER_COLUMN_C_N_NAME_3);
5659 }
5660 else {
5661 bindName = true;
5662
5663 query.append(_FINDER_COLUMN_C_N_NAME_2);
5664 }
5665
5666 String sql = query.toString();
5667
5668 Session session = null;
5669
5670 try {
5671 session = openSession();
5672
5673 Query q = session.createQuery(sql);
5674
5675 QueryPos qPos = QueryPos.getInstance(q);
5676
5677 qPos.add(companyId);
5678
5679 if (bindName) {
5680 qPos.add(name.toLowerCase());
5681 }
5682
5683 List<Role> list = q.list();
5684
5685 if (list.isEmpty()) {
5686 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5687 finderArgs, list);
5688 }
5689 else {
5690 Role role = list.get(0);
5691
5692 result = role;
5693
5694 cacheResult(role);
5695
5696 if ((role.getCompanyId() != companyId) ||
5697 (role.getName() == null) ||
5698 !role.getName().equals(name)) {
5699 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5700 finderArgs, role);
5701 }
5702 }
5703 }
5704 catch (Exception e) {
5705 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5706 finderArgs);
5707
5708 throw processException(e);
5709 }
5710 finally {
5711 closeSession(session);
5712 }
5713 }
5714
5715 if (result instanceof List<?>) {
5716 return null;
5717 }
5718 else {
5719 return (Role)result;
5720 }
5721 }
5722
5723
5731 @Override
5732 public Role removeByC_N(long companyId, String name)
5733 throws NoSuchRoleException, SystemException {
5734 Role role = findByC_N(companyId, name);
5735
5736 return remove(role);
5737 }
5738
5739
5747 @Override
5748 public int countByC_N(long companyId, String name)
5749 throws SystemException {
5750 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5751
5752 Object[] finderArgs = new Object[] { companyId, name };
5753
5754 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5755 this);
5756
5757 if (count == null) {
5758 StringBundler query = new StringBundler(3);
5759
5760 query.append(_SQL_COUNT_ROLE_WHERE);
5761
5762 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5763
5764 boolean bindName = false;
5765
5766 if (name == null) {
5767 query.append(_FINDER_COLUMN_C_N_NAME_1);
5768 }
5769 else if (name.equals(StringPool.BLANK)) {
5770 query.append(_FINDER_COLUMN_C_N_NAME_3);
5771 }
5772 else {
5773 bindName = true;
5774
5775 query.append(_FINDER_COLUMN_C_N_NAME_2);
5776 }
5777
5778 String sql = query.toString();
5779
5780 Session session = null;
5781
5782 try {
5783 session = openSession();
5784
5785 Query q = session.createQuery(sql);
5786
5787 QueryPos qPos = QueryPos.getInstance(q);
5788
5789 qPos.add(companyId);
5790
5791 if (bindName) {
5792 qPos.add(name.toLowerCase());
5793 }
5794
5795 count = (Long)q.uniqueResult();
5796
5797 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5798 }
5799 catch (Exception e) {
5800 FinderCacheUtil.removeResult(finderPath, finderArgs);
5801
5802 throw processException(e);
5803 }
5804 finally {
5805 closeSession(session);
5806 }
5807 }
5808
5809 return count.intValue();
5810 }
5811
5812 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5813 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5814 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?";
5815 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')";
5816 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5817 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5818 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
5819 new String[] {
5820 Integer.class.getName(), String.class.getName(),
5821
5822 Integer.class.getName(), Integer.class.getName(),
5823 OrderByComparator.class.getName()
5824 });
5825 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5826 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5827 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
5828 new String[] { Integer.class.getName(), String.class.getName() },
5829 RoleModelImpl.TYPE_COLUMN_BITMASK |
5830 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
5831 RoleModelImpl.NAME_COLUMN_BITMASK);
5832 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5833 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5834 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
5835 new String[] { Integer.class.getName(), String.class.getName() });
5836
5837
5845 @Override
5846 public List<Role> findByT_S(int type, String subtype)
5847 throws SystemException {
5848 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5849 null);
5850 }
5851
5852
5866 @Override
5867 public List<Role> findByT_S(int type, String subtype, int start, int end)
5868 throws SystemException {
5869 return findByT_S(type, subtype, start, end, null);
5870 }
5871
5872
5887 @Override
5888 public List<Role> findByT_S(int type, String subtype, int start, int end,
5889 OrderByComparator orderByComparator) throws SystemException {
5890 boolean pagination = true;
5891 FinderPath finderPath = null;
5892 Object[] finderArgs = null;
5893
5894 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5895 (orderByComparator == null)) {
5896 pagination = false;
5897 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
5898 finderArgs = new Object[] { type, subtype };
5899 }
5900 else {
5901 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
5902 finderArgs = new Object[] {
5903 type, subtype,
5904
5905 start, end, orderByComparator
5906 };
5907 }
5908
5909 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
5910 finderArgs, this);
5911
5912 if ((list != null) && !list.isEmpty()) {
5913 for (Role role : list) {
5914 if ((type != role.getType()) ||
5915 !Validator.equals(subtype, role.getSubtype())) {
5916 list = null;
5917
5918 break;
5919 }
5920 }
5921 }
5922
5923 if (list == null) {
5924 StringBundler query = null;
5925
5926 if (orderByComparator != null) {
5927 query = new StringBundler(4 +
5928 (orderByComparator.getOrderByFields().length * 3));
5929 }
5930 else {
5931 query = new StringBundler(4);
5932 }
5933
5934 query.append(_SQL_SELECT_ROLE_WHERE);
5935
5936 query.append(_FINDER_COLUMN_T_S_TYPE_2);
5937
5938 boolean bindSubtype = false;
5939
5940 if (subtype == null) {
5941 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
5942 }
5943 else if (subtype.equals(StringPool.BLANK)) {
5944 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
5945 }
5946 else {
5947 bindSubtype = true;
5948
5949 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
5950 }
5951
5952 if (orderByComparator != null) {
5953 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5954 orderByComparator);
5955 }
5956 else
5957 if (pagination) {
5958 query.append(RoleModelImpl.ORDER_BY_JPQL);
5959 }
5960
5961 String sql = query.toString();
5962
5963 Session session = null;
5964
5965 try {
5966 session = openSession();
5967
5968 Query q = session.createQuery(sql);
5969
5970 QueryPos qPos = QueryPos.getInstance(q);
5971
5972 qPos.add(type);
5973
5974 if (bindSubtype) {
5975 qPos.add(subtype);
5976 }
5977
5978 if (!pagination) {
5979 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5980 end, false);
5981
5982 Collections.sort(list);
5983
5984 list = new UnmodifiableList<Role>(list);
5985 }
5986 else {
5987 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5988 end);
5989 }
5990
5991 cacheResult(list);
5992
5993 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5994 }
5995 catch (Exception e) {
5996 FinderCacheUtil.removeResult(finderPath, finderArgs);
5997
5998 throw processException(e);
5999 }
6000 finally {
6001 closeSession(session);
6002 }
6003 }
6004
6005 return list;
6006 }
6007
6008
6018 @Override
6019 public Role findByT_S_First(int type, String subtype,
6020 OrderByComparator orderByComparator)
6021 throws NoSuchRoleException, SystemException {
6022 Role role = fetchByT_S_First(type, subtype, orderByComparator);
6023
6024 if (role != null) {
6025 return role;
6026 }
6027
6028 StringBundler msg = new StringBundler(6);
6029
6030 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6031
6032 msg.append("type=");
6033 msg.append(type);
6034
6035 msg.append(", subtype=");
6036 msg.append(subtype);
6037
6038 msg.append(StringPool.CLOSE_CURLY_BRACE);
6039
6040 throw new NoSuchRoleException(msg.toString());
6041 }
6042
6043
6052 @Override
6053 public Role fetchByT_S_First(int type, String subtype,
6054 OrderByComparator orderByComparator) throws SystemException {
6055 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
6056
6057 if (!list.isEmpty()) {
6058 return list.get(0);
6059 }
6060
6061 return null;
6062 }
6063
6064
6074 @Override
6075 public Role findByT_S_Last(int type, String subtype,
6076 OrderByComparator orderByComparator)
6077 throws NoSuchRoleException, SystemException {
6078 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
6079
6080 if (role != null) {
6081 return role;
6082 }
6083
6084 StringBundler msg = new StringBundler(6);
6085
6086 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6087
6088 msg.append("type=");
6089 msg.append(type);
6090
6091 msg.append(", subtype=");
6092 msg.append(subtype);
6093
6094 msg.append(StringPool.CLOSE_CURLY_BRACE);
6095
6096 throw new NoSuchRoleException(msg.toString());
6097 }
6098
6099
6108 @Override
6109 public Role fetchByT_S_Last(int type, String subtype,
6110 OrderByComparator orderByComparator) throws SystemException {
6111 int count = countByT_S(type, subtype);
6112
6113 if (count == 0) {
6114 return null;
6115 }
6116
6117 List<Role> list = findByT_S(type, subtype, count - 1, count,
6118 orderByComparator);
6119
6120 if (!list.isEmpty()) {
6121 return list.get(0);
6122 }
6123
6124 return null;
6125 }
6126
6127
6138 @Override
6139 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
6140 OrderByComparator orderByComparator)
6141 throws NoSuchRoleException, SystemException {
6142 Role role = findByPrimaryKey(roleId);
6143
6144 Session session = null;
6145
6146 try {
6147 session = openSession();
6148
6149 Role[] array = new RoleImpl[3];
6150
6151 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
6152 orderByComparator, true);
6153
6154 array[1] = role;
6155
6156 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
6157 orderByComparator, false);
6158
6159 return array;
6160 }
6161 catch (Exception e) {
6162 throw processException(e);
6163 }
6164 finally {
6165 closeSession(session);
6166 }
6167 }
6168
6169 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
6170 String subtype, OrderByComparator orderByComparator, boolean previous) {
6171 StringBundler query = null;
6172
6173 if (orderByComparator != null) {
6174 query = new StringBundler(6 +
6175 (orderByComparator.getOrderByFields().length * 6));
6176 }
6177 else {
6178 query = new StringBundler(3);
6179 }
6180
6181 query.append(_SQL_SELECT_ROLE_WHERE);
6182
6183 query.append(_FINDER_COLUMN_T_S_TYPE_2);
6184
6185 boolean bindSubtype = false;
6186
6187 if (subtype == null) {
6188 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6189 }
6190 else if (subtype.equals(StringPool.BLANK)) {
6191 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6192 }
6193 else {
6194 bindSubtype = true;
6195
6196 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6197 }
6198
6199 if (orderByComparator != null) {
6200 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6201
6202 if (orderByConditionFields.length > 0) {
6203 query.append(WHERE_AND);
6204 }
6205
6206 for (int i = 0; i < orderByConditionFields.length; i++) {
6207 query.append(_ORDER_BY_ENTITY_ALIAS);
6208 query.append(orderByConditionFields[i]);
6209
6210 if ((i + 1) < orderByConditionFields.length) {
6211 if (orderByComparator.isAscending() ^ previous) {
6212 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6213 }
6214 else {
6215 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6216 }
6217 }
6218 else {
6219 if (orderByComparator.isAscending() ^ previous) {
6220 query.append(WHERE_GREATER_THAN);
6221 }
6222 else {
6223 query.append(WHERE_LESSER_THAN);
6224 }
6225 }
6226 }
6227
6228 query.append(ORDER_BY_CLAUSE);
6229
6230 String[] orderByFields = orderByComparator.getOrderByFields();
6231
6232 for (int i = 0; i < orderByFields.length; i++) {
6233 query.append(_ORDER_BY_ENTITY_ALIAS);
6234 query.append(orderByFields[i]);
6235
6236 if ((i + 1) < orderByFields.length) {
6237 if (orderByComparator.isAscending() ^ previous) {
6238 query.append(ORDER_BY_ASC_HAS_NEXT);
6239 }
6240 else {
6241 query.append(ORDER_BY_DESC_HAS_NEXT);
6242 }
6243 }
6244 else {
6245 if (orderByComparator.isAscending() ^ previous) {
6246 query.append(ORDER_BY_ASC);
6247 }
6248 else {
6249 query.append(ORDER_BY_DESC);
6250 }
6251 }
6252 }
6253 }
6254 else {
6255 query.append(RoleModelImpl.ORDER_BY_JPQL);
6256 }
6257
6258 String sql = query.toString();
6259
6260 Query q = session.createQuery(sql);
6261
6262 q.setFirstResult(0);
6263 q.setMaxResults(2);
6264
6265 QueryPos qPos = QueryPos.getInstance(q);
6266
6267 qPos.add(type);
6268
6269 if (bindSubtype) {
6270 qPos.add(subtype);
6271 }
6272
6273 if (orderByComparator != null) {
6274 Object[] values = orderByComparator.getOrderByConditionValues(role);
6275
6276 for (Object value : values) {
6277 qPos.add(value);
6278 }
6279 }
6280
6281 List<Role> list = q.list();
6282
6283 if (list.size() == 2) {
6284 return list.get(1);
6285 }
6286 else {
6287 return null;
6288 }
6289 }
6290
6291
6299 @Override
6300 public List<Role> filterFindByT_S(int type, String subtype)
6301 throws SystemException {
6302 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
6303 QueryUtil.ALL_POS, null);
6304 }
6305
6306
6320 @Override
6321 public List<Role> filterFindByT_S(int type, String subtype, int start,
6322 int end) throws SystemException {
6323 return filterFindByT_S(type, subtype, start, end, null);
6324 }
6325
6326
6341 @Override
6342 public List<Role> filterFindByT_S(int type, String subtype, int start,
6343 int end, OrderByComparator orderByComparator) throws SystemException {
6344 if (!InlineSQLHelperUtil.isEnabled()) {
6345 return findByT_S(type, subtype, start, end, orderByComparator);
6346 }
6347
6348 StringBundler query = null;
6349
6350 if (orderByComparator != null) {
6351 query = new StringBundler(4 +
6352 (orderByComparator.getOrderByFields().length * 3));
6353 }
6354 else {
6355 query = new StringBundler(4);
6356 }
6357
6358 if (getDB().isSupportsInlineDistinct()) {
6359 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6360 }
6361 else {
6362 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6363 }
6364
6365 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
6366
6367 boolean bindSubtype = false;
6368
6369 if (subtype == null) {
6370 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6371 }
6372 else if (subtype.equals(StringPool.BLANK)) {
6373 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6374 }
6375 else {
6376 bindSubtype = true;
6377
6378 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6379 }
6380
6381 if (!getDB().isSupportsInlineDistinct()) {
6382 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6383 }
6384
6385 if (orderByComparator != null) {
6386 if (getDB().isSupportsInlineDistinct()) {
6387 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6388 orderByComparator, true);
6389 }
6390 else {
6391 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6392 orderByComparator, true);
6393 }
6394 }
6395 else {
6396 if (getDB().isSupportsInlineDistinct()) {
6397 query.append(RoleModelImpl.ORDER_BY_JPQL);
6398 }
6399 else {
6400 query.append(RoleModelImpl.ORDER_BY_SQL);
6401 }
6402 }
6403
6404 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6405 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6406
6407 Session session = null;
6408
6409 try {
6410 session = openSession();
6411
6412 SQLQuery q = session.createSQLQuery(sql);
6413
6414 if (getDB().isSupportsInlineDistinct()) {
6415 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6416 }
6417 else {
6418 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6419 }
6420
6421 QueryPos qPos = QueryPos.getInstance(q);
6422
6423 qPos.add(type);
6424
6425 if (bindSubtype) {
6426 qPos.add(subtype);
6427 }
6428
6429 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6430 }
6431 catch (Exception e) {
6432 throw processException(e);
6433 }
6434 finally {
6435 closeSession(session);
6436 }
6437 }
6438
6439
6450 @Override
6451 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
6452 String subtype, OrderByComparator orderByComparator)
6453 throws NoSuchRoleException, SystemException {
6454 if (!InlineSQLHelperUtil.isEnabled()) {
6455 return findByT_S_PrevAndNext(roleId, type, subtype,
6456 orderByComparator);
6457 }
6458
6459 Role role = findByPrimaryKey(roleId);
6460
6461 Session session = null;
6462
6463 try {
6464 session = openSession();
6465
6466 Role[] array = new RoleImpl[3];
6467
6468 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
6469 orderByComparator, true);
6470
6471 array[1] = role;
6472
6473 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
6474 orderByComparator, false);
6475
6476 return array;
6477 }
6478 catch (Exception e) {
6479 throw processException(e);
6480 }
6481 finally {
6482 closeSession(session);
6483 }
6484 }
6485
6486 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
6487 int type, String subtype, OrderByComparator orderByComparator,
6488 boolean previous) {
6489 StringBundler query = null;
6490
6491 if (orderByComparator != null) {
6492 query = new StringBundler(6 +
6493 (orderByComparator.getOrderByFields().length * 6));
6494 }
6495 else {
6496 query = new StringBundler(3);
6497 }
6498
6499 if (getDB().isSupportsInlineDistinct()) {
6500 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6501 }
6502 else {
6503 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6504 }
6505
6506 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
6507
6508 boolean bindSubtype = false;
6509
6510 if (subtype == null) {
6511 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6512 }
6513 else if (subtype.equals(StringPool.BLANK)) {
6514 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6515 }
6516 else {
6517 bindSubtype = true;
6518
6519 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6520 }
6521
6522 if (!getDB().isSupportsInlineDistinct()) {
6523 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6524 }
6525
6526 if (orderByComparator != null) {
6527 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6528
6529 if (orderByConditionFields.length > 0) {
6530 query.append(WHERE_AND);
6531 }
6532
6533 for (int i = 0; i < orderByConditionFields.length; i++) {
6534 if (getDB().isSupportsInlineDistinct()) {
6535 query.append(_ORDER_BY_ENTITY_ALIAS);
6536 }
6537 else {
6538 query.append(_ORDER_BY_ENTITY_TABLE);
6539 }
6540
6541 query.append(orderByConditionFields[i]);
6542
6543 if ((i + 1) < orderByConditionFields.length) {
6544 if (orderByComparator.isAscending() ^ previous) {
6545 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6546 }
6547 else {
6548 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6549 }
6550 }
6551 else {
6552 if (orderByComparator.isAscending() ^ previous) {
6553 query.append(WHERE_GREATER_THAN);
6554 }
6555 else {
6556 query.append(WHERE_LESSER_THAN);
6557 }
6558 }
6559 }
6560
6561 query.append(ORDER_BY_CLAUSE);
6562
6563 String[] orderByFields = orderByComparator.getOrderByFields();
6564
6565 for (int i = 0; i < orderByFields.length; i++) {
6566 if (getDB().isSupportsInlineDistinct()) {
6567 query.append(_ORDER_BY_ENTITY_ALIAS);
6568 }
6569 else {
6570 query.append(_ORDER_BY_ENTITY_TABLE);
6571 }
6572
6573 query.append(orderByFields[i]);
6574
6575 if ((i + 1) < orderByFields.length) {
6576 if (orderByComparator.isAscending() ^ previous) {
6577 query.append(ORDER_BY_ASC_HAS_NEXT);
6578 }
6579 else {
6580 query.append(ORDER_BY_DESC_HAS_NEXT);
6581 }
6582 }
6583 else {
6584 if (orderByComparator.isAscending() ^ previous) {
6585 query.append(ORDER_BY_ASC);
6586 }
6587 else {
6588 query.append(ORDER_BY_DESC);
6589 }
6590 }
6591 }
6592 }
6593 else {
6594 if (getDB().isSupportsInlineDistinct()) {
6595 query.append(RoleModelImpl.ORDER_BY_JPQL);
6596 }
6597 else {
6598 query.append(RoleModelImpl.ORDER_BY_SQL);
6599 }
6600 }
6601
6602 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6603 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6604
6605 SQLQuery q = session.createSQLQuery(sql);
6606
6607 q.setFirstResult(0);
6608 q.setMaxResults(2);
6609
6610 if (getDB().isSupportsInlineDistinct()) {
6611 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6612 }
6613 else {
6614 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6615 }
6616
6617 QueryPos qPos = QueryPos.getInstance(q);
6618
6619 qPos.add(type);
6620
6621 if (bindSubtype) {
6622 qPos.add(subtype);
6623 }
6624
6625 if (orderByComparator != null) {
6626 Object[] values = orderByComparator.getOrderByConditionValues(role);
6627
6628 for (Object value : values) {
6629 qPos.add(value);
6630 }
6631 }
6632
6633 List<Role> list = q.list();
6634
6635 if (list.size() == 2) {
6636 return list.get(1);
6637 }
6638 else {
6639 return null;
6640 }
6641 }
6642
6643
6650 @Override
6651 public void removeByT_S(int type, String subtype) throws SystemException {
6652 for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
6653 QueryUtil.ALL_POS, null)) {
6654 remove(role);
6655 }
6656 }
6657
6658
6666 @Override
6667 public int countByT_S(int type, String subtype) throws SystemException {
6668 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
6669
6670 Object[] finderArgs = new Object[] { type, subtype };
6671
6672 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6673 this);
6674
6675 if (count == null) {
6676 StringBundler query = new StringBundler(3);
6677
6678 query.append(_SQL_COUNT_ROLE_WHERE);
6679
6680 query.append(_FINDER_COLUMN_T_S_TYPE_2);
6681
6682 boolean bindSubtype = false;
6683
6684 if (subtype == null) {
6685 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6686 }
6687 else if (subtype.equals(StringPool.BLANK)) {
6688 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6689 }
6690 else {
6691 bindSubtype = true;
6692
6693 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6694 }
6695
6696 String sql = query.toString();
6697
6698 Session session = null;
6699
6700 try {
6701 session = openSession();
6702
6703 Query q = session.createQuery(sql);
6704
6705 QueryPos qPos = QueryPos.getInstance(q);
6706
6707 qPos.add(type);
6708
6709 if (bindSubtype) {
6710 qPos.add(subtype);
6711 }
6712
6713 count = (Long)q.uniqueResult();
6714
6715 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6716 }
6717 catch (Exception e) {
6718 FinderCacheUtil.removeResult(finderPath, finderArgs);
6719
6720 throw processException(e);
6721 }
6722 finally {
6723 closeSession(session);
6724 }
6725 }
6726
6727 return count.intValue();
6728 }
6729
6730
6738 @Override
6739 public int filterCountByT_S(int type, String subtype)
6740 throws SystemException {
6741 if (!InlineSQLHelperUtil.isEnabled()) {
6742 return countByT_S(type, subtype);
6743 }
6744
6745 StringBundler query = new StringBundler(3);
6746
6747 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
6748
6749 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
6750
6751 boolean bindSubtype = false;
6752
6753 if (subtype == null) {
6754 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6755 }
6756 else if (subtype.equals(StringPool.BLANK)) {
6757 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6758 }
6759 else {
6760 bindSubtype = true;
6761
6762 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6763 }
6764
6765 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6766 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6767
6768 Session session = null;
6769
6770 try {
6771 session = openSession();
6772
6773 SQLQuery q = session.createSQLQuery(sql);
6774
6775 q.addScalar(COUNT_COLUMN_NAME,
6776 com.liferay.portal.kernel.dao.orm.Type.LONG);
6777
6778 QueryPos qPos = QueryPos.getInstance(q);
6779
6780 qPos.add(type);
6781
6782 if (bindSubtype) {
6783 qPos.add(subtype);
6784 }
6785
6786 Long count = (Long)q.uniqueResult();
6787
6788 return count.intValue();
6789 }
6790 catch (Exception e) {
6791 throw processException(e);
6792 }
6793 finally {
6794 closeSession(session);
6795 }
6796 }
6797
6798 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
6799 private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND ";
6800 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
6801 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
6802 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
6803 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
6804 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
6805 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
6806 new String[] {
6807 Long.class.getName(), Long.class.getName(), Long.class.getName()
6808 },
6809 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
6810 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
6811 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
6812 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
6813 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
6814 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
6815 new String[] {
6816 Long.class.getName(), Long.class.getName(), Long.class.getName()
6817 });
6818
6819
6829 @Override
6830 public Role findByC_C_C(long companyId, long classNameId, long classPK)
6831 throws NoSuchRoleException, SystemException {
6832 Role role = fetchByC_C_C(companyId, classNameId, classPK);
6833
6834 if (role == null) {
6835 StringBundler msg = new StringBundler(8);
6836
6837 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6838
6839 msg.append("companyId=");
6840 msg.append(companyId);
6841
6842 msg.append(", classNameId=");
6843 msg.append(classNameId);
6844
6845 msg.append(", classPK=");
6846 msg.append(classPK);
6847
6848 msg.append(StringPool.CLOSE_CURLY_BRACE);
6849
6850 if (_log.isWarnEnabled()) {
6851 _log.warn(msg.toString());
6852 }
6853
6854 throw new NoSuchRoleException(msg.toString());
6855 }
6856
6857 return role;
6858 }
6859
6860
6869 @Override
6870 public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
6871 throws SystemException {
6872 return fetchByC_C_C(companyId, classNameId, classPK, true);
6873 }
6874
6875
6885 @Override
6886 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
6887 boolean retrieveFromCache) throws SystemException {
6888 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
6889
6890 Object result = null;
6891
6892 if (retrieveFromCache) {
6893 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
6894 finderArgs, this);
6895 }
6896
6897 if (result instanceof Role) {
6898 Role role = (Role)result;
6899
6900 if ((companyId != role.getCompanyId()) ||
6901 (classNameId != role.getClassNameId()) ||
6902 (classPK != role.getClassPK())) {
6903 result = null;
6904 }
6905 }
6906
6907 if (result == null) {
6908 StringBundler query = new StringBundler(5);
6909
6910 query.append(_SQL_SELECT_ROLE_WHERE);
6911
6912 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
6913
6914 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
6915
6916 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
6917
6918 String sql = query.toString();
6919
6920 Session session = null;
6921
6922 try {
6923 session = openSession();
6924
6925 Query q = session.createQuery(sql);
6926
6927 QueryPos qPos = QueryPos.getInstance(q);
6928
6929 qPos.add(companyId);
6930
6931 qPos.add(classNameId);
6932
6933 qPos.add(classPK);
6934
6935 List<Role> list = q.list();
6936
6937 if (list.isEmpty()) {
6938 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
6939 finderArgs, list);
6940 }
6941 else {
6942 Role role = list.get(0);
6943
6944 result = role;
6945
6946 cacheResult(role);
6947
6948 if ((role.getCompanyId() != companyId) ||
6949 (role.getClassNameId() != classNameId) ||
6950 (role.getClassPK() != classPK)) {
6951 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
6952 finderArgs, role);
6953 }
6954 }
6955 }
6956 catch (Exception e) {
6957 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
6958 finderArgs);
6959
6960 throw processException(e);
6961 }
6962 finally {
6963 closeSession(session);
6964 }
6965 }
6966
6967 if (result instanceof List<?>) {
6968 return null;
6969 }
6970 else {
6971 return (Role)result;
6972 }
6973 }
6974
6975
6984 @Override
6985 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
6986 throws NoSuchRoleException, SystemException {
6987 Role role = findByC_C_C(companyId, classNameId, classPK);
6988
6989 return remove(role);
6990 }
6991
6992
7001 @Override
7002 public int countByC_C_C(long companyId, long classNameId, long classPK)
7003 throws SystemException {
7004 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
7005
7006 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
7007
7008 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7009 this);
7010
7011 if (count == null) {
7012 StringBundler query = new StringBundler(4);
7013
7014 query.append(_SQL_COUNT_ROLE_WHERE);
7015
7016 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
7017
7018 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
7019
7020 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
7021
7022 String sql = query.toString();
7023
7024 Session session = null;
7025
7026 try {
7027 session = openSession();
7028
7029 Query q = session.createQuery(sql);
7030
7031 QueryPos qPos = QueryPos.getInstance(q);
7032
7033 qPos.add(companyId);
7034
7035 qPos.add(classNameId);
7036
7037 qPos.add(classPK);
7038
7039 count = (Long)q.uniqueResult();
7040
7041 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7042 }
7043 catch (Exception e) {
7044 FinderCacheUtil.removeResult(finderPath, finderArgs);
7045
7046 throw processException(e);
7047 }
7048 finally {
7049 closeSession(session);
7050 }
7051 }
7052
7053 return count.intValue();
7054 }
7055
7056 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
7057 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
7058 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
7059
7060 public RolePersistenceImpl() {
7061 setModelClass(Role.class);
7062 }
7063
7064
7069 @Override
7070 public void cacheResult(Role role) {
7071 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7072 RoleImpl.class, role.getPrimaryKey(), role);
7073
7074 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
7075 new Object[] { role.getCompanyId(), role.getName() }, role);
7076
7077 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
7078 new Object[] {
7079 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
7080 }, role);
7081
7082 role.resetOriginalValues();
7083 }
7084
7085
7090 @Override
7091 public void cacheResult(List<Role> roles) {
7092 for (Role role : roles) {
7093 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7094 RoleImpl.class, role.getPrimaryKey()) == null) {
7095 cacheResult(role);
7096 }
7097 else {
7098 role.resetOriginalValues();
7099 }
7100 }
7101 }
7102
7103
7110 @Override
7111 public void clearCache() {
7112 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7113 CacheRegistryUtil.clear(RoleImpl.class.getName());
7114 }
7115
7116 EntityCacheUtil.clearCache(RoleImpl.class.getName());
7117
7118 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7119 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7120 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7121 }
7122
7123
7130 @Override
7131 public void clearCache(Role role) {
7132 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7133 RoleImpl.class, role.getPrimaryKey());
7134
7135 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7136 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7137
7138 clearUniqueFindersCache(role);
7139 }
7140
7141 @Override
7142 public void clearCache(List<Role> roles) {
7143 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7144 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7145
7146 for (Role role : roles) {
7147 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7148 RoleImpl.class, role.getPrimaryKey());
7149
7150 clearUniqueFindersCache(role);
7151 }
7152 }
7153
7154 protected void cacheUniqueFindersCache(Role role) {
7155 if (role.isNew()) {
7156 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
7157
7158 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
7159 Long.valueOf(1));
7160 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
7161
7162 args = new Object[] {
7163 role.getCompanyId(), role.getClassNameId(),
7164 role.getClassPK()
7165 };
7166
7167 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
7168 Long.valueOf(1));
7169 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
7170 }
7171 else {
7172 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
7173
7174 if ((roleModelImpl.getColumnBitmask() &
7175 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
7176 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
7177
7178 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
7179 Long.valueOf(1));
7180 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
7181 }
7182
7183 if ((roleModelImpl.getColumnBitmask() &
7184 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
7185 Object[] args = new Object[] {
7186 role.getCompanyId(), role.getClassNameId(),
7187 role.getClassPK()
7188 };
7189
7190 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
7191 Long.valueOf(1));
7192 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
7193 }
7194 }
7195 }
7196
7197 protected void clearUniqueFindersCache(Role role) {
7198 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
7199
7200 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
7201
7202 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
7203 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
7204
7205 if ((roleModelImpl.getColumnBitmask() &
7206 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
7207 args = new Object[] {
7208 roleModelImpl.getOriginalCompanyId(),
7209 roleModelImpl.getOriginalName()
7210 };
7211
7212 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
7213 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
7214 }
7215
7216 args = new Object[] {
7217 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
7218 };
7219
7220 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
7221 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
7222
7223 if ((roleModelImpl.getColumnBitmask() &
7224 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
7225 args = new Object[] {
7226 roleModelImpl.getOriginalCompanyId(),
7227 roleModelImpl.getOriginalClassNameId(),
7228 roleModelImpl.getOriginalClassPK()
7229 };
7230
7231 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
7232 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
7233 }
7234 }
7235
7236
7242 @Override
7243 public Role create(long roleId) {
7244 Role role = new RoleImpl();
7245
7246 role.setNew(true);
7247 role.setPrimaryKey(roleId);
7248
7249 String uuid = PortalUUIDUtil.generate();
7250
7251 role.setUuid(uuid);
7252
7253 return role;
7254 }
7255
7256
7264 @Override
7265 public Role remove(long roleId) throws NoSuchRoleException, SystemException {
7266 return remove((Serializable)roleId);
7267 }
7268
7269
7277 @Override
7278 public Role remove(Serializable primaryKey)
7279 throws NoSuchRoleException, SystemException {
7280 Session session = null;
7281
7282 try {
7283 session = openSession();
7284
7285 Role role = (Role)session.get(RoleImpl.class, primaryKey);
7286
7287 if (role == null) {
7288 if (_log.isWarnEnabled()) {
7289 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7290 }
7291
7292 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7293 primaryKey);
7294 }
7295
7296 return remove(role);
7297 }
7298 catch (NoSuchRoleException nsee) {
7299 throw nsee;
7300 }
7301 catch (Exception e) {
7302 throw processException(e);
7303 }
7304 finally {
7305 closeSession(session);
7306 }
7307 }
7308
7309 @Override
7310 protected Role removeImpl(Role role) throws SystemException {
7311 role = toUnwrappedModel(role);
7312
7313 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
7314
7315 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(role.getPrimaryKey());
7316
7317 Session session = null;
7318
7319 try {
7320 session = openSession();
7321
7322 if (!session.contains(role)) {
7323 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
7324 }
7325
7326 if (role != null) {
7327 session.delete(role);
7328 }
7329 }
7330 catch (Exception e) {
7331 throw processException(e);
7332 }
7333 finally {
7334 closeSession(session);
7335 }
7336
7337 if (role != null) {
7338 clearCache(role);
7339 }
7340
7341 return role;
7342 }
7343
7344 @Override
7345 public Role updateImpl(com.liferay.portal.model.Role role)
7346 throws SystemException {
7347 role = toUnwrappedModel(role);
7348
7349 boolean isNew = role.isNew();
7350
7351 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
7352
7353 if (Validator.isNull(role.getUuid())) {
7354 String uuid = PortalUUIDUtil.generate();
7355
7356 role.setUuid(uuid);
7357 }
7358
7359 Session session = null;
7360
7361 try {
7362 session = openSession();
7363
7364 if (role.isNew()) {
7365 session.save(role);
7366
7367 role.setNew(false);
7368 }
7369 else {
7370 session.merge(role);
7371 }
7372 }
7373 catch (Exception e) {
7374 throw processException(e);
7375 }
7376 finally {
7377 closeSession(session);
7378 }
7379
7380 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7381
7382 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
7383 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7384 }
7385
7386 else {
7387 if ((roleModelImpl.getColumnBitmask() &
7388 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7389 Object[] args = new Object[] { roleModelImpl.getOriginalUuid() };
7390
7391 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7392 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7393 args);
7394
7395 args = new Object[] { roleModelImpl.getUuid() };
7396
7397 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7398 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7399 args);
7400 }
7401
7402 if ((roleModelImpl.getColumnBitmask() &
7403 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7404 Object[] args = new Object[] {
7405 roleModelImpl.getOriginalUuid(),
7406 roleModelImpl.getOriginalCompanyId()
7407 };
7408
7409 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7410 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7411 args);
7412
7413 args = new Object[] {
7414 roleModelImpl.getUuid(), roleModelImpl.getCompanyId()
7415 };
7416
7417 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7418 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7419 args);
7420 }
7421
7422 if ((roleModelImpl.getColumnBitmask() &
7423 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7424 Object[] args = new Object[] {
7425 roleModelImpl.getOriginalCompanyId()
7426 };
7427
7428 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7429 args);
7430 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7431 args);
7432
7433 args = new Object[] { roleModelImpl.getCompanyId() };
7434
7435 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7436 args);
7437 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7438 args);
7439 }
7440
7441 if ((roleModelImpl.getColumnBitmask() &
7442 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
7443 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
7444
7445 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
7446 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
7447 args);
7448
7449 args = new Object[] { roleModelImpl.getName() };
7450
7451 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
7452 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
7453 args);
7454 }
7455
7456 if ((roleModelImpl.getColumnBitmask() &
7457 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
7458 Object[] args = new Object[] { roleModelImpl.getOriginalType() };
7459
7460 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
7461 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
7462 args);
7463
7464 args = new Object[] { roleModelImpl.getType() };
7465
7466 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
7467 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
7468 args);
7469 }
7470
7471 if ((roleModelImpl.getColumnBitmask() &
7472 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
7473 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
7474
7475 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
7476 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
7477 args);
7478
7479 args = new Object[] { roleModelImpl.getSubtype() };
7480
7481 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
7482 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
7483 args);
7484 }
7485
7486 if ((roleModelImpl.getColumnBitmask() &
7487 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
7488 Object[] args = new Object[] {
7489 roleModelImpl.getOriginalType(),
7490 roleModelImpl.getOriginalSubtype()
7491 };
7492
7493 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
7494 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
7495 args);
7496
7497 args = new Object[] {
7498 roleModelImpl.getType(), roleModelImpl.getSubtype()
7499 };
7500
7501 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
7502 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
7503 args);
7504 }
7505 }
7506
7507 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7508 RoleImpl.class, role.getPrimaryKey(), role);
7509
7510 clearUniqueFindersCache(role);
7511 cacheUniqueFindersCache(role);
7512
7513 return role;
7514 }
7515
7516 protected Role toUnwrappedModel(Role role) {
7517 if (role instanceof RoleImpl) {
7518 return role;
7519 }
7520
7521 RoleImpl roleImpl = new RoleImpl();
7522
7523 roleImpl.setNew(role.isNew());
7524 roleImpl.setPrimaryKey(role.getPrimaryKey());
7525
7526 roleImpl.setUuid(role.getUuid());
7527 roleImpl.setRoleId(role.getRoleId());
7528 roleImpl.setCompanyId(role.getCompanyId());
7529 roleImpl.setUserId(role.getUserId());
7530 roleImpl.setUserName(role.getUserName());
7531 roleImpl.setCreateDate(role.getCreateDate());
7532 roleImpl.setModifiedDate(role.getModifiedDate());
7533 roleImpl.setClassNameId(role.getClassNameId());
7534 roleImpl.setClassPK(role.getClassPK());
7535 roleImpl.setName(role.getName());
7536 roleImpl.setTitle(role.getTitle());
7537 roleImpl.setDescription(role.getDescription());
7538 roleImpl.setType(role.getType());
7539 roleImpl.setSubtype(role.getSubtype());
7540
7541 return roleImpl;
7542 }
7543
7544
7552 @Override
7553 public Role findByPrimaryKey(Serializable primaryKey)
7554 throws NoSuchRoleException, SystemException {
7555 Role role = fetchByPrimaryKey(primaryKey);
7556
7557 if (role == null) {
7558 if (_log.isWarnEnabled()) {
7559 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7560 }
7561
7562 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7563 primaryKey);
7564 }
7565
7566 return role;
7567 }
7568
7569
7577 @Override
7578 public Role findByPrimaryKey(long roleId)
7579 throws NoSuchRoleException, SystemException {
7580 return findByPrimaryKey((Serializable)roleId);
7581 }
7582
7583
7590 @Override
7591 public Role fetchByPrimaryKey(Serializable primaryKey)
7592 throws SystemException {
7593 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7594 RoleImpl.class, primaryKey);
7595
7596 if (role == _nullRole) {
7597 return null;
7598 }
7599
7600 if (role == null) {
7601 Session session = null;
7602
7603 try {
7604 session = openSession();
7605
7606 role = (Role)session.get(RoleImpl.class, primaryKey);
7607
7608 if (role != null) {
7609 cacheResult(role);
7610 }
7611 else {
7612 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7613 RoleImpl.class, primaryKey, _nullRole);
7614 }
7615 }
7616 catch (Exception e) {
7617 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7618 RoleImpl.class, primaryKey);
7619
7620 throw processException(e);
7621 }
7622 finally {
7623 closeSession(session);
7624 }
7625 }
7626
7627 return role;
7628 }
7629
7630
7637 @Override
7638 public Role fetchByPrimaryKey(long roleId) throws SystemException {
7639 return fetchByPrimaryKey((Serializable)roleId);
7640 }
7641
7642
7648 @Override
7649 public List<Role> findAll() throws SystemException {
7650 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7651 }
7652
7653
7665 @Override
7666 public List<Role> findAll(int start, int end) throws SystemException {
7667 return findAll(start, end, null);
7668 }
7669
7670
7683 @Override
7684 public List<Role> findAll(int start, int end,
7685 OrderByComparator orderByComparator) throws SystemException {
7686 boolean pagination = true;
7687 FinderPath finderPath = null;
7688 Object[] finderArgs = null;
7689
7690 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7691 (orderByComparator == null)) {
7692 pagination = false;
7693 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7694 finderArgs = FINDER_ARGS_EMPTY;
7695 }
7696 else {
7697 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7698 finderArgs = new Object[] { start, end, orderByComparator };
7699 }
7700
7701 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
7702 finderArgs, this);
7703
7704 if (list == null) {
7705 StringBundler query = null;
7706 String sql = null;
7707
7708 if (orderByComparator != null) {
7709 query = new StringBundler(2 +
7710 (orderByComparator.getOrderByFields().length * 3));
7711
7712 query.append(_SQL_SELECT_ROLE);
7713
7714 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7715 orderByComparator);
7716
7717 sql = query.toString();
7718 }
7719 else {
7720 sql = _SQL_SELECT_ROLE;
7721
7722 if (pagination) {
7723 sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
7724 }
7725 }
7726
7727 Session session = null;
7728
7729 try {
7730 session = openSession();
7731
7732 Query q = session.createQuery(sql);
7733
7734 if (!pagination) {
7735 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7736 end, false);
7737
7738 Collections.sort(list);
7739
7740 list = new UnmodifiableList<Role>(list);
7741 }
7742 else {
7743 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7744 end);
7745 }
7746
7747 cacheResult(list);
7748
7749 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7750 }
7751 catch (Exception e) {
7752 FinderCacheUtil.removeResult(finderPath, finderArgs);
7753
7754 throw processException(e);
7755 }
7756 finally {
7757 closeSession(session);
7758 }
7759 }
7760
7761 return list;
7762 }
7763
7764
7769 @Override
7770 public void removeAll() throws SystemException {
7771 for (Role role : findAll()) {
7772 remove(role);
7773 }
7774 }
7775
7776
7782 @Override
7783 public int countAll() throws SystemException {
7784 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7785 FINDER_ARGS_EMPTY, this);
7786
7787 if (count == null) {
7788 Session session = null;
7789
7790 try {
7791 session = openSession();
7792
7793 Query q = session.createQuery(_SQL_COUNT_ROLE);
7794
7795 count = (Long)q.uniqueResult();
7796
7797 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7798 FINDER_ARGS_EMPTY, count);
7799 }
7800 catch (Exception e) {
7801 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7802 FINDER_ARGS_EMPTY);
7803
7804 throw processException(e);
7805 }
7806 finally {
7807 closeSession(session);
7808 }
7809 }
7810
7811 return count.intValue();
7812 }
7813
7814
7821 @Override
7822 public List<com.liferay.portal.model.Group> getGroups(long pk)
7823 throws SystemException {
7824 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7825 }
7826
7827
7840 @Override
7841 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7842 int end) throws SystemException {
7843 return getGroups(pk, start, end, null);
7844 }
7845
7846
7860 @Override
7861 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7862 int end, OrderByComparator orderByComparator) throws SystemException {
7863 return roleToGroupTableMapper.getRightBaseModels(pk, start, end,
7864 orderByComparator);
7865 }
7866
7867
7874 @Override
7875 public int getGroupsSize(long pk) throws SystemException {
7876 long[] pks = roleToGroupTableMapper.getRightPrimaryKeys(pk);
7877
7878 return pks.length;
7879 }
7880
7881
7889 @Override
7890 public boolean containsGroup(long pk, long groupPK)
7891 throws SystemException {
7892 return roleToGroupTableMapper.containsTableMapping(pk, groupPK);
7893 }
7894
7895
7902 @Override
7903 public boolean containsGroups(long pk) throws SystemException {
7904 if (getGroupsSize(pk) > 0) {
7905 return true;
7906 }
7907 else {
7908 return false;
7909 }
7910 }
7911
7912
7919 @Override
7920 public void addGroup(long pk, long groupPK) throws SystemException {
7921 roleToGroupTableMapper.addTableMapping(pk, groupPK);
7922 }
7923
7924
7931 @Override
7932 public void addGroup(long pk, com.liferay.portal.model.Group group)
7933 throws SystemException {
7934 roleToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
7935 }
7936
7937
7944 @Override
7945 public void addGroups(long pk, long[] groupPKs) throws SystemException {
7946 for (long groupPK : groupPKs) {
7947 roleToGroupTableMapper.addTableMapping(pk, groupPK);
7948 }
7949 }
7950
7951
7958 @Override
7959 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
7960 throws SystemException {
7961 for (com.liferay.portal.model.Group group : groups) {
7962 roleToGroupTableMapper.addTableMapping(pk, group.getPrimaryKey());
7963 }
7964 }
7965
7966
7972 @Override
7973 public void clearGroups(long pk) throws SystemException {
7974 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
7975 }
7976
7977
7984 @Override
7985 public void removeGroup(long pk, long groupPK) throws SystemException {
7986 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
7987 }
7988
7989
7996 @Override
7997 public void removeGroup(long pk, com.liferay.portal.model.Group group)
7998 throws SystemException {
7999 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
8000 }
8001
8002
8009 @Override
8010 public void removeGroups(long pk, long[] groupPKs)
8011 throws SystemException {
8012 for (long groupPK : groupPKs) {
8013 roleToGroupTableMapper.deleteTableMapping(pk, groupPK);
8014 }
8015 }
8016
8017
8024 @Override
8025 public void removeGroups(long pk,
8026 List<com.liferay.portal.model.Group> groups) throws SystemException {
8027 for (com.liferay.portal.model.Group group : groups) {
8028 roleToGroupTableMapper.deleteTableMapping(pk, group.getPrimaryKey());
8029 }
8030 }
8031
8032
8039 @Override
8040 public void setGroups(long pk, long[] groupPKs) throws SystemException {
8041 roleToGroupTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
8042
8043 for (Long groupPK : groupPKs) {
8044 roleToGroupTableMapper.addTableMapping(pk, groupPK);
8045 }
8046 }
8047
8048
8055 @Override
8056 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
8057 throws SystemException {
8058 try {
8059 long[] groupPKs = new long[groups.size()];
8060
8061 for (int i = 0; i < groups.size(); i++) {
8062 com.liferay.portal.model.Group group = groups.get(i);
8063
8064 groupPKs[i] = group.getPrimaryKey();
8065 }
8066
8067 setGroups(pk, groupPKs);
8068 }
8069 catch (Exception e) {
8070 throw processException(e);
8071 }
8072 finally {
8073 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8074 }
8075 }
8076
8077
8084 @Override
8085 public List<com.liferay.portal.model.User> getUsers(long pk)
8086 throws SystemException {
8087 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8088 }
8089
8090
8103 @Override
8104 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
8105 int end) throws SystemException {
8106 return getUsers(pk, start, end, null);
8107 }
8108
8109
8123 @Override
8124 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
8125 int end, OrderByComparator orderByComparator) throws SystemException {
8126 return roleToUserTableMapper.getRightBaseModels(pk, start, end,
8127 orderByComparator);
8128 }
8129
8130
8137 @Override
8138 public int getUsersSize(long pk) throws SystemException {
8139 long[] pks = roleToUserTableMapper.getRightPrimaryKeys(pk);
8140
8141 return pks.length;
8142 }
8143
8144
8152 @Override
8153 public boolean containsUser(long pk, long userPK) throws SystemException {
8154 return roleToUserTableMapper.containsTableMapping(pk, userPK);
8155 }
8156
8157
8164 @Override
8165 public boolean containsUsers(long pk) throws SystemException {
8166 if (getUsersSize(pk) > 0) {
8167 return true;
8168 }
8169 else {
8170 return false;
8171 }
8172 }
8173
8174
8181 @Override
8182 public void addUser(long pk, long userPK) throws SystemException {
8183 roleToUserTableMapper.addTableMapping(pk, userPK);
8184 }
8185
8186
8193 @Override
8194 public void addUser(long pk, com.liferay.portal.model.User user)
8195 throws SystemException {
8196 roleToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
8197 }
8198
8199
8206 @Override
8207 public void addUsers(long pk, long[] userPKs) throws SystemException {
8208 for (long userPK : userPKs) {
8209 roleToUserTableMapper.addTableMapping(pk, userPK);
8210 }
8211 }
8212
8213
8220 @Override
8221 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
8222 throws SystemException {
8223 for (com.liferay.portal.model.User user : users) {
8224 roleToUserTableMapper.addTableMapping(pk, user.getPrimaryKey());
8225 }
8226 }
8227
8228
8234 @Override
8235 public void clearUsers(long pk) throws SystemException {
8236 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
8237 }
8238
8239
8246 @Override
8247 public void removeUser(long pk, long userPK) throws SystemException {
8248 roleToUserTableMapper.deleteTableMapping(pk, userPK);
8249 }
8250
8251
8258 @Override
8259 public void removeUser(long pk, com.liferay.portal.model.User user)
8260 throws SystemException {
8261 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
8262 }
8263
8264
8271 @Override
8272 public void removeUsers(long pk, long[] userPKs) throws SystemException {
8273 for (long userPK : userPKs) {
8274 roleToUserTableMapper.deleteTableMapping(pk, userPK);
8275 }
8276 }
8277
8278
8285 @Override
8286 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
8287 throws SystemException {
8288 for (com.liferay.portal.model.User user : users) {
8289 roleToUserTableMapper.deleteTableMapping(pk, user.getPrimaryKey());
8290 }
8291 }
8292
8293
8300 @Override
8301 public void setUsers(long pk, long[] userPKs) throws SystemException {
8302 roleToUserTableMapper.deleteLeftPrimaryKeyTableMappings(pk);
8303
8304 for (Long userPK : userPKs) {
8305 roleToUserTableMapper.addTableMapping(pk, userPK);
8306 }
8307 }
8308
8309
8316 @Override
8317 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
8318 throws SystemException {
8319 try {
8320 long[] userPKs = new long[users.size()];
8321
8322 for (int i = 0; i < users.size(); i++) {
8323 com.liferay.portal.model.User user = users.get(i);
8324
8325 userPKs[i] = user.getPrimaryKey();
8326 }
8327
8328 setUsers(pk, userPKs);
8329 }
8330 catch (Exception e) {
8331 throw processException(e);
8332 }
8333 finally {
8334 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8335 }
8336 }
8337
8338 @Override
8339 protected Set<String> getBadColumnNames() {
8340 return _badColumnNames;
8341 }
8342
8343
8346 public void afterPropertiesSet() {
8347 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
8348 com.liferay.portal.util.PropsUtil.get(
8349 "value.object.listener.com.liferay.portal.model.Role")));
8350
8351 if (listenerClassNames.length > 0) {
8352 try {
8353 List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
8354
8355 for (String listenerClassName : listenerClassNames) {
8356 listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
8357 getClassLoader(), listenerClassName));
8358 }
8359
8360 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8361 }
8362 catch (Exception e) {
8363 _log.error(e);
8364 }
8365 }
8366
8367 roleToGroupTableMapper = TableMapperFactory.getTableMapper("Groups_Roles",
8368 "roleId", "groupId", this, groupPersistence);
8369
8370 roleToUserTableMapper = TableMapperFactory.getTableMapper("Users_Roles",
8371 "roleId", "userId", this, userPersistence);
8372 }
8373
8374 public void destroy() {
8375 EntityCacheUtil.removeCache(RoleImpl.class.getName());
8376 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8377 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8378 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8379 }
8380
8381 @BeanReference(type = GroupPersistence.class)
8382 protected GroupPersistence groupPersistence;
8383 protected TableMapper<Role, com.liferay.portal.model.Group> roleToGroupTableMapper;
8384 @BeanReference(type = UserPersistence.class)
8385 protected UserPersistence userPersistence;
8386 protected TableMapper<Role, com.liferay.portal.model.User> roleToUserTableMapper;
8387 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
8388 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
8389 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
8390 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
8391 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
8392 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
8393 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
8394 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
8395 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
8396 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
8397 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
8398 private static final String _FILTER_ENTITY_ALIAS = "role";
8399 private static final String _FILTER_ENTITY_TABLE = "Role_";
8400 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
8401 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
8402 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
8403 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
8404 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
8405 private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
8406 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
8407 "uuid", "type"
8408 });
8409 private static Role _nullRole = new RoleImpl() {
8410 @Override
8411 public Object clone() {
8412 return this;
8413 }
8414
8415 @Override
8416 public CacheModel<Role> toCacheModel() {
8417 return _nullRoleCacheModel;
8418 }
8419 };
8420
8421 private static CacheModel<Role> _nullRoleCacheModel = new CacheModel<Role>() {
8422 @Override
8423 public Role toEntityModel() {
8424 return _nullRole;
8425 }
8426 };
8427 }