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