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