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
373 else {
374 if ((permissionModelImpl.getColumnBitmask() &
375 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID.getColumnBitmask()) != 0) {
376 Object[] args = new Object[] {
377 Long.valueOf(permissionModelImpl.getOriginalResourceId())
378 };
379
380 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEID,
381 args);
382 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID,
383 args);
384
385 args = new Object[] {
386 Long.valueOf(permissionModelImpl.getResourceId())
387 };
388
389 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_RESOURCEID,
390 args);
391 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID,
392 args);
393 }
394 }
395
396 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
397 PermissionImpl.class, permission.getPrimaryKey(), permission);
398
399 if (isNew) {
400 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
401 new Object[] {
402 permission.getActionId(),
403 Long.valueOf(permission.getResourceId())
404 }, permission);
405 }
406 else {
407 if ((permissionModelImpl.getColumnBitmask() &
408 FINDER_PATH_FETCH_BY_A_R.getColumnBitmask()) != 0) {
409 Object[] args = new Object[] {
410 permissionModelImpl.getOriginalActionId(),
411 Long.valueOf(permissionModelImpl.getOriginalResourceId())
412 };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_A_R, args);
415
416 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R, args);
417
418 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
419 new Object[] {
420 permission.getActionId(),
421 Long.valueOf(permission.getResourceId())
422 }, permission);
423 }
424 }
425
426 return permission;
427 }
428
429 protected Permission toUnwrappedModel(Permission permission) {
430 if (permission instanceof PermissionImpl) {
431 return permission;
432 }
433
434 PermissionImpl permissionImpl = new PermissionImpl();
435
436 permissionImpl.setNew(permission.isNew());
437 permissionImpl.setPrimaryKey(permission.getPrimaryKey());
438
439 permissionImpl.setPermissionId(permission.getPermissionId());
440 permissionImpl.setCompanyId(permission.getCompanyId());
441 permissionImpl.setActionId(permission.getActionId());
442 permissionImpl.setResourceId(permission.getResourceId());
443
444 return permissionImpl;
445 }
446
447
455 @Override
456 public Permission findByPrimaryKey(Serializable primaryKey)
457 throws NoSuchModelException, SystemException {
458 return findByPrimaryKey(((Long)primaryKey).longValue());
459 }
460
461
469 public Permission findByPrimaryKey(long permissionId)
470 throws NoSuchPermissionException, SystemException {
471 Permission permission = fetchByPrimaryKey(permissionId);
472
473 if (permission == null) {
474 if (_log.isWarnEnabled()) {
475 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + permissionId);
476 }
477
478 throw new NoSuchPermissionException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
479 permissionId);
480 }
481
482 return permission;
483 }
484
485
492 @Override
493 public Permission fetchByPrimaryKey(Serializable primaryKey)
494 throws SystemException {
495 return fetchByPrimaryKey(((Long)primaryKey).longValue());
496 }
497
498
505 public Permission fetchByPrimaryKey(long permissionId)
506 throws SystemException {
507 Permission permission = (Permission)EntityCacheUtil.getResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
508 PermissionImpl.class, permissionId);
509
510 if (permission == _nullPermission) {
511 return null;
512 }
513
514 if (permission == null) {
515 Session session = null;
516
517 boolean hasException = false;
518
519 try {
520 session = openSession();
521
522 permission = (Permission)session.get(PermissionImpl.class,
523 Long.valueOf(permissionId));
524 }
525 catch (Exception e) {
526 hasException = true;
527
528 throw processException(e);
529 }
530 finally {
531 if (permission != null) {
532 cacheResult(permission);
533 }
534 else if (!hasException) {
535 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
536 PermissionImpl.class, permissionId, _nullPermission);
537 }
538
539 closeSession(session);
540 }
541 }
542
543 return permission;
544 }
545
546
553 public List<Permission> findByResourceId(long resourceId)
554 throws SystemException {
555 return findByResourceId(resourceId, QueryUtil.ALL_POS,
556 QueryUtil.ALL_POS, null);
557 }
558
559
572 public List<Permission> findByResourceId(long resourceId, int start, int end)
573 throws SystemException {
574 return findByResourceId(resourceId, start, end, null);
575 }
576
577
591 public List<Permission> findByResourceId(long resourceId, int start,
592 int end, OrderByComparator orderByComparator) throws SystemException {
593 FinderPath finderPath = null;
594 Object[] finderArgs = null;
595
596 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
597 (orderByComparator == null)) {
598 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_RESOURCEID;
599 finderArgs = new Object[] { resourceId };
600 }
601 else {
602 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_RESOURCEID;
603 finderArgs = new Object[] { resourceId, start, end, orderByComparator };
604 }
605
606 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(finderPath,
607 finderArgs, this);
608
609 if ((list != null) && !list.isEmpty()) {
610 for (Permission permission : list) {
611 if ((resourceId != permission.getResourceId())) {
612 list = null;
613
614 break;
615 }
616 }
617 }
618
619 if (list == null) {
620 StringBundler query = null;
621
622 if (orderByComparator != null) {
623 query = new StringBundler(3 +
624 (orderByComparator.getOrderByFields().length * 3));
625 }
626 else {
627 query = new StringBundler(2);
628 }
629
630 query.append(_SQL_SELECT_PERMISSION_WHERE);
631
632 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
633
634 if (orderByComparator != null) {
635 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
636 orderByComparator);
637 }
638
639 String sql = query.toString();
640
641 Session session = null;
642
643 try {
644 session = openSession();
645
646 Query q = session.createQuery(sql);
647
648 QueryPos qPos = QueryPos.getInstance(q);
649
650 qPos.add(resourceId);
651
652 list = (List<Permission>)QueryUtil.list(q, getDialect(), start,
653 end);
654 }
655 catch (Exception e) {
656 throw processException(e);
657 }
658 finally {
659 if (list == null) {
660 FinderCacheUtil.removeResult(finderPath, finderArgs);
661 }
662 else {
663 cacheResult(list);
664
665 FinderCacheUtil.putResult(finderPath, finderArgs, list);
666 }
667
668 closeSession(session);
669 }
670 }
671
672 return list;
673 }
674
675
684 public Permission findByResourceId_First(long resourceId,
685 OrderByComparator orderByComparator)
686 throws NoSuchPermissionException, SystemException {
687 Permission permission = fetchByResourceId_First(resourceId,
688 orderByComparator);
689
690 if (permission != null) {
691 return permission;
692 }
693
694 StringBundler msg = new StringBundler(4);
695
696 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
697
698 msg.append("resourceId=");
699 msg.append(resourceId);
700
701 msg.append(StringPool.CLOSE_CURLY_BRACE);
702
703 throw new NoSuchPermissionException(msg.toString());
704 }
705
706
714 public Permission fetchByResourceId_First(long resourceId,
715 OrderByComparator orderByComparator) throws SystemException {
716 List<Permission> list = findByResourceId(resourceId, 0, 1,
717 orderByComparator);
718
719 if (!list.isEmpty()) {
720 return list.get(0);
721 }
722
723 return null;
724 }
725
726
735 public Permission findByResourceId_Last(long resourceId,
736 OrderByComparator orderByComparator)
737 throws NoSuchPermissionException, SystemException {
738 Permission permission = fetchByResourceId_Last(resourceId,
739 orderByComparator);
740
741 if (permission != null) {
742 return permission;
743 }
744
745 StringBundler msg = new StringBundler(4);
746
747 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
748
749 msg.append("resourceId=");
750 msg.append(resourceId);
751
752 msg.append(StringPool.CLOSE_CURLY_BRACE);
753
754 throw new NoSuchPermissionException(msg.toString());
755 }
756
757
765 public Permission fetchByResourceId_Last(long resourceId,
766 OrderByComparator orderByComparator) throws SystemException {
767 int count = countByResourceId(resourceId);
768
769 List<Permission> list = findByResourceId(resourceId, count - 1, count,
770 orderByComparator);
771
772 if (!list.isEmpty()) {
773 return list.get(0);
774 }
775
776 return null;
777 }
778
779
789 public Permission[] findByResourceId_PrevAndNext(long permissionId,
790 long resourceId, OrderByComparator orderByComparator)
791 throws NoSuchPermissionException, SystemException {
792 Permission permission = findByPrimaryKey(permissionId);
793
794 Session session = null;
795
796 try {
797 session = openSession();
798
799 Permission[] array = new PermissionImpl[3];
800
801 array[0] = getByResourceId_PrevAndNext(session, permission,
802 resourceId, orderByComparator, true);
803
804 array[1] = permission;
805
806 array[2] = getByResourceId_PrevAndNext(session, permission,
807 resourceId, orderByComparator, false);
808
809 return array;
810 }
811 catch (Exception e) {
812 throw processException(e);
813 }
814 finally {
815 closeSession(session);
816 }
817 }
818
819 protected Permission getByResourceId_PrevAndNext(Session session,
820 Permission permission, long resourceId,
821 OrderByComparator orderByComparator, boolean previous) {
822 StringBundler query = null;
823
824 if (orderByComparator != null) {
825 query = new StringBundler(6 +
826 (orderByComparator.getOrderByFields().length * 6));
827 }
828 else {
829 query = new StringBundler(3);
830 }
831
832 query.append(_SQL_SELECT_PERMISSION_WHERE);
833
834 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
835
836 if (orderByComparator != null) {
837 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
838
839 if (orderByConditionFields.length > 0) {
840 query.append(WHERE_AND);
841 }
842
843 for (int i = 0; i < orderByConditionFields.length; i++) {
844 query.append(_ORDER_BY_ENTITY_ALIAS);
845 query.append(orderByConditionFields[i]);
846
847 if ((i + 1) < orderByConditionFields.length) {
848 if (orderByComparator.isAscending() ^ previous) {
849 query.append(WHERE_GREATER_THAN_HAS_NEXT);
850 }
851 else {
852 query.append(WHERE_LESSER_THAN_HAS_NEXT);
853 }
854 }
855 else {
856 if (orderByComparator.isAscending() ^ previous) {
857 query.append(WHERE_GREATER_THAN);
858 }
859 else {
860 query.append(WHERE_LESSER_THAN);
861 }
862 }
863 }
864
865 query.append(ORDER_BY_CLAUSE);
866
867 String[] orderByFields = orderByComparator.getOrderByFields();
868
869 for (int i = 0; i < orderByFields.length; i++) {
870 query.append(_ORDER_BY_ENTITY_ALIAS);
871 query.append(orderByFields[i]);
872
873 if ((i + 1) < orderByFields.length) {
874 if (orderByComparator.isAscending() ^ previous) {
875 query.append(ORDER_BY_ASC_HAS_NEXT);
876 }
877 else {
878 query.append(ORDER_BY_DESC_HAS_NEXT);
879 }
880 }
881 else {
882 if (orderByComparator.isAscending() ^ previous) {
883 query.append(ORDER_BY_ASC);
884 }
885 else {
886 query.append(ORDER_BY_DESC);
887 }
888 }
889 }
890 }
891
892 String sql = query.toString();
893
894 Query q = session.createQuery(sql);
895
896 q.setFirstResult(0);
897 q.setMaxResults(2);
898
899 QueryPos qPos = QueryPos.getInstance(q);
900
901 qPos.add(resourceId);
902
903 if (orderByComparator != null) {
904 Object[] values = orderByComparator.getOrderByConditionValues(permission);
905
906 for (Object value : values) {
907 qPos.add(value);
908 }
909 }
910
911 List<Permission> list = q.list();
912
913 if (list.size() == 2) {
914 return list.get(1);
915 }
916 else {
917 return null;
918 }
919 }
920
921
930 public Permission findByA_R(String actionId, long resourceId)
931 throws NoSuchPermissionException, SystemException {
932 Permission permission = fetchByA_R(actionId, resourceId);
933
934 if (permission == null) {
935 StringBundler msg = new StringBundler(6);
936
937 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
938
939 msg.append("actionId=");
940 msg.append(actionId);
941
942 msg.append(", resourceId=");
943 msg.append(resourceId);
944
945 msg.append(StringPool.CLOSE_CURLY_BRACE);
946
947 if (_log.isWarnEnabled()) {
948 _log.warn(msg.toString());
949 }
950
951 throw new NoSuchPermissionException(msg.toString());
952 }
953
954 return permission;
955 }
956
957
965 public Permission fetchByA_R(String actionId, long resourceId)
966 throws SystemException {
967 return fetchByA_R(actionId, resourceId, true);
968 }
969
970
979 public Permission fetchByA_R(String actionId, long resourceId,
980 boolean retrieveFromCache) throws SystemException {
981 Object[] finderArgs = new Object[] { actionId, resourceId };
982
983 Object result = null;
984
985 if (retrieveFromCache) {
986 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A_R,
987 finderArgs, this);
988 }
989
990 if (result instanceof Permission) {
991 Permission permission = (Permission)result;
992
993 if (!Validator.equals(actionId, permission.getActionId()) ||
994 (resourceId != permission.getResourceId())) {
995 result = null;
996 }
997 }
998
999 if (result == null) {
1000 StringBundler query = new StringBundler(3);
1001
1002 query.append(_SQL_SELECT_PERMISSION_WHERE);
1003
1004 if (actionId == null) {
1005 query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
1006 }
1007 else {
1008 if (actionId.equals(StringPool.BLANK)) {
1009 query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
1010 }
1011 else {
1012 query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
1013 }
1014 }
1015
1016 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
1017
1018 String sql = query.toString();
1019
1020 Session session = null;
1021
1022 try {
1023 session = openSession();
1024
1025 Query q = session.createQuery(sql);
1026
1027 QueryPos qPos = QueryPos.getInstance(q);
1028
1029 if (actionId != null) {
1030 qPos.add(actionId);
1031 }
1032
1033 qPos.add(resourceId);
1034
1035 List<Permission> list = q.list();
1036
1037 result = list;
1038
1039 Permission permission = null;
1040
1041 if (list.isEmpty()) {
1042 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
1043 finderArgs, list);
1044 }
1045 else {
1046 permission = list.get(0);
1047
1048 cacheResult(permission);
1049
1050 if ((permission.getActionId() == null) ||
1051 !permission.getActionId().equals(actionId) ||
1052 (permission.getResourceId() != resourceId)) {
1053 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
1054 finderArgs, permission);
1055 }
1056 }
1057
1058 return permission;
1059 }
1060 catch (Exception e) {
1061 throw processException(e);
1062 }
1063 finally {
1064 if (result == null) {
1065 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
1066 finderArgs);
1067 }
1068
1069 closeSession(session);
1070 }
1071 }
1072 else {
1073 if (result instanceof List<?>) {
1074 return null;
1075 }
1076 else {
1077 return (Permission)result;
1078 }
1079 }
1080 }
1081
1082
1088 public List<Permission> findAll() throws SystemException {
1089 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1090 }
1091
1092
1104 public List<Permission> findAll(int start, int end)
1105 throws SystemException {
1106 return findAll(start, end, null);
1107 }
1108
1109
1122 public List<Permission> findAll(int start, int end,
1123 OrderByComparator orderByComparator) throws SystemException {
1124 FinderPath finderPath = null;
1125 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1126
1127 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1128 (orderByComparator == null)) {
1129 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1130 finderArgs = FINDER_ARGS_EMPTY;
1131 }
1132 else {
1133 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1134 finderArgs = new Object[] { start, end, orderByComparator };
1135 }
1136
1137 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(finderPath,
1138 finderArgs, this);
1139
1140 if (list == null) {
1141 StringBundler query = null;
1142 String sql = null;
1143
1144 if (orderByComparator != null) {
1145 query = new StringBundler(2 +
1146 (orderByComparator.getOrderByFields().length * 3));
1147
1148 query.append(_SQL_SELECT_PERMISSION);
1149
1150 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1151 orderByComparator);
1152
1153 sql = query.toString();
1154 }
1155 else {
1156 sql = _SQL_SELECT_PERMISSION;
1157 }
1158
1159 Session session = null;
1160
1161 try {
1162 session = openSession();
1163
1164 Query q = session.createQuery(sql);
1165
1166 if (orderByComparator == null) {
1167 list = (List<Permission>)QueryUtil.list(q, getDialect(),
1168 start, end, false);
1169
1170 Collections.sort(list);
1171 }
1172 else {
1173 list = (List<Permission>)QueryUtil.list(q, getDialect(),
1174 start, end);
1175 }
1176 }
1177 catch (Exception e) {
1178 throw processException(e);
1179 }
1180 finally {
1181 if (list == null) {
1182 FinderCacheUtil.removeResult(finderPath, finderArgs);
1183 }
1184 else {
1185 cacheResult(list);
1186
1187 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1188 }
1189
1190 closeSession(session);
1191 }
1192 }
1193
1194 return list;
1195 }
1196
1197
1203 public void removeByResourceId(long resourceId) throws SystemException {
1204 for (Permission permission : findByResourceId(resourceId)) {
1205 remove(permission);
1206 }
1207 }
1208
1209
1217 public Permission removeByA_R(String actionId, long resourceId)
1218 throws NoSuchPermissionException, SystemException {
1219 Permission permission = findByA_R(actionId, resourceId);
1220
1221 return remove(permission);
1222 }
1223
1224
1229 public void removeAll() throws SystemException {
1230 for (Permission permission : findAll()) {
1231 remove(permission);
1232 }
1233 }
1234
1235
1242 public int countByResourceId(long resourceId) throws SystemException {
1243 Object[] finderArgs = new Object[] { resourceId };
1244
1245 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEID,
1246 finderArgs, this);
1247
1248 if (count == null) {
1249 StringBundler query = new StringBundler(2);
1250
1251 query.append(_SQL_COUNT_PERMISSION_WHERE);
1252
1253 query.append(_FINDER_COLUMN_RESOURCEID_RESOURCEID_2);
1254
1255 String sql = query.toString();
1256
1257 Session session = null;
1258
1259 try {
1260 session = openSession();
1261
1262 Query q = session.createQuery(sql);
1263
1264 QueryPos qPos = QueryPos.getInstance(q);
1265
1266 qPos.add(resourceId);
1267
1268 count = (Long)q.uniqueResult();
1269 }
1270 catch (Exception e) {
1271 throw processException(e);
1272 }
1273 finally {
1274 if (count == null) {
1275 count = Long.valueOf(0);
1276 }
1277
1278 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEID,
1279 finderArgs, count);
1280
1281 closeSession(session);
1282 }
1283 }
1284
1285 return count.intValue();
1286 }
1287
1288
1296 public int countByA_R(String actionId, long resourceId)
1297 throws SystemException {
1298 Object[] finderArgs = new Object[] { actionId, resourceId };
1299
1300 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
1301 finderArgs, this);
1302
1303 if (count == null) {
1304 StringBundler query = new StringBundler(3);
1305
1306 query.append(_SQL_COUNT_PERMISSION_WHERE);
1307
1308 if (actionId == null) {
1309 query.append(_FINDER_COLUMN_A_R_ACTIONID_1);
1310 }
1311 else {
1312 if (actionId.equals(StringPool.BLANK)) {
1313 query.append(_FINDER_COLUMN_A_R_ACTIONID_3);
1314 }
1315 else {
1316 query.append(_FINDER_COLUMN_A_R_ACTIONID_2);
1317 }
1318 }
1319
1320 query.append(_FINDER_COLUMN_A_R_RESOURCEID_2);
1321
1322 String sql = query.toString();
1323
1324 Session session = null;
1325
1326 try {
1327 session = openSession();
1328
1329 Query q = session.createQuery(sql);
1330
1331 QueryPos qPos = QueryPos.getInstance(q);
1332
1333 if (actionId != null) {
1334 qPos.add(actionId);
1335 }
1336
1337 qPos.add(resourceId);
1338
1339 count = (Long)q.uniqueResult();
1340 }
1341 catch (Exception e) {
1342 throw processException(e);
1343 }
1344 finally {
1345 if (count == null) {
1346 count = Long.valueOf(0);
1347 }
1348
1349 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
1350 count);
1351
1352 closeSession(session);
1353 }
1354 }
1355
1356 return count.intValue();
1357 }
1358
1359
1365 public int countAll() throws SystemException {
1366 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1367 FINDER_ARGS_EMPTY, this);
1368
1369 if (count == null) {
1370 Session session = null;
1371
1372 try {
1373 session = openSession();
1374
1375 Query q = session.createQuery(_SQL_COUNT_PERMISSION);
1376
1377 count = (Long)q.uniqueResult();
1378 }
1379 catch (Exception e) {
1380 throw processException(e);
1381 }
1382 finally {
1383 if (count == null) {
1384 count = Long.valueOf(0);
1385 }
1386
1387 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1388 FINDER_ARGS_EMPTY, count);
1389
1390 closeSession(session);
1391 }
1392 }
1393
1394 return count.intValue();
1395 }
1396
1397
1404 public List<com.liferay.portal.model.Group> getGroups(long pk)
1405 throws SystemException {
1406 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1407 }
1408
1409
1422 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1423 int end) throws SystemException {
1424 return getGroups(pk, start, end, null);
1425 }
1426
1427 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1428 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1429 com.liferay.portal.model.impl.GroupImpl.class,
1430 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1431 "getGroups",
1432 new String[] {
1433 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1434 "com.liferay.portal.kernel.util.OrderByComparator"
1435 });
1436
1437 static {
1438 FINDER_PATH_GET_GROUPS.setCacheKeyGeneratorCacheName(null);
1439 }
1440
1441
1455 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1456 int end, OrderByComparator orderByComparator) throws SystemException {
1457 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
1458
1459 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1460 finderArgs, this);
1461
1462 if (list == null) {
1463 Session session = null;
1464
1465 try {
1466 session = openSession();
1467
1468 String sql = null;
1469
1470 if (orderByComparator != null) {
1471 sql = _SQL_GETGROUPS.concat(ORDER_BY_CLAUSE)
1472 .concat(orderByComparator.getOrderBy());
1473 }
1474 else {
1475 sql = _SQL_GETGROUPS.concat(com.liferay.portal.model.impl.GroupModelImpl.ORDER_BY_SQL);
1476 }
1477
1478 SQLQuery q = session.createSQLQuery(sql);
1479
1480 q.addEntity("Group_",
1481 com.liferay.portal.model.impl.GroupImpl.class);
1482
1483 QueryPos qPos = QueryPos.getInstance(q);
1484
1485 qPos.add(pk);
1486
1487 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1488 getDialect(), start, end);
1489 }
1490 catch (Exception e) {
1491 throw processException(e);
1492 }
1493 finally {
1494 if (list == null) {
1495 FinderCacheUtil.removeResult(FINDER_PATH_GET_GROUPS,
1496 finderArgs);
1497 }
1498 else {
1499 groupPersistence.cacheResult(list);
1500
1501 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS,
1502 finderArgs, list);
1503 }
1504
1505 closeSession(session);
1506 }
1507 }
1508
1509 return list;
1510 }
1511
1512 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1513 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1514 Long.class,
1515 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1516 "getGroupsSize", new String[] { Long.class.getName() });
1517
1518 static {
1519 FINDER_PATH_GET_GROUPS_SIZE.setCacheKeyGeneratorCacheName(null);
1520 }
1521
1522
1529 public int getGroupsSize(long pk) throws SystemException {
1530 Object[] finderArgs = new Object[] { pk };
1531
1532 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1533 finderArgs, this);
1534
1535 if (count == null) {
1536 Session session = null;
1537
1538 try {
1539 session = openSession();
1540
1541 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1542
1543 q.addScalar(COUNT_COLUMN_NAME,
1544 com.liferay.portal.kernel.dao.orm.Type.LONG);
1545
1546 QueryPos qPos = QueryPos.getInstance(q);
1547
1548 qPos.add(pk);
1549
1550 count = (Long)q.uniqueResult();
1551 }
1552 catch (Exception e) {
1553 throw processException(e);
1554 }
1555 finally {
1556 if (count == null) {
1557 count = Long.valueOf(0);
1558 }
1559
1560 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1561 finderArgs, count);
1562
1563 closeSession(session);
1564 }
1565 }
1566
1567 return count.intValue();
1568 }
1569
1570 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1571 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1572 Boolean.class,
1573 PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME,
1574 "containsGroup",
1575 new String[] { Long.class.getName(), Long.class.getName() });
1576
1577
1585 public boolean containsGroup(long pk, long groupPK)
1586 throws SystemException {
1587 Object[] finderArgs = new Object[] { pk, groupPK };
1588
1589 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1590 finderArgs, this);
1591
1592 if (value == null) {
1593 try {
1594 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1595 }
1596 catch (Exception e) {
1597 throw processException(e);
1598 }
1599 finally {
1600 if (value == null) {
1601 value = Boolean.FALSE;
1602 }
1603
1604 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1605 finderArgs, value);
1606 }
1607 }
1608
1609 return value.booleanValue();
1610 }
1611
1612
1619 public boolean containsGroups(long pk) throws SystemException {
1620 if (getGroupsSize(pk) > 0) {
1621 return true;
1622 }
1623 else {
1624 return false;
1625 }
1626 }
1627
1628
1635 public void addGroup(long pk, long groupPK) throws SystemException {
1636 try {
1637 addGroup.add(pk, groupPK);
1638 }
1639 catch (Exception e) {
1640 throw processException(e);
1641 }
1642 finally {
1643 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1644 }
1645 }
1646
1647
1654 public void addGroup(long pk, com.liferay.portal.model.Group group)
1655 throws SystemException {
1656 try {
1657 addGroup.add(pk, group.getPrimaryKey());
1658 }
1659 catch (Exception e) {
1660 throw processException(e);
1661 }
1662 finally {
1663 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1664 }
1665 }
1666
1667
1674 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1675 try {
1676 for (long groupPK : groupPKs) {
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 addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1696 throws SystemException {
1697 try {
1698 for (com.liferay.portal.model.Group group : groups) {
1699 addGroup.add(pk, group.getPrimaryKey());
1700 }
1701 }
1702 catch (Exception e) {
1703 throw processException(e);
1704 }
1705 finally {
1706 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1707 }
1708 }
1709
1710
1716 public void clearGroups(long pk) throws SystemException {
1717 try {
1718 clearGroups.clear(pk);
1719 }
1720 catch (Exception e) {
1721 throw processException(e);
1722 }
1723 finally {
1724 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1725 }
1726 }
1727
1728
1735 public void removeGroup(long pk, long groupPK) throws SystemException {
1736 try {
1737 removeGroup.remove(pk, groupPK);
1738 }
1739 catch (Exception e) {
1740 throw processException(e);
1741 }
1742 finally {
1743 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1744 }
1745 }
1746
1747
1754 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1755 throws SystemException {
1756 try {
1757 removeGroup.remove(pk, group.getPrimaryKey());
1758 }
1759 catch (Exception e) {
1760 throw processException(e);
1761 }
1762 finally {
1763 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1764 }
1765 }
1766
1767
1774 public void removeGroups(long pk, long[] groupPKs)
1775 throws SystemException {
1776 try {
1777 for (long groupPK : groupPKs) {
1778 removeGroup.remove(pk, groupPK);
1779 }
1780 }
1781 catch (Exception e) {
1782 throw processException(e);
1783 }
1784 finally {
1785 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1786 }
1787 }
1788
1789
1796 public void removeGroups(long pk,
1797 List<com.liferay.portal.model.Group> groups) throws SystemException {
1798 try {
1799 for (com.liferay.portal.model.Group group : groups) {
1800 removeGroup.remove(pk, group.getPrimaryKey());
1801 }
1802 }
1803 catch (Exception e) {
1804 throw processException(e);
1805 }
1806 finally {
1807 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1808 }
1809 }
1810
1811
1818 public void setGroups(long pk, long[] groupPKs) throws SystemException {
1819 try {
1820 Set<Long> groupPKSet = SetUtil.fromArray(groupPKs);
1821
1822 List<com.liferay.portal.model.Group> groups = getGroups(pk);
1823
1824 for (com.liferay.portal.model.Group group : groups) {
1825 if (!groupPKSet.remove(group.getPrimaryKey())) {
1826 removeGroup.remove(pk, group.getPrimaryKey());
1827 }
1828 }
1829
1830 for (Long groupPK : groupPKSet) {
1831 addGroup.add(pk, groupPK);
1832 }
1833 }
1834 catch (Exception e) {
1835 throw processException(e);
1836 }
1837 finally {
1838 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1839 }
1840 }
1841
1842
1849 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1850 throws SystemException {
1851 try {
1852 long[] groupPKs = new long[groups.size()];
1853
1854 for (int i = 0; i < groups.size(); i++) {
1855 com.liferay.portal.model.Group group = groups.get(i);
1856
1857 groupPKs[i] = group.getPrimaryKey();
1858 }
1859
1860 setGroups(pk, groupPKs);
1861 }
1862 catch (Exception e) {
1863 throw processException(e);
1864 }
1865 finally {
1866 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_GROUPS_PERMISSIONS_NAME);
1867 }
1868 }
1869
1870
1877 public List<com.liferay.portal.model.Role> getRoles(long pk)
1878 throws SystemException {
1879 return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1880 }
1881
1882
1895 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1896 int end) throws SystemException {
1897 return getRoles(pk, start, end, null);
1898 }
1899
1900 public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1901 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1902 com.liferay.portal.model.impl.RoleImpl.class,
1903 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1904 "getRoles",
1905 new String[] {
1906 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1907 "com.liferay.portal.kernel.util.OrderByComparator"
1908 });
1909
1910 static {
1911 FINDER_PATH_GET_ROLES.setCacheKeyGeneratorCacheName(null);
1912 }
1913
1914
1928 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1929 int end, OrderByComparator orderByComparator) throws SystemException {
1930 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
1931
1932 List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
1933 finderArgs, this);
1934
1935 if (list == null) {
1936 Session session = null;
1937
1938 try {
1939 session = openSession();
1940
1941 String sql = null;
1942
1943 if (orderByComparator != null) {
1944 sql = _SQL_GETROLES.concat(ORDER_BY_CLAUSE)
1945 .concat(orderByComparator.getOrderBy());
1946 }
1947 else {
1948 sql = _SQL_GETROLES.concat(com.liferay.portal.model.impl.RoleModelImpl.ORDER_BY_SQL);
1949 }
1950
1951 SQLQuery q = session.createSQLQuery(sql);
1952
1953 q.addEntity("Role_",
1954 com.liferay.portal.model.impl.RoleImpl.class);
1955
1956 QueryPos qPos = QueryPos.getInstance(q);
1957
1958 qPos.add(pk);
1959
1960 list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
1961 getDialect(), start, end);
1962 }
1963 catch (Exception e) {
1964 throw processException(e);
1965 }
1966 finally {
1967 if (list == null) {
1968 FinderCacheUtil.removeResult(FINDER_PATH_GET_ROLES,
1969 finderArgs);
1970 }
1971 else {
1972 rolePersistence.cacheResult(list);
1973
1974 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES,
1975 finderArgs, list);
1976 }
1977
1978 closeSession(session);
1979 }
1980 }
1981
1982 return list;
1983 }
1984
1985 public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1986 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1987 Long.class,
1988 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
1989 "getRolesSize", new String[] { Long.class.getName() });
1990
1991 static {
1992 FINDER_PATH_GET_ROLES_SIZE.setCacheKeyGeneratorCacheName(null);
1993 }
1994
1995
2002 public int getRolesSize(long pk) throws SystemException {
2003 Object[] finderArgs = new Object[] { pk };
2004
2005 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
2006 finderArgs, this);
2007
2008 if (count == null) {
2009 Session session = null;
2010
2011 try {
2012 session = openSession();
2013
2014 SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
2015
2016 q.addScalar(COUNT_COLUMN_NAME,
2017 com.liferay.portal.kernel.dao.orm.Type.LONG);
2018
2019 QueryPos qPos = QueryPos.getInstance(q);
2020
2021 qPos.add(pk);
2022
2023 count = (Long)q.uniqueResult();
2024 }
2025 catch (Exception e) {
2026 throw processException(e);
2027 }
2028 finally {
2029 if (count == null) {
2030 count = Long.valueOf(0);
2031 }
2032
2033 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
2034 finderArgs, count);
2035
2036 closeSession(session);
2037 }
2038 }
2039
2040 return count.intValue();
2041 }
2042
2043 public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
2044 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
2045 Boolean.class,
2046 PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME,
2047 "containsRole",
2048 new String[] { Long.class.getName(), Long.class.getName() });
2049
2050
2058 public boolean containsRole(long pk, long rolePK) throws SystemException {
2059 Object[] finderArgs = new Object[] { pk, rolePK };
2060
2061 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
2062 finderArgs, this);
2063
2064 if (value == null) {
2065 try {
2066 value = Boolean.valueOf(containsRole.contains(pk, rolePK));
2067 }
2068 catch (Exception e) {
2069 throw processException(e);
2070 }
2071 finally {
2072 if (value == null) {
2073 value = Boolean.FALSE;
2074 }
2075
2076 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
2077 finderArgs, value);
2078 }
2079 }
2080
2081 return value.booleanValue();
2082 }
2083
2084
2091 public boolean containsRoles(long pk) throws SystemException {
2092 if (getRolesSize(pk) > 0) {
2093 return true;
2094 }
2095 else {
2096 return false;
2097 }
2098 }
2099
2100
2107 public void addRole(long pk, long rolePK) throws SystemException {
2108 try {
2109 addRole.add(pk, rolePK);
2110 }
2111 catch (Exception e) {
2112 throw processException(e);
2113 }
2114 finally {
2115 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2116 }
2117 }
2118
2119
2126 public void addRole(long pk, com.liferay.portal.model.Role role)
2127 throws SystemException {
2128 try {
2129 addRole.add(pk, role.getPrimaryKey());
2130 }
2131 catch (Exception e) {
2132 throw processException(e);
2133 }
2134 finally {
2135 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2136 }
2137 }
2138
2139
2146 public void addRoles(long pk, long[] rolePKs) throws SystemException {
2147 try {
2148 for (long rolePK : rolePKs) {
2149 addRole.add(pk, rolePK);
2150 }
2151 }
2152 catch (Exception e) {
2153 throw processException(e);
2154 }
2155 finally {
2156 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2157 }
2158 }
2159
2160
2167 public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
2168 throws SystemException {
2169 try {
2170 for (com.liferay.portal.model.Role role : roles) {
2171 addRole.add(pk, role.getPrimaryKey());
2172 }
2173 }
2174 catch (Exception e) {
2175 throw processException(e);
2176 }
2177 finally {
2178 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2179 }
2180 }
2181
2182
2188 public void clearRoles(long pk) throws SystemException {
2189 try {
2190 clearRoles.clear(pk);
2191 }
2192 catch (Exception e) {
2193 throw processException(e);
2194 }
2195 finally {
2196 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2197 }
2198 }
2199
2200
2207 public void removeRole(long pk, long rolePK) throws SystemException {
2208 try {
2209 removeRole.remove(pk, rolePK);
2210 }
2211 catch (Exception e) {
2212 throw processException(e);
2213 }
2214 finally {
2215 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2216 }
2217 }
2218
2219
2226 public void removeRole(long pk, com.liferay.portal.model.Role role)
2227 throws SystemException {
2228 try {
2229 removeRole.remove(pk, role.getPrimaryKey());
2230 }
2231 catch (Exception e) {
2232 throw processException(e);
2233 }
2234 finally {
2235 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2236 }
2237 }
2238
2239
2246 public void removeRoles(long pk, long[] rolePKs) throws SystemException {
2247 try {
2248 for (long rolePK : rolePKs) {
2249 removeRole.remove(pk, rolePK);
2250 }
2251 }
2252 catch (Exception e) {
2253 throw processException(e);
2254 }
2255 finally {
2256 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2257 }
2258 }
2259
2260
2267 public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
2268 throws SystemException {
2269 try {
2270 for (com.liferay.portal.model.Role role : roles) {
2271 removeRole.remove(pk, role.getPrimaryKey());
2272 }
2273 }
2274 catch (Exception e) {
2275 throw processException(e);
2276 }
2277 finally {
2278 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2279 }
2280 }
2281
2282
2289 public void setRoles(long pk, long[] rolePKs) throws SystemException {
2290 try {
2291 Set<Long> rolePKSet = SetUtil.fromArray(rolePKs);
2292
2293 List<com.liferay.portal.model.Role> roles = getRoles(pk);
2294
2295 for (com.liferay.portal.model.Role role : roles) {
2296 if (!rolePKSet.remove(role.getPrimaryKey())) {
2297 removeRole.remove(pk, role.getPrimaryKey());
2298 }
2299 }
2300
2301 for (Long rolePK : rolePKSet) {
2302 addRole.add(pk, rolePK);
2303 }
2304 }
2305 catch (Exception e) {
2306 throw processException(e);
2307 }
2308 finally {
2309 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2310 }
2311 }
2312
2313
2320 public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
2321 throws SystemException {
2322 try {
2323 long[] rolePKs = new long[roles.size()];
2324
2325 for (int i = 0; i < roles.size(); i++) {
2326 com.liferay.portal.model.Role role = roles.get(i);
2327
2328 rolePKs[i] = role.getPrimaryKey();
2329 }
2330
2331 setRoles(pk, rolePKs);
2332 }
2333 catch (Exception e) {
2334 throw processException(e);
2335 }
2336 finally {
2337 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_ROLES_PERMISSIONS_NAME);
2338 }
2339 }
2340
2341
2348 public List<com.liferay.portal.model.User> getUsers(long pk)
2349 throws SystemException {
2350 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
2351 }
2352
2353
2366 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2367 int end) throws SystemException {
2368 return getUsers(pk, start, end, null);
2369 }
2370
2371 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2372 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2373 com.liferay.portal.model.impl.UserImpl.class,
2374 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2375 "getUsers",
2376 new String[] {
2377 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
2378 "com.liferay.portal.kernel.util.OrderByComparator"
2379 });
2380
2381 static {
2382 FINDER_PATH_GET_USERS.setCacheKeyGeneratorCacheName(null);
2383 }
2384
2385
2399 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
2400 int end, OrderByComparator orderByComparator) throws SystemException {
2401 Object[] finderArgs = new Object[] { pk, start, end, orderByComparator };
2402
2403 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
2404 finderArgs, this);
2405
2406 if (list == null) {
2407 Session session = null;
2408
2409 try {
2410 session = openSession();
2411
2412 String sql = null;
2413
2414 if (orderByComparator != null) {
2415 sql = _SQL_GETUSERS.concat(ORDER_BY_CLAUSE)
2416 .concat(orderByComparator.getOrderBy());
2417 }
2418 else {
2419 sql = _SQL_GETUSERS;
2420 }
2421
2422 SQLQuery q = session.createSQLQuery(sql);
2423
2424 q.addEntity("User_",
2425 com.liferay.portal.model.impl.UserImpl.class);
2426
2427 QueryPos qPos = QueryPos.getInstance(q);
2428
2429 qPos.add(pk);
2430
2431 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
2432 getDialect(), start, end);
2433 }
2434 catch (Exception e) {
2435 throw processException(e);
2436 }
2437 finally {
2438 if (list == null) {
2439 FinderCacheUtil.removeResult(FINDER_PATH_GET_USERS,
2440 finderArgs);
2441 }
2442 else {
2443 userPersistence.cacheResult(list);
2444
2445 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS,
2446 finderArgs, list);
2447 }
2448
2449 closeSession(session);
2450 }
2451 }
2452
2453 return list;
2454 }
2455
2456 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2457 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2458 Long.class,
2459 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2460 "getUsersSize", new String[] { Long.class.getName() });
2461
2462 static {
2463 FINDER_PATH_GET_USERS_SIZE.setCacheKeyGeneratorCacheName(null);
2464 }
2465
2466
2473 public int getUsersSize(long pk) throws SystemException {
2474 Object[] finderArgs = new Object[] { pk };
2475
2476 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
2477 finderArgs, this);
2478
2479 if (count == null) {
2480 Session session = null;
2481
2482 try {
2483 session = openSession();
2484
2485 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
2486
2487 q.addScalar(COUNT_COLUMN_NAME,
2488 com.liferay.portal.kernel.dao.orm.Type.LONG);
2489
2490 QueryPos qPos = QueryPos.getInstance(q);
2491
2492 qPos.add(pk);
2493
2494 count = (Long)q.uniqueResult();
2495 }
2496 catch (Exception e) {
2497 throw processException(e);
2498 }
2499 finally {
2500 if (count == null) {
2501 count = Long.valueOf(0);
2502 }
2503
2504 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
2505 finderArgs, count);
2506
2507 closeSession(session);
2508 }
2509 }
2510
2511 return count.intValue();
2512 }
2513
2514 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
2515 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
2516 Boolean.class,
2517 PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME,
2518 "containsUser",
2519 new String[] { Long.class.getName(), Long.class.getName() });
2520
2521
2529 public boolean containsUser(long pk, long userPK) throws SystemException {
2530 Object[] finderArgs = new Object[] { pk, userPK };
2531
2532 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
2533 finderArgs, this);
2534
2535 if (value == null) {
2536 try {
2537 value = Boolean.valueOf(containsUser.contains(pk, userPK));
2538 }
2539 catch (Exception e) {
2540 throw processException(e);
2541 }
2542 finally {
2543 if (value == null) {
2544 value = Boolean.FALSE;
2545 }
2546
2547 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
2548 finderArgs, value);
2549 }
2550 }
2551
2552 return value.booleanValue();
2553 }
2554
2555
2562 public boolean containsUsers(long pk) throws SystemException {
2563 if (getUsersSize(pk) > 0) {
2564 return true;
2565 }
2566 else {
2567 return false;
2568 }
2569 }
2570
2571
2578 public void addUser(long pk, long userPK) throws SystemException {
2579 try {
2580 addUser.add(pk, userPK);
2581 }
2582 catch (Exception e) {
2583 throw processException(e);
2584 }
2585 finally {
2586 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2587 }
2588 }
2589
2590
2597 public void addUser(long pk, com.liferay.portal.model.User user)
2598 throws SystemException {
2599 try {
2600 addUser.add(pk, user.getPrimaryKey());
2601 }
2602 catch (Exception e) {
2603 throw processException(e);
2604 }
2605 finally {
2606 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2607 }
2608 }
2609
2610
2617 public void addUsers(long pk, long[] userPKs) throws SystemException {
2618 try {
2619 for (long userPK : userPKs) {
2620 addUser.add(pk, userPK);
2621 }
2622 }
2623 catch (Exception e) {
2624 throw processException(e);
2625 }
2626 finally {
2627 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2628 }
2629 }
2630
2631
2638 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
2639 throws SystemException {
2640 try {
2641 for (com.liferay.portal.model.User user : users) {
2642 addUser.add(pk, user.getPrimaryKey());
2643 }
2644 }
2645 catch (Exception e) {
2646 throw processException(e);
2647 }
2648 finally {
2649 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2650 }
2651 }
2652
2653
2659 public void clearUsers(long pk) throws SystemException {
2660 try {
2661 clearUsers.clear(pk);
2662 }
2663 catch (Exception e) {
2664 throw processException(e);
2665 }
2666 finally {
2667 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2668 }
2669 }
2670
2671
2678 public void removeUser(long pk, long userPK) throws SystemException {
2679 try {
2680 removeUser.remove(pk, userPK);
2681 }
2682 catch (Exception e) {
2683 throw processException(e);
2684 }
2685 finally {
2686 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2687 }
2688 }
2689
2690
2697 public void removeUser(long pk, com.liferay.portal.model.User user)
2698 throws SystemException {
2699 try {
2700 removeUser.remove(pk, user.getPrimaryKey());
2701 }
2702 catch (Exception e) {
2703 throw processException(e);
2704 }
2705 finally {
2706 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2707 }
2708 }
2709
2710
2717 public void removeUsers(long pk, long[] userPKs) throws SystemException {
2718 try {
2719 for (long userPK : userPKs) {
2720 removeUser.remove(pk, userPK);
2721 }
2722 }
2723 catch (Exception e) {
2724 throw processException(e);
2725 }
2726 finally {
2727 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2728 }
2729 }
2730
2731
2738 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
2739 throws SystemException {
2740 try {
2741 for (com.liferay.portal.model.User user : users) {
2742 removeUser.remove(pk, user.getPrimaryKey());
2743 }
2744 }
2745 catch (Exception e) {
2746 throw processException(e);
2747 }
2748 finally {
2749 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2750 }
2751 }
2752
2753
2760 public void setUsers(long pk, long[] userPKs) throws SystemException {
2761 try {
2762 Set<Long> userPKSet = SetUtil.fromArray(userPKs);
2763
2764 List<com.liferay.portal.model.User> users = getUsers(pk);
2765
2766 for (com.liferay.portal.model.User user : users) {
2767 if (!userPKSet.remove(user.getPrimaryKey())) {
2768 removeUser.remove(pk, user.getPrimaryKey());
2769 }
2770 }
2771
2772 for (Long userPK : userPKSet) {
2773 addUser.add(pk, userPK);
2774 }
2775 }
2776 catch (Exception e) {
2777 throw processException(e);
2778 }
2779 finally {
2780 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2781 }
2782 }
2783
2784
2791 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2792 throws SystemException {
2793 try {
2794 long[] userPKs = new long[users.size()];
2795
2796 for (int i = 0; i < users.size(); i++) {
2797 com.liferay.portal.model.User user = users.get(i);
2798
2799 userPKs[i] = user.getPrimaryKey();
2800 }
2801
2802 setUsers(pk, userPKs);
2803 }
2804 catch (Exception e) {
2805 throw processException(e);
2806 }
2807 finally {
2808 FinderCacheUtil.clearCache(PermissionModelImpl.MAPPING_TABLE_USERS_PERMISSIONS_NAME);
2809 }
2810 }
2811
2812
2815 public void afterPropertiesSet() {
2816 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2817 com.liferay.portal.util.PropsUtil.get(
2818 "value.object.listener.com.liferay.portal.model.Permission")));
2819
2820 if (listenerClassNames.length > 0) {
2821 try {
2822 List<ModelListener<Permission>> listenersList = new ArrayList<ModelListener<Permission>>();
2823
2824 for (String listenerClassName : listenerClassNames) {
2825 listenersList.add((ModelListener<Permission>)InstanceFactory.newInstance(
2826 listenerClassName));
2827 }
2828
2829 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2830 }
2831 catch (Exception e) {
2832 _log.error(e);
2833 }
2834 }
2835
2836 containsGroup = new ContainsGroup();
2837
2838 addGroup = new AddGroup();
2839 clearGroups = new ClearGroups();
2840 removeGroup = new RemoveGroup();
2841
2842 containsRole = new ContainsRole();
2843
2844 addRole = new AddRole();
2845 clearRoles = new ClearRoles();
2846 removeRole = new RemoveRole();
2847
2848 containsUser = new ContainsUser();
2849
2850 addUser = new AddUser();
2851 clearUsers = new ClearUsers();
2852 removeUser = new RemoveUser();
2853 }
2854
2855 public void destroy() {
2856 EntityCacheUtil.removeCache(PermissionImpl.class.getName());
2857 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2858 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2859 }
2860
2861 @BeanReference(type = AccountPersistence.class)
2862 protected AccountPersistence accountPersistence;
2863 @BeanReference(type = AddressPersistence.class)
2864 protected AddressPersistence addressPersistence;
2865 @BeanReference(type = BrowserTrackerPersistence.class)
2866 protected BrowserTrackerPersistence browserTrackerPersistence;
2867 @BeanReference(type = ClassNamePersistence.class)
2868 protected ClassNamePersistence classNamePersistence;
2869 @BeanReference(type = ClusterGroupPersistence.class)
2870 protected ClusterGroupPersistence clusterGroupPersistence;
2871 @BeanReference(type = CompanyPersistence.class)
2872 protected CompanyPersistence companyPersistence;
2873 @BeanReference(type = ContactPersistence.class)
2874 protected ContactPersistence contactPersistence;
2875 @BeanReference(type = CountryPersistence.class)
2876 protected CountryPersistence countryPersistence;
2877 @BeanReference(type = EmailAddressPersistence.class)
2878 protected EmailAddressPersistence emailAddressPersistence;
2879 @BeanReference(type = GroupPersistence.class)
2880 protected GroupPersistence groupPersistence;
2881 @BeanReference(type = ImagePersistence.class)
2882 protected ImagePersistence imagePersistence;
2883 @BeanReference(type = LayoutPersistence.class)
2884 protected LayoutPersistence layoutPersistence;
2885 @BeanReference(type = LayoutBranchPersistence.class)
2886 protected LayoutBranchPersistence layoutBranchPersistence;
2887 @BeanReference(type = LayoutPrototypePersistence.class)
2888 protected LayoutPrototypePersistence layoutPrototypePersistence;
2889 @BeanReference(type = LayoutRevisionPersistence.class)
2890 protected LayoutRevisionPersistence layoutRevisionPersistence;
2891 @BeanReference(type = LayoutSetPersistence.class)
2892 protected LayoutSetPersistence layoutSetPersistence;
2893 @BeanReference(type = LayoutSetBranchPersistence.class)
2894 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
2895 @BeanReference(type = LayoutSetPrototypePersistence.class)
2896 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
2897 @BeanReference(type = ListTypePersistence.class)
2898 protected ListTypePersistence listTypePersistence;
2899 @BeanReference(type = LockPersistence.class)
2900 protected LockPersistence lockPersistence;
2901 @BeanReference(type = MembershipRequestPersistence.class)
2902 protected MembershipRequestPersistence membershipRequestPersistence;
2903 @BeanReference(type = OrganizationPersistence.class)
2904 protected OrganizationPersistence organizationPersistence;
2905 @BeanReference(type = OrgGroupPermissionPersistence.class)
2906 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2907 @BeanReference(type = OrgGroupRolePersistence.class)
2908 protected OrgGroupRolePersistence orgGroupRolePersistence;
2909 @BeanReference(type = OrgLaborPersistence.class)
2910 protected OrgLaborPersistence orgLaborPersistence;
2911 @BeanReference(type = PasswordPolicyPersistence.class)
2912 protected PasswordPolicyPersistence passwordPolicyPersistence;
2913 @BeanReference(type = PasswordPolicyRelPersistence.class)
2914 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2915 @BeanReference(type = PasswordTrackerPersistence.class)
2916 protected PasswordTrackerPersistence passwordTrackerPersistence;
2917 @BeanReference(type = PermissionPersistence.class)
2918 protected PermissionPersistence permissionPersistence;
2919 @BeanReference(type = PhonePersistence.class)
2920 protected PhonePersistence phonePersistence;
2921 @BeanReference(type = PluginSettingPersistence.class)
2922 protected PluginSettingPersistence pluginSettingPersistence;
2923 @BeanReference(type = PortalPreferencesPersistence.class)
2924 protected PortalPreferencesPersistence portalPreferencesPersistence;
2925 @BeanReference(type = PortletPersistence.class)
2926 protected PortletPersistence portletPersistence;
2927 @BeanReference(type = PortletItemPersistence.class)
2928 protected PortletItemPersistence portletItemPersistence;
2929 @BeanReference(type = PortletPreferencesPersistence.class)
2930 protected PortletPreferencesPersistence portletPreferencesPersistence;
2931 @BeanReference(type = RegionPersistence.class)
2932 protected RegionPersistence regionPersistence;
2933 @BeanReference(type = ReleasePersistence.class)
2934 protected ReleasePersistence releasePersistence;
2935 @BeanReference(type = RepositoryPersistence.class)
2936 protected RepositoryPersistence repositoryPersistence;
2937 @BeanReference(type = RepositoryEntryPersistence.class)
2938 protected RepositoryEntryPersistence repositoryEntryPersistence;
2939 @BeanReference(type = ResourcePersistence.class)
2940 protected ResourcePersistence resourcePersistence;
2941 @BeanReference(type = ResourceActionPersistence.class)
2942 protected ResourceActionPersistence resourceActionPersistence;
2943 @BeanReference(type = ResourceBlockPersistence.class)
2944 protected ResourceBlockPersistence resourceBlockPersistence;
2945 @BeanReference(type = ResourceBlockPermissionPersistence.class)
2946 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
2947 @BeanReference(type = ResourceCodePersistence.class)
2948 protected ResourceCodePersistence resourceCodePersistence;
2949 @BeanReference(type = ResourcePermissionPersistence.class)
2950 protected ResourcePermissionPersistence resourcePermissionPersistence;
2951 @BeanReference(type = ResourceTypePermissionPersistence.class)
2952 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
2953 @BeanReference(type = RolePersistence.class)
2954 protected RolePersistence rolePersistence;
2955 @BeanReference(type = ServiceComponentPersistence.class)
2956 protected ServiceComponentPersistence serviceComponentPersistence;
2957 @BeanReference(type = ShardPersistence.class)
2958 protected ShardPersistence shardPersistence;
2959 @BeanReference(type = SubscriptionPersistence.class)
2960 protected SubscriptionPersistence subscriptionPersistence;
2961 @BeanReference(type = TeamPersistence.class)
2962 protected TeamPersistence teamPersistence;
2963 @BeanReference(type = TicketPersistence.class)
2964 protected TicketPersistence ticketPersistence;
2965 @BeanReference(type = UserPersistence.class)
2966 protected UserPersistence userPersistence;
2967 @BeanReference(type = UserGroupPersistence.class)
2968 protected UserGroupPersistence userGroupPersistence;
2969 @BeanReference(type = UserGroupGroupRolePersistence.class)
2970 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
2971 @BeanReference(type = UserGroupRolePersistence.class)
2972 protected UserGroupRolePersistence userGroupRolePersistence;
2973 @BeanReference(type = UserIdMapperPersistence.class)
2974 protected UserIdMapperPersistence userIdMapperPersistence;
2975 @BeanReference(type = UserNotificationEventPersistence.class)
2976 protected UserNotificationEventPersistence userNotificationEventPersistence;
2977 @BeanReference(type = UserTrackerPersistence.class)
2978 protected UserTrackerPersistence userTrackerPersistence;
2979 @BeanReference(type = UserTrackerPathPersistence.class)
2980 protected UserTrackerPathPersistence userTrackerPathPersistence;
2981 @BeanReference(type = VirtualHostPersistence.class)
2982 protected VirtualHostPersistence virtualHostPersistence;
2983 @BeanReference(type = WebDAVPropsPersistence.class)
2984 protected WebDAVPropsPersistence webDAVPropsPersistence;
2985 @BeanReference(type = WebsitePersistence.class)
2986 protected WebsitePersistence websitePersistence;
2987 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
2988 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
2989 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
2990 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
2991 protected ContainsGroup containsGroup;
2992 protected AddGroup addGroup;
2993 protected ClearGroups clearGroups;
2994 protected RemoveGroup removeGroup;
2995 protected ContainsRole containsRole;
2996 protected AddRole addRole;
2997 protected ClearRoles clearRoles;
2998 protected RemoveRole removeRole;
2999 protected ContainsUser containsUser;
3000 protected AddUser addUser;
3001 protected ClearUsers clearUsers;
3002 protected RemoveUser removeUser;
3003
3004 protected class ContainsGroup {
3005 protected ContainsGroup() {
3006 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3007 _SQL_CONTAINSGROUP,
3008 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3009 RowMapper.COUNT);
3010 }
3011
3012 protected boolean contains(long permissionId, long groupId) {
3013 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3014 new Long(permissionId), new Long(groupId)
3015 });
3016
3017 if (results.size() > 0) {
3018 Integer count = results.get(0);
3019
3020 if (count.intValue() > 0) {
3021 return true;
3022 }
3023 }
3024
3025 return false;
3026 }
3027
3028 private MappingSqlQuery<Integer> _mappingSqlQuery;
3029 }
3030
3031 protected class AddGroup {
3032 protected AddGroup() {
3033 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3034 "INSERT INTO Groups_Permissions (permissionId, groupId) VALUES (?, ?)",
3035 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3036 }
3037
3038 protected void add(long permissionId, long groupId)
3039 throws SystemException {
3040 if (!containsGroup.contains(permissionId, groupId)) {
3041 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3042
3043 for (ModelListener<Permission> listener : listeners) {
3044 listener.onBeforeAddAssociation(permissionId,
3045 com.liferay.portal.model.Group.class.getName(), groupId);
3046 }
3047
3048 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3049 listener.onBeforeAddAssociation(groupId,
3050 Permission.class.getName(), permissionId);
3051 }
3052
3053 _sqlUpdate.update(new Object[] {
3054 new Long(permissionId), new Long(groupId)
3055 });
3056
3057 for (ModelListener<Permission> listener : listeners) {
3058 listener.onAfterAddAssociation(permissionId,
3059 com.liferay.portal.model.Group.class.getName(), groupId);
3060 }
3061
3062 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3063 listener.onAfterAddAssociation(groupId,
3064 Permission.class.getName(), permissionId);
3065 }
3066 }
3067 }
3068
3069 private SqlUpdate _sqlUpdate;
3070 }
3071
3072 protected class ClearGroups {
3073 protected ClearGroups() {
3074 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3075 "DELETE FROM Groups_Permissions WHERE permissionId = ?",
3076 new int[] { java.sql.Types.BIGINT });
3077 }
3078
3079 protected void clear(long permissionId) throws SystemException {
3080 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3081
3082 List<com.liferay.portal.model.Group> groups = null;
3083
3084 if ((listeners.length > 0) || (groupListeners.length > 0)) {
3085 groups = getGroups(permissionId);
3086
3087 for (com.liferay.portal.model.Group group : groups) {
3088 for (ModelListener<Permission> listener : listeners) {
3089 listener.onBeforeRemoveAssociation(permissionId,
3090 com.liferay.portal.model.Group.class.getName(),
3091 group.getPrimaryKey());
3092 }
3093
3094 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3095 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
3096 Permission.class.getName(), permissionId);
3097 }
3098 }
3099 }
3100
3101 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3102
3103 if ((listeners.length > 0) || (groupListeners.length > 0)) {
3104 for (com.liferay.portal.model.Group group : groups) {
3105 for (ModelListener<Permission> listener : listeners) {
3106 listener.onAfterRemoveAssociation(permissionId,
3107 com.liferay.portal.model.Group.class.getName(),
3108 group.getPrimaryKey());
3109 }
3110
3111 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3112 listener.onAfterRemoveAssociation(group.getPrimaryKey(),
3113 Permission.class.getName(), permissionId);
3114 }
3115 }
3116 }
3117 }
3118
3119 private SqlUpdate _sqlUpdate;
3120 }
3121
3122 protected class RemoveGroup {
3123 protected RemoveGroup() {
3124 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3125 "DELETE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?",
3126 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3127 }
3128
3129 protected void remove(long permissionId, long groupId)
3130 throws SystemException {
3131 if (containsGroup.contains(permissionId, groupId)) {
3132 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
3133
3134 for (ModelListener<Permission> listener : listeners) {
3135 listener.onBeforeRemoveAssociation(permissionId,
3136 com.liferay.portal.model.Group.class.getName(), groupId);
3137 }
3138
3139 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3140 listener.onBeforeRemoveAssociation(groupId,
3141 Permission.class.getName(), permissionId);
3142 }
3143
3144 _sqlUpdate.update(new Object[] {
3145 new Long(permissionId), new Long(groupId)
3146 });
3147
3148 for (ModelListener<Permission> listener : listeners) {
3149 listener.onAfterRemoveAssociation(permissionId,
3150 com.liferay.portal.model.Group.class.getName(), groupId);
3151 }
3152
3153 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
3154 listener.onAfterRemoveAssociation(groupId,
3155 Permission.class.getName(), permissionId);
3156 }
3157 }
3158 }
3159
3160 private SqlUpdate _sqlUpdate;
3161 }
3162
3163 protected class ContainsRole {
3164 protected ContainsRole() {
3165 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3166 _SQL_CONTAINSROLE,
3167 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3168 RowMapper.COUNT);
3169 }
3170
3171 protected boolean contains(long permissionId, long roleId) {
3172 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3173 new Long(permissionId), new Long(roleId)
3174 });
3175
3176 if (results.size() > 0) {
3177 Integer count = results.get(0);
3178
3179 if (count.intValue() > 0) {
3180 return true;
3181 }
3182 }
3183
3184 return false;
3185 }
3186
3187 private MappingSqlQuery<Integer> _mappingSqlQuery;
3188 }
3189
3190 protected class AddRole {
3191 protected AddRole() {
3192 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3193 "INSERT INTO Roles_Permissions (permissionId, roleId) VALUES (?, ?)",
3194 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3195 }
3196
3197 protected void add(long permissionId, long roleId)
3198 throws SystemException {
3199 if (!containsRole.contains(permissionId, roleId)) {
3200 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3201
3202 for (ModelListener<Permission> listener : listeners) {
3203 listener.onBeforeAddAssociation(permissionId,
3204 com.liferay.portal.model.Role.class.getName(), roleId);
3205 }
3206
3207 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3208 listener.onBeforeAddAssociation(roleId,
3209 Permission.class.getName(), permissionId);
3210 }
3211
3212 _sqlUpdate.update(new Object[] {
3213 new Long(permissionId), new Long(roleId)
3214 });
3215
3216 for (ModelListener<Permission> listener : listeners) {
3217 listener.onAfterAddAssociation(permissionId,
3218 com.liferay.portal.model.Role.class.getName(), roleId);
3219 }
3220
3221 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3222 listener.onAfterAddAssociation(roleId,
3223 Permission.class.getName(), permissionId);
3224 }
3225 }
3226 }
3227
3228 private SqlUpdate _sqlUpdate;
3229 }
3230
3231 protected class ClearRoles {
3232 protected ClearRoles() {
3233 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3234 "DELETE FROM Roles_Permissions WHERE permissionId = ?",
3235 new int[] { java.sql.Types.BIGINT });
3236 }
3237
3238 protected void clear(long permissionId) throws SystemException {
3239 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3240
3241 List<com.liferay.portal.model.Role> roles = null;
3242
3243 if ((listeners.length > 0) || (roleListeners.length > 0)) {
3244 roles = getRoles(permissionId);
3245
3246 for (com.liferay.portal.model.Role role : roles) {
3247 for (ModelListener<Permission> listener : listeners) {
3248 listener.onBeforeRemoveAssociation(permissionId,
3249 com.liferay.portal.model.Role.class.getName(),
3250 role.getPrimaryKey());
3251 }
3252
3253 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3254 listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
3255 Permission.class.getName(), permissionId);
3256 }
3257 }
3258 }
3259
3260 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3261
3262 if ((listeners.length > 0) || (roleListeners.length > 0)) {
3263 for (com.liferay.portal.model.Role role : roles) {
3264 for (ModelListener<Permission> listener : listeners) {
3265 listener.onAfterRemoveAssociation(permissionId,
3266 com.liferay.portal.model.Role.class.getName(),
3267 role.getPrimaryKey());
3268 }
3269
3270 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3271 listener.onAfterRemoveAssociation(role.getPrimaryKey(),
3272 Permission.class.getName(), permissionId);
3273 }
3274 }
3275 }
3276 }
3277
3278 private SqlUpdate _sqlUpdate;
3279 }
3280
3281 protected class RemoveRole {
3282 protected RemoveRole() {
3283 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3284 "DELETE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?",
3285 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3286 }
3287
3288 protected void remove(long permissionId, long roleId)
3289 throws SystemException {
3290 if (containsRole.contains(permissionId, roleId)) {
3291 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
3292
3293 for (ModelListener<Permission> listener : listeners) {
3294 listener.onBeforeRemoveAssociation(permissionId,
3295 com.liferay.portal.model.Role.class.getName(), roleId);
3296 }
3297
3298 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3299 listener.onBeforeRemoveAssociation(roleId,
3300 Permission.class.getName(), permissionId);
3301 }
3302
3303 _sqlUpdate.update(new Object[] {
3304 new Long(permissionId), new Long(roleId)
3305 });
3306
3307 for (ModelListener<Permission> listener : listeners) {
3308 listener.onAfterRemoveAssociation(permissionId,
3309 com.liferay.portal.model.Role.class.getName(), roleId);
3310 }
3311
3312 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
3313 listener.onAfterRemoveAssociation(roleId,
3314 Permission.class.getName(), permissionId);
3315 }
3316 }
3317 }
3318
3319 private SqlUpdate _sqlUpdate;
3320 }
3321
3322 protected class ContainsUser {
3323 protected ContainsUser() {
3324 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
3325 _SQL_CONTAINSUSER,
3326 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT },
3327 RowMapper.COUNT);
3328 }
3329
3330 protected boolean contains(long permissionId, long userId) {
3331 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
3332 new Long(permissionId), new Long(userId)
3333 });
3334
3335 if (results.size() > 0) {
3336 Integer count = results.get(0);
3337
3338 if (count.intValue() > 0) {
3339 return true;
3340 }
3341 }
3342
3343 return false;
3344 }
3345
3346 private MappingSqlQuery<Integer> _mappingSqlQuery;
3347 }
3348
3349 protected class AddUser {
3350 protected AddUser() {
3351 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3352 "INSERT INTO Users_Permissions (permissionId, userId) VALUES (?, ?)",
3353 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3354 }
3355
3356 protected void add(long permissionId, long userId)
3357 throws SystemException {
3358 if (!containsUser.contains(permissionId, userId)) {
3359 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3360
3361 for (ModelListener<Permission> listener : listeners) {
3362 listener.onBeforeAddAssociation(permissionId,
3363 com.liferay.portal.model.User.class.getName(), userId);
3364 }
3365
3366 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3367 listener.onBeforeAddAssociation(userId,
3368 Permission.class.getName(), permissionId);
3369 }
3370
3371 _sqlUpdate.update(new Object[] {
3372 new Long(permissionId), new Long(userId)
3373 });
3374
3375 for (ModelListener<Permission> listener : listeners) {
3376 listener.onAfterAddAssociation(permissionId,
3377 com.liferay.portal.model.User.class.getName(), userId);
3378 }
3379
3380 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3381 listener.onAfterAddAssociation(userId,
3382 Permission.class.getName(), permissionId);
3383 }
3384 }
3385 }
3386
3387 private SqlUpdate _sqlUpdate;
3388 }
3389
3390 protected class ClearUsers {
3391 protected ClearUsers() {
3392 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3393 "DELETE FROM Users_Permissions WHERE permissionId = ?",
3394 new int[] { java.sql.Types.BIGINT });
3395 }
3396
3397 protected void clear(long permissionId) throws SystemException {
3398 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3399
3400 List<com.liferay.portal.model.User> users = null;
3401
3402 if ((listeners.length > 0) || (userListeners.length > 0)) {
3403 users = getUsers(permissionId);
3404
3405 for (com.liferay.portal.model.User user : users) {
3406 for (ModelListener<Permission> listener : listeners) {
3407 listener.onBeforeRemoveAssociation(permissionId,
3408 com.liferay.portal.model.User.class.getName(),
3409 user.getPrimaryKey());
3410 }
3411
3412 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3413 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
3414 Permission.class.getName(), permissionId);
3415 }
3416 }
3417 }
3418
3419 _sqlUpdate.update(new Object[] { new Long(permissionId) });
3420
3421 if ((listeners.length > 0) || (userListeners.length > 0)) {
3422 for (com.liferay.portal.model.User user : users) {
3423 for (ModelListener<Permission> listener : listeners) {
3424 listener.onAfterRemoveAssociation(permissionId,
3425 com.liferay.portal.model.User.class.getName(),
3426 user.getPrimaryKey());
3427 }
3428
3429 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3430 listener.onAfterRemoveAssociation(user.getPrimaryKey(),
3431 Permission.class.getName(), permissionId);
3432 }
3433 }
3434 }
3435 }
3436
3437 private SqlUpdate _sqlUpdate;
3438 }
3439
3440 protected class RemoveUser {
3441 protected RemoveUser() {
3442 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
3443 "DELETE FROM Users_Permissions WHERE permissionId = ? AND userId = ?",
3444 new int[] { java.sql.Types.BIGINT, java.sql.Types.BIGINT });
3445 }
3446
3447 protected void remove(long permissionId, long userId)
3448 throws SystemException {
3449 if (containsUser.contains(permissionId, userId)) {
3450 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
3451
3452 for (ModelListener<Permission> listener : listeners) {
3453 listener.onBeforeRemoveAssociation(permissionId,
3454 com.liferay.portal.model.User.class.getName(), userId);
3455 }
3456
3457 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3458 listener.onBeforeRemoveAssociation(userId,
3459 Permission.class.getName(), permissionId);
3460 }
3461
3462 _sqlUpdate.update(new Object[] {
3463 new Long(permissionId), new Long(userId)
3464 });
3465
3466 for (ModelListener<Permission> listener : listeners) {
3467 listener.onAfterRemoveAssociation(permissionId,
3468 com.liferay.portal.model.User.class.getName(), userId);
3469 }
3470
3471 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
3472 listener.onAfterRemoveAssociation(userId,
3473 Permission.class.getName(), permissionId);
3474 }
3475 }
3476 }
3477
3478 private SqlUpdate _sqlUpdate;
3479 }
3480
3481 private static final String _SQL_SELECT_PERMISSION = "SELECT permission FROM Permission permission";
3482 private static final String _SQL_SELECT_PERMISSION_WHERE = "SELECT permission FROM Permission permission WHERE ";
3483 private static final String _SQL_COUNT_PERMISSION = "SELECT COUNT(permission) FROM Permission permission";
3484 private static final String _SQL_COUNT_PERMISSION_WHERE = "SELECT COUNT(permission) FROM Permission permission WHERE ";
3485 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Permissions ON (Groups_Permissions.groupId = Group_.groupId) WHERE (Groups_Permissions.permissionId = ?)";
3486 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ?";
3487 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?";
3488 private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Roles_Permissions ON (Roles_Permissions.roleId = Role_.roleId) WHERE (Roles_Permissions.permissionId = ?)";
3489 private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ?";
3490 private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?";
3491 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Permissions ON (Users_Permissions.userId = User_.userId) WHERE (Users_Permissions.permissionId = ?)";
3492 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ?";
3493 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ? AND userId = ?";
3494 private static final String _FINDER_COLUMN_RESOURCEID_RESOURCEID_2 = "permission.resourceId = ?";
3495 private static final String _FINDER_COLUMN_A_R_ACTIONID_1 = "permission.actionId IS NULL AND ";
3496 private static final String _FINDER_COLUMN_A_R_ACTIONID_2 = "permission.actionId = ? AND ";
3497 private static final String _FINDER_COLUMN_A_R_ACTIONID_3 = "(permission.actionId IS NULL OR permission.actionId = ?) AND ";
3498 private static final String _FINDER_COLUMN_A_R_RESOURCEID_2 = "permission.resourceId = ?";
3499 private static final String _ORDER_BY_ENTITY_ALIAS = "permission.";
3500 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Permission exists with the primary key ";
3501 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No Permission exists with the key {";
3502 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3503 private static Log _log = LogFactoryUtil.getLog(PermissionPersistenceImpl.class);
3504 private static Permission _nullPermission = new PermissionImpl() {
3505 @Override
3506 public Object clone() {
3507 return this;
3508 }
3509
3510 @Override
3511 public CacheModel<Permission> toCacheModel() {
3512 return _nullPermissionCacheModel;
3513 }
3514 };
3515
3516 private static CacheModel<Permission> _nullPermissionCacheModel = new CacheModel<Permission>() {
3517 public Permission toEntityModel() {
3518 return _nullPermission;
3519 }
3520 };
3521 }