001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchRoleException;
019 import com.liferay.portal.kernel.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.SQLQuery;
033 import com.liferay.portal.kernel.dao.orm.Session;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.log.Log;
036 import com.liferay.portal.kernel.log.LogFactoryUtil;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.InstanceFactory;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.SetUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.StringUtil;
044 import com.liferay.portal.kernel.util.UnmodifiableList;
045 import com.liferay.portal.kernel.util.Validator;
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_COMPANYID =
095 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
096 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
097 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
098 new String[] {
099 Long.class.getName(),
100
101 Integer.class.getName(), Integer.class.getName(),
102 OrderByComparator.class.getName()
103 });
104 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
105 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
106 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
107 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
108 new String[] { Long.class.getName() },
109 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
110 RoleModelImpl.NAME_COLUMN_BITMASK);
111 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
112 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
113 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
114 new String[] { Long.class.getName() });
115
116
123 public List<Role> findByCompanyId(long companyId) throws SystemException {
124 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
125 null);
126 }
127
128
141 public List<Role> findByCompanyId(long companyId, int start, int end)
142 throws SystemException {
143 return findByCompanyId(companyId, start, end, null);
144 }
145
146
160 public List<Role> findByCompanyId(long companyId, 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_COMPANYID;
170 finderArgs = new Object[] { companyId };
171 }
172 else {
173 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
174 finderArgs = new Object[] { companyId, 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 ((companyId != role.getCompanyId())) {
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 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
204
205 if (orderByComparator != null) {
206 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
207 orderByComparator);
208 }
209 else
210 if (pagination) {
211 query.append(RoleModelImpl.ORDER_BY_JPQL);
212 }
213
214 String sql = query.toString();
215
216 Session session = null;
217
218 try {
219 session = openSession();
220
221 Query q = session.createQuery(sql);
222
223 QueryPos qPos = QueryPos.getInstance(q);
224
225 qPos.add(companyId);
226
227 if (!pagination) {
228 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
229 end, false);
230
231 Collections.sort(list);
232
233 list = new UnmodifiableList<Role>(list);
234 }
235 else {
236 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
237 end);
238 }
239
240 cacheResult(list);
241
242 FinderCacheUtil.putResult(finderPath, finderArgs, list);
243 }
244 catch (Exception e) {
245 FinderCacheUtil.removeResult(finderPath, finderArgs);
246
247 throw processException(e);
248 }
249 finally {
250 closeSession(session);
251 }
252 }
253
254 return list;
255 }
256
257
266 public Role findByCompanyId_First(long companyId,
267 OrderByComparator orderByComparator)
268 throws NoSuchRoleException, SystemException {
269 Role role = fetchByCompanyId_First(companyId, orderByComparator);
270
271 if (role != null) {
272 return role;
273 }
274
275 StringBundler msg = new StringBundler(4);
276
277 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
278
279 msg.append("companyId=");
280 msg.append(companyId);
281
282 msg.append(StringPool.CLOSE_CURLY_BRACE);
283
284 throw new NoSuchRoleException(msg.toString());
285 }
286
287
295 public Role fetchByCompanyId_First(long companyId,
296 OrderByComparator orderByComparator) throws SystemException {
297 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
298
299 if (!list.isEmpty()) {
300 return list.get(0);
301 }
302
303 return null;
304 }
305
306
315 public Role findByCompanyId_Last(long companyId,
316 OrderByComparator orderByComparator)
317 throws NoSuchRoleException, SystemException {
318 Role role = fetchByCompanyId_Last(companyId, orderByComparator);
319
320 if (role != null) {
321 return role;
322 }
323
324 StringBundler msg = new StringBundler(4);
325
326 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
327
328 msg.append("companyId=");
329 msg.append(companyId);
330
331 msg.append(StringPool.CLOSE_CURLY_BRACE);
332
333 throw new NoSuchRoleException(msg.toString());
334 }
335
336
344 public Role fetchByCompanyId_Last(long companyId,
345 OrderByComparator orderByComparator) throws SystemException {
346 int count = countByCompanyId(companyId);
347
348 List<Role> list = findByCompanyId(companyId, count - 1, count,
349 orderByComparator);
350
351 if (!list.isEmpty()) {
352 return list.get(0);
353 }
354
355 return null;
356 }
357
358
368 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
369 OrderByComparator orderByComparator)
370 throws NoSuchRoleException, SystemException {
371 Role role = findByPrimaryKey(roleId);
372
373 Session session = null;
374
375 try {
376 session = openSession();
377
378 Role[] array = new RoleImpl[3];
379
380 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
381 orderByComparator, true);
382
383 array[1] = role;
384
385 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
386 orderByComparator, false);
387
388 return array;
389 }
390 catch (Exception e) {
391 throw processException(e);
392 }
393 finally {
394 closeSession(session);
395 }
396 }
397
398 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
399 long companyId, OrderByComparator orderByComparator, boolean previous) {
400 StringBundler query = null;
401
402 if (orderByComparator != null) {
403 query = new StringBundler(6 +
404 (orderByComparator.getOrderByFields().length * 6));
405 }
406 else {
407 query = new StringBundler(3);
408 }
409
410 query.append(_SQL_SELECT_ROLE_WHERE);
411
412 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
413
414 if (orderByComparator != null) {
415 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
416
417 if (orderByConditionFields.length > 0) {
418 query.append(WHERE_AND);
419 }
420
421 for (int i = 0; i < orderByConditionFields.length; i++) {
422 query.append(_ORDER_BY_ENTITY_ALIAS);
423 query.append(orderByConditionFields[i]);
424
425 if ((i + 1) < orderByConditionFields.length) {
426 if (orderByComparator.isAscending() ^ previous) {
427 query.append(WHERE_GREATER_THAN_HAS_NEXT);
428 }
429 else {
430 query.append(WHERE_LESSER_THAN_HAS_NEXT);
431 }
432 }
433 else {
434 if (orderByComparator.isAscending() ^ previous) {
435 query.append(WHERE_GREATER_THAN);
436 }
437 else {
438 query.append(WHERE_LESSER_THAN);
439 }
440 }
441 }
442
443 query.append(ORDER_BY_CLAUSE);
444
445 String[] orderByFields = orderByComparator.getOrderByFields();
446
447 for (int i = 0; i < orderByFields.length; i++) {
448 query.append(_ORDER_BY_ENTITY_ALIAS);
449 query.append(orderByFields[i]);
450
451 if ((i + 1) < orderByFields.length) {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(ORDER_BY_ASC_HAS_NEXT);
454 }
455 else {
456 query.append(ORDER_BY_DESC_HAS_NEXT);
457 }
458 }
459 else {
460 if (orderByComparator.isAscending() ^ previous) {
461 query.append(ORDER_BY_ASC);
462 }
463 else {
464 query.append(ORDER_BY_DESC);
465 }
466 }
467 }
468 }
469 else {
470 query.append(RoleModelImpl.ORDER_BY_JPQL);
471 }
472
473 String sql = query.toString();
474
475 Query q = session.createQuery(sql);
476
477 q.setFirstResult(0);
478 q.setMaxResults(2);
479
480 QueryPos qPos = QueryPos.getInstance(q);
481
482 qPos.add(companyId);
483
484 if (orderByComparator != null) {
485 Object[] values = orderByComparator.getOrderByConditionValues(role);
486
487 for (Object value : values) {
488 qPos.add(value);
489 }
490 }
491
492 List<Role> list = q.list();
493
494 if (list.size() == 2) {
495 return list.get(1);
496 }
497 else {
498 return null;
499 }
500 }
501
502
509 public List<Role> filterFindByCompanyId(long companyId)
510 throws SystemException {
511 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
512 QueryUtil.ALL_POS, null);
513 }
514
515
528 public List<Role> filterFindByCompanyId(long companyId, int start, int end)
529 throws SystemException {
530 return filterFindByCompanyId(companyId, start, end, null);
531 }
532
533
547 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
548 OrderByComparator orderByComparator) throws SystemException {
549 if (!InlineSQLHelperUtil.isEnabled()) {
550 return findByCompanyId(companyId, start, end, orderByComparator);
551 }
552
553 StringBundler query = null;
554
555 if (orderByComparator != null) {
556 query = new StringBundler(3 +
557 (orderByComparator.getOrderByFields().length * 3));
558 }
559 else {
560 query = new StringBundler(3);
561 }
562
563 if (getDB().isSupportsInlineDistinct()) {
564 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
565 }
566 else {
567 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
568 }
569
570 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
571
572 if (!getDB().isSupportsInlineDistinct()) {
573 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
574 }
575
576 if (orderByComparator != null) {
577 if (getDB().isSupportsInlineDistinct()) {
578 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
579 orderByComparator);
580 }
581 else {
582 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
583 orderByComparator);
584 }
585 }
586 else {
587 if (getDB().isSupportsInlineDistinct()) {
588 query.append(RoleModelImpl.ORDER_BY_JPQL);
589 }
590 else {
591 query.append(RoleModelImpl.ORDER_BY_SQL);
592 }
593 }
594
595 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
596 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
597
598 Session session = null;
599
600 try {
601 session = openSession();
602
603 SQLQuery q = session.createSQLQuery(sql);
604
605 if (getDB().isSupportsInlineDistinct()) {
606 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
607 }
608 else {
609 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
610 }
611
612 QueryPos qPos = QueryPos.getInstance(q);
613
614 qPos.add(companyId);
615
616 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
617 }
618 catch (Exception e) {
619 throw processException(e);
620 }
621 finally {
622 closeSession(session);
623 }
624 }
625
626
636 public Role[] filterFindByCompanyId_PrevAndNext(long roleId,
637 long companyId, OrderByComparator orderByComparator)
638 throws NoSuchRoleException, SystemException {
639 if (!InlineSQLHelperUtil.isEnabled()) {
640 return findByCompanyId_PrevAndNext(roleId, companyId,
641 orderByComparator);
642 }
643
644 Role role = findByPrimaryKey(roleId);
645
646 Session session = null;
647
648 try {
649 session = openSession();
650
651 Role[] array = new RoleImpl[3];
652
653 array[0] = filterGetByCompanyId_PrevAndNext(session, role,
654 companyId, orderByComparator, true);
655
656 array[1] = role;
657
658 array[2] = filterGetByCompanyId_PrevAndNext(session, role,
659 companyId, orderByComparator, false);
660
661 return array;
662 }
663 catch (Exception e) {
664 throw processException(e);
665 }
666 finally {
667 closeSession(session);
668 }
669 }
670
671 protected Role filterGetByCompanyId_PrevAndNext(Session session, Role role,
672 long companyId, OrderByComparator orderByComparator, boolean previous) {
673 StringBundler query = null;
674
675 if (orderByComparator != null) {
676 query = new StringBundler(6 +
677 (orderByComparator.getOrderByFields().length * 6));
678 }
679 else {
680 query = new StringBundler(3);
681 }
682
683 if (getDB().isSupportsInlineDistinct()) {
684 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
685 }
686 else {
687 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
688 }
689
690 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
691
692 if (!getDB().isSupportsInlineDistinct()) {
693 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
694 }
695
696 if (orderByComparator != null) {
697 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
698
699 if (orderByConditionFields.length > 0) {
700 query.append(WHERE_AND);
701 }
702
703 for (int i = 0; i < orderByConditionFields.length; i++) {
704 if (getDB().isSupportsInlineDistinct()) {
705 query.append(_ORDER_BY_ENTITY_ALIAS);
706 }
707 else {
708 query.append(_ORDER_BY_ENTITY_TABLE);
709 }
710
711 query.append(orderByConditionFields[i]);
712
713 if ((i + 1) < orderByConditionFields.length) {
714 if (orderByComparator.isAscending() ^ previous) {
715 query.append(WHERE_GREATER_THAN_HAS_NEXT);
716 }
717 else {
718 query.append(WHERE_LESSER_THAN_HAS_NEXT);
719 }
720 }
721 else {
722 if (orderByComparator.isAscending() ^ previous) {
723 query.append(WHERE_GREATER_THAN);
724 }
725 else {
726 query.append(WHERE_LESSER_THAN);
727 }
728 }
729 }
730
731 query.append(ORDER_BY_CLAUSE);
732
733 String[] orderByFields = orderByComparator.getOrderByFields();
734
735 for (int i = 0; i < orderByFields.length; i++) {
736 if (getDB().isSupportsInlineDistinct()) {
737 query.append(_ORDER_BY_ENTITY_ALIAS);
738 }
739 else {
740 query.append(_ORDER_BY_ENTITY_TABLE);
741 }
742
743 query.append(orderByFields[i]);
744
745 if ((i + 1) < orderByFields.length) {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(ORDER_BY_ASC_HAS_NEXT);
748 }
749 else {
750 query.append(ORDER_BY_DESC_HAS_NEXT);
751 }
752 }
753 else {
754 if (orderByComparator.isAscending() ^ previous) {
755 query.append(ORDER_BY_ASC);
756 }
757 else {
758 query.append(ORDER_BY_DESC);
759 }
760 }
761 }
762 }
763 else {
764 if (getDB().isSupportsInlineDistinct()) {
765 query.append(RoleModelImpl.ORDER_BY_JPQL);
766 }
767 else {
768 query.append(RoleModelImpl.ORDER_BY_SQL);
769 }
770 }
771
772 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
773 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
774
775 SQLQuery q = session.createSQLQuery(sql);
776
777 q.setFirstResult(0);
778 q.setMaxResults(2);
779
780 if (getDB().isSupportsInlineDistinct()) {
781 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
782 }
783 else {
784 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
785 }
786
787 QueryPos qPos = QueryPos.getInstance(q);
788
789 qPos.add(companyId);
790
791 if (orderByComparator != null) {
792 Object[] values = orderByComparator.getOrderByConditionValues(role);
793
794 for (Object value : values) {
795 qPos.add(value);
796 }
797 }
798
799 List<Role> list = q.list();
800
801 if (list.size() == 2) {
802 return list.get(1);
803 }
804 else {
805 return null;
806 }
807 }
808
809
815 public void removeByCompanyId(long companyId) throws SystemException {
816 for (Role role : findByCompanyId(companyId, QueryUtil.ALL_POS,
817 QueryUtil.ALL_POS, null)) {
818 remove(role);
819 }
820 }
821
822
829 public int countByCompanyId(long companyId) throws SystemException {
830 FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
831
832 Object[] finderArgs = new Object[] { companyId };
833
834 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
835 this);
836
837 if (count == null) {
838 StringBundler query = new StringBundler(2);
839
840 query.append(_SQL_COUNT_ROLE_WHERE);
841
842 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
843
844 String sql = query.toString();
845
846 Session session = null;
847
848 try {
849 session = openSession();
850
851 Query q = session.createQuery(sql);
852
853 QueryPos qPos = QueryPos.getInstance(q);
854
855 qPos.add(companyId);
856
857 count = (Long)q.uniqueResult();
858
859 FinderCacheUtil.putResult(finderPath, finderArgs, count);
860 }
861 catch (Exception e) {
862 FinderCacheUtil.removeResult(finderPath, finderArgs);
863
864 throw processException(e);
865 }
866 finally {
867 closeSession(session);
868 }
869 }
870
871 return count.intValue();
872 }
873
874
881 public int filterCountByCompanyId(long companyId) throws SystemException {
882 if (!InlineSQLHelperUtil.isEnabled()) {
883 return countByCompanyId(companyId);
884 }
885
886 StringBundler query = new StringBundler(2);
887
888 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
889
890 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
891
892 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
893 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
894
895 Session session = null;
896
897 try {
898 session = openSession();
899
900 SQLQuery q = session.createSQLQuery(sql);
901
902 q.addScalar(COUNT_COLUMN_NAME,
903 com.liferay.portal.kernel.dao.orm.Type.LONG);
904
905 QueryPos qPos = QueryPos.getInstance(q);
906
907 qPos.add(companyId);
908
909 Long count = (Long)q.uniqueResult();
910
911 return count.intValue();
912 }
913 catch (Exception e) {
914 throw processException(e);
915 }
916 finally {
917 closeSession(session);
918 }
919 }
920
921 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
922 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
923 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
924 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByName",
925 new String[] {
926 String.class.getName(),
927
928 Integer.class.getName(), Integer.class.getName(),
929 OrderByComparator.class.getName()
930 });
931 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
932 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
933 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByName",
934 new String[] { String.class.getName() },
935 RoleModelImpl.NAME_COLUMN_BITMASK);
936 public static final FinderPath FINDER_PATH_COUNT_BY_NAME = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
937 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
938 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByName",
939 new String[] { String.class.getName() });
940
941
948 public List<Role> findByName(String name) throws SystemException {
949 return findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
950 }
951
952
965 public List<Role> findByName(String name, int start, int end)
966 throws SystemException {
967 return findByName(name, start, end, null);
968 }
969
970
984 public List<Role> findByName(String name, int start, int end,
985 OrderByComparator orderByComparator) throws SystemException {
986 boolean pagination = true;
987 FinderPath finderPath = null;
988 Object[] finderArgs = null;
989
990 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
991 (orderByComparator == null)) {
992 pagination = false;
993 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME;
994 finderArgs = new Object[] { name };
995 }
996 else {
997 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NAME;
998 finderArgs = new Object[] { name, start, end, orderByComparator };
999 }
1000
1001 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1002 finderArgs, this);
1003
1004 if ((list != null) && !list.isEmpty()) {
1005 for (Role role : list) {
1006 if (!Validator.equals(name, role.getName())) {
1007 list = null;
1008
1009 break;
1010 }
1011 }
1012 }
1013
1014 if (list == null) {
1015 StringBundler query = null;
1016
1017 if (orderByComparator != null) {
1018 query = new StringBundler(3 +
1019 (orderByComparator.getOrderByFields().length * 3));
1020 }
1021 else {
1022 query = new StringBundler(3);
1023 }
1024
1025 query.append(_SQL_SELECT_ROLE_WHERE);
1026
1027 if (name == null) {
1028 query.append(_FINDER_COLUMN_NAME_NAME_1);
1029 }
1030 else {
1031 if (name.equals(StringPool.BLANK)) {
1032 query.append(_FINDER_COLUMN_NAME_NAME_3);
1033 }
1034 else {
1035 query.append(_FINDER_COLUMN_NAME_NAME_2);
1036 }
1037 }
1038
1039 if (orderByComparator != null) {
1040 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1041 orderByComparator);
1042 }
1043 else
1044 if (pagination) {
1045 query.append(RoleModelImpl.ORDER_BY_JPQL);
1046 }
1047
1048 String sql = query.toString();
1049
1050 Session session = null;
1051
1052 try {
1053 session = openSession();
1054
1055 Query q = session.createQuery(sql);
1056
1057 QueryPos qPos = QueryPos.getInstance(q);
1058
1059 if (name != null) {
1060 qPos.add(name);
1061 }
1062
1063 if (!pagination) {
1064 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1065 end, false);
1066
1067 Collections.sort(list);
1068
1069 list = new UnmodifiableList<Role>(list);
1070 }
1071 else {
1072 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1073 end);
1074 }
1075
1076 cacheResult(list);
1077
1078 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1079 }
1080 catch (Exception e) {
1081 FinderCacheUtil.removeResult(finderPath, finderArgs);
1082
1083 throw processException(e);
1084 }
1085 finally {
1086 closeSession(session);
1087 }
1088 }
1089
1090 return list;
1091 }
1092
1093
1102 public Role findByName_First(String name,
1103 OrderByComparator orderByComparator)
1104 throws NoSuchRoleException, SystemException {
1105 Role role = fetchByName_First(name, orderByComparator);
1106
1107 if (role != null) {
1108 return role;
1109 }
1110
1111 StringBundler msg = new StringBundler(4);
1112
1113 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1114
1115 msg.append("name=");
1116 msg.append(name);
1117
1118 msg.append(StringPool.CLOSE_CURLY_BRACE);
1119
1120 throw new NoSuchRoleException(msg.toString());
1121 }
1122
1123
1131 public Role fetchByName_First(String name,
1132 OrderByComparator orderByComparator) throws SystemException {
1133 List<Role> list = findByName(name, 0, 1, orderByComparator);
1134
1135 if (!list.isEmpty()) {
1136 return list.get(0);
1137 }
1138
1139 return null;
1140 }
1141
1142
1151 public Role findByName_Last(String name, OrderByComparator orderByComparator)
1152 throws NoSuchRoleException, SystemException {
1153 Role role = fetchByName_Last(name, orderByComparator);
1154
1155 if (role != null) {
1156 return role;
1157 }
1158
1159 StringBundler msg = new StringBundler(4);
1160
1161 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1162
1163 msg.append("name=");
1164 msg.append(name);
1165
1166 msg.append(StringPool.CLOSE_CURLY_BRACE);
1167
1168 throw new NoSuchRoleException(msg.toString());
1169 }
1170
1171
1179 public Role fetchByName_Last(String name,
1180 OrderByComparator orderByComparator) throws SystemException {
1181 int count = countByName(name);
1182
1183 List<Role> list = findByName(name, count - 1, count, orderByComparator);
1184
1185 if (!list.isEmpty()) {
1186 return list.get(0);
1187 }
1188
1189 return null;
1190 }
1191
1192
1202 public Role[] findByName_PrevAndNext(long roleId, String name,
1203 OrderByComparator orderByComparator)
1204 throws NoSuchRoleException, SystemException {
1205 Role role = findByPrimaryKey(roleId);
1206
1207 Session session = null;
1208
1209 try {
1210 session = openSession();
1211
1212 Role[] array = new RoleImpl[3];
1213
1214 array[0] = getByName_PrevAndNext(session, role, name,
1215 orderByComparator, true);
1216
1217 array[1] = role;
1218
1219 array[2] = getByName_PrevAndNext(session, role, name,
1220 orderByComparator, false);
1221
1222 return array;
1223 }
1224 catch (Exception e) {
1225 throw processException(e);
1226 }
1227 finally {
1228 closeSession(session);
1229 }
1230 }
1231
1232 protected Role getByName_PrevAndNext(Session session, Role role,
1233 String name, OrderByComparator orderByComparator, boolean previous) {
1234 StringBundler query = null;
1235
1236 if (orderByComparator != null) {
1237 query = new StringBundler(6 +
1238 (orderByComparator.getOrderByFields().length * 6));
1239 }
1240 else {
1241 query = new StringBundler(3);
1242 }
1243
1244 query.append(_SQL_SELECT_ROLE_WHERE);
1245
1246 if (name == null) {
1247 query.append(_FINDER_COLUMN_NAME_NAME_1);
1248 }
1249 else {
1250 if (name.equals(StringPool.BLANK)) {
1251 query.append(_FINDER_COLUMN_NAME_NAME_3);
1252 }
1253 else {
1254 query.append(_FINDER_COLUMN_NAME_NAME_2);
1255 }
1256 }
1257
1258 if (orderByComparator != null) {
1259 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1260
1261 if (orderByConditionFields.length > 0) {
1262 query.append(WHERE_AND);
1263 }
1264
1265 for (int i = 0; i < orderByConditionFields.length; i++) {
1266 query.append(_ORDER_BY_ENTITY_ALIAS);
1267 query.append(orderByConditionFields[i]);
1268
1269 if ((i + 1) < orderByConditionFields.length) {
1270 if (orderByComparator.isAscending() ^ previous) {
1271 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1272 }
1273 else {
1274 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1275 }
1276 }
1277 else {
1278 if (orderByComparator.isAscending() ^ previous) {
1279 query.append(WHERE_GREATER_THAN);
1280 }
1281 else {
1282 query.append(WHERE_LESSER_THAN);
1283 }
1284 }
1285 }
1286
1287 query.append(ORDER_BY_CLAUSE);
1288
1289 String[] orderByFields = orderByComparator.getOrderByFields();
1290
1291 for (int i = 0; i < orderByFields.length; i++) {
1292 query.append(_ORDER_BY_ENTITY_ALIAS);
1293 query.append(orderByFields[i]);
1294
1295 if ((i + 1) < orderByFields.length) {
1296 if (orderByComparator.isAscending() ^ previous) {
1297 query.append(ORDER_BY_ASC_HAS_NEXT);
1298 }
1299 else {
1300 query.append(ORDER_BY_DESC_HAS_NEXT);
1301 }
1302 }
1303 else {
1304 if (orderByComparator.isAscending() ^ previous) {
1305 query.append(ORDER_BY_ASC);
1306 }
1307 else {
1308 query.append(ORDER_BY_DESC);
1309 }
1310 }
1311 }
1312 }
1313 else {
1314 query.append(RoleModelImpl.ORDER_BY_JPQL);
1315 }
1316
1317 String sql = query.toString();
1318
1319 Query q = session.createQuery(sql);
1320
1321 q.setFirstResult(0);
1322 q.setMaxResults(2);
1323
1324 QueryPos qPos = QueryPos.getInstance(q);
1325
1326 if (name != null) {
1327 qPos.add(name);
1328 }
1329
1330 if (orderByComparator != null) {
1331 Object[] values = orderByComparator.getOrderByConditionValues(role);
1332
1333 for (Object value : values) {
1334 qPos.add(value);
1335 }
1336 }
1337
1338 List<Role> list = q.list();
1339
1340 if (list.size() == 2) {
1341 return list.get(1);
1342 }
1343 else {
1344 return null;
1345 }
1346 }
1347
1348
1355 public List<Role> filterFindByName(String name) throws SystemException {
1356 return filterFindByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1357 }
1358
1359
1372 public List<Role> filterFindByName(String name, int start, int end)
1373 throws SystemException {
1374 return filterFindByName(name, start, end, null);
1375 }
1376
1377
1391 public List<Role> filterFindByName(String name, int start, int end,
1392 OrderByComparator orderByComparator) throws SystemException {
1393 if (!InlineSQLHelperUtil.isEnabled()) {
1394 return findByName(name, start, end, orderByComparator);
1395 }
1396
1397 StringBundler query = null;
1398
1399 if (orderByComparator != null) {
1400 query = new StringBundler(3 +
1401 (orderByComparator.getOrderByFields().length * 3));
1402 }
1403 else {
1404 query = new StringBundler(3);
1405 }
1406
1407 if (getDB().isSupportsInlineDistinct()) {
1408 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1409 }
1410 else {
1411 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1412 }
1413
1414 if (name == null) {
1415 query.append(_FINDER_COLUMN_NAME_NAME_1);
1416 }
1417 else {
1418 if (name.equals(StringPool.BLANK)) {
1419 query.append(_FINDER_COLUMN_NAME_NAME_3);
1420 }
1421 else {
1422 query.append(_FINDER_COLUMN_NAME_NAME_2);
1423 }
1424 }
1425
1426 if (!getDB().isSupportsInlineDistinct()) {
1427 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1428 }
1429
1430 if (orderByComparator != null) {
1431 if (getDB().isSupportsInlineDistinct()) {
1432 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1433 orderByComparator);
1434 }
1435 else {
1436 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1437 orderByComparator);
1438 }
1439 }
1440 else {
1441 if (getDB().isSupportsInlineDistinct()) {
1442 query.append(RoleModelImpl.ORDER_BY_JPQL);
1443 }
1444 else {
1445 query.append(RoleModelImpl.ORDER_BY_SQL);
1446 }
1447 }
1448
1449 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1450 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1451
1452 Session session = null;
1453
1454 try {
1455 session = openSession();
1456
1457 SQLQuery q = session.createSQLQuery(sql);
1458
1459 if (getDB().isSupportsInlineDistinct()) {
1460 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1461 }
1462 else {
1463 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1464 }
1465
1466 QueryPos qPos = QueryPos.getInstance(q);
1467
1468 if (name != null) {
1469 qPos.add(name);
1470 }
1471
1472 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1473 }
1474 catch (Exception e) {
1475 throw processException(e);
1476 }
1477 finally {
1478 closeSession(session);
1479 }
1480 }
1481
1482
1492 public Role[] filterFindByName_PrevAndNext(long roleId, String name,
1493 OrderByComparator orderByComparator)
1494 throws NoSuchRoleException, SystemException {
1495 if (!InlineSQLHelperUtil.isEnabled()) {
1496 return findByName_PrevAndNext(roleId, name, orderByComparator);
1497 }
1498
1499 Role role = findByPrimaryKey(roleId);
1500
1501 Session session = null;
1502
1503 try {
1504 session = openSession();
1505
1506 Role[] array = new RoleImpl[3];
1507
1508 array[0] = filterGetByName_PrevAndNext(session, role, name,
1509 orderByComparator, true);
1510
1511 array[1] = role;
1512
1513 array[2] = filterGetByName_PrevAndNext(session, role, name,
1514 orderByComparator, false);
1515
1516 return array;
1517 }
1518 catch (Exception e) {
1519 throw processException(e);
1520 }
1521 finally {
1522 closeSession(session);
1523 }
1524 }
1525
1526 protected Role filterGetByName_PrevAndNext(Session session, Role role,
1527 String name, OrderByComparator orderByComparator, boolean previous) {
1528 StringBundler query = null;
1529
1530 if (orderByComparator != null) {
1531 query = new StringBundler(6 +
1532 (orderByComparator.getOrderByFields().length * 6));
1533 }
1534 else {
1535 query = new StringBundler(3);
1536 }
1537
1538 if (getDB().isSupportsInlineDistinct()) {
1539 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1540 }
1541 else {
1542 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1543 }
1544
1545 if (name == null) {
1546 query.append(_FINDER_COLUMN_NAME_NAME_1);
1547 }
1548 else {
1549 if (name.equals(StringPool.BLANK)) {
1550 query.append(_FINDER_COLUMN_NAME_NAME_3);
1551 }
1552 else {
1553 query.append(_FINDER_COLUMN_NAME_NAME_2);
1554 }
1555 }
1556
1557 if (!getDB().isSupportsInlineDistinct()) {
1558 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1559 }
1560
1561 if (orderByComparator != null) {
1562 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1563
1564 if (orderByConditionFields.length > 0) {
1565 query.append(WHERE_AND);
1566 }
1567
1568 for (int i = 0; i < orderByConditionFields.length; i++) {
1569 if (getDB().isSupportsInlineDistinct()) {
1570 query.append(_ORDER_BY_ENTITY_ALIAS);
1571 }
1572 else {
1573 query.append(_ORDER_BY_ENTITY_TABLE);
1574 }
1575
1576 query.append(orderByConditionFields[i]);
1577
1578 if ((i + 1) < orderByConditionFields.length) {
1579 if (orderByComparator.isAscending() ^ previous) {
1580 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1581 }
1582 else {
1583 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1584 }
1585 }
1586 else {
1587 if (orderByComparator.isAscending() ^ previous) {
1588 query.append(WHERE_GREATER_THAN);
1589 }
1590 else {
1591 query.append(WHERE_LESSER_THAN);
1592 }
1593 }
1594 }
1595
1596 query.append(ORDER_BY_CLAUSE);
1597
1598 String[] orderByFields = orderByComparator.getOrderByFields();
1599
1600 for (int i = 0; i < orderByFields.length; i++) {
1601 if (getDB().isSupportsInlineDistinct()) {
1602 query.append(_ORDER_BY_ENTITY_ALIAS);
1603 }
1604 else {
1605 query.append(_ORDER_BY_ENTITY_TABLE);
1606 }
1607
1608 query.append(orderByFields[i]);
1609
1610 if ((i + 1) < orderByFields.length) {
1611 if (orderByComparator.isAscending() ^ previous) {
1612 query.append(ORDER_BY_ASC_HAS_NEXT);
1613 }
1614 else {
1615 query.append(ORDER_BY_DESC_HAS_NEXT);
1616 }
1617 }
1618 else {
1619 if (orderByComparator.isAscending() ^ previous) {
1620 query.append(ORDER_BY_ASC);
1621 }
1622 else {
1623 query.append(ORDER_BY_DESC);
1624 }
1625 }
1626 }
1627 }
1628 else {
1629 if (getDB().isSupportsInlineDistinct()) {
1630 query.append(RoleModelImpl.ORDER_BY_JPQL);
1631 }
1632 else {
1633 query.append(RoleModelImpl.ORDER_BY_SQL);
1634 }
1635 }
1636
1637 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1638 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1639
1640 SQLQuery q = session.createSQLQuery(sql);
1641
1642 q.setFirstResult(0);
1643 q.setMaxResults(2);
1644
1645 if (getDB().isSupportsInlineDistinct()) {
1646 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1647 }
1648 else {
1649 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1650 }
1651
1652 QueryPos qPos = QueryPos.getInstance(q);
1653
1654 if (name != null) {
1655 qPos.add(name);
1656 }
1657
1658 if (orderByComparator != null) {
1659 Object[] values = orderByComparator.getOrderByConditionValues(role);
1660
1661 for (Object value : values) {
1662 qPos.add(value);
1663 }
1664 }
1665
1666 List<Role> list = q.list();
1667
1668 if (list.size() == 2) {
1669 return list.get(1);
1670 }
1671 else {
1672 return null;
1673 }
1674 }
1675
1676
1682 public void removeByName(String name) throws SystemException {
1683 for (Role role : findByName(name, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1684 null)) {
1685 remove(role);
1686 }
1687 }
1688
1689
1696 public int countByName(String name) throws SystemException {
1697 FinderPath finderPath = FINDER_PATH_COUNT_BY_NAME;
1698
1699 Object[] finderArgs = new Object[] { name };
1700
1701 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1702 this);
1703
1704 if (count == null) {
1705 StringBundler query = new StringBundler(2);
1706
1707 query.append(_SQL_COUNT_ROLE_WHERE);
1708
1709 if (name == null) {
1710 query.append(_FINDER_COLUMN_NAME_NAME_1);
1711 }
1712 else {
1713 if (name.equals(StringPool.BLANK)) {
1714 query.append(_FINDER_COLUMN_NAME_NAME_3);
1715 }
1716 else {
1717 query.append(_FINDER_COLUMN_NAME_NAME_2);
1718 }
1719 }
1720
1721 String sql = query.toString();
1722
1723 Session session = null;
1724
1725 try {
1726 session = openSession();
1727
1728 Query q = session.createQuery(sql);
1729
1730 QueryPos qPos = QueryPos.getInstance(q);
1731
1732 if (name != null) {
1733 qPos.add(name);
1734 }
1735
1736 count = (Long)q.uniqueResult();
1737
1738 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1739 }
1740 catch (Exception e) {
1741 FinderCacheUtil.removeResult(finderPath, finderArgs);
1742
1743 throw processException(e);
1744 }
1745 finally {
1746 closeSession(session);
1747 }
1748 }
1749
1750 return count.intValue();
1751 }
1752
1753
1760 public int filterCountByName(String name) throws SystemException {
1761 if (!InlineSQLHelperUtil.isEnabled()) {
1762 return countByName(name);
1763 }
1764
1765 StringBundler query = new StringBundler(2);
1766
1767 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
1768
1769 if (name == null) {
1770 query.append(_FINDER_COLUMN_NAME_NAME_1);
1771 }
1772 else {
1773 if (name.equals(StringPool.BLANK)) {
1774 query.append(_FINDER_COLUMN_NAME_NAME_3);
1775 }
1776 else {
1777 query.append(_FINDER_COLUMN_NAME_NAME_2);
1778 }
1779 }
1780
1781 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1782 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1783
1784 Session session = null;
1785
1786 try {
1787 session = openSession();
1788
1789 SQLQuery q = session.createSQLQuery(sql);
1790
1791 q.addScalar(COUNT_COLUMN_NAME,
1792 com.liferay.portal.kernel.dao.orm.Type.LONG);
1793
1794 QueryPos qPos = QueryPos.getInstance(q);
1795
1796 if (name != null) {
1797 qPos.add(name);
1798 }
1799
1800 Long count = (Long)q.uniqueResult();
1801
1802 return count.intValue();
1803 }
1804 catch (Exception e) {
1805 throw processException(e);
1806 }
1807 finally {
1808 closeSession(session);
1809 }
1810 }
1811
1812 private static final String _FINDER_COLUMN_NAME_NAME_1 = "role.name IS NULL";
1813 private static final String _FINDER_COLUMN_NAME_NAME_2 = "role.name = ?";
1814 private static final String _FINDER_COLUMN_NAME_NAME_3 = "(role.name IS NULL OR role.name = ?)";
1815 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1816 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1817 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findBySubtype",
1818 new String[] {
1819 String.class.getName(),
1820
1821 Integer.class.getName(), Integer.class.getName(),
1822 OrderByComparator.class.getName()
1823 });
1824 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE =
1825 new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1826 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
1827 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findBySubtype",
1828 new String[] { String.class.getName() },
1829 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
1830 RoleModelImpl.NAME_COLUMN_BITMASK);
1831 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
1832 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
1833 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countBySubtype",
1834 new String[] { String.class.getName() });
1835
1836
1843 public List<Role> findBySubtype(String subtype) throws SystemException {
1844 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1845 }
1846
1847
1860 public List<Role> findBySubtype(String subtype, int start, int end)
1861 throws SystemException {
1862 return findBySubtype(subtype, start, end, null);
1863 }
1864
1865
1879 public List<Role> findBySubtype(String subtype, int start, int end,
1880 OrderByComparator orderByComparator) throws SystemException {
1881 boolean pagination = true;
1882 FinderPath finderPath = null;
1883 Object[] finderArgs = null;
1884
1885 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1886 (orderByComparator == null)) {
1887 pagination = false;
1888 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE;
1889 finderArgs = new Object[] { subtype };
1890 }
1891 else {
1892 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_SUBTYPE;
1893 finderArgs = new Object[] { subtype, start, end, orderByComparator };
1894 }
1895
1896 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
1897 finderArgs, this);
1898
1899 if ((list != null) && !list.isEmpty()) {
1900 for (Role role : list) {
1901 if (!Validator.equals(subtype, role.getSubtype())) {
1902 list = null;
1903
1904 break;
1905 }
1906 }
1907 }
1908
1909 if (list == null) {
1910 StringBundler query = null;
1911
1912 if (orderByComparator != null) {
1913 query = new StringBundler(3 +
1914 (orderByComparator.getOrderByFields().length * 3));
1915 }
1916 else {
1917 query = new StringBundler(3);
1918 }
1919
1920 query.append(_SQL_SELECT_ROLE_WHERE);
1921
1922 if (subtype == null) {
1923 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
1924 }
1925 else {
1926 if (subtype.equals(StringPool.BLANK)) {
1927 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
1928 }
1929 else {
1930 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
1931 }
1932 }
1933
1934 if (orderByComparator != null) {
1935 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1936 orderByComparator);
1937 }
1938 else
1939 if (pagination) {
1940 query.append(RoleModelImpl.ORDER_BY_JPQL);
1941 }
1942
1943 String sql = query.toString();
1944
1945 Session session = null;
1946
1947 try {
1948 session = openSession();
1949
1950 Query q = session.createQuery(sql);
1951
1952 QueryPos qPos = QueryPos.getInstance(q);
1953
1954 if (subtype != null) {
1955 qPos.add(subtype);
1956 }
1957
1958 if (!pagination) {
1959 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1960 end, false);
1961
1962 Collections.sort(list);
1963
1964 list = new UnmodifiableList<Role>(list);
1965 }
1966 else {
1967 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
1968 end);
1969 }
1970
1971 cacheResult(list);
1972
1973 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1974 }
1975 catch (Exception e) {
1976 FinderCacheUtil.removeResult(finderPath, finderArgs);
1977
1978 throw processException(e);
1979 }
1980 finally {
1981 closeSession(session);
1982 }
1983 }
1984
1985 return list;
1986 }
1987
1988
1997 public Role findBySubtype_First(String subtype,
1998 OrderByComparator orderByComparator)
1999 throws NoSuchRoleException, SystemException {
2000 Role role = fetchBySubtype_First(subtype, orderByComparator);
2001
2002 if (role != null) {
2003 return role;
2004 }
2005
2006 StringBundler msg = new StringBundler(4);
2007
2008 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2009
2010 msg.append("subtype=");
2011 msg.append(subtype);
2012
2013 msg.append(StringPool.CLOSE_CURLY_BRACE);
2014
2015 throw new NoSuchRoleException(msg.toString());
2016 }
2017
2018
2026 public Role fetchBySubtype_First(String subtype,
2027 OrderByComparator orderByComparator) throws SystemException {
2028 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
2029
2030 if (!list.isEmpty()) {
2031 return list.get(0);
2032 }
2033
2034 return null;
2035 }
2036
2037
2046 public Role findBySubtype_Last(String subtype,
2047 OrderByComparator orderByComparator)
2048 throws NoSuchRoleException, SystemException {
2049 Role role = fetchBySubtype_Last(subtype, orderByComparator);
2050
2051 if (role != null) {
2052 return role;
2053 }
2054
2055 StringBundler msg = new StringBundler(4);
2056
2057 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2058
2059 msg.append("subtype=");
2060 msg.append(subtype);
2061
2062 msg.append(StringPool.CLOSE_CURLY_BRACE);
2063
2064 throw new NoSuchRoleException(msg.toString());
2065 }
2066
2067
2075 public Role fetchBySubtype_Last(String subtype,
2076 OrderByComparator orderByComparator) throws SystemException {
2077 int count = countBySubtype(subtype);
2078
2079 List<Role> list = findBySubtype(subtype, count - 1, count,
2080 orderByComparator);
2081
2082 if (!list.isEmpty()) {
2083 return list.get(0);
2084 }
2085
2086 return null;
2087 }
2088
2089
2099 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
2100 OrderByComparator orderByComparator)
2101 throws NoSuchRoleException, SystemException {
2102 Role role = findByPrimaryKey(roleId);
2103
2104 Session session = null;
2105
2106 try {
2107 session = openSession();
2108
2109 Role[] array = new RoleImpl[3];
2110
2111 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
2112 orderByComparator, true);
2113
2114 array[1] = role;
2115
2116 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
2117 orderByComparator, false);
2118
2119 return array;
2120 }
2121 catch (Exception e) {
2122 throw processException(e);
2123 }
2124 finally {
2125 closeSession(session);
2126 }
2127 }
2128
2129 protected Role getBySubtype_PrevAndNext(Session session, Role role,
2130 String subtype, OrderByComparator orderByComparator, boolean previous) {
2131 StringBundler query = null;
2132
2133 if (orderByComparator != null) {
2134 query = new StringBundler(6 +
2135 (orderByComparator.getOrderByFields().length * 6));
2136 }
2137 else {
2138 query = new StringBundler(3);
2139 }
2140
2141 query.append(_SQL_SELECT_ROLE_WHERE);
2142
2143 if (subtype == null) {
2144 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2145 }
2146 else {
2147 if (subtype.equals(StringPool.BLANK)) {
2148 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2149 }
2150 else {
2151 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2152 }
2153 }
2154
2155 if (orderByComparator != null) {
2156 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2157
2158 if (orderByConditionFields.length > 0) {
2159 query.append(WHERE_AND);
2160 }
2161
2162 for (int i = 0; i < orderByConditionFields.length; i++) {
2163 query.append(_ORDER_BY_ENTITY_ALIAS);
2164 query.append(orderByConditionFields[i]);
2165
2166 if ((i + 1) < orderByConditionFields.length) {
2167 if (orderByComparator.isAscending() ^ previous) {
2168 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2169 }
2170 else {
2171 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2172 }
2173 }
2174 else {
2175 if (orderByComparator.isAscending() ^ previous) {
2176 query.append(WHERE_GREATER_THAN);
2177 }
2178 else {
2179 query.append(WHERE_LESSER_THAN);
2180 }
2181 }
2182 }
2183
2184 query.append(ORDER_BY_CLAUSE);
2185
2186 String[] orderByFields = orderByComparator.getOrderByFields();
2187
2188 for (int i = 0; i < orderByFields.length; i++) {
2189 query.append(_ORDER_BY_ENTITY_ALIAS);
2190 query.append(orderByFields[i]);
2191
2192 if ((i + 1) < orderByFields.length) {
2193 if (orderByComparator.isAscending() ^ previous) {
2194 query.append(ORDER_BY_ASC_HAS_NEXT);
2195 }
2196 else {
2197 query.append(ORDER_BY_DESC_HAS_NEXT);
2198 }
2199 }
2200 else {
2201 if (orderByComparator.isAscending() ^ previous) {
2202 query.append(ORDER_BY_ASC);
2203 }
2204 else {
2205 query.append(ORDER_BY_DESC);
2206 }
2207 }
2208 }
2209 }
2210 else {
2211 query.append(RoleModelImpl.ORDER_BY_JPQL);
2212 }
2213
2214 String sql = query.toString();
2215
2216 Query q = session.createQuery(sql);
2217
2218 q.setFirstResult(0);
2219 q.setMaxResults(2);
2220
2221 QueryPos qPos = QueryPos.getInstance(q);
2222
2223 if (subtype != null) {
2224 qPos.add(subtype);
2225 }
2226
2227 if (orderByComparator != null) {
2228 Object[] values = orderByComparator.getOrderByConditionValues(role);
2229
2230 for (Object value : values) {
2231 qPos.add(value);
2232 }
2233 }
2234
2235 List<Role> list = q.list();
2236
2237 if (list.size() == 2) {
2238 return list.get(1);
2239 }
2240 else {
2241 return null;
2242 }
2243 }
2244
2245
2252 public List<Role> filterFindBySubtype(String subtype)
2253 throws SystemException {
2254 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
2255 QueryUtil.ALL_POS, null);
2256 }
2257
2258
2271 public List<Role> filterFindBySubtype(String subtype, int start, int end)
2272 throws SystemException {
2273 return filterFindBySubtype(subtype, start, end, null);
2274 }
2275
2276
2290 public List<Role> filterFindBySubtype(String subtype, int start, int end,
2291 OrderByComparator orderByComparator) throws SystemException {
2292 if (!InlineSQLHelperUtil.isEnabled()) {
2293 return findBySubtype(subtype, start, end, orderByComparator);
2294 }
2295
2296 StringBundler query = null;
2297
2298 if (orderByComparator != null) {
2299 query = new StringBundler(3 +
2300 (orderByComparator.getOrderByFields().length * 3));
2301 }
2302 else {
2303 query = new StringBundler(3);
2304 }
2305
2306 if (getDB().isSupportsInlineDistinct()) {
2307 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2308 }
2309 else {
2310 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2311 }
2312
2313 if (subtype == null) {
2314 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2315 }
2316 else {
2317 if (subtype.equals(StringPool.BLANK)) {
2318 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2319 }
2320 else {
2321 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2322 }
2323 }
2324
2325 if (!getDB().isSupportsInlineDistinct()) {
2326 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2327 }
2328
2329 if (orderByComparator != null) {
2330 if (getDB().isSupportsInlineDistinct()) {
2331 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2332 orderByComparator);
2333 }
2334 else {
2335 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2336 orderByComparator);
2337 }
2338 }
2339 else {
2340 if (getDB().isSupportsInlineDistinct()) {
2341 query.append(RoleModelImpl.ORDER_BY_JPQL);
2342 }
2343 else {
2344 query.append(RoleModelImpl.ORDER_BY_SQL);
2345 }
2346 }
2347
2348 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2349 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2350
2351 Session session = null;
2352
2353 try {
2354 session = openSession();
2355
2356 SQLQuery q = session.createSQLQuery(sql);
2357
2358 if (getDB().isSupportsInlineDistinct()) {
2359 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2360 }
2361 else {
2362 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2363 }
2364
2365 QueryPos qPos = QueryPos.getInstance(q);
2366
2367 if (subtype != null) {
2368 qPos.add(subtype);
2369 }
2370
2371 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2372 }
2373 catch (Exception e) {
2374 throw processException(e);
2375 }
2376 finally {
2377 closeSession(session);
2378 }
2379 }
2380
2381
2391 public Role[] filterFindBySubtype_PrevAndNext(long roleId, String subtype,
2392 OrderByComparator orderByComparator)
2393 throws NoSuchRoleException, SystemException {
2394 if (!InlineSQLHelperUtil.isEnabled()) {
2395 return findBySubtype_PrevAndNext(roleId, subtype, orderByComparator);
2396 }
2397
2398 Role role = findByPrimaryKey(roleId);
2399
2400 Session session = null;
2401
2402 try {
2403 session = openSession();
2404
2405 Role[] array = new RoleImpl[3];
2406
2407 array[0] = filterGetBySubtype_PrevAndNext(session, role, subtype,
2408 orderByComparator, true);
2409
2410 array[1] = role;
2411
2412 array[2] = filterGetBySubtype_PrevAndNext(session, role, subtype,
2413 orderByComparator, false);
2414
2415 return array;
2416 }
2417 catch (Exception e) {
2418 throw processException(e);
2419 }
2420 finally {
2421 closeSession(session);
2422 }
2423 }
2424
2425 protected Role filterGetBySubtype_PrevAndNext(Session session, Role role,
2426 String subtype, OrderByComparator orderByComparator, boolean previous) {
2427 StringBundler query = null;
2428
2429 if (orderByComparator != null) {
2430 query = new StringBundler(6 +
2431 (orderByComparator.getOrderByFields().length * 6));
2432 }
2433 else {
2434 query = new StringBundler(3);
2435 }
2436
2437 if (getDB().isSupportsInlineDistinct()) {
2438 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2439 }
2440 else {
2441 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2442 }
2443
2444 if (subtype == null) {
2445 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2446 }
2447 else {
2448 if (subtype.equals(StringPool.BLANK)) {
2449 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2450 }
2451 else {
2452 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2453 }
2454 }
2455
2456 if (!getDB().isSupportsInlineDistinct()) {
2457 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2458 }
2459
2460 if (orderByComparator != null) {
2461 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2462
2463 if (orderByConditionFields.length > 0) {
2464 query.append(WHERE_AND);
2465 }
2466
2467 for (int i = 0; i < orderByConditionFields.length; i++) {
2468 if (getDB().isSupportsInlineDistinct()) {
2469 query.append(_ORDER_BY_ENTITY_ALIAS);
2470 }
2471 else {
2472 query.append(_ORDER_BY_ENTITY_TABLE);
2473 }
2474
2475 query.append(orderByConditionFields[i]);
2476
2477 if ((i + 1) < orderByConditionFields.length) {
2478 if (orderByComparator.isAscending() ^ previous) {
2479 query.append(WHERE_GREATER_THAN_HAS_NEXT);
2480 }
2481 else {
2482 query.append(WHERE_LESSER_THAN_HAS_NEXT);
2483 }
2484 }
2485 else {
2486 if (orderByComparator.isAscending() ^ previous) {
2487 query.append(WHERE_GREATER_THAN);
2488 }
2489 else {
2490 query.append(WHERE_LESSER_THAN);
2491 }
2492 }
2493 }
2494
2495 query.append(ORDER_BY_CLAUSE);
2496
2497 String[] orderByFields = orderByComparator.getOrderByFields();
2498
2499 for (int i = 0; i < orderByFields.length; i++) {
2500 if (getDB().isSupportsInlineDistinct()) {
2501 query.append(_ORDER_BY_ENTITY_ALIAS);
2502 }
2503 else {
2504 query.append(_ORDER_BY_ENTITY_TABLE);
2505 }
2506
2507 query.append(orderByFields[i]);
2508
2509 if ((i + 1) < orderByFields.length) {
2510 if (orderByComparator.isAscending() ^ previous) {
2511 query.append(ORDER_BY_ASC_HAS_NEXT);
2512 }
2513 else {
2514 query.append(ORDER_BY_DESC_HAS_NEXT);
2515 }
2516 }
2517 else {
2518 if (orderByComparator.isAscending() ^ previous) {
2519 query.append(ORDER_BY_ASC);
2520 }
2521 else {
2522 query.append(ORDER_BY_DESC);
2523 }
2524 }
2525 }
2526 }
2527 else {
2528 if (getDB().isSupportsInlineDistinct()) {
2529 query.append(RoleModelImpl.ORDER_BY_JPQL);
2530 }
2531 else {
2532 query.append(RoleModelImpl.ORDER_BY_SQL);
2533 }
2534 }
2535
2536 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2537 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2538
2539 SQLQuery q = session.createSQLQuery(sql);
2540
2541 q.setFirstResult(0);
2542 q.setMaxResults(2);
2543
2544 if (getDB().isSupportsInlineDistinct()) {
2545 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2546 }
2547 else {
2548 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2549 }
2550
2551 QueryPos qPos = QueryPos.getInstance(q);
2552
2553 if (subtype != null) {
2554 qPos.add(subtype);
2555 }
2556
2557 if (orderByComparator != null) {
2558 Object[] values = orderByComparator.getOrderByConditionValues(role);
2559
2560 for (Object value : values) {
2561 qPos.add(value);
2562 }
2563 }
2564
2565 List<Role> list = q.list();
2566
2567 if (list.size() == 2) {
2568 return list.get(1);
2569 }
2570 else {
2571 return null;
2572 }
2573 }
2574
2575
2581 public void removeBySubtype(String subtype) throws SystemException {
2582 for (Role role : findBySubtype(subtype, QueryUtil.ALL_POS,
2583 QueryUtil.ALL_POS, null)) {
2584 remove(role);
2585 }
2586 }
2587
2588
2595 public int countBySubtype(String subtype) throws SystemException {
2596 FinderPath finderPath = FINDER_PATH_COUNT_BY_SUBTYPE;
2597
2598 Object[] finderArgs = new Object[] { subtype };
2599
2600 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2601 this);
2602
2603 if (count == null) {
2604 StringBundler query = new StringBundler(2);
2605
2606 query.append(_SQL_COUNT_ROLE_WHERE);
2607
2608 if (subtype == null) {
2609 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2610 }
2611 else {
2612 if (subtype.equals(StringPool.BLANK)) {
2613 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2614 }
2615 else {
2616 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2617 }
2618 }
2619
2620 String sql = query.toString();
2621
2622 Session session = null;
2623
2624 try {
2625 session = openSession();
2626
2627 Query q = session.createQuery(sql);
2628
2629 QueryPos qPos = QueryPos.getInstance(q);
2630
2631 if (subtype != null) {
2632 qPos.add(subtype);
2633 }
2634
2635 count = (Long)q.uniqueResult();
2636
2637 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2638 }
2639 catch (Exception e) {
2640 FinderCacheUtil.removeResult(finderPath, finderArgs);
2641
2642 throw processException(e);
2643 }
2644 finally {
2645 closeSession(session);
2646 }
2647 }
2648
2649 return count.intValue();
2650 }
2651
2652
2659 public int filterCountBySubtype(String subtype) throws SystemException {
2660 if (!InlineSQLHelperUtil.isEnabled()) {
2661 return countBySubtype(subtype);
2662 }
2663
2664 StringBundler query = new StringBundler(2);
2665
2666 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2667
2668 if (subtype == null) {
2669 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2670 }
2671 else {
2672 if (subtype.equals(StringPool.BLANK)) {
2673 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2674 }
2675 else {
2676 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2677 }
2678 }
2679
2680 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2681 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
2682
2683 Session session = null;
2684
2685 try {
2686 session = openSession();
2687
2688 SQLQuery q = session.createSQLQuery(sql);
2689
2690 q.addScalar(COUNT_COLUMN_NAME,
2691 com.liferay.portal.kernel.dao.orm.Type.LONG);
2692
2693 QueryPos qPos = QueryPos.getInstance(q);
2694
2695 if (subtype != null) {
2696 qPos.add(subtype);
2697 }
2698
2699 Long count = (Long)q.uniqueResult();
2700
2701 return count.intValue();
2702 }
2703 catch (Exception e) {
2704 throw processException(e);
2705 }
2706 finally {
2707 closeSession(session);
2708 }
2709 }
2710
2711 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
2712 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
2713 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
2714 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2715 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2716 FINDER_CLASS_NAME_ENTITY, "fetchByC_N",
2717 new String[] { Long.class.getName(), String.class.getName() },
2718 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
2719 RoleModelImpl.NAME_COLUMN_BITMASK);
2720 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2721 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2722 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_N",
2723 new String[] { Long.class.getName(), String.class.getName() });
2724
2725
2734 public Role findByC_N(long companyId, String name)
2735 throws NoSuchRoleException, SystemException {
2736 Role role = fetchByC_N(companyId, name);
2737
2738 if (role == null) {
2739 StringBundler msg = new StringBundler(6);
2740
2741 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2742
2743 msg.append("companyId=");
2744 msg.append(companyId);
2745
2746 msg.append(", name=");
2747 msg.append(name);
2748
2749 msg.append(StringPool.CLOSE_CURLY_BRACE);
2750
2751 if (_log.isWarnEnabled()) {
2752 _log.warn(msg.toString());
2753 }
2754
2755 throw new NoSuchRoleException(msg.toString());
2756 }
2757
2758 return role;
2759 }
2760
2761
2769 public Role fetchByC_N(long companyId, String name)
2770 throws SystemException {
2771 return fetchByC_N(companyId, name, true);
2772 }
2773
2774
2783 public Role fetchByC_N(long companyId, String name,
2784 boolean retrieveFromCache) throws SystemException {
2785 Object[] finderArgs = new Object[] { companyId, name };
2786
2787 Object result = null;
2788
2789 if (retrieveFromCache) {
2790 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
2791 finderArgs, this);
2792 }
2793
2794 if (result instanceof Role) {
2795 Role role = (Role)result;
2796
2797 if ((companyId != role.getCompanyId()) ||
2798 !Validator.equals(name, role.getName())) {
2799 result = null;
2800 }
2801 }
2802
2803 if (result == null) {
2804 StringBundler query = new StringBundler(4);
2805
2806 query.append(_SQL_SELECT_ROLE_WHERE);
2807
2808 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2809
2810 if (name == null) {
2811 query.append(_FINDER_COLUMN_C_N_NAME_1);
2812 }
2813 else {
2814 if (name.equals(StringPool.BLANK)) {
2815 query.append(_FINDER_COLUMN_C_N_NAME_3);
2816 }
2817 else {
2818 query.append(_FINDER_COLUMN_C_N_NAME_2);
2819 }
2820 }
2821
2822 String sql = query.toString();
2823
2824 Session session = null;
2825
2826 try {
2827 session = openSession();
2828
2829 Query q = session.createQuery(sql);
2830
2831 QueryPos qPos = QueryPos.getInstance(q);
2832
2833 qPos.add(companyId);
2834
2835 if (name != null) {
2836 qPos.add(name);
2837 }
2838
2839 List<Role> list = q.list();
2840
2841 if (list.isEmpty()) {
2842 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2843 finderArgs, list);
2844 }
2845 else {
2846 Role role = list.get(0);
2847
2848 result = role;
2849
2850 cacheResult(role);
2851
2852 if ((role.getCompanyId() != companyId) ||
2853 (role.getName() == null) ||
2854 !role.getName().equals(name)) {
2855 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
2856 finderArgs, role);
2857 }
2858 }
2859 }
2860 catch (Exception e) {
2861 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
2862 finderArgs);
2863
2864 throw processException(e);
2865 }
2866 finally {
2867 closeSession(session);
2868 }
2869 }
2870
2871 if (result instanceof List<?>) {
2872 return null;
2873 }
2874 else {
2875 return (Role)result;
2876 }
2877 }
2878
2879
2887 public Role removeByC_N(long companyId, String name)
2888 throws NoSuchRoleException, SystemException {
2889 Role role = findByC_N(companyId, name);
2890
2891 return remove(role);
2892 }
2893
2894
2902 public int countByC_N(long companyId, String name)
2903 throws SystemException {
2904 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_N;
2905
2906 Object[] finderArgs = new Object[] { companyId, name };
2907
2908 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2909 this);
2910
2911 if (count == null) {
2912 StringBundler query = new StringBundler(3);
2913
2914 query.append(_SQL_COUNT_ROLE_WHERE);
2915
2916 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2917
2918 if (name == null) {
2919 query.append(_FINDER_COLUMN_C_N_NAME_1);
2920 }
2921 else {
2922 if (name.equals(StringPool.BLANK)) {
2923 query.append(_FINDER_COLUMN_C_N_NAME_3);
2924 }
2925 else {
2926 query.append(_FINDER_COLUMN_C_N_NAME_2);
2927 }
2928 }
2929
2930 String sql = query.toString();
2931
2932 Session session = null;
2933
2934 try {
2935 session = openSession();
2936
2937 Query q = session.createQuery(sql);
2938
2939 QueryPos qPos = QueryPos.getInstance(q);
2940
2941 qPos.add(companyId);
2942
2943 if (name != null) {
2944 qPos.add(name);
2945 }
2946
2947 count = (Long)q.uniqueResult();
2948
2949 FinderCacheUtil.putResult(finderPath, finderArgs, count);
2950 }
2951 catch (Exception e) {
2952 FinderCacheUtil.removeResult(finderPath, finderArgs);
2953
2954 throw processException(e);
2955 }
2956 finally {
2957 closeSession(session);
2958 }
2959 }
2960
2961 return count.intValue();
2962 }
2963
2964 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
2965 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
2966 private static final String _FINDER_COLUMN_C_N_NAME_2 = "lower(role.name) = lower(CAST_TEXT(?))";
2967 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR lower(role.name) = lower(CAST_TEXT(?)))";
2968 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2969 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2970 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
2971 new String[] {
2972 Integer.class.getName(), String.class.getName(),
2973
2974 Integer.class.getName(), Integer.class.getName(),
2975 OrderByComparator.class.getName()
2976 });
2977 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2978 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
2979 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
2980 new String[] { Integer.class.getName(), String.class.getName() },
2981 RoleModelImpl.TYPE_COLUMN_BITMASK |
2982 RoleModelImpl.SUBTYPE_COLUMN_BITMASK |
2983 RoleModelImpl.NAME_COLUMN_BITMASK);
2984 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
2985 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
2986 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
2987 new String[] { Integer.class.getName(), String.class.getName() });
2988
2989
2997 public List<Role> findByT_S(int type, String subtype)
2998 throws SystemException {
2999 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
3000 null);
3001 }
3002
3003
3017 public List<Role> findByT_S(int type, String subtype, int start, int end)
3018 throws SystemException {
3019 return findByT_S(type, subtype, start, end, null);
3020 }
3021
3022
3037 public List<Role> findByT_S(int type, String subtype, int start, int end,
3038 OrderByComparator orderByComparator) throws SystemException {
3039 boolean pagination = true;
3040 FinderPath finderPath = null;
3041 Object[] finderArgs = null;
3042
3043 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3044 (orderByComparator == null)) {
3045 pagination = false;
3046 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
3047 finderArgs = new Object[] { type, subtype };
3048 }
3049 else {
3050 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
3051 finderArgs = new Object[] {
3052 type, subtype,
3053
3054 start, end, orderByComparator
3055 };
3056 }
3057
3058 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
3059 finderArgs, this);
3060
3061 if ((list != null) && !list.isEmpty()) {
3062 for (Role role : list) {
3063 if ((type != role.getType()) ||
3064 !Validator.equals(subtype, role.getSubtype())) {
3065 list = null;
3066
3067 break;
3068 }
3069 }
3070 }
3071
3072 if (list == null) {
3073 StringBundler query = null;
3074
3075 if (orderByComparator != null) {
3076 query = new StringBundler(4 +
3077 (orderByComparator.getOrderByFields().length * 3));
3078 }
3079 else {
3080 query = new StringBundler(4);
3081 }
3082
3083 query.append(_SQL_SELECT_ROLE_WHERE);
3084
3085 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3086
3087 if (subtype == null) {
3088 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3089 }
3090 else {
3091 if (subtype.equals(StringPool.BLANK)) {
3092 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3093 }
3094 else {
3095 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3096 }
3097 }
3098
3099 if (orderByComparator != null) {
3100 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3101 orderByComparator);
3102 }
3103 else
3104 if (pagination) {
3105 query.append(RoleModelImpl.ORDER_BY_JPQL);
3106 }
3107
3108 String sql = query.toString();
3109
3110 Session session = null;
3111
3112 try {
3113 session = openSession();
3114
3115 Query q = session.createQuery(sql);
3116
3117 QueryPos qPos = QueryPos.getInstance(q);
3118
3119 qPos.add(type);
3120
3121 if (subtype != null) {
3122 qPos.add(subtype);
3123 }
3124
3125 if (!pagination) {
3126 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3127 end, false);
3128
3129 Collections.sort(list);
3130
3131 list = new UnmodifiableList<Role>(list);
3132 }
3133 else {
3134 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
3135 end);
3136 }
3137
3138 cacheResult(list);
3139
3140 FinderCacheUtil.putResult(finderPath, finderArgs, list);
3141 }
3142 catch (Exception e) {
3143 FinderCacheUtil.removeResult(finderPath, finderArgs);
3144
3145 throw processException(e);
3146 }
3147 finally {
3148 closeSession(session);
3149 }
3150 }
3151
3152 return list;
3153 }
3154
3155
3165 public Role findByT_S_First(int type, String subtype,
3166 OrderByComparator orderByComparator)
3167 throws NoSuchRoleException, SystemException {
3168 Role role = fetchByT_S_First(type, subtype, orderByComparator);
3169
3170 if (role != null) {
3171 return role;
3172 }
3173
3174 StringBundler msg = new StringBundler(6);
3175
3176 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3177
3178 msg.append("type=");
3179 msg.append(type);
3180
3181 msg.append(", subtype=");
3182 msg.append(subtype);
3183
3184 msg.append(StringPool.CLOSE_CURLY_BRACE);
3185
3186 throw new NoSuchRoleException(msg.toString());
3187 }
3188
3189
3198 public Role fetchByT_S_First(int type, String subtype,
3199 OrderByComparator orderByComparator) throws SystemException {
3200 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
3201
3202 if (!list.isEmpty()) {
3203 return list.get(0);
3204 }
3205
3206 return null;
3207 }
3208
3209
3219 public Role findByT_S_Last(int type, String subtype,
3220 OrderByComparator orderByComparator)
3221 throws NoSuchRoleException, SystemException {
3222 Role role = fetchByT_S_Last(type, subtype, orderByComparator);
3223
3224 if (role != null) {
3225 return role;
3226 }
3227
3228 StringBundler msg = new StringBundler(6);
3229
3230 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3231
3232 msg.append("type=");
3233 msg.append(type);
3234
3235 msg.append(", subtype=");
3236 msg.append(subtype);
3237
3238 msg.append(StringPool.CLOSE_CURLY_BRACE);
3239
3240 throw new NoSuchRoleException(msg.toString());
3241 }
3242
3243
3252 public Role fetchByT_S_Last(int type, String subtype,
3253 OrderByComparator orderByComparator) throws SystemException {
3254 int count = countByT_S(type, subtype);
3255
3256 List<Role> list = findByT_S(type, subtype, count - 1, count,
3257 orderByComparator);
3258
3259 if (!list.isEmpty()) {
3260 return list.get(0);
3261 }
3262
3263 return null;
3264 }
3265
3266
3277 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
3278 OrderByComparator orderByComparator)
3279 throws NoSuchRoleException, SystemException {
3280 Role role = findByPrimaryKey(roleId);
3281
3282 Session session = null;
3283
3284 try {
3285 session = openSession();
3286
3287 Role[] array = new RoleImpl[3];
3288
3289 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
3290 orderByComparator, true);
3291
3292 array[1] = role;
3293
3294 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
3295 orderByComparator, false);
3296
3297 return array;
3298 }
3299 catch (Exception e) {
3300 throw processException(e);
3301 }
3302 finally {
3303 closeSession(session);
3304 }
3305 }
3306
3307 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
3308 String subtype, OrderByComparator orderByComparator, boolean previous) {
3309 StringBundler query = null;
3310
3311 if (orderByComparator != null) {
3312 query = new StringBundler(6 +
3313 (orderByComparator.getOrderByFields().length * 6));
3314 }
3315 else {
3316 query = new StringBundler(3);
3317 }
3318
3319 query.append(_SQL_SELECT_ROLE_WHERE);
3320
3321 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3322
3323 if (subtype == null) {
3324 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3325 }
3326 else {
3327 if (subtype.equals(StringPool.BLANK)) {
3328 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3329 }
3330 else {
3331 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3332 }
3333 }
3334
3335 if (orderByComparator != null) {
3336 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3337
3338 if (orderByConditionFields.length > 0) {
3339 query.append(WHERE_AND);
3340 }
3341
3342 for (int i = 0; i < orderByConditionFields.length; i++) {
3343 query.append(_ORDER_BY_ENTITY_ALIAS);
3344 query.append(orderByConditionFields[i]);
3345
3346 if ((i + 1) < orderByConditionFields.length) {
3347 if (orderByComparator.isAscending() ^ previous) {
3348 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3349 }
3350 else {
3351 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3352 }
3353 }
3354 else {
3355 if (orderByComparator.isAscending() ^ previous) {
3356 query.append(WHERE_GREATER_THAN);
3357 }
3358 else {
3359 query.append(WHERE_LESSER_THAN);
3360 }
3361 }
3362 }
3363
3364 query.append(ORDER_BY_CLAUSE);
3365
3366 String[] orderByFields = orderByComparator.getOrderByFields();
3367
3368 for (int i = 0; i < orderByFields.length; i++) {
3369 query.append(_ORDER_BY_ENTITY_ALIAS);
3370 query.append(orderByFields[i]);
3371
3372 if ((i + 1) < orderByFields.length) {
3373 if (orderByComparator.isAscending() ^ previous) {
3374 query.append(ORDER_BY_ASC_HAS_NEXT);
3375 }
3376 else {
3377 query.append(ORDER_BY_DESC_HAS_NEXT);
3378 }
3379 }
3380 else {
3381 if (orderByComparator.isAscending() ^ previous) {
3382 query.append(ORDER_BY_ASC);
3383 }
3384 else {
3385 query.append(ORDER_BY_DESC);
3386 }
3387 }
3388 }
3389 }
3390 else {
3391 query.append(RoleModelImpl.ORDER_BY_JPQL);
3392 }
3393
3394 String sql = query.toString();
3395
3396 Query q = session.createQuery(sql);
3397
3398 q.setFirstResult(0);
3399 q.setMaxResults(2);
3400
3401 QueryPos qPos = QueryPos.getInstance(q);
3402
3403 qPos.add(type);
3404
3405 if (subtype != null) {
3406 qPos.add(subtype);
3407 }
3408
3409 if (orderByComparator != null) {
3410 Object[] values = orderByComparator.getOrderByConditionValues(role);
3411
3412 for (Object value : values) {
3413 qPos.add(value);
3414 }
3415 }
3416
3417 List<Role> list = q.list();
3418
3419 if (list.size() == 2) {
3420 return list.get(1);
3421 }
3422 else {
3423 return null;
3424 }
3425 }
3426
3427
3435 public List<Role> filterFindByT_S(int type, String subtype)
3436 throws SystemException {
3437 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
3438 QueryUtil.ALL_POS, null);
3439 }
3440
3441
3455 public List<Role> filterFindByT_S(int type, String subtype, int start,
3456 int end) throws SystemException {
3457 return filterFindByT_S(type, subtype, start, end, null);
3458 }
3459
3460
3475 public List<Role> filterFindByT_S(int type, String subtype, int start,
3476 int end, OrderByComparator orderByComparator) throws SystemException {
3477 if (!InlineSQLHelperUtil.isEnabled()) {
3478 return findByT_S(type, subtype, start, end, orderByComparator);
3479 }
3480
3481 StringBundler query = null;
3482
3483 if (orderByComparator != null) {
3484 query = new StringBundler(4 +
3485 (orderByComparator.getOrderByFields().length * 3));
3486 }
3487 else {
3488 query = new StringBundler(4);
3489 }
3490
3491 if (getDB().isSupportsInlineDistinct()) {
3492 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3493 }
3494 else {
3495 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3496 }
3497
3498 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3499
3500 if (subtype == null) {
3501 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3502 }
3503 else {
3504 if (subtype.equals(StringPool.BLANK)) {
3505 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3506 }
3507 else {
3508 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3509 }
3510 }
3511
3512 if (!getDB().isSupportsInlineDistinct()) {
3513 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3514 }
3515
3516 if (orderByComparator != null) {
3517 if (getDB().isSupportsInlineDistinct()) {
3518 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3519 orderByComparator);
3520 }
3521 else {
3522 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3523 orderByComparator);
3524 }
3525 }
3526 else {
3527 if (getDB().isSupportsInlineDistinct()) {
3528 query.append(RoleModelImpl.ORDER_BY_JPQL);
3529 }
3530 else {
3531 query.append(RoleModelImpl.ORDER_BY_SQL);
3532 }
3533 }
3534
3535 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3536 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3537
3538 Session session = null;
3539
3540 try {
3541 session = openSession();
3542
3543 SQLQuery q = session.createSQLQuery(sql);
3544
3545 if (getDB().isSupportsInlineDistinct()) {
3546 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3547 }
3548 else {
3549 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3550 }
3551
3552 QueryPos qPos = QueryPos.getInstance(q);
3553
3554 qPos.add(type);
3555
3556 if (subtype != null) {
3557 qPos.add(subtype);
3558 }
3559
3560 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
3561 }
3562 catch (Exception e) {
3563 throw processException(e);
3564 }
3565 finally {
3566 closeSession(session);
3567 }
3568 }
3569
3570
3581 public Role[] filterFindByT_S_PrevAndNext(long roleId, int type,
3582 String subtype, OrderByComparator orderByComparator)
3583 throws NoSuchRoleException, SystemException {
3584 if (!InlineSQLHelperUtil.isEnabled()) {
3585 return findByT_S_PrevAndNext(roleId, type, subtype,
3586 orderByComparator);
3587 }
3588
3589 Role role = findByPrimaryKey(roleId);
3590
3591 Session session = null;
3592
3593 try {
3594 session = openSession();
3595
3596 Role[] array = new RoleImpl[3];
3597
3598 array[0] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
3599 orderByComparator, true);
3600
3601 array[1] = role;
3602
3603 array[2] = filterGetByT_S_PrevAndNext(session, role, type, subtype,
3604 orderByComparator, false);
3605
3606 return array;
3607 }
3608 catch (Exception e) {
3609 throw processException(e);
3610 }
3611 finally {
3612 closeSession(session);
3613 }
3614 }
3615
3616 protected Role filterGetByT_S_PrevAndNext(Session session, Role role,
3617 int type, String subtype, OrderByComparator orderByComparator,
3618 boolean previous) {
3619 StringBundler query = null;
3620
3621 if (orderByComparator != null) {
3622 query = new StringBundler(6 +
3623 (orderByComparator.getOrderByFields().length * 6));
3624 }
3625 else {
3626 query = new StringBundler(3);
3627 }
3628
3629 if (getDB().isSupportsInlineDistinct()) {
3630 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
3631 }
3632 else {
3633 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
3634 }
3635
3636 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3637
3638 if (subtype == null) {
3639 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3640 }
3641 else {
3642 if (subtype.equals(StringPool.BLANK)) {
3643 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3644 }
3645 else {
3646 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3647 }
3648 }
3649
3650 if (!getDB().isSupportsInlineDistinct()) {
3651 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
3652 }
3653
3654 if (orderByComparator != null) {
3655 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3656
3657 if (orderByConditionFields.length > 0) {
3658 query.append(WHERE_AND);
3659 }
3660
3661 for (int i = 0; i < orderByConditionFields.length; i++) {
3662 if (getDB().isSupportsInlineDistinct()) {
3663 query.append(_ORDER_BY_ENTITY_ALIAS);
3664 }
3665 else {
3666 query.append(_ORDER_BY_ENTITY_TABLE);
3667 }
3668
3669 query.append(orderByConditionFields[i]);
3670
3671 if ((i + 1) < orderByConditionFields.length) {
3672 if (orderByComparator.isAscending() ^ previous) {
3673 query.append(WHERE_GREATER_THAN_HAS_NEXT);
3674 }
3675 else {
3676 query.append(WHERE_LESSER_THAN_HAS_NEXT);
3677 }
3678 }
3679 else {
3680 if (orderByComparator.isAscending() ^ previous) {
3681 query.append(WHERE_GREATER_THAN);
3682 }
3683 else {
3684 query.append(WHERE_LESSER_THAN);
3685 }
3686 }
3687 }
3688
3689 query.append(ORDER_BY_CLAUSE);
3690
3691 String[] orderByFields = orderByComparator.getOrderByFields();
3692
3693 for (int i = 0; i < orderByFields.length; i++) {
3694 if (getDB().isSupportsInlineDistinct()) {
3695 query.append(_ORDER_BY_ENTITY_ALIAS);
3696 }
3697 else {
3698 query.append(_ORDER_BY_ENTITY_TABLE);
3699 }
3700
3701 query.append(orderByFields[i]);
3702
3703 if ((i + 1) < orderByFields.length) {
3704 if (orderByComparator.isAscending() ^ previous) {
3705 query.append(ORDER_BY_ASC_HAS_NEXT);
3706 }
3707 else {
3708 query.append(ORDER_BY_DESC_HAS_NEXT);
3709 }
3710 }
3711 else {
3712 if (orderByComparator.isAscending() ^ previous) {
3713 query.append(ORDER_BY_ASC);
3714 }
3715 else {
3716 query.append(ORDER_BY_DESC);
3717 }
3718 }
3719 }
3720 }
3721 else {
3722 if (getDB().isSupportsInlineDistinct()) {
3723 query.append(RoleModelImpl.ORDER_BY_JPQL);
3724 }
3725 else {
3726 query.append(RoleModelImpl.ORDER_BY_SQL);
3727 }
3728 }
3729
3730 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3731 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3732
3733 SQLQuery q = session.createSQLQuery(sql);
3734
3735 q.setFirstResult(0);
3736 q.setMaxResults(2);
3737
3738 if (getDB().isSupportsInlineDistinct()) {
3739 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
3740 }
3741 else {
3742 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
3743 }
3744
3745 QueryPos qPos = QueryPos.getInstance(q);
3746
3747 qPos.add(type);
3748
3749 if (subtype != null) {
3750 qPos.add(subtype);
3751 }
3752
3753 if (orderByComparator != null) {
3754 Object[] values = orderByComparator.getOrderByConditionValues(role);
3755
3756 for (Object value : values) {
3757 qPos.add(value);
3758 }
3759 }
3760
3761 List<Role> list = q.list();
3762
3763 if (list.size() == 2) {
3764 return list.get(1);
3765 }
3766 else {
3767 return null;
3768 }
3769 }
3770
3771
3778 public void removeByT_S(int type, String subtype) throws SystemException {
3779 for (Role role : findByT_S(type, subtype, QueryUtil.ALL_POS,
3780 QueryUtil.ALL_POS, null)) {
3781 remove(role);
3782 }
3783 }
3784
3785
3793 public int countByT_S(int type, String subtype) throws SystemException {
3794 FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
3795
3796 Object[] finderArgs = new Object[] { type, subtype };
3797
3798 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3799 this);
3800
3801 if (count == null) {
3802 StringBundler query = new StringBundler(3);
3803
3804 query.append(_SQL_COUNT_ROLE_WHERE);
3805
3806 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3807
3808 if (subtype == null) {
3809 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3810 }
3811 else {
3812 if (subtype.equals(StringPool.BLANK)) {
3813 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3814 }
3815 else {
3816 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3817 }
3818 }
3819
3820 String sql = query.toString();
3821
3822 Session session = null;
3823
3824 try {
3825 session = openSession();
3826
3827 Query q = session.createQuery(sql);
3828
3829 QueryPos qPos = QueryPos.getInstance(q);
3830
3831 qPos.add(type);
3832
3833 if (subtype != null) {
3834 qPos.add(subtype);
3835 }
3836
3837 count = (Long)q.uniqueResult();
3838
3839 FinderCacheUtil.putResult(finderPath, finderArgs, count);
3840 }
3841 catch (Exception e) {
3842 FinderCacheUtil.removeResult(finderPath, finderArgs);
3843
3844 throw processException(e);
3845 }
3846 finally {
3847 closeSession(session);
3848 }
3849 }
3850
3851 return count.intValue();
3852 }
3853
3854
3862 public int filterCountByT_S(int type, String subtype)
3863 throws SystemException {
3864 if (!InlineSQLHelperUtil.isEnabled()) {
3865 return countByT_S(type, subtype);
3866 }
3867
3868 StringBundler query = new StringBundler(3);
3869
3870 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
3871
3872 query.append(_FINDER_COLUMN_T_S_TYPE_2);
3873
3874 if (subtype == null) {
3875 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
3876 }
3877 else {
3878 if (subtype.equals(StringPool.BLANK)) {
3879 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
3880 }
3881 else {
3882 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
3883 }
3884 }
3885
3886 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3887 Role.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
3888
3889 Session session = null;
3890
3891 try {
3892 session = openSession();
3893
3894 SQLQuery q = session.createSQLQuery(sql);
3895
3896 q.addScalar(COUNT_COLUMN_NAME,
3897 com.liferay.portal.kernel.dao.orm.Type.LONG);
3898
3899 QueryPos qPos = QueryPos.getInstance(q);
3900
3901 qPos.add(type);
3902
3903 if (subtype != null) {
3904 qPos.add(subtype);
3905 }
3906
3907 Long count = (Long)q.uniqueResult();
3908
3909 return count.intValue();
3910 }
3911 catch (Exception e) {
3912 throw processException(e);
3913 }
3914 finally {
3915 closeSession(session);
3916 }
3917 }
3918
3919 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
3920 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
3921 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
3922 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
3923 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3924 RoleModelImpl.FINDER_CACHE_ENABLED, RoleImpl.class,
3925 FINDER_CLASS_NAME_ENTITY, "fetchByC_C_C",
3926 new String[] {
3927 Long.class.getName(), Long.class.getName(), Long.class.getName()
3928 },
3929 RoleModelImpl.COMPANYID_COLUMN_BITMASK |
3930 RoleModelImpl.CLASSNAMEID_COLUMN_BITMASK |
3931 RoleModelImpl.CLASSPK_COLUMN_BITMASK);
3932 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
3933 RoleModelImpl.FINDER_CACHE_ENABLED, Long.class,
3934 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_C",
3935 new String[] {
3936 Long.class.getName(), Long.class.getName(), Long.class.getName()
3937 });
3938
3939
3949 public Role findByC_C_C(long companyId, long classNameId, long classPK)
3950 throws NoSuchRoleException, SystemException {
3951 Role role = fetchByC_C_C(companyId, classNameId, classPK);
3952
3953 if (role == null) {
3954 StringBundler msg = new StringBundler(8);
3955
3956 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3957
3958 msg.append("companyId=");
3959 msg.append(companyId);
3960
3961 msg.append(", classNameId=");
3962 msg.append(classNameId);
3963
3964 msg.append(", classPK=");
3965 msg.append(classPK);
3966
3967 msg.append(StringPool.CLOSE_CURLY_BRACE);
3968
3969 if (_log.isWarnEnabled()) {
3970 _log.warn(msg.toString());
3971 }
3972
3973 throw new NoSuchRoleException(msg.toString());
3974 }
3975
3976 return role;
3977 }
3978
3979
3988 public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
3989 throws SystemException {
3990 return fetchByC_C_C(companyId, classNameId, classPK, true);
3991 }
3992
3993
4003 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
4004 boolean retrieveFromCache) throws SystemException {
4005 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
4006
4007 Object result = null;
4008
4009 if (retrieveFromCache) {
4010 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
4011 finderArgs, this);
4012 }
4013
4014 if (result instanceof Role) {
4015 Role role = (Role)result;
4016
4017 if ((companyId != role.getCompanyId()) ||
4018 (classNameId != role.getClassNameId()) ||
4019 (classPK != role.getClassPK())) {
4020 result = null;
4021 }
4022 }
4023
4024 if (result == null) {
4025 StringBundler query = new StringBundler(5);
4026
4027 query.append(_SQL_SELECT_ROLE_WHERE);
4028
4029 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
4030
4031 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
4032
4033 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
4034
4035 String sql = query.toString();
4036
4037 Session session = null;
4038
4039 try {
4040 session = openSession();
4041
4042 Query q = session.createQuery(sql);
4043
4044 QueryPos qPos = QueryPos.getInstance(q);
4045
4046 qPos.add(companyId);
4047
4048 qPos.add(classNameId);
4049
4050 qPos.add(classPK);
4051
4052 List<Role> list = q.list();
4053
4054 if (list.isEmpty()) {
4055 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
4056 finderArgs, list);
4057 }
4058 else {
4059 Role role = list.get(0);
4060
4061 result = role;
4062
4063 cacheResult(role);
4064
4065 if ((role.getCompanyId() != companyId) ||
4066 (role.getClassNameId() != classNameId) ||
4067 (role.getClassPK() != classPK)) {
4068 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
4069 finderArgs, role);
4070 }
4071 }
4072 }
4073 catch (Exception e) {
4074 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
4075 finderArgs);
4076
4077 throw processException(e);
4078 }
4079 finally {
4080 closeSession(session);
4081 }
4082 }
4083
4084 if (result instanceof List<?>) {
4085 return null;
4086 }
4087 else {
4088 return (Role)result;
4089 }
4090 }
4091
4092
4101 public Role removeByC_C_C(long companyId, long classNameId, long classPK)
4102 throws NoSuchRoleException, SystemException {
4103 Role role = findByC_C_C(companyId, classNameId, classPK);
4104
4105 return remove(role);
4106 }
4107
4108
4117 public int countByC_C_C(long companyId, long classNameId, long classPK)
4118 throws SystemException {
4119 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_C;
4120
4121 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
4122
4123 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4124 this);
4125
4126 if (count == null) {
4127 StringBundler query = new StringBundler(4);
4128
4129 query.append(_SQL_COUNT_ROLE_WHERE);
4130
4131 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
4132
4133 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
4134
4135 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
4136
4137 String sql = query.toString();
4138
4139 Session session = null;
4140
4141 try {
4142 session = openSession();
4143
4144 Query q = session.createQuery(sql);
4145
4146 QueryPos qPos = QueryPos.getInstance(q);
4147
4148 qPos.add(companyId);
4149
4150 qPos.add(classNameId);
4151
4152 qPos.add(classPK);
4153
4154 count = (Long)q.uniqueResult();
4155
4156 FinderCacheUtil.putResult(finderPath, finderArgs, count);
4157 }
4158 catch (Exception e) {
4159 FinderCacheUtil.removeResult(finderPath, finderArgs);
4160
4161 throw processException(e);
4162 }
4163 finally {
4164 closeSession(session);
4165 }
4166 }
4167
4168 return count.intValue();
4169 }
4170
4171 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
4172 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
4173 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
4174
4175
4180 public void cacheResult(Role role) {
4181 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4182 RoleImpl.class, role.getPrimaryKey(), role);
4183
4184 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
4185 new Object[] { Long.valueOf(role.getCompanyId()), role.getName() },
4186 role);
4187
4188 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
4189 new Object[] {
4190 Long.valueOf(role.getCompanyId()),
4191 Long.valueOf(role.getClassNameId()),
4192 Long.valueOf(role.getClassPK())
4193 }, role);
4194
4195 role.resetOriginalValues();
4196 }
4197
4198
4203 public void cacheResult(List<Role> roles) {
4204 for (Role role : roles) {
4205 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4206 RoleImpl.class, role.getPrimaryKey()) == null) {
4207 cacheResult(role);
4208 }
4209 else {
4210 role.resetOriginalValues();
4211 }
4212 }
4213 }
4214
4215
4222 @Override
4223 public void clearCache() {
4224 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
4225 CacheRegistryUtil.clear(RoleImpl.class.getName());
4226 }
4227
4228 EntityCacheUtil.clearCache(RoleImpl.class.getName());
4229
4230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
4231 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4232 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4233 }
4234
4235
4242 @Override
4243 public void clearCache(Role role) {
4244 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4245 RoleImpl.class, role.getPrimaryKey());
4246
4247 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4248 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4249
4250 clearUniqueFindersCache(role);
4251 }
4252
4253 @Override
4254 public void clearCache(List<Role> roles) {
4255 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4256 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4257
4258 for (Role role : roles) {
4259 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4260 RoleImpl.class, role.getPrimaryKey());
4261
4262 clearUniqueFindersCache(role);
4263 }
4264 }
4265
4266 protected void cacheUniqueFindersCache(Role role) {
4267 if (role.isNew()) {
4268 Object[] args = new Object[] {
4269 Long.valueOf(role.getCompanyId()),
4270
4271 role.getName()
4272 };
4273
4274 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
4275 Long.valueOf(1));
4276 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
4277
4278 args = new Object[] {
4279 Long.valueOf(role.getCompanyId()),
4280 Long.valueOf(role.getClassNameId()),
4281 Long.valueOf(role.getClassPK())
4282 };
4283
4284 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
4285 Long.valueOf(1));
4286 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
4287 }
4288 else {
4289 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
4290
4291 if ((roleModelImpl.getColumnBitmask() &
4292 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
4293 Object[] args = new Object[] {
4294 Long.valueOf(role.getCompanyId()),
4295
4296 role.getName()
4297 };
4298
4299 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, args,
4300 Long.valueOf(1));
4301 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N, args, role);
4302 }
4303
4304 if ((roleModelImpl.getColumnBitmask() &
4305 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
4306 Object[] args = new Object[] {
4307 Long.valueOf(role.getCompanyId()),
4308 Long.valueOf(role.getClassNameId()),
4309 Long.valueOf(role.getClassPK())
4310 };
4311
4312 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C, args,
4313 Long.valueOf(1));
4314 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C, args, role);
4315 }
4316 }
4317 }
4318
4319 protected void clearUniqueFindersCache(Role role) {
4320 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
4321
4322 Object[] args = new Object[] {
4323 Long.valueOf(role.getCompanyId()),
4324
4325 role.getName()
4326 };
4327
4328 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
4329 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
4330
4331 if ((roleModelImpl.getColumnBitmask() &
4332 FINDER_PATH_FETCH_BY_C_N.getColumnBitmask()) != 0) {
4333 args = new Object[] {
4334 Long.valueOf(roleModelImpl.getOriginalCompanyId()),
4335
4336 roleModelImpl.getOriginalName()
4337 };
4338
4339 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_N, args);
4340 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N, args);
4341 }
4342
4343 args = new Object[] {
4344 Long.valueOf(role.getCompanyId()),
4345 Long.valueOf(role.getClassNameId()),
4346 Long.valueOf(role.getClassPK())
4347 };
4348
4349 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4350 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
4351
4352 if ((roleModelImpl.getColumnBitmask() &
4353 FINDER_PATH_FETCH_BY_C_C_C.getColumnBitmask()) != 0) {
4354 args = new Object[] {
4355 Long.valueOf(roleModelImpl.getOriginalCompanyId()),
4356 Long.valueOf(roleModelImpl.getOriginalClassNameId()),
4357 Long.valueOf(roleModelImpl.getOriginalClassPK())
4358 };
4359
4360 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_C, args);
4361 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C, args);
4362 }
4363 }
4364
4365
4371 public Role create(long roleId) {
4372 Role role = new RoleImpl();
4373
4374 role.setNew(true);
4375 role.setPrimaryKey(roleId);
4376
4377 return role;
4378 }
4379
4380
4388 public Role remove(long roleId) throws NoSuchRoleException, SystemException {
4389 return remove(Long.valueOf(roleId));
4390 }
4391
4392
4400 @Override
4401 public Role remove(Serializable primaryKey)
4402 throws NoSuchRoleException, SystemException {
4403 Session session = null;
4404
4405 try {
4406 session = openSession();
4407
4408 Role role = (Role)session.get(RoleImpl.class, primaryKey);
4409
4410 if (role == null) {
4411 if (_log.isWarnEnabled()) {
4412 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
4413 }
4414
4415 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4416 primaryKey);
4417 }
4418
4419 return remove(role);
4420 }
4421 catch (NoSuchRoleException nsee) {
4422 throw nsee;
4423 }
4424 catch (Exception e) {
4425 throw processException(e);
4426 }
4427 finally {
4428 closeSession(session);
4429 }
4430 }
4431
4432 @Override
4433 protected Role removeImpl(Role role) throws SystemException {
4434 role = toUnwrappedModel(role);
4435
4436 try {
4437 clearGroups.clear(role.getPrimaryKey());
4438 }
4439 catch (Exception e) {
4440 throw processException(e);
4441 }
4442 finally {
4443 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
4444 }
4445
4446 try {
4447 clearUsers.clear(role.getPrimaryKey());
4448 }
4449 catch (Exception e) {
4450 throw processException(e);
4451 }
4452 finally {
4453 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4454 }
4455
4456 Session session = null;
4457
4458 try {
4459 session = openSession();
4460
4461 if (!session.contains(role)) {
4462 role = (Role)session.get(RoleImpl.class, role.getPrimaryKeyObj());
4463 }
4464
4465 if (role != null) {
4466 session.delete(role);
4467 }
4468 }
4469 catch (Exception e) {
4470 throw processException(e);
4471 }
4472 finally {
4473 closeSession(session);
4474 }
4475
4476 if (role != null) {
4477 clearCache(role);
4478 }
4479
4480 return role;
4481 }
4482
4483 @Override
4484 public Role updateImpl(com.liferay.portal.model.Role role)
4485 throws SystemException {
4486 role = toUnwrappedModel(role);
4487
4488 boolean isNew = role.isNew();
4489
4490 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
4491
4492 Session session = null;
4493
4494 try {
4495 session = openSession();
4496
4497 if (role.isNew()) {
4498 session.save(role);
4499
4500 role.setNew(false);
4501 }
4502 else {
4503 session.merge(role);
4504 }
4505 }
4506 catch (Exception e) {
4507 throw processException(e);
4508 }
4509 finally {
4510 closeSession(session);
4511 }
4512
4513 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
4514
4515 if (isNew || !RoleModelImpl.COLUMN_BITMASK_ENABLED) {
4516 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4517 }
4518
4519 else {
4520 if ((roleModelImpl.getColumnBitmask() &
4521 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
4522 Object[] args = new Object[] {
4523 Long.valueOf(roleModelImpl.getOriginalCompanyId())
4524 };
4525
4526 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4527 args);
4528 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4529 args);
4530
4531 args = new Object[] { Long.valueOf(roleModelImpl.getCompanyId()) };
4532
4533 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
4534 args);
4535 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
4536 args);
4537 }
4538
4539 if ((roleModelImpl.getColumnBitmask() &
4540 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME.getColumnBitmask()) != 0) {
4541 Object[] args = new Object[] { roleModelImpl.getOriginalName() };
4542
4543 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
4544 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
4545 args);
4546
4547 args = new Object[] { roleModelImpl.getName() };
4548
4549 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_NAME, args);
4550 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_NAME,
4551 args);
4552 }
4553
4554 if ((roleModelImpl.getColumnBitmask() &
4555 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE.getColumnBitmask()) != 0) {
4556 Object[] args = new Object[] { roleModelImpl.getOriginalSubtype() };
4557
4558 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
4559 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
4560 args);
4561
4562 args = new Object[] { roleModelImpl.getSubtype() };
4563
4564 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_SUBTYPE, args);
4565 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_SUBTYPE,
4566 args);
4567 }
4568
4569 if ((roleModelImpl.getColumnBitmask() &
4570 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
4571 Object[] args = new Object[] {
4572 Integer.valueOf(roleModelImpl.getOriginalType()),
4573
4574 roleModelImpl.getOriginalSubtype()
4575 };
4576
4577 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
4578 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
4579 args);
4580
4581 args = new Object[] {
4582 Integer.valueOf(roleModelImpl.getType()),
4583
4584 roleModelImpl.getSubtype()
4585 };
4586
4587 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
4588 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
4589 args);
4590 }
4591 }
4592
4593 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4594 RoleImpl.class, role.getPrimaryKey(), role);
4595
4596 clearUniqueFindersCache(role);
4597 cacheUniqueFindersCache(role);
4598
4599 return role;
4600 }
4601
4602 protected Role toUnwrappedModel(Role role) {
4603 if (role instanceof RoleImpl) {
4604 return role;
4605 }
4606
4607 RoleImpl roleImpl = new RoleImpl();
4608
4609 roleImpl.setNew(role.isNew());
4610 roleImpl.setPrimaryKey(role.getPrimaryKey());
4611
4612 roleImpl.setRoleId(role.getRoleId());
4613 roleImpl.setCompanyId(role.getCompanyId());
4614 roleImpl.setClassNameId(role.getClassNameId());
4615 roleImpl.setClassPK(role.getClassPK());
4616 roleImpl.setName(role.getName());
4617 roleImpl.setTitle(role.getTitle());
4618 roleImpl.setDescription(role.getDescription());
4619 roleImpl.setType(role.getType());
4620 roleImpl.setSubtype(role.getSubtype());
4621
4622 return roleImpl;
4623 }
4624
4625
4633 @Override
4634 public Role findByPrimaryKey(Serializable primaryKey)
4635 throws NoSuchModelException, SystemException {
4636 return findByPrimaryKey(((Long)primaryKey).longValue());
4637 }
4638
4639
4647 public Role findByPrimaryKey(long roleId)
4648 throws NoSuchRoleException, SystemException {
4649 Role role = fetchByPrimaryKey(roleId);
4650
4651 if (role == null) {
4652 if (_log.isWarnEnabled()) {
4653 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + roleId);
4654 }
4655
4656 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
4657 roleId);
4658 }
4659
4660 return role;
4661 }
4662
4663
4670 @Override
4671 public Role fetchByPrimaryKey(Serializable primaryKey)
4672 throws SystemException {
4673 return fetchByPrimaryKey(((Long)primaryKey).longValue());
4674 }
4675
4676
4683 public Role fetchByPrimaryKey(long roleId) throws SystemException {
4684 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4685 RoleImpl.class, roleId);
4686
4687 if (role == _nullRole) {
4688 return null;
4689 }
4690
4691 if (role == null) {
4692 Session session = null;
4693
4694 try {
4695 session = openSession();
4696
4697 role = (Role)session.get(RoleImpl.class, Long.valueOf(roleId));
4698
4699 if (role != null) {
4700 cacheResult(role);
4701 }
4702 else {
4703 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4704 RoleImpl.class, roleId, _nullRole);
4705 }
4706 }
4707 catch (Exception e) {
4708 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
4709 RoleImpl.class, roleId);
4710
4711 throw processException(e);
4712 }
4713 finally {
4714 closeSession(session);
4715 }
4716 }
4717
4718 return role;
4719 }
4720
4721
4727 public List<Role> findAll() throws SystemException {
4728 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
4729 }
4730
4731
4743 public List<Role> findAll(int start, int end) throws SystemException {
4744 return findAll(start, end, null);
4745 }
4746
4747
4760 public List<Role> findAll(int start, int end,
4761 OrderByComparator orderByComparator) throws SystemException {
4762 boolean pagination = true;
4763 FinderPath finderPath = null;
4764 Object[] finderArgs = null;
4765
4766 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4767 (orderByComparator == null)) {
4768 pagination = false;
4769 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
4770 finderArgs = FINDER_ARGS_EMPTY;
4771 }
4772 else {
4773 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
4774 finderArgs = new Object[] { start, end, orderByComparator };
4775 }
4776
4777 List<Role> list = (List<Role>)FinderCacheUtil.getResult(finderPath,
4778 finderArgs, this);
4779
4780 if (list == null) {
4781 StringBundler query = null;
4782 String sql = null;
4783
4784 if (orderByComparator != null) {
4785 query = new StringBundler(2 +
4786 (orderByComparator.getOrderByFields().length * 3));
4787
4788 query.append(_SQL_SELECT_ROLE);
4789
4790 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4791 orderByComparator);
4792
4793 sql = query.toString();
4794 }
4795 else {
4796 sql = _SQL_SELECT_ROLE;
4797
4798 if (pagination) {
4799 sql = sql.concat(RoleModelImpl.ORDER_BY_JPQL);
4800 }
4801 }
4802
4803 Session session = null;
4804
4805 try {
4806 session = openSession();
4807
4808 Query q = session.createQuery(sql);
4809
4810 if (!pagination) {
4811 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4812 end, false);
4813
4814 Collections.sort(list);
4815
4816 list = new UnmodifiableList<Role>(list);
4817 }
4818 else {
4819 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
4820 end);
4821 }
4822
4823 cacheResult(list);
4824
4825 FinderCacheUtil.putResult(finderPath, finderArgs, list);
4826 }
4827 catch (Exception e) {
4828 FinderCacheUtil.removeResult(finderPath, finderArgs);
4829
4830 throw processException(e);
4831 }
4832 finally {
4833 closeSession(session);
4834 }
4835 }
4836
4837 return list;
4838 }
4839
4840
4845 public void removeAll() throws SystemException {
4846 for (Role role : findAll()) {
4847 remove(role);
4848 }
4849 }
4850
4851
4857 public int countAll() throws SystemException {
4858 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4859 FINDER_ARGS_EMPTY, this);
4860
4861 if (count == null) {
4862 Session session = null;
4863
4864 try {
4865 session = openSession();
4866
4867 Query q = session.createQuery(_SQL_COUNT_ROLE);
4868
4869 count = (Long)q.uniqueResult();
4870
4871 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4872 FINDER_ARGS_EMPTY, count);
4873 }
4874 catch (Exception e) {
4875 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
4876 FINDER_ARGS_EMPTY);
4877
4878 throw processException(e);
4879 }
4880 finally {
4881 closeSession(session);
4882 }
4883 }
4884
4885 return count.intValue();
4886 }
4887
4888
4895 public List<com.liferay.portal.model.Group> getGroups(long pk)
4896 throws SystemException {
4897 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
4898 }
4899
4900
4913 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
4914 int end) throws SystemException {
4915 return getGroups(pk, start, end, null);
4916 }
4917
4918 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
4919 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
4920 com.liferay.portal.model.impl.GroupImpl.class,
4921 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroups",
4922 new String[] {
4923 Long.class.getName(), Integer.class.getName(),
4924 Integer.class.getName(), OrderByComparator.class.getName()
4925 });
4926
4927 static {
4928 FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
4929 }
4930
4931
4945 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
4946 int end, OrderByComparator orderByComparator) throws SystemException {
4947 boolean pagination = true;
4948 Object[] finderArgs = null;
4949
4950 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4951 (orderByComparator == null)) {
4952 pagination = false;
4953 finderArgs = new Object[] { pk };
4954 }
4955 else {
4956 finderArgs = new Object[] { pk, start, end, orderByComparator };
4957 }
4958
4959 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
4960 finderArgs, this);
4961
4962 if (list == null) {
4963 Session session = null;
4964
4965 try {
4966 session = openSession();
4967
4968 String sql = null;
4969
4970 if (orderByComparator != null) {
4971 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
4972 .concat(orderByComparator.getOrderBy());
4973 }
4974 else {
4975 sql = _SQL_GETGROUPS;
4976
4977 if (pagination) {
4978 sql = sql.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
4979 }
4980 }
4981
4982 SQLQuery q = session.createSQLQuery(sql);
4983
4984 q.addEntity("Group_",
4985 com.liferay.portal.model.impl.GroupImpl.class);
4986
4987 QueryPos qPos = QueryPos.getInstance(q);
4988
4989 qPos.add(pk);
4990
4991 if (!pagination) {
4992 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
4993 getDialect(), start, end, false);
4994
4995 Collections.sort(list);
4996
4997 list = new UnmodifiableList<com.liferay.portal.model.Group>(list);
4998 }
4999 else {
5000 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
5001 getDialect(), start, end);
5002 }
5003
5004 groupPersistence.cacheResult(list);
5005
5006 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
5007 list);
5008 }
5009 catch (Exception e) {
5010 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS, finderArgs);
5011
5012 throw processException(e);
5013 }
5014 finally {
5015 closeSession(session);
5016 }
5017 }
5018
5019 return list;
5020 }
5021
5022 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
5023 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Long.class,
5024 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroupsSize",
5025 new String[] { Long.class.getName() });
5026
5027 static {
5028 FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
5029 }
5030
5031
5038 public int getGroupsSize(long pk) throws SystemException {
5039 Object[] finderArgs = new Object[] { pk };
5040
5041 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
5042 finderArgs, this);
5043
5044 if (count == null) {
5045 Session session = null;
5046
5047 try {
5048 session = openSession();
5049
5050 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
5051
5052 q.addScalar(COUNT_COLUMN_NAME,
5053 com.liferay.portal.kernel.dao.orm.Type.LONG);
5054
5055 QueryPos qPos = QueryPos.getInstance(q);
5056
5057 qPos.add(pk);
5058
5059 count = (Long)q.uniqueResult();
5060
5061 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
5062 finderArgs, count);
5063 }
5064 catch (Exception e) {
5065 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS_SIZE,
5066 finderArgs);
5067
5068 throw processException(e);
5069 }
5070 finally {
5071 closeSession(session);
5072 }
5073 }
5074
5075 return count.intValue();
5076 }
5077
5078 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
5079 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES, Boolean.class,
5080 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "containsGroup",
5081 new String[] { Long.class.getName(), Long.class.getName() });
5082
5083
5091 public boolean containsGroup(long pk, long groupPK)
5092 throws SystemException {
5093 Object[] finderArgs = new Object[] { pk, groupPK };
5094
5095 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
5096 finderArgs, this);
5097
5098 if (value == null) {
5099 try {
5100 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
5101
5102 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
5103 finderArgs, value);
5104 }
5105 catch (Exception e) {
5106 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_GROUP,
5107 finderArgs);
5108
5109 throw processException(e);
5110 }
5111 }
5112
5113 return value.booleanValue();
5114 }
5115
5116
5123 public boolean containsGroups(long pk) throws SystemException {
5124 if (getGroupsSize(pk) > 0) {
5125 return true;
5126 }
5127 else {
5128 return false;
5129 }
5130 }
5131
5132
5139 public void addGroup(long pk, long groupPK) throws SystemException {
5140 try {
5141 addGroup.add(pk, groupPK);
5142 }
5143 catch (Exception e) {
5144 throw processException(e);
5145 }
5146 finally {
5147 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5148 }
5149 }
5150
5151
5158 public void addGroup(long pk, com.liferay.portal.model.Group group)
5159 throws SystemException {
5160 try {
5161 addGroup.add(pk, group.getPrimaryKey());
5162 }
5163 catch (Exception e) {
5164 throw processException(e);
5165 }
5166 finally {
5167 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5168 }
5169 }
5170
5171
5178 public void addGroups(long pk, long[] groupPKs) throws SystemException {
5179 try {
5180 for (long groupPK : groupPKs) {
5181 addGroup.add(pk, groupPK);
5182 }
5183 }
5184 catch (Exception e) {
5185 throw processException(e);
5186 }
5187 finally {
5188 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5189 }
5190 }
5191
5192
5199 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
5200 throws SystemException {
5201 try {
5202 for (com.liferay.portal.model.Group group : groups) {
5203 addGroup.add(pk, group.getPrimaryKey());
5204 }
5205 }
5206 catch (Exception e) {
5207 throw processException(e);
5208 }
5209 finally {
5210 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5211 }
5212 }
5213
5214
5220 public void clearGroups(long pk) throws SystemException {
5221 try {
5222 clearGroups.clear(pk);
5223 }
5224 catch (Exception e) {
5225 throw processException(e);
5226 }
5227 finally {
5228 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5229 }
5230 }
5231
5232
5239 public void removeGroup(long pk, long groupPK) throws SystemException {
5240 try {
5241 removeGroup.remove(pk, groupPK);
5242 }
5243 catch (Exception e) {
5244 throw processException(e);
5245 }
5246 finally {
5247 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5248 }
5249 }
5250
5251
5258 public void removeGroup(long pk, com.liferay.portal.model.Group group)
5259 throws SystemException {
5260 try {
5261 removeGroup.remove(pk, group.getPrimaryKey());
5262 }
5263 catch (Exception e) {
5264 throw processException(e);
5265 }
5266 finally {
5267 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5268 }
5269 }
5270
5271
5278 public void removeGroups(long pk, long[] groupPKs)
5279 throws SystemException {
5280 try {
5281 for (long groupPK : groupPKs) {
5282 removeGroup.remove(pk, groupPK);
5283 }
5284 }
5285 catch (Exception e) {
5286 throw processException(e);
5287 }
5288 finally {
5289 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5290 }
5291 }
5292
5293
5300 public void removeGroups(long pk,
5301 List<com.liferay.portal.model.Group> groups) throws SystemException {
5302 try {
5303 for (com.liferay.portal.model.Group group : groups) {
5304 removeGroup.remove(pk, group.getPrimaryKey());
5305 }
5306 }
5307 catch (Exception e) {
5308 throw processException(e);
5309 }
5310 finally {
5311 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5312 }
5313 }
5314
5315
5322 public void setGroups(long pk, long[] groupPKs) throws SystemException {
5323 try {
5324 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
5325
5326 List<com.liferay.portal.model.Group> groups = getGroups(pk);
5327
5328 for (com.liferay.portal.model.Group group : groups) {
5329 if (!groupPKSet.remove(group.getPrimaryKey())) {
5330 removeGroup.remove(pk, group.getPrimaryKey());
5331 }
5332 }
5333
5334 for (Long groupPK : groupPKSet) {
5335 addGroup.add(pk, groupPK);
5336 }
5337 }
5338 catch (Exception e) {
5339 throw processException(e);
5340 }
5341 finally {
5342 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5343 }
5344 }
5345
5346
5353 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
5354 throws SystemException {
5355 try {
5356 long[] groupPKs = new long[groups.size()];
5357
5358 for (int i = 0; i < groups.size(); i++) {
5359 com.liferay.portal.model.Group group = groups.get(i);
5360
5361 groupPKs[i] = group.getPrimaryKey();
5362 }
5363
5364 setGroups(pk, groupPKs);
5365 }
5366 catch (Exception e) {
5367 throw processException(e);
5368 }
5369 finally {
5370 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
5371 }
5372 }
5373
5374
5381 public List<com.liferay.portal.model.User> getUsers(long pk)
5382 throws SystemException {
5383 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
5384 }
5385
5386
5399 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
5400 int end) throws SystemException {
5401 return getUsers(pk, start, end, null);
5402 }
5403
5404 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5405 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
5406 com.liferay.portal.model.impl.UserImpl.class,
5407 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsers",
5408 new String[] {
5409 Long.class.getName(), Integer.class.getName(),
5410 Integer.class.getName(), OrderByComparator.class.getName()
5411 });
5412
5413 static {
5414 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
5415 }
5416
5417
5431 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
5432 int end, OrderByComparator orderByComparator) throws SystemException {
5433 boolean pagination = true;
5434 Object[] finderArgs = null;
5435
5436 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5437 (orderByComparator == null)) {
5438 pagination = false;
5439 finderArgs = new Object[] { pk };
5440 }
5441 else {
5442 finderArgs = new Object[] { pk, start, end, orderByComparator };
5443 }
5444
5445 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
5446 finderArgs, this);
5447
5448 if (list == null) {
5449 Session session = null;
5450
5451 try {
5452 session = openSession();
5453
5454 String sql = null;
5455
5456 if (orderByComparator != null) {
5457 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
5458 .concat(orderByComparator.getOrderBy());
5459 }
5460 else {
5461 sql = _SQL_GETUSERS;
5462
5463 if (pagination) {
5464 sql = sql.concat(com.liferay.portal.model.impl.UserModelImpl.ORDER_BY_SQL);
5465 }
5466 }
5467
5468 SQLQuery q = session.createSQLQuery(sql);
5469
5470 q.addEntity("User_",
5471 com.liferay.portal.model.impl.UserImpl.class);
5472
5473 QueryPos qPos = QueryPos.getInstance(q);
5474
5475 qPos.add(pk);
5476
5477 if (!pagination) {
5478 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
5479 getDialect(), start, end, false);
5480
5481 Collections.sort(list);
5482
5483 list = new UnmodifiableList<com.liferay.portal.model.User>(list);
5484 }
5485 else {
5486 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
5487 getDialect(), start, end);
5488 }
5489
5490 userPersistence.cacheResult(list);
5491
5492 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
5493 list);
5494 }
5495 catch (Exception e) {
5496 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS, finderArgs);
5497
5498 throw processException(e);
5499 }
5500 finally {
5501 closeSession(session);
5502 }
5503 }
5504
5505 return list;
5506 }
5507
5508 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5509 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, Long.class,
5510 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsersSize",
5511 new String[] { Long.class.getName() });
5512
5513 static {
5514 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
5515 }
5516
5517
5524 public int getUsersSize(long pk) throws SystemException {
5525 Object[] finderArgs = new Object[] { pk };
5526
5527 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
5528 finderArgs, this);
5529
5530 if (count == null) {
5531 Session session = null;
5532
5533 try {
5534 session = openSession();
5535
5536 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
5537
5538 q.addScalar(COUNT_COLUMN_NAME,
5539 com.liferay.portal.kernel.dao.orm.Type.LONG);
5540
5541 QueryPos qPos = QueryPos.getInstance(q);
5542
5543 qPos.add(pk);
5544
5545 count = (Long)q.uniqueResult();
5546
5547 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
5548 finderArgs, count);
5549 }
5550 catch (Exception e) {
5551 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS_SIZE,
5552 finderArgs);
5553
5554 throw processException(e);
5555 }
5556 finally {
5557 closeSession(session);
5558 }
5559 }
5560
5561 return count.intValue();
5562 }
5563
5564 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
5565 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES, Boolean.class,
5566 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "containsUser",
5567 new String[] { Long.class.getName(), Long.class.getName() });
5568
5569
5577 public boolean containsUser(long pk, long userPK) throws SystemException {
5578 Object[] finderArgs = new Object[] { pk, userPK };
5579
5580 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
5581 finderArgs, this);
5582
5583 if (value == null) {
5584 try {
5585 value = Boolean.valueOf(containsUser.contains(pk, userPK));
5586
5587 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
5588 finderArgs, value);
5589 }
5590 catch (Exception e) {
5591 FinderCacheUtil.removeResult(FINDER_PATH_CONTAINS_USER,
5592 finderArgs);
5593
5594 throw processException(e);
5595 }
5596 }
5597
5598 return value.booleanValue();
5599 }
5600
5601
5608 public boolean containsUsers(long pk) throws SystemException {
5609 if (getUsersSize(pk) > 0) {
5610 return true;
5611 }
5612 else {
5613 return false;
5614 }
5615 }
5616
5617
5624 public void addUser(long pk, long userPK) throws SystemException {
5625 try {
5626 addUser.add(pk, userPK);
5627 }
5628 catch (Exception e) {
5629 throw processException(e);
5630 }
5631 finally {
5632 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5633 }
5634 }
5635
5636
5643 public void addUser(long pk, com.liferay.portal.model.User user)
5644 throws SystemException {
5645 try {
5646 addUser.add(pk, user.getPrimaryKey());
5647 }
5648 catch (Exception e) {
5649 throw processException(e);
5650 }
5651 finally {
5652 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5653 }
5654 }
5655
5656
5663 public void addUsers(long pk, long[] userPKs) throws SystemException {
5664 try {
5665 for (long userPK : userPKs) {
5666 addUser.add(pk, userPK);
5667 }
5668 }
5669 catch (Exception e) {
5670 throw processException(e);
5671 }
5672 finally {
5673 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5674 }
5675 }
5676
5677
5684 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
5685 throws SystemException {
5686 try {
5687 for (com.liferay.portal.model.User user : users) {
5688 addUser.add(pk, user.getPrimaryKey());
5689 }
5690 }
5691 catch (Exception e) {
5692 throw processException(e);
5693 }
5694 finally {
5695 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5696 }
5697 }
5698
5699
5705 public void clearUsers(long pk) throws SystemException {
5706 try {
5707 clearUsers.clear(pk);
5708 }
5709 catch (Exception e) {
5710 throw processException(e);
5711 }
5712 finally {
5713 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5714 }
5715 }
5716
5717
5724 public void removeUser(long pk, long userPK) throws SystemException {
5725 try {
5726 removeUser.remove(pk, userPK);
5727 }
5728 catch (Exception e) {
5729 throw processException(e);
5730 }
5731 finally {
5732 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5733 }
5734 }
5735
5736
5743 public void removeUser(long pk, com.liferay.portal.model.User user)
5744 throws SystemException {
5745 try {
5746 removeUser.remove(pk, user.getPrimaryKey());
5747 }
5748 catch (Exception e) {
5749 throw processException(e);
5750 }
5751 finally {
5752 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5753 }
5754 }
5755
5756
5763 public void removeUsers(long pk, long[] userPKs) throws SystemException {
5764 try {
5765 for (long userPK : userPKs) {
5766 removeUser.remove(pk, userPK);
5767 }
5768 }
5769 catch (Exception e) {
5770 throw processException(e);
5771 }
5772 finally {
5773 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5774 }
5775 }
5776
5777
5784 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
5785 throws SystemException {
5786 try {
5787 for (com.liferay.portal.model.User user : users) {
5788 removeUser.remove(pk, user.getPrimaryKey());
5789 }
5790 }
5791 catch (Exception e) {
5792 throw processException(e);
5793 }
5794 finally {
5795 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5796 }
5797 }
5798
5799
5806 public void setUsers(long pk, long[] userPKs) throws SystemException {
5807 try {
5808 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
5809
5810 List<com.liferay.portal.model.User> users = getUsers(pk);
5811
5812 for (com.liferay.portal.model.User user : users) {
5813 if (!userPKSet.remove(user.getPrimaryKey())) {
5814 removeUser.remove(pk, user.getPrimaryKey());
5815 }
5816 }
5817
5818 for (Long userPK : userPKSet) {
5819 addUser.add(pk, userPK);
5820 }
5821 }
5822 catch (Exception e) {
5823 throw processException(e);
5824 }
5825 finally {
5826 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5827 }
5828 }
5829
5830
5837 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
5838 throws SystemException {
5839 try {
5840 long[] userPKs = new long[users.size()];
5841
5842 for (int i = 0; i < users.size(); i++) {
5843 com.liferay.portal.model.User user = users.get(i);
5844
5845 userPKs[i] = user.getPrimaryKey();
5846 }
5847
5848 setUsers(pk, userPKs);
5849 }
5850 catch (Exception e) {
5851 throw processException(e);
5852 }
5853 finally {
5854 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
5855 }
5856 }
5857
5858
5861 public void afterPropertiesSet() {
5862 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
5863 com.liferay.portal.util.PropsUtil.get(
5864 "value.object.listener.com.liferay.portal.model.Role")));
5865
5866 if (listenerClassNames.length > 0) {
5867 try {
5868 List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
5869
5870 for (String listenerClassName : listenerClassNames) {
5871 listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
5872 listenerClassName));
5873 }
5874
5875 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
5876 }
5877 catch (Exception e) {
5878 _log.error(e);
5879 }
5880 }
5881
5882 containsGroup = new ContainsGroup();
5883
5884 addGroup = new AddGroup();
5885 clearGroups = new ClearGroups();
5886 removeGroup = new RemoveGroup();
5887
5888 containsUser = new ContainsUser();
5889
5890 addUser = new AddUser();
5891 clearUsers = new ClearUsers();
5892 removeUser = new RemoveUser();
5893 }
5894
5895 public void destroy() {
5896 EntityCacheUtil.removeCache(RoleImpl.class.getName());
5897 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
5898 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
5899 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
5900 }
5901
5902 @BeanReference(type = GroupPersistence.class)
5903 protected GroupPersistence groupPersistence;
5904 protected ContainsGroup containsGroup;
5905 protected AddGroup addGroup;
5906 protected ClearGroups clearGroups;
5907 protected RemoveGroup removeGroup;
5908 @BeanReference(type = UserPersistence.class)
5909 protected UserPersistence userPersistence;
5910 protected ContainsUser containsUser;
5911 protected AddUser addUser;
5912 protected ClearUsers clearUsers;
5913 protected RemoveUser removeUser;
5914
5915 protected class ContainsGroup {
5916 protected ContainsGroup() {
5917 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
5918 _SQL_CONTAINSGROUP,
5919 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
5920 RowMapper.COUNT);
5921 }
5922
5923 protected boolean contains(long roleId, long groupId) {
5924 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
5925 new Long(roleId), new Long(groupId)
5926 });
5927
5928 if (results.size() > 0) {
5929 Integer count = results.get(0);
5930
5931 if (count.intValue() > 0) {
5932 return true;
5933 }
5934 }
5935
5936 return false;
5937 }
5938
5939 private MappingSqlQuery<Integer> _mappingSqlQuery;
5940 }
5941
5942 protected class AddGroup {
5943 protected AddGroup() {
5944 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5945 "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
5946 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5947 }
5948
5949 protected void add(long roleId, long groupId) throws SystemException {
5950 if (!containsGroup.contains(roleId, groupId)) {
5951 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
5952
5953 for (ModelListener<Role> listener : listeners) {
5954 listener.onBeforeAddAssociation(roleId,
5955 com.liferay.portal.model.Group.class.getName(), groupId);
5956 }
5957
5958 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
5959 listener.onBeforeAddAssociation(groupId,
5960 Role.class.getName(), roleId);
5961 }
5962
5963 _sqlUpdate.update(new Object[] {
5964 new Long(roleId), new Long(groupId)
5965 });
5966
5967 for (ModelListener<Role> listener : listeners) {
5968 listener.onAfterAddAssociation(roleId,
5969 com.liferay.portal.model.Group.class.getName(), groupId);
5970 }
5971
5972 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
5973 listener.onAfterAddAssociation(groupId,
5974 Role.class.getName(), roleId);
5975 }
5976 }
5977 }
5978
5979 private SqlUpdate _sqlUpdate;
5980 }
5981
5982 protected class ClearGroups {
5983 protected ClearGroups() {
5984 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5985 "DELETE FROM Groups_Roles WHERE roleId = ?",
5986 new int[] { java.sql.Types.BIGINT });
5987 }
5988
5989 protected void clear(long roleId) throws SystemException {
5990 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
5991
5992 List<com.liferay.portal.model.Group> groups = null;
5993
5994 if ((listeners.length > 0) || (groupListeners.length > 0)) {
5995 groups = getGroups(roleId);
5996
5997 for (com.liferay.portal.model.Group group : groups) {
5998 for (ModelListener<Role> listener : listeners) {
5999 listener.onBeforeRemoveAssociation(roleId,
6000 com.liferay.portal.model.Group.class.getName(),
6001 group.getPrimaryKey());
6002 }
6003
6004 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6005 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
6006 Role.class.getName(), roleId);
6007 }
6008 }
6009 }
6010
6011 _sqlUpdate.update(new Object[] { new Long(roleId) });
6012
6013 if ((listeners.length > 0) || (groupListeners.length > 0)) {
6014 for (com.liferay.portal.model.Group group : groups) {
6015 for (ModelListener<Role> listener : listeners) {
6016 listener.onAfterRemoveAssociation(roleId,
6017 com.liferay.portal.model.Group.class.getName(),
6018 group.getPrimaryKey());
6019 }
6020
6021 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6022 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
6023 Role.class.getName(), roleId);
6024 }
6025 }
6026 }
6027 }
6028
6029 private SqlUpdate _sqlUpdate;
6030 }
6031
6032 protected class RemoveGroup {
6033 protected RemoveGroup() {
6034 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6035 "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
6036 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6037 }
6038
6039 protected void remove(long roleId, long groupId)
6040 throws SystemException {
6041 if (containsGroup.contains(roleId, groupId)) {
6042 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
6043
6044 for (ModelListener<Role> listener : listeners) {
6045 listener.onBeforeRemoveAssociation(roleId,
6046 com.liferay.portal.model.Group.class.getName(), groupId);
6047 }
6048
6049 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6050 listener.onBeforeRemoveAssociation(groupId,
6051 Role.class.getName(), roleId);
6052 }
6053
6054 _sqlUpdate.update(new Object[] {
6055 new Long(roleId), new Long(groupId)
6056 });
6057
6058 for (ModelListener<Role> listener : listeners) {
6059 listener.onAfterRemoveAssociation(roleId,
6060 com.liferay.portal.model.Group.class.getName(), groupId);
6061 }
6062
6063 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
6064 listener.onAfterRemoveAssociation(groupId,
6065 Role.class.getName(), roleId);
6066 }
6067 }
6068 }
6069
6070 private SqlUpdate _sqlUpdate;
6071 }
6072
6073 protected class ContainsUser {
6074 protected ContainsUser() {
6075 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
6076 _SQL_CONTAINSUSER,
6077 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
6078 RowMapper.COUNT);
6079 }
6080
6081 protected boolean contains(long roleId, long userId) {
6082 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
6083 new Long(roleId), new Long(userId)
6084 });
6085
6086 if (results.size() > 0) {
6087 Integer count = results.get(0);
6088
6089 if (count.intValue() > 0) {
6090 return true;
6091 }
6092 }
6093
6094 return false;
6095 }
6096
6097 private MappingSqlQuery<Integer> _mappingSqlQuery;
6098 }
6099
6100 protected class AddUser {
6101 protected AddUser() {
6102 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6103 "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
6104 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6105 }
6106
6107 protected void add(long roleId, long userId) throws SystemException {
6108 if (!containsUser.contains(roleId, userId)) {
6109 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6110
6111 for (ModelListener<Role> listener : listeners) {
6112 listener.onBeforeAddAssociation(roleId,
6113 com.liferay.portal.model.User.class.getName(), userId);
6114 }
6115
6116 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6117 listener.onBeforeAddAssociation(userId,
6118 Role.class.getName(), roleId);
6119 }
6120
6121 _sqlUpdate.update(new Object[] {
6122 new Long(roleId), new Long(userId)
6123 });
6124
6125 for (ModelListener<Role> listener : listeners) {
6126 listener.onAfterAddAssociation(roleId,
6127 com.liferay.portal.model.User.class.getName(), userId);
6128 }
6129
6130 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6131 listener.onAfterAddAssociation(userId,
6132 Role.class.getName(), roleId);
6133 }
6134 }
6135 }
6136
6137 private SqlUpdate _sqlUpdate;
6138 }
6139
6140 protected class ClearUsers {
6141 protected ClearUsers() {
6142 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6143 "DELETE FROM Users_Roles WHERE roleId = ?",
6144 new int[] { java.sql.Types.BIGINT });
6145 }
6146
6147 protected void clear(long roleId) throws SystemException {
6148 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6149
6150 List<com.liferay.portal.model.User> users = null;
6151
6152 if ((listeners.length > 0) || (userListeners.length > 0)) {
6153 users = getUsers(roleId);
6154
6155 for (com.liferay.portal.model.User user : users) {
6156 for (ModelListener<Role> listener : listeners) {
6157 listener.onBeforeRemoveAssociation(roleId,
6158 com.liferay.portal.model.User.class.getName(),
6159 user.getPrimaryKey());
6160 }
6161
6162 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6163 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
6164 Role.class.getName(), roleId);
6165 }
6166 }
6167 }
6168
6169 _sqlUpdate.update(new Object[] { new Long(roleId) });
6170
6171 if ((listeners.length > 0) || (userListeners.length > 0)) {
6172 for (com.liferay.portal.model.User user : users) {
6173 for (ModelListener<Role> listener : listeners) {
6174 listener.onAfterRemoveAssociation(roleId,
6175 com.liferay.portal.model.User.class.getName(),
6176 user.getPrimaryKey());
6177 }
6178
6179 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6180 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
6181 Role.class.getName(), roleId);
6182 }
6183 }
6184 }
6185 }
6186
6187 private SqlUpdate _sqlUpdate;
6188 }
6189
6190 protected class RemoveUser {
6191 protected RemoveUser() {
6192 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
6193 "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
6194 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
6195 }
6196
6197 protected void remove(long roleId, long userId)
6198 throws SystemException {
6199 if (containsUser.contains(roleId, userId)) {
6200 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
6201
6202 for (ModelListener<Role> listener : listeners) {
6203 listener.onBeforeRemoveAssociation(roleId,
6204 com.liferay.portal.model.User.class.getName(), userId);
6205 }
6206
6207 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6208 listener.onBeforeRemoveAssociation(userId,
6209 Role.class.getName(), roleId);
6210 }
6211
6212 _sqlUpdate.update(new Object[] {
6213 new Long(roleId), new Long(userId)
6214 });
6215
6216 for (ModelListener<Role> listener : listeners) {
6217 listener.onAfterRemoveAssociation(roleId,
6218 com.liferay.portal.model.User.class.getName(), userId);
6219 }
6220
6221 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
6222 listener.onAfterRemoveAssociation(userId,
6223 Role.class.getName(), roleId);
6224 }
6225 }
6226 }
6227
6228 private SqlUpdate _sqlUpdate;
6229 }
6230
6231 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
6232 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
6233 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
6234 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
6235 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
6236 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
6237 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
6238 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
6239 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
6240 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
6241 private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "role.roleId";
6242 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
6243 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
6244 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
6245 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
6246 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
6247 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
6248 private static final String _FILTER_ENTITY_ALIAS = "role";
6249 private static final String _FILTER_ENTITY_TABLE = "Role_";
6250 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
6251 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
6252 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
6253 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
6254 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
6255 private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
6256 private static Role _nullRole = new RoleImpl() {
6257 @Override
6258 public Object clone() {
6259 return this;
6260 }
6261
6262 @Override
6263 public CacheModel<Role> toCacheModel() {
6264 return _nullRoleCacheModel;
6265 }
6266 };
6267
6268 private static CacheModel<Role> _nullRoleCacheModel = new CacheModel<Role>() {
6269 public Role toEntityModel() {
6270 return _nullRole;
6271 }
6272 };
6273 }