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.annotation.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.Validator;
045 import com.liferay.portal.model.ModelListener;
046 import com.liferay.portal.model.Role;
047 import com.liferay.portal.model.impl.RoleImpl;
048 import com.liferay.portal.model.impl.RoleModelImpl;
049 import com.liferay.portal.security.permission.InlineSQLHelperUtil;
050 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.List;
057 import java.util.Set;
058
059
075 public class RolePersistenceImpl extends BasePersistenceImpl<Role>
076 implements RolePersistence {
077 public static final String FINDER_CLASS_NAME_ENTITY = RoleImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
079 ".List";
080 public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
081 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
082 "findByCompanyId",
083 new String[] {
084 Long.class.getName(),
085
086 "java.lang.Integer", "java.lang.Integer",
087 "com.liferay.portal.kernel.util.OrderByComparator"
088 });
089 public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
090 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
091 "countByCompanyId", new String[] { Long.class.getName() });
092 public static final FinderPath FINDER_PATH_FIND_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
093 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
094 "findBySubtype",
095 new String[] {
096 String.class.getName(),
097
098 "java.lang.Integer", "java.lang.Integer",
099 "com.liferay.portal.kernel.util.OrderByComparator"
100 });
101 public static final FinderPath FINDER_PATH_COUNT_BY_SUBTYPE = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
102 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "countBySubtype", new String[] { String.class.getName() });
104 public static final FinderPath FINDER_PATH_FETCH_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
105 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
106 "fetchByC_N",
107 new String[] { Long.class.getName(), String.class.getName() });
108 public static final FinderPath FINDER_PATH_COUNT_BY_C_N = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
109 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
110 "countByC_N",
111 new String[] { Long.class.getName(), String.class.getName() });
112 public static final FinderPath FINDER_PATH_FIND_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
113 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
114 "findByT_S",
115 new String[] {
116 Integer.class.getName(), String.class.getName(),
117
118 "java.lang.Integer", "java.lang.Integer",
119 "com.liferay.portal.kernel.util.OrderByComparator"
120 });
121 public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
122 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123 "countByT_S",
124 new String[] { Integer.class.getName(), String.class.getName() });
125 public static final FinderPath FINDER_PATH_FETCH_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
126 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
127 "fetchByC_C_C",
128 new String[] {
129 Long.class.getName(), Long.class.getName(), Long.class.getName()
130 });
131 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_C = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
132 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
133 "countByC_C_C",
134 new String[] {
135 Long.class.getName(), Long.class.getName(), Long.class.getName()
136 });
137 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
138 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
139 "findAll", new String[0]);
140 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RoleModelImpl.ENTITY_CACHE_ENABLED,
141 RoleModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
142 "countAll", new String[0]);
143
144
149 public void cacheResult(Role role) {
150 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
151 RoleImpl.class, role.getPrimaryKey(), role);
152
153 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
154 new Object[] { new Long(role.getCompanyId()), role.getName() }, role);
155
156 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
157 new Object[] {
158 new Long(role.getCompanyId()), new Long(role.getClassNameId()),
159 new Long(role.getClassPK())
160 }, role);
161 }
162
163
168 public void cacheResult(List<Role> roles) {
169 for (Role role : roles) {
170 if (EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
171 RoleImpl.class, role.getPrimaryKey(), this) == null) {
172 cacheResult(role);
173 }
174 }
175 }
176
177
184 public void clearCache() {
185 CacheRegistryUtil.clear(RoleImpl.class.getName());
186 EntityCacheUtil.clearCache(RoleImpl.class.getName());
187 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
188 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
189 }
190
191
198 public void clearCache(Role role) {
199 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
200 RoleImpl.class, role.getPrimaryKey());
201
202 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
203 new Object[] { new Long(role.getCompanyId()), role.getName() });
204
205 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
206 new Object[] {
207 new Long(role.getCompanyId()), new Long(role.getClassNameId()),
208 new Long(role.getClassPK())
209 });
210 }
211
212
218 public Role create(long roleId) {
219 Role role = new RoleImpl();
220
221 role.setNew(true);
222 role.setPrimaryKey(roleId);
223
224 return role;
225 }
226
227
235 public Role remove(Serializable primaryKey)
236 throws NoSuchModelException, SystemException {
237 return remove(((Long)primaryKey).longValue());
238 }
239
240
248 public Role remove(long roleId) throws NoSuchRoleException, SystemException {
249 Session session = null;
250
251 try {
252 session = openSession();
253
254 Role role = (Role)session.get(RoleImpl.class, new Long(roleId));
255
256 if (role == null) {
257 if (_log.isWarnEnabled()) {
258 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + roleId);
259 }
260
261 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
262 roleId);
263 }
264
265 return remove(role);
266 }
267 catch (NoSuchRoleException nsee) {
268 throw nsee;
269 }
270 catch (Exception e) {
271 throw processException(e);
272 }
273 finally {
274 closeSession(session);
275 }
276 }
277
278 protected Role removeImpl(Role role) throws SystemException {
279 role = toUnwrappedModel(role);
280
281 try {
282 clearGroups.clear(role.getPrimaryKey());
283 }
284 catch (Exception e) {
285 throw processException(e);
286 }
287 finally {
288 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
289 }
290
291 try {
292 clearPermissions.clear(role.getPrimaryKey());
293 }
294 catch (Exception e) {
295 throw processException(e);
296 }
297 finally {
298 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
299 }
300
301 try {
302 clearUsers.clear(role.getPrimaryKey());
303 }
304 catch (Exception e) {
305 throw processException(e);
306 }
307 finally {
308 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
309 }
310
311 Session session = null;
312
313 try {
314 session = openSession();
315
316 BatchSessionUtil.delete(session, role);
317 }
318 catch (Exception e) {
319 throw processException(e);
320 }
321 finally {
322 closeSession(session);
323 }
324
325 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
326
327 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
328
329 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
330 new Object[] {
331 new Long(roleModelImpl.getCompanyId()),
332
333 roleModelImpl.getName()
334 });
335
336 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
337 new Object[] {
338 new Long(roleModelImpl.getCompanyId()),
339 new Long(roleModelImpl.getClassNameId()),
340 new Long(roleModelImpl.getClassPK())
341 });
342
343 EntityCacheUtil.removeResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
344 RoleImpl.class, role.getPrimaryKey());
345
346 return role;
347 }
348
349 public Role updateImpl(com.liferay.portal.model.Role role, boolean merge)
350 throws SystemException {
351 role = toUnwrappedModel(role);
352
353 boolean isNew = role.isNew();
354
355 RoleModelImpl roleModelImpl = (RoleModelImpl)role;
356
357 Session session = null;
358
359 try {
360 session = openSession();
361
362 BatchSessionUtil.update(session, role, merge);
363
364 role.setNew(false);
365 }
366 catch (Exception e) {
367 throw processException(e);
368 }
369 finally {
370 closeSession(session);
371 }
372
373 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
374
375 EntityCacheUtil.putResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
376 RoleImpl.class, role.getPrimaryKey(), role);
377
378 if (!isNew &&
379 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
380 !Validator.equals(role.getName(),
381 roleModelImpl.getOriginalName()))) {
382 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
383 new Object[] {
384 new Long(roleModelImpl.getOriginalCompanyId()),
385
386 roleModelImpl.getOriginalName()
387 });
388 }
389
390 if (isNew ||
391 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
392 !Validator.equals(role.getName(),
393 roleModelImpl.getOriginalName()))) {
394 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
395 new Object[] { new Long(role.getCompanyId()), role.getName() },
396 role);
397 }
398
399 if (!isNew &&
400 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
401 (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
402 (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
403 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
404 new Object[] {
405 new Long(roleModelImpl.getOriginalCompanyId()),
406 new Long(roleModelImpl.getOriginalClassNameId()),
407 new Long(roleModelImpl.getOriginalClassPK())
408 });
409 }
410
411 if (isNew ||
412 ((role.getCompanyId() != roleModelImpl.getOriginalCompanyId()) ||
413 (role.getClassNameId() != roleModelImpl.getOriginalClassNameId()) ||
414 (role.getClassPK() != roleModelImpl.getOriginalClassPK()))) {
415 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
416 new Object[] {
417 new Long(role.getCompanyId()),
418 new Long(role.getClassNameId()), new Long(role.getClassPK())
419 }, role);
420 }
421
422 return role;
423 }
424
425 protected Role toUnwrappedModel(Role role) {
426 if (role instanceof RoleImpl) {
427 return role;
428 }
429
430 RoleImpl roleImpl = new RoleImpl();
431
432 roleImpl.setNew(role.isNew());
433 roleImpl.setPrimaryKey(role.getPrimaryKey());
434
435 roleImpl.setRoleId(role.getRoleId());
436 roleImpl.setCompanyId(role.getCompanyId());
437 roleImpl.setClassNameId(role.getClassNameId());
438 roleImpl.setClassPK(role.getClassPK());
439 roleImpl.setName(role.getName());
440 roleImpl.setTitle(role.getTitle());
441 roleImpl.setDescription(role.getDescription());
442 roleImpl.setType(role.getType());
443 roleImpl.setSubtype(role.getSubtype());
444
445 return roleImpl;
446 }
447
448
456 public Role findByPrimaryKey(Serializable primaryKey)
457 throws NoSuchModelException, SystemException {
458 return findByPrimaryKey(((Long)primaryKey).longValue());
459 }
460
461
469 public Role findByPrimaryKey(long roleId)
470 throws NoSuchRoleException, SystemException {
471 Role role = fetchByPrimaryKey(roleId);
472
473 if (role == null) {
474 if (_log.isWarnEnabled()) {
475 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + roleId);
476 }
477
478 throw new NoSuchRoleException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
479 roleId);
480 }
481
482 return role;
483 }
484
485
492 public Role fetchByPrimaryKey(Serializable primaryKey)
493 throws SystemException {
494 return fetchByPrimaryKey(((Long)primaryKey).longValue());
495 }
496
497
504 public Role fetchByPrimaryKey(long roleId) throws SystemException {
505 Role role = (Role)EntityCacheUtil.getResult(RoleModelImpl.ENTITY_CACHE_ENABLED,
506 RoleImpl.class, roleId, this);
507
508 if (role == null) {
509 Session session = null;
510
511 try {
512 session = openSession();
513
514 role = (Role)session.get(RoleImpl.class, new Long(roleId));
515 }
516 catch (Exception e) {
517 throw processException(e);
518 }
519 finally {
520 if (role != null) {
521 cacheResult(role);
522 }
523
524 closeSession(session);
525 }
526 }
527
528 return role;
529 }
530
531
538 public List<Role> findByCompanyId(long companyId) throws SystemException {
539 return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
540 null);
541 }
542
543
556 public List<Role> findByCompanyId(long companyId, int start, int end)
557 throws SystemException {
558 return findByCompanyId(companyId, start, end, null);
559 }
560
561
575 public List<Role> findByCompanyId(long companyId, int start, int end,
576 OrderByComparator orderByComparator) throws SystemException {
577 Object[] finderArgs = new Object[] {
578 companyId,
579
580 String.valueOf(start), String.valueOf(end),
581 String.valueOf(orderByComparator)
582 };
583
584 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
585 finderArgs, this);
586
587 if (list == null) {
588 StringBundler query = null;
589
590 if (orderByComparator != null) {
591 query = new StringBundler(3 +
592 (orderByComparator.getOrderByFields().length * 3));
593 }
594 else {
595 query = new StringBundler(3);
596 }
597
598 query.append(_SQL_SELECT_ROLE_WHERE);
599
600 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
601
602 if (orderByComparator != null) {
603 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
604 orderByComparator);
605 }
606
607 else {
608 query.append(RoleModelImpl.ORDER_BY_JPQL);
609 }
610
611 String sql = query.toString();
612
613 Session session = null;
614
615 try {
616 session = openSession();
617
618 Query q = session.createQuery(sql);
619
620 QueryPos qPos = QueryPos.getInstance(q);
621
622 qPos.add(companyId);
623
624 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
625 }
626 catch (Exception e) {
627 throw processException(e);
628 }
629 finally {
630 if (list == null) {
631 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
632 finderArgs);
633 }
634 else {
635 cacheResult(list);
636
637 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
638 finderArgs, list);
639 }
640
641 closeSession(session);
642 }
643 }
644
645 return list;
646 }
647
648
661 public Role findByCompanyId_First(long companyId,
662 OrderByComparator orderByComparator)
663 throws NoSuchRoleException, SystemException {
664 List<Role> list = findByCompanyId(companyId, 0, 1, orderByComparator);
665
666 if (list.isEmpty()) {
667 StringBundler msg = new StringBundler(4);
668
669 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
670
671 msg.append("companyId=");
672 msg.append(companyId);
673
674 msg.append(StringPool.CLOSE_CURLY_BRACE);
675
676 throw new NoSuchRoleException(msg.toString());
677 }
678 else {
679 return list.get(0);
680 }
681 }
682
683
696 public Role findByCompanyId_Last(long companyId,
697 OrderByComparator orderByComparator)
698 throws NoSuchRoleException, SystemException {
699 int count = countByCompanyId(companyId);
700
701 List<Role> list = findByCompanyId(companyId, count - 1, count,
702 orderByComparator);
703
704 if (list.isEmpty()) {
705 StringBundler msg = new StringBundler(4);
706
707 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
708
709 msg.append("companyId=");
710 msg.append(companyId);
711
712 msg.append(StringPool.CLOSE_CURLY_BRACE);
713
714 throw new NoSuchRoleException(msg.toString());
715 }
716 else {
717 return list.get(0);
718 }
719 }
720
721
735 public Role[] findByCompanyId_PrevAndNext(long roleId, long companyId,
736 OrderByComparator orderByComparator)
737 throws NoSuchRoleException, SystemException {
738 Role role = findByPrimaryKey(roleId);
739
740 Session session = null;
741
742 try {
743 session = openSession();
744
745 Role[] array = new RoleImpl[3];
746
747 array[0] = getByCompanyId_PrevAndNext(session, role, companyId,
748 orderByComparator, true);
749
750 array[1] = role;
751
752 array[2] = getByCompanyId_PrevAndNext(session, role, companyId,
753 orderByComparator, false);
754
755 return array;
756 }
757 catch (Exception e) {
758 throw processException(e);
759 }
760 finally {
761 closeSession(session);
762 }
763 }
764
765 protected Role getByCompanyId_PrevAndNext(Session session, Role role,
766 long companyId, OrderByComparator orderByComparator, boolean previous) {
767 StringBundler query = null;
768
769 if (orderByComparator != null) {
770 query = new StringBundler(6 +
771 (orderByComparator.getOrderByFields().length * 6));
772 }
773 else {
774 query = new StringBundler(3);
775 }
776
777 query.append(_SQL_SELECT_ROLE_WHERE);
778
779 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
780
781 if (orderByComparator != null) {
782 String[] orderByFields = orderByComparator.getOrderByFields();
783
784 if (orderByFields.length > 0) {
785 query.append(WHERE_AND);
786 }
787
788 for (int i = 0; i < orderByFields.length; i++) {
789 query.append(_ORDER_BY_ENTITY_ALIAS);
790 query.append(orderByFields[i]);
791
792 if ((i + 1) < orderByFields.length) {
793 if (orderByComparator.isAscending() ^ previous) {
794 query.append(WHERE_GREATER_THAN_HAS_NEXT);
795 }
796 else {
797 query.append(WHERE_LESSER_THAN_HAS_NEXT);
798 }
799 }
800 else {
801 if (orderByComparator.isAscending() ^ previous) {
802 query.append(WHERE_GREATER_THAN);
803 }
804 else {
805 query.append(WHERE_LESSER_THAN);
806 }
807 }
808 }
809
810 query.append(ORDER_BY_CLAUSE);
811
812 for (int i = 0; i < orderByFields.length; i++) {
813 query.append(_ORDER_BY_ENTITY_ALIAS);
814 query.append(orderByFields[i]);
815
816 if ((i + 1) < orderByFields.length) {
817 if (orderByComparator.isAscending() ^ previous) {
818 query.append(ORDER_BY_ASC_HAS_NEXT);
819 }
820 else {
821 query.append(ORDER_BY_DESC_HAS_NEXT);
822 }
823 }
824 else {
825 if (orderByComparator.isAscending() ^ previous) {
826 query.append(ORDER_BY_ASC);
827 }
828 else {
829 query.append(ORDER_BY_DESC);
830 }
831 }
832 }
833 }
834
835 else {
836 query.append(RoleModelImpl.ORDER_BY_JPQL);
837 }
838
839 String sql = query.toString();
840
841 Query q = session.createQuery(sql);
842
843 q.setFirstResult(0);
844 q.setMaxResults(2);
845
846 QueryPos qPos = QueryPos.getInstance(q);
847
848 qPos.add(companyId);
849
850 if (orderByComparator != null) {
851 Object[] values = orderByComparator.getOrderByValues(role);
852
853 for (Object value : values) {
854 qPos.add(value);
855 }
856 }
857
858 List<Role> list = q.list();
859
860 if (list.size() == 2) {
861 return list.get(1);
862 }
863 else {
864 return null;
865 }
866 }
867
868
875 public List<Role> filterFindByCompanyId(long companyId)
876 throws SystemException {
877 return filterFindByCompanyId(companyId, QueryUtil.ALL_POS,
878 QueryUtil.ALL_POS, null);
879 }
880
881
894 public List<Role> filterFindByCompanyId(long companyId, int start, int end)
895 throws SystemException {
896 return filterFindByCompanyId(companyId, start, end, null);
897 }
898
899
913 public List<Role> filterFindByCompanyId(long companyId, int start, int end,
914 OrderByComparator orderByComparator) throws SystemException {
915 if (!InlineSQLHelperUtil.isEnabled()) {
916 return findByCompanyId(companyId, start, end, orderByComparator);
917 }
918
919 StringBundler query = null;
920
921 if (orderByComparator != null) {
922 query = new StringBundler(3 +
923 (orderByComparator.getOrderByFields().length * 3));
924 }
925 else {
926 query = new StringBundler(3);
927 }
928
929 if (getDB().isSupportsInlineDistinct()) {
930 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
931 }
932 else {
933 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
934 }
935
936 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
937
938 if (!getDB().isSupportsInlineDistinct()) {
939 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
940 }
941
942 if (orderByComparator != null) {
943 if (getDB().isSupportsInlineDistinct()) {
944 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
945 orderByComparator);
946 }
947 else {
948 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
949 orderByComparator);
950 }
951 }
952
953 else {
954 if (getDB().isSupportsInlineDistinct()) {
955 query.append(RoleModelImpl.ORDER_BY_JPQL);
956 }
957 else {
958 query.append(RoleModelImpl.ORDER_BY_SQL);
959 }
960 }
961
962 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
963 Role.class.getName(), _FILTER_COLUMN_PK, _FILTER_COLUMN_USERID);
964
965 Session session = null;
966
967 try {
968 session = openSession();
969
970 SQLQuery q = session.createSQLQuery(sql);
971
972 if (getDB().isSupportsInlineDistinct()) {
973 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
974 }
975 else {
976 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
977 }
978
979 QueryPos qPos = QueryPos.getInstance(q);
980
981 qPos.add(companyId);
982
983 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
984 }
985 catch (Exception e) {
986 throw processException(e);
987 }
988 finally {
989 closeSession(session);
990 }
991 }
992
993
1000 public List<Role> findBySubtype(String subtype) throws SystemException {
1001 return findBySubtype(subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1002 }
1003
1004
1017 public List<Role> findBySubtype(String subtype, int start, int end)
1018 throws SystemException {
1019 return findBySubtype(subtype, start, end, null);
1020 }
1021
1022
1036 public List<Role> findBySubtype(String subtype, int start, int end,
1037 OrderByComparator orderByComparator) throws SystemException {
1038 Object[] finderArgs = new Object[] {
1039 subtype,
1040
1041 String.valueOf(start), String.valueOf(end),
1042 String.valueOf(orderByComparator)
1043 };
1044
1045 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_SUBTYPE,
1046 finderArgs, this);
1047
1048 if (list == null) {
1049 StringBundler query = null;
1050
1051 if (orderByComparator != null) {
1052 query = new StringBundler(3 +
1053 (orderByComparator.getOrderByFields().length * 3));
1054 }
1055 else {
1056 query = new StringBundler(3);
1057 }
1058
1059 query.append(_SQL_SELECT_ROLE_WHERE);
1060
1061 if (subtype == null) {
1062 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
1063 }
1064 else {
1065 if (subtype.equals(StringPool.BLANK)) {
1066 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
1067 }
1068 else {
1069 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
1070 }
1071 }
1072
1073 if (orderByComparator != null) {
1074 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1075 orderByComparator);
1076 }
1077
1078 else {
1079 query.append(RoleModelImpl.ORDER_BY_JPQL);
1080 }
1081
1082 String sql = query.toString();
1083
1084 Session session = null;
1085
1086 try {
1087 session = openSession();
1088
1089 Query q = session.createQuery(sql);
1090
1091 QueryPos qPos = QueryPos.getInstance(q);
1092
1093 if (subtype != null) {
1094 qPos.add(subtype);
1095 }
1096
1097 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1098 }
1099 catch (Exception e) {
1100 throw processException(e);
1101 }
1102 finally {
1103 if (list == null) {
1104 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_SUBTYPE,
1105 finderArgs);
1106 }
1107 else {
1108 cacheResult(list);
1109
1110 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_SUBTYPE,
1111 finderArgs, list);
1112 }
1113
1114 closeSession(session);
1115 }
1116 }
1117
1118 return list;
1119 }
1120
1121
1134 public Role findBySubtype_First(String subtype,
1135 OrderByComparator orderByComparator)
1136 throws NoSuchRoleException, SystemException {
1137 List<Role> list = findBySubtype(subtype, 0, 1, orderByComparator);
1138
1139 if (list.isEmpty()) {
1140 StringBundler msg = new StringBundler(4);
1141
1142 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1143
1144 msg.append("subtype=");
1145 msg.append(subtype);
1146
1147 msg.append(StringPool.CLOSE_CURLY_BRACE);
1148
1149 throw new NoSuchRoleException(msg.toString());
1150 }
1151 else {
1152 return list.get(0);
1153 }
1154 }
1155
1156
1169 public Role findBySubtype_Last(String subtype,
1170 OrderByComparator orderByComparator)
1171 throws NoSuchRoleException, SystemException {
1172 int count = countBySubtype(subtype);
1173
1174 List<Role> list = findBySubtype(subtype, count - 1, count,
1175 orderByComparator);
1176
1177 if (list.isEmpty()) {
1178 StringBundler msg = new StringBundler(4);
1179
1180 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1181
1182 msg.append("subtype=");
1183 msg.append(subtype);
1184
1185 msg.append(StringPool.CLOSE_CURLY_BRACE);
1186
1187 throw new NoSuchRoleException(msg.toString());
1188 }
1189 else {
1190 return list.get(0);
1191 }
1192 }
1193
1194
1208 public Role[] findBySubtype_PrevAndNext(long roleId, String subtype,
1209 OrderByComparator orderByComparator)
1210 throws NoSuchRoleException, SystemException {
1211 Role role = findByPrimaryKey(roleId);
1212
1213 Session session = null;
1214
1215 try {
1216 session = openSession();
1217
1218 Role[] array = new RoleImpl[3];
1219
1220 array[0] = getBySubtype_PrevAndNext(session, role, subtype,
1221 orderByComparator, true);
1222
1223 array[1] = role;
1224
1225 array[2] = getBySubtype_PrevAndNext(session, role, subtype,
1226 orderByComparator, false);
1227
1228 return array;
1229 }
1230 catch (Exception e) {
1231 throw processException(e);
1232 }
1233 finally {
1234 closeSession(session);
1235 }
1236 }
1237
1238 protected Role getBySubtype_PrevAndNext(Session session, Role role,
1239 String subtype, OrderByComparator orderByComparator, boolean previous) {
1240 StringBundler query = null;
1241
1242 if (orderByComparator != null) {
1243 query = new StringBundler(6 +
1244 (orderByComparator.getOrderByFields().length * 6));
1245 }
1246 else {
1247 query = new StringBundler(3);
1248 }
1249
1250 query.append(_SQL_SELECT_ROLE_WHERE);
1251
1252 if (subtype == null) {
1253 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
1254 }
1255 else {
1256 if (subtype.equals(StringPool.BLANK)) {
1257 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
1258 }
1259 else {
1260 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
1261 }
1262 }
1263
1264 if (orderByComparator != null) {
1265 String[] orderByFields = orderByComparator.getOrderByFields();
1266
1267 if (orderByFields.length > 0) {
1268 query.append(WHERE_AND);
1269 }
1270
1271 for (int i = 0; i < orderByFields.length; i++) {
1272 query.append(_ORDER_BY_ENTITY_ALIAS);
1273 query.append(orderByFields[i]);
1274
1275 if ((i + 1) < orderByFields.length) {
1276 if (orderByComparator.isAscending() ^ previous) {
1277 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1278 }
1279 else {
1280 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1281 }
1282 }
1283 else {
1284 if (orderByComparator.isAscending() ^ previous) {
1285 query.append(WHERE_GREATER_THAN);
1286 }
1287 else {
1288 query.append(WHERE_LESSER_THAN);
1289 }
1290 }
1291 }
1292
1293 query.append(ORDER_BY_CLAUSE);
1294
1295 for (int i = 0; i < orderByFields.length; i++) {
1296 query.append(_ORDER_BY_ENTITY_ALIAS);
1297 query.append(orderByFields[i]);
1298
1299 if ((i + 1) < orderByFields.length) {
1300 if (orderByComparator.isAscending() ^ previous) {
1301 query.append(ORDER_BY_ASC_HAS_NEXT);
1302 }
1303 else {
1304 query.append(ORDER_BY_DESC_HAS_NEXT);
1305 }
1306 }
1307 else {
1308 if (orderByComparator.isAscending() ^ previous) {
1309 query.append(ORDER_BY_ASC);
1310 }
1311 else {
1312 query.append(ORDER_BY_DESC);
1313 }
1314 }
1315 }
1316 }
1317
1318 else {
1319 query.append(RoleModelImpl.ORDER_BY_JPQL);
1320 }
1321
1322 String sql = query.toString();
1323
1324 Query q = session.createQuery(sql);
1325
1326 q.setFirstResult(0);
1327 q.setMaxResults(2);
1328
1329 QueryPos qPos = QueryPos.getInstance(q);
1330
1331 if (subtype != null) {
1332 qPos.add(subtype);
1333 }
1334
1335 if (orderByComparator != null) {
1336 Object[] values = orderByComparator.getOrderByValues(role);
1337
1338 for (Object value : values) {
1339 qPos.add(value);
1340 }
1341 }
1342
1343 List<Role> list = q.list();
1344
1345 if (list.size() == 2) {
1346 return list.get(1);
1347 }
1348 else {
1349 return null;
1350 }
1351 }
1352
1353
1360 public List<Role> filterFindBySubtype(String subtype)
1361 throws SystemException {
1362 return filterFindBySubtype(subtype, QueryUtil.ALL_POS,
1363 QueryUtil.ALL_POS, null);
1364 }
1365
1366
1379 public List<Role> filterFindBySubtype(String subtype, int start, int end)
1380 throws SystemException {
1381 return filterFindBySubtype(subtype, start, end, null);
1382 }
1383
1384
1398 public List<Role> filterFindBySubtype(String subtype, int start, int end,
1399 OrderByComparator orderByComparator) throws SystemException {
1400 if (!InlineSQLHelperUtil.isEnabled()) {
1401 return findBySubtype(subtype, start, end, orderByComparator);
1402 }
1403
1404 StringBundler query = null;
1405
1406 if (orderByComparator != null) {
1407 query = new StringBundler(3 +
1408 (orderByComparator.getOrderByFields().length * 3));
1409 }
1410 else {
1411 query = new StringBundler(3);
1412 }
1413
1414 if (getDB().isSupportsInlineDistinct()) {
1415 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
1416 }
1417 else {
1418 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
1419 }
1420
1421 if (subtype == null) {
1422 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
1423 }
1424 else {
1425 if (subtype.equals(StringPool.BLANK)) {
1426 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
1427 }
1428 else {
1429 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
1430 }
1431 }
1432
1433 if (!getDB().isSupportsInlineDistinct()) {
1434 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
1435 }
1436
1437 if (orderByComparator != null) {
1438 if (getDB().isSupportsInlineDistinct()) {
1439 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1440 orderByComparator);
1441 }
1442 else {
1443 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1444 orderByComparator);
1445 }
1446 }
1447
1448 else {
1449 if (getDB().isSupportsInlineDistinct()) {
1450 query.append(RoleModelImpl.ORDER_BY_JPQL);
1451 }
1452 else {
1453 query.append(RoleModelImpl.ORDER_BY_SQL);
1454 }
1455 }
1456
1457 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1458 Role.class.getName(), _FILTER_COLUMN_PK, _FILTER_COLUMN_USERID);
1459
1460 Session session = null;
1461
1462 try {
1463 session = openSession();
1464
1465 SQLQuery q = session.createSQLQuery(sql);
1466
1467 if (getDB().isSupportsInlineDistinct()) {
1468 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
1469 }
1470 else {
1471 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
1472 }
1473
1474 QueryPos qPos = QueryPos.getInstance(q);
1475
1476 if (subtype != null) {
1477 qPos.add(subtype);
1478 }
1479
1480 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1481 }
1482 catch (Exception e) {
1483 throw processException(e);
1484 }
1485 finally {
1486 closeSession(session);
1487 }
1488 }
1489
1490
1499 public Role findByC_N(long companyId, String name)
1500 throws NoSuchRoleException, SystemException {
1501 Role role = fetchByC_N(companyId, name);
1502
1503 if (role == null) {
1504 StringBundler msg = new StringBundler(6);
1505
1506 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1507
1508 msg.append("companyId=");
1509 msg.append(companyId);
1510
1511 msg.append(", name=");
1512 msg.append(name);
1513
1514 msg.append(StringPool.CLOSE_CURLY_BRACE);
1515
1516 if (_log.isWarnEnabled()) {
1517 _log.warn(msg.toString());
1518 }
1519
1520 throw new NoSuchRoleException(msg.toString());
1521 }
1522
1523 return role;
1524 }
1525
1526
1534 public Role fetchByC_N(long companyId, String name)
1535 throws SystemException {
1536 return fetchByC_N(companyId, name, true);
1537 }
1538
1539
1547 public Role fetchByC_N(long companyId, String name,
1548 boolean retrieveFromCache) throws SystemException {
1549 Object[] finderArgs = new Object[] { companyId, name };
1550
1551 Object result = null;
1552
1553 if (retrieveFromCache) {
1554 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_N,
1555 finderArgs, this);
1556 }
1557
1558 if (result == null) {
1559 StringBundler query = new StringBundler(4);
1560
1561 query.append(_SQL_SELECT_ROLE_WHERE);
1562
1563 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
1564
1565 if (name == null) {
1566 query.append(_FINDER_COLUMN_C_N_NAME_1);
1567 }
1568 else {
1569 if (name.equals(StringPool.BLANK)) {
1570 query.append(_FINDER_COLUMN_C_N_NAME_3);
1571 }
1572 else {
1573 query.append(_FINDER_COLUMN_C_N_NAME_2);
1574 }
1575 }
1576
1577 query.append(RoleModelImpl.ORDER_BY_JPQL);
1578
1579 String sql = query.toString();
1580
1581 Session session = null;
1582
1583 try {
1584 session = openSession();
1585
1586 Query q = session.createQuery(sql);
1587
1588 QueryPos qPos = QueryPos.getInstance(q);
1589
1590 qPos.add(companyId);
1591
1592 if (name != null) {
1593 qPos.add(name);
1594 }
1595
1596 List<Role> list = q.list();
1597
1598 result = list;
1599
1600 Role role = null;
1601
1602 if (list.isEmpty()) {
1603 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1604 finderArgs, list);
1605 }
1606 else {
1607 role = list.get(0);
1608
1609 cacheResult(role);
1610
1611 if ((role.getCompanyId() != companyId) ||
1612 (role.getName() == null) ||
1613 !role.getName().equals(name)) {
1614 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_N,
1615 finderArgs, role);
1616 }
1617 }
1618
1619 return role;
1620 }
1621 catch (Exception e) {
1622 throw processException(e);
1623 }
1624 finally {
1625 if (result == null) {
1626 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_N,
1627 finderArgs);
1628 }
1629
1630 closeSession(session);
1631 }
1632 }
1633 else {
1634 if (result instanceof List<?>) {
1635 return null;
1636 }
1637 else {
1638 return (Role)result;
1639 }
1640 }
1641 }
1642
1643
1651 public List<Role> findByT_S(int type, String subtype)
1652 throws SystemException {
1653 return findByT_S(type, subtype, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1654 null);
1655 }
1656
1657
1671 public List<Role> findByT_S(int type, String subtype, int start, int end)
1672 throws SystemException {
1673 return findByT_S(type, subtype, start, end, null);
1674 }
1675
1676
1691 public List<Role> findByT_S(int type, String subtype, int start, int end,
1692 OrderByComparator orderByComparator) throws SystemException {
1693 Object[] finderArgs = new Object[] {
1694 type, subtype,
1695
1696 String.valueOf(start), String.valueOf(end),
1697 String.valueOf(orderByComparator)
1698 };
1699
1700 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_T_S,
1701 finderArgs, this);
1702
1703 if (list == null) {
1704 StringBundler query = null;
1705
1706 if (orderByComparator != null) {
1707 query = new StringBundler(4 +
1708 (orderByComparator.getOrderByFields().length * 3));
1709 }
1710 else {
1711 query = new StringBundler(4);
1712 }
1713
1714 query.append(_SQL_SELECT_ROLE_WHERE);
1715
1716 query.append(_FINDER_COLUMN_T_S_TYPE_2);
1717
1718 if (subtype == null) {
1719 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
1720 }
1721 else {
1722 if (subtype.equals(StringPool.BLANK)) {
1723 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
1724 }
1725 else {
1726 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
1727 }
1728 }
1729
1730 if (orderByComparator != null) {
1731 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1732 orderByComparator);
1733 }
1734
1735 else {
1736 query.append(RoleModelImpl.ORDER_BY_JPQL);
1737 }
1738
1739 String sql = query.toString();
1740
1741 Session session = null;
1742
1743 try {
1744 session = openSession();
1745
1746 Query q = session.createQuery(sql);
1747
1748 QueryPos qPos = QueryPos.getInstance(q);
1749
1750 qPos.add(type);
1751
1752 if (subtype != null) {
1753 qPos.add(subtype);
1754 }
1755
1756 list = (List<Role>)QueryUtil.list(q, getDialect(), start, end);
1757 }
1758 catch (Exception e) {
1759 throw processException(e);
1760 }
1761 finally {
1762 if (list == null) {
1763 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_T_S,
1764 finderArgs);
1765 }
1766 else {
1767 cacheResult(list);
1768
1769 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_T_S,
1770 finderArgs, list);
1771 }
1772
1773 closeSession(session);
1774 }
1775 }
1776
1777 return list;
1778 }
1779
1780
1794 public Role findByT_S_First(int type, String subtype,
1795 OrderByComparator orderByComparator)
1796 throws NoSuchRoleException, SystemException {
1797 List<Role> list = findByT_S(type, subtype, 0, 1, orderByComparator);
1798
1799 if (list.isEmpty()) {
1800 StringBundler msg = new StringBundler(6);
1801
1802 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1803
1804 msg.append("type=");
1805 msg.append(type);
1806
1807 msg.append(", subtype=");
1808 msg.append(subtype);
1809
1810 msg.append(StringPool.CLOSE_CURLY_BRACE);
1811
1812 throw new NoSuchRoleException(msg.toString());
1813 }
1814 else {
1815 return list.get(0);
1816 }
1817 }
1818
1819
1833 public Role findByT_S_Last(int type, String subtype,
1834 OrderByComparator orderByComparator)
1835 throws NoSuchRoleException, SystemException {
1836 int count = countByT_S(type, subtype);
1837
1838 List<Role> list = findByT_S(type, subtype, count - 1, count,
1839 orderByComparator);
1840
1841 if (list.isEmpty()) {
1842 StringBundler msg = new StringBundler(6);
1843
1844 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1845
1846 msg.append("type=");
1847 msg.append(type);
1848
1849 msg.append(", subtype=");
1850 msg.append(subtype);
1851
1852 msg.append(StringPool.CLOSE_CURLY_BRACE);
1853
1854 throw new NoSuchRoleException(msg.toString());
1855 }
1856 else {
1857 return list.get(0);
1858 }
1859 }
1860
1861
1876 public Role[] findByT_S_PrevAndNext(long roleId, int type, String subtype,
1877 OrderByComparator orderByComparator)
1878 throws NoSuchRoleException, SystemException {
1879 Role role = findByPrimaryKey(roleId);
1880
1881 Session session = null;
1882
1883 try {
1884 session = openSession();
1885
1886 Role[] array = new RoleImpl[3];
1887
1888 array[0] = getByT_S_PrevAndNext(session, role, type, subtype,
1889 orderByComparator, true);
1890
1891 array[1] = role;
1892
1893 array[2] = getByT_S_PrevAndNext(session, role, type, subtype,
1894 orderByComparator, false);
1895
1896 return array;
1897 }
1898 catch (Exception e) {
1899 throw processException(e);
1900 }
1901 finally {
1902 closeSession(session);
1903 }
1904 }
1905
1906 protected Role getByT_S_PrevAndNext(Session session, Role role, int type,
1907 String subtype, OrderByComparator orderByComparator, boolean previous) {
1908 StringBundler query = null;
1909
1910 if (orderByComparator != null) {
1911 query = new StringBundler(6 +
1912 (orderByComparator.getOrderByFields().length * 6));
1913 }
1914 else {
1915 query = new StringBundler(3);
1916 }
1917
1918 query.append(_SQL_SELECT_ROLE_WHERE);
1919
1920 query.append(_FINDER_COLUMN_T_S_TYPE_2);
1921
1922 if (subtype == null) {
1923 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
1924 }
1925 else {
1926 if (subtype.equals(StringPool.BLANK)) {
1927 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
1928 }
1929 else {
1930 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
1931 }
1932 }
1933
1934 if (orderByComparator != null) {
1935 String[] orderByFields = orderByComparator.getOrderByFields();
1936
1937 if (orderByFields.length > 0) {
1938 query.append(WHERE_AND);
1939 }
1940
1941 for (int i = 0; i < orderByFields.length; i++) {
1942 query.append(_ORDER_BY_ENTITY_ALIAS);
1943 query.append(orderByFields[i]);
1944
1945 if ((i + 1) < orderByFields.length) {
1946 if (orderByComparator.isAscending() ^ previous) {
1947 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1948 }
1949 else {
1950 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1951 }
1952 }
1953 else {
1954 if (orderByComparator.isAscending() ^ previous) {
1955 query.append(WHERE_GREATER_THAN);
1956 }
1957 else {
1958 query.append(WHERE_LESSER_THAN);
1959 }
1960 }
1961 }
1962
1963 query.append(ORDER_BY_CLAUSE);
1964
1965 for (int i = 0; i < orderByFields.length; i++) {
1966 query.append(_ORDER_BY_ENTITY_ALIAS);
1967 query.append(orderByFields[i]);
1968
1969 if ((i + 1) < orderByFields.length) {
1970 if (orderByComparator.isAscending() ^ previous) {
1971 query.append(ORDER_BY_ASC_HAS_NEXT);
1972 }
1973 else {
1974 query.append(ORDER_BY_DESC_HAS_NEXT);
1975 }
1976 }
1977 else {
1978 if (orderByComparator.isAscending() ^ previous) {
1979 query.append(ORDER_BY_ASC);
1980 }
1981 else {
1982 query.append(ORDER_BY_DESC);
1983 }
1984 }
1985 }
1986 }
1987
1988 else {
1989 query.append(RoleModelImpl.ORDER_BY_JPQL);
1990 }
1991
1992 String sql = query.toString();
1993
1994 Query q = session.createQuery(sql);
1995
1996 q.setFirstResult(0);
1997 q.setMaxResults(2);
1998
1999 QueryPos qPos = QueryPos.getInstance(q);
2000
2001 qPos.add(type);
2002
2003 if (subtype != null) {
2004 qPos.add(subtype);
2005 }
2006
2007 if (orderByComparator != null) {
2008 Object[] values = orderByComparator.getOrderByValues(role);
2009
2010 for (Object value : values) {
2011 qPos.add(value);
2012 }
2013 }
2014
2015 List<Role> list = q.list();
2016
2017 if (list.size() == 2) {
2018 return list.get(1);
2019 }
2020 else {
2021 return null;
2022 }
2023 }
2024
2025
2033 public List<Role> filterFindByT_S(int type, String subtype)
2034 throws SystemException {
2035 return filterFindByT_S(type, subtype, QueryUtil.ALL_POS,
2036 QueryUtil.ALL_POS, null);
2037 }
2038
2039
2053 public List<Role> filterFindByT_S(int type, String subtype, int start,
2054 int end) throws SystemException {
2055 return filterFindByT_S(type, subtype, start, end, null);
2056 }
2057
2058
2073 public List<Role> filterFindByT_S(int type, String subtype, int start,
2074 int end, OrderByComparator orderByComparator) throws SystemException {
2075 if (!InlineSQLHelperUtil.isEnabled()) {
2076 return findByT_S(type, subtype, start, end, orderByComparator);
2077 }
2078
2079 StringBundler query = null;
2080
2081 if (orderByComparator != null) {
2082 query = new StringBundler(4 +
2083 (orderByComparator.getOrderByFields().length * 3));
2084 }
2085 else {
2086 query = new StringBundler(4);
2087 }
2088
2089 if (getDB().isSupportsInlineDistinct()) {
2090 query.append(_FILTER_SQL_SELECT_ROLE_WHERE);
2091 }
2092 else {
2093 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1);
2094 }
2095
2096 query.append(_FINDER_COLUMN_T_S_TYPE_2);
2097
2098 if (subtype == null) {
2099 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
2100 }
2101 else {
2102 if (subtype.equals(StringPool.BLANK)) {
2103 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
2104 }
2105 else {
2106 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
2107 }
2108 }
2109
2110 if (!getDB().isSupportsInlineDistinct()) {
2111 query.append(_FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2);
2112 }
2113
2114 if (orderByComparator != null) {
2115 if (getDB().isSupportsInlineDistinct()) {
2116 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2117 orderByComparator);
2118 }
2119 else {
2120 appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2121 orderByComparator);
2122 }
2123 }
2124
2125 else {
2126 if (getDB().isSupportsInlineDistinct()) {
2127 query.append(RoleModelImpl.ORDER_BY_JPQL);
2128 }
2129 else {
2130 query.append(RoleModelImpl.ORDER_BY_SQL);
2131 }
2132 }
2133
2134 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2135 Role.class.getName(), _FILTER_COLUMN_PK, _FILTER_COLUMN_USERID);
2136
2137 Session session = null;
2138
2139 try {
2140 session = openSession();
2141
2142 SQLQuery q = session.createSQLQuery(sql);
2143
2144 if (getDB().isSupportsInlineDistinct()) {
2145 q.addEntity(_FILTER_ENTITY_ALIAS, RoleImpl.class);
2146 }
2147 else {
2148 q.addEntity(_FILTER_ENTITY_TABLE, RoleImpl.class);
2149 }
2150
2151 QueryPos qPos = QueryPos.getInstance(q);
2152
2153 qPos.add(type);
2154
2155 if (subtype != null) {
2156 qPos.add(subtype);
2157 }
2158
2159 return (List<Role>)QueryUtil.list(q, getDialect(), start, end);
2160 }
2161 catch (Exception e) {
2162 throw processException(e);
2163 }
2164 finally {
2165 closeSession(session);
2166 }
2167 }
2168
2169
2179 public Role findByC_C_C(long companyId, long classNameId, long classPK)
2180 throws NoSuchRoleException, SystemException {
2181 Role role = fetchByC_C_C(companyId, classNameId, classPK);
2182
2183 if (role == null) {
2184 StringBundler msg = new StringBundler(8);
2185
2186 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2187
2188 msg.append("companyId=");
2189 msg.append(companyId);
2190
2191 msg.append(", classNameId=");
2192 msg.append(classNameId);
2193
2194 msg.append(", classPK=");
2195 msg.append(classPK);
2196
2197 msg.append(StringPool.CLOSE_CURLY_BRACE);
2198
2199 if (_log.isWarnEnabled()) {
2200 _log.warn(msg.toString());
2201 }
2202
2203 throw new NoSuchRoleException(msg.toString());
2204 }
2205
2206 return role;
2207 }
2208
2209
2218 public Role fetchByC_C_C(long companyId, long classNameId, long classPK)
2219 throws SystemException {
2220 return fetchByC_C_C(companyId, classNameId, classPK, true);
2221 }
2222
2223
2232 public Role fetchByC_C_C(long companyId, long classNameId, long classPK,
2233 boolean retrieveFromCache) throws SystemException {
2234 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2235
2236 Object result = null;
2237
2238 if (retrieveFromCache) {
2239 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_C,
2240 finderArgs, this);
2241 }
2242
2243 if (result == null) {
2244 StringBundler query = new StringBundler(5);
2245
2246 query.append(_SQL_SELECT_ROLE_WHERE);
2247
2248 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2249
2250 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2251
2252 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2253
2254 query.append(RoleModelImpl.ORDER_BY_JPQL);
2255
2256 String sql = query.toString();
2257
2258 Session session = null;
2259
2260 try {
2261 session = openSession();
2262
2263 Query q = session.createQuery(sql);
2264
2265 QueryPos qPos = QueryPos.getInstance(q);
2266
2267 qPos.add(companyId);
2268
2269 qPos.add(classNameId);
2270
2271 qPos.add(classPK);
2272
2273 List<Role> list = q.list();
2274
2275 result = list;
2276
2277 Role role = null;
2278
2279 if (list.isEmpty()) {
2280 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
2281 finderArgs, list);
2282 }
2283 else {
2284 role = list.get(0);
2285
2286 cacheResult(role);
2287
2288 if ((role.getCompanyId() != companyId) ||
2289 (role.getClassNameId() != classNameId) ||
2290 (role.getClassPK() != classPK)) {
2291 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_C,
2292 finderArgs, role);
2293 }
2294 }
2295
2296 return role;
2297 }
2298 catch (Exception e) {
2299 throw processException(e);
2300 }
2301 finally {
2302 if (result == null) {
2303 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_C,
2304 finderArgs);
2305 }
2306
2307 closeSession(session);
2308 }
2309 }
2310 else {
2311 if (result instanceof List<?>) {
2312 return null;
2313 }
2314 else {
2315 return (Role)result;
2316 }
2317 }
2318 }
2319
2320
2326 public List<Role> findAll() throws SystemException {
2327 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2328 }
2329
2330
2342 public List<Role> findAll(int start, int end) throws SystemException {
2343 return findAll(start, end, null);
2344 }
2345
2346
2359 public List<Role> findAll(int start, int end,
2360 OrderByComparator orderByComparator) throws SystemException {
2361 Object[] finderArgs = new Object[] {
2362 String.valueOf(start), String.valueOf(end),
2363 String.valueOf(orderByComparator)
2364 };
2365
2366 List<Role> list = (List<Role>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2367 finderArgs, this);
2368
2369 if (list == null) {
2370 StringBundler query = null;
2371 String sql = null;
2372
2373 if (orderByComparator != null) {
2374 query = new StringBundler(2 +
2375 (orderByComparator.getOrderByFields().length * 3));
2376
2377 query.append(_SQL_SELECT_ROLE);
2378
2379 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2380 orderByComparator);
2381
2382 sql = query.toString();
2383 }
2384 else {
2385 sql = _SQL_SELECT_ROLE.concat(RoleModelImpl.ORDER_BY_JPQL);
2386 }
2387
2388 Session session = null;
2389
2390 try {
2391 session = openSession();
2392
2393 Query q = session.createQuery(sql);
2394
2395 if (orderByComparator == null) {
2396 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2397 end, false);
2398
2399 Collections.sort(list);
2400 }
2401 else {
2402 list = (List<Role>)QueryUtil.list(q, getDialect(), start,
2403 end);
2404 }
2405 }
2406 catch (Exception e) {
2407 throw processException(e);
2408 }
2409 finally {
2410 if (list == null) {
2411 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
2412 finderArgs);
2413 }
2414 else {
2415 cacheResult(list);
2416
2417 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
2418 list);
2419 }
2420
2421 closeSession(session);
2422 }
2423 }
2424
2425 return list;
2426 }
2427
2428
2434 public void removeByCompanyId(long companyId) throws SystemException {
2435 for (Role role : findByCompanyId(companyId)) {
2436 remove(role);
2437 }
2438 }
2439
2440
2446 public void removeBySubtype(String subtype) throws SystemException {
2447 for (Role role : findBySubtype(subtype)) {
2448 remove(role);
2449 }
2450 }
2451
2452
2459 public void removeByC_N(long companyId, String name)
2460 throws NoSuchRoleException, SystemException {
2461 Role role = findByC_N(companyId, name);
2462
2463 remove(role);
2464 }
2465
2466
2473 public void removeByT_S(int type, String subtype) throws SystemException {
2474 for (Role role : findByT_S(type, subtype)) {
2475 remove(role);
2476 }
2477 }
2478
2479
2487 public void removeByC_C_C(long companyId, long classNameId, long classPK)
2488 throws NoSuchRoleException, SystemException {
2489 Role role = findByC_C_C(companyId, classNameId, classPK);
2490
2491 remove(role);
2492 }
2493
2494
2499 public void removeAll() throws SystemException {
2500 for (Role role : findAll()) {
2501 remove(role);
2502 }
2503 }
2504
2505
2512 public int countByCompanyId(long companyId) throws SystemException {
2513 Object[] finderArgs = new Object[] { companyId };
2514
2515 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
2516 finderArgs, this);
2517
2518 if (count == null) {
2519 StringBundler query = new StringBundler(2);
2520
2521 query.append(_SQL_COUNT_ROLE_WHERE);
2522
2523 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2524
2525 String sql = query.toString();
2526
2527 Session session = null;
2528
2529 try {
2530 session = openSession();
2531
2532 Query q = session.createQuery(sql);
2533
2534 QueryPos qPos = QueryPos.getInstance(q);
2535
2536 qPos.add(companyId);
2537
2538 count = (Long)q.uniqueResult();
2539 }
2540 catch (Exception e) {
2541 throw processException(e);
2542 }
2543 finally {
2544 if (count == null) {
2545 count = Long.valueOf(0);
2546 }
2547
2548 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
2549 finderArgs, count);
2550
2551 closeSession(session);
2552 }
2553 }
2554
2555 return count.intValue();
2556 }
2557
2558
2565 public int filterCountByCompanyId(long companyId) throws SystemException {
2566 if (!InlineSQLHelperUtil.isEnabled()) {
2567 return countByCompanyId(companyId);
2568 }
2569
2570 StringBundler query = new StringBundler(2);
2571
2572 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2573
2574 query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2575
2576 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2577 Role.class.getName(), _FILTER_COLUMN_PK, _FILTER_COLUMN_USERID);
2578
2579 Session session = null;
2580
2581 try {
2582 session = openSession();
2583
2584 SQLQuery q = session.createSQLQuery(sql);
2585
2586 q.addScalar(COUNT_COLUMN_NAME,
2587 com.liferay.portal.kernel.dao.orm.Type.LONG);
2588
2589 QueryPos qPos = QueryPos.getInstance(q);
2590
2591 qPos.add(companyId);
2592
2593 Long count = (Long)q.uniqueResult();
2594
2595 return count.intValue();
2596 }
2597 catch (Exception e) {
2598 throw processException(e);
2599 }
2600 finally {
2601 closeSession(session);
2602 }
2603 }
2604
2605
2612 public int countBySubtype(String subtype) throws SystemException {
2613 Object[] finderArgs = new Object[] { subtype };
2614
2615 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_SUBTYPE,
2616 finderArgs, this);
2617
2618 if (count == null) {
2619 StringBundler query = new StringBundler(2);
2620
2621 query.append(_SQL_COUNT_ROLE_WHERE);
2622
2623 if (subtype == null) {
2624 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2625 }
2626 else {
2627 if (subtype.equals(StringPool.BLANK)) {
2628 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2629 }
2630 else {
2631 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2632 }
2633 }
2634
2635 String sql = query.toString();
2636
2637 Session session = null;
2638
2639 try {
2640 session = openSession();
2641
2642 Query q = session.createQuery(sql);
2643
2644 QueryPos qPos = QueryPos.getInstance(q);
2645
2646 if (subtype != null) {
2647 qPos.add(subtype);
2648 }
2649
2650 count = (Long)q.uniqueResult();
2651 }
2652 catch (Exception e) {
2653 throw processException(e);
2654 }
2655 finally {
2656 if (count == null) {
2657 count = Long.valueOf(0);
2658 }
2659
2660 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_SUBTYPE,
2661 finderArgs, count);
2662
2663 closeSession(session);
2664 }
2665 }
2666
2667 return count.intValue();
2668 }
2669
2670
2677 public int filterCountBySubtype(String subtype) throws SystemException {
2678 if (!InlineSQLHelperUtil.isEnabled()) {
2679 return countBySubtype(subtype);
2680 }
2681
2682 StringBundler query = new StringBundler(2);
2683
2684 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2685
2686 if (subtype == null) {
2687 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_1);
2688 }
2689 else {
2690 if (subtype.equals(StringPool.BLANK)) {
2691 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_3);
2692 }
2693 else {
2694 query.append(_FINDER_COLUMN_SUBTYPE_SUBTYPE_2);
2695 }
2696 }
2697
2698 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2699 Role.class.getName(), _FILTER_COLUMN_PK, _FILTER_COLUMN_USERID);
2700
2701 Session session = null;
2702
2703 try {
2704 session = openSession();
2705
2706 SQLQuery q = session.createSQLQuery(sql);
2707
2708 q.addScalar(COUNT_COLUMN_NAME,
2709 com.liferay.portal.kernel.dao.orm.Type.LONG);
2710
2711 QueryPos qPos = QueryPos.getInstance(q);
2712
2713 if (subtype != null) {
2714 qPos.add(subtype);
2715 }
2716
2717 Long count = (Long)q.uniqueResult();
2718
2719 return count.intValue();
2720 }
2721 catch (Exception e) {
2722 throw processException(e);
2723 }
2724 finally {
2725 closeSession(session);
2726 }
2727 }
2728
2729
2737 public int countByC_N(long companyId, String name)
2738 throws SystemException {
2739 Object[] finderArgs = new Object[] { companyId, name };
2740
2741 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_N,
2742 finderArgs, this);
2743
2744 if (count == null) {
2745 StringBundler query = new StringBundler(3);
2746
2747 query.append(_SQL_COUNT_ROLE_WHERE);
2748
2749 query.append(_FINDER_COLUMN_C_N_COMPANYID_2);
2750
2751 if (name == null) {
2752 query.append(_FINDER_COLUMN_C_N_NAME_1);
2753 }
2754 else {
2755 if (name.equals(StringPool.BLANK)) {
2756 query.append(_FINDER_COLUMN_C_N_NAME_3);
2757 }
2758 else {
2759 query.append(_FINDER_COLUMN_C_N_NAME_2);
2760 }
2761 }
2762
2763 String sql = query.toString();
2764
2765 Session session = null;
2766
2767 try {
2768 session = openSession();
2769
2770 Query q = session.createQuery(sql);
2771
2772 QueryPos qPos = QueryPos.getInstance(q);
2773
2774 qPos.add(companyId);
2775
2776 if (name != null) {
2777 qPos.add(name);
2778 }
2779
2780 count = (Long)q.uniqueResult();
2781 }
2782 catch (Exception e) {
2783 throw processException(e);
2784 }
2785 finally {
2786 if (count == null) {
2787 count = Long.valueOf(0);
2788 }
2789
2790 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_N, finderArgs,
2791 count);
2792
2793 closeSession(session);
2794 }
2795 }
2796
2797 return count.intValue();
2798 }
2799
2800
2808 public int countByT_S(int type, String subtype) throws SystemException {
2809 Object[] finderArgs = new Object[] { type, subtype };
2810
2811 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_T_S,
2812 finderArgs, this);
2813
2814 if (count == null) {
2815 StringBundler query = new StringBundler(3);
2816
2817 query.append(_SQL_COUNT_ROLE_WHERE);
2818
2819 query.append(_FINDER_COLUMN_T_S_TYPE_2);
2820
2821 if (subtype == null) {
2822 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
2823 }
2824 else {
2825 if (subtype.equals(StringPool.BLANK)) {
2826 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
2827 }
2828 else {
2829 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
2830 }
2831 }
2832
2833 String sql = query.toString();
2834
2835 Session session = null;
2836
2837 try {
2838 session = openSession();
2839
2840 Query q = session.createQuery(sql);
2841
2842 QueryPos qPos = QueryPos.getInstance(q);
2843
2844 qPos.add(type);
2845
2846 if (subtype != null) {
2847 qPos.add(subtype);
2848 }
2849
2850 count = (Long)q.uniqueResult();
2851 }
2852 catch (Exception e) {
2853 throw processException(e);
2854 }
2855 finally {
2856 if (count == null) {
2857 count = Long.valueOf(0);
2858 }
2859
2860 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_T_S, finderArgs,
2861 count);
2862
2863 closeSession(session);
2864 }
2865 }
2866
2867 return count.intValue();
2868 }
2869
2870
2878 public int filterCountByT_S(int type, String subtype)
2879 throws SystemException {
2880 if (!InlineSQLHelperUtil.isEnabled()) {
2881 return countByT_S(type, subtype);
2882 }
2883
2884 StringBundler query = new StringBundler(3);
2885
2886 query.append(_FILTER_SQL_COUNT_ROLE_WHERE);
2887
2888 query.append(_FINDER_COLUMN_T_S_TYPE_2);
2889
2890 if (subtype == null) {
2891 query.append(_FINDER_COLUMN_T_S_SUBTYPE_1);
2892 }
2893 else {
2894 if (subtype.equals(StringPool.BLANK)) {
2895 query.append(_FINDER_COLUMN_T_S_SUBTYPE_3);
2896 }
2897 else {
2898 query.append(_FINDER_COLUMN_T_S_SUBTYPE_2);
2899 }
2900 }
2901
2902 String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2903 Role.class.getName(), _FILTER_COLUMN_PK, _FILTER_COLUMN_USERID);
2904
2905 Session session = null;
2906
2907 try {
2908 session = openSession();
2909
2910 SQLQuery q = session.createSQLQuery(sql);
2911
2912 q.addScalar(COUNT_COLUMN_NAME,
2913 com.liferay.portal.kernel.dao.orm.Type.LONG);
2914
2915 QueryPos qPos = QueryPos.getInstance(q);
2916
2917 qPos.add(type);
2918
2919 if (subtype != null) {
2920 qPos.add(subtype);
2921 }
2922
2923 Long count = (Long)q.uniqueResult();
2924
2925 return count.intValue();
2926 }
2927 catch (Exception e) {
2928 throw processException(e);
2929 }
2930 finally {
2931 closeSession(session);
2932 }
2933 }
2934
2935
2944 public int countByC_C_C(long companyId, long classNameId, long classPK)
2945 throws SystemException {
2946 Object[] finderArgs = new Object[] { companyId, classNameId, classPK };
2947
2948 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_C,
2949 finderArgs, this);
2950
2951 if (count == null) {
2952 StringBundler query = new StringBundler(4);
2953
2954 query.append(_SQL_COUNT_ROLE_WHERE);
2955
2956 query.append(_FINDER_COLUMN_C_C_C_COMPANYID_2);
2957
2958 query.append(_FINDER_COLUMN_C_C_C_CLASSNAMEID_2);
2959
2960 query.append(_FINDER_COLUMN_C_C_C_CLASSPK_2);
2961
2962 String sql = query.toString();
2963
2964 Session session = null;
2965
2966 try {
2967 session = openSession();
2968
2969 Query q = session.createQuery(sql);
2970
2971 QueryPos qPos = QueryPos.getInstance(q);
2972
2973 qPos.add(companyId);
2974
2975 qPos.add(classNameId);
2976
2977 qPos.add(classPK);
2978
2979 count = (Long)q.uniqueResult();
2980 }
2981 catch (Exception e) {
2982 throw processException(e);
2983 }
2984 finally {
2985 if (count == null) {
2986 count = Long.valueOf(0);
2987 }
2988
2989 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_C,
2990 finderArgs, count);
2991
2992 closeSession(session);
2993 }
2994 }
2995
2996 return count.intValue();
2997 }
2998
2999
3005 public int countAll() throws SystemException {
3006 Object[] finderArgs = new Object[0];
3007
3008 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3009 finderArgs, this);
3010
3011 if (count == null) {
3012 Session session = null;
3013
3014 try {
3015 session = openSession();
3016
3017 Query q = session.createQuery(_SQL_COUNT_ROLE);
3018
3019 count = (Long)q.uniqueResult();
3020 }
3021 catch (Exception e) {
3022 throw processException(e);
3023 }
3024 finally {
3025 if (count == null) {
3026 count = Long.valueOf(0);
3027 }
3028
3029 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3030 count);
3031
3032 closeSession(session);
3033 }
3034 }
3035
3036 return count.intValue();
3037 }
3038
3039
3046 public List<com.liferay.portal.model.Group> getGroups(long pk)
3047 throws SystemException {
3048 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3049 }
3050
3051
3064 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3065 int end) throws SystemException {
3066 return getGroups(pk, start, end, null);
3067 }
3068
3069 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3070 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
3071 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroups",
3072 new String[] {
3073 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3074 "com.liferay.portal.kernel.util.OrderByComparator"
3075 });
3076
3077
3091 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
3092 int end, OrderByComparator orderByComparator) throws SystemException {
3093 Object[] finderArgs = new Object[] {
3094 pk, String.valueOf(start), String.valueOf(end),
3095 String.valueOf(orderByComparator)
3096 };
3097
3098 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
3099 finderArgs, this);
3100
3101 if (list == null) {
3102 Session session = null;
3103
3104 try {
3105 session = openSession();
3106
3107 String sql = null;
3108
3109 if (orderByComparator != null) {
3110 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
3111 .concat(orderByComparator.getOrderBy());
3112 }
3113 else {
3114 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
3115 }
3116
3117 SQLQuery q = session.createSQLQuery(sql);
3118
3119 q.addEntity("Group_",
3120 com.liferay.portal.model.impl.GroupImpl.class);
3121
3122 QueryPos qPos = QueryPos.getInstance(q);
3123
3124 qPos.add(pk);
3125
3126 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
3127 getDialect(), start, end);
3128 }
3129 catch (Exception e) {
3130 throw processException(e);
3131 }
3132 finally {
3133 if (list == null) {
3134 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
3135 finderArgs);
3136 }
3137 else {
3138 groupPersistence.cacheResult(list);
3139
3140 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
3141 finderArgs, list);
3142 }
3143
3144 closeSession(session);
3145 }
3146 }
3147
3148 return list;
3149 }
3150
3151 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3152 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
3153 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "getGroupsSize",
3154 new String[] { Long.class.getName() });
3155
3156
3163 public int getGroupsSize(long pk) throws SystemException {
3164 Object[] finderArgs = new Object[] { pk };
3165
3166 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
3167 finderArgs, this);
3168
3169 if (count == null) {
3170 Session session = null;
3171
3172 try {
3173 session = openSession();
3174
3175 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
3176
3177 q.addScalar(COUNT_COLUMN_NAME,
3178 com.liferay.portal.kernel.dao.orm.Type.LONG);
3179
3180 QueryPos qPos = QueryPos.getInstance(q);
3181
3182 qPos.add(pk);
3183
3184 count = (Long)q.uniqueResult();
3185 }
3186 catch (Exception e) {
3187 throw processException(e);
3188 }
3189 finally {
3190 if (count == null) {
3191 count = Long.valueOf(0);
3192 }
3193
3194 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
3195 finderArgs, count);
3196
3197 closeSession(session);
3198 }
3199 }
3200
3201 return count.intValue();
3202 }
3203
3204 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
3205 RoleModelImpl.FINDER_CACHE_ENABLED_GROUPS_ROLES,
3206 RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME, "containsGroup",
3207 new String[] { Long.class.getName(), Long.class.getName() });
3208
3209
3217 public boolean containsGroup(long pk, long groupPK)
3218 throws SystemException {
3219 Object[] finderArgs = new Object[] { pk, groupPK };
3220
3221 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
3222 finderArgs, this);
3223
3224 if (value == null) {
3225 try {
3226 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
3227 }
3228 catch (Exception e) {
3229 throw processException(e);
3230 }
3231 finally {
3232 if (value == null) {
3233 value = Boolean.FALSE;
3234 }
3235
3236 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
3237 finderArgs, value);
3238 }
3239 }
3240
3241 return value.booleanValue();
3242 }
3243
3244
3251 public boolean containsGroups(long pk) throws SystemException {
3252 if (getGroupsSize(pk) > 0) {
3253 return true;
3254 }
3255 else {
3256 return false;
3257 }
3258 }
3259
3260
3267 public void addGroup(long pk, long groupPK) throws SystemException {
3268 try {
3269 addGroup.add(pk, groupPK);
3270 }
3271 catch (Exception e) {
3272 throw processException(e);
3273 }
3274 finally {
3275 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3276 }
3277 }
3278
3279
3286 public void addGroup(long pk, com.liferay.portal.model.Group group)
3287 throws SystemException {
3288 try {
3289 addGroup.add(pk, group.getPrimaryKey());
3290 }
3291 catch (Exception e) {
3292 throw processException(e);
3293 }
3294 finally {
3295 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3296 }
3297 }
3298
3299
3306 public void addGroups(long pk, long[] groupPKs) throws SystemException {
3307 try {
3308 for (long groupPK : groupPKs) {
3309 addGroup.add(pk, groupPK);
3310 }
3311 }
3312 catch (Exception e) {
3313 throw processException(e);
3314 }
3315 finally {
3316 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3317 }
3318 }
3319
3320
3327 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
3328 throws SystemException {
3329 try {
3330 for (com.liferay.portal.model.Group group : groups) {
3331 addGroup.add(pk, group.getPrimaryKey());
3332 }
3333 }
3334 catch (Exception e) {
3335 throw processException(e);
3336 }
3337 finally {
3338 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3339 }
3340 }
3341
3342
3348 public void clearGroups(long pk) throws SystemException {
3349 try {
3350 clearGroups.clear(pk);
3351 }
3352 catch (Exception e) {
3353 throw processException(e);
3354 }
3355 finally {
3356 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3357 }
3358 }
3359
3360
3367 public void removeGroup(long pk, long groupPK) throws SystemException {
3368 try {
3369 removeGroup.remove(pk, groupPK);
3370 }
3371 catch (Exception e) {
3372 throw processException(e);
3373 }
3374 finally {
3375 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3376 }
3377 }
3378
3379
3386 public void removeGroup(long pk, com.liferay.portal.model.Group group)
3387 throws SystemException {
3388 try {
3389 removeGroup.remove(pk, group.getPrimaryKey());
3390 }
3391 catch (Exception e) {
3392 throw processException(e);
3393 }
3394 finally {
3395 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3396 }
3397 }
3398
3399
3406 public void removeGroups(long pk, long[] groupPKs)
3407 throws SystemException {
3408 try {
3409 for (long groupPK : groupPKs) {
3410 removeGroup.remove(pk, groupPK);
3411 }
3412 }
3413 catch (Exception e) {
3414 throw processException(e);
3415 }
3416 finally {
3417 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3418 }
3419 }
3420
3421
3428 public void removeGroups(long pk,
3429 List<com.liferay.portal.model.Group> groups) throws SystemException {
3430 try {
3431 for (com.liferay.portal.model.Group group : groups) {
3432 removeGroup.remove(pk, group.getPrimaryKey());
3433 }
3434 }
3435 catch (Exception e) {
3436 throw processException(e);
3437 }
3438 finally {
3439 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3440 }
3441 }
3442
3443
3450 public void setGroups(long pk, long[] groupPKs) throws SystemException {
3451 try {
3452 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
3453
3454 List<com.liferay.portal.model.Group> groups = getGroups(pk);
3455
3456 for (com.liferay.portal.model.Group group : groups) {
3457 if (!groupPKSet.remove(group.getPrimaryKey())) {
3458 removeGroup.remove(pk, group.getPrimaryKey());
3459 }
3460 }
3461
3462 for (Long groupPK : groupPKSet) {
3463 addGroup.add(pk, groupPK);
3464 }
3465 }
3466 catch (Exception e) {
3467 throw processException(e);
3468 }
3469 finally {
3470 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3471 }
3472 }
3473
3474
3481 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
3482 throws SystemException {
3483 try {
3484 long[] groupPKs = new long[groups.size()];
3485
3486 for (int i = 0; i < groups.size(); i++) {
3487 com.liferay.portal.model.Group group = groups.get(i);
3488
3489 groupPKs[i] = group.getPrimaryKey();
3490 }
3491
3492 setGroups(pk, groupPKs);
3493 }
3494 catch (Exception e) {
3495 throw processException(e);
3496 }
3497 finally {
3498 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_GROUPS_ROLES_NAME);
3499 }
3500 }
3501
3502
3509 public List<com.liferay.portal.model.Permission> getPermissions(long pk)
3510 throws SystemException {
3511 return getPermissions(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3512 }
3513
3514
3527 public List<com.liferay.portal.model.Permission> getPermissions(long pk,
3528 int start, int end) throws SystemException {
3529 return getPermissions(pk, start, end, null);
3530 }
3531
3532 public static final FinderPath FINDER_PATH_GET_PERMISSIONS = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3533 RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
3534 RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
3535 "getPermissions",
3536 new String[] {
3537 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
3538 "com.liferay.portal.kernel.util.OrderByComparator"
3539 });
3540
3541
3555 public List<com.liferay.portal.model.Permission> getPermissions(long pk,
3556 int start, int end, OrderByComparator orderByComparator)
3557 throws SystemException {
3558 Object[] finderArgs = new Object[] {
3559 pk, String.valueOf(start), String.valueOf(end),
3560 String.valueOf(orderByComparator)
3561 };
3562
3563 List<com.liferay.portal.model.Permission> list = (List<com.liferay.portal.model.Permission>)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS,
3564 finderArgs, this);
3565
3566 if (list == null) {
3567 Session session = null;
3568
3569 try {
3570 session = openSession();
3571
3572 String sql = null;
3573
3574 if (orderByComparator != null) {
3575 sql = _SQL_GETPERMISSIONS.concat(ORDER_BY_CLAUSE)
3576 .concat(orderByComparator.getOrderBy());
3577 }
3578 else {
3579 sql = _SQL_GETPERMISSIONS;
3580 }
3581
3582 SQLQuery q = session.createSQLQuery(sql);
3583
3584 q.addEntity("Permission_",
3585 com.liferay.portal.model.impl.PermissionImpl.class);
3586
3587 QueryPos qPos = QueryPos.getInstance(q);
3588
3589 qPos.add(pk);
3590
3591 list = (List<com.liferay.portal.model.Permission>)QueryUtil.list(q,
3592 getDialect(), start, end);
3593 }
3594 catch (Exception e) {
3595 throw processException(e);
3596 }
3597 finally {
3598 if (list == null) {
3599 FinderCacheUtil.removeResult(FINDER_PATH_GET_PERMISSIONS,
3600 finderArgs);
3601 }
3602 else {
3603 permissionPersistence.cacheResult(list);
3604
3605 FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS,
3606 finderArgs, list);
3607 }
3608
3609 closeSession(session);
3610 }
3611 }
3612
3613 return list;
3614 }
3615
3616 public static final FinderPath FINDER_PATH_GET_PERMISSIONS_SIZE = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3617 RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
3618 RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
3619 "getPermissionsSize", new String[] { Long.class.getName() });
3620
3621
3628 public int getPermissionsSize(long pk) throws SystemException {
3629 Object[] finderArgs = new Object[] { pk };
3630
3631 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
3632 finderArgs, this);
3633
3634 if (count == null) {
3635 Session session = null;
3636
3637 try {
3638 session = openSession();
3639
3640 SQLQuery q = session.createSQLQuery(_SQL_GETPERMISSIONSSIZE);
3641
3642 q.addScalar(COUNT_COLUMN_NAME,
3643 com.liferay.portal.kernel.dao.orm.Type.LONG);
3644
3645 QueryPos qPos = QueryPos.getInstance(q);
3646
3647 qPos.add(pk);
3648
3649 count = (Long)q.uniqueResult();
3650 }
3651 catch (Exception e) {
3652 throw processException(e);
3653 }
3654 finally {
3655 if (count == null) {
3656 count = Long.valueOf(0);
3657 }
3658
3659 FinderCacheUtil.putResult(FINDER_PATH_GET_PERMISSIONS_SIZE,
3660 finderArgs, count);
3661
3662 closeSession(session);
3663 }
3664 }
3665
3666 return count.intValue();
3667 }
3668
3669 public static final FinderPath FINDER_PATH_CONTAINS_PERMISSION = new FinderPath(com.liferay.portal.model.impl.PermissionModelImpl.ENTITY_CACHE_ENABLED,
3670 RoleModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
3671 RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
3672 "containsPermission",
3673 new String[] { Long.class.getName(), Long.class.getName() });
3674
3675
3683 public boolean containsPermission(long pk, long permissionPK)
3684 throws SystemException {
3685 Object[] finderArgs = new Object[] { pk, permissionPK };
3686
3687 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_PERMISSION,
3688 finderArgs, this);
3689
3690 if (value == null) {
3691 try {
3692 value = Boolean.valueOf(containsPermission.contains(pk,
3693 permissionPK));
3694 }
3695 catch (Exception e) {
3696 throw processException(e);
3697 }
3698 finally {
3699 if (value == null) {
3700 value = Boolean.FALSE;
3701 }
3702
3703 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_PERMISSION,
3704 finderArgs, value);
3705 }
3706 }
3707
3708 return value.booleanValue();
3709 }
3710
3711
3718 public boolean containsPermissions(long pk) throws SystemException {
3719 if (getPermissionsSize(pk) > 0) {
3720 return true;
3721 }
3722 else {
3723 return false;
3724 }
3725 }
3726
3727
3734 public void addPermission(long pk, long permissionPK)
3735 throws SystemException {
3736 try {
3737 addPermission.add(pk, permissionPK);
3738 }
3739 catch (Exception e) {
3740 throw processException(e);
3741 }
3742 finally {
3743 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3744 }
3745 }
3746
3747
3754 public void addPermission(long pk,
3755 com.liferay.portal.model.Permission permission)
3756 throws SystemException {
3757 try {
3758 addPermission.add(pk, permission.getPrimaryKey());
3759 }
3760 catch (Exception e) {
3761 throw processException(e);
3762 }
3763 finally {
3764 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3765 }
3766 }
3767
3768
3775 public void addPermissions(long pk, long[] permissionPKs)
3776 throws SystemException {
3777 try {
3778 for (long permissionPK : permissionPKs) {
3779 addPermission.add(pk, permissionPK);
3780 }
3781 }
3782 catch (Exception e) {
3783 throw processException(e);
3784 }
3785 finally {
3786 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3787 }
3788 }
3789
3790
3797 public void addPermissions(long pk,
3798 List<com.liferay.portal.model.Permission> permissions)
3799 throws SystemException {
3800 try {
3801 for (com.liferay.portal.model.Permission permission : permissions) {
3802 addPermission.add(pk, permission.getPrimaryKey());
3803 }
3804 }
3805 catch (Exception e) {
3806 throw processException(e);
3807 }
3808 finally {
3809 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3810 }
3811 }
3812
3813
3819 public void clearPermissions(long pk) throws SystemException {
3820 try {
3821 clearPermissions.clear(pk);
3822 }
3823 catch (Exception e) {
3824 throw processException(e);
3825 }
3826 finally {
3827 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3828 }
3829 }
3830
3831
3838 public void removePermission(long pk, long permissionPK)
3839 throws SystemException {
3840 try {
3841 removePermission.remove(pk, permissionPK);
3842 }
3843 catch (Exception e) {
3844 throw processException(e);
3845 }
3846 finally {
3847 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3848 }
3849 }
3850
3851
3858 public void removePermission(long pk,
3859 com.liferay.portal.model.Permission permission)
3860 throws SystemException {
3861 try {
3862 removePermission.remove(pk, permission.getPrimaryKey());
3863 }
3864 catch (Exception e) {
3865 throw processException(e);
3866 }
3867 finally {
3868 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3869 }
3870 }
3871
3872
3879 public void removePermissions(long pk, long[] permissionPKs)
3880 throws SystemException {
3881 try {
3882 for (long permissionPK : permissionPKs) {
3883 removePermission.remove(pk, permissionPK);
3884 }
3885 }
3886 catch (Exception e) {
3887 throw processException(e);
3888 }
3889 finally {
3890 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3891 }
3892 }
3893
3894
3901 public void removePermissions(long pk,
3902 List<com.liferay.portal.model.Permission> permissions)
3903 throws SystemException {
3904 try {
3905 for (com.liferay.portal.model.Permission permission : permissions) {
3906 removePermission.remove(pk, permission.getPrimaryKey());
3907 }
3908 }
3909 catch (Exception e) {
3910 throw processException(e);
3911 }
3912 finally {
3913 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3914 }
3915 }
3916
3917
3924 public void setPermissions(long pk, long[] permissionPKs)
3925 throws SystemException {
3926 try {
3927 Set<Long> permissionPKSet = SetUtil.fromArray(permissionPKs);
3928
3929 List<com.liferay.portal.model.Permission> permissions = getPermissions(pk);
3930
3931 for (com.liferay.portal.model.Permission permission : permissions) {
3932 if (!permissionPKSet.remove(permission.getPrimaryKey())) {
3933 removePermission.remove(pk, permission.getPrimaryKey());
3934 }
3935 }
3936
3937 for (Long permissionPK : permissionPKSet) {
3938 addPermission.add(pk, permissionPK);
3939 }
3940 }
3941 catch (Exception e) {
3942 throw processException(e);
3943 }
3944 finally {
3945 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3946 }
3947 }
3948
3949
3956 public void setPermissions(long pk,
3957 List<com.liferay.portal.model.Permission> permissions)
3958 throws SystemException {
3959 try {
3960 long[] permissionPKs = new long[permissions.size()];
3961
3962 for (int i = 0; i < permissions.size(); i++) {
3963 com.liferay.portal.model.Permission permission = permissions.get(i);
3964
3965 permissionPKs[i] = permission.getPrimaryKey();
3966 }
3967
3968 setPermissions(pk, permissionPKs);
3969 }
3970 catch (Exception e) {
3971 throw processException(e);
3972 }
3973 finally {
3974 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
3975 }
3976 }
3977
3978
3985 public List<com.liferay.portal.model.User> getUsers(long pk)
3986 throws SystemException {
3987 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
3988 }
3989
3990
4003 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
4004 int end) throws SystemException {
4005 return getUsers(pk, start, end, null);
4006 }
4007
4008 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4009 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
4010 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsers",
4011 new String[] {
4012 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
4013 "com.liferay.portal.kernel.util.OrderByComparator"
4014 });
4015
4016
4030 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
4031 int end, OrderByComparator orderByComparator) throws SystemException {
4032 Object[] finderArgs = new Object[] {
4033 pk, String.valueOf(start), String.valueOf(end),
4034 String.valueOf(orderByComparator)
4035 };
4036
4037 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
4038 finderArgs, this);
4039
4040 if (list == null) {
4041 Session session = null;
4042
4043 try {
4044 session = openSession();
4045
4046 String sql = null;
4047
4048 if (orderByComparator != null) {
4049 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
4050 .concat(orderByComparator.getOrderBy());
4051 }
4052 else {
4053 sql = _SQL_GETUSERS;
4054 }
4055
4056 SQLQuery q = session.createSQLQuery(sql);
4057
4058 q.addEntity("User_",
4059 com.liferay.portal.model.impl.UserImpl.class);
4060
4061 QueryPos qPos = QueryPos.getInstance(q);
4062
4063 qPos.add(pk);
4064
4065 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
4066 getDialect(), start, end);
4067 }
4068 catch (Exception e) {
4069 throw processException(e);
4070 }
4071 finally {
4072 if (list == null) {
4073 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
4074 finderArgs);
4075 }
4076 else {
4077 userPersistence.cacheResult(list);
4078
4079 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
4080 finderArgs, list);
4081 }
4082
4083 closeSession(session);
4084 }
4085 }
4086
4087 return list;
4088 }
4089
4090 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4091 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
4092 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "getUsersSize",
4093 new String[] { Long.class.getName() });
4094
4095
4102 public int getUsersSize(long pk) throws SystemException {
4103 Object[] finderArgs = new Object[] { pk };
4104
4105 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
4106 finderArgs, this);
4107
4108 if (count == null) {
4109 Session session = null;
4110
4111 try {
4112 session = openSession();
4113
4114 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
4115
4116 q.addScalar(COUNT_COLUMN_NAME,
4117 com.liferay.portal.kernel.dao.orm.Type.LONG);
4118
4119 QueryPos qPos = QueryPos.getInstance(q);
4120
4121 qPos.add(pk);
4122
4123 count = (Long)q.uniqueResult();
4124 }
4125 catch (Exception e) {
4126 throw processException(e);
4127 }
4128 finally {
4129 if (count == null) {
4130 count = Long.valueOf(0);
4131 }
4132
4133 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
4134 finderArgs, count);
4135
4136 closeSession(session);
4137 }
4138 }
4139
4140 return count.intValue();
4141 }
4142
4143 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
4144 RoleModelImpl.FINDER_CACHE_ENABLED_USERS_ROLES,
4145 RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME, "containsUser",
4146 new String[] { Long.class.getName(), Long.class.getName() });
4147
4148
4156 public boolean containsUser(long pk, long userPK) throws SystemException {
4157 Object[] finderArgs = new Object[] { pk, userPK };
4158
4159 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
4160 finderArgs, this);
4161
4162 if (value == null) {
4163 try {
4164 value = Boolean.valueOf(containsUser.contains(pk, userPK));
4165 }
4166 catch (Exception e) {
4167 throw processException(e);
4168 }
4169 finally {
4170 if (value == null) {
4171 value = Boolean.FALSE;
4172 }
4173
4174 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
4175 finderArgs, value);
4176 }
4177 }
4178
4179 return value.booleanValue();
4180 }
4181
4182
4189 public boolean containsUsers(long pk) throws SystemException {
4190 if (getUsersSize(pk) > 0) {
4191 return true;
4192 }
4193 else {
4194 return false;
4195 }
4196 }
4197
4198
4205 public void addUser(long pk, long userPK) throws SystemException {
4206 try {
4207 addUser.add(pk, userPK);
4208 }
4209 catch (Exception e) {
4210 throw processException(e);
4211 }
4212 finally {
4213 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4214 }
4215 }
4216
4217
4224 public void addUser(long pk, com.liferay.portal.model.User user)
4225 throws SystemException {
4226 try {
4227 addUser.add(pk, user.getPrimaryKey());
4228 }
4229 catch (Exception e) {
4230 throw processException(e);
4231 }
4232 finally {
4233 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4234 }
4235 }
4236
4237
4244 public void addUsers(long pk, long[] userPKs) throws SystemException {
4245 try {
4246 for (long userPK : userPKs) {
4247 addUser.add(pk, userPK);
4248 }
4249 }
4250 catch (Exception e) {
4251 throw processException(e);
4252 }
4253 finally {
4254 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4255 }
4256 }
4257
4258
4265 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
4266 throws SystemException {
4267 try {
4268 for (com.liferay.portal.model.User user : users) {
4269 addUser.add(pk, user.getPrimaryKey());
4270 }
4271 }
4272 catch (Exception e) {
4273 throw processException(e);
4274 }
4275 finally {
4276 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4277 }
4278 }
4279
4280
4286 public void clearUsers(long pk) throws SystemException {
4287 try {
4288 clearUsers.clear(pk);
4289 }
4290 catch (Exception e) {
4291 throw processException(e);
4292 }
4293 finally {
4294 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4295 }
4296 }
4297
4298
4305 public void removeUser(long pk, long userPK) throws SystemException {
4306 try {
4307 removeUser.remove(pk, userPK);
4308 }
4309 catch (Exception e) {
4310 throw processException(e);
4311 }
4312 finally {
4313 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4314 }
4315 }
4316
4317
4324 public void removeUser(long pk, com.liferay.portal.model.User user)
4325 throws SystemException {
4326 try {
4327 removeUser.remove(pk, user.getPrimaryKey());
4328 }
4329 catch (Exception e) {
4330 throw processException(e);
4331 }
4332 finally {
4333 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4334 }
4335 }
4336
4337
4344 public void removeUsers(long pk, long[] userPKs) throws SystemException {
4345 try {
4346 for (long userPK : userPKs) {
4347 removeUser.remove(pk, userPK);
4348 }
4349 }
4350 catch (Exception e) {
4351 throw processException(e);
4352 }
4353 finally {
4354 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4355 }
4356 }
4357
4358
4365 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
4366 throws SystemException {
4367 try {
4368 for (com.liferay.portal.model.User user : users) {
4369 removeUser.remove(pk, user.getPrimaryKey());
4370 }
4371 }
4372 catch (Exception e) {
4373 throw processException(e);
4374 }
4375 finally {
4376 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4377 }
4378 }
4379
4380
4387 public void setUsers(long pk, long[] userPKs) throws SystemException {
4388 try {
4389 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
4390
4391 List<com.liferay.portal.model.User> users = getUsers(pk);
4392
4393 for (com.liferay.portal.model.User user : users) {
4394 if (!userPKSet.remove(user.getPrimaryKey())) {
4395 removeUser.remove(pk, user.getPrimaryKey());
4396 }
4397 }
4398
4399 for (Long userPK : userPKSet) {
4400 addUser.add(pk, userPK);
4401 }
4402 }
4403 catch (Exception e) {
4404 throw processException(e);
4405 }
4406 finally {
4407 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4408 }
4409 }
4410
4411
4418 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
4419 throws SystemException {
4420 try {
4421 long[] userPKs = new long[users.size()];
4422
4423 for (int i = 0; i < users.size(); i++) {
4424 com.liferay.portal.model.User user = users.get(i);
4425
4426 userPKs[i] = user.getPrimaryKey();
4427 }
4428
4429 setUsers(pk, userPKs);
4430 }
4431 catch (Exception e) {
4432 throw processException(e);
4433 }
4434 finally {
4435 FinderCacheUtil.clearCache(RoleModelImpl.MAPPING_TABLE_USERS_ROLES_NAME);
4436 }
4437 }
4438
4439
4442 public void afterPropertiesSet() {
4443 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4444 com.liferay.portal.util.PropsUtil.get(
4445 "value.object.listener.com.liferay.portal.model.Role")));
4446
4447 if (listenerClassNames.length > 0) {
4448 try {
4449 List<ModelListener<Role>> listenersList = new ArrayList<ModelListener<Role>>();
4450
4451 for (String listenerClassName : listenerClassNames) {
4452 listenersList.add((ModelListener<Role>)InstanceFactory.newInstance(
4453 listenerClassName));
4454 }
4455
4456 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4457 }
4458 catch (Exception e) {
4459 _log.error(e);
4460 }
4461 }
4462
4463 containsGroup = new ContainsGroup(this);
4464
4465 addGroup = new AddGroup(this);
4466 clearGroups = new ClearGroups(this);
4467 removeGroup = new RemoveGroup(this);
4468
4469 containsPermission = new ContainsPermission(this);
4470
4471 addPermission = new AddPermission(this);
4472 clearPermissions = new ClearPermissions(this);
4473 removePermission = new RemovePermission(this);
4474
4475 containsUser = new ContainsUser(this);
4476
4477 addUser = new AddUser(this);
4478 clearUsers = new ClearUsers(this);
4479 removeUser = new RemoveUser(this);
4480 }
4481
4482 public void destroy() {
4483 EntityCacheUtil.removeCache(RoleImpl.class.getName());
4484 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4485 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
4486 }
4487
4488 @BeanReference(type = AccountPersistence.class)
4489 protected AccountPersistence accountPersistence;
4490 @BeanReference(type = AddressPersistence.class)
4491 protected AddressPersistence addressPersistence;
4492 @BeanReference(type = BrowserTrackerPersistence.class)
4493 protected BrowserTrackerPersistence browserTrackerPersistence;
4494 @BeanReference(type = ClassNamePersistence.class)
4495 protected ClassNamePersistence classNamePersistence;
4496 @BeanReference(type = ClusterGroupPersistence.class)
4497 protected ClusterGroupPersistence clusterGroupPersistence;
4498 @BeanReference(type = CompanyPersistence.class)
4499 protected CompanyPersistence companyPersistence;
4500 @BeanReference(type = ContactPersistence.class)
4501 protected ContactPersistence contactPersistence;
4502 @BeanReference(type = CountryPersistence.class)
4503 protected CountryPersistence countryPersistence;
4504 @BeanReference(type = EmailAddressPersistence.class)
4505 protected EmailAddressPersistence emailAddressPersistence;
4506 @BeanReference(type = GroupPersistence.class)
4507 protected GroupPersistence groupPersistence;
4508 @BeanReference(type = ImagePersistence.class)
4509 protected ImagePersistence imagePersistence;
4510 @BeanReference(type = LayoutPersistence.class)
4511 protected LayoutPersistence layoutPersistence;
4512 @BeanReference(type = LayoutPrototypePersistence.class)
4513 protected LayoutPrototypePersistence layoutPrototypePersistence;
4514 @BeanReference(type = LayoutSetPersistence.class)
4515 protected LayoutSetPersistence layoutSetPersistence;
4516 @BeanReference(type = LayoutSetPrototypePersistence.class)
4517 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
4518 @BeanReference(type = ListTypePersistence.class)
4519 protected ListTypePersistence listTypePersistence;
4520 @BeanReference(type = LockPersistence.class)
4521 protected LockPersistence lockPersistence;
4522 @BeanReference(type = MembershipRequestPersistence.class)
4523 protected MembershipRequestPersistence membershipRequestPersistence;
4524 @BeanReference(type = OrganizationPersistence.class)
4525 protected OrganizationPersistence organizationPersistence;
4526 @BeanReference(type = OrgGroupPermissionPersistence.class)
4527 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
4528 @BeanReference(type = OrgGroupRolePersistence.class)
4529 protected OrgGroupRolePersistence orgGroupRolePersistence;
4530 @BeanReference(type = OrgLaborPersistence.class)
4531 protected OrgLaborPersistence orgLaborPersistence;
4532 @BeanReference(type = PasswordPolicyPersistence.class)
4533 protected PasswordPolicyPersistence passwordPolicyPersistence;
4534 @BeanReference(type = PasswordPolicyRelPersistence.class)
4535 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
4536 @BeanReference(type = PasswordTrackerPersistence.class)
4537 protected PasswordTrackerPersistence passwordTrackerPersistence;
4538 @BeanReference(type = PermissionPersistence.class)
4539 protected PermissionPersistence permissionPersistence;
4540 @BeanReference(type = PhonePersistence.class)
4541 protected PhonePersistence phonePersistence;
4542 @BeanReference(type = PluginSettingPersistence.class)
4543 protected PluginSettingPersistence pluginSettingPersistence;
4544 @BeanReference(type = PortletPersistence.class)
4545 protected PortletPersistence portletPersistence;
4546 @BeanReference(type = PortletItemPersistence.class)
4547 protected PortletItemPersistence portletItemPersistence;
4548 @BeanReference(type = PortletPreferencesPersistence.class)
4549 protected PortletPreferencesPersistence portletPreferencesPersistence;
4550 @BeanReference(type = RegionPersistence.class)
4551 protected RegionPersistence regionPersistence;
4552 @BeanReference(type = ReleasePersistence.class)
4553 protected ReleasePersistence releasePersistence;
4554 @BeanReference(type = ResourcePersistence.class)
4555 protected ResourcePersistence resourcePersistence;
4556 @BeanReference(type = ResourceActionPersistence.class)
4557 protected ResourceActionPersistence resourceActionPersistence;
4558 @BeanReference(type = ResourceCodePersistence.class)
4559 protected ResourceCodePersistence resourceCodePersistence;
4560 @BeanReference(type = ResourcePermissionPersistence.class)
4561 protected ResourcePermissionPersistence resourcePermissionPersistence;
4562 @BeanReference(type = RolePersistence.class)
4563 protected RolePersistence rolePersistence;
4564 @BeanReference(type = ServiceComponentPersistence.class)
4565 protected ServiceComponentPersistence serviceComponentPersistence;
4566 @BeanReference(type = ShardPersistence.class)
4567 protected ShardPersistence shardPersistence;
4568 @BeanReference(type = SubscriptionPersistence.class)
4569 protected SubscriptionPersistence subscriptionPersistence;
4570 @BeanReference(type = TicketPersistence.class)
4571 protected TicketPersistence ticketPersistence;
4572 @BeanReference(type = TeamPersistence.class)
4573 protected TeamPersistence teamPersistence;
4574 @BeanReference(type = UserPersistence.class)
4575 protected UserPersistence userPersistence;
4576 @BeanReference(type = UserGroupPersistence.class)
4577 protected UserGroupPersistence userGroupPersistence;
4578 @BeanReference(type = UserGroupGroupRolePersistence.class)
4579 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
4580 @BeanReference(type = UserGroupRolePersistence.class)
4581 protected UserGroupRolePersistence userGroupRolePersistence;
4582 @BeanReference(type = UserIdMapperPersistence.class)
4583 protected UserIdMapperPersistence userIdMapperPersistence;
4584 @BeanReference(type = UserTrackerPersistence.class)
4585 protected UserTrackerPersistence userTrackerPersistence;
4586 @BeanReference(type = UserTrackerPathPersistence.class)
4587 protected UserTrackerPathPersistence userTrackerPathPersistence;
4588 @BeanReference(type = WebDAVPropsPersistence.class)
4589 protected WebDAVPropsPersistence webDAVPropsPersistence;
4590 @BeanReference(type = WebsitePersistence.class)
4591 protected WebsitePersistence websitePersistence;
4592 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
4593 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
4594 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
4595 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
4596 protected ContainsGroup containsGroup;
4597 protected AddGroup addGroup;
4598 protected ClearGroups clearGroups;
4599 protected RemoveGroup removeGroup;
4600 protected ContainsPermission containsPermission;
4601 protected AddPermission addPermission;
4602 protected ClearPermissions clearPermissions;
4603 protected RemovePermission removePermission;
4604 protected ContainsUser containsUser;
4605 protected AddUser addUser;
4606 protected ClearUsers clearUsers;
4607 protected RemoveUser removeUser;
4608
4609 protected class ContainsGroup {
4610 protected ContainsGroup(RolePersistenceImpl persistenceImpl) {
4611 super();
4612
4613 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4614 _SQL_CONTAINSGROUP,
4615 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4616 RowMapper.COUNT);
4617 }
4618
4619 protected boolean contains(long roleId, long groupId) {
4620 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4621 new Long(roleId), new Long(groupId)
4622 });
4623
4624 if (results.size() > 0) {
4625 Integer count = results.get(0);
4626
4627 if (count.intValue() > 0) {
4628 return true;
4629 }
4630 }
4631
4632 return false;
4633 }
4634
4635 private MappingSqlQuery<Integer> _mappingSqlQuery;
4636 }
4637
4638 protected class AddGroup {
4639 protected AddGroup(RolePersistenceImpl persistenceImpl) {
4640 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4641 "INSERT INTO Groups_Roles (roleId, groupId) VALUES (?, ?)",
4642 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4643 _persistenceImpl = persistenceImpl;
4644 }
4645
4646 protected void add(long roleId, long groupId) throws SystemException {
4647 if (!_persistenceImpl.containsGroup.contains(roleId, groupId)) {
4648 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4649
4650 for (ModelListener<Role> listener : listeners) {
4651 listener.onBeforeAddAssociation(roleId,
4652 com.liferay.portal.model.Group.class.getName(), groupId);
4653 }
4654
4655 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4656 listener.onBeforeAddAssociation(groupId,
4657 Role.class.getName(), roleId);
4658 }
4659
4660 _sqlUpdate.update(new Object[] {
4661 new Long(roleId), new Long(groupId)
4662 });
4663
4664 for (ModelListener<Role> listener : listeners) {
4665 listener.onAfterAddAssociation(roleId,
4666 com.liferay.portal.model.Group.class.getName(), groupId);
4667 }
4668
4669 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4670 listener.onAfterAddAssociation(groupId,
4671 Role.class.getName(), roleId);
4672 }
4673 }
4674 }
4675
4676 private SqlUpdate _sqlUpdate;
4677 private RolePersistenceImpl _persistenceImpl;
4678 }
4679
4680 protected class ClearGroups {
4681 protected ClearGroups(RolePersistenceImpl persistenceImpl) {
4682 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4683 "DELETE FROM Groups_Roles WHERE roleId = ?",
4684 new int[] { java.sql.Types.BIGINT });
4685 }
4686
4687 protected void clear(long roleId) throws SystemException {
4688 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4689
4690 List<com.liferay.portal.model.Group> groups = null;
4691
4692 if ((listeners.length > 0) || (groupListeners.length > 0)) {
4693 groups = getGroups(roleId);
4694
4695 for (com.liferay.portal.model.Group group : groups) {
4696 for (ModelListener<Role> listener : listeners) {
4697 listener.onBeforeRemoveAssociation(roleId,
4698 com.liferay.portal.model.Group.class.getName(),
4699 group.getPrimaryKey());
4700 }
4701
4702 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4703 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
4704 Role.class.getName(), roleId);
4705 }
4706 }
4707 }
4708
4709 _sqlUpdate.update(new Object[] { new Long(roleId) });
4710
4711 if ((listeners.length > 0) || (groupListeners.length > 0)) {
4712 for (com.liferay.portal.model.Group group : groups) {
4713 for (ModelListener<Role> listener : listeners) {
4714 listener.onAfterRemoveAssociation(roleId,
4715 com.liferay.portal.model.Group.class.getName(),
4716 group.getPrimaryKey());
4717 }
4718
4719 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4720 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
4721 Role.class.getName(), roleId);
4722 }
4723 }
4724 }
4725 }
4726
4727 private SqlUpdate _sqlUpdate;
4728 }
4729
4730 protected class RemoveGroup {
4731 protected RemoveGroup(RolePersistenceImpl persistenceImpl) {
4732 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4733 "DELETE FROM Groups_Roles WHERE roleId = ? AND groupId = ?",
4734 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4735 _persistenceImpl = persistenceImpl;
4736 }
4737
4738 protected void remove(long roleId, long groupId)
4739 throws SystemException {
4740 if (_persistenceImpl.containsGroup.contains(roleId, groupId)) {
4741 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
4742
4743 for (ModelListener<Role> listener : listeners) {
4744 listener.onBeforeRemoveAssociation(roleId,
4745 com.liferay.portal.model.Group.class.getName(), groupId);
4746 }
4747
4748 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4749 listener.onBeforeRemoveAssociation(groupId,
4750 Role.class.getName(), roleId);
4751 }
4752
4753 _sqlUpdate.update(new Object[] {
4754 new Long(roleId), new Long(groupId)
4755 });
4756
4757 for (ModelListener<Role> listener : listeners) {
4758 listener.onAfterRemoveAssociation(roleId,
4759 com.liferay.portal.model.Group.class.getName(), groupId);
4760 }
4761
4762 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
4763 listener.onAfterRemoveAssociation(groupId,
4764 Role.class.getName(), roleId);
4765 }
4766 }
4767 }
4768
4769 private SqlUpdate _sqlUpdate;
4770 private RolePersistenceImpl _persistenceImpl;
4771 }
4772
4773 protected class ContainsPermission {
4774 protected ContainsPermission(RolePersistenceImpl persistenceImpl) {
4775 super();
4776
4777 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4778 _SQL_CONTAINSPERMISSION,
4779 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4780 RowMapper.COUNT);
4781 }
4782
4783 protected boolean contains(long roleId, long permissionId) {
4784 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4785 new Long(roleId), new Long(permissionId)
4786 });
4787
4788 if (results.size() > 0) {
4789 Integer count = results.get(0);
4790
4791 if (count.intValue() > 0) {
4792 return true;
4793 }
4794 }
4795
4796 return false;
4797 }
4798
4799 private MappingSqlQuery<Integer> _mappingSqlQuery;
4800 }
4801
4802 protected class AddPermission {
4803 protected AddPermission(RolePersistenceImpl persistenceImpl) {
4804 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4805 "INSERT INTO Roles_Permissions (roleId, permissionId) VALUES (?, ?)",
4806 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4807 _persistenceImpl = persistenceImpl;
4808 }
4809
4810 protected void add(long roleId, long permissionId)
4811 throws SystemException {
4812 if (!_persistenceImpl.containsPermission.contains(roleId,
4813 permissionId)) {
4814 ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4815 permissionPersistence.getListeners();
4816
4817 for (ModelListener<Role> listener : listeners) {
4818 listener.onBeforeAddAssociation(roleId,
4819 com.liferay.portal.model.Permission.class.getName(),
4820 permissionId);
4821 }
4822
4823 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4824 listener.onBeforeAddAssociation(permissionId,
4825 Role.class.getName(), roleId);
4826 }
4827
4828 _sqlUpdate.update(new Object[] {
4829 new Long(roleId), new Long(permissionId)
4830 });
4831
4832 for (ModelListener<Role> listener : listeners) {
4833 listener.onAfterAddAssociation(roleId,
4834 com.liferay.portal.model.Permission.class.getName(),
4835 permissionId);
4836 }
4837
4838 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4839 listener.onAfterAddAssociation(permissionId,
4840 Role.class.getName(), roleId);
4841 }
4842 }
4843 }
4844
4845 private SqlUpdate _sqlUpdate;
4846 private RolePersistenceImpl _persistenceImpl;
4847 }
4848
4849 protected class ClearPermissions {
4850 protected ClearPermissions(RolePersistenceImpl persistenceImpl) {
4851 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4852 "DELETE FROM Roles_Permissions WHERE roleId = ?",
4853 new int[] { java.sql.Types.BIGINT });
4854 }
4855
4856 protected void clear(long roleId) throws SystemException {
4857 ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4858 permissionPersistence.getListeners();
4859
4860 List<com.liferay.portal.model.Permission> permissions = null;
4861
4862 if ((listeners.length > 0) || (permissionListeners.length > 0)) {
4863 permissions = getPermissions(roleId);
4864
4865 for (com.liferay.portal.model.Permission permission : permissions) {
4866 for (ModelListener<Role> listener : listeners) {
4867 listener.onBeforeRemoveAssociation(roleId,
4868 com.liferay.portal.model.Permission.class.getName(),
4869 permission.getPrimaryKey());
4870 }
4871
4872 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4873 listener.onBeforeRemoveAssociation(permission.getPrimaryKey(),
4874 Role.class.getName(), roleId);
4875 }
4876 }
4877 }
4878
4879 _sqlUpdate.update(new Object[] { new Long(roleId) });
4880
4881 if ((listeners.length > 0) || (permissionListeners.length > 0)) {
4882 for (com.liferay.portal.model.Permission permission : permissions) {
4883 for (ModelListener<Role> listener : listeners) {
4884 listener.onAfterRemoveAssociation(roleId,
4885 com.liferay.portal.model.Permission.class.getName(),
4886 permission.getPrimaryKey());
4887 }
4888
4889 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4890 listener.onAfterRemoveAssociation(permission.getPrimaryKey(),
4891 Role.class.getName(), roleId);
4892 }
4893 }
4894 }
4895 }
4896
4897 private SqlUpdate _sqlUpdate;
4898 }
4899
4900 protected class RemovePermission {
4901 protected RemovePermission(RolePersistenceImpl persistenceImpl) {
4902 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4903 "DELETE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?",
4904 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4905 _persistenceImpl = persistenceImpl;
4906 }
4907
4908 protected void remove(long roleId, long permissionId)
4909 throws SystemException {
4910 if (_persistenceImpl.containsPermission.contains(roleId,
4911 permissionId)) {
4912 ModelListener<com.liferay.portal.model.Permission>[] permissionListeners =
4913 permissionPersistence.getListeners();
4914
4915 for (ModelListener<Role> listener : listeners) {
4916 listener.onBeforeRemoveAssociation(roleId,
4917 com.liferay.portal.model.Permission.class.getName(),
4918 permissionId);
4919 }
4920
4921 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4922 listener.onBeforeRemoveAssociation(permissionId,
4923 Role.class.getName(), roleId);
4924 }
4925
4926 _sqlUpdate.update(new Object[] {
4927 new Long(roleId), new Long(permissionId)
4928 });
4929
4930 for (ModelListener<Role> listener : listeners) {
4931 listener.onAfterRemoveAssociation(roleId,
4932 com.liferay.portal.model.Permission.class.getName(),
4933 permissionId);
4934 }
4935
4936 for (ModelListener<com.liferay.portal.model.Permission> listener : permissionListeners) {
4937 listener.onAfterRemoveAssociation(permissionId,
4938 Role.class.getName(), roleId);
4939 }
4940 }
4941 }
4942
4943 private SqlUpdate _sqlUpdate;
4944 private RolePersistenceImpl _persistenceImpl;
4945 }
4946
4947 protected class ContainsUser {
4948 protected ContainsUser(RolePersistenceImpl persistenceImpl) {
4949 super();
4950
4951 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
4952 _SQL_CONTAINSUSER,
4953 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
4954 RowMapper.COUNT);
4955 }
4956
4957 protected boolean contains(long roleId, long userId) {
4958 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
4959 new Long(roleId), new Long(userId)
4960 });
4961
4962 if (results.size() > 0) {
4963 Integer count = results.get(0);
4964
4965 if (count.intValue() > 0) {
4966 return true;
4967 }
4968 }
4969
4970 return false;
4971 }
4972
4973 private MappingSqlQuery<Integer> _mappingSqlQuery;
4974 }
4975
4976 protected class AddUser {
4977 protected AddUser(RolePersistenceImpl persistenceImpl) {
4978 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
4979 "INSERT INTO Users_Roles (roleId, userId) VALUES (?, ?)",
4980 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
4981 _persistenceImpl = persistenceImpl;
4982 }
4983
4984 protected void add(long roleId, long userId) throws SystemException {
4985 if (!_persistenceImpl.containsUser.contains(roleId, userId)) {
4986 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
4987
4988 for (ModelListener<Role> listener : listeners) {
4989 listener.onBeforeAddAssociation(roleId,
4990 com.liferay.portal.model.User.class.getName(), userId);
4991 }
4992
4993 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
4994 listener.onBeforeAddAssociation(userId,
4995 Role.class.getName(), roleId);
4996 }
4997
4998 _sqlUpdate.update(new Object[] {
4999 new Long(roleId), new Long(userId)
5000 });
5001
5002 for (ModelListener<Role> listener : listeners) {
5003 listener.onAfterAddAssociation(roleId,
5004 com.liferay.portal.model.User.class.getName(), userId);
5005 }
5006
5007 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
5008 listener.onAfterAddAssociation(userId,
5009 Role.class.getName(), roleId);
5010 }
5011 }
5012 }
5013
5014 private SqlUpdate _sqlUpdate;
5015 private RolePersistenceImpl _persistenceImpl;
5016 }
5017
5018 protected class ClearUsers {
5019 protected ClearUsers(RolePersistenceImpl persistenceImpl) {
5020 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5021 "DELETE FROM Users_Roles WHERE roleId = ?",
5022 new int[] { java.sql.Types.BIGINT });
5023 }
5024
5025 protected void clear(long roleId) throws SystemException {
5026 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
5027
5028 List<com.liferay.portal.model.User> users = null;
5029
5030 if ((listeners.length > 0) || (userListeners.length > 0)) {
5031 users = getUsers(roleId);
5032
5033 for (com.liferay.portal.model.User user : users) {
5034 for (ModelListener<Role> listener : listeners) {
5035 listener.onBeforeRemoveAssociation(roleId,
5036 com.liferay.portal.model.User.class.getName(),
5037 user.getPrimaryKey());
5038 }
5039
5040 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
5041 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
5042 Role.class.getName(), roleId);
5043 }
5044 }
5045 }
5046
5047 _sqlUpdate.update(new Object[] { new Long(roleId) });
5048
5049 if ((listeners.length > 0) || (userListeners.length > 0)) {
5050 for (com.liferay.portal.model.User user : users) {
5051 for (ModelListener<Role> listener : listeners) {
5052 listener.onAfterRemoveAssociation(roleId,
5053 com.liferay.portal.model.User.class.getName(),
5054 user.getPrimaryKey());
5055 }
5056
5057 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
5058 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
5059 Role.class.getName(), roleId);
5060 }
5061 }
5062 }
5063 }
5064
5065 private SqlUpdate _sqlUpdate;
5066 }
5067
5068 protected class RemoveUser {
5069 protected RemoveUser(RolePersistenceImpl persistenceImpl) {
5070 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
5071 "DELETE FROM Users_Roles WHERE roleId = ? AND userId = ?",
5072 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
5073 _persistenceImpl = persistenceImpl;
5074 }
5075
5076 protected void remove(long roleId, long userId)
5077 throws SystemException {
5078 if (_persistenceImpl.containsUser.contains(roleId, userId)) {
5079 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
5080
5081 for (ModelListener<Role> listener : listeners) {
5082 listener.onBeforeRemoveAssociation(roleId,
5083 com.liferay.portal.model.User.class.getName(), userId);
5084 }
5085
5086 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
5087 listener.onBeforeRemoveAssociation(userId,
5088 Role.class.getName(), roleId);
5089 }
5090
5091 _sqlUpdate.update(new Object[] {
5092 new Long(roleId), new Long(userId)
5093 });
5094
5095 for (ModelListener<Role> listener : listeners) {
5096 listener.onAfterRemoveAssociation(roleId,
5097 com.liferay.portal.model.User.class.getName(), userId);
5098 }
5099
5100 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
5101 listener.onAfterRemoveAssociation(userId,
5102 Role.class.getName(), roleId);
5103 }
5104 }
5105 }
5106
5107 private SqlUpdate _sqlUpdate;
5108 private RolePersistenceImpl _persistenceImpl;
5109 }
5110
5111 private static final String _SQL_SELECT_ROLE = "SELECT role FROM Role role";
5112 private static final String _SQL_SELECT_ROLE_WHERE = "SELECT role FROM Role role WHERE ";
5113 private static final String _SQL_COUNT_ROLE = "SELECT COUNT(role) FROM Role role";
5114 private static final String _SQL_COUNT_ROLE_WHERE = "SELECT COUNT(role) FROM Role role WHERE ";
5115 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Roles ON (Groups_Roles.groupId = Group_.groupId) WHERE (Groups_Roles.roleId = ?)";
5116 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ?";
5117 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Roles WHERE roleId = ? AND groupId = ?";
5118 private static final String _SQL_GETPERMISSIONS = "SELECT {Permission_.*} FROM Permission_ INNER JOIN Roles_Permissions ON (Roles_Permissions.permissionId = Permission_.permissionId) WHERE (Roles_Permissions.roleId = ?)";
5119 private static final String _SQL_GETPERMISSIONSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ?";
5120 private static final String _SQL_CONTAINSPERMISSION = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE roleId = ? AND permissionId = ?";
5121 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Roles ON (Users_Roles.userId = User_.userId) WHERE (Users_Roles.roleId = ?)";
5122 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ?";
5123 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Roles WHERE roleId = ? AND userId = ?";
5124 private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "role.companyId = ?";
5125 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_1 = "role.subtype IS NULL";
5126 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_2 = "role.subtype = ?";
5127 private static final String _FINDER_COLUMN_SUBTYPE_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
5128 private static final String _FINDER_COLUMN_C_N_COMPANYID_2 = "role.companyId = ? AND ";
5129 private static final String _FINDER_COLUMN_C_N_NAME_1 = "role.name IS NULL";
5130 private static final String _FINDER_COLUMN_C_N_NAME_2 = "role.name = ?";
5131 private static final String _FINDER_COLUMN_C_N_NAME_3 = "(role.name IS NULL OR role.name = ?)";
5132 private static final String _FINDER_COLUMN_T_S_TYPE_2 = "role.type = ? AND ";
5133 private static final String _FINDER_COLUMN_T_S_SUBTYPE_1 = "role.subtype IS NULL";
5134 private static final String _FINDER_COLUMN_T_S_SUBTYPE_2 = "role.subtype = ?";
5135 private static final String _FINDER_COLUMN_T_S_SUBTYPE_3 = "(role.subtype IS NULL OR role.subtype = ?)";
5136 private static final String _FINDER_COLUMN_C_C_C_COMPANYID_2 = "role.companyId = ? AND ";
5137 private static final String _FINDER_COLUMN_C_C_C_CLASSNAMEID_2 = "role.classNameId = ? AND ";
5138 private static final String _FINDER_COLUMN_C_C_C_CLASSPK_2 = "role.classPK = ?";
5139 private static final String _FILTER_SQL_SELECT_ROLE_WHERE = "SELECT DISTINCT {role.*} FROM Role_ role WHERE ";
5140 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_1 =
5141 "SELECT {Role_.*} FROM (SELECT DISTINCT role.roleId FROM Role_ role WHERE ";
5142 private static final String _FILTER_SQL_SELECT_ROLE_NO_INLINE_DISTINCT_WHERE_2 =
5143 ") TEMP_TABLE INNER JOIN Role_ ON TEMP_TABLE.roleId = Role_.roleId";
5144 private static final String _FILTER_SQL_COUNT_ROLE_WHERE = "SELECT COUNT(DISTINCT role.roleId) AS COUNT_VALUE FROM Role_ role WHERE ";
5145 private static final String _FILTER_COLUMN_PK = "role.roleId";
5146 private static final String _FILTER_COLUMN_USERID = null;
5147 private static final String _FILTER_ENTITY_ALIAS = "role";
5148 private static final String _FILTER_ENTITY_TABLE = "Role_";
5149 private static final String _ORDER_BY_ENTITY_ALIAS = "role.";
5150 private static final String _ORDER_BY_ENTITY_TABLE = "Role_.";
5151 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Role exists with the primary key ";
5152 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Role exists with the key {";
5153 private static Log _log = LogFactoryUtil.getLog(RolePersistenceImpl.class);
5154 }