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.jdbc.MappingSqlQuery;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
022 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
023 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
025 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
026 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderPath;
028 import com.liferay.portal.kernel.dao.orm.Query;
029 import com.liferay.portal.kernel.dao.orm.QueryPos;
030 import com.liferay.portal.kernel.dao.orm.QueryUtil;
031 import com.liferay.portal.kernel.dao.orm.SQLQuery;
032 import com.liferay.portal.kernel.dao.orm.Session;
033 import com.liferay.portal.kernel.exception.SystemException;
034 import com.liferay.portal.kernel.log.Log;
035 import com.liferay.portal.kernel.log.LogFactoryUtil;
036 import com.liferay.portal.kernel.util.GetterUtil;
037 import com.liferay.portal.kernel.util.InstanceFactory;
038 import com.liferay.portal.kernel.util.OrderByComparator;
039 import com.liferay.portal.kernel.util.SetUtil;
040 import com.liferay.portal.kernel.util.StringBundler;
041 import com.liferay.portal.kernel.util.StringPool;
042 import com.liferay.portal.kernel.util.StringUtil;
043 import com.liferay.portal.kernel.util.UnmodifiableList;
044 import com.liferay.portal.kernel.util.Validator;
045 import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
046 import com.liferay.portal.model.CacheModel;
047 import com.liferay.portal.model.ModelListener;
048 import com.liferay.portal.model.Role;
049 import com.liferay.portal.model.impl.RoleImpl;
050 import com.liferay.portal.model.impl.RoleModelImpl;
051 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
052 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
053
054 import java.io.Serializable;
055
056 import java.util.ArrayList;
057 import java.util.Collections;
058 import java.util.List;
059 import java.util.Set;
060
061
073 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
074 implements RolePersistence {
075
080 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
081 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List1";
083 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084 ".List2";
085 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
086 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
087 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
088 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
089 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
090 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
092 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
095 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
097 new String[] {
098 String.class.getName(),
099
100 Integer.class.getName(), Integer.class.getName(),
101 OrderByComparator.class.getName()
102 });
103 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
104 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
105 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
106 new String[] { String.class.getName() },
107 RoleModelImpl.UUID_COLUMN_BITMASK |
108 RoleModelImpl.NAME_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
110 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
112 new String[] { String.class.getName() });
113
114
121 @Override
122 public List<Role> findByUuid(String uuid) throws SystemException {
123 return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124 }
125
126
139 @Override
140 public List<Role> findByUuid(String uuid, int start, int end)
141 throws SystemException {
142 return findByUuid(uuid, start, end, null);
143 }
144
145
159 @Override
160 public List<Role> findByUuid(String uuid, int start, int end,
161 OrderByComparator orderByComparator) throws SystemException {
162 boolean pagination = true;
163 FinderPath finderPath = null;
164 Object[] finderArgs = null;
165
166 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
167 (orderByComparator == null)) {
168 pagination = false;
169 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
170 finderArgs = new Object[] { uuid };
171 }
172 else {
173 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
174 finderArgs = new Object[] { uuid, start, end, orderByComparator };
175 }
176
177 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
178 finderArgs, this);
179
180 if ((list != null) && !list.isEmpty()) {
181 for (Role role : list) {
182 if (!Validator.equals(uuid, role.getUuid())) {
183 list = null;
184
185 break;
186 }
187 }
188 }
189
190 if (list == null) {
191 StringBundler query = null;
192
193 if (orderByComparator != null) {
194 query = new StringBundler(3 +
195 (orderByComparator.getOrderByFields().length * 3));
196 }
197 else {
198 query = new StringBundler(3);
199 }
200
201 query.append(_SQL_SELECT_ROLE_WHERE);
202
203 boolean bindUuid = false;
204
205 if (uuid == null) {
206 query.append(_FINDER_COLUMN_UUID_UUID_1);
207 }
208 else if (uuid.equals(StringPool.BLANK)) {
209 query.append(_FINDER_COLUMN_UUID_UUID_3);
210 }
211 else {
212 bindUuid = true;
213
214 query.append(_FINDER_COLUMN_UUID_UUID_2);
215 }
216
217 if (orderByComparator != null) {
218 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
219 orderByComparator);
220 }
221 else
222 if (pagination) {
223 query.append(RoleModelImpl.ORDER_BY_JPQL);
224 }
225
226 String sql = query.toString();
227
228 Session session = null;
229
230 try {
231 session = openSession();
232
233 Query q = session.createQuery(sql);
234
235 QueryPos qPos = QueryPos.getInstance(q);
236
237 if (bindUuid) {
238 qPos.add(uuid);
239 }
240
241 if (!pagination) {
242 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
243 end, false);
244
245 Collections.sort(list);
246
247 list = new UnmodifiableList<Role>(list);
248 }
249 else {
250 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
251 end);
252 }
253
254 cacheResult(list);
255
256 FinderCacheUtil.putResult(finderPath, finderArgs, list);
257 }
258 catch (Exception e) {
259 FinderCacheUtil.removeResult(finderPath, finderArgs);
260
261 throw processException(e);
262 }
263 finally {
264 closeSession(session);
265 }
266 }
267
268 return list;
269 }
270
271
280 @Override
281 public Role findByUuid_First(String uuid,
282 OrderByComparator orderByComparator)
283 throws NoSuchRoleException, SystemException {
284 Role role = fetchByUuid_First(uuid, orderByComparator);
285
286 if (role != null) {
287 return role;
288 }
289
290 StringBundler msg = new StringBundler(4);
291
292 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
293
294 msg.append("uuid=");
295 msg.append(uuid);
296
297 msg.append(StringPool.CLOSE_CURLY_BRACE);
298
299 throw new NoSuchRoleException(msg.toString());
300 }
301
302
310 @Override
311 public Role fetchByUuid_First(String uuid,
312 OrderByComparator orderByComparator) throws SystemException {
313 List<Role> list = findByUuid(uuid, 0, 1, orderByComparator);
314
315 if (!list.isEmpty()) {
316 return list.get(0);
317 }
318
319 return null;
320 }
321
322
331 @Override
332 public Role findByUuid_Last(String uuid, OrderByComparator orderByComparator)
333 throws NoSuchRoleException, SystemException {
334 Role role = fetchByUuid_Last(uuid, orderByComparator);
335
336 if (role != null) {
337 return role;
338 }
339
340 StringBundler msg = new StringBundler(4);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("uuid=");
345 msg.append(uuid);
346
347 msg.append(StringPool.CLOSE_CURLY_BRACE);
348
349 throw new NoSuchRoleException(msg.toString());
350 }
351
352
360 @Override
361 public Role fetchByUuid_Last(String uuid,
362 OrderByComparator orderByComparator) throws SystemException {
363 int count = countByUuid(uuid);
364
365 if (count == 0) {
366 return null;
367 }
368
369 List<Role> list = findByUuid(uuid, count - 1, count, orderByComparator);
370
371 if (!list.isEmpty()) {
372 return list.get(0);
373 }
374
375 return null;
376 }
377
378
388 @Override
389 public Role[] findByUuid_PrevAndNext(long roleId, String uuid,
390 OrderByComparator orderByComparator)
391 throws NoSuchRoleException, SystemException {
392 Role role = findByPrimaryKey(roleId);
393
394 Session session = null;
395
396 try {
397 session = openSession();
398
399 Role[] array = new RoleImpl[3];
400
401 array[0] = getByUuid_PrevAndNext(session, role, uuid,
402 orderByComparator, true);
403
404 array[1] = role;
405
406 array[2] = getByUuid_PrevAndNext(session, role, uuid,
407 orderByComparator, false);
408
409 return array;
410 }
411 catch (Exception e) {
412 throw processException(e);
413 }
414 finally {
415 closeSession(session);
416 }
417 }
418
419 protected Role getByUuid_PrevAndNext(Session session, Role role,
420 String uuid, OrderByComparator orderByComparator, boolean previous) {
421 StringBundler query = null;
422
423 if (orderByComparator != null) {
424 query = new StringBundler(6 +
425 (orderByComparator.getOrderByFields().length * 6));
426 }
427 else {
428 query = new StringBundler(3);
429 }
430
431 query.append(_SQL_SELECT_ROLE_WHERE);
432
433 boolean bindUuid = false;
434
435 if (uuid == null) {
436 query.append(_FINDER_COLUMN_UUID_UUID_1);
437 }
438 else if (uuid.equals(StringPool.BLANK)) {
439 query.append(_FINDER_COLUMN_UUID_UUID_3);
440 }
441 else {
442 bindUuid = true;
443
444 query.append(_FINDER_COLUMN_UUID_UUID_2);
445 }
446
447 if (orderByComparator != null) {
448 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
449
450 if (orderByConditionFields.length > 0) {
451 query.append(WHERE_AND);
452 }
453
454 for (int i = 0; i < orderByConditionFields.length; i++) {
455 query.append(_ORDER_BY_ENTITY_ALIAS);
456 query.append(orderByConditionFields[i]);
457
458 if ((i + 1) < orderByConditionFields.length) {
459 if (orderByComparator.isAscending() ^ previous) {
460 query.append(WHERE_GREATER_THAN_HAS_NEXT);
461 }
462 else {
463 query.append(WHERE_LESSER_THAN_HAS_NEXT);
464 }
465 }
466 else {
467 if (orderByComparator.isAscending() ^ previous) {
468 query.append(WHERE_GREATER_THAN);
469 }
470 else {
471 query.append(WHERE_LESSER_THAN);
472 }
473 }
474 }
475
476 query.append(ORDER_BY_CLAUSE);
477
478 String[] orderByFields = orderByComparator.getOrderByFields();
479
480 for (int i = 0; i < orderByFields.length; i++) {
481 query.append(_ORDER_BY_ENTITY_ALIAS);
482 query.append(orderByFields[i]);
483
484 if ((i + 1) < orderByFields.length) {
485 if (orderByComparator.isAscending() ^ previous) {
486 query.append(ORDER_BY_ASC_HAS_NEXT);
487 }
488 else {
489 query.append(ORDER_BY_DESC_HAS_NEXT);
490 }
491 }
492 else {
493 if (orderByComparator.isAscending() ^ previous) {
494 query.append(ORDER_BY_ASC);
495 }
496 else {
497 query.append(ORDER_BY_DESC);
498 }
499 }
500 }
501 }
502 else {
503 query.append(RoleModelImpl.ORDER_BY_JPQL);
504 }
505
506 String sql = query.toString();
507
508 Query q = session.createQuery(sql);
509
510 q.setFirstResult(0);
511 q.setMaxResults(2);
512
513 QueryPos qPos = QueryPos.getInstance(q);
514
515 if (bindUuid) {
516 qPos.add(uuid);
517 }
518
519 if (orderByComparator != null) {
520 Object[] values = orderByComparator.getOrderByConditionValues(role);
521
522 for (Object value : values) {
523 qPos.add(value);
524 }
525 }
526
527 List<Role> list = q.list();
528
529 if (list.size() == 2) {
530 return list.get(1);
531 }
532 else {
533 return null;
534 }
535 }
536
537
544 @Override
545 public List<Role> filterFindByUuid(String uuid) throws SystemException {
546 return filterFindByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
547 }
548
549
562 @Override
563 public List<Role> filterFindByUuid(String uuid, int start, int end)
564 throws SystemException {
565 return filterFindByUuid(uuid, start, end, null);
566 }
567
568
582 @Override
583 public List<Role> filterFindByUuid(String uuid, int start, int end,
584 OrderByComparator orderByComparator) throws SystemException {
585 if (!InlineSQLHelperUtil.isEnabled()) {
586 return findByUuid(uuid, start, end, orderByComparator);
587 }
588
589 StringBundler query = null;
590
591 if (orderByComparator != null) {
592 query = new StringBundler(3 +
593 (orderByComparator.getOrderByFields().length * 3));
594 }
595 else {
596 query = new StringBundler(3);
597 }
598
599 if (getDB().isSupportsInlineDistinct()) {
600 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
601 }
602 else {
603 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
604 }
605
606 boolean bindUuid = false;
607
608 if (uuid == null) {
609 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
610 }
611 else if (uuid.equals(StringPool.BLANK)) {
612 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
613 }
614 else {
615 bindUuid = true;
616
617 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
618 }
619
620 if (!getDB().isSupportsInlineDistinct()) {
621 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
622 }
623
624 if (orderByComparator != null) {
625 if (getDB().isSupportsInlineDistinct()) {
626 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
627 orderByComparator, true);
628 }
629 else {
630 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
631 orderByComparator, true);
632 }
633 }
634 else {
635 if (getDB().isSupportsInlineDistinct()) {
636 query.append(RoleModelImpl.ORDER_BY_JPQL);
637 }
638 else {
639 query.append(RoleModelImpl.ORDER_BY_SQL);
640 }
641 }
642
643 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
644 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 SQLQuery q = session.createSQLQuery(sql);
652
653 if (getDB().isSupportsInlineDistinct()) {
654 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
655 }
656 else {
657 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
658 }
659
660 QueryPos qPos = QueryPos.getInstance(q);
661
662 if (bindUuid) {
663 qPos.add(uuid);
664 }
665
666 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
667 }
668 catch (Exception e) {
669 throw processException(e);
670 }
671 finally {
672 closeSession(session);
673 }
674 }
675
676
686 @Override
687 public Role[] filterFindByUuid_PrevAndNext(long roleId, String uuid,
688 OrderByComparator orderByComparator)
689 throws NoSuchRoleException, SystemException {
690 if (!InlineSQLHelperUtil.isEnabled()) {
691 return findByUuid_PrevAndNext(roleId, uuid, orderByComparator);
692 }
693
694 Role role = findByPrimaryKey(roleId);
695
696 Session session = null;
697
698 try {
699 session = openSession();
700
701 Role[] array = new RoleImpl[3];
702
703 array[0] = filterGetByUuid_PrevAndNext(session, role, uuid,
704 orderByComparator, true);
705
706 array[1] = role;
707
708 array[2] = filterGetByUuid_PrevAndNext(session, role, uuid,
709 orderByComparator, false);
710
711 return array;
712 }
713 catch (Exception e) {
714 throw processException(e);
715 }
716 finally {
717 closeSession(session);
718 }
719 }
720
721 protected Role filterGetByUuid_PrevAndNext(Session session, Role role,
722 String uuid, OrderByComparator orderByComparator, boolean previous) {
723 StringBundler query = null;
724
725 if (orderByComparator != null) {
726 query = new StringBundler(6 +
727 (orderByComparator.getOrderByFields().length * 6));
728 }
729 else {
730 query = new StringBundler(3);
731 }
732
733 if (getDB().isSupportsInlineDistinct()) {
734 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
735 }
736 else {
737 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
738 }
739
740 boolean bindUuid = false;
741
742 if (uuid == null) {
743 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
744 }
745 else if (uuid.equals(StringPool.BLANK)) {
746 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
747 }
748 else {
749 bindUuid = true;
750
751 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
752 }
753
754 if (!getDB().isSupportsInlineDistinct()) {
755 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
756 }
757
758 if (orderByComparator != null) {
759 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
760
761 if (orderByConditionFields.length > 0) {
762 query.append(WHERE_AND);
763 }
764
765 for (int i = 0; i < orderByConditionFields.length; i++) {
766 if (getDB().isSupportsInlineDistinct()) {
767 query.append(_ORDER_BY_ENTITY_ALIAS);
768 }
769 else {
770 query.append(_ORDER_BY_ENTITY_TABLE);
771 }
772
773 query.append(orderByConditionFields[i]);
774
775 if ((i + 1) < orderByConditionFields.length) {
776 if (orderByComparator.isAscending() ^ previous) {
777 query.append(WHERE_GREATER_THAN_HAS_NEXT);
778 }
779 else {
780 query.append(WHERE_LESSER_THAN_HAS_NEXT);
781 }
782 }
783 else {
784 if (orderByComparator.isAscending() ^ previous) {
785 query.append(WHERE_GREATER_THAN);
786 }
787 else {
788 query.append(WHERE_LESSER_THAN);
789 }
790 }
791 }
792
793 query.append(ORDER_BY_CLAUSE);
794
795 String[] orderByFields = orderByComparator.getOrderByFields();
796
797 for (int i = 0; i < orderByFields.length; i++) {
798 if (getDB().isSupportsInlineDistinct()) {
799 query.append(_ORDER_BY_ENTITY_ALIAS);
800 }
801 else {
802 query.append(_ORDER_BY_ENTITY_TABLE);
803 }
804
805 query.append(orderByFields[i]);
806
807 if ((i + 1) < orderByFields.length) {
808 if (orderByComparator.isAscending() ^ previous) {
809 query.append(ORDER_BY_ASC_HAS_NEXT);
810 }
811 else {
812 query.append(ORDER_BY_DESC_HAS_NEXT);
813 }
814 }
815 else {
816 if (orderByComparator.isAscending() ^ previous) {
817 query.append(ORDER_BY_ASC);
818 }
819 else {
820 query.append(ORDER_BY_DESC);
821 }
822 }
823 }
824 }
825 else {
826 if (getDB().isSupportsInlineDistinct()) {
827 query.append(RoleModelImpl.ORDER_BY_JPQL);
828 }
829 else {
830 query.append(RoleModelImpl.ORDER_BY_SQL);
831 }
832 }
833
834 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
835 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
836
837 SQLQuery q = session.createSQLQuery(sql);
838
839 q.setFirstResult(0);
840 q.setMaxResults(2);
841
842 if (getDB().isSupportsInlineDistinct()) {
843 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
844 }
845 else {
846 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
847 }
848
849 QueryPos qPos = QueryPos.getInstance(q);
850
851 if (bindUuid) {
852 qPos.add(uuid);
853 }
854
855 if (orderByComparator != null) {
856 Object[] values = orderByComparator.getOrderByConditionValues(role);
857
858 for (Object value : values) {
859 qPos.add(value);
860 }
861 }
862
863 List<Role> list = q.list();
864
865 if (list.size() == 2) {
866 return list.get(1);
867 }
868 else {
869 return null;
870 }
871 }
872
873
879 @Override
880 public void removeByUuid(String uuid) throws SystemException {
881 for (Role role : findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
882 null)) {
883 remove(role);
884 }
885 }
886
887
894 @Override
895 public int countByUuid(String uuid) throws SystemException {
896 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
897
898 Object[] finderArgs = new Object[] { uuid };
899
900 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
901 this);
902
903 if (count == null) {
904 StringBundler query = new StringBundler(2);
905
906 query.append(_SQL_COUNT_ROLE_WHERE);
907
908 boolean bindUuid = false;
909
910 if (uuid == null) {
911 query.append(_FINDER_COLUMN_UUID_UUID_1);
912 }
913 else if (uuid.equals(StringPool.BLANK)) {
914 query.append(_FINDER_COLUMN_UUID_UUID_3);
915 }
916 else {
917 bindUuid = true;
918
919 query.append(_FINDER_COLUMN_UUID_UUID_2);
920 }
921
922 String sql = query.toString();
923
924 Session session = null;
925
926 try {
927 session = openSession();
928
929 Query q = session.createQuery(sql);
930
931 QueryPos qPos = QueryPos.getInstance(q);
932
933 if (bindUuid) {
934 qPos.add(uuid);
935 }
936
937 count = (Long)q.uniqueResult();
938
939 FinderCacheUtil.putResult(finderPath, finderArgs, count);
940 }
941 catch (Exception e) {
942 FinderCacheUtil.removeResult(finderPath, finderArgs);
943
944 throw processException(e);
945 }
946 finally {
947 closeSession(session);
948 }
949 }
950
951 return count.intValue();
952 }
953
954
961 @Override
962 public int filterCountByUuid(String uuid) throws SystemException {
963 if (!InlineSQLHelperUtil.isEnabled()) {
964 return countByUuid(uuid);
965 }
966
967 StringBundler query = new StringBundler(2);
968
969 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
970
971 boolean bindUuid = false;
972
973 if (uuid == null) {
974 query.append(_FINDER_COLUMN_UUID_UUID_1_SQL);
975 }
976 else if (uuid.equals(StringPool.BLANK)) {
977 query.append(_FINDER_COLUMN_UUID_UUID_3_SQL);
978 }
979 else {
980 bindUuid = true;
981
982 query.append(_FINDER_COLUMN_UUID_UUID_2_SQL);
983 }
984
985 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
986 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
987
988 Session session = null;
989
990 try {
991 session = openSession();
992
993 SQLQuery q = session.createSQLQuery(sql);
994
995 q.addScalar(COUNT_COLUMN_NAME,
996 com.liferay.portal.kernel.dao.orm.Type.LONG);
997
998 QueryPos qPos = QueryPos.getInstance(q);
999
1000 if (bindUuid) {
1001 qPos.add(uuid);
1002 }
1003
1004 Long count = (Long)q.uniqueResult();
1005
1006 return count.intValue();
1007 }
1008 catch (Exception e) {
1009 throw processException(e);
1010 }
1011 finally {
1012 closeSession(session);
1013 }
1014 }
1015
1016 private static final String _FINDER_COLUMN_UUID_UUID_1 = "role.uuid IS NULL";
1017 private static final String _FINDER_COLUMN_UUID_UUID_2 = "role.uuid = ?";
1018 private static final String _FINDER_COLUMN_UUID_UUID_3 = "(role.uuid IS NULL OR role.uuid = '')";
1019 private static final String _FINDER_COLUMN_UUID_UUID_1_SQL = "role.uuid_ IS NULL";
1020 private static final String _FINDER_COLUMN_UUID_UUID_2_SQL = "role.uuid_ = ?";
1021 private static final String _FINDER_COLUMN_UUID_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '')";
1022 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1023 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1024 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
1025 new String[] {
1026 String.class.getName(), Long.class.getName(),
1027
1028 Integer.class.getName(), Integer.class.getName(),
1029 OrderByComparator.class.getName()
1030 });
1031 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
1032 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1033 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1034 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
1035 new String[] { String.class.getName(), Long.class.getName() },
1036 RoleModelImpl.UUID_COLUMN_BITMASK |
1037 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
1038 RoleModelImpl.NAME_COLUMN_BITMASK);
1039 public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1040 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1041 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
1042 new String[] { String.class.getName(), Long.class.getName() });
1043
1044
1052 @Override
1053 public List<Role> findByUuid_C(String uuid, long companyId)
1054 throws SystemException {
1055 return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1056 QueryUtil.ALL_POS, null);
1057 }
1058
1059
1073 @Override
1074 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1075 int end) throws SystemException {
1076 return findByUuid_C(uuid, companyId, start, end, null);
1077 }
1078
1079
1094 @Override
1095 public List<Role> findByUuid_C(String uuid, long companyId, int start,
1096 int end, OrderByComparator orderByComparator) throws SystemException {
1097 boolean pagination = true;
1098 FinderPath finderPath = null;
1099 Object[] finderArgs = null;
1100
1101 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1102 (orderByComparator == null)) {
1103 pagination = false;
1104 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1105 finderArgs = new Object[] { uuid, companyId };
1106 }
1107 else {
1108 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1109 finderArgs = new Object[] {
1110 uuid, companyId,
1111
1112 start, end, orderByComparator
1113 };
1114 }
1115
1116 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1117 finderArgs, this);
1118
1119 if ((list != null) && !list.isEmpty()) {
1120 for (Role role : list) {
1121 if (!Validator.equals(uuid, role.getUuid()) ||
1122 (companyId != role.getCompanyId())) {
1123 list = null;
1124
1125 break;
1126 }
1127 }
1128 }
1129
1130 if (list == null) {
1131 StringBundler query = null;
1132
1133 if (orderByComparator != null) {
1134 query = new StringBundler(4 +
1135 (orderByComparator.getOrderByFields().length * 3));
1136 }
1137 else {
1138 query = new StringBundler(4);
1139 }
1140
1141 query.append(_SQL_SELECT_ROLE_WHERE);
1142
1143 boolean bindUuid = false;
1144
1145 if (uuid == null) {
1146 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1147 }
1148 else if (uuid.equals(StringPool.BLANK)) {
1149 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1150 }
1151 else {
1152 bindUuid = true;
1153
1154 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1155 }
1156
1157 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1158
1159 if (orderByComparator != null) {
1160 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1161 orderByComparator);
1162 }
1163 else
1164 if (pagination) {
1165 query.append(RoleModelImpl.ORDER_BY_JPQL);
1166 }
1167
1168 String sql = query.toString();
1169
1170 Session session = null;
1171
1172 try {
1173 session = openSession();
1174
1175 Query q = session.createQuery(sql);
1176
1177 QueryPos qPos = QueryPos.getInstance(q);
1178
1179 if (bindUuid) {
1180 qPos.add(uuid);
1181 }
1182
1183 qPos.add(companyId);
1184
1185 if (!pagination) {
1186 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1187 end, false);
1188
1189 Collections.sort(list);
1190
1191 list = new UnmodifiableList<Role>(list);
1192 }
1193 else {
1194 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1195 end);
1196 }
1197
1198 cacheResult(list);
1199
1200 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1201 }
1202 catch (Exception e) {
1203 FinderCacheUtil.removeResult(finderPath, finderArgs);
1204
1205 throw processException(e);
1206 }
1207 finally {
1208 closeSession(session);
1209 }
1210 }
1211
1212 return list;
1213 }
1214
1215
1225 @Override
1226 public Role findByUuid_C_First(String uuid, long companyId,
1227 OrderByComparator orderByComparator)
1228 throws NoSuchRoleException, SystemException {
1229 Role role = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1230
1231 if (role != null) {
1232 return role;
1233 }
1234
1235 StringBundler msg = new StringBundler(6);
1236
1237 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1238
1239 msg.append("uuid=");
1240 msg.append(uuid);
1241
1242 msg.append(", companyId=");
1243 msg.append(companyId);
1244
1245 msg.append(StringPool.CLOSE_CURLY_BRACE);
1246
1247 throw new NoSuchRoleException(msg.toString());
1248 }
1249
1250
1259 @Override
1260 public Role fetchByUuid_C_First(String uuid, long companyId,
1261 OrderByComparator orderByComparator) throws SystemException {
1262 List<Role> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1263
1264 if (!list.isEmpty()) {
1265 return list.get(0);
1266 }
1267
1268 return null;
1269 }
1270
1271
1281 @Override
1282 public Role findByUuid_C_Last(String uuid, long companyId,
1283 OrderByComparator orderByComparator)
1284 throws NoSuchRoleException, SystemException {
1285 Role role = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1286
1287 if (role != null) {
1288 return role;
1289 }
1290
1291 StringBundler msg = new StringBundler(6);
1292
1293 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1294
1295 msg.append("uuid=");
1296 msg.append(uuid);
1297
1298 msg.append(", companyId=");
1299 msg.append(companyId);
1300
1301 msg.append(StringPool.CLOSE_CURLY_BRACE);
1302
1303 throw new NoSuchRoleException(msg.toString());
1304 }
1305
1306
1315 @Override
1316 public Role fetchByUuid_C_Last(String uuid, long companyId,
1317 OrderByComparator orderByComparator) throws SystemException {
1318 int count = countByUuid_C(uuid, companyId);
1319
1320 if (count == 0) {
1321 return null;
1322 }
1323
1324 List<Role> list = findByUuid_C(uuid, companyId, count - 1, count,
1325 orderByComparator);
1326
1327 if (!list.isEmpty()) {
1328 return list.get(0);
1329 }
1330
1331 return null;
1332 }
1333
1334
1345 @Override
1346 public Role[] findByUuid_C_PrevAndNext(long roleId, String uuid,
1347 long companyId, OrderByComparator orderByComparator)
1348 throws NoSuchRoleException, SystemException {
1349 Role role = findByPrimaryKey(roleId);
1350
1351 Session session = null;
1352
1353 try {
1354 session = openSession();
1355
1356 Role[] array = new RoleImpl[3];
1357
1358 array[0] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1359 orderByComparator, true);
1360
1361 array[1] = role;
1362
1363 array[2] = getByUuid_C_PrevAndNext(session, role, uuid, companyId,
1364 orderByComparator, false);
1365
1366 return array;
1367 }
1368 catch (Exception e) {
1369 throw processException(e);
1370 }
1371 finally {
1372 closeSession(session);
1373 }
1374 }
1375
1376 protected Role getByUuid_C_PrevAndNext(Session session, Role role,
1377 String uuid, long companyId, OrderByComparator orderByComparator,
1378 boolean previous) {
1379 StringBundler query = null;
1380
1381 if (orderByComparator != null) {
1382 query = new StringBundler(6 +
1383 (orderByComparator.getOrderByFields().length * 6));
1384 }
1385 else {
1386 query = new StringBundler(3);
1387 }
1388
1389 query.append(_SQL_SELECT_ROLE_WHERE);
1390
1391 boolean bindUuid = false;
1392
1393 if (uuid == null) {
1394 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1395 }
1396 else if (uuid.equals(StringPool.BLANK)) {
1397 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1398 }
1399 else {
1400 bindUuid = true;
1401
1402 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1403 }
1404
1405 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1406
1407 if (orderByComparator != null) {
1408 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1409
1410 if (orderByConditionFields.length > 0) {
1411 query.append(WHERE_AND);
1412 }
1413
1414 for (int i = 0; i < orderByConditionFields.length; i++) {
1415 query.append(_ORDER_BY_ENTITY_ALIAS);
1416 query.append(orderByConditionFields[i]);
1417
1418 if ((i + 1) < orderByConditionFields.length) {
1419 if (orderByComparator.isAscending() ^ previous) {
1420 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1421 }
1422 else {
1423 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1424 }
1425 }
1426 else {
1427 if (orderByComparator.isAscending() ^ previous) {
1428 query.append(WHERE_GREATER_THAN);
1429 }
1430 else {
1431 query.append(WHERE_LESSER_THAN);
1432 }
1433 }
1434 }
1435
1436 query.append(ORDER_BY_CLAUSE);
1437
1438 String[] orderByFields = orderByComparator.getOrderByFields();
1439
1440 for (int i = 0; i < orderByFields.length; i++) {
1441 query.append(_ORDER_BY_ENTITY_ALIAS);
1442 query.append(orderByFields[i]);
1443
1444 if ((i + 1) < orderByFields.length) {
1445 if (orderByComparator.isAscending() ^ previous) {
1446 query.append(ORDER_BY_ASC_HAS_NEXT);
1447 }
1448 else {
1449 query.append(ORDER_BY_DESC_HAS_NEXT);
1450 }
1451 }
1452 else {
1453 if (orderByComparator.isAscending() ^ previous) {
1454 query.append(ORDER_BY_ASC);
1455 }
1456 else {
1457 query.append(ORDER_BY_DESC);
1458 }
1459 }
1460 }
1461 }
1462 else {
1463 query.append(RoleModelImpl.ORDER_BY_JPQL);
1464 }
1465
1466 String sql = query.toString();
1467
1468 Query q = session.createQuery(sql);
1469
1470 q.setFirstResult(0);
1471 q.setMaxResults(2);
1472
1473 QueryPos qPos = QueryPos.getInstance(q);
1474
1475 if (bindUuid) {
1476 qPos.add(uuid);
1477 }
1478
1479 qPos.add(companyId);
1480
1481 if (orderByComparator != null) {
1482 Object[] values = orderByComparator.getOrderByConditionValues(role);
1483
1484 for (Object value : values) {
1485 qPos.add(value);
1486 }
1487 }
1488
1489 List<Role> list = q.list();
1490
1491 if (list.size() == 2) {
1492 return list.get(1);
1493 }
1494 else {
1495 return null;
1496 }
1497 }
1498
1499
1507 @Override
1508 public List<Role> filterFindByUuid_C(String uuid, long companyId)
1509 throws SystemException {
1510 return filterFindByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1511 QueryUtil.ALL_POS, null);
1512 }
1513
1514
1528 @Override
1529 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1530 int start, int end) throws SystemException {
1531 return filterFindByUuid_C(uuid, companyId, start, end, null);
1532 }
1533
1534
1549 @Override
1550 public List<Role> filterFindByUuid_C(String uuid, long companyId,
1551 int start, int end, OrderByComparator orderByComparator)
1552 throws SystemException {
1553 if (!InlineSQLHelperUtil.isEnabled()) {
1554 return findByUuid_C(uuid, companyId, start, end, orderByComparator);
1555 }
1556
1557 StringBundler query = null;
1558
1559 if (orderByComparator != null) {
1560 query = new StringBundler(4 +
1561 (orderByComparator.getOrderByFields().length * 3));
1562 }
1563 else {
1564 query = new StringBundler(4);
1565 }
1566
1567 if (getDB().isSupportsInlineDistinct()) {
1568 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1569 }
1570 else {
1571 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1572 }
1573
1574 boolean bindUuid = false;
1575
1576 if (uuid == null) {
1577 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1578 }
1579 else if (uuid.equals(StringPool.BLANK)) {
1580 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1581 }
1582 else {
1583 bindUuid = true;
1584
1585 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1586 }
1587
1588 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1589
1590 if (!getDB().isSupportsInlineDistinct()) {
1591 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1592 }
1593
1594 if (orderByComparator != null) {
1595 if (getDB().isSupportsInlineDistinct()) {
1596 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1597 orderByComparator, true);
1598 }
1599 else {
1600 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1601 orderByComparator, true);
1602 }
1603 }
1604 else {
1605 if (getDB().isSupportsInlineDistinct()) {
1606 query.append(RoleModelImpl.ORDER_BY_JPQL);
1607 }
1608 else {
1609 query.append(RoleModelImpl.ORDER_BY_SQL);
1610 }
1611 }
1612
1613 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1614 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1615
1616 Session session = null;
1617
1618 try {
1619 session = openSession();
1620
1621 SQLQuery q = session.createSQLQuery(sql);
1622
1623 if (getDB().isSupportsInlineDistinct()) {
1624 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1625 }
1626 else {
1627 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1628 }
1629
1630 QueryPos qPos = QueryPos.getInstance(q);
1631
1632 if (bindUuid) {
1633 qPos.add(uuid);
1634 }
1635
1636 qPos.add(companyId);
1637
1638 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1639 }
1640 catch (Exception e) {
1641 throw processException(e);
1642 }
1643 finally {
1644 closeSession(session);
1645 }
1646 }
1647
1648
1659 @Override
1660 public Role[] filterFindByUuid_C_PrevAndNext(long roleId, String uuid,
1661 long companyId, OrderByComparator orderByComparator)
1662 throws NoSuchRoleException, SystemException {
1663 if (!InlineSQLHelperUtil.isEnabled()) {
1664 return findByUuid_C_PrevAndNext(roleId, uuid, companyId,
1665 orderByComparator);
1666 }
1667
1668 Role role = findByPrimaryKey(roleId);
1669
1670 Session session = null;
1671
1672 try {
1673 session = openSession();
1674
1675 Role[] array = new RoleImpl[3];
1676
1677 array[0] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1678 companyId, orderByComparator, true);
1679
1680 array[1] = role;
1681
1682 array[2] = filterGetByUuid_C_PrevAndNext(session, role, uuid,
1683 companyId, orderByComparator, false);
1684
1685 return array;
1686 }
1687 catch (Exception e) {
1688 throw processException(e);
1689 }
1690 finally {
1691 closeSession(session);
1692 }
1693 }
1694
1695 protected Role filterGetByUuid_C_PrevAndNext(Session session, Role role,
1696 String uuid, long companyId, OrderByComparator orderByComparator,
1697 boolean previous) {
1698 StringBundler query = null;
1699
1700 if (orderByComparator != null) {
1701 query = new StringBundler(6 +
1702 (orderByComparator.getOrderByFields().length * 6));
1703 }
1704 else {
1705 query = new StringBundler(3);
1706 }
1707
1708 if (getDB().isSupportsInlineDistinct()) {
1709 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1710 }
1711 else {
1712 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1713 }
1714
1715 boolean bindUuid = false;
1716
1717 if (uuid == null) {
1718 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1719 }
1720 else if (uuid.equals(StringPool.BLANK)) {
1721 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1722 }
1723 else {
1724 bindUuid = true;
1725
1726 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1727 }
1728
1729 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1730
1731 if (!getDB().isSupportsInlineDistinct()) {
1732 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1733 }
1734
1735 if (orderByComparator != null) {
1736 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1737
1738 if (orderByConditionFields.length > 0) {
1739 query.append(WHERE_AND);
1740 }
1741
1742 for (int i = 0; i < orderByConditionFields.length; i++) {
1743 if (getDB().isSupportsInlineDistinct()) {
1744 query.append(_ORDER_BY_ENTITY_ALIAS);
1745 }
1746 else {
1747 query.append(_ORDER_BY_ENTITY_TABLE);
1748 }
1749
1750 query.append(orderByConditionFields[i]);
1751
1752 if ((i + 1) < orderByConditionFields.length) {
1753 if (orderByComparator.isAscending() ^ previous) {
1754 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1755 }
1756 else {
1757 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1758 }
1759 }
1760 else {
1761 if (orderByComparator.isAscending() ^ previous) {
1762 query.append(WHERE_GREATER_THAN);
1763 }
1764 else {
1765 query.append(WHERE_LESSER_THAN);
1766 }
1767 }
1768 }
1769
1770 query.append(ORDER_BY_CLAUSE);
1771
1772 String[] orderByFields = orderByComparator.getOrderByFields();
1773
1774 for (int i = 0; i < orderByFields.length; i++) {
1775 if (getDB().isSupportsInlineDistinct()) {
1776 query.append(_ORDER_BY_ENTITY_ALIAS);
1777 }
1778 else {
1779 query.append(_ORDER_BY_ENTITY_TABLE);
1780 }
1781
1782 query.append(orderByFields[i]);
1783
1784 if ((i + 1) < orderByFields.length) {
1785 if (orderByComparator.isAscending() ^ previous) {
1786 query.append(ORDER_BY_ASC_HAS_NEXT);
1787 }
1788 else {
1789 query.append(ORDER_BY_DESC_HAS_NEXT);
1790 }
1791 }
1792 else {
1793 if (orderByComparator.isAscending() ^ previous) {
1794 query.append(ORDER_BY_ASC);
1795 }
1796 else {
1797 query.append(ORDER_BY_DESC);
1798 }
1799 }
1800 }
1801 }
1802 else {
1803 if (getDB().isSupportsInlineDistinct()) {
1804 query.append(RoleModelImpl.ORDER_BY_JPQL);
1805 }
1806 else {
1807 query.append(RoleModelImpl.ORDER_BY_SQL);
1808 }
1809 }
1810
1811 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1812 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1813
1814 SQLQuery q = session.createSQLQuery(sql);
1815
1816 q.setFirstResult(0);
1817 q.setMaxResults(2);
1818
1819 if (getDB().isSupportsInlineDistinct()) {
1820 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1821 }
1822 else {
1823 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1824 }
1825
1826 QueryPos qPos = QueryPos.getInstance(q);
1827
1828 if (bindUuid) {
1829 qPos.add(uuid);
1830 }
1831
1832 qPos.add(companyId);
1833
1834 if (orderByComparator != null) {
1835 Object[] values = orderByComparator.getOrderByConditionValues(role);
1836
1837 for (Object value : values) {
1838 qPos.add(value);
1839 }
1840 }
1841
1842 List<Role> list = q.list();
1843
1844 if (list.size() == 2) {
1845 return list.get(1);
1846 }
1847 else {
1848 return null;
1849 }
1850 }
1851
1852
1859 @Override
1860 public void removeByUuid_C(String uuid, long companyId)
1861 throws SystemException {
1862 for (Role role : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1863 QueryUtil.ALL_POS, null)) {
1864 remove(role);
1865 }
1866 }
1867
1868
1876 @Override
1877 public int countByUuid_C(String uuid, long companyId)
1878 throws SystemException {
1879 FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1880
1881 Object[] finderArgs = new Object[] { uuid, companyId };
1882
1883 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1884 this);
1885
1886 if (count == null) {
1887 StringBundler query = new StringBundler(3);
1888
1889 query.append(_SQL_COUNT_ROLE_WHERE);
1890
1891 boolean bindUuid = false;
1892
1893 if (uuid == null) {
1894 query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1895 }
1896 else if (uuid.equals(StringPool.BLANK)) {
1897 query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1898 }
1899 else {
1900 bindUuid = true;
1901
1902 query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1903 }
1904
1905 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1906
1907 String sql = query.toString();
1908
1909 Session session = null;
1910
1911 try {
1912 session = openSession();
1913
1914 Query q = session.createQuery(sql);
1915
1916 QueryPos qPos = QueryPos.getInstance(q);
1917
1918 if (bindUuid) {
1919 qPos.add(uuid);
1920 }
1921
1922 qPos.add(companyId);
1923
1924 count = (Long)q.uniqueResult();
1925
1926 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1927 }
1928 catch (Exception e) {
1929 FinderCacheUtil.removeResult(finderPath, finderArgs);
1930
1931 throw processException(e);
1932 }
1933 finally {
1934 closeSession(session);
1935 }
1936 }
1937
1938 return count.intValue();
1939 }
1940
1941
1949 @Override
1950 public int filterCountByUuid_C(String uuid, long companyId)
1951 throws SystemException {
1952 if (!InlineSQLHelperUtil.isEnabled()) {
1953 return countByUuid_C(uuid, companyId);
1954 }
1955
1956 StringBundler query = new StringBundler(3);
1957
1958 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1959
1960 boolean bindUuid = false;
1961
1962 if (uuid == null) {
1963 query.append(_FINDER_COLUMN_UUID_C_UUID_1_SQL);
1964 }
1965 else if (uuid.equals(StringPool.BLANK)) {
1966 query.append(_FINDER_COLUMN_UUID_C_UUID_3_SQL);
1967 }
1968 else {
1969 bindUuid = true;
1970
1971 query.append(_FINDER_COLUMN_UUID_C_UUID_2_SQL);
1972 }
1973
1974 query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1975
1976 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1977 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1978
1979 Session session = null;
1980
1981 try {
1982 session = openSession();
1983
1984 SQLQuery q = session.createSQLQuery(sql);
1985
1986 q.addScalar(COUNT_COLUMN_NAME,
1987 com.liferay.portal.kernel.dao.orm.Type.LONG);
1988
1989 QueryPos qPos = QueryPos.getInstance(q);
1990
1991 if (bindUuid) {
1992 qPos.add(uuid);
1993 }
1994
1995 qPos.add(companyId);
1996
1997 Long count = (Long)q.uniqueResult();
1998
1999 return count.intValue();
2000 }
2001 catch (Exception e) {
2002 throw processException(e);
2003 }
2004 finally {
2005 closeSession(session);
2006 }
2007 }
2008
2009 private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "role.uuid IS NULL AND ";
2010 private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "role.uuid = ? AND ";
2011 private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(role.uuid IS NULL OR role.uuid = '') AND ";
2012 private static final String _FINDER_COLUMN_UUID_C_UUID_1_SQL = "role.uuid_ IS NULL AND ";
2013 private static final String _FINDER_COLUMN_UUID_C_UUID_2_SQL = "role.uuid_ = ? AND ";
2014 private static final String _FINDER_COLUMN_UUID_C_UUID_3_SQL = "(role.uuid_ IS NULL OR role.uuid_ = '') AND ";
2015 private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "role.companyId = ?";
2016 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2017 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2018 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2019 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2020 new String[] {
2021 Long.class.getName(),
2022
2023 Integer.class.getName(), Integer.class.getName(),
2024 OrderByComparator.class.getName()
2025 });
2026 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2027 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2028 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2029 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2030 new String[] { Long.class.getName() },
2031 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
2032 RoleModelImpl.NAME_COLUMN_BITMASK);
2033 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2034 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2035 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2036 new String[] { Long.class.getName() });
2037
2038
2045 @Override
2046 public List<Role> findByCompanyId(long companyId) throws SystemException {
2047 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2048 null);
2049 }
2050
2051
2064 @Override
2065 public List<Role> findByCompanyId(long companyId, int start, int end)
2066 throws SystemException {
2067 return findByCompanyId(companyId, start, end, null);
2068 }
2069
2070
2084 @Override
2085 public List<Role> findByCompanyId(long companyId, int start, int end,
2086 OrderByComparator orderByComparator) throws SystemException {
2087 boolean pagination = true;
2088 FinderPath finderPath = null;
2089 Object[] finderArgs = null;
2090
2091 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2092 (orderByComparator == null)) {
2093 pagination = false;
2094 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2095 finderArgs = new Object[] { companyId };
2096 }
2097 else {
2098 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2099 finderArgs = new Object[] { companyId, start, end, orderByComparator };
2100 }
2101
2102 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2103 finderArgs, this);
2104
2105 if ((list != null) && !list.isEmpty()) {
2106 for (Role role : list) {
2107 if ((companyId != role.getCompanyId())) {
2108 list = null;
2109
2110 break;
2111 }
2112 }
2113 }
2114
2115 if (list == null) {
2116 StringBundler query = null;
2117
2118 if (orderByComparator != null) {
2119 query = new StringBundler(3 +
2120 (orderByComparator.getOrderByFields().length * 3));
2121 }
2122 else {
2123 query = new StringBundler(3);
2124 }
2125
2126 query.append(_SQL_SELECT_ROLE_WHERE);
2127
2128 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2129
2130 if (orderByComparator != null) {
2131 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2132 orderByComparator);
2133 }
2134 else
2135 if (pagination) {
2136 query.append(RoleModelImpl.ORDER_BY_JPQL);
2137 }
2138
2139 String sql = query.toString();
2140
2141 Session session = null;
2142
2143 try {
2144 session = openSession();
2145
2146 Query q = session.createQuery(sql);
2147
2148 QueryPos qPos = QueryPos.getInstance(q);
2149
2150 qPos.add(companyId);
2151
2152 if (!pagination) {
2153 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2154 end, false);
2155
2156 Collections.sort(list);
2157
2158 list = new UnmodifiableList<Role>(list);
2159 }
2160 else {
2161 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2162 end);
2163 }
2164
2165 cacheResult(list);
2166
2167 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2168 }
2169 catch (Exception e) {
2170 FinderCacheUtil.removeResult(finderPath, finderArgs);
2171
2172 throw processException(e);
2173 }
2174 finally {
2175 closeSession(session);
2176 }
2177 }
2178
2179 return list;
2180 }
2181
2182
2191 @Override
2192 public Role findByCompanyId_First(long companyId,
2193 OrderByComparator orderByComparator)
2194 throws NoSuchRoleException, SystemException {
2195 Role role = fetchByCompanyId_First(companyId, orderByComparator);
2196
2197 if (role != null) {
2198 return role;
2199 }
2200
2201 StringBundler msg = new StringBundler(4);
2202
2203 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2204
2205 msg.append("companyId=");
2206 msg.append(companyId);
2207
2208 msg.append(StringPool.CLOSE_CURLY_BRACE);
2209
2210 throw new NoSuchRoleException(msg.toString());
2211 }
2212
2213
2221 @Override
2222 public Role fetchByCompanyId_First(long companyId,
2223 OrderByComparator orderByComparator) throws SystemException {
2224 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
2225
2226 if (!list.isEmpty()) {
2227 return list.get(0);
2228 }
2229
2230 return null;
2231 }
2232
2233
2242 @Override
2243 public Role findByCompanyId_Last(long companyId,
2244 OrderByComparator orderByComparator)
2245 throws NoSuchRoleException, SystemException {
2246 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
2247
2248 if (role != null) {
2249 return role;
2250 }
2251
2252 StringBundler msg = new StringBundler(4);
2253
2254 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2255
2256 msg.append("companyId=");
2257 msg.append(companyId);
2258
2259 msg.append(StringPool.CLOSE_CURLY_BRACE);
2260
2261 throw new NoSuchRoleException(msg.toString());
2262 }
2263
2264
2272 @Override
2273 public Role fetchByCompanyId_Last(long companyId,
2274 OrderByComparator orderByComparator) throws SystemException {
2275 int count = countByCompanyId(companyId);
2276
2277 if (count == 0) {
2278 return null;
2279 }
2280
2281 List<Role> list = findByCompanyId(companyId, count - 1, count,
2282 orderByComparator);
2283
2284 if (!list.isEmpty()) {
2285 return list.get(0);
2286 }
2287
2288 return null;
2289 }
2290
2291
2301 @Override
2302 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
2303 OrderByComparator orderByComparator)
2304 throws NoSuchRoleException, SystemException {
2305 Role role = findByPrimaryKey(roleId);
2306
2307 Session session = null;
2308
2309 try {
2310 session = openSession();
2311
2312 Role[] array = new RoleImpl[3];
2313
2314 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
2315 orderByComparator, true);
2316
2317 array[1] = role;
2318
2319 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
2320 orderByComparator, false);
2321
2322 return array;
2323 }
2324 catch (Exception e) {
2325 throw processException(e);
2326 }
2327 finally {
2328 closeSession(session);
2329 }
2330 }
2331
2332 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
2333 long companyId, OrderByComparator orderByComparator, boolean previous) {
2334 StringBundler query = null;
2335
2336 if (orderByComparator != null) {
2337 query = new StringBundler(6 +
2338 (orderByComparator.getOrderByFields().length * 6));
2339 }
2340 else {
2341 query = new StringBundler(3);
2342 }
2343
2344 query.append(_SQL_SELECT_ROLE_WHERE);
2345
2346 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2347
2348 if (orderByComparator != null) {
2349 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2350
2351 if (orderByConditionFields.length > 0) {
2352 query.append(WHERE_AND);
2353 }
2354
2355 for (int i = 0; i < orderByConditionFields.length; i++) {
2356 query.append(_ORDER_BY_ENTITY_ALIAS);
2357 query.append(orderByConditionFields[i]);
2358
2359 if ((i + 1) < orderByConditionFields.length) {
2360 if (orderByComparator.isAscending() ^ previous) {
2361 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2362 }
2363 else {
2364 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2365 }
2366 }
2367 else {
2368 if (orderByComparator.isAscending() ^ previous) {
2369 query.append(WHERE_GREATER_THAN);
2370 }
2371 else {
2372 query.append(WHERE_LESSER_THAN);
2373 }
2374 }
2375 }
2376
2377 query.append(ORDER_BY_CLAUSE);
2378
2379 String[] orderByFields = orderByComparator.getOrderByFields();
2380
2381 for (int i = 0; i < orderByFields.length; i++) {
2382 query.append(_ORDER_BY_ENTITY_ALIAS);
2383 query.append(orderByFields[i]);
2384
2385 if ((i + 1) < orderByFields.length) {
2386 if (orderByComparator.isAscending() ^ previous) {
2387 query.append(ORDER_BY_ASC_HAS_NEXT);
2388 }
2389 else {
2390 query.append(ORDER_BY_DESC_HAS_NEXT);
2391 }
2392 }
2393 else {
2394 if (orderByComparator.isAscending() ^ previous) {
2395 query.append(ORDER_BY_ASC);
2396 }
2397 else {
2398 query.append(ORDER_BY_DESC);
2399 }
2400 }
2401 }
2402 }
2403 else {
2404 query.append(RoleModelImpl.ORDER_BY_JPQL);
2405 }
2406
2407 String sql = query.toString();
2408
2409 Query q = session.createQuery(sql);
2410
2411 q.setFirstResult(0);
2412 q.setMaxResults(2);
2413
2414 QueryPos qPos = QueryPos.getInstance(q);
2415
2416 qPos.add(companyId);
2417
2418 if (orderByComparator != null) {
2419 Object[] values = orderByComparator.getOrderByConditionValues(role);
2420
2421 for (Object value : values) {
2422 qPos.add(value);
2423 }
2424 }
2425
2426 List<Role> list = q.list();
2427
2428 if (list.size() == 2) {
2429 return list.get(1);
2430 }
2431 else {
2432 return null;
2433 }
2434 }
2435
2436
2443 @Override
2444 public List<Role> filterFindByCompanyId(long companyId)
2445 throws SystemException {
2446 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
2447 QueryUtil.ALL_POS, null);
2448 }
2449
2450
2463 @Override
2464 public List<Role> filterFindByCompanyId(long companyId, int start, int end)
2465 throws SystemException {
2466 return filterFindByCompanyId(companyId, start, end, null);
2467 }
2468
2469
2483 @Override
2484 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
2485 OrderByComparator orderByComparator) throws SystemException {
2486 if (!InlineSQLHelperUtil.isEnabled()) {
2487 return findByCompanyId(companyId, start, end, orderByComparator);
2488 }
2489
2490 StringBundler query = null;
2491
2492 if (orderByComparator != null) {
2493 query = new StringBundler(3 +
2494 (orderByComparator.getOrderByFields().length * 3));
2495 }
2496 else {
2497 query = new StringBundler(3);
2498 }
2499
2500 if (getDB().isSupportsInlineDistinct()) {
2501 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2502 }
2503 else {
2504 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2505 }
2506
2507 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2508
2509 if (!getDB().isSupportsInlineDistinct()) {
2510 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2511 }
2512
2513 if (orderByComparator != null) {
2514 if (getDB().isSupportsInlineDistinct()) {
2515 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2516 orderByComparator, true);
2517 }
2518 else {
2519 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2520 orderByComparator, true);
2521 }
2522 }
2523 else {
2524 if (getDB().isSupportsInlineDistinct()) {
2525 query.append(RoleModelImpl.ORDER_BY_JPQL);
2526 }
2527 else {
2528 query.append(RoleModelImpl.ORDER_BY_SQL);
2529 }
2530 }
2531
2532 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2533 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2534
2535 Session session = null;
2536
2537 try {
2538 session = openSession();
2539
2540 SQLQuery q = session.createSQLQuery(sql);
2541
2542 if (getDB().isSupportsInlineDistinct()) {
2543 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2544 }
2545 else {
2546 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2547 }
2548
2549 QueryPos qPos = QueryPos.getInstance(q);
2550
2551 qPos.add(companyId);
2552
2553 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2554 }
2555 catch (Exception e) {
2556 throw processException(e);
2557 }
2558 finally {
2559 closeSession(session);
2560 }
2561 }
2562
2563
2573 @Override
2574 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
2575 long companyId, OrderByComparator orderByComparator)
2576 throws NoSuchRoleException, SystemException {
2577 if (!InlineSQLHelperUtil.isEnabled()) {
2578 return findByCompanyId_PrevAndNext(roleId, companyId,
2579 orderByComparator);
2580 }
2581
2582 Role role = findByPrimaryKey(roleId);
2583
2584 Session session = null;
2585
2586 try {
2587 session = openSession();
2588
2589 Role[] array = new RoleImpl[3];
2590
2591 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
2592 companyId, orderByComparator, true);
2593
2594 array[1] = role;
2595
2596 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
2597 companyId, orderByComparator, false);
2598
2599 return array;
2600 }
2601 catch (Exception e) {
2602 throw processException(e);
2603 }
2604 finally {
2605 closeSession(session);
2606 }
2607 }
2608
2609 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
2610 long companyId, OrderByComparator orderByComparator, boolean previous) {
2611 StringBundler query = null;
2612
2613 if (orderByComparator != null) {
2614 query = new StringBundler(6 +
2615 (orderByComparator.getOrderByFields().length * 6));
2616 }
2617 else {
2618 query = new StringBundler(3);
2619 }
2620
2621 if (getDB().isSupportsInlineDistinct()) {
2622 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2623 }
2624 else {
2625 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2626 }
2627
2628 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2629
2630 if (!getDB().isSupportsInlineDistinct()) {
2631 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2632 }
2633
2634 if (orderByComparator != null) {
2635 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2636
2637 if (orderByConditionFields.length > 0) {
2638 query.append(WHERE_AND);
2639 }
2640
2641 for (int i = 0; i < orderByConditionFields.length; i++) {
2642 if (getDB().isSupportsInlineDistinct()) {
2643 query.append(_ORDER_BY_ENTITY_ALIAS);
2644 }
2645 else {
2646 query.append(_ORDER_BY_ENTITY_TABLE);
2647 }
2648
2649 query.append(orderByConditionFields[i]);
2650
2651 if ((i + 1) < orderByConditionFields.length) {
2652 if (orderByComparator.isAscending() ^ previous) {
2653 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2654 }
2655 else {
2656 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2657 }
2658 }
2659 else {
2660 if (orderByComparator.isAscending() ^ previous) {
2661 query.append(WHERE_GREATER_THAN);
2662 }
2663 else {
2664 query.append(WHERE_LESSER_THAN);
2665 }
2666 }
2667 }
2668
2669 query.append(ORDER_BY_CLAUSE);
2670
2671 String[] orderByFields = orderByComparator.getOrderByFields();
2672
2673 for (int i = 0; i < orderByFields.length; i++) {
2674 if (getDB().isSupportsInlineDistinct()) {
2675 query.append(_ORDER_BY_ENTITY_ALIAS);
2676 }
2677 else {
2678 query.append(_ORDER_BY_ENTITY_TABLE);
2679 }
2680
2681 query.append(orderByFields[i]);
2682
2683 if ((i + 1) < orderByFields.length) {
2684 if (orderByComparator.isAscending() ^ previous) {
2685 query.append(ORDER_BY_ASC_HAS_NEXT);
2686 }
2687 else {
2688 query.append(ORDER_BY_DESC_HAS_NEXT);
2689 }
2690 }
2691 else {
2692 if (orderByComparator.isAscending() ^ previous) {
2693 query.append(ORDER_BY_ASC);
2694 }
2695 else {
2696 query.append(ORDER_BY_DESC);
2697 }
2698 }
2699 }
2700 }
2701 else {
2702 if (getDB().isSupportsInlineDistinct()) {
2703 query.append(RoleModelImpl.ORDER_BY_JPQL);
2704 }
2705 else {
2706 query.append(RoleModelImpl.ORDER_BY_SQL);
2707 }
2708 }
2709
2710 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2711 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2712
2713 SQLQuery q = session.createSQLQuery(sql);
2714
2715 q.setFirstResult(0);
2716 q.setMaxResults(2);
2717
2718 if (getDB().isSupportsInlineDistinct()) {
2719 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2720 }
2721 else {
2722 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2723 }
2724
2725 QueryPos qPos = QueryPos.getInstance(q);
2726
2727 qPos.add(companyId);
2728
2729 if (orderByComparator != null) {
2730 Object[] values = orderByComparator.getOrderByConditionValues(role);
2731
2732 for (Object value : values) {
2733 qPos.add(value);
2734 }
2735 }
2736
2737 List<Role> list = q.list();
2738
2739 if (list.size() == 2) {
2740 return list.get(1);
2741 }
2742 else {
2743 return null;
2744 }
2745 }
2746
2747
2753 @Override
2754 public void removeByCompanyId(long companyId) throws SystemException {
2755 for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
2756 QueryUtil.ALL_POS, null)) {
2757 remove(role);
2758 }
2759 }
2760
2761
2768 @Override
2769 public int countByCompanyId(long companyId) throws SystemException {
2770 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2771
2772 Object[] finderArgs = new Object[] { companyId };
2773
2774 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2775 this);
2776
2777 if (count == null) {
2778 StringBundler query = new StringBundler(2);
2779
2780 query.append(_SQL_COUNT_ROLE_WHERE);
2781
2782 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2783
2784 String sql = query.toString();
2785
2786 Session session = null;
2787
2788 try {
2789 session = openSession();
2790
2791 Query q = session.createQuery(sql);
2792
2793 QueryPos qPos = QueryPos.getInstance(q);
2794
2795 qPos.add(companyId);
2796
2797 count = (Long)q.uniqueResult();
2798
2799 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2800 }
2801 catch (Exception e) {
2802 FinderCacheUtil.removeResult(finderPath, finderArgs);
2803
2804 throw processException(e);
2805 }
2806 finally {
2807 closeSession(session);
2808 }
2809 }
2810
2811 return count.intValue();
2812 }
2813
2814
2821 @Override
2822 public int filterCountByCompanyId(long companyId) throws SystemException {
2823 if (!InlineSQLHelperUtil.isEnabled()) {
2824 return countByCompanyId(companyId);
2825 }
2826
2827 StringBundler query = new StringBundler(2);
2828
2829 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2830
2831 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2832
2833 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2834 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2835
2836 Session session = null;
2837
2838 try {
2839 session = openSession();
2840
2841 SQLQuery q = session.createSQLQuery(sql);
2842
2843 q.addScalar(COUNT_COLUMN_NAME,
2844 com.liferay.portal.kernel.dao.orm.Type.LONG);
2845
2846 QueryPos qPos = QueryPos.getInstance(q);
2847
2848 qPos.add(companyId);
2849
2850 Long count = (Long)q.uniqueResult();
2851
2852 return count.intValue();
2853 }
2854 catch (Exception e) {
2855 throw processException(e);
2856 }
2857 finally {
2858 closeSession(session);
2859 }
2860 }
2861
2862 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
2863 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2864 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2865 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
2866 new String[] {
2867 String.class.getName(),
2868
2869 Integer.class.getName(), Integer.class.getName(),
2870 OrderByComparator.class.getName()
2871 });
2872 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2873 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2874 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
2875 new String[] { String.class.getName() },
2876 RoleModelImpl.NAME_COLUMN_BITMASK);
2877 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2878 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2879 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
2880 new String[] { String.class.getName() });
2881
2882
2889 @Override
2890 public List<Role> findByName(String name) throws SystemException {
2891 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2892 }
2893
2894
2907 @Override
2908 public List<Role> findByName(String name, int start, int end)
2909 throws SystemException {
2910 return findByName(name, start, end, null);
2911 }
2912
2913
2927 @Override
2928 public List<Role> findByName(String name, int start, int end,
2929 OrderByComparator orderByComparator) throws SystemException {
2930 boolean pagination = true;
2931 FinderPath finderPath = null;
2932 Object[] finderArgs = null;
2933
2934 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2935 (orderByComparator == null)) {
2936 pagination = false;
2937 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
2938 finderArgs = new Object[] { name };
2939 }
2940 else {
2941 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
2942 finderArgs = new Object[] { name, start, end, orderByComparator };
2943 }
2944
2945 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
2946 finderArgs, this);
2947
2948 if ((list != null) && !list.isEmpty()) {
2949 for (Role role : list) {
2950 if (!Validator.equals(name, role.getName())) {
2951 list = null;
2952
2953 break;
2954 }
2955 }
2956 }
2957
2958 if (list == null) {
2959 StringBundler query = null;
2960
2961 if (orderByComparator != null) {
2962 query = new StringBundler(3 +
2963 (orderByComparator.getOrderByFields().length * 3));
2964 }
2965 else {
2966 query = new StringBundler(3);
2967 }
2968
2969 query.append(_SQL_SELECT_ROLE_WHERE);
2970
2971 boolean bindName = false;
2972
2973 if (name == null) {
2974 query.append(_FINDER_COLUMN_NAME_NAME_1);
2975 }
2976 else if (name.equals(StringPool.BLANK)) {
2977 query.append(_FINDER_COLUMN_NAME_NAME_3);
2978 }
2979 else {
2980 bindName = true;
2981
2982 query.append(_FINDER_COLUMN_NAME_NAME_2);
2983 }
2984
2985 if (orderByComparator != null) {
2986 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2987 orderByComparator);
2988 }
2989 else
2990 if (pagination) {
2991 query.append(RoleModelImpl.ORDER_BY_JPQL);
2992 }
2993
2994 String sql = query.toString();
2995
2996 Session session = null;
2997
2998 try {
2999 session = openSession();
3000
3001 Query q = session.createQuery(sql);
3002
3003 QueryPos qPos = QueryPos.getInstance(q);
3004
3005 if (bindName) {
3006 qPos.add(name);
3007 }
3008
3009 if (!pagination) {
3010 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3011 end, false);
3012
3013 Collections.sort(list);
3014
3015 list = new UnmodifiableList<Role>(list);
3016 }
3017 else {
3018 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3019 end);
3020 }
3021
3022 cacheResult(list);
3023
3024 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3025 }
3026 catch (Exception e) {
3027 FinderCacheUtil.removeResult(finderPath, finderArgs);
3028
3029 throw processException(e);
3030 }
3031 finally {
3032 closeSession(session);
3033 }
3034 }
3035
3036 return list;
3037 }
3038
3039
3048 @Override
3049 public Role findByName_First(String name,
3050 OrderByComparator orderByComparator)
3051 throws NoSuchRoleException, SystemException {
3052 Role role = fetchByName_First(name, orderByComparator);
3053
3054 if (role != null) {
3055 return role;
3056 }
3057
3058 StringBundler msg = new StringBundler(4);
3059
3060 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3061
3062 msg.append("name=");
3063 msg.append(name);
3064
3065 msg.append(StringPool.CLOSE_CURLY_BRACE);
3066
3067 throw new NoSuchRoleException(msg.toString());
3068 }
3069
3070
3078 @Override
3079 public Role fetchByName_First(String name,
3080 OrderByComparator orderByComparator) throws SystemException {
3081 List<Role> list = findByName(name, 0, 1, orderByComparator);
3082
3083 if (!list.isEmpty()) {
3084 return list.get(0);
3085 }
3086
3087 return null;
3088 }
3089
3090
3099 @Override
3100 public Role findByName_Last(String name, OrderByComparator orderByComparator)
3101 throws NoSuchRoleException, SystemException {
3102 Role role = fetchByName_Last(name, orderByComparator);
3103
3104 if (role != null) {
3105 return role;
3106 }
3107
3108 StringBundler msg = new StringBundler(4);
3109
3110 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3111
3112 msg.append("name=");
3113 msg.append(name);
3114
3115 msg.append(StringPool.CLOSE_CURLY_BRACE);
3116
3117 throw new NoSuchRoleException(msg.toString());
3118 }
3119
3120
3128 @Override
3129 public Role fetchByName_Last(String name,
3130 OrderByComparator orderByComparator) throws SystemException {
3131 int count = countByName(name);
3132
3133 if (count == 0) {
3134 return null;
3135 }
3136
3137 List<Role> list = findByName(name, count - 1, count, orderByComparator);
3138
3139 if (!list.isEmpty()) {
3140 return list.get(0);
3141 }
3142
3143 return null;
3144 }
3145
3146
3156 @Override
3157 public Role[] findByName_PrevAndNext(long roleId, String name,
3158 OrderByComparator orderByComparator)
3159 throws NoSuchRoleException, SystemException {
3160 Role role = findByPrimaryKey(roleId);
3161
3162 Session session = null;
3163
3164 try {
3165 session = openSession();
3166
3167 Role[] array = new RoleImpl[3];
3168
3169 array[0] = getByName_PrevAndNext(session, role, name,
3170 orderByComparator, true);
3171
3172 array[1] = role;
3173
3174 array[2] = getByName_PrevAndNext(session, role, name,
3175 orderByComparator, false);
3176
3177 return array;
3178 }
3179 catch (Exception e) {
3180 throw processException(e);
3181 }
3182 finally {
3183 closeSession(session);
3184 }
3185 }
3186
3187 protected Role getByName_PrevAndNext(Session session, Role role,
3188 String name, OrderByComparator orderByComparator, boolean previous) {
3189 StringBundler query = null;
3190
3191 if (orderByComparator != null) {
3192 query = new StringBundler(6 +
3193 (orderByComparator.getOrderByFields().length * 6));
3194 }
3195 else {
3196 query = new StringBundler(3);
3197 }
3198
3199 query.append(_SQL_SELECT_ROLE_WHERE);
3200
3201 boolean bindName = false;
3202
3203 if (name == null) {
3204 query.append(_FINDER_COLUMN_NAME_NAME_1);
3205 }
3206 else if (name.equals(StringPool.BLANK)) {
3207 query.append(_FINDER_COLUMN_NAME_NAME_3);
3208 }
3209 else {
3210 bindName = true;
3211
3212 query.append(_FINDER_COLUMN_NAME_NAME_2);
3213 }
3214
3215 if (orderByComparator != null) {
3216 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3217
3218 if (orderByConditionFields.length > 0) {
3219 query.append(WHERE_AND);
3220 }
3221
3222 for (int i = 0; i < orderByConditionFields.length; i++) {
3223 query.append(_ORDER_BY_ENTITY_ALIAS);
3224 query.append(orderByConditionFields[i]);
3225
3226 if ((i + 1) < orderByConditionFields.length) {
3227 if (orderByComparator.isAscending() ^ previous) {
3228 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3229 }
3230 else {
3231 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3232 }
3233 }
3234 else {
3235 if (orderByComparator.isAscending() ^ previous) {
3236 query.append(WHERE_GREATER_THAN);
3237 }
3238 else {
3239 query.append(WHERE_LESSER_THAN);
3240 }
3241 }
3242 }
3243
3244 query.append(ORDER_BY_CLAUSE);
3245
3246 String[] orderByFields = orderByComparator.getOrderByFields();
3247
3248 for (int i = 0; i < orderByFields.length; i++) {
3249 query.append(_ORDER_BY_ENTITY_ALIAS);
3250 query.append(orderByFields[i]);
3251
3252 if ((i + 1) < orderByFields.length) {
3253 if (orderByComparator.isAscending() ^ previous) {
3254 query.append(ORDER_BY_ASC_HAS_NEXT);
3255 }
3256 else {
3257 query.append(ORDER_BY_DESC_HAS_NEXT);
3258 }
3259 }
3260 else {
3261 if (orderByComparator.isAscending() ^ previous) {
3262 query.append(ORDER_BY_ASC);
3263 }
3264 else {
3265 query.append(ORDER_BY_DESC);
3266 }
3267 }
3268 }
3269 }
3270 else {
3271 query.append(RoleModelImpl.ORDER_BY_JPQL);
3272 }
3273
3274 String sql = query.toString();
3275
3276 Query q = session.createQuery(sql);
3277
3278 q.setFirstResult(0);
3279 q.setMaxResults(2);
3280
3281 QueryPos qPos = QueryPos.getInstance(q);
3282
3283 if (bindName) {
3284 qPos.add(name);
3285 }
3286
3287 if (orderByComparator != null) {
3288 Object[] values = orderByComparator.getOrderByConditionValues(role);
3289
3290 for (Object value : values) {
3291 qPos.add(value);
3292 }
3293 }
3294
3295 List<Role> list = q.list();
3296
3297 if (list.size() == 2) {
3298 return list.get(1);
3299 }
3300 else {
3301 return null;
3302 }
3303 }
3304
3305
3312 @Override
3313 public List<Role> filterFindByName(String name) throws SystemException {
3314 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3315 }
3316
3317
3330 @Override
3331 public List<Role> filterFindByName(String name, int start, int end)
3332 throws SystemException {
3333 return filterFindByName(name, start, end, null);
3334 }
3335
3336
3350 @Override
3351 public List<Role> filterFindByName(String name, int start, int end,
3352 OrderByComparator orderByComparator) throws SystemException {
3353 if (!InlineSQLHelperUtil.isEnabled()) {
3354 return findByName(name, start, end, orderByComparator);
3355 }
3356
3357 StringBundler query = null;
3358
3359 if (orderByComparator != null) {
3360 query = new StringBundler(3 +
3361 (orderByComparator.getOrderByFields().length * 3));
3362 }
3363 else {
3364 query = new StringBundler(3);
3365 }
3366
3367 if (getDB().isSupportsInlineDistinct()) {
3368 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3369 }
3370 else {
3371 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3372 }
3373
3374 boolean bindName = false;
3375
3376 if (name == null) {
3377 query.append(_FINDER_COLUMN_NAME_NAME_1);
3378 }
3379 else if (name.equals(StringPool.BLANK)) {
3380 query.append(_FINDER_COLUMN_NAME_NAME_3);
3381 }
3382 else {
3383 bindName = true;
3384
3385 query.append(_FINDER_COLUMN_NAME_NAME_2);
3386 }
3387
3388 if (!getDB().isSupportsInlineDistinct()) {
3389 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3390 }
3391
3392 if (orderByComparator != null) {
3393 if (getDB().isSupportsInlineDistinct()) {
3394 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3395 orderByComparator, true);
3396 }
3397 else {
3398 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3399 orderByComparator, true);
3400 }
3401 }
3402 else {
3403 if (getDB().isSupportsInlineDistinct()) {
3404 query.append(RoleModelImpl.ORDER_BY_JPQL);
3405 }
3406 else {
3407 query.append(RoleModelImpl.ORDER_BY_SQL);
3408 }
3409 }
3410
3411 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3412 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3413
3414 Session session = null;
3415
3416 try {
3417 session = openSession();
3418
3419 SQLQuery q = session.createSQLQuery(sql);
3420
3421 if (getDB().isSupportsInlineDistinct()) {
3422 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3423 }
3424 else {
3425 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3426 }
3427
3428 QueryPos qPos = QueryPos.getInstance(q);
3429
3430 if (bindName) {
3431 qPos.add(name);
3432 }
3433
3434 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3435 }
3436 catch (Exception e) {
3437 throw processException(e);
3438 }
3439 finally {
3440 closeSession(session);
3441 }
3442 }
3443
3444
3454 @Override
3455 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
3456 OrderByComparator orderByComparator)
3457 throws NoSuchRoleException, SystemException {
3458 if (!InlineSQLHelperUtil.isEnabled()) {
3459 return findByName_PrevAndNext(roleId, name, orderByComparator);
3460 }
3461
3462 Role role = findByPrimaryKey(roleId);
3463
3464 Session session = null;
3465
3466 try {
3467 session = openSession();
3468
3469 Role[] array = new RoleImpl[3];
3470
3471 array[0] = filterGetByName_PrevAndNext(session, role, name,
3472 orderByComparator, true);
3473
3474 array[1] = role;
3475
3476 array[2] = filterGetByName_PrevAndNext(session, role, name,
3477 orderByComparator, false);
3478
3479 return array;
3480 }
3481 catch (Exception e) {
3482 throw processException(e);
3483 }
3484 finally {
3485 closeSession(session);
3486 }
3487 }
3488
3489 protected Role filterGetByName_PrevAndNext(Session session, Role role,
3490 String name, OrderByComparator orderByComparator, boolean previous) {
3491 StringBundler query = null;
3492
3493 if (orderByComparator != null) {
3494 query = new StringBundler(6 +
3495 (orderByComparator.getOrderByFields().length * 6));
3496 }
3497 else {
3498 query = new StringBundler(3);
3499 }
3500
3501 if (getDB().isSupportsInlineDistinct()) {
3502 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3503 }
3504 else {
3505 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3506 }
3507
3508 boolean bindName = false;
3509
3510 if (name == null) {
3511 query.append(_FINDER_COLUMN_NAME_NAME_1);
3512 }
3513 else if (name.equals(StringPool.BLANK)) {
3514 query.append(_FINDER_COLUMN_NAME_NAME_3);
3515 }
3516 else {
3517 bindName = true;
3518
3519 query.append(_FINDER_COLUMN_NAME_NAME_2);
3520 }
3521
3522 if (!getDB().isSupportsInlineDistinct()) {
3523 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3524 }
3525
3526 if (orderByComparator != null) {
3527 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3528
3529 if (orderByConditionFields.length > 0) {
3530 query.append(WHERE_AND);
3531 }
3532
3533 for (int i = 0; i < orderByConditionFields.length; i++) {
3534 if (getDB().isSupportsInlineDistinct()) {
3535 query.append(_ORDER_BY_ENTITY_ALIAS);
3536 }
3537 else {
3538 query.append(_ORDER_BY_ENTITY_TABLE);
3539 }
3540
3541 query.append(orderByConditionFields[i]);
3542
3543 if ((i + 1) < orderByConditionFields.length) {
3544 if (orderByComparator.isAscending() ^ previous) {
3545 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3546 }
3547 else {
3548 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3549 }
3550 }
3551 else {
3552 if (orderByComparator.isAscending() ^ previous) {
3553 query.append(WHERE_GREATER_THAN);
3554 }
3555 else {
3556 query.append(WHERE_LESSER_THAN);
3557 }
3558 }
3559 }
3560
3561 query.append(ORDER_BY_CLAUSE);
3562
3563 String[] orderByFields = orderByComparator.getOrderByFields();
3564
3565 for (int i = 0; i < orderByFields.length; i++) {
3566 if (getDB().isSupportsInlineDistinct()) {
3567 query.append(_ORDER_BY_ENTITY_ALIAS);
3568 }
3569 else {
3570 query.append(_ORDER_BY_ENTITY_TABLE);
3571 }
3572
3573 query.append(orderByFields[i]);
3574
3575 if ((i + 1) < orderByFields.length) {
3576 if (orderByComparator.isAscending() ^ previous) {
3577 query.append(ORDER_BY_ASC_HAS_NEXT);
3578 }
3579 else {
3580 query.append(ORDER_BY_DESC_HAS_NEXT);
3581 }
3582 }
3583 else {
3584 if (orderByComparator.isAscending() ^ previous) {
3585 query.append(ORDER_BY_ASC);
3586 }
3587 else {
3588 query.append(ORDER_BY_DESC);
3589 }
3590 }
3591 }
3592 }
3593 else {
3594 if (getDB().isSupportsInlineDistinct()) {
3595 query.append(RoleModelImpl.ORDER_BY_JPQL);
3596 }
3597 else {
3598 query.append(RoleModelImpl.ORDER_BY_SQL);
3599 }
3600 }
3601
3602 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3603 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3604
3605 SQLQuery q = session.createSQLQuery(sql);
3606
3607 q.setFirstResult(0);
3608 q.setMaxResults(2);
3609
3610 if (getDB().isSupportsInlineDistinct()) {
3611 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3612 }
3613 else {
3614 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3615 }
3616
3617 QueryPos qPos = QueryPos.getInstance(q);
3618
3619 if (bindName) {
3620 qPos.add(name);
3621 }
3622
3623 if (orderByComparator != null) {
3624 Object[] values = orderByComparator.getOrderByConditionValues(role);
3625
3626 for (Object value : values) {
3627 qPos.add(value);
3628 }
3629 }
3630
3631 List<Role> list = q.list();
3632
3633 if (list.size() == 2) {
3634 return list.get(1);
3635 }
3636 else {
3637 return null;
3638 }
3639 }
3640
3641
3647 @Override
3648 public void removeByName(String name) throws SystemException {
3649 for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3650 null)) {
3651 remove(role);
3652 }
3653 }
3654
3655
3662 @Override
3663 public int countByName(String name) throws SystemException {
3664 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
3665
3666 Object[] finderArgs = new Object[] { name };
3667
3668 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3669 this);
3670
3671 if (count == null) {
3672 StringBundler query = new StringBundler(2);
3673
3674 query.append(_SQL_COUNT_ROLE_WHERE);
3675
3676 boolean bindName = false;
3677
3678 if (name == null) {
3679 query.append(_FINDER_COLUMN_NAME_NAME_1);
3680 }
3681 else if (name.equals(StringPool.BLANK)) {
3682 query.append(_FINDER_COLUMN_NAME_NAME_3);
3683 }
3684 else {
3685 bindName = true;
3686
3687 query.append(_FINDER_COLUMN_NAME_NAME_2);
3688 }
3689
3690 String sql = query.toString();
3691
3692 Session session = null;
3693
3694 try {
3695 session = openSession();
3696
3697 Query q = session.createQuery(sql);
3698
3699 QueryPos qPos = QueryPos.getInstance(q);
3700
3701 if (bindName) {
3702 qPos.add(name);
3703 }
3704
3705 count = (Long)q.uniqueResult();
3706
3707 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3708 }
3709 catch (Exception e) {
3710 FinderCacheUtil.removeResult(finderPath, finderArgs);
3711
3712 throw processException(e);
3713 }
3714 finally {
3715 closeSession(session);
3716 }
3717 }
3718
3719 return count.intValue();
3720 }
3721
3722
3729 @Override
3730 public int filterCountByName(String name) throws SystemException {
3731 if (!InlineSQLHelperUtil.isEnabled()) {
3732 return countByName(name);
3733 }
3734
3735 StringBundler query = new StringBundler(2);
3736
3737 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3738
3739 boolean bindName = false;
3740
3741 if (name == null) {
3742 query.append(_FINDER_COLUMN_NAME_NAME_1);
3743 }
3744 else if (name.equals(StringPool.BLANK)) {
3745 query.append(_FINDER_COLUMN_NAME_NAME_3);
3746 }
3747 else {
3748 bindName = true;
3749
3750 query.append(_FINDER_COLUMN_NAME_NAME_2);
3751 }
3752
3753 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3754 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3755
3756 Session session = null;
3757
3758 try {
3759 session = openSession();
3760
3761 SQLQuery q = session.createSQLQuery(sql);
3762
3763 q.addScalar(COUNT_COLUMN_NAME,
3764 com.liferay.portal.kernel.dao.orm.Type.LONG);
3765
3766 QueryPos qPos = QueryPos.getInstance(q);
3767
3768 if (bindName) {
3769 qPos.add(name);
3770 }
3771
3772 Long count = (Long)q.uniqueResult();
3773
3774 return count.intValue();
3775 }
3776 catch (Exception e) {
3777 throw processException(e);
3778 }
3779 finally {
3780 closeSession(session);
3781 }
3782 }
3783
3784 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
3785 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
3786 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = '')";
3787 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3788 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3789 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByType",
3790 new String[] {
3791 Integer.class.getName(),
3792
3793 Integer.class.getName(), Integer.class.getName(),
3794 OrderByComparator.class.getName()
3795 });
3796 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3797 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3798 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByType",
3799 new String[] { Integer.class.getName() },
3800 RoleModelImpl.TYPE_COLUMN_BITMASK |
3801 RoleModelImpl.NAME_COLUMN_BITMASK);
3802 public static final FinderPath FINDER_PATH_COUNT_BY_TYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3803 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3804 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByType",
3805 new String[] { Integer.class.getName() });
3806
3807
3814 @Override
3815 public List<Role> findByType(int type) throws SystemException {
3816 return findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3817 }
3818
3819
3832 @Override
3833 public List<Role> findByType(int type, int start, int end)
3834 throws SystemException {
3835 return findByType(type, start, end, null);
3836 }
3837
3838
3852 @Override
3853 public List<Role> findByType(int type, int start, int end,
3854 OrderByComparator orderByComparator) throws SystemException {
3855 boolean pagination = true;
3856 FinderPath finderPath = null;
3857 Object[] finderArgs = null;
3858
3859 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3860 (orderByComparator == null)) {
3861 pagination = false;
3862 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE;
3863 finderArgs = new Object[] { type };
3864 }
3865 else {
3866 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TYPE;
3867 finderArgs = new Object[] { type, start, end, orderByComparator };
3868 }
3869
3870 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
3871 finderArgs, this);
3872
3873 if ((list != null) && !list.isEmpty()) {
3874 for (Role role : list) {
3875 if ((type != role.getType())) {
3876 list = null;
3877
3878 break;
3879 }
3880 }
3881 }
3882
3883 if (list == null) {
3884 StringBundler query = null;
3885
3886 if (orderByComparator != null) {
3887 query = new StringBundler(3 +
3888 (orderByComparator.getOrderByFields().length * 3));
3889 }
3890 else {
3891 query = new StringBundler(3);
3892 }
3893
3894 query.append(_SQL_SELECT_ROLE_WHERE);
3895
3896 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
3897
3898 if (orderByComparator != null) {
3899 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3900 orderByComparator);
3901 }
3902 else
3903 if (pagination) {
3904 query.append(RoleModelImpl.ORDER_BY_JPQL);
3905 }
3906
3907 String sql = query.toString();
3908
3909 Session session = null;
3910
3911 try {
3912 session = openSession();
3913
3914 Query q = session.createQuery(sql);
3915
3916 QueryPos qPos = QueryPos.getInstance(q);
3917
3918 qPos.add(type);
3919
3920 if (!pagination) {
3921 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3922 end, false);
3923
3924 Collections.sort(list);
3925
3926 list = new UnmodifiableList<Role>(list);
3927 }
3928 else {
3929 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3930 end);
3931 }
3932
3933 cacheResult(list);
3934
3935 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3936 }
3937 catch (Exception e) {
3938 FinderCacheUtil.removeResult(finderPath, finderArgs);
3939
3940 throw processException(e);
3941 }
3942 finally {
3943 closeSession(session);
3944 }
3945 }
3946
3947 return list;
3948 }
3949
3950
3959 @Override
3960 public Role findByType_First(int type, OrderByComparator orderByComparator)
3961 throws NoSuchRoleException, SystemException {
3962 Role role = fetchByType_First(type, orderByComparator);
3963
3964 if (role != null) {
3965 return role;
3966 }
3967
3968 StringBundler msg = new StringBundler(4);
3969
3970 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3971
3972 msg.append("type=");
3973 msg.append(type);
3974
3975 msg.append(StringPool.CLOSE_CURLY_BRACE);
3976
3977 throw new NoSuchRoleException(msg.toString());
3978 }
3979
3980
3988 @Override
3989 public Role fetchByType_First(int type, OrderByComparator orderByComparator)
3990 throws SystemException {
3991 List<Role> list = findByType(type, 0, 1, orderByComparator);
3992
3993 if (!list.isEmpty()) {
3994 return list.get(0);
3995 }
3996
3997 return null;
3998 }
3999
4000
4009 @Override
4010 public Role findByType_Last(int type, OrderByComparator orderByComparator)
4011 throws NoSuchRoleException, SystemException {
4012 Role role = fetchByType_Last(type, orderByComparator);
4013
4014 if (role != null) {
4015 return role;
4016 }
4017
4018 StringBundler msg = new StringBundler(4);
4019
4020 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4021
4022 msg.append("type=");
4023 msg.append(type);
4024
4025 msg.append(StringPool.CLOSE_CURLY_BRACE);
4026
4027 throw new NoSuchRoleException(msg.toString());
4028 }
4029
4030
4038 @Override
4039 public Role fetchByType_Last(int type, OrderByComparator orderByComparator)
4040 throws SystemException {
4041 int count = countByType(type);
4042
4043 if (count == 0) {
4044 return null;
4045 }
4046
4047 List<Role> list = findByType(type, count - 1, count, orderByComparator);
4048
4049 if (!list.isEmpty()) {
4050 return list.get(0);
4051 }
4052
4053 return null;
4054 }
4055
4056
4066 @Override
4067 public Role[] findByType_PrevAndNext(long roleId, int type,
4068 OrderByComparator orderByComparator)
4069 throws NoSuchRoleException, SystemException {
4070 Role role = findByPrimaryKey(roleId);
4071
4072 Session session = null;
4073
4074 try {
4075 session = openSession();
4076
4077 Role[] array = new RoleImpl[3];
4078
4079 array[0] = getByType_PrevAndNext(session, role, type,
4080 orderByComparator, true);
4081
4082 array[1] = role;
4083
4084 array[2] = getByType_PrevAndNext(session, role, type,
4085 orderByComparator, false);
4086
4087 return array;
4088 }
4089 catch (Exception e) {
4090 throw processException(e);
4091 }
4092 finally {
4093 closeSession(session);
4094 }
4095 }
4096
4097 protected Role getByType_PrevAndNext(Session session, Role role, int type,
4098 OrderByComparator orderByComparator, boolean previous) {
4099 StringBundler query = null;
4100
4101 if (orderByComparator != null) {
4102 query = new StringBundler(6 +
4103 (orderByComparator.getOrderByFields().length * 6));
4104 }
4105 else {
4106 query = new StringBundler(3);
4107 }
4108
4109 query.append(_SQL_SELECT_ROLE_WHERE);
4110
4111 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4112
4113 if (orderByComparator != null) {
4114 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4115
4116 if (orderByConditionFields.length > 0) {
4117 query.append(WHERE_AND);
4118 }
4119
4120 for (int i = 0; i < orderByConditionFields.length; i++) {
4121 query.append(_ORDER_BY_ENTITY_ALIAS);
4122 query.append(orderByConditionFields[i]);
4123
4124 if ((i + 1) < orderByConditionFields.length) {
4125 if (orderByComparator.isAscending() ^ previous) {
4126 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4127 }
4128 else {
4129 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4130 }
4131 }
4132 else {
4133 if (orderByComparator.isAscending() ^ previous) {
4134 query.append(WHERE_GREATER_THAN);
4135 }
4136 else {
4137 query.append(WHERE_LESSER_THAN);
4138 }
4139 }
4140 }
4141
4142 query.append(ORDER_BY_CLAUSE);
4143
4144 String[] orderByFields = orderByComparator.getOrderByFields();
4145
4146 for (int i = 0; i < orderByFields.length; i++) {
4147 query.append(_ORDER_BY_ENTITY_ALIAS);
4148 query.append(orderByFields[i]);
4149
4150 if ((i + 1) < orderByFields.length) {
4151 if (orderByComparator.isAscending() ^ previous) {
4152 query.append(ORDER_BY_ASC_HAS_NEXT);
4153 }
4154 else {
4155 query.append(ORDER_BY_DESC_HAS_NEXT);
4156 }
4157 }
4158 else {
4159 if (orderByComparator.isAscending() ^ previous) {
4160 query.append(ORDER_BY_ASC);
4161 }
4162 else {
4163 query.append(ORDER_BY_DESC);
4164 }
4165 }
4166 }
4167 }
4168 else {
4169 query.append(RoleModelImpl.ORDER_BY_JPQL);
4170 }
4171
4172 String sql = query.toString();
4173
4174 Query q = session.createQuery(sql);
4175
4176 q.setFirstResult(0);
4177 q.setMaxResults(2);
4178
4179 QueryPos qPos = QueryPos.getInstance(q);
4180
4181 qPos.add(type);
4182
4183 if (orderByComparator != null) {
4184 Object[] values = orderByComparator.getOrderByConditionValues(role);
4185
4186 for (Object value : values) {
4187 qPos.add(value);
4188 }
4189 }
4190
4191 List<Role> list = q.list();
4192
4193 if (list.size() == 2) {
4194 return list.get(1);
4195 }
4196 else {
4197 return null;
4198 }
4199 }
4200
4201
4208 @Override
4209 public List<Role> filterFindByType(int type) throws SystemException {
4210 return filterFindByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4211 }
4212
4213
4226 @Override
4227 public List<Role> filterFindByType(int type, int start, int end)
4228 throws SystemException {
4229 return filterFindByType(type, start, end, null);
4230 }
4231
4232
4246 @Override
4247 public List<Role> filterFindByType(int type, int start, int end,
4248 OrderByComparator orderByComparator) throws SystemException {
4249 if (!InlineSQLHelperUtil.isEnabled()) {
4250 return findByType(type, start, end, orderByComparator);
4251 }
4252
4253 StringBundler query = null;
4254
4255 if (orderByComparator != null) {
4256 query = new StringBundler(3 +
4257 (orderByComparator.getOrderByFields().length * 3));
4258 }
4259 else {
4260 query = new StringBundler(3);
4261 }
4262
4263 if (getDB().isSupportsInlineDistinct()) {
4264 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4265 }
4266 else {
4267 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4268 }
4269
4270 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4271
4272 if (!getDB().isSupportsInlineDistinct()) {
4273 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4274 }
4275
4276 if (orderByComparator != null) {
4277 if (getDB().isSupportsInlineDistinct()) {
4278 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4279 orderByComparator, true);
4280 }
4281 else {
4282 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4283 orderByComparator, true);
4284 }
4285 }
4286 else {
4287 if (getDB().isSupportsInlineDistinct()) {
4288 query.append(RoleModelImpl.ORDER_BY_JPQL);
4289 }
4290 else {
4291 query.append(RoleModelImpl.ORDER_BY_SQL);
4292 }
4293 }
4294
4295 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4296 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4297
4298 Session session = null;
4299
4300 try {
4301 session = openSession();
4302
4303 SQLQuery q = session.createSQLQuery(sql);
4304
4305 if (getDB().isSupportsInlineDistinct()) {
4306 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4307 }
4308 else {
4309 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4310 }
4311
4312 QueryPos qPos = QueryPos.getInstance(q);
4313
4314 qPos.add(type);
4315
4316 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
4317 }
4318 catch (Exception e) {
4319 throw processException(e);
4320 }
4321 finally {
4322 closeSession(session);
4323 }
4324 }
4325
4326
4336 @Override
4337 public Role[] filterFindByType_PrevAndNext(long roleId, int type,
4338 OrderByComparator orderByComparator)
4339 throws NoSuchRoleException, SystemException {
4340 if (!InlineSQLHelperUtil.isEnabled()) {
4341 return findByType_PrevAndNext(roleId, type, orderByComparator);
4342 }
4343
4344 Role role = findByPrimaryKey(roleId);
4345
4346 Session session = null;
4347
4348 try {
4349 session = openSession();
4350
4351 Role[] array = new RoleImpl[3];
4352
4353 array[0] = filterGetByType_PrevAndNext(session, role, type,
4354 orderByComparator, true);
4355
4356 array[1] = role;
4357
4358 array[2] = filterGetByType_PrevAndNext(session, role, type,
4359 orderByComparator, false);
4360
4361 return array;
4362 }
4363 catch (Exception e) {
4364 throw processException(e);
4365 }
4366 finally {
4367 closeSession(session);
4368 }
4369 }
4370
4371 protected Role filterGetByType_PrevAndNext(Session session, Role role,
4372 int type, OrderByComparator orderByComparator, boolean previous) {
4373 StringBundler query = null;
4374
4375 if (orderByComparator != null) {
4376 query = new StringBundler(6 +
4377 (orderByComparator.getOrderByFields().length * 6));
4378 }
4379 else {
4380 query = new StringBundler(3);
4381 }
4382
4383 if (getDB().isSupportsInlineDistinct()) {
4384 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
4385 }
4386 else {
4387 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
4388 }
4389
4390 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4391
4392 if (!getDB().isSupportsInlineDistinct()) {
4393 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
4394 }
4395
4396 if (orderByComparator != null) {
4397 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4398
4399 if (orderByConditionFields.length > 0) {
4400 query.append(WHERE_AND);
4401 }
4402
4403 for (int i = 0; i < orderByConditionFields.length; i++) {
4404 if (getDB().isSupportsInlineDistinct()) {
4405 query.append(_ORDER_BY_ENTITY_ALIAS);
4406 }
4407 else {
4408 query.append(_ORDER_BY_ENTITY_TABLE);
4409 }
4410
4411 query.append(orderByConditionFields[i]);
4412
4413 if ((i + 1) < orderByConditionFields.length) {
4414 if (orderByComparator.isAscending() ^ previous) {
4415 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4416 }
4417 else {
4418 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4419 }
4420 }
4421 else {
4422 if (orderByComparator.isAscending() ^ previous) {
4423 query.append(WHERE_GREATER_THAN);
4424 }
4425 else {
4426 query.append(WHERE_LESSER_THAN);
4427 }
4428 }
4429 }
4430
4431 query.append(ORDER_BY_CLAUSE);
4432
4433 String[] orderByFields = orderByComparator.getOrderByFields();
4434
4435 for (int i = 0; i < orderByFields.length; i++) {
4436 if (getDB().isSupportsInlineDistinct()) {
4437 query.append(_ORDER_BY_ENTITY_ALIAS);
4438 }
4439 else {
4440 query.append(_ORDER_BY_ENTITY_TABLE);
4441 }
4442
4443 query.append(orderByFields[i]);
4444
4445 if ((i + 1) < orderByFields.length) {
4446 if (orderByComparator.isAscending() ^ previous) {
4447 query.append(ORDER_BY_ASC_HAS_NEXT);
4448 }
4449 else {
4450 query.append(ORDER_BY_DESC_HAS_NEXT);
4451 }
4452 }
4453 else {
4454 if (orderByComparator.isAscending() ^ previous) {
4455 query.append(ORDER_BY_ASC);
4456 }
4457 else {
4458 query.append(ORDER_BY_DESC);
4459 }
4460 }
4461 }
4462 }
4463 else {
4464 if (getDB().isSupportsInlineDistinct()) {
4465 query.append(RoleModelImpl.ORDER_BY_JPQL);
4466 }
4467 else {
4468 query.append(RoleModelImpl.ORDER_BY_SQL);
4469 }
4470 }
4471
4472 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4473 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4474
4475 SQLQuery q = session.createSQLQuery(sql);
4476
4477 q.setFirstResult(0);
4478 q.setMaxResults(2);
4479
4480 if (getDB().isSupportsInlineDistinct()) {
4481 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
4482 }
4483 else {
4484 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
4485 }
4486
4487 QueryPos qPos = QueryPos.getInstance(q);
4488
4489 qPos.add(type);
4490
4491 if (orderByComparator != null) {
4492 Object[] values = orderByComparator.getOrderByConditionValues(role);
4493
4494 for (Object value : values) {
4495 qPos.add(value);
4496 }
4497 }
4498
4499 List<Role> list = q.list();
4500
4501 if (list.size() == 2) {
4502 return list.get(1);
4503 }
4504 else {
4505 return null;
4506 }
4507 }
4508
4509
4515 @Override
4516 public void removeByType(int type) throws SystemException {
4517 for (Role role : findByType(type, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4518 null)) {
4519 remove(role);
4520 }
4521 }
4522
4523
4530 @Override
4531 public int countByType(int type) throws SystemException {
4532 FinderPath finderPath = FINDER_PATH_COUNT_BY_TYPE;
4533
4534 Object[] finderArgs = new Object[] { type };
4535
4536 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4537 this);
4538
4539 if (count == null) {
4540 StringBundler query = new StringBundler(2);
4541
4542 query.append(_SQL_COUNT_ROLE_WHERE);
4543
4544 query.append(_FINDER_COLUMN_TYPE_TYPE_2);
4545
4546 String sql = query.toString();
4547
4548 Session session = null;
4549
4550 try {
4551 session = openSession();
4552
4553 Query q = session.createQuery(sql);
4554
4555 QueryPos qPos = QueryPos.getInstance(q);
4556
4557 qPos.add(type);
4558
4559 count = (Long)q.uniqueResult();
4560
4561 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4562 }
4563 catch (Exception e) {
4564 FinderCacheUtil.removeResult(finderPath, finderArgs);
4565
4566 throw processException(e);
4567 }
4568 finally {
4569 closeSession(session);
4570 }
4571 }
4572
4573 return count.intValue();
4574 }
4575
4576
4583 @Override
4584 public int filterCountByType(int type) throws SystemException {
4585 if (!InlineSQLHelperUtil.isEnabled()) {
4586 return countByType(type);
4587 }
4588
4589 StringBundler query = new StringBundler(2);
4590
4591 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
4592
4593 query.append(_FINDER_COLUMN_TYPE_TYPE_2_SQL);
4594
4595 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4596 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
4597
4598 Session session = null;
4599
4600 try {
4601 session = openSession();
4602
4603 SQLQuery q = session.createSQLQuery(sql);
4604
4605 q.addScalar(COUNT_COLUMN_NAME,
4606 com.liferay.portal.kernel.dao.orm.Type.LONG);
4607
4608 QueryPos qPos = QueryPos.getInstance(q);
4609
4610 qPos.add(type);
4611
4612 Long count = (Long)q.uniqueResult();
4613
4614 return count.intValue();
4615 }
4616 catch (Exception e) {
4617 throw processException(e);
4618 }
4619 finally {
4620 closeSession(session);
4621 }
4622 }
4623
4624 private static final String _FINDER_COLUMN_TYPE_TYPE_2 = "role.type = ?";
4625 private static final String _FINDER_COLUMN_TYPE_TYPE_2_SQL = "role.type_ = ?";
4626 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4627 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4628 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
4629 new String[] {
4630 String.class.getName(),
4631
4632 Integer.class.getName(), Integer.class.getName(),
4633 OrderByComparator.class.getName()
4634 });
4635 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
4636 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4637 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
4638 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
4639 new String[] { String.class.getName() },
4640 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
4641 RoleModelImpl.NAME_COLUMN_BITMASK);
4642 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
4643 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
4644 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
4645 new String[] { String.class.getName() });
4646
4647
4654 @Override
4655 public List<Role> findBySubtype(String subtype) throws SystemException {
4656 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4657 }
4658
4659
4672 @Override
4673 public List<Role> findBySubtype(String subtype, int start, int end)
4674 throws SystemException {
4675 return findBySubtype(subtype, start, end, null);
4676 }
4677
4678
4692 @Override
4693 public List<Role> findBySubtype(String subtype, int start, int end,
4694 OrderByComparator orderByComparator) throws SystemException {
4695 boolean pagination = true;
4696 FinderPath finderPath = null;
4697 Object[] finderArgs = null;
4698
4699 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4700 (orderByComparator == null)) {
4701 pagination = false;
4702 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
4703 finderArgs = new Object[] { subtype };
4704 }
4705 else {
4706 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
4707 finderArgs = new Object[] { subtype, start, end, orderByComparator };
4708 }
4709
4710 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
4711 finderArgs, this);
4712
4713 if ((list != null) && !list.isEmpty()) {
4714 for (Role role : list) {
4715 if (!Validator.equals(subtype, role.getSubtype())) {
4716 list = null;
4717
4718 break;
4719 }
4720 }
4721 }
4722
4723 if (list == null) {
4724 StringBundler query = null;
4725
4726 if (orderByComparator != null) {
4727 query = new StringBundler(3 +
4728 (orderByComparator.getOrderByFields().length * 3));
4729 }
4730 else {
4731 query = new StringBundler(3);
4732 }
4733
4734 query.append(_SQL_SELECT_ROLE_WHERE);
4735
4736 boolean bindSubtype = false;
4737
4738 if (subtype == null) {
4739 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4740 }
4741 else if (subtype.equals(StringPool.BLANK)) {
4742 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4743 }
4744 else {
4745 bindSubtype = true;
4746
4747 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4748 }
4749
4750 if (orderByComparator != null) {
4751 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4752 orderByComparator);
4753 }
4754 else
4755 if (pagination) {
4756 query.append(RoleModelImpl.ORDER_BY_JPQL);
4757 }
4758
4759 String sql = query.toString();
4760
4761 Session session = null;
4762
4763 try {
4764 session = openSession();
4765
4766 Query q = session.createQuery(sql);
4767
4768 QueryPos qPos = QueryPos.getInstance(q);
4769
4770 if (bindSubtype) {
4771 qPos.add(subtype);
4772 }
4773
4774 if (!pagination) {
4775 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4776 end, false);
4777
4778 Collections.sort(list);
4779
4780 list = new UnmodifiableList<Role>(list);
4781 }
4782 else {
4783 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4784 end);
4785 }
4786
4787 cacheResult(list);
4788
4789 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4790 }
4791 catch (Exception e) {
4792 FinderCacheUtil.removeResult(finderPath, finderArgs);
4793
4794 throw processException(e);
4795 }
4796 finally {
4797 closeSession(session);
4798 }
4799 }
4800
4801 return list;
4802 }
4803
4804
4813 @Override
4814 public Role findBySubtype_First(String subtype,
4815 OrderByComparator orderByComparator)
4816 throws NoSuchRoleException, SystemException {
4817 Role role = fetchBySubtype_First(subtype, orderByComparator);
4818
4819 if (role != null) {
4820 return role;
4821 }
4822
4823 StringBundler msg = new StringBundler(4);
4824
4825 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4826
4827 msg.append("subtype=");
4828 msg.append(subtype);
4829
4830 msg.append(StringPool.CLOSE_CURLY_BRACE);
4831
4832 throw new NoSuchRoleException(msg.toString());
4833 }
4834
4835
4843 @Override
4844 public Role fetchBySubtype_First(String subtype,
4845 OrderByComparator orderByComparator) throws SystemException {
4846 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
4847
4848 if (!list.isEmpty()) {
4849 return list.get(0);
4850 }
4851
4852 return null;
4853 }
4854
4855
4864 @Override
4865 public Role findBySubtype_Last(String subtype,
4866 OrderByComparator orderByComparator)
4867 throws NoSuchRoleException, SystemException {
4868 Role role = fetchBySubtype_Last(subtype, orderByComparator);
4869
4870 if (role != null) {
4871 return role;
4872 }
4873
4874 StringBundler msg = new StringBundler(4);
4875
4876 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4877
4878 msg.append("subtype=");
4879 msg.append(subtype);
4880
4881 msg.append(StringPool.CLOSE_CURLY_BRACE);
4882
4883 throw new NoSuchRoleException(msg.toString());
4884 }
4885
4886
4894 @Override
4895 public Role fetchBySubtype_Last(String subtype,
4896 OrderByComparator orderByComparator) throws SystemException {
4897 int count = countBySubtype(subtype);
4898
4899 if (count == 0) {
4900 return null;
4901 }
4902
4903 List<Role> list = findBySubtype(subtype, count - 1, count,
4904 orderByComparator);
4905
4906 if (!list.isEmpty()) {
4907 return list.get(0);
4908 }
4909
4910 return null;
4911 }
4912
4913
4923 @Override
4924 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
4925 OrderByComparator orderByComparator)
4926 throws NoSuchRoleException, SystemException {
4927 Role role = findByPrimaryKey(roleId);
4928
4929 Session session = null;
4930
4931 try {
4932 session = openSession();
4933
4934 Role[] array = new RoleImpl[3];
4935
4936 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
4937 orderByComparator, true);
4938
4939 array[1] = role;
4940
4941 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
4942 orderByComparator, false);
4943
4944 return array;
4945 }
4946 catch (Exception e) {
4947 throw processException(e);
4948 }
4949 finally {
4950 closeSession(session);
4951 }
4952 }
4953
4954 protected Role getBySubtype_PrevAndNext(Session session, Role role,
4955 String subtype, OrderByComparator orderByComparator, boolean previous) {
4956 StringBundler query = null;
4957
4958 if (orderByComparator != null) {
4959 query = new StringBundler(6 +
4960 (orderByComparator.getOrderByFields().length * 6));
4961 }
4962 else {
4963 query = new StringBundler(3);
4964 }
4965
4966 query.append(_SQL_SELECT_ROLE_WHERE);
4967
4968 boolean bindSubtype = false;
4969
4970 if (subtype == null) {
4971 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
4972 }
4973 else if (subtype.equals(StringPool.BLANK)) {
4974 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
4975 }
4976 else {
4977 bindSubtype = true;
4978
4979 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
4980 }
4981
4982 if (orderByComparator != null) {
4983 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4984
4985 if (orderByConditionFields.length > 0) {
4986 query.append(WHERE_AND);
4987 }
4988
4989 for (int i = 0; i < orderByConditionFields.length; i++) {
4990 query.append(_ORDER_BY_ENTITY_ALIAS);
4991 query.append(orderByConditionFields[i]);
4992
4993 if ((i + 1) < orderByConditionFields.length) {
4994 if (orderByComparator.isAscending() ^ previous) {
4995 query.append(WHERE_GREATER_THAN_HAS_NEXT);
4996 }
4997 else {
4998 query.append(WHERE_LESSER_THAN_HAS_NEXT);
4999 }
5000 }
5001 else {
5002 if (orderByComparator.isAscending() ^ previous) {
5003 query.append(WHERE_GREATER_THAN);
5004 }
5005 else {
5006 query.append(WHERE_LESSER_THAN);
5007 }
5008 }
5009 }
5010
5011 query.append(ORDER_BY_CLAUSE);
5012
5013 String[] orderByFields = orderByComparator.getOrderByFields();
5014
5015 for (int i = 0; i < orderByFields.length; i++) {
5016 query.append(_ORDER_BY_ENTITY_ALIAS);
5017 query.append(orderByFields[i]);
5018
5019 if ((i + 1) < orderByFields.length) {
5020 if (orderByComparator.isAscending() ^ previous) {
5021 query.append(ORDER_BY_ASC_HAS_NEXT);
5022 }
5023 else {
5024 query.append(ORDER_BY_DESC_HAS_NEXT);
5025 }
5026 }
5027 else {
5028 if (orderByComparator.isAscending() ^ previous) {
5029 query.append(ORDER_BY_ASC);
5030 }
5031 else {
5032 query.append(ORDER_BY_DESC);
5033 }
5034 }
5035 }
5036 }
5037 else {
5038 query.append(RoleModelImpl.ORDER_BY_JPQL);
5039 }
5040
5041 String sql = query.toString();
5042
5043 Query q = session.createQuery(sql);
5044
5045 q.setFirstResult(0);
5046 q.setMaxResults(2);
5047
5048 QueryPos qPos = QueryPos.getInstance(q);
5049
5050 if (bindSubtype) {
5051 qPos.add(subtype);
5052 }
5053
5054 if (orderByComparator != null) {
5055 Object[] values = orderByComparator.getOrderByConditionValues(role);
5056
5057 for (Object value : values) {
5058 qPos.add(value);
5059 }
5060 }
5061
5062 List<Role> list = q.list();
5063
5064 if (list.size() == 2) {
5065 return list.get(1);
5066 }
5067 else {
5068 return null;
5069 }
5070 }
5071
5072
5079 @Override
5080 public List<Role> filterFindBySubtype(String subtype)
5081 throws SystemException {
5082 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
5083 QueryUtil.ALL_POS, null);
5084 }
5085
5086
5099 @Override
5100 public List<Role> filterFindBySubtype(String subtype, int start, int end)
5101 throws SystemException {
5102 return filterFindBySubtype(subtype, start, end, null);
5103 }
5104
5105
5119 @Override
5120 public List<Role> filterFindBySubtype(String subtype, int start, int end,
5121 OrderByComparator orderByComparator) throws SystemException {
5122 if (!InlineSQLHelperUtil.isEnabled()) {
5123 return findBySubtype(subtype, start, end, orderByComparator);
5124 }
5125
5126 StringBundler query = null;
5127
5128 if (orderByComparator != null) {
5129 query = new StringBundler(3 +
5130 (orderByComparator.getOrderByFields().length * 3));
5131 }
5132 else {
5133 query = new StringBundler(3);
5134 }
5135
5136 if (getDB().isSupportsInlineDistinct()) {
5137 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5138 }
5139 else {
5140 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5141 }
5142
5143 boolean bindSubtype = false;
5144
5145 if (subtype == null) {
5146 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5147 }
5148 else if (subtype.equals(StringPool.BLANK)) {
5149 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5150 }
5151 else {
5152 bindSubtype = true;
5153
5154 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5155 }
5156
5157 if (!getDB().isSupportsInlineDistinct()) {
5158 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5159 }
5160
5161 if (orderByComparator != null) {
5162 if (getDB().isSupportsInlineDistinct()) {
5163 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5164 orderByComparator, true);
5165 }
5166 else {
5167 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5168 orderByComparator, true);
5169 }
5170 }
5171 else {
5172 if (getDB().isSupportsInlineDistinct()) {
5173 query.append(RoleModelImpl.ORDER_BY_JPQL);
5174 }
5175 else {
5176 query.append(RoleModelImpl.ORDER_BY_SQL);
5177 }
5178 }
5179
5180 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5181 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5182
5183 Session session = null;
5184
5185 try {
5186 session = openSession();
5187
5188 SQLQuery q = session.createSQLQuery(sql);
5189
5190 if (getDB().isSupportsInlineDistinct()) {
5191 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5192 }
5193 else {
5194 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5195 }
5196
5197 QueryPos qPos = QueryPos.getInstance(q);
5198
5199 if (bindSubtype) {
5200 qPos.add(subtype);
5201 }
5202
5203 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
5204 }
5205 catch (Exception e) {
5206 throw processException(e);
5207 }
5208 finally {
5209 closeSession(session);
5210 }
5211 }
5212
5213
5223 @Override
5224 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
5225 OrderByComparator orderByComparator)
5226 throws NoSuchRoleException, SystemException {
5227 if (!InlineSQLHelperUtil.isEnabled()) {
5228 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
5229 }
5230
5231 Role role = findByPrimaryKey(roleId);
5232
5233 Session session = null;
5234
5235 try {
5236 session = openSession();
5237
5238 Role[] array = new RoleImpl[3];
5239
5240 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5241 orderByComparator, true);
5242
5243 array[1] = role;
5244
5245 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
5246 orderByComparator, false);
5247
5248 return array;
5249 }
5250 catch (Exception e) {
5251 throw processException(e);
5252 }
5253 finally {
5254 closeSession(session);
5255 }
5256 }
5257
5258 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
5259 String subtype, OrderByComparator orderByComparator, boolean previous) {
5260 StringBundler query = null;
5261
5262 if (orderByComparator != null) {
5263 query = new StringBundler(6 +
5264 (orderByComparator.getOrderByFields().length * 6));
5265 }
5266 else {
5267 query = new StringBundler(3);
5268 }
5269
5270 if (getDB().isSupportsInlineDistinct()) {
5271 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
5272 }
5273 else {
5274 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
5275 }
5276
5277 boolean bindSubtype = false;
5278
5279 if (subtype == null) {
5280 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5281 }
5282 else if (subtype.equals(StringPool.BLANK)) {
5283 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5284 }
5285 else {
5286 bindSubtype = true;
5287
5288 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5289 }
5290
5291 if (!getDB().isSupportsInlineDistinct()) {
5292 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
5293 }
5294
5295 if (orderByComparator != null) {
5296 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5297
5298 if (orderByConditionFields.length > 0) {
5299 query.append(WHERE_AND);
5300 }
5301
5302 for (int i = 0; i < orderByConditionFields.length; i++) {
5303 if (getDB().isSupportsInlineDistinct()) {
5304 query.append(_ORDER_BY_ENTITY_ALIAS);
5305 }
5306 else {
5307 query.append(_ORDER_BY_ENTITY_TABLE);
5308 }
5309
5310 query.append(orderByConditionFields[i]);
5311
5312 if ((i + 1) < orderByConditionFields.length) {
5313 if (orderByComparator.isAscending() ^ previous) {
5314 query.append(WHERE_GREATER_THAN_HAS_NEXT);
5315 }
5316 else {
5317 query.append(WHERE_LESSER_THAN_HAS_NEXT);
5318 }
5319 }
5320 else {
5321 if (orderByComparator.isAscending() ^ previous) {
5322 query.append(WHERE_GREATER_THAN);
5323 }
5324 else {
5325 query.append(WHERE_LESSER_THAN);
5326 }
5327 }
5328 }
5329
5330 query.append(ORDER_BY_CLAUSE);
5331
5332 String[] orderByFields = orderByComparator.getOrderByFields();
5333
5334 for (int i = 0; i < orderByFields.length; i++) {
5335 if (getDB().isSupportsInlineDistinct()) {
5336 query.append(_ORDER_BY_ENTITY_ALIAS);
5337 }
5338 else {
5339 query.append(_ORDER_BY_ENTITY_TABLE);
5340 }
5341
5342 query.append(orderByFields[i]);
5343
5344 if ((i + 1) < orderByFields.length) {
5345 if (orderByComparator.isAscending() ^ previous) {
5346 query.append(ORDER_BY_ASC_HAS_NEXT);
5347 }
5348 else {
5349 query.append(ORDER_BY_DESC_HAS_NEXT);
5350 }
5351 }
5352 else {
5353 if (orderByComparator.isAscending() ^ previous) {
5354 query.append(ORDER_BY_ASC);
5355 }
5356 else {
5357 query.append(ORDER_BY_DESC);
5358 }
5359 }
5360 }
5361 }
5362 else {
5363 if (getDB().isSupportsInlineDistinct()) {
5364 query.append(RoleModelImpl.ORDER_BY_JPQL);
5365 }
5366 else {
5367 query.append(RoleModelImpl.ORDER_BY_SQL);
5368 }
5369 }
5370
5371 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5372 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5373
5374 SQLQuery q = session.createSQLQuery(sql);
5375
5376 q.setFirstResult(0);
5377 q.setMaxResults(2);
5378
5379 if (getDB().isSupportsInlineDistinct()) {
5380 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
5381 }
5382 else {
5383 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
5384 }
5385
5386 QueryPos qPos = QueryPos.getInstance(q);
5387
5388 if (bindSubtype) {
5389 qPos.add(subtype);
5390 }
5391
5392 if (orderByComparator != null) {
5393 Object[] values = orderByComparator.getOrderByConditionValues(role);
5394
5395 for (Object value : values) {
5396 qPos.add(value);
5397 }
5398 }
5399
5400 List<Role> list = q.list();
5401
5402 if (list.size() == 2) {
5403 return list.get(1);
5404 }
5405 else {
5406 return null;
5407 }
5408 }
5409
5410
5416 @Override
5417 public void removeBySubtype(String subtype) throws SystemException {
5418 for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
5419 QueryUtil.ALL_POS, null)) {
5420 remove(role);
5421 }
5422 }
5423
5424
5431 @Override
5432 public int countBySubtype(String subtype) throws SystemException {
5433 FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
5434
5435 Object[] finderArgs = new Object[] { subtype };
5436
5437 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5438 this);
5439
5440 if (count == null) {
5441 StringBundler query = new StringBundler(2);
5442
5443 query.append(_SQL_COUNT_ROLE_WHERE);
5444
5445 boolean bindSubtype = false;
5446
5447 if (subtype == null) {
5448 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5449 }
5450 else if (subtype.equals(StringPool.BLANK)) {
5451 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5452 }
5453 else {
5454 bindSubtype = true;
5455
5456 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5457 }
5458
5459 String sql = query.toString();
5460
5461 Session session = null;
5462
5463 try {
5464 session = openSession();
5465
5466 Query q = session.createQuery(sql);
5467
5468 QueryPos qPos = QueryPos.getInstance(q);
5469
5470 if (bindSubtype) {
5471 qPos.add(subtype);
5472 }
5473
5474 count = (Long)q.uniqueResult();
5475
5476 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5477 }
5478 catch (Exception e) {
5479 FinderCacheUtil.removeResult(finderPath, finderArgs);
5480
5481 throw processException(e);
5482 }
5483 finally {
5484 closeSession(session);
5485 }
5486 }
5487
5488 return count.intValue();
5489 }
5490
5491
5498 @Override
5499 public int filterCountBySubtype(String subtype) throws SystemException {
5500 if (!InlineSQLHelperUtil.isEnabled()) {
5501 return countBySubtype(subtype);
5502 }
5503
5504 StringBundler query = new StringBundler(2);
5505
5506 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
5507
5508 boolean bindSubtype = false;
5509
5510 if (subtype == null) {
5511 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
5512 }
5513 else if (subtype.equals(StringPool.BLANK)) {
5514 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
5515 }
5516 else {
5517 bindSubtype = true;
5518
5519 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
5520 }
5521
5522 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5523 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
5524
5525 Session session = null;
5526
5527 try {
5528 session = openSession();
5529
5530 SQLQuery q = session.createSQLQuery(sql);
5531
5532 q.addScalar(COUNT_COLUMN_NAME,
5533 com.liferay.portal.kernel.dao.orm.Type.LONG);
5534
5535 QueryPos qPos = QueryPos.getInstance(q);
5536
5537 if (bindSubtype) {
5538 qPos.add(subtype);
5539 }
5540
5541 Long count = (Long)q.uniqueResult();
5542
5543 return count.intValue();
5544 }
5545 catch (Exception e) {
5546 throw processException(e);
5547 }
5548 finally {
5549 closeSession(session);
5550 }
5551 }
5552
5553 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5554 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5555 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
5556 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5557 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5558 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
5559 new String[] { Long.class.getName(), String.class.getName() },
5560 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
5561 RoleModelImpl.NAME_COLUMN_BITMASK);
5562 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5563 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5564 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
5565 new String[] { Long.class.getName(), String.class.getName() });
5566
5567
5576 @Override
5577 public Role findByC_N(long companyId, String name)
5578 throws NoSuchRoleException, SystemException {
5579 Role role = fetchByC_N(companyId, name);
5580
5581 if (role == null) {
5582 StringBundler msg = new StringBundler(6);
5583
5584 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5585
5586 msg.append("companyId=");
5587 msg.append(companyId);
5588
5589 msg.append(", name=");
5590 msg.append(name);
5591
5592 msg.append(StringPool.CLOSE_CURLY_BRACE);
5593
5594 if (_log.isWarnEnabled()) {
5595 _log.warn(msg.toString());
5596 }
5597
5598 throw new NoSuchRoleException(msg.toString());
5599 }
5600
5601 return role;
5602 }
5603
5604
5612 @Override
5613 public Role fetchByC_N(long companyId, String name)
5614 throws SystemException {
5615 return fetchByC_N(companyId, name, true);
5616 }
5617
5618
5627 @Override
5628 public Role fetchByC_N(long companyId, String name,
5629 boolean retrieveFromCache) throws SystemException {
5630 Object[] finderArgs = new Object[] { companyId, name };
5631
5632 Object result = null;
5633
5634 if (retrieveFromCache) {
5635 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
5636 finderArgs, this);
5637 }
5638
5639 if (result instanceof Role) {
5640 Role role = (Role)result;
5641
5642 if ((companyId != role.getCompanyId()) ||
5643 !Validator.equals(name, role.getName())) {
5644 result = null;
5645 }
5646 }
5647
5648 if (result == null) {
5649 StringBundler query = new StringBundler(4);
5650
5651 query.append(_SQL_SELECT_ROLE_WHERE);
5652
5653 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5654
5655 boolean bindName = false;
5656
5657 if (name == null) {
5658 query.append(_FINDER_COLUMN_C_N_NAME_1);
5659 }
5660 else if (name.equals(StringPool.BLANK)) {
5661 query.append(_FINDER_COLUMN_C_N_NAME_3);
5662 }
5663 else {
5664 bindName = true;
5665
5666 query.append(_FINDER_COLUMN_C_N_NAME_2);
5667 }
5668
5669 String sql = query.toString();
5670
5671 Session session = null;
5672
5673 try {
5674 session = openSession();
5675
5676 Query q = session.createQuery(sql);
5677
5678 QueryPos qPos = QueryPos.getInstance(q);
5679
5680 qPos.add(companyId);
5681
5682 if (bindName) {
5683 qPos.add(name.toLowerCase());
5684 }
5685
5686 List<Role> list = q.list();
5687
5688 if (list.isEmpty()) {
5689 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5690 finderArgs, list);
5691 }
5692 else {
5693 Role role = list.get(0);
5694
5695 result = role;
5696
5697 cacheResult(role);
5698
5699 if ((role.getCompanyId() != companyId) ||
5700 (role.getName() == null) ||
5701 !role.getName().equals(name)) {
5702 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
5703 finderArgs, role);
5704 }
5705 }
5706 }
5707 catch (Exception e) {
5708 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
5709 finderArgs);
5710
5711 throw processException(e);
5712 }
5713 finally {
5714 closeSession(session);
5715 }
5716 }
5717
5718 if (result instanceof List<?>) {
5719 return null;
5720 }
5721 else {
5722 return (Role)result;
5723 }
5724 }
5725
5726
5734 @Override
5735 public Role removeByC_N(long companyId, String name)
5736 throws NoSuchRoleException, SystemException {
5737 Role role = findByC_N(companyId, name);
5738
5739 return remove(role);
5740 }
5741
5742
5750 @Override
5751 public int countByC_N(long companyId, String name)
5752 throws SystemException {
5753 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
5754
5755 Object[] finderArgs = new Object[] { companyId, name };
5756
5757 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5758 this);
5759
5760 if (count == null) {
5761 StringBundler query = new StringBundler(3);
5762
5763 query.append(_SQL_COUNT_ROLE_WHERE);
5764
5765 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
5766
5767 boolean bindName = false;
5768
5769 if (name == null) {
5770 query.append(_FINDER_COLUMN_C_N_NAME_1);
5771 }
5772 else if (name.equals(StringPool.BLANK)) {
5773 query.append(_FINDER_COLUMN_C_N_NAME_3);
5774 }
5775 else {
5776 bindName = true;
5777
5778 query.append(_FINDER_COLUMN_C_N_NAME_2);
5779 }
5780
5781 String sql = query.toString();
5782
5783 Session session = null;
5784
5785 try {
5786 session = openSession();
5787
5788 Query q = session.createQuery(sql);
5789
5790 QueryPos qPos = QueryPos.getInstance(q);
5791
5792 qPos.add(companyId);
5793
5794 if (bindName) {
5795 qPos.add(name.toLowerCase());
5796 }
5797
5798 count = (Long)q.uniqueResult();
5799
5800 FinderCacheUtil.putResult(finderPath, finderArgs, count);
5801 }
5802 catch (Exception e) {
5803 FinderCacheUtil.removeResult(finderPath, finderArgs);
5804
5805 throw processException(e);
5806 }
5807 finally {
5808 closeSession(session);
5809 }
5810 }
5811
5812 return count.intValue();
5813 }
5814
5815 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5816 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5817 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = ?";
5818 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = '')";
5819 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5820 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5821 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
5822 new String[] {
5823 Integer.class.getName(), String.class.getName(),
5824
5825 Integer.class.getName(), Integer.class.getName(),
5826 OrderByComparator.class.getName()
5827 });
5828 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5829 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
5830 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
5831 new String[] { Integer.class.getName(), String.class.getName() },
5832 RoleModelImpl.TYPE_COLUMN_BITMASK |
5833 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
5834 RoleModelImpl.NAME_COLUMN_BITMASK);
5835 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
5836 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
5837 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
5838 new String[] { Integer.class.getName(), String.class.getName() });
5839
5840
5848 @Override
5849 public List<Role> findByT_S(int type, String subtype)
5850 throws SystemException {
5851 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5852 null);
5853 }
5854
5855
5869 @Override
5870 public List<Role> findByT_S(int type, String subtype, int start, int end)
5871 throws SystemException {
5872 return findByT_S(type, subtype, start, end, null);
5873 }
5874
5875
5890 @Override
5891 public List<Role> findByT_S(int type, String subtype, int start, int end,
5892 OrderByComparator orderByComparator) throws SystemException {
5893 boolean pagination = true;
5894 FinderPath finderPath = null;
5895 Object[] finderArgs = null;
5896
5897 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5898 (orderByComparator == null)) {
5899 pagination = false;
5900 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
5901 finderArgs = new Object[] { type, subtype };
5902 }
5903 else {
5904 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
5905 finderArgs = new Object[] {
5906 type, subtype,
5907
5908 start, end, orderByComparator
5909 };
5910 }
5911
5912 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
5913 finderArgs, this);
5914
5915 if ((list != null) && !list.isEmpty()) {
5916 for (Role role : list) {
5917 if ((type != role.getType()) ||
5918 !Validator.equals(subtype, role.getSubtype())) {
5919 list = null;
5920
5921 break;
5922 }
5923 }
5924 }
5925
5926 if (list == null) {
5927 StringBundler query = null;
5928
5929 if (orderByComparator != null) {
5930 query = new StringBundler(4 +
5931 (orderByComparator.getOrderByFields().length * 3));
5932 }
5933 else {
5934 query = new StringBundler(4);
5935 }
5936
5937 query.append(_SQL_SELECT_ROLE_WHERE);
5938
5939 query.append(_FINDER_COLUMN_T_S_TYPE_2);
5940
5941 boolean bindSubtype = false;
5942
5943 if (subtype == null) {
5944 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
5945 }
5946 else if (subtype.equals(StringPool.BLANK)) {
5947 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
5948 }
5949 else {
5950 bindSubtype = true;
5951
5952 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
5953 }
5954
5955 if (orderByComparator != null) {
5956 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5957 orderByComparator);
5958 }
5959 else
5960 if (pagination) {
5961 query.append(RoleModelImpl.ORDER_BY_JPQL);
5962 }
5963
5964 String sql = query.toString();
5965
5966 Session session = null;
5967
5968 try {
5969 session = openSession();
5970
5971 Query q = session.createQuery(sql);
5972
5973 QueryPos qPos = QueryPos.getInstance(q);
5974
5975 qPos.add(type);
5976
5977 if (bindSubtype) {
5978 qPos.add(subtype);
5979 }
5980
5981 if (!pagination) {
5982 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5983 end, false);
5984
5985 Collections.sort(list);
5986
5987 list = new UnmodifiableList<Role>(list);
5988 }
5989 else {
5990 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
5991 end);
5992 }
5993
5994 cacheResult(list);
5995
5996 FinderCacheUtil.putResult(finderPath, finderArgs, list);
5997 }
5998 catch (Exception e) {
5999 FinderCacheUtil.removeResult(finderPath, finderArgs);
6000
6001 throw processException(e);
6002 }
6003 finally {
6004 closeSession(session);
6005 }
6006 }
6007
6008 return list;
6009 }
6010
6011
6021 @Override
6022 public Role findByT_S_First(int type, String subtype,
6023 OrderByComparator orderByComparator)
6024 throws NoSuchRoleException, SystemException {
6025 Role role = fetchByT_S_First(type, subtype, orderByComparator);
6026
6027 if (role != null) {
6028 return role;
6029 }
6030
6031 StringBundler msg = new StringBundler(6);
6032
6033 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6034
6035 msg.append("type=");
6036 msg.append(type);
6037
6038 msg.append(", subtype=");
6039 msg.append(subtype);
6040
6041 msg.append(StringPool.CLOSE_CURLY_BRACE);
6042
6043 throw new NoSuchRoleException(msg.toString());
6044 }
6045
6046
6055 @Override
6056 public Role fetchByT_S_First(int type, String subtype,
6057 OrderByComparator orderByComparator) throws SystemException {
6058 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
6059
6060 if (!list.isEmpty()) {
6061 return list.get(0);
6062 }
6063
6064 return null;
6065 }
6066
6067
6077 @Override
6078 public Role findByT_S_Last(int type, String subtype,
6079 OrderByComparator orderByComparator)
6080 throws NoSuchRoleException, SystemException {
6081 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
6082
6083 if (role != null) {
6084 return role;
6085 }
6086
6087 StringBundler msg = new StringBundler(6);
6088
6089 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6090
6091 msg.append("type=");
6092 msg.append(type);
6093
6094 msg.append(", subtype=");
6095 msg.append(subtype);
6096
6097 msg.append(StringPool.CLOSE_CURLY_BRACE);
6098
6099 throw new NoSuchRoleException(msg.toString());
6100 }
6101
6102
6111 @Override
6112 public Role fetchByT_S_Last(int type, String subtype,
6113 OrderByComparator orderByComparator) throws SystemException {
6114 int count = countByT_S(type, subtype);
6115
6116 if (count == 0) {
6117 return null;
6118 }
6119
6120 List<Role> list = findByT_S(type, subtype, count - 1, count,
6121 orderByComparator);
6122
6123 if (!list.isEmpty()) {
6124 return list.get(0);
6125 }
6126
6127 return null;
6128 }
6129
6130
6141 @Override
6142 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
6143 OrderByComparator orderByComparator)
6144 throws NoSuchRoleException, SystemException {
6145 Role role = findByPrimaryKey(roleId);
6146
6147 Session session = null;
6148
6149 try {
6150 session = openSession();
6151
6152 Role[] array = new RoleImpl[3];
6153
6154 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
6155 orderByComparator, true);
6156
6157 array[1] = role;
6158
6159 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
6160 orderByComparator, false);
6161
6162 return array;
6163 }
6164 catch (Exception e) {
6165 throw processException(e);
6166 }
6167 finally {
6168 closeSession(session);
6169 }
6170 }
6171
6172 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
6173 String subtype, OrderByComparator orderByComparator, boolean previous) {
6174 StringBundler query = null;
6175
6176 if (orderByComparator != null) {
6177 query = new StringBundler(6 +
6178 (orderByComparator.getOrderByFields().length * 6));
6179 }
6180 else {
6181 query = new StringBundler(3);
6182 }
6183
6184 query.append(_SQL_SELECT_ROLE_WHERE);
6185
6186 query.append(_FINDER_COLUMN_T_S_TYPE_2);
6187
6188 boolean bindSubtype = false;
6189
6190 if (subtype == null) {
6191 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6192 }
6193 else if (subtype.equals(StringPool.BLANK)) {
6194 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6195 }
6196 else {
6197 bindSubtype = true;
6198
6199 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6200 }
6201
6202 if (orderByComparator != null) {
6203 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6204
6205 if (orderByConditionFields.length > 0) {
6206 query.append(WHERE_AND);
6207 }
6208
6209 for (int i = 0; i < orderByConditionFields.length; i++) {
6210 query.append(_ORDER_BY_ENTITY_ALIAS);
6211 query.append(orderByConditionFields[i]);
6212
6213 if ((i + 1) < orderByConditionFields.length) {
6214 if (orderByComparator.isAscending() ^ previous) {
6215 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6216 }
6217 else {
6218 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6219 }
6220 }
6221 else {
6222 if (orderByComparator.isAscending() ^ previous) {
6223 query.append(WHERE_GREATER_THAN);
6224 }
6225 else {
6226 query.append(WHERE_LESSER_THAN);
6227 }
6228 }
6229 }
6230
6231 query.append(ORDER_BY_CLAUSE);
6232
6233 String[] orderByFields = orderByComparator.getOrderByFields();
6234
6235 for (int i = 0; i < orderByFields.length; i++) {
6236 query.append(_ORDER_BY_ENTITY_ALIAS);
6237 query.append(orderByFields[i]);
6238
6239 if ((i + 1) < orderByFields.length) {
6240 if (orderByComparator.isAscending() ^ previous) {
6241 query.append(ORDER_BY_ASC_HAS_NEXT);
6242 }
6243 else {
6244 query.append(ORDER_BY_DESC_HAS_NEXT);
6245 }
6246 }
6247 else {
6248 if (orderByComparator.isAscending() ^ previous) {
6249 query.append(ORDER_BY_ASC);
6250 }
6251 else {
6252 query.append(ORDER_BY_DESC);
6253 }
6254 }
6255 }
6256 }
6257 else {
6258 query.append(RoleModelImpl.ORDER_BY_JPQL);
6259 }
6260
6261 String sql = query.toString();
6262
6263 Query q = session.createQuery(sql);
6264
6265 q.setFirstResult(0);
6266 q.setMaxResults(2);
6267
6268 QueryPos qPos = QueryPos.getInstance(q);
6269
6270 qPos.add(type);
6271
6272 if (bindSubtype) {
6273 qPos.add(subtype);
6274 }
6275
6276 if (orderByComparator != null) {
6277 Object[] values = orderByComparator.getOrderByConditionValues(role);
6278
6279 for (Object value : values) {
6280 qPos.add(value);
6281 }
6282 }
6283
6284 List<Role> list = q.list();
6285
6286 if (list.size() == 2) {
6287 return list.get(1);
6288 }
6289 else {
6290 return null;
6291 }
6292 }
6293
6294
6302 @Override
6303 public List<Role> filterFindByT_S(int type, String subtype)
6304 throws SystemException {
6305 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
6306 QueryUtil.ALL_POS, null);
6307 }
6308
6309
6323 @Override
6324 public List<Role> filterFindByT_S(int type, String subtype, int start,
6325 int end) throws SystemException {
6326 return filterFindByT_S(type, subtype, start, end, null);
6327 }
6328
6329
6344 @Override
6345 public List<Role> filterFindByT_S(int type, String subtype, int start,
6346 int end, OrderByComparator orderByComparator) throws SystemException {
6347 if (!InlineSQLHelperUtil.isEnabled()) {
6348 return findByT_S(type, subtype, start, end, orderByComparator);
6349 }
6350
6351 StringBundler query = null;
6352
6353 if (orderByComparator != null) {
6354 query = new StringBundler(4 +
6355 (orderByComparator.getOrderByFields().length * 3));
6356 }
6357 else {
6358 query = new StringBundler(4);
6359 }
6360
6361 if (getDB().isSupportsInlineDistinct()) {
6362 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6363 }
6364 else {
6365 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6366 }
6367
6368 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
6369
6370 boolean bindSubtype = false;
6371
6372 if (subtype == null) {
6373 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6374 }
6375 else if (subtype.equals(StringPool.BLANK)) {
6376 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6377 }
6378 else {
6379 bindSubtype = true;
6380
6381 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6382 }
6383
6384 if (!getDB().isSupportsInlineDistinct()) {
6385 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6386 }
6387
6388 if (orderByComparator != null) {
6389 if (getDB().isSupportsInlineDistinct()) {
6390 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6391 orderByComparator, true);
6392 }
6393 else {
6394 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6395 orderByComparator, true);
6396 }
6397 }
6398 else {
6399 if (getDB().isSupportsInlineDistinct()) {
6400 query.append(RoleModelImpl.ORDER_BY_JPQL);
6401 }
6402 else {
6403 query.append(RoleModelImpl.ORDER_BY_SQL);
6404 }
6405 }
6406
6407 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6408 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6409
6410 Session session = null;
6411
6412 try {
6413 session = openSession();
6414
6415 SQLQuery q = session.createSQLQuery(sql);
6416
6417 if (getDB().isSupportsInlineDistinct()) {
6418 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6419 }
6420 else {
6421 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6422 }
6423
6424 QueryPos qPos = QueryPos.getInstance(q);
6425
6426 qPos.add(type);
6427
6428 if (bindSubtype) {
6429 qPos.add(subtype);
6430 }
6431
6432 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
6433 }
6434 catch (Exception e) {
6435 throw processException(e);
6436 }
6437 finally {
6438 closeSession(session);
6439 }
6440 }
6441
6442
6453 @Override
6454 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
6455 String subtype, OrderByComparator orderByComparator)
6456 throws NoSuchRoleException, SystemException {
6457 if (!InlineSQLHelperUtil.isEnabled()) {
6458 return findByT_S_PrevAndNext(roleId, type, subtype,
6459 orderByComparator);
6460 }
6461
6462 Role role = findByPrimaryKey(roleId);
6463
6464 Session session = null;
6465
6466 try {
6467 session = openSession();
6468
6469 Role[] array = new RoleImpl[3];
6470
6471 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
6472 orderByComparator, true);
6473
6474 array[1] = role;
6475
6476 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
6477 orderByComparator, false);
6478
6479 return array;
6480 }
6481 catch (Exception e) {
6482 throw processException(e);
6483 }
6484 finally {
6485 closeSession(session);
6486 }
6487 }
6488
6489 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
6490 int type, String subtype, OrderByComparator orderByComparator,
6491 boolean previous) {
6492 StringBundler query = null;
6493
6494 if (orderByComparator != null) {
6495 query = new StringBundler(6 +
6496 (orderByComparator.getOrderByFields().length * 6));
6497 }
6498 else {
6499 query = new StringBundler(3);
6500 }
6501
6502 if (getDB().isSupportsInlineDistinct()) {
6503 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
6504 }
6505 else {
6506 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
6507 }
6508
6509 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
6510
6511 boolean bindSubtype = false;
6512
6513 if (subtype == null) {
6514 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6515 }
6516 else if (subtype.equals(StringPool.BLANK)) {
6517 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6518 }
6519 else {
6520 bindSubtype = true;
6521
6522 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6523 }
6524
6525 if (!getDB().isSupportsInlineDistinct()) {
6526 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
6527 }
6528
6529 if (orderByComparator != null) {
6530 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6531
6532 if (orderByConditionFields.length > 0) {
6533 query.append(WHERE_AND);
6534 }
6535
6536 for (int i = 0; i < orderByConditionFields.length; i++) {
6537 if (getDB().isSupportsInlineDistinct()) {
6538 query.append(_ORDER_BY_ENTITY_ALIAS);
6539 }
6540 else {
6541 query.append(_ORDER_BY_ENTITY_TABLE);
6542 }
6543
6544 query.append(orderByConditionFields[i]);
6545
6546 if ((i + 1) < orderByConditionFields.length) {
6547 if (orderByComparator.isAscending() ^ previous) {
6548 query.append(WHERE_GREATER_THAN_HAS_NEXT);
6549 }
6550 else {
6551 query.append(WHERE_LESSER_THAN_HAS_NEXT);
6552 }
6553 }
6554 else {
6555 if (orderByComparator.isAscending() ^ previous) {
6556 query.append(WHERE_GREATER_THAN);
6557 }
6558 else {
6559 query.append(WHERE_LESSER_THAN);
6560 }
6561 }
6562 }
6563
6564 query.append(ORDER_BY_CLAUSE);
6565
6566 String[] orderByFields = orderByComparator.getOrderByFields();
6567
6568 for (int i = 0; i < orderByFields.length; i++) {
6569 if (getDB().isSupportsInlineDistinct()) {
6570 query.append(_ORDER_BY_ENTITY_ALIAS);
6571 }
6572 else {
6573 query.append(_ORDER_BY_ENTITY_TABLE);
6574 }
6575
6576 query.append(orderByFields[i]);
6577
6578 if ((i + 1) < orderByFields.length) {
6579 if (orderByComparator.isAscending() ^ previous) {
6580 query.append(ORDER_BY_ASC_HAS_NEXT);
6581 }
6582 else {
6583 query.append(ORDER_BY_DESC_HAS_NEXT);
6584 }
6585 }
6586 else {
6587 if (orderByComparator.isAscending() ^ previous) {
6588 query.append(ORDER_BY_ASC);
6589 }
6590 else {
6591 query.append(ORDER_BY_DESC);
6592 }
6593 }
6594 }
6595 }
6596 else {
6597 if (getDB().isSupportsInlineDistinct()) {
6598 query.append(RoleModelImpl.ORDER_BY_JPQL);
6599 }
6600 else {
6601 query.append(RoleModelImpl.ORDER_BY_SQL);
6602 }
6603 }
6604
6605 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6606 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6607
6608 SQLQuery q = session.createSQLQuery(sql);
6609
6610 q.setFirstResult(0);
6611 q.setMaxResults(2);
6612
6613 if (getDB().isSupportsInlineDistinct()) {
6614 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
6615 }
6616 else {
6617 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
6618 }
6619
6620 QueryPos qPos = QueryPos.getInstance(q);
6621
6622 qPos.add(type);
6623
6624 if (bindSubtype) {
6625 qPos.add(subtype);
6626 }
6627
6628 if (orderByComparator != null) {
6629 Object[] values = orderByComparator.getOrderByConditionValues(role);
6630
6631 for (Object value : values) {
6632 qPos.add(value);
6633 }
6634 }
6635
6636 List<Role> list = q.list();
6637
6638 if (list.size() == 2) {
6639 return list.get(1);
6640 }
6641 else {
6642 return null;
6643 }
6644 }
6645
6646
6653 @Override
6654 public void removeByT_S(int type, String subtype) throws SystemException {
6655 for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
6656 QueryUtil.ALL_POS, null)) {
6657 remove(role);
6658 }
6659 }
6660
6661
6669 @Override
6670 public int countByT_S(int type, String subtype) throws SystemException {
6671 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
6672
6673 Object[] finderArgs = new Object[] { type, subtype };
6674
6675 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6676 this);
6677
6678 if (count == null) {
6679 StringBundler query = new StringBundler(3);
6680
6681 query.append(_SQL_COUNT_ROLE_WHERE);
6682
6683 query.append(_FINDER_COLUMN_T_S_TYPE_2);
6684
6685 boolean bindSubtype = false;
6686
6687 if (subtype == null) {
6688 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6689 }
6690 else if (subtype.equals(StringPool.BLANK)) {
6691 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6692 }
6693 else {
6694 bindSubtype = true;
6695
6696 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6697 }
6698
6699 String sql = query.toString();
6700
6701 Session session = null;
6702
6703 try {
6704 session = openSession();
6705
6706 Query q = session.createQuery(sql);
6707
6708 QueryPos qPos = QueryPos.getInstance(q);
6709
6710 qPos.add(type);
6711
6712 if (bindSubtype) {
6713 qPos.add(subtype);
6714 }
6715
6716 count = (Long)q.uniqueResult();
6717
6718 FinderCacheUtil.putResult(finderPath, finderArgs, count);
6719 }
6720 catch (Exception e) {
6721 FinderCacheUtil.removeResult(finderPath, finderArgs);
6722
6723 throw processException(e);
6724 }
6725 finally {
6726 closeSession(session);
6727 }
6728 }
6729
6730 return count.intValue();
6731 }
6732
6733
6741 @Override
6742 public int filterCountByT_S(int type, String subtype)
6743 throws SystemException {
6744 if (!InlineSQLHelperUtil.isEnabled()) {
6745 return countByT_S(type, subtype);
6746 }
6747
6748 StringBundler query = new StringBundler(3);
6749
6750 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
6751
6752 query.append(_FINDER_COLUMN_T_S_TYPE_2_SQL);
6753
6754 boolean bindSubtype = false;
6755
6756 if (subtype == null) {
6757 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
6758 }
6759 else if (subtype.equals(StringPool.BLANK)) {
6760 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
6761 }
6762 else {
6763 bindSubtype = true;
6764
6765 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
6766 }
6767
6768 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6769 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
6770
6771 Session session = null;
6772
6773 try {
6774 session = openSession();
6775
6776 SQLQuery q = session.createSQLQuery(sql);
6777
6778 q.addScalar(COUNT_COLUMN_NAME,
6779 com.liferay.portal.kernel.dao.orm.Type.LONG);
6780
6781 QueryPos qPos = QueryPos.getInstance(q);
6782
6783 qPos.add(type);
6784
6785 if (bindSubtype) {
6786 qPos.add(subtype);
6787 }
6788
6789 Long count = (Long)q.uniqueResult();
6790
6791 return count.intValue();
6792 }
6793 catch (Exception e) {
6794 throw processException(e);
6795 }
6796 finally {
6797 closeSession(session);
6798 }
6799 }
6800
6801 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
6802 private static final String _FINDER_COLUMN_T_S_TYPE_2_SQL = "role.type_ = ? AND ";
6803 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
6804 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
6805 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = '')";
6806 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
6807 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
6808 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
6809 new String[] {
6810 Long.class.getName(), Long.class.getName(), Long.class.getName()
6811 },
6812 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
6813 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
6814 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
6815 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
6816 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
6817 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
6818 new String[] {
6819 Long.class.getName(), Long.class.getName(), Long.class.getName()
6820 });
6821
6822
6832 @Override
6833 public Role findByC_C_C(long companyId, long classNameId, long classPK)
6834 throws NoSuchRoleException, SystemException {
6835 Role role = fetchByC_C_C(companyId, classNameId, classPK);
6836
6837 if (role == null) {
6838 StringBundler msg = new StringBundler(8);
6839
6840 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6841
6842 msg.append("companyId=");
6843 msg.append(companyId);
6844
6845 msg.append(", classNameId=");
6846 msg.append(classNameId);
6847
6848 msg.append(", classPK=");
6849 msg.append(classPK);
6850
6851 msg.append(StringPool.CLOSE_CURLY_BRACE);
6852
6853 if (_log.isWarnEnabled()) {
6854 _log.warn(msg.toString());
6855 }
6856
6857 throw new NoSuchRoleException(msg.toString());
6858 }
6859
6860 return role;
6861 }
6862
6863
6872 @Override
6873 public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
6874 throws SystemException {
6875 return fetchByC_C_C(companyId, classNameId, classPK, true);
6876 }
6877
6878
6888 @Override
6889 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
6890 boolean retrieveFromCache) throws SystemException {
6891 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
6892
6893 Object result = null;
6894
6895 if (retrieveFromCache) {
6896 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
6897 finderArgs, this);
6898 }
6899
6900 if (result instanceof Role) {
6901 Role role = (Role)result;
6902
6903 if ((companyId != role.getCompanyId()) ||
6904 (classNameId != role.getClassNameId()) ||
6905 (classPK != role.getClassPK())) {
6906 result = null;
6907 }
6908 }
6909
6910 if (result == null) {
6911 StringBundler query = new StringBundler(5);
6912
6913 query.append(_SQL_SELECT_ROLE_WHERE);
6914
6915 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
6916
6917 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
6918
6919 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
6920
6921 String sql = query.toString();
6922
6923 Session session = null;
6924
6925 try {
6926 session = openSession();
6927
6928 Query q = session.createQuery(sql);
6929
6930 QueryPos qPos = QueryPos.getInstance(q);
6931
6932 qPos.add(companyId);
6933
6934 qPos.add(classNameId);
6935
6936 qPos.add(classPK);
6937
6938 List<Role> list = q.list();
6939
6940 if (list.isEmpty()) {
6941 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
6942 finderArgs, list);
6943 }
6944 else {
6945 Role role = list.get(0);
6946
6947 result = role;
6948
6949 cacheResult(role);
6950
6951 if ((role.getCompanyId() != companyId) ||
6952 (role.getClassNameId() != classNameId) ||
6953 (role.getClassPK() != classPK)) {
6954 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
6955 finderArgs, role);
6956 }
6957 }
6958 }
6959 catch (Exception e) {
6960 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
6961 finderArgs);
6962
6963 throw processException(e);
6964 }
6965 finally {
6966 closeSession(session);
6967 }
6968 }
6969
6970 if (result instanceof List<?>) {
6971 return null;
6972 }
6973 else {
6974 return (Role)result;
6975 }
6976 }
6977
6978
6987 @Override
6988 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
6989 throws NoSuchRoleException, SystemException {
6990 Role role = findByC_C_C(companyId, classNameId, classPK);
6991
6992 return remove(role);
6993 }
6994
6995
7004 @Override
7005 public int countByC_C_C(long companyId, long classNameId, long classPK)
7006 throws SystemException {
7007 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
7008
7009 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
7010
7011 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7012 this);
7013
7014 if (count == null) {
7015 StringBundler query = new StringBundler(4);
7016
7017 query.append(_SQL_COUNT_ROLE_WHERE);
7018
7019 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
7020
7021 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
7022
7023 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
7024
7025 String sql = query.toString();
7026
7027 Session session = null;
7028
7029 try {
7030 session = openSession();
7031
7032 Query q = session.createQuery(sql);
7033
7034 QueryPos qPos = QueryPos.getInstance(q);
7035
7036 qPos.add(companyId);
7037
7038 qPos.add(classNameId);
7039
7040 qPos.add(classPK);
7041
7042 count = (Long)q.uniqueResult();
7043
7044 FinderCacheUtil.putResult(finderPath, finderArgs, count);
7045 }
7046 catch (Exception e) {
7047 FinderCacheUtil.removeResult(finderPath, finderArgs);
7048
7049 throw processException(e);
7050 }
7051 finally {
7052 closeSession(session);
7053 }
7054 }
7055
7056 return count.intValue();
7057 }
7058
7059 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
7060 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
7061 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
7062
7063
7068 @Override
7069 public void cacheResult(Role role) {
7070 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7071 RoleImpl.class, role.getPrimaryKey(), role);
7072
7073 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
7074 new Object[] { role.getCompanyId(), role.getName() }, role);
7075
7076 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
7077 new Object[] {
7078 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
7079 }, role);
7080
7081 role.resetOriginalValues();
7082 }
7083
7084
7089 @Override
7090 public void cacheResult(List<Role> roles) {
7091 for (Role role : roles) {
7092 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7093 RoleImpl.class, role.getPrimaryKey()) == null) {
7094 cacheResult(role);
7095 }
7096 else {
7097 role.resetOriginalValues();
7098 }
7099 }
7100 }
7101
7102
7109 @Override
7110 public void clearCache() {
7111 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7112 CacheRegistryUtil.clear(RoleImpl.class.getName());
7113 }
7114
7115 EntityCacheUtil.clearCache(RoleImpl.class.getName());
7116
7117 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7118 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7119 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7120 }
7121
7122
7129 @Override
7130 public void clearCache(Role role) {
7131 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7132 RoleImpl.class, role.getPrimaryKey());
7133
7134 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7135 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7136
7137 clearUniqueFindersCache(role);
7138 }
7139
7140 @Override
7141 public void clearCache(List<Role> roles) {
7142 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7143 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7144
7145 for (Role role : roles) {
7146 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7147 RoleImpl.class, role.getPrimaryKey());
7148
7149 clearUniqueFindersCache(role);
7150 }
7151 }
7152
7153 protected void cacheUniqueFindersCache(Role role) {
7154 if (role.isNew()) {
7155 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
7156
7157 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
7158 Long.valueOf(1));
7159 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
7160
7161 args = new Object[] {
7162 role.getCompanyId(), role.getClassNameId(),
7163 role.getClassPK()
7164 };
7165
7166 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
7167 Long.valueOf(1));
7168 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
7169 }
7170 else {
7171 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
7172
7173 if ((roleModelImpl.getColumnBitmask() &
7174 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
7175 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
7176
7177 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
7178 Long.valueOf(1));
7179 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
7180 }
7181
7182 if ((roleModelImpl.getColumnBitmask() &
7183 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
7184 Object[] args = new Object[] {
7185 role.getCompanyId(), role.getClassNameId(),
7186 role.getClassPK()
7187 };
7188
7189 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
7190 Long.valueOf(1));
7191 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
7192 }
7193 }
7194 }
7195
7196 protected void clearUniqueFindersCache(Role role) {
7197 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
7198
7199 Object[] args = new Object[] { role.getCompanyId(), role.getName() };
7200
7201 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
7202 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
7203
7204 if ((roleModelImpl.getColumnBitmask() &
7205 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
7206 args = new Object[] {
7207 roleModelImpl.getOriginalCompanyId(),
7208 roleModelImpl.getOriginalName()
7209 };
7210
7211 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
7212 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
7213 }
7214
7215 args = new Object[] {
7216 role.getCompanyId(), role.getClassNameId(), role.getClassPK()
7217 };
7218
7219 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
7220 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
7221
7222 if ((roleModelImpl.getColumnBitmask() &
7223 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
7224 args = new Object[] {
7225 roleModelImpl.getOriginalCompanyId(),
7226 roleModelImpl.getOriginalClassNameId(),
7227 roleModelImpl.getOriginalClassPK()
7228 };
7229
7230 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
7231 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
7232 }
7233 }
7234
7235
7241 @Override
7242 public Role create(long roleId) {
7243 Role role = new RoleImpl();
7244
7245 role.setNew(true);
7246 role.setPrimaryKey(roleId);
7247
7248 String uuid = PortalUUIDUtil.generate();
7249
7250 role.setUuid(uuid);
7251
7252 return role;
7253 }
7254
7255
7263 @Override
7264 public Role remove(long roleId) throws NoSuchRoleException, SystemException {
7265 return remove((Serializable)roleId);
7266 }
7267
7268
7276 @Override
7277 public Role remove(Serializable primaryKey)
7278 throws NoSuchRoleException, SystemException {
7279 Session session = null;
7280
7281 try {
7282 session = openSession();
7283
7284 Role role = (Role)session.get(RoleImpl.class, primaryKey);
7285
7286 if (role == null) {
7287 if (_log.isWarnEnabled()) {
7288 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7289 }
7290
7291 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7292 primaryKey);
7293 }
7294
7295 return remove(role);
7296 }
7297 catch (NoSuchRoleException nsee) {
7298 throw nsee;
7299 }
7300 catch (Exception e) {
7301 throw processException(e);
7302 }
7303 finally {
7304 closeSession(session);
7305 }
7306 }
7307
7308 @Override
7309 protected Role removeImpl(Role role) throws SystemException {
7310 role = toUnwrappedModel(role);
7311
7312 try {
7313 clearGroups.clear(role.getPrimaryKey());
7314 }
7315 catch (Exception e) {
7316 throw processException(e);
7317 }
7318 finally {
7319 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
7320 }
7321
7322 try {
7323 clearUsers.clear(role.getPrimaryKey());
7324 }
7325 catch (Exception e) {
7326 throw processException(e);
7327 }
7328 finally {
7329 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
7330 }
7331
7332 Session session = null;
7333
7334 try {
7335 session = openSession();
7336
7337 if (!session.contains(role)) {
7338 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
7339 }
7340
7341 if (role != null) {
7342 session.delete(role);
7343 }
7344 }
7345 catch (Exception e) {
7346 throw processException(e);
7347 }
7348 finally {
7349 closeSession(session);
7350 }
7351
7352 if (role != null) {
7353 clearCache(role);
7354 }
7355
7356 return role;
7357 }
7358
7359 @Override
7360 public Role updateImpl(com.liferay.portal.model.Role role)
7361 throws SystemException {
7362 role = toUnwrappedModel(role);
7363
7364 boolean isNew = role.isNew();
7365
7366 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
7367
7368 if (Validator.isNull(role.getUuid())) {
7369 String uuid = PortalUUIDUtil.generate();
7370
7371 role.setUuid(uuid);
7372 }
7373
7374 Session session = null;
7375
7376 try {
7377 session = openSession();
7378
7379 if (role.isNew()) {
7380 session.save(role);
7381
7382 role.setNew(false);
7383 }
7384 else {
7385 session.merge(role);
7386 }
7387 }
7388 catch (Exception e) {
7389 throw processException(e);
7390 }
7391 finally {
7392 closeSession(session);
7393 }
7394
7395 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7396
7397 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
7398 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7399 }
7400
7401 else {
7402 if ((roleModelImpl.getColumnBitmask() &
7403 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7404 Object[] args = new Object[] { roleModelImpl.getOriginalUuid() };
7405
7406 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7407 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7408 args);
7409
7410 args = new Object[] { roleModelImpl.getUuid() };
7411
7412 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7413 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7414 args);
7415 }
7416
7417 if ((roleModelImpl.getColumnBitmask() &
7418 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7419 Object[] args = new Object[] {
7420 roleModelImpl.getOriginalUuid(),
7421 roleModelImpl.getOriginalCompanyId()
7422 };
7423
7424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7425 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7426 args);
7427
7428 args = new Object[] {
7429 roleModelImpl.getUuid(), roleModelImpl.getCompanyId()
7430 };
7431
7432 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7433 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7434 args);
7435 }
7436
7437 if ((roleModelImpl.getColumnBitmask() &
7438 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7439 Object[] args = new Object[] {
7440 roleModelImpl.getOriginalCompanyId()
7441 };
7442
7443 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7444 args);
7445 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7446 args);
7447
7448 args = new Object[] { roleModelImpl.getCompanyId() };
7449
7450 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7451 args);
7452 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7453 args);
7454 }
7455
7456 if ((roleModelImpl.getColumnBitmask() &
7457 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
7458 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
7459
7460 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
7461 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
7462 args);
7463
7464 args = new Object[] { roleModelImpl.getName() };
7465
7466 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
7467 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
7468 args);
7469 }
7470
7471 if ((roleModelImpl.getColumnBitmask() &
7472 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE.getColumnBitmask()) != 0) {
7473 Object[] args = new Object[] { roleModelImpl.getOriginalType() };
7474
7475 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
7476 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
7477 args);
7478
7479 args = new Object[] { roleModelImpl.getType() };
7480
7481 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TYPE, args);
7482 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TYPE,
7483 args);
7484 }
7485
7486 if ((roleModelImpl.getColumnBitmask() &
7487 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
7488 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
7489
7490 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
7491 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
7492 args);
7493
7494 args = new Object[] { roleModelImpl.getSubtype() };
7495
7496 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
7497 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
7498 args);
7499 }
7500
7501 if ((roleModelImpl.getColumnBitmask() &
7502 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
7503 Object[] args = new Object[] {
7504 roleModelImpl.getOriginalType(),
7505 roleModelImpl.getOriginalSubtype()
7506 };
7507
7508 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
7509 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
7510 args);
7511
7512 args = new Object[] {
7513 roleModelImpl.getType(), roleModelImpl.getSubtype()
7514 };
7515
7516 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
7517 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
7518 args);
7519 }
7520 }
7521
7522 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7523 RoleImpl.class, role.getPrimaryKey(), role);
7524
7525 clearUniqueFindersCache(role);
7526 cacheUniqueFindersCache(role);
7527
7528 return role;
7529 }
7530
7531 protected Role toUnwrappedModel(Role role) {
7532 if (role instanceof RoleImpl) {
7533 return role;
7534 }
7535
7536 RoleImpl roleImpl = new RoleImpl();
7537
7538 roleImpl.setNew(role.isNew());
7539 roleImpl.setPrimaryKey(role.getPrimaryKey());
7540
7541 roleImpl.setUuid(role.getUuid());
7542 roleImpl.setRoleId(role.getRoleId());
7543 roleImpl.setCompanyId(role.getCompanyId());
7544 roleImpl.setUserId(role.getUserId());
7545 roleImpl.setUserName(role.getUserName());
7546 roleImpl.setCreateDate(role.getCreateDate());
7547 roleImpl.setModifiedDate(role.getModifiedDate());
7548 roleImpl.setClassNameId(role.getClassNameId());
7549 roleImpl.setClassPK(role.getClassPK());
7550 roleImpl.setName(role.getName());
7551 roleImpl.setTitle(role.getTitle());
7552 roleImpl.setDescription(role.getDescription());
7553 roleImpl.setType(role.getType());
7554 roleImpl.setSubtype(role.getSubtype());
7555
7556 return roleImpl;
7557 }
7558
7559
7567 @Override
7568 public Role findByPrimaryKey(Serializable primaryKey)
7569 throws NoSuchRoleException, SystemException {
7570 Role role = fetchByPrimaryKey(primaryKey);
7571
7572 if (role == null) {
7573 if (_log.isWarnEnabled()) {
7574 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7575 }
7576
7577 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7578 primaryKey);
7579 }
7580
7581 return role;
7582 }
7583
7584
7592 @Override
7593 public Role findByPrimaryKey(long roleId)
7594 throws NoSuchRoleException, SystemException {
7595 return findByPrimaryKey((Serializable)roleId);
7596 }
7597
7598
7605 @Override
7606 public Role fetchByPrimaryKey(Serializable primaryKey)
7607 throws SystemException {
7608 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7609 RoleImpl.class, primaryKey);
7610
7611 if (role == _nullRole) {
7612 return null;
7613 }
7614
7615 if (role == null) {
7616 Session session = null;
7617
7618 try {
7619 session = openSession();
7620
7621 role = (Role)session.get(RoleImpl.class, primaryKey);
7622
7623 if (role != null) {
7624 cacheResult(role);
7625 }
7626 else {
7627 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7628 RoleImpl.class, primaryKey, _nullRole);
7629 }
7630 }
7631 catch (Exception e) {
7632 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
7633 RoleImpl.class, primaryKey);
7634
7635 throw processException(e);
7636 }
7637 finally {
7638 closeSession(session);
7639 }
7640 }
7641
7642 return role;
7643 }
7644
7645
7652 @Override
7653 public Role fetchByPrimaryKey(long roleId) throws SystemException {
7654 return fetchByPrimaryKey((Serializable)roleId);
7655 }
7656
7657
7663 @Override
7664 public List<Role> findAll() throws SystemException {
7665 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7666 }
7667
7668
7680 @Override
7681 public List<Role> findAll(int start, int end) throws SystemException {
7682 return findAll(start, end, null);
7683 }
7684
7685
7698 @Override
7699 public List<Role> findAll(int start, int end,
7700 OrderByComparator orderByComparator) throws SystemException {
7701 boolean pagination = true;
7702 FinderPath finderPath = null;
7703 Object[] finderArgs = null;
7704
7705 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7706 (orderByComparator == null)) {
7707 pagination = false;
7708 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7709 finderArgs = FINDER_ARGS_EMPTY;
7710 }
7711 else {
7712 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7713 finderArgs = new Object[] { start, end, orderByComparator };
7714 }
7715
7716 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
7717 finderArgs, this);
7718
7719 if (list == null) {
7720 StringBundler query = null;
7721 String sql = null;
7722
7723 if (orderByComparator != null) {
7724 query = new StringBundler(2 +
7725 (orderByComparator.getOrderByFields().length * 3));
7726
7727 query.append(_SQL_SELECT_ROLE);
7728
7729 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7730 orderByComparator);
7731
7732 sql = query.toString();
7733 }
7734 else {
7735 sql = _SQL_SELECT_ROLE;
7736
7737 if (pagination) {
7738 sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
7739 }
7740 }
7741
7742 Session session = null;
7743
7744 try {
7745 session = openSession();
7746
7747 Query q = session.createQuery(sql);
7748
7749 if (!pagination) {
7750 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7751 end, false);
7752
7753 Collections.sort(list);
7754
7755 list = new UnmodifiableList<Role>(list);
7756 }
7757 else {
7758 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
7759 end);
7760 }
7761
7762 cacheResult(list);
7763
7764 FinderCacheUtil.putResult(finderPath, finderArgs, list);
7765 }
7766 catch (Exception e) {
7767 FinderCacheUtil.removeResult(finderPath, finderArgs);
7768
7769 throw processException(e);
7770 }
7771 finally {
7772 closeSession(session);
7773 }
7774 }
7775
7776 return list;
7777 }
7778
7779
7784 @Override
7785 public void removeAll() throws SystemException {
7786 for (Role role : findAll()) {
7787 remove(role);
7788 }
7789 }
7790
7791
7797 @Override
7798 public int countAll() throws SystemException {
7799 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7800 FINDER_ARGS_EMPTY, this);
7801
7802 if (count == null) {
7803 Session session = null;
7804
7805 try {
7806 session = openSession();
7807
7808 Query q = session.createQuery(_SQL_COUNT_ROLE);
7809
7810 count = (Long)q.uniqueResult();
7811
7812 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7813 FINDER_ARGS_EMPTY, count);
7814 }
7815 catch (Exception e) {
7816 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7817 FINDER_ARGS_EMPTY);
7818
7819 throw processException(e);
7820 }
7821 finally {
7822 closeSession(session);
7823 }
7824 }
7825
7826 return count.intValue();
7827 }
7828
7829
7836 @Override
7837 public List<com.liferay.portal.model.Group> getGroups(long pk)
7838 throws SystemException {
7839 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
7840 }
7841
7842
7855 @Override
7856 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7857 int end) throws SystemException {
7858 return getGroups(pk, start, end, null);
7859 }
7860
7861 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
7862 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
7863 com.liferay.portal.model.impl.GroupImpl.class,
7864 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroups",
7865 new String[] {
7866 Long.class.getName(), Integer.class.getName(),
7867 Integer.class.getName(), OrderByComparator.class.getName()
7868 });
7869
7870 static {
7871 FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
7872 }
7873
7874
7888 @Override
7889 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
7890 int end, OrderByComparator orderByComparator) throws SystemException {
7891 boolean pagination = true;
7892 Object[] finderArgs = null;
7893
7894 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7895 (orderByComparator == null)) {
7896 pagination = false;
7897 finderArgs = new Object[] { pk };
7898 }
7899 else {
7900 finderArgs = new Object[] { pk, start, end, orderByComparator };
7901 }
7902
7903 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
7904 finderArgs, this);
7905
7906 if (list == null) {
7907 Session session = null;
7908
7909 try {
7910 session = openSession();
7911
7912 String sql = null;
7913
7914 if (orderByComparator != null) {
7915 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
7916 .concat(orderByComparator.getOrderBy());
7917 }
7918 else {
7919 sql = _SQL_GETGROUPS;
7920
7921 if (pagination) {
7922 sql = sql.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
7923 }
7924 }
7925
7926 SQLQuery q = session.createSQLQuery(sql);
7927
7928 q.addEntity("Group_",
7929 com.liferay.portal.model.impl.GroupImpl.class);
7930
7931 QueryPos qPos = QueryPos.getInstance(q);
7932
7933 qPos.add(pk);
7934
7935 if (!pagination) {
7936 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
7937 getDialect(), start, end, false);
7938
7939 Collections.sort(list);
7940
7941 list = new UnmodifiableList<com.liferay.portal.model.Group>(list);
7942 }
7943 else {
7944 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
7945 getDialect(), start, end);
7946 }
7947
7948 groupPersistence.cacheResult(list);
7949
7950 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
7951 list);
7952 }
7953 catch (Exception e) {
7954 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS, finderArgs);
7955
7956 throw processException(e);
7957 }
7958 finally {
7959 closeSession(session);
7960 }
7961 }
7962
7963 return list;
7964 }
7965
7966 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
7967 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Long.class,
7968 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroupsSize",
7969 new String[] { Long.class.getName() });
7970
7971 static {
7972 FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
7973 }
7974
7975
7982 @Override
7983 public int getGroupsSize(long pk) throws SystemException {
7984 Object[] finderArgs = new Object[] { pk };
7985
7986 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
7987 finderArgs, this);
7988
7989 if (count == null) {
7990 Session session = null;
7991
7992 try {
7993 session = openSession();
7994
7995 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
7996
7997 q.addScalar(COUNT_COLUMN_NAME,
7998 com.liferay.portal.kernel.dao.orm.Type.LONG);
7999
8000 QueryPos qPos = QueryPos.getInstance(q);
8001
8002 qPos.add(pk);
8003
8004 count = (Long)q.uniqueResult();
8005
8006 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
8007 finderArgs, count);
8008 }
8009 catch (Exception e) {
8010 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS_SIZE,
8011 finderArgs);
8012
8013 throw processException(e);
8014 }
8015 finally {
8016 closeSession(session);
8017 }
8018 }
8019
8020 return count.intValue();
8021 }
8022
8023 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
8024 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Boolean.class,
8025 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "containsGroup",
8026 new String[] { Long.class.getName(), Long.class.getName() });
8027
8028
8036 @Override
8037 public boolean containsGroup(long pk, long groupPK)
8038 throws SystemException {
8039 Object[] finderArgs = new Object[] { pk, groupPK };
8040
8041 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
8042 finderArgs, this);
8043
8044 if (value == null) {
8045 try {
8046 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
8047
8048 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
8049 finderArgs, value);
8050 }
8051 catch (Exception e) {
8052 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_GROUP,
8053 finderArgs);
8054
8055 throw processException(e);
8056 }
8057 }
8058
8059 return value.booleanValue();
8060 }
8061
8062
8069 @Override
8070 public boolean containsGroups(long pk) throws SystemException {
8071 if (getGroupsSize(pk) > 0) {
8072 return true;
8073 }
8074 else {
8075 return false;
8076 }
8077 }
8078
8079
8086 @Override
8087 public void addGroup(long pk, long groupPK) throws SystemException {
8088 try {
8089 addGroup.add(pk, groupPK);
8090 }
8091 catch (Exception e) {
8092 throw processException(e);
8093 }
8094 finally {
8095 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8096 }
8097 }
8098
8099
8106 @Override
8107 public void addGroup(long pk, com.liferay.portal.model.Group group)
8108 throws SystemException {
8109 try {
8110 addGroup.add(pk, group.getPrimaryKey());
8111 }
8112 catch (Exception e) {
8113 throw processException(e);
8114 }
8115 finally {
8116 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8117 }
8118 }
8119
8120
8127 @Override
8128 public void addGroups(long pk, long[] groupPKs) throws SystemException {
8129 try {
8130 for (long groupPK : groupPKs) {
8131 addGroup.add(pk, groupPK);
8132 }
8133 }
8134 catch (Exception e) {
8135 throw processException(e);
8136 }
8137 finally {
8138 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8139 }
8140 }
8141
8142
8149 @Override
8150 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
8151 throws SystemException {
8152 try {
8153 for (com.liferay.portal.model.Group group : groups) {
8154 addGroup.add(pk, group.getPrimaryKey());
8155 }
8156 }
8157 catch (Exception e) {
8158 throw processException(e);
8159 }
8160 finally {
8161 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8162 }
8163 }
8164
8165
8171 @Override
8172 public void clearGroups(long pk) throws SystemException {
8173 try {
8174 clearGroups.clear(pk);
8175 }
8176 catch (Exception e) {
8177 throw processException(e);
8178 }
8179 finally {
8180 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8181 }
8182 }
8183
8184
8191 @Override
8192 public void removeGroup(long pk, long groupPK) throws SystemException {
8193 try {
8194 removeGroup.remove(pk, groupPK);
8195 }
8196 catch (Exception e) {
8197 throw processException(e);
8198 }
8199 finally {
8200 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8201 }
8202 }
8203
8204
8211 @Override
8212 public void removeGroup(long pk, com.liferay.portal.model.Group group)
8213 throws SystemException {
8214 try {
8215 removeGroup.remove(pk, group.getPrimaryKey());
8216 }
8217 catch (Exception e) {
8218 throw processException(e);
8219 }
8220 finally {
8221 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8222 }
8223 }
8224
8225
8232 @Override
8233 public void removeGroups(long pk, long[] groupPKs)
8234 throws SystemException {
8235 try {
8236 for (long groupPK : groupPKs) {
8237 removeGroup.remove(pk, groupPK);
8238 }
8239 }
8240 catch (Exception e) {
8241 throw processException(e);
8242 }
8243 finally {
8244 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8245 }
8246 }
8247
8248
8255 @Override
8256 public void removeGroups(long pk,
8257 List<com.liferay.portal.model.Group> groups) throws SystemException {
8258 try {
8259 for (com.liferay.portal.model.Group group : groups) {
8260 removeGroup.remove(pk, group.getPrimaryKey());
8261 }
8262 }
8263 catch (Exception e) {
8264 throw processException(e);
8265 }
8266 finally {
8267 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8268 }
8269 }
8270
8271
8278 @Override
8279 public void setGroups(long pk, long[] groupPKs) throws SystemException {
8280 try {
8281 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
8282
8283 List<com.liferay.portal.model.Group> groups = getGroups(pk);
8284
8285 for (com.liferay.portal.model.Group group : groups) {
8286 if (!groupPKSet.remove(group.getPrimaryKey())) {
8287 removeGroup.remove(pk, group.getPrimaryKey());
8288 }
8289 }
8290
8291 for (Long groupPK : groupPKSet) {
8292 addGroup.add(pk, groupPK);
8293 }
8294 }
8295 catch (Exception e) {
8296 throw processException(e);
8297 }
8298 finally {
8299 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8300 }
8301 }
8302
8303
8310 @Override
8311 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
8312 throws SystemException {
8313 try {
8314 long[] groupPKs = new long[groups.size()];
8315
8316 for (int i = 0; i < groups.size(); i++) {
8317 com.liferay.portal.model.Group group = groups.get(i);
8318
8319 groupPKs[i] = group.getPrimaryKey();
8320 }
8321
8322 setGroups(pk, groupPKs);
8323 }
8324 catch (Exception e) {
8325 throw processException(e);
8326 }
8327 finally {
8328 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
8329 }
8330 }
8331
8332
8339 @Override
8340 public List<com.liferay.portal.model.User> getUsers(long pk)
8341 throws SystemException {
8342 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
8343 }
8344
8345
8358 @Override
8359 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
8360 int end) throws SystemException {
8361 return getUsers(pk, start, end, null);
8362 }
8363
8364 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
8365 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
8366 com.liferay.portal.model.impl.UserImpl.class,
8367 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsers",
8368 new String[] {
8369 Long.class.getName(), Integer.class.getName(),
8370 Integer.class.getName(), OrderByComparator.class.getName()
8371 });
8372
8373 static {
8374 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
8375 }
8376
8377
8391 @Override
8392 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
8393 int end, OrderByComparator orderByComparator) throws SystemException {
8394 boolean pagination = true;
8395 Object[] finderArgs = null;
8396
8397 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8398 (orderByComparator == null)) {
8399 pagination = false;
8400 finderArgs = new Object[] { pk };
8401 }
8402 else {
8403 finderArgs = new Object[] { pk, start, end, orderByComparator };
8404 }
8405
8406 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
8407 finderArgs, this);
8408
8409 if (list == null) {
8410 Session session = null;
8411
8412 try {
8413 session = openSession();
8414
8415 String sql = null;
8416
8417 if (orderByComparator != null) {
8418 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
8419 .concat(orderByComparator.getOrderBy());
8420 }
8421 else {
8422 sql = _SQL_GETUSERS;
8423
8424 if (pagination) {
8425 sql = sql.concat(com.liferay.portal.model.impl.UserModelImpl.ORDER_BY_SQL);
8426 }
8427 }
8428
8429 SQLQuery q = session.createSQLQuery(sql);
8430
8431 q.addEntity("User_",
8432 com.liferay.portal.model.impl.UserImpl.class);
8433
8434 QueryPos qPos = QueryPos.getInstance(q);
8435
8436 qPos.add(pk);
8437
8438 if (!pagination) {
8439 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
8440 getDialect(), start, end, false);
8441
8442 Collections.sort(list);
8443
8444 list = new UnmodifiableList<com.liferay.portal.model.User>(list);
8445 }
8446 else {
8447 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
8448 getDialect(), start, end);
8449 }
8450
8451 userPersistence.cacheResult(list);
8452
8453 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
8454 list);
8455 }
8456 catch (Exception e) {
8457 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS, finderArgs);
8458
8459 throw processException(e);
8460 }
8461 finally {
8462 closeSession(session);
8463 }
8464 }
8465
8466 return list;
8467 }
8468
8469 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
8470 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, Long.class,
8471 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsersSize",
8472 new String[] { Long.class.getName() });
8473
8474 static {
8475 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
8476 }
8477
8478
8485 @Override
8486 public int getUsersSize(long pk) throws SystemException {
8487 Object[] finderArgs = new Object[] { pk };
8488
8489 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
8490 finderArgs, this);
8491
8492 if (count == null) {
8493 Session session = null;
8494
8495 try {
8496 session = openSession();
8497
8498 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
8499
8500 q.addScalar(COUNT_COLUMN_NAME,
8501 com.liferay.portal.kernel.dao.orm.Type.LONG);
8502
8503 QueryPos qPos = QueryPos.getInstance(q);
8504
8505 qPos.add(pk);
8506
8507 count = (Long)q.uniqueResult();
8508
8509 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
8510 finderArgs, count);
8511 }
8512 catch (Exception e) {
8513 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS_SIZE,
8514 finderArgs);
8515
8516 throw processException(e);
8517 }
8518 finally {
8519 closeSession(session);
8520 }
8521 }
8522
8523 return count.intValue();
8524 }
8525
8526 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
8527 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, Boolean.class,
8528 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "containsUser",
8529 new String[] { Long.class.getName(), Long.class.getName() });
8530
8531
8539 @Override
8540 public boolean containsUser(long pk, long userPK) throws SystemException {
8541 Object[] finderArgs = new Object[] { pk, userPK };
8542
8543 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
8544 finderArgs, this);
8545
8546 if (value == null) {
8547 try {
8548 value = Boolean.valueOf(containsUser.contains(pk, userPK));
8549
8550 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
8551 finderArgs, value);
8552 }
8553 catch (Exception e) {
8554 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USER,
8555 finderArgs);
8556
8557 throw processException(e);
8558 }
8559 }
8560
8561 return value.booleanValue();
8562 }
8563
8564
8571 @Override
8572 public boolean containsUsers(long pk) throws SystemException {
8573 if (getUsersSize(pk) > 0) {
8574 return true;
8575 }
8576 else {
8577 return false;
8578 }
8579 }
8580
8581
8588 @Override
8589 public void addUser(long pk, long userPK) throws SystemException {
8590 try {
8591 addUser.add(pk, userPK);
8592 }
8593 catch (Exception e) {
8594 throw processException(e);
8595 }
8596 finally {
8597 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8598 }
8599 }
8600
8601
8608 @Override
8609 public void addUser(long pk, com.liferay.portal.model.User user)
8610 throws SystemException {
8611 try {
8612 addUser.add(pk, user.getPrimaryKey());
8613 }
8614 catch (Exception e) {
8615 throw processException(e);
8616 }
8617 finally {
8618 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8619 }
8620 }
8621
8622
8629 @Override
8630 public void addUsers(long pk, long[] userPKs) throws SystemException {
8631 try {
8632 for (long userPK : userPKs) {
8633 addUser.add(pk, userPK);
8634 }
8635 }
8636 catch (Exception e) {
8637 throw processException(e);
8638 }
8639 finally {
8640 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8641 }
8642 }
8643
8644
8651 @Override
8652 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
8653 throws SystemException {
8654 try {
8655 for (com.liferay.portal.model.User user : users) {
8656 addUser.add(pk, user.getPrimaryKey());
8657 }
8658 }
8659 catch (Exception e) {
8660 throw processException(e);
8661 }
8662 finally {
8663 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8664 }
8665 }
8666
8667
8673 @Override
8674 public void clearUsers(long pk) throws SystemException {
8675 try {
8676 clearUsers.clear(pk);
8677 }
8678 catch (Exception e) {
8679 throw processException(e);
8680 }
8681 finally {
8682 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8683 }
8684 }
8685
8686
8693 @Override
8694 public void removeUser(long pk, long userPK) throws SystemException {
8695 try {
8696 removeUser.remove(pk, userPK);
8697 }
8698 catch (Exception e) {
8699 throw processException(e);
8700 }
8701 finally {
8702 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8703 }
8704 }
8705
8706
8713 @Override
8714 public void removeUser(long pk, com.liferay.portal.model.User user)
8715 throws SystemException {
8716 try {
8717 removeUser.remove(pk, user.getPrimaryKey());
8718 }
8719 catch (Exception e) {
8720 throw processException(e);
8721 }
8722 finally {
8723 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8724 }
8725 }
8726
8727
8734 @Override
8735 public void removeUsers(long pk, long[] userPKs) throws SystemException {
8736 try {
8737 for (long userPK : userPKs) {
8738 removeUser.remove(pk, userPK);
8739 }
8740 }
8741 catch (Exception e) {
8742 throw processException(e);
8743 }
8744 finally {
8745 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8746 }
8747 }
8748
8749
8756 @Override
8757 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
8758 throws SystemException {
8759 try {
8760 for (com.liferay.portal.model.User user : users) {
8761 removeUser.remove(pk, user.getPrimaryKey());
8762 }
8763 }
8764 catch (Exception e) {
8765 throw processException(e);
8766 }
8767 finally {
8768 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8769 }
8770 }
8771
8772
8779 @Override
8780 public void setUsers(long pk, long[] userPKs) throws SystemException {
8781 try {
8782 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
8783
8784 List<com.liferay.portal.model.User> users = getUsers(pk);
8785
8786 for (com.liferay.portal.model.User user : users) {
8787 if (!userPKSet.remove(user.getPrimaryKey())) {
8788 removeUser.remove(pk, user.getPrimaryKey());
8789 }
8790 }
8791
8792 for (Long userPK : userPKSet) {
8793 addUser.add(pk, userPK);
8794 }
8795 }
8796 catch (Exception e) {
8797 throw processException(e);
8798 }
8799 finally {
8800 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8801 }
8802 }
8803
8804
8811 @Override
8812 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
8813 throws SystemException {
8814 try {
8815 long[] userPKs = new long[users.size()];
8816
8817 for (int i = 0; i < users.size(); i++) {
8818 com.liferay.portal.model.User user = users.get(i);
8819
8820 userPKs[i] = user.getPrimaryKey();
8821 }
8822
8823 setUsers(pk, userPKs);
8824 }
8825 catch (Exception e) {
8826 throw processException(e);
8827 }
8828 finally {
8829 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
8830 }
8831 }
8832
8833 @Override
8834 protected Set<String> getBadColumnNames() {
8835 return _badColumnNames;
8836 }
8837
8838
8841 public void afterPropertiesSet() {
8842 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
8843 com.liferay.portal.util.PropsUtil.get(
8844 "value.object.listener.com.liferay.portal.model.Role")));
8845
8846 if (listenerClassNames.length > 0) {
8847 try {
8848 List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
8849
8850 for (String listenerClassName : listenerClassNames) {
8851 listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
8852 getClassLoader(), listenerClassName));
8853 }
8854
8855 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8856 }
8857 catch (Exception e) {
8858 _log.error(e);
8859 }
8860 }
8861
8862 containsGroup = new ContainsGroup();
8863
8864 addGroup = new AddGroup();
8865 clearGroups = new ClearGroups();
8866 removeGroup = new RemoveGroup();
8867
8868 containsUser = new ContainsUser();
8869
8870 addUser = new AddUser();
8871 clearUsers = new ClearUsers();
8872 removeUser = new RemoveUser();
8873 }
8874
8875 public void destroy() {
8876 EntityCacheUtil.removeCache(RoleImpl.class.getName());
8877 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8878 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8879 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8880 }
8881
8882 @BeanReference(type = GroupPersistence.class)
8883 protected GroupPersistence groupPersistence;
8884 protected ContainsGroup containsGroup;
8885 protected AddGroup addGroup;
8886 protected ClearGroups clearGroups;
8887 protected RemoveGroup removeGroup;
8888 @BeanReference(type = UserPersistence.class)
8889 protected UserPersistence userPersistence;
8890 protected ContainsUser containsUser;
8891 protected AddUser addUser;
8892 protected ClearUsers clearUsers;
8893 protected RemoveUser removeUser;
8894
8895 protected class ContainsGroup {
8896 protected ContainsGroup() {
8897 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
8898 "SELECT 1 FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
8899 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
8900 RowMapper.COUNT);
8901 }
8902
8903 protected boolean contains(long roleId, long groupId) {
8904 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
8905 new Long(roleId), new Long(groupId)
8906 });
8907
8908 if (results.isEmpty()) {
8909 return false;
8910 }
8911
8912 return true;
8913 }
8914
8915 private MappingSqlQuery<Integer> _mappingSqlQuery;
8916 }
8917
8918 protected class AddGroup {
8919 protected AddGroup() {
8920 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8921 "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
8922 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
8923 }
8924
8925 protected void add(long roleId, long groupId) throws SystemException {
8926 if (!containsGroup.contains(roleId, groupId)) {
8927 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
8928
8929 for (ModelListener<Role> listener : listeners) {
8930 listener.onBeforeAddAssociation(roleId,
8931 com.liferay.portal.model.Group.class.getName(), groupId);
8932 }
8933
8934 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
8935 listener.onBeforeAddAssociation(groupId,
8936 Role.class.getName(), roleId);
8937 }
8938
8939 _sqlUpdate.update(new Object[] {
8940 new Long(roleId), new Long(groupId)
8941 });
8942
8943 for (ModelListener<Role> listener : listeners) {
8944 listener.onAfterAddAssociation(roleId,
8945 com.liferay.portal.model.Group.class.getName(), groupId);
8946 }
8947
8948 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
8949 listener.onAfterAddAssociation(groupId,
8950 Role.class.getName(), roleId);
8951 }
8952 }
8953 }
8954
8955 private SqlUpdate _sqlUpdate;
8956 }
8957
8958 protected class ClearGroups {
8959 protected ClearGroups() {
8960 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
8961 "DELETE FROM Groups_Roles WHERE roleId = ?",
8962 new int[] { java.sql.Types.BIGINT });
8963 }
8964
8965 protected void clear(long roleId) throws SystemException {
8966 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
8967
8968 List<com.liferay.portal.model.Group> groups = null;
8969
8970 if ((listeners.length > 0) || (groupListeners.length > 0)) {
8971 groups = getGroups(roleId);
8972
8973 for (com.liferay.portal.model.Group group : groups) {
8974 for (ModelListener<Role> listener : listeners) {
8975 listener.onBeforeRemoveAssociation(roleId,
8976 com.liferay.portal.model.Group.class.getName(),
8977 group.getPrimaryKey());
8978 }
8979
8980 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
8981 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
8982 Role.class.getName(), roleId);
8983 }
8984 }
8985 }
8986
8987 _sqlUpdate.update(new Object[] { new Long(roleId) });
8988
8989 if ((listeners.length > 0) || (groupListeners.length > 0)) {
8990 for (com.liferay.portal.model.Group group : groups) {
8991 for (ModelListener<Role> listener : listeners) {
8992 listener.onAfterRemoveAssociation(roleId,
8993 com.liferay.portal.model.Group.class.getName(),
8994 group.getPrimaryKey());
8995 }
8996
8997 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
8998 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
8999 Role.class.getName(), roleId);
9000 }
9001 }
9002 }
9003 }
9004
9005 private SqlUpdate _sqlUpdate;
9006 }
9007
9008 protected class RemoveGroup {
9009 protected RemoveGroup() {
9010 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9011 "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
9012 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9013 }
9014
9015 protected void remove(long roleId, long groupId)
9016 throws SystemException {
9017 if (containsGroup.contains(roleId, groupId)) {
9018 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
9019
9020 for (ModelListener<Role> listener : listeners) {
9021 listener.onBeforeRemoveAssociation(roleId,
9022 com.liferay.portal.model.Group.class.getName(), groupId);
9023 }
9024
9025 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
9026 listener.onBeforeRemoveAssociation(groupId,
9027 Role.class.getName(), roleId);
9028 }
9029
9030 _sqlUpdate.update(new Object[] {
9031 new Long(roleId), new Long(groupId)
9032 });
9033
9034 for (ModelListener<Role> listener : listeners) {
9035 listener.onAfterRemoveAssociation(roleId,
9036 com.liferay.portal.model.Group.class.getName(), groupId);
9037 }
9038
9039 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
9040 listener.onAfterRemoveAssociation(groupId,
9041 Role.class.getName(), roleId);
9042 }
9043 }
9044 }
9045
9046 private SqlUpdate _sqlUpdate;
9047 }
9048
9049 protected class ContainsUser {
9050 protected ContainsUser() {
9051 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
9052 "SELECT 1 FROM Users_Roles WHERE roleId = ? AND userId = ?",
9053 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
9054 RowMapper.COUNT);
9055 }
9056
9057 protected boolean contains(long roleId, long userId) {
9058 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
9059 new Long(roleId), new Long(userId)
9060 });
9061
9062 if (results.isEmpty()) {
9063 return false;
9064 }
9065
9066 return true;
9067 }
9068
9069 private MappingSqlQuery<Integer> _mappingSqlQuery;
9070 }
9071
9072 protected class AddUser {
9073 protected AddUser() {
9074 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9075 "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
9076 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9077 }
9078
9079 protected void add(long roleId, long userId) throws SystemException {
9080 if (!containsUser.contains(roleId, userId)) {
9081 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
9082
9083 for (ModelListener<Role> listener : listeners) {
9084 listener.onBeforeAddAssociation(roleId,
9085 com.liferay.portal.model.User.class.getName(), userId);
9086 }
9087
9088 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9089 listener.onBeforeAddAssociation(userId,
9090 Role.class.getName(), roleId);
9091 }
9092
9093 _sqlUpdate.update(new Object[] {
9094 new Long(roleId), new Long(userId)
9095 });
9096
9097 for (ModelListener<Role> listener : listeners) {
9098 listener.onAfterAddAssociation(roleId,
9099 com.liferay.portal.model.User.class.getName(), userId);
9100 }
9101
9102 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9103 listener.onAfterAddAssociation(userId,
9104 Role.class.getName(), roleId);
9105 }
9106 }
9107 }
9108
9109 private SqlUpdate _sqlUpdate;
9110 }
9111
9112 protected class ClearUsers {
9113 protected ClearUsers() {
9114 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9115 "DELETE FROM Users_Roles WHERE roleId = ?",
9116 new int[] { java.sql.Types.BIGINT });
9117 }
9118
9119 protected void clear(long roleId) throws SystemException {
9120 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
9121
9122 List<com.liferay.portal.model.User> users = null;
9123
9124 if ((listeners.length > 0) || (userListeners.length > 0)) {
9125 users = getUsers(roleId);
9126
9127 for (com.liferay.portal.model.User user : users) {
9128 for (ModelListener<Role> listener : listeners) {
9129 listener.onBeforeRemoveAssociation(roleId,
9130 com.liferay.portal.model.User.class.getName(),
9131 user.getPrimaryKey());
9132 }
9133
9134 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9135 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
9136 Role.class.getName(), roleId);
9137 }
9138 }
9139 }
9140
9141 _sqlUpdate.update(new Object[] { new Long(roleId) });
9142
9143 if ((listeners.length > 0) || (userListeners.length > 0)) {
9144 for (com.liferay.portal.model.User user : users) {
9145 for (ModelListener<Role> listener : listeners) {
9146 listener.onAfterRemoveAssociation(roleId,
9147 com.liferay.portal.model.User.class.getName(),
9148 user.getPrimaryKey());
9149 }
9150
9151 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9152 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
9153 Role.class.getName(), roleId);
9154 }
9155 }
9156 }
9157 }
9158
9159 private SqlUpdate _sqlUpdate;
9160 }
9161
9162 protected class RemoveUser {
9163 protected RemoveUser() {
9164 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
9165 "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
9166 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
9167 }
9168
9169 protected void remove(long roleId, long userId)
9170 throws SystemException {
9171 if (containsUser.contains(roleId, userId)) {
9172 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
9173
9174 for (ModelListener<Role> listener : listeners) {
9175 listener.onBeforeRemoveAssociation(roleId,
9176 com.liferay.portal.model.User.class.getName(), userId);
9177 }
9178
9179 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9180 listener.onBeforeRemoveAssociation(userId,
9181 Role.class.getName(), roleId);
9182 }
9183
9184 _sqlUpdate.update(new Object[] {
9185 new Long(roleId), new Long(userId)
9186 });
9187
9188 for (ModelListener<Role> listener : listeners) {
9189 listener.onAfterRemoveAssociation(roleId,
9190 com.liferay.portal.model.User.class.getName(), userId);
9191 }
9192
9193 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
9194 listener.onAfterRemoveAssociation(userId,
9195 Role.class.getName(), roleId);
9196 }
9197 }
9198 }
9199
9200 private SqlUpdate _sqlUpdate;
9201 }
9202
9203 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
9204 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
9205 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
9206 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
9207 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
9208 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
9209 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
9210 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
9211 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
9212 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
9213 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
9214 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
9215 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
9216 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
9217 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
9218 private static final String _FILTER_ENTITY_ALIAS = "role";
9219 private static final String _FILTER_ENTITY_TABLE = "Role_";
9220 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
9221 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
9222 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
9223 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
9224 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
9225 private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
9226 private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
9227 "uuid", "type"
9228 });
9229 private static Role _nullRole = new RoleImpl() {
9230 @Override
9231 public Object clone() {
9232 return this;
9233 }
9234
9235 @Override
9236 public CacheModel<Role> toCacheModel() {
9237 return _nullRoleCacheModel;
9238 }
9239 };
9240
9241 private static CacheModel<Role> _nullRoleCacheModel = new CacheModel<Role>() {
9242 @Override
9243 public Role toEntityModel() {
9244 return _nullRole;
9245 }
9246 };
9247 }