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