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