001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchPermissionException;
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.Permission;
047 import com.liferay.portal.model.impl.PermissionImpl;
048 import com.liferay.portal.model.impl.PermissionModelImpl;
049 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
050
051 import java.io.Serializable;
052
053 import java.util.ArrayList;
054 import java.util.Collections;
055 import java.util.List;
056 import java.util.Set;
057
058
074 public class PermissionPersistenceImpl extends BasePersistenceImpl<Permission>
075 implements PermissionPersistence {
076 public static final String FINDER_CLASS_NAME_ENTITY = PermissionImpl.class.getName();
077 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
078 ".List";
079 public static final FinderPath FINDER_PATH_FIND_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
080 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
081 "findByResourceId",
082 new String[] {
083 Long.class.getName(),
084
085 "java.lang.Integer", "java.lang.Integer",
086 "com.liferay.portal.kernel.util.OrderByComparator"
087 });
088 public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
089 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
090 "countByResourceId", new String[] { Long.class.getName() });
091 public static final FinderPath FINDER_PATH_FETCH_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
092 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
093 "fetchByA_R",
094 new String[] { String.class.getName(), Long.class.getName() });
095 public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
096 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097 "countByA_R",
098 new String[] { String.class.getName(), Long.class.getName() });
099 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
100 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
101 "findAll", new String[0]);
102 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
103 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "countAll", new String[0]);
105
106
111 public void cacheResult(Permission permission) {
112 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
113 PermissionImpl.class, permission.getPrimaryKey(), permission);
114
115 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
116 new Object[] {
117 permission.getActionId(), new Long(permission.getResourceId())
118 }, permission);
119 }
120
121
126 public void cacheResult(List<Permission> permissions) {
127 for (Permission permission : permissions) {
128 if (EntityCacheUtil.getResult(
129 PermissionModelImpl.ENTITY_CACHE_ENABLED,
130 PermissionImpl.class, permission.getPrimaryKey(), this) == null) {
131 cacheResult(permission);
132 }
133 }
134 }
135
136
143 public void clearCache() {
144 CacheRegistryUtil.clear(PermissionImpl.class.getName());
145 EntityCacheUtil.clearCache(PermissionImpl.class.getName());
146 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
147 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
148 }
149
150
157 public void clearCache(Permission permission) {
158 EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
159 PermissionImpl.class, permission.getPrimaryKey());
160
161 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
162 new Object[] {
163 permission.getActionId(), new Long(permission.getResourceId())
164 });
165 }
166
167
173 public Permission create(long permissionId) {
174 Permission permission = new PermissionImpl();
175
176 permission.setNew(true);
177 permission.setPrimaryKey(permissionId);
178
179 return permission;
180 }
181
182
190 public Permission remove(Serializable primaryKey)
191 throws NoSuchModelException, SystemException {
192 return remove(((Long)primaryKey).longValue());
193 }
194
195
203 public Permission remove(long permissionId)
204 throws NoSuchPermissionException, SystemException {
205 Session session = null;
206
207 try {
208 session = openSession();
209
210 Permission permission = (Permission)session.get(PermissionImpl.class,
211 new Long(permissionId));
212
213 if (permission == null) {
214 if (_log.isWarnEnabled()) {
215 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
216 }
217
218 throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
219 permissionId);
220 }
221
222 return remove(permission);
223 }
224 catch (NoSuchPermissionException nsee) {
225 throw nsee;
226 }
227 catch (Exception e) {
228 throw processException(e);
229 }
230 finally {
231 closeSession(session);
232 }
233 }
234
235 protected Permission removeImpl(Permission permission)
236 throws SystemException {
237 permission = toUnwrappedModel(permission);
238
239 try {
240 clearGroups.clear(permission.getPrimaryKey());
241 }
242 catch (Exception e) {
243 throw processException(e);
244 }
245 finally {
246 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
247 }
248
249 try {
250 clearRoles.clear(permission.getPrimaryKey());
251 }
252 catch (Exception e) {
253 throw processException(e);
254 }
255 finally {
256 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
257 }
258
259 try {
260 clearUsers.clear(permission.getPrimaryKey());
261 }
262 catch (Exception e) {
263 throw processException(e);
264 }
265 finally {
266 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
267 }
268
269 Session session = null;
270
271 try {
272 session = openSession();
273
274 BatchSessionUtil.delete(session, permission);
275 }
276 catch (Exception e) {
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282
283 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
284
285 PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
286
287 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
288 new Object[] {
289 permissionModelImpl.getActionId(),
290 new Long(permissionModelImpl.getResourceId())
291 });
292
293 EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
294 PermissionImpl.class, permission.getPrimaryKey());
295
296 return permission;
297 }
298
299 public Permission updateImpl(
300 com.liferay.portal.model.Permission permission, boolean merge)
301 throws SystemException {
302 permission = toUnwrappedModel(permission);
303
304 boolean isNew = permission.isNew();
305
306 PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
307
308 Session session = null;
309
310 try {
311 session = openSession();
312
313 BatchSessionUtil.update(session, permission, merge);
314
315 permission.setNew(false);
316 }
317 catch (Exception e) {
318 throw processException(e);
319 }
320 finally {
321 closeSession(session);
322 }
323
324 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
325
326 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
327 PermissionImpl.class, permission.getPrimaryKey(), permission);
328
329 if (!isNew &&
330 (!Validator.equals(permission.getActionId(),
331 permissionModelImpl.getOriginalActionId()) ||
332 (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
333 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
334 new Object[] {
335 permissionModelImpl.getOriginalActionId(),
336 new Long(permissionModelImpl.getOriginalResourceId())
337 });
338 }
339
340 if (isNew ||
341 (!Validator.equals(permission.getActionId(),
342 permissionModelImpl.getOriginalActionId()) ||
343 (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
344 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
345 new Object[] {
346 permission.getActionId(),
347 new Long(permission.getResourceId())
348 }, permission);
349 }
350
351 return permission;
352 }
353
354 protected Permission toUnwrappedModel(Permission permission) {
355 if (permission instanceof PermissionImpl) {
356 return permission;
357 }
358
359 PermissionImpl permissionImpl = new PermissionImpl();
360
361 permissionImpl.setNew(permission.isNew());
362 permissionImpl.setPrimaryKey(permission.getPrimaryKey());
363
364 permissionImpl.setPermissionId(permission.getPermissionId());
365 permissionImpl.setCompanyId(permission.getCompanyId());
366 permissionImpl.setActionId(permission.getActionId());
367 permissionImpl.setResourceId(permission.getResourceId());
368
369 return permissionImpl;
370 }
371
372
380 public Permission findByPrimaryKey(Serializable primaryKey)
381 throws NoSuchModelException, SystemException {
382 return findByPrimaryKey(((Long)primaryKey).longValue());
383 }
384
385
393 public Permission findByPrimaryKey(long permissionId)
394 throws NoSuchPermissionException, SystemException {
395 Permission permission = fetchByPrimaryKey(permissionId);
396
397 if (permission == null) {
398 if (_log.isWarnEnabled()) {
399 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
400 }
401
402 throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
403 permissionId);
404 }
405
406 return permission;
407 }
408
409
416 public Permission fetchByPrimaryKey(Serializable primaryKey)
417 throws SystemException {
418 return fetchByPrimaryKey(((Long)primaryKey).longValue());
419 }
420
421
428 public Permission fetchByPrimaryKey(long permissionId)
429 throws SystemException {
430 Permission permission = (Permission)EntityCacheUtil.getResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
431 PermissionImpl.class, permissionId, this);
432
433 if (permission == null) {
434 Session session = null;
435
436 try {
437 session = openSession();
438
439 permission = (Permission)session.get(PermissionImpl.class,
440 new Long(permissionId));
441 }
442 catch (Exception e) {
443 throw processException(e);
444 }
445 finally {
446 if (permission != null) {
447 cacheResult(permission);
448 }
449
450 closeSession(session);
451 }
452 }
453
454 return permission;
455 }
456
457
464 public List<Permission> findByResourceId(long resourceId)
465 throws SystemException {
466 return findByResourceId(resourceId, QueryUtil.ALL_POS,
467 QueryUtil.ALL_POS, null);
468 }
469
470
483 public List<Permission> findByResourceId(long resourceId, int start, int end)
484 throws SystemException {
485 return findByResourceId(resourceId, start, end, null);
486 }
487
488
502 public List<Permission> findByResourceId(long resourceId, int start,
503 int end, OrderByComparator orderByComparator) throws SystemException {
504 Object[] finderArgs = new Object[] {
505 resourceId,
506
507 String.valueOf(start), String.valueOf(end),
508 String.valueOf(orderByComparator)
509 };
510
511 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RESOURCEID,
512 finderArgs, this);
513
514 if (list == null) {
515 StringBundler query = null;
516
517 if (orderByComparator != null) {
518 query = new StringBundler(3 +
519 (orderByComparator.getOrderByFields().length * 3));
520 }
521 else {
522 query = new StringBundler(2);
523 }
524
525 query.append(_SQL_SELECT_PERMISSION_WHERE);
526
527 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
528
529 if (orderByComparator != null) {
530 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
531 orderByComparator);
532 }
533
534 String sql = query.toString();
535
536 Session session = null;
537
538 try {
539 session = openSession();
540
541 Query q = session.createQuery(sql);
542
543 QueryPos qPos = QueryPos.getInstance(q);
544
545 qPos.add(resourceId);
546
547 list = (List<Permission>)QueryUtil.list(q, getDialect(), start,
548 end);
549 }
550 catch (Exception e) {
551 throw processException(e);
552 }
553 finally {
554 if (list == null) {
555 FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_RESOURCEID,
556 finderArgs);
557 }
558 else {
559 cacheResult(list);
560
561 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RESOURCEID,
562 finderArgs, list);
563 }
564
565 closeSession(session);
566 }
567 }
568
569 return list;
570 }
571
572
585 public Permission findByResourceId_First(long resourceId,
586 OrderByComparator orderByComparator)
587 throws NoSuchPermissionException, SystemException {
588 List<Permission> list = findByResourceId(resourceId, 0, 1,
589 orderByComparator);
590
591 if (list.isEmpty()) {
592 StringBundler msg = new StringBundler(4);
593
594 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
595
596 msg.append("resourceId=");
597 msg.append(resourceId);
598
599 msg.append(StringPool.CLOSE_CURLY_BRACE);
600
601 throw new NoSuchPermissionException(msg.toString());
602 }
603 else {
604 return list.get(0);
605 }
606 }
607
608
621 public Permission findByResourceId_Last(long resourceId,
622 OrderByComparator orderByComparator)
623 throws NoSuchPermissionException, SystemException {
624 int count = countByResourceId(resourceId);
625
626 List<Permission> list = findByResourceId(resourceId, count - 1, count,
627 orderByComparator);
628
629 if (list.isEmpty()) {
630 StringBundler msg = new StringBundler(4);
631
632 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
633
634 msg.append("resourceId=");
635 msg.append(resourceId);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 throw new NoSuchPermissionException(msg.toString());
640 }
641 else {
642 return list.get(0);
643 }
644 }
645
646
660 public Permission[] findByResourceId_PrevAndNext(long permissionId,
661 long resourceId, OrderByComparator orderByComparator)
662 throws NoSuchPermissionException, SystemException {
663 Permission permission = findByPrimaryKey(permissionId);
664
665 Session session = null;
666
667 try {
668 session = openSession();
669
670 Permission[] array = new PermissionImpl[3];
671
672 array[0] = getByResourceId_PrevAndNext(session, permission,
673 resourceId, orderByComparator, true);
674
675 array[1] = permission;
676
677 array[2] = getByResourceId_PrevAndNext(session, permission,
678 resourceId, orderByComparator, false);
679
680 return array;
681 }
682 catch (Exception e) {
683 throw processException(e);
684 }
685 finally {
686 closeSession(session);
687 }
688 }
689
690 protected Permission getByResourceId_PrevAndNext(Session session,
691 Permission permission, long resourceId,
692 OrderByComparator orderByComparator, boolean previous) {
693 StringBundler query = null;
694
695 if (orderByComparator != null) {
696 query = new StringBundler(6 +
697 (orderByComparator.getOrderByFields().length * 6));
698 }
699 else {
700 query = new StringBundler(3);
701 }
702
703 query.append(_SQL_SELECT_PERMISSION_WHERE);
704
705 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
706
707 if (orderByComparator != null) {
708 String[] orderByFields = orderByComparator.getOrderByFields();
709
710 if (orderByFields.length > 0) {
711 query.append(WHERE_AND);
712 }
713
714 for (int i = 0; i < orderByFields.length; i++) {
715 query.append(_ORDER_BY_ENTITY_ALIAS);
716 query.append(orderByFields[i]);
717
718 if ((i + 1) < orderByFields.length) {
719 if (orderByComparator.isAscending() ^ previous) {
720 query.append(WHERE_GREATER_THAN_HAS_NEXT);
721 }
722 else {
723 query.append(WHERE_LESSER_THAN_HAS_NEXT);
724 }
725 }
726 else {
727 if (orderByComparator.isAscending() ^ previous) {
728 query.append(WHERE_GREATER_THAN);
729 }
730 else {
731 query.append(WHERE_LESSER_THAN);
732 }
733 }
734 }
735
736 query.append(ORDER_BY_CLAUSE);
737
738 for (int i = 0; i < orderByFields.length; i++) {
739 query.append(_ORDER_BY_ENTITY_ALIAS);
740 query.append(orderByFields[i]);
741
742 if ((i + 1) < orderByFields.length) {
743 if (orderByComparator.isAscending() ^ previous) {
744 query.append(ORDER_BY_ASC_HAS_NEXT);
745 }
746 else {
747 query.append(ORDER_BY_DESC_HAS_NEXT);
748 }
749 }
750 else {
751 if (orderByComparator.isAscending() ^ previous) {
752 query.append(ORDER_BY_ASC);
753 }
754 else {
755 query.append(ORDER_BY_DESC);
756 }
757 }
758 }
759 }
760
761 String sql = query.toString();
762
763 Query q = session.createQuery(sql);
764
765 q.setFirstResult(0);
766 q.setMaxResults(2);
767
768 QueryPos qPos = QueryPos.getInstance(q);
769
770 qPos.add(resourceId);
771
772 if (orderByComparator != null) {
773 Object[] values = orderByComparator.getOrderByValues(permission);
774
775 for (Object value : values) {
776 qPos.add(value);
777 }
778 }
779
780 List<Permission> list = q.list();
781
782 if (list.size() == 2) {
783 return list.get(1);
784 }
785 else {
786 return null;
787 }
788 }
789
790
799 public Permission findByA_R(String actionId, long resourceId)
800 throws NoSuchPermissionException, SystemException {
801 Permission permission = fetchByA_R(actionId, resourceId);
802
803 if (permission == null) {
804 StringBundler msg = new StringBundler(6);
805
806 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
807
808 msg.append("actionId=");
809 msg.append(actionId);
810
811 msg.append(", resourceId=");
812 msg.append(resourceId);
813
814 msg.append(StringPool.CLOSE_CURLY_BRACE);
815
816 if (_log.isWarnEnabled()) {
817 _log.warn(msg.toString());
818 }
819
820 throw new NoSuchPermissionException(msg.toString());
821 }
822
823 return permission;
824 }
825
826
834 public Permission fetchByA_R(String actionId, long resourceId)
835 throws SystemException {
836 return fetchByA_R(actionId, resourceId, true);
837 }
838
839
847 public Permission fetchByA_R(String actionId, long resourceId,
848 boolean retrieveFromCache) throws SystemException {
849 Object[] finderArgs = new Object[] { actionId, resourceId };
850
851 Object result = null;
852
853 if (retrieveFromCache) {
854 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A_R,
855 finderArgs, this);
856 }
857
858 if (result == null) {
859 StringBundler query = new StringBundler(3);
860
861 query.append(_SQL_SELECT_PERMISSION_WHERE);
862
863 if (actionId == null) {
864 query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
865 }
866 else {
867 if (actionId.equals(StringPool.BLANK)) {
868 query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
869 }
870 else {
871 query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
872 }
873 }
874
875 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
876
877 String sql = query.toString();
878
879 Session session = null;
880
881 try {
882 session = openSession();
883
884 Query q = session.createQuery(sql);
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 if (actionId != null) {
889 qPos.add(actionId);
890 }
891
892 qPos.add(resourceId);
893
894 List<Permission> list = q.list();
895
896 result = list;
897
898 Permission permission = null;
899
900 if (list.isEmpty()) {
901 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
902 finderArgs, list);
903 }
904 else {
905 permission = list.get(0);
906
907 cacheResult(permission);
908
909 if ((permission.getActionId() == null) ||
910 !permission.getActionId().equals(actionId) ||
911 (permission.getResourceId() != resourceId)) {
912 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
913 finderArgs, permission);
914 }
915 }
916
917 return permission;
918 }
919 catch (Exception e) {
920 throw processException(e);
921 }
922 finally {
923 if (result == null) {
924 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
925 finderArgs);
926 }
927
928 closeSession(session);
929 }
930 }
931 else {
932 if (result instanceof List<?>) {
933 return null;
934 }
935 else {
936 return (Permission)result;
937 }
938 }
939 }
940
941
947 public List<Permission> findAll() throws SystemException {
948 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
949 }
950
951
963 public List<Permission> findAll(int start, int end)
964 throws SystemException {
965 return findAll(start, end, null);
966 }
967
968
981 public List<Permission> findAll(int start, int end,
982 OrderByComparator orderByComparator) throws SystemException {
983 Object[] finderArgs = new Object[] {
984 String.valueOf(start), String.valueOf(end),
985 String.valueOf(orderByComparator)
986 };
987
988 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
989 finderArgs, this);
990
991 if (list == null) {
992 StringBundler query = null;
993 String sql = null;
994
995 if (orderByComparator != null) {
996 query = new StringBundler(2 +
997 (orderByComparator.getOrderByFields().length * 3));
998
999 query.append(_SQL_SELECT_PERMISSION);
1000
1001 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1002 orderByComparator);
1003
1004 sql = query.toString();
1005 }
1006 else {
1007 sql = _SQL_SELECT_PERMISSION;
1008 }
1009
1010 Session session = null;
1011
1012 try {
1013 session = openSession();
1014
1015 Query q = session.createQuery(sql);
1016
1017 if (orderByComparator == null) {
1018 list = (List<Permission>)QueryUtil.list(q, getDialect(),
1019 start, end, false);
1020
1021 Collections.sort(list);
1022 }
1023 else {
1024 list = (List<Permission>)QueryUtil.list(q, getDialect(),
1025 start, end);
1026 }
1027 }
1028 catch (Exception e) {
1029 throw processException(e);
1030 }
1031 finally {
1032 if (list == null) {
1033 FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1034 finderArgs);
1035 }
1036 else {
1037 cacheResult(list);
1038
1039 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1040 list);
1041 }
1042
1043 closeSession(session);
1044 }
1045 }
1046
1047 return list;
1048 }
1049
1050
1056 public void removeByResourceId(long resourceId) throws SystemException {
1057 for (Permission permission : findByResourceId(resourceId)) {
1058 remove(permission);
1059 }
1060 }
1061
1062
1069 public void removeByA_R(String actionId, long resourceId)
1070 throws NoSuchPermissionException, SystemException {
1071 Permission permission = findByA_R(actionId, resourceId);
1072
1073 remove(permission);
1074 }
1075
1076
1081 public void removeAll() throws SystemException {
1082 for (Permission permission : findAll()) {
1083 remove(permission);
1084 }
1085 }
1086
1087
1094 public int countByResourceId(long resourceId) throws SystemException {
1095 Object[] finderArgs = new Object[] { resourceId };
1096
1097 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEID,
1098 finderArgs, this);
1099
1100 if (count == null) {
1101 StringBundler query = new StringBundler(2);
1102
1103 query.append(_SQL_COUNT_PERMISSION_WHERE);
1104
1105 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
1106
1107 String sql = query.toString();
1108
1109 Session session = null;
1110
1111 try {
1112 session = openSession();
1113
1114 Query q = session.createQuery(sql);
1115
1116 QueryPos qPos = QueryPos.getInstance(q);
1117
1118 qPos.add(resourceId);
1119
1120 count = (Long)q.uniqueResult();
1121 }
1122 catch (Exception e) {
1123 throw processException(e);
1124 }
1125 finally {
1126 if (count == null) {
1127 count = Long.valueOf(0);
1128 }
1129
1130 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEID,
1131 finderArgs, count);
1132
1133 closeSession(session);
1134 }
1135 }
1136
1137 return count.intValue();
1138 }
1139
1140
1148 public int countByA_R(String actionId, long resourceId)
1149 throws SystemException {
1150 Object[] finderArgs = new Object[] { actionId, resourceId };
1151
1152 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
1153 finderArgs, this);
1154
1155 if (count == null) {
1156 StringBundler query = new StringBundler(3);
1157
1158 query.append(_SQL_COUNT_PERMISSION_WHERE);
1159
1160 if (actionId == null) {
1161 query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
1162 }
1163 else {
1164 if (actionId.equals(StringPool.BLANK)) {
1165 query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
1166 }
1167 else {
1168 query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
1169 }
1170 }
1171
1172 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
1173
1174 String sql = query.toString();
1175
1176 Session session = null;
1177
1178 try {
1179 session = openSession();
1180
1181 Query q = session.createQuery(sql);
1182
1183 QueryPos qPos = QueryPos.getInstance(q);
1184
1185 if (actionId != null) {
1186 qPos.add(actionId);
1187 }
1188
1189 qPos.add(resourceId);
1190
1191 count = (Long)q.uniqueResult();
1192 }
1193 catch (Exception e) {
1194 throw processException(e);
1195 }
1196 finally {
1197 if (count == null) {
1198 count = Long.valueOf(0);
1199 }
1200
1201 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
1202 count);
1203
1204 closeSession(session);
1205 }
1206 }
1207
1208 return count.intValue();
1209 }
1210
1211
1217 public int countAll() throws SystemException {
1218 Object[] finderArgs = new Object[0];
1219
1220 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1221 finderArgs, this);
1222
1223 if (count == null) {
1224 Session session = null;
1225
1226 try {
1227 session = openSession();
1228
1229 Query q = session.createQuery(_SQL_COUNT_PERMISSION);
1230
1231 count = (Long)q.uniqueResult();
1232 }
1233 catch (Exception e) {
1234 throw processException(e);
1235 }
1236 finally {
1237 if (count == null) {
1238 count = Long.valueOf(0);
1239 }
1240
1241 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1242 count);
1243
1244 closeSession(session);
1245 }
1246 }
1247
1248 return count.intValue();
1249 }
1250
1251
1258 public List<com.liferay.portal.model.Group> getGroups(long pk)
1259 throws SystemException {
1260 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1261 }
1262
1263
1276 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1277 int end) throws SystemException {
1278 return getGroups(pk, start, end, null);
1279 }
1280
1281 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1282 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1283 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1284 "getGroups",
1285 new String[] {
1286 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1287 "com.liferay.portal.kernel.util.OrderByComparator"
1288 });
1289
1290
1304 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1305 int end, OrderByComparator orderByComparator) throws SystemException {
1306 Object[] finderArgs = new Object[] {
1307 pk, String.valueOf(start), String.valueOf(end),
1308 String.valueOf(orderByComparator)
1309 };
1310
1311 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1312 finderArgs, this);
1313
1314 if (list == null) {
1315 Session session = null;
1316
1317 try {
1318 session = openSession();
1319
1320 String sql = null;
1321
1322 if (orderByComparator != null) {
1323 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1324 .concat(orderByComparator.getOrderBy());
1325 }
1326 else {
1327 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1328 }
1329
1330 SQLQuery q = session.createSQLQuery(sql);
1331
1332 q.addEntity("Group_",
1333 com.liferay.portal.model.impl.GroupImpl.class);
1334
1335 QueryPos qPos = QueryPos.getInstance(q);
1336
1337 qPos.add(pk);
1338
1339 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1340 getDialect(), start, end);
1341 }
1342 catch (Exception e) {
1343 throw processException(e);
1344 }
1345 finally {
1346 if (list == null) {
1347 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
1348 finderArgs);
1349 }
1350 else {
1351 groupPersistence.cacheResult(list);
1352
1353 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
1354 finderArgs, list);
1355 }
1356
1357 closeSession(session);
1358 }
1359 }
1360
1361 return list;
1362 }
1363
1364 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1365 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1366 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1367 "getGroupsSize", new String[] { Long.class.getName() });
1368
1369
1376 public int getGroupsSize(long pk) throws SystemException {
1377 Object[] finderArgs = new Object[] { pk };
1378
1379 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1380 finderArgs, this);
1381
1382 if (count == null) {
1383 Session session = null;
1384
1385 try {
1386 session = openSession();
1387
1388 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1389
1390 q.addScalar(COUNT_COLUMN_NAME,
1391 com.liferay.portal.kernel.dao.orm.Type.LONG);
1392
1393 QueryPos qPos = QueryPos.getInstance(q);
1394
1395 qPos.add(pk);
1396
1397 count = (Long)q.uniqueResult();
1398 }
1399 catch (Exception e) {
1400 throw processException(e);
1401 }
1402 finally {
1403 if (count == null) {
1404 count = Long.valueOf(0);
1405 }
1406
1407 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1408 finderArgs, count);
1409
1410 closeSession(session);
1411 }
1412 }
1413
1414 return count.intValue();
1415 }
1416
1417 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1418 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1419 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1420 "containsGroup",
1421 new String[] { Long.class.getName(), Long.class.getName() });
1422
1423
1431 public boolean containsGroup(long pk, long groupPK)
1432 throws SystemException {
1433 Object[] finderArgs = new Object[] { pk, groupPK };
1434
1435 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1436 finderArgs, this);
1437
1438 if (value == null) {
1439 try {
1440 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1441 }
1442 catch (Exception e) {
1443 throw processException(e);
1444 }
1445 finally {
1446 if (value == null) {
1447 value = Boolean.FALSE;
1448 }
1449
1450 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1451 finderArgs, value);
1452 }
1453 }
1454
1455 return value.booleanValue();
1456 }
1457
1458
1465 public boolean containsGroups(long pk) throws SystemException {
1466 if (getGroupsSize(pk) > 0) {
1467 return true;
1468 }
1469 else {
1470 return false;
1471 }
1472 }
1473
1474
1481 public void addGroup(long pk, long groupPK) throws SystemException {
1482 try {
1483 addGroup.add(pk, groupPK);
1484 }
1485 catch (Exception e) {
1486 throw processException(e);
1487 }
1488 finally {
1489 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1490 }
1491 }
1492
1493
1500 public void addGroup(long pk, com.liferay.portal.model.Group group)
1501 throws SystemException {
1502 try {
1503 addGroup.add(pk, group.getPrimaryKey());
1504 }
1505 catch (Exception e) {
1506 throw processException(e);
1507 }
1508 finally {
1509 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1510 }
1511 }
1512
1513
1520 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1521 try {
1522 for (long groupPK : groupPKs) {
1523 addGroup.add(pk, groupPK);
1524 }
1525 }
1526 catch (Exception e) {
1527 throw processException(e);
1528 }
1529 finally {
1530 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1531 }
1532 }
1533
1534
1541 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1542 throws SystemException {
1543 try {
1544 for (com.liferay.portal.model.Group group : groups) {
1545 addGroup.add(pk, group.getPrimaryKey());
1546 }
1547 }
1548 catch (Exception e) {
1549 throw processException(e);
1550 }
1551 finally {
1552 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1553 }
1554 }
1555
1556
1562 public void clearGroups(long pk) throws SystemException {
1563 try {
1564 clearGroups.clear(pk);
1565 }
1566 catch (Exception e) {
1567 throw processException(e);
1568 }
1569 finally {
1570 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1571 }
1572 }
1573
1574
1581 public void removeGroup(long pk, long groupPK) throws SystemException {
1582 try {
1583 removeGroup.remove(pk, groupPK);
1584 }
1585 catch (Exception e) {
1586 throw processException(e);
1587 }
1588 finally {
1589 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1590 }
1591 }
1592
1593
1600 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1601 throws SystemException {
1602 try {
1603 removeGroup.remove(pk, group.getPrimaryKey());
1604 }
1605 catch (Exception e) {
1606 throw processException(e);
1607 }
1608 finally {
1609 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1610 }
1611 }
1612
1613
1620 public void removeGroups(long pk, long[] groupPKs)
1621 throws SystemException {
1622 try {
1623 for (long groupPK : groupPKs) {
1624 removeGroup.remove(pk, groupPK);
1625 }
1626 }
1627 catch (Exception e) {
1628 throw processException(e);
1629 }
1630 finally {
1631 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1632 }
1633 }
1634
1635
1642 public void removeGroups(long pk,
1643 List<com.liferay.portal.model.Group> groups) throws SystemException {
1644 try {
1645 for (com.liferay.portal.model.Group group : groups) {
1646 removeGroup.remove(pk, group.getPrimaryKey());
1647 }
1648 }
1649 catch (Exception e) {
1650 throw processException(e);
1651 }
1652 finally {
1653 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1654 }
1655 }
1656
1657
1664 public void setGroups(long pk, long[] groupPKs) throws SystemException {
1665 try {
1666 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1667
1668 List<com.liferay.portal.model.Group> groups = getGroups(pk);
1669
1670 for (com.liferay.portal.model.Group group : groups) {
1671 if (!groupPKSet.remove(group.getPrimaryKey())) {
1672 removeGroup.remove(pk, group.getPrimaryKey());
1673 }
1674 }
1675
1676 for (Long groupPK : groupPKSet) {
1677 addGroup.add(pk, groupPK);
1678 }
1679 }
1680 catch (Exception e) {
1681 throw processException(e);
1682 }
1683 finally {
1684 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1685 }
1686 }
1687
1688
1695 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1696 throws SystemException {
1697 try {
1698 long[] groupPKs = new long[groups.size()];
1699
1700 for (int i = 0; i < groups.size(); i++) {
1701 com.liferay.portal.model.Group group = groups.get(i);
1702
1703 groupPKs[i] = group.getPrimaryKey();
1704 }
1705
1706 setGroups(pk, groupPKs);
1707 }
1708 catch (Exception e) {
1709 throw processException(e);
1710 }
1711 finally {
1712 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1713 }
1714 }
1715
1716
1723 public List<com.liferay.portal.model.Role> getRoles(long pk)
1724 throws SystemException {
1725 return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1726 }
1727
1728
1741 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1742 int end) throws SystemException {
1743 return getRoles(pk, start, end, null);
1744 }
1745
1746 public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1747 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1748 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1749 "getRoles",
1750 new String[] {
1751 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1752 "com.liferay.portal.kernel.util.OrderByComparator"
1753 });
1754
1755
1769 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1770 int end, OrderByComparator orderByComparator) throws SystemException {
1771 Object[] finderArgs = new Object[] {
1772 pk, String.valueOf(start), String.valueOf(end),
1773 String.valueOf(orderByComparator)
1774 };
1775
1776 List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
1777 finderArgs, this);
1778
1779 if (list == null) {
1780 Session session = null;
1781
1782 try {
1783 session = openSession();
1784
1785 String sql = null;
1786
1787 if (orderByComparator != null) {
1788 sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
1789 .concat(orderByComparator.getOrderBy());
1790 }
1791 else {
1792 sql = _SQL_GETROLES.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
1793 }
1794
1795 SQLQuery q = session.createSQLQuery(sql);
1796
1797 q.addEntity("Role_",
1798 com.liferay.portal.model.impl.RoleImpl.class);
1799
1800 QueryPos qPos = QueryPos.getInstance(q);
1801
1802 qPos.add(pk);
1803
1804 list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
1805 getDialect(), start, end);
1806 }
1807 catch (Exception e) {
1808 throw processException(e);
1809 }
1810 finally {
1811 if (list == null) {
1812 FinderCacheUtil.removeResult(FINDER_PATH_GET_ROLES,
1813 finderArgs);
1814 }
1815 else {
1816 rolePersistence.cacheResult(list);
1817
1818 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES,
1819 finderArgs, list);
1820 }
1821
1822 closeSession(session);
1823 }
1824 }
1825
1826 return list;
1827 }
1828
1829 public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1830 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1831 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1832 "getRolesSize", new String[] { Long.class.getName() });
1833
1834
1841 public int getRolesSize(long pk) throws SystemException {
1842 Object[] finderArgs = new Object[] { pk };
1843
1844 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
1845 finderArgs, this);
1846
1847 if (count == null) {
1848 Session session = null;
1849
1850 try {
1851 session = openSession();
1852
1853 SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
1854
1855 q.addScalar(COUNT_COLUMN_NAME,
1856 com.liferay.portal.kernel.dao.orm.Type.LONG);
1857
1858 QueryPos qPos = QueryPos.getInstance(q);
1859
1860 qPos.add(pk);
1861
1862 count = (Long)q.uniqueResult();
1863 }
1864 catch (Exception e) {
1865 throw processException(e);
1866 }
1867 finally {
1868 if (count == null) {
1869 count = Long.valueOf(0);
1870 }
1871
1872 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
1873 finderArgs, count);
1874
1875 closeSession(session);
1876 }
1877 }
1878
1879 return count.intValue();
1880 }
1881
1882 public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1883 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1884 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1885 "containsRole",
1886 new String[] { Long.class.getName(), Long.class.getName() });
1887
1888
1896 public boolean containsRole(long pk, long rolePK) throws SystemException {
1897 Object[] finderArgs = new Object[] { pk, rolePK };
1898
1899 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
1900 finderArgs, this);
1901
1902 if (value == null) {
1903 try {
1904 value = Boolean.valueOf(containsRole.contains(pk, rolePK));
1905 }
1906 catch (Exception e) {
1907 throw processException(e);
1908 }
1909 finally {
1910 if (value == null) {
1911 value = Boolean.FALSE;
1912 }
1913
1914 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
1915 finderArgs, value);
1916 }
1917 }
1918
1919 return value.booleanValue();
1920 }
1921
1922
1929 public boolean containsRoles(long pk) throws SystemException {
1930 if (getRolesSize(pk) > 0) {
1931 return true;
1932 }
1933 else {
1934 return false;
1935 }
1936 }
1937
1938
1945 public void addRole(long pk, long rolePK) throws SystemException {
1946 try {
1947 addRole.add(pk, rolePK);
1948 }
1949 catch (Exception e) {
1950 throw processException(e);
1951 }
1952 finally {
1953 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1954 }
1955 }
1956
1957
1964 public void addRole(long pk, com.liferay.portal.model.Role role)
1965 throws SystemException {
1966 try {
1967 addRole.add(pk, role.getPrimaryKey());
1968 }
1969 catch (Exception e) {
1970 throw processException(e);
1971 }
1972 finally {
1973 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1974 }
1975 }
1976
1977
1984 public void addRoles(long pk, long[] rolePKs) throws SystemException {
1985 try {
1986 for (long rolePK : rolePKs) {
1987 addRole.add(pk, rolePK);
1988 }
1989 }
1990 catch (Exception e) {
1991 throw processException(e);
1992 }
1993 finally {
1994 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
1995 }
1996 }
1997
1998
2005 public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
2006 throws SystemException {
2007 try {
2008 for (com.liferay.portal.model.Role role : roles) {
2009 addRole.add(pk, role.getPrimaryKey());
2010 }
2011 }
2012 catch (Exception e) {
2013 throw processException(e);
2014 }
2015 finally {
2016 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2017 }
2018 }
2019
2020
2026 public void clearRoles(long pk) throws SystemException {
2027 try {
2028 clearRoles.clear(pk);
2029 }
2030 catch (Exception e) {
2031 throw processException(e);
2032 }
2033 finally {
2034 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2035 }
2036 }
2037
2038
2045 public void removeRole(long pk, long rolePK) throws SystemException {
2046 try {
2047 removeRole.remove(pk, rolePK);
2048 }
2049 catch (Exception e) {
2050 throw processException(e);
2051 }
2052 finally {
2053 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2054 }
2055 }
2056
2057
2064 public void removeRole(long pk, com.liferay.portal.model.Role role)
2065 throws SystemException {
2066 try {
2067 removeRole.remove(pk, role.getPrimaryKey());
2068 }
2069 catch (Exception e) {
2070 throw processException(e);
2071 }
2072 finally {
2073 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2074 }
2075 }
2076
2077
2084 public void removeRoles(long pk, long[] rolePKs) throws SystemException {
2085 try {
2086 for (long rolePK : rolePKs) {
2087 removeRole.remove(pk, rolePK);
2088 }
2089 }
2090 catch (Exception e) {
2091 throw processException(e);
2092 }
2093 finally {
2094 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2095 }
2096 }
2097
2098
2105 public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
2106 throws SystemException {
2107 try {
2108 for (com.liferay.portal.model.Role role : roles) {
2109 removeRole.remove(pk, role.getPrimaryKey());
2110 }
2111 }
2112 catch (Exception e) {
2113 throw processException(e);
2114 }
2115 finally {
2116 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2117 }
2118 }
2119
2120
2127 public void setRoles(long pk, long[] rolePKs) throws SystemException {
2128 try {
2129 Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
2130
2131 List<com.liferay.portal.model.Role> roles = getRoles(pk);
2132
2133 for (com.liferay.portal.model.Role role : roles) {
2134 if (!rolePKSet.remove(role.getPrimaryKey())) {
2135 removeRole.remove(pk, role.getPrimaryKey());
2136 }
2137 }
2138
2139 for (Long rolePK : rolePKSet) {
2140 addRole.add(pk, rolePK);
2141 }
2142 }
2143 catch (Exception e) {
2144 throw processException(e);
2145 }
2146 finally {
2147 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2148 }
2149 }
2150
2151
2158 public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
2159 throws SystemException {
2160 try {
2161 long[] rolePKs = new long[roles.size()];
2162
2163 for (int i = 0; i < roles.size(); i++) {
2164 com.liferay.portal.model.Role role = roles.get(i);
2165
2166 rolePKs[i] = role.getPrimaryKey();
2167 }
2168
2169 setRoles(pk, rolePKs);
2170 }
2171 catch (Exception e) {
2172 throw processException(e);
2173 }
2174 finally {
2175 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2176 }
2177 }
2178
2179
2186 public List<com.liferay.portal.model.User> getUsers(long pk)
2187 throws SystemException {
2188 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2189 }
2190
2191
2204 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2205 int end) throws SystemException {
2206 return getUsers(pk, start, end, null);
2207 }
2208
2209 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2210 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2211 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2212 "getUsers",
2213 new String[] {
2214 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2215 "com.liferay.portal.kernel.util.OrderByComparator"
2216 });
2217
2218
2232 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2233 int end, OrderByComparator orderByComparator) throws SystemException {
2234 Object[] finderArgs = new Object[] {
2235 pk, String.valueOf(start), String.valueOf(end),
2236 String.valueOf(orderByComparator)
2237 };
2238
2239 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2240 finderArgs, this);
2241
2242 if (list == null) {
2243 Session session = null;
2244
2245 try {
2246 session = openSession();
2247
2248 String sql = null;
2249
2250 if (orderByComparator != null) {
2251 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
2252 .concat(orderByComparator.getOrderBy());
2253 }
2254 else {
2255 sql = _SQL_GETUSERS;
2256 }
2257
2258 SQLQuery q = session.createSQLQuery(sql);
2259
2260 q.addEntity("User_",
2261 com.liferay.portal.model.impl.UserImpl.class);
2262
2263 QueryPos qPos = QueryPos.getInstance(q);
2264
2265 qPos.add(pk);
2266
2267 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2268 getDialect(), start, end);
2269 }
2270 catch (Exception e) {
2271 throw processException(e);
2272 }
2273 finally {
2274 if (list == null) {
2275 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
2276 finderArgs);
2277 }
2278 else {
2279 userPersistence.cacheResult(list);
2280
2281 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
2282 finderArgs, list);
2283 }
2284
2285 closeSession(session);
2286 }
2287 }
2288
2289 return list;
2290 }
2291
2292 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2293 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2294 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2295 "getUsersSize", new String[] { Long.class.getName() });
2296
2297
2304 public int getUsersSize(long pk) throws SystemException {
2305 Object[] finderArgs = new Object[] { pk };
2306
2307 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2308 finderArgs, this);
2309
2310 if (count == null) {
2311 Session session = null;
2312
2313 try {
2314 session = openSession();
2315
2316 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2317
2318 q.addScalar(COUNT_COLUMN_NAME,
2319 com.liferay.portal.kernel.dao.orm.Type.LONG);
2320
2321 QueryPos qPos = QueryPos.getInstance(q);
2322
2323 qPos.add(pk);
2324
2325 count = (Long)q.uniqueResult();
2326 }
2327 catch (Exception e) {
2328 throw processException(e);
2329 }
2330 finally {
2331 if (count == null) {
2332 count = Long.valueOf(0);
2333 }
2334
2335 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2336 finderArgs, count);
2337
2338 closeSession(session);
2339 }
2340 }
2341
2342 return count.intValue();
2343 }
2344
2345 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2346 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2347 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2348 "containsUser",
2349 new String[] { Long.class.getName(), Long.class.getName() });
2350
2351
2359 public boolean containsUser(long pk, long userPK) throws SystemException {
2360 Object[] finderArgs = new Object[] { pk, userPK };
2361
2362 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2363 finderArgs, this);
2364
2365 if (value == null) {
2366 try {
2367 value = Boolean.valueOf(containsUser.contains(pk, userPK));
2368 }
2369 catch (Exception e) {
2370 throw processException(e);
2371 }
2372 finally {
2373 if (value == null) {
2374 value = Boolean.FALSE;
2375 }
2376
2377 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2378 finderArgs, value);
2379 }
2380 }
2381
2382 return value.booleanValue();
2383 }
2384
2385
2392 public boolean containsUsers(long pk) throws SystemException {
2393 if (getUsersSize(pk) > 0) {
2394 return true;
2395 }
2396 else {
2397 return false;
2398 }
2399 }
2400
2401
2408 public void addUser(long pk, long userPK) throws SystemException {
2409 try {
2410 addUser.add(pk, userPK);
2411 }
2412 catch (Exception e) {
2413 throw processException(e);
2414 }
2415 finally {
2416 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2417 }
2418 }
2419
2420
2427 public void addUser(long pk, com.liferay.portal.model.User user)
2428 throws SystemException {
2429 try {
2430 addUser.add(pk, user.getPrimaryKey());
2431 }
2432 catch (Exception e) {
2433 throw processException(e);
2434 }
2435 finally {
2436 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2437 }
2438 }
2439
2440
2447 public void addUsers(long pk, long[] userPKs) throws SystemException {
2448 try {
2449 for (long userPK : userPKs) {
2450 addUser.add(pk, userPK);
2451 }
2452 }
2453 catch (Exception e) {
2454 throw processException(e);
2455 }
2456 finally {
2457 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2458 }
2459 }
2460
2461
2468 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2469 throws SystemException {
2470 try {
2471 for (com.liferay.portal.model.User user : users) {
2472 addUser.add(pk, user.getPrimaryKey());
2473 }
2474 }
2475 catch (Exception e) {
2476 throw processException(e);
2477 }
2478 finally {
2479 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2480 }
2481 }
2482
2483
2489 public void clearUsers(long pk) throws SystemException {
2490 try {
2491 clearUsers.clear(pk);
2492 }
2493 catch (Exception e) {
2494 throw processException(e);
2495 }
2496 finally {
2497 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2498 }
2499 }
2500
2501
2508 public void removeUser(long pk, long userPK) throws SystemException {
2509 try {
2510 removeUser.remove(pk, userPK);
2511 }
2512 catch (Exception e) {
2513 throw processException(e);
2514 }
2515 finally {
2516 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2517 }
2518 }
2519
2520
2527 public void removeUser(long pk, com.liferay.portal.model.User user)
2528 throws SystemException {
2529 try {
2530 removeUser.remove(pk, user.getPrimaryKey());
2531 }
2532 catch (Exception e) {
2533 throw processException(e);
2534 }
2535 finally {
2536 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2537 }
2538 }
2539
2540
2547 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2548 try {
2549 for (long userPK : userPKs) {
2550 removeUser.remove(pk, userPK);
2551 }
2552 }
2553 catch (Exception e) {
2554 throw processException(e);
2555 }
2556 finally {
2557 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2558 }
2559 }
2560
2561
2568 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2569 throws SystemException {
2570 try {
2571 for (com.liferay.portal.model.User user : users) {
2572 removeUser.remove(pk, user.getPrimaryKey());
2573 }
2574 }
2575 catch (Exception e) {
2576 throw processException(e);
2577 }
2578 finally {
2579 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2580 }
2581 }
2582
2583
2590 public void setUsers(long pk, long[] userPKs) throws SystemException {
2591 try {
2592 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2593
2594 List<com.liferay.portal.model.User> users = getUsers(pk);
2595
2596 for (com.liferay.portal.model.User user : users) {
2597 if (!userPKSet.remove(user.getPrimaryKey())) {
2598 removeUser.remove(pk, user.getPrimaryKey());
2599 }
2600 }
2601
2602 for (Long userPK : userPKSet) {
2603 addUser.add(pk, userPK);
2604 }
2605 }
2606 catch (Exception e) {
2607 throw processException(e);
2608 }
2609 finally {
2610 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2611 }
2612 }
2613
2614
2621 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2622 throws SystemException {
2623 try {
2624 long[] userPKs = new long[users.size()];
2625
2626 for (int i = 0; i < users.size(); i++) {
2627 com.liferay.portal.model.User user = users.get(i);
2628
2629 userPKs[i] = user.getPrimaryKey();
2630 }
2631
2632 setUsers(pk, userPKs);
2633 }
2634 catch (Exception e) {
2635 throw processException(e);
2636 }
2637 finally {
2638 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2639 }
2640 }
2641
2642
2645 public void afterPropertiesSet() {
2646 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2647 com.liferay.portal.util.PropsUtil.get(
2648 "value.object.listener.com.liferay.portal.model.Permission")));
2649
2650 if (listenerClassNames.length > 0) {
2651 try {
2652 List<ModelListener<Permission>> listenersList = new ArrayList<ModelListener<Permission>>();
2653
2654 for (String listenerClassName : listenerClassNames) {
2655 listenersList.add((ModelListener<Permission>)InstanceFactory.newInstance(
2656 listenerClassName));
2657 }
2658
2659 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2660 }
2661 catch (Exception e) {
2662 _log.error(e);
2663 }
2664 }
2665
2666 containsGroup = new ContainsGroup(this);
2667
2668 addGroup = new AddGroup(this);
2669 clearGroups = new ClearGroups(this);
2670 removeGroup = new RemoveGroup(this);
2671
2672 containsRole = new ContainsRole(this);
2673
2674 addRole = new AddRole(this);
2675 clearRoles = new ClearRoles(this);
2676 removeRole = new RemoveRole(this);
2677
2678 containsUser = new ContainsUser(this);
2679
2680 addUser = new AddUser(this);
2681 clearUsers = new ClearUsers(this);
2682 removeUser = new RemoveUser(this);
2683 }
2684
2685 public void destroy() {
2686 EntityCacheUtil.removeCache(PermissionImpl.class.getName());
2687 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2688 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2689 }
2690
2691 @BeanReference(type = AccountPersistence.class)
2692 protected AccountPersistence accountPersistence;
2693 @BeanReference(type = AddressPersistence.class)
2694 protected AddressPersistence addressPersistence;
2695 @BeanReference(type = BrowserTrackerPersistence.class)
2696 protected BrowserTrackerPersistence browserTrackerPersistence;
2697 @BeanReference(type = ClassNamePersistence.class)
2698 protected ClassNamePersistence classNamePersistence;
2699 @BeanReference(type = ClusterGroupPersistence.class)
2700 protected ClusterGroupPersistence clusterGroupPersistence;
2701 @BeanReference(type = CompanyPersistence.class)
2702 protected CompanyPersistence companyPersistence;
2703 @BeanReference(type = ContactPersistence.class)
2704 protected ContactPersistence contactPersistence;
2705 @BeanReference(type = CountryPersistence.class)
2706 protected CountryPersistence countryPersistence;
2707 @BeanReference(type = EmailAddressPersistence.class)
2708 protected EmailAddressPersistence emailAddressPersistence;
2709 @BeanReference(type = GroupPersistence.class)
2710 protected GroupPersistence groupPersistence;
2711 @BeanReference(type = ImagePersistence.class)
2712 protected ImagePersistence imagePersistence;
2713 @BeanReference(type = LayoutPersistence.class)
2714 protected LayoutPersistence layoutPersistence;
2715 @BeanReference(type = LayoutPrototypePersistence.class)
2716 protected LayoutPrototypePersistence layoutPrototypePersistence;
2717 @BeanReference(type = LayoutSetPersistence.class)
2718 protected LayoutSetPersistence layoutSetPersistence;
2719 @BeanReference(type = LayoutSetPrototypePersistence.class)
2720 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2721 @BeanReference(type = ListTypePersistence.class)
2722 protected ListTypePersistence listTypePersistence;
2723 @BeanReference(type = LockPersistence.class)
2724 protected LockPersistence lockPersistence;
2725 @BeanReference(type = MembershipRequestPersistence.class)
2726 protected MembershipRequestPersistence membershipRequestPersistence;
2727 @BeanReference(type = OrganizationPersistence.class)
2728 protected OrganizationPersistence organizationPersistence;
2729 @BeanReference(type = OrgGroupPermissionPersistence.class)
2730 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2731 @BeanReference(type = OrgGroupRolePersistence.class)
2732 protected OrgGroupRolePersistence orgGroupRolePersistence;
2733 @BeanReference(type = OrgLaborPersistence.class)
2734 protected OrgLaborPersistence orgLaborPersistence;
2735 @BeanReference(type = PasswordPolicyPersistence.class)
2736 protected PasswordPolicyPersistence passwordPolicyPersistence;
2737 @BeanReference(type = PasswordPolicyRelPersistence.class)
2738 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2739 @BeanReference(type = PasswordTrackerPersistence.class)
2740 protected PasswordTrackerPersistence passwordTrackerPersistence;
2741 @BeanReference(type = PermissionPersistence.class)
2742 protected PermissionPersistence permissionPersistence;
2743 @BeanReference(type = PhonePersistence.class)
2744 protected PhonePersistence phonePersistence;
2745 @BeanReference(type = PluginSettingPersistence.class)
2746 protected PluginSettingPersistence pluginSettingPersistence;
2747 @BeanReference(type = PortletPersistence.class)
2748 protected PortletPersistence portletPersistence;
2749 @BeanReference(type = PortletItemPersistence.class)
2750 protected PortletItemPersistence portletItemPersistence;
2751 @BeanReference(type = PortletPreferencesPersistence.class)
2752 protected PortletPreferencesPersistence portletPreferencesPersistence;
2753 @BeanReference(type = RegionPersistence.class)
2754 protected RegionPersistence regionPersistence;
2755 @BeanReference(type = ReleasePersistence.class)
2756 protected ReleasePersistence releasePersistence;
2757 @BeanReference(type = ResourcePersistence.class)
2758 protected ResourcePersistence resourcePersistence;
2759 @BeanReference(type = ResourceActionPersistence.class)
2760 protected ResourceActionPersistence resourceActionPersistence;
2761 @BeanReference(type = ResourceCodePersistence.class)
2762 protected ResourceCodePersistence resourceCodePersistence;
2763 @BeanReference(type = ResourcePermissionPersistence.class)
2764 protected ResourcePermissionPersistence resourcePermissionPersistence;
2765 @BeanReference(type = RolePersistence.class)
2766 protected RolePersistence rolePersistence;
2767 @BeanReference(type = ServiceComponentPersistence.class)
2768 protected ServiceComponentPersistence serviceComponentPersistence;
2769 @BeanReference(type = ShardPersistence.class)
2770 protected ShardPersistence shardPersistence;
2771 @BeanReference(type = SubscriptionPersistence.class)
2772 protected SubscriptionPersistence subscriptionPersistence;
2773 @BeanReference(type = TicketPersistence.class)
2774 protected TicketPersistence ticketPersistence;
2775 @BeanReference(type = TeamPersistence.class)
2776 protected TeamPersistence teamPersistence;
2777 @BeanReference(type = UserPersistence.class)
2778 protected UserPersistence userPersistence;
2779 @BeanReference(type = UserGroupPersistence.class)
2780 protected UserGroupPersistence userGroupPersistence;
2781 @BeanReference(type = UserGroupGroupRolePersistence.class)
2782 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2783 @BeanReference(type = UserGroupRolePersistence.class)
2784 protected UserGroupRolePersistence userGroupRolePersistence;
2785 @BeanReference(type = UserIdMapperPersistence.class)
2786 protected UserIdMapperPersistence userIdMapperPersistence;
2787 @BeanReference(type = UserTrackerPersistence.class)
2788 protected UserTrackerPersistence userTrackerPersistence;
2789 @BeanReference(type = UserTrackerPathPersistence.class)
2790 protected UserTrackerPathPersistence userTrackerPathPersistence;
2791 @BeanReference(type = WebDAVPropsPersistence.class)
2792 protected WebDAVPropsPersistence webDAVPropsPersistence;
2793 @BeanReference(type = WebsitePersistence.class)
2794 protected WebsitePersistence websitePersistence;
2795 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2796 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2797 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2798 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2799 protected ContainsGroup containsGroup;
2800 protected AddGroup addGroup;
2801 protected ClearGroups clearGroups;
2802 protected RemoveGroup removeGroup;
2803 protected ContainsRole containsRole;
2804 protected AddRole addRole;
2805 protected ClearRoles clearRoles;
2806 protected RemoveRole removeRole;
2807 protected ContainsUser containsUser;
2808 protected AddUser addUser;
2809 protected ClearUsers clearUsers;
2810 protected RemoveUser removeUser;
2811
2812 protected class ContainsGroup {
2813 protected ContainsGroup(PermissionPersistenceImpl persistenceImpl) {
2814 super();
2815
2816 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2817 _SQL_CONTAINSGROUP,
2818 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2819 RowMapper.COUNT);
2820 }
2821
2822 protected boolean contains(long permissionId, long groupId) {
2823 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2824 new Long(permissionId), new Long(groupId)
2825 });
2826
2827 if (results.size() > 0) {
2828 Integer count = results.get(0);
2829
2830 if (count.intValue() > 0) {
2831 return true;
2832 }
2833 }
2834
2835 return false;
2836 }
2837
2838 private MappingSqlQuery<Integer> _mappingSqlQuery;
2839 }
2840
2841 protected class AddGroup {
2842 protected AddGroup(PermissionPersistenceImpl persistenceImpl) {
2843 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2844 "INSERT INTO Groups_Permissions (permissionId, groupId) VALUES (?, ?)",
2845 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2846 _persistenceImpl = persistenceImpl;
2847 }
2848
2849 protected void add(long permissionId, long groupId)
2850 throws SystemException {
2851 if (!_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2852 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2853
2854 for (ModelListener<Permission> listener : listeners) {
2855 listener.onBeforeAddAssociation(permissionId,
2856 com.liferay.portal.model.Group.class.getName(), groupId);
2857 }
2858
2859 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2860 listener.onBeforeAddAssociation(groupId,
2861 Permission.class.getName(), permissionId);
2862 }
2863
2864 _sqlUpdate.update(new Object[] {
2865 new Long(permissionId), new Long(groupId)
2866 });
2867
2868 for (ModelListener<Permission> listener : listeners) {
2869 listener.onAfterAddAssociation(permissionId,
2870 com.liferay.portal.model.Group.class.getName(), groupId);
2871 }
2872
2873 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2874 listener.onAfterAddAssociation(groupId,
2875 Permission.class.getName(), permissionId);
2876 }
2877 }
2878 }
2879
2880 private SqlUpdate _sqlUpdate;
2881 private PermissionPersistenceImpl _persistenceImpl;
2882 }
2883
2884 protected class ClearGroups {
2885 protected ClearGroups(PermissionPersistenceImpl persistenceImpl) {
2886 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2887 "DELETE FROM Groups_Permissions WHERE permissionId = ?",
2888 new int[] { java.sql.Types.BIGINT });
2889 }
2890
2891 protected void clear(long permissionId) throws SystemException {
2892 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2893
2894 List<com.liferay.portal.model.Group> groups = null;
2895
2896 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2897 groups = getGroups(permissionId);
2898
2899 for (com.liferay.portal.model.Group group : groups) {
2900 for (ModelListener<Permission> listener : listeners) {
2901 listener.onBeforeRemoveAssociation(permissionId,
2902 com.liferay.portal.model.Group.class.getName(),
2903 group.getPrimaryKey());
2904 }
2905
2906 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2907 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2908 Permission.class.getName(), permissionId);
2909 }
2910 }
2911 }
2912
2913 _sqlUpdate.update(new Object[] { new Long(permissionId) });
2914
2915 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2916 for (com.liferay.portal.model.Group group : groups) {
2917 for (ModelListener<Permission> listener : listeners) {
2918 listener.onAfterRemoveAssociation(permissionId,
2919 com.liferay.portal.model.Group.class.getName(),
2920 group.getPrimaryKey());
2921 }
2922
2923 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2924 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
2925 Permission.class.getName(), permissionId);
2926 }
2927 }
2928 }
2929 }
2930
2931 private SqlUpdate _sqlUpdate;
2932 }
2933
2934 protected class RemoveGroup {
2935 protected RemoveGroup(PermissionPersistenceImpl persistenceImpl) {
2936 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2937 "DELETE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?",
2938 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
2939 _persistenceImpl = persistenceImpl;
2940 }
2941
2942 protected void remove(long permissionId, long groupId)
2943 throws SystemException {
2944 if (_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2945 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2946
2947 for (ModelListener<Permission> listener : listeners) {
2948 listener.onBeforeRemoveAssociation(permissionId,
2949 com.liferay.portal.model.Group.class.getName(), groupId);
2950 }
2951
2952 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2953 listener.onBeforeRemoveAssociation(groupId,
2954 Permission.class.getName(), permissionId);
2955 }
2956
2957 _sqlUpdate.update(new Object[] {
2958 new Long(permissionId), new Long(groupId)
2959 });
2960
2961 for (ModelListener<Permission> listener : listeners) {
2962 listener.onAfterRemoveAssociation(permissionId,
2963 com.liferay.portal.model.Group.class.getName(), groupId);
2964 }
2965
2966 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2967 listener.onAfterRemoveAssociation(groupId,
2968 Permission.class.getName(), permissionId);
2969 }
2970 }
2971 }
2972
2973 private SqlUpdate _sqlUpdate;
2974 private PermissionPersistenceImpl _persistenceImpl;
2975 }
2976
2977 protected class ContainsRole {
2978 protected ContainsRole(PermissionPersistenceImpl persistenceImpl) {
2979 super();
2980
2981 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2982 _SQL_CONTAINSROLE,
2983 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2984 RowMapper.COUNT);
2985 }
2986
2987 protected boolean contains(long permissionId, long roleId) {
2988 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2989 new Long(permissionId), new Long(roleId)
2990 });
2991
2992 if (results.size() > 0) {
2993 Integer count = results.get(0);
2994
2995 if (count.intValue() > 0) {
2996 return true;
2997 }
2998 }
2999
3000 return false;
3001 }
3002
3003 private MappingSqlQuery<Integer> _mappingSqlQuery;
3004 }
3005
3006 protected class AddRole {
3007 protected AddRole(PermissionPersistenceImpl persistenceImpl) {
3008 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3009 "INSERT INTO Roles_Permissions (permissionId, roleId) VALUES (?, ?)",
3010 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3011 _persistenceImpl = persistenceImpl;
3012 }
3013
3014 protected void add(long permissionId, long roleId)
3015 throws SystemException {
3016 if (!_persistenceImpl.containsRole.contains(permissionId, roleId)) {
3017 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3018
3019 for (ModelListener<Permission> listener : listeners) {
3020 listener.onBeforeAddAssociation(permissionId,
3021 com.liferay.portal.model.Role.class.getName(), roleId);
3022 }
3023
3024 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3025 listener.onBeforeAddAssociation(roleId,
3026 Permission.class.getName(), permissionId);
3027 }
3028
3029 _sqlUpdate.update(new Object[] {
3030 new Long(permissionId), new Long(roleId)
3031 });
3032
3033 for (ModelListener<Permission> listener : listeners) {
3034 listener.onAfterAddAssociation(permissionId,
3035 com.liferay.portal.model.Role.class.getName(), roleId);
3036 }
3037
3038 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3039 listener.onAfterAddAssociation(roleId,
3040 Permission.class.getName(), permissionId);
3041 }
3042 }
3043 }
3044
3045 private SqlUpdate _sqlUpdate;
3046 private PermissionPersistenceImpl _persistenceImpl;
3047 }
3048
3049 protected class ClearRoles {
3050 protected ClearRoles(PermissionPersistenceImpl persistenceImpl) {
3051 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3052 "DELETE FROM Roles_Permissions WHERE permissionId = ?",
3053 new int[] { java.sql.Types.BIGINT });
3054 }
3055
3056 protected void clear(long permissionId) throws SystemException {
3057 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3058
3059 List<com.liferay.portal.model.Role> roles = null;
3060
3061 if ((listeners.length > 0) || (roleListeners.length > 0)) {
3062 roles = getRoles(permissionId);
3063
3064 for (com.liferay.portal.model.Role role : roles) {
3065 for (ModelListener<Permission> listener : listeners) {
3066 listener.onBeforeRemoveAssociation(permissionId,
3067 com.liferay.portal.model.Role.class.getName(),
3068 role.getPrimaryKey());
3069 }
3070
3071 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3072 listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
3073 Permission.class.getName(), permissionId);
3074 }
3075 }
3076 }
3077
3078 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3079
3080 if ((listeners.length > 0) || (roleListeners.length > 0)) {
3081 for (com.liferay.portal.model.Role role : roles) {
3082 for (ModelListener<Permission> listener : listeners) {
3083 listener.onAfterRemoveAssociation(permissionId,
3084 com.liferay.portal.model.Role.class.getName(),
3085 role.getPrimaryKey());
3086 }
3087
3088 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3089 listener.onAfterRemoveAssociation(role.getPrimaryKey(),
3090 Permission.class.getName(), permissionId);
3091 }
3092 }
3093 }
3094 }
3095
3096 private SqlUpdate _sqlUpdate;
3097 }
3098
3099 protected class RemoveRole {
3100 protected RemoveRole(PermissionPersistenceImpl persistenceImpl) {
3101 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3102 "DELETE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?",
3103 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3104 _persistenceImpl = persistenceImpl;
3105 }
3106
3107 protected void remove(long permissionId, long roleId)
3108 throws SystemException {
3109 if (_persistenceImpl.containsRole.contains(permissionId, roleId)) {
3110 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3111
3112 for (ModelListener<Permission> listener : listeners) {
3113 listener.onBeforeRemoveAssociation(permissionId,
3114 com.liferay.portal.model.Role.class.getName(), roleId);
3115 }
3116
3117 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3118 listener.onBeforeRemoveAssociation(roleId,
3119 Permission.class.getName(), permissionId);
3120 }
3121
3122 _sqlUpdate.update(new Object[] {
3123 new Long(permissionId), new Long(roleId)
3124 });
3125
3126 for (ModelListener<Permission> listener : listeners) {
3127 listener.onAfterRemoveAssociation(permissionId,
3128 com.liferay.portal.model.Role.class.getName(), roleId);
3129 }
3130
3131 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3132 listener.onAfterRemoveAssociation(roleId,
3133 Permission.class.getName(), permissionId);
3134 }
3135 }
3136 }
3137
3138 private SqlUpdate _sqlUpdate;
3139 private PermissionPersistenceImpl _persistenceImpl;
3140 }
3141
3142 protected class ContainsUser {
3143 protected ContainsUser(PermissionPersistenceImpl persistenceImpl) {
3144 super();
3145
3146 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3147 _SQL_CONTAINSUSER,
3148 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3149 RowMapper.COUNT);
3150 }
3151
3152 protected boolean contains(long permissionId, long userId) {
3153 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3154 new Long(permissionId), new Long(userId)
3155 });
3156
3157 if (results.size() > 0) {
3158 Integer count = results.get(0);
3159
3160 if (count.intValue() > 0) {
3161 return true;
3162 }
3163 }
3164
3165 return false;
3166 }
3167
3168 private MappingSqlQuery<Integer> _mappingSqlQuery;
3169 }
3170
3171 protected class AddUser {
3172 protected AddUser(PermissionPersistenceImpl persistenceImpl) {
3173 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3174 "INSERT INTO Users_Permissions (permissionId, userId) VALUES (?, ?)",
3175 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3176 _persistenceImpl = persistenceImpl;
3177 }
3178
3179 protected void add(long permissionId, long userId)
3180 throws SystemException {
3181 if (!_persistenceImpl.containsUser.contains(permissionId, userId)) {
3182 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3183
3184 for (ModelListener<Permission> listener : listeners) {
3185 listener.onBeforeAddAssociation(permissionId,
3186 com.liferay.portal.model.User.class.getName(), userId);
3187 }
3188
3189 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3190 listener.onBeforeAddAssociation(userId,
3191 Permission.class.getName(), permissionId);
3192 }
3193
3194 _sqlUpdate.update(new Object[] {
3195 new Long(permissionId), new Long(userId)
3196 });
3197
3198 for (ModelListener<Permission> listener : listeners) {
3199 listener.onAfterAddAssociation(permissionId,
3200 com.liferay.portal.model.User.class.getName(), userId);
3201 }
3202
3203 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3204 listener.onAfterAddAssociation(userId,
3205 Permission.class.getName(), permissionId);
3206 }
3207 }
3208 }
3209
3210 private SqlUpdate _sqlUpdate;
3211 private PermissionPersistenceImpl _persistenceImpl;
3212 }
3213
3214 protected class ClearUsers {
3215 protected ClearUsers(PermissionPersistenceImpl persistenceImpl) {
3216 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3217 "DELETE FROM Users_Permissions WHERE permissionId = ?",
3218 new int[] { java.sql.Types.BIGINT });
3219 }
3220
3221 protected void clear(long permissionId) throws SystemException {
3222 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3223
3224 List<com.liferay.portal.model.User> users = null;
3225
3226 if ((listeners.length > 0) || (userListeners.length > 0)) {
3227 users = getUsers(permissionId);
3228
3229 for (com.liferay.portal.model.User user : users) {
3230 for (ModelListener<Permission> listener : listeners) {
3231 listener.onBeforeRemoveAssociation(permissionId,
3232 com.liferay.portal.model.User.class.getName(),
3233 user.getPrimaryKey());
3234 }
3235
3236 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3237 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3238 Permission.class.getName(), permissionId);
3239 }
3240 }
3241 }
3242
3243 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3244
3245 if ((listeners.length > 0) || (userListeners.length > 0)) {
3246 for (com.liferay.portal.model.User user : users) {
3247 for (ModelListener<Permission> listener : listeners) {
3248 listener.onAfterRemoveAssociation(permissionId,
3249 com.liferay.portal.model.User.class.getName(),
3250 user.getPrimaryKey());
3251 }
3252
3253 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3254 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
3255 Permission.class.getName(), permissionId);
3256 }
3257 }
3258 }
3259 }
3260
3261 private SqlUpdate _sqlUpdate;
3262 }
3263
3264 protected class RemoveUser {
3265 protected RemoveUser(PermissionPersistenceImpl persistenceImpl) {
3266 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3267 "DELETE FROM Users_Permissions WHERE permissionId = ? AND userId = ?",
3268 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3269 _persistenceImpl = persistenceImpl;
3270 }
3271
3272 protected void remove(long permissionId, long userId)
3273 throws SystemException {
3274 if (_persistenceImpl.containsUser.contains(permissionId, userId)) {
3275 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3276
3277 for (ModelListener<Permission> listener : listeners) {
3278 listener.onBeforeRemoveAssociation(permissionId,
3279 com.liferay.portal.model.User.class.getName(), userId);
3280 }
3281
3282 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3283 listener.onBeforeRemoveAssociation(userId,
3284 Permission.class.getName(), permissionId);
3285 }
3286
3287 _sqlUpdate.update(new Object[] {
3288 new Long(permissionId), new Long(userId)
3289 });
3290
3291 for (ModelListener<Permission> listener : listeners) {
3292 listener.onAfterRemoveAssociation(permissionId,
3293 com.liferay.portal.model.User.class.getName(), userId);
3294 }
3295
3296 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3297 listener.onAfterRemoveAssociation(userId,
3298 Permission.class.getName(), permissionId);
3299 }
3300 }
3301 }
3302
3303 private SqlUpdate _sqlUpdate;
3304 private PermissionPersistenceImpl _persistenceImpl;
3305 }
3306
3307 private static final String _SQL_SELECT_PERMISSION = "SELECT permission FROM Permission permission";
3308 private static final String _SQL_SELECT_PERMISSION_WHERE = "SELECT permission FROM Permission permission WHERE ";
3309 private static final String _SQL_COUNT_PERMISSION = "SELECT COUNT(permission) FROM Permission permission";
3310 private static final String _SQL_COUNT_PERMISSION_WHERE = "SELECT COUNT(permission) FROM Permission permission WHERE ";
3311 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Permissions ON (Groups_Permissions.groupId = Group_.groupId) WHERE (Groups_Permissions.permissionId = ?)";
3312 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ?";
3313 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?";
3314 private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Roles_Permissions ON (Roles_Permissions.roleId = Role_.roleId) WHERE (Roles_Permissions.permissionId = ?)";
3315 private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ?";
3316 private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?";
3317 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Permissions ON (Users_Permissions.userId = User_.userId) WHERE (Users_Permissions.permissionId = ?)";
3318 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ?";
3319 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ? AND userId = ?";
3320 private static final String _FINDER_COLUMN_RESOURCEID_RESOURCEID_2 = "permission.resourceId = ?";
3321 private static final String _FINDER_COLUMN_A_R_ACTIONID_1 = "permission.actionId IS NULL AND ";
3322 private static final String _FINDER_COLUMN_A_R_ACTIONID_2 = "permission.actionId = ? AND ";
3323 private static final String _FINDER_COLUMN_A_R_ACTIONID_3 = "(permission.actionId IS NULL OR permission.actionId = ?) AND ";
3324 private static final String _FINDER_COLUMN_A_R_RESOURCEID_2 = "permission.resourceId = ?";
3325 private static final String _ORDER_BY_ENTITY_ALIAS = "permission.";
3326 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Permission exists with the primary key ";
3327 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Permission exists with the key {";
3328 private static Log _log = LogFactoryUtil.getLog(PermissionPersistenceImpl.class);
3329 }