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