1
19
20 package com.liferay.portal.service.persistence;
21
22 import com.liferay.portal.NoSuchPermissionException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.annotation.BeanReference;
25 import com.liferay.portal.kernel.cache.CacheRegistry;
26 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQuery;
27 import com.liferay.portal.kernel.dao.jdbc.MappingSqlQueryFactoryUtil;
28 import com.liferay.portal.kernel.dao.jdbc.RowMapper;
29 import com.liferay.portal.kernel.dao.jdbc.SqlUpdate;
30 import com.liferay.portal.kernel.dao.jdbc.SqlUpdateFactoryUtil;
31 import com.liferay.portal.kernel.dao.orm.DynamicQuery;
32 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
33 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
34 import com.liferay.portal.kernel.dao.orm.FinderPath;
35 import com.liferay.portal.kernel.dao.orm.Query;
36 import com.liferay.portal.kernel.dao.orm.QueryPos;
37 import com.liferay.portal.kernel.dao.orm.QueryUtil;
38 import com.liferay.portal.kernel.dao.orm.SQLQuery;
39 import com.liferay.portal.kernel.dao.orm.Session;
40 import com.liferay.portal.kernel.dao.orm.Type;
41 import com.liferay.portal.kernel.log.Log;
42 import com.liferay.portal.kernel.log.LogFactoryUtil;
43 import com.liferay.portal.kernel.util.GetterUtil;
44 import com.liferay.portal.kernel.util.OrderByComparator;
45 import com.liferay.portal.kernel.util.StringPool;
46 import com.liferay.portal.kernel.util.StringUtil;
47 import com.liferay.portal.kernel.util.Validator;
48 import com.liferay.portal.model.ModelListener;
49 import com.liferay.portal.model.Permission;
50 import com.liferay.portal.model.impl.PermissionImpl;
51 import com.liferay.portal.model.impl.PermissionModelImpl;
52 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
53
54 import java.sql.Types;
55
56 import java.util.ArrayList;
57 import java.util.Collections;
58 import java.util.List;
59
60
66 public class PermissionPersistenceImpl extends BasePersistenceImpl
67 implements PermissionPersistence {
68 public static final String FINDER_CLASS_NAME_ENTITY = PermissionImpl.class.getName();
69 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
70 ".List";
71 public static final FinderPath FINDER_PATH_FIND_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
72 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
73 "findByResourceId", new String[] { Long.class.getName() });
74 public static final FinderPath FINDER_PATH_FIND_BY_OBC_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
75 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
76 "findByResourceId",
77 new String[] {
78 Long.class.getName(),
79
80 "java.lang.Integer", "java.lang.Integer",
81 "com.liferay.portal.kernel.util.OrderByComparator"
82 });
83 public static final FinderPath FINDER_PATH_COUNT_BY_RESOURCEID = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
84 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
85 "countByResourceId", new String[] { Long.class.getName() });
86 public static final FinderPath FINDER_PATH_FETCH_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
87 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
88 "fetchByA_R",
89 new String[] { String.class.getName(), Long.class.getName() });
90 public static final FinderPath FINDER_PATH_COUNT_BY_A_R = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
91 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
92 "countByA_R",
93 new String[] { String.class.getName(), Long.class.getName() });
94 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
95 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
96 "findAll", new String[0]);
97 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(PermissionModelImpl.ENTITY_CACHE_ENABLED,
98 PermissionModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
99 "countAll", new String[0]);
100
101 public void cacheResult(Permission permission) {
102 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
103 PermissionImpl.class, permission.getPrimaryKey(), permission);
104
105 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
106 new Object[] {
107 permission.getActionId(), new Long(permission.getResourceId())
108 }, permission);
109 }
110
111 public void cacheResult(List<Permission> permissions) {
112 for (Permission permission : permissions) {
113 if (EntityCacheUtil.getResult(
114 PermissionModelImpl.ENTITY_CACHE_ENABLED,
115 PermissionImpl.class, permission.getPrimaryKey(), this) == null) {
116 cacheResult(permission);
117 }
118 }
119 }
120
121 public void clearCache() {
122 CacheRegistry.clear(PermissionImpl.class.getName());
123 EntityCacheUtil.clearCache(PermissionImpl.class.getName());
124 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
125 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
126 }
127
128 public Permission create(long permissionId) {
129 Permission permission = new PermissionImpl();
130
131 permission.setNew(true);
132 permission.setPrimaryKey(permissionId);
133
134 return permission;
135 }
136
137 public Permission remove(long permissionId)
138 throws NoSuchPermissionException, SystemException {
139 Session session = null;
140
141 try {
142 session = openSession();
143
144 Permission permission = (Permission)session.get(PermissionImpl.class,
145 new Long(permissionId));
146
147 if (permission == null) {
148 if (_log.isWarnEnabled()) {
149 _log.warn("No Permission exists with the primary key " +
150 permissionId);
151 }
152
153 throw new NoSuchPermissionException(
154 "No Permission exists with the primary key " +
155 permissionId);
156 }
157
158 return remove(permission);
159 }
160 catch (NoSuchPermissionException nsee) {
161 throw nsee;
162 }
163 catch (Exception e) {
164 throw processException(e);
165 }
166 finally {
167 closeSession(session);
168 }
169 }
170
171 public Permission remove(Permission permission) throws SystemException {
172 for (ModelListener<Permission> listener : listeners) {
173 listener.onBeforeRemove(permission);
174 }
175
176 permission = removeImpl(permission);
177
178 for (ModelListener<Permission> listener : listeners) {
179 listener.onAfterRemove(permission);
180 }
181
182 return permission;
183 }
184
185 protected Permission removeImpl(Permission permission)
186 throws SystemException {
187 try {
188 clearGroups.clear(permission.getPrimaryKey());
189 }
190 catch (Exception e) {
191 throw processException(e);
192 }
193 finally {
194 FinderCacheUtil.clearCache("Groups_Permissions");
195 }
196
197 try {
198 clearRoles.clear(permission.getPrimaryKey());
199 }
200 catch (Exception e) {
201 throw processException(e);
202 }
203 finally {
204 FinderCacheUtil.clearCache("Roles_Permissions");
205 }
206
207 try {
208 clearUsers.clear(permission.getPrimaryKey());
209 }
210 catch (Exception e) {
211 throw processException(e);
212 }
213 finally {
214 FinderCacheUtil.clearCache("Users_Permissions");
215 }
216
217 Session session = null;
218
219 try {
220 session = openSession();
221
222 if (permission.isCachedModel() || BatchSessionUtil.isEnabled()) {
223 Object staleObject = session.get(PermissionImpl.class,
224 permission.getPrimaryKeyObj());
225
226 if (staleObject != null) {
227 session.evict(staleObject);
228 }
229 }
230
231 session.delete(permission);
232
233 session.flush();
234 }
235 catch (Exception e) {
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241
242 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
243
244 PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
245
246 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
247 new Object[] {
248 permissionModelImpl.getOriginalActionId(),
249 new Long(permissionModelImpl.getOriginalResourceId())
250 });
251
252 EntityCacheUtil.removeResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
253 PermissionImpl.class, permission.getPrimaryKey());
254
255 return permission;
256 }
257
258
261 public Permission update(Permission permission) throws SystemException {
262 if (_log.isWarnEnabled()) {
263 _log.warn(
264 "Using the deprecated update(Permission permission) method. Use update(Permission permission, boolean merge) instead.");
265 }
266
267 return update(permission, false);
268 }
269
270
283 public Permission update(Permission permission, boolean merge)
284 throws SystemException {
285 boolean isNew = permission.isNew();
286
287 for (ModelListener<Permission> listener : listeners) {
288 if (isNew) {
289 listener.onBeforeCreate(permission);
290 }
291 else {
292 listener.onBeforeUpdate(permission);
293 }
294 }
295
296 permission = updateImpl(permission, merge);
297
298 for (ModelListener<Permission> listener : listeners) {
299 if (isNew) {
300 listener.onAfterCreate(permission);
301 }
302 else {
303 listener.onAfterUpdate(permission);
304 }
305 }
306
307 return permission;
308 }
309
310 public Permission updateImpl(
311 com.liferay.portal.model.Permission permission, boolean merge)
312 throws SystemException {
313 boolean isNew = permission.isNew();
314
315 PermissionModelImpl permissionModelImpl = (PermissionModelImpl)permission;
316
317 Session session = null;
318
319 try {
320 session = openSession();
321
322 BatchSessionUtil.update(session, permission, merge);
323
324 permission.setNew(false);
325 }
326 catch (Exception e) {
327 throw processException(e);
328 }
329 finally {
330 closeSession(session);
331 }
332
333 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
334
335 EntityCacheUtil.putResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
336 PermissionImpl.class, permission.getPrimaryKey(), permission);
337
338 if (!isNew &&
339 (!Validator.equals(permission.getActionId(),
340 permissionModelImpl.getOriginalActionId()) ||
341 (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
342 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_A_R,
343 new Object[] {
344 permissionModelImpl.getOriginalActionId(),
345 new Long(permissionModelImpl.getOriginalResourceId())
346 });
347 }
348
349 if (isNew ||
350 (!Validator.equals(permission.getActionId(),
351 permissionModelImpl.getOriginalActionId()) ||
352 (permission.getResourceId() != permissionModelImpl.getOriginalResourceId()))) {
353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
354 new Object[] {
355 permission.getActionId(),
356 new Long(permission.getResourceId())
357 }, permission);
358 }
359
360 return permission;
361 }
362
363 public Permission findByPrimaryKey(long permissionId)
364 throws NoSuchPermissionException, SystemException {
365 Permission permission = fetchByPrimaryKey(permissionId);
366
367 if (permission == null) {
368 if (_log.isWarnEnabled()) {
369 _log.warn("No Permission exists with the primary key " +
370 permissionId);
371 }
372
373 throw new NoSuchPermissionException(
374 "No Permission exists with the primary key " + permissionId);
375 }
376
377 return permission;
378 }
379
380 public Permission fetchByPrimaryKey(long permissionId)
381 throws SystemException {
382 Permission permission = (Permission)EntityCacheUtil.getResult(PermissionModelImpl.ENTITY_CACHE_ENABLED,
383 PermissionImpl.class, permissionId, this);
384
385 if (permission == null) {
386 Session session = null;
387
388 try {
389 session = openSession();
390
391 permission = (Permission)session.get(PermissionImpl.class,
392 new Long(permissionId));
393 }
394 catch (Exception e) {
395 throw processException(e);
396 }
397 finally {
398 if (permission != null) {
399 cacheResult(permission);
400 }
401
402 closeSession(session);
403 }
404 }
405
406 return permission;
407 }
408
409 public List<Permission> findByResourceId(long resourceId)
410 throws SystemException {
411 Object[] finderArgs = new Object[] { new Long(resourceId) };
412
413 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_RESOURCEID,
414 finderArgs, this);
415
416 if (list == null) {
417 Session session = null;
418
419 try {
420 session = openSession();
421
422 StringBuilder query = new StringBuilder();
423
424 query.append(
425 "SELECT permission FROM Permission permission WHERE ");
426
427 query.append("permission.resourceId = ?");
428
429 query.append(" ");
430
431 Query q = session.createQuery(query.toString());
432
433 QueryPos qPos = QueryPos.getInstance(q);
434
435 qPos.add(resourceId);
436
437 list = q.list();
438 }
439 catch (Exception e) {
440 throw processException(e);
441 }
442 finally {
443 if (list == null) {
444 list = new ArrayList<Permission>();
445 }
446
447 cacheResult(list);
448
449 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_RESOURCEID,
450 finderArgs, list);
451
452 closeSession(session);
453 }
454 }
455
456 return list;
457 }
458
459 public List<Permission> findByResourceId(long resourceId, int start, int end)
460 throws SystemException {
461 return findByResourceId(resourceId, start, end, null);
462 }
463
464 public List<Permission> findByResourceId(long resourceId, int start,
465 int end, OrderByComparator obc) throws SystemException {
466 Object[] finderArgs = new Object[] {
467 new Long(resourceId),
468
469 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
470 };
471
472 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_RESOURCEID,
473 finderArgs, this);
474
475 if (list == null) {
476 Session session = null;
477
478 try {
479 session = openSession();
480
481 StringBuilder query = new StringBuilder();
482
483 query.append(
484 "SELECT permission FROM Permission permission WHERE ");
485
486 query.append("permission.resourceId = ?");
487
488 query.append(" ");
489
490 if (obc != null) {
491 query.append("ORDER BY ");
492
493 String[] orderByFields = obc.getOrderByFields();
494
495 for (int i = 0; i < orderByFields.length; i++) {
496 query.append("permission.");
497 query.append(orderByFields[i]);
498
499 if (obc.isAscending()) {
500 query.append(" ASC");
501 }
502 else {
503 query.append(" DESC");
504 }
505
506 if ((i + 1) < orderByFields.length) {
507 query.append(", ");
508 }
509 }
510 }
511
512 Query q = session.createQuery(query.toString());
513
514 QueryPos qPos = QueryPos.getInstance(q);
515
516 qPos.add(resourceId);
517
518 list = (List<Permission>)QueryUtil.list(q, getDialect(), start,
519 end);
520 }
521 catch (Exception e) {
522 throw processException(e);
523 }
524 finally {
525 if (list == null) {
526 list = new ArrayList<Permission>();
527 }
528
529 cacheResult(list);
530
531 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_RESOURCEID,
532 finderArgs, list);
533
534 closeSession(session);
535 }
536 }
537
538 return list;
539 }
540
541 public Permission findByResourceId_First(long resourceId,
542 OrderByComparator obc)
543 throws NoSuchPermissionException, SystemException {
544 List<Permission> list = findByResourceId(resourceId, 0, 1, obc);
545
546 if (list.isEmpty()) {
547 StringBuilder msg = new StringBuilder();
548
549 msg.append("No Permission exists with the key {");
550
551 msg.append("resourceId=" + resourceId);
552
553 msg.append(StringPool.CLOSE_CURLY_BRACE);
554
555 throw new NoSuchPermissionException(msg.toString());
556 }
557 else {
558 return list.get(0);
559 }
560 }
561
562 public Permission findByResourceId_Last(long resourceId,
563 OrderByComparator obc)
564 throws NoSuchPermissionException, SystemException {
565 int count = countByResourceId(resourceId);
566
567 List<Permission> list = findByResourceId(resourceId, count - 1, count,
568 obc);
569
570 if (list.isEmpty()) {
571 StringBuilder msg = new StringBuilder();
572
573 msg.append("No Permission exists with the key {");
574
575 msg.append("resourceId=" + resourceId);
576
577 msg.append(StringPool.CLOSE_CURLY_BRACE);
578
579 throw new NoSuchPermissionException(msg.toString());
580 }
581 else {
582 return list.get(0);
583 }
584 }
585
586 public Permission[] findByResourceId_PrevAndNext(long permissionId,
587 long resourceId, OrderByComparator obc)
588 throws NoSuchPermissionException, SystemException {
589 Permission permission = findByPrimaryKey(permissionId);
590
591 int count = countByResourceId(resourceId);
592
593 Session session = null;
594
595 try {
596 session = openSession();
597
598 StringBuilder query = new StringBuilder();
599
600 query.append("SELECT permission FROM Permission permission WHERE ");
601
602 query.append("permission.resourceId = ?");
603
604 query.append(" ");
605
606 if (obc != null) {
607 query.append("ORDER BY ");
608
609 String[] orderByFields = obc.getOrderByFields();
610
611 for (int i = 0; i < orderByFields.length; i++) {
612 query.append("permission.");
613 query.append(orderByFields[i]);
614
615 if (obc.isAscending()) {
616 query.append(" ASC");
617 }
618 else {
619 query.append(" DESC");
620 }
621
622 if ((i + 1) < orderByFields.length) {
623 query.append(", ");
624 }
625 }
626 }
627
628 Query q = session.createQuery(query.toString());
629
630 QueryPos qPos = QueryPos.getInstance(q);
631
632 qPos.add(resourceId);
633
634 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
635 permission);
636
637 Permission[] array = new PermissionImpl[3];
638
639 array[0] = (Permission)objArray[0];
640 array[1] = (Permission)objArray[1];
641 array[2] = (Permission)objArray[2];
642
643 return array;
644 }
645 catch (Exception e) {
646 throw processException(e);
647 }
648 finally {
649 closeSession(session);
650 }
651 }
652
653 public Permission findByA_R(String actionId, long resourceId)
654 throws NoSuchPermissionException, SystemException {
655 Permission permission = fetchByA_R(actionId, resourceId);
656
657 if (permission == null) {
658 StringBuilder msg = new StringBuilder();
659
660 msg.append("No Permission exists with the key {");
661
662 msg.append("actionId=" + actionId);
663
664 msg.append(", ");
665 msg.append("resourceId=" + resourceId);
666
667 msg.append(StringPool.CLOSE_CURLY_BRACE);
668
669 if (_log.isWarnEnabled()) {
670 _log.warn(msg.toString());
671 }
672
673 throw new NoSuchPermissionException(msg.toString());
674 }
675
676 return permission;
677 }
678
679 public Permission fetchByA_R(String actionId, long resourceId)
680 throws SystemException {
681 return fetchByA_R(actionId, resourceId, true);
682 }
683
684 public Permission fetchByA_R(String actionId, long resourceId,
685 boolean retrieveFromCache) throws SystemException {
686 Object[] finderArgs = new Object[] { actionId, new Long(resourceId) };
687
688 Object result = null;
689
690 if (retrieveFromCache) {
691 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_A_R,
692 finderArgs, this);
693 }
694
695 if (result == null) {
696 Session session = null;
697
698 try {
699 session = openSession();
700
701 StringBuilder query = new StringBuilder();
702
703 query.append(
704 "SELECT permission FROM Permission permission WHERE ");
705
706 if (actionId == null) {
707 query.append("permission.actionId IS NULL");
708 }
709 else {
710 query.append("permission.actionId = ?");
711 }
712
713 query.append(" AND ");
714
715 query.append("permission.resourceId = ?");
716
717 query.append(" ");
718
719 Query q = session.createQuery(query.toString());
720
721 QueryPos qPos = QueryPos.getInstance(q);
722
723 if (actionId != null) {
724 qPos.add(actionId);
725 }
726
727 qPos.add(resourceId);
728
729 List<Permission> list = q.list();
730
731 result = list;
732
733 Permission permission = null;
734
735 if (list.isEmpty()) {
736 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
737 finderArgs, list);
738 }
739 else {
740 permission = list.get(0);
741
742 cacheResult(permission);
743
744 if ((permission.getActionId() == null) ||
745 !permission.getActionId().equals(actionId) ||
746 (permission.getResourceId() != resourceId)) {
747 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
748 finderArgs, permission);
749 }
750 }
751
752 return permission;
753 }
754 catch (Exception e) {
755 throw processException(e);
756 }
757 finally {
758 if (result == null) {
759 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_A_R,
760 finderArgs, new ArrayList<Permission>());
761 }
762
763 closeSession(session);
764 }
765 }
766 else {
767 if (result instanceof List) {
768 return null;
769 }
770 else {
771 return (Permission)result;
772 }
773 }
774 }
775
776 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
777 throws SystemException {
778 Session session = null;
779
780 try {
781 session = openSession();
782
783 dynamicQuery.compile(session);
784
785 return dynamicQuery.list();
786 }
787 catch (Exception e) {
788 throw processException(e);
789 }
790 finally {
791 closeSession(session);
792 }
793 }
794
795 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
796 int start, int end) throws SystemException {
797 Session session = null;
798
799 try {
800 session = openSession();
801
802 dynamicQuery.setLimit(start, end);
803
804 dynamicQuery.compile(session);
805
806 return dynamicQuery.list();
807 }
808 catch (Exception e) {
809 throw processException(e);
810 }
811 finally {
812 closeSession(session);
813 }
814 }
815
816 public List<Permission> findAll() throws SystemException {
817 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
818 }
819
820 public List<Permission> findAll(int start, int end)
821 throws SystemException {
822 return findAll(start, end, null);
823 }
824
825 public List<Permission> findAll(int start, int end, OrderByComparator obc)
826 throws SystemException {
827 Object[] finderArgs = new Object[] {
828 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
829 };
830
831 List<Permission> list = (List<Permission>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
832 finderArgs, this);
833
834 if (list == null) {
835 Session session = null;
836
837 try {
838 session = openSession();
839
840 StringBuilder query = new StringBuilder();
841
842 query.append("SELECT permission FROM Permission permission ");
843
844 if (obc != null) {
845 query.append("ORDER BY ");
846
847 String[] orderByFields = obc.getOrderByFields();
848
849 for (int i = 0; i < orderByFields.length; i++) {
850 query.append("permission.");
851 query.append(orderByFields[i]);
852
853 if (obc.isAscending()) {
854 query.append(" ASC");
855 }
856 else {
857 query.append(" DESC");
858 }
859
860 if ((i + 1) < orderByFields.length) {
861 query.append(", ");
862 }
863 }
864 }
865
866 Query q = session.createQuery(query.toString());
867
868 if (obc == null) {
869 list = (List<Permission>)QueryUtil.list(q, getDialect(),
870 start, end, false);
871
872 Collections.sort(list);
873 }
874 else {
875 list = (List<Permission>)QueryUtil.list(q, getDialect(),
876 start, end);
877 }
878 }
879 catch (Exception e) {
880 throw processException(e);
881 }
882 finally {
883 if (list == null) {
884 list = new ArrayList<Permission>();
885 }
886
887 cacheResult(list);
888
889 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
890
891 closeSession(session);
892 }
893 }
894
895 return list;
896 }
897
898 public void removeByResourceId(long resourceId) throws SystemException {
899 for (Permission permission : findByResourceId(resourceId)) {
900 remove(permission);
901 }
902 }
903
904 public void removeByA_R(String actionId, long resourceId)
905 throws NoSuchPermissionException, SystemException {
906 Permission permission = findByA_R(actionId, resourceId);
907
908 remove(permission);
909 }
910
911 public void removeAll() throws SystemException {
912 for (Permission permission : findAll()) {
913 remove(permission);
914 }
915 }
916
917 public int countByResourceId(long resourceId) throws SystemException {
918 Object[] finderArgs = new Object[] { new Long(resourceId) };
919
920 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_RESOURCEID,
921 finderArgs, this);
922
923 if (count == null) {
924 Session session = null;
925
926 try {
927 session = openSession();
928
929 StringBuilder query = new StringBuilder();
930
931 query.append("SELECT COUNT(permission) ");
932 query.append("FROM Permission permission WHERE ");
933
934 query.append("permission.resourceId = ?");
935
936 query.append(" ");
937
938 Query q = session.createQuery(query.toString());
939
940 QueryPos qPos = QueryPos.getInstance(q);
941
942 qPos.add(resourceId);
943
944 count = (Long)q.uniqueResult();
945 }
946 catch (Exception e) {
947 throw processException(e);
948 }
949 finally {
950 if (count == null) {
951 count = Long.valueOf(0);
952 }
953
954 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_RESOURCEID,
955 finderArgs, count);
956
957 closeSession(session);
958 }
959 }
960
961 return count.intValue();
962 }
963
964 public int countByA_R(String actionId, long resourceId)
965 throws SystemException {
966 Object[] finderArgs = new Object[] { actionId, new Long(resourceId) };
967
968 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_A_R,
969 finderArgs, this);
970
971 if (count == null) {
972 Session session = null;
973
974 try {
975 session = openSession();
976
977 StringBuilder query = new StringBuilder();
978
979 query.append("SELECT COUNT(permission) ");
980 query.append("FROM Permission permission WHERE ");
981
982 if (actionId == null) {
983 query.append("permission.actionId IS NULL");
984 }
985 else {
986 query.append("permission.actionId = ?");
987 }
988
989 query.append(" AND ");
990
991 query.append("permission.resourceId = ?");
992
993 query.append(" ");
994
995 Query q = session.createQuery(query.toString());
996
997 QueryPos qPos = QueryPos.getInstance(q);
998
999 if (actionId != null) {
1000 qPos.add(actionId);
1001 }
1002
1003 qPos.add(resourceId);
1004
1005 count = (Long)q.uniqueResult();
1006 }
1007 catch (Exception e) {
1008 throw processException(e);
1009 }
1010 finally {
1011 if (count == null) {
1012 count = Long.valueOf(0);
1013 }
1014
1015 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_A_R, finderArgs,
1016 count);
1017
1018 closeSession(session);
1019 }
1020 }
1021
1022 return count.intValue();
1023 }
1024
1025 public int countAll() throws SystemException {
1026 Object[] finderArgs = new Object[0];
1027
1028 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1029 finderArgs, this);
1030
1031 if (count == null) {
1032 Session session = null;
1033
1034 try {
1035 session = openSession();
1036
1037 Query q = session.createQuery(
1038 "SELECT COUNT(permission) FROM Permission permission");
1039
1040 count = (Long)q.uniqueResult();
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 if (count == null) {
1047 count = Long.valueOf(0);
1048 }
1049
1050 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1051 count);
1052
1053 closeSession(session);
1054 }
1055 }
1056
1057 return count.intValue();
1058 }
1059
1060 public List<com.liferay.portal.model.Group> getGroups(long pk)
1061 throws SystemException {
1062 return getGroups(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1063 }
1064
1065 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1066 int end) throws SystemException {
1067 return getGroups(pk, start, end, null);
1068 }
1069
1070 public static final FinderPath FINDER_PATH_GET_GROUPS = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1071 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1072 "Groups_Permissions", "getGroups",
1073 new String[] {
1074 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1075 "com.liferay.portal.kernel.util.OrderByComparator"
1076 });
1077
1078 public List<com.liferay.portal.model.Group> getGroups(long pk, int start,
1079 int end, OrderByComparator obc) throws SystemException {
1080 Object[] finderArgs = new Object[] {
1081 new Long(pk), String.valueOf(start), String.valueOf(end),
1082 String.valueOf(obc)
1083 };
1084
1085 List<com.liferay.portal.model.Group> list = (List<com.liferay.portal.model.Group>)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS,
1086 finderArgs, this);
1087
1088 if (list == null) {
1089 Session session = null;
1090
1091 try {
1092 session = openSession();
1093
1094 StringBuilder sb = new StringBuilder();
1095
1096 sb.append(_SQL_GETGROUPS);
1097
1098 if (obc != null) {
1099 sb.append("ORDER BY ");
1100 sb.append(obc.getOrderBy());
1101 }
1102
1103 else {
1104 sb.append("ORDER BY ");
1105
1106 sb.append("Group_.name ASC");
1107 }
1108
1109 String sql = sb.toString();
1110
1111 SQLQuery q = session.createSQLQuery(sql);
1112
1113 q.addEntity("Group_",
1114 com.liferay.portal.model.impl.GroupImpl.class);
1115
1116 QueryPos qPos = QueryPos.getInstance(q);
1117
1118 qPos.add(pk);
1119
1120 list = (List<com.liferay.portal.model.Group>)QueryUtil.list(q,
1121 getDialect(), start, end);
1122 }
1123 catch (Exception e) {
1124 throw processException(e);
1125 }
1126 finally {
1127 if (list == null) {
1128 list = new ArrayList<com.liferay.portal.model.Group>();
1129 }
1130
1131 groupPersistence.cacheResult(list);
1132
1133 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS, finderArgs,
1134 list);
1135
1136 closeSession(session);
1137 }
1138 }
1139
1140 return list;
1141 }
1142
1143 public static final FinderPath FINDER_PATH_GET_GROUPS_SIZE = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1144 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1145 "Groups_Permissions", "getGroupsSize",
1146 new String[] { Long.class.getName() });
1147
1148 public int getGroupsSize(long pk) throws SystemException {
1149 Object[] finderArgs = new Object[] { new Long(pk) };
1150
1151 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_GROUPS_SIZE,
1152 finderArgs, this);
1153
1154 if (count == null) {
1155 Session session = null;
1156
1157 try {
1158 session = openSession();
1159
1160 SQLQuery q = session.createSQLQuery(_SQL_GETGROUPSSIZE);
1161
1162 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1163
1164 QueryPos qPos = QueryPos.getInstance(q);
1165
1166 qPos.add(pk);
1167
1168 count = (Long)q.uniqueResult();
1169 }
1170 catch (Exception e) {
1171 throw processException(e);
1172 }
1173 finally {
1174 if (count == null) {
1175 count = Long.valueOf(0);
1176 }
1177
1178 FinderCacheUtil.putResult(FINDER_PATH_GET_GROUPS_SIZE,
1179 finderArgs, count);
1180
1181 closeSession(session);
1182 }
1183 }
1184
1185 return count.intValue();
1186 }
1187
1188 public static final FinderPath FINDER_PATH_CONTAINS_GROUP = new FinderPath(com.liferay.portal.model.impl.GroupModelImpl.ENTITY_CACHE_ENABLED,
1189 PermissionModelImpl.FINDER_CACHE_ENABLED_GROUPS_PERMISSIONS,
1190 "Groups_Permissions", "containsGroup",
1191 new String[] { Long.class.getName(), Long.class.getName() });
1192
1193 public boolean containsGroup(long pk, long groupPK)
1194 throws SystemException {
1195 Object[] finderArgs = new Object[] { new Long(pk), new Long(groupPK) };
1196
1197 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_GROUP,
1198 finderArgs, this);
1199
1200 if (value == null) {
1201 try {
1202 value = Boolean.valueOf(containsGroup.contains(pk, groupPK));
1203 }
1204 catch (Exception e) {
1205 throw processException(e);
1206 }
1207 finally {
1208 if (value == null) {
1209 value = Boolean.FALSE;
1210 }
1211
1212 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_GROUP,
1213 finderArgs, value);
1214 }
1215 }
1216
1217 return value.booleanValue();
1218 }
1219
1220 public boolean containsGroups(long pk) throws SystemException {
1221 if (getGroupsSize(pk) > 0) {
1222 return true;
1223 }
1224 else {
1225 return false;
1226 }
1227 }
1228
1229 public void addGroup(long pk, long groupPK) throws SystemException {
1230 try {
1231 addGroup.add(pk, groupPK);
1232 }
1233 catch (Exception e) {
1234 throw processException(e);
1235 }
1236 finally {
1237 FinderCacheUtil.clearCache("Groups_Permissions");
1238 }
1239 }
1240
1241 public void addGroup(long pk, com.liferay.portal.model.Group group)
1242 throws SystemException {
1243 try {
1244 addGroup.add(pk, group.getPrimaryKey());
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 FinderCacheUtil.clearCache("Groups_Permissions");
1251 }
1252 }
1253
1254 public void addGroups(long pk, long[] groupPKs) throws SystemException {
1255 try {
1256 for (long groupPK : groupPKs) {
1257 addGroup.add(pk, groupPK);
1258 }
1259 }
1260 catch (Exception e) {
1261 throw processException(e);
1262 }
1263 finally {
1264 FinderCacheUtil.clearCache("Groups_Permissions");
1265 }
1266 }
1267
1268 public void addGroups(long pk, List<com.liferay.portal.model.Group> groups)
1269 throws SystemException {
1270 try {
1271 for (com.liferay.portal.model.Group group : groups) {
1272 addGroup.add(pk, group.getPrimaryKey());
1273 }
1274 }
1275 catch (Exception e) {
1276 throw processException(e);
1277 }
1278 finally {
1279 FinderCacheUtil.clearCache("Groups_Permissions");
1280 }
1281 }
1282
1283 public void clearGroups(long pk) throws SystemException {
1284 try {
1285 clearGroups.clear(pk);
1286 }
1287 catch (Exception e) {
1288 throw processException(e);
1289 }
1290 finally {
1291 FinderCacheUtil.clearCache("Groups_Permissions");
1292 }
1293 }
1294
1295 public void removeGroup(long pk, long groupPK) throws SystemException {
1296 try {
1297 removeGroup.remove(pk, groupPK);
1298 }
1299 catch (Exception e) {
1300 throw processException(e);
1301 }
1302 finally {
1303 FinderCacheUtil.clearCache("Groups_Permissions");
1304 }
1305 }
1306
1307 public void removeGroup(long pk, com.liferay.portal.model.Group group)
1308 throws SystemException {
1309 try {
1310 removeGroup.remove(pk, group.getPrimaryKey());
1311 }
1312 catch (Exception e) {
1313 throw processException(e);
1314 }
1315 finally {
1316 FinderCacheUtil.clearCache("Groups_Permissions");
1317 }
1318 }
1319
1320 public void removeGroups(long pk, long[] groupPKs)
1321 throws SystemException {
1322 try {
1323 for (long groupPK : groupPKs) {
1324 removeGroup.remove(pk, groupPK);
1325 }
1326 }
1327 catch (Exception e) {
1328 throw processException(e);
1329 }
1330 finally {
1331 FinderCacheUtil.clearCache("Groups_Permissions");
1332 }
1333 }
1334
1335 public void removeGroups(long pk,
1336 List<com.liferay.portal.model.Group> groups) throws SystemException {
1337 try {
1338 for (com.liferay.portal.model.Group group : groups) {
1339 removeGroup.remove(pk, group.getPrimaryKey());
1340 }
1341 }
1342 catch (Exception e) {
1343 throw processException(e);
1344 }
1345 finally {
1346 FinderCacheUtil.clearCache("Groups_Permissions");
1347 }
1348 }
1349
1350 public void setGroups(long pk, long[] groupPKs) throws SystemException {
1351 try {
1352 clearGroups.clear(pk);
1353
1354 for (long groupPK : groupPKs) {
1355 addGroup.add(pk, groupPK);
1356 }
1357 }
1358 catch (Exception e) {
1359 throw processException(e);
1360 }
1361 finally {
1362 FinderCacheUtil.clearCache("Groups_Permissions");
1363 }
1364 }
1365
1366 public void setGroups(long pk, List<com.liferay.portal.model.Group> groups)
1367 throws SystemException {
1368 try {
1369 clearGroups.clear(pk);
1370
1371 for (com.liferay.portal.model.Group group : groups) {
1372 addGroup.add(pk, group.getPrimaryKey());
1373 }
1374 }
1375 catch (Exception e) {
1376 throw processException(e);
1377 }
1378 finally {
1379 FinderCacheUtil.clearCache("Groups_Permissions");
1380 }
1381 }
1382
1383 public List<com.liferay.portal.model.Role> getRoles(long pk)
1384 throws SystemException {
1385 return getRoles(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1386 }
1387
1388 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1389 int end) throws SystemException {
1390 return getRoles(pk, start, end, null);
1391 }
1392
1393 public static final FinderPath FINDER_PATH_GET_ROLES = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1394 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1395 "Roles_Permissions", "getRoles",
1396 new String[] {
1397 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1398 "com.liferay.portal.kernel.util.OrderByComparator"
1399 });
1400
1401 public List<com.liferay.portal.model.Role> getRoles(long pk, int start,
1402 int end, OrderByComparator obc) throws SystemException {
1403 Object[] finderArgs = new Object[] {
1404 new Long(pk), String.valueOf(start), String.valueOf(end),
1405 String.valueOf(obc)
1406 };
1407
1408 List<com.liferay.portal.model.Role> list = (List<com.liferay.portal.model.Role>)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES,
1409 finderArgs, this);
1410
1411 if (list == null) {
1412 Session session = null;
1413
1414 try {
1415 session = openSession();
1416
1417 StringBuilder sb = new StringBuilder();
1418
1419 sb.append(_SQL_GETROLES);
1420
1421 if (obc != null) {
1422 sb.append("ORDER BY ");
1423 sb.append(obc.getOrderBy());
1424 }
1425
1426 else {
1427 sb.append("ORDER BY ");
1428
1429 sb.append("Role_.name ASC");
1430 }
1431
1432 String sql = sb.toString();
1433
1434 SQLQuery q = session.createSQLQuery(sql);
1435
1436 q.addEntity("Role_",
1437 com.liferay.portal.model.impl.RoleImpl.class);
1438
1439 QueryPos qPos = QueryPos.getInstance(q);
1440
1441 qPos.add(pk);
1442
1443 list = (List<com.liferay.portal.model.Role>)QueryUtil.list(q,
1444 getDialect(), start, end);
1445 }
1446 catch (Exception e) {
1447 throw processException(e);
1448 }
1449 finally {
1450 if (list == null) {
1451 list = new ArrayList<com.liferay.portal.model.Role>();
1452 }
1453
1454 rolePersistence.cacheResult(list);
1455
1456 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES, finderArgs,
1457 list);
1458
1459 closeSession(session);
1460 }
1461 }
1462
1463 return list;
1464 }
1465
1466 public static final FinderPath FINDER_PATH_GET_ROLES_SIZE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1467 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1468 "Roles_Permissions", "getRolesSize",
1469 new String[] { Long.class.getName() });
1470
1471 public int getRolesSize(long pk) throws SystemException {
1472 Object[] finderArgs = new Object[] { new Long(pk) };
1473
1474 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_ROLES_SIZE,
1475 finderArgs, this);
1476
1477 if (count == null) {
1478 Session session = null;
1479
1480 try {
1481 session = openSession();
1482
1483 SQLQuery q = session.createSQLQuery(_SQL_GETROLESSIZE);
1484
1485 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1486
1487 QueryPos qPos = QueryPos.getInstance(q);
1488
1489 qPos.add(pk);
1490
1491 count = (Long)q.uniqueResult();
1492 }
1493 catch (Exception e) {
1494 throw processException(e);
1495 }
1496 finally {
1497 if (count == null) {
1498 count = Long.valueOf(0);
1499 }
1500
1501 FinderCacheUtil.putResult(FINDER_PATH_GET_ROLES_SIZE,
1502 finderArgs, count);
1503
1504 closeSession(session);
1505 }
1506 }
1507
1508 return count.intValue();
1509 }
1510
1511 public static final FinderPath FINDER_PATH_CONTAINS_ROLE = new FinderPath(com.liferay.portal.model.impl.RoleModelImpl.ENTITY_CACHE_ENABLED,
1512 PermissionModelImpl.FINDER_CACHE_ENABLED_ROLES_PERMISSIONS,
1513 "Roles_Permissions", "containsRole",
1514 new String[] { Long.class.getName(), Long.class.getName() });
1515
1516 public boolean containsRole(long pk, long rolePK) throws SystemException {
1517 Object[] finderArgs = new Object[] { new Long(pk), new Long(rolePK) };
1518
1519 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_ROLE,
1520 finderArgs, this);
1521
1522 if (value == null) {
1523 try {
1524 value = Boolean.valueOf(containsRole.contains(pk, rolePK));
1525 }
1526 catch (Exception e) {
1527 throw processException(e);
1528 }
1529 finally {
1530 if (value == null) {
1531 value = Boolean.FALSE;
1532 }
1533
1534 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_ROLE,
1535 finderArgs, value);
1536 }
1537 }
1538
1539 return value.booleanValue();
1540 }
1541
1542 public boolean containsRoles(long pk) throws SystemException {
1543 if (getRolesSize(pk) > 0) {
1544 return true;
1545 }
1546 else {
1547 return false;
1548 }
1549 }
1550
1551 public void addRole(long pk, long rolePK) throws SystemException {
1552 try {
1553 addRole.add(pk, rolePK);
1554 }
1555 catch (Exception e) {
1556 throw processException(e);
1557 }
1558 finally {
1559 FinderCacheUtil.clearCache("Roles_Permissions");
1560 }
1561 }
1562
1563 public void addRole(long pk, com.liferay.portal.model.Role role)
1564 throws SystemException {
1565 try {
1566 addRole.add(pk, role.getPrimaryKey());
1567 }
1568 catch (Exception e) {
1569 throw processException(e);
1570 }
1571 finally {
1572 FinderCacheUtil.clearCache("Roles_Permissions");
1573 }
1574 }
1575
1576 public void addRoles(long pk, long[] rolePKs) throws SystemException {
1577 try {
1578 for (long rolePK : rolePKs) {
1579 addRole.add(pk, rolePK);
1580 }
1581 }
1582 catch (Exception e) {
1583 throw processException(e);
1584 }
1585 finally {
1586 FinderCacheUtil.clearCache("Roles_Permissions");
1587 }
1588 }
1589
1590 public void addRoles(long pk, List<com.liferay.portal.model.Role> roles)
1591 throws SystemException {
1592 try {
1593 for (com.liferay.portal.model.Role role : roles) {
1594 addRole.add(pk, role.getPrimaryKey());
1595 }
1596 }
1597 catch (Exception e) {
1598 throw processException(e);
1599 }
1600 finally {
1601 FinderCacheUtil.clearCache("Roles_Permissions");
1602 }
1603 }
1604
1605 public void clearRoles(long pk) throws SystemException {
1606 try {
1607 clearRoles.clear(pk);
1608 }
1609 catch (Exception e) {
1610 throw processException(e);
1611 }
1612 finally {
1613 FinderCacheUtil.clearCache("Roles_Permissions");
1614 }
1615 }
1616
1617 public void removeRole(long pk, long rolePK) throws SystemException {
1618 try {
1619 removeRole.remove(pk, rolePK);
1620 }
1621 catch (Exception e) {
1622 throw processException(e);
1623 }
1624 finally {
1625 FinderCacheUtil.clearCache("Roles_Permissions");
1626 }
1627 }
1628
1629 public void removeRole(long pk, com.liferay.portal.model.Role role)
1630 throws SystemException {
1631 try {
1632 removeRole.remove(pk, role.getPrimaryKey());
1633 }
1634 catch (Exception e) {
1635 throw processException(e);
1636 }
1637 finally {
1638 FinderCacheUtil.clearCache("Roles_Permissions");
1639 }
1640 }
1641
1642 public void removeRoles(long pk, long[] rolePKs) throws SystemException {
1643 try {
1644 for (long rolePK : rolePKs) {
1645 removeRole.remove(pk, rolePK);
1646 }
1647 }
1648 catch (Exception e) {
1649 throw processException(e);
1650 }
1651 finally {
1652 FinderCacheUtil.clearCache("Roles_Permissions");
1653 }
1654 }
1655
1656 public void removeRoles(long pk, List<com.liferay.portal.model.Role> roles)
1657 throws SystemException {
1658 try {
1659 for (com.liferay.portal.model.Role role : roles) {
1660 removeRole.remove(pk, role.getPrimaryKey());
1661 }
1662 }
1663 catch (Exception e) {
1664 throw processException(e);
1665 }
1666 finally {
1667 FinderCacheUtil.clearCache("Roles_Permissions");
1668 }
1669 }
1670
1671 public void setRoles(long pk, long[] rolePKs) throws SystemException {
1672 try {
1673 clearRoles.clear(pk);
1674
1675 for (long rolePK : rolePKs) {
1676 addRole.add(pk, rolePK);
1677 }
1678 }
1679 catch (Exception e) {
1680 throw processException(e);
1681 }
1682 finally {
1683 FinderCacheUtil.clearCache("Roles_Permissions");
1684 }
1685 }
1686
1687 public void setRoles(long pk, List<com.liferay.portal.model.Role> roles)
1688 throws SystemException {
1689 try {
1690 clearRoles.clear(pk);
1691
1692 for (com.liferay.portal.model.Role role : roles) {
1693 addRole.add(pk, role.getPrimaryKey());
1694 }
1695 }
1696 catch (Exception e) {
1697 throw processException(e);
1698 }
1699 finally {
1700 FinderCacheUtil.clearCache("Roles_Permissions");
1701 }
1702 }
1703
1704 public List<com.liferay.portal.model.User> getUsers(long pk)
1705 throws SystemException {
1706 return getUsers(pk, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
1707 }
1708
1709 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1710 int end) throws SystemException {
1711 return getUsers(pk, start, end, null);
1712 }
1713
1714 public static final FinderPath FINDER_PATH_GET_USERS = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1715 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1716 "Users_Permissions", "getUsers",
1717 new String[] {
1718 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
1719 "com.liferay.portal.kernel.util.OrderByComparator"
1720 });
1721
1722 public List<com.liferay.portal.model.User> getUsers(long pk, int start,
1723 int end, OrderByComparator obc) throws SystemException {
1724 Object[] finderArgs = new Object[] {
1725 new Long(pk), String.valueOf(start), String.valueOf(end),
1726 String.valueOf(obc)
1727 };
1728
1729 List<com.liferay.portal.model.User> list = (List<com.liferay.portal.model.User>)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS,
1730 finderArgs, this);
1731
1732 if (list == null) {
1733 Session session = null;
1734
1735 try {
1736 session = openSession();
1737
1738 StringBuilder sb = new StringBuilder();
1739
1740 sb.append(_SQL_GETUSERS);
1741
1742 if (obc != null) {
1743 sb.append("ORDER BY ");
1744 sb.append(obc.getOrderBy());
1745 }
1746
1747 String sql = sb.toString();
1748
1749 SQLQuery q = session.createSQLQuery(sql);
1750
1751 q.addEntity("User_",
1752 com.liferay.portal.model.impl.UserImpl.class);
1753
1754 QueryPos qPos = QueryPos.getInstance(q);
1755
1756 qPos.add(pk);
1757
1758 list = (List<com.liferay.portal.model.User>)QueryUtil.list(q,
1759 getDialect(), start, end);
1760 }
1761 catch (Exception e) {
1762 throw processException(e);
1763 }
1764 finally {
1765 if (list == null) {
1766 list = new ArrayList<com.liferay.portal.model.User>();
1767 }
1768
1769 userPersistence.cacheResult(list);
1770
1771 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS, finderArgs,
1772 list);
1773
1774 closeSession(session);
1775 }
1776 }
1777
1778 return list;
1779 }
1780
1781 public static final FinderPath FINDER_PATH_GET_USERS_SIZE = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1782 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1783 "Users_Permissions", "getUsersSize",
1784 new String[] { Long.class.getName() });
1785
1786 public int getUsersSize(long pk) throws SystemException {
1787 Object[] finderArgs = new Object[] { new Long(pk) };
1788
1789 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_GET_USERS_SIZE,
1790 finderArgs, this);
1791
1792 if (count == null) {
1793 Session session = null;
1794
1795 try {
1796 session = openSession();
1797
1798 SQLQuery q = session.createSQLQuery(_SQL_GETUSERSSIZE);
1799
1800 q.addScalar(COUNT_COLUMN_NAME, Type.LONG);
1801
1802 QueryPos qPos = QueryPos.getInstance(q);
1803
1804 qPos.add(pk);
1805
1806 count = (Long)q.uniqueResult();
1807 }
1808 catch (Exception e) {
1809 throw processException(e);
1810 }
1811 finally {
1812 if (count == null) {
1813 count = Long.valueOf(0);
1814 }
1815
1816 FinderCacheUtil.putResult(FINDER_PATH_GET_USERS_SIZE,
1817 finderArgs, count);
1818
1819 closeSession(session);
1820 }
1821 }
1822
1823 return count.intValue();
1824 }
1825
1826 public static final FinderPath FINDER_PATH_CONTAINS_USER = new FinderPath(com.liferay.portal.model.impl.UserModelImpl.ENTITY_CACHE_ENABLED,
1827 PermissionModelImpl.FINDER_CACHE_ENABLED_USERS_PERMISSIONS,
1828 "Users_Permissions", "containsUser",
1829 new String[] { Long.class.getName(), Long.class.getName() });
1830
1831 public boolean containsUser(long pk, long userPK) throws SystemException {
1832 Object[] finderArgs = new Object[] { new Long(pk), new Long(userPK) };
1833
1834 Boolean value = (Boolean)FinderCacheUtil.getResult(FINDER_PATH_CONTAINS_USER,
1835 finderArgs, this);
1836
1837 if (value == null) {
1838 try {
1839 value = Boolean.valueOf(containsUser.contains(pk, userPK));
1840 }
1841 catch (Exception e) {
1842 throw processException(e);
1843 }
1844 finally {
1845 if (value == null) {
1846 value = Boolean.FALSE;
1847 }
1848
1849 FinderCacheUtil.putResult(FINDER_PATH_CONTAINS_USER,
1850 finderArgs, value);
1851 }
1852 }
1853
1854 return value.booleanValue();
1855 }
1856
1857 public boolean containsUsers(long pk) throws SystemException {
1858 if (getUsersSize(pk) > 0) {
1859 return true;
1860 }
1861 else {
1862 return false;
1863 }
1864 }
1865
1866 public void addUser(long pk, long userPK) throws SystemException {
1867 try {
1868 addUser.add(pk, userPK);
1869 }
1870 catch (Exception e) {
1871 throw processException(e);
1872 }
1873 finally {
1874 FinderCacheUtil.clearCache("Users_Permissions");
1875 }
1876 }
1877
1878 public void addUser(long pk, com.liferay.portal.model.User user)
1879 throws SystemException {
1880 try {
1881 addUser.add(pk, user.getPrimaryKey());
1882 }
1883 catch (Exception e) {
1884 throw processException(e);
1885 }
1886 finally {
1887 FinderCacheUtil.clearCache("Users_Permissions");
1888 }
1889 }
1890
1891 public void addUsers(long pk, long[] userPKs) throws SystemException {
1892 try {
1893 for (long userPK : userPKs) {
1894 addUser.add(pk, userPK);
1895 }
1896 }
1897 catch (Exception e) {
1898 throw processException(e);
1899 }
1900 finally {
1901 FinderCacheUtil.clearCache("Users_Permissions");
1902 }
1903 }
1904
1905 public void addUsers(long pk, List<com.liferay.portal.model.User> users)
1906 throws SystemException {
1907 try {
1908 for (com.liferay.portal.model.User user : users) {
1909 addUser.add(pk, user.getPrimaryKey());
1910 }
1911 }
1912 catch (Exception e) {
1913 throw processException(e);
1914 }
1915 finally {
1916 FinderCacheUtil.clearCache("Users_Permissions");
1917 }
1918 }
1919
1920 public void clearUsers(long pk) throws SystemException {
1921 try {
1922 clearUsers.clear(pk);
1923 }
1924 catch (Exception e) {
1925 throw processException(e);
1926 }
1927 finally {
1928 FinderCacheUtil.clearCache("Users_Permissions");
1929 }
1930 }
1931
1932 public void removeUser(long pk, long userPK) throws SystemException {
1933 try {
1934 removeUser.remove(pk, userPK);
1935 }
1936 catch (Exception e) {
1937 throw processException(e);
1938 }
1939 finally {
1940 FinderCacheUtil.clearCache("Users_Permissions");
1941 }
1942 }
1943
1944 public void removeUser(long pk, com.liferay.portal.model.User user)
1945 throws SystemException {
1946 try {
1947 removeUser.remove(pk, user.getPrimaryKey());
1948 }
1949 catch (Exception e) {
1950 throw processException(e);
1951 }
1952 finally {
1953 FinderCacheUtil.clearCache("Users_Permissions");
1954 }
1955 }
1956
1957 public void removeUsers(long pk, long[] userPKs) throws SystemException {
1958 try {
1959 for (long userPK : userPKs) {
1960 removeUser.remove(pk, userPK);
1961 }
1962 }
1963 catch (Exception e) {
1964 throw processException(e);
1965 }
1966 finally {
1967 FinderCacheUtil.clearCache("Users_Permissions");
1968 }
1969 }
1970
1971 public void removeUsers(long pk, List<com.liferay.portal.model.User> users)
1972 throws SystemException {
1973 try {
1974 for (com.liferay.portal.model.User user : users) {
1975 removeUser.remove(pk, user.getPrimaryKey());
1976 }
1977 }
1978 catch (Exception e) {
1979 throw processException(e);
1980 }
1981 finally {
1982 FinderCacheUtil.clearCache("Users_Permissions");
1983 }
1984 }
1985
1986 public void setUsers(long pk, long[] userPKs) throws SystemException {
1987 try {
1988 clearUsers.clear(pk);
1989
1990 for (long userPK : userPKs) {
1991 addUser.add(pk, userPK);
1992 }
1993 }
1994 catch (Exception e) {
1995 throw processException(e);
1996 }
1997 finally {
1998 FinderCacheUtil.clearCache("Users_Permissions");
1999 }
2000 }
2001
2002 public void setUsers(long pk, List<com.liferay.portal.model.User> users)
2003 throws SystemException {
2004 try {
2005 clearUsers.clear(pk);
2006
2007 for (com.liferay.portal.model.User user : users) {
2008 addUser.add(pk, user.getPrimaryKey());
2009 }
2010 }
2011 catch (Exception e) {
2012 throw processException(e);
2013 }
2014 finally {
2015 FinderCacheUtil.clearCache("Users_Permissions");
2016 }
2017 }
2018
2019 public void afterPropertiesSet() {
2020 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2021 com.liferay.portal.util.PropsUtil.get(
2022 "value.object.listener.com.liferay.portal.model.Permission")));
2023
2024 if (listenerClassNames.length > 0) {
2025 try {
2026 List<ModelListener<Permission>> listenersList = new ArrayList<ModelListener<Permission>>();
2027
2028 for (String listenerClassName : listenerClassNames) {
2029 listenersList.add((ModelListener<Permission>)Class.forName(
2030 listenerClassName).newInstance());
2031 }
2032
2033 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2034 }
2035 catch (Exception e) {
2036 _log.error(e);
2037 }
2038 }
2039
2040 containsGroup = new ContainsGroup(this);
2041
2042 addGroup = new AddGroup(this);
2043 clearGroups = new ClearGroups(this);
2044 removeGroup = new RemoveGroup(this);
2045
2046 containsRole = new ContainsRole(this);
2047
2048 addRole = new AddRole(this);
2049 clearRoles = new ClearRoles(this);
2050 removeRole = new RemoveRole(this);
2051
2052 containsUser = new ContainsUser(this);
2053
2054 addUser = new AddUser(this);
2055 clearUsers = new ClearUsers(this);
2056 removeUser = new RemoveUser(this);
2057 }
2058
2059 @BeanReference(name = "com.liferay.portal.service.persistence.AccountPersistence.impl")
2060 protected com.liferay.portal.service.persistence.AccountPersistence accountPersistence;
2061 @BeanReference(name = "com.liferay.portal.service.persistence.AddressPersistence.impl")
2062 protected com.liferay.portal.service.persistence.AddressPersistence addressPersistence;
2063 @BeanReference(name = "com.liferay.portal.service.persistence.BrowserTrackerPersistence.impl")
2064 protected com.liferay.portal.service.persistence.BrowserTrackerPersistence browserTrackerPersistence;
2065 @BeanReference(name = "com.liferay.portal.service.persistence.ClassNamePersistence.impl")
2066 protected com.liferay.portal.service.persistence.ClassNamePersistence classNamePersistence;
2067 @BeanReference(name = "com.liferay.portal.service.persistence.CompanyPersistence.impl")
2068 protected com.liferay.portal.service.persistence.CompanyPersistence companyPersistence;
2069 @BeanReference(name = "com.liferay.portal.service.persistence.ContactPersistence.impl")
2070 protected com.liferay.portal.service.persistence.ContactPersistence contactPersistence;
2071 @BeanReference(name = "com.liferay.portal.service.persistence.CountryPersistence.impl")
2072 protected com.liferay.portal.service.persistence.CountryPersistence countryPersistence;
2073 @BeanReference(name = "com.liferay.portal.service.persistence.EmailAddressPersistence.impl")
2074 protected com.liferay.portal.service.persistence.EmailAddressPersistence emailAddressPersistence;
2075 @BeanReference(name = "com.liferay.portal.service.persistence.GroupPersistence.impl")
2076 protected com.liferay.portal.service.persistence.GroupPersistence groupPersistence;
2077 @BeanReference(name = "com.liferay.portal.service.persistence.ImagePersistence.impl")
2078 protected com.liferay.portal.service.persistence.ImagePersistence imagePersistence;
2079 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutPersistence.impl")
2080 protected com.liferay.portal.service.persistence.LayoutPersistence layoutPersistence;
2081 @BeanReference(name = "com.liferay.portal.service.persistence.LayoutSetPersistence.impl")
2082 protected com.liferay.portal.service.persistence.LayoutSetPersistence layoutSetPersistence;
2083 @BeanReference(name = "com.liferay.portal.service.persistence.ListTypePersistence.impl")
2084 protected com.liferay.portal.service.persistence.ListTypePersistence listTypePersistence;
2085 @BeanReference(name = "com.liferay.portal.service.persistence.MembershipRequestPersistence.impl")
2086 protected com.liferay.portal.service.persistence.MembershipRequestPersistence membershipRequestPersistence;
2087 @BeanReference(name = "com.liferay.portal.service.persistence.OrganizationPersistence.impl")
2088 protected com.liferay.portal.service.persistence.OrganizationPersistence organizationPersistence;
2089 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupPermissionPersistence.impl")
2090 protected com.liferay.portal.service.persistence.OrgGroupPermissionPersistence orgGroupPermissionPersistence;
2091 @BeanReference(name = "com.liferay.portal.service.persistence.OrgGroupRolePersistence.impl")
2092 protected com.liferay.portal.service.persistence.OrgGroupRolePersistence orgGroupRolePersistence;
2093 @BeanReference(name = "com.liferay.portal.service.persistence.OrgLaborPersistence.impl")
2094 protected com.liferay.portal.service.persistence.OrgLaborPersistence orgLaborPersistence;
2095 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyPersistence.impl")
2096 protected com.liferay.portal.service.persistence.PasswordPolicyPersistence passwordPolicyPersistence;
2097 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordPolicyRelPersistence.impl")
2098 protected com.liferay.portal.service.persistence.PasswordPolicyRelPersistence passwordPolicyRelPersistence;
2099 @BeanReference(name = "com.liferay.portal.service.persistence.PasswordTrackerPersistence.impl")
2100 protected com.liferay.portal.service.persistence.PasswordTrackerPersistence passwordTrackerPersistence;
2101 @BeanReference(name = "com.liferay.portal.service.persistence.PermissionPersistence.impl")
2102 protected com.liferay.portal.service.persistence.PermissionPersistence permissionPersistence;
2103 @BeanReference(name = "com.liferay.portal.service.persistence.PhonePersistence.impl")
2104 protected com.liferay.portal.service.persistence.PhonePersistence phonePersistence;
2105 @BeanReference(name = "com.liferay.portal.service.persistence.PluginSettingPersistence.impl")
2106 protected com.liferay.portal.service.persistence.PluginSettingPersistence pluginSettingPersistence;
2107 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPersistence.impl")
2108 protected com.liferay.portal.service.persistence.PortletPersistence portletPersistence;
2109 @BeanReference(name = "com.liferay.portal.service.persistence.PortletItemPersistence.impl")
2110 protected com.liferay.portal.service.persistence.PortletItemPersistence portletItemPersistence;
2111 @BeanReference(name = "com.liferay.portal.service.persistence.PortletPreferencesPersistence.impl")
2112 protected com.liferay.portal.service.persistence.PortletPreferencesPersistence portletPreferencesPersistence;
2113 @BeanReference(name = "com.liferay.portal.service.persistence.RegionPersistence.impl")
2114 protected com.liferay.portal.service.persistence.RegionPersistence regionPersistence;
2115 @BeanReference(name = "com.liferay.portal.service.persistence.ReleasePersistence.impl")
2116 protected com.liferay.portal.service.persistence.ReleasePersistence releasePersistence;
2117 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePersistence.impl")
2118 protected com.liferay.portal.service.persistence.ResourcePersistence resourcePersistence;
2119 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceActionPersistence.impl")
2120 protected com.liferay.portal.service.persistence.ResourceActionPersistence resourceActionPersistence;
2121 @BeanReference(name = "com.liferay.portal.service.persistence.ResourceCodePersistence.impl")
2122 protected com.liferay.portal.service.persistence.ResourceCodePersistence resourceCodePersistence;
2123 @BeanReference(name = "com.liferay.portal.service.persistence.ResourcePermissionPersistence.impl")
2124 protected com.liferay.portal.service.persistence.ResourcePermissionPersistence resourcePermissionPersistence;
2125 @BeanReference(name = "com.liferay.portal.service.persistence.RolePersistence.impl")
2126 protected com.liferay.portal.service.persistence.RolePersistence rolePersistence;
2127 @BeanReference(name = "com.liferay.portal.service.persistence.ServiceComponentPersistence.impl")
2128 protected com.liferay.portal.service.persistence.ServiceComponentPersistence serviceComponentPersistence;
2129 @BeanReference(name = "com.liferay.portal.service.persistence.ShardPersistence.impl")
2130 protected com.liferay.portal.service.persistence.ShardPersistence shardPersistence;
2131 @BeanReference(name = "com.liferay.portal.service.persistence.SubscriptionPersistence.impl")
2132 protected com.liferay.portal.service.persistence.SubscriptionPersistence subscriptionPersistence;
2133 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
2134 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
2135 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupPersistence.impl")
2136 protected com.liferay.portal.service.persistence.UserGroupPersistence userGroupPersistence;
2137 @BeanReference(name = "com.liferay.portal.service.persistence.UserGroupRolePersistence.impl")
2138 protected com.liferay.portal.service.persistence.UserGroupRolePersistence userGroupRolePersistence;
2139 @BeanReference(name = "com.liferay.portal.service.persistence.UserIdMapperPersistence.impl")
2140 protected com.liferay.portal.service.persistence.UserIdMapperPersistence userIdMapperPersistence;
2141 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPersistence.impl")
2142 protected com.liferay.portal.service.persistence.UserTrackerPersistence userTrackerPersistence;
2143 @BeanReference(name = "com.liferay.portal.service.persistence.UserTrackerPathPersistence.impl")
2144 protected com.liferay.portal.service.persistence.UserTrackerPathPersistence userTrackerPathPersistence;
2145 @BeanReference(name = "com.liferay.portal.service.persistence.WebDAVPropsPersistence.impl")
2146 protected com.liferay.portal.service.persistence.WebDAVPropsPersistence webDAVPropsPersistence;
2147 @BeanReference(name = "com.liferay.portal.service.persistence.WebsitePersistence.impl")
2148 protected com.liferay.portal.service.persistence.WebsitePersistence websitePersistence;
2149 protected ContainsGroup containsGroup;
2150 protected AddGroup addGroup;
2151 protected ClearGroups clearGroups;
2152 protected RemoveGroup removeGroup;
2153 protected ContainsRole containsRole;
2154 protected AddRole addRole;
2155 protected ClearRoles clearRoles;
2156 protected RemoveRole removeRole;
2157 protected ContainsUser containsUser;
2158 protected AddUser addUser;
2159 protected ClearUsers clearUsers;
2160 protected RemoveUser removeUser;
2161
2162 protected class ContainsGroup {
2163 protected ContainsGroup(PermissionPersistenceImpl persistenceImpl) {
2164 super();
2165
2166 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2167 _SQL_CONTAINSGROUP,
2168 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2169 }
2170
2171 protected boolean contains(long permissionId, long groupId) {
2172 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2173 new Long(permissionId), new Long(groupId)
2174 });
2175
2176 if (results.size() > 0) {
2177 Integer count = results.get(0);
2178
2179 if (count.intValue() > 0) {
2180 return true;
2181 }
2182 }
2183
2184 return false;
2185 }
2186
2187 private MappingSqlQuery _mappingSqlQuery;
2188 }
2189
2190 protected class AddGroup {
2191 protected AddGroup(PermissionPersistenceImpl persistenceImpl) {
2192 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2193 "INSERT INTO Groups_Permissions (permissionId, groupId) VALUES (?, ?)",
2194 new int[] { Types.BIGINT, Types.BIGINT });
2195 _persistenceImpl = persistenceImpl;
2196 }
2197
2198 protected void add(long permissionId, long groupId)
2199 throws SystemException {
2200 if (!_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2201 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2202
2203 for (ModelListener<Permission> listener : listeners) {
2204 listener.onBeforeAddAssociation(permissionId,
2205 com.liferay.portal.model.Group.class.getName(), groupId);
2206 }
2207
2208 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2209 listener.onBeforeAddAssociation(groupId,
2210 Permission.class.getName(), permissionId);
2211 }
2212
2213 _sqlUpdate.update(new Object[] {
2214 new Long(permissionId), new Long(groupId)
2215 });
2216
2217 for (ModelListener<Permission> listener : listeners) {
2218 listener.onAfterAddAssociation(permissionId,
2219 com.liferay.portal.model.Group.class.getName(), groupId);
2220 }
2221
2222 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2223 listener.onAfterAddAssociation(groupId,
2224 Permission.class.getName(), permissionId);
2225 }
2226 }
2227 }
2228
2229 private SqlUpdate _sqlUpdate;
2230 private PermissionPersistenceImpl _persistenceImpl;
2231 }
2232
2233 protected class ClearGroups {
2234 protected ClearGroups(PermissionPersistenceImpl persistenceImpl) {
2235 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2236 "DELETE FROM Groups_Permissions WHERE permissionId = ?",
2237 new int[] { Types.BIGINT });
2238 }
2239
2240 protected void clear(long permissionId) throws SystemException {
2241 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2242
2243 List<com.liferay.portal.model.Group> groups = null;
2244
2245 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2246 groups = getGroups(permissionId);
2247
2248 for (com.liferay.portal.model.Group group : groups) {
2249 for (ModelListener<Permission> listener : listeners) {
2250 listener.onBeforeRemoveAssociation(permissionId,
2251 com.liferay.portal.model.Group.class.getName(),
2252 group.getPrimaryKey());
2253 }
2254
2255 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2256 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2257 Permission.class.getName(), permissionId);
2258 }
2259 }
2260 }
2261
2262 _sqlUpdate.update(new Object[] { new Long(permissionId) });
2263
2264 if ((listeners.length > 0) || (groupListeners.length > 0)) {
2265 for (com.liferay.portal.model.Group group : groups) {
2266 for (ModelListener<Permission> listener : listeners) {
2267 listener.onAfterRemoveAssociation(permissionId,
2268 com.liferay.portal.model.Group.class.getName(),
2269 group.getPrimaryKey());
2270 }
2271
2272 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2273 listener.onBeforeRemoveAssociation(group.getPrimaryKey(),
2274 Permission.class.getName(), permissionId);
2275 }
2276 }
2277 }
2278 }
2279
2280 private SqlUpdate _sqlUpdate;
2281 }
2282
2283 protected class RemoveGroup {
2284 protected RemoveGroup(PermissionPersistenceImpl persistenceImpl) {
2285 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2286 "DELETE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?",
2287 new int[] { Types.BIGINT, Types.BIGINT });
2288 _persistenceImpl = persistenceImpl;
2289 }
2290
2291 protected void remove(long permissionId, long groupId)
2292 throws SystemException {
2293 if (_persistenceImpl.containsGroup.contains(permissionId, groupId)) {
2294 ModelListener<com.liferay.portal.model.Group>[] groupListeners = groupPersistence.getListeners();
2295
2296 for (ModelListener<Permission> listener : listeners) {
2297 listener.onBeforeRemoveAssociation(permissionId,
2298 com.liferay.portal.model.Group.class.getName(), groupId);
2299 }
2300
2301 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2302 listener.onBeforeRemoveAssociation(groupId,
2303 Permission.class.getName(), permissionId);
2304 }
2305
2306 _sqlUpdate.update(new Object[] {
2307 new Long(permissionId), new Long(groupId)
2308 });
2309
2310 for (ModelListener<Permission> listener : listeners) {
2311 listener.onAfterRemoveAssociation(permissionId,
2312 com.liferay.portal.model.Group.class.getName(), groupId);
2313 }
2314
2315 for (ModelListener<com.liferay.portal.model.Group> listener : groupListeners) {
2316 listener.onAfterRemoveAssociation(groupId,
2317 Permission.class.getName(), permissionId);
2318 }
2319 }
2320 }
2321
2322 private SqlUpdate _sqlUpdate;
2323 private PermissionPersistenceImpl _persistenceImpl;
2324 }
2325
2326 protected class ContainsRole {
2327 protected ContainsRole(PermissionPersistenceImpl persistenceImpl) {
2328 super();
2329
2330 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2331 _SQL_CONTAINSROLE,
2332 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2333 }
2334
2335 protected boolean contains(long permissionId, long roleId) {
2336 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2337 new Long(permissionId), new Long(roleId)
2338 });
2339
2340 if (results.size() > 0) {
2341 Integer count = results.get(0);
2342
2343 if (count.intValue() > 0) {
2344 return true;
2345 }
2346 }
2347
2348 return false;
2349 }
2350
2351 private MappingSqlQuery _mappingSqlQuery;
2352 }
2353
2354 protected class AddRole {
2355 protected AddRole(PermissionPersistenceImpl persistenceImpl) {
2356 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2357 "INSERT INTO Roles_Permissions (permissionId, roleId) VALUES (?, ?)",
2358 new int[] { Types.BIGINT, Types.BIGINT });
2359 _persistenceImpl = persistenceImpl;
2360 }
2361
2362 protected void add(long permissionId, long roleId)
2363 throws SystemException {
2364 if (!_persistenceImpl.containsRole.contains(permissionId, roleId)) {
2365 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2366
2367 for (ModelListener<Permission> listener : listeners) {
2368 listener.onBeforeAddAssociation(permissionId,
2369 com.liferay.portal.model.Role.class.getName(), roleId);
2370 }
2371
2372 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2373 listener.onBeforeAddAssociation(roleId,
2374 Permission.class.getName(), permissionId);
2375 }
2376
2377 _sqlUpdate.update(new Object[] {
2378 new Long(permissionId), new Long(roleId)
2379 });
2380
2381 for (ModelListener<Permission> listener : listeners) {
2382 listener.onAfterAddAssociation(permissionId,
2383 com.liferay.portal.model.Role.class.getName(), roleId);
2384 }
2385
2386 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2387 listener.onAfterAddAssociation(roleId,
2388 Permission.class.getName(), permissionId);
2389 }
2390 }
2391 }
2392
2393 private SqlUpdate _sqlUpdate;
2394 private PermissionPersistenceImpl _persistenceImpl;
2395 }
2396
2397 protected class ClearRoles {
2398 protected ClearRoles(PermissionPersistenceImpl persistenceImpl) {
2399 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2400 "DELETE FROM Roles_Permissions WHERE permissionId = ?",
2401 new int[] { Types.BIGINT });
2402 }
2403
2404 protected void clear(long permissionId) throws SystemException {
2405 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2406
2407 List<com.liferay.portal.model.Role> roles = null;
2408
2409 if ((listeners.length > 0) || (roleListeners.length > 0)) {
2410 roles = getRoles(permissionId);
2411
2412 for (com.liferay.portal.model.Role role : roles) {
2413 for (ModelListener<Permission> listener : listeners) {
2414 listener.onBeforeRemoveAssociation(permissionId,
2415 com.liferay.portal.model.Role.class.getName(),
2416 role.getPrimaryKey());
2417 }
2418
2419 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2420 listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
2421 Permission.class.getName(), permissionId);
2422 }
2423 }
2424 }
2425
2426 _sqlUpdate.update(new Object[] { new Long(permissionId) });
2427
2428 if ((listeners.length > 0) || (roleListeners.length > 0)) {
2429 for (com.liferay.portal.model.Role role : roles) {
2430 for (ModelListener<Permission> listener : listeners) {
2431 listener.onAfterRemoveAssociation(permissionId,
2432 com.liferay.portal.model.Role.class.getName(),
2433 role.getPrimaryKey());
2434 }
2435
2436 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2437 listener.onBeforeRemoveAssociation(role.getPrimaryKey(),
2438 Permission.class.getName(), permissionId);
2439 }
2440 }
2441 }
2442 }
2443
2444 private SqlUpdate _sqlUpdate;
2445 }
2446
2447 protected class RemoveRole {
2448 protected RemoveRole(PermissionPersistenceImpl persistenceImpl) {
2449 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2450 "DELETE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?",
2451 new int[] { Types.BIGINT, Types.BIGINT });
2452 _persistenceImpl = persistenceImpl;
2453 }
2454
2455 protected void remove(long permissionId, long roleId)
2456 throws SystemException {
2457 if (_persistenceImpl.containsRole.contains(permissionId, roleId)) {
2458 ModelListener<com.liferay.portal.model.Role>[] roleListeners = rolePersistence.getListeners();
2459
2460 for (ModelListener<Permission> listener : listeners) {
2461 listener.onBeforeRemoveAssociation(permissionId,
2462 com.liferay.portal.model.Role.class.getName(), roleId);
2463 }
2464
2465 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2466 listener.onBeforeRemoveAssociation(roleId,
2467 Permission.class.getName(), permissionId);
2468 }
2469
2470 _sqlUpdate.update(new Object[] {
2471 new Long(permissionId), new Long(roleId)
2472 });
2473
2474 for (ModelListener<Permission> listener : listeners) {
2475 listener.onAfterRemoveAssociation(permissionId,
2476 com.liferay.portal.model.Role.class.getName(), roleId);
2477 }
2478
2479 for (ModelListener<com.liferay.portal.model.Role> listener : roleListeners) {
2480 listener.onAfterRemoveAssociation(roleId,
2481 Permission.class.getName(), permissionId);
2482 }
2483 }
2484 }
2485
2486 private SqlUpdate _sqlUpdate;
2487 private PermissionPersistenceImpl _persistenceImpl;
2488 }
2489
2490 protected class ContainsUser {
2491 protected ContainsUser(PermissionPersistenceImpl persistenceImpl) {
2492 super();
2493
2494 _mappingSqlQuery = MappingSqlQueryFactoryUtil.getMappingSqlQuery(getDataSource(),
2495 _SQL_CONTAINSUSER,
2496 new int[] { Types.BIGINT, Types.BIGINT }, RowMapper.COUNT);
2497 }
2498
2499 protected boolean contains(long permissionId, long userId) {
2500 List<Integer> results = _mappingSqlQuery.execute(new Object[] {
2501 new Long(permissionId), new Long(userId)
2502 });
2503
2504 if (results.size() > 0) {
2505 Integer count = results.get(0);
2506
2507 if (count.intValue() > 0) {
2508 return true;
2509 }
2510 }
2511
2512 return false;
2513 }
2514
2515 private MappingSqlQuery _mappingSqlQuery;
2516 }
2517
2518 protected class AddUser {
2519 protected AddUser(PermissionPersistenceImpl persistenceImpl) {
2520 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2521 "INSERT INTO Users_Permissions (permissionId, userId) VALUES (?, ?)",
2522 new int[] { Types.BIGINT, Types.BIGINT });
2523 _persistenceImpl = persistenceImpl;
2524 }
2525
2526 protected void add(long permissionId, long userId)
2527 throws SystemException {
2528 if (!_persistenceImpl.containsUser.contains(permissionId, userId)) {
2529 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2530
2531 for (ModelListener<Permission> listener : listeners) {
2532 listener.onBeforeAddAssociation(permissionId,
2533 com.liferay.portal.model.User.class.getName(), userId);
2534 }
2535
2536 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2537 listener.onBeforeAddAssociation(userId,
2538 Permission.class.getName(), permissionId);
2539 }
2540
2541 _sqlUpdate.update(new Object[] {
2542 new Long(permissionId), new Long(userId)
2543 });
2544
2545 for (ModelListener<Permission> listener : listeners) {
2546 listener.onAfterAddAssociation(permissionId,
2547 com.liferay.portal.model.User.class.getName(), userId);
2548 }
2549
2550 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2551 listener.onAfterAddAssociation(userId,
2552 Permission.class.getName(), permissionId);
2553 }
2554 }
2555 }
2556
2557 private SqlUpdate _sqlUpdate;
2558 private PermissionPersistenceImpl _persistenceImpl;
2559 }
2560
2561 protected class ClearUsers {
2562 protected ClearUsers(PermissionPersistenceImpl persistenceImpl) {
2563 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2564 "DELETE FROM Users_Permissions WHERE permissionId = ?",
2565 new int[] { Types.BIGINT });
2566 }
2567
2568 protected void clear(long permissionId) throws SystemException {
2569 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2570
2571 List<com.liferay.portal.model.User> users = null;
2572
2573 if ((listeners.length > 0) || (userListeners.length > 0)) {
2574 users = getUsers(permissionId);
2575
2576 for (com.liferay.portal.model.User user : users) {
2577 for (ModelListener<Permission> listener : listeners) {
2578 listener.onBeforeRemoveAssociation(permissionId,
2579 com.liferay.portal.model.User.class.getName(),
2580 user.getPrimaryKey());
2581 }
2582
2583 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2584 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2585 Permission.class.getName(), permissionId);
2586 }
2587 }
2588 }
2589
2590 _sqlUpdate.update(new Object[] { new Long(permissionId) });
2591
2592 if ((listeners.length > 0) || (userListeners.length > 0)) {
2593 for (com.liferay.portal.model.User user : users) {
2594 for (ModelListener<Permission> listener : listeners) {
2595 listener.onAfterRemoveAssociation(permissionId,
2596 com.liferay.portal.model.User.class.getName(),
2597 user.getPrimaryKey());
2598 }
2599
2600 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2601 listener.onBeforeRemoveAssociation(user.getPrimaryKey(),
2602 Permission.class.getName(), permissionId);
2603 }
2604 }
2605 }
2606 }
2607
2608 private SqlUpdate _sqlUpdate;
2609 }
2610
2611 protected class RemoveUser {
2612 protected RemoveUser(PermissionPersistenceImpl persistenceImpl) {
2613 _sqlUpdate = SqlUpdateFactoryUtil.getSqlUpdate(getDataSource(),
2614 "DELETE FROM Users_Permissions WHERE permissionId = ? AND userId = ?",
2615 new int[] { Types.BIGINT, Types.BIGINT });
2616 _persistenceImpl = persistenceImpl;
2617 }
2618
2619 protected void remove(long permissionId, long userId)
2620 throws SystemException {
2621 if (_persistenceImpl.containsUser.contains(permissionId, userId)) {
2622 ModelListener<com.liferay.portal.model.User>[] userListeners = userPersistence.getListeners();
2623
2624 for (ModelListener<Permission> listener : listeners) {
2625 listener.onBeforeRemoveAssociation(permissionId,
2626 com.liferay.portal.model.User.class.getName(), userId);
2627 }
2628
2629 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2630 listener.onBeforeRemoveAssociation(userId,
2631 Permission.class.getName(), permissionId);
2632 }
2633
2634 _sqlUpdate.update(new Object[] {
2635 new Long(permissionId), new Long(userId)
2636 });
2637
2638 for (ModelListener<Permission> listener : listeners) {
2639 listener.onAfterRemoveAssociation(permissionId,
2640 com.liferay.portal.model.User.class.getName(), userId);
2641 }
2642
2643 for (ModelListener<com.liferay.portal.model.User> listener : userListeners) {
2644 listener.onAfterRemoveAssociation(userId,
2645 Permission.class.getName(), permissionId);
2646 }
2647 }
2648 }
2649
2650 private SqlUpdate _sqlUpdate;
2651 private PermissionPersistenceImpl _persistenceImpl;
2652 }
2653
2654 private static final String _SQL_GETGROUPS = "SELECT {Group_.*} FROM Group_ INNER JOIN Groups_Permissions ON (Groups_Permissions.groupId = Group_.groupId) WHERE (Groups_Permissions.permissionId = ?)";
2655 private static final String _SQL_GETGROUPSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ?";
2656 private static final String _SQL_CONTAINSGROUP = "SELECT COUNT(*) AS COUNT_VALUE FROM Groups_Permissions WHERE permissionId = ? AND groupId = ?";
2657 private static final String _SQL_GETROLES = "SELECT {Role_.*} FROM Role_ INNER JOIN Roles_Permissions ON (Roles_Permissions.roleId = Role_.roleId) WHERE (Roles_Permissions.permissionId = ?)";
2658 private static final String _SQL_GETROLESSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ?";
2659 private static final String _SQL_CONTAINSROLE = "SELECT COUNT(*) AS COUNT_VALUE FROM Roles_Permissions WHERE permissionId = ? AND roleId = ?";
2660 private static final String _SQL_GETUSERS = "SELECT {User_.*} FROM User_ INNER JOIN Users_Permissions ON (Users_Permissions.userId = User_.userId) WHERE (Users_Permissions.permissionId = ?)";
2661 private static final String _SQL_GETUSERSSIZE = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ?";
2662 private static final String _SQL_CONTAINSUSER = "SELECT COUNT(*) AS COUNT_VALUE FROM Users_Permissions WHERE permissionId = ? AND userId = ?";
2663 private static Log _log = LogFactoryUtil.getLog(PermissionPersistenceImpl.class);
2664}