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