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