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