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