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