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.bean.BeanReference;
020 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
022 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
023 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
024 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
025 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
026 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
027 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
028 import com.liferay.portal.kernel.dao.orm.FinderPath;
029 import com.liferay.portal.kernel.dao.orm.Query;
030 import com.liferay.portal.kernel.dao.orm.QueryPos;
031 import com.liferay.portal.kernel.dao.orm.QueryUtil;
032 import com.liferay.portal.kernel.dao.orm.SQLQuery;
033 import com.liferay.portal.kernel.dao.orm.Session;
034 import com.liferay.portal.kernel.exception.SystemException;
035 import com.liferay.portal.kernel.log.Log;
036 import com.liferay.portal.kernel.log.LogFactoryUtil;
037 import com.liferay.portal.kernel.util.GetterUtil;
038 import com.liferay.portal.kernel.util.InstanceFactory;
039 import com.liferay.portal.kernel.util.OrderByComparator;
040 import com.liferay.portal.kernel.util.SetUtil;
041 import com.liferay.portal.kernel.util.StringBundler;
042 import com.liferay.portal.kernel.util.StringPool;
043 import com.liferay.portal.kernel.util.StringUtil;
044 import com.liferay.portal.kernel.util.Validator;
045 import com.liferay.portal.model.CacheModel;
046 import com.liferay.portal.model.ModelListener;
047 import com.liferay.portal.model.Permission;
048 import com.liferay.portal.model.impl.PermissionImpl;
049 import com.liferay.portal.model.impl.PermissionModelImpl;
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
071 public class PermissionPersistenceImpl extends BasePersistenceImpl<Permission>
072 implements PermissionPersistence {
073
078 public static final String FINDER_CLASS_NAME_ENTITY = PermissionImpl.class.getName();
079 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080 ".List1";
081 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082 ".List2";
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEID =
084 new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
085 PermissionModelImpl.FINDER_CACHE_ENABLED, PermissionImpl.class,
086 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByResourceId",
087 new String[] {
088 Long.class.getName(),
089
090 "java.lang.Integer", "java.lang.Integer",
091 "com.liferay.portal.kernel.util.OrderByComparator"
092 });
093 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID =
094 new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
095 PermissionModelImpl.FINDER_CACHE_ENABLED, PermissionImpl.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByResourceId",
097 new String[] { Long.class.getName() },
098 PermissionModelImpl.RESOURCEID_COLUMN_BITMASK);
099 public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
100 PermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
101 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByResourceId",
102 new String[] { Long.class.getName() });
103 public static final FinderPath FINDER_PATH_FETCH_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
104 PermissionModelImpl.FINDER_CACHE_ENABLED, PermissionImpl.class,
105 FINDER_CLASS_NAME_ENTITY, "fetchByA_R",
106 new String[] { String.class.getName(), Long.class.getName() },
107 PermissionModelImpl.ACTIONID_COLUMN_BITMASK |
108 PermissionModelImpl.RESOURCEID_COLUMN_BITMASK);
109 public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
110 PermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
111 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByA_R",
112 new String[] { String.class.getName(), Long.class.getName() });
113 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
114 PermissionModelImpl.FINDER_CACHE_ENABLED, PermissionImpl.class,
115 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
116 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
117 PermissionModelImpl.FINDER_CACHE_ENABLED, PermissionImpl.class,
118 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
119 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
120 PermissionModelImpl.FINDER_CACHE_ENABLED, Long.class,
121 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
122
123
128 public void cacheResult(Permission permission) {
129 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
130 PermissionImpl.class, permission.getPrimaryKey(), permission);
131
132 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
133 new Object[] {
134 permission.getActionId(),
135 Long.valueOf(permission.getResourceId())
136 }, permission);
137
138 permission.resetOriginalValues();
139 }
140
141
146 public void cacheResult(List<Permission> permissions) {
147 for (Permission permission : permissions) {
148 if (EntityCacheUtil.getResult(
149 PermissionModelImpl.ENTITY_CACHE_ENABLED,
150 PermissionImpl.class, permission.getPrimaryKey()) == null) {
151 cacheResult(permission);
152 }
153 else {
154 permission.resetOriginalValues();
155 }
156 }
157 }
158
159
166 @Override
167 public void clearCache() {
168 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
169 CacheRegistryUtil.clear(PermissionImpl.class.getName());
170 }
171
172 EntityCacheUtil.clearCache(PermissionImpl.class.getName());
173
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
177 }
178
179
186 @Override
187 public void clearCache(Permission permission) {
188 EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
189 PermissionImpl.class, permission.getPrimaryKey());
190
191 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
192 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
193
194 clearUniqueFindersCache(permission);
195 }
196
197 @Override
198 public void clearCache(List<Permission> permissions) {
199 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
200 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
201
202 for (Permission permission : permissions) {
203 EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
204 PermissionImpl.class, permission.getPrimaryKey());
205
206 clearUniqueFindersCache(permission);
207 }
208 }
209
210 protected void clearUniqueFindersCache(Permission permission) {
211 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
212 new Object[] {
213 permission.getActionId(),
214 Long.valueOf(permission.getResourceId())
215 });
216 }
217
218
224 public Permission create(long permissionId) {
225 Permission permission = new PermissionImpl();
226
227 permission.setNew(true);
228 permission.setPrimaryKey(permissionId);
229
230 return permission;
231 }
232
233
241 public Permission remove(long permissionId)
242 throws NoSuchPermissionException, SystemException {
243 return remove(Long.valueOf(permissionId));
244 }
245
246
254 @Override
255 public Permission remove(Serializable primaryKey)
256 throws NoSuchPermissionException, SystemException {
257 Session session = null;
258
259 try {
260 session = openSession();
261
262 Permission permission = (Permission)session.get(PermissionImpl.class,
263 primaryKey);
264
265 if (permission == null) {
266 if (_log.isWarnEnabled()) {
267 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
268 }
269
270 throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
271 primaryKey);
272 }
273
274 return remove(permission);
275 }
276 catch (NoSuchPermissionException nsee) {
277 throw nsee;
278 }
279 catch (Exception e) {
280 throw processException(e);
281 }
282 finally {
283 closeSession(session);
284 }
285 }
286
287 @Override
288 protected Permission removeImpl(Permission permission)
289 throws SystemException {
290 permission = toUnwrappedModel(permission);
291
292 try {
293 clearGroups.clear(permission.getPrimaryKey());
294 }
295 catch (Exception e) {
296 throw processException(e);
297 }
298 finally {
299 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
300 }
301
302 try {
303 clearRoles.clear(permission.getPrimaryKey());
304 }
305 catch (Exception e) {
306 throw processException(e);
307 }
308 finally {
309 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
310 }
311
312 try {
313 clearUsers.clear(permission.getPrimaryKey());
314 }
315 catch (Exception e) {
316 throw processException(e);
317 }
318 finally {
319 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
320 }
321
322 Session session = null;
323
324 try {
325 session = openSession();
326
327 BatchSessionUtil.delete(session, permission);
328 }
329 catch (Exception e) {
330 throw processException(e);
331 }
332 finally {
333 closeSession(session);
334 }
335
336 clearCache(permission);
337
338 return permission;
339 }
340
341 @Override
342 public Permission updateImpl(
343 com.liferay.portal.model.Permission permission, boolean merge)
344 throws SystemException {
345 permission = toUnwrappedModel(permission);
346
347 boolean isNew = permission.isNew();
348
349 PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
350
351 Session session = null;
352
353 try {
354 session = openSession();
355
356 BatchSessionUtil.update(session, permission, merge);
357
358 permission.setNew(false);
359 }
360 catch (Exception e) {
361 throw processException(e);
362 }
363 finally {
364 closeSession(session);
365 }
366
367 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
368
369 if (isNew || !PermissionModelImpl.COLUMN_BITMASK_ENABLED) {
370 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
371 }
372 else {
373 if ((permissionModelImpl.getColumnBitmask() &
374 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID.getColumnBitmask()) != 0) {
375 Object[] args = new Object[] {
376 Long.valueOf(permissionModelImpl.getOriginalResourceId())
377 };
378
379 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEID,
380 args);
381 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID,
382 args);
383
384 args = new Object[] {
385 Long.valueOf(permissionModelImpl.getResourceId())
386 };
387
388 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEID,
389 args);
390 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID,
391 args);
392 }
393 }
394
395 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
396 PermissionImpl.class, permission.getPrimaryKey(), permission);
397
398 if (isNew) {
399 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
400 new Object[] {
401 permission.getActionId(),
402 Long.valueOf(permission.getResourceId())
403 }, permission);
404 }
405 else {
406 if ((permissionModelImpl.getColumnBitmask() &
407 FINDER_PATH_FETCH_BY_A_R.getColumnBitmask()) != 0) {
408 Object[] args = new Object[] {
409 permissionModelImpl.getOriginalActionId(),
410 Long.valueOf(permissionModelImpl.getOriginalResourceId())
411 };
412
413 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A_R, args);
414 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R, args);
415
416 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
417 new Object[] {
418 permission.getActionId(),
419 Long.valueOf(permission.getResourceId())
420 }, permission);
421 }
422 }
423
424 return permission;
425 }
426
427 protected Permission toUnwrappedModel(Permission permission) {
428 if (permission instanceof PermissionImpl) {
429 return permission;
430 }
431
432 PermissionImpl permissionImpl = new PermissionImpl();
433
434 permissionImpl.setNew(permission.isNew());
435 permissionImpl.setPrimaryKey(permission.getPrimaryKey());
436
437 permissionImpl.setPermissionId(permission.getPermissionId());
438 permissionImpl.setCompanyId(permission.getCompanyId());
439 permissionImpl.setActionId(permission.getActionId());
440 permissionImpl.setResourceId(permission.getResourceId());
441
442 return permissionImpl;
443 }
444
445
453 @Override
454 public Permission findByPrimaryKey(Serializable primaryKey)
455 throws NoSuchModelException, SystemException {
456 return findByPrimaryKey(((Long)primaryKey).longValue());
457 }
458
459
467 public Permission findByPrimaryKey(long permissionId)
468 throws NoSuchPermissionException, SystemException {
469 Permission permission = fetchByPrimaryKey(permissionId);
470
471 if (permission == null) {
472 if (_log.isWarnEnabled()) {
473 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
474 }
475
476 throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
477 permissionId);
478 }
479
480 return permission;
481 }
482
483
490 @Override
491 public Permission fetchByPrimaryKey(Serializable primaryKey)
492 throws SystemException {
493 return fetchByPrimaryKey(((Long)primaryKey).longValue());
494 }
495
496
503 public Permission fetchByPrimaryKey(long permissionId)
504 throws SystemException {
505 Permission permission = (Permission)EntityCacheUtil.getResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
506 PermissionImpl.class, permissionId);
507
508 if (permission == _nullPermission) {
509 return null;
510 }
511
512 if (permission == null) {
513 Session session = null;
514
515 boolean hasException = false;
516
517 try {
518 session = openSession();
519
520 permission = (Permission)session.get(PermissionImpl.class,
521 Long.valueOf(permissionId));
522 }
523 catch (Exception e) {
524 hasException = true;
525
526 throw processException(e);
527 }
528 finally {
529 if (permission != null) {
530 cacheResult(permission);
531 }
532 else if (!hasException) {
533 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
534 PermissionImpl.class, permissionId, _nullPermission);
535 }
536
537 closeSession(session);
538 }
539 }
540
541 return permission;
542 }
543
544
551 public List<Permission> findByResourceId(long resourceId)
552 throws SystemException {
553 return findByResourceId(resourceId, QueryUtil.ALL_POS,
554 QueryUtil.ALL_POS, null);
555 }
556
557
570 public List<Permission> findByResourceId(long resourceId, int start, int end)
571 throws SystemException {
572 return findByResourceId(resourceId, start, end, null);
573 }
574
575
589 public List<Permission> findByResourceId(long resourceId, int start,
590 int end, OrderByComparator orderByComparator) throws SystemException {
591 FinderPath finderPath = null;
592 Object[] finderArgs = null;
593
594 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
595 (orderByComparator == null)) {
596 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID;
597 finderArgs = new Object[] { resourceId };
598 }
599 else {
600 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEID;
601 finderArgs = new Object[] { resourceId, start, end, orderByComparator };
602 }
603
604 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(finderPath,
605 finderArgs, this);
606
607 if ((list != null) && !list.isEmpty()) {
608 for (Permission permission : list) {
609 if ((resourceId != permission.getResourceId())) {
610 list = null;
611
612 break;
613 }
614 }
615 }
616
617 if (list == null) {
618 StringBundler query = null;
619
620 if (orderByComparator != null) {
621 query = new StringBundler(3 +
622 (orderByComparator.getOrderByFields().length * 3));
623 }
624 else {
625 query = new StringBundler(2);
626 }
627
628 query.append(_SQL_SELECT_PERMISSION_WHERE);
629
630 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
631
632 if (orderByComparator != null) {
633 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
634 orderByComparator);
635 }
636
637 String sql = query.toString();
638
639 Session session = null;
640
641 try {
642 session = openSession();
643
644 Query q = session.createQuery(sql);
645
646 QueryPos qPos = QueryPos.getInstance(q);
647
648 qPos.add(resourceId);
649
650 list = (List<Permission>)QueryUtil.list(q, getDialect(), start,
651 end);
652 }
653 catch (Exception e) {
654 throw processException(e);
655 }
656 finally {
657 if (list == null) {
658 FinderCacheUtil.removeResult(finderPath, finderArgs);
659 }
660 else {
661 cacheResult(list);
662
663 FinderCacheUtil.putResult(finderPath, finderArgs, list);
664 }
665
666 closeSession(session);
667 }
668 }
669
670 return list;
671 }
672
673
686 public Permission findByResourceId_First(long resourceId,
687 OrderByComparator orderByComparator)
688 throws NoSuchPermissionException, SystemException {
689 List<Permission> list = findByResourceId(resourceId, 0, 1,
690 orderByComparator);
691
692 if (list.isEmpty()) {
693 StringBundler msg = new StringBundler(4);
694
695 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
696
697 msg.append("resourceId=");
698 msg.append(resourceId);
699
700 msg.append(StringPool.CLOSE_CURLY_BRACE);
701
702 throw new NoSuchPermissionException(msg.toString());
703 }
704 else {
705 return list.get(0);
706 }
707 }
708
709
722 public Permission findByResourceId_Last(long resourceId,
723 OrderByComparator orderByComparator)
724 throws NoSuchPermissionException, SystemException {
725 int count = countByResourceId(resourceId);
726
727 List<Permission> list = findByResourceId(resourceId, count - 1, count,
728 orderByComparator);
729
730 if (list.isEmpty()) {
731 StringBundler msg = new StringBundler(4);
732
733 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
734
735 msg.append("resourceId=");
736 msg.append(resourceId);
737
738 msg.append(StringPool.CLOSE_CURLY_BRACE);
739
740 throw new NoSuchPermissionException(msg.toString());
741 }
742 else {
743 return list.get(0);
744 }
745 }
746
747
761 public Permission[] findByResourceId_PrevAndNext(long permissionId,
762 long resourceId, OrderByComparator orderByComparator)
763 throws NoSuchPermissionException, SystemException {
764 Permission permission = findByPrimaryKey(permissionId);
765
766 Session session = null;
767
768 try {
769 session = openSession();
770
771 Permission[] array = new PermissionImpl[3];
772
773 array[0] = getByResourceId_PrevAndNext(session, permission,
774 resourceId, orderByComparator, true);
775
776 array[1] = permission;
777
778 array[2] = getByResourceId_PrevAndNext(session, permission,
779 resourceId, orderByComparator, false);
780
781 return array;
782 }
783 catch (Exception e) {
784 throw processException(e);
785 }
786 finally {
787 closeSession(session);
788 }
789 }
790
791 protected Permission getByResourceId_PrevAndNext(Session session,
792 Permission permission, long resourceId,
793 OrderByComparator orderByComparator, boolean previous) {
794 StringBundler query = null;
795
796 if (orderByComparator != null) {
797 query = new StringBundler(6 +
798 (orderByComparator.getOrderByFields().length * 6));
799 }
800 else {
801 query = new StringBundler(3);
802 }
803
804 query.append(_SQL_SELECT_PERMISSION_WHERE);
805
806 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
807
808 if (orderByComparator != null) {
809 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
810
811 if (orderByConditionFields.length > 0) {
812 query.append(WHERE_AND);
813 }
814
815 for (int i = 0; i < orderByConditionFields.length; i++) {
816 query.append(_ORDER_BY_ENTITY_ALIAS);
817 query.append(orderByConditionFields[i]);
818
819 if ((i + 1) < orderByConditionFields.length) {
820 if (orderByComparator.isAscending() ^ previous) {
821 query.append(WHERE_GREATER_THAN_HAS_NEXT);
822 }
823 else {
824 query.append(WHERE_LESSER_THAN_HAS_NEXT);
825 }
826 }
827 else {
828 if (orderByComparator.isAscending() ^ previous) {
829 query.append(WHERE_GREATER_THAN);
830 }
831 else {
832 query.append(WHERE_LESSER_THAN);
833 }
834 }
835 }
836
837 query.append(ORDER_BY_CLAUSE);
838
839 String[] orderByFields = orderByComparator.getOrderByFields();
840
841 for (int i = 0; i < orderByFields.length; i++) {
842 query.append(_ORDER_BY_ENTITY_ALIAS);
843 query.append(orderByFields[i]);
844
845 if ((i + 1) < orderByFields.length) {
846 if (orderByComparator.isAscending() ^ previous) {
847 query.append(ORDER_BY_ASC_HAS_NEXT);
848 }
849 else {
850 query.append(ORDER_BY_DESC_HAS_NEXT);
851 }
852 }
853 else {
854 if (orderByComparator.isAscending() ^ previous) {
855 query.append(ORDER_BY_ASC);
856 }
857 else {
858 query.append(ORDER_BY_DESC);
859 }
860 }
861 }
862 }
863
864 String sql = query.toString();
865
866 Query q = session.createQuery(sql);
867
868 q.setFirstResult(0);
869 q.setMaxResults(2);
870
871 QueryPos qPos = QueryPos.getInstance(q);
872
873 qPos.add(resourceId);
874
875 if (orderByComparator != null) {
876 Object[] values = orderByComparator.getOrderByConditionValues(permission);
877
878 for (Object value : values) {
879 qPos.add(value);
880 }
881 }
882
883 List<Permission> list = q.list();
884
885 if (list.size() == 2) {
886 return list.get(1);
887 }
888 else {
889 return null;
890 }
891 }
892
893
902 public Permission findByA_R(String actionId, long resourceId)
903 throws NoSuchPermissionException, SystemException {
904 Permission permission = fetchByA_R(actionId, resourceId);
905
906 if (permission == null) {
907 StringBundler msg = new StringBundler(6);
908
909 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
910
911 msg.append("actionId=");
912 msg.append(actionId);
913
914 msg.append(", resourceId=");
915 msg.append(resourceId);
916
917 msg.append(StringPool.CLOSE_CURLY_BRACE);
918
919 if (_log.isWarnEnabled()) {
920 _log.warn(msg.toString());
921 }
922
923 throw new NoSuchPermissionException(msg.toString());
924 }
925
926 return permission;
927 }
928
929
937 public Permission fetchByA_R(String actionId, long resourceId)
938 throws SystemException {
939 return fetchByA_R(actionId, resourceId, true);
940 }
941
942
951 public Permission fetchByA_R(String actionId, long resourceId,
952 boolean retrieveFromCache) throws SystemException {
953 Object[] finderArgs = new Object[] { actionId, resourceId };
954
955 Object result = null;
956
957 if (retrieveFromCache) {
958 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A_R,
959 finderArgs, this);
960 }
961
962 if (result instanceof Permission) {
963 Permission permission = (Permission)result;
964
965 if (!Validator.equals(actionId, permission.getActionId()) ||
966 (resourceId != permission.getResourceId())) {
967 result = null;
968 }
969 }
970
971 if (result == null) {
972 StringBundler query = new StringBundler(3);
973
974 query.append(_SQL_SELECT_PERMISSION_WHERE);
975
976 if (actionId == null) {
977 query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
978 }
979 else {
980 if (actionId.equals(StringPool.BLANK)) {
981 query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
982 }
983 else {
984 query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
985 }
986 }
987
988 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
989
990 String sql = query.toString();
991
992 Session session = null;
993
994 try {
995 session = openSession();
996
997 Query q = session.createQuery(sql);
998
999 QueryPos qPos = QueryPos.getInstance(q);
1000
1001 if (actionId != null) {
1002 qPos.add(actionId);
1003 }
1004
1005 qPos.add(resourceId);
1006
1007 List<Permission> list = q.list();
1008
1009 result = list;
1010
1011 Permission permission = null;
1012
1013 if (list.isEmpty()) {
1014 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
1015 finderArgs, list);
1016 }
1017 else {
1018 permission = list.get(0);
1019
1020 cacheResult(permission);
1021
1022 if ((permission.getActionId() == null) ||
1023 !permission.getActionId().equals(actionId) ||
1024 (permission.getResourceId() != resourceId)) {
1025 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
1026 finderArgs, permission);
1027 }
1028 }
1029
1030 return permission;
1031 }
1032 catch (Exception e) {
1033 throw processException(e);
1034 }
1035 finally {
1036 if (result == null) {
1037 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
1038 finderArgs);
1039 }
1040
1041 closeSession(session);
1042 }
1043 }
1044 else {
1045 if (result instanceof List<?>) {
1046 return null;
1047 }
1048 else {
1049 return (Permission)result;
1050 }
1051 }
1052 }
1053
1054
1060 public List<Permission> findAll() throws SystemException {
1061 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1062 }
1063
1064
1076 public List<Permission> findAll(int start, int end)
1077 throws SystemException {
1078 return findAll(start, end, null);
1079 }
1080
1081
1094 public List<Permission> findAll(int start, int end,
1095 OrderByComparator orderByComparator) throws SystemException {
1096 FinderPath finderPath = null;
1097 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1098
1099 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1100 (orderByComparator == null)) {
1101 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1102 finderArgs = FINDER_ARGS_EMPTY;
1103 }
1104 else {
1105 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1106 finderArgs = new Object[] { start, end, orderByComparator };
1107 }
1108
1109 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(finderPath,
1110 finderArgs, this);
1111
1112 if (list == null) {
1113 StringBundler query = null;
1114 String sql = null;
1115
1116 if (orderByComparator != null) {
1117 query = new StringBundler(2 +
1118 (orderByComparator.getOrderByFields().length * 3));
1119
1120 query.append(_SQL_SELECT_PERMISSION);
1121
1122 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1123 orderByComparator);
1124
1125 sql = query.toString();
1126 }
1127 else {
1128 sql = _SQL_SELECT_PERMISSION;
1129 }
1130
1131 Session session = null;
1132
1133 try {
1134 session = openSession();
1135
1136 Query q = session.createQuery(sql);
1137
1138 if (orderByComparator == null) {
1139 list = (List<Permission>)QueryUtil.list(q, getDialect(),
1140 start, end, false);
1141
1142 Collections.sort(list);
1143 }
1144 else {
1145 list = (List<Permission>)QueryUtil.list(q, getDialect(),
1146 start, end);
1147 }
1148 }
1149 catch (Exception e) {
1150 throw processException(e);
1151 }
1152 finally {
1153 if (list == null) {
1154 FinderCacheUtil.removeResult(finderPath, finderArgs);
1155 }
1156 else {
1157 cacheResult(list);
1158
1159 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1160 }
1161
1162 closeSession(session);
1163 }
1164 }
1165
1166 return list;
1167 }
1168
1169
1175 public void removeByResourceId(long resourceId) throws SystemException {
1176 for (Permission permission : findByResourceId(resourceId)) {
1177 remove(permission);
1178 }
1179 }
1180
1181
1188 public void removeByA_R(String actionId, long resourceId)
1189 throws NoSuchPermissionException, SystemException {
1190 Permission permission = findByA_R(actionId, resourceId);
1191
1192 remove(permission);
1193 }
1194
1195
1200 public void removeAll() throws SystemException {
1201 for (Permission permission : findAll()) {
1202 remove(permission);
1203 }
1204 }
1205
1206
1213 public int countByResourceId(long resourceId) throws SystemException {
1214 Object[] finderArgs = new Object[] { resourceId };
1215
1216 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEID,
1217 finderArgs, this);
1218
1219 if (count == null) {
1220 StringBundler query = new StringBundler(2);
1221
1222 query.append(_SQL_COUNT_PERMISSION_WHERE);
1223
1224 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
1225
1226 String sql = query.toString();
1227
1228 Session session = null;
1229
1230 try {
1231 session = openSession();
1232
1233 Query q = session.createQuery(sql);
1234
1235 QueryPos qPos = QueryPos.getInstance(q);
1236
1237 qPos.add(resourceId);
1238
1239 count = (Long)q.uniqueResult();
1240 }
1241 catch (Exception e) {
1242 throw processException(e);
1243 }
1244 finally {
1245 if (count == null) {
1246 count = Long.valueOf(0);
1247 }
1248
1249 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEID,
1250 finderArgs, count);
1251
1252 closeSession(session);
1253 }
1254 }
1255
1256 return count.intValue();
1257 }
1258
1259
1267 public int countByA_R(String actionId, long resourceId)
1268 throws SystemException {
1269 Object[] finderArgs = new Object[] { actionId, resourceId };
1270
1271 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
1272 finderArgs, this);
1273
1274 if (count == null) {
1275 StringBundler query = new StringBundler(3);
1276
1277 query.append(_SQL_COUNT_PERMISSION_WHERE);
1278
1279 if (actionId == null) {
1280 query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
1281 }
1282 else {
1283 if (actionId.equals(StringPool.BLANK)) {
1284 query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
1285 }
1286 else {
1287 query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
1288 }
1289 }
1290
1291 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
1292
1293 String sql = query.toString();
1294
1295 Session session = null;
1296
1297 try {
1298 session = openSession();
1299
1300 Query q = session.createQuery(sql);
1301
1302 QueryPos qPos = QueryPos.getInstance(q);
1303
1304 if (actionId != null) {
1305 qPos.add(actionId);
1306 }
1307
1308 qPos.add(resourceId);
1309
1310 count = (Long)q.uniqueResult();
1311 }
1312 catch (Exception e) {
1313 throw processException(e);
1314 }
1315 finally {
1316 if (count == null) {
1317 count = Long.valueOf(0);
1318 }
1319
1320 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
1321 count);
1322
1323 closeSession(session);
1324 }
1325 }
1326
1327 return count.intValue();
1328 }
1329
1330
1336 public int countAll() throws SystemException {
1337 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1338 FINDER_ARGS_EMPTY, this);
1339
1340 if (count == null) {
1341 Session session = null;
1342
1343 try {
1344 session = openSession();
1345
1346 Query q = session.createQuery(_SQL_COUNT_PERMISSION);
1347
1348 count = (Long)q.uniqueResult();
1349 }
1350 catch (Exception e) {
1351 throw processException(e);
1352 }
1353 finally {
1354 if (count == null) {
1355 count = Long.valueOf(0);
1356 }
1357
1358 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1359 FINDER_ARGS_EMPTY, count);
1360
1361 closeSession(session);
1362 }
1363 }
1364
1365 return count.intValue();
1366 }
1367
1368
1375 public List<com.liferay.portal.model.Group> getGroups(long pk)
1376 throws SystemException {
1377 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1378 }
1379
1380
1393 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1394 int end) throws SystemException {
1395 return getGroups(pk, start, end, null);
1396 }
1397
1398 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1399 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1400 com.liferay.portal.model.impl.GroupImpl.class,
1401 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1402 "getGroups",
1403 new String[] {
1404 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1405 "com.liferay.portal.kernel.util.OrderByComparator"
1406 });
1407
1408 static {
1409 FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
1410 }
1411
1412
1426 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1427 int end, OrderByComparator orderByComparator) throws SystemException {
1428 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
1429
1430 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1431 finderArgs, this);
1432
1433 if (list == null) {
1434 Session session = null;
1435
1436 try {
1437 session = openSession();
1438
1439 String sql = null;
1440
1441 if (orderByComparator != null) {
1442 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1443 .concat(orderByComparator.getOrderBy());
1444 }
1445 else {
1446 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1447 }
1448
1449 SQLQuery q = session.createSQLQuery(sql);
1450
1451 q.addEntity("Group_",
1452 com.liferay.portal.model.impl.GroupImpl.class);
1453
1454 QueryPos qPos = QueryPos.getInstance(q);
1455
1456 qPos.add(pk);
1457
1458 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1459 getDialect(), start, end);
1460 }
1461 catch (Exception e) {
1462 throw processException(e);
1463 }
1464 finally {
1465 if (list == null) {
1466 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
1467 finderArgs);
1468 }
1469 else {
1470 groupPersistence.cacheResult(list);
1471
1472 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
1473 finderArgs, list);
1474 }
1475
1476 closeSession(session);
1477 }
1478 }
1479
1480 return list;
1481 }
1482
1483 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1484 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1485 Long.class,
1486 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1487 "getGroupsSize", new String[] { Long.class.getName() });
1488
1489 static {
1490 FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
1491 }
1492
1493
1500 public int getGroupsSize(long pk) throws SystemException {
1501 Object[] finderArgs = new Object[] { pk };
1502
1503 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1504 finderArgs, this);
1505
1506 if (count == null) {
1507 Session session = null;
1508
1509 try {
1510 session = openSession();
1511
1512 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1513
1514 q.addScalar(COUNT_COLUMN_NAME,
1515 com.liferay.portal.kernel.dao.orm.Type.LONG);
1516
1517 QueryPos qPos = QueryPos.getInstance(q);
1518
1519 qPos.add(pk);
1520
1521 count = (Long)q.uniqueResult();
1522 }
1523 catch (Exception e) {
1524 throw processException(e);
1525 }
1526 finally {
1527 if (count == null) {
1528 count = Long.valueOf(0);
1529 }
1530
1531 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1532 finderArgs, count);
1533
1534 closeSession(session);
1535 }
1536 }
1537
1538 return count.intValue();
1539 }
1540
1541 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1542 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1543 Boolean.class,
1544 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1545 "containsGroup",
1546 new String[] { Long.class.getName(), Long.class.getName() });
1547
1548
1556 public boolean containsGroup(long pk, long groupPK)
1557 throws SystemException {
1558 Object[] finderArgs = new Object[] { pk, groupPK };
1559
1560 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1561 finderArgs, this);
1562
1563 if (value == null) {
1564 try {
1565 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1566 }
1567 catch (Exception e) {
1568 throw processException(e);
1569 }
1570 finally {
1571 if (value == null) {
1572 value = Boolean.FALSE;
1573 }
1574
1575 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1576 finderArgs, value);
1577 }
1578 }
1579
1580 return value.booleanValue();
1581 }
1582
1583
1590 public boolean containsGroups(long pk) throws SystemException {
1591 if (getGroupsSize(pk) > 0) {
1592 return true;
1593 }
1594 else {
1595 return false;
1596 }
1597 }
1598
1599
1606 public void addGroup(long pk, long groupPK) throws SystemException {
1607 try {
1608 addGroup.add(pk, groupPK);
1609 }
1610 catch (Exception e) {
1611 throw processException(e);
1612 }
1613 finally {
1614 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1615 }
1616 }
1617
1618
1625 public void addGroup(long pk, com.liferay.portal.model.Group group)
1626 throws SystemException {
1627 try {
1628 addGroup.add(pk, group.getPrimaryKey());
1629 }
1630 catch (Exception e) {
1631 throw processException(e);
1632 }
1633 finally {
1634 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1635 }
1636 }
1637
1638
1645 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1646 try {
1647 for (long groupPK : groupPKs) {
1648 addGroup.add(pk, groupPK);
1649 }
1650 }
1651 catch (Exception e) {
1652 throw processException(e);
1653 }
1654 finally {
1655 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1656 }
1657 }
1658
1659
1666 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1667 throws SystemException {
1668 try {
1669 for (com.liferay.portal.model.Group group : groups) {
1670 addGroup.add(pk, group.getPrimaryKey());
1671 }
1672 }
1673 catch (Exception e) {
1674 throw processException(e);
1675 }
1676 finally {
1677 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1678 }
1679 }
1680
1681
1687 public void clearGroups(long pk) throws SystemException {
1688 try {
1689 clearGroups.clear(pk);
1690 }
1691 catch (Exception e) {
1692 throw processException(e);
1693 }
1694 finally {
1695 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1696 }
1697 }
1698
1699
1706 public void removeGroup(long pk, long groupPK) throws SystemException {
1707 try {
1708 removeGroup.remove(pk, groupPK);
1709 }
1710 catch (Exception e) {
1711 throw processException(e);
1712 }
1713 finally {
1714 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1715 }
1716 }
1717
1718
1725 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1726 throws SystemException {
1727 try {
1728 removeGroup.remove(pk, group.getPrimaryKey());
1729 }
1730 catch (Exception e) {
1731 throw processException(e);
1732 }
1733 finally {
1734 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1735 }
1736 }
1737
1738
1745 public void removeGroups(long pk, long[] groupPKs)
1746 throws SystemException {
1747 try {
1748 for (long groupPK : groupPKs) {
1749 removeGroup.remove(pk, groupPK);
1750 }
1751 }
1752 catch (Exception e) {
1753 throw processException(e);
1754 }
1755 finally {
1756 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1757 }
1758 }
1759
1760
1767 public void removeGroups(long pk,
1768 List<com.liferay.portal.model.Group> groups) throws SystemException {
1769 try {
1770 for (com.liferay.portal.model.Group group : groups) {
1771 removeGroup.remove(pk, group.getPrimaryKey());
1772 }
1773 }
1774 catch (Exception e) {
1775 throw processException(e);
1776 }
1777 finally {
1778 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1779 }
1780 }
1781
1782
1789 public void setGroups(long pk, long[] groupPKs) throws SystemException {
1790 try {
1791 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1792
1793 List<com.liferay.portal.model.Group> groups = getGroups(pk);
1794
1795 for (com.liferay.portal.model.Group group : groups) {
1796 if (!groupPKSet.remove(group.getPrimaryKey())) {
1797 removeGroup.remove(pk, group.getPrimaryKey());
1798 }
1799 }
1800
1801 for (Long groupPK : groupPKSet) {
1802 addGroup.add(pk, groupPK);
1803 }
1804 }
1805 catch (Exception e) {
1806 throw processException(e);
1807 }
1808 finally {
1809 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1810 }
1811 }
1812
1813
1820 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1821 throws SystemException {
1822 try {
1823 long[] groupPKs = new long[groups.size()];
1824
1825 for (int i = 0; i < groups.size(); i++) {
1826 com.liferay.portal.model.Group group = groups.get(i);
1827
1828 groupPKs[i] = group.getPrimaryKey();
1829 }
1830
1831 setGroups(pk, groupPKs);
1832 }
1833 catch (Exception e) {
1834 throw processException(e);
1835 }
1836 finally {
1837 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1838 }
1839 }
1840
1841
1848 public List<com.liferay.portal.model.Role> getRoles(long pk)
1849 throws SystemException {
1850 return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1851 }
1852
1853
1866 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1867 int end) throws SystemException {
1868 return getRoles(pk, start, end, null);
1869 }
1870
1871 public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1872 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1873 com.liferay.portal.model.impl.RoleImpl.class,
1874 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1875 "getRoles",
1876 new String[] {
1877 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1878 "com.liferay.portal.kernel.util.OrderByComparator"
1879 });
1880
1881 static {
1882 FINDER_PATH_GET_ROLES.setCacheKeyGeneratorCacheName(null);
1883 }
1884
1885
1899 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1900 int end, OrderByComparator orderByComparator) throws SystemException {
1901 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
1902
1903 List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
1904 finderArgs, this);
1905
1906 if (list == null) {
1907 Session session = null;
1908
1909 try {
1910 session = openSession();
1911
1912 String sql = null;
1913
1914 if (orderByComparator != null) {
1915 sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
1916 .concat(orderByComparator.getOrderBy());
1917 }
1918 else {
1919 sql = _SQL_GETROLES.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
1920 }
1921
1922 SQLQuery q = session.createSQLQuery(sql);
1923
1924 q.addEntity("Role_",
1925 com.liferay.portal.model.impl.RoleImpl.class);
1926
1927 QueryPos qPos = QueryPos.getInstance(q);
1928
1929 qPos.add(pk);
1930
1931 list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
1932 getDialect(), start, end);
1933 }
1934 catch (Exception e) {
1935 throw processException(e);
1936 }
1937 finally {
1938 if (list == null) {
1939 FinderCacheUtil.removeResult(FINDER_PATH_GET_ROLES,
1940 finderArgs);
1941 }
1942 else {
1943 rolePersistence.cacheResult(list);
1944
1945 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES,
1946 finderArgs, list);
1947 }
1948
1949 closeSession(session);
1950 }
1951 }
1952
1953 return list;
1954 }
1955
1956 public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1957 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1958 Long.class,
1959 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1960 "getRolesSize", new String[] { Long.class.getName() });
1961
1962 static {
1963 FINDER_PATH_GET_ROLES_SIZE.setCacheKeyGeneratorCacheName(null);
1964 }
1965
1966
1973 public int getRolesSize(long pk) throws SystemException {
1974 Object[] finderArgs = new Object[] { pk };
1975
1976 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
1977 finderArgs, this);
1978
1979 if (count == null) {
1980 Session session = null;
1981
1982 try {
1983 session = openSession();
1984
1985 SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
1986
1987 q.addScalar(COUNT_COLUMN_NAME,
1988 com.liferay.portal.kernel.dao.orm.Type.LONG);
1989
1990 QueryPos qPos = QueryPos.getInstance(q);
1991
1992 qPos.add(pk);
1993
1994 count = (Long)q.uniqueResult();
1995 }
1996 catch (Exception e) {
1997 throw processException(e);
1998 }
1999 finally {
2000 if (count == null) {
2001 count = Long.valueOf(0);
2002 }
2003
2004 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
2005 finderArgs, count);
2006
2007 closeSession(session);
2008 }
2009 }
2010
2011 return count.intValue();
2012 }
2013
2014 public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
2015 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2016 Boolean.class,
2017 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
2018 "containsRole",
2019 new String[] { Long.class.getName(), Long.class.getName() });
2020
2021
2029 public boolean containsRole(long pk, long rolePK) throws SystemException {
2030 Object[] finderArgs = new Object[] { pk, rolePK };
2031
2032 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
2033 finderArgs, this);
2034
2035 if (value == null) {
2036 try {
2037 value = Boolean.valueOf(containsRole.contains(pk, rolePK));
2038 }
2039 catch (Exception e) {
2040 throw processException(e);
2041 }
2042 finally {
2043 if (value == null) {
2044 value = Boolean.FALSE;
2045 }
2046
2047 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
2048 finderArgs, value);
2049 }
2050 }
2051
2052 return value.booleanValue();
2053 }
2054
2055
2062 public boolean containsRoles(long pk) throws SystemException {
2063 if (getRolesSize(pk) > 0) {
2064 return true;
2065 }
2066 else {
2067 return false;
2068 }
2069 }
2070
2071
2078 public void addRole(long pk, long rolePK) throws SystemException {
2079 try {
2080 addRole.add(pk, rolePK);
2081 }
2082 catch (Exception e) {
2083 throw processException(e);
2084 }
2085 finally {
2086 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2087 }
2088 }
2089
2090
2097 public void addRole(long pk, com.liferay.portal.model.Role role)
2098 throws SystemException {
2099 try {
2100 addRole.add(pk, role.getPrimaryKey());
2101 }
2102 catch (Exception e) {
2103 throw processException(e);
2104 }
2105 finally {
2106 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2107 }
2108 }
2109
2110
2117 public void addRoles(long pk, long[] rolePKs) throws SystemException {
2118 try {
2119 for (long rolePK : rolePKs) {
2120 addRole.add(pk, rolePK);
2121 }
2122 }
2123 catch (Exception e) {
2124 throw processException(e);
2125 }
2126 finally {
2127 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2128 }
2129 }
2130
2131
2138 public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
2139 throws SystemException {
2140 try {
2141 for (com.liferay.portal.model.Role role : roles) {
2142 addRole.add(pk, role.getPrimaryKey());
2143 }
2144 }
2145 catch (Exception e) {
2146 throw processException(e);
2147 }
2148 finally {
2149 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2150 }
2151 }
2152
2153
2159 public void clearRoles(long pk) throws SystemException {
2160 try {
2161 clearRoles.clear(pk);
2162 }
2163 catch (Exception e) {
2164 throw processException(e);
2165 }
2166 finally {
2167 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2168 }
2169 }
2170
2171
2178 public void removeRole(long pk, long rolePK) throws SystemException {
2179 try {
2180 removeRole.remove(pk, rolePK);
2181 }
2182 catch (Exception e) {
2183 throw processException(e);
2184 }
2185 finally {
2186 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2187 }
2188 }
2189
2190
2197 public void removeRole(long pk, com.liferay.portal.model.Role role)
2198 throws SystemException {
2199 try {
2200 removeRole.remove(pk, role.getPrimaryKey());
2201 }
2202 catch (Exception e) {
2203 throw processException(e);
2204 }
2205 finally {
2206 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2207 }
2208 }
2209
2210
2217 public void removeRoles(long pk, long[] rolePKs) throws SystemException {
2218 try {
2219 for (long rolePK : rolePKs) {
2220 removeRole.remove(pk, rolePK);
2221 }
2222 }
2223 catch (Exception e) {
2224 throw processException(e);
2225 }
2226 finally {
2227 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2228 }
2229 }
2230
2231
2238 public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
2239 throws SystemException {
2240 try {
2241 for (com.liferay.portal.model.Role role : roles) {
2242 removeRole.remove(pk, role.getPrimaryKey());
2243 }
2244 }
2245 catch (Exception e) {
2246 throw processException(e);
2247 }
2248 finally {
2249 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2250 }
2251 }
2252
2253
2260 public void setRoles(long pk, long[] rolePKs) throws SystemException {
2261 try {
2262 Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
2263
2264 List<com.liferay.portal.model.Role> roles = getRoles(pk);
2265
2266 for (com.liferay.portal.model.Role role : roles) {
2267 if (!rolePKSet.remove(role.getPrimaryKey())) {
2268 removeRole.remove(pk, role.getPrimaryKey());
2269 }
2270 }
2271
2272 for (Long rolePK : rolePKSet) {
2273 addRole.add(pk, rolePK);
2274 }
2275 }
2276 catch (Exception e) {
2277 throw processException(e);
2278 }
2279 finally {
2280 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2281 }
2282 }
2283
2284
2291 public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
2292 throws SystemException {
2293 try {
2294 long[] rolePKs = new long[roles.size()];
2295
2296 for (int i = 0; i < roles.size(); i++) {
2297 com.liferay.portal.model.Role role = roles.get(i);
2298
2299 rolePKs[i] = role.getPrimaryKey();
2300 }
2301
2302 setRoles(pk, rolePKs);
2303 }
2304 catch (Exception e) {
2305 throw processException(e);
2306 }
2307 finally {
2308 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2309 }
2310 }
2311
2312
2319 public List<com.liferay.portal.model.User> getUsers(long pk)
2320 throws SystemException {
2321 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2322 }
2323
2324
2337 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2338 int end) throws SystemException {
2339 return getUsers(pk, start, end, null);
2340 }
2341
2342 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2343 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2344 com.liferay.portal.model.impl.UserImpl.class,
2345 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2346 "getUsers",
2347 new String[] {
2348 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2349 "com.liferay.portal.kernel.util.OrderByComparator"
2350 });
2351
2352 static {
2353 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
2354 }
2355
2356
2370 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2371 int end, OrderByComparator orderByComparator) throws SystemException {
2372 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
2373
2374 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2375 finderArgs, this);
2376
2377 if (list == null) {
2378 Session session = null;
2379
2380 try {
2381 session = openSession();
2382
2383 String sql = null;
2384
2385 if (orderByComparator != null) {
2386 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
2387 .concat(orderByComparator.getOrderBy());
2388 }
2389 else {
2390 sql = _SQL_GETUSERS;
2391 }
2392
2393 SQLQuery q = session.createSQLQuery(sql);
2394
2395 q.addEntity("User_",
2396 com.liferay.portal.model.impl.UserImpl.class);
2397
2398 QueryPos qPos = QueryPos.getInstance(q);
2399
2400 qPos.add(pk);
2401
2402 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2403 getDialect(), start, end);
2404 }
2405 catch (Exception e) {
2406 throw processException(e);
2407 }
2408 finally {
2409 if (list == null) {
2410 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
2411 finderArgs);
2412 }
2413 else {
2414 userPersistence.cacheResult(list);
2415
2416 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
2417 finderArgs, list);
2418 }
2419
2420 closeSession(session);
2421 }
2422 }
2423
2424 return list;
2425 }
2426
2427 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2428 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2429 Long.class,
2430 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2431 "getUsersSize", new String[] { Long.class.getName() });
2432
2433 static {
2434 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
2435 }
2436
2437
2444 public int getUsersSize(long pk) throws SystemException {
2445 Object[] finderArgs = new Object[] { pk };
2446
2447 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2448 finderArgs, this);
2449
2450 if (count == null) {
2451 Session session = null;
2452
2453 try {
2454 session = openSession();
2455
2456 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2457
2458 q.addScalar(COUNT_COLUMN_NAME,
2459 com.liferay.portal.kernel.dao.orm.Type.LONG);
2460
2461 QueryPos qPos = QueryPos.getInstance(q);
2462
2463 qPos.add(pk);
2464
2465 count = (Long)q.uniqueResult();
2466 }
2467 catch (Exception e) {
2468 throw processException(e);
2469 }
2470 finally {
2471 if (count == null) {
2472 count = Long.valueOf(0);
2473 }
2474
2475 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2476 finderArgs, count);
2477
2478 closeSession(session);
2479 }
2480 }
2481
2482 return count.intValue();
2483 }
2484
2485 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2486 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2487 Boolean.class,
2488 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2489 "containsUser",
2490 new String[] { Long.class.getName(), Long.class.getName() });
2491
2492
2500 public boolean containsUser(long pk, long userPK) throws SystemException {
2501 Object[] finderArgs = new Object[] { pk, userPK };
2502
2503 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2504 finderArgs, this);
2505
2506 if (value == null) {
2507 try {
2508 value = Boolean.valueOf(containsUser.contains(pk, userPK));
2509 }
2510 catch (Exception e) {
2511 throw processException(e);
2512 }
2513 finally {
2514 if (value == null) {
2515 value = Boolean.FALSE;
2516 }
2517
2518 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2519 finderArgs, value);
2520 }
2521 }
2522
2523 return value.booleanValue();
2524 }
2525
2526
2533 public boolean containsUsers(long pk) throws SystemException {
2534 if (getUsersSize(pk) > 0) {
2535 return true;
2536 }
2537 else {
2538 return false;
2539 }
2540 }
2541
2542
2549 public void addUser(long pk, long userPK) throws SystemException {
2550 try {
2551 addUser.add(pk, userPK);
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 addUser(long pk, com.liferay.portal.model.User user)
2569 throws SystemException {
2570 try {
2571 addUser.add(pk, user.getPrimaryKey());
2572 }
2573 catch (Exception e) {
2574 throw processException(e);
2575 }
2576 finally {
2577 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2578 }
2579 }
2580
2581
2588 public void addUsers(long pk, long[] userPKs) throws SystemException {
2589 try {
2590 for (long userPK : userPKs) {
2591 addUser.add(pk, userPK);
2592 }
2593 }
2594 catch (Exception e) {
2595 throw processException(e);
2596 }
2597 finally {
2598 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2599 }
2600 }
2601
2602
2609 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2610 throws SystemException {
2611 try {
2612 for (com.liferay.portal.model.User user : users) {
2613 addUser.add(pk, user.getPrimaryKey());
2614 }
2615 }
2616 catch (Exception e) {
2617 throw processException(e);
2618 }
2619 finally {
2620 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2621 }
2622 }
2623
2624
2630 public void clearUsers(long pk) throws SystemException {
2631 try {
2632 clearUsers.clear(pk);
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
2649 public void removeUser(long pk, long userPK) throws SystemException {
2650 try {
2651 removeUser.remove(pk, userPK);
2652 }
2653 catch (Exception e) {
2654 throw processException(e);
2655 }
2656 finally {
2657 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2658 }
2659 }
2660
2661
2668 public void removeUser(long pk, com.liferay.portal.model.User user)
2669 throws SystemException {
2670 try {
2671 removeUser.remove(pk, user.getPrimaryKey());
2672 }
2673 catch (Exception e) {
2674 throw processException(e);
2675 }
2676 finally {
2677 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2678 }
2679 }
2680
2681
2688 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2689 try {
2690 for (long userPK : userPKs) {
2691 removeUser.remove(pk, userPK);
2692 }
2693 }
2694 catch (Exception e) {
2695 throw processException(e);
2696 }
2697 finally {
2698 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2699 }
2700 }
2701
2702
2709 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2710 throws SystemException {
2711 try {
2712 for (com.liferay.portal.model.User user : users) {
2713 removeUser.remove(pk, user.getPrimaryKey());
2714 }
2715 }
2716 catch (Exception e) {
2717 throw processException(e);
2718 }
2719 finally {
2720 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2721 }
2722 }
2723
2724
2731 public void setUsers(long pk, long[] userPKs) throws SystemException {
2732 try {
2733 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2734
2735 List<com.liferay.portal.model.User> users = getUsers(pk);
2736
2737 for (com.liferay.portal.model.User user : users) {
2738 if (!userPKSet.remove(user.getPrimaryKey())) {
2739 removeUser.remove(pk, user.getPrimaryKey());
2740 }
2741 }
2742
2743 for (Long userPK : userPKSet) {
2744 addUser.add(pk, userPK);
2745 }
2746 }
2747 catch (Exception e) {
2748 throw processException(e);
2749 }
2750 finally {
2751 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2752 }
2753 }
2754
2755
2762 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2763 throws SystemException {
2764 try {
2765 long[] userPKs = new long[users.size()];
2766
2767 for (int i = 0; i < users.size(); i++) {
2768 com.liferay.portal.model.User user = users.get(i);
2769
2770 userPKs[i] = user.getPrimaryKey();
2771 }
2772
2773 setUsers(pk, userPKs);
2774 }
2775 catch (Exception e) {
2776 throw processException(e);
2777 }
2778 finally {
2779 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2780 }
2781 }
2782
2783
2786 public void afterPropertiesSet() {
2787 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2788 com.liferay.portal.util.PropsUtil.get(
2789 "value.object.listener.com.liferay.portal.model.Permission")));
2790
2791 if (listenerClassNames.length > 0) {
2792 try {
2793 List<ModelListener<Permission>> listenersList = new ArrayList<ModelListener<Permission>>();
2794
2795 for (String listenerClassName : listenerClassNames) {
2796 listenersList.add((ModelListener<Permission>)InstanceFactory.newInstance(
2797 listenerClassName));
2798 }
2799
2800 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2801 }
2802 catch (Exception e) {
2803 _log.error(e);
2804 }
2805 }
2806
2807 containsGroup = new ContainsGroup();
2808
2809 addGroup = new AddGroup();
2810 clearGroups = new ClearGroups();
2811 removeGroup = new RemoveGroup();
2812
2813 containsRole = new ContainsRole();
2814
2815 addRole = new AddRole();
2816 clearRoles = new ClearRoles();
2817 removeRole = new RemoveRole();
2818
2819 containsUser = new ContainsUser();
2820
2821 addUser = new AddUser();
2822 clearUsers = new ClearUsers();
2823 removeUser = new RemoveUser();
2824 }
2825
2826 public void destroy() {
2827 EntityCacheUtil.removeCache(PermissionImpl.class.getName());
2828 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2829 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2830 }
2831
2832 @BeanReference(type = AccountPersistence.class)
2833 protected AccountPersistence accountPersistence;
2834 @BeanReference(type = AddressPersistence.class)
2835 protected AddressPersistence addressPersistence;
2836 @BeanReference(type = BrowserTrackerPersistence.class)
2837 protected BrowserTrackerPersistence browserTrackerPersistence;
2838 @BeanReference(type = ClassNamePersistence.class)
2839 protected ClassNamePersistence classNamePersistence;
2840 @BeanReference(type = ClusterGroupPersistence.class)
2841 protected ClusterGroupPersistence clusterGroupPersistence;
2842 @BeanReference(type = CompanyPersistence.class)
2843 protected CompanyPersistence companyPersistence;
2844 @BeanReference(type = ContactPersistence.class)
2845 protected ContactPersistence contactPersistence;
2846 @BeanReference(type = CountryPersistence.class)
2847 protected CountryPersistence countryPersistence;
2848 @BeanReference(type = EmailAddressPersistence.class)
2849 protected EmailAddressPersistence emailAddressPersistence;
2850 @BeanReference(type = GroupPersistence.class)
2851 protected GroupPersistence groupPersistence;
2852 @BeanReference(type = ImagePersistence.class)
2853 protected ImagePersistence imagePersistence;
2854 @BeanReference(type = LayoutPersistence.class)
2855 protected LayoutPersistence layoutPersistence;
2856 @BeanReference(type = LayoutBranchPersistence.class)
2857 protected LayoutBranchPersistence layoutBranchPersistence;
2858 @BeanReference(type = LayoutPrototypePersistence.class)
2859 protected LayoutPrototypePersistence layoutPrototypePersistence;
2860 @BeanReference(type = LayoutRevisionPersistence.class)
2861 protected LayoutRevisionPersistence layoutRevisionPersistence;
2862 @BeanReference(type = LayoutSetPersistence.class)
2863 protected LayoutSetPersistence layoutSetPersistence;
2864 @BeanReference(type = LayoutSetBranchPersistence.class)
2865 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2866 @BeanReference(type = LayoutSetPrototypePersistence.class)
2867 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2868 @BeanReference(type = ListTypePersistence.class)
2869 protected ListTypePersistence listTypePersistence;
2870 @BeanReference(type = LockPersistence.class)
2871 protected LockPersistence lockPersistence;
2872 @BeanReference(type = MembershipRequestPersistence.class)
2873 protected MembershipRequestPersistence membershipRequestPersistence;
2874 @BeanReference(type = OrganizationPersistence.class)
2875 protected OrganizationPersistence organizationPersistence;
2876 @BeanReference(type = OrgGroupPermissionPersistence.class)
2877 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2878 @BeanReference(type = OrgGroupRolePersistence.class)
2879 protected OrgGroupRolePersistence orgGroupRolePersistence;
2880 @BeanReference(type = OrgLaborPersistence.class)
2881 protected OrgLaborPersistence orgLaborPersistence;
2882 @BeanReference(type = PasswordPolicyPersistence.class)
2883 protected PasswordPolicyPersistence passwordPolicyPersistence;
2884 @BeanReference(type = PasswordPolicyRelPersistence.class)
2885 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2886 @BeanReference(type = PasswordTrackerPersistence.class)
2887 protected PasswordTrackerPersistence passwordTrackerPersistence;
2888 @BeanReference(type = PermissionPersistence.class)
2889 protected PermissionPersistence permissionPersistence;
2890 @BeanReference(type = PhonePersistence.class)
2891 protected PhonePersistence phonePersistence;
2892 @BeanReference(type = PluginSettingPersistence.class)
2893 protected PluginSettingPersistence pluginSettingPersistence;
2894 @BeanReference(type = PortalPreferencesPersistence.class)
2895 protected PortalPreferencesPersistence portalPreferencesPersistence;
2896 @BeanReference(type = PortletPersistence.class)
2897 protected PortletPersistence portletPersistence;
2898 @BeanReference(type = PortletItemPersistence.class)
2899 protected PortletItemPersistence portletItemPersistence;
2900 @BeanReference(type = PortletPreferencesPersistence.class)
2901 protected PortletPreferencesPersistence portletPreferencesPersistence;
2902 @BeanReference(type = RegionPersistence.class)
2903 protected RegionPersistence regionPersistence;
2904 @BeanReference(type = ReleasePersistence.class)
2905 protected ReleasePersistence releasePersistence;
2906 @BeanReference(type = RepositoryPersistence.class)
2907 protected RepositoryPersistence repositoryPersistence;
2908 @BeanReference(type = RepositoryEntryPersistence.class)
2909 protected RepositoryEntryPersistence repositoryEntryPersistence;
2910 @BeanReference(type = ResourcePersistence.class)
2911 protected ResourcePersistence resourcePersistence;
2912 @BeanReference(type = ResourceActionPersistence.class)
2913 protected ResourceActionPersistence resourceActionPersistence;
2914 @BeanReference(type = ResourceBlockPersistence.class)
2915 protected ResourceBlockPersistence resourceBlockPersistence;
2916 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2917 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2918 @BeanReference(type = ResourceCodePersistence.class)
2919 protected ResourceCodePersistence resourceCodePersistence;
2920 @BeanReference(type = ResourcePermissionPersistence.class)
2921 protected ResourcePermissionPersistence resourcePermissionPersistence;
2922 @BeanReference(type = ResourceTypePermissionPersistence.class)
2923 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2924 @BeanReference(type = RolePersistence.class)
2925 protected RolePersistence rolePersistence;
2926 @BeanReference(type = ServiceComponentPersistence.class)
2927 protected ServiceComponentPersistence serviceComponentPersistence;
2928 @BeanReference(type = ShardPersistence.class)
2929 protected ShardPersistence shardPersistence;
2930 @BeanReference(type = SubscriptionPersistence.class)
2931 protected SubscriptionPersistence subscriptionPersistence;
2932 @BeanReference(type = TeamPersistence.class)
2933 protected TeamPersistence teamPersistence;
2934 @BeanReference(type = TicketPersistence.class)
2935 protected TicketPersistence ticketPersistence;
2936 @BeanReference(type = UserPersistence.class)
2937 protected UserPersistence userPersistence;
2938 @BeanReference(type = UserGroupPersistence.class)
2939 protected UserGroupPersistence userGroupPersistence;
2940 @BeanReference(type = UserGroupGroupRolePersistence.class)
2941 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2942 @BeanReference(type = UserGroupRolePersistence.class)
2943 protected UserGroupRolePersistence userGroupRolePersistence;
2944 @BeanReference(type = UserIdMapperPersistence.class)
2945 protected UserIdMapperPersistence userIdMapperPersistence;
2946 @BeanReference(type = UserNotificationEventPersistence.class)
2947 protected UserNotificationEventPersistence userNotificationEventPersistence;
2948 @BeanReference(type = UserTrackerPersistence.class)
2949 protected UserTrackerPersistence userTrackerPersistence;
2950 @BeanReference(type = UserTrackerPathPersistence.class)
2951 protected UserTrackerPathPersistence userTrackerPathPersistence;
2952 @BeanReference(type = VirtualHostPersistence.class)
2953 protected VirtualHostPersistence virtualHostPersistence;
2954 @BeanReference(type = WebDAVPropsPersistence.class)
2955 protected WebDAVPropsPersistence webDAVPropsPersistence;
2956 @BeanReference(type = WebsitePersistence.class)
2957 protected WebsitePersistence websitePersistence;
2958 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2959 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2960 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2961 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2962 protected ContainsGroup containsGroup;
2963 protected AddGroup addGroup;
2964 protected ClearGroups clearGroups;
2965 protected RemoveGroup removeGroup;
2966 protected ContainsRole containsRole;
2967 protected AddRole addRole;
2968 protected ClearRoles clearRoles;
2969 protected RemoveRole removeRole;
2970 protected ContainsUser containsUser;
2971 protected AddUser addUser;
2972 protected ClearUsers clearUsers;
2973 protected RemoveUser removeUser;
2974
2975 protected class ContainsGroup {
2976 protected ContainsGroup() {
2977 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2978 _SQL_CONTAINSGROUP,
2979 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
2980 RowMapper.COUNT);
2981 }
2982
2983 protected boolean contains(long permissionId, long groupId) {
2984 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2985 new Long(permissionId), new Long(groupId)
2986 });
2987
2988 if (results.size() > 0) {
2989 Integer count = results.get(0);
2990
2991 if (count.intValue() > 0) {
2992 return true;
2993 }
2994 }
2995
2996 return false;
2997 }
2998
2999 private MappingSqlQuery<Integer> _mappingSqlQuery;
3000 }
3001
3002 protected class AddGroup {
3003 protected AddGroup() {
3004 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3005 "INSERT INTO Groups_Permissions (permissionId, groupId) VALUES (?, ?)",
3006 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3007 }
3008
3009 protected void add(long permissionId, long groupId)
3010 throws SystemException {
3011 if (!containsGroup.contains(permissionId, groupId)) {
3012 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3013
3014 for (ModelListener<Permission> listener : listeners) {
3015 listener.onBeforeAddAssociation(permissionId,
3016 com.liferay.portal.model.Group.class.getName(), groupId);
3017 }
3018
3019 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3020 listener.onBeforeAddAssociation(groupId,
3021 Permission.class.getName(), permissionId);
3022 }
3023
3024 _sqlUpdate.update(new Object[] {
3025 new Long(permissionId), new Long(groupId)
3026 });
3027
3028 for (ModelListener<Permission> listener : listeners) {
3029 listener.onAfterAddAssociation(permissionId,
3030 com.liferay.portal.model.Group.class.getName(), groupId);
3031 }
3032
3033 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3034 listener.onAfterAddAssociation(groupId,
3035 Permission.class.getName(), permissionId);
3036 }
3037 }
3038 }
3039
3040 private SqlUpdate _sqlUpdate;
3041 }
3042
3043 protected class ClearGroups {
3044 protected ClearGroups() {
3045 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3046 "DELETE FROM Groups_Permissions WHERE permissionId = ?",
3047 new int[] { java.sql.Types.BIGINT });
3048 }
3049
3050 protected void clear(long permissionId) throws SystemException {
3051 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3052
3053 List<com.liferay.portal.model.Group> groups = null;
3054
3055 if ((listeners.length > 0) || (groupListeners.length > 0)) {
3056 groups = getGroups(permissionId);
3057
3058 for (com.liferay.portal.model.Group group : groups) {
3059 for (ModelListener<Permission> listener : listeners) {
3060 listener.onBeforeRemoveAssociation(permissionId,
3061 com.liferay.portal.model.Group.class.getName(),
3062 group.getPrimaryKey());
3063 }
3064
3065 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3066 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
3067 Permission.class.getName(), permissionId);
3068 }
3069 }
3070 }
3071
3072 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3073
3074 if ((listeners.length > 0) || (groupListeners.length > 0)) {
3075 for (com.liferay.portal.model.Group group : groups) {
3076 for (ModelListener<Permission> listener : listeners) {
3077 listener.onAfterRemoveAssociation(permissionId,
3078 com.liferay.portal.model.Group.class.getName(),
3079 group.getPrimaryKey());
3080 }
3081
3082 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3083 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
3084 Permission.class.getName(), permissionId);
3085 }
3086 }
3087 }
3088 }
3089
3090 private SqlUpdate _sqlUpdate;
3091 }
3092
3093 protected class RemoveGroup {
3094 protected RemoveGroup() {
3095 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3096 "DELETE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?",
3097 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3098 }
3099
3100 protected void remove(long permissionId, long groupId)
3101 throws SystemException {
3102 if (containsGroup.contains(permissionId, groupId)) {
3103 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3104
3105 for (ModelListener<Permission> listener : listeners) {
3106 listener.onBeforeRemoveAssociation(permissionId,
3107 com.liferay.portal.model.Group.class.getName(), groupId);
3108 }
3109
3110 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3111 listener.onBeforeRemoveAssociation(groupId,
3112 Permission.class.getName(), permissionId);
3113 }
3114
3115 _sqlUpdate.update(new Object[] {
3116 new Long(permissionId), new Long(groupId)
3117 });
3118
3119 for (ModelListener<Permission> listener : listeners) {
3120 listener.onAfterRemoveAssociation(permissionId,
3121 com.liferay.portal.model.Group.class.getName(), groupId);
3122 }
3123
3124 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3125 listener.onAfterRemoveAssociation(groupId,
3126 Permission.class.getName(), permissionId);
3127 }
3128 }
3129 }
3130
3131 private SqlUpdate _sqlUpdate;
3132 }
3133
3134 protected class ContainsRole {
3135 protected ContainsRole() {
3136 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3137 _SQL_CONTAINSROLE,
3138 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3139 RowMapper.COUNT);
3140 }
3141
3142 protected boolean contains(long permissionId, long roleId) {
3143 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3144 new Long(permissionId), new Long(roleId)
3145 });
3146
3147 if (results.size() > 0) {
3148 Integer count = results.get(0);
3149
3150 if (count.intValue() > 0) {
3151 return true;
3152 }
3153 }
3154
3155 return false;
3156 }
3157
3158 private MappingSqlQuery<Integer> _mappingSqlQuery;
3159 }
3160
3161 protected class AddRole {
3162 protected AddRole() {
3163 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3164 "INSERT INTO Roles_Permissions (permissionId, roleId) VALUES (?, ?)",
3165 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3166 }
3167
3168 protected void add(long permissionId, long roleId)
3169 throws SystemException {
3170 if (!containsRole.contains(permissionId, roleId)) {
3171 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3172
3173 for (ModelListener<Permission> listener : listeners) {
3174 listener.onBeforeAddAssociation(permissionId,
3175 com.liferay.portal.model.Role.class.getName(), roleId);
3176 }
3177
3178 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3179 listener.onBeforeAddAssociation(roleId,
3180 Permission.class.getName(), permissionId);
3181 }
3182
3183 _sqlUpdate.update(new Object[] {
3184 new Long(permissionId), new Long(roleId)
3185 });
3186
3187 for (ModelListener<Permission> listener : listeners) {
3188 listener.onAfterAddAssociation(permissionId,
3189 com.liferay.portal.model.Role.class.getName(), roleId);
3190 }
3191
3192 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3193 listener.onAfterAddAssociation(roleId,
3194 Permission.class.getName(), permissionId);
3195 }
3196 }
3197 }
3198
3199 private SqlUpdate _sqlUpdate;
3200 }
3201
3202 protected class ClearRoles {
3203 protected ClearRoles() {
3204 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3205 "DELETE FROM Roles_Permissions WHERE permissionId = ?",
3206 new int[] { java.sql.Types.BIGINT });
3207 }
3208
3209 protected void clear(long permissionId) throws SystemException {
3210 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3211
3212 List<com.liferay.portal.model.Role> roles = null;
3213
3214 if ((listeners.length > 0) || (roleListeners.length > 0)) {
3215 roles = getRoles(permissionId);
3216
3217 for (com.liferay.portal.model.Role role : roles) {
3218 for (ModelListener<Permission> listener : listeners) {
3219 listener.onBeforeRemoveAssociation(permissionId,
3220 com.liferay.portal.model.Role.class.getName(),
3221 role.getPrimaryKey());
3222 }
3223
3224 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3225 listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
3226 Permission.class.getName(), permissionId);
3227 }
3228 }
3229 }
3230
3231 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3232
3233 if ((listeners.length > 0) || (roleListeners.length > 0)) {
3234 for (com.liferay.portal.model.Role role : roles) {
3235 for (ModelListener<Permission> listener : listeners) {
3236 listener.onAfterRemoveAssociation(permissionId,
3237 com.liferay.portal.model.Role.class.getName(),
3238 role.getPrimaryKey());
3239 }
3240
3241 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3242 listener.onAfterRemoveAssociation(role.getPrimaryKey(),
3243 Permission.class.getName(), permissionId);
3244 }
3245 }
3246 }
3247 }
3248
3249 private SqlUpdate _sqlUpdate;
3250 }
3251
3252 protected class RemoveRole {
3253 protected RemoveRole() {
3254 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3255 "DELETE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?",
3256 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3257 }
3258
3259 protected void remove(long permissionId, long roleId)
3260 throws SystemException {
3261 if (containsRole.contains(permissionId, roleId)) {
3262 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3263
3264 for (ModelListener<Permission> listener : listeners) {
3265 listener.onBeforeRemoveAssociation(permissionId,
3266 com.liferay.portal.model.Role.class.getName(), roleId);
3267 }
3268
3269 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3270 listener.onBeforeRemoveAssociation(roleId,
3271 Permission.class.getName(), permissionId);
3272 }
3273
3274 _sqlUpdate.update(new Object[] {
3275 new Long(permissionId), new Long(roleId)
3276 });
3277
3278 for (ModelListener<Permission> listener : listeners) {
3279 listener.onAfterRemoveAssociation(permissionId,
3280 com.liferay.portal.model.Role.class.getName(), roleId);
3281 }
3282
3283 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3284 listener.onAfterRemoveAssociation(roleId,
3285 Permission.class.getName(), permissionId);
3286 }
3287 }
3288 }
3289
3290 private SqlUpdate _sqlUpdate;
3291 }
3292
3293 protected class ContainsUser {
3294 protected ContainsUser() {
3295 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3296 _SQL_CONTAINSUSER,
3297 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3298 RowMapper.COUNT);
3299 }
3300
3301 protected boolean contains(long permissionId, long userId) {
3302 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3303 new Long(permissionId), new Long(userId)
3304 });
3305
3306 if (results.size() > 0) {
3307 Integer count = results.get(0);
3308
3309 if (count.intValue() > 0) {
3310 return true;
3311 }
3312 }
3313
3314 return false;
3315 }
3316
3317 private MappingSqlQuery<Integer> _mappingSqlQuery;
3318 }
3319
3320 protected class AddUser {
3321 protected AddUser() {
3322 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3323 "INSERT INTO Users_Permissions (permissionId, userId) VALUES (?, ?)",
3324 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3325 }
3326
3327 protected void add(long permissionId, long userId)
3328 throws SystemException {
3329 if (!containsUser.contains(permissionId, userId)) {
3330 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3331
3332 for (ModelListener<Permission> listener : listeners) {
3333 listener.onBeforeAddAssociation(permissionId,
3334 com.liferay.portal.model.User.class.getName(), userId);
3335 }
3336
3337 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3338 listener.onBeforeAddAssociation(userId,
3339 Permission.class.getName(), permissionId);
3340 }
3341
3342 _sqlUpdate.update(new Object[] {
3343 new Long(permissionId), new Long(userId)
3344 });
3345
3346 for (ModelListener<Permission> listener : listeners) {
3347 listener.onAfterAddAssociation(permissionId,
3348 com.liferay.portal.model.User.class.getName(), userId);
3349 }
3350
3351 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3352 listener.onAfterAddAssociation(userId,
3353 Permission.class.getName(), permissionId);
3354 }
3355 }
3356 }
3357
3358 private SqlUpdate _sqlUpdate;
3359 }
3360
3361 protected class ClearUsers {
3362 protected ClearUsers() {
3363 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3364 "DELETE FROM Users_Permissions WHERE permissionId = ?",
3365 new int[] { java.sql.Types.BIGINT });
3366 }
3367
3368 protected void clear(long permissionId) throws SystemException {
3369 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3370
3371 List<com.liferay.portal.model.User> users = null;
3372
3373 if ((listeners.length > 0) || (userListeners.length > 0)) {
3374 users = getUsers(permissionId);
3375
3376 for (com.liferay.portal.model.User user : users) {
3377 for (ModelListener<Permission> listener : listeners) {
3378 listener.onBeforeRemoveAssociation(permissionId,
3379 com.liferay.portal.model.User.class.getName(),
3380 user.getPrimaryKey());
3381 }
3382
3383 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3384 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3385 Permission.class.getName(), permissionId);
3386 }
3387 }
3388 }
3389
3390 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3391
3392 if ((listeners.length > 0) || (userListeners.length > 0)) {
3393 for (com.liferay.portal.model.User user : users) {
3394 for (ModelListener<Permission> listener : listeners) {
3395 listener.onAfterRemoveAssociation(permissionId,
3396 com.liferay.portal.model.User.class.getName(),
3397 user.getPrimaryKey());
3398 }
3399
3400 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3401 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
3402 Permission.class.getName(), permissionId);
3403 }
3404 }
3405 }
3406 }
3407
3408 private SqlUpdate _sqlUpdate;
3409 }
3410
3411 protected class RemoveUser {
3412 protected RemoveUser() {
3413 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3414 "DELETE FROM Users_Permissions WHERE permissionId = ? AND userId = ?",
3415 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3416 }
3417
3418 protected void remove(long permissionId, long userId)
3419 throws SystemException {
3420 if (containsUser.contains(permissionId, userId)) {
3421 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3422
3423 for (ModelListener<Permission> listener : listeners) {
3424 listener.onBeforeRemoveAssociation(permissionId,
3425 com.liferay.portal.model.User.class.getName(), userId);
3426 }
3427
3428 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3429 listener.onBeforeRemoveAssociation(userId,
3430 Permission.class.getName(), permissionId);
3431 }
3432
3433 _sqlUpdate.update(new Object[] {
3434 new Long(permissionId), new Long(userId)
3435 });
3436
3437 for (ModelListener<Permission> listener : listeners) {
3438 listener.onAfterRemoveAssociation(permissionId,
3439 com.liferay.portal.model.User.class.getName(), userId);
3440 }
3441
3442 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3443 listener.onAfterRemoveAssociation(userId,
3444 Permission.class.getName(), permissionId);
3445 }
3446 }
3447 }
3448
3449 private SqlUpdate _sqlUpdate;
3450 }
3451
3452 private static final String _SQL_SELECT_PERMISSION = "SELECT permission FROM Permission permission";
3453 private static final String _SQL_SELECT_PERMISSION_WHERE = "SELECT permission FROM Permission permission WHERE ";
3454 private static final String _SQL_COUNT_PERMISSION = "SELECT COUNT(permission) FROM Permission permission";
3455 private static final String _SQL_COUNT_PERMISSION_WHERE = "SELECT COUNT(permission) FROM Permission permission WHERE ";
3456 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Permissions ON (Groups_Permissions.groupId = Group_.groupId) WHERE (Groups_Permissions.permissionId = ?)";
3457 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ?";
3458 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?";
3459 private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Roles_Permissions ON (Roles_Permissions.roleId = Role_.roleId) WHERE (Roles_Permissions.permissionId = ?)";
3460 private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ?";
3461 private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?";
3462 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Permissions ON (Users_Permissions.userId = User_.userId) WHERE (Users_Permissions.permissionId = ?)";
3463 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ?";
3464 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ? AND userId = ?";
3465 private static final String _FINDER_COLUMN_RESOURCEID_RESOURCEID_2 = "permission.resourceId = ?";
3466 private static final String _FINDER_COLUMN_A_R_ACTIONID_1 = "permission.actionId IS NULL AND ";
3467 private static final String _FINDER_COLUMN_A_R_ACTIONID_2 = "permission.actionId = ? AND ";
3468 private static final String _FINDER_COLUMN_A_R_ACTIONID_3 = "(permission.actionId IS NULL OR permission.actionId = ?) AND ";
3469 private static final String _FINDER_COLUMN_A_R_RESOURCEID_2 = "permission.resourceId = ?";
3470 private static final String _ORDER_BY_ENTITY_ALIAS = "permission.";
3471 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Permission exists with the primary key ";
3472 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Permission exists with the key {";
3473 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3474 private static Log _log = LogFactoryUtil.getLog(PermissionPersistenceImpl.class);
3475 private static Permission _nullPermission = new PermissionImpl() {
3476 @Override
3477 public Object clone() {
3478 return this;
3479 }
3480
3481 @Override
3482 public CacheModel<Permission> toCacheModel() {
3483 return _nullPermissionCacheModel;
3484 }
3485 };
3486
3487 private static CacheModel<Permission> _nullPermissionCacheModel = new CacheModel<Permission>() {
3488 public Permission toEntityModel() {
3489 return _nullPermission;
3490 }
3491 };
3492 }